/* Colours are the dataviz reference palette's chrome and series tokens; dark mode has its own
   validated steps rather than an automatic inversion. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6d68;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --hover: rgba(11, 11, 11, 0.04);
  --link: #1c5cab;
  --accent: #2a78d6;
  --good: #0ca30c;
  --good-ink: #006300;
  --warning: #b07a00;
  --critical: #d03b3b;
  --limit: #c4372f;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --ink: #ffffff; --ink-2: #c3c2b7; --muted: #9a988f;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.1); --hover: rgba(255, 255, 255, 0.05);
    --link: #86b6ef; --accent: #3987e5; --good-ink: #0ca30c; --warning: #fab219; --limit: #ff7b72;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --ink: #ffffff; --ink-2: #c3c2b7; --muted: #9a988f;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.1); --hover: rgba(255, 255, 255, 0.05);
  --link: #86b6ef; --accent: #3987e5; --good-ink: #0ca30c; --warning: #fab219; --limit: #ff7b72;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--page); color: var(--ink); font: 14px/1.45 var(--font); }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; font-weight: 600; margin: 0 0 4px; }
h2 { font-size: 16px; font-weight: 600; margin: 28px 0 8px; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---- header ---- */
.top { display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 52px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.brand { color: var(--ink-2); font-weight: 600; display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand .logo { height: 15px; width: auto; display: block; }
.brand:hover { color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-sub { color: var(--muted); font-weight: 400; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav a { color: var(--ink-2); padding: 6px 10px; border-radius: 6px; white-space: nowrap; }
.nav a:hover { background: var(--hover); text-decoration: none; }
.nav a.active { color: var(--ink); background: var(--hover); font-weight: 600; }
.signout { display: flex; align-items: center; gap: 10px; margin: 0; }
.who { color: var(--muted); }
main { padding: 20px 24px 48px; max-width: 1440px; margin: 0 auto; }

/* ---- controls ---- */
input, select, button { font: inherit; color: inherit; }
input[type="search"], input[type="text"], input:not([type]), input[type="password"], input[type="datetime-local"], select {
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; min-height: 34px;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn { background: var(--ink); color: var(--surface); border: 0; border-radius: 6px; padding: 8px 16px; cursor: pointer; font-weight: 600; }
.btn:hover { opacity: 0.88; }
.btn-ghost { background: transparent; border: 1px solid var(--border); border-radius: 6px; padding: 5px 12px; cursor: pointer; min-height: 32px; }
.btn-ghost:hover { background: var(--hover); }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 14px 0; }
.filters input[type="search"] { width: 320px; max-width: 100%; }
.filters label { display: flex; align-items: center; gap: 6px; color: var(--ink-2); }
.check { cursor: pointer; }
.seg { display: inline-flex; max-width: 100%; overflow-x: auto; scrollbar-width: none; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: 6px 12px; cursor: pointer; border-right: 1px solid var(--border); white-space: nowrap; }
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--hover); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); font-weight: 600; }

/* ---- page parts ---- */
.page-head { margin: 4px 0 8px; }
.page-head p { margin: 2px 0; }
.h1-sub { font-size: 14px; font-weight: 400; margin-left: 6px; }
.crumbs { color: var(--muted); margin-bottom: 4px !important; }
.notice { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent); padding: 8px 12px; border-radius: 6px; margin: 0 0 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 20px; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }
.summary { min-height: 1.45em; margin: 10px 0 4px; }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
table.data { width: 100%; border-collapse: collapse; }
.data th, .data td { padding: 7px 12px; text-align: left; border-bottom: 1px solid var(--grid); white-space: nowrap; vertical-align: top; }
.data th { font-weight: 600; color: var(--ink-2); background: var(--surface); position: sticky; top: 0; font-size: 13px; }
.data th[data-sort] { cursor: pointer; user-select: none; }
.data th[data-sort]:hover { color: var(--ink); }
.data th[aria-sort="ascending"]::after { content: " ↑"; }
.data th[aria-sort="descending"]::after { content: " ↓"; }
.data tbody tr:hover { background: var(--hover); }
.data tbody tr:last-child td { border-bottom: 0; }
.data .num { text-align: right; font-variant-numeric: tabular-nums; }
.data td.values { white-space: normal; min-width: 260px; color: var(--ink-2); }
.kv .k { color: var(--muted); }
.health { white-space: nowrap; }
.health.online span { color: var(--good); }
.health.late span { color: var(--warning); }
.health.offline { color: var(--muted); }

/* ---- device page ---- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-top: 6px; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 14px; cursor: pointer; color: var(--ink-2); margin-bottom: -1px; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); font-weight: 600; }
.tab-link { margin-left: auto; padding: 8px 4px; }
.charts { display: grid; grid-template-columns: repeat(auto-fill, minmax(560px, 1fr)); gap: 14px; }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px 8px; min-width: 0; }
.chart-card h3 { font-size: 14px; font-weight: 600; margin: 0; }
.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.chart-stats { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; display: flex; gap: 12px; flex-wrap: wrap; }
.chart-stats b { color: var(--ink); font-weight: 600; }
.chart-body { margin-top: 6px; transition: opacity 0.15s; }
.loading .chart-body, .loading #chart { opacity: 0.45; }
details.occasional { margin-top: 18px; }
details.occasional summary { cursor: pointer; color: var(--ink-2); }
.text-values { margin: 18px 0 0; color: var(--ink-2); }
.text-values dt { color: var(--muted); }
.text-values dd { margin: 0 0 6px; }
.msg-values { white-space: normal !important; min-width: 300px; color: var(--ink-2); }
dialog { border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--ink); max-width: min(900px, 92vw); width: 100%; padding: 16px; }
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.dialog-head h2 { margin: 0; }
#raw-json { max-height: 70vh; overflow: auto; font: 12px/1.5 var(--mono); background: var(--page); padding: 12px; border-radius: 6px; }

/* ---- uPlot ---- */
.uplot, .uplot * { font-family: var(--font); }
.u-axis { color: var(--muted); }
.u-select { background: rgba(42, 120, 214, 0.1); }
.u-cursor-x { border-right: 1px solid var(--ink-2) !important; }
.u-cursor-y { display: none; }
.tt { position: absolute; z-index: 5; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 9px; font-size: 12px; box-shadow: 0 2px 10px rgba(0,0,0,0.12); white-space: nowrap; font-variant-numeric: tabular-nums; }
.tt .tt-time { color: var(--muted); margin-bottom: 2px; }
.tt .tt-row { display: flex; align-items: center; gap: 6px; }
.tt .tt-key { width: 12px; height: 2px; border-radius: 1px; flex: none; }
.tt b { font-weight: 600; }
.tt .tt-name { color: var(--ink-2); }

/* ---- compare ---- */
.compare { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 14px; align-items: start; }
.picker { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; max-height: 70vh; overflow: auto; margin: 0; }
.picker legend { font-weight: 600; padding: 0 4px; }
.picker label { display: flex; gap: 8px; align-items: center; padding: 3px 0; cursor: pointer; }
.picker label.off { color: var(--muted); }
#chart { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px; min-height: 360px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 2px; border-radius: 1px; display: inline-block; }

/* ---- export ---- */
.export-form { max-width: 640px; display: grid; gap: 14px; }
.export-form fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; }
.export-form legend { font-weight: 600; margin-bottom: 6px; }
.export-form label { display: grid; gap: 4px; color: var(--ink-2); }
.export-form label.radio { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--ink); }
.export-form label.radio select, .export-form label.radio input:not([type="radio"]) { flex: 1 1 260px; }

/* ---- status ---- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin: 10px 0 14px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.tile-label { color: var(--ink-2); }
.tile-value { font-size: 26px; font-weight: 600; margin: 2px 0; }
form.inline { display: inline; }

/* ---- login ---- */
.login { display: grid; place-items: center; min-height: calc(100vh - 160px); }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 14px; }
.login-card h1 { margin-bottom: 4px; }
.login-card label { display: grid; gap: 4px; color: var(--ink-2); }
.form-error { color: var(--critical); margin: 0; }

@media (max-width: 760px) {
  .top { padding: 0 16px; gap: 12px; }
  .brand-sub { display: none; }
  .who { max-width: 84px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  main { padding: 16px 16px 40px; }
  .charts { grid-template-columns: 1fr; }
  .compare { grid-template-columns: 1fr; }
  .tab-link { display: none; }
}

/* ---- account / users ---- */
.who { color: var(--ink-2); padding: 6px 8px; border-radius: 6px; }
.who:hover, .who.active { background: var(--hover); text-decoration: none; color: var(--ink); }
.notice.ok { border-left-color: var(--good); }
.notice.err { border-left-color: var(--critical); }
.form-card { max-width: 520px; display: grid; gap: 12px; margin-bottom: 18px; }
.form-card h2 { margin: 0 0 2px; }
.form-card label { display: grid; gap: 4px; color: var(--ink-2); }
.form-card label.check { display: flex; align-items: center; gap: 8px; color: var(--ink); }
.form-card input:not([type="checkbox"]):not([type="radio"]) { width: 100%; }
.data td.actions { white-space: normal; min-width: 280px; }
.actions details { display: inline-block; margin-right: 8px; vertical-align: top; }
.actions summary { cursor: pointer; color: var(--link); }
.inline-form { display: grid; gap: 8px; margin: 8px 0; max-width: 320px; }
.inline-form label { display: grid; gap: 4px; color: var(--ink-2); }
.btn-ghost.danger { color: var(--critical); }

/* ---- chart image export ---- */
.btn-small { min-height: 26px; padding: 2px 8px; font-size: 12px; }
.chart-head .btn-small { margin-left: auto; }
.compare-tools { display: flex; justify-content: flex-end; margin-top: 8px; }

/* ---- find by state ---- */
.presets { margin: 6px 0 14px; }
.presets summary { cursor: pointer; font-weight: 600; }
.presets ul { margin: 8px 0 0; padding-left: 20px; columns: 2 420px; }
.presets li { margin: 3px 0; break-inside: avoid; }
.find-form { display: grid; gap: 12px; max-width: 960px; }
.find-form .inline-label { display: flex; align-items: center; gap: 8px; color: var(--ink-2); }
.find-form fieldset.cond { border: 1px solid var(--border); border-radius: 8px; padding: 8px 14px 12px; margin: 0; display: grid; gap: 8px; }
.find-form legend { font-weight: 600; padding: 0 4px; }
.find-form legend label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.find-form label.radio { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; color: var(--ink); }
.find-form .row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.find-form input.n { width: 90px; }
.find-form .and { color: var(--muted); }
.small { font-size: 12px; margin: 0; }
table.mini { width: auto; margin-top: 4px; font-size: 13px; }
table.mini th, table.mini td { padding: 4px 10px; }
.data td.why { white-space: normal; min-width: 280px; color: var(--ink-2); }
.bat.low .bat-flag { color: var(--warning); font-weight: 600; }
.bat.critical .bat-flag { color: var(--critical); font-weight: 600; }
.bat-flag { font-size: 12px; }

/* ---- theme, public links, access, limits, download dialog (2026-10-23) ---- */
.nav-spacer { flex: 1; }
.theme-btn { white-space: nowrap; }
.share-bar { margin: 0; padding: 8px 24px; background: var(--surface); border-bottom: 1px solid var(--border); color: var(--ink-2); }
.tab-link-2 { margin-left: 16px; }
.chart-tools { display: inline-flex; gap: 6px; margin-left: auto; }
.chart-head .chart-tools .btn-small { margin-left: 0; }
.limit-info { color: var(--muted); }
.limit-info.out { color: var(--limit); font-weight: 600; }
.dl-form { display: grid; gap: 12px; }
.dl-form fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 6px; }
.dl-form legend { font-weight: 600; margin-bottom: 4px; }
.dl-form label { display: grid; gap: 4px; color: var(--ink-2); }
.dl-form label.radio, .dl-form label.check { display: flex; align-items: center; gap: 8px; color: var(--ink); }
.dl-form .png-only, .dl-form .csv-only { display: grid; gap: 10px; }
.dl-form input:not([type="radio"]):not([type="checkbox"]), .dl-form select { width: 100%; }
#dl-dialog, #limits-dialog { max-width: 460px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; }
.seg-radio { display: flex; flex-wrap: wrap; gap: 6px 18px; }
.seg-radio label { display: flex !important; align-items: center; gap: 6px; color: var(--ink) !important; }
fieldset.access { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px 10px; margin: 0; }
fieldset.access legend { font-weight: 600; padding: 0 4px; color: var(--ink-2); }
fieldset.access[disabled] { opacity: 0.5; }
.access-fields { display: grid; gap: 6px; }
.access-fields label.radio { display: flex !important; align-items: center; gap: 8px; color: var(--ink) !important; }
.app-checks { display: grid; gap: 6px; margin-left: 24px; }
.app-checks[data-off] { opacity: 0.55; }
.app-filter { width: 100%; max-width: 280px; }
.app-list { max-height: 220px; overflow: auto; border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; background: var(--page);
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); grid-auto-rows: max-content; align-content: start; gap: 2px 12px; }
.app-list label { display: flex !important; align-items: center; gap: 6px; color: var(--ink) !important; white-space: nowrap; min-width: 0; line-height: 1.6; }
.app-list label span { overflow: hidden; text-overflow: ellipsis; }
.app-list input, .access-fields input[type="radio"], .share-form input[type="radio"] { flex: none; margin: 0; }
.img-limits { display: grid; gap: 4px; }
.img-limits .muted { margin: 0; }
.data td.sees { white-space: normal; min-width: 200px; max-width: 420px; }
.access-edit summary { cursor: pointer; color: var(--link); margin-top: 4px; }
.access-edit .inline-form { max-width: 520px; }
.share-form fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 6px; }
.share-form legend { font-weight: 600; margin-bottom: 4px; color: var(--ink-2); }
.share-form label.radio { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--ink); }
.share-form label.radio select, .share-form label.radio input:not([type="radio"]) { flex: 1 1 220px; width: auto; }
.data td.link-cell { white-space: nowrap; }
.share-url { width: 300px; max-width: 46vw; font-size: 12px; margin-right: 6px; }
.data td.note { white-space: normal; min-width: 140px; }
.data tr.new td { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.data tr.dim td { color: var(--muted); }
@media (max-width: 760px) {
  .theme-btn { display: none; }
  .share-bar { padding: 8px 16px; }
}
