:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --border: #e3e2de;
  --grid: #ecebe7;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #2a78d6;
  --series: #2a78d6;
  --band: rgba(42, 120, 214, 0.14);
  --good: #008300;
  --off: #9a9993;
  --err: #c0392b;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --border: #2e2e2b;
    --grid: #2a2a27;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --accent: #3987e5;
    --series: #3987e5;
    --band: rgba(57, 135, 229, 0.2);
    --good: #3fb950;
    --off: #6d6c66;
    --err: #ff6b5e;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.75rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 650; color: var(--text); }
.who { display: flex; align-items: center; gap: 0.75rem; color: var(--text-2); font-size: 0.85rem; }
.who form { margin: 0; }
button.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }

main { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }

/* Login */
.login { max-width: 360px; margin: 10vh auto; display: grid; gap: 0.9rem; }
.login label { display: grid; gap: 0.3rem; font-size: 0.85rem; color: var(--text-2); }
.login input {
  font: inherit; padding: 0.6rem 0.7rem; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
button.primary {
  font: inherit; font-weight: 600; padding: 0.65rem; border: 0; border-radius: 8px;
  background: var(--accent); color: #fff; cursor: pointer;
}
.err { color: var(--err); margin: 0; }

/* Device list */
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
a.dev { color: var(--text); display: grid; gap: 0.6rem; transition: border-color .15s; }
a.dev:hover { border-color: var(--accent); }
.dev-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.dev p { margin: 0; }
.status { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.78rem; color: var(--text-2); white-space: nowrap; }
.status i { width: 8px; height: 8px; border-radius: 50%; background: var(--off); }
.status.on i { background: var(--good); }
.mini { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem 1rem; margin: 0; }
.mini dt { font-size: 0.78rem; color: var(--muted); }
.mini dd { margin: 0; font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.mini small, .t-value small { font-size: 0.7em; font-weight: 400; color: var(--text-2); margin-left: 0.2em; }

/* Device page */
.crumb { margin: 0 0 0.75rem; font-size: 0.9rem; }
.dev-title { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 0 1rem; }
.dev-title p { margin: 0 0 1rem; }
.tiles { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); margin-bottom: 1.5rem; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.85rem 1rem; }
.t-label { font-size: 0.8rem; color: var(--text-2); }
.t-value { font-size: 1.9rem; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.2; margin: 0.15rem 0; }
.t-ago { font-size: 0.75rem; color: var(--muted); }

.range { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-bottom: 1rem; background: var(--surface); }
.range a { padding: 0.35rem 0.9rem; color: var(--text-2); font-size: 0.85rem; }
.range a + a { border-left: 1px solid var(--border); }
.range a.active { background: var(--accent); color: #fff; }

.charts { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 520px), 1fr)); }
figure.chart { margin: 0; }
figcaption { font-weight: 600; font-size: 0.92rem; margin-bottom: 0.4rem; }
.plot { position: relative; height: 200px; }
.plot svg { display: block; width: 100%; height: 100%; overflow: visible; }
.plot .axis text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.plot .gridline { stroke: var(--grid); stroke-width: 1; }
.plot .line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.plot .band { fill: var(--band); stroke: none; }
.plot .hair { stroke: var(--text-2); stroke-width: 1; stroke-dasharray: 3 3; }
.plot .dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; }
.tip {
  position: absolute; pointer-events: none; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 0.4rem 0.6rem; font-size: 0.8rem;
  box-shadow: 0 4px 14px rgba(0,0,0,.12); white-space: nowrap; transform: translate(-50%, -110%);
}
.tip strong { font-size: 0.95rem; font-variant-numeric: tabular-nums; }
.tip .muted { display: block; }

@media (max-width: 520px) {
  .who span { display: none; }
  .t-value { font-size: 1.5rem; }
}
.ok { color: var(--good); margin: 0; font-weight: 600; }
.login.card { margin-top: 1rem; }
.login h1 { margin: 0; }
.login p { margin: 0; }
