/* ═══════════════════════════════════════════════════════════
   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;
  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, #0ea5e9 0%, #0284c7 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, #0284c7 0%, #0369a1 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: #94a3b8;
}

.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;
  display: grid;
  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: #64748b;
  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-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;
}

.chart-btn {
  padding: 6px 12px;
  border: none;
  background: transparent;
  color: #64748b;
  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: #ef4444;
  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: #dc2626;
  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: #64748b;
  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: #64748b;
  font-style: italic;
  line-height: 1.4;
}

#bedFilter,
#ptypeFilter {
  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;
}

.listing-info p {
  margin: 0;
  font-size: 13px;
  color: #64748b;
  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, #2563eb 0%, #1d4ed8 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: #94a3b8;
}

.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: #94a3b8;
  font-size: 14px;
  font-weight: 600;
  user-select: none;
}

.pagination-info {
  font-size: 12px;
  color: #94a3b8;
  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: 768px) {

  /* 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: #64748b;
    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: #64748b !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 {
    max-height: 85vh !important;
    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;
  }
}