/* ===========================================================================
   notifmon · telemetry console
   Mission-control design system. Dark is the default world; the light theme is
   a selected set, not an auto-invert. Charts draw their series from the dataviz
   categorical palette (validated for both surfaces).
   =========================================================================== */

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0b0e14;            /* page plane, deep cool slate */
  --surface-1: #11151d;     /* panels */
  --surface-2: #0d1017;     /* rail / topbar */
  --surface-3: #161b25;     /* hover / elevated */
  --surface-inset: #0a0d13; /* wells, code, map frame */
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.13);
  --text: #e8ebf2;
  --text-dim: #9aa4b4;
  --text-muted: #798498;
  --accent: #4c8dff;
  --accent-ink: #cfe0ff;
  --accent-wash: rgba(76, 141, 255, 0.14);
  --good: #2ec27e;
  --warn: #f5a623;
  --danger: #f0616d;
  --danger-wash: rgba(240, 97, 109, 0.12);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px -12px rgba(0, 0, 0, 0.55);
  --shadow-pop: 0 8px 28px -6px rgba(0, 0, 0, 0.6);
  --grid-line: #1d2430;
  /* chart series — dataviz dark steps */
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #2ea043; --s7: #9085e9; --s8: #e66767;
  --seq: #3987e5;
}

:root[data-theme='light'] {
  color-scheme: light;
  --bg: #eef0f4;
  --surface-1: #ffffff;
  --surface-2: #f6f7f9;
  --surface-3: #eef1f6;
  --surface-inset: #f1f3f7;
  --border: rgba(12, 22, 40, 0.10);
  --border-strong: rgba(12, 22, 40, 0.18);
  --text: #0e1626;
  --text-dim: #4a5568;
  --text-muted: #6b7686;
  --accent: #2a6fe0;
  --accent-ink: #11408f;
  --accent-wash: rgba(42, 111, 224, 0.10);
  --good: #0f9d58;
  --warn: #c67c08;
  --danger: #d4343f;
  --danger-wash: rgba(212, 52, 63, 0.08);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 12px 28px -14px rgba(16, 24, 40, 0.22);
  --shadow-pop: 0 10px 30px -8px rgba(16, 24, 40, 0.24);
  --grid-line: #e4e8ef;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --seq: #2a78d6;
}

* { box-sizing: border-box; }

/* A CSS `display` value overrides the `hidden` attribute; keep hidden winning
   so toggled views/overlays actually collapse. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.mono { font-family: ui-monospace, 'SF Mono', 'JetBrains Mono', 'Cascadia Code', Menlo, monospace; }
.dim { color: var(--text-dim); font-weight: 400; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

h1, h2, h3 { margin: 0; letter-spacing: -0.015em; font-weight: 650; }
h1 { font-size: 1.4rem; }
h3 { font-size: 0.95rem; }

/* Browser surfaces wear the design (craft-floor). */
::selection { background: var(--accent-wash); color: var(--text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--text-muted); background-clip: content-box; }

a { color: var(--accent); text-decoration: none; }

/* ============================= Brand mark ============================= */
.brand-mark {
  width: 22px; height: 22px; border-radius: 7px; flex: none;
  background:
    radial-gradient(circle at 50% 50%, var(--accent) 0 22%, transparent 24%),
    conic-gradient(from 210deg, var(--s3), var(--s1), var(--s7), var(--s3));
  box-shadow: inset 0 0 0 1px var(--border-strong), 0 0 0 3px var(--accent-wash);
  position: relative;
}
.brand-word { font-weight: 700; letter-spacing: -0.02em; font-size: 1.02rem; }

/* ============================= Auth ============================= */
.auth-wrap {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(900px 500px at 15% -10%, var(--accent-wash), transparent 60%),
    radial-gradient(700px 500px at 110% 120%, rgba(25,160,112,0.10), transparent 55%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 16px; padding: 28px;
  box-shadow: var(--shadow-pop);
}
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.auth-card h1 { margin-bottom: 6px; }
.auth-card p { margin: 0 0 18px; }

.field-stack { display: grid; gap: 14px; }
.field-stack label { display: grid; gap: 6px; font-size: 0.82rem; color: var(--text-dim); font-weight: 550; }
input, select {
  font: inherit; color: var(--text); background: var(--surface-inset);
  border: 1px solid var(--border-strong); border-radius: 9px; padding: 9px 11px; width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder { color: var(--text-muted); }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.form-error { color: var(--danger); font-size: 0.82rem; min-height: 1em; margin: 2px 0 0; }

/* ============================= Buttons ============================= */
.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  font: inherit; font-weight: 550; font-size: 0.86rem; cursor: pointer;
  padding: 8px 14px; border-radius: 9px; border: 1px solid var(--border-strong);
  background: var(--surface-3); color: var(--text);
  transition: background 0.15s, border-color 0.15s, transform 0.06s;
}
.btn:hover { background: var(--surface-1); border-color: var(--text-muted); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--accent); border-color: transparent; color: #fff; }
:root[data-theme='light'] .btn-primary { color: #fff; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); border-color: transparent; }
.btn-danger { background: transparent; border-color: color-mix(in srgb, var(--danger) 45%, transparent); color: var(--danger); }
.btn-danger:hover { background: var(--danger-wash); border-color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 0.78rem; }

.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; flex: none;
  border-radius: 9px; border: 1px solid transparent; background: transparent;
  color: var(--text-dim); cursor: pointer; transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

/* ============================= Shell layout ============================= */
.shell {
  display: grid;
  grid-template-columns: 236px 1fr;
  grid-template-rows: 60px 1fr;
  grid-template-areas: 'rail topbar' 'rail content';
  height: 100vh; height: 100dvh;
}
.rail {
  grid-area: rail; background: var(--surface-2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px; gap: 6px; overflow-y: auto;
}
.rail-brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 14px; }
.rail-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.rail-foot { display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--border); padding-top: 8px; margin-top: 8px; }

.nav-item {
  display: flex; align-items: center; gap: 11px; width: 100%; text-align: left;
  font: inherit; font-weight: 530; font-size: 0.88rem; color: var(--text-dim);
  background: transparent; border: 0; border-radius: 9px; padding: 9px 11px; cursor: pointer;
  transition: background 0.14s, color 0.14s;
}
.nav-item:hover { background: var(--surface-3); color: var(--text); }
.nav-item.is-active { background: var(--accent-wash); color: var(--accent-ink); }
.nav-ico { display: inline-grid; place-items: center; width: 18px; height: 18px; flex: none; }
.nav-ico svg { width: 18px; height: 18px; }
.nav-item.is-active .nav-ico { color: var(--accent); }

/* ============================= Topbar ============================= */
.topbar {
  grid-area: topbar; display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 0 22px; background: color-mix(in srgb, var(--surface-2) 82%, transparent);
  border-bottom: 1px solid var(--border); backdrop-filter: blur(10px);
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.view-title { font-size: 1.05rem; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); flex: none; }
.live-dot.ok { background: var(--good); box-shadow: 0 0 0 4px color-mix(in srgb, var(--good) 20%, transparent); }
.live-label { font-size: 0.78rem; }

.range-picker { display: flex; background: var(--surface-inset); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.range-btn {
  font: inherit; font-size: 0.8rem; font-weight: 550; color: var(--text-dim);
  background: transparent; border: 0; border-radius: 7px; padding: 5px 11px; cursor: pointer;
  transition: background 0.14s, color 0.14s;
}
.range-btn:hover { color: var(--text); }
.range-btn.is-active { background: var(--surface-3); color: var(--text); box-shadow: var(--shadow); }
.device-select { width: auto; min-width: 120px; padding: 7px 10px; font-size: 0.82rem; }

.ico-light, .ico-dark { display: none; }
:root[data-theme='dark'] .ico-light { display: inline-grid; }
:root[data-theme='light'] .ico-dark { display: inline-grid; }
#themeToggle span { place-items: center; }

/* ============================= Content ============================= */
.content { grid-area: content; overflow-y: auto; padding: 22px; }
.view { display: grid; gap: 18px; max-width: 1360px; margin: 0 auto; animation: viewIn 0.3s cubic-bezier(0.2, 0.7, 0.2, 1); }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .view { animation: none; } }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.stack { display: grid; gap: 18px; align-content: start; }

/* ============================= Panels ============================= */
.panel {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px;
  padding: 18px; box-shadow: var(--shadow); min-width: 0;
}
.panel-wide { grid-column: 1 / -1; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.panel-head h3 { display: flex; align-items: baseline; gap: 6px; }

/* ============================= KPI tiles ============================= */
.kpi-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }
.kpi-strip.kpi-sm { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.kpi {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px 18px; box-shadow: var(--shadow); position: relative;
}
.kpi-label { display: flex; align-items: center; gap: 8px; color: var(--text-dim); font-size: 0.8rem; font-weight: 550; }
.kpi-label .nav-ico { width: 15px; height: 15px; color: var(--kpi-accent, var(--accent)); }
.kpi-label .nav-ico svg { width: 15px; height: 15px; }
.kpi-value { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 2rem; font-weight: 600; letter-spacing: -0.03em; margin-top: 8px; line-height: 1; }
.kpi-delta { display: inline-flex; align-items: center; gap: 4px; font-size: 0.78rem; font-weight: 600; margin-top: 8px; font-variant-numeric: tabular-nums; }
.kpi-delta.up { color: var(--good); }
.kpi-delta.down { color: var(--danger); }
.kpi-delta.flat { color: var(--text-muted); }
.kpi-delta svg { width: 13px; height: 13px; }

/* ============================= Charts ============================= */
.chart-xl { height: 220px; }
.chart-lg { height: 260px; }
.chart-md { height: 190px; }
svg.chart { width: 100%; height: 100%; display: block; overflow: visible; }
.chart-grid line { stroke: var(--grid-line); stroke-width: 1; }
.chart-axis text { fill: var(--text-muted); font-size: 10.5px; font-variant-numeric: tabular-nums; }
.chart-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { stroke: var(--surface-1); stroke-width: 2; }
.bar-rect { rx: 3; }
.crosshair { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 3 3; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--text-dim); }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }

/* floating tooltip (one shared element) */
.viz-tip {
  position: fixed; z-index: 60; pointer-events: none; background: var(--surface-3);
  border: 1px solid var(--border-strong); border-radius: 9px; padding: 8px 11px;
  box-shadow: var(--shadow-pop); font-size: 0.8rem; color: var(--text);
  transform: translate(-50%, calc(-100% - 12px)); transition: opacity 0.1s; max-width: 260px;
}
.viz-tip .tip-row { display: flex; align-items: center; gap: 7px; justify-content: space-between; }
.viz-tip .tip-k { color: var(--text-dim); }
.viz-tip b { font-variant-numeric: tabular-nums; font-family: ui-monospace, Menlo, monospace; }

/* horizontal bars */
.hbars { display: grid; gap: 10px; }
.hbar { display: grid; grid-template-columns: 1fr; gap: 5px; cursor: default; }
.hbar-top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; font-size: 0.84rem; }
.hbar-name { color: var(--text); font-weight: 530; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-val { color: var(--text-dim); font-variant-numeric: tabular-nums; flex: none; }
.hbar-track { height: 8px; background: var(--surface-inset); border-radius: 6px; overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 6px; background: var(--seq); transform-origin: left; animation: barGrow 0.5s cubic-bezier(0.2, 0.7, 0.2, 1); }
@keyframes barGrow { from { transform: scaleX(0); } to { transform: scaleX(1); } }

/* heatmap */
.heatmap { display: grid; gap: 3px; }
.heatmap-row { display: grid; grid-template-columns: 30px repeat(24, 1fr); gap: 3px; align-items: center; }
.heat-cell { aspect-ratio: 1; border-radius: 3px; background: var(--surface-inset); cursor: default; }
.heat-rowlabel, .heat-collabel { font-size: 9.5px; color: var(--text-muted); text-align: center; font-variant-numeric: tabular-nums; }
.heat-rowlabel { text-align: right; padding-right: 2px; }
.heat-cols { display: grid; grid-template-columns: 30px repeat(24, 1fr); gap: 3px; margin-top: 4px; }

/* ============================= Overview bits ============================= */
.mini-map { height: 220px; border-radius: 11px; overflow: hidden; border: 1px solid var(--border); background: var(--surface-inset); }
.stat-row { display: flex; flex-wrap: wrap; gap: 18px; margin-top: 14px; }
.stat { display: grid; gap: 1px; }
.stat-k { font-size: 0.74rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-v { font-family: ui-monospace, Menlo, monospace; font-size: 0.95rem; }

.status-body { display: flex; align-items: center; gap: 14px; }
.status-ring { width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; flex: none; border: 2px solid var(--border-strong); }
.status-ring.home { border-color: var(--good); background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good); }
.status-ring.away { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); }
.status-ring svg { width: 24px; height: 24px; }
.status-text .big { font-size: 1.05rem; font-weight: 650; }
.status-text .sub { color: var(--text-dim); font-size: 0.82rem; }

.peaks { display: grid; gap: 12px; }
.peak { display: flex; align-items: center; gap: 12px; }
.peak-ico { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--surface-inset); color: var(--accent); flex: none; }
.peak-ico svg { width: 17px; height: 17px; }
.peak-main { min-width: 0; }
.peak-k { font-size: 0.76rem; color: var(--text-muted); }
.peak-v { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============================= Timeline / feeds ============================= */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.search-box { display: flex; align-items: center; gap: 8px; background: var(--surface-inset); border: 1px solid var(--border-strong); border-radius: 10px; padding: 0 11px; flex: 1; min-width: 180px; }
.search-box svg { width: 16px; height: 16px; color: var(--text-muted); flex: none; }
.search-box input { border: 0; background: transparent; padding: 9px 0; }
.search-box input:focus { box-shadow: none; }

.chip-row { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  font: inherit; font-size: 0.78rem; font-weight: 550; cursor: pointer;
  padding: 6px 11px; border-radius: 999px; border: 1px solid var(--border-strong);
  background: transparent; color: var(--text-dim); display: inline-flex; align-items: center; gap: 6px;
  transition: background 0.14s, color 0.14s, border-color 0.14s;
}
.chip:hover { color: var(--text); }
.chip.on { background: var(--accent-wash); color: var(--accent-ink); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }

.timeline { display: grid; gap: 2px; position: relative; }
.tl-item { display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; padding: 11px 6px; border-radius: 10px; align-items: start; transition: background 0.12s; }
.tl-item:hover { background: var(--surface-3); }
.tl-ico { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex: none; margin-top: 1px; }
.tl-ico svg { width: 16px; height: 16px; }
.tl-main { min-width: 0; }
.tl-primary { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.tl-secondary { color: var(--text); }
.tl-detail { color: var(--text-dim); font-size: 0.86rem; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.tl-time { color: var(--text-muted); font-size: 0.78rem; white-space: nowrap; font-variant-numeric: tabular-nums; text-align: right; }
.feed-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; }

.feed { display: grid; gap: 2px; }
.feed-item { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 11px 6px; border-radius: 10px; }
.feed-item:hover { background: var(--surface-3); }
.feed-item .fi-head { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.feed-item .fi-body { color: var(--text-dim); font-size: 0.87rem; grid-column: 1; }
.feed-item .fi-time { color: var(--text-muted); font-size: 0.78rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.feed-item .revealed { grid-column: 1 / -1; font-family: ui-monospace, Menlo, monospace; color: var(--accent-ink); }

.badge { font-size: 0.68rem; font-weight: 650; padding: 2px 7px; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.03em; }
.badge-code { background: var(--danger-wash); color: var(--danger); }
.badge-dir { background: var(--surface-inset); color: var(--text-dim); }
.badge svg { width: 11px; height: 11px; vertical-align: -1px; }

/* ============================= Contacts / threads ============================= */
.contact-list { display: grid; gap: 2px; max-height: 420px; overflow-y: auto; }
.contact-row { display: grid; grid-template-columns: 34px 1fr auto; gap: 11px; align-items: center; padding: 9px 8px; border-radius: 10px; cursor: pointer; transition: background 0.12s; }
.contact-row:hover, .contact-row.sel { background: var(--surface-3); }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 650; font-size: 0.8rem; color: #fff; flex: none; }
.contact-name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-sub { font-size: 0.78rem; color: var(--text-muted); }
.contact-counts { display: flex; gap: 10px; font-size: 0.78rem; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.contact-counts span { display: inline-flex; align-items: center; gap: 4px; }
.contact-counts svg { width: 12px; height: 12px; }

.thread { display: grid; gap: 8px; max-height: 440px; overflow-y: auto; padding: 2px; }
.bubble { max-width: 78%; padding: 8px 12px; border-radius: 13px; font-size: 0.88rem; }
.bubble .bt { display: block; font-size: 0.68rem; color: var(--text-muted); margin-top: 3px; font-variant-numeric: tabular-nums; }
.bubble.in { background: var(--surface-3); border-bottom-left-radius: 4px; justify-self: start; }
.bubble.out { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; justify-self: end; }
.bubble.out .bt { color: rgba(255,255,255,0.75); }

/* ============================= Tables ============================= */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.data-table th { text-align: left; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.data-table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tbody tr { transition: background 0.1s; }
.data-table tbody tr:hover { background: var(--surface-3); }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.pill { font-size: 0.72rem; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--surface-inset); color: var(--text-dim); }
.pill.enter, .pill.in { background: color-mix(in srgb, var(--good) 15%, transparent); color: var(--good); }
.pill.exit, .pill.missed { background: var(--danger-wash); color: var(--danger); }
.pill.out { background: var(--accent-wash); color: var(--accent-ink); }

/* ============================= Toggles / switches ============================= */
.switch-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.toggle-inline { display: inline-flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--text-dim); cursor: pointer; width: auto; }
.toggle-inline input { width: auto; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; cursor: pointer; }
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch-track { position: absolute; inset: 0; background: var(--surface-inset); border: 1px solid var(--border-strong); border-radius: 999px; transition: background 0.18s, border-color 0.18s; }
.switch-track::before { content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--text-muted); transition: transform 0.18s, background 0.18s; }
.switch input:checked + .switch-track { background: var(--accent); border-color: transparent; }
.switch input:checked + .switch-track::before { transform: translateX(18px); background: #fff; }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px var(--accent-wash); }

.switch-grid .switch-cell { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 13px; background: var(--surface-inset); border: 1px solid var(--border); border-radius: 11px; font-size: 0.85rem; }

/* ============================= Map view ============================= */
.map-panel { padding-bottom: 14px; }
.map-full { height: min(56vh, 520px); border-radius: 12px; overflow: hidden; border: 1px solid var(--border); background: var(--surface-inset); }
.map-tools { display: flex; gap: 14px; flex-wrap: wrap; }
.playback { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.playback input[type='range'] { flex: 1; accent-color: var(--accent); }
input[type='range'] { accent-color: var(--accent); }
.gf-form { display: grid; gap: 14px; }
.gf-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.gf-grid label, .gf-form > label { display: grid; gap: 6px; font-size: 0.8rem; color: var(--text-dim); font-weight: 550; }
.row-gap { display: flex; gap: 10px; flex-wrap: wrap; }

/* Leaflet surfaces themed */
.leaflet-container { background: var(--surface-inset); font-family: inherit; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface-3); color: var(--text); box-shadow: var(--shadow-pop); }
.leaflet-popup-content { font-size: 0.82rem; }
.leaflet-bar a { background: var(--surface-3); color: var(--text); border-color: var(--border); }
.leaflet-bar a:hover { background: var(--surface-1); }
:root[data-theme='dark'] .leaflet-tile { filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.92) saturate(0.8); }
:root[data-theme='dark'] .leaflet-control-attribution { background: rgba(0,0,0,0.5); color: var(--text-muted); }
.leaflet-control-attribution a { color: var(--text-dim); }

/* ============================= Insights notes ============================= */
.insight-notes { display: grid; gap: 12px; }
.insight-note { display: flex; gap: 12px; align-items: flex-start; padding: 12px; background: var(--surface-inset); border-radius: 11px; }
.insight-note . in-ico { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--accent-wash); color: var(--accent); flex: none; }
.insight-note .in-ico svg { width: 16px; height: 16px; }
.insight-note .in-v { font-weight: 650; font-family: ui-monospace, Menlo, monospace; }
.insight-note .in-k { color: var(--text-dim); font-size: 0.85rem; }

/* ============================= Misc ============================= */
.codebox { background: var(--surface-inset); border: 1px solid var(--border); border-radius: 11px; padding: 14px; font-family: ui-monospace, Menlo, monospace; font-size: 0.82rem; white-space: pre-wrap; word-break: break-all; margin: 14px 0; color: var(--accent-ink); }
.empty { color: var(--text-muted); text-align: center; padding: 28px 10px; }
.danger-panel { border-color: color-mix(in srgb, var(--danger) 30%, var(--border)); }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(10px);
  background: var(--surface-3); color: var(--text); border: 1px solid var(--border-strong);
  border-radius: 11px; padding: 11px 18px; box-shadow: var(--shadow-pop); z-index: 90;
  opacity: 0; transition: opacity 0.2s, transform 0.2s; font-size: 0.86rem; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { border-color: var(--danger); color: var(--danger); }

.bottom-nav { display: none; }
.mobile-only { display: none; }

/* ============================= Responsive ============================= */
@media (max-width: 1100px) {
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 56px 1fr auto;
    grid-template-areas: 'topbar' 'content' 'bottomnav';
    overflow-x: hidden;
  }
  .topbar { min-width: 0; gap: 8px; }
  .topbar-left { flex: 0 0 auto; min-width: 0; }
  .view-title { white-space: nowrap; font-size: 0.98rem; }
  .live-label { display: none; }
  .topbar-right { min-width: 0; gap: 6px; }
  .range-picker { overflow-x: auto; min-width: 0; scrollbar-width: none; flex: 1 1 auto; }
  .range-picker::-webkit-scrollbar { display: none; }
  .range-btn { white-space: nowrap; }
  /* Above Leaflet's map panes (z-index 400–700) so the open rail is clickable over a map. */
  .rail { position: fixed; z-index: 1200; top: 0; bottom: 0; left: 0; width: 240px; transform: translateX(-100%); transition: transform 0.25s cubic-bezier(0.2,0.7,0.2,1); box-shadow: var(--shadow-pop); }
  .rail.open { transform: none; }
  .rail-foot { margin-bottom: 64px; }
  .mobile-only { display: inline-grid; }
  .content { padding: 16px; }
  .kpi-strip { grid-template-columns: 1fr 1fr; gap: 12px; }
  .kpi-value { font-size: 1.6rem; }
  .topbar { padding: 0 14px; }
  .range-picker { padding: 2px; }
  .range-btn { padding: 5px 8px; }
  .device-select { display: none; }
  .bottom-nav {
    grid-area: bottomnav; display: flex; justify-content: space-around; align-items: center;
    background: var(--surface-2); border-top: 1px solid var(--border); padding: 6px 4px 8px;
    position: sticky; bottom: 0;
  }
  .bottom-nav button { background: transparent; border: 0; color: var(--text-muted); display: grid; place-items: center; gap: 2px; font: inherit; font-size: 0.62rem; cursor: pointer; padding: 4px 8px; border-radius: 9px; }
  .bottom-nav button svg { width: 20px; height: 20px; }
  .bottom-nav button.is-active { color: var(--accent); }
}
@media (max-width: 520px) {
  .kpi-strip { grid-template-columns: 1fr 1fr; }
  .kpi-value { font-size: 1.5rem; }
  .delta-cmp { display: none; }
  .gf-grid { grid-template-columns: 1fr 1fr; }
  .tl-item { grid-template-columns: 34px 1fr; }
  .tl-time { grid-column: 2; text-align: left; }
}

/* Backdrop when the mobile rail is open */
.rail-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 1100; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.rail-backdrop.show { opacity: 1; pointer-events: auto; }
