:root {
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink2: #52514e;
  --muted: #7a7974;
  --line: #e4e3df;
  --grid: #ecebe7;
  --accent: #2a78d6;
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --good: #0ca30c;
  --bad: #d03b3b;
  --warn: #fab219;
  --good-bg: #e6f5e6;
  --bad-bg: #fbe9e9;
  --unk-bg: #efeeea;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink2: #c3c2b7;
    --muted: #8f8e86;
    --line: #2e2e2c;
    --grid: #262624;
    --accent: #3987e5;
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --good-bg: #13261a;
    --bad-bg: #2d1616;
    --unk-bg: #232321;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--ink); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
h1 { font-size: 22px; margin: 4px 0 12px; }
h2 { font-size: 16px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1.2em; margin: 8px 0 0; }

button, input, select { font: inherit; color: inherit; }
button { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 9px 14px; cursor: pointer; }
button.secondary { background: transparent; color: var(--ink); border: 1px solid var(--line); }
button.danger { background: transparent; color: var(--bad); border: 1px solid var(--line); }
button:disabled { opacity: .5; cursor: default; }
.link-btn { background: none; color: var(--accent); padding: 6px 0; }
.icon-btn { background: none; color: var(--ink2); font-size: 20px; padding: 4px 8px; }
input { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
label { display: block; color: var(--ink2); }
label.check { display: flex; align-items: center; gap: 8px; }
label.check input { width: auto; }

.screen { min-height: 100vh; }
#login, #setup { display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: grid; gap: 12px; text-align: center; }
.login-card label { text-align: left; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin: 12px; }
.top { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 10px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); background: var(--page); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.tabs button { background: none; color: var(--ink2); padding: 6px 10px; border-radius: 8px; white-space: nowrap; }
.tabs button.active { background: var(--unk-bg); color: var(--ink); font-weight: 600; }
.conn { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.conn.on { background: var(--good); }
.tab { max-width: 980px; margin: 0 auto; padding-bottom: 32px; }

.dev-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px; margin-bottom: 10px; }
.dev-head h2 { margin: 0; font-size: 18px; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--unk-bg); color: var(--ink2); }
.badge.good { background: var(--good-bg); color: var(--ink); }
.badge.bad { background: var(--bad-bg); color: var(--ink); }
.phases { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (max-width: 560px) { .phases { grid-template-columns: 1fr; } }
.ph { border-radius: 12px; padding: 10px 12px; background: var(--unk-bg); border-left: 4px solid var(--line); }
.ph.on { background: var(--good-bg); border-left-color: var(--good); }
.ph.off { background: var(--bad-bg); border-left-color: var(--bad); }
.ph-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.ph-name { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.ph-state { font-size: 13px; color: var(--ink2); }
.ph-v { font-size: 34px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.15; margin: 4px 0; }
.ph-v small { font-size: 16px; font-weight: 500; color: var(--ink2); }
.ph-rows { display: grid; grid-template-columns: auto 1fr; gap: 0 10px; font-size: 13px; color: var(--ink2); font-variant-numeric: tabular-nums; }
.ph-rows b { color: var(--ink); font-weight: 600; text-align: right; }
.total { margin-top: 10px; color: var(--ink2); font-variant-numeric: tabular-nums; }
.total b { color: var(--ink); }
.sim { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; color: var(--ink2); }
.sim button { padding: 5px 10px; font-size: 13px; }

.chart-box { margin-top: 12px; }
.chart-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.legend { display: flex; gap: 12px; font-size: 13px; color: var(--ink2); }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend i { width: 14px; height: 2px; display: inline-block; border-radius: 1px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { background: none; color: var(--ink2); border-radius: 0; padding: 4px 10px; font-size: 13px; }
.seg button.active { background: var(--unk-bg); color: var(--ink); font-weight: 600; }
.chart { position: relative; margin-top: 6px; touch-action: pan-y; }
.chart svg { display: block; width: 100%; height: 220px; overflow: visible; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .cross { stroke: var(--ink2); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.tip { position: absolute; top: 0; pointer-events: none; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 12px; box-shadow: 0 4px 14px rgba(0,0,0,.15); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tip div { display: flex; align-items: center; gap: 6px; }
.empty { color: var(--muted); font-size: 13px; padding: 20px 0; text-align: center; }
details.table-view { margin-top: 6px; font-size: 13px; color: var(--ink2); }
details.table-view table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
details.table-view td, details.table-view th { padding: 3px 6px; border-bottom: 1px solid var(--line); text-align: right; }

.events { list-style: none; margin: 0; padding: 0; }
.events li { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); align-items: baseline; }
.events li:last-child { border-bottom: 0; }
.events time { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; flex: none; min-width: 92px; }
.events .ico { flex: none; width: 1.2em; text-align: center; }

.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.row input { flex: 1; min-width: 180px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }
.plain { list-style: none; padding: 0; margin: 0; }
.plain li { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); gap: 8px; }
.dev-edit { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 10px; }
.dev-edit .grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0; }
.dev-edit label { font-size: 13px; }
.notice { margin-top: 10px; padding: 10px; border-radius: 10px; background: var(--unk-bg); font-size: 14px; word-break: break-all; }
.notice code { font-size: 15px; color: var(--ink); user-select: all; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: var(--page); padding: 10px 16px; border-radius: 10px; max-width: 90vw; z-index: 9; }
@media (forced-colors: active) { .series { stroke: CanvasText; } }
