:root {
  color-scheme: light;
  --page: #f4f4f1;
  --surface-1: #fcfcfb;
  --surface-2: #f0efec;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #6f6d67;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #1c5cab;
  --accent-soft: #cde2fb;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --band: rgba(42, 120, 214, 0.16);
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface-1: #1a1a19; --surface-2: #242423;
    --text-primary: #ffffff; --text-secondary: #c3c2b7; --text-muted: #9a988f;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,0.10);
    --accent: #6da7ec; --accent-soft: #184f95;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
    --band: rgba(57, 135, 229, 0.22);
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface-1: #1a1a19; --surface-2: #242423;
  --text-primary: #ffffff; --text-secondary: #c3c2b7; --text-muted: #9a988f;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,0.10);
  --accent: #6da7ec; --accent-soft: #184f95;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
  --band: rgba(57, 135, 229, 0.22);
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--text-primary); font-size: 14px; }
a { color: var(--accent); }
h3 { font-size: 14px; margin: 0; font-weight: 600; }
h4 { font-size: 12.5px; margin: 14px 0 6px; font-weight: 600; color: var(--text-secondary); }
.muted { color: var(--text-muted); font-size: 12px; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 20px; padding: 10px 20px; background: var(--surface-1); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 30px; height: 30px; color: var(--accent); }
.brand-title { font-weight: 700; font-size: 15px; letter-spacing: .2px; }
.brand-sub { color: var(--text-muted); font-size: 12px; }
.tabs { display: flex; gap: 2px; flex-wrap: wrap; }
.tabs button { background: none; border: 0; padding: 8px 12px; color: var(--text-secondary); font: inherit; border-radius: 8px; cursor: pointer; }
.tabs button:hover { background: var(--surface-2); }
.tabs button[aria-selected="true"] { color: var(--text-primary); background: var(--surface-2); font-weight: 600; box-shadow: inset 0 -2px 0 var(--accent); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.status-pill { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text-secondary); white-space: nowrap; }
.status-pill .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }

main { padding: 16px 20px 8px; max-width: 1680px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }

/* ---------- controls ---------- */
.filter-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; margin-bottom: 12px; }
.filter-row.compact { margin: 8px 0; }
.ctl { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-secondary); }
.ctl.chk { gap: 4px; }
select, input[type="date"], input[type="search"] { font: inherit; font-size: 13px; color: var(--text-primary); background: var(--surface-1); border: 1px solid var(--border); border-radius: 7px; padding: 5px 8px; }
.search { min-width: 180px; }
.btn, .icon-btn { font: inherit; font-size: 13px; background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border); border-radius: 7px; padding: 5px 10px; cursor: pointer; }
.icon-btn { width: 32px; padding: 5px 0; }
.btn:hover, .icon-btn:hover { background: var(--surface-2); }
.date-ctl { display: flex; align-items: center; gap: 6px; }
.tier { font-size: 11.5px; padding: 3px 8px; border-radius: 6px; border: 1px solid var(--border); color: var(--text-secondary); text-transform: uppercase; letter-spacing: .5px; }
input[type="range"] { width: 90px; accent-color: var(--accent); }

/* ---------- cards / layout ---------- */
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 14px; min-width: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.kpi-label { font-size: 12px; color: var(--text-secondary); }
.kpi-value { font-size: 26px; font-weight: 650; margin-top: 4px; line-height: 1.1; }
.kpi-value.small { font-size: 17px; margin-top: 8px; }
.kpi-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; }
.monitor-grid { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 14px; }
.side .card { margin-bottom: 14px; }
.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.three-col { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.split { display: grid; grid-template-columns: 1.2fr 1fr; gap: 14px; }
@media (max-width: 1200px) {
  .monitor-grid, .two-col, .three-col { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  main { padding: 12px 16px; }
  .kpis { grid-template-columns: minmax(0, 1fr); }
  .split { grid-template-columns: minmax(0, 1fr); }
  .brand-sub { display: none; }
}

/* ---------- map ---------- */
.map-wrap { position: relative; padding: 0; overflow: hidden; }
#map { height: min(76vh, 820px); min-height: 460px; width: 100%; }
.legend { position: absolute; left: 12px; bottom: 12px; background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 11.5px; max-width: calc(100% - 24px); box-shadow: var(--shadow); }
.legend .ramp { height: 10px; width: 300px; max-width: 100%; border-radius: 2px; }
.legend .ticks { position: relative; height: 14px; width: 300px; max-width: 100%; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.legend .ticks span { position: absolute; transform: translateX(-50%); }
.legend .title { font-weight: 600; margin-bottom: 5px; }
.legend .cats { display: grid; grid-template-columns: auto 1fr; gap: 3px 8px; align-items: center; }
.legend .sw { width: 14px; height: 10px; border-radius: 2px; }
.readout { position: absolute; right: 12px; top: 12px; background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px; min-width: 210px; box-shadow: var(--shadow); pointer-events: none; }
.readout .big { font-size: 20px; font-weight: 650; }
.readout .row { display: flex; justify-content: space-between; gap: 10px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.map-note { position: absolute; right: 12px; bottom: 30px; font-size: 11px; color: var(--text-muted); background: var(--surface-1); padding: 3px 7px; border-radius: 5px; border: 1px solid var(--border); }
.maplibregl-ctrl-attrib { font-size: 10px; }
.cat-chip { display: inline-flex; align-items: center; gap: 6px; }
.cat-chip i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

/* ---------- tables ---------- */
.table-wrap { overflow: auto; max-height: 360px; }
.table-wrap.tall { max-height: 620px; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
th, td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--surface-1); color: var(--text-secondary); font-weight: 600; z-index: 1; cursor: default; }
th.sortable { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td, tr.selected td { background: var(--surface-2); }
tr.highlight td { font-weight: 600; }
.tableview summary { cursor: pointer; font-size: 12px; color: var(--text-secondary); margin-top: 6px; }
.bar-cell { position: relative; }
.bar-cell .bar { position: absolute; left: 0; top: 50%; height: 6px; transform: translateY(-50%); border-radius: 0 3px 3px 0; opacity: .35; }

/* ---------- charts ---------- */
.chart { width: 100%; position: relative; }
.chart svg { display: block; overflow: visible; }
.chart .gridline line { stroke: var(--grid); }
.chart .gridline path { stroke: none; }
.chart .axis path, .chart .axis line { stroke: var(--axis); }
.chart .axis text { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .ref-line { stroke: var(--text-muted); stroke-width: 1; }
.chart .ref-label { fill: var(--text-muted); font-size: 10.5px; }
.chart .crosshair { stroke: var(--text-muted); stroke-width: 1; }
.legend-inline { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-secondary); margin: 4px 0; }
.legend-inline i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
.tooltip { position: fixed; z-index: 100; background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px; font-size: 12px; pointer-events: none; box-shadow: 0 4px 16px rgba(0,0,0,.12); max-width: 280px; }
.tooltip .t-title { font-weight: 600; margin-bottom: 3px; }
.tooltip .t-row { display: flex; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums; }
.tooltip .t-key { color: var(--text-secondary); }
.empty { color: var(--text-muted); font-size: 12.5px; padding: 30px 0; text-align: center; }

/* ---------- download ---------- */
.dl-buttons { display: flex; flex-wrap: wrap; gap: 10px; margin: 6px 0 4px; }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn:focus-visible, .icon-btn:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.spec-table th { position: static; width: 90px; vertical-align: top; color: var(--text-secondary); }
.spec-table td { white-space: normal; color: var(--text-secondary); line-height: 1.5; }
pre.code { background: var(--surface-2); border-radius: 8px; padding: 12px 14px; font-size: 12px; overflow-x: auto; line-height: 1.5; }
a.dl-link { font-weight: 600; text-decoration: none; }
a.dl-link:hover { text-decoration: underline; }

/* ---------- prose ---------- */
.prose { max-width: 1060px; margin: 0 auto; line-height: 1.6; padding: 24px 32px; }
.prose h2 { font-size: 20px; margin: 26px 0 8px; }
.prose h2:first-child { margin-top: 0; }
.prose h3 { font-size: 15px; margin: 18px 0 6px; }
.prose p, .prose li { color: var(--text-secondary); }
.prose code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.prose .diagram { overflow-x: auto; margin: 12px 0; }
.foot { text-align: center; font-size: 11.5px; color: var(--text-muted); padding: 10px 20px 22px; }
