/* ============================================
   PROPERTY MAP VIEW
   Split layout: map on the left, filterable result cards on the right.
   ============================================ */

.map-view {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 200px);
  min-height: 600px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
}

.map-view-public {
  height: calc(100vh - 240px);
}

/* ----- Filters bar ----- */
.map-filters-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-muted);
  flex-wrap: wrap;
}

.map-search-wrap {
  position: relative;
  flex: 1 1 220px;
  min-width: 200px;
  max-width: 320px;
}

.map-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.map-search-input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-size: 14px;
  background: var(--surface);
}

.map-search-input:focus {
  outline: none;
  border-color: var(--info-solid);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.map-filter-group {
  display: flex;
  align-items: center;
}

.map-filter-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 500;
}

.map-filter-select {
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font-size: 14px;
  background: var(--surface);
  color: #111;
  cursor: pointer;
  min-width: 120px;
}

.map-filter-select:focus {
  outline: none;
  border-color: var(--info-solid);
}

.map-clear-btn {
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
}

.map-clear-btn:hover {
  background: var(--surface-alt);
}

.map-view-toggle {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  overflow: hidden;
  margin-left: auto;
}

.map-toggle-btn {
  padding: 8px 14px;
  background: var(--surface);
  border: none;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
}

.map-toggle-btn + .map-toggle-btn {
  border-left: 1px solid var(--border);
}

.map-toggle-btn.active {
  background: #2563eb;
  color: #fff;
}

/* ----- Split layout ----- */
.map-split {
  display: grid;
  grid-template-columns: 1fr 380px;
  flex: 1;
  min-height: 0;
}

/* In single-pane modes (Map only / List only), collapse the grid to one
   1fr column so the surviving child fills the full width. The hidden child
   uses display:none, which removes it from the grid layout entirely. */
.map-split.mode-map,
.map-split.mode-list {
  grid-template-columns: 1fr;
}

.map-split.mode-list .map-canvas,
.map-split.mode-map .map-results {
  display: none;
}

/* In list-only mode, drop the left border that normally separates the
   results panel from the map (no map = no separator needed). */
.map-split.mode-list .map-results {
  border-left: none;
}

.map-canvas {
  width: 100%;
  height: 100%;
  background: var(--surface-alt);
}

.map-results {
  border-left: 1px solid var(--border);
  overflow-y: auto;
  background: var(--surface);
  display: flex;
  flex-direction: column;
}

.map-results-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--text-secondary);
  position: sticky;
  top: 0;
  z-index: 1;
}

#map-results-count {
  font-weight: 600;
}

.map-geocode-status {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
}

.map-results-list {
  padding: 8px;
}

/* In List mode the right pane takes the full width — tile the photo-rich
   grid cards across it, matching the old public grid view. */
.map-results-list.map-results-list-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  padding: 16px;
}

/* Reset interactive styles inherited from .map-result-card on the grid card,
   since .property-card has its own hover/border treatment. */
.map-grid-card {
  cursor: pointer;
}

/* ----- Result cards ----- */
.map-result-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.map-result-card:hover {
  border-color: var(--info-solid);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.1);
}

.map-result-card-active {
  border-color: var(--info-solid);
  background: var(--info-bg);
}

.map-result-price {
  font-size: 16px;
  font-weight: 700;
  color: #111;
  margin-bottom: 4px;
}

/* In the map sidebar, result cards are narrow (~360px). Shrink the
   price cells so $79,000 doesn't crowd the cell padding. */
.map-result-card .price-cells {
  margin: 8px 0 4px;
  gap: 4px;
}
.map-result-card .price-cell {
  padding: 5px 6px;
}
.map-result-card .price-cell-value {
  font-size: 12px;
}
.map-result-card .price-cell-label {
  font-size: 9px;
}

.map-result-address {
  font-size: 14px;
  /* 2026-07-22: was hardcoded #111 — invisible on dark-mode card
     backgrounds. Theme token adapts to both modes. */
  color: var(--text-primary, #111);
  font-weight: 500;
}

.map-result-location {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.map-result-stats {
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  gap: 6px;
  align-items: center;
}

.map-result-divider {
  color: #d1d5db;
}

.map-result-stats-pending,
.map-popup-pending {
  color: var(--text-muted);
  font-style: italic;
  font-size: 12px;
}

.map-result-footer {
  margin-top: 10px;
}

.map-card-btn {
  width: 100%;
  padding: 8px 12px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

.map-card-btn:hover {
  background: #1d4ed8;
}

/* Agent-side secondary CTA ("View property") — subtle, not the buyer's
   filled lead-capture button (2026-07-18). */
.map-card-btn.map-card-btn-view {
  background: var(--surface);
  color: var(--brand-primary);
  border: 1px solid var(--border-strong, #cbd5e1);
}

.map-card-btn.map-card-btn-view:hover {
  background: var(--surface-alt);
}

/* ----- Price marker ----- */
.map-price-marker {
  background: transparent !important;
  border: none !important;
}

.map-price-marker-bubble {
  background: var(--surface);
  color: #111;
  border: 1.5px solid var(--brand-primary);
  border-radius: 16px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  text-align: center;
  transform: translateY(-4px);
  transition: transform 0.15s, background 0.15s, color 0.15s;
}

.map-marker-hover .map-price-marker-bubble,
.map-price-marker:hover .map-price-marker-bubble {
  background: #2563eb;
  color: #fff;
  transform: translateY(-6px) scale(1.05);
  z-index: 10;
}

/* ----- Cluster marker (overrides Leaflet.markercluster default) ----- */
.map-cluster-marker {
  background: transparent !important;
  border: none !important;
}

.map-cluster-bubble {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #2563eb;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  transition: transform 0.15s, background 0.15s;
}

.map-cluster-marker:hover .map-cluster-bubble {
  background: #1d4ed8;
  transform: scale(1.1);
}

/* ----- Popup styling ----- */
.map-popup {
  font-family: inherit;
  min-width: 200px;
  max-width: 240px;
}

/* Thumbnail at the top of the popup. Fixed aspect, cropped via object-fit
   so wildly different photo sizes still look uniform. */
.map-popup-photo {
  position: relative;
  width: 100%;
  height: 110px;
  margin: -10px -12px 8px;     /* extend to popup edges (Leaflet adds 10/12 padding) */
  border-radius: 6px 6px 0 0;
  overflow: hidden;
  background: var(--surface-alt);
  display: flex;
  align-items: center;
  justify-content: center;
}

.map-popup-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.map-popup-photo-fallback {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* When the image is present we hide the fallback text. When the image fails
   to load it removes itself (see onerror) and the fallback becomes visible. */
.map-popup-photo img + .map-popup-photo-fallback {
  display: none;
}

.map-popup-photo-failed .map-popup-photo-fallback,
.map-popup-photo-empty .map-popup-photo-fallback {
  display: block;
}

.map-popup-price {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 4px;
  color: #111;
}

.map-popup-address {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  line-height: 1.4;
}

.map-popup-stats {
  font-size: 13px;
  color: var(--text-muted);
}

/* ----- Public mode toggle ----- */
.public-mode-toggle {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  overflow: hidden;
  margin-top: 16px;
}

.public-mode-btn {
  padding: 8px 16px;
  background: var(--surface);
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-secondary);
}

.public-mode-btn + .public-mode-btn {
  border-left: 1px solid var(--border);
}

.public-mode-btn.active {
  background: #2563eb;
  color: #fff;
}

.public-view-container {
  margin-top: 16px;
}

/* ----- Agent dashboard map toggle ----- */
.agent-view-toggle {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  overflow: hidden;
  margin-left: auto;
}

.agent-view-btn {
  padding: 8px 16px;
  background: var(--surface);
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-secondary);
}

.agent-view-btn + .agent-view-btn {
  border-left: 1px solid var(--border);
}

.agent-view-btn.active {
  background: #2563eb;
  color: #fff;
}

.agent-properties-view {
  margin-top: 16px;
}

/* Make agent dashboard header support the toggle */
.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

/* ----- Responsive ----- */
@media (max-width: 900px) {
  .map-split {
    grid-template-columns: 1fr;
    grid-template-rows: 50% 50%;
  }
  /* Single-pane modes: collapse to one 1fr row so the surviving child
     fills the full height. (Same fix pattern as the desktop columns rule.) */
  .map-split.mode-map,
  .map-split.mode-list {
    grid-template-rows: 1fr;
  }
  .map-results {
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .map-split.mode-list .map-results {
    border-top: none;
  }
  .map-view-toggle {
    margin-left: 0;
  }
}

/* ============================================
   2026-06-14 — Full-screen public split + photo split-cards (InvestorLift-style)
   ============================================ */
/* Use ~all the screen for the public map/list (thin hero bar above). */
.map-view-public { height: calc(100vh - 112px); min-height: 540px; }

/* Photo on the Split-mode result card. */
.map-result-card-photo { padding: 0; overflow: hidden; }
.map-result-hero {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  background: var(--surface-alt);
  overflow: hidden;
}
.map-result-hero > img {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.map-result-hero-fallback {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: 12px;
}
.map-result-hero-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: 12px;
}
.map-result-hero .hero-fallback-icon,
.map-result-hero-empty .hero-fallback-icon { font-size: 24px; }
.map-result-card-photo .map-result-body { padding: 10px 12px 4px; }
.map-result-card-photo .map-result-footer { padding: 6px 12px 12px; }
