/* Paleta categórica validada (modo claro y oscuro). Los colores de texto nunca usan el color de serie. */
:root {
  color-scheme: light;
  --bg: #f4f4f1; --surface: #fcfcfb; --surface-2: #f0efec;
  --text: #0b0b0b; --text-2: #52514e; --muted: #77766f;
  --line: #e1e0da; --grid: #ecebe6;
  --accent: #256abf; --accent-soft: #cde2fb;
  --neg: #b3261e; --pos: #006300; --warn-bg: #fff4d6; --warn-line: #e8b93b; --warn-text: #5c4300;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #94938a;
    --line: #34332f; --grid: #2a2a27;
    --accent: #6da7ec; --accent-soft: #184f95;
    --neg: #ff8a80; --pos: #6fd36f; --warn-bg: #3a2f10; --warn-line: #a47a10; --warn-text: #f3d98a;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #0ca30c; --s7: #9085e9; --s8: #e66767;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }

/* ---------- barra superior ---------- */
.top {
  position: sticky; top: 0; z-index: 20; background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.top-in { max-width: 1280px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 18px; min-height: 52px; }
.marca { font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
.nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; min-width: 0; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  color: var(--text-2); text-decoration: none; padding: 14px 12px; white-space: nowrap;
  border-bottom: 2px solid transparent; font-weight: 500;
}
.nav a:hover { color: var(--text); }
.nav a.activa { color: var(--text); border-bottom-color: var(--s1); }
.salir { background: none; border: 1px solid var(--line); color: var(--text-2); border-radius: 8px; padding: 6px 10px; cursor: pointer; font: inherit; font-size: 13px; }
.salir:hover { color: var(--text); border-color: var(--muted); }

/* ---------- contenido ---------- */
main { max-width: 1280px; margin: 0 auto; padding: 20px 16px 60px; }
h1 { font-size: 22px; margin: 4px 0 2px; }
.sub { color: var(--text-2); margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 10px; }
.card, .kpi, .filtros { min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.card h2 small { font-weight: 400; color: var(--muted); font-size: 13px; margin-left: 6px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr)); gap: 16px; }
.grid2 > .card { margin-bottom: 0; }
.fila { margin-bottom: 16px; }

/* ---------- filtros ---------- */
.filtros {
  display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: end;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; margin-bottom: 16px;
}
.filtros label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); }
.filtros input, .filtros select, .filtros button.msel {
  font: inherit; font-size: 14px; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; min-width: 130px;
}
.filtros input[type=search] { min-width: 220px; max-width: 100%; }
.atajos { display: flex; gap: 6px; flex-wrap: wrap; }
.atajos button, .btn {
  font: inherit; font-size: 13px; color: var(--text-2); background: var(--surface-2); cursor: pointer;
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px;
}
.atajos button:hover, .btn:hover { color: var(--text); border-color: var(--muted); }
.atajos button.on { background: var(--accent-soft); color: var(--text); border-color: var(--accent); }
.btn.primario { background: var(--accent); color: #fff; border-color: var(--accent); }
@media (prefers-color-scheme: dark) { :root:where(:not([data-theme="light"])) .btn.primario { color: #0b0b0b; } }
.chk { flex-direction: row !important; align-items: center; gap: 8px !important; font-size: 13px !important; }
.chk input { min-width: 0 !important; }

/* selector múltiple */
.msel-wrap { position: relative; }
.msel { text-align: left; cursor: pointer; }
.msel-panel {
  position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; min-width: 240px; max-height: 300px; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 6px; display: none;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
}
.msel-wrap.abierto .msel-panel { display: block; }
.msel-panel label { flex-direction: row; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 6px; font-size: 14px; color: var(--text); cursor: pointer; }
.msel-panel label:hover { background: var(--surface-2); }
.msel-panel input { min-width: 0; }

/* ---------- tarjetas de cifras ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; min-width: 0; }
.kpi .t { font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
.kpi .v { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .n { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.neg .v, .neg { color: var(--neg); }

/* ---------- tablas ---------- */
.tabla-wrap { overflow: auto; max-height: 560px; border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--surface-2); color: var(--text-2); font-weight: 600; font-size: 12px; z-index: 1; }
th.ord { cursor: pointer; user-select: none; }
th.ord:hover { color: var(--text); }
td.num, th.num { text-align: right; }
td.txt-largo { white-space: normal; min-width: 220px; max-width: 420px; }
tr:last-child td { border-bottom: 0; }
tr.total td { font-weight: 700; background: var(--surface-2); position: sticky; bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
.barra { display: inline-block; height: 6px; border-radius: 3px; background: var(--s1); vertical-align: middle; margin-left: 8px; min-width: 1px; }

/* ---------- gráficos ---------- */
.grafico { width: 100%; height: 320px; }
.grafico.alto { height: 400px; }
.leyenda-nota { color: var(--muted); font-size: 12px; margin-top: 6px; }

/* ---------- avisos ---------- */
.aviso { background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn-text); border-radius: 12px; padding: 12px 16px; margin-bottom: 16px; font-size: 14px; }
.aviso b { color: inherit; }
.aviso .acciones { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }
.error { background: var(--surface); border: 1px solid var(--neg); color: var(--neg); border-radius: 12px; padding: 12px 16px; margin-bottom: 16px; }
.cargando { color: var(--muted); padding: 24px; text-align: center; }
.vacio { color: var(--muted); padding: 20px; text-align: center; }

/* ---------- inicio ---------- */
.accesos { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin-bottom: 20px; }
.acceso { display: block; text-decoration: none; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.acceso:hover { border-color: var(--s1); }
.acceso b { display: block; font-size: 16px; margin-bottom: 4px; }
.acceso span { color: var(--text-2); font-size: 13.5px; }
.acceso.pronto { opacity: .6; pointer-events: none; }

/* ---------- login ---------- */
.login-box { max-width: 360px; margin: 12vh auto 0; padding: 0 16px; }
.login-box .card { padding: 24px; }
.login-box label { display: block; font-size: 13px; color: var(--text-2); margin: 12px 0 4px; }
.login-box input { width: 100%; font: inherit; font-size: 16px; color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.login-box button { width: 100%; margin-top: 18px; padding: 11px; font-size: 15px; }

@media (max-width: 640px) {
  .grid2 { grid-template-columns: 1fr; }
  .kpi .v { font-size: 19px; }
  .marca { display: none; }
  .grafico { height: 280px; }
}
