/* Polokwane Projects Ledger — Smooth Modern Explorer
   Buttery smooth interactions, zero layout shifts, refined typography, and tactile modern cards. */

:root, [data-theme-mode="light"] {
  --paper: #F8F9FA;
  --panel: #FFFFFF;
  --ink: #0F172A;
  --muted: #64748B;
  --line: #E2E8F0;
  --grid: #F1F5F9;
  --ok: #16A34A;
  --prog: #D97706;
  --fund: #2563EB;
  --cut: #94A3B8;
  --more: #DC2626;

  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --radius-full: 999px;

  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.07), 0 2px 4px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 25px -3px rgba(15, 23, 42, 0.1), 0 4px 6px -2px rgba(15, 23, 42, 0.05);
  --shadow-drawer: -12px 0 36px rgba(15, 23, 42, 0.18);

  --head: "Inter Tight", "Inter", system-ui, -apple-system, sans-serif;
  --serif: "Inter", system-ui, -apple-system, sans-serif;
  --font: var(--head);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme-mode="light"]) {
    --paper: #0B0F17;
    --panel: #131A26;
    --ink: #F1F5F9;
    --muted: #94A3B8;
    --line: #222F43;
    --grid: #1A2333;
    --ok: #34D399;
    --prog: #FBBF24;
    --fund: #60A5FA;
    --cut: #94A3B8;
    --more: #F87171;
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.6);
    --shadow-drawer: -12px 0 40px rgba(0, 0, 0, 0.7);
  }
}

[data-theme-mode="dark"] {
  --paper: #0B0F17;
  --panel: #131A26;
  --ink: #F1F5F9;
  --muted: #94A3B8;
  --line: #222F43;
  --grid: #1A2333;
  --ok: #34D399;
  --prog: #FBBF24;
  --fund: #60A5FA;
  --cut: #94A3B8;
  --more: #F87171;
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.6);
  --shadow-drawer: -12px 0 40px rgba(0, 0, 0, 0.7);
}

*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0; background: var(--paper); color: var(--ink); font-family: var(--serif); font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility;
  font-feature-settings: "cv11", "ss01";
}
body.drawer-open { overflow: hidden; }

button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--fund); outline-offset: 2px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* ---------- sticky top nav bar ---------- */
.strip {
  position: sticky; top: 0; z-index: 1050;
  display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 20px; background: color-mix(in srgb, var(--panel) 92%, transparent);
  color: var(--ink); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line); box-shadow: var(--shadow-xs);
  transition: background-color 0.2s ease, border-color 0.2s ease;
}
.strip-brand { display: flex; align-items: center; gap: 10px; }
.strip-title { font: 800 13.5px var(--head); letter-spacing: -.01em; color: var(--ink); white-space: nowrap; }
.strip-sub { font: 500 12px var(--serif); color: var(--muted); white-space: nowrap; }
@media (max-width: 640px) { .strip-sub { display: none; } }

.strip-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.nav-tabs { display: inline-flex; align-items: center; background: var(--grid); padding: 3px; border-radius: var(--radius-full); }
.nav-tab {
  border: 0; background: transparent; color: var(--muted);
  padding: 6px 14px; font: 600 12px var(--serif); cursor: pointer; border-radius: var(--radius-full);
  display: inline-flex; align-items: center; gap: 6px; transition: all 0.2s var(--ease);
}
.nav-tab:hover { color: var(--ink); }
.nav-tab.active { background: var(--panel); color: var(--fund); font-weight: 700; box-shadow: var(--shadow-sm); }
.tab-icon { font-size: 13px; }

.strip-actions { display: flex; align-items: center; gap: 8px; }
.theme-picker-wrap { position: relative; }
.theme-select {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: var(--radius-md); padding: 6px 10px; font: 600 12px var(--serif); cursor: pointer;
  box-shadow: var(--shadow-xs); transition: all 0.15s var(--ease);
}
.theme-select:hover { border-color: var(--muted); }
.theme-select option { background: var(--panel); color: var(--ink); }
.mode-btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: var(--radius-md); padding: 5px 9px; font-size: 14px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; box-shadow: var(--shadow-xs);
  transition: transform 0.2s var(--ease), border-color 0.15s ease;
}
.mode-btn:hover { border-color: var(--fund); transform: scale(1.06); }

/* ---------- masthead / hero ---------- */
.mast {
  max-width: 1380px; margin: 0 auto; padding: 24px 20px 20px;
  border-bottom: 1px solid var(--line); transition: padding 0.25s var(--ease);
}
.mast-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.kicker { margin: 0; font: 700 12px var(--serif); letter-spacing: .06em; text-transform: uppercase; color: var(--fund); }
.collapse-btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  border-radius: var(--radius-full); padding: 4px 10px; font: 600 11.5px var(--serif); cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; box-shadow: var(--shadow-xs); transition: all 0.15s var(--ease);
}
.collapse-btn:hover { color: var(--ink); border-color: var(--ink); }
.collapse-icon { font-size: 9px; transition: transform 0.2s ease; }

.mast.compact { padding: 12px 20px 14px; }
.mast.compact .mast-content { display: none; }
.mast.compact .tally { margin-top: 6px; }
.mast.compact .stat { padding: 10px 14px; }
.mast.compact .stat b { font-size: 22px; }
.mast.compact .collapse-icon { transform: rotate(180deg); }

h1 { font-family: var(--head); font-weight: 800; font-size: clamp(28px, 4vw, 44px); line-height: 1.1; letter-spacing: -.02em; margin: 0 0 10px; max-width: 22ch; }
.dek { font-family: var(--serif); font-size: clamp(15px, 1.5vw, 16.5px); line-height: 1.55; color: var(--muted); margin: 0; max-width: 66ch; }

/* Interactive tally cards */
.tally {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-top: 18px;
}
.stat {
  padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--panel);
  box-shadow: var(--shadow-xs); cursor: pointer; transition: all 0.2s var(--ease); text-align: left; user-select: none;
}
.stat:hover {
  transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: color-mix(in srgb, var(--ink) 25%, var(--line));
}
.stat.active {
  border-color: var(--more); box-shadow: 0 0 0 2px var(--more), var(--shadow-md); background: color-mix(in srgb, var(--more) 5%, var(--panel));
}
.stat b {
  display: block; font: 800 clamp(24px, 3.2vw, 34px) var(--head); letter-spacing: -.02em; line-height: 1.05; font-variant-numeric: tabular-nums;
}
.stat span {
  display: block; margin-top: 4px; font: 500 12px var(--serif); color: var(--muted); line-height: 1.35;
}
.stat.more b { color: var(--more); }
.stat.cut b { color: var(--muted); }

/* ---------- main layout: explorer ---------- */
#viewExplorer { max-width: 1380px; margin: 0 auto; padding: 20px 20px 40px; display: grid; gap: 24px; }
@media (min-width: 900px) {
  #viewExplorer { grid-template-columns: minmax(0, 1.35fr) minmax(380px, 1.05fr); align-items: start; }
  .mapwrap { position: sticky; top: 68px; height: calc(100vh - 90px); min-height: 600px; display: flex; flex-direction: column; }
  #map { flex: 1 1 auto; height: 100% !important; min-height: 420px; }
}
.side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.side-header { display: flex; align-items: center; justify-content: space-between; border-bottom: 2px solid var(--line); padding-bottom: 8px; }
.sect { margin: 0; font: 800 19px var(--head); letter-spacing: -.01em; }
.count-badge { font: 700 11.5px var(--head); background: var(--grid); color: var(--muted); padding: 3px 8px; border-radius: var(--radius-full); }

/* ---------- map styling & quick controls ---------- */
.mapwrap {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md); position: relative; overflow: hidden;
}
#map { height: min(64vh, 600px); background: var(--grid); }
.tiles-street { filter: grayscale(.85) contrast(.95) brightness(1.04); }

.map-toolbar {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.map-toolbar-left { display: flex; gap: 6px; align-items: center; }
.map-ctrl-btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 5px 12px;
  border-radius: var(--radius-full); font: 600 12px var(--serif); cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px; box-shadow: var(--shadow-xs);
  transition: all 0.15s var(--ease);
}
.map-ctrl-btn:hover { background: var(--grid); border-color: var(--muted); }
.map-ctrl-btn[aria-pressed="true"] { background: var(--fund); color: #fff; border-color: var(--fund); }
.ctrl-icon { font-size: 13px; }

.map-filter-pill {
  font: 600 11.5px var(--serif); background: var(--fund); color: #fff; padding: 4px 12px; border-radius: var(--radius-full);
  display: inline-flex; align-items: center; gap: 6px; box-shadow: var(--shadow-xs);
}
.map-filter-pill button { border: 0; background: none; color: #fff; cursor: pointer; font-size: 13px; font-weight: 700; padding: 0; }

.mapnote { margin: 0; padding: 7px 12px; font: 12px var(--serif); color: var(--muted); border-top: 1px solid var(--line); background: var(--panel); }

.legend-wrap { border-top: 1px solid var(--line); background: var(--panel); }
.legend-toggle {
  width: 100%; border: 0; background: none; padding: 6px 12px; font: 600 11px var(--serif); text-transform: uppercase;
  color: var(--muted); display: flex; justify-content: space-between; align-items: center; cursor: pointer;
}
.legend-toggle:hover { color: var(--ink); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 6px 12px 10px; font: 500 12px var(--serif); color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.swr { width: 13px; height: 13px; border-radius: 50%; display: inline-block; border: 2.5px solid var(--more); }
.swc { width: 13px; height: 13px; border-radius: 50%; display: inline-block; border: 2px dashed var(--cut); }
.swward { width: 16px; height: 10px; display: inline-block; border: 1.5px solid var(--ink); border-radius: 2px; }
.swroad { width: 18px; height: 4px; display: inline-block; background: var(--fund); border-radius: 2px; }
.swapprox {
  width: 14px; height: 14px; border-radius: 50%; display: inline-block; position: relative;
  background: color-mix(in srgb, var(--fund) 25%, transparent); border: 1px solid var(--fund);
}
.swapprox::after { content: ""; position: absolute; inset: 3px; border-radius: 50%; background: var(--fund); }

/* Ward shading legend */
.shadebar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding: 8px 12px; border-top: 1px solid var(--line); }
.shadeleg { border: 0; padding: 0 12px 8px; font-size: 11.5px; }
.sw.sq { border-radius: 2px; width: 14px; height: 11px; }
.sw.none { background: var(--paper); border: 1px solid var(--line); }

/* Pins (Google AdvancedMarker & Leaflet divIcon) */
.pinwrap { background: none; border: 0; overflow: visible; }
.pinwrap .pin { transform: none; }
.leaflet-control-layers-scrollbar { overflow: visible; padding-right: 0; }
.leaflet-container { font-family: var(--head); border-radius: var(--radius-lg); }
.leaflet-bar a, .leaflet-control-layers { border-radius: var(--radius-sm) !important; border-color: var(--line) !important; }

.pin { position: relative; width: 16px; height: 16px; padding: 0; border: 0; background: none; cursor: pointer; transform: translateY(50%); transition: opacity .15s; }
.pin .dot { position: absolute; inset: 0; border-radius: 50%; background: var(--c); border: 2px solid #FFFFFF; box-shadow: 0 1px 4px rgba(0,0,0,.35); }
.pin .ring { position: absolute; inset: -6px; border-radius: 50%; display: none; }
.pin[data-money="more"] .ring, .pin[data-money="new"] .ring { display: block; border: 2.5px solid var(--more); }
.pin[data-money="cut"] .ring { display: block; border: 2px dashed #5E6670; }
.pin .lbl {
  position: absolute; left: 22px; top: 50%; transform: translateY(-50%); white-space: nowrap;
  font: 600 11.5px var(--serif); letter-spacing: 0;
  color: #111418; background: #FFFFFF; padding: 2px 7px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.pin.approx::before {
  content: ""; position: absolute; inset: -8px; border-radius: 50%;
  background: color-mix(in srgb, var(--c) 20%, transparent); border: 1px solid color-mix(in srgb, var(--c) 70%, transparent);
}
.pin.approx .dot { inset: 2px; border-width: 2px; }
.pin.onroute .dot { inset: 2px; border-width: 2px; }
.pin.sel .dot { transform: scale(1.4); }
.pin.sel .lbl { background: var(--more); border-color: var(--more); color: #fff; }
.pin.dim { opacity: .22; }
.pin.dim .lbl { display: none; }
.pin.left .lbl { left: auto; right: 22px; }
.pin.up .lbl, .pin.down .lbl { left: 50%; transform: translateX(-50%); }
.pin.up .lbl { top: auto; bottom: 22px; }
.pin.down .lbl { top: 22px; }
.pin.nolbl .lbl { display: none; }
.pin.nolbl:hover .lbl { display: block; z-index: 1; }
.pin:hover .lbl { background: #111418; color: #FFFFFF; }

.wardwrap { background: none; border: 0; }
.wardlbl {
  transform: translate(-50%, -50%); white-space: nowrap; font: 700 11px var(--serif); letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink); opacity: .45; text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 2px #fff; pointer-events: none;
}

/* Touch map lock */
#map.locked { touch-action: pan-x pan-y; }
.maplock {
  position: absolute; z-index: 1000; left: 50%; bottom: 14px; transform: translateX(-50%); padding: 8px 16px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink); font: 600 13px var(--serif);
  border-radius: var(--radius-full); box-shadow: var(--shadow-md);
}
#map:not(.locked) .maplock { background: var(--fund); border-color: var(--fund); color: #fff; }

/* ---------- search & filters ---------- */
.search-box {
  display: flex; align-items: center; border: 1px solid var(--line); background: var(--panel);
  border-radius: var(--radius-md); box-shadow: var(--shadow-xs); transition: all 0.2s var(--ease);
}
.search-box:focus-within {
  border-color: var(--fund); box-shadow: 0 0 0 3px color-mix(in srgb, var(--fund) 16%, transparent);
}
.search-icon { padding-left: 10px; color: var(--muted); font-size: 14px; pointer-events: none; }
.search {
  width: 100%; border: 0; background: transparent; padding: 10px 10px; font: 400 14.5px var(--serif); outline: none;
}
.search::placeholder { color: var(--muted); }
.search-clear {
  border: 0; background: none; color: var(--muted); font-size: 15px; padding: 6px 10px; cursor: pointer;
}
.search-clear:hover { color: var(--ink); }
.search-kbd {
  margin-right: 10px; padding: 2px 6px; font: 600 10.5px monospace; border: 1px solid var(--line);
  background: var(--grid); color: var(--muted); border-radius: var(--radius-xs); pointer-events: none;
}

/* Status filter chips with count badges */
.filters { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius-full); padding: 5px 12px;
  cursor: pointer; font: 600 12px var(--serif); letter-spacing: 0; display: inline-flex; align-items: center; gap: 6px;
  box-shadow: var(--shadow-xs); transition: all 0.15s var(--ease);
}
.chip:hover {
  border-color: var(--fund); color: var(--fund); background: color-mix(in srgb, var(--fund) 6%, var(--panel));
}
.chip[aria-pressed="true"] {
  background: var(--fund); color: #fff; border-color: var(--fund); box-shadow: 0 2px 6px color-mix(in srgb, var(--fund) 35%, transparent);
}
.chip-count {
  font: 700 10.5px var(--head); opacity: .8; background: color-mix(in srgb, currentColor 18%, transparent);
  padding: 1px 5px; border-radius: var(--radius-full);
}

/* Dropdown select grid */
.filter-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 6px; }
.select-wrapper { position: relative; }
.select-wrapper select {
  width: 100%; border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius-sm); padding: 8px 10px;
  font: 500 12.5px var(--serif); text-overflow: ellipsis; outline: none; cursor: pointer; box-shadow: var(--shadow-xs);
  transition: all 0.15s var(--ease);
}
.select-wrapper select:focus {
  border-color: var(--fund); box-shadow: 0 0 0 3px color-mix(in srgb, var(--fund) 16%, transparent);
}

/* Active filter pills row */
.active-filters {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 8px 12px;
  background: color-mix(in srgb, var(--fund) 6%, var(--panel)); border: 1px solid color-mix(in srgb, var(--fund) 25%, var(--line));
  border-radius: var(--radius-md);
}
.active-pill {
  display: inline-flex; align-items: center; gap: 6px; font: 600 12px var(--serif);
  background: var(--panel); border: 1px solid var(--line); padding: 3px 9px; border-radius: var(--radius-full);
  box-shadow: var(--shadow-xs);
}
.active-pill-remove {
  border: 0; background: none; color: var(--more); font-size: 13px; font-weight: 700; cursor: pointer; padding: 0; line-height: 1;
}
.active-clear-btn {
  border: 0; background: none; color: var(--fund); font: 600 12px var(--serif); cursor: pointer; text-decoration: underline; margin-left: auto;
}

/* Toolbar */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; font: 500 13px var(--serif); color: var(--muted); }
.toolbar-right { display: flex; align-items: center; gap: 8px; }
.sort-select { border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius-sm); padding: 5px 9px; font: 500 12.5px var(--serif); }
.dl-chip { font-size: 12px; border-radius: var(--radius-full); }
.linkbtn { border: 0; background: none; padding: 0; color: var(--fund); font: 600 12.5px var(--serif); cursor: pointer; text-decoration: underline; }
.linkbtn.firm { text-align: left; font-size: 13.5px; }
.notice { font: 13px var(--serif); color: var(--muted); padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--panel); }

/* ---------- project list & tactile modern cards ---------- */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.list li {
  border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs); transition: all 0.2s var(--ease); overflow: hidden;
}
.list li:hover {
  transform: translateY(-2px); border-color: color-mix(in srgb, var(--fund) 35%, var(--line)); box-shadow: var(--shadow-md);
}
.item {
  position: relative; display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: start; width: 100%; text-align: left;
  background: none; border: 0; padding: 14px 16px 14px 18px; cursor: pointer;
}
.item::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--c);
}
.item.sel {
  box-shadow: inset 0 0 0 2px var(--fund); background: color-mix(in srgb, var(--fund) 4%, var(--panel));
}
.body { display: flex; flex-direction: column; gap: 4px; }
.kick { font: 700 11px var(--serif); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.kick i { font-style: normal; font-size: 8px; }
.item .t { font: 700 15.5px var(--serif); letter-spacing: -.01em; line-height: 1.28; color: var(--ink); }
.item .m { font: 12.5px var(--serif); color: var(--muted); }

/* Card inline progress bar */
.card-prog-wrap { display: flex; align-items: center; gap: 8px; margin-top: 3px; }
.card-prog-bar { flex: 1; max-width: 140px; height: 5px; background: var(--grid); border-radius: var(--radius-full); overflow: hidden; }
.card-prog-fill { height: 100%; background: var(--ok); border-radius: var(--radius-full); }
.card-prog-txt { font: 600 11px var(--serif); color: var(--muted); }

.fig { text-align: right; display: grid; justify-items: end; gap: 2px; min-width: 80px; }
.fig b { font: 750 18px var(--head); letter-spacing: -.01em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.fig small { font: 500 11px var(--serif); color: var(--muted); }
.delta { font: 700 12px var(--serif); font-variant-numeric: tabular-nums; white-space: nowrap; padding: 2px 6px; border-radius: var(--radius-xs); }
.delta.more { color: var(--more); background: color-mix(in srgb, var(--more) 10%, transparent); }
.delta.cut { color: var(--muted); background: var(--grid); }
.delta.new { color: var(--more); background: color-mix(in srgb, var(--more) 12%, transparent); }
.empty { padding: 28px 12px; color: var(--muted); text-align: center; font-size: 14px; }
.tag {
  display: inline-block; justify-self: start; font: 600 10.5px var(--serif); line-height: 1;
  padding: 3px 7px; margin: 2px 4px 0 0; border: 1px solid var(--line); color: var(--muted); border-radius: var(--radius-full);
}
.tag.warn { border-color: var(--more); color: var(--more); background: color-mix(in srgb, var(--more) 8%, transparent); }

/* ---------- slide-over drawer detail panel (ZERO LAYOUT JUMP) ---------- */
.detail-backdrop {
  position: fixed; inset: 0; z-index: 1200;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s var(--ease);
}
.detail-backdrop.open {
  opacity: 1; pointer-events: auto;
}

.detail {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 1300;
  width: min(560px, 100vw); background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-drawer);
  overflow-y: auto; overscroll-behavior: contain;
  padding: 24px 26px 40px;
  transform: translateX(105%); opacity: 0; pointer-events: none;
  transition: transform 0.3s var(--ease), opacity 0.25s ease;
}
.detail.open {
  transform: translateX(0); opacity: 1; pointer-events: auto;
}

.detail-top-nav { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.detail-back-btn {
  border: 1px solid var(--line); background: var(--grid); color: var(--ink); padding: 5px 12px;
  font: 600 12px var(--serif); cursor: pointer; display: inline-flex; align-items: center; gap: 5px;
  border-radius: var(--radius-full); transition: all 0.15s var(--ease);
}
.detail-back-btn:hover { background: var(--line); }
.detail .close {
  border: 0; background: none; font: 400 24px var(--head); line-height: 1; cursor: pointer; color: var(--muted);
  padding: 4px; border-radius: var(--radius-xs); transition: color 0.15s ease;
}
.detail .close:hover { color: var(--ink); }

.detail h2 { font: 800 24px var(--head); letter-spacing: -.01em; line-height: 1.18; margin: 8px 0 12px; }
.status { display: inline-flex; align-items: center; gap: 7px; font: 600 13px var(--serif); }
.bigfig {
  display: flex; flex-wrap: wrap; gap: 12px 28px; margin: 16px 0 8px; padding: 12px 0;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.bigfig b { display: block; font: 800 32px var(--head); letter-spacing: -.02em; line-height: 1.05; font-variant-numeric: tabular-nums; }
.bigfig span { display: block; font: 500 12px var(--serif); color: var(--muted); margin-top: 3px; }
.bigfig .delta { white-space: normal; padding: 0; background: transparent; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 14px 0; font-size: 13.5px; }
.kv dt { font: 500 12.5px var(--serif); color: var(--muted); }
.kv dd { margin: 0; }
.budget { width: 100%; border-collapse: collapse; font-size: 13.5px; margin: 10px 0; }
.budget th { text-align: left; font: 600 12px var(--serif); color: var(--muted); padding: 6px 8px 6px 0; border-bottom: 2px solid var(--line); }
.budget td { padding: 8px 8px 8px 0; border-bottom: 1px solid var(--grid); vertical-align: top; }
.budget .n { text-align: right; font-family: var(--head); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar { height: 6px; background: var(--grid); margin-top: 5px; position: relative; overflow: hidden; border-radius: var(--radius-full); }
.bar i { position: absolute; inset: 0 auto 0 0; border-radius: var(--radius-full); }
.hint { font-size: 12.5px; color: var(--muted); margin: 0; }
.note { font-size: 14px; line-height: 1.55; margin: 10px 0; }
.issue {
  font-size: 13.5px; margin: 12px 0; padding: 10px 12px; border-left: 4px solid var(--more);
  background: color-mix(in srgb, var(--more) 8%, transparent); border-radius: var(--radius-xs);
}
.issue b { font: 700 13px var(--serif); color: var(--more); }
.prog { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; margin: 12px 0 4px; font: 600 13px var(--serif); color: var(--muted); }
.prog .bar { margin: 0; height: 8px; }
.hist { margin: 18px 0; border-top: 2px solid var(--line); padding-top: 10px; }
.hist h4 { margin: 0 0 10px; font: 800 16px var(--serif); letter-spacing: -.01em; }
.traj { display: grid; grid-template-columns: 76px 1fr; gap: 10px; align-items: baseline; padding: 7px 0; border-bottom: 1px solid var(--grid); }
.traj .fy { font: 600 12px var(--serif); color: var(--muted); font-variant-numeric: tabular-nums; }
.steps { display: flex; flex-wrap: wrap; align-items: baseline; gap: 3px 6px; }
.step { font: 700 14px var(--serif); font-variant-numeric: tabular-nums; cursor: help; }
.step.up { color: var(--more); } .step.down { color: var(--muted); }
.step.incl { opacity: .6; }
.step sup, .budget sup { font-size: 9px; font-weight: 600; margin-left: 1px; color: var(--muted); }
.arr { font-style: normal; color: var(--line); font-size: 12px; }
.milestones { list-style: none; margin: 10px 0 6px; padding: 0; font-size: 13px; }
.milestones li { padding: 3px 0; }
.milestones b { font: 600 12px var(--serif); font-variant-numeric: tabular-nums; margin-right: 6px; }
.hist details { margin-top: 12px; }
.hist summary { cursor: pointer; font: 600 13px var(--serif); color: var(--fund); }
.budget td.d { white-space: nowrap; }
.src { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 12px; }
.src a { color: var(--fund); font-size: 13px; display: block; margin-top: 4px; word-break: break-word; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.btn {
  display: inline-block; padding: 9px 16px; background: var(--fund); color: #fff; text-decoration: none;
  border: 1px solid var(--fund); font: 600 13px var(--serif); cursor: pointer; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-xs); transition: all 0.15s var(--ease);
}
.btn:hover { background: color-mix(in srgb, var(--fund) 85%, black); border-color: transparent; }
.btn.alt { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.alt:hover { border-color: var(--ink); color: var(--ink); }

/* Budget step sparklines */
.spark { display: block; width: 100%; height: auto; max-width: 340px; margin: 2px 0 4px; overflow: visible; }
.spark .base { stroke: var(--line); stroke-width: 1; }
.spark .ln { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; }
.spark .ln.incl { stroke-dasharray: 4 3; opacity: .55; }
.spark .pt { fill: var(--ink); stroke: var(--panel); stroke-width: 2; }
.spark .pt.up { fill: var(--more); } .spark .pt.down { fill: var(--cut); }
.spark .pt.incl { fill: var(--panel); stroke: var(--muted); }
.spark .hit { fill: transparent; cursor: help; outline: none; }
.spark .hit:focus-visible { stroke: var(--fund); stroke-width: 2; }
.traj.charted { align-items: start; }
.traj.charted .fy { padding-top: 4px; }
.traj.axis { border-bottom: 0; padding-top: 2px; }
.ax { display: flex; justify-content: space-between; max-width: 340px; font: 500 11.5px var(--serif); color: var(--muted); font-variant-numeric: tabular-nums; }
.tip {
  position: absolute; z-index: 2000; max-width: 280px; padding: 6px 10px; background: var(--ink); color: var(--paper);
  font: 500 12px/1.4 var(--serif); pointer-events: none; box-shadow: var(--shadow-md); border-radius: var(--radius-sm);
}

/* ---------- analytics: cluster table ---------- */
.areas { max-width: 1380px; margin: 0 auto; padding: 20px 20px 40px; display: grid; gap: 12px; }
.tablewrap { overflow-x: auto; border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius-md); box-shadow: var(--shadow-xs); }
.areatable { min-width: 560px; max-width: 100%; margin: 0; }
.areatable th[scope="row"] { text-align: left; font: 600 14px var(--serif); padding: 12px 14px; border-bottom: 1px solid var(--grid); }
.areatable th { padding: 12px 14px; }
.areatable td { padding: 12px 14px; }
.areatable tr[data-cluster] { cursor: pointer; transition: background 0.12s var(--ease); }
.areatable tr[data-cluster]:hover, .areatable tr.sel { background: color-mix(in srgb, var(--fund) 6%, var(--panel)); }
.areatable tr.sel th { color: var(--fund); }
.areatable td.up { color: var(--more); }
.areatable tr.tot th, .areatable tr.tot td { border-top: 2px solid var(--line); font-weight: 800; background: color-mix(in srgb, var(--ink) 3%, var(--panel)); }
.areatable tr.nw th { font-weight: 500; color: var(--muted); }
.areatable .bar { margin-top: 4px; }

/* ---------- mobile navigation bar ---------- */
.mobile-nav {
  display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 1050;
  background: var(--panel); border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(0,0,0,.08);
}
.mobile-nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  padding: 8px 4px; border: 0; background: none; color: var(--muted); font: 600 11px var(--serif); cursor: pointer; position: relative;
  transition: all 0.15s ease;
}
.mobile-nav-btn.active { color: var(--fund); font-weight: 700; }
.m-icon { font-size: 16px; }
.m-badge {
  position: absolute; top: 4px; right: calc(50% - 20px); font: 700 9px var(--head); background: var(--fund); color: #fff;
  padding: 1px 5px; border-radius: var(--radius-full); min-width: 14px; text-align: center;
}

.foot { max-width: 1380px; margin: 0 auto; padding: 20px 20px 40px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }

/* Whole-municipality view: smaller pins and ward labels until zoomed in. */
#map[data-zoomed-out="1"] .pin .dot { inset: 3px; border-width: 1.5px; }
#map[data-zoomed-out="1"] .pin .ring { inset: -4px; border-width: 2px; }
#map[data-zoomed-out="1"] .pin.approx::before { inset: -5px; }
#map.far .wardlbl { font-size: 9px; letter-spacing: .04em; opacity: .45; }
.list li.more { border: 0; padding: 12px 0; text-align: center; background: none; box-shadow: none; }

/* Responsive adjustments */
@media (max-width: 768px) {
  body { padding-bottom: 56px; }
  .mobile-nav { display: flex; }
  .nav-tabs { display: none; }
  .strip { padding: 10px 14px; }
  .mast { padding: 16px 14px 14px; }
  #viewExplorer { padding: 14px 14px 30px; gap: 16px; }
  .mapwrap { height: 420px; }
  #map { height: 100% !important; min-height: 280px; }
  .tally { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat { padding: 10px 12px; }
  .legend { font-size: 11px; gap: 4px 10px; }
  .filter-grid { grid-template-columns: 1fr 1fr; }
  .traj { grid-template-columns: 64px 1fr; }

  /* Mobile view switching */
  body[data-mobile-view="map"] .side { display: none; }
  body[data-mobile-view="map"] .mapwrap { display: flex; height: calc(100vh - 130px); }
  body[data-mobile-view="list"] .mapwrap { display: none; }
  body[data-mobile-view="list"] .side { display: flex; }
  body[data-mobile-view="analytics"] #viewExplorer { display: none; }
  body[data-mobile-view="analytics"] .areas { display: grid; }
}

@media (max-width: 640px) {
  .detail {
    top: auto; left: 0; right: 0; bottom: 0;
    width: 100vw; max-height: 85vh;
    border-left: 0; border-top: 1px solid var(--line);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -10px 35px rgba(0, 0, 0, 0.25);
    transform: translateY(105%);
  }
  .detail.open {
    transform: translateY(0);
  }
}
