/* The Air Network: "Valley paper". Tokens and layout follow DESIGN_SPEC.md. */

/* ---------- Tokens ---------- */
:root {
  --ground: #F3EFE6;
  --surface: #FFFDF8;
  --surface-2: #F8F4EC;
  --line: #E2DBCD;
  --ink: #1D1F1B;
  --ink-2: #55594F;
  --ink-3: #6B6F64;
  --accent: #1F5F57;
  --accent-ink: #FFFFFF;
  --accent-soft: #DCEAE5;
  --warn: #9A4F16;
  --warn-soft: #F6E6D3;
  --ok: #2E8A66;

  --b1: #8FD0BF;
  --b2: #BFD686;
  --b3: #EDCB5E;
  --b4: #E8914B;
  --b5: #B9453B;
  --b6: #6F2B5F;

  --font-display: "Fraunces", Georgia, "Times New Roman", serif;
  --font-ui: "Geist", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --r-card: 16px;
  --r-ctl: 10px;
  --rail: 232px;
  --tabbar: 64px;
  --pad-card: 24px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #121412;
    --surface: #1A1D1A;
    --surface-2: #20241F;
    --line: #2E332D;
    --ink: #ECE8DF;
    --ink-2: #B3B0A6;
    --ink-3: #8D8B83;
    --accent: #7CC3B4;
    --accent-ink: #0E1A18;
    --accent-soft: #1E3430;
    --warn: #E0A060;
    --warn-soft: #3A2A1A;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --ground: #121412;
  --surface: #1A1D1A;
  --surface-2: #20241F;
  --line: #2E332D;
  --ink: #ECE8DF;
  --ink-2: #B3B0A6;
  --ink-3: #8D8B83;
  --accent: #7CC3B4;
  --accent-ink: #0E1A18;
  --accent-soft: #1E3430;
  --warn: #E0A060;
  --warn-soft: #3A2A1A;
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--ground);
  color: var(--ink);
  font: 400 15px/1.55 var(--font-ui);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3, h4, p, ul, ol, dl, dd, figure { margin: 0; }
ul, ol { padding: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-underline-offset: 3px; }
img, svg { display: block; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 2000;
  background: var(--accent); color: var(--accent-ink); padding: 12px 16px; min-height: 44px;
  border-radius: var(--r-ctl); text-decoration: none; font-weight: 500;
}
.skip-link:focus { top: 12px; }

.icon { width: 20px; height: 20px; flex: none; }
.mono { font-family: var(--font-mono); font-size: 12px; font-weight: 400; letter-spacing: 0; }
.muted { color: var(--ink-3); }
.label { font: 500 13px/1.35 var(--font-ui); color: var(--ink-2); }
.caption { font: 400 12px/1.4 var(--font-mono); color: var(--ink-3); }
.display { font-family: var(--font-display); font-optical-sizing: auto; font-weight: 500; }

/* ---------- Shell ---------- */
.app {
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  min-height: 100vh;
}

.rail {
  position: sticky; top: 0;
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
  padding: 28px 16px 20px;
  background: var(--ground);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.wordmark {
  display: inline-flex; align-items: center; gap: 10px;
  color: var(--ink); text-decoration: none;
  min-height: 44px; padding: 0 8px; border-radius: var(--r-ctl);
  align-self: flex-start;
}
.wordmark .mark { width: 26px; height: 26px; color: var(--accent); }
.wordmark-text {
  display: flex; flex-direction: column;
  font-family: var(--font-display); font-optical-sizing: auto;
  font-size: 24px; line-height: 0.95; font-weight: 500; letter-spacing: -0.015em;
}
.tagline { margin: 2px 0 28px 8px; font: 400 12px/1.4 var(--font-mono); color: var(--ink-2); }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  height: 44px; padding: 0 12px;
  border-radius: var(--r-ctl);
  color: var(--ink-2); text-decoration: none;
  font: 500 15px/1 var(--font-ui);
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }

.rail-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding-top: 24px; }
.outdoor-mini { font: 500 13px/1.45 var(--font-ui); color: var(--ink-2); padding: 0 12px; }
.outdoor-mini .l1 { display: block; color: var(--ink); }
.outdoor-mini .l2 { display: block; }
.outdoor-mini .short { display: none; }
.theme-toggle {
  display: inline-flex; align-items: center; gap: 12px;
  min-height: 44px; padding: 0 12px;
  border: 0; border-radius: var(--r-ctl); background: transparent;
  color: var(--ink-2); font: 500 14px/1 var(--font-ui); cursor: pointer; text-align: left;
}
.theme-toggle:hover { background: var(--surface-2); color: var(--ink); }
.theme-toggle .i-sun { display: none; }
:root[data-effective-theme="dark"] .theme-toggle .i-sun { display: block; }
:root[data-effective-theme="dark"] .theme-toggle .i-moon { display: none; }

.topbar { display: none; }

main {
  width: 100%;
  max-width: calc(1200px + 80px);
  margin: 0 auto;
  padding: 40px;
  min-width: 0;
}
main:focus { outline: none; }

.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px 24px; flex-wrap: wrap;
  margin-bottom: 32px;
}
.page-head h1 {
  font-family: var(--font-display); font-optical-sizing: auto;
  font-size: 34px; line-height: 40px; font-weight: 500; letter-spacing: -0.01em;
}
.page-head h1:focus { outline: none; }
.page-head-right { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.updated { color: var(--ink-2); white-space: nowrap; }

/* Device pill: a native select dressed as a pill */
.device-pill {
  position: relative; display: inline-flex; align-items: center;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
  min-height: 44px; max-width: 100%;
}
.device-pill:hover { background: var(--surface-2); }
.device-pill:has(select:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.device-pill select {
  appearance: none; -webkit-appearance: none;
  border: 0; background: transparent; outline: none;
  min-height: 44px; padding: 0 40px 0 34px;
  font: 500 14px/1 var(--font-ui); color: var(--ink);
  cursor: pointer; max-width: 260px; text-overflow: ellipsis;
}
.device-pill .dot { position: absolute; left: 15px; pointer-events: none; }
.device-pill .chev { position: absolute; right: 14px; width: 18px; height: 18px; pointer-events: none; color: var(--ink-3); }

.dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none;
  background: var(--ink-3);
}
.dot[data-state="online"] { background: var(--ok); }
.dot[data-state="offline"] { background: var(--warn); }

/* ---------- Building blocks ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  padding: var(--pad-card);
  min-width: 0;
}
.card-title { font: 600 15px/1.35 var(--font-ui); color: var(--ink); }
.card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 8px 16px; flex-wrap: wrap; margin-bottom: 16px;
}

.stack { display: flex; flex-direction: column; gap: 24px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  background: var(--chip-bg, var(--surface-2)); color: var(--chip-fg, var(--ink));
  font: 500 13px/1.3 var(--font-ui); white-space: nowrap;
}
.chip-neutral { background: var(--surface-2); color: var(--ink-2); box-shadow: inset 0 0 0 1px var(--line); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: var(--r-ctl);
  background: var(--surface); color: var(--ink);
  font: 500 14px/1 var(--font-ui); text-decoration: none; white-space: nowrap;
  cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--accent); padding: 0 12px; }
.btn-quiet:hover { background: var(--accent-soft); }
.btn .icon { width: 18px; height: 18px; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; flex: none;
  border: 1px solid transparent; border-radius: var(--r-ctl);
  background: transparent; color: var(--ink-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* Segmented control (toggle buttons) */
.seg {
  display: inline-flex; flex-wrap: wrap;
  border: 1px solid var(--line); border-radius: var(--r-ctl);
  background: var(--surface-2); overflow: hidden;
}
.seg button {
  min-height: 44px; min-width: 44px; padding: 0 12px;
  border: 0; border-right: 1px solid var(--line); background: transparent;
  color: var(--ink-2); font: 500 14px/1 var(--font-ui); cursor: pointer;
}
.seg button:last-child { border-right: 0; }
.seg button:hover { color: var(--ink); background: var(--surface); }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.seg button:focus-visible { outline-offset: -3px; }

/* Switch */
.switch {
  display: inline-flex; align-items: center; gap: 10px;
  min-height: 44px; padding: 0 4px;
  border: 0; background: transparent; color: var(--ink); cursor: pointer;
  font: 500 14px/1 var(--font-ui);
}
.switch .track {
  position: relative; width: 38px; height: 22px; border-radius: 999px;
  background: var(--line); transition: background .15s;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface); transition: transform .15s;
}
.switch[aria-checked="true"] .track { background: var(--accent); }
.switch[aria-checked="true"] .track::after { transform: translateX(16px); background: var(--accent-ink); }

.toolbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 12px 16px;
  margin-bottom: 24px;
}
.toolbar .spacer { flex: 1; }

/* Notices */
.notice {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 18px; border-radius: 12px;
  background: var(--warn-soft); color: var(--warn);
  font: 500 14px/1.5 var(--font-ui);
}
.notice .icon { margin-top: 1px; }
.notice p { color: var(--ink); font-weight: 400; }
.notice strong { color: var(--warn); font-weight: 600; }

.callout {
  background: var(--surface-2); border-radius: 12px; padding: 16px;
}
.callout-title { display: flex; align-items: center; gap: 10px; font: 600 15px/1.35 var(--font-ui); }
.callout-title .icon { color: var(--accent); }
.callout p { margin-top: 6px; color: var(--ink-2); font-size: 14px; }

/* States */
.state {
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
  padding: 24px; border: 1px dashed var(--line); border-radius: var(--r-card);
  color: var(--ink-2);
}
.state h2, .state h3 { font: 600 15px/1.35 var(--font-ui); color: var(--ink); }
.state p { max-width: 60ch; }
.state-error { border-style: solid; background: var(--surface); }
.state-error h2, .state-error h3 { color: var(--warn); }
.state.inline { padding: 16px; }

.skeleton {
  border-radius: 12px; background: var(--surface-2);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.55; } }
.loading-frame { opacity: 0.5; transition: opacity .2s; pointer-events: none; }

/* ---------- Overview ---------- */
.ov-top { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 24px; }
.ov-strips { display: flex; flex-direction: column; gap: 12px; margin-top: 24px; }
.ov-strips:empty { display: none; }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-top: 24px; }

.hero { display: flex; flex-direction: column; }
.hero-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.hero-value { display: flex; align-items: baseline; gap: 12px; margin-top: 8px; }
.hero-num {
  font-family: var(--font-display); font-optical-sizing: auto; font-weight: 500;
  font-size: 112px; line-height: 0.95; letter-spacing: -0.02em;
}
.hero-unit { font: 400 16px/1 var(--font-mono); color: var(--ink-3); }
.hero-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; margin-top: 14px; }
.hero-meaning { color: var(--ink); font-size: 15px; }
.hero-spark { margin-top: 20px; }
.spark-axis { display: flex; justify-content: space-between; margin-top: 6px; }

.bandbar { position: relative; margin-top: 22px; }
.bandbar-names { display: grid; grid-template-columns: repeat(6, 1fr); gap: 2px; margin-top: 10px; }
.bandbar-names span { font: 400 11px/1.3 var(--font-ui); color: var(--ink-3); text-align: center; min-width: 0; }
.bandbar-names span.on { color: var(--ink); font-weight: 600; }
.bandbar-names small { display: block; font: 400 10px/1.3 var(--font-mono); color: var(--ink-3); margin-top: 1px; }
.bandbar-track { display: grid; grid-template-columns: repeat(6, 1fr); gap: 2px; }
.bandbar-track span { height: 6px; border-radius: 2px; }
.bandbar-marker {
  position: absolute; top: -5px; width: 4px; height: 16px; margin-left: -2px;
  border-radius: 2px; background: var(--ink); box-shadow: 0 0 0 2px var(--surface);
}
.bandbar-ticks { position: absolute; left: 0; right: 0; top: 12px; height: 16px; }
.bandbar-ticks span { position: absolute; transform: translateX(-50%); font: 400 11px/1 var(--font-mono); color: var(--ink-3); }

.spark { width: 100%; overflow: visible; }
.spark .spark-line { fill: none; stroke: var(--ink); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.spark .spark-dot { fill: none; stroke: var(--ink); stroke-width: 3; stroke-linecap: round; }
.spark .spark-base { stroke: var(--line); stroke-width: 1; }
.spark-empty { height: 40px; display: flex; align-items: center; }

.outside { display: flex; flex-direction: column; gap: 18px; }
.out-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.out-grid dt { font: 500 13px/1.3 var(--font-ui); color: var(--ink-2); }
.out-grid dd { margin-top: 3px; display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.out-grid .v { font-family: var(--font-display); font-optical-sizing: auto; font-weight: 500; font-size: 24px; line-height: 1.1; }
.out-grid .u { font: 400 12px/1 var(--font-mono); color: var(--ink-3); }
.out-grid .word { font: 500 15px/1.3 var(--font-ui); }
.outside .caption { margin-top: auto; }

.tile { display: flex; flex-direction: column; gap: 6px; padding: 20px; }
.tile-value { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.tile-num { font-family: var(--font-display); font-optical-sizing: auto; font-weight: 500; font-size: 40px; line-height: 1.05; letter-spacing: -0.01em; }
.tile-unit { font: 400 12px/1 var(--font-mono); color: var(--ink-3); }
.tile .chip { align-self: flex-start; }
.tile .spark, .tile .spark-empty { margin-top: 10px; }

/* ---------- History ---------- */
.charts { display: flex; flex-direction: column; gap: 16px; }
.chart-card { padding-bottom: 12px; }
.chart-head { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 4px 16px; }
.chart-stats { color: var(--ink-2); }
.readout {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px;
  min-height: 22px; margin: 8px 0 8px;
  font: 400 12px/1.5 var(--font-mono); color: var(--ink-2);
}
.readout .time { color: var(--ink); font-weight: 500; }
.readout .key { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.readout b { color: var(--ink); font-weight: 500; }
.sw { display: inline-block; width: 16px; height: 0; border-top: 2px solid var(--sw); }
.sw.dash { border-top-style: dashed; opacity: 0.8; }
.sw.dot2 { border-top: 1px dashed var(--ink-3); }
.plot { position: relative; width: 100%; min-height: 240px; }
.plot-empty {
  position: absolute; inset: 0 0 44px 48px; display: grid; place-items: center;
  color: var(--ink-3); font: 400 13px/1.4 var(--font-ui); pointer-events: none; text-align: center;
}
.hint { color: var(--ink-2); margin: -8px 0 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; min-height: 44px; }

/* uPlot theming */
.uplot { font-family: var(--font-mono); }
.u-select { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.u-cursor-x { border-right: 1px solid var(--ink-3) !important; }
.u-cursor-y { display: none; }
.u-cursor-pt { border-width: 2px !important; }

/* ---------- Patterns ---------- */
.heatmap-wrap { position: relative; overflow-x: auto; padding-bottom: 4px; }
.heatmap {
  display: grid; grid-template-columns: 40px repeat(24, minmax(11px, 1fr));
  gap: 3px; min-width: 360px;
}
.hm-hour, .hm-day { font: 400 11px/1 var(--font-mono); color: var(--ink-3); }
.hm-hour { text-align: center; padding-bottom: 4px; align-self: end; }
.hm-day { display: flex; align-items: center; }
.hm-cell { aspect-ratio: 1; border-radius: 3px; background: var(--c, transparent); }
.hm-cell.empty {
  background: repeating-linear-gradient(135deg, var(--line) 0 1.5px, transparent 1.5px 5px);
}
.hm-cell:hover { outline: 2px solid var(--ink); outline-offset: 0; }
.hm-tip {
  position: absolute; z-index: 5; pointer-events: none;
  background: var(--ink); color: var(--surface); border-radius: 8px;
  padding: 6px 10px; font: 400 12px/1.4 var(--font-mono); white-space: nowrap;
  transform: translate(-50%, -100%); margin-top: -8px;
}
.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 16px; align-items: center; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font: 400 12px/1.3 var(--font-ui); color: var(--ink-2); }
.legend-item i { width: 14px; height: 14px; border-radius: 3px; background: var(--c); }
.legend-item i.empty { background: repeating-linear-gradient(135deg, var(--line) 0 1.5px, transparent 1.5px 5px); box-shadow: inset 0 0 0 1px var(--line); }
.ramp { display: inline-flex; align-items: center; gap: 8px; font: 400 12px/1 var(--font-mono); color: var(--ink-2); }
.ramp i { width: 120px; height: 10px; border-radius: 3px; display: inline-flex; overflow: hidden; }
.ramp i b { flex: 1; }

.callouts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.stat-value { font-family: var(--font-display); font-optical-sizing: auto; font-weight: 500; font-size: 40px; line-height: 1.05; margin-top: 6px; }
.stat-sub { margin-top: 6px; color: var(--ink-2); font-size: 14px; }

details.table-view { margin-top: 16px; }
details.table-view summary { cursor: pointer; color: var(--accent); font: 500 14px/1 var(--font-ui); min-height: 44px; display: inline-flex; align-items: center; }
.table-scroll { overflow-x: auto; margin-top: 8px; }
table.data { border-collapse: collapse; font: 400 12px/1.4 var(--font-mono); }
table.data th, table.data td { padding: 4px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.data th { color: var(--ink-3); font-weight: 400; }

/* ---------- Map ---------- */
.map-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; align-items: start; }
.map-card { position: relative; padding: 0; overflow: hidden; isolation: isolate; }
.map { height: min(640px, calc(100vh - 200px)); min-height: 420px; background: var(--surface-2); }
.map.placing { cursor: crosshair; }
.map.placing .leaflet-interactive, .map.placing .leaflet-grab { cursor: crosshair; }
.place-banner {
  position: absolute; left: 12px; right: 12px; top: 12px; z-index: 1000;
  display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap;
  padding: 8px 8px 8px 16px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line);
}
.place-banner p { flex: 1 1 200px; font-size: 14px; }
.device-list { display: flex; flex-direction: column; gap: 12px; }
.map-hint { font: 400 13px/1.45 var(--font-ui); color: var(--ink-2); margin-bottom: 12px; }
.dl-item { padding: 16px; }
.dl-top { display: flex; align-items: center; gap: 10px; }
.dl-name {
  flex: 1; min-width: 0; text-align: left; border: 0; background: none; padding: 0;
  font: 600 15px/1.3 var(--font-ui); color: var(--ink); cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-height: 44px;
}
.dl-name:hover { color: var(--accent); }
.dl-meta { color: var(--ink-3); margin-top: 2px; }
.dl-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.airnet-pin { background: none; border: 0; }
.airnet-pin span {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  background: var(--pin-bg); color: var(--pin-fg);
  box-shadow: 0 0 0 2px var(--surface);
  font: 600 13px/1 var(--font-ui); font-variant-numeric: tabular-nums;
}
.airnet-pin.offline span { background: var(--surface-2); color: var(--ink-2); box-shadow: 0 0 0 2px var(--surface), inset 0 0 0 1px var(--ink-3); }
.airnet-pin:focus-visible { outline: none; }
.airnet-pin:focus-visible span { outline: 2px solid var(--accent); outline-offset: 2px; }

.leaflet-container { background: var(--surface-2); font: 400 13px/1.4 var(--font-ui); }
/* Tone the OpenStreetMap tiles to the page: only the markers carry colour. */
.map .leaflet-tile-pane { filter: grayscale(0.85) sepia(0.18) contrast(0.92) brightness(1.03); }
:root[data-effective-theme="dark"] .map .leaflet-tile-pane {
  filter: grayscale(0.9) invert(1) hue-rotate(180deg) brightness(0.82) contrast(0.88);
}
.leaflet-bar { border: 1px solid var(--line) !important; box-shadow: none !important; border-radius: var(--r-ctl) !important; overflow: hidden; }
.leaflet-bar a, .leaflet-touch .leaflet-bar a {
  width: 44px; height: 44px; line-height: 44px;
  background: var(--surface); color: var(--ink); border-bottom-color: var(--line);
}
.leaflet-bar a:hover { background: var(--surface-2); }
.leaflet-bar a.leaflet-disabled { background: var(--surface-2); color: var(--ink-3); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--surface); color: var(--ink); box-shadow: none; border: 1px solid var(--line);
}
.leaflet-popup-content-wrapper { border-radius: 12px; }
.leaflet-popup-content { margin: 14px 16px; min-width: 190px; font: 400 14px/1.45 var(--font-ui); }
.leaflet-container a.leaflet-popup-close-button { color: var(--ink-3); width: 32px; height: 32px; font: 20px/32px var(--font-ui); }
.leaflet-control-attribution {
  background: color-mix(in srgb, var(--surface) 88%, transparent) !important;
  color: var(--ink-3) !important; font: 400 11px/1.4 var(--font-ui);
}
.leaflet-control-attribution a { color: var(--accent); }
.pop-name { font: 600 15px/1.3 var(--font-ui); margin-bottom: 8px; }
.pop-grid { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 13px; }
.pop-grid dt { color: var(--ink-2); }
.pop-grid dd { font-variant-numeric: tabular-nums; }
.pop-open { margin-top: 12px; }

/* ---------- Insights ---------- */
.md > * + * { margin-top: 10px; }
.md ul, .md ol { padding-left: 1.3em; }
.md li + li { margin-top: 4px; }
.md strong { font-weight: 600; }
.md code { font: 400 13px/1 var(--font-mono); background: var(--surface-2); padding: 2px 5px; border-radius: 5px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip-btn {
  min-height: 44px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: 500 14px/1 var(--font-ui); cursor: pointer;
}
.chip-btn:hover { background: var(--accent-soft); border-color: var(--accent-soft); color: var(--accent); }
.setup-steps { margin-top: 12px; padding-left: 1.3em; display: flex; flex-direction: column; gap: 10px; }
.setup-steps code, .code {
  font: 400 13px/1.4 var(--font-mono); background: var(--surface-2);
  border: 1px solid var(--line); padding: 1px 6px; border-radius: 6px; white-space: nowrap;
}
.thinking { color: var(--ink-3); }

/* ---------- Demo mode ---------- */
.demo-pill {
  display: none; align-items: center; min-height: 28px; padding: 0 12px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font: 600 12px/1 var(--font-ui); letter-spacing: 0.02em;
}
:root[data-demo] .demo-pill { display: inline-flex; }
:root[data-demo] .owner-only { display: none !important; }

/* ---------- Chat ---------- */
.chat { max-width: 860px; display: flex; flex-direction: column; padding-bottom: 0; }
.chat-head { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-bottom: 8px; }
.chat-head:not(:has(> :not([hidden]))) { display: none; }
.chat-badge {
  margin-right: auto; display: inline-flex; align-items: center; min-height: 28px; padding: 0 12px;
  border-radius: 999px; background: var(--accent-soft); color: var(--accent); font: 600 12px/1 var(--font-ui);
}
.chat-badge[hidden], .chat-head .btn[hidden] { display: none; }
.chat-log { display: flex; flex-direction: column; gap: 20px; }
.msg { display: flex; gap: 12px; align-items: flex-start; }
.msg-avatar {
  flex: none; width: 32px; height: 32px; border-radius: 999px;
  display: grid; place-items: center; background: var(--accent-soft); color: var(--accent);
}
.msg-avatar svg { width: 18px; height: 18px; }
.msg-body { flex: 1; min-width: 0; font-size: 15px; line-height: 1.6; overflow-wrap: anywhere; }
.msg-ai .msg-body { padding-top: 4px; }
.msg-me { justify-content: flex-end; }
.msg-me .msg-body {
  flex: 0 1 auto; max-width: min(80%, 560px); padding: 10px 16px;
  background: var(--accent-soft); color: var(--ink); border-radius: 18px 18px 6px 18px; white-space: pre-wrap;
}
.msg-summary .msg-body {
  padding: 14px 18px 16px; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 6px 16px 16px 16px;
}
.msg-summary-head { display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap; margin-bottom: 10px; }
.msg-label { font: 600 13px/1 var(--font-ui); color: var(--ink-2); }
.msg-meta {
  display: flex; align-items: center; flex-wrap: wrap; gap: 4px 12px;
  margin-top: 8px; font: 400 12px/1.4 var(--font-mono); color: var(--ink-3);
}
.msg-error { color: var(--warn); margin-bottom: 10px; }
.link-btn {
  display: inline-flex; align-items: center; min-height: 44px; margin: -12px 0; padding: 0 6px;
  border: 0; background: none; color: var(--accent); cursor: pointer;
  font: 500 12px/1 var(--font-ui); text-decoration: underline; text-underline-offset: 3px;
}
.typing { display: inline-flex; gap: 5px; padding: 8px 0; }
.typing i { width: 7px; height: 7px; border-radius: 999px; background: var(--ink-3); animation: typing 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing { 0%, 60%, 100% { opacity: 0.3; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }
.chat-suggest { margin-top: 20px; }
.chat-suggest[hidden] { display: none; }
.chat-bottom {
  position: sticky; bottom: 0; z-index: 5;
  margin: 20px calc(-1 * var(--pad-card)) 0; padding: 14px var(--pad-card);
  background: var(--surface); border-top: 1px solid var(--line); border-radius: 0 0 var(--r-card) var(--r-card);
}
.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; min-width: 0; min-height: 44px; max-height: 140px; resize: none; padding: 11px 16px;
  border: 1px solid var(--line); border-radius: 22px; background: var(--surface-2); color: var(--ink);
  font: 400 15px/1.4 var(--font-ui);
}
.composer textarea::placeholder { color: var(--ink-3); }
.composer-send { width: 44px; min-width: 44px; padding: 0; justify-content: center; border-radius: 999px; }
.gate { display: flex; flex-direction: column; gap: 10px; }
.gate-title { display: flex; align-items: center; gap: 10px; font: 600 15px/1.4 var(--font-ui); }
.gate-title .icon { flex: none; color: var(--accent); }
.gate-row { display: flex; gap: 8px; }
.gate-row input {
  flex: 1; min-width: 0; min-height: 44px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--r-ctl); background: var(--surface-2); color: var(--ink);
  font: 400 15px/1 var(--font-ui);
}
.gate-msg { font: 500 13px/1.4 var(--font-ui); color: var(--warn); }
.gate-msg:empty { display: none; }

/* ---------- Share ---------- */
.share-card {
  max-width: 520px; margin: 0 auto; padding: 40px 32px;
  display: flex; flex-direction: column; align-items: center; gap: 16px; text-align: center;
}
.share-eyebrow { font: 500 28px/1.2 var(--font-display); font-optical-sizing: auto; }
.share-qr {
  width: min(320px, 100%); height: auto; aspect-ratio: 1; padding: 16px;
  background: #FFFFFF; border: 1px solid var(--line); border-radius: 16px;
}
.share-url { font-size: 14px; color: var(--ink-2); overflow-wrap: anywhere; }
.share-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.share-note { max-width: 420px; }

/* ---------- Devices ---------- */
.dev-card { display: flex; flex-direction: column; gap: 24px; }
.dev-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px 24px; flex-wrap: wrap; }
.dev-name-row { display: flex; align-items: center; gap: 4px; }
.dev-name { font-family: var(--font-display); font-optical-sizing: auto; font-weight: 500; font-size: 26px; line-height: 1.2; }
.dev-sub { display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; margin-top: 4px; color: var(--ink-2); }
.status { display: inline-flex; align-items: center; gap: 8px; font: 500 14px/1 var(--font-ui); }
.stats-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.stat {
  background: var(--surface-2); border-radius: 12px; padding: 14px 16px; min-width: 0;
}
.stat dt { font: 500 13px/1.3 var(--font-ui); color: var(--ink-2); }
.stat dd { margin-top: 4px; font-family: var(--font-display); font-optical-sizing: auto; font-weight: 500; font-size: 22px; line-height: 1.2; }
.stat dd .u { font: 400 12px/1 var(--font-mono); color: var(--ink-3); margin-left: 4px; }
.stat .sub { display: block; font: 400 12px/1.4 var(--font-mono); color: var(--ink-3); margin-top: 4px; }
.stat .bar { display: block; }
.bar { height: 6px; border-radius: 3px; background: var(--line); margin-top: 8px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.dev-section h3 { font: 600 15px/1.35 var(--font-ui); margin-bottom: 10px; }
.dev-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
.meter { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; max-width: 280px; }
.meter span { height: 8px; border-radius: 3px; background: var(--line); }
.meter span.on { background: var(--accent); }
.meter-labels { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; max-width: 280px; margin-top: 4px; }
.meter-note { margin-top: 10px; color: var(--ink-2); font-size: 14px; }
.flags { display: flex; gap: 8px; flex-wrap: wrap; }
.coverage { display: grid; grid-template-columns: repeat(30, 1fr); gap: 3px; align-items: end; height: 56px; }
.coverage i { display: block; background: var(--accent); border-radius: 2px 2px 0 0; min-height: 3px; }
.coverage i.none { background: var(--line); min-height: 2px; }
.coverage-axis { display: flex; justify-content: space-between; margin-top: 6px; }
.gaps { list-style: none; display: flex; flex-direction: column; }
.gaps li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.gaps li:last-child { border-bottom: 0; }
.gaps .mono { color: var(--ink-2); }

.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 24px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field input[type="text"], .field textarea {
  min-height: 44px; padding: 10px 14px; border: 1px solid var(--line); border-radius: var(--r-ctl);
  background: var(--surface-2); color: var(--ink); width: 100%;
}
.field textarea { resize: vertical; min-height: 76px; line-height: 1.45; }
.field .help { font: 400 12px/1.4 var(--font-mono); color: var(--ink-3); }
.form-foot { grid-column: 1 / -1; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.save-msg { font-size: 14px; color: var(--ink-2); }
.save-msg.err { color: var(--warn); }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.seg-radio { align-self: flex-start; }
.seg-radio label {
  position: relative; display: inline-flex; align-items: center;
  min-height: 44px; padding: 0 18px; border-right: 1px solid var(--line);
  color: var(--ink-2); font: 500 14px/1 var(--font-ui); cursor: pointer;
}
.seg-radio label:last-child { border-right: 0; }
.seg-radio input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.seg-radio label:hover { color: var(--ink); background: var(--surface); }
.seg-radio label:has(input:checked) { background: var(--accent-soft); color: var(--accent); }
.seg-radio label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: -3px; }
legend { padding: 0; }

/* ---------- Tablet: icon rail ---------- */
@media (max-width: 1023px) {
  :root { --rail: 72px; }
  .rail { padding: 20px 12px; align-items: center; }
  .wordmark { padding: 0; justify-content: center; width: 44px; }
  .wordmark-text, .tagline { display: none; }
  .rail .wordmark { margin-bottom: 24px; }
  .nav a { width: 48px; justify-content: center; padding: 0; }
  .nav a span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .rail-foot { align-items: center; }
  .outdoor-mini { padding: 0; text-align: center; }
  .outdoor-mini .full { display: none; }
  .outdoor-mini .short { display: inline; }
  .rail-toggle { width: 44px; padding: 0; justify-content: center; }
  .rail-toggle .theme-label { display: none; }
  main { padding: 32px; }
  .ov-top { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1199px) {
  .map-layout { grid-template-columns: 1fr; }
}
@media (max-width: 899px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- Phone: top bar + bottom tabs ---------- */
@media (max-width: 767px) {
  :root { --pad-card: 20px; }
  .app { grid-template-columns: minmax(0, 1fr); }
  .topbar {
    position: sticky; top: 0; z-index: 1100;
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    height: 60px; padding: 0 8px 0 12px;
    background: var(--ground); border-bottom: 1px solid var(--line);
  }
  .topbar .wordmark { width: auto; padding: 0 4px; flex: none; }
  .topbar .wordmark-text { display: flex; font-size: 20px; }
  .topbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: 4px; min-width: 0; flex: 1 1 auto; }
  .topbar .device-slot { min-width: 0; flex: 0 1 auto; }
  .topbar .device-pill { width: 100%; }
  .topbar .device-pill select { max-width: 220px; width: 100%; min-width: 0; }
  .topbar { height: 64px; }

  .rail {
    position: fixed; top: auto; left: 0; right: 0; bottom: 0; z-index: 1100;
    height: auto; padding: 0 0 env(safe-area-inset-bottom); overflow: visible;
    flex-direction: row; align-items: stretch;
    background: var(--surface); border-right: 0; border-top: 1px solid var(--line);
  }
  .rail .wordmark, .rail .tagline, .rail-foot { display: none; }
  .nav { flex-direction: row; width: 100%; gap: 0; }
  .nav a {
    flex: 1 1 0; width: auto; min-width: 0; height: var(--tabbar);
    flex-direction: column; justify-content: center; gap: 4px;
    border-radius: 0; padding: 0 2px;
  }
  .nav a span { position: static; width: auto; height: auto; overflow: visible; clip: auto; font: 500 11px/1 var(--font-ui); }
  .nav a[aria-current="page"] { background: transparent; }
  .nav a[aria-current="page"] .icon { background: var(--accent-soft); border-radius: 999px; width: 44px; padding: 0 12px; box-sizing: border-box; height: 24px; }

  main { padding: 20px 16px calc(var(--tabbar) + 32px + env(safe-area-inset-bottom)); }
  .page-head { margin-bottom: 20px; }
  .page-head h1 { font-size: 28px; line-height: 34px; }
  .page-head .device-slot { display: none; }
  .chat-bottom { bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); }
  .share-link span { display: none; }
  .share-card { padding: 32px 20px; }

  .hero-num { font-size: clamp(76px, 24vw, 112px); }
  .tile { padding: 16px; }
  .tile-num { font-size: 34px; }
  .tiles { gap: 12px; }
  .callouts { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dev-cols, .form { grid-template-columns: 1fr; }
  .map { height: 58vh; min-height: 320px; }
  .toolbar { gap: 12px; }
  .seg button { padding: 0 11px; }
  .hm-hour.minor { visibility: hidden; }
  .bandbar-names span { font-size: 10px; letter-spacing: -0.01em; }
  .bandbar-names small { font-size: 9px; }
  .heatmap { grid-template-columns: 30px repeat(24, minmax(11px, 1fr)); }
}
@media (min-width: 768px) {
  .topbar .device-slot { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
