/* Paleta y roles de color — ver dataviz skill / references/palette.md */
:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --surface-2: #ffffff;
  --page: #f4f5f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --success-text: #006300;

  --series-1: #2a78d6; /* azul */
  --series-2: #008300; /* verde */
  --series-3: #e87ba4; /* magenta */
  --series-4: #eda100; /* amarillo */
  --series-5: #1baf7a; /* aqua */
  --series-6: #eb6834; /* naranjo */
  --series-7: #4a3aa7; /* violeta */
  --series-8: #e34948; /* rojo */
  --series-other: #898781;

  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;

  --seq-100: #cde2fb;
  --seq-300: #6da7ec;
  --seq-500: #256abf;
  --seq-700: #0d366b;

  --radius: 12px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.06), 0 1px 1px rgba(11, 11, 11, 0.04);
  --shadow-lg: 0 10px 30px rgba(20, 20, 40, 0.10), 0 2px 8px rgba(20, 20, 40, 0.06);

  /* Marca / shell — el sidebar se mantiene oscuro en ambos temas (patrón "dark rail") */
  --brand-1: #171a3d;
  --brand-2: #2c2470;
  --brand-3: #4a3aa7;
  --accent-vivo: #22d3ee;   /* cian vivo — estado activo, focos de atención */
  --accent-vivo-2: #7c5cff; /* violeta vivo — detalles secundarios */
  --sidebar-w: 234px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --surface-2: #202020;
    --page: #101014;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --success-text: #0ca30c;

    --series-1: #3987e5;
    --series-2: #008300;
    --series-3: #d55181;
    --series-4: #c98500;
    --series-5: #199e70;
    --series-6: #d95926;
    --series-7: #9085e9;
    --series-8: #e66767;
    --series-other: #898781;
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.45), 0 2px 8px rgba(0, 0, 0, 0.3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --surface-2: #202020;
  --page: #101014;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --success-text: #0ca30c;

  --series-1: #3987e5;
  --series-2: #008300;
  --series-3: #d55181;
  --series-4: #c98500;
  --series-5: #199e70;
  --series-6: #d95926;
  --series-7: #9085e9;
  --series-8: #e66767;
  --series-other: #898781;
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.45), 0 2px 8px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  height: 100%;
}

/* ---------- estructura general: sidebar + contenido ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex: none;
  background: linear-gradient(165deg, var(--brand-1) 0%, var(--brand-2) 55%, var(--brand-3) 130%);
  color: #fff;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
  z-index: 30;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 20px 18px 16px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--accent-vivo), var(--accent-vivo-2));
  font-size: 17px; flex: none; box-shadow: 0 4px 14px rgba(34, 211, 238, 0.35);
}
.brand-title { font-size: 15.5px; font-weight: 700; letter-spacing: .01em; }
.brand-sub { font-size: 11px; color: rgba(255,255,255,0.62); margin-top: 1px; }

.sidebar-nav { list-style: none; margin: 6px 0 0; padding: 4px 10px; flex: 1; }
.sidebar-nav li { margin-bottom: 3px; }
.sidebar-nav button {
  width: 100%; display: flex; align-items: center; gap: 10px;
  background: none; border: none; border-radius: 9px; cursor: pointer;
  color: rgba(255,255,255,0.72); font-size: 13px; font-weight: 500;
  padding: 9px 11px; text-align: left; transition: background .12s ease, color .12s ease;
  border-left: 3px solid transparent;
}
.sidebar-nav button:hover { background: rgba(255,255,255,0.07); color: #fff; }
.sidebar-nav li.activo button {
  background: rgba(255,255,255,0.12); color: #fff;
  border-left: 3px solid var(--accent-vivo);
}
.sidebar-nav .icono { font-size: 15px; width: 18px; text-align: center; flex: none; }
.sidebar-nav .contador-tab {
  margin-left: auto; font-size: 10.5px; font-variant-numeric: tabular-nums;
  background: rgba(255,255,255,0.14); padding: 1px 6px; border-radius: 999px; color: rgba(255,255,255,0.85);
}

.sidebar-footer { padding: 12px 18px 18px; font-size: 10.5px; color: rgba(255,255,255,0.45); border-top: 1px solid rgba(255,255,255,0.08); }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ---------- barra superior ---------- */
.top-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 16px 26px;
  background: var(--surface-1); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.top-bar h1 { font-size: 19px; margin: 0; font-weight: 700; letter-spacing: -.01em; }
.top-bar .subtitulo { color: var(--text-secondary); font-size: 12.5px; margin-top: 3px; }
.tema-toggle {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-secondary);
  border-radius: 8px; padding: 7px 12px; cursor: pointer; font-size: 12.5px; font-weight: 500;
}
.tema-toggle:hover { color: var(--text-primary); border-color: var(--accent-vivo-2); }

/* ---------- filtros ---------- */
.filtros {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 14px;
  padding: 12px 26px; background: var(--surface-1); border-bottom: 1px solid var(--border);
  position: sticky; top: 61px; z-index: 19;
}
.filtro-campo { display: flex; flex-direction: column; gap: 3px; min-width: 128px; }
.filtro-campo label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }
.filtro-campo select, .filtro-campo input[type="date"] {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-primary);
  border-radius: 7px; padding: 6px 8px; font-size: 13px; min-height: 30px;
}
.filtro-multi { position: relative; }
.filtro-multi-btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-primary);
  border-radius: 7px; padding: 6px 28px 6px 8px; font-size: 13px; min-height: 30px; min-width: 140px;
  text-align: left; cursor: pointer; position: relative;
}
.filtro-multi-btn::after { content: "▾"; position: absolute; right: 8px; top: 6px; color: var(--text-muted); }
.filtro-multi-panel {
  display: none; position: absolute; top: calc(100% + 4px); left: 0; z-index: 30;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow-lg); padding: 8px; min-width: 220px; max-height: 280px; overflow: auto;
}
.filtro-multi.abierto .filtro-multi-panel { display: block; }
.filtro-multi-panel label {
  display: flex; align-items: center; gap: 7px; padding: 4px 6px; border-radius: 5px; font-size: 12.5px; cursor: pointer;
}
.filtro-multi-panel label:hover { background: var(--page); }
.filtro-multi-panel .acciones { display: flex; gap: 8px; padding: 4px 6px 6px; border-bottom: 1px solid var(--gridline); margin-bottom: 4px; }
.filtro-multi-panel .acciones button {
  background: none; border: none; color: var(--series-1); cursor: pointer; font-size: 11.5px; padding: 0;
}

.btn-limpiar {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-secondary);
  border-radius: 7px; padding: 7px 12px; font-size: 12.5px; cursor: pointer; white-space: nowrap; font-weight: 500;
}
.btn-limpiar:hover { color: var(--text-primary); border-color: var(--accent-vivo-2); }
.contador-eventos { font-size: 12.5px; color: var(--text-secondary); white-space: nowrap; margin-left: auto; }
.contador-eventos strong { color: var(--text-primary); font-variant-numeric: tabular-nums; }

/* ---------- KPIs (siempre visibles, con acento de color) ---------- */
.kpi-fila {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px;
  padding: 18px 26px 4px;
}
.kpi-tile {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); border-left: 3px solid var(--acento, var(--series-1));
  transition: transform .12s ease, box-shadow .12s ease;
}
.kpi-tile:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.kpi-tile .label { font-size: 12px; color: var(--text-secondary); font-weight: 500; }
.kpi-tile .valor { font-size: 25px; font-weight: 700; margin-top: 4px; line-height: 1.15; letter-spacing: -.01em; }
.kpi-tile .detalle { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }

/* ---------- contenido / pestañas ---------- */
.tab-content { flex: 1; padding: 18px 26px 60px; max-width: 1400px; width: 100%; margin: 0 auto; }
.tab-panel { display: none; }
.tab-panel.activo { display: block; animation: aparecer .18s ease; }
@keyframes aparecer { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2.una-columna { grid-template-columns: 1fr; }
.grid-1 { display: grid; grid-template-columns: 1fr; gap: 16px; }
/* evita que una tarjeta con contenido ancho (tabla, canvas) fuerce su columna
   por sobre el reparto 1fr/1fr ("grid blowout" — min-width:auto es el default) */
.grid-2 > *, .grid-1 > * { min-width: 0; }
@media (max-width: 980px) { .grid-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 16px;
}
.card-header { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-header h2 { font-size: 15.5px; margin: 0; font-weight: 700; letter-spacing: -.005em; }
.card-header h2::before {
  content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--acento, var(--series-1)); margin-right: 8px;
}
.card-header .card-sub { font-size: 12px; color: var(--text-muted); }
.card-controles { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card-controles select, .card-controles button {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-secondary);
  border-radius: 6px; padding: 5px 10px; font-size: 12px; cursor: pointer; font-weight: 500;
}
.card-controles button.activo { color: #fff; border-color: var(--acento, var(--series-1)); background: var(--acento, var(--series-1)); }
.chart-wrap { position: relative; width: 100%; }
.chart-wrap.alto { height: 360px; }
.chart-wrap.medio { height: 280px; }

.toggle-tabla { font-size: 11.5px; color: var(--series-1); background: none; border: none; cursor: pointer; padding: 0; }

table.tabla-datos { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.tabla-datos.tabla-pivot { width: max-content; min-width: 100%; }
table.tabla-datos.tabla-pivot td, table.tabla-datos.tabla-pivot th { white-space: nowrap; }
table.tabla-datos th, table.tabla-datos td {
  padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
}
table.tabla-datos th {
  color: var(--text-muted); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .03em;
  cursor: pointer; user-select: none; white-space: nowrap;
  background: var(--page); position: sticky; top: 0;
}
table.tabla-datos th:hover { color: var(--text-primary); }
table.tabla-datos th.num, table.tabla-datos td.num { text-align: right; }
table.tabla-datos tbody tr:hover { background: var(--page); }
table.tabla-datos tbody tr.fila-clicable { cursor: pointer; }
table.tabla-datos tbody tr.fila-activa { background: color-mix(in srgb, var(--acento, var(--series-1)) 14%, transparent); }
table.tabla-datos tbody tr.fila-activa:hover { background: color-mix(in srgb, var(--acento, var(--series-1)) 20%, transparent); }
.tabla-scroll { max-height: 420px; overflow: auto; border: 1px solid var(--gridline); border-radius: 10px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 7px; border-radius: 999px;
  font-size: 11px; font-weight: 700; white-space: nowrap;
}
.badge-critical { background: color-mix(in srgb, var(--status-critical) 16%, transparent); color: var(--status-critical); }
.badge-warning { background: color-mix(in srgb, var(--status-warning) 20%, transparent); color: #8a5a00; }
.badge-muted { background: var(--page); color: var(--text-muted); }

.leyenda { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 8px; font-size: 12px; color: var(--text-secondary); }
.leyenda-item { display: flex; align-items: center; gap: 6px; }
.leyenda-marca { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

.paginacion { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: 12px; color: var(--text-secondary); }
.paginacion button {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-primary);
  border-radius: 6px; padding: 4px 10px; cursor: pointer;
}
.paginacion button:disabled { opacity: .4; cursor: default; }

.buscador { border: 1px solid var(--border); background: var(--surface-2); color: var(--text-primary); border-radius: 7px; padding: 7px 11px; font-size: 13px; width: 100%; max-width: 320px; }

.avisos-lista { margin: 0; padding-left: 18px; }
.avisos-lista li { margin-bottom: 6px; color: var(--text-secondary); font-size: 12.5px; }

.fila-detalle { background: var(--page); }
.fila-detalle td { padding: 10px 14px; }
.lineas-detalle { width: 100%; border-collapse: collapse; font-size: 12px; }
.lineas-detalle th, .lineas-detalle td { padding: 4px 8px; border-bottom: 1px solid var(--gridline); text-align: left; }
.lineas-detalle th.num, .lineas-detalle td.num { text-align: right; }

.vacio { color: var(--text-muted); font-size: 12.5px; padding: 20px 0; text-align: center; }

.footer-nota { color: var(--text-muted); font-size: 11.5px; text-align: center; margin-top: 30px; }

@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; transform: translateX(-100%); transition: transform .18s ease; }
  .sidebar.abierta { transform: none; }
  :root { --sidebar-w: 220px; }
}
