/* ============================================================
   Consultor SURA — rediseño: chat con conversación, tema oscuro/claro
   Toda superficie, línea y texto pasa por una variable; el atributo
   data-theme del <html> alterna oscuro (por defecto) y claro.
   ============================================================ */

:root,
:root[data-theme="dark"] {
  --bg: #0a1730;             /* fondo del chat / main */
  --sidebar: #0c1c39;        /* barra lateral */
  --surface: #10233f;        /* tarjetas y paneles */
  --surface-2: #0e2144;      /* composer, hovers */
  --band: #16325c;           /* banda de cabecera de panel */
  --band-ink: #cdddff;

  --line: rgba(255, 255, 255, 0.08);
  --line-2: rgba(255, 255, 255, 0.05);
  --line-strong: rgba(255, 255, 255, 0.12);

  --ink: #eaf1ff;            /* texto principal */
  --text: #d7e0ee;
  --text-2: #b9c5da;
  --muted: #8fa0bd;
  --faint: #6b7d9c;

  --brand: #9cc0ff;          /* rótulo "Consultor" del bot */
  --link: #7ea6ff;           /* interacción / enlaces / activo */
  --primary: #2f6bea;        /* botón enviar, acción estrella */
  --primary-ink: #2f6bea;
  --amber: #f5a623;          /* SOLO el estado vivo del agente */

  --user-bubble: #17335f;
  --active: rgba(79, 131, 247, 0.15);
  --avatar-bg: #1a3a6b;
  --avatar-ink: #7ea6ff;
  --sidebar-avatar-ink: #cdddff;
  --menu-bg: #14294b;

  --ok: #4ade80;
  --err: #ff8080;
  --err-soft: rgba(255, 128, 128, 0.12);
  --th: #7286a6;

  --band-pill-bg: rgba(255, 255, 255, 0.08);
  --band-excel-bg: #2f6bea;
  --band-excel-ink: #ffffff;

  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 4px 20px rgba(0, 0, 0, 0.3);
  --send-glow: 0 4px 14px rgba(47, 107, 234, 0.4);
  --logo-filter: brightness(0) invert(1);
  --code-bg: #071328;
  --scrollbar: rgba(255, 255, 255, 0.14);

  --login-bg: radial-gradient(120% 70% at 50% 0%, #10233f 0%, #0a1730 60%);
  --login-card: #0e2144;
  --login-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
  --seg-bg: rgba(0, 0, 0, 0.25);
  --bar-grad: linear-gradient(90deg, #2f6bea, #7ea6ff);
  --bar-track: rgba(255, 255, 255, 0.06);
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --sidebar: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --band: #06204c;
  --band-ink: #ffffff;

  --line: #e6e9ef;
  --line-2: #f2f4f7;
  --line-strong: #dbe1ea;

  --ink: #1b2330;
  --text: #1b2330;
  --text-2: #3a4351;
  --muted: #5a6372;
  --faint: #8a94a3;

  --brand: #06204c;
  --link: #1a56db;
  --primary: #06204c;
  --primary-ink: #041833;
  --amber: #b45309;

  --user-bubble: #eef2f9;
  --active: #eaeff8;
  --avatar-bg: #06204c;
  --avatar-ink: #ffffff;
  --sidebar-avatar-ink: #ffffff;
  --menu-bg: #ffffff;

  --ok: #15803d;
  --err: #c02626;
  --err-soft: #fbeae8;
  --th: #8a94a3;

  --band-pill-bg: rgba(255, 255, 255, 0.12);
  --band-excel-bg: #ffffff;
  --band-excel-ink: #06204c;

  --shadow: 0 12px 40px rgba(6, 32, 76, 0.1);
  --shadow-sm: 0 4px 20px rgba(6, 32, 76, 0.07);
  --send-glow: 0 4px 14px rgba(6, 32, 76, 0.16);
  --logo-filter: none;
  --code-bg: #0b1b33;
  --scrollbar: rgba(6, 32, 76, 0.18);

  --login-bg: radial-gradient(120% 70% at 50% 0%, #edf3fd 0%, #f6f8fc 60%);
  --login-card: #ffffff;
  --login-shadow: 0 20px 50px rgba(6, 32, 76, 0.12);
  --seg-bg: rgba(255, 255, 255, 0.12);
  --bar-grad: linear-gradient(90deg, #06204c, #1a56db);
  --bar-track: #eef1f5;
}

:root {
  --display: "Archivo", system-ui, sans-serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --r: 12px;
  --r-sm: 10px;
  --r-lg: 16px;
  --maxw: 740px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; overflow: hidden; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

.app { height: 100vh; display: flex; background: var(--bg); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }

/* ============================================================
   SIDEBAR
   ============================================================ */

.sidebar {
  width: 264px;
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 16px 12px 12px;
  gap: 0;
  overflow: hidden;
}
.app.sidebar-collapsed .sidebar { display: none; }

.sb-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; }
.sb-logo { height: 24px; width: auto; display: block; flex-shrink: 0; filter: var(--logo-filter); }
.sb-brand-sep { width: 1px; height: 18px; background: var(--line-strong); flex-shrink: 0; }
.sb-brand-name {
  font-family: var(--display);
  font-weight: 700;
  font-size: 15px;
  color: var(--ink);
  letter-spacing: 0.01em;
}

.new-chat {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  background: color-mix(in srgb, var(--ink) 6%, transparent);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  padding: 11px 14px;
  cursor: pointer;
  font-family: var(--display);
  font-weight: 600;
  font-size: 13.5px;
  color: var(--ink);
  transition: background 0.12s, border-color 0.12s;
}
.new-chat svg { flex-shrink: 0; color: var(--link); }
.new-chat:hover { border-color: var(--link); }

.sb-search { position: relative; margin: 12px 0 8px; }
.sb-search svg {
  position: absolute;
  left: 11px; top: 50%;
  transform: translateY(-50%);
  color: var(--faint);
  pointer-events: none;
}
.sb-search input {
  width: 100%;
  background: color-mix(in srgb, var(--ink) 5%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 8px 10px 8px 32px;
  font-size: 13px;
  font-family: var(--sans);
  color: var(--ink);
  outline: none;
}
.sb-search input::placeholder { color: var(--faint); }
.sb-search input:focus { border-color: var(--link); }

.chat-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 6px;
}
.chat-group {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--faint);
  padding: 14px 12px 5px;
}
.chat-group:first-child { padding-top: 8px; }
.chat-empty { padding: 10px 12px; font-size: 12.5px; color: var(--faint); }

.chat-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  cursor: pointer;
  color: var(--text-2);
}
.chat-item:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); }
.chat-item.active { background: var(--active); color: var(--ink); }
.chat-item.active .chat-item-title { font-weight: 550; }
.chat-item-title {
  flex: 1;
  font-size: 13.5px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-item-x {
  flex-shrink: 0;
  border: none; background: none; cursor: pointer;
  color: var(--faint);
  font-size: 16px; line-height: 1;
  padding: 0 3px;
  opacity: 0;
  transition: opacity 0.1s;
}
.chat-item:hover .chat-item-x { opacity: 1; }
.chat-item-x:hover { color: var(--err); }

.sb-user {
  position: relative;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sb-user-btn {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  margin: -4px;
  border-radius: var(--r-sm);
  text-align: left;
  color: inherit;
  font-family: inherit;
  transition: background 0.12s;
}
.sb-user-btn:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); }
.sb-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--avatar-bg);
  color: var(--sidebar-avatar-ink);
  display: grid; place-items: center;
  flex-shrink: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 12px;
}
.sb-user-meta { flex: 1; min-width: 0; }
.sb-user-name { font-size: 13px; font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-user-role { font-size: 11px; color: var(--faint); }
.sb-user-caret { flex-shrink: 0; color: var(--faint); transition: transform 0.15s; }
.sb-user[data-open="true"] .sb-user-caret { transform: rotate(180deg); }

.sb-iconbtn {
  flex-shrink: 0;
  border: none;
  background: color-mix(in srgb, var(--ink) 6%, transparent);
  cursor: pointer;
  color: var(--muted);
  width: 30px; height: 30px;
  border-radius: 8px;
  display: grid; place-items: center;
  transition: color 0.12s, background 0.12s;
}
.sb-iconbtn:hover { color: var(--ink); }
.sb-iconbtn--theme { color: var(--amber); }

/* menú del perfil (Usuarios / Cerrar sesión) — lenguaje de menús del diseño */
.sb-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0; right: 0;
  background: var(--menu-bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sb-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink);
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
}
.sb-menu-item svg { flex-shrink: 0; color: var(--muted); }
.sb-menu-item:hover { background: color-mix(in srgb, var(--ink) 8%, transparent); }
.sb-menu-item--danger, .sb-menu-item--danger svg { color: var(--err); }

/* ============================================================
   TOPBAR
   ============================================================ */

.topbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
}
.sidebar-toggle {
  flex-shrink: 0;
  border: none; background: none; cursor: pointer;
  color: var(--muted);
  width: 34px; height: 34px;
  border-radius: var(--r-sm);
  display: grid; place-items: center;
}
.sidebar-toggle:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); color: var(--ink); }

.topbar-title { display: flex; align-items: center; gap: 9px; }
.tt-name { font-family: var(--display); font-weight: 600; font-size: 14.5px; color: var(--ink); }

.model-pick { display: flex; align-items: center; }
#model {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: 4px 24px 4px 8px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' fill='none' stroke='%238fa0bd' stroke-width='1.5' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
}
#model:hover { background-color: color-mix(in srgb, var(--ink) 6%, transparent); }
#model option { color: #1b2330; }

.dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--faint);
  vertical-align: middle;
}
.dot.ok { background: var(--ok); }
.dot.error { background: var(--err); }

/* ============================================================
   CHAT
   ============================================================ */

.chat { flex: 1; overflow-y: auto; scroll-behavior: smooth; padding: 32px 24px; }
.chat > .welcome { max-width: var(--maxw); margin: 0 auto; }
/* Cada hijo directo del chat se centra: los mensajes se agregan al vuelo. */
.chat > .msg { max-width: var(--maxw); margin-left: auto; margin-right: auto; }
.chat > .msg + .msg { margin-top: 30px; }

.welcome { display: flex; flex-direction: column; align-items: center; }

/* === MENSAJES === */

.msg { display: flex; gap: 14px; }

/* usuario: burbuja a la derecha, sin avatar */
.msg--user { justify-content: flex-end; }
.msg--user .msg-body { max-width: 78%; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.msg--user .bubble {
  background: var(--user-bubble);
  border-radius: 20px 20px 6px 20px;
  padding: 12px 17px;
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
}
.msg--user .bubble p { margin: 0; }

/* bot / error: avatar + cuerpo */
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: grid; place-items: center;
  flex-shrink: 0;
  margin-top: 2px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 14px;
}
.avatar--bot { background: var(--avatar-bg); color: var(--avatar-ink); }
.msg--bot .msg-body, .msg--error .msg-body, .activity-live .msg-body { flex: 1; min-width: 0; }

.msg-meta { display: flex; align-items: baseline; gap: 9px; margin-bottom: 8px; }
.msg-meta .who { font-family: var(--display); font-weight: 600; font-size: 13.5px; color: var(--brand); }
.msg-meta .when { font-size: 12px; color: var(--faint); }

.bubble--err {
  background: var(--err-soft);
  border: 1px solid color-mix(in srgb, var(--err) 30%, transparent);
  border-radius: var(--r);
  padding: 10px 14px;
  color: var(--err);
}
.bubble--err p { margin: 0; }

.msg-files { display: flex; flex-wrap: wrap; gap: 6px; }

/* === CONTENIDO MARKDOWN (respuestas) === */

.content { color: var(--text); }
.content > *:first-child { margin-top: 0; }
.content > *:last-child { margin-bottom: 0; }
.content p { margin: 0 0 12px; font-size: 15px; line-height: 1.65; }
.content strong { font-weight: 650; color: var(--ink); }
.content h1, .content h2, .content h3, .content h4 {
  font-weight: 650;
  letter-spacing: -0.01em;
  margin: 20px 0 8px;
  line-height: 1.3;
  color: var(--ink);
}
.content h1 { font-size: 19px; }
.content h2 { font-size: 16.5px; }
.content h3 { font-size: 15px; }
.content h1:first-child, .content h2:first-child, .content h3:first-child { margin-top: 2px; }
.content ul, .content ol { margin: 4px 0 12px; padding-left: 22px; }
.content li { margin-bottom: 3px; }
.content a { color: var(--link); }

.content code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.5px 5px;
}
.content pre {
  background: var(--code-bg);
  color: #e6e8eb;
  border-radius: var(--r-sm);
  padding: 12px 14px;
  overflow-x: auto;
  margin: 12px 0;
  font-size: 12.5px;
  line-height: 1.5;
}
.content pre code { background: none; border: none; padding: 0; color: inherit; }

/* tablas markdown sueltas (no el panel de resultados) */
.content table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  margin: 12px 0;
  font-size: 13.5px;
  display: block;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}
.content th, .content td { border-bottom: 1px solid var(--line-2); padding: 8px 12px; text-align: left; white-space: nowrap; }
.content tr:last-child td { border-bottom: none; }
.content th { font-weight: 600; color: var(--muted); background: color-mix(in srgb, var(--ink) 4%, transparent); }

/* ============================================================
   PANEL DE RESULTADOS
   ============================================================ */

.result-panel {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.rp-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 15px;
  background: var(--band);
  flex-wrap: wrap;
}
.rp-title {
  font-family: var(--display);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--band-ink);
}
.rp-count { font-size: 12px; color: color-mix(in srgb, var(--band-ink) 60%, transparent); }

.rp-actions { margin-left: auto; display: flex; align-items: center; gap: 7px; }
.rp-search {
  font-family: var(--sans);
  font-size: 12.5px;
  color: var(--band-ink);
  background: var(--band-pill-bg);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 6px 12px;
  width: 130px;
  transition: width 0.15s;
}
.rp-search::placeholder { color: color-mix(in srgb, var(--band-ink) 55%, transparent); }
.rp-search:focus { outline: none; width: 170px; border-color: color-mix(in srgb, var(--band-ink) 40%, transparent); }

.rp-btn {
  font-family: var(--display);
  font-size: 12px;
  font-weight: 550;
  color: var(--band-ink);
  background: var(--band-pill-bg);
  border: none;
  border-radius: 999px;
  padding: 6px 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: filter 0.12s;
}
.rp-btn:hover { filter: brightness(1.15); }
.rp-btn:disabled { opacity: 0.5; cursor: default; }
.rp-btn--excel {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 650;
  color: var(--band-excel-ink);
  background: var(--band-excel-bg);
}
.rp-btn--excel svg { flex-shrink: 0; }

.rp-note:empty { display: none; }
.rp-note {
  margin: 0;
  padding: 8px 15px;
  font-size: 12.5px;
  color: var(--err);
  background: var(--err-soft);
  border-bottom: 1px solid var(--line);
}

.rp-table-wrap { overflow: auto; max-height: 440px; }
.rp-table-wrap table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; color: var(--text); }
.rp-table-wrap th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 10px 15px;
  text-align: left;
  font-weight: 600;
  font-size: 11.5px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--th);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.rp-table-wrap th:hover { color: var(--ink); }
.rp-table-wrap th::after {
  content: "";
  display: inline-block;
  margin-left: 5px;
  border: 4px solid transparent;
  vertical-align: middle;
  opacity: 0;
}
.rp-table-wrap th.sorted { color: var(--ink); }
.rp-table-wrap th.sorted::after { opacity: 1; border-bottom-color: var(--link); margin-bottom: 3px; }
.rp-table-wrap th.sorted.desc::after { border-bottom-color: transparent; border-top-color: var(--link); margin-bottom: -5px; }
.rp-table-wrap td {
  border-bottom: 1px solid var(--line-2);
  padding: 10px 15px;
  white-space: nowrap;
  max-width: 380px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rp-table-wrap tbody tr:last-child td { border-bottom: none; }
.rp-table-wrap tbody tr:hover td { background: color-mix(in srgb, var(--link) 8%, transparent); }
.rp-table-wrap .num { text-align: right; font-variant-numeric: tabular-nums; }
.rp-table-wrap td.empty { color: var(--faint); }

.rp-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 15px;
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--ink) 2%, transparent);
  min-height: 34px;
}
.rp-status { font-size: 12px; color: var(--faint); }
.rp-more {
  margin-left: auto;
  font-family: var(--display);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--link);
  background: none; border: none; cursor: pointer;
  padding: 2px 4px;
}
.rp-more:hover { text-decoration: underline; }
.rp-more[hidden] { display: none; }

.result-panel .sql-toggle { margin: 0; padding: 10px 15px; border-top: 1px solid var(--line); }
.result-panel .sql-toggle pre { margin-bottom: 0; }

/* === DISCLOSURES: ver sql / ver proceso === */

.disclosure { margin-top: 12px; font-size: 13px; }
.disclosure > summary {
  color: var(--link);
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  user-select: none;
  font-family: var(--display);
  font-weight: 550;
  font-size: 12.5px;
}
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary::before { content: "›"; display: inline-block; transition: transform 0.15s; color: var(--faint); }
.disclosure[open] > summary::before { transform: rotate(90deg); }

.sql-toggle pre {
  margin-top: 8px;
  font-family: var(--mono);
  background: var(--code-bg);
  color: #e6e8eb;
  border-radius: var(--r-sm);
  padding: 10px 12px;
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* === DESCARGAS === */

.downloads { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.download-chip {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  padding: 8px 12px 8px 9px;
  transition: border-color 0.12s;
}
.download-chip:hover { border-color: var(--link); }
.download-chip:visited { color: var(--ink); }
.dl-icon {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 650;
  color: #fff;
  background: var(--primary);
  border-radius: 3px;
  padding: 3px 5px;
}
.dl-name { font-size: 14px; }
.dl-size { font-size: 12px; color: var(--faint); }
.dl-arrow { color: var(--link); font-weight: 650; }

/* === ACTIVIDAD EN VIVO (firma del agente) === */

.activity-live .act-headline {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 11px 16px;
  color: var(--ink);
  max-width: 100%;
  min-width: 0;
}
.act-head-text { font-family: var(--display); font-weight: 600; font-size: 13.5px; color: var(--brand); flex-shrink: 0; }
.act-time { font-family: var(--mono); font-size: 12px; color: var(--amber); font-weight: 600; flex-shrink: 0; }
.act-action { color: var(--muted); font-weight: 400; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.spinner {
  width: 15px; height: 15px;
  flex-shrink: 0;
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 8%, var(--amber));
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2.5px), #000 calc(100% - 2px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 2.5px), #000 calc(100% - 2px));
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 1.6s; } }

.proc-live { margin-top: 10px; }
.act-log {
  margin-top: 10px;
  padding-left: 14px;
  border-left: 2px solid var(--line-strong);
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.act-step { font-size: 13px; line-height: 1.5; color: var(--text); position: relative; }
.act-step::before {
  content: "";
  position: absolute;
  left: -19px; top: 8px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--line-strong);
}
.act-think { color: var(--muted); font-style: italic; }
.act-think::before { background: var(--faint); }
.act-say { color: var(--text); }
.act-doc { color: var(--link); }
.act-doc::before { background: var(--link); }
.act-sql { color: var(--muted); }
.act-sql::before { background: var(--link); }
.act-sql code {
  font-family: var(--mono);
  font-size: 12px;
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.5px 5px;
  color: var(--text);
}
.act-st { font-family: var(--mono); font-size: 11.5px; color: var(--ok); }
.act-st.act-err { color: var(--err); }

.act-live-text {
  margin-top: 12px;
  font-size: 15px;
  line-height: 1.65;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}
.act-live-text::after {
  content: "▍";
  color: var(--amber);
  animation: blink 1.1s step-end infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* === ARTIFACTS (piezas HTML interactivas del agente) === */

.artifact-panel {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.artifact-frame {
  display: block;
  width: 100%;
  height: 460px;
  border: none;
  background: #0a1730; /* el artifact trae tema oscuro propio */
}

.artifact-full {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
.artifact-full-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 18px;
  background: var(--band);
}
.artifact-full-frame {
  flex: 1;
  width: 100%;
  border: none;
  background: #0a1730;
}

/* === CHARTS === */

.chart-wrapper {
  margin: 14px 0;
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 14px;
  height: 320px;
  background: var(--surface);
}
.chart-host { width: 100%; height: 100%; }

/* ============================================================
   COMPOSER
   ============================================================ */

.composer { flex-shrink: 0; padding: 12px 24px 20px; }
.composer-inner { max-width: var(--maxw); margin: 0 auto; }
.composer.dragover #form { border-color: var(--link); box-shadow: 0 0 0 3px color-mix(in srgb, var(--link) 20%, transparent); }

.attach-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  padding: 5px 6px 5px 9px;
  font-size: 12.5px;
  max-width: 240px;
}
.chip-thumb { width: 22px; height: 22px; border-radius: 3px; object-fit: cover; flex-shrink: 0; }
.chip-icon {
  width: 22px; height: 22px; border-radius: 3px; flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--active); color: var(--link);
  font-size: 9px; font-weight: 650; text-transform: uppercase;
  font-family: var(--mono);
}
.chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-x { border: none; background: none; cursor: pointer; color: var(--faint); font-size: 16px; line-height: 1; padding: 0 2px; flex-shrink: 0; }
.chip-x:hover { color: var(--err); }

#form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: 26px;
  padding: 8px;
  box-shadow: var(--shadow-sm);
}
:root[data-theme="light"] #form { background: var(--surface); }
#form:focus-within { border-color: var(--link); }

.round-btn {
  flex-shrink: 0;
  border: none; background: none; cursor: pointer;
  color: var(--muted);
  width: 40px; height: 40px;
  border-radius: 50%;
  display: grid; place-items: center;
}
.round-btn:hover { color: var(--ink); }
#attach-btn[aria-expanded="true"] { background: var(--active); color: var(--link); }
.round-btn--send {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--send-glow);
}
.round-btn--send:hover { color: #fff; filter: brightness(1.08); }
.round-btn--send:disabled { opacity: 0.5; cursor: default; box-shadow: none; }
.round-btn--stop { background: var(--err); box-shadow: none; }

#input {
  flex: 1;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: none;
  border: none;
  resize: none;
  padding: 9px 2px;
  max-height: 180px;
  min-height: 22px;
}
#input:focus { outline: none; }
#input::placeholder { color: var(--faint); }

.composer-hint { margin: 9px 0 0; font-size: 11.5px; color: var(--faint); text-align: center; }

/* ============================================================
   INICIO VACÍO — saludo centrado con el composer al medio
   ============================================================ */

/* Con la clase is-empty el chat deja de estirarse y los márgenes automáticos
   centran el bloque saludo+composer en el alto libre, como en el diseño. */
.main.is-empty .chat { flex: 0 0 auto; margin-top: auto; padding-bottom: 0; }
.main.is-empty .composer { margin-bottom: auto; padding-top: 0; }
.main.is-empty .composer-inner { max-width: 500px; }
.main.is-empty .composer-hint { display: none; }

.hero { display: flex; flex-direction: column; align-items: center; text-align: center; }
.hero-logo { height: 34px; width: auto; filter: var(--logo-filter); margin-bottom: 22px; }
.hero-title { margin: 0 0 8px; font-family: var(--display); font-weight: 700; font-size: 27px; color: var(--ink); }
:root[data-theme="light"] .hero-title { color: #06204c; }
.hero-sub { margin: 0 0 26px; font-size: 15px; color: var(--muted); }

/* ============================================================
   MENÚS CONTEXTUALES (conversación, respuesta, adjuntar)
   ============================================================ */

.ctx-menu {
  position: absolute;
  min-width: 194px;
  background: var(--menu-bg);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 70;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.ctx-menu--fixed { position: fixed; }
.ctx-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink);
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
}
.ctx-item svg { flex-shrink: 0; color: var(--muted); }
.ctx-item:hover { background: color-mix(in srgb, var(--ink) 8%, transparent); }
.ctx-item--danger, .ctx-item--danger svg { color: var(--err); }
.ctx-sep { height: 1px; background: var(--line); margin: 5px 8px; }

/* el del "+" del composer se ancla justo encima del pill, como el diseño */
#form { position: relative; }
.attach-menu { bottom: calc(100% + 8px); left: 0; width: 210px; }

/* === ACCIONES DE UNA RESPUESTA (copiar / regenerar / más) === */

.ans-actions {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: color-mix(in srgb, var(--ink) 5%, transparent);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 3px;
  margin-top: 12px;
}
.ans-btn {
  border: none;
  background: none;
  cursor: pointer;
  color: var(--muted);
  width: 30px; height: 30px;
  border-radius: 7px;
  display: grid; place-items: center;
}
.ans-btn:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 7%, transparent); }
.ans-btn.open { color: var(--link); background: var(--active); }

/* ============================================================
   GRÁFICO DENTRO DEL PANEL — la tabla se convierte en gráfico
   ============================================================ */

/* selector Barras / Línea / Torta en la banda, como el diseño */
.rp-tabs {
  display: inline-flex;
  background: var(--seg-bg);
  border-radius: 999px;
  padding: 3px;
}
.rp-tab {
  font-family: var(--display);
  font-size: 12px;
  font-weight: 600;
  color: var(--band-ink);
  background: none;
  border: none;
  border-radius: 999px;
  padding: 5px 12px;
  cursor: pointer;
}
.rp-tab.active { color: #06204c; background: #fff; }

.rp-chart-body { padding: 20px 20px 14px; }

/* barras horizontales con degradado (vista Barras) */
.gbar { display: flex; flex-direction: column; gap: 13px; }
.gbar-row { display: flex; align-items: center; gap: 12px; }
.gbar-label {
  width: 132px;
  flex-shrink: 0;
  text-align: right;
  font-size: 12.5px;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gbar-track { flex: 1; height: 22px; background: var(--bar-track); border-radius: 6px; }
.gbar-fill { height: 100%; background: var(--bar-grad); border-radius: 6px; min-width: 3px; }
.gbar-value {
  width: 92px;
  flex-shrink: 0;
  text-align: right;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

/* torta monocromática azul con total al centro y leyenda (vista Torta) */
.gpie { display: flex; align-items: center; gap: 28px; flex-wrap: wrap; }
.gpie-donut { position: relative; width: 180px; height: 180px; flex-shrink: 0; }
.gpie-donut svg { width: 100%; height: 100%; display: block; }
.gpie-center {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-family: var(--display);
  font-weight: 700;
  font-size: 17px;
  color: var(--ink);
  pointer-events: none;
}
.gpie-legend { flex: 1; min-width: 220px; display: flex; flex-direction: column; gap: 9px; }
.gpie-item { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text); }
.gpie-swatch { width: 11px; height: 11px; border-radius: 3px; flex-shrink: 0; }
.gpie-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gpie-pct { font-variant-numeric: tabular-nums; color: var(--link); font-weight: 600; font-size: 12.5px; }

/* la vista Línea reutiliza el lienzo de ECharts, sin marco propio */
.gline { height: 260px; }
.gline .chart-wrapper { margin: 0; border: none; box-shadow: none; padding: 0; height: 100%; background: none; }

/* ============================================================
   LOGIN
   ============================================================ */

.login-screen {
  position: fixed; inset: 0;
  background: var(--login-bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.login-card {
  width: min(340px, 90vw);
  background: var(--login-card);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  box-shadow: var(--login-shadow);
  padding: 30px;
  display: flex; flex-direction: column;
}
.login-logo { height: 30px; width: auto; align-self: center; filter: var(--logo-filter); margin-bottom: 18px; }
.login-card h2 { margin: 0 0 4px; text-align: center; font-family: var(--display); font-size: 20px; font-weight: 700; color: var(--ink); }
.login-sub { margin: 0 0 22px; text-align: center; font-size: 12.5px; color: var(--muted); }
.login-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.login-field {
  display: flex;
  align-items: center;
  gap: 8px;
  background: color-mix(in srgb, var(--ink) 5%, transparent);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 14px;
}
:root[data-theme="light"] .login-field { background: #f4f6f9; border-color: #e6e9ef; }
.login-field svg { flex-shrink: 0; color: var(--muted); }
.login-field input {
  flex: 1;
  min-width: 0;
  font-family: var(--sans);
  font-size: 13.5px;
  color: var(--ink);
  background: none;
  border: none;
  padding: 0;
}
.login-field input:focus { outline: none; }
.login-field:focus-within { border-color: var(--link); }
.login-foot { margin: 16px 0 0; text-align: center; font-size: 11px; color: var(--faint); }
.login-error { margin: 0 0 10px; font-size: 12.5px; color: var(--err); }

.send-btn {
  font-family: var(--display);
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: var(--primary);
  border: none;
  border-radius: var(--r-sm);
  padding: 10px 18px;
  cursor: pointer;
  transition: filter 0.12s;
}
.send-btn:hover { filter: brightness(1.08); }
.login-btn { width: 100%; margin-top: 2px; border-radius: 10px; padding: 11px; font-size: 14.5px; box-shadow: var(--send-glow); }

/* micrófono dictando: rojo con pulso suave */
.round-btn--rec { color: var(--err); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

/* ============================================================
   PANEL DE USUARIOS (admin)
   ============================================================ */

.modal-back {
  position: fixed; inset: 0;
  background: rgba(6, 12, 28, 0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 60; padding: 20px;
}
.modal {
  width: min(680px, 100%);
  max-height: 85vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 4px solid var(--primary);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 18px 20px 20px;
  color: var(--ink);
}
.modal-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.modal-head-text { flex: 1; }
.modal-head h3 { margin: 0; font-family: var(--display); font-size: 17px; font-weight: 700; }
.modal-sub { margin: 2px 0 0; font-size: 12.5px; color: var(--faint); }
.modal-x { font-size: 22px; color: var(--faint); background: none; border: none; cursor: pointer; }
.modal-x:hover { color: var(--err); }

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--display);
  font-weight: 600;
  font-size: 13px;
  color: #fff;
  background: var(--primary);
  border: none;
  border-radius: 10px;
  padding: 9px 15px;
  cursor: pointer;
  transition: filter 0.12s;
}
.btn-primary:hover { filter: brightness(1.08); }

/* grid de usuarios, como el mock: avatar+nombre / usuario / rol / modelos / estado / ⋯ */
.users-grid { border: 1px solid var(--line); border-radius: 12px; overflow: visible; }
.u-row {
  display: grid;
  grid-template-columns: 1.5fr 1fr 0.8fr 1.6fr 0.9fr 36px;
  gap: 10px;
  padding: 12px 16px;
  align-items: center;
  border-top: 1px solid var(--line-2);
  font-size: 13px;
  color: var(--text);
}
.u-row--head {
  border-top: none;
  padding: 11px 16px;
  background: color-mix(in srgb, var(--ink) 3%, transparent);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--faint);
  border-radius: 12px 12px 0 0;
}
.u-row--off > *:not(.u-cell-menu) { opacity: 0.45; }
.u-who { display: flex; align-items: center; gap: 9px; min-width: 0; }
.u-who-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.u-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--avatar-bg);
  color: var(--sidebar-avatar-ink);
  display: grid; place-items: center;
  flex-shrink: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 11px;
}
.u-login { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.u-pill {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-2);
  background: color-mix(in srgb, var(--ink) 7%, transparent);
  border-radius: 999px;
  padding: 3px 9px;
}
.u-pill--admin { color: var(--link); background: var(--active); }
.u-estado { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--ok); }
.u-estado::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); }
.u-estado--off { color: var(--faint); }
.u-estado--off::before { background: var(--faint); }
.u-cell-menu { position: relative; text-align: center; }
.u-menu-btn {
  border: none; background: none; cursor: pointer;
  color: var(--faint);
  width: 28px; height: 28px;
  border-radius: 7px;
  display: inline-grid; place-items: center;
  font-size: 16px;
  line-height: 1;
}
.u-menu-btn:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 7%, transparent); }
.u-cell-menu .ctx-menu { right: 0; top: calc(100% + 4px); }
.users-all-models { color: var(--faint); font-style: italic; font-size: 12px; }

.model-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.users-table .model-chips { margin-top: 0; }
.model-chip {
  font-family: var(--display);
  font-size: 11.5px; font-weight: 550;
  color: var(--faint);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 9px;
  cursor: pointer;
}
.model-chip:hover { color: var(--ink); border-color: var(--link); }
.model-chip.active { color: var(--band-ink); background: var(--primary); border-color: var(--primary); }

.user-new {
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--ink) 3%, transparent);
}
.user-new-row { display: flex; flex-wrap: wrap; gap: 6px; }
.user-new-row input, .user-new-row select {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  padding: 6px 9px;
  background: var(--surface-2);
}
.user-new-row input { flex: 1; min-width: 110px; }
.user-new-row input:focus, .user-new-row select:focus { outline: none; border-color: var(--link); }

/* foco visible en toda la app */
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }

/* ============================================================
   RESPONSIVE
   ============================================================ */

/* La barra de direcciones móvil come parte del 100vh; dvh sigue al viewport real. */
@supports (height: 100dvh) {
  .app { height: 100dvh; }
}

.sb-backdrop { display: none; }

@media (max-width: 720px) {
  /* Drawer off-canvas: la barra lateral flota sobre el contenido con telón;
     tocar el telón o elegir una consulta la cierra (JS). */
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: min(300px, 85vw);
    box-shadow: 0 0 60px rgba(0, 0, 0, 0.5);
  }
  .app:not(.sidebar-collapsed) .sidebar { display: flex; }
  .app:not(.sidebar-collapsed) .sb-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 39;
    background: rgba(4, 10, 24, 0.55);
  }

  /* el pie respeta el home indicator del iPhone */
  .composer { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
}

@media (max-width: 600px) {
  .chat { padding: 20px 14px; }
  .composer { padding-left: 12px; padding-right: 12px; }
  .topbar { padding: 10px 12px; }
  .composer-hint { display: none; }

  /* iOS hace zoom al enfocar inputs con letra < 16px */
  #input, .sb-search input, .login-field input, .rp-search { font-size: 16px; }

  .hero-title { font-size: 23px; }
  .hero-logo { height: 28px; }
  .msg { gap: 10px; }
  .avatar { width: 28px; height: 28px; font-size: 12px; }
  .msg--user .msg-body { max-width: 88%; }
  .artifact-frame { height: 380px; }

  /* la banda del panel respira en pantallas angostas */
  .rp-head { padding: 10px 12px; }
  .rp-search { width: 100px; }
  .rp-search:focus { width: 130px; }
}
