:root {
  color-scheme: light;
  --page: #eef3f5;
  --surface: #f6f9fa;
  --surface-raised: #ffffff;
  --surface-sunken: #e7edf0;
  --text-primary: #0b1520;
  --text-secondary: #46586a;
  --text-muted: #7c8fa0;
  --border: rgba(11, 21, 32, 0.11);
  --border-strong: rgba(11, 21, 32, 0.20);
  --gridline: #dde4e8;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-wash: rgba(42, 120, 214, 0.10);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --status-good: #0ca30c;
  --status-good-wash: rgba(12, 163, 12, 0.12);
  --status-warning: #b8790a;
  --status-warning-wash: rgba(250, 178, 25, 0.18);
  --status-serious: #c2572f;
  --status-serious-wash: rgba(236, 131, 90, 0.18);
  --status-critical: #d03b3b;
  --status-critical-wash: rgba(208, 59, 59, 0.14);
  --shadow-card: 0 1px 2px rgba(11, 21, 32, 0.06), 0 8px 24px -12px rgba(11, 21, 32, 0.18);
  --shadow-modal: 0 24px 64px -16px rgba(6, 12, 20, 0.45);
  --radio: 14px;
  --radio-sm: 9px;
  --sidebar-w: 250px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0a121a;
    --surface: #0f1a24;
    --surface-raised: #142330;
    --surface-sunken: #0a1219;
    --text-primary: #f3f7f9;
    --text-secondary: #aebdca;
    --text-muted: #7690a2;
    --border: rgba(255, 255, 255, 0.09);
    --border-strong: rgba(255, 255, 255, 0.18);
    --gridline: #24333f;
    --accent: #3987e5;
    --accent-ink: #061019;
    --accent-wash: rgba(57, 135, 229, 0.16);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --status-good: #33c733;
    --status-good-wash: rgba(51, 199, 51, 0.14);
    --status-warning: #fab219;
    --status-warning-wash: rgba(250, 178, 25, 0.16);
    --status-serious: #ec835a;
    --status-serious-wash: rgba(236, 131, 90, 0.16);
    --status-critical: #e66767;
    --status-critical-wash: rgba(230, 103, 103, 0.16);
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.5);
    --shadow-modal: 0 24px 64px -16px rgba(0, 0, 0, 0.6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0a121a;
  --surface: #0f1a24;
  --surface-raised: #142330;
  --surface-sunken: #0a1219;
  --text-primary: #f3f7f9;
  --text-secondary: #aebdca;
  --text-muted: #7690a2;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.18);
  --gridline: #24333f;
  --accent: #3987e5;
  --accent-ink: #061019;
  --accent-wash: rgba(57, 135, 229, 0.16);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --status-good: #33c733;
  --status-good-wash: rgba(51, 199, 51, 0.14);
  --status-warning: #fab219;
  --status-warning-wash: rgba(250, 178, 25, 0.16);
  --status-serious: #ec835a;
  --status-serious-wash: rgba(236, 131, 90, 0.16);
  --status-critical: #e66767;
  --status-critical-wash: rgba(230, 103, 103, 0.16);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.5);
  --shadow-modal: 0 24px 64px -16px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--page);
  color: var(--text-primary);
  font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
.mono { font-family: "IBM Plex Mono", ui-monospace, monospace; }

.layout { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.marca { display: flex; align-items: center; gap: 10px; padding: 4px 10px 24px 10px; }
.marca-texto {
  font-family: "Big Shoulders Display", "IBM Plex Sans", sans-serif;
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: 0.01em;
  line-height: 1.15;
}
.marca-icono {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--series-3));
  color: var(--accent-ink); font-size: 1rem; flex: none;
  box-shadow: 0 4px 14px -4px rgba(57, 135, 229, 0.5);
}
.nav-item {
  width: 100%; display: flex; align-items: center; gap: 10px;
  background: transparent; border: none; border-left: 2px solid transparent;
  color: var(--text-primary); padding: 9px 12px; border-radius: 8px;
  font-size: 0.88rem; cursor: pointer; text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-item:hover { background: var(--surface-sunken); }
.nav-item.activo {
  background: var(--accent-wash); border-left-color: var(--accent);
  color: var(--accent); font-weight: 600;
}
.nav-icono { opacity: 0.85; }
.sidebar-footer { margin-top: auto; padding: 12px 6px 4px 6px; border-top: 1px solid var(--border); }
.updated-pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: "IBM Plex Mono", monospace; font-size: 11px;
  color: var(--text-secondary); background: var(--surface-raised);
  border: 1px solid var(--border); border-radius: 100px; padding: 6px 12px;
}
.live-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--status-good); box-shadow: 0 0 0 3px var(--status-good-wash); }

/* ---------- Contenido ---------- */
.contenido { flex: 1; padding: 26px 30px 60px 30px; max-width: 1280px; width: 100%; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 22px; padding-bottom: 16px; border-bottom: 1px solid var(--border);
}
.topbar h1 {
  font-family: "Big Shoulders Display", sans-serif;
  font-size: 1.9rem; font-weight: 700; margin: 0; letter-spacing: 0.01em; line-height: 1;
}
.topbar-nota { font-size: 0.78rem; color: var(--text-muted); font-family: "IBM Plex Mono", monospace; }

.section-label {
  display: flex; align-items: center; gap: 10px; margin: 30px 0 14px;
  font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted);
}
.section-label::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ---------- Summary strip ---------- */
.summary-strip {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1px; background: var(--border); border: 1px solid var(--border);
  border-radius: var(--radio); overflow: hidden; box-shadow: var(--shadow-card);
}
.stat-tile { position: relative; background: var(--surface-raised); padding: 16px 18px; display: flex; flex-direction: column; gap: 2px; }
.stat-tile-icono { position: absolute; top: 14px; right: 16px; font-size: 1.1rem; opacity: 0.85; }
.stat-label { font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); font-weight: 600; }
.stat-value { font-family: "Big Shoulders Display", sans-serif; font-weight: 700; font-size: 28px; line-height: 1.15; margin-top: 2px; }
.stat-tile.stat-good .stat-value { color: var(--status-good); }
.stat-tile.stat-crit .stat-value { color: var(--status-critical); }

/* ---------- Comparación por unidad ---------- */
.unidad-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
.unidad-card {
  background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radio);
  padding: 18px 20px; box-shadow: var(--shadow-card);
}
.unidad-card.consolidado { border-color: var(--accent); background: linear-gradient(180deg, var(--accent-wash), var(--surface-raised) 60%); }
.unidad-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.unidad-card-head h4 { margin: 0; font-size: 1rem; font-weight: 700; }
.unidad-card-pct { font-family: "IBM Plex Mono", monospace; font-size: 0.78rem; color: var(--text-muted); }
.unidad-metricas { display: flex; flex-direction: column; gap: 8px; }
.unidad-metrica { display: flex; justify-content: space-between; align-items: baseline; font-size: 0.86rem; }
.unidad-metrica .u-etiqueta { color: var(--text-muted); }
.unidad-metrica .u-valor { font-family: "IBM Plex Mono", monospace; font-weight: 500; }
.unidad-metrica.destacada { margin-top: 4px; padding-top: 10px; border-top: 1px dashed var(--border); }
.unidad-metrica.destacada .u-etiqueta { font-weight: 600; color: var(--text-secondary); }
.unidad-metrica.destacada .u-valor { font-size: 1.05rem; font-weight: 700; }

/* ---------- Gráficos ---------- */
.graficos-resumen { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; }
.chart-block { background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radio); padding: 16px 18px 12px; box-shadow: var(--shadow-card); }
.chart-block-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.chart-title { font-size: 12.5px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; }
.grafico-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radio-sm); padding: 16px; height: 280px; }
.grafico-wrap-resumen { height: 230px; padding: 0; background: transparent; border: none; }

/* ---------- Tablas genéricas ---------- */
.tabla-wrap { overflow-x: auto; background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radio); box-shadow: var(--shadow-card); }
table.tabla-datos { width: 100%; border-collapse: collapse; font-size: 0.82rem; white-space: nowrap; }
table.tabla-datos th {
  text-align: right; font-weight: 600; color: var(--text-muted); font-size: 0.68rem;
  text-transform: uppercase; letter-spacing: 0.03em; padding: 10px 12px;
  border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface-raised);
}
table.tabla-datos th:first-child, table.tabla-datos td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface-raised); }
table.tabla-datos td { text-align: right; padding: 9px 12px; font-family: "IBM Plex Mono", monospace; color: var(--text-primary); border-bottom: 1px solid var(--border); }
table.tabla-datos tbody tr:hover td { background: var(--surface-sunken); }
table.tabla-datos tr.fila-total td { font-weight: 700; background: var(--surface-sunken); }
table.tabla-datos tr.fila-sub td:first-child { padding-left: 26px; color: var(--text-secondary); font-weight: 400; }
table.tabla-datos th.th-ordenable { cursor: pointer; user-select: none; white-space: nowrap; }
table.tabla-datos th.th-ordenable:hover { color: var(--text-primary); }
table.tabla-datos td.left { text-align: left; }
.nombre-empleado.activo { color: var(--status-good); }
.nombre-empleado.baja { color: var(--status-critical); }
.badge-baja {
  display: inline-block; font-size: 0.66rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--status-critical); background: var(--status-critical-wash); border-radius: 100px; padding: 2px 8px; margin-left: 6px;
}
td.valor-positivo { color: var(--status-good); }
td.valor-negativo { color: var(--status-critical); }
.estado-chip { display: inline-flex; white-space: nowrap; }

/* ---------- Status chip / semáforo ---------- */
.status-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600; padding: 4px 10px; border-radius: 100px; width: fit-content; }
.status-chip .dot { width: 6px; height: 6px; border-radius: 50%; }
.status-chip.critical { background: var(--status-critical-wash); color: var(--status-critical); }
.status-chip.critical .dot { background: var(--status-critical); }
.status-chip.good { background: var(--status-good-wash); color: var(--status-good); }
.status-chip.good .dot { background: var(--status-good); }
.status-chip.neutral { background: var(--surface-sunken); color: var(--text-muted); }
.status-chip.neutral .dot { background: var(--text-muted); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; border-bottom: 1px solid var(--border); padding-bottom: 12px; }
.tab-btn {
  background: var(--surface-raised); border: 1px solid var(--border); color: var(--text-secondary);
  padding: 8px 15px; border-radius: 999px; font-size: 0.85rem; font-weight: 500; cursor: pointer;
  transition: all 0.15s ease;
}
.tab-btn:hover { color: var(--text-primary); border-color: var(--border-strong); }
.tab-btn.activo { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; box-shadow: 0 4px 14px -4px rgba(57, 135, 229, 0.5); }

.nota-fuente {
  margin-top: 14px; font-size: 0.78rem; color: var(--text-muted); font-style: italic; line-height: 1.5;
}

.sin-alertas { color: var(--text-muted); font-style: italic; padding: 16px 2px; font-size: 0.88rem; }

/* ---------- Diagnóstico / hallazgos ---------- */
.btn-analizar {
  background: var(--accent); color: var(--accent-ink); border: none; border-radius: 10px;
  padding: 11px 22px; font-size: 0.9rem; font-weight: 700; cursor: pointer;
  transition: filter 0.15s ease; box-shadow: 0 4px 14px -4px rgba(57, 135, 229, 0.5);
}
.btn-analizar:hover { filter: brightness(1.08); }
.btn-analizar:disabled { opacity: 0.6; cursor: default; }
.btn-analizar-sm { padding: 8px 16px; font-size: 0.82rem; }
.analisis-seccion { display: flex; justify-content: flex-end; margin-bottom: 14px; }

/* ---------- Filtros (Nómina, etc.) ---------- */
.filtros-fila { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.filtros-fila select {
  background: var(--surface-raised); border: 1px solid var(--border); color: var(--text-primary);
  border-radius: 8px; padding: 8px 12px; font-size: 0.85rem; font-family: inherit; cursor: pointer;
}
.filtros-fila select:focus { outline: none; border-color: var(--accent); }

/* ---------- Filas clickeables con detalle expandible ---------- */
tr.fila-clickeable { cursor: pointer; }
tr.fila-clickeable:hover td { background: var(--surface-sunken); }
td.celda-chevron { width: 20px; text-align: center !important; color: var(--text-muted); }
tr.fila-detalle td { padding: 10px 12px 16px 32px; background: var(--surface); }
table.tabla-anidada { width: 100%; border-collapse: collapse; font-size: 0.76rem; }
table.tabla-anidada th {
  text-align: right; font-weight: 600; color: var(--text-muted); font-size: 0.66rem;
  text-transform: uppercase; padding: 6px 10px; border-bottom: 1px solid var(--border);
}
table.tabla-anidada th:first-child, table.tabla-anidada td:first-child { text-align: left; }
table.tabla-anidada td { text-align: right; padding: 6px 10px; font-family: "IBM Plex Mono", monospace; border-bottom: 1px solid var(--border); }
table.tabla-anidada th.th-ordenable { cursor: pointer; user-select: none; white-space: nowrap; }
table.tabla-anidada th.th-ordenable:hover { color: var(--text-primary); }

.hallazgos-lista { display: flex; flex-direction: column; gap: 10px; }
.hallazgo-card {
  background: var(--surface-raised); border: 1px solid var(--border); border-left: 3px solid var(--border);
  border-radius: var(--radio-sm); padding: 13px 16px; box-shadow: var(--shadow-card);
}
.hallazgo-card.severidad-alta { border-left-color: var(--status-critical); }
.hallazgo-card.severidad-media { border-left-color: var(--status-warning); }
.hallazgo-card.severidad-baja { border-left-color: var(--text-muted); }
.hallazgo-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.hallazgo-texto { font-size: 0.9rem; line-height: 1.5; color: var(--text-primary); }

.diagnostico-card {
  background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radio);
  padding: 20px 22px; box-shadow: var(--shadow-card); margin-bottom: 14px;
}
.diagnostico-fecha { font-family: "IBM Plex Mono", monospace; font-size: 0.74rem; color: var(--text-muted); margin-bottom: 10px; }
.diagnostico-texto { font-size: 0.95rem; line-height: 1.55; color: var(--text-primary); }
.diagnostico-anomalias { margin: 14px 0 0 0; padding-left: 20px; }
.diagnostico-anomalias li { color: var(--status-critical); font-size: 0.87rem; margin-bottom: 6px; line-height: 1.45; }
.diagnostico-recomendacion {
  margin-top: 14px; padding: 13px 15px; background: var(--accent-wash); border-left: 3px solid var(--accent);
  border-radius: var(--radio-sm); font-size: 0.9rem; line-height: 1.5;
}

/* ---------- Chat ---------- */
.chat-panel {
  display: flex; flex-direction: column; height: calc(100vh - 190px); max-height: 640px;
  background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radio);
  box-shadow: var(--shadow-card); overflow: hidden;
}
.chat-mensajes { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.chat-mensaje { display: flex; }
.chat-mensaje.chat-assistant { justify-content: flex-start; }
.chat-mensaje.chat-user { justify-content: flex-end; }
.chat-burbuja { max-width: 76%; padding: 11px 15px; border-radius: 14px; font-size: 0.92rem; line-height: 1.5; white-space: pre-wrap; }
.chat-assistant .chat-burbuja { background: var(--surface-sunken); color: var(--text-primary); border-bottom-left-radius: 4px; }
.chat-user .chat-burbuja { background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.chat-dots { display: inline-flex; gap: 4px; align-items: center; padding: 2px 4px; }
.chat-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted); animation: chatDot 1.1s ease-in-out infinite; }
.chat-dots span:nth-child(2) { animation-delay: 0.15s; }
.chat-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chatDot { 0%, 60%, 100% { opacity: 0.35; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
.chat-input-row { display: flex; gap: 10px; padding: 14px 16px; border-top: 1px solid var(--border); background: var(--surface); }
/* selector por CLASE, no por id — así todas las instancias de chat (hoy
   solo la global, pero cualquier otra que se agregue después) se ven
   iguales sin tener que repetir estilos por cada id nuevo */
.chat-input-row input[type="text"] {
  flex: 1; min-width: 0; background: var(--surface-raised); border: 1px solid var(--border);
  color: var(--text-primary); border-radius: 10px; padding: 12px 15px; font-size: 0.95rem; font-family: inherit;
}
.chat-input-row input[type="text"]:focus { outline: none; border-color: var(--accent); }
.chat-input-row input[type="text"]:disabled { opacity: 0.6; }
.chat-input-row button[type="submit"] {
  background: var(--accent); color: var(--accent-ink); border: none; border-radius: 10px;
  padding: 10px 24px; font-size: 0.9rem; font-weight: 700; cursor: pointer; transition: filter 0.15s ease; flex: none;
}
.chat-input-row button[type="submit"]:hover { filter: brightness(1.08); }
.chat-input-row button[type="submit"]:disabled { opacity: 0.6; cursor: default; }

/* ---------- Chat global (fijo arriba de cada pestaña) ---------- */
.chat-global {
  background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radio);
  box-shadow: var(--shadow-card); margin-bottom: 22px; overflow: hidden;
}
.chat-global-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); cursor: pointer;
}
.chat-global-titulo { font-size: 0.84rem; font-weight: 700; color: var(--text-secondary); }
.chat-global-toggle {
  background: transparent; border: none; color: var(--text-muted); font-size: 0.9rem; cursor: pointer;
  padding: 2px 6px; transition: transform 0.15s ease;
}
.chat-panel-global { height: 260px; border: none; border-radius: 0; box-shadow: none; }
.chat-global.colapsado .chat-panel-global { display: none; }
.chat-global.colapsado .chat-global-toggle { transform: rotate(-90deg); }

/* ---------- Menú hamburguesa (mobile) ---------- */
.btn-menu {
  display: none; position: fixed; top: 12px; left: 12px; z-index: 40;
  background: var(--surface-raised); border: 1px solid var(--border); color: var(--text-primary);
  width: 40px; height: 40px; border-radius: 8px; font-size: 1.1rem; box-shadow: var(--shadow-card);
}
.overlay { display: none; position: fixed; inset: 0; background: rgba(4, 9, 14, 0.55); backdrop-filter: blur(2px); z-index: 20; }

@media (max-width: 860px) {
  .btn-menu { display: block; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 30; transform: translateX(-105%); transition: transform 0.2s ease; box-shadow: var(--shadow-modal); }
  .sidebar.abierto { transform: translateX(0); }
  .overlay.visible { display: block; }
  .contenido { padding: 64px 16px 40px 16px; }
  .topbar h1 { font-size: 1.4rem; }
  .stat-value { font-size: 22px; }
  .grafico-wrap { height: 220px; }
  .grafico-wrap-resumen { height: 200px; }
  .graficos-resumen { grid-template-columns: 1fr; }
}
