:root {
  color-scheme: light;
  --page: #f9f9f7; --surface: #fcfcfb; --surface-2: #f3f2ee;
  --ink: #0b0b0b; --ink-2: #52514e; --muted: #898781;
  --grid: #e1e0d9; --axis: #c3c2b7; --ring: rgba(11,11,11,0.10);
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b; --neutral: #898781;
  --accent: #2a78d6; --accent-ink: #fff;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
    --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --ring: rgba(255,255,255,0.10);
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --accent: #3987e5;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
  --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --ring: rgba(255,255,255,0.10);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --accent: #3987e5;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--page); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
h1 { font-size: 20px; margin: 0; font-weight: 650; }
h2 { font-size: 15px; margin: 0; font-weight: 600; }
.sub, .hint { color: var(--ink-2); margin: 2px 0 0; font-size: 13px; }
.hint { color: var(--muted); font-size: 12px; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 18px 24px;
       border-bottom: 1px solid var(--ring); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.top-actions { display: flex; gap: 8px; }
main { padding: 20px 24px 48px; display: flex; flex-direction: column; gap: 16px; max-width: 1600px; margin: 0 auto; }

.btn { border: 1px solid var(--ring); background: var(--surface); color: var(--ink); border-radius: 8px; padding: 7px 12px;
       font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }

.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--ring); border-radius: 12px; padding: 14px 16px; }
.kpi .label { color: var(--ink-2); font-size: 12px; }
.kpi .value { font-size: 26px; font-weight: 650; margin-top: 2px; }
.kpi .foot { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi .foot b { color: var(--ink-2); font-weight: 600; }

.grid.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--ring); border-radius: 12px; padding: 16px; min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 8px; flex-wrap: wrap; }
.chart { height: 300px; width: 100%; }
.chart.tall { height: 420px; }
.chart.short { height: 260px; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--ring); border-radius: 999px; padding: 3px 10px; font-size: 12px; cursor: pointer; background: transparent; color: var(--ink-2); }
.chip.on { background: var(--surface-2); color: var(--ink); border-color: var(--axis); font-weight: 600; }
.seg { display: inline-flex; border: 1px solid var(--ring); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; color: var(--ink-2); padding: 4px 10px; font: inherit; font-size: 12px; cursor: pointer; }
.seg button.on { background: var(--surface-2); color: var(--ink); font-weight: 600; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; }
input[type=search], select { font: inherit; font-size: 13px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--ring);
  background: var(--surface); color: var(--ink); }
input[type=search] { width: 240px; }

.table-wrap { overflow: auto; max-height: 620px; border-top: 1px solid var(--grid); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--ink-2); font-weight: 600; font-size: 12px; padding: 8px 10px; position: sticky; top: 0;
     background: var(--surface); border-bottom: 1px solid var(--grid); cursor: pointer; user-select: none; white-space: nowrap; }
td { padding: 7px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
tbody tr:hover { background: var(--surface-2); cursor: pointer; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.src-name { font-weight: 550; max-width: 380px; }
.src-id { color: var(--muted); font-size: 11px; }
.muted { color: var(--muted); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.status { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; font-size: 12px; }
.status .ico { font-size: 11px; width: 14px; text-align: center; }
.tier { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 4px; background: var(--surface-2); color: var(--ink-2); margin: 1px 2px 1px 0; white-space: nowrap; }

.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(720px, 100vw); background: var(--surface); border-left: 1px solid var(--ring);
          box-shadow: -12px 0 32px rgba(0,0,0,.12); z-index: 20; display: flex; flex-direction: column; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--grid); gap: 12px; }
#dBody { padding: 16px 20px 40px; overflow: auto; }
dl.meta { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; margin: 0 0 16px; font-size: 13px; }
dl.meta dt { color: var(--muted); }
dl.meta dd { margin: 0; word-break: break-word; }
pre.log { background: var(--surface-2); padding: 10px; border-radius: 8px; font-size: 11px; max-height: 300px; overflow: auto; white-space: pre-wrap; }
h3 { font-size: 13px; margin: 18px 0 8px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--page);
         padding: 9px 16px; border-radius: 8px; z-index: 30; font-size: 13px; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid.two { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .top { padding: 12px 16px; }
  main { padding: 16px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  input[type=search] { width: 100%; }
}

/* tabs */
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 10px; }
.tabs button { border: 0; background: transparent; color: var(--ink-2); font: inherit; font-size: 13px; padding: 6px 14px; border-radius: 8px; cursor: pointer; }
.tabs button.on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 0 0 1px var(--ring); }

/* map explorer */
.map-bar-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.map-controls { display: grid; grid-template-columns: 1fr 1fr 170px; gap: 8px; margin-bottom: 10px; }
.map-controls label { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--muted); min-width: 0; }
.map-controls select { width: 100%; }
.map-title { font-weight: 600; font-size: 13px; min-height: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map { position: relative; width: 100%; aspect-ratio: 975 / 610; }
.map svg, .map canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.map canvas { pointer-events: none; }
.map .county { stroke: var(--surface); stroke-width: 0.25; }
.map .state-border { fill: none; stroke: var(--surface); stroke-width: 0.9; stroke-linejoin: round; }
.map .nation { fill: none; stroke: var(--axis); stroke-width: 0.6; }
.map .hl { stroke: var(--ink); stroke-width: 1.4; }
.map .loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.legend { display: flex; align-items: flex-end; gap: 0; margin-top: 8px; font-size: 11px; color: var(--ink-2); flex-wrap: wrap; }
.legend .sw { display: flex; flex-direction: column; min-width: 44px; flex: 1; }
.legend .sw i { height: 10px; display: block; margin-right: 2px; }
.legend .sw span { margin-top: 3px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.legend .na { margin-left: 12px; display: flex; align-items: center; gap: 4px; }
.legend .na i { width: 12px; height: 10px; background: var(--surface-2); border: 1px solid var(--ring); display: inline-block; }
.map-tip { position: fixed; z-index: 40; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--ring);
           border-radius: 8px; padding: 7px 10px; font-size: 12px; box-shadow: 0 6px 18px rgba(0,0,0,.14); max-width: 280px; }
.map-tip b { font-weight: 600; }
.map-tip .row { display: flex; justify-content: space-between; gap: 12px; }
.map-tip .row span:last-child { font-variant-numeric: tabular-nums; }
.kpis.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1100px) { .map-controls { grid-template-columns: 1fr 1fr; } .map-controls .narrow { grid-column: span 2; } }
@media (max-width: 640px) { .kpis.three { grid-template-columns: 1fr; } .tabs { order: 3; width: 100%; } .top { flex-wrap: wrap; } }

/* sign-in: viewers see no refresh actions */
.who { color: var(--ink-2); font-size: 12px; align-self: center; white-space: nowrap; }
.top-actions form { margin: 0; }
body.viewer #runDue, body.viewer [data-run], body.viewer #mRedump, body.viewer #srcTable td button { display: none !important; }
