:root {
  color-scheme: dark;
  --bg: #0d1117;
  --panel: #151b23;
  --panel-2: #1b2330;
  --line: #263041;
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #4fa3ff;
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --idle: #8b98a9;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
h1 { font-size: 20px; margin: 0 0 4px; font-weight: 600; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
.error { color: var(--bad); }

/* shell */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 16px; letter-spacing: .3px; padding: 0 8px 18px; }
.brand-mark { color: var(--accent); }
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a { color: var(--muted); padding: 8px 10px; border-radius: 6px; }
#nav a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
#nav a.active { background: var(--panel-2); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 8px; }
.conn { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--idle); flex: none; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); } .dot.warn { background: var(--warn); }
.view { padding: 24px 28px 48px; min-width: 0; outline: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }

/* controls */
.btn { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 7px 12px; cursor: pointer; font: inherit; }
.btn:hover { border-color: #3a4a62; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #04121f; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: progress; }
input, select { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; font: inherit; }
input:focus, select:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar .spacer { flex: 1; }

/* cards */
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.stat .value { font-size: 26px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }
.section { margin-top: 22px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; font-variant-numeric: tabular-nums; word-break: break-word; }

/* table */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; background: var(--panel-2); position: sticky; top: 0; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
tbody tr:hover { background: #18202b; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; }

/* badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; border: 1px solid transparent; }
.b-moving, .b-VERIFIED, .b-ok { color: var(--ok); border-color: #2a5a35; background: #12261a; }
.b-stationary, .b-AVAILABLE_BUT_UNTESTED { color: var(--accent); border-color: #234a73; background: #0f1f33; }
.b-stale, .b-UNKNOWN, .b-warn { color: var(--warn); border-color: #5c4615; background: #261d09; }
.b-no_location, .b-UNAVAILABLE, .b-fail { color: var(--bad); border-color: #6b2522; background: #2a1110; }
.b-recent { color: var(--ok); } .b-no_data { color: var(--bad); }

/* map */
.map { height: calc(100vh - 140px); min-height: 420px; border-radius: var(--radius); border: 1px solid var(--line); }
.map.small-map { height: 320px; min-height: 0; }
.leaflet-container { background: #0b0f14; }
.map-off { display: grid; place-items: center; color: var(--muted); }

/* raw inspector */
pre.raw { background: #0a0e13; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; overflow: auto; max-height: 480px; font-family: var(--mono); font-size: 12px; }
details > summary { cursor: pointer; color: var(--muted); margin-bottom: 8px; }
.banner { border: 1px solid #5c4615; background: #261d09; color: #f0d58c; border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; }
.banner.bad { border-color: #6b2522; background: #2a1110; color: #ffb3ad; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* login */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card { width: min(360px, calc(100vw - 32px)); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
.login-card .brand { padding: 0 0 4px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 16px; }
  .brand { padding: 0 8px 0 0; }
  #nav { flex-direction: row; flex-wrap: wrap; }
  .side-foot { margin: 0 0 0 auto; flex-direction: row; align-items: center; padding: 0; }
  .view { padding: 16px; }
  .two { grid-template-columns: 1fr; }
}

/* minimal test page */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.topbar .brand { padding: 0; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.page { max-width: 1100px; margin: 0 auto; padding: 20px 16px 48px; display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 12px; }
.row.between { justify-content: space-between; align-items: center; }
.row .grow { flex: 1; min-width: 240px; display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
.row h2 { margin: 0; }
