:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --text: #1b2430;
  --muted: #5d6877;
  --border: #dde1e8;
  --accent: #2f5fd0;
  --accent-contrast: #ffffff;
  --danger: #b3261e;
  --warn-bg: #fff4d6;
  --warn-text: #5c4200;
  --c1: #2f5fd0;
  --c2: #d9822b;
  --c3: #2c9a7a;
  --c4: #b04a9b;
  --c5: #7a6ad8;
  --line: #c0392b;
  --shadow: 0 1px 2px rgba(20, 30, 50, 0.06), 0 4px 14px rgba(20, 30, 50, 0.05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1319;
    --surface: #171d26;
    --surface-2: #1f2733;
    --text: #e8ecf2;
    --muted: #9aa5b6;
    --border: #2a3342;
    --accent: #7ba2ff;
    --accent-contrast: #0c1220;
    --danger: #ff8a80;
    --warn-bg: #3a2f10;
    --warn-text: #ffe29a;
    --c1: #6c93f2;
    --c2: #f0a45a;
    --c3: #4fc6a3;
    --c4: #d983c8;
    --c5: #a99cf5;
    --line: #ff8a7a;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 130px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { line-height: 1.25; margin: 0; }
h2 { font-size: 1.15rem; }
h3 { font-size: 0.95rem; color: var(--muted); font-weight: 600; }
a { color: var(--accent); }
.hidden { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px 24px; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 1.35rem; margin-bottom: 4px; }
.login-card p { color: var(--muted); margin: 0 0 18px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
input, select, button { font: inherit; }
input[type="password"], select {
  width: 100%; padding: 10px 12px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); min-height: 44px;
}
.btn {
  background: var(--accent); color: var(--accent-contrast); border: 0; border-radius: 9px;
  padding: 10px 16px; min-height: 44px; font-weight: 600; cursor: pointer;
}
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn:disabled { opacity: 0.6; cursor: default; }
.error { color: var(--danger); min-height: 1.4em; margin: 8px 0 0; font-size: 0.9rem; }

/* App */
.topbar {
  position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-in { max-width: 1180px; margin: 0 auto; padding: 10px 16px; display: grid; gap: 10px; }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.title-row h1 { font-size: 1.1rem; }
.filters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.filters .field { margin: 0; }
.nav { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: thin; }
.nav a {
  white-space: nowrap; text-decoration: none; color: var(--muted); font-size: 0.85rem;
  padding: 4px 10px; border-radius: 999px; background: var(--surface-2);
}
.nav a:hover { color: var(--text); }
main { max-width: 1180px; margin: 0 auto; padding: 18px 16px 48px; display: grid; gap: 22px; }
section { display: grid; gap: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px;
  box-shadow: var(--shadow); min-width: 0;
}
.grid-kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 0.82rem; }
.kpi .value { font-size: 1.6rem; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 0.78rem; margin-top: 2px; }
.sec-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.sec-head .note { color: var(--muted); font-size: 0.82rem; }
.note-box { background: var(--warn-bg); color: var(--warn-text); border-radius: 10px; padding: 8px 12px; font-size: 0.85rem; }
.muted { color: var(--muted); }
.cols-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }

/* Charts */
.chart { width: 100%; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { stroke: var(--muted); stroke-width: 1; }
.bar { cursor: pointer; }
.bar:hover { opacity: 0.8; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; font-size: 0.82rem; color: var(--muted); }
.legend span.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.legend span.ln { display: inline-block; width: 14px; height: 0; border-top: 2px solid var(--line); margin-right: 5px; vertical-align: 3px; }
.empty { color: var(--muted); padding: 22px 0; text-align: center; }
#tip {
  position: fixed; z-index: 50; pointer-events: none; background: #111; color: #fff; padding: 6px 9px;
  border-radius: 8px; font-size: 12px; line-height: 1.4; max-width: 260px; display: none; box-shadow: 0 4px 16px rgba(0,0,0,.35);
}

/* Barras horizontales */
.hbars { display: grid; gap: 7px; }
.hrow { display: grid; grid-template-columns: minmax(80px, 38%) 1fr auto; gap: 8px; align-items: center; font-size: 0.85rem; }
.hrow .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hrow .track { background: var(--surface-2); border-radius: 6px; height: 14px; overflow: hidden; }
.hrow .fill { height: 100%; border-radius: 6px; background: var(--c1); }
.hrow .val { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.82rem; }

/* Tablas */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.85rem; }
caption { text-align: left; color: var(--muted); font-size: 0.82rem; padding-bottom: 6px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
th button { all: unset; cursor: pointer; font-weight: 600; color: inherit; }
th button:focus-visible { outline: 2px solid var(--accent); }
td.name { max-width: 280px; overflow: hidden; text-overflow: ellipsis; text-align: left; }
.pill { font-size: 0.72rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }

footer { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 0 16px 28px; }

@media (max-height: 720px) {
  .topbar { position: static; }
  html { scroll-padding-top: 12px; }
}
@media (max-width: 560px) {
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .field:first-child { grid-column: 1 / -1; }
  .kpi .value { font-size: 1.35rem; }
  html { scroll-padding-top: 200px; }
}
