:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --pos: #2a78d6;
  --neg: #e34948;
  --mid: #f0efec;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --good-text: #006300;
  --critical-text: #b42f2f;
  --seq: #cde2fb, #9ec5f4, #6da7ec, #3987e5, #256abf, #184f95, #0d366b;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@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;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --pos: #3987e5;
    --neg: #e66767;
    --mid: #383835;
    --good-text: #0ca30c;
    --critical-text: #e66767;
    --shadow: none;
  }
}
: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;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --pos: #3987e5;
  --neg: #e66767;
  --mid: #383835;
  --good-text: #0ca30c;
  --critical-text: #e66767;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 15px; }
h3 { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.neg { color: var(--critical-text); }
.posv { color: var(--good-text); }
[hidden] { display: none !important; }

/* ---------- header */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-row {
  max-width: 1640px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; min-width: 0; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 7px; background: var(--accent);
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 14px; flex: none;
}
.brand h1 { font-size: 15px; white-space: nowrap; }
.brand .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
select, input[type=text], input[type=password], input[type=date] {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; min-height: 34px;
}
select:focus, input:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
  padding: 6px 12px; min-height: 34px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--critical-text); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { min-height: 28px; padding: 3px 9px; font-size: 12px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 6px 10px; cursor: pointer; min-height: 32px; }
.seg button[aria-pressed=true] { background: var(--surface-2); font-weight: 600; }

.tabs {
  max-width: 1640px; margin: 0 auto; padding: 0 16px;
  display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 0; background: none; padding: 9px 12px; cursor: pointer; color: var(--ink-2);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab[aria-selected=true] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.tab:hover { color: var(--ink); }
.tab .count {
  display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px;
  background: var(--critical); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}

.layout {
  max-width: 1640px; margin: 0 auto; padding: 16px 16px 48px;
  display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start;
}
main { min-width: 0; }
.view { display: grid; gap: 16px; }
#files-toggle { display: none; }
@media (max-width: 1180px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { order: -1; display: none; }
  .sidebar.open { display: block; }
  #files-toggle { display: inline-block; }
}

/* ---------- file sidebar */
.sidebar { position: sticky; top: 112px; max-height: calc(100vh - 128px); overflow-y: auto; min-width: 0; }
@media (max-width: 1180px) { .sidebar { position: static; max-height: none; } }
.sidebar .card { padding: 14px; }
.sidebar h2 { font-size: 14px; }
.side-sub { font-size: 12px; color: var(--muted); margin: 2px 0 12px; }
.meter { height: 8px; border-radius: 4px; background: var(--mid); overflow: hidden; margin: 6px 0 4px; }
.meter > span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.meter-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-2); }
.file-days { list-style: none; margin: 10px 0 0; padding: 0; }
.file-day {
  display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center;
  padding: 6px 6px; border-radius: 6px; cursor: pointer; border-bottom: 1px solid var(--grid);
}
.file-day:hover { background: var(--surface-2); }
.file-day[aria-current=true] { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); }
.file-day .fd-date { font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.file-day .fd-date .badge { margin-left: 4px; padding: 0; border: 0; background: none; vertical-align: -2px; }
.chips { display: flex; gap: 3px; }
.chip {
  font-size: 10.5px; font-weight: 600; letter-spacing: .02em; padding: 1px 5px; border-radius: 4px;
  border: 1px solid transparent; white-space: nowrap; line-height: 16px;
}
.chip.on { background: var(--accent); color: #fff; }
.chip.off { border: 1px dashed var(--muted); color: var(--muted); background: transparent; }
.chip.opt { border-style: dotted; opacity: .7; }
.chip-legend { display: flex; gap: 10px; flex-wrap: wrap; font-size: 11px; color: var(--muted); margin-top: 8px; }
.chip-legend span { display: inline-flex; gap: 4px; align-items: center; }
.side-files { font-size: 11px; color: var(--muted); padding: 2px 6px 8px; word-break: break-all; }
.side-files div { display: flex; gap: 6px; }
.side-files b { color: var(--ink-2); font-weight: 600; flex: none; width: 38px; }
a.chip { text-decoration: none; }
a.chip.on:hover { filter: brightness(1.15); }

/* document uploaders: no file sidebar, the documents view takes the full width */
body.uploader .layout { grid-template-columns: minmax(0, 1fr); }
body.uploader .sidebar, body.uploader #files-toggle { display: none; }

/* ---------- cards & grid */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; min-width: 0;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-wide { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 960px) { .g2, .g3, .g-wide { grid-template-columns: minmax(0, 1fr); } }

/* ---------- KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi { padding: 14px 16px; }
.kpi .label { font-size: 12px; color: var(--ink-2); }
.kpi .value { font-size: 24px; font-weight: 600; margin-top: 4px; letter-spacing: -0.01em; }
.kpi .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.hero { grid-column: span 2; }
.kpi.hero .value { font-size: 40px; line-height: 1.1; }
@media (max-width: 520px) { .kpi.hero { grid-column: span 1; } .kpi.hero .value { font-size: 32px; } }
.split-line { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 6px; font-size: 12px; color: var(--ink-2); }

/* ---------- status badges (icon + label, never color alone) */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px 1px 6px; border-radius: 999px;
  font-size: 12px; white-space: nowrap; border: 1px solid var(--border); background: var(--surface);
}
.badge .dot {
  width: 14px; height: 14px; border-radius: 50%; display: inline-grid; place-items: center;
  font-size: 10px; font-weight: 700; color: #fff; flex: none;
}
.badge.good .dot { background: var(--good); }
.badge.warning .dot { background: var(--warning); color: #0b0b0b; }
.badge.serious .dot { background: var(--serious); }
.badge.critical .dot { background: var(--critical); }
.badge.info .dot { background: var(--muted); }
.badge.missing .dot { background: transparent; border: 1.5px dashed var(--muted); color: var(--muted); }

.alert {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface);
}
.alert .badge { margin-top: 1px; }

/* ---------- calendar strip */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal-head { font-size: 11px; color: var(--muted); text-align: center; }
.cal-day {
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 7px; min-height: 64px; cursor: pointer;
  background: var(--surface); text-align: left; display: flex; flex-direction: column; gap: 2px; min-width: 0;
  border-top-width: 4px;
}
.cal-day:hover { background: var(--surface-2); }
.cal-day.empty { visibility: hidden; }
.cal-day.good { border-top-color: var(--good); }
.cal-day.warning { border-top-color: var(--warning); }
.cal-day.serious { border-top-color: var(--serious); }
.cal-day.critical { border-top-color: var(--critical); }
.cal-day.missing { border-top-style: dashed; border-top-color: var(--muted); }
.cal-day.nodata { opacity: .45; cursor: default; }
.cal-day .d { font-weight: 600; font-size: 13px; }
.cal-day .v { font-size: 11px; color: var(--ink-2); font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 520px) { .cal-day .v { display: none; } .cal-day { min-height: 40px; } }

/* ---------- tables */
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th {
  text-align: left; font-weight: 600; font-size: 12px; color: var(--ink-2); padding: 7px 10px;
  border-bottom: 1px solid var(--axis); white-space: nowrap; position: sticky; top: 0; background: var(--surface);
}
th.num { text-align: right; }
td { padding: 7px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
tr.sub td { color: var(--ink-2); }
tr.float-row td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
tfoot td { font-weight: 600; border-top: 1px solid var(--axis); border-bottom: 0; }
/* a scroll box of its own, so the sticky headers (and totals) stay visible while scrolling */
.scroll-y { max-height: 520px; overflow-y: auto; }
.scroll-y tfoot td { position: sticky; bottom: 0; background: var(--surface); }
.empty-state { padding: 28px; text-align: center; color: var(--muted); }

/* ---------- charts */
.chart { position: relative; height: 260px; }
.chart.tall { height: 340px; }
.chart.short { height: 200px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin-bottom: 8px; }
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend .ln { width: 14px; height: 2px; border-radius: 1px; display: inline-block; }

.heatmap { display: grid; gap: 2px; font-size: 11px; }
.heatmap .hm-cell { height: 18px; border-radius: 3px; background: var(--surface-2); }
.heatmap .hm-label { color: var(--muted); white-space: nowrap; padding-right: 6px; font-variant-numeric: tabular-nums; line-height: 18px; }
.heatmap .hm-hour { color: var(--muted); text-align: center; }
.hm-scale { display: flex; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); margin-top: 10px; }
.hm-scale span.sw { width: 22px; height: 10px; border-radius: 2px; }

/* ---------- day view */
.day-nav { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.day-title { font-size: 18px; font-weight: 600; margin-right: 6px; }
.pill-list { display: flex; gap: 6px; flex-wrap: wrap; }
.times { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

/* ---------- uploads */
.drop {
  display: block;
  border: 2px dashed var(--axis); border-radius: var(--radius); padding: 32px 16px; text-align: center;
  background: var(--surface); cursor: pointer; transition: background .15s, border-color .15s;
}
.drop.over { border-color: var(--accent); background: var(--surface-2); }
.drop:hover { border-color: var(--accent); }
.drop strong { display: block; font-size: 15px; margin-bottom: 4px; }
.drop .muted { display: block; }
.drop.compact { padding: 14px 10px; }
.drop.compact strong { font-size: 13px; margin: 0; }
.drop.compact .muted { font-size: 11px; }
.drop.busy { opacity: .6; pointer-events: none; }
.result { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--grid); }
.result:last-child { border-bottom: 0; }
.result .fname { font-weight: 600; word-break: break-all; }
details summary { cursor: pointer; color: var(--ink-2); font-size: 12px; }
.form-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.form-row label { display: inline-flex; gap: 6px; align-items: center; }
.station-picks[hidden] { display: none; }
.inline-edit { display: inline-block; text-align: left; vertical-align: top; }
.inline-edit summary { list-style: none; }
.inline-edit summary::-webkit-details-marker { display: none; }
.inline-edit[open] form { margin: 8px 0; }

.tooltip {
  position: fixed; pointer-events: none; z-index: 50; background: var(--ink); color: var(--page);
  padding: 6px 9px; border-radius: 6px; font-size: 12px; max-width: 260px; display: none;
}

/* ---------- login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; }
.login-card form { display: grid; gap: 12px; margin-top: 16px; }
.login-card label { display: grid; gap: 4px; font-size: 12px; color: var(--ink-2); }
.login-card input { width: 100%; }
.error { color: var(--critical-text); font-size: 13px; min-height: 18px; }

.spinner { padding: 40px; text-align: center; color: var(--muted); }
