/* ===========================
   JARVIS CHAT – estilos
   =========================== */

:root{
  --jarvis-primary: #0A5AC2;
  --jarvis-primary-600: #094aa0;
  --jarvis-bg: #ffffff;
  --jarvis-header: #0A5AC2;
  --jarvis-msg-user: #0A5AC2;
  --jarvis-msg-user-text: #ffffff;
  --jarvis-msg-bot: #eef2f7;
  --jarvis-border: #e6eaf2;
  --jarvis-shadow: 0 20px 50px rgba(10,90,194,.25);
  --radius: 14px;
  --radius-bubble: 14px;
  --z-chat: 10000;
  --font: Inter, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", sans-serif;
}

* { box-sizing: border-box; }

.jarvis-fab{
  position: fixed; right: 20px; bottom: 20px;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--jarvis-primary); color: #fff; border: 0;
  display: grid; place-items: center; cursor: pointer;
  box-shadow: 0 10px 28px rgba(0,0,0,.22);
  z-index: var(--z-chat);
}
.jarvis-fab i{ font-size: 22px; line-height: 1; }
.jarvis-fab:hover{ filter: brightness(1.05); transform: translateY(-1px); }

button.btn-ask-jarvis {width: 100%;}

/* ===== Ventana ===== */
.chat-window{
  width: 360px;
  height: 80vh;          /* puedes subir/bajar esta cifra */
  max-height: 78vh;       /* evita que tape demasiada pantalla */
  min-height: 420px;      /* ¡clave para que no colapse! */
  display: flex;
  flex-direction: column;
  position: fixed; right: 20px; bottom: 92px;
  width: 380px; max-height: 70vh;
  background: var(--jarvis-bg);
  border: 1px solid var(--jarvis-border);
  border-radius: var(--radius);
  box-shadow: var(--jarvis-shadow);
  display: flex; flex-direction: column;
  overflow: hidden;
  z-index: var(--z-chat);
  font-family: var(--font);
}

.hidden{ display: none !important; }

/* ===== Cabecera (estilo “bueno”) ===== */
.chat-header{
  height: 56px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 10px;
  background: var(--jarvis-header);
  color: #fff;
  flex: 0 0 auto;
   display: flex;
  align-items: center;
  justify-content: space-between;
}
.chat-title{
  display: flex; align-items: center; gap: 10px;
  font-weight: 700;
  height:55px;
}
.chat-title .avatar{
  width: 50px; height: 50px; border-radius: 50%;
  object-fit: cover; border: 2px solid rgba(255,255,255,.35);
}
.chat-sub{
  font-size: 12px; opacity: .85; font-weight: 500; margin-left: 4px;
}
.chat-actions{ display: flex; align-items: center; gap: 6px; }
.icon-btn{
  width: 36px; height: 36px; border: 0; border-radius: 10px;
  /*background: rgba(255,255,255,.12); */
  color: #fff; cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn:hover{ background: rgba(255,255,255,.22); }

/* ===== Log ===== */
.chat-log{
  background: #f8fafc;
  min-height: 240px;
  padding: 14px 12px;
  overflow-y: auto;
  flex: 1 1 auto;
}
.chat-log.hidden{ display: none; }

/* Mensaje genérico */
.msg{ margin-bottom: 12px; display: flex; gap: 8px; }
.msg .bubble{
  padding: 10px 12px;
  border-radius: var(--radius-bubble);
  border: 1px solid var(--jarvis-border);
  max-width: 80%;
  line-height: 1.35;
  font-size: 14.5px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msg .meta{ font-size: 11px; color: #667085; margin-top: 4px; }

/* Bot (izquierda) */
.msg.bot .avatar{
  width: 32px; height: 32px; border-radius: 50%; object-fit: cover;
}
.msg.bot .bubble{
  background: var(--jarvis-msg-bot);
  color: #192133;
}

/* Usuario (derecha) */
.msg.user{ justify-content: flex-end; }
.msg.user .bubble{
  background: var(--jarvis-msg-user);
  color: var(--jarvis-msg-user-text);
  border-color: rgba(10,90,194,.1);
}

/* ===== Barra de entrada ===== */
.chat-input-row{
  display: grid; grid-template-columns: 40px 1fr 42px; gap: 8px; align-items: center;
  padding: 10px; border-top: 1px solid var(--jarvis-border); background: #fff;
  flex: 0 0 auto; 
}
#chatText{
  width: 100%; min-height: 44px; max-height: 110px; resize: vertical;
  border: 1px solid var(--jarvis-border);
  border-radius: 12px; padding: 10px 12px; font-size: 14.5px;
  outline: none;
}
#chatText:focus{ border-color: #cbd5e1; box-shadow: 0 0 0 3px rgba(10,90,194,.08); }
.send-btn{
  background: var(--jarvis-primary); color: #fff; border: 0;
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center; cursor: pointer;
}
.send-btn:hover{ background: var(--jarvis-primary-600); }

.history-modal{
  position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 10001;
  display: grid; place-items: center;
}
.history-card{
  width: 520px; max-height: 80vh; overflow: hidden; background: #fff;
  border: 1px solid var(--jarvis-border); border-radius: 14px; box-shadow: var(--jarvis-shadow);
  display: flex; flex-direction: column;
}
.history-head{
  display: flex; justify-content: space-between; align-items: center;
  background: #3e7ecf; color: #fff; padding: 10px 12px; font-weight: 700;
}
.history-list{
  padding: 10px; overflow-y: auto; background: #f8fafc;border-bottom: 1px solid #cbcbcb;
}
.history-item{
  background:#fff; border:1px solid var(--jarvis-border); border-radius: 12px;
  padding:10px 12px; margin-bottom: 10px; cursor: pointer;
}
.history-item:hover{ border-color:#cbd5e1; background:#fff; }
.history-item .meta{ font-size:12px; color:#667085; margin-top:4px; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  background: #f9f9f9;
}

.chat-message {
  max-width: 80%;
  margin: 8px 0;
  padding: 8px 12px;
  border-radius: 12px;
  line-height: 1.4;
}

.user-message {
  background-color: #0055cc;
  color: white;
  align-self: flex-end;
}

.bot-message {
  background-color: #e6e6e6;
  color: #333;
  align-self: flex-start;
}

.chat-input {
  display: flex;
  border-top: 1px solid #ddd;
}

.chat-input input {
  flex: 1;
  padding: 10px;
  border: none;
  outline: none;
}

.chat-input button {
  background-color: #0055cc;
  color: white;
  border: none;
  padding: 10px 16px;
  cursor: pointer;
}

/* ===== Indicador escribiendo ===== */
.typing{ display: inline-flex; gap: 4px; align-items: center; }
.typing span{
  width: 6px; height: 6px; border-radius: 50%; background: #9aa4b2;
  display: inline-block; animation: blink 1.2s infinite;
}
.typing span:nth-child(2){ animation-delay: .15s; }
.typing span:nth-child(3){ animation-delay: .30s; }
@keyframes blink{ 0%, 80%, 100%{ opacity:.25 } 40%{ opacity:1 } }

/* === Toasts dentro del chat === */
.chat-toasts {
  position: absolute;
  bottom: 72px; /* encima del input */
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 30;
}
.chat-toast {
  min-width: 220px;
  max-width: 360px;
  padding: 10px 12px;
  border-radius: 10px;
  color: #fff;
  font-size: 13px;
  box-shadow: 0 6px 22px rgba(0,0,0,.12);
  animation: toastIn .18s ease-out;
}
.chat-toast.ok    { background: #0EA366; }     /* verde */
.chat-toast.warn  { background: #F59E0B; }     /* amber */
.chat-toast.err   { background: #D14343; }     /* rojo */

@keyframes toastIn { from { opacity: 0; transform: translateY(6px);} to {opacity:1; transform: translateY(0);} }

/* === Panel de históricos DENTRO del chat-window === */
.history-panel {
  position: absolute;
  inset: 56px 0 70px 0; /* debajo cabecera, encima input */
  background: #fff;
  z-index: 25;
  border-top: 1px solid #eef0f3;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 240px; 
  overflow: auto;
}
.history-panel.hidden { display: none; }
.history-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid #eef0f3;
  font-weight: 600; color: #0A2540;
}
.history-head .title { flex: 0 0 auto; color:#fff}
.history-head .spacer { flex: 1 1 auto; }
.history-list {
  padding: 10px 12px;
  overflow: auto;
}
.history-item {
  display: grid; grid-template-columns: 1fr auto;
  gap: 8px; align-items: center;
  padding: 8px 10px; border: 1px solid #eef0f3; border-radius: 8px;
  margin-bottom: 8px;
}
.history-item .meta { font-size: 12px; color: #5b6675; }
.history-item .title { font-weight: 600; color: #0A2540; }
.history-item .actions { display: flex; gap: 6px; }
.history-item button.btn {
  border: none; border-radius: 8px; padding: 6px 10px;
  cursor: pointer; font-size: 12px;
}
.history-item .btn.restore { background: #0A5AC2; color: #fff; }
.history-item .btn.delete  { background: #FEE2E2; color: #B91C1C; }

/* === Confirm bar dentro del chat === */
.chat-confirm{
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: 10px;
    background: #0a5ac2;
    color: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
    padding: 12px;  
    z-index: 20;
    width: 300px;
    z-index:99;
}
.chat-confirm .text{
  font-size: 14px;
  line-height: 1.35;
  margin-bottom: 10px;
}
.chat-confirm .actions{
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.chat-confirm .btn{
  border: 0; border-radius: 8px;
  padding: 8px 12px;
  background: rgba(255,255,255,.2);
  color: #fff; cursor: pointer;
}

.chat-confirm .btn.ok{ background: #3e7ecf;color: #fff;}
.chat-confirm .btn:focus{ outline: 2px solid rgba(255,255,255,.5); }
.chat-confirm.hidden { display: none; }

/* Fila de entrada del chat */
.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

/* Icono de adjuntar */
.chat-input-row .icon-btn {
  flex: 0 0 auto;
}

/* Textarea por defecto (con icono de adjuntar) */
.chat-input-row textarea#chatText {
  flex: 1 1 auto;
  width: auto;          /* que mande el flex */
  min-height: 36px;
  max-height: 120px;
  resize: none;
}

/* Botón de enviar */
.chat-input-row .send-btn {
  flex: 0 0 auto;
}

/* === MODO SIN ICONO (ADMIN OFF) === */
.chat-input-row.admin-off .icon-btn {
  display: none;        /* ocultamos el icono */
}

/* Cuando no hay icono, el textarea ocupa TODO el espacio disponible */
.chat-input-row.admin-off textarea#chatText {
  flex: 1 1 auto;
  width: 100%;          /* se estira a todo el ancho libre */
}

/* === Origen de la respuesta (FAQ / Docs / OpenAI) === */
.origin-badges {
  margin-top: 6px;
  font-size: 10px;
}

.origin-badge {
  display: inline-block;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 999px;
  margin-right: 4px;
  background: #eee;
  color: #555;
  line-height: 1;
}

/* Colores según origen */
.origin-faq {
  background: #fef3c7;   /* amarillo suave */
  color: #92400e;
}

.origin-docs {
  background: #dbeafe;   /* azul suave */
  color: #1d4ed8;
}

.origin-openai {
  background: #e5e7eb;   /* gris neutro */
  color: #374151;
}

.jarvis-avatar-shell {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-right: 8px;
}


/* === Botones de feedback para FAQ (solo modo admin) === */
.faq-actions {
  margin-top: 6px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.faq-btn {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.faq-approve {
  background: #dcfce7;   /* verde suave */
  color: #166534;
}

.faq-reject {
  background: #fee2e2;   /* rojo suave */
  color: #991b1b;
}

.faq-status-ok {
  margin-top: 4px;
  font-size: 11px;
  color: #166534;
}

.faq-status-ko {
  margin-top: 4px;
  font-size: 11px;
  color: #991b1b;
}

/* ===========================
   Panel admin FAQs
   =========================== */

.faq-admin-panel {
    position: fixed;
    top: 70px;
    left: 14px;
    width: 56vw;
    max-height: 91vh;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
    border: 1px solid #d0d7ea;
    display: flex;
    flex-direction: column;
    font-size: 14px;
    z-index: 9999;
}

.faq-admin-panel.hidden {
  display: none;
}

.faq-admin-header {
  padding: 8px 12px;
  background: var(--jarvis-header);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 12px 12px 0 0;
}

.faq-admin-header .title {
  font-weight: 600;
}

.faq-admin-close {
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 10px;
    background: #0b5ac2;
    color: #fff;
    cursor: pointer;
    display: grid;
    place-items: center;
    font-size:18px;
}

.faq-admin-close:hover{
  background: rgba(255,255,255,.22); 
}


.faq-admin-body {
  padding: 8px 10px;
  overflow-y: auto;
}

.faq-admin-loading,
.faq-admin-error,
.faq-empty,
.faq-empty-doc {
  padding: 6px 4px;
  color: #555;
}

.faq-admin-error {
  color: #b30000;
}

.faq-doc {
  border: 1px solid #e3e7f2;
  border-radius: 8px;
  padding: 6px;
  margin-bottom: 8px;
  background: #f9fbff;
}

.faq-doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 4px;
}

.faq-doc-header .file-name {
  font-weight: 600;
  font-size: 13px;
}

.faq-doc-header .file-meta {
  font-size: 11px;
  color: #666;
}

.faq-doc-header .faq-refresh-doc {
  font-size: 14px;
  padding: 6px 6px;
  border-radius: 6px;
  border: 1px solid #ccd4ea;
  background: #fff;
  cursor: pointer;
}

.faq-questions {
  margin-top: 4px;
  margin-bottom: 6px;
  max-height: 200px;
  overflow-y: auto;
}

.faq-row {
  border-top: 1px solid #e1e6f0;
  padding-top: 4px;
  margin-top: 4px;
}

.faq-row:first-child {
  border-top: none;
  margin-top: 0;
  padding-top: 0;
}

.faq-row-main {
  margin-bottom: 4px;
}

.faq-question {
  font-weight: 600;
  margin-bottom: 2px;
}

.faq-answer {
  font-size: 14px;
  color: #555;
}

.faq-row-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  font-size: 11px;
  color: #666;
}

.faq-dates span {
  display: inline-block;
  margin-right: 6px;
}

.faq-actions .faq-status-btn {
  font-size: 14px;
  margin-left: 4px;
  padding: 4px 4px;
  border-radius: 6px;
  border: 1px solid #ccd4ea;
  background: #fff;
  cursor: pointer;
}

.faq-new {
  margin-top: 6px;
  border-top: 1px dashed #d0d7ea;
  padding-top: 4px;
}

.faq-new-title {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 6px;
    margin-top: 6px;
}

.faq-new-question, .faq-new-answer {
    width: 100%;
    box-sizing: border-box;
    border-radius: 6px;
    border: 1px solid #ccd4ea;
    padding: 6px 6px;
    font-size: 14px;
    margin-bottom: 8px;
}

.faq-new-actions {
  text-align: right;
}

.faq-new-save {
  font-size: 14px;
  padding: 6px 6px;
  border-radius: 6px;
  border: 1px solid var(--jarvis-primary);
  background: var(--jarvis-primary);
  color: #fff;
  cursor: pointer;
}

.faq-new-save:hover{
 background: rgba(255, 255, 255, .22);
}

button#openFaqAdminHeader {
    float: right;
    right: 18px;
    position: absolute;
    height: 30px;
    border: 1px solid #e2e6ef;
    border-radius: 10px;
}



