/* ═══════════════════════════════════════════════════════════
   OTTAWA MAP - MODERN UI STYLES
   ═══════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ─── 1. RESET & BASE ───────────────────────────────────────── */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100vh;
  overflow: hidden;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: #1e293b;
  background-color: #f8fafc;
}

body {
  display: flex;
  flex-direction: column;
}

/* ─── 2. CONTROLS OVERLAY ──────────────────────────────────── */
#controls {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  padding: 12px 20px;
  border-radius: 12px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  z-index: 9999;
  transition: all 0.3s ease;
}

#controls label {
  font-size: 14px;
  font-weight: 500;
  color: #475569;
}

#controls input[type="number"] {
  width: 70px;
  padding: 6px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s ease;
}

#controls input[type="number"]:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

#controls button:not(.bed-btn):not(.ptype-btn):not(.clear-filters-btn) {
  padding: 8px 16px;
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.2);
}

#controls button:not(.bed-btn):not(.ptype-btn):not(.clear-filters-btn):hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(37, 99, 235, 0.3);
}

#controls button:not(.bed-btn):not(.ptype-btn):not(.clear-filters-btn):active {
  transform: translateY(0);
}

/* ─── 3. APP CONTAINER ──────────────────────────────────────── */
#appContainer {
  flex: 1;
  display: flex;
  height: 0;
}

/* ─── 4. LISTINGS SIDEBAR ───────────────────────────────────── */
#listingsPanel {
  width: 420px;
  max-width: 90vw;
  flex: none;   /* same as #areasPanel: keep its 420px next to the map */
  background: #ffffff;
  box-shadow: 4px 0 12px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1001;
}

#listingsPanel.open {
  transform: translateX(0);
}

#listingsPanel.hidden {
  display: none;
}

.toolbar-btn {
  position: sticky;
  top: 0;
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, #0369a1 0%, #075985 100%);
  color: white;
  border: none;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: all 0.2s ease;
  z-index: 10;
}

.toolbar-btn:hover {
  background: linear-gradient(135deg, #075985 0%, #0c4a6e 100%);
}

/* Search Container */
.search-container {
  position: sticky;
  top: 45px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  z-index: 9;
}

.search-container .search-icon {
  font-size: 16px;
  flex-shrink: 0;
  opacity: 0.6;
}

.search-container input {
  flex: 1;
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: white;
  color: #1e293b;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  outline: none;
}

.search-container input::placeholder {
  color: #566072;
}

.search-container input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Sort Container */
.sort-container {
  position: sticky;
  top: 90px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
  z-index: 9;
}

.sort-container label {
  font-size: 14px;
  font-weight: 500;
  color: #475569;
}

.sort-container select {
  flex: 1;
  padding: 6px 12px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: white;
  cursor: pointer;
  transition: border-color 0.2s ease;
}

.sort-container select:focus {
  outline: none;
  border-color: #2563eb;
}

/* ─── 5. MAIN PANEL ─────────────────────────────────────────── */
#mainPanel {
  flex: 1;
  min-width: 0;   /* shrink beside an open sidebar instead of running off the right edge (wide charts set a large min width) */
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 1fr auto;
  height: 100%;
}

#mainPanel.full-map {
  grid-template-rows: 1fr;
}

#map {
  grid-row: 1;
  width: 100%;
  height: 100%;
  min-height: 0;
}

/* ─── 6. INSIGHTS FOOTER ────────────────────────────────────── */
#insights {
  height: 35vh;
  /* Fixed height for footer */
  min-height: 280px;
  display: flex;
  gap: 20px;
  padding: 16px 24px;
  background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
  border-top: 1px solid #e2e8f0;
}

#insights.hidden {
  display: none;
}

/* LEFT COLUMN: Summary Cards */
.insights-left {
  flex: 0 0 450px;
  /* Fixed width for cards */
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  /* 2 columns */
  grid-auto-rows: 1fr;
  gap: 12px;
}

.card {
  background: white;
  border-radius: 10px;
  padding: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.1);
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.card strong {
  font-size: 11px;
  font-weight: 600;
  color: #526071;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.card span {
  font-size: 18px;
  font-weight: 700;
  color: #1e293b;
}

/* RIGHT COLUMN: Chart */
.insights-right {
  flex: 1;
  /* Take remaining space */
  display: flex;
  flex-direction: column;
  background: white;
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  min-width: 0;
  /* Prevent flex overflow */
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.chart-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.chart-container-full {
  flex: 1;
  position: relative;
  min-height: 0;
  width: 100%;
}

.chart-container-full canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100% !important;
  height: 100% !important;
}

/* Chart Controls */
.chart-controls {
  /* Deprecated in new layout, using .chart-header .btn-group instead */
  display: none;
}

.btn-group {
  display: inline-flex;
  background: #e2e8f0;
  padding: 4px;
  border-radius: 8px;
  gap: 4px;
}

.btn-group[hidden] {
  display: none;
}

.chart-btn {
  padding: 6px 12px;
  border: none;
  background: transparent;
  color: #526071;
  font-size: 13px;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.chart-btn:hover {
  color: #1e293b;
  background: rgba(255, 255, 255, 0.5);
}

.chart-btn.active {
  background: white;
  color: #2563eb;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* ─── 8. FILTER PANEL ───────────────────────────────────────── */
#filterPanel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: 320px;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(10px);
  padding: 0;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  z-index: 9999;
  overflow: hidden;
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
  visibility: hidden;
  opacity: 0;
  transform: translateX(-50%) translateY(10px);
  pointer-events: none;
  left: 50%;
  /* Center it relative to parent #controls */
}

#filterPanel.show {
  visibility: visible;
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.filter-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  border-bottom: 1px solid #e2e8f0;
}

.filter-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #1e293b;
}

.clear-filters-btn {
  padding: 6px 12px;
  background: #dc2626;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.clear-filters-btn:hover {
  background: #b91c1c;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(239, 68, 68, 0.3);
}

.filter-section {
  border: none;
  padding: 16px;
  margin: 0;
  border-bottom: 1px solid #f1f5f9;
}

.filter-section:last-child {
  border-bottom: none;
}

.filter-section legend {
  font-size: 14px;
  font-weight: 600;
  color: #475569;
  margin-bottom: 12px;
  padding: 0;
}

/* ─── noUiSlider Customization ──────────────────────────────── */
#filterPanel .noUi-target {
  background: #e2e8f0;
  border: none;
  border-radius: 6px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.06);
  height: 6px;
}

#filterPanel .noUi-connect {
  background: linear-gradient(90deg, #3b82f6 0%, #2563eb 100%);
  border-radius: 6px;
}

#filterPanel .noUi-handle {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: white;
  border: 2.5px solid #2563eb;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25);
  cursor: grab;
  top: -8px;
  right: -10px;
}

#filterPanel .noUi-handle:active {
  cursor: grabbing;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15), 0 2px 6px rgba(37, 99, 235, 0.25);
  transform: scale(1.1);
}

#filterPanel .noUi-handle::before,
#filterPanel .noUi-handle::after {
  display: none;
}

/* ─── Range Value Labels ────────────────────────────────────── */
.range-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  gap: 8px;
}

.range-labels span {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  color: #334155;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.filter-mode-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding: 8px 12px;
  background: #f8fafc;
  border-radius: 6px;
  border-left: 3px solid #2563eb;
}

.filter-mode-indicator .mode-label {
  font-size: 12px;
  font-weight: 500;
  color: #526071;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.filter-mode-indicator #bedModeText {
  font-size: 13px;
  font-weight: 600;
  color: #2563eb;
}

.filter-hint {
  margin: 10px 0 0 0;
  font-size: 12px;
  color: #526071;
  font-style: italic;
  line-height: 1.4;
}

#bedFilter,
#ptypeFilter,
#changeFilter {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.bed-btn,
.ptype-btn {
  flex: 1;
  min-width: 45%;
  padding: 10px 16px;
  border: 2px solid #2563eb;
  background: transparent;
  color: #2563eb;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  text-align: center;
}

.bed-btn {
  min-width: 50px;
}

.ptype-btn {
  font-size: 13px;
  /* Slightly smaller for longer text */
  flex: 1 1 45%;
  /* Use 2x2 grid layout */
}

.bed-btn:hover,
.ptype-btn:hover {
  background: rgba(37, 99, 235, 0.05);
  transform: translateY(-1px);
}

.bed-btn.selected,
.ptype-btn.selected {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: white;
  border-color: #1d4ed8;
  box-shadow: 0 4px 8px rgba(37, 99, 235, 0.4);
  transform: scale(1.05);
}

.bed-btn.selected-exact {
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  color: white;
  border-color: #059669;
  box-shadow: 0 2px 6px rgba(5, 150, 105, 0.3);
}

.bed-btn.selected-exact::after {
  content: "✓";
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 10px;
}

/* ─── 10. LISTING ROWS (SIDEBAR) ────────────────────────────── */
.listing-rows {
  padding: 12px;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.listing-row {
  display: flex;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid #e2e8f0;
  background: white;
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.listing-row:hover {
  background: #f8fafc;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.listing-row.highlight {
  background: #eff6ff;
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.listing-row img,
.no-image-placeholder {
  width: 140px;
  height: 90px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  background: linear-gradient(135deg, #e2e8f0 0%, #cbd5e1 100%);
}

.image-wrapper {
  width: 140px;
  height: 90px;
  flex-shrink: 0;
  border-radius: 6px;
  overflow: hidden;
}

.listing-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.listing-info strong {
  font-size: 18px;
  font-weight: 700;
  color: #2563eb;
}

/* "▲ 2.3% over asking" / "▼ 1.5% under asking" under a listing's price */
.ask-diff {
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  margin-top: -2px;
}

.ask-diff.up { color: var(--up, #047857); }
.ask-diff.down { color: var(--down, #dc2626); }
.ask-diff.flat { color: #526071; }

.listing-info p {
  margin: 0;
  font-size: 13px;
  color: #526071;
  line-height: 1.4;
}

.listing-info .view-btn {
  margin-top: auto;
  padding: 6px 14px;
  font-size: 13px;
}

/* ─── Selection Banner ───────────────────────────────────────── */
.selection-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: linear-gradient(135deg, #1e40af 0%, #1e3a8a 100%);
  color: white;
  font-size: 13px;
  font-weight: 600;
  border-bottom: 1px solid #1e40af;
}

.selection-banner button {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.2s ease;
}

.selection-banner button:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* ─── Pagination Controls ───────────────────────────────────── */
.pagination-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 12px;
  border-top: 1px solid #e2e8f0;
  background: #f8fafc;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.pagination-controls:empty {
  display: none;
}

.page-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: #475569;
  cursor: pointer;
  transition: all 0.15s ease;
}

.page-btn:hover {
  background: #f1f5f9;
  border-color: #566072;
}

.page-btn.active {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: white;
  border-color: #2563eb;
  font-weight: 600;
}

.page-btn.nav-btn {
  font-size: 14px;
  font-weight: 700;
  color: #2563eb;
  border-color: #2563eb;
}

.page-btn.nav-btn:disabled {
  color: #cbd5e1;
  border-color: #e2e8f0;
  cursor: default;
  background: #f8fafc;
}

.page-ellipsis {
  width: 24px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #566072;
  font-size: 14px;
  font-weight: 600;
  user-select: none;
}

.pagination-info {
  font-size: 12px;
  color: #566072;
  margin-left: 8px;
}

/* ─── Selected Marker ───────────────────────────────────────── */
.marker-selected .count-label {
  background: #dc2626 !important;
  border-color: #b91c1c !important;
  box-shadow: 0 0 12px rgba(220, 38, 38, 0.5) !important;
  transform: scale(1.1);
}

/* ─── 11. MAP MARKERS ────────────────────────────────────────── */
.red-dot {
  width: 12px;
  height: 12px;
  background: #dc2626;
  border: 2px solid white;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  box-sizing: border-box;
}

/* Cluster Marker (grouping by Leaflet MarkerCluster) */
.cluster-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.cluster-marker .cluster-label {
  background: #7c3aed;
  color: white;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(124, 58, 237, 0.3);
  border: 1px solid #6d28d9;
}

.cluster-marker:hover .cluster-label {
  background: #6d28d9;
  border-color: #5b21b6;
  transform: scale(1.05);
}

/* Price Label Marker (Single Property) */
.price-marker {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
}

.price-marker .marker-dot {
  display: none;
  /* Hide the dot, show only label */
}

.price-marker .price-label {
  position: relative;
  background: white;
  color: #1e293b;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  border: 1px solid #e2e8f0;
}

.price-marker:hover .price-label {
  background: #2563eb;
  color: white;
  border-color: #2563eb;
}

/* Count Badge Marker (Multiple Properties) */
.count-marker {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
}

.count-marker .marker-dot {
  display: none;
  /* Hide the dot, show only badge */
}

.count-marker .count-label {
  position: relative;
  background: #2563eb;
  color: white;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.3);
  border: 1px solid #1d4ed8;
}

.count-marker:hover .count-label {
  background: #1d4ed8;
  border-color: #1e40af;
  transform: scale(1.05);
}

.drag-handle {
  width: 24px;
  height: 24px;
  background: #f59e0b;
  /* Amber/Orange for high visibility */
  border: 3px solid white;
  border-radius: 50%;
  cursor: move;
  box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.7);
  box-sizing: border-box;
  animation: handle-pulse 2s infinite;
  z-index: 9999 !important;
  /* Force to top */
}

@keyframes handle-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.7);
  }

  70% {
    box-shadow: 0 0 0 15px rgba(245, 158, 11, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(245, 158, 11, 0);
  }
}

/* ─── 12. RESPONSIVE DESIGN ─────────────────────────────── */

/* ── Tablet / narrow desktop ── */
@media (max-width: 1100px) {
  .summary-cards {
    grid-template-columns: repeat(2, 1fr);
  }

  .bottom-section {
    flex-direction: column;
    gap: 12px;
  }

  .chart-container {
    min-width: 0;
    max-width: 100%;
  }

  .suggested-listing-card {
    min-width: 0;
    max-width: 100%;
    max-height: 400px;
  }

  .image-carousel {
    height: clamp(160px, 20vw, 200px);
  }

  #insights {
    height: 45vh;
  }
}

/* ── Mobile ── */
@media (max-width: 900px) {

  /* Body: full-height, no overflow so bottom panel fills space */
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  body {
    display: flex;
    flex-direction: column;
  }

  /* Controls bar: full-width, compact */
  #controls {
    flex-wrap: nowrap;
    justify-content: space-between;
    width: calc(100% - 16px);
    left: 8px;
    transform: none;
    padding: 6px 8px;
    gap: 4px;
    top: 8px;
  }

  #controls label {
    font-size: 11px;
    white-space: nowrap;
  }

  #controls input[type="number"] {
    width: 40px;
    padding: 4px 6px;
    font-size: 12px;
  }

  #controls button:not(.bed-btn):not(.ptype-btn):not(.clear-filters-btn) {
    padding: 6px 8px;
    font-size: 11px;
    white-space: nowrap;
  }

  /* Leaflet zoom: move to bottom right on mobile */
  .leaflet-top.leaflet-left {
    top: auto !important;
    bottom: 20px !important;
    left: auto !important;
    right: 12px !important;
  }

  /* Filter panel: full width, compact */
  #filterPanel {
    left: 12px !important;
    right: 12px;
    width: auto;
    transform: translateY(10px);
    max-height: 55vh;
    overflow-y: auto;
  }

  #filterPanel.show {
    transform: translateY(0);
  }

  /* Compact filter sections on mobile */
  .filter-header {
    padding: 10px 12px;
  }

  .filter-header h3 {
    font-size: 14px;
  }

  .filter-section {
    padding: 10px 12px;
  }

  .filter-section legend {
    font-size: 13px;
    margin-bottom: 8px;
  }

  .range-labels {
    font-size: 11px;
    margin-top: 6px;
  }

  .bed-btn,
  .ptype-btn {
    border-width: 1.5px;
  }

  .bed-btn {
    min-width: 40px;
    padding: 7px 10px;
    font-size: 13px;
  }

  .ptype-btn {
    font-size: 11px;
    padding: 7px 4px;
    min-width: auto;
  }

  #bedFilter {
    gap: 5px;
  }

  .filter-hint {
    font-size: 11px;
    margin-top: 6px;
  }

  .clear-filters-btn {
    padding: 4px 10px;
    font-size: 12px;
  }

  /* App container: stack vertically, fill height */
  #appContainer {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 0;
    min-height: 0;
  }

  /* Main panel: flex column, fill all space */
  #mainPanel {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 0;
    min-height: 0;
  }

  /* Map: fixed height on mobile */
  #map {
    height: 55vh;
    min-height: 250px;
    flex: none;
  }

  /* Hide desktop sidebar on mobile — we use inline panel instead */
  #listingsPanel {
    display: none !important;
  }

  /* ── Mobile Tab Bar ── */
  .mobile-tab-bar {
    display: flex !important;
    border-top: 1px solid #e2e8f0;
    background: #f8fafc;
    flex: none;
  }

  .mobile-tab {
    flex: 1;
    padding: 10px 0;
    border: none;
    background: transparent;
    font-size: 14px;
    font-weight: 600;
    color: #526071;
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 3px solid transparent;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-tab:active {
    background: #e2e8f0;
  }

  .mobile-tab.active {
    color: #2563eb;
    border-bottom-color: #2563eb;
    background: white;
  }

  /* ── Mobile Listings Panel (inline) ── */
  .mobile-listings-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: white;
    min-height: 0;
  }

  .mobile-listings-panel .sort-container {
    position: sticky;
    top: 0;
    flex: none;
    border-bottom: 1px solid #e2e8f0;
  }

  .mobile-listings-panel .search-container {
    position: sticky;
    top: 0;
    flex: none;
    display: flex !important;
    padding: 10px 12px;
    background: white;
    border-bottom: 1px solid #e2e8f0;
    z-index: 2;
  }

  .mobile-listings-panel .listing-rows {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px 12px;
    min-height: 0;
  }

  .mobile-listings-panel .pagination-controls {
    flex: none;
    position: sticky;
    bottom: 0;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
  }

  /* ── Insights footer: stack cards + chart vertically, fills bottom ── */
  #insights {
    height: auto;
    min-height: auto;
    flex: 1;
    flex-direction: column;
    padding: 12px;
    gap: 12px;
    overflow-y: auto;
  }

  /* When insights is hidden on mobile */
  #insights.mobile-hidden {
    display: none;
  }

  /* Cards: 3 columns on mobile */
  .insights-left {
    flex: none;
    width: 100%;
  }

  .summary-cards {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  .card {
    padding: 10px 8px;
  }

  .card strong {
    font-size: 10px;
    margin-bottom: 2px;
  }

  .card span {
    font-size: 16px;
  }

  /* Chart: full width */
  .insights-right {
    flex: none;
    width: 100%;
    min-height: 200px;
  }

  .chart-container-full {
    min-height: 150px;
  }

  .chart-header {
    flex-wrap: wrap;
    gap: 8px;
  }

  /* Listing rows: slightly more compact */
  .listing-row img,
  .no-image-placeholder {
    width: 100px;
    height: 70px;
  }

  .image-wrapper {
    width: 100px;
    height: 70px;
  }

  .listing-info strong {
    font-size: 16px;
  }

  .listing-info p {
    font-size: 12px;
  }

  .image-carousel {
    height: 180px;
  }
}

/* ── Extra-small mobile ── */
@media (max-width: 480px) {

  #controls {
    font-size: 12px;
    gap: 6px;
    padding: 6px 10px;
  }

  #controls button:not(.bed-btn):not(.clear-filters-btn) {
    padding: 5px 10px;
    font-size: 12px;
  }

  /* Cards: 2 columns on very small screens */
  .summary-cards {
    grid-template-columns: repeat(2, 1fr);
  }

  .card span {
    font-size: 14px;
  }

  #map {
    height: 50vh;
    min-height: 250px;
  }

  .property-info-section strong {
    font-size: 20px;
  }

  .listing-row img,
  .no-image-placeholder {
    width: 80px;
    height: 60px;
  }

  .image-wrapper {
    width: 80px;
    height: 60px;
  }
}

/* ── Desktop: hide mobile-only elements ── */
.mobile-tab-bar {
  display: none;
}

.mobile-listings-panel {
  display: none;
}

/* ── Landscape phone: side-by-side layout ── */
@media (max-height: 500px) and (orientation: landscape) {

  /* Full height, no scroll */
  html,
  body {
    height: 100% !important;
    overflow: hidden !important;
  }

  body {
    display: flex !important;
    flex-direction: column !important;
  }

  /* App container */
  #appContainer {
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    height: 0 !important;
    min-height: 0 !important;
  }

  /* Controls: centered over the map (map is 60% width, center = 30%) */
  #controls {
    padding: 4px 10px !important;
    gap: 6px !important;
    top: 4px !important;
    left: 30% !important;
    width: auto !important;
    max-width: 55% !important;
    transform: translateX(-50%) !important;
    flex-wrap: nowrap !important;
    justify-content: center !important;
    align-items: center !important;
  }

  #controls label {
    font-size: 11px !important;
  }

  #controls input[type="number"] {
    width: 40px !important;
    padding: 2px 4px !important;
    font-size: 11px !important;
  }

  #controls button:not(.bed-btn):not(.clear-filters-btn) {
    padding: 3px 8px !important;
    font-size: 11px !important;
  }

  /* Zoom controls: bottom-left of map */
  .leaflet-top.leaflet-left {
    top: auto !important;
    bottom: 10px !important;
    left: 8px !important;
  }

  /* Hide desktop sidebar */
  #listingsPanel {
    display: none !important;
  }

  /* ── Grid: map left 60%, content right 40% ── */
  #mainPanel {
    display: grid !important;
    grid-template-columns: 60% 40% !important;
    grid-template-rows: auto 1fr !important;
    height: 0 !important;
    min-height: 0 !important;
    flex: 1 !important;
  }

  /* Map: full left column */
  #map {
    grid-column: 1 !important;
    grid-row: 1 / -1 !important;
    height: 100% !important;
    min-height: 0 !important;
    flex: none !important;
  }

  /* ── Tab bar: styled, centered, at top of right column ── */
  .mobile-tab-bar {
    grid-column: 2 !important;
    grid-row: 1 !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    gap: 4px !important;
    padding: 6px 12px !important;
    background: #f1f5f9 !important;
    border-left: 1px solid #e2e8f0;
    border-top: none !important;
    border-bottom: 1px solid #e2e8f0;
    flex: none !important;
  }

  .mobile-tab {
    flex: none !important;
    padding: 5px 16px !important;
    font-size: 12px !important;
    font-weight: 600 !important;
    border: 1px solid #cbd5e1 !important;
    border-radius: 6px !important;
    background: white !important;
    color: #526071 !important;
    border-bottom: 1px solid #cbd5e1 !important;
    transition: all 0.15s ease !important;
  }

  .mobile-tab.active {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%) !important;
    color: white !important;
    border-color: #1d4ed8 !important;
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.3) !important;
  }

  /* Insights: right column content, scrollable */
  #insights {
    grid-column: 2 !important;
    grid-row: 2 !important;
    border-left: 1px solid #e2e8f0;
    overflow-y: auto !important;
    padding: 8px !important;
    gap: 8px !important;
    flex-direction: column !important;
    height: auto !important;
    min-height: 0 !important;
  }

  .insights-left {
    flex: none !important;
    width: 100% !important;
  }

  .insights-right {
    flex: none !important;
    width: 100% !important;
    min-height: 200px !important;
  }

  .chart-container-full {
    min-height: 150px !important;
  }

  /* Mobile listings: right column — NO display:none so JS inline style works */
  .mobile-listings-panel {
    grid-column: 2 !important;
    grid-row: 2 !important;
    border-left: 1px solid #e2e8f0;
    overflow: hidden !important;
    flex-direction: column !important;
    min-height: 0 !important;
  }

  .mobile-listings-panel .sort-container {
    position: sticky !important;
    top: 0 !important;
  }

  .mobile-listings-panel .search-container {
    position: sticky !important;
    top: 0 !important;
    flex: none !important;
    display: flex !important;
    padding: 6px 8px !important;
    background: white !important;
    border-bottom: 1px solid #e2e8f0;
    z-index: 2;
  }

  .mobile-listings-panel .search-container input {
    padding: 5px 8px !important;
    font-size: 12px !important;
  }

  .mobile-listings-panel .listing-rows {
    padding: 6px 8px;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    min-height: 0 !important;
  }

  /* Stat cards: 2 columns for narrow panel */
  .summary-cards {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 4px !important;
  }

  .card {
    padding: 5px 4px;
  }

  .card strong {
    font-size: 9px;
  }

  .card span {
    font-size: 12px;
  }

  .chart-header {
    gap: 4px;
    flex-wrap: wrap;
  }

  .chart-header h3 {
    font-size: 13px;
  }

  .chart-btn {
    padding: 3px 8px;
    font-size: 11px;
  }

  /* Filter panel: drop centered below controls */
  #filterPanel {
    width: 260px !important;
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%) translateY(10px) !important;
  }

  #filterPanel.show {
    transform: translateX(-50%) translateY(0) !important;
  }

  .filter-section {
    padding: 6px 10px;
  }

  .filter-section legend {
    font-size: 12px;
    margin-bottom: 4px;
  }

  .bed-btn {
    padding: 4px 6px !important;
    font-size: 11px !important;
    min-width: 36px !important;
  }

  /* Listing images: compact */
  .listing-row img,
  .no-image-placeholder {
    width: 60px !important;
    height: 44px !important;
  }

  .image-wrapper {
    width: 60px !important;
    height: 44px !important;
  }

  .listing-info strong {
    font-size: 13px !important;
  }

  .listing-info p {
    font-size: 10px !important;
  }
}

/* ─── ACTIVE LISTINGS ───────────────────────────────────────── */

/* Sold | Active switch, top-right of the map (the left side is the listings sidebar and the zoom buttons) */
.mode-tabs {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 9999;
  display: inline-flex;
  padding: 4px;
  gap: 2px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-radius: 12px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.mode-tabs a {
  padding: 8px 18px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 600;
  color: #475569;
  text-decoration: none;
  transition: background 0.2s ease, color 0.2s ease;
}

.mode-tabs a:hover {
  background: #e2e8f0;
}

.mode-tabs a.active {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: #ffffff;
}

/* "▼ $14,100 (6.6%)" next to a price: last asking-price change. Red = cut, green = increase. */
.chg {
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  margin-top: -2px;
}

.chg.down { color: var(--down, #dc2626); }
.chg.up { color: var(--up, #047857); }
.chg.flat { color: #526071; font-weight: 500; }

.price-marker .price-label .arrow { font-size: 10px; }
.price-marker .price-label .arrow.down { color: #dc2626; }
.price-marker .price-label .arrow.up { color: #047857; }
.price-marker:hover .price-label .arrow { color: #ffffff; }

.as-of {
  font-size: 12px;
  color: #526071;
}

.recent-changes {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.recent-row {
  display: grid;
  grid-template-columns: 150px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 8px 4px;
  border-bottom: 1px solid #f1f5f9;
  color: inherit;
  text-decoration: none;
  font-size: 13px;
}

.recent-row:hover { background: #f8fafc; }
.recent-addr { color: #334155; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-date { color: #566072; font-size: 12px; }

.empty-note {
  padding: 16px;
  color: #526071;
  font-size: 13px;
}

.listing-info .ptype-text {
  font-weight: 600;
  color: #475569;
}

/* ─── 13. ACTIVE LISTINGS: INSIGHT CHARTS ───────────────────── */

/* The footer holds charts now, so it gets more of the screen. Scoped: the sold page shares #insights. */
@media (min-width: 1101px) {
  #insights.insights-charts {
    height: 42vh;
    min-height: 340px;
  }
}

.insight-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.insight-tab {
  border: 1px solid transparent;
  background: transparent;
  color: #526071;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.insight-tab:hover { background: #f1f5f9; }
.insight-tab.active { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }

.insight-tab:focus-visible,
.chip-btn:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.insight-pane {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.insight-pane[hidden] { display: none; }

.pane-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 22px;
  margin-bottom: 4px;
  font-size: 12px;
  color: #526071;
}

.pane-hint { margin-right: auto; }

.scatter-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

/* Same shapes as the chart's dots: ▼ cut, ▲ increase, ● unchanged */
.legend-key {
  display: inline-block;
  width: 10px;
  height: 10px;
}

.legend-key.down { background: #dc2626; clip-path: polygon(0 0, 100% 0, 50% 100%); }
.legend-key.up { background: #059669; clip-path: polygon(50% 0, 0 100%, 100% 100%); }
.legend-key.none { background: #94a3b8; border-radius: 50%; }

.chart-box {
  position: relative;
  flex: 1;
  min-height: 0;
}

.chart-pair {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: minmax(0, 1fr);
  gap: 16px;
}

.chart-fig {
  margin: 0;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.chart-fig figcaption {
  margin-bottom: 2px;
  font-size: 12px;
  font-weight: 600;
  color: #475569;
}

.curve-note { font-weight: 600; color: #1e293b; }

.curve-foot {
  margin: 6px 0 0;
  font-size: 11px;
  line-height: 1.4;
  color: #526071;
}

/* What the charts are filtering by */
.selection-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  margin-bottom: 6px;
  padding: 6px 8px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  font-size: 12px;
  color: #1e3a8a;
}

.selection-bar[hidden] { display: none; }
.selection-summary { font-weight: 700; }
.selection-chips { display: flex; flex-wrap: wrap; gap: 4px; }
#clearSelection { margin-left: auto; }

.chip-btn {
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #334155;
  border-radius: 999px;
  padding: 3px 10px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
}

.chip-btn:hover { background: #f1f5f9; }

/* Touch screens only: a finger drag scrolls the page, so selecting an area needs its own mode */
.brush-toggle { display: none; }
@media (hover: none) { .brush-toggle { display: inline-block; } }
.brush-toggle.on { background: #2563eb; border-color: #2563eb; color: #ffffff; }
canvas.brushing { touch-action: none; }

/* "80% of comparable homes sold by day 52; this one is at day 71" on the clicked listing's row */
.listing-info .sell-note {
  margin: 4px 0;
  padding: 4px 6px;
  background: #f1f5f9;
  border-left: 3px solid #1e293b;
  border-radius: 3px;
  font-size: 12px;
  color: #334155;
}

/* Markers the charts point at: is-linked = steady (hovering a dot), is-pulsing = animated (hovering a histogram bar) */
.is-linked,
.is-pulsing {
  z-index: 9000 !important;
}

.price-marker.is-linked .price-label {
  background: #2563eb;
  color: #ffffff;
  border-color: #1d4ed8;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.35), 0 2px 6px rgba(0, 0, 0, 0.2);
  transform: scale(1.12);
}

.price-marker.is-linked .price-label .arrow { color: #ffffff; }

.count-marker.is-linked .count-label,
.cluster-marker.is-linked .cluster-label {
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.45);
  transform: scale(1.12);
}

@keyframes marker-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.75); transform: scale(1); }
  50% { box-shadow: 0 0 0 7px rgba(245, 158, 11, 0); transform: scale(1.12); }
}

.is-pulsing .price-label,
.is-pulsing .count-label,
.is-pulsing .cluster-label {
  animation: marker-pulse 1s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .is-pulsing .price-label,
  .is-pulsing .count-label,
  .is-pulsing .cluster-label {
    animation: none;
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.9);
  }
}

/* Tablets: a narrower cards column gives the charts room (the sold page keeps its 450px) */
@media (min-width: 901px) and (max-width: 1100px) {
  .insights-charts .insights-left {
    flex-basis: 300px;
  }
}

/* Phones (portrait and landscape): the footer scrolls, so each chart gets a fixed height instead of filling it */
@media (max-width: 900px), (max-height: 500px) and (orientation: landscape) {
  .insights-charts .insights-right {
    min-height: 0;
  }

  .insight-tabs {
    width: 100%;
  }

  .insight-tab {
    flex: 1 1 auto;
    padding: 8px 6px;
    text-align: center;
  }

  .insight-pane {
    flex: none;
  }

  .insight-pane .chart-box {
    flex: none;
    height: 240px;
  }

  .chart-pair {
    grid-template-columns: 1fr;
    grid-template-rows: none;
    gap: 12px;
  }

  .chart-pair .chart-box {
    height: 190px;
  }

  .selection-bar {
    font-size: 11px;
  }

  #clearSelection {
    margin-left: 0;
  }

  .pane-toolbar {
    flex-wrap: wrap;
  }
}

/* ─── 14. NEIGHBOURHOOD MODE (sold map) ─────────────────────── */

/* Circle | Neighbourhood switch, first item of the controls bar. The ID + 4 classes beat the blue-button rule of #controls. */
.area-toggle {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: #e2e8f0;
  border-radius: 9px;
}

#controls .area-toggle button.area-btn.area-btn.area-btn {
  padding: 5px 11px;
  background: transparent;
  color: #475569;
  box-shadow: none;
  font-size: 13px;
  font-weight: 600;
  border-radius: 7px;
  transform: none;
  white-space: nowrap;
}

#controls .area-toggle button.area-btn.area-btn.area-btn:hover:not(.active) {
  background: #f1f5f9;
  transform: none;
  box-shadow: none;
}

#controls .area-toggle button.area-btn.area-btn.area-btn.active {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: #ffffff;
  box-shadow: 0 1px 3px rgba(37, 99, 235, 0.35);
}

.area-toggle .area-btn:focus-visible,
.areas-table .th-btn:focus-visible,
.area-row:focus-visible,
.area-clear:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.radius-group {
  display: inline-flex;
  align-items: center;
}

.radius-group[hidden],
.area-title[hidden],
.area-hint[hidden] {
  display: none;
}

#controls #toggleAreas.is-on {
  background: linear-gradient(135deg, #0369a1 0%, #075985 100%);
}

/* Which neighbourhood the cards and chart describe (above the cards) */
.area-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 6px 10px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  color: #1d4ed8;
  font-weight: 700;
  font-size: 14px;
}

.area-title-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.area-clear {
  border: none;
  background: transparent;
  color: #1d4ed8;
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}

.area-clear:hover { background: #dbeafe; }

.area-hint {
  margin-bottom: 8px;
  font-size: 13px;
  color: #526071;
}

/* The neighbourhood table: a left panel on desktop (like the listings), the Areas tab on phones */
#areasPanel {
  width: 420px;
  max-width: 90vw;
  flex: none;   /* never let the map squeeze it: current Chrome shrank it to 0px wide, so the table never showed */
  background: #ffffff;
  box-shadow: 4px 0 12px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1001;
}

#areasPanel.open { transform: translateX(0); }
#areasPanel.hidden { display: none; }

.areas-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.areas-head {
  flex: none;
  padding: 10px 12px 6px;
  border-bottom: 1px solid #e2e8f0;
}

.areas-filter {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
}

.areas-filter:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.areas-meta {
  margin-top: 6px;
  min-height: 16px;
  font-size: 12px;
  color: #526071;
}

.areas-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.areas-table {
  width: 100%;
  table-layout: fixed;   /* the column widths come from the <colgroup>; long names wrap */
  border-collapse: collapse;
  font-size: 13px;
}

.areas-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  padding: 0;
  text-align: right;
  white-space: nowrap;
}

.areas-table thead th.c-name { text-align: left; }

.th-btn {
  width: 100%;
  padding: 8px 4px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  color: #526071;
  text-transform: uppercase;
  cursor: pointer;
  text-align: inherit;
}

.th-btn:hover { color: #1e293b; }
.th-btn.on-map { color: #1d4ed8; }
.th-btn.on-map .th-label::before { content: "● "; font-size: 8px; vertical-align: middle; }
.th-arrow { display: inline-block; min-width: 10px; font-size: 8px; margin-left: 2px; }

.areas-table td {
  padding: 8px 4px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

.areas-table td.c-name {
  padding-left: 12px;
  font-weight: 600;
  color: #1e293b;
}

.areas-table .c-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.areas-table td.c-num:last-child { padding-right: 12px; }

.area-row { cursor: pointer; }
.area-row:hover { background: #f1f5f9; }
.area-row.is-selected { background: #eff6ff; box-shadow: inset 3px 0 0 #2563eb; }
.area-row.is-low td.is-stat { color: #566072; font-weight: 400; }   /* fewer than the minimum sample: the estimates are greyed out */
.area-row.is-unassigned td.c-name { font-style: italic; }

.areas-empty {
  padding: 24px 12px;
  text-align: center;
  color: #526071;
}

.areas-foot {
  flex: none;
  padding: 8px 12px;
  border-top: 1px solid #e2e8f0;
  background: #f8fafc;
  font-size: 11px;
  line-height: 1.4;
  color: #526071;
}

/* Hover and selection of a neighbourhood on the map. The hover is a glow (white edge, warm halo, brighter fill) so the area
   under the pointer is obvious before the click; the selected area keeps a white edge with a blue halo. No dark outline. */
.leaflet-container path.leaflet-interactive:focus,
.leaflet-container path.leaflet-interactive:focus-visible { outline: none; }

path.nb-hover {
  filter: drop-shadow(0 0 3px rgba(255, 255, 255, 0.95)) drop-shadow(0 0 9px rgba(251, 191, 36, 0.9)) brightness(1.12) saturate(1.12);
}

/* The selected area is an outline only (its fill is clear, see styleFor): a blue edge with a white and a blue glow, readable on
   light and dark map tiles alike. The glow is drawn from the stroke only, so the middle stays see-through. */
path.nb-selected {
  filter: drop-shadow(0 0 2px rgba(255, 255, 255, 0.95)) drop-shadow(0 0 8px rgba(37, 99, 235, 0.9));
}

path.nb-selected.nb-hover {
  filter: drop-shadow(0 0 2px rgba(255, 255, 255, 0.95)) drop-shadow(0 0 9px rgba(37, 99, 235, 1));
}

/* Map legend: what the colours mean, and the grey of areas with too few sales */
.area-legend {
  width: 220px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 10px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  font-size: 12px;
  color: #334155;
}

.area-legend-metric {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 600;
}

.area-legend-metric select {
  flex: 1;
  min-width: 0;
  padding: 3px 4px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-family: inherit;
  font-size: 12px;
  color: #1e293b;
  background: #ffffff;
}

.area-legend-bar {
  height: 10px;
  margin: 8px 0 3px;
  border-radius: 5px;
}

.area-legend-scale {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #526071;
}

.area-legend-low {
  display: flex;
  align-items: center;
  margin-top: 6px;
  font-size: 11px;
  color: #526071;
}

.area-legend-swatch {
  display: inline-block;
  width: 14px;
  height: 10px;
  margin-right: 6px;
  background: rgba(156, 163, 175, 0.3);
  border: 1px dashed #6b7280;
  border-radius: 2px;
}

.area-tip { font-size: 12px; line-height: 1.4; }

@media (prefers-reduced-motion: reduce) {
  #areasPanel { transition: none; }
}

/* Narrow desktop windows: the controls bar is wider now, so keep it clear of the Sold | Active switch */

/* A 420px sidebar (listings or the neighbourhood table) is open: the bar sits on the map beside it, not over the sidebar's header
   (it used to cover the "View Insights" button on windows under ~1250px) and wraps if the map is narrow. */
@media (min-width: 901px) and (min-height: 501px) {
  body.side-open #controls {
    left: 436px;
    transform: none;
    max-width: calc(100vw - 436px - 200px);
    flex-wrap: wrap;
    row-gap: 6px;
  }
}

/* Phones: the table is the Areas tab; the controls bar gets a second row for the switch */
@media (max-width: 900px), (max-height: 500px) and (orientation: landscape) {
  #areasPanel { display: none !important; }
}

@media (max-width: 900px) and (min-height: 501px) {
  /* Sold | Active becomes a slim strip above the map: the controls bar used to sit on top of it and hide it */
  .sold-map .mode-tabs, .active-map .mode-tabs { position: static; align-self: center; flex: none; margin: 4px 0; padding: 2px; border-radius: 10px; }
  .sold-map .mode-tabs a, .active-map .mode-tabs a { padding: 0 22px; font-size: 13px; }
  .sold-map #controls, .active-map #controls { top: 58px; }
  .sold-map #map, .active-map #map { height: calc(55vh - 52px); min-height: 214px; }   /* the strip takes 52px: keep the panel below the same size */

  /* Controls bar: [Circle | Neighbourhood] [Filters] on one row, the radius on a second row (Circle mode only).
     The tab bar under the map replaces the Listings and Neighbourhoods buttons. */
  #controls { flex-wrap: wrap; justify-content: center; row-gap: 6px; }
  #controls .area-toggle { order: 1; flex: 1 1 0; min-width: 0; justify-content: center; }
  #controls #filterToggle { order: 2; }
  #controls .radius-group { order: 3; flex: 1 0 100%; justify-content: center; }
  #controls #toggleListings, #controls #toggleAreas { display: none; }
  #controls .area-toggle button.area-btn.area-btn.area-btn { flex: 1; padding: 6px 8px; font-size: 12px; }
}

@media (max-width: 900px) {
  .mobile-areas-panel { overflow: hidden; }
  .mobile-areas-panel .areas-body { background: #ffffff; }
  .areas-table td { padding: 10px 5px; }
  .areas-table td.c-name { font-size: 12px; }
  .areas-table { font-size: 12px; }
  .area-legend { width: 196px; padding: 6px 8px; margin-bottom: 4px; }   /* clear of the attribution, which wraps to two lines */
  .area-legend-metric { font-size: 11px; }
  .area-legend-metric select { font-size: 11px; }
  .area-title { font-size: 13px; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .area-legend { width: 196px; margin-bottom: 4px; }
  /* Sold | Active would cover the third tab of the right-hand column: move it to the map's bottom-right corner (this page only) */
  .sold-map .mode-tabs, .active-map .mode-tabs { top: auto; bottom: 34px; right: calc(40% + 8px); padding: 2px; }
  .sold-map .mode-tabs a, .active-map .mode-tabs a { padding: 4px 10px; font-size: 12px; }
  #controls .area-toggle button.area-btn.area-btn.area-btn { padding: 2px 6px; font-size: 11px; }
  .areas-table td { padding: 6px 4px; }
  .areas-table td.c-name { font-size: 11px; }
  .areas-table { font-size: 11px; }
  .areas-filter { padding: 4px 8px; font-size: 12px; }
}

/* ═══════════════════════════════════════════════════════════
   15. PHASE 0 FIXES: layout, states, touch targets
   Every rule here fixes a measured bug; the look is unchanged.
   ═══════════════════════════════════════════════════════════ */

/* Focus: one visible ring for every control (keyboard only) */
button:focus-visible, a:focus-visible, select:focus-visible, summary:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}
.toolbar-btn:focus-visible, .selection-banner button:focus-visible, .mode-tabs a.active:focus-visible,
.page-btn.active:focus-visible, .mobile-tab.active:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: -4px;
  box-shadow: 0 0 0 2px #1d4ed8;
}

/* "Sold" on the Sold page is where you already are: it must not look like a button */
.mode-tabs a.active { cursor: default; pointer-events: none; }

/* Property type in a listing row: a label, not a second price */
.listing-info p .ptype-text { font-size: inherit; }

/* "View Details" looks like what it is: a button */
.listing-info .view-btn {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border: 1px solid #2563eb;
  border-radius: 8px;
  color: #1d4ed8;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}
.listing-info .view-btn:hover { background: #2563eb; color: #ffffff; }

/* The Leaflet zoom buttons moved to the bottom right; the legend is lifted above the attribution by script (neighbourhoods.js) */

/* ── Controls bar: as wide as its content, wraps instead of squeezing the buttons, stays clear of Sold | Active ── */
.mode-tabs { z-index: 10000; }
@media (min-width: 901px) and (min-height: 501px) {
  #controls {
    width: max-content;
    max-width: calc(100vw - 372px);
    flex-wrap: wrap;
    justify-content: center;
    row-gap: 8px;
  }
  body.side-open #controls { width: max-content; }
  #insights { overflow: hidden; min-height: 0; }
}
#controls button, #controls label, #controls .radius-group { white-space: nowrap; }
.chart-header { flex-wrap: wrap; gap: 8px; }

/* ── Filter panel: never taller than the screen, scrolls inside itself (max-height is set from script) ── */
#filterPanel { display: none; overflow-y: auto; overscroll-behavior: contain; }   /* script sets display: block while it is open */

/* ── Insights footer: the cards fill their column (no empty band above or below them), and the footer follows the
      width of the column it is in, not the window: with a sidebar open the chart used to be squeezed to 60px ── */
#mainPanel { container-type: inline-size; container-name: main; }
.insights-left { justify-content: flex-start; min-height: 0; }
.insights-left > .area-title, .insights-left > .area-hint, .insights-left > .data-status { flex: none; }
.summary-cards { flex: 1 1 auto; min-height: 0; grid-auto-rows: minmax(0, 1fr); gap: 10px; }
.card { min-height: 0; padding: 8px 10px; }
.card strong { text-align: center; line-height: 1.25; }

@container main (max-width: 1000px) {
  .insights-left { flex-basis: 300px; }
}
@container main (max-width: 760px) {
  #insights, #insights.insights-charts {
    flex-direction: column;
    height: auto;
    min-height: 0;
    max-height: 48vh;
    overflow-y: auto;
    overflow-x: hidden;
    gap: 12px;
  }
  .insights-left { flex: none; width: 100%; }
  .summary-cards { flex: none; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-rows: auto; }
  .card { padding: 8px 6px; }
  .insights-right, .insights-charts .insights-right { flex: none; min-height: 300px; width: 100%; }
  .insight-pane { flex: none; }
  .insight-pane .chart-box { flex: none; height: 230px; }
  .chart-pair .chart-box { height: 190px; }
  .chart-container-full { min-height: 200px; }
  .insight-tabs { width: 100%; }
  .insight-tab { flex: 1 1 auto; text-align: center; }
  .pane-toolbar { flex-wrap: wrap; }
}
@container main (max-width: 520px) {
  .summary-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-pair { grid-template-columns: 1fr; grid-template-rows: none; }
}

/* ── Loading, empty and error states (status.js) ── */
.data-status {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  margin-bottom: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
}
.data-status[hidden] { display: none; }
.data-status.is-empty { background: #fffbeb; border: 1px solid #fcd34d; color: #78350f; }
.data-status.is-error { background: #fef2f2; border: 1px solid #fca5a5; color: #7f1d1d; }
.data-status-text { flex: 1 1 140px; min-width: 0; }
.data-status-btn {
  min-height: 32px;
  padding: 4px 12px;
  border: 1px solid currentColor;
  border-radius: 6px;
  background: #ffffff;
  color: inherit;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.data-status-btn:hover { background: #f8fafc; }

.chart-container-full, .chart-box { position: relative; }
.chart-empty {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  text-align: center;
  background: rgba(255, 255, 255, 0.94);
  color: #475569;
  font-size: 13px;
  font-weight: 500;
}
.chart-empty[hidden] { display: none; }

@keyframes skeleton-shimmer { to { background-position: -200% 0; } }
.is-loading .card span {
  display: inline-block;
  min-width: 64px;
  min-height: 1.3em;
  color: transparent !important;
  background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
  background-size: 200% 100%;
  border-radius: 6px;
  animation: skeleton-shimmer 1.3s linear infinite;
}
.is-loading .chart-container-full::after,
.is-loading .chart-box::after {
  content: "Loading…";
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.9);
  color: #475569;
  font-size: 13px;
}
@media (prefers-reduced-motion: reduce) {
  .is-loading .card span { animation: none; }
}

/* ── Phones and short landscape screens: 40px touch targets (WCAG AA asks for 24px, thumbs want more) ── */
@media (max-width: 900px), (max-height: 500px) and (orientation: landscape) {
  .mode-tabs a { display: inline-flex; align-items: center; min-height: 40px; }
  #controls .area-toggle button.area-btn.area-btn.area-btn,
  #controls #filterToggle { min-height: 40px; }
  #controls input[type="number"] { height: 40px; width: 56px; }
  .clear-filters-btn, .bed-btn, .ptype-btn, .chart-btn, .insight-tab, .chip-btn, .th-btn,
  .listing-info .view-btn, .selection-banner button, .area-clear, .data-status-btn { min-height: 40px; }
  .area-clear { min-width: 40px; }
  .mobile-tab { min-height: 44px; }
  .page-btn, .page-ellipsis { width: 40px; height: 40px; }
  .pagination-controls { gap: 6px; }
  .search-container input, .sort-container select, .areas-filter, .area-legend-metric select { min-height: 40px; }
  .areas-table td { padding-top: 12px; padding-bottom: 12px; }
  .recent-row { min-height: 44px; }
  .leaflet-touch .leaflet-bar a, .leaflet-control-zoom a { width: 40px; height: 40px; line-height: 40px; }
  #controls #toggleListings, #controls #toggleAreas { min-height: 40px; }
  .areas-table td { height: 44px; }
  .leaflet-control-attribution a { display: inline-block; padding: 12px 3px; margin: -12px 0; }
  #filterPanel .noUi-handle {
    width: 40px; height: 40px; top: -17px; right: -20px;
    background: transparent; border: 0; box-shadow: none;
  }
  #filterPanel .noUi-handle::after {
    content: ""; display: block; position: absolute; top: 10px; left: 10px;
    width: 20px; height: 20px; box-sizing: border-box; border-radius: 50%;
    background: #ffffff; border: 2.5px solid #2563eb; box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25);
  }
  #filterPanel .filter-section .noUi-target { margin: 10px 0 14px; }
}

/* Short landscape phones: the controls bar sits top left over the map, Sold | Active top right of the map (the bottom corners
   belong to the zoom buttons and the legend) */
@media (max-height: 500px) and (orientation: landscape) {
  #controls { left: 8px !important; transform: none !important; max-width: calc(60vw - 150px) !important; flex-wrap: wrap !important; row-gap: 4px !important; }
  .sold-map .mode-tabs, .active-map .mode-tabs { top: 4px !important; bottom: auto !important; right: calc(40vw + 8px) !important; }
}

/* ── Design tokens read by the scripts (charts) and available to every rule: the defaults are the current look ── */
:root {
  --accent: #2563eb;
  --accent-dim: #bfdbfe;
  --ink: #1e293b;
  --up: #047857;
  --down: #dc2626;
  --flat: #94a3b8;
  --chart-text: #526071;
  --chart-grid: #f1f5f9;
  --chart-bar: rgba(54, 162, 235, 1);
  --chart-bar-fill: rgba(54, 162, 235, 0.2);
  --chart-line: red;
  --chart-line-fill: rgba(255, 0, 0, 0.2);
  --chart-line-dom: #f59e0b;
  --chart-line-dom-fill: rgba(245, 158, 11, 0.2);
  --chart-line-diff: #8b5cf6;
  --chart-line-diff-fill: rgba(139, 92, 246, 0.2);
}

.insight-pane .chart-box { min-height: 140px; }

/* Phone layouts: the cards take the height of their text (the footer scrolls), they do not stretch to fill it */
@media (max-width: 900px), (max-height: 500px) and (orientation: landscape) {
  .summary-cards { flex: none; grid-auto-rows: auto; }
  .insights-left { flex: none; }
}
