:root {
  --bg:          #0b1220;
  --surface:     #131c2e;
  --surface-2:   #1a2541;
  --surface-overlay: rgba(19,28,46,.94);
  --border:      #243250;
  --border-soft: #1c2640;
  --text:        #e7ecf5;
  --text-dim:    #98a2b8;
  --text-muted:  #6b768f;
  --text-on-primary: #fff;
  --primary:     #ef4d6a;
  --primary-hov: #d83e59;
  --accent:      #4f8cff;
  --accent-hov:  #6fa3ff;
  --chip:        #1f2a44;
  --chip-active: #2a3a63;
  --hover-tint:  rgba(255,255,255,.06);
  --hover-tint-strong: rgba(255,255,255,.10);
  --shadow:      0 20px 60px rgba(0,0,0,.5);
  --shadow-soft: 0 4px 14px rgba(0,0,0,.45);
  --scrim:       rgba(0,0,0,.55);
  --radius:      10px;
  --accent-soft: rgba(79,140,255,.18);
  --accent-soft-border: rgba(79,140,255,.25);
  --accent-fg:   #9bbcff;
  --warn-soft:   rgba(251,191,36,.18);
  --warn-fg:     #fbbf24;
  --town-fill:        #29b6f6;
  --town-border:      #0277bd;
  --town-fill-inactive: #90a4ae;
  --town-select-fill:   #0288d1;
  --town-select-border: #01579b;
}

:root[data-theme="light"] {
  --bg:          #f6f7fb;
  --surface:     #ffffff;
  --surface-2:   #eef1f7;
  --surface-overlay: rgba(255,255,255,.94);
  --border:      #d6dbe5;
  --border-soft: #e6e9f0;
  --text:        #0f1626;
  --text-dim:    #54607a;
  --text-muted:  #7a8499;
  --text-on-primary: #fff;
  --chip:        #eef1f7;
  --chip-active: #d8e1f5;
  --hover-tint:  rgba(15,22,38,.05);
  --hover-tint-strong: rgba(15,22,38,.08);
  --shadow:      0 12px 32px rgba(15,22,38,.12);
  --shadow-soft: 0 2px 10px rgba(15,22,38,.08);
  --scrim:       rgba(15,22,38,.35);
  --accent-soft: rgba(79,140,255,.12);
  --accent-soft-border: rgba(79,140,255,.30);
  --accent-fg:   #2a5db8;
  --warn-soft:   rgba(180,120,10,.14);
  --warn-fg:     #a06f00;
  --town-fill:        #0288d1;
  --town-border:      #01579b;
  --town-fill-inactive: #b0bec5;
  --town-select-fill:   #01579b;
  --town-select-border: #003c71;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* Kill the browser's default SVG focus ring on Leaflet polygons — Chrome/Firefox draw
   a black rectangle around the focused path's bounding box after a click, which on
   block polygons looks like a hard outline that overlaps neighbours. Map polygons
   aren't keyboard-navigable in this UI, so removing it costs no accessibility. */
.leaflet-interactive:focus { outline: none; }

/* Force [hidden] to win against component-level display rules (e.g. display: flex
   on .trivia-card, .search-panel) so element.hidden = true actually hides them. */
[hidden] { display: none !important; }

/* Chromium/WebKit scrollbar — matches Firefox's scrollbar-color: var(--border) transparent.
   Applied globally so every overflow container gets consistent styling without per-rule
   duplication. The 3px radius keeps it subtle rather than pill-shaped. */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
/* Light theme: --border is near-white so use --text-muted (#7a8499) for visible contrast. */
:root[data-theme="light"] ::-webkit-scrollbar-thumb { background: var(--text-muted); }
:root[data-theme="light"] ::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
:root[data-theme="light"] { scrollbar-color: var(--text-muted) transparent; }

html, body {
  height: 100dvh;
  font-family: system-ui, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  /* Prevents double-tap from zooming the browser UI while keeping pinch-to-zoom. */
  touch-action: manipulation;
}
body.modal-open { overflow: hidden; }

/* ── Map — fills entire viewport ─────────────── */
#map { position: fixed; inset: 0; z-index: 0; }

/* ── Top chip bar ─────────────────────────────── */
.topbar {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 6px 8px;
  background: var(--surface-overlay);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  /* Reserve ~76px on the right of the centred topbar for the trivia FAB so the chip
     bar doesn't run into it on medium viewports. */
  max-width: calc(100dvw - 108px);
  overflow-x: auto;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  min-height: 44px;
  background: var(--chip);
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.chip:hover { background: var(--chip-active); }
.chip.active { background: var(--chip-active); border-color: var(--accent); }
.chip svg { width: 14px; height: 14px; opacity: .7; flex-shrink: 0; }

.chip-all.has-filters { background: var(--primary); color: var(--text-on-primary); border-color: var(--primary); }
.chip-all.has-filters:hover { background: var(--primary-hov); border-color: var(--primary-hov); }
.chip-clear { padding: 6px 10px; color: var(--text-dim); }
.chip-clear:hover { background: var(--chip-active); color: var(--text); }

/* Theme toggle — floating circular control at bottom-left of the map.
   Sun/moon SVGs both live in the markup; CSS hides the inactive one based on
   the data-theme attribute on <html>. Sits in the empty bottom-left corner
   (bottom-right has the lease/psf legend at high zoom + attribution always). */
#theme-toggle {
  position: fixed;
  bottom: 16px;
  left: 16px;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface-overlay);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-soft);
  color: var(--text-dim);
  cursor: pointer;
  font-family: inherit;
  transition: color .12s, border-color .12s;
}
#theme-toggle:hover { color: var(--text); border-color: var(--accent); }
.theme-icon { width: 16px; height: 16px; opacity: 1; }
:root[data-theme="dark"]  #theme-toggle .theme-icon-sun  { display: none; }
:root[data-theme="light"] #theme-toggle .theme-icon-moon { display: none; }

/* ── PWA install button + iOS tooltip ────────────────────────────────────────
   Button sits directly above the theme toggle (bottom: 60px = 16 + 36 + 8).
   Tooltip card anchors bottom-left, pointing toward the button. */
#pwa-install-btn {
  position: fixed;
  bottom: 60px;
  left: 16px;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface-overlay);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-soft);
  color: var(--text-dim);
  cursor: pointer;
  font-family: inherit;
  transition: color .12s, border-color .12s;
}
#pwa-install-btn:hover { color: var(--text); border-color: var(--accent); }

#pwa-install-tooltip {
  position: fixed;
  bottom: 104px;
  left: 16px;
  z-index: 501;
  width: 220px;
  padding: 14px 14px 12px;
  background: var(--surface-overlay);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
#pwa-install-tip-close {
  position: absolute;
  top: 8px; right: 8px;
  display: flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; padding: 0;
  border: none; border-radius: 50%;
  background: transparent;
  color: var(--text-muted); cursor: pointer;
}
#pwa-install-tip-close:hover { color: var(--text); background: var(--hover-tint); }
.pwa-tip-title { margin: 0 0 8px; font-size: .85rem; font-weight: 600; color: var(--text); }
.pwa-tip-steps {
  margin: 0; padding-left: 18px;
  font-size: .8rem; color: var(--text-dim); line-height: 1.6;
}
.pwa-tip-steps li { margin-bottom: 2px; }
.pwa-tip-share-icon { vertical-align: middle; margin: 0 1px; }

/* ── Floating search ──────────────────────────────
   FAB sits outside the topbar (so its dropdown isn't clipped by topbar overflow).
   Collapsed = circular lens button. Expanded = a 320px input + dropdown panel. */
.search-fab {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 11;
}
.search-fab-btn {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  background: var(--surface-overlay);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, border-color .15s;
}
.search-fab-btn:hover { background: var(--chip-active); border-color: var(--accent); }

.search-panel { display: none; position: relative; }
.search-fab.open .search-fab-btn { display: none; }
.search-fab.open .search-panel { display: block; }

.search-field {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 320px;
  height: 44px;
  padding: 0 12px;
  background: var(--surface-overlay);
  backdrop-filter: blur(12px);
  border: 1px solid var(--accent);
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.search-field .search-icon { opacity: .65; flex-shrink: 0; }

#search-input {
  flex: 1;
  min-width: 0;
  height: 100%;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
#search-input::placeholder { color: var(--text-muted); }
/* Strip the native search-input X (we render our own .search-clear). */
#search-input::-webkit-search-cancel-button,
#search-input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; }

.search-clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 999px;
}
.search-clear:hover { background: var(--hover-tint); color: var(--text); }

#search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 320px;
  max-height: 60dvh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  z-index: 20;
  padding: 4px;
}
.search-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  min-height: 44px;
}
.search-row:hover, .search-row.active { background: var(--chip-active); }
.search-row-text { flex: 1; min-width: 0; }
.search-row-title {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-row-sub {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.search-pill {
  flex-shrink: 0;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .04em;
  border-radius: 999px;
  text-transform: uppercase;
}
.search-pill[data-type="hdb"]       { background: rgba(79,140,255,.18); color: #9bbcff; }
.search-pill[data-type="condo"]     { background: rgba(251,146,60,.18);  color: #fdba74; }
.search-pill[data-type="bus"]       { background: rgba(250,204,21,.18);  color: #fde68a; }
.search-pill[data-type="mrt"]       { background: rgba(239,77,106,.20);  color: #fda4af; }
.search-pill[data-type="school"]    { background: rgba(52,211,153,.18);  color: #6ee7b7; }
.search-pill[data-type="hospital"]  { background: rgba(244,114,182,.18); color: #f9a8d4; }
.search-pill[data-type="shopping"]  { background: rgba(167,139,250,.20); color: #c4b5fd; }
.search-pill[data-type="hotel"]     { background: rgba(34,211,238,.18);  color: #67e8f9; }
.search-pill[data-type="religious"] { background: rgba(217,180,90,.20);  color: #fcd34d; }
.search-pill[data-type="place"]     { background: rgba(255,255,255,.08); color: var(--text-dim); }

/* Light-theme search-pill colours: same hues, deeper foregrounds so the tint reads on white. */
:root[data-theme="light"] .search-pill[data-type="hdb"]       { background: rgba(79,140,255,.16);  color: #2a5db8; }
:root[data-theme="light"] .search-pill[data-type="condo"]     { background: rgba(234,88,12,.14);   color: #b54708; }
:root[data-theme="light"] .search-pill[data-type="bus"]       { background: rgba(202,138,4,.14);   color: #92580d; }
:root[data-theme="light"] .search-pill[data-type="mrt"]       { background: rgba(239,77,106,.16);  color: #b42746; }
:root[data-theme="light"] .search-pill[data-type="school"]    { background: rgba(16,150,99,.14);   color: #1d6b4a; }
:root[data-theme="light"] .search-pill[data-type="hospital"]  { background: rgba(219,39,119,.14);  color: #a4196b; }
:root[data-theme="light"] .search-pill[data-type="shopping"]  { background: rgba(124,58,237,.14);  color: #5b21b6; }
:root[data-theme="light"] .search-pill[data-type="hotel"]     { background: rgba(8,145,178,.14);   color: #0e7490; }
:root[data-theme="light"] .search-pill[data-type="religious"] { background: rgba(180,120,10,.18);  color: #8a5a00; }
:root[data-theme="light"] .search-pill[data-type="place"]     { background: rgba(15,22,38,.06);    color: var(--text-dim); }

.search-empty {
  padding: 14px 12px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}

/* ── Result cluster: counts folded into the List button ── */
.results-cluster { display: inline-flex; align-items: center; }
/* Tighter padding than .chip default since the inner two-line count already
   gives the button visual weight; keeps the chip from dominating the bar. */
.chip-results { padding: 4px 10px; gap: 8px; }
#results-text {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.15;
  font-size: 11px;
  color: var(--text-dim);
}
#results-text strong { color: var(--accent); font-weight: 700; font-size: 12px; margin-right: 2px; }
.rc-line { white-space: nowrap; }

/* ── Modal scrim ───────────────────────────────── */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--scrim);
  backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.scrim.open { display: flex; }

/* ── Modal ─────────────────────────────────────── */
.modal {
  width: 100%;
  max-width: 560px;
  max-height: calc(100dvh - 48px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  animation: modal-pop .22s cubic-bezier(.2,.9,.3,1.1);
}
@keyframes modal-pop {
  from { opacity: 0; transform: scale(.96) translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.modal-head h2 { font-size: 17px; font-weight: 600; color: var(--text); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.modal-body {
  overflow-y: auto;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.modal-body::-webkit-scrollbar { width: 6px; }
.modal-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Collapsible section ────────────────────────── */
.section { border-bottom: 1px solid var(--border-soft); }
.section:last-child { border-bottom: none; }

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  cursor: pointer;
  user-select: none;
}
.section-head:hover { background: var(--hover-tint); }
.section-head h3 { font-size: 14px; font-weight: 600; color: var(--text); }
.section-head-right { display: flex; align-items: center; gap: 6px; }
.section-summary { font-size: 12px; color: var(--text-dim); }

.chevron { color: var(--text-muted); flex-shrink: 0; transition: transform .2s; }
.section.open .chevron { transform: rotate(180deg); }

.section-body { padding: 0 20px 18px; display: none; }
.section.open .section-body { display: block; }

/* ── Pills ─────────────────────────────────────── */
.pills { display: flex; flex-wrap: wrap; gap: 8px; }

.pill {
  padding: 7px 14px;
  min-height: 44px;
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 999px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.pill:hover { border-color: var(--accent); }
.pill.selected { background: var(--accent); border-color: var(--accent); color: var(--text-on-primary); }

/* Dimmed when the current filter combination yields zero matches for this
   option. Still clickable (and still shows .selected) because the user may
   be staging a selection before relaxing other filters. The share suffix
   ("0%" / "0") is already informative; the dim is a fast visual scan cue. */
.pill.empty { opacity: 0.4; }
.pill.empty.selected { opacity: 0.6; }

/* Desktop pointer-input devices don't need the 44px mobile touch target —
   compact the pill so the flat-model grid fits more options per row and the
   modal stays scannable. `hover: hover` keeps the relaxation off mobile. */
@media (hover: none) {
  /* ⓘ tags in list rows are hover-only — useless and potentially confusing on touch. */
  .list-tag-info { display: none; }
}

@media (hover: hover) {
  .flat-group .pill { min-height: 32px; padding: 5px 11px; font-size: 12px; }
  .flat-group .pills { gap: 6px; }
}

/* Superscript share inside flat-model pills (e.g. "4I 55%" = 55% of 4-room
   txns). The "%" is a CSS ::after suffix so the JS-set textContent stays a
   plain number, but the rendered pill always reads as a percentage — without
   it "55" was ambiguous (count? version? subtype?). Inherits foreground
   colour from .pill.selected so it stays legible on the accent background;
   :empty hides the gap when the boot loader hasn't filled it yet (or the
   parent type has only one model so showing 100% is pure noise). */
.pill .pill-share {
  font-size: 9px;
  font-weight: 600;
  margin-left: 3px;
  opacity: 0.75;
  vertical-align: super;
  line-height: 1;
}
.pill .pill-share:empty { display: none; }
.pill .pill-share::after { content: "%"; }

/* Sub-text shown beneath a pill row when its share annotations are dynamic
   (recomputed against the current filters). Italic + dim so it reads as
   metadata, not a control. */
.share-note {
  margin: 8px 4px 0;
  font-size: 11px;
  font-style: italic;
  color: var(--text-dim);
}

/* ── Range row ─────────────────────────────────── */
.range-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
}

.field label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.field input,
.field select {
  width: 100%;
  padding: 9px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  appearance: auto;
}
.field input:focus,
.field select:focus { border-color: var(--accent); }

/* ── Dual-handle price slider ──────────────────── */
.dual-slider-wrap {
  position: relative;
  height: 36px;         /* enough room for thumbs */
  margin: 12px 4px 4px;
}

/* shared track */
.dual-slider-wrap::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0; right: 0;
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  transform: translateY(-50%);
  pointer-events: none;
}

/* coloured fill between thumbs */
.dual-slider-fill {
  position: absolute;
  top: 50%;
  height: 4px;
  background: var(--accent);
  border-radius: 999px;
  transform: translateY(-50%);
  pointer-events: none;
  /* left/right set by JS via inline style */
}

.dual-slider-wrap input[type="range"] {
  position: absolute;
  width: 100%;
  top: 50%;
  transform: translateY(-50%);
  height: 4px;
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
  pointer-events: none;
  outline: none;
  margin: 0;
  padding: 0;
  border: none;
}

/* make only the thumb interactive */
.dual-slider-wrap input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  cursor: pointer;
  pointer-events: all;
}
.dual-slider-wrap input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  cursor: pointer;
  pointer-events: all;
}

/* Major-tick row rendered just below the slider track. JS fills it with
   absolutely-positioned <span class="tick"> children whose left% maps to the
   data value — same percentage system the dual-slider-fill uses, so ticks
   align with the fill (not strictly with the thumb centre, which is offset
   by half its width; the visual approximation is consistent everywhere). */
.slider-ticks {
  position: relative;
  height: 22px;
  margin: -4px 4px 0;
  pointer-events: none;
}
.slider-ticks .tick {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
}
.slider-ticks .tick::before {
  content: "";
  display: block;
  width: 1px;
  height: 6px;
  background: var(--border);
  margin: 0 auto 2px;
}
/* ── Histogram-driven floor-area filter ─────────────────────────────────────
   Bars are vertical density of transactions per 10-sqm bin; the brush handles
   live in .histo-brush, which sits over the bottom edge of the bars. Selected
   bars use --accent; unselected fade. Click-to-select-bin is on .histo-bar. */
.histogram-wrap {
  margin: 8px 4px 4px;
}
.histo-bars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 64px;
  padding: 0;
}
.histo-bar {
  flex: 1;
  height: 100%;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  position: relative;
  display: flex;
  align-items: flex-end;
  min-width: 0;
}
/* The visible bar is a child pseudo-fill so the click target stays full-height
   even on tiny bars (the 160+ tail is <1% of data). --bar-h is set inline. */
.histo-bar::after {
  content: "";
  display: block;
  width: 100%;
  height: var(--bar-h, 0%);
  min-height: 2px;
  background: var(--border);
  border-radius: 2px 2px 0 0;
  transition: background-color 0.12s;
}
.histo-bar.selected::after { background: var(--accent); }
.histo-bar:hover::after { filter: brightness(1.1); }

.histo-brush {
  position: relative;
  height: 22px;
  margin-top: 4px;
}
.histo-brush::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0; right: 0;
  height: 3px;
  background: var(--border);
  border-radius: 999px;
  transform: translateY(-50%);
  pointer-events: none;
}
.histo-brush .dual-slider-fill {
  position: absolute;
  top: 50%;
  height: 3px;
  background: var(--accent);
  border-radius: 999px;
  transform: translateY(-50%);
  pointer-events: none;
}
.histo-brush input[type="range"] {
  position: absolute;
  top: 50%;
  left: 0;
  width: 100%;
  height: 3px;
  transform: translateY(-50%);
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
  pointer-events: none;
  outline: none;
  margin: 0;
  padding: 0;
  border: none;
}
.histo-brush input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  cursor: grab;
  pointer-events: all;
}
.histo-brush input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  cursor: grab;
  pointer-events: all;
}

/* native month picker accent */
.field input[type="month"]::-webkit-calendar-picker-indicator { filter: invert(.6); }

.field-label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
}
.field-label--spaced { margin-top: 14px; }
.section-hint { font-size: 11px; font-weight: 400; opacity: .6; }
.pills--spaced { margin-bottom: 14px; }

/* ── Month-range calendar picker ─────────────── */
.month-picker { margin-top: 4px; }

.mp-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.mp-year-lbl { font-weight: 600; font-size: 14px; }
.mp-nav-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 6px;
  font-family: inherit;
  transition: background .12s;
}
.mp-nav-btn:hover:not(:disabled) { background: var(--chip-active); }
.mp-nav-btn:disabled { opacity: .3; cursor: default; }

.mp-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
}
.mp-month {
  padding: 8px 4px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  transition: background .1s, color .1s;
}
.mp-month:hover:not(.mp-out) { background: var(--chip-active); }
.mp-month.mp-out  { opacity: .25; cursor: default; pointer-events: none; }
.mp-month.mp-from { background: var(--accent); color: var(--text-on-primary); border-radius: 6px 0 0 6px; }
.mp-month.mp-to   { background: var(--accent); color: var(--text-on-primary); border-radius: 0 6px 6px 0; }
.mp-month.mp-from.mp-to { border-radius: 6px; } /* same month selected for both */
.mp-month.mp-range { background: var(--accent-soft); border-radius: 0; color: var(--text); }

.mp-range-lbl {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
  min-height: 18px;
}
.mp-lbl-from, .mp-lbl-to { color: var(--accent); font-weight: 600; }
.mp-lbl-hint { opacity: .5; font-style: italic; }


/* ── Town search ───────────────────────────────── */
/* Above the region tabs. When non-empty, the location section gains a
   `.searching` class that hides the region accordion and flattens every
   region-group into one scrollable list with non-matching labels hidden. */
.town-search {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 8px;
  font: inherit;
  font-size: 13px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-sizing: border-box;
}
.town-search:focus { outline: none; border-color: var(--accent); }

.section[data-key="location"].searching .region-tabs { display: none; }
.section[data-key="location"].searching .region-towns-group { display: block; }
.section[data-key="location"].searching .checkbox-list label.town-hidden { display: none; }

.town-search-empty {
  margin: 8px 4px 0;
  font-size: 12px;
  font-style: italic;
  color: var(--text-dim);
}

/* ── Region tabs (horizontal) ──────────────────── */
.region-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.region-tab {
  flex: 1;
  padding: 8px 6px;
  background: var(--chip);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  transition: background .15s, border-color .15s, color .15s;
  line-height: 1.3;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  user-select: none;
}
.region-tab:hover { background: var(--chip-active); color: var(--text); }
.region-tab.active { background: var(--chip-active); border-color: var(--accent); color: var(--text); }

/* Unified custom checkbox for every checkbox in the filter modal — the
   native rendering on a 14px checkbox makes the indeterminate dash hard to
   spot, and accent-color produces inconsistent themes across browsers.
   Applied to: region select-all (tabs), town checkboxes (list), and flat
   type-group checkboxes (pill grid headers). */
.region-select-all,
.checkbox-list input[type="checkbox"],
.flat-group-cb {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background: var(--surface);
  border: 1.5px solid var(--text-muted);
  border-radius: 3px;
  position: relative;
  transition: background .12s, border-color .12s;
}
.region-select-all:hover,
.checkbox-list input[type="checkbox"]:hover,
.flat-group-cb:hover { border-color: var(--accent); }

.region-select-all:checked,
.region-select-all:indeterminate,
.checkbox-list input[type="checkbox"]:checked,
.flat-group-cb:checked,
.flat-group-cb:indeterminate {
  background: var(--accent);
  border-color: var(--accent);
}
/* ✓ for fully-selected */
.region-select-all:checked::after,
.checkbox-list input[type="checkbox"]:checked::after,
.flat-group-cb:checked::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 0;
  width: 5px;
  height: 10px;
  border: solid var(--text-on-primary);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
/* — for partially-selected */
.region-select-all:indeterminate::after,
.flat-group-cb:indeterminate::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 6px;
  width: 9px;
  height: 2px;
  background: var(--text-on-primary);
  border-radius: 1px;
}


/* ── Town checkboxes ───────────────────────────── */
.checkbox-list {
  max-height: 200px;
  overflow-y: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 0;
}

.checkbox-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
}
.checkbox-list label:hover { background: var(--chip); }
/* `.checkbox-list input[type="checkbox"]` rendering moved to the unified
   custom-checkbox rule above so all three checkbox types in the modal share
   one theme. */

/* Only the active region's towns are visible */
.region-towns-group { display: none; }
.region-towns-group.active { display: block; }


/* ── Error message ─────────────────────────────── */
.error-msg {
  font-size: 11px;
  color: var(--primary);
  min-height: 16px;
  margin-top: 4px;
}

/* ── Modal footer ──────────────────────────────── */
.modal-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px 12px;
  padding: 14px 20px;
  border-top: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.modal-freshness {
  width: 100%;
  margin: 0;
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
}

.btn {
  padding: 11px 22px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .12s;
}
.btn-ghost { background: transparent; color: var(--text-dim); border-color: transparent; }
.btn-ghost:hover { color: var(--text); }
.btn-primary { background: var(--primary); color: var(--text-on-primary); min-width: 200px; min-height: 44px; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hov); }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }

/* ── Block hover tooltip ───────────────────────── */
.block-tooltip {
  font-size: 12px;
  line-height: 1.5;
  padding: 6px 10px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: var(--shadow-soft);
  pointer-events: none;
  max-width: 260px;
}
.block-tooltip::before { display: none; }

/* ── Lease-remaining / price legend ─────────────── */
.map-legend {
  background: var(--surface-overlay);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.6;
  box-shadow: var(--shadow-soft);
  color: var(--text);
  /* Fixed width sized to the longer mode (lease, with " yrs" suffix) so toggling
     between Lease and PSF doesn't make the legend re-flow. */
  width: 144px;
}

.map-legend small {
  display: block;
  font-weight: 400;
  color: var(--text-muted);
  font-size: 10px;
  margin: -2px 0 6px;
}

/* Header row: mode toggle + collapse button side by side */
.legend-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}
.legend-header .legend-toggle { flex: 1; }

.legend-collapse-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  font-size: 10px;
  font-weight: 600;
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  cursor: pointer;
  flex-shrink: 0;
}
.legend-collapse-btn:hover { background: var(--chip-active); color: var(--text); }

/* Collapsed: shrink to a circle the same size as the theme toggle. */
.map-legend.collapsed {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  overflow: hidden;
}
.map-legend.collapsed .legend-collapse-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 14px;
  border: none;
}

.legend-toggle { display: flex; gap: 4px; }

.legend-btn {
  flex: 1;
  padding: 3px 6px;
  min-height: 28px;
  font-size: 10px;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--chip);
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
}
.legend-btn.active { background: var(--accent); color: var(--text-on-primary); border-color: var(--accent); }
.legend-btn:not(.active):hover { background: var(--chip-active); color: var(--text); }

.map-legend strong {
  display: block;
  margin-bottom: 4px;
  font-size: 11px;
  color: var(--text);
}
.map-legend div { display: flex; align-items: center; gap: 7px; }
.map-legend span {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* ── Leaflet popup overrides — match dark theme ── */
.leaflet-popup-content-wrapper {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.leaflet-popup-tip { background: var(--surface); border: 1px solid var(--border); }
.leaflet-popup-close-button { color: var(--text-dim) !important; }
.leaflet-popup-close-button:hover { color: var(--text) !important; }
/* Leaflet's default is ~11px / 1.4 — too tight for the txn list. Bump for readability. */
.leaflet-popup-content { font-size: 14px; line-height: 1.55; }

/* Town tooltip (low zoom) — Leaflet's default white default with no token usage. */
.leaflet-tooltip {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow-soft);
  font-family: inherit;
}
.leaflet-tooltip-top::before  { border-top-color:    var(--border); }
.leaflet-tooltip-bottom::before { border-bottom-color: var(--border); }
.leaflet-tooltip-left::before  { border-left-color:   var(--border); }
.leaflet-tooltip-right::before { border-right-color:  var(--border); }

/* ── Popup transaction list + open-details arrow ───── */
/* Fixed max-height shows ~5 rows; rest scroll. Each row is ~62px (3 lines + padding). */
.popup-txn-list {
  max-height: 380px;
  overflow-y: auto;
  margin-top: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.popup-txn-list::-webkit-scrollbar { width: 6px; }
.popup-txn-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Small arrow button rendered next to the block name — replaces the old bottom
   "View details" button. 32px square keeps it tappable on mobile. */
.popup-open-details {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin-left: 8px;
  padding: 0;
  flex-shrink: 0;
  vertical-align: middle;
  border-radius: 999px;
  background: var(--accent);
  color: var(--text-on-primary);
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: background .12s, transform .12s, box-shadow .12s;
}
.popup-open-details:hover {
  background: var(--accent-hov);
  transform: translateY(-1px);
  box-shadow: var(--shadow-soft);
}
.popup-open-details:active { transform: translateY(0); box-shadow: none; }

/* ── Property info ─────────────────────────────── */
.prop-info {
  font-size: 12px;
  color: var(--text-dim);
  border-top: 1px solid var(--border-soft);
  margin-top: 6px;
  padding-top: 6px;
}
/* Numbers pop in accent-fg; labels stay dim so the count reads first. */
.pi-num   { color: var(--accent-fg); font-weight: 600; }
.pi-label { color: var(--text-dim); }
.pi-amenity { color: var(--text-muted); font-style: italic; }
/* Header row: address+postal left, ↗ button right — flex so the button
   stays flush-right without disrupting the text reflow below. */
.popup-header-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  justify-content: space-between;
}
.popup-header-row strong { flex: 1; }
/* Years-left inline — bright so it reads at a glance, not tucked in parens. */
.popup-lease-left { color: var(--text); font-weight: 600; }

/* ── Popup / tooltip content classes ───────────── */
/* Leaflet injects popup HTML into the live DOM, so these classes work inside popups. */
.popup-sm  { min-width: 200px; }
.popup-md  { min-width: 220px; }
.popup-lg  { min-width: 260px; max-width: 320px; }
.popup-region     { font-size: 11px; color: var(--text-dim); }
.popup-meta       { color: var(--text-dim); }
.popup-warning    { color: var(--warn-fg); }
.popup-breakdown  { color: var(--accent); cursor: help; margin-left: 2px; font-size: 12px; }

.popup-info-tip {
  position: fixed;
  z-index: 10000;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text);
  box-shadow: var(--shadow);
  max-width: 220px;
}
.popup-dim        { color: var(--text-muted); }
.popup-hint       { color: var(--text-muted); font-size: 12px; }
.popup-error-text { color: var(--primary); font-size: 12px; }
.popup-txn-row    { border-top: 1px solid var(--border-soft); padding: 8px 0; margin-top: 4px; line-height: 1.6; }
.popup-txn-num    { color: var(--text); font-size: 12px; font-weight: 700; margin-right: 4px; opacity: .85; }
.popup-txn-model  { color: var(--text-dim); font-size: 0.92em; }
.popup-txn-code   { color: var(--accent-fg); background: var(--accent-soft); padding: 1px 6px; border-radius: 3px; font-size: 0.92em; cursor: help; }

.flat-groups { display: flex; flex-direction: column; gap: 2px; }
.flat-group + .flat-group { border-top: 1px solid var(--border-soft); margin-top: 4px; padding-top: 4px; }
.flat-group-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  font-weight: 600;
  user-select: none;
}
.flat-group-cb-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  flex-shrink: 0;
}
.flat-group-cb-label input { cursor: pointer; }
/* Chevron toggle on the right of each group head. Pushed flush-right with
   margin-left:auto so the row stays single-line and the chevron lands in the
   same column for every group — easier to scan and tap. */
.flat-group-toggle {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color .12s, color .12s, background .12s;
}
.flat-group-toggle:hover { border-color: var(--accent); color: var(--text); }
.flat-group-chevron { transition: transform .15s; }
.flat-group:not(.collapsed) .flat-group-chevron { transform: rotate(180deg); }
.flat-group.collapsed .pills:not(.inline) { display: none; }
.flat-group:not(.collapsed) .pills:not(.inline) { padding: 4px 0 8px; }
/* Single-model groups (1-Room, Multi-Gen) render their lone pill inline next
   to the checkbox label — saves a row and matches the visual weight of the
   collapsed multi-model rows. */
.pills.inline { margin-left: auto; flex-wrap: nowrap; }
.popup-nonres-notice {
  color: var(--warn-fg);
  font-size: 12px;
  border: 1px solid var(--warn-fg);
  border-radius: 3px;
  padding: 3px 6px;
  margin: 4px 0;
}
/* ── Detail panel ──────────────────────────────── */
#detail-panel {
  position: fixed;
  top: 0; right: 0;
  width: 480px;
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 1000;
  box-shadow: var(--shadow);
  transform: translateX(100%);
  transition: transform .25s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#detail-panel.open { transform: translateX(0); }

#detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 14px 16px 12px;
  background: var(--surface-2);
  color: var(--text);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 8px;
}
/* flex: 1 + min-width: 0 lets the inner text column claim all available width so
   long MRT names don't wrap mid-word. Without this, the div is only as wide as its
   widest unwrapped child (the block title), leaving ~104px for meta rows. */
#detail-header > div { flex: 1; min-width: 0; }
#detail-block-name {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.35;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
}
.detail-postal {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--chip);
  border: 1px solid var(--border-soft);
  border-radius: 4px;
  padding: 1px 8px;
  letter-spacing: .02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.7;
}
#detail-meta { margin-top: 6px; }
.meta-subline {
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.6;
  margin-top: 5px;
}
.meta-subline strong { color: var(--text); font-weight: 700; }
.meta-mrt {
  font-size: 14px;
  color: var(--text-dim);
  margin-top: 4px;
}
#detail-count-tabs {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  flex-shrink: 0;
}
#detail-count {
  flex: 1;
  padding: 0 16px;
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 500;
  min-width: 0;
}

#detail-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
#detail-close:hover { color: var(--text); }

#detail-panel-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

#detail-prop-info {
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border-soft);
}
#detail-prop-info:empty { display: none; }

/* Stat tiles — headline numbers. auto-fit so 2 tiles fill 50/50, 3 tiles fill 33/33/33. */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}
.stat-tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
}
.stat-num { font-size: 22px; font-weight: 700; color: var(--text); line-height: 1.05; }
.stat-lbl { font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.stat-tile--price { background: var(--accent-soft); border-color: var(--accent-soft-border); }
.stat-tile--price .stat-num { color: var(--accent-fg); }

/* Flat-mix pills — one per sold flat type. Compact label + bold count, scannable. */
.mix-row { display: flex; flex-wrap: wrap; gap: 6px; }
.mix-pill {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 5px 12px;
  font-size: 14px;
  color: var(--text-dim);
  background: var(--chip);
  border: 1px solid var(--border-soft);
  border-radius: 999px;
}
.mix-pill strong { color: var(--text); font-weight: 700; }
.mix-unit { font-size: 12px; color: var(--text-muted); font-weight: 400; }

.panel-section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.chart-reset-btn {
  font-size: 14px;
  line-height: 1;
  padding: 2px 6px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  cursor: pointer;
  flex-shrink: 0;
}
.chart-reset-btn:hover { background: var(--chip-active); color: var(--text); }
.panel-subtitle {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
}

#detail-chart-section {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}
#detail-chart { width: 100%; height: 280px; }

#detail-rent-section {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}
#detail-rent-chart { width: 100%; height: 200px; }

.panel-empty { font-size: 13px; color: var(--text-muted); padding: 8px 0; }

/* ── Detail panel tabs — lives inside #detail-count-tabs flex row ── */
#detail-tabs {
  display: flex;
  gap: 2px;
  padding: 0 8px;
  background: transparent;
  border-bottom: none;
  flex-shrink: 0;
}

/* ── Transactions tab — sortable table ─────────── */
/* overflow-x lets the table scroll horizontally on narrow panels (mobile bottom-sheet)
   instead of wrapping into illegible cells. */
#detail-txn-table-wrap { overflow-x: auto; padding: 4px 0 12px; }
.detail-txn-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  color: var(--text);
}
.detail-txn-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  user-select: none;
}
.detail-txn-table th.sortable { cursor: pointer; }
.detail-txn-table th.sortable:hover { color: var(--text); }
.detail-txn-table th.sorted { color: var(--accent); }
.detail-txn-table th.sorted::after { content: " ▼"; font-size: 9px; }
.detail-txn-table th.sorted.asc::after { content: " ▲"; }
.detail-txn-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
  line-height: 1.4;
}
.detail-txn-table tbody tr:hover td { background: var(--hover-tint); }
.detail-txn-table .col-num   { text-align: right; font-variant-numeric: tabular-nums; }
.detail-txn-table .col-price { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
/* max-width caps the merged Flat column so long model names ("Adjoined flat", "Maisonette")
   don't push Price/PSF off-screen at 480px panel width. */
.detail-txn-table .col-flat  { max-width: 150px; overflow: hidden; text-overflow: ellipsis; }

/* ── List panel — slides in from left ──────────── */
#list-panel {
  position: fixed;
  top: 0; left: 0;
  width: 280px;
  height: 100%;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 1000;
  box-shadow: var(--shadow);
  transform: translateX(-100%);
  transition: transform .25s cubic-bezier(.4,0,.2,1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#list-panel.open { transform: translateX(0); }

#list-panel-header {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "title close"
    "pager pager";
  column-gap: 8px;
  row-gap: 8px;
  align-items: center;
  padding: 10px 8px 10px 16px;
  background: var(--surface-2);
  color: var(--text);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#list-panel-title { grid-area: title; }
#list-panel-close { grid-area: close; }
#list-panel-pager { grid-area: pager; }
.list-tab {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  min-height: 40px;
  transition: color .12s, border-color .12s;
}
.list-tab:hover { color: var(--text); }
.list-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
#list-panel-title {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  line-height: 1.4;
  min-width: 0;
  flex: 1;
}
.title-caveat { color: var(--text-muted); font-weight: 400; font-size: 11px; }
#list-panel-title svg { margin-top: 2px; flex-shrink: 0; opacity: .6; }
#list-panel-title strong { color: var(--accent); font-weight: 700; }
.title-lines { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.title-line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.title-line strong { color: var(--accent); font-weight: 700; font-size: 14px; }
.title-sep { color: var(--text-muted); margin: 0 7px; }
#list-panel-close {
  background: var(--hover-tint);
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  padding: 0;
  min-width: 44px;
  min-height: 44px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, color .15s;
}
#list-panel-close:hover { background: var(--hover-tint-strong); color: var(--text); }

#list-panel-body {
  flex: 1;
  overflow-y: auto;
}

/* Row */
.list-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background .12s, border-color .12s;
  min-height: 60px;
  color: var(--text);
}
.list-row:hover { background: var(--chip); }
.list-row.active {
  background: var(--chip-active);
  border-left-color: var(--accent);
}

.list-row-swatch {
  width: 4px;
  align-self: stretch;
  border-radius: 2px;
  flex-shrink: 0;
  margin: 2px 0;
}

.list-row-rank {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--chip);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .12s, color .12s;
}
.list-rank-top { background: var(--accent-soft); color: var(--accent-fg); }
.list-row.active .list-row-rank { background: var(--accent); color: var(--text-on-primary); }

.list-row-info { flex: 1; min-width: 0; }
.list-row-addr {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-row-tags {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 4px;
  flex-wrap: wrap;
}
.list-tag {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 99px;
  font-weight: 500;
  white-space: nowrap;
}
.list-tag-txn   { background: var(--accent-soft); color: var(--accent-fg); }
/* .list-tag-price and .list-tag-lease bg/color are set inline per-row to mirror their bins. */
.list-tag-scope { opacity: .65; font-weight: 400; }
.list-tag-info  { opacity: .7; cursor: help; font-weight: 400; }
.list-tag-span  { background: var(--hover-tint); color: var(--text-dim); }
.list-tag-track { background: var(--hover-tint); color: var(--text); font-variant-numeric: tabular-nums; }
.list-tag-mrt   { background: var(--accent-soft); color: var(--accent-fg); }
.list-row-arrow {
  color: var(--text-muted);
  flex-shrink: 0;
  transition: color .12s, transform .12s;
}
.list-row:hover .list-row-arrow,
.list-row.active .list-row-arrow { color: var(--accent); transform: translateX(2px); }

/* Pager in the list-panel header — compact arrow buttons + "page/total" label.
   Lives between the title and the close button so it's always visible, never
   requires scrolling to the bottom of the list to reach. */
#list-panel-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
#list-panel-pager[hidden] { display: none; }
.pager-btn {
  background: var(--accent-soft);
  border: 1px solid transparent;
  color: var(--accent-fg);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  min-height: 30px;
  font-family: inherit;
  transition: background .12s, color .12s, transform .08s;
}
.pager-btn:hover:not([disabled]) {
  background: var(--accent);
  color: var(--text-on-primary);
}
.pager-btn:active:not([disabled]) { transform: scale(.97); }
.pager-btn[disabled] {
  background: var(--hover-tint);
  color: var(--text-muted);
  cursor: not-allowed;
}
.pager-label {
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex: 0 0 auto;
  text-align: center;
}
.pager-label strong { color: var(--accent); font-weight: 700; }

/* States */
.list-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 32px 16px;
  font-size: 13px;
  color: var(--text-muted);
}
.list-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: list-spin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes list-spin { to { transform: rotate(360deg); } }

.list-error {
  padding: 24px 16px;
  font-size: 13px;
  color: var(--primary);
  text-align: center;
}
.list-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 40px 16px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.6;
}


/* ── MRT proximity feature ───────── */

/* Inline line under the year label in popups + detail panel header. */
.popup-mrt {
  color: var(--accent-fg);
  font-weight: 500;
}

/* ── "Did you know?" floating button + card popout ───────── */
.trivia-fab-wrap {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 11;
}
.trivia-fab {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-overlay);
  backdrop-filter: blur(12px);
  color: var(--accent-fg);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background .15s, color .15s, transform .12s;
}
.trivia-fab:hover { background: var(--surface-2); color: var(--text); }
.trivia-fab[aria-expanded="true"] {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--accent);
}

.trivia-card {
  position: absolute;
  top: 52px;
  right: 0;
  width: 360px;
  max-width: calc(100dvw - 32px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: trivia-card-pop .18s cubic-bezier(.2,.9,.3,1.1);
}
@keyframes trivia-card-pop {
  from { opacity: 0; transform: translateY(-6px) scale(.98); }
  to   { opacity: 1; transform: none; }
}
.trivia-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px 8px;
}
.trivia-card-head h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: .03em;
  text-transform: uppercase;
}
.icon-btn-sm {
  width: 28px;
  height: 28px;
  border-radius: 6px;
}
.trivia-card-body {
  padding: 4px 16px 14px;
  min-height: 120px;
}
.trivia-fact {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.trivia-fact-label {
  font-size: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.trivia-fact-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}
.trivia-fact-detail {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.4;
}
.trivia-fact.clickable { cursor: pointer; }
.trivia-fact.clickable:hover .trivia-fact-detail { color: var(--accent-fg); }
.trivia-fact.clickable .trivia-fact-detail::after {
  content: " ›";
  color: var(--accent-fg);
}
.trivia-card-status {
  padding: 0 16px 12px;
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  font-style: italic;
}
.trivia-card-status.info { color: var(--accent-fg); }
.trivia-card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-top: 1px solid var(--border-soft);
  background: var(--surface-2);
}
.trivia-nav {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--chip);
  color: var(--text-dim);
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.trivia-nav:hover:not(:disabled) {
  background: var(--chip-active);
  color: var(--text);
}
.trivia-nav:disabled { opacity: .4; cursor: not-allowed; }
.trivia-nav-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--text-on-primary);
}
.trivia-nav-primary:hover:not(:disabled) {
  background: var(--primary-hov);
  border-color: var(--primary-hov);
  color: var(--text-on-primary);
}
.trivia-counter {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ── Mobile — modal becomes bottom sheet ───────── */
@media (max-width: 640px) {
  /* Topbar shifts right to make room for the search FAB (left) and trivia FAB (right). */
  .topbar {
    left: 60px;
    right: 60px;
    transform: none;
    max-width: none;
    border-radius: 12px;
  }
  /* Push results cluster to the right edge of the fixed-width topbar so hiding
     the X button doesn't leave dead space on the right. */
  .results-cluster { margin-left: auto; }
  .search-fab { top: 16px; left: 8px; }
  .trivia-fab-wrap { right: 8px; }
  /* When expanded on mobile, the FAB stretches edge-to-edge above the topbar. */
  .search-fab.open { right: 8px; }
  .search-fab.open .search-field { width: auto; }
  .search-fab.open #search-results { width: auto; left: 0; right: 0; }
  .scrim { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    max-height: 92dvh;
    border-radius: 16px 16px 0 0;
  }
  #detail-panel {
    width: 100%;
    height: 90dvh;
    top: auto;
    bottom: 0;
    transform: translateY(100%);
    border-radius: 16px 16px 0 0;
  }
  #detail-panel.open { transform: translateY(0); }
  #list-panel {
    width: 100%;
    height: 90dvh;
    top: auto;
    bottom: 0;
    transform: translateY(100%);
    border-radius: 16px 16px 0 0;
  }
  #list-panel.open { transform: translateY(0); }
  /* Mobile: ≥44px touch targets on the pager pills per project rule. */
  .pager-btn { min-height: 44px; padding: 10px 18px; font-size: 13px; }
  .pager-label { font-size: 13px; }
  /* iOS auto-zooms inputs with font-size < 16px on focus; override here to prevent it. */
  #search-input { font-size: 16px; }
  .popup-open-details { width: 44px; height: 44px; }

  /* Collapsed circle button needs to be tappable; inline one inherits row height from toggle btns */
  .map-legend.collapsed .legend-collapse-btn { min-height: 36px; font-size: 14px; }
  /* 36px is still comfortably tappable for this small legend widget. */
  .legend-btn { min-height: 36px; }

  /* Trivia: card pops out from below the FAB; widen toward the left edge so it doesn't
     get clipped against the right viewport edge on narrow screens. */
  .trivia-card {
    width: calc(100dvw - 24px);
    right: 0;
  }
}

/* Privacy dialog — native <dialog> opened from the map attribution bar.
   Mobile-friendly: caps height at 100dvh and width at viewport. */
.privacy-dialog {
  padding: 0;
  border: 1px solid var(--surface-2);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  max-width: min(420px, 100vw);
  max-height: 100dvh;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}
.privacy-dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.privacy-dialog form { padding: 18px 20px; }
.privacy-dialog h3 { margin: 0 0 8px; font-size: 1.05rem; }
.privacy-dialog p { margin: 8px 0; font-size: 0.875rem; line-height: 1.45; color: var(--text-dim); }
.privacy-dialog a { color: inherit; text-decoration: underline; }
.privacy-dialog menu { margin: 14px 0 0; padding: 0; text-align: right; }
.privacy-dialog button {
  background: var(--surface-2);
  color: var(--text);
  border: 0;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 0.875rem;
  cursor: pointer;
  min-height: 36px;
}

/* ── Privacy dialog: feedback trigger ──────────────────────────────── */
.privacy-feedback-trigger {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  flex-wrap: wrap;
  gap: 0 1.5rem;
  align-items: center;
}
.privacy-feedback-trigger button {
  background: transparent;
  border: none;
  padding: 0;
  color: var(--accent-fg);
  font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  min-height: 44px;
}
.privacy-feedback-trigger button:hover { color: var(--accent); }
.privacy-about-link {
  color: var(--text-muted, #7a8a9e);
  font-size: 0.875rem;
  text-decoration: underline;
  text-underline-offset: 2px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}
.privacy-about-link:hover { color: var(--accent-fg); }
.privacy-feedback-done {
  font-size: 0.8rem;
  color: var(--text-dim);
  font-style: italic;
}

/* ── Feedback dialog ───────────────────────────────────────────────── */
.feedback-dialog {
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  max-width: min(400px, 100vw);
  max-height: 100dvh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.feedback-dialog::backdrop { background: rgba(0,0,0,.45); }

.feedback-step { padding: 18px 20px 22px; }

.feedback-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.feedback-header h3 { font-size: 1rem; font-weight: 600; margin: 0; }

.feedback-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: 999px;
  flex-shrink: 0;
}
.feedback-close:hover { background: var(--hover-tint); color: var(--text); }

.feedback-question {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 10px;
  line-height: 1.4;
}
.feedback-question--spaced { margin-top: 20px; }
.feedback-optional { font-weight: 400; font-size: 0.75rem; color: var(--text-dim); }

/* Purpose radio group — stacked, full-width labels for easy tapping */
.feedback-purposes {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.feedback-radio-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  padding: 6px 4px;
  border-radius: 6px;
  min-height: 44px;
  transition: background .1s;
}
.feedback-radio-label:hover { background: var(--hover-tint); }
.feedback-radio-label input[type="radio"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  cursor: pointer;
}

/* Thumbs — two equal buttons side by side */
.feedback-thumbs { display: flex; gap: 10px; }
.feedback-thumb {
  flex: 1;
  min-height: 48px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.feedback-thumb:hover { border-color: var(--accent); background: var(--chip-active); }
.feedback-thumb.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-fg);
  font-weight: 600;
}

.feedback-textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  margin-top: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  min-height: 68px;
  outline: none;
  display: block;
}
.feedback-textarea:focus { border-color: var(--accent); }
.feedback-char-count {
  display: block;
  text-align: right;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
}

.feedback-footer { display: flex; justify-content: flex-end; margin-top: 20px; }

.feedback-thankyou {
  font-size: 1rem;
  text-align: center;
  padding: 28px 0 10px;
  margin: 0;
  color: var(--text-dim);
}

@media (max-width: 640px) {
  .feedback-dialog {
    margin: auto auto 0;
    max-width: 100vw;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-bottom: none;
  }
}
