:root {
  color-scheme: light;
  --bg: #f6f5f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e3e1dc;
  --text: #1b1b1a;
  --text-2: #52514e;
  --text-3: #7a7974;
  --accent: #2a78d6;
  --accent-soft: #e4eefb;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --bar: #2a78d6;
  --bar-track: #ebe9e4;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --station: #7a7974;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 2px 8px rgb(0 0 0 / 0.04);
  --tile-filter: grayscale(0.9) contrast(0.9) brightness(1.04);
  --radius: 12px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2e2e2b;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #8f8e86;
    --accent: #5598e7;
    --accent-soft: #1b2a3d;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --bar: #3987e5;
    --bar-track: #2a2a27;
    --station: #a3a29a;
    --shadow: none;
    --tile-filter: grayscale(1) invert(1) brightness(0.82) contrast(0.92);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211;
  --surface: #1a1a19;
  --surface-2: #232321;
  --border: #2e2e2b;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --text-3: #8f8e86;
  --accent: #5598e7;
  --accent-soft: #1b2a3d;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --bar: #3987e5;
  --bar-track: #2a2a27;
  --station: #a3a29a;
  --shadow: none;
  --tile-filter: grayscale(1) invert(1) brightness(0.82) contrast(0.92);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }

/* Cabecera */
.site-header {
  position: sticky; top: 0; z-index: 1000;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.header-inner { display: flex; align-items: center; gap: 24px; min-height: 56px; }
.brand {
  display: flex; align-items: center; gap: 8px; flex: none;
  font-weight: 700; font-size: 16px; color: var(--text); letter-spacing: -0.01em;
}
.brand:hover { text-decoration: none; }
.brand svg { width: 22px; height: 22px; color: var(--accent); }
.site-nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; margin-right: -16px; padding-right: 16px; }
.site-nav::-webkit-scrollbar { display: none; }
.site-nav a {
  padding: 6px 10px; border-radius: 8px; color: var(--text-2); white-space: nowrap; font-size: 14px;
}
.site-nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.site-nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

@media (max-width: 720px) {
  .header-inner { flex-direction: column; align-items: stretch; gap: 0; padding-top: 8px; }
  .site-nav { padding-bottom: 8px; margin-left: -10px; }
}

/* Encabezado de página */
.page-head { padding: 28px 0 8px; }
.page-head h1 { margin: 0 0 4px; font-size: 28px; line-height: 1.2; letter-spacing: -0.02em; }
.page-head p { margin: 0; color: var(--text-2); max-width: 70ch; }
.stamp { font-size: 13px; color: var(--text-3); margin-top: 6px; }
.stamp time { font-variant-numeric: tabular-nums; }

h2 { font-size: 17px; margin: 0 0 4px; letter-spacing: -0.01em; }
.sub { color: var(--text-3); font-size: 13px; margin: 0 0 14px; }

section { margin: 20px 0; }

/* Tarjetas */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); min-width: 0;
}
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); } }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 1000px) { .kpis { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); } }
@media (max-width: 520px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { font-size: 13px; color: var(--text-2); }
.kpi .value { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.15; margin-top: 4px; }
.kpi .value small { font-size: 16px; font-weight: 600; color: var(--text-2); margin-left: 2px; }
.kpi .hint { font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* Gráficos */
.chart-box { position: relative; height: 240px; }
.chart-box.tall { height: 300px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--text-2); margin: 0 0 10px; padding: 0; list-style: none; }
.legend li { display: flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.swatch.diamond { transform: rotate(45deg); border-radius: 2px; width: 9px; height: 9px; }
.swatch.dot { border-radius: 50%; }
.empty { color: var(--text-3); font-size: 14px; padding: 24px 0; text-align: center; }

/* Barras horizontales hechas con CSS */
.bars { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 160px) 1fr auto; gap: 10px; align-items: center; font-size: 14px; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.bar-track { height: 10px; background: var(--bar-track); border-radius: 4px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--bar); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-row .val { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 4.5em; text-align: right; }

/* Tablas */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-3); font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
tr[hidden] { display: none; }

/* Píldoras de línea y etiquetas */
.line {
  display: inline-flex; align-items: center; justify-content: center; min-width: 2.4em;
  padding: 1px 7px; border-radius: 6px; font-size: 12px; font-weight: 700; line-height: 1.6;
}
.tag {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}
.tag.live { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.delay { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Filtros */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 0 0 14px; }
.filters input[type="search"], .filters select {
  font: inherit; font-size: 14px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
.filters input[type="search"] { flex: 1 1 220px; }
.filters label.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text-2); cursor: pointer; user-select: none; }
.filters .count { font-size: 13px; color: var(--text-3); margin-left: auto; }

/* Avisos */
.alerts { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.alert { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.alert-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; color: var(--text-3); margin-bottom: 6px; }
.alert p { margin: 0; font-size: 14px; overflow-wrap: anywhere; }

/* Mapa */
.map { height: min(72vh, 680px); border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; background: var(--surface-2); }
.map.short { height: 420px; }
.leaflet-container { font: 13px/1.45 var(--font); }
.map .leaflet-tile-pane { filter: var(--tile-filter); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); }
.leaflet-popup-content { margin: 12px 14px; }
.leaflet-popup-content .pop-title { font-weight: 700; display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.leaflet-popup-content .pop-row { color: var(--text-2); }
.ld-marker { width: 12px; height: 12px; transform: rotate(45deg); border-radius: 2px; border: 2px solid var(--surface); box-shadow: 0 0 0 1px rgb(0 0 0 / 0.25); }

/* Catálogo */
.datasets { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
@media (max-width: 400px) { .datasets { grid-template-columns: minmax(0, 1fr); } }
.dataset h3 { margin: 0 0 6px; font-size: 15px; line-height: 1.35; }
.dataset p { margin: 0 0 10px; color: var(--text-2); font-size: 14px; }
.dataset .foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; align-items: center; font-size: 12px; color: var(--text-3); }
.ok { color: var(--good); font-weight: 600; }
.ko { color: var(--critical); font-weight: 600; }

.callout { background: var(--accent-soft); border-radius: 10px; padding: 12px 14px; font-size: 14px; color: var(--text); }

.site-footer { color: var(--text-3); font-size: 13px; padding: 28px 16px 40px; border-top: 1px solid var(--border); margin-top: 32px; }
.site-footer p { margin: 4px 0; }

.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
