/* ============================================================================
   HAVENLY DESIGN SYSTEM — MAPBOX & SEARCH RESULTS PAGE
   Drop after havenly-ds.css, havenly-ds-dark.css, havenly-ds-nav.css.

   Requires: Mapbox GL JS v3.x CSS (from CDN or npm).
     <link href="https://api.mapbox.com/mapbox-gl-js/v3.6.0/mapbox-gl.css" rel="stylesheet">

   Provides:
     - .hv-map (container + theme-aware styling)
     - .hv-pin (custom price-pill markers, Airbnb-style)
     - .hv-cluster (cluster bubble markers)
     - .hv-popup (Mapbox popup re-skinned to match Havenly cards)
     - .hv-srp (search results page layout — filter bar + map+list dual view)
     - .hv-listing-card (compact horizontal card for SRP)
     - .hv-filter-chip + .hv-filter-bar
     - Mobile map toggle UI
   ============================================================================ */

/* ─── Mapbox CSS overrides — adapt their controls to Havenly tokens ─── */

.mapboxgl-ctrl-group {
  background: var(--hv-color-surface-default) !important;
  border: 1px solid var(--hv-color-border-default) !important;
  box-shadow: var(--hv-shadow-sm) !important;
  border-radius: var(--hv-radius-sm) !important;
  overflow: hidden;
}
.mapboxgl-ctrl-group button {
  width: 36px !important;
  height: 36px !important;
  background-color: transparent !important;
  transition: background-color var(--hv-duration-mid) var(--hv-ease-hover);
}
.mapboxgl-ctrl-group button:hover {
  background-color: var(--hv-color-surface-muted) !important;
}
.mapboxgl-ctrl-group button + button {
  border-top: 1px solid var(--hv-color-border-subtle) !important;
}
.mapboxgl-ctrl-attrib {
  background: rgba(255, 255, 255, 0.85) !important;
  backdrop-filter: blur(6px);
  border-radius: var(--hv-radius-sm) !important;
  font-size: 10px;
  padding: 2px 6px !important;
}
[data-theme="dark"] .mapboxgl-ctrl-attrib {
  background: rgba(10, 20, 36, 0.85) !important;
  color: var(--hv-color-text-muted);
}
[data-theme="dark"] .mapboxgl-ctrl-attrib a {
  color: var(--hv-color-text-default-subdued);
}

/* ─── Map container ─── */

.hv-map {
  position: relative;
  width: 100%;
  height: 100%;
  background: var(--hv-color-surface-muted);
  overflow: hidden;
}
.hv-map__canvas {
  position: absolute;
  inset: 0;
}
.hv-map--rounded { border-radius: var(--hv-radius-lg); }

/* ─── Custom markers (Airbnb-style price/category pill) ─── */
/* Created as a DOM element passed to new mapboxgl.Marker({ element }) */

.hv-pin {
  display: inline-flex;
  align-items: center;
  gap: var(--hv-space-1);
  padding: var(--hv-space-1) var(--hv-space-2);
  background: var(--hv-color-surface-default);
  color: var(--hv-color-text-default);
  border: 1px solid var(--hv-color-border-default);
  border-radius: var(--hv-radius-full);
  box-shadow: var(--hv-shadow-md);
  font-family: var(--hv-font-sans);
  font-size: var(--hv-text-xs);
  font-weight: var(--hv-weight-bold);
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  transform-origin: center bottom;
  transition: transform var(--hv-duration-fast) var(--hv-ease-hover),
              background-color var(--hv-duration-mid) var(--hv-ease-hover),
              color var(--hv-duration-mid) var(--hv-ease-hover),
              box-shadow var(--hv-duration-mid) var(--hv-ease-hover),
              border-color var(--hv-duration-mid) var(--hv-ease-hover);
  user-select: none;
  -webkit-user-select: none;
}
.hv-pin:hover {
  transform: scale(1.08);
  z-index: 2;
  box-shadow: var(--hv-shadow-lg);
  border-color: var(--hv-color-border-brand);
}
.hv-pin--featured {
  background: var(--hv-core-lemon-100);
  color: var(--hv-core-lemon-500);
  border-color: var(--hv-core-lemon-100);
}
.hv-pin--selected {
  background: var(--hv-color-action-primary);
  color: var(--hv-color-text-inverse);
  border-color: var(--hv-color-action-primary);
  transform: scale(1.12);
  z-index: 3;
  box-shadow: var(--hv-shadow-xl);
}
[data-theme="dark"] .hv-pin {
  background: var(--hv-color-surface-muted);
  color: var(--hv-color-text-default);
  border-color: var(--hv-color-border-default);
}
[data-theme="dark"] .hv-pin--featured {
  background: rgba(232, 163, 11, 0.20);
  color: #ffd166;
  border-color: rgba(232, 163, 11, 0.4);
}

.hv-pin__icon {
  width: 12px; height: 12px;
  flex-shrink: 0;
}
.hv-pin__dot {
  width: 6px; height: 6px;
  background: var(--hv-color-sage-500, #2d8650);
  border-radius: var(--hv-radius-full);
  flex-shrink: 0;
}
.hv-pin__dot--closed { background: var(--hv-core-neutral-300); }

/* Pulse animation on hover sync from list */
@keyframes hv-pin-pulse {
  0%, 100% { transform: scale(1.08); }
  50%      { transform: scale(1.20); }
}
.hv-pin--pulsing {
  animation: hv-pin-pulse 800ms ease-in-out infinite;
  z-index: 2;
  border-color: var(--hv-color-border-brand);
}

/* ─── Cluster bubble ─── */

.hv-cluster {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--hv-font-sans);
  font-weight: var(--hv-weight-bold);
  font-size: var(--hv-text-xs);
  color: white;
  background: var(--hv-color-action-primary);
  border: 3px solid var(--hv-color-surface-default);
  border-radius: var(--hv-radius-full);
  box-shadow: var(--hv-shadow-md);
  cursor: pointer;
  transition: transform var(--hv-duration-fast) var(--hv-ease-hover);
}
.hv-cluster:hover { transform: scale(1.08); }
.hv-cluster--sm {
  width: 36px; height: 36px;
  background: var(--hv-core-brand-400);
}
.hv-cluster--md {
  width: 44px; height: 44px;
  background: var(--hv-color-action-primary);
}
.hv-cluster--lg {
  width: 56px; height: 56px;
  background: var(--hv-core-brand-800);
  font-size: var(--hv-text-sm);
}

/* ─── Popup (re-skin Mapbox default) ─── */

.mapboxgl-popup {
  font-family: var(--hv-font-sans);
  z-index: 5;
}
.mapboxgl-popup-content {
  padding: 0 !important;
  background: var(--hv-color-surface-default) !important;
  border-radius: var(--hv-radius-lg) !important;
  box-shadow: var(--hv-shadow-xl) !important;
  border: 1px solid var(--hv-color-border-subtle) !important;
  overflow: hidden;
  width: 240px;
}
.mapboxgl-popup-close-button {
  width: 28px !important;
  height: 28px !important;
  font-size: 18px !important;
  line-height: 1 !important;
  color: var(--hv-color-text-default) !important;
  background: rgba(255, 255, 255, 0.9) !important;
  border-radius: var(--hv-radius-full) !important;
  margin: var(--hv-space-2) !important;
  padding: 0 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  z-index: 2 !important;
  border: none !important;
}
.mapboxgl-popup-close-button:hover { background: white !important; }
.mapboxgl-popup-tip {
  border-top-color: var(--hv-color-surface-default) !important;
  border-bottom-color: var(--hv-color-surface-default) !important;
}
[data-theme="dark"] .mapboxgl-popup-close-button {
  background: rgba(10, 20, 36, 0.9) !important;
  color: var(--hv-color-text-default) !important;
}
[data-theme="dark"] .mapboxgl-popup-tip {
  border-top-color: var(--hv-color-surface-default) !important;
  border-bottom-color: var(--hv-color-surface-default) !important;
}

.hv-popup-card {
  display: block;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}
.hv-popup-card__media {
  position: relative;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  background: var(--hv-color-surface-muted);
}
.hv-popup-card__image {
  width: 100%; height: 100%;
  object-fit: cover;
  background-size: cover;
  background-position: center;
}
.hv-popup-card__body {
  padding: var(--hv-space-3) var(--hv-space-4) var(--hv-space-4);
}
.hv-popup-card__title {
  font-size: var(--hv-text-sm);
  font-weight: var(--hv-weight-bold);
  color: var(--hv-color-text-default);
  margin: 0 0 var(--hv-space-1);
  line-height: var(--hv-lh-snug);
}
.hv-popup-card__meta {
  display: flex;
  align-items: center;
  gap: var(--hv-space-2);
  font-size: var(--hv-text-xxs);
  color: var(--hv-color-text-muted);
}
.hv-popup-card__rating {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-weight: var(--hv-weight-bold);
  color: var(--hv-color-text-default);
}

/* ─── SRP layout ─── */

.hv-srp {
  display: grid;
  grid-template-rows: auto 1fr;
  height: calc(100vh - 64px);
  background: var(--hv-color-surface-default);
}

.hv-srp__filter-bar {
  display: flex;
  align-items: center;
  gap: var(--hv-space-2);
  padding: var(--hv-space-3) var(--hv-page-margin);
  background: var(--hv-color-surface-default);
  border-bottom: 1px solid var(--hv-color-border-subtle);
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.hv-srp__filter-bar::-webkit-scrollbar { display: none; }

.hv-srp__main {
  display: grid;
  grid-template-columns: 1fr;
  overflow: hidden;
  position: relative;
}
@media (min-width: 940px) {
  .hv-srp__main { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 1240px) {
  .hv-srp__main { grid-template-columns: 1.1fr 1fr; }
}

/* List column */
.hv-srp__list {
  overflow-y: auto;
  padding: var(--hv-space-4) var(--hv-page-margin);
  display: flex;
  flex-direction: column;
  gap: var(--hv-space-3);
  background: var(--hv-color-surface-default);
}
.hv-srp__list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--hv-space-2);
}
.hv-srp__count {
  font-size: var(--hv-text-sm);
  color: var(--hv-color-text-default-subdued);
}
.hv-srp__count strong {
  color: var(--hv-color-text-default);
  font-weight: var(--hv-weight-bold);
}

/* Map column */
.hv-srp__map-pane {
  position: relative;
  display: none;
  height: 100%;
}
@media (min-width: 940px) {
  .hv-srp__map-pane { display: block; }
}
.hv-srp__map-pane .hv-map {
  position: absolute;
  inset: 0;
}

/* Mobile: full-screen map toggle */
.hv-srp__map-fab {
  position: fixed;
  bottom: var(--hv-space-6);
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: var(--hv-space-2);
  padding: var(--hv-space-3) var(--hv-space-5);
  background: var(--hv-color-surface-deep);
  color: var(--hv-color-text-inverse);
  border: none;
  border-radius: var(--hv-radius-full);
  font-family: var(--hv-font-sans);
  font-size: var(--hv-text-sm);
  font-weight: var(--hv-weight-bold);
  cursor: pointer;
  box-shadow: var(--hv-shadow-xl);
  z-index: 30;
  transition: transform var(--hv-duration-fast) var(--hv-ease-hover);
}
.hv-srp__map-fab:hover { transform: translateX(-50%) scale(1.04); }
.hv-srp__map-fab svg { width: 16px; height: 16px; }
@media (min-width: 940px) {
  .hv-srp__map-fab { display: none; }
}

.hv-srp[data-mobile-view="map"] .hv-srp__list { display: none; }
.hv-srp[data-mobile-view="map"] .hv-srp__map-pane {
  display: block;
  grid-column: 1 / -1;
}
.hv-srp[data-mobile-view="map"] .hv-srp__map-fab {
  /* swap to "List" label via JS */
}

/* ─── Filter chips ─── */

.hv-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--hv-space-1);
  padding: var(--hv-space-2) var(--hv-space-3);
  font-family: var(--hv-font-sans);
  font-size: var(--hv-text-xs);
  font-weight: var(--hv-weight-bold);
  color: var(--hv-color-text-default);
  background: var(--hv-color-surface-default);
  border: 1px solid var(--hv-color-border-default);
  border-radius: var(--hv-radius-full);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background-color var(--hv-duration-mid) var(--hv-ease-hover),
              border-color var(--hv-duration-mid) var(--hv-ease-hover),
              color var(--hv-duration-mid) var(--hv-ease-hover);
}
.hv-filter-chip:hover {
  border-color: var(--hv-color-border-strong);
  background: var(--hv-color-surface-muted);
}
.hv-filter-chip[aria-pressed="true"],
.hv-filter-chip--active {
  background: var(--hv-color-surface-deep);
  color: var(--hv-color-text-inverse);
  border-color: var(--hv-color-surface-deep);
}
.hv-filter-chip svg {
  width: 12px; height: 12px;
  opacity: 0.7;
}
.hv-filter-chip[aria-pressed="true"] svg { opacity: 1; }

.hv-filter-chip__count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  padding: 0 5px;
  height: 18px;
  margin-left: var(--hv-space-1);
  background: var(--hv-color-action-primary);
  color: white;
  border-radius: var(--hv-radius-full);
  font-size: 10px;
  font-weight: var(--hv-weight-bold);
}

.hv-filter-divider {
  width: 1px;
  height: 24px;
  background: var(--hv-color-border-subtle);
  margin: 0 var(--hv-space-2);
  flex-shrink: 0;
}

/* ─── Compact horizontal listing card (SRP-optimized) ─── */

.hv-listing-card {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: var(--hv-space-4);
  padding: var(--hv-space-3);
  background: var(--hv-color-surface-default);
  border: 1px solid var(--hv-color-border-subtle);
  border-radius: var(--hv-radius-lg);
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: transform var(--hv-duration-grand) var(--hv-ease-scale),
              box-shadow var(--hv-duration-grand) var(--hv-ease-scale),
              border-color var(--hv-duration-mid) var(--hv-ease-hover);
}
.hv-listing-card:hover,
.hv-listing-card--highlighted {
  border-color: var(--hv-color-border-default);
  box-shadow: var(--hv-shadow-md);
  transform: translateY(-1px);
}
.hv-listing-card--highlighted {
  border-color: var(--hv-color-border-brand);
}
@media (max-width: 640px) {
  .hv-listing-card {
    grid-template-columns: 100px 1fr;
    gap: var(--hv-space-3);
  }
}

.hv-listing-card__media {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: var(--hv-radius-md);
  overflow: hidden;
  background: var(--hv-color-surface-muted);
}
.hv-listing-card__image {
  width: 100%; height: 100%;
  object-fit: cover;
  background-size: cover;
  background-position: center;
  transition: transform var(--hv-duration-grand) var(--hv-ease-scale);
}
.hv-listing-card:hover .hv-listing-card__image { transform: scale(1.05); }
.hv-listing-card__media-tag {
  position: absolute;
  top: var(--hv-space-2);
  left: var(--hv-space-2);
}
.hv-listing-card__fav {
  position: absolute;
  top: var(--hv-space-1);
  right: var(--hv-space-1);
  width: 28px; height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: none;
  border-radius: var(--hv-radius-full);
  cursor: pointer;
  color: var(--hv-color-text-default);
  transition: transform var(--hv-duration-fast) var(--hv-ease-hover),
              background-color var(--hv-duration-fast) ease;
}
.hv-listing-card__fav:hover { background: white; transform: scale(1.1); }
.hv-listing-card__fav[aria-pressed="true"] { color: var(--hv-core-magenta-500); }
.hv-listing-card__fav svg { width: 14px; height: 14px; }

.hv-listing-card__body {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 0;
}
.hv-listing-card__top {
  display: flex;
  flex-direction: column;
  gap: var(--hv-space-1);
  min-width: 0;
}
.hv-listing-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--hv-space-2);
}
.hv-listing-card__title {
  font-size: var(--hv-text-sm);
  font-weight: var(--hv-weight-bold);
  color: var(--hv-color-text-default);
  line-height: var(--hv-lh-snug);
  letter-spacing: var(--hv-tracking-tight);
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}
.hv-listing-card__rating {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: var(--hv-text-xs);
  font-weight: var(--hv-weight-bold);
  color: var(--hv-color-text-default);
  flex-shrink: 0;
}
.hv-listing-card__rating svg {
  width: 12px; height: 12px;
  color: var(--hv-core-lemon-300);
  fill: currentColor;
}
.hv-listing-card__rating-count {
  color: var(--hv-color-text-muted);
  font-weight: var(--hv-weight-normal);
  margin-left: 2px;
}
.hv-listing-card__category {
  font-size: var(--hv-text-xs);
  color: var(--hv-color-text-muted);
  display: flex;
  align-items: center;
  gap: var(--hv-space-1);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hv-listing-card__price-dot,
.hv-listing-card__dot {
  width: 2px; height: 2px;
  background: currentColor;
  border-radius: var(--hv-radius-full);
  flex-shrink: 0;
}
.hv-listing-card__bottom {
  display: flex;
  align-items: center;
  gap: var(--hv-space-2);
  margin-top: var(--hv-space-2);
  font-size: var(--hv-text-xxs);
  color: var(--hv-color-text-muted);
}
.hv-listing-card__status {
  display: inline-flex;
  align-items: center;
  gap: var(--hv-space-1);
  color: var(--hv-core-sage-500);
  font-weight: var(--hv-weight-bold);
}
.hv-listing-card__status--closed { color: var(--hv-core-error-500); }
.hv-listing-card__status::before {
  content: '';
  width: 6px; height: 6px;
  background: currentColor;
  border-radius: var(--hv-radius-full);
}

/* ─── Sort dropdown ─── */

.hv-sort {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: var(--hv-space-2);
}
.hv-sort__label {
  font-size: var(--hv-text-xs);
  color: var(--hv-color-text-muted);
}
.hv-sort__select {
  font-family: inherit;
  font-size: var(--hv-text-xs);
  font-weight: var(--hv-weight-bold);
  color: var(--hv-color-text-default);
  background: transparent;
  border: 1px solid var(--hv-color-border-default);
  border-radius: var(--hv-radius-sm);
  padding: var(--hv-space-1) var(--hv-space-3);
  cursor: pointer;
  transition: border-color var(--hv-duration-mid) var(--hv-ease-hover);
}
.hv-sort__select:hover { border-color: var(--hv-color-border-strong); }
.hv-sort__select:focus-visible {
  outline: 2px solid var(--hv-color-border-focus);
  outline-offset: 2px;
}

/* ─── Pagination ─── */

.hv-pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--hv-space-1);
  padding: var(--hv-space-6) 0 var(--hv-space-4);
  font-family: var(--hv-font-sans);
}
.hv-pagination__page {
  width: 36px; height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--hv-text-sm);
  font-weight: var(--hv-weight-bold);
  color: var(--hv-color-text-default-subdued);
  border: 1px solid transparent;
  border-radius: var(--hv-radius-sm);
  background: transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background-color var(--hv-duration-mid) var(--hv-ease-hover),
              color var(--hv-duration-mid) var(--hv-ease-hover);
}
.hv-pagination__page:hover {
  background: var(--hv-color-surface-muted);
  color: var(--hv-color-text-default);
}
.hv-pagination__page[aria-current="page"] {
  background: var(--hv-color-action-primary);
  color: var(--hv-color-text-inverse);
}
.hv-pagination__page:disabled,
.hv-pagination__page[aria-disabled="true"] {
  opacity: 0.4;
  cursor: not-allowed;
}
.hv-pagination__ellipsis {
  width: 24px;
  text-align: center;
  color: var(--hv-color-text-quiet);
  font-size: var(--hv-text-sm);
}
