:root {
  color-scheme: light dark;
  --plane: #f9f9f7; --surface: #fcfcfb; --ink: #0b0b0b; --ink-2: #52514e; --muted: #898781; --grid: #e1e0d9;
  --accent: #2a78d6; --good: #1baf7a; --bad: #e34948;
}
@media (prefers-color-scheme: dark) {
  :root { --plane: #0d0d0d; --surface: #1a1a19; --ink: #fff; --ink-2: #c3c2b7; --grid: #2c2c2a; --accent: #3987e5; --good: #199e70; --bad: #e66767; }
  .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.85) contrast(0.9); }
  .leaflet-control-zoom a, .leaflet-control-attribution { background: var(--surface); color: var(--ink-2); }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--plane); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
[hidden] { display: none !important; }
a { color: var(--accent); }
header { display: flex; align-items: center; gap: 16px; padding: 16px 24px 0; }
header h1 { font-size: 20px; margin: 0; flex: 1; }
header .back { color: var(--ink-2); text-decoration: none; }
main { padding: 16px 24px 40px; display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--surface); border-radius: 12px; padding: 16px 20px; }
.card h2 { margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.06em; }
.pill { font-size: 12px; padding: 2px 10px; border-radius: 999px; background: var(--grid); color: var(--ink-2); white-space: nowrap; }
.pill.good { background: color-mix(in oklab, var(--good) 18%, var(--surface)); color: var(--good); }
.pill.bad { background: color-mix(in oklab, var(--bad) 18%, var(--surface)); color: var(--bad); }
.join { display: flex; gap: 24px; align-items: center; }
.join img { width: 180px; height: 180px; background: #fff; border-radius: 8px; padding: 6px; }
.join code { display: block; margin-top: 8px; font-size: 12px; color: var(--ink-2); word-break: break-all; }
.join p { margin: 0; color: var(--ink-2); }
.map { height: 380px; border-radius: 8px; overflow: hidden; background: var(--grid); }
.map-tools { display: flex; gap: 12px; align-items: center; margin-top: 8px; color: var(--ink-2); font-size: 13px; }
.devices { display: grid; grid-template-columns: repeat(auto-fill, minmax(460px, 1fr)); gap: 16px; }
.device { display: flex; flex-direction: column; gap: 10px; border-top: 4px solid var(--grid); }
.device .head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.device .name { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.device .swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.device .sub { color: var(--muted); font-size: 12px; }
.numbers { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; margin: 0; }
.numbers dt { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.numbers dd { margin: 0; font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: clip; }
.numbers dd small { font-size: 12px; font-weight: 500; color: var(--ink-2); margin-left: 3px; }
.since { color: var(--muted); font-size: 12px; }
.chart h3 { margin: 0 0 2px; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.uplot { font-family: inherit; }
.empty { color: var(--ink-2); }
.groups { display: flex; flex-direction: column; }
.group-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--grid); }
.group-row:first-child { border-top: 0; }
.group-row .meta { color: var(--ink-2); font-size: 13px; }
form.create { display: flex; gap: 8px; }
input[type=text] { flex: 1; padding: 8px 10px; border: 1px solid var(--grid); border-radius: 8px; background: var(--plane); color: var(--ink); font: inherit; }
button { padding: 8px 14px; border: 0; border-radius: 8px; background: var(--accent); color: #fff; font: inherit; font-weight: 600; cursor: pointer; }
button:disabled { opacity: 0.5; cursor: default; }
button.mark { background: var(--bad); font-size: 15px; padding: 10px 22px; }
button.quiet { background: transparent; color: var(--ink-2); }
button.quiet:hover { color: var(--bad); }
.toast { color: var(--ink-2); font-size: 13px; min-width: 120px; }

.head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.head-row h2 { margin: 0; }
.hint { color: var(--ink-2); margin: 8px 0; font-size: 13px; }
.button-link { display: inline-block; padding: 8px 14px; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 600; text-decoration: none; }
.button-link.disabled { opacity: 0.5; pointer-events: none; }
table.downloads { width: 100%; border-collapse: collapse; font-size: 14px; }
table.downloads td { padding: 8px 6px; border-top: 1px solid var(--grid); vertical-align: middle; }
table.downloads td.num { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); white-space: nowrap; }
table.downloads td.act { text-align: right; white-space: nowrap; }
table.downloads a.dl { color: var(--accent); font-weight: 600; text-decoration: none; }

.row-actions { display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.apk-card { align-items: center; }

.join { position: relative; }
.join-body { flex: 1; }
.join-toggle { align-self: flex-start; }
.join-collapsed { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 20px; }

/* --- battery --- */
.head-right { display: flex; align-items: center; gap: 8px; }
.battery { display: inline-flex; align-items: center; gap: 4px; color: var(--ink-2); }
.battery svg { display: block; }
.battery-text { font-size: 12px; font-variant-numeric: tabular-nums; }
.battery-low { color: var(--bad); font-weight: 700; }
.battery-low .battery-text { font-size: 14px; }

/* --- misc --- */
.error { color: var(--bad); }
.device .chart + .chart { margin-top: 4px; }

/* --- admin --- */
.table-scroll { overflow-x: auto; }
table.admin { width: 100%; border-collapse: collapse; font-size: 14px; }
table.admin th { text-align: left; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; padding: 4px 6px; }
table.admin th.num, table.admin td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.admin td { padding: 8px 6px; border-top: 1px solid var(--grid); vertical-align: middle; }
table.admin td.act { text-align: right; white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--ink-2); }
.admin-devices { display: flex; flex-direction: column; }
.admin-device { border-top: 1px solid var(--grid); }
.admin-device:first-child { border-top: 0; }
.admin-device-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 4px; background: transparent; color: var(--ink); text-align: left; font-weight: 400; border-radius: 8px; }
.admin-device-row:not(:disabled):hover { background: color-mix(in oklab, var(--accent) 8%, var(--surface)); }
.admin-device-row:disabled { opacity: 0.55; cursor: default; }
.admin-device-row .swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.admin-device-name { display: flex; flex-direction: column; min-width: 160px; }
.admin-device-row .meta { color: var(--ink-2); font-size: 13px; flex: 1; }
.admin-device-row .meta.mono { flex: none; }
.admin-device .watched { display: flex; flex-direction: column; gap: 16px; padding: 4px 0 16px; }
.admin-device .watched .device { border-top-width: 4px; }
@media (max-width: 720px) {
  .admin-device-row { flex-wrap: wrap; gap: 6px 12px; }
  .admin-device-row .meta { flex: none; }
}

/* live signals view */
button.small { padding: 4px 10px; font-size: 12px; }
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 2000; overflow: auto; padding: 24px; }
.signals-sheet { max-width: 1240px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.signals-sheet h2 { display: flex; align-items: center; gap: 8px; text-transform: none; font-size: 16px; letter-spacing: 0; color: var(--ink); }
.signals-sheet .sub { color: var(--muted); font-size: 12px; max-width: 70ch; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px 16px; margin: 0; }
.facts dt { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.facts dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 600; }
.facts dd small { font-weight: 400; color: var(--muted); }
.facts dd.good { color: var(--good); }
.facts .wide { grid-column: 1 / -1; }
.facts .wide dd { font-weight: 400; color: var(--ink-2); }
.signals { display: grid; grid-template-columns: repeat(auto-fit, minmax(440px, 1fr)); gap: 12px 20px; }
.chart.multi .u-legend { font-size: 11px; color: var(--ink-2); }
.chart.multi .u-legend .u-value { font-variant-numeric: tabular-nums; }
@media (max-width: 720px) {
  .numbers { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .overlay { padding: 8px; }
  .signals { grid-template-columns: 1fr; }
}
