/* ── 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;
}

/* ── 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: var(--chip);
  border-radius: 999px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.pill:hover { background: var(--chip-active); 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; }
}

.flat-group .pill { flex: 0 0 90px; width: 90px; overflow: hidden; text-align: center; }

@media (hover: hover) {
  .flat-group .pill { min-height: 32px; padding: 5px 11px; font-size: 12px; flex: 0 0 80px; width: 80px; }
  .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. */
.pill .pill-share {
  font-variant-numeric: tabular-nums;
  font-size: 10px;
  font-weight: 600;
  margin-left: 2px;
  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: 12px;
  color: var(--text);
  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(--primary); border-color: var(--primary); opacity: .75; }
.btn-ghost:hover { opacity: 1; background: rgba(239,77,106,.08); }
.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; }

