:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e6;
  --text: #191919;
  --text-2: #5c6470;
  --link: #1b64be;
  --down: #dc3c3d;
  --problem: #e0612a;
  --check: #b27c00;
  --check-bg: #fff6dc;
  --ok: #0a8a1f;
  --info: #5c6470;
  --down-bg: #fde8e8;
  --problem-bg: #fdeee5;
  --ok-bg: #e5f6e8;
  --info-bg: #eef0f3;
  --bar: #84b9f3;
  --bar-strong: #2370cd;
  --bar-now: #257de0;
  --dark-band: #e3e6ea;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121212;
    --surface: #191919;
    --surface-2: #222426;
    --border: #33373c;
    --text: #efefef;
    --text-2: #a3a9b1;
    --link: #6aabf1;
    --down: #eb6263;
    --problem: #f18a59;
    --check: #fbb315;
    --check-bg: #2e2610;
    --ok: #0aac23;
    --info: #a3a9b1;
    --down-bg: #3a1a1a;
    --problem-bg: #3a2418;
    --ok-bg: #12301a;
    --info-bg: #26292d;
    --bar: #1b64be;
    --bar-strong: #6aabf1;
    --bar-now: #338ced;
    --dark-band: #2a2d31;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121212; --surface: #191919; --surface-2: #222426; --border: #33373c; --text: #efefef; --text-2: #a3a9b1;
  --link: #6aabf1; --down: #eb6263; --problem: #f18a59; --check: #fbb315; --check-bg: #2e2610; --ok: #0aac23;
  --info: #a3a9b1; --down-bg: #3a1a1a; --problem-bg: #3a2418; --ok-bg: #12301a; --info-bg: #26292d;
  --bar: #1b64be; --bar-strong: #6aabf1; --bar-now: #338ced; --dark-band: #2a2d31;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); -webkit-text-size-adjust: 100%; }
a { color: var(--link); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
main { max-width: 1180px; margin: 0 auto; padding: 16px; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

/* header */
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.pill { font-size: 12px; font-weight: 500; color: var(--text-2); border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; }
.who { font-size: 14px; color: var(--text-2); white-space: nowrap; display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.who #user { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.who a { flex: none; }

/* state badges: icon + word, never colour alone */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 600; border-radius: 999px;
  padding: 2px 10px 2px 6px; white-space: nowrap; }
.badge .ic { display: inline-grid; place-items: center; width: 17px; height: 17px; border-radius: 50%; color: #fff;
  font-size: 11px; font-weight: 700; }
.b-down { background: var(--down-bg); color: var(--down); } .b-down .ic { background: var(--down); }
.b-problem { background: var(--problem-bg); color: var(--problem); } .b-problem .ic { background: var(--problem); }
.b-check { background: var(--check-bg); color: var(--check); } .b-check .ic { background: var(--check); color: #191919; }
.b-ok { background: var(--ok-bg); color: var(--ok); } .b-ok .ic { background: var(--ok); }
.b-info, .b-pending { background: var(--info-bg); color: var(--info); } .b-info .ic, .b-pending .ic { background: var(--info); }

/* overview tiles */
.overview { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.tile { display: block; text-decoration: none; color: inherit; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px; }
.tile:hover { border-color: var(--link); }
.tile .row1 { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tile h2 { font-size: 20px; }
.tile .site { color: var(--text-2); font-weight: 400; font-size: 15px; }
.tile ul { margin: 8px 0 0; padding-left: 18px; font-size: 14px; }
.tile .fine { margin-top: 8px; font-size: 14px; color: var(--ok); }

/* unit section */
.unit { margin-top: 22px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; scroll-margin-top: 64px; }
.unit-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.unit-head h2 { font-size: 22px; }
.unit-head .site { color: var(--text-2); font-weight: 400; }
.unit-head .sky { font-size: 14px; color: var(--text-2); }
.sectitle { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); margin: 18px 0 8px; font-weight: 600; }

/* problems */
.probs { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.prob { border: 1px solid var(--border); border-left-width: 5px; border-radius: 8px; padding: 10px 12px; background: var(--surface); }
.prob.l-down { border-left-color: var(--down); } .prob.l-problem { border-left-color: var(--problem); }
.prob.l-check { border-left-color: var(--check); } .prob.l-info { border-left-color: var(--info); }
.prob .ptitle { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; font-weight: 600; }
.prob .since { font-weight: 400; font-size: 13px; color: var(--text-2); }
.prob p { margin: 4px 0 0; }
.prob .checks { margin: 6px 0 0; padding-left: 20px; }
.prob .checks li { margin: 2px 0; }
.prob .chk { font-size: 13px; font-weight: 600; color: var(--text-2); margin-top: 6px; }
.allgood { padding: 10px 12px; border-radius: 8px; background: var(--ok-bg); color: var(--ok); font-weight: 600; }
.note { font-size: 14px; color: var(--text-2); margin: 8px 0 0; }

/* health grid */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; }
.card { border: 1px solid var(--border); border-radius: 10px; padding: 12px; min-width: 0; background: var(--surface); }
.card h3 { font-size: 15px; margin-bottom: 6px; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 3px 12px; margin: 0; font-size: 14px; }
dl.kv dt { color: var(--text-2); }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.good { color: var(--ok); } .bad { color: var(--down); } .warn { color: var(--check); }
.cam { padding: 8px 0; border-top: 1px solid var(--border); }
.cam:first-of-type { border-top: 0; padding-top: 0; }
.cam .camname { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.meter { position: relative; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-top: 3px; }
.meter > span { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 4px; background: var(--bar-now); }
.meter.m-warn > span { background: var(--check); } .meter.m-bad > span { background: var(--down); }
.diskrow { margin: 6px 0; font-size: 14px; }
.diskrow .lbl { display: flex; justify-content: space-between; gap: 8px; }
details { margin-top: 8px; }
details summary { cursor: pointer; color: var(--link); font-size: 14px; }
pre.body { white-space: pre-wrap; overflow-wrap: anywhere; font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--surface-2); border-radius: 6px; padding: 8px 10px; margin: 6px 0 0; max-height: 360px; overflow: auto; }

/* tables */
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-weight: 600; color: var(--text-2); background: var(--surface-2); position: sticky; top: 0; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
.st { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; font-size: 13px; }
.st-missed { color: var(--down); } .st-nodet, .st-notrk { color: var(--check); } .st-ok { color: var(--ok); }
.st-prog, .st-none { color: var(--text-2); }

/* charts */
.chart { width: 100%; overflow: hidden; }
.chart svg { display: block; width: 100%; height: auto; }
.chart text { fill: var(--text-2); font: 11px var(--font); }
.chart .bar { fill: var(--bar); } .chart .bar-strong { fill: var(--bar-strong); } .chart .bar-now { fill: var(--bar-now); }
.chart .band { fill: var(--dark-band); }
.chart .axis { stroke: var(--border); stroke-width: 1; }
.chart .miss { fill: var(--down); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--text-2); margin: 4px 0 6px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 5px; }
.legend .k-bar { background: var(--bar); } .legend .k-strong { background: var(--bar-strong); }
.legend .k-now { background: var(--bar-now); } .legend .k-band { background: var(--dark-band); border: 1px solid var(--border); }
.more { margin-top: 8px; font-size: 14px; }
button.link { background: none; border: 0; padding: 0; color: var(--link); font: inherit; cursor: pointer; text-decoration: underline; }

footer { margin-top: 24px; }

/* sign-in page */
body.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-box { max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 24px; }
.login-box h1 { font-size: 22px; margin-bottom: 8px; }
.btn { display: inline-block; background: var(--bar-strong); color: #fff; text-decoration: none; padding: 9px 18px;
  border-radius: 8px; font-weight: 600; }
.err { color: var(--down); }

@media (max-width: 600px) {
  main { padding: 12px; }
  .top { padding: 8px 12px; }
  .brand .pill { display: none; }
  .unit { padding: 12px; margin-top: 16px; }
  .unit-head h2 { font-size: 20px; }
  .grid { grid-template-columns: 1fr; }
  th, td { padding: 6px 8px; }
}
