:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;
  --series-1-track: #cde2fb;
  --series-2: #eb6834;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --critical: #d03b3b;
  --critical-text: #b32e2e;
  --font: 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: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-1-track: #184f95;
    --series-2: #d95926;
    --good-text: #0ca30c;
    --critical-text: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;
  --series-1-track: #184f95;
  --series-2: #d95926;
  --good-text: #0ca30c;
  --critical-text: #e66767;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--page);
  padding: 0 16px 32px;
}
h1 { font-size: 18px; margin: 0; font-weight: 650; }
h2 { font-size: 14px; margin: 0; font-weight: 650; color: var(--ink); }
a { color: inherit; }
button { font: inherit; }

.topbar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 14px 0 10px; border-bottom: 1px solid var(--grid); margin-bottom: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.meta { color: var(--ink-2); font-size: 12.5px; }
.controls { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; cursor: pointer; text-decoration: none; font-size: 13px;
}
.btn:hover { border-color: var(--axis); }
.btn[disabled] { opacity: .5; cursor: default; }
.btn.primary { background: var(--series-1); color: #fff; border-color: transparent; }

.live-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.live-dot.live { background: var(--good); box-shadow: 0 0 0 0 rgba(12,163,12,.6); animation: pulse 2s infinite; }
.live-dot.stale { background: var(--warning); }
.live-dot.offline { background: var(--critical); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(12,163,12,.55); } 70% { box-shadow: 0 0 0 8px rgba(12,163,12,0); } 100% { box-shadow: 0 0 0 0 rgba(12,163,12,0); } }
.pill { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--ink-2); white-space: nowrap; }
.pill.live { color: var(--good-text); border-color: var(--good); }
.pill.stale { color: var(--ink); border-color: var(--warning); }
.pill.offline { color: var(--critical-text); border-color: var(--critical); }

main { display: flex; flex-direction: column; gap: 16px; max-width: 1400px; margin: 0 auto; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 12px; }
.grid { display: grid; gap: 16px; }
.grid-main { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
.stack { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
@media (max-width: 960px) { .grid-main { grid-template-columns: 1fr; } }

/* stat tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.tile .label { color: var(--ink-2); font-size: 12.5px; }
.tile .value { font-size: 28px; font-weight: 600; line-height: 1.1; }
.tile.hero .value { font-size: 40px; }
.tile .sub { color: var(--muted); font-size: 12px; }
.delta { font-size: 12px; color: var(--ink-2); }
.delta.up { color: var(--good-text); }
.delta.down { color: var(--critical-text); }
.meter { height: 8px; border-radius: 4px; background: var(--series-1-track); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; transition: width .6s ease; }
.meter.invalid > span { background: var(--series-2); }
.meter.invalid { background: var(--grid); }

/* tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
.results td.pos { color: var(--muted); width: 28px; }
.results .name { min-width: 0; }
.results .name .primary { font-weight: 550; }
.results .name .secondary { color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 420px; }
.results .barcell { width: 32%; min-width: 120px; }
.bar { position: relative; height: 14px; background: transparent; }
.bar .track { position: absolute; inset: 0; background: var(--grid); border-radius: 0 4px 4px 0; opacity: .5; }
.bar .fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--series-1); border-radius: 0 4px 4px 0; transition: width .6s ease; }
.bar .threshold { position: absolute; top: -3px; bottom: -3px; width: 1px; background: var(--ink-2); }
.bar .fill.below { opacity: .55; }
.results tr.changed td { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: rgba(42,120,214,.12); } to { background: transparent; } }
.badge { font-size: 10.5px; padding: 1px 6px; border-radius: 999px; border: 1px solid var(--border); color: var(--ink-2); margin-left: 6px; vertical-align: middle; }
.badge.over { border-color: var(--good); color: var(--good-text); }

.regions tr { cursor: pointer; }
.regions tr:hover td { background: rgba(42,120,214,.06); }
.regions tr.selected td { background: rgba(42,120,214,.12); }
.regions .mini { display: flex; align-items: center; gap: 8px; }
.regions .mini .meter { width: 70px; flex: none; }
.regions .stale td { opacity: .6; }
.leader { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; display: inline-block; vertical-align: bottom; }

/* trend charts */
.chart { position: relative; margin-top: 8px; }
.chart svg { width: 100%; height: 130px; display: block; overflow: visible; }
.chart .title { font-size: 12px; color: var(--ink-2); display: flex; justify-content: space-between; }
.chart .title b { color: var(--ink); font-weight: 600; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--series-1); opacity: .10; }
.chart .dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart .crosshair { stroke: var(--ink-2); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 10.5px; font-family: var(--font); }
.chart text.end { fill: var(--ink); font-weight: 600; font-size: 11.5px; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .empty { color: var(--muted); font-size: 12.5px; padding: 12px 0; }

/* feed */
.feed { max-height: 520px; overflow: auto; display: flex; flex-direction: column; }
.ev { display: grid; grid-template-columns: 52px 18px 1fr; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--grid); align-items: start; }
.ev:last-child { border-bottom: none; }
.ev .time { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.ev .icon { color: var(--ink-2); text-align: center; font-size: 12px; }
.ev .msg { min-width: 0; overflow-wrap: anywhere; }
.ev .detail { color: var(--muted); font-size: 12px; margin-top: 2px; }
.ev.warn .icon { color: var(--warning); }
.ev.error .icon, .ev.error .msg { color: var(--critical-text); }
.ev.rank .icon { color: var(--series-2); }
.ev.new { animation: flash 2s ease-out; }

/* drill-down */
.drill-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-bottom: 10px; }
@media (max-width: 700px) { .drill-row { grid-template-columns: 1fr; } }
select { width: 100%; font: inherit; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--ink); }
select:disabled { opacity: .55; }
.drill-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; margin: 8px 0 10px; }
.drill-kpis .tile .value { font-size: 20px; }
.docs { margin: 10px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.docs li { display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline; font-size: 13px; }
.docs .doc-label { color: var(--ink-2); }
.docs time { color: var(--muted); font-size: 12px; }
.status { color: var(--ink-2); font-size: 12.5px; margin: 6px 0; }
.status.error { color: var(--critical-text); }
.loading { opacity: .55; transition: opacity .2s; }

/* export */
.export-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

footer { max-width: 1400px; margin: 24px auto 0; color: var(--muted); font-size: 12px; }

.tooltip {
  position: fixed; z-index: 10; pointer-events: none; background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 9px; font-size: 12px; box-shadow: 0 4px 14px rgba(0,0,0,.12);
  max-width: 320px;
}
.tooltip b { font-weight: 650; }
.tooltip .row { display: flex; gap: 10px; justify-content: space-between; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
