/* ═══════════════════════════════════════════════════════════
   V2 · MAP FIRST
   The map fills the window. Everything else floats on it as glass: one control pill on top, the listings and the neighbourhood
   table as cards on the left, the figures and the chart in a drawer you can fold down to a single row of numbers.
   The time period is a compact menu in the control pill. Loaded after map.css.
   ═══════════════════════════════════════════════════════════ */

:root {
  --glass: rgba(255, 255, 255, 0.9);
  --glass-solid: #ffffff;
  --glass-line: rgba(255, 255, 255, 0.75);
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #526071;
  --line: #dde4ee;
  --accent: #4f46e5;
  --accent-dim: #c7d2fe;
  --accent-ink: #3730a3;
  --up: #047857;
  --down: #b91c1c;
  --flat: #64748b;
  --shadow: 0 10px 32px rgba(15, 23, 42, 0.26), 0 2px 6px rgba(15, 23, 42, 0.12);
  --chart-text: #475569;
  --chart-grid: #e8edf5;
  --chart-bar: #4f46e5;
  --chart-bar-fill: rgba(79, 70, 229, 0.2);
  --chart-line: #0f172a;
  --chart-line-fill: rgba(15, 23, 42, 0.08);
  --chart-line-dom: #c2410c;
  --chart-line-dom-fill: rgba(194, 65, 12, 0.1);
  --chart-line-diff: #0f766e;
  --chart-line-diff-fill: rgba(15, 118, 110, 0.1);
}

.glass-fx { backdrop-filter: blur(14px) saturate(1.4); -webkit-backdrop-filter: blur(14px) saturate(1.4); }

/* ── Sold | Active: a small pill, top left of the map ── */
.mode-tabs {
  top: 14px;
  left: 14px;
  right: auto;
  padding: 3px;
  border-radius: 14px;
  background: var(--glass);
  border: 1px solid var(--glass-line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px) saturate(1.4);
}
.mode-tabs a { padding: 7px 16px; border-radius: 11px; color: var(--ink-2); font-size: 13.5px; }
.mode-tabs a:hover { background: #e9edf5; }
.mode-tabs a.active { background: var(--ink); background-image: none; color: #ffffff; }

/* ── The control pill ── */
#controls {
  gap: 8px;
  padding: 7px 10px;
  border-radius: 16px;
  background: var(--glass);
  border: 1px solid var(--glass-line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px) saturate(1.4);
}
#controls label { color: var(--muted); font-size: 13px; }
#controls input[type="number"] { border-radius: 8px; border-color: #cbd5e1; }

#controls button:not(.bed-btn):not(.ptype-btn):not(.clear-filters-btn) {
  padding: 7px 13px;
  background: #ffffff;
  background-image: none;
  color: var(--ink);
  border: 1px solid #cdd6e3;
  border-radius: 10px;
  box-shadow: none;
  font-size: 13px;
  font-weight: 600;
}
#controls button:not(.bed-btn):not(.ptype-btn):not(.clear-filters-btn):hover { background: #f1f4f9; transform: none; box-shadow: none; }
#controls #toggleAreas.is-on { background: var(--accent); background-image: none; color: #ffffff; border-color: var(--accent); }

.area-toggle { background: #e8ecf3; border-radius: 11px; padding: 2px; }
#controls .area-toggle button.area-btn.area-btn.area-btn { border: 0; border-radius: 9px; background: transparent; background-image: none; color: var(--ink-2); padding: 6px 12px; }
#controls .area-toggle button.area-btn.area-btn.area-btn.active { background: var(--accent); background-image: none; color: #ffffff; box-shadow: 0 1px 3px rgba(79, 70, 229, 0.4); }
#controls .area-toggle button.area-btn.area-btn.area-btn:hover:not(.active) { background: #d9dfeb; }

/* ── Time period: a compact menu that always shows the period in force ── */
.period-menu { position: relative; display: inline-flex; }
#controls .period-menu .pm.pm-btn.pm {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 10px;
  min-height: 38px;
  text-align: left;
}
.pm-icon { flex: none; color: var(--accent-ink); }
.pm-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.pm-name { font-size: 13px; font-weight: 700; color: var(--ink); white-space: nowrap; }
.pm-range { font-size: 11px; font-weight: 500; color: var(--muted); white-space: nowrap; }
.pm-range:empty { display: none; }
.pm-caret { color: var(--muted); font-size: 12px; }
.pm-btn[aria-expanded="true"] { border-color: var(--accent) !important; box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.18) !important; }

.period-menu-pop {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  z-index: 10020;
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 250px;
  padding: 6px;
  background: var(--glass-solid);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.period-menu-pop[hidden] { display: none; }
#controls .period-menu .period-menu-pop button.pm.pm-opt.pm {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
}
#controls .period-menu .period-menu-pop button.pm.pm-opt.pm::before {
  content: "";
  flex: none;
  width: 14px;
  height: 14px;
  box-sizing: border-box;
  border: 2px solid #94a3b8;
  border-radius: 50%;
}
#controls .period-menu .period-menu-pop button.pm.pm-opt.pm:hover { background: #eef1f8; }
#controls .period-menu .period-menu-pop button.pm.pm-opt.pm.is-active { background: #eef0ff; color: var(--accent-ink); font-weight: 700; }
#controls .period-menu .period-menu-pop button.pm.pm-opt.pm.is-active::before { border-color: var(--accent); background: radial-gradient(circle, var(--accent) 0 3px, transparent 4px); }
.period-menu-pop .period-dock { margin: 4px 4px 6px; padding: 12px 10px 4px; border-top: 1px solid var(--line); }

/* ── Filters ── */
#filterPanel { border-radius: 16px; border: 1px solid var(--glass-line); background: var(--glass-solid); box-shadow: var(--shadow); }
.filter-header { background: transparent; border-bottom-color: var(--line); }
.bed-btn, .ptype-btn { border-width: 1px; border-color: #c4cddb; color: var(--ink-2); border-radius: 10px; font-size: 13px; padding: 8px 10px; }
.bed-btn.selected, .ptype-btn.selected { background: var(--accent); background-image: none; border-color: var(--accent); color: #ffffff; box-shadow: none; transform: none; }
#filterPanel .noUi-connect { background: var(--accent); }
#filterPanel .noUi-handle { border-color: var(--accent); }

/* ── Markers: white pills for prices, solid accent pills for counts ── */
.price-marker .price-label { padding: 3px 9px; border: 0; border-radius: 999px; background: rgba(255, 255, 255, 0.97); color: var(--ink); font-weight: 700; box-shadow: 0 2px 8px rgba(15, 23, 42, 0.35); }
.price-marker:hover .price-label { background: var(--ink); color: #ffffff; }
.count-marker .count-label, .cluster-marker .cluster-label { padding: 3px 10px; border: 2px solid #ffffff; border-radius: 999px; background: var(--accent); color: #ffffff; font-weight: 700; box-shadow: 0 2px 8px rgba(30, 27, 75, 0.45); }
.count-marker:hover .count-label, .cluster-marker:hover .cluster-label { background: var(--accent-ink); border-color: #ffffff; }
.leaflet-control-zoom { border: 0 !important; border-radius: 12px !important; overflow: hidden; box-shadow: var(--shadow) !important; }
.area-legend { border-radius: 14px; border: 1px solid var(--glass-line); background: var(--glass); box-shadow: var(--shadow); backdrop-filter: blur(14px); }
.area-title { background: #eef0ff; border-color: #c7d2fe; color: var(--accent-ink); }

/* ── Cards and charts (shared by the drawer and the phone panel) ── */
.card { background: rgba(255, 255, 255, 0.8); border: 1px solid var(--line); border-radius: 12px; box-shadow: none; }
.card strong { color: var(--muted); letter-spacing: 0.05em; }
.card span { color: var(--ink); }
.drawer-period { display: block; margin: 0 0 8px; color: var(--ink-2); font-size: 12.5px; font-weight: 600; }
.insights-right { background: transparent; box-shadow: none; padding: 0; }
.chart-btn.active { color: var(--accent-ink); }
.btn-group { background: #e8ecf3; border-radius: 10px; }
.insight-tab.active { background: #eef0ff; border-color: #c7d2fe; color: var(--accent-ink); }
.page-btn.active { background: var(--accent); background-image: none; border-color: var(--accent); }
.drawer-toggle { display: none; }

/* ── Desktop: the map is the page ── */
@media (min-width: 901px) and (min-height: 501px) {
  body { display: block; background: #0f172a; }
  #appContainer, #mainPanel { position: absolute; inset: 0; display: block; height: auto; flex: none; }
  #appContainer { overflow: hidden; }
  #map { position: absolute; inset: 0; width: 100%; height: 100%; }

  #controls { top: 14px; max-width: calc(100vw - 2 * 240px); }
  body.side-open #controls { left: 424px; max-width: calc(100vw - 424px - 24px); }
  .mode-tabs { z-index: 10001; }

  /* the neighbourhood legend ("Colour by"): Leaflet puts it bottom left, which is under the table and the drawer here.
     Move that corner to the top right, below the control pill (!important beats the inline bottom set by positionLegend) */
  #map .leaflet-bottom.leaflet-left { top: 70px; right: 4px; bottom: auto !important; left: auto; }

  /* the listings and the neighbourhood table float over the map instead of pushing it */
  #listingsPanel, #areasPanel {
    position: absolute;
    left: 14px;
    top: 70px;
    bottom: 34px;
    width: 396px;
    max-width: none;
    overflow: hidden;
    background: var(--glass);
    border: 1px solid var(--glass-line);
    border-radius: 16px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px) saturate(1.4);
    transform: translateX(calc(-100% - 28px));
  }
  #listingsPanel.open, #areasPanel.open { transform: none; }
  #listingsPanel.hidden, #areasPanel.hidden { display: none; }
  .toolbar-btn { background: transparent; background-image: none; color: var(--accent-ink); border-bottom: 1px solid var(--line); font-size: 13px; }
  .toolbar-btn:hover { background: #eef0ff; background-image: none; }
  .search-container, .sort-container { background: transparent; }
  .listing-row { border: 1px solid var(--line); border-radius: 12px; }
  .areas-table thead th { background: #f3f5fa; }
  .area-row.is-selected { background: #eef0ff; box-shadow: inset 3px 0 0 var(--accent); }

  /* the drawer */
  #insights, #insights.hidden, #insights.insights-charts {
    position: absolute;
    left: 14px;
    right: 76px;
    bottom: 34px;
    display: flex;
    flex-direction: row;
    gap: 18px;
    height: min(330px, 40vh);
    min-height: 236px;
    max-height: none;
    padding: 14px 16px;
    overflow: visible;
    background: var(--glass);
    border: 1px solid var(--glass-line);
    border-radius: 18px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px) saturate(1.4);
    z-index: 900;
  }
  body.side-open #insights, body.side-open #insights.insights-charts { left: 424px; }
  .insights-left { flex: 0 0 360px; justify-content: flex-start; }
  .summary-cards { gap: 8px; }
  .insights-right, .insights-charts .insights-right { flex: 1; min-width: 0; padding: 0; }
  .drawer-toggle {
    position: absolute;
    top: -15px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 901;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 14px;
    border: 1px solid var(--glass-line);
    border-radius: 999px;
    background: var(--glass-solid);
    color: var(--ink-2);
    font: inherit;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.25);
  }
  .drawer-toggle:hover { color: var(--accent-ink); }
  .dt-caret { transition: transform 0.2s ease; }

  /* folded: one row of numbers */
  body.drawer-collapsed #insights, body.drawer-collapsed #insights.insights-charts { height: auto; min-height: 0; padding: 10px 16px 12px; }
  body.drawer-collapsed .insights-right { display: none; }
  body.drawer-collapsed .insights-left { flex: 1 1 auto; }
  body.drawer-collapsed .summary-cards { grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); grid-auto-rows: auto; }
  body.drawer-collapsed .card { padding: 6px 10px; }
  body.drawer-collapsed .drawer-period { margin-bottom: 6px; }
  body.drawer-collapsed .dt-caret { transform: rotate(180deg); }

  /* narrower windows: the cards go in a single column beside the chart, the pill wraps */
  @media (max-width: 1180px) { .insights-left { flex-basis: 300px; } }
}
@container main (max-width: 700px) {
  #insights, #insights.insights-charts { flex-direction: column; overflow-y: auto; max-height: 46vh; }
  .insights-left { flex: none; width: 100%; }
}

/* ── Phones and tablets: the standard tabs under the map, in glass and indigo ── */
@media (max-width: 900px) {
  .mode-tabs { background: var(--glass-solid); border-color: var(--line); backdrop-filter: none; }
  #controls { background: var(--glass); }
  .period-menu { order: 4; flex: 1 1 150px; min-width: 0; position: static; }
  #controls .radius-group { flex: 0 0 auto; }
  #controls .period-menu .pm.pm-btn.pm { width: 100%; min-height: 40px; }
  .pm-range { display: none; }
  .pm-text { flex: 1; }
  .period-menu-pop { position: absolute; left: 0; right: 0; min-width: 0; width: auto; top: calc(100% + 8px); max-height: 60vh; overflow-y: auto; }
  #controls .period-menu .period-menu-pop button.pm.pm-opt.pm { min-height: 44px; }
  .mobile-tab-bar { background: #f1f4f9; }
  .mobile-tab.active { color: var(--accent-ink); border-bottom-color: var(--accent); }
}
@media (max-height: 500px) and (orientation: landscape) {
  #controls .period-menu .pm.pm-btn.pm { min-height: 40px; }
  .pm-range { display: none; }
  .period-menu-pop { min-width: 220px; }
}

.chg.down, .ask-diff.down { color: var(--down); }
.recent-date { color: var(--muted); }

@media (max-width: 900px) {
  #controls .area-toggle { flex: 1 1 60%; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .sold-map .mode-tabs, .active-map .mode-tabs { left: auto !important; }
}

/* ═══════════════════════════════════════════════════════════
   PHONE · D · BOTTOM TAB NAVIGATION
   A native-style bar of tabs at the bottom: Map, Listings, Insights, Filters (and Areas in Neighbourhood mode). Each tab is its
   own full-screen view; nothing is stacked on top of the map. Desktop (901px and wider) ignores all of this.
   ═══════════════════════════════════════════════════════════ */
.m-only { display: none; }

@media (max-width: 900px), (max-height: 500px) and (orientation: landscape) {
  :root {
    --m-top: env(safe-area-inset-top, 0px);
    --m-bottom: env(safe-area-inset-bottom, 0px);
    --m-nav-h: calc(62px + var(--m-bottom));
    --m-bar-h: calc(60px + var(--m-top));
    --tap: 44px;
    --m-bg: #f1f4f9;
  }

  /* the page: a fixed map above the tab bar; the views are laid over the map */
  html, body { height: 100% !important; overflow: hidden !important; overscroll-behavior: none; }
  body { display: block !important; }
  #appContainer, #mainPanel { position: fixed !important; inset: 0 !important; display: block !important; height: auto !important; min-height: 0 !important; flex: none !important; grid-template-columns: none !important; grid-template-rows: none !important; }
  #appContainer { z-index: 1100; }
  #map { position: absolute !important; inset: 0 0 var(--m-nav-h) 0 !important; width: 100% !important; height: auto !important; min-height: 0 !important; grid-column: auto !important; grid-row: auto !important; }
  #listingsPanel, #areasPanel { display: none !important; }

  /* Sold | Active: a small pill, top left, over the map and over the top bar */
  .sold-map .mode-tabs, .active-map .mode-tabs {
    position: fixed !important; top: calc(7px + var(--m-top)) !important; left: 10px !important; right: auto !important; bottom: auto !important;
    margin: 0 !important; padding: 3px !important; border-radius: 15px !important; z-index: 1300 !important; gap: 0;
    background: #e8ecf3; border: 0; box-shadow: none; backdrop-filter: none;
  }
  body[data-mtab="map"] .mode-tabs { background: var(--glass-solid) !important; border: 1px solid var(--line) !important; box-shadow: var(--shadow) !important; }
  .sold-map .mode-tabs a, .active-map .mode-tabs a { display: inline-flex; align-items: center; justify-content: center; min-height: var(--tap); padding: 0 16px; font-size: 14px; font-weight: 700; border-radius: 12px; }
  .sold-map .mode-tabs a.active, .active-map .mode-tabs a.active { background: var(--ink); color: #fff; }

  /* ── bottom navigation ── */
  .mobile-tab-bar { display: flex !important; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1200; height: var(--m-nav-h); padding: 0 0 var(--m-bottom); background: var(--glass-solid) !important; border-top: 1px solid var(--line) !important; box-shadow: 0 -4px 18px rgba(15, 23, 42, 0.08); }
  .mobile-tab { position: relative; flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: var(--tap); padding: 4px 2px 2px; border: 0 !important; border-radius: 0 !important; background: transparent !important; box-shadow: none !important; color: var(--muted) !important; font: inherit; -webkit-tap-highlight-color: transparent; }
  .mobile-tab .m-ico { font-size: 22px; line-height: 1; filter: grayscale(1); opacity: 0.75; }
  .mobile-tab .m-lbl { font-size: 12px; font-weight: 700; line-height: 1.2; }
  .mobile-tab.active { background: transparent !important; box-shadow: none !important; border-color: transparent !important; color: var(--accent-ink) !important; }
  .mobile-tab.active .m-ico { filter: none; opacity: 1; }
  .mobile-tab.active::before { content: ""; position: absolute; top: 0; left: 24%; right: 24%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent); }
  .mobile-tab[hidden] { display: none !important; }
  .m-badge { position: absolute; top: 4px; left: calc(50% + 6px); min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 800; line-height: 20px; text-align: center; box-shadow: 0 0 0 2px var(--glass-solid); }
  .m-badge[hidden] { display: none; }

  /* ── top bar: the title of the view; none on the map ── */
  .m-topbar { display: none; position: fixed; top: 0; left: 0; right: 0; z-index: 1150; height: var(--m-bar-h); padding: var(--m-top) 12px 0 164px; background: var(--glass-solid); box-shadow: 0 1px 0 var(--line); align-items: center; }
  body:not([data-mtab="map"]) .m-topbar { display: flex; }
  .m-bar-text { min-width: 0; display: flex; flex-direction: column; justify-content: center; line-height: 1.2; }
  .m-bar-text h1 { margin: 0; font-size: 18px; font-weight: 800; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .m-bar-sub { font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .m-sum-status { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; position: fixed; left: 12px; right: 12px; top: calc(var(--m-bar-h) + 6px); z-index: 1250; padding: 8px 12px; border-radius: 12px; font-size: 13px; color: #78350f; background: #fffbeb; border: 1px solid #fcd34d; box-shadow: var(--shadow); }
  body[data-mtab="map"] .m-sum-status { top: calc(66px + var(--m-top)); }
  .m-sum-status[hidden] { display: none; }
  .m-sum-status.is-error { color: #7f1d1d; background: #fef2f2; border-color: #fca5a5; }
  .m-sum-status button { min-height: var(--tap); padding: 0 14px; border: 1px solid #cdd6e3; border-radius: 10px; background: #fff; font: inherit; font-weight: 700; color: var(--ink); }

  /* Leaflet: the zoom buttons and the attribution sit just above the tab bar (the map ends there) */
  .leaflet-top.leaflet-left { display: none; }
  .leaflet-control-zoom a, .leaflet-touch .leaflet-bar a { width: var(--tap) !important; height: var(--tap) !important; line-height: var(--tap) !important; }
  .leaflet-control-attribution a { display: inline-block; padding: 14px 3px !important; margin: -14px 0 !important; }
  .drag-handle::after { content: ""; position: absolute; inset: -14px; border-radius: 50%; }

  /* ── the views: Listings, Areas, Insights fill the space between the bars ── */
  #mobileListingsPanel, #mobileAreasPanel, #insights {
    display: none !important; position: fixed !important; left: 0; right: 0; top: var(--m-bar-h) !important; bottom: var(--m-nav-h) !important; height: auto !important; min-height: 0 !important; max-height: none !important; z-index: 1000;
    flex-direction: column; overflow-y: auto !important; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
    background: var(--m-bg) !important; border: 0 !important; border-radius: 0 !important; box-shadow: none !important; backdrop-filter: none !important; padding: 0 !important; margin: 0 !important; grid-column: auto !important; grid-row: auto !important;
  }
  body[data-mtab="listings"] #mobileListingsPanel, body[data-mtab="areas"] #mobileAreasPanel { display: flex !important; }
  body[data-mtab="insights"] #insights { display: flex !important; padding: 14px 14px 24px !important; gap: 14px !important; }

  /* listings: search and sort share a row at the top of the scroll; the pages come last */
  #mobileListingsPanel { flex-direction: row !important; flex-wrap: wrap; align-content: flex-start; }
  #mobileListingsPanel .search-container { position: sticky; top: 0; z-index: 3; flex: 1 1 0; min-width: 0; display: flex !important; align-items: center; padding: 8px 6px 8px 12px; background: var(--m-bg) !important; border: 0; }
  #mobileListingsPanel .search-container .search-icon { display: none; }
  #mobileListingsPanel .sort-container { position: sticky; top: 0; z-index: 3; flex: 0 0 168px; display: flex; align-items: center; padding: 8px 12px 8px 0; background: var(--m-bg) !important; border: 0; }
  #mobileListingsPanel .sort-container label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  #mobileListingsPanel .search-container input, #mobileListingsPanel .sort-container select { width: 100%; min-height: var(--tap); padding-left: 10px; font-size: 15px; background: #fff; }
  #mobileListingsPanel .sort-container select { flex: 1; min-width: 0; padding-right: 4px; }
  #mobileListingsPanel .listing-rows { flex: 1 1 100% !important; overflow: visible !important; padding: 2px 12px 4px !important; min-height: 0; }
  #mobileListingsPanel .pagination-controls { position: static !important; flex: 1 1 100%; padding: 8px 12px 24px; background: transparent !important; border: 0 !important; flex-wrap: wrap; justify-content: center; }
  #mobileListingsPanel .listing-row { min-height: 88px; background: #fff; }
  #mobileListingsPanel .listing-row.highlight:not(.is-selected) { background: #f7f7ff; border: 2px solid var(--accent) !important; box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.18); }
  .page-btn, .page-ellipsis { min-width: var(--tap) !important; width: var(--tap) !important; height: var(--tap) !important; }
  .listing-info .view-btn, .selection-banner button, .data-status-btn, .area-clear, .chart-btn, .insight-tab, .chip-btn { min-height: var(--tap) !important; min-width: var(--tap); }
  #mobileAreasPanel .areas-body { flex: none; background: #fff; }
  .areas-filter, .area-legend-metric select, .th-btn { min-height: var(--tap) !important; }

  /* insights */
  .insights-left, .insights-right { flex: none !important; width: 100% !important; min-height: 0 !important; }
  .insights-right { display: flex; flex-direction: column; }
  .chart-container-full { flex: none !important; height: 260px !important; min-height: 260px !important; }
  #insights .drawer-period { display: none; }   /* the period is in the top bar */

  /* ── the Filters tab: #controls is a page between the two bars ── */
  #controls { display: none !important; }
  body[data-mtab="filters"] #controls {
    display: grid !important; position: fixed !important; left: 0 !important; right: 0 !important; top: var(--m-bar-h) !important; bottom: var(--m-nav-h) !important; z-index: 1150 !important;
    width: auto !important; max-width: none !important; height: auto !important; transform: none !important; transition: none !important;
    grid-template-columns: 1fr auto; align-content: start; gap: 8px 10px;
    padding: 6px 16px 96px !important; border: 0 !important; border-radius: 0 !important; box-shadow: none !important; backdrop-filter: none !important;
    background: var(--glass-solid) !important; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  }
  body[data-mtab="filters"] #controls > *, body[data-mtab="filters"] #controls .filter-section { grid-column: 1 / -1; min-width: 0; order: 0 !important; }
  body[data-mtab="filters"] #controls #filterPanel { display: contents !important; visibility: visible !important; opacity: 1 !important; pointer-events: auto !important; transform: none !important; }
  body[data-mtab="filters"] #controls .filter-header { display: contents !important; }
  body[data-mtab="filters"] #controls .filter-header h3 { display: none; }
  body[data-mtab="filters"] #controls #clearFilters { grid-column: 2 !important; grid-row: 1; justify-self: end; min-height: var(--tap); padding: 0 14px; border-radius: 12px; background: #ffffff !important; color: var(--down) !important; border: 1px solid #f1c5c5 !important; font-size: 14px; font-weight: 700; }
  body[data-mtab="filters"] #controls .m-sec-label { display: block; grid-column: 1 !important; grid-row: 1; align-self: center; margin: 0; font-size: 12px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
  body[data-mtab="filters"] #controls .m-sec-label[data-sec="period"] { grid-column: 1 / -1 !important; grid-row: auto; margin-top: 10px; }
  body[data-mtab="filters"] #controls #toggleListings, body[data-mtab="filters"] #controls #toggleAreas, body[data-mtab="filters"] #controls #filterToggle, body[data-mtab="filters"] #controls #periodMenuBtn { display: none !important; }
  body[data-mtab="filters"] #controls .area-toggle { display: flex; width: 100%; padding: 3px; }
  body[data-mtab="filters"] #controls .area-toggle button.area-btn.area-btn.area-btn { flex: 1; min-height: var(--tap); font-size: 15px; }
  body[data-mtab="filters"] #controls .radius-group { display: flex; align-items: center; gap: 10px; }
  body[data-mtab="filters"] #controls .radius-group[hidden] { display: none !important; }
  body[data-mtab="filters"] #controls .radius-group label { font-size: 15px; color: var(--ink-2); }
  body[data-mtab="filters"] #controls input[type="number"] { width: 84px !important; height: var(--tap) !important; font-size: 16px !important; padding: 0 10px !important; }
  body[data-mtab="filters"] #controls .period-menu { display: block; position: static; width: 100%; flex: none; }
  body[data-mtab="filters"] #controls .period-menu .period-menu-pop, body[data-mtab="filters"] #controls .period-menu .period-menu-pop[hidden] {
    display: grid !important; position: static; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; min-width: 0; max-height: none; padding: 0; border: 0; box-shadow: none; background: transparent; overflow: visible;
  }
  body[data-mtab="filters"] #controls .period-menu .period-menu-pop button.pm.pm-opt.pm { min-height: var(--tap); padding: 8px 10px; border: 1px solid #d5dce8; border-radius: 12px; font-size: 14px; line-height: 1.2; white-space: normal !important; }
  body[data-mtab="filters"] #controls .period-menu .period-menu-pop button.pm.pm-opt.pm.is-active { border-color: var(--accent); }
  body[data-mtab="filters"] #controls .period-menu .period-dock { grid-column: 1 / -1; margin: 4px 0 0; padding: 14px 6px 6px; }
  body[data-mtab="filters"] #controls .filter-section { display: block; margin: 0; padding: 14px 0 4px; border: 0; border-top: 1px solid var(--line); background: transparent; }
  body[data-mtab="filters"] #controls .filter-section legend { margin: 0 0 6px; padding: 0; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 800; float: none; }
  body[data-mtab="filters"] #controls .range-labels span { font-size: 14px; padding: 6px 10px; }
  body[data-mtab="filters"] #controls .bed-btn, body[data-mtab="filters"] #controls .ptype-btn { min-height: var(--tap); font-size: 15px; }
  body[data-mtab="filters"] #controls #bedFilter { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
  body[data-mtab="filters"] #controls #ptypeFilter, body[data-mtab="filters"] #controls #changeFilter { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  body[data-mtab="filters"] #controls .bed-btn { min-width: 0; padding: 0; }
  body[data-mtab="filters"] #controls .ptype-btn { padding: 0 6px; font-size: 14px; }
  body[data-mtab="filters"] #controls .filter-hint { font-size: 12.5px; color: var(--muted); }
  body[data-mtab="filters"] #controls .filter-section .noUi-target { margin: 10px 20px 14px !important; }
  body[data-mtab="filters"] #controls .noUi-handle { width: var(--tap) !important; height: var(--tap) !important; top: -19px !important; right: -22px !important; }
  body[data-mtab="filters"] #controls .noUi-handle::after { top: 12px !important; left: 12px !important; }
  body[data-mtab="filters"] #controls .m-filter-foot { display: block; position: fixed; left: 0; right: 0; bottom: var(--m-nav-h); z-index: 5; margin: 0; padding: 10px 16px; background: var(--glass-solid); border-top: 1px solid var(--line); }
  body[data-mtab="filters"] #controls .m-filter-foot .m-apply { width: 100%; min-height: 52px; padding: 0 16px; border: 0; border-radius: 14px; background: var(--accent); background-image: none; color: #fff; font: inherit; font-size: 17px; font-weight: 800; box-shadow: 0 4px 14px rgba(79, 70, 229, 0.4); }
}

/* a phone on its side: a slimmer bar and tab bar; the tabs keep icon and label side by side */
@media (max-height: 500px) and (orientation: landscape) {
  :root { --m-nav-h: calc(52px + var(--m-bottom)); --m-bar-h: calc(54px + var(--m-top)); }
  .mobile-tab { flex-direction: row; gap: 6px; }
  .mobile-tab .m-ico { font-size: 18px; }
  .mobile-tab.active::before { left: 10%; right: 10%; }
  .m-badge { position: static; margin-left: 2px; box-shadow: none; }
}

/* ═══════════════════════════════════════════════════════════
   PHONE · D · selection bar, the selected listing, and page controls
   ═══════════════════════════════════════════════════════════ */
.page-status { display: none; }   /* "Page 5 of 22": phones only; the desktop shows the page numbers */
.m-selbar { display: none; }

@media (max-width: 900px), (max-height: 500px) and (orientation: landscape) {
  /* ── selection bar: what is selected, on every tab, with a Clear button that is always in the same place ── */
  .m-selbar:not([hidden]) { display: flex; flex-direction: column; position: fixed; left: 0; right: 0; top: var(--m-bar-h); z-index: 1190; background: var(--accent-soft, #eef0ff); border-bottom: 2px solid var(--accent); box-shadow: 0 6px 14px rgba(15, 23, 42, 0.12); }
  body[data-mtab="map"] .m-selbar:not([hidden]) { top: calc(66px + var(--m-top)); left: 10px; right: 10px; border: 2px solid var(--accent); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
  .m-selrow { display: flex; align-items: center; gap: 8px; min-height: 56px; padding: 6px 12px 6px 14px; }
  .m-selrow + .m-selrow { border-top: 1px solid #c7d2fe; }
  .m-seltext { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 1px; min-height: var(--tap); padding: 0; border: 0; background: none; font: inherit; text-align: left; color: var(--ink); }
  button.m-seltext { cursor: pointer; }
  .m-seltext b { font-size: 11px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent-ink); }
  .m-seltext span { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .m-selclear { flex: none; min-height: var(--tap); padding: 0 14px; border: 1px solid var(--accent); border-radius: 12px; background: #fff; color: var(--accent-ink); font: inherit; font-size: 14px; font-weight: 800; }
  /* the views start under the bar when it shows */
  #mobileListingsPanel, #mobileAreasPanel, #insights { top: calc(var(--m-bar-h) + var(--m-sel-h, 0px)) !important; }
  body[data-mtab="filters"] #controls { top: calc(var(--m-bar-h) + var(--m-sel-h, 0px)) !important; }
  /* on the Insights tab the chart's own selection bar (one chip per selection) does that job */
  body[data-mtab="insights"] .selection-bar { position: sticky; top: -14px; z-index: 5; }

  /* ── the selected listing in the list ── */
  #mobileListingsPanel .listing-row.is-selected { flex-wrap: wrap; border: 2px solid var(--accent) !important; background: #f7f7ff; box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.18); }
  #mobileListingsPanel .listing-row.is-selected .listing-info { flex: 1 1 0; min-width: 0; }
  .sel-head { flex: 1 1 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: -2px -2px 8px; padding: 0 0 6px; border-bottom: 1px solid #c7d2fe; }
  .sel-badge { display: inline-flex; align-items: center; min-height: 28px; padding: 0 10px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; }
  .sel-hint { font-size: 12.5px; color: var(--muted); text-align: right; }
  #mobileListingsPanel .listing-row.is-selected .sell-note { margin: 4px 0 6px; font-size: 13px; color: var(--ink-2); }
  .price-marker.is-linked .price-label, .count-marker.is-linked .count-label { outline: 3px solid var(--accent); outline-offset: 2px; }

  /* ── page controls: ‹ Prev   Page 5 of 22   Next ›  (the numbers are for the desktop) ── */
  .pagination-controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 8px; }
  .pagination-controls .page-btn:not(.nav-btn), .pagination-controls .page-ellipsis { display: none !important; }
  .pagination-controls .page-btn.nav-btn { width: auto !important; min-width: 104px !important; padding: 0 14px; font-size: 0; font-weight: 700; }
  .pagination-controls .page-btn.nav-btn::after { font-size: 15px; }
  .pagination-controls .page-btn[data-dir="prev"] { order: 1; }
  .pagination-controls .page-btn[data-dir="prev"]::after { content: "\2039  Prev"; }
  .pagination-controls .page-btn[data-dir="next"] { order: 3; }
  .pagination-controls .page-btn[data-dir="next"]::after { content: "Next  \203A"; }
  .pagination-controls .page-status { display: block; order: 2; flex: 1; text-align: center; font-size: 14px; font-weight: 700; color: var(--ink); }
  .pagination-controls .pagination-info { order: 4; flex: 1 1 100%; text-align: center; font-size: 12.5px; color: var(--muted); }
}
