/* Colours and fonts come from the site-wide /theme.css (loaded first in index.html).
   These are fallbacks for when no /theme.css is served (it is optional);
   :where() gives them zero specificity, so theme.css always wins when it is present. */
:where(:root) {
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --bg: #f1f5f9; --card: #ffffff; --line: #cbd5e1; --text: #0f172a; --muted: #64748b;
  --accent: #0284c7; --ok: #15803d; --warn: #b45309; --bad: #b91c1c; --off: #94a3b8;
  --ok-bg: rgba(21,128,61,.12); --warn-bg: rgba(180,83,9,.12); --off-bg: rgba(148,163,184,.18);
  --banner-bg: #fef3c7; --banner-fg: #78350f;
}
@media (prefers-color-scheme: dark) {
  :where(:root:not([data-theme="light"])) {
    --bg: #0f172a; --card: #1e293b; --line: #334155; --text: #e2e8f0; --muted: #94a3b8;
    --accent: #38bdf8; --ok: #4ade80; --warn: #fbbf24; --bad: #f87171; --off: #64748b;
    --ok-bg: rgba(74,222,128,.16); --warn-bg: rgba(251,191,36,.16); --off-bg: rgba(71,85,105,.3);
    --banner-bg: #422006; --banner-fg: #fde68a;
  }
}
:where(:root[data-theme="dark"]) {
  --bg: #0f172a; --card: #1e293b; --line: #334155; --text: #e2e8f0; --muted: #94a3b8;
  --accent: #38bdf8; --ok: #4ade80; --warn: #fbbf24; --bad: #f87171; --off: #64748b;
  --ok-bg: rgba(74,222,128,.16); --warn-bg: rgba(251,191,36,.16); --off-bg: rgba(71,85,105,.3);
  --banner-bg: #422006; --banner-fg: #fde68a;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
* { box-sizing: border-box; margin: 0; padding: 0; }
html { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
body { font-family: var(--font-sans); background: var(--bg); color: var(--text);
       line-height: 1.5; padding: 1rem; max-width: 1280px; margin: 0 auto; }
header { position: relative; padding-right: 3rem; }
h1 { font-size: 1.5rem; }
.theme-btn { position: absolute; top: 0; right: 0; width: 32px; height: 32px; margin: 0; padding: 0; display: grid; place-items: center;
             background: none; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); cursor: pointer; }
.theme-btn:hover { color: var(--accent); border-color: var(--accent); }
.theme-btn svg { width: 16px; height: 16px; }
.theme-btn .sun { display: none; }
:root[data-theme-now="dark"] .theme-btn .sun { display: block; }
:root[data-theme-now="dark"] .theme-btn .moon { display: none; }
h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: .6rem; }
.plain { text-transform: none; letter-spacing: 0; }
.subtitle { color: var(--muted); margin-bottom: 1rem; font-size: .95rem; }
.card { background: var(--card); border-radius: 12px; padding: 1rem; box-shadow: 0 1px 4px rgba(0,0,0,.15); min-width: 0; }
.row { display: grid; gap: 1rem; margin-bottom: 1rem; }
.row.top { grid-template-columns: 1.4fr 1fr .8fr; }
.row.main { grid-template-columns: 1fr 260px; }
@media (max-width: 1000px) { .row.top, .row.main { grid-template-columns: 1fr; } }

#warnings { background: var(--banner-bg); color: var(--banner-fg); border-radius: 10px; padding: .7rem 1rem .7rem 2rem; margin-bottom: 1rem; font-size: .9rem; }

.now-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .6rem; }
.stn { border: 1px solid var(--line); border-radius: 10px; padding: .6rem .7rem; cursor: pointer; background: none; color: inherit; font: inherit; text-align: left;
       display: flex; flex-direction: column; justify-content: flex-start; }
.stn.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.stn .name { font-weight: 700; display: flex; justify-content: space-between; align-items: center; gap: .3rem; }
.stn .big { font-size: 1.5rem; font-weight: 700; line-height: 1.25; }
.stn .big small { font-size: .8rem; }
.stn .none { font-size: 1rem; color: var(--muted); font-weight: 500; }
.kv { font-size: .8rem; color: var(--muted); display: flex; justify-content: space-between; gap: .5rem; }
.kv b { color: var(--text); font-weight: 600; }
.tag { font-size: .65rem; padding: 0 .4rem; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); font-weight: 500; white-space: nowrap; }
.tag.live { border-color: var(--ok); color: var(--ok); }
.stale { color: var(--warn); font-size: .75rem; text-transform: none; letter-spacing: 0; font-weight: 500; }
table.bands.is-stale { opacity: .5; }

table.bands { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.bands th { color: var(--muted); font-weight: 500; padding: .2rem; font-size: .75rem; text-align: center; }
table.bands td { padding: .12rem .2rem; text-align: center; }
table.bands th:first-child, table.bands td:first-child { text-align: left; }
.pill { display: inline-block; min-width: 4.6rem; padding: 0 .4rem; border-radius: 6px; font-size: .75rem; font-weight: 600; }
.open { background: var(--ok-bg); color: var(--ok); }
.marginal { background: var(--warn-bg); color: var(--warn); }
.closed, .unknown { background: var(--off-bg); color: var(--off); }
.absorbed { background: var(--off-bg); color: var(--bad); }
.behind { color: var(--muted); font-size: .75rem; }
.note { font-size: .72rem; color: var(--muted); margin-top: .5rem; }

.sw { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.sw > div { border: 1px solid var(--line); border-radius: 8px; padding: .4rem .6rem; }
.sw .lbl { font-size: .72rem; color: var(--muted); }
.sw .val { font-size: 1.15rem; font-weight: 700; }
.val.warn { color: var(--warn); } .val.bad { color: var(--bad); }

.chart { position: relative; height: 420px; }
.chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .axis-title { fill: var(--muted); font-size: 11px; }
.chart .series { fill: none; stroke-linejoin: round; stroke-linecap: round; }
.chart .series.fallback { opacity: .4; }
.chart .flare.m { fill: var(--warn); opacity: .14; }
.chart .flare.x { fill: var(--bad); opacity: .2; }
.chart .flare-label { fill: var(--muted); font-size: 10px; }
.flare-key { display: inline-block; width: 14px; height: 8px; margin-right: 4px; background: var(--warn); opacity: .45; border-radius: 2px; }
.chart .cursor { stroke: var(--muted); stroke-width: 1; }
.chart .empty { fill: var(--muted); font-size: 14px; }
.tip { position: absolute; pointer-events: none; background: var(--card); border: 1px solid var(--line); border-radius: 8px;
       padding: .35rem .55rem; font-size: .75rem; white-space: nowrap; box-shadow: 0 2px 8px rgba(0,0,0,.25); z-index: 2; }
.tip b { display: block; margin-bottom: .15rem; }
.tip i { display: inline-block; width: 14px; height: 3px; margin-right: .35rem; vertical-align: middle; border-radius: 2px; }
.legend { display: flex; flex-wrap: wrap; gap: .3rem 1rem; font-size: .78rem; color: var(--muted); margin-top: .5rem; }
.legend svg { vertical-align: middle; margin-right: .3rem; }

.controls label, .controls .label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .3rem; }
select, button { width: 100%; padding: .5rem; border-radius: 6px; border: 1px solid var(--line); background: var(--bg);
                 color: var(--text); margin-bottom: .8rem; font: inherit; }
button { background: var(--accent); color: var(--card); font-weight: 600; cursor: pointer; border: none; }
.checks label { display: flex; align-items: center; gap: .5rem; margin-bottom: .35rem; color: var(--text); font-size: .9rem; }
.checks input { width: auto; }
.status { font-size: .8rem; color: var(--muted); padding-top: .8rem; border-top: 1px solid var(--line); }
.status.ok { color: var(--ok); } .status.err { color: var(--bad); } .status.warn { color: var(--warn); }
footer { color: var(--muted); font-size: .75rem; margin-top: 1rem; line-height: 1.6; }
footer a { color: var(--accent); }
footer #about { margin-bottom: .4rem; }
