/* post-geo-map — app styles. Tokens on :root; dark via prefers-color-scheme + [data-theme]. */

:root {
  color-scheme: light;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace;

  /* chrome */
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #f3f3f0;
  --surface-3: #ebebe7;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #64625c;
  --link: #1c5cab;
  --line: #e1e0d9;
  --line-strong: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.1);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 6px 24px rgba(0, 0, 0, 0.08);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-wash: rgba(42, 120, 214, 0.1);
  --focus: #2a78d6;
  --good: #006300;
  --bad: #b42323;
  --warn-bg: #fff4d6;

  /* map + chart encodings (read by JS via getComputedStyle) */
  --map-ink: #1b1b1a;
  --map-halo: #ffffff;
  --map-mask: rgba(244, 244, 241, 0.72);
  --map-district: rgba(11, 11, 11, 0.55);
  --map-zones: #4a3aa7;
  --map-route: #1b1b1a;
  --map-straight: #1b1b1a;
  --map-nodata: #d9d8d2;
  --map-cell-edge: #ffffff;
  --cell-edge-opacity: 0.55;
  --map-hub: #eb6834;
  --map-optimal: #4a3aa7;
  --map-added: #4a3aa7;
  --cell-opacity: 0.45;
  /* diverging (UP vs NP: d_up − d_np): blue arm = Ukrposhta closer, orange arm = Nova Poshta closer */
  --div-up-3: #1c5cab; --div-up-2: #3987e5; --div-up-1: #9ec5f4; --div-mid: #f0efec;
  --div-np-1: #efb19b; --div-np-2: #d45e2f; --div-np-3: #9c390c;
  /* sequential blue (magnitude) — light → dark */
  --seq-1: #b7d3f6; --seq-2: #6da7ec; --seq-3: #2a78d6; --seq-4: #1c5cab; --seq-5: #0d366b;
  /* second sequential context (population): orange at matching OKLCH lightness */
  --pop-1: #f2c4b4; --pop-2: #e28969; --pop-3: #c54e1c; --pop-4: #9c390c; --pop-5: #611f02;
  /* categorical slots 1–2: operator identity */
  --cat-1: #2a78d6; --cat-2: #eb6834;
  --chart-grid: #e1e0d9;
  --chart-axis: #c3c2b7;

  --radius: 10px;
  --radius-sm: 7px;
  --header-h: 52px;
  --panel-w: 360px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --dur: 180ms;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f0f0e;
    --surface: #1a1a19;
    --surface-2: #222221;
    --surface-3: #2b2b29;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #9a988f;
    --line: #2c2c2a;
    --line-strong: #43433f;
    --ring: rgba(255, 255, 255, 0.1);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 28px rgba(0, 0, 0, 0.45);
    --accent: #3987e5;
    --accent-ink: #ffffff;
    --accent-wash: rgba(57, 135, 229, 0.16);
    --focus: #6da7ec; --link: #86b6ef;
    --good: #2fbf4a;
    --bad: #f07272;
    --warn-bg: #3a2f12;
    --map-ink: #f4f4f1;
    --map-halo: #111111;
    --map-mask: rgba(10, 10, 10, 0.7);
    --map-district: rgba(255, 255, 255, 0.55);
    --map-zones: #9085e9;
    --map-route: #f4f4f1;
    --map-straight: #f4f4f1;
    --map-nodata: #333331;
    --map-cell-edge: #111111;
    --cell-edge-opacity: 0.45;
    --div-up-3: #86b6ef; --div-up-2: #3987e5; --div-up-1: #184f95; --div-mid: #383835;
    --div-np-1: #883008; --div-np-2: #d45e2f; --div-np-3: #e89d83;
    --map-hub: #ef7a45;
    --map-optimal: #9085e9;
    --map-added: #9085e9;
    --cell-opacity: 0.5;
    --seq-1: #104281; --seq-2: #1c5cab; --seq-3: #3987e5; --seq-4: #6da7ec; --seq-5: #b7d3f6;
    --pop-1: #752601; --pop-2: #9c390c; --pop-3: #d45e2f; --pop-4: #e28969; --pop-5: #f2c4b4;
    --cat-1: #3987e5; --cat-2: #d95926;
    --chart-grid: #2c2c2a;
    --chart-axis: #43433f;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f0f0e;
  --surface: #1a1a19;
  --surface-2: #222221;
  --surface-3: #2b2b29;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #9a988f;
  --line: #2c2c2a;
  --line-strong: #43433f;
  --ring: rgba(255, 255, 255, 0.1);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 28px rgba(0, 0, 0, 0.45);
  --accent: #3987e5;
  --accent-ink: #ffffff;
  --accent-wash: rgba(57, 135, 229, 0.16);
  --focus: #6da7ec; --link: #86b6ef;
  --good: #2fbf4a;
  --bad: #f07272;
  --warn-bg: #3a2f12;
  --map-ink: #f4f4f1;
  --map-halo: #111111;
  --map-mask: rgba(10, 10, 10, 0.7);
  --map-district: rgba(255, 255, 255, 0.55);
  --map-zones: #9085e9;
  --map-route: #f4f4f1;
  --map-straight: #f4f4f1;
  --map-nodata: #333331;
  --map-cell-edge: #111111;
  --cell-edge-opacity: 0.45;
  --div-up-3: #86b6ef; --div-up-2: #3987e5; --div-up-1: #184f95; --div-mid: #383835;
  --div-np-1: #883008; --div-np-2: #d45e2f; --div-np-3: #e89d83;
  --map-hub: #ef7a45;
  --map-optimal: #9085e9;
  --map-added: #9085e9;
  --cell-opacity: 0.5;
  --seq-1: #104281; --seq-2: #1c5cab; --seq-3: #3987e5; --seq-4: #6da7ec; --seq-5: #b7d3f6;
  --pop-1: #752601; --pop-2: #9c390c; --pop-3: #d45e2f; --pop-4: #e28969; --pop-5: #f2c4b4;
  --cat-1: #3987e5; --cat-2: #d95926;
  --chart-grid: #2c2c2a;
  --chart-axis: #43433f;
}

/* ------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
/* app shell: the root never scrolls (focusing an off-screen control must not shift the layout) */
html, body { height: 100%; overflow: hidden; overflow: clip; }
body {
  margin: 0;
  font: 14px/1.45 var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
p { margin: 0 0 .6em; }
a { color: var(--link, var(--accent)); text-underline-offset: 2px; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.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: 8px; top: -40px; z-index: 50; padding: 8px 12px;
  background: var(--surface); color: var(--ink); border-radius: var(--radius-sm); box-shadow: var(--shadow);
}
.skip-link:focus { top: 8px; }
.tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ app bar */
.appbar {
  position: relative; z-index: 20;
  height: var(--header-h);
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 26px; height: 26px; flex: none; }
.brand-mark .bg { fill: var(--accent); }
.brand-title { font-size: 15px; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar-spacer { flex: 1; }
.appbar .select { height: 32px; }
.appbar-actions { display: flex; align-items: center; gap: 8px; }

/* ------------------------------------------------------------------ controls */
.select, .input {
  height: 34px; padding: 0 10px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  min-width: 0;
}
.select { padding-right: 28px; appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
.input::placeholder { color: var(--muted); }
.select:hover, .input:hover { border-color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font-weight: 500; white-space: nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.06); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-icon { width: 32px; padding: 0; }
.btn svg { width: 16px; height: 16px; flex: none; }

/* segmented control (radio inputs or aria-pressed buttons) */
.seg {
  display: inline-flex; padding: 2px; gap: 2px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px;
  max-width: 100%;
}
.seg.block { display: flex; }
.seg > label, .seg > button { flex: 1; position: relative; display: flex; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span, .seg > button {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 28px; padding: 0 10px; border-radius: 7px; border: 0;
  background: transparent; color: var(--ink-2); font-weight: 500; font-size: 13px; white-space: nowrap;
  cursor: pointer; user-select: none;
}
.seg span:hover, .seg > button:hover { color: var(--ink); }
.seg input:checked + span, .seg > button[aria-pressed="true"] {
  background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--ring), 0 1px 2px rgba(0,0,0,.08);
}
.seg input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 1px; }
.seg svg { width: 15px; height: 15px; }

/* checkbox rows */
.check { display: flex; align-items: center; gap: 9px; min-height: 30px; cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); flex: none; }
.check .key { margin-left: auto; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip > span {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px;
  border: 1px solid var(--line-strong); border-radius: 999px; font-size: 13px; color: var(--ink-2);
  cursor: pointer; user-select: none; background: var(--surface);
}
.chip > span::before {
  content: ""; width: 12px; height: 12px; border-radius: 3px; border: 1.5px solid var(--muted); flex: none;
}
.chip input:checked + span { color: var(--ink); border-color: var(--accent); background: var(--accent-wash); }
.chip input:checked + span::before {
  border-color: var(--accent); background: var(--accent)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 6.2 5 8.5l4.5-5' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/10px no-repeat;
}
.chip input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.chip .count { color: var(--muted); font-variant-numeric: tabular-nums; }

/* switch */
.switch { position: relative; display: flex; align-items: center; gap: 10px; cursor: pointer; min-height: 32px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  width: 34px; height: 20px; border-radius: 999px; background: var(--line-strong); position: relative; flex: none;
  transition: background var(--dur) var(--ease);
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform var(--dur) var(--ease);
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(14px); }
.switch input:focus-visible + .track { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ------------------------------------------------------------------ layout */
.layout { position: relative; height: calc(100% - var(--header-h)); display: flex; }
.panel {
  position: relative; z-index: 10;
  width: var(--panel-w); flex: none; height: 100%;
  display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--line);
  transition: margin-left 220ms var(--ease);
}
.panel.collapsed { margin-left: calc(-1 * var(--panel-w)); }
.panel-collapse {
  position: absolute; top: 12px; right: -33px; z-index: 11;
  width: 32px; height: 40px; display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--line); border-left: 0;
  border-radius: 0 8px 8px 0; color: var(--ink-2);
}
.panel-collapse svg { width: 16px; height: 16px; transition: transform var(--dur) var(--ease); }
.panel.collapsed .panel-collapse svg { transform: rotate(180deg); }
.sheet-handle { display: none; }

.tabs {
  display: flex; gap: 2px; padding: 8px 10px 0; border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none; flex: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; padding: 8px 10px 10px; border: 0; background: none; color: var(--ink-2);
  font-weight: 500; white-space: nowrap; border-radius: 6px 6px 0 0;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); }
.tab[aria-selected="true"]::after {
  content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px; border-radius: 2px;
  background: var(--accent);
}
.panel-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; }
.tabpanel { padding: 4px 16px 24px; }

.section { padding: 14px 0; border-bottom: 1px solid var(--line); }
.section:last-child { border-bottom: 0; }
.section-h {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 12px; font-weight: 600; letter-spacing: .02em; color: var(--ink-2); margin-bottom: 8px;
}
.section-h .hint { font-weight: 400; color: var(--muted); letter-spacing: 0; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 8px; }
.row > .grow { flex: 1; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12px; color: var(--ink-2); }
.help { font-size: 12px; color: var(--muted); margin: 6px 0 0; }

/* hub picker */
.hub-current {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  background: var(--surface-2); border-radius: var(--radius-sm); min-height: 44px;
}
.hub-current .glyph { width: 18px; height: 18px; flex: none; color: var(--map-hub); }
.hub-current .name { font-weight: 500; line-height: 1.25; }
.hub-current .sub { font-size: 12px; color: var(--muted); }
.combo { position: relative; }
.combo .input { width: 100%; padding-left: 32px; }
.combo .search-ico { position: absolute; left: 10px; top: 9px; width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.listbox {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px);
  max-height: 260px; overflow-y: auto; margin: 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow);
}
.listbox li { padding: 7px 8px; border-radius: 5px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; }
.listbox li .pc { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; min-width: 42px; }
.listbox li[aria-selected="true"], .listbox li:hover { background: var(--accent-wash); }
.listbox .empty { color: var(--muted); cursor: default; }

/* layer list */
.layers { display: grid; grid-template-columns: 1fr; gap: 0; }
.key { display: inline-block; flex: none; }
.key-fill { width: 14px; height: 14px; border-radius: 3px; }
.key-line { width: 18px; height: 0; border-top: 2px solid var(--map-ink); }
.key-dash { width: 18px; height: 0; border-top: 2px dashed var(--map-ink); }
.key-thin { width: 18px; height: 0; border-top: 1px solid var(--map-ink); opacity: .55; }
.key-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--map-ink); box-shadow: 0 0 0 2px var(--surface); }
.key-ramp { width: 26px; height: 10px; border-radius: 2px; }

/* scenario */
.scenario-box { padding: 10px 12px; border: 1px dashed var(--line-strong); border-radius: var(--radius); }
.scenario-box.on { border-style: solid; border-color: var(--map-added); background: color-mix(in srgb, var(--map-added) 7%, transparent); }
.scenario-counts { font-size: 13px; color: var(--ink-2); }

.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.btn-grid .btn { width: 100%; }

/* ------------------------------------------------------------------ KPI tiles */
.scope-line { font-size: 13px; color: var(--ink-2); margin: 10px 0 2px; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.kpi {
  padding: 10px 12px 11px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
  min-width: 0; transition: opacity var(--dur) var(--ease);
}
.kpi .label { font-size: 12px; color: var(--ink-2); line-height: 1.3; min-height: 2.6em; }
.kpi .value { font-size: 21px; font-weight: 600; letter-spacing: -.01em; line-height: 1.2; margin-top: 4px; overflow-wrap: anywhere; }
.kpi .value small { font-size: 13px; font-weight: 500; color: var(--ink-2); }
.kpi .delta { font-size: 12px; margin-top: 3px; font-variant-numeric: tabular-nums; }
.kpi .delta.good { color: var(--good); }
.kpi .delta.bad { color: var(--bad); }
.kpi .delta.neutral { color: var(--muted); }
.kpi.wide { grid-column: span 2; }
.is-stale { opacity: .55; }

/* ------------------------------------------------------------------ charts */
.card { margin-top: 14px; padding: 12px 12px 10px; border: 1px solid var(--line); border-radius: var(--radius); }
.card-h { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.card-h h3 { font-size: 13px; }
.card-sub { font-size: 12px; color: var(--muted); margin: 2px 0 6px; }
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.chart .grid line { stroke: var(--chart-grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .axis line, .chart .axis path { stroke: var(--chart-axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .bar { fill: var(--seq-3); }
.chart .bar.within { fill: var(--seq-3); }
.chart .bar.beyond { fill: var(--seq-2); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart .hit:focus + .bar, .chart .bar.hover { filter: brightness(1.12); }
.chart .ref { stroke: var(--line-strong); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--seq-3); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--seq-3); opacity: .1; }
.chart .marker { fill: var(--seq-3); stroke: var(--surface); stroke-width: 2; }
.chart .crosshair { stroke: var(--line-strong); stroke-width: 1; }
.chart .label-strong { fill: var(--ink); font-weight: 600; }
.chart .dumb-up { fill: var(--cat-1); stroke: var(--surface); stroke-width: 2; }
.chart .dumb-np { fill: var(--cat-2); stroke: var(--surface); stroke-width: 2; }
.chart .dumb-link { stroke: var(--line-strong); stroke-width: 2; stroke-linecap: round; }
.chart .row-label { fill: var(--ink-2); font-size: 12px; }
.chart-tip {
  position: absolute; z-index: 5; pointer-events: none; min-width: 120px;
  padding: 7px 9px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow); font-size: 12px; white-space: nowrap;
}
.chart-tip strong { display: block; font-size: 14px; }
.chart-tip .k { color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.chart-tip .lk { width: 12px; height: 0; border-top: 2px solid; display: inline-block; }
.legend-inline { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--ink-2); margin: 2px 0 6px; }
.legend-inline .sw { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
details.table-view { margin-top: 6px; }
details.table-view summary { cursor: pointer; font-size: 12px; color: var(--ink-2); padding: 4px 0; width: max-content; }
details.table-view summary:hover { color: var(--ink); }

/* tables */
.table-wrap { overflow-x: auto; margin-top: 6px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
table.data { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.data th, table.data td { padding: 6px 8px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
table.data th:first-child, table.data td:first-child { text-align: left; white-space: normal; }
table.data td { font-variant-numeric: tabular-nums; }
table.data thead th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; color: var(--ink-2); font-size: 12px; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: var(--surface-2); }
table.data tbody tr.is-focus td { background: var(--accent-wash); }
table.data th button {
  all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 3px; border-radius: 3px;
}
table.data th button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
table.data th button .arr { font-size: 10px; color: var(--muted); width: 8px; }
table.data tr.total td, table.data tr.total th { font-weight: 600; background: var(--surface-2); }
.linkish { all: unset; cursor: pointer; color: var(--ink); text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px; border-radius: 3px; }
.linkish:hover { text-decoration-color: var(--ink); }
.linkish:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* compare */
.reading { font-size: 14px; line-height: 1.55; margin: 12px 0 4px; }
.reading strong { font-weight: 600; }
.vs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.vs .kpi .label { min-height: 0; display: flex; align-items: center; gap: 6px; }
.op-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.vs abbr { text-decoration: none; cursor: help; }
.op-dot.up { background: var(--cat-1); }
.op-dot.np { background: var(--cat-2); }

/* about */
.prose { font-size: 13.5px; line-height: 1.6; color: var(--ink); }
.prose h3 { font-size: 13px; margin: 16px 0 6px; }
.prose ul { margin: 0 0 8px; padding-left: 18px; }
.prose li { margin-bottom: 4px; }
.sources { list-style: none; padding: 0; margin: 8px 0 0; }
.sources li { padding: 9px 0; border-bottom: 1px solid var(--line); }
.sources li:last-child { border-bottom: 0; }
.sources .src-name { font-weight: 500; }
.sources .src-meta { font-size: 12px; color: var(--muted); }
.badge {
  display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: var(--surface-3); color: var(--ink-2); vertical-align: 1px;
}
.callout { padding: 9px 11px; border-radius: var(--radius-sm); background: var(--warn-bg); font-size: 12.5px; margin-top: 10px; }

/* empty / error states */
.empty-state { padding: 22px 6px; text-align: center; color: var(--muted); font-size: 13px; }
.empty-state svg { width: 28px; height: 28px; display: block; margin: 0 auto 8px; color: var(--line-strong); }

/* ------------------------------------------------------------------ map */
.map-wrap { position: relative; flex: 1; min-width: 0; height: 100%; }
#map { position: absolute; inset: 0; background: var(--bg); }
#map.picking .maplibregl-canvas-container, #map.scenario .maplibregl-canvas-container { cursor: crosshair; }

.map-status {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 5;
  display: flex; align-items: center; gap: 8px; padding: 6px 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow);
  font-size: 12.5px; color: var(--ink-2); white-space: nowrap;
  opacity: 0; transition: opacity 240ms var(--ease); pointer-events: none;
}
.map-status.show { opacity: 1; }
.spinner {
  width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line-strong); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.scenario-banner {
  position: absolute; top: 12px; left: 48px; z-index: 5; max-width: calc(100% - 110px);
  display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 12px;
  background: var(--surface); border: 1px solid var(--map-added); border-radius: 999px; box-shadow: var(--shadow);
  font-size: 12.5px;
}
.scenario-banner .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--map-added); flex: none; }

.legend {
  position: absolute; left: 12px; bottom: 28px; z-index: 4;
  width: 248px; max-width: calc(100% - 24px);
  padding: 10px 12px; background: color-mix(in srgb, var(--surface) 94%, transparent);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  font-size: 12px; backdrop-filter: blur(6px);
}
.legend h4 { font-size: 12px; font-weight: 600; margin-bottom: 6px; display: flex; justify-content: space-between; gap: 8px; }
.legend h4 button { all: unset; cursor: pointer; color: var(--muted); font-weight: 400; border-radius: 3px; }
.legend h4 button:focus-visible { outline: 2px solid var(--focus); }
.legend .ramp { display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; }
.legend .ramp i { height: 10px; display: block; }
.legend .ramp i:first-child { border-radius: 3px 0 0 3px; }
.legend .ramp i:last-child { border-radius: 0 3px 3px 0; }
.legend .block-title { color: var(--ink-2); margin-bottom: 5px; }
.legend .ramp-labels { position: relative; height: 15px; margin-top: 3px; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 11px; }
.legend .ramp-labels span { position: absolute; top: 0; transform: translateX(-50%); white-space: nowrap; }
.key-dot.hollow { background: var(--surface); box-shadow: inset 0 0 0 1.6px var(--map-ink); }
.key-dot.added { background: var(--map-added); width: 12px; height: 12px; }
.legend .block + .block { margin-top: 9px; padding-top: 8px; border-top: 1px solid var(--line); }
.legend .items { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; color: var(--ink-2); }
.legend .items > div { display: flex; align-items: center; gap: 7px; min-width: 0; }
.legend.collapsed .body { display: none; }
.legend .div-ends { display: flex; justify-content: space-between; color: var(--ink-2); margin-bottom: 4px; }
.legend .items .span2 { grid-column: span 2; }
.key-hex { width: 14px; height: 12px; border: 2px solid var(--map-ink); clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%); background: transparent; }
.legend .flow-keys { display: flex; gap: 14px; align-items: center; color: var(--ink-2); }
.legend .flow-keys > div { display: flex; align-items: center; gap: 6px; }
.legend .flow-line { display: inline-block; width: 22px; border-top: 2px solid var(--map-route); border-radius: 2px; }
.legend.collapsed h4 { margin: 0; }
.lk-star { width: 14px; height: 14px; flex: none; }

.map-tooltip {
  position: absolute; z-index: 6; pointer-events: none; max-width: 260px;
  padding: 8px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow); font-size: 12px; line-height: 1.4;
}
.map-tooltip .t-title { font-weight: 600; font-size: 13px; }
.map-tooltip .t-sub { color: var(--muted); margin-bottom: 4px; }
.map-tooltip dl { display: grid; grid-template-columns: auto auto; gap: 1px 12px; margin: 0; }
.map-tooltip dt { color: var(--ink-2); }
.map-tooltip dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

/* MapLibre popup + controls, themed */
.maplibregl-popup-content {
  background: var(--surface); color: var(--ink); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px; border: 1px solid var(--line); font: 13px/1.45 var(--font); min-width: 240px;
}
.maplibregl-popup-tip { border-top-color: var(--surface) !important; border-bottom-color: var(--surface) !important; }
.maplibregl-popup-close-button { font-size: 18px; width: 28px; height: 28px; color: var(--muted); border-radius: 6px; right: 4px; top: 4px; }
.maplibregl-popup-close-button:hover { background: var(--surface-2); }
.pop h3 { font-size: 14px; padding-right: 22px; line-height: 1.3; }
.pop .sub { color: var(--muted); font-size: 12px; margin: 2px 0 8px; }
.pop dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0 0 10px; }
.pop dt { color: var(--ink-2); font-size: 12px; }
.pop dd { margin: 0; font-size: 12.5px; overflow-wrap: anywhere; }
.pop .status-open::before, .pop .status-closed::before, .pop .status-unknown::before {
  content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; vertical-align: 1px;
}
.pop .status-open::before { background: #0ca30c; }
.pop .status-closed::before { background: #d03b3b; }
.pop .status-unknown::before { background: var(--muted); }
.pop .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.maplibregl-ctrl-group { background: var(--surface); box-shadow: 0 0 0 1px var(--line) !important; }
.maplibregl-ctrl-group button + button { border-top-color: var(--line); }
.maplibregl-ctrl button .maplibregl-ctrl-icon { filter: none; }
:root[data-theme-resolved="dark"] .maplibregl-ctrl button .maplibregl-ctrl-icon { filter: invert(1) hue-rotate(180deg); }
.maplibregl-ctrl-attrib { background: color-mix(in srgb, var(--surface) 85%, transparent) !important; color: var(--ink-2); font-size: 11px; }
.maplibregl-ctrl-attrib .maplibregl-ctrl-attrib-inner, .maplibregl-ctrl-attrib a { color: var(--ink-2) !important; }
.maplibregl-ctrl-attrib-button { background-color: var(--surface) !important; }
:root[data-theme-resolved="dark"] .maplibregl-ctrl-attrib-button { filter: invert(1); }

/* draggable hypothetical office marker */
.added-marker {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--map-added); color: #fff; border: 2px solid var(--map-halo);
  box-shadow: 0 1px 4px rgba(0,0,0,.35); cursor: grab; touch-action: none;
}
.added-marker:active { cursor: grabbing; }
.added-marker svg { width: 14px; height: 14px; }
.added-marker:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ------------------------------------------------------------------ toasts */
.toasts {
  position: fixed; z-index: 60; left: 50%; bottom: 20px; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; align-items: center; width: min(420px, calc(100% - 24px));
  pointer-events: none;
}
.toast {
  pointer-events: auto; width: 100%; display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px; background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  border-left: 3px solid var(--accent); border-radius: var(--radius-sm); box-shadow: var(--shadow); font-size: 13px;
  animation: toast-in 200ms var(--ease);
}
.toast.error { border-left-color: #d03b3b; }
.toast.ok { border-left-color: #0ca30c; }
.toast .msg { flex: 1; overflow-wrap: anywhere; }
.toast button { all: unset; cursor: pointer; color: var(--muted); padding: 0 4px; border-radius: 3px; }
.toast button:focus-visible { outline: 2px solid var(--focus); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* ------------------------------------------------------------------ phone: bottom sheet */
@media (max-width: 768px) {
  :root { --header-h: 48px; }
  .appbar { padding: 0 8px 0 10px; gap: 6px; }
  .brand-title .long { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .brand-mark { width: 24px; height: 24px; }
  .appbar .select { max-width: 92px; }
  .appbar .seg span, .appbar .seg > button { padding: 0 7px; }
  #share-btn .label { display: none; }
  #share-btn { width: 32px; padding: 0; }
  .layout { display: block; }
  .map-wrap { position: absolute; inset: 0; }
  .panel {
    position: absolute; left: 0; right: 0; bottom: 0; width: auto; height: var(--sheet-h, 42%);
    min-height: 96px; max-height: calc(100% - 8px);
    border-right: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0;
    box-shadow: 0 -6px 24px rgba(0,0,0,.14); margin-left: 0 !important;
    transition: height 240ms var(--ease);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .panel.dragging { transition: none; }
  .panel-collapse { display: none; }
  .sheet-handle { display: flex; justify-content: center; flex: none; }
  .sheet-handle button {
    width: 100%; height: 22px; border: 0; background: none; display: grid; place-items: center; touch-action: none; cursor: grab;
  }
  .sheet-handle .grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line-strong); }
  .tabs { padding-top: 0; }
  .tabpanel { padding: 2px 14px 20px; }
  .legend { bottom: auto; top: 10px; left: 10px; width: 210px; padding: 8px 10px; }
  .scenario-banner { top: auto; bottom: calc(var(--sheet-h, 42%) + 10px); left: 10px; }
  .map-status { top: auto; bottom: calc(var(--sheet-h, 42%) + 10px); }
  .toasts { bottom: auto; top: calc(var(--header-h) + 8px); }
  .maplibregl-ctrl-bottom-right, .maplibregl-ctrl-bottom-left { bottom: var(--sheet-h, 42%); }
  .maplibregl-ctrl-top-right { top: 0; }
  .map-tooltip { max-width: 220px; }
  .maplibregl-popup-content { min-width: 0; max-width: 280px; }
}
.appbar #theme-menu { display: none; }
@media (max-width: 400px) {
  .appbar #theme-toggle { display: none; }
  .appbar #theme-menu { display: inline-flex; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
}

@media (forced-colors: active) {
  .seg input:checked + span, .seg > button[aria-pressed="true"], .tab[aria-selected="true"] { outline: 2px solid CanvasText; }
}
