/* ============================================
   North TLV Apartment Finder — Styles
   ============================================ */

:root {
  --bg-primary: #0a0b10;
  --bg-secondary: #12131a;
  --bg-card: #181923;
  --bg-hover: #1e2030;
  --bg-input: #1a1b26;
  --border: #2a2c3e;
  --border-hover: #3d4060;
  --text-primary: #e8e9f0;
  --text-secondary: #8b8fa3;
  --text-muted: #5c5f73;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.15);
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --price-color: #4ade80;
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.5);
  --transition: 0.2s ease;
  --sidebar-width: 320px;
  --topbar-height: 56px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
}

/* ---- Topbar ---- */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  z-index: 1000;
  position: relative;
}
.topbar-left { display: flex; align-items: center; gap: 1rem; }
.topbar-right { display: flex; align-items: center; gap: 0.75rem; }

.logo {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex; align-items: center; gap: 0.4rem;
  white-space: nowrap;
}
.logo span { background: linear-gradient(135deg, var(--accent), #a78bfa); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }

.search-box {
  display: flex;
  align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 0.75rem;
  width: 340px;
  transition: border-color var(--transition);
}
.search-box:focus-within { border-color: var(--accent); }
.search-box svg { color: var(--text-muted); flex-shrink: 0; }
.search-box input {
  background: none; border: none; color: var(--text-primary);
  padding: 0.5rem; font-size: 0.85rem; width: 100%; outline: none;
  font-family: inherit;
}
.search-box input::placeholder { color: var(--text-muted); }

.view-toggle { display: flex; background: var(--bg-input); border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--border); }
.view-btn {
  background: none; border: none; color: var(--text-muted); padding: 0.45rem 0.6rem;
  cursor: pointer; transition: all var(--transition); display: flex; align-items: center;
}
.view-btn:hover { color: var(--text-secondary); background: var(--bg-hover); }
.view-btn.active { color: var(--accent); background: var(--accent-glow); }

.stats-badge {
  background: var(--accent-glow);
  color: var(--accent);
  padding: 0.3rem 0.8rem;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.btn-heatmap {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  font-size: 1rem;
  transition: all var(--transition);
}
.btn-heatmap:hover { border-color: var(--warning); }
.btn-heatmap.active { background: rgba(251, 191, 36, 0.15); border-color: var(--warning); }

/* ---- Main Layout ---- */
.main-layout {
  display: flex;
  height: calc(100vh - var(--topbar-height));
  position: relative;
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  padding: 1rem;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.sidebar::-webkit-scrollbar { width: 5px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.sidebar-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1rem; padding-bottom: 0.75rem; border-bottom: 1px solid var(--border);
}
.sidebar-header h3 { font-size: 1rem; font-weight: 600; }
.btn-clear {
  background: none; border: none; color: var(--accent); cursor: pointer;
  font-size: 0.78rem; font-family: inherit; font-weight: 500;
  transition: color var(--transition);
}
.btn-clear:hover { color: var(--accent-hover); }

.filter-section { margin-bottom: 1.2rem; }
.filter-label {
  display: block; font-size: 0.78rem; font-weight: 600; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 0.5rem;
}

.range-inputs {
  display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.5rem;
}
.range-inputs input {
  background: var(--bg-input); border: 1px solid var(--border); color: var(--text-primary);
  padding: 0.4rem 0.6rem; border-radius: var(--radius-sm); font-size: 0.82rem;
  width: 100%; outline: none; font-family: inherit;
  transition: border-color var(--transition);
}
.range-inputs input:focus { border-color: var(--accent); }
.range-sep { color: var(--text-muted); font-size: 0.85rem; }

/* Range Slider */
.range-slider-container {
  position: relative; height: 28px; margin-bottom: 0.3rem;
}
.range-track {
  position: absolute; top: 12px; left: 0; right: 0; height: 4px;
  background: var(--border); border-radius: 2px;
}
.range-slider {
  position: absolute; top: 0; width: 100%; height: 28px;
  -webkit-appearance: none; appearance: none; background: transparent;
  pointer-events: none; outline: none;
}
.range-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px;
  background: var(--accent); border-radius: 50%; cursor: pointer;
  pointer-events: auto; box-shadow: 0 0 6px rgba(99,102,241,0.4);
  transition: transform 0.15s;
}
.range-slider::-webkit-slider-thumb:hover { transform: scale(1.2); }

/* Chips */
.quick-filters, .neighborhood-chips, .type-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  background: var(--bg-input); border: 1px solid var(--border); color: var(--text-secondary);
  padding: 0.3rem 0.7rem; border-radius: 20px; font-size: 0.75rem;
  cursor: pointer; transition: all var(--transition); font-family: inherit;
  white-space: nowrap;
}
.chip:hover { border-color: var(--accent); color: var(--text-primary); }
.chip.active { background: var(--accent-glow); border-color: var(--accent); color: var(--accent); }

/* Room Buttons */
.room-buttons { display: flex; gap: 0.35rem; }
.room-btn {
  background: var(--bg-input); border: 1px solid var(--border); color: var(--text-secondary);
  width: 40px; height: 36px; border-radius: var(--radius-sm); cursor: pointer;
  font-size: 0.85rem; font-weight: 500; transition: all var(--transition); font-family: inherit;
}
.room-btn:hover { border-color: var(--accent); color: var(--text-primary); }
.room-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Amenity Toggles */
.amenity-toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 0.3rem; }
.toggle-item {
  display: flex; align-items: center; gap: 0.4rem; padding: 0.35rem 0.5rem;
  border-radius: var(--radius-sm); cursor: pointer; transition: background var(--transition);
  font-size: 0.8rem;
}
.toggle-item:hover { background: var(--bg-hover); }
.toggle-item input { accent-color: var(--accent); }
.toggle-label { color: var(--text-secondary); white-space: nowrap; }

/* Select */
.filter-select {
  width: 100%; background: var(--bg-input); border: 1px solid var(--border);
  color: var(--text-primary); padding: 0.45rem 0.6rem; border-radius: var(--radius-sm);
  font-size: 0.82rem; outline: none; font-family: inherit;
  cursor: pointer;
}
.filter-select:focus { border-color: var(--accent); }

/* Market Stats */
.stats-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem;
}
.stat-card {
  background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.6rem; text-align: center;
}
.stat-value { font-size: 1rem; font-weight: 700; color: var(--price-color); }
.stat-label { font-size: 0.65rem; color: var(--text-muted); margin-top: 2px; text-transform: uppercase; }

/* ---- Map ---- */
.map-container { flex: 1; position: relative; }
#map { width: 100%; height: 100%; background: var(--bg-primary); }

/* Custom map markers */
.price-marker {
  background: var(--bg-card);
  border: 2px solid var(--accent);
  color: var(--price-color);
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  font-family: 'Inter', sans-serif;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  transition: all 0.15s;
  cursor: pointer;
  text-align: center;
  line-height: 1.3;
}
.price-marker:hover {
  transform: scale(1.1);
  border-color: var(--accent-hover);
  z-index: 1000 !important;
}
.price-marker.selected {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent-hover);
}

.price-marker-penthouse { border-color: var(--warning); }
.price-marker-garden { border-color: var(--success); }

/* Landmark markers (schools, kindergartens) */
.landmark-marker {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.5));
}
.landmark-pin {
  width: 36px;
  height: 36px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  border: 2px solid rgba(255,255,255,0.4);
}
.landmark-pin span {
  transform: rotate(45deg);
  line-height: 1;
}
.landmark-label {
  margin-top: 4px;
  background: rgba(0,0,0,0.75);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  padding: 2px 6px;
  border-radius: 10px;
  white-space: nowrap;
  text-align: center;
}
.landmark-kindergarten  .landmark-pin { background: #f59e0b; }
.landmark-kindergarten2 .landmark-pin { background: #3b82f6; }
.landmark-school        .landmark-pin { background: #10b981; }

/* Walking time — popup */
.popup-walk {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 6px 0 4px;
}
.popup-walk span {
  font-size: 0.72rem;
  color: #34d399;
  background: rgba(52, 211, 153, 0.12);
  padding: 2px 7px;
  border-radius: 10px;
  white-space: nowrap;
}

/* Walking time — listing card */
.card-walk {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 4px 0 2px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.card-walk span {
  font-size: 0.7rem;
  color: #34d399;
  background: rgba(52, 211, 153, 0.12);
  padding: 2px 7px;
  border-radius: 10px;
  white-space: nowrap;
}

/* Marker cluster overrides */
.marker-cluster-small { background-color: rgba(99, 102, 241, 0.3) !important; }
.marker-cluster-small div { background-color: rgba(99, 102, 241, 0.7) !important; color: #fff !important; font-family: 'Inter', sans-serif !important; font-weight: 600 !important; }
.marker-cluster-medium { background-color: rgba(251, 191, 36, 0.3) !important; }
.marker-cluster-medium div { background-color: rgba(251, 191, 36, 0.7) !important; color: #000 !important; font-family: 'Inter', sans-serif !important; font-weight: 600 !important; }
.marker-cluster-large { background-color: rgba(248, 113, 113, 0.3) !important; }
.marker-cluster-large div { background-color: rgba(248, 113, 113, 0.7) !important; color: #fff !important; font-family: 'Inter', sans-serif !important; font-weight: 600 !important; }

/* Neighborhood overlay */
.neighborhood-overlay {
  position: absolute; bottom: 1rem; left: 1rem; z-index: 800;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.8rem 1rem;
  box-shadow: var(--shadow); display: none; max-width: 280px;
}
.neighborhood-overlay h4 { font-size: 0.9rem; margin-bottom: 0.4rem; }
.overlay-stats { font-size: 0.78rem; color: var(--text-secondary); line-height: 1.5; }

/* ---- Listings Panel ---- */
.listings-panel {
  width: 420px;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.listings-panel::-webkit-scrollbar { width: 5px; }
.listings-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.8rem 1rem; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg-secondary); z-index: 10;
}
.panel-header h3 { font-size: 0.95rem; font-weight: 600; }
.panel-close {
  background: none; border: none; color: var(--text-muted); font-size: 1.2rem;
  cursor: pointer; transition: color var(--transition);
}
.panel-close:hover { color: var(--text-primary); }

.listings-grid { padding: 0.5rem; display: flex; flex-direction: column; gap: 0.5rem; }

/* Listing Card */
.listing-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: all var(--transition);
}
.listing-card:hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: var(--shadow); }
.listing-card.highlighted { border-color: var(--accent); box-shadow: 0 0 12px var(--accent-glow); }

.card-image {
  width: 100%; height: 160px; object-fit: cover; display: block;
  background: var(--bg-hover);
}
.card-image-placeholder {
  width: 100%; height: 160px; background: var(--bg-hover);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 2rem;
}

.card-body { padding: 0.75rem; }
.card-price {
  font-size: 1.15rem; font-weight: 700; color: var(--price-color);
  margin-bottom: 0.15rem;
}
.card-ppsqm { font-size: 0.72rem; color: var(--text-muted); margin-bottom: 0.4rem; }
.card-address {
  font-size: 0.82rem; color: var(--text-secondary); margin-bottom: 0.5rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.card-specs {
  display: flex; gap: 0.6rem; flex-wrap: wrap;
}
.card-spec {
  display: flex; align-items: center; gap: 0.25rem;
  font-size: 0.75rem; color: var(--text-secondary);
}
.card-spec svg { width: 14px; height: 14px; stroke: var(--text-muted); }

.card-tags { display: flex; gap: 0.3rem; margin-top: 0.5rem; flex-wrap: wrap; }
.card-tag {
  background: var(--bg-hover); padding: 2px 6px; border-radius: 4px;
  font-size: 0.65rem; color: var(--text-muted);
}
.card-tag.tag-parking { color: var(--accent); background: var(--accent-glow); }
.card-tag.tag-elevator { color: var(--success); background: rgba(52,211,153,0.1); }
.card-tag.tag-renovated { color: var(--warning); background: rgba(251,191,36,0.1); }

.card-source {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 0.5rem; padding-top: 0.4rem; border-top: 1px solid var(--border);
  font-size: 0.68rem; color: var(--text-muted);
}

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  z-index: 2000; display: none; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
}
.modal-overlay.active { display: flex; }

.modal {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius-lg); max-width: 700px; width: 95%;
  max-height: 90vh; overflow-y: auto; position: relative;
  box-shadow: var(--shadow-lg);
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.modal::-webkit-scrollbar { width: 5px; }
.modal::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.modal-close {
  position: absolute; top: 0.75rem; right: 0.75rem; z-index: 10;
  background: rgba(0,0,0,0.6); border: none; color: #fff; width: 32px; height: 32px;
  border-radius: 50%; cursor: pointer; font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition);
}
.modal-close:hover { background: rgba(0,0,0,0.8); }

/* ── Lightbox ────────────────────────────────────────────────────────── */
.lightbox {
  display: none;
  position: fixed; inset: 0; z-index: 9000;
  background: rgba(0, 0, 0, 0.94);
  flex-direction: column; align-items: center; justify-content: center;
}
.lightbox.active { display: flex; }

.lightbox-img-wrap {
  flex: 1; display: flex; align-items: center; justify-content: center;
  width: 100%; min-height: 0; padding: 56px 64px;
  box-sizing: border-box; cursor: zoom-in;
}
.lightbox-img {
  max-width: 100%; max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
  user-select: none;
  transition: opacity 0.15s;
}
.lightbox-img.fading { opacity: 0; }

.lightbox-close {
  position: fixed; top: 16px; right: 20px;
  background: rgba(255,255,255,0.12); border: none; color: #fff;
  width: 40px; height: 40px; border-radius: 50%; font-size: 1.1rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background 0.15s; z-index: 9001;
}
.lightbox-close:hover { background: rgba(255,255,255,0.28); }

.lightbox-nav {
  position: fixed; top: 50%; transform: translateY(-50%);
  background: rgba(255,255,255,0.1); border: none; color: #fff;
  width: 48px; height: 64px; border-radius: 6px; font-size: 2.2rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background 0.15s; z-index: 9001; line-height: 1; padding: 0;
}
.lightbox-nav:hover { background: rgba(255,255,255,0.25); }
.lightbox-nav.hidden { display: none; }
.lightbox-prev { left: 12px; }
.lightbox-next { right: 12px; }

.lightbox-counter {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  color: rgba(255,255,255,0.7); font-size: 0.82rem; font-family: 'Inter', sans-serif;
  background: rgba(0,0,0,0.45); padding: 4px 12px; border-radius: 12px;
  pointer-events: none;
}

@media (max-width: 600px) {
  .lightbox-img-wrap { padding: 48px 56px; }
  .lightbox-nav { width: 38px; height: 52px; font-size: 1.7rem; }
  .lightbox-prev { left: 4px; }
  .lightbox-next { right: 4px; }
}

.modal-gallery-wrapper {
  position: relative; overflow: hidden; background: var(--bg-primary);
}
.modal-gallery {
  display: flex; overflow-x: auto; scroll-snap-type: x mandatory;
  scrollbar-width: none; background: var(--bg-primary);
}
.modal-gallery::-webkit-scrollbar { display: none; }
.modal-gallery img {
  width: 100%; min-width: 100%; height: 320px; object-fit: cover;
  scroll-snap-align: start; flex-shrink: 0;
}
.modal-gallery-placeholder {
  width: 100%; height: 200px; background: var(--bg-hover);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 3rem;
}
.gallery-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  background: rgba(0,0,0,0.55); color: #fff; border: none;
  width: 36px; height: 36px; border-radius: 50%; font-size: 1.4rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  line-height: 1; transition: background 0.15s; z-index: 10;
  padding: 0;
}
.gallery-nav:hover { background: rgba(0,0,0,0.85); }
.gallery-nav-prev { left: 10px; }
.gallery-nav-next { right: 10px; }
.gallery-nav.hidden { display: none; }
.gallery-dots {
  position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 5px; z-index: 10;
}
.gallery-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: rgba(255,255,255,0.45); transition: background 0.2s; cursor: pointer;
}
.gallery-dot.active { background: #fff; }

.modal-body { padding: 1.5rem; }
.modal-header-info { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 0.3rem; gap: 1rem; }
.modal-header-info h2 { font-size: 1.2rem; font-weight: 700; flex: 1; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.modal-price { font-size: 1.4rem; font-weight: 700; color: var(--price-color); white-space: nowrap; }
.modal-address { font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 1rem; }

.modal-tags { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.modal-tag {
  padding: 4px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 500;
  background: var(--bg-hover); color: var(--text-secondary); border: 1px solid var(--border);
}
.modal-tag-highlight { background: var(--accent-glow); color: var(--accent); border-color: var(--accent); }

.modal-specs {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 0.75rem; margin-bottom: 1.2rem;
}
.modal-spec {
  background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.65rem; text-align: center;
}
.modal-spec-value { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); }
.modal-spec-label { font-size: 0.68rem; color: var(--text-muted); margin-top: 2px; text-transform: uppercase; }

.modal-description {
  font-size: 0.88rem; color: var(--text-secondary); line-height: 1.6;
  margin-bottom: 1rem; padding: 0.8rem;
  background: var(--bg-input); border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  max-height: 200px; overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}

.modal-price-analysis {
  background: rgba(74, 222, 128, 0.05);
  border: 1px solid rgba(74, 222, 128, 0.2);
  border-radius: var(--radius-sm);
  padding: 0.8rem;
  margin-bottom: 1rem;
}
.modal-price-analysis h4 { font-size: 0.8rem; color: var(--success); margin-bottom: 0.4rem; }
.modal-price-analysis p { font-size: 0.82rem; color: var(--text-secondary); line-height: 1.5; }

.modal-link {
  display: inline-flex; align-items: center; gap: 0.3rem;
  color: var(--accent); font-size: 0.88rem; font-weight: 500;
  text-decoration: none; transition: color var(--transition);
}
.modal-link:hover { color: var(--accent-hover); }

/* ---- Grid View ---- */
.grid-view .listings-panel {
  width: 100%; border-left: none; position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
}
.grid-view .listings-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 0.75rem; padding: 1rem;
}
.grid-view .map-container { display: none; }

/* ---- List View ---- */
.list-view .listings-panel { width: 100%; border-left: none; }
.list-view .listing-card { display: flex; flex-direction: row; }
.list-view .card-image, .list-view .card-image-placeholder { width: 200px; height: 140px; min-width: 200px; }
.list-view .map-container { display: none; }

/* ---- Loading ---- */
.loading-spinner {
  display: flex; align-items: center; justify-content: center;
  padding: 3rem; color: var(--text-muted);
}
.loading-spinner::after {
  content: ''; width: 32px; height: 32px;
  border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Mobile Bottom Nav ---- */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(60px + env(safe-area-inset-bottom, 0px));
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  z-index: 1100;
  justify-content: space-around;
  align-items: flex-start;
  padding-top: 6px;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.mobile-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.65rem;
  font-family: inherit;
  cursor: pointer;
  padding: 0.4rem 1.2rem;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.mobile-nav-btn.active { color: var(--accent); }
.mobile-nav-btn svg { stroke: currentColor; }

/* ---- Mobile sidebar overlay ---- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 999;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.sidebar-overlay.active { display: block; }

/* ---- Responsive ---- */
@media (max-width: 1024px) {
  .sidebar { width: 260px; }
  .listings-panel { width: 340px; }
}

@media (max-width: 768px) {
  /* CSS custom prop for mobile bottom nav height */
  :root {
    --mobile-nav-height: calc(60px + env(safe-area-inset-bottom, 0px));
  }

  /* Show mobile nav */
  .mobile-nav { display: flex; }

  /* Adjust body and main layout for mobile */
  body {
    height: 100vh;
    height: 100dvh;
    position: fixed;
    width: 100%;
    top: 0;
    left: 0;
  }
  .main-layout {
    height: calc(100vh - var(--topbar-height) - var(--mobile-nav-height));
    height: calc(100dvh - var(--topbar-height) - var(--mobile-nav-height));
  }

  /* Topbar compact */
  .topbar {
    padding: 0 0.5rem;
    padding-top: env(safe-area-inset-top, 0px);
    height: calc(var(--topbar-height) + env(safe-area-inset-top, 0px));
    gap: 0.5rem;
  }
  .topbar-left { gap: 0.5rem; flex: 1; min-width: 0; }
  .topbar-right { gap: 0.4rem; flex-shrink: 0; }
  .logo span { display: none; }
  .logo { font-size: 1.3rem; }
  .search-box { width: 100%; min-width: 0; flex: 1; }
  .search-box input { font-size: 16px; } /* Prevents iOS zoom on focus */
  .view-toggle { display: none; }
  .stats-badge { font-size: 0.7rem; padding: 0.25rem 0.5rem; }
  .btn-heatmap { padding: 0.35rem 0.5rem; font-size: 0.9rem; }

  /* Sidebar as slide-over from left */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 85vw;
    max-width: 340px;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 1rem;
    padding-top: calc(1rem + env(safe-area-inset-top, 0px));
    padding-bottom: calc(1rem + var(--mobile-nav-height));
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  .sidebar.mobile-open {
    transform: translateX(0);
  }

  /* Listings panel as full-screen overlay */
  .listings-panel {
    width: 100%;
    position: fixed;
    top: var(--topbar-height);
    bottom: var(--mobile-nav-height);
    left: 0;
    right: 0;
    z-index: 950;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-left: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  .listings-panel.mobile-open {
    transform: translateY(0);
  }
  .listings-panel .panel-header { display: none; }

  /* Grid view on mobile listings */
  .listings-panel .listings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    padding: 0.5rem;
    overflow-y: visible;
  }

  /* Smaller cards on mobile */
  .listing-card { -webkit-tap-highlight-color: transparent; }
  .card-image, .card-image-placeholder { height: 110px; }
  .card-body { padding: 0.5rem; }
  .card-price { font-size: 0.95rem; }
  .card-ppsqm { font-size: 0.65rem; }
  .card-address { font-size: 0.72rem; }
  .card-specs { gap: 0.3rem; }
  .card-spec { font-size: 0.68rem; }
  .card-spec svg { width: 12px; height: 12px; }
  .card-tags { gap: 0.2rem; }
  .card-tag { font-size: 0.58rem; padding: 1px 4px; }
  .card-source { font-size: 0.6rem; }

  /* Map container full area */
  .map-container { flex: 1; position: relative; }

  /* Modal as bottom sheet */
  .modal-overlay { align-items: flex-end; }
  .modal {
    width: 100%;
    max-width: 100%;
    max-height: 92vh;
    max-height: 92dvh;
    border-radius: 16px 16px 0 0;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  .modal-close {
    position: sticky;
    top: 0.5rem;
    float: right;
    margin: 0.5rem;
    z-index: 20;
  }
  .modal-gallery img { height: 200px; }
  .modal-body { padding: 1rem; padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px)); }
  .modal-header-info { flex-direction: column; gap: 0.3rem; }
  .modal-header-info h2 { font-size: 1rem; }
  .modal-price { font-size: 1.2rem; }
  .modal-specs { grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
  .modal-spec { padding: 0.5rem 0.3rem; }
  .modal-spec-value { font-size: 0.9rem; }
  .modal-spec-label { font-size: 0.6rem; }
  .modal-description { font-size: 0.82rem; }

  /* Filter adjustments for mobile */
  .filter-section { margin-bottom: 1rem; }
  .filter-label { font-size: 0.72rem; }
  .range-inputs input { font-size: 16px; padding: 0.5rem; } /* Prevent iOS zoom */
  .room-buttons { flex-wrap: wrap; }
  .room-btn { min-width: 38px; height: 38px; -webkit-tap-highlight-color: transparent; }
  .chip { padding: 0.35rem 0.65rem; -webkit-tap-highlight-color: transparent; }
  .amenity-toggles { grid-template-columns: 1fr 1fr; gap: 0.25rem; }
  .toggle-item { font-size: 0.75rem; padding: 0.4rem; }
  .filter-select { font-size: 16px; padding: 0.5rem; } /* Prevent iOS zoom */

  /* Price markers smaller on mobile */
  .price-marker { font-size: 0.65rem; padding: 2px 6px; }

  /* Hide map overlays on mobile - they get in the way */
  .neighborhood-overlay { display: none !important; }

  /* Grid/List view overrides for mobile */
  .grid-view .listings-panel,
  .list-view .listings-panel {
    position: fixed;
    width: 100%;
  }
  .list-view .listing-card { flex-direction: column; }
  .list-view .card-image, .list-view .card-image-placeholder { width: 100%; min-width: unset; height: 110px; }
}

/* ---- Leaflet popup override ---- */
.leaflet-popup-content-wrapper {
  background: var(--bg-card) !important;
  color: var(--text-primary) !important;
  border-radius: var(--radius) !important;
  border: 1px solid var(--border) !important;
  box-shadow: var(--shadow) !important;
}
.leaflet-popup-tip { background: var(--bg-card) !important; }
.leaflet-popup-content { font-family: 'Inter', sans-serif !important; font-size: 0.82rem !important; }

.popup-content { min-width: 200px; }
.popup-content img { width: 100%; height: 120px; object-fit: cover; border-radius: 6px; margin-bottom: 0.5rem; }
.popup-price { font-size: 1rem; font-weight: 700; color: var(--price-color); }
.popup-address { font-size: 0.78rem; color: var(--text-secondary); margin: 0.2rem 0; }
.popup-specs { font-size: 0.75rem; color: var(--text-muted); }
.popup-btn {
  display: block; width: 100%; margin-top: 0.5rem; padding: 0.4rem;
  background: var(--accent); color: #fff; border: none; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 0.78rem; font-family: inherit; font-weight: 500;
}
.popup-btn:hover { background: var(--accent-hover); }
