/* Eturnal Rest -- Zillow-style split map page.
   Left: full-height interactive Leaflet map. Right: scrollable rail of
   cemetery cards for the current viewport. Mobile: stacks with a Map|List
   toggle. Brand-blue, Merriweather+Lato, calm + premium. */

:root {
  --map-header-h: 72px; /* match the redesigned nav (72px rest) */
  --map-toolbar-h: 60px;
}

/* The map page is a fixed-height app; no document scroll, panes scroll. */
.map-body {
  overflow: hidden;
}
.map-shell {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--map-header-h));
  background: var(--cream);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ===================== Filter toolbar ===================== */
.map-toolbar {
  flex: 0 0 auto;
  min-height: var(--map-toolbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  background: var(--white);
  border-bottom: 1px solid var(--line-cool);
  box-shadow: 0 1px 0 rgba(29, 55, 68, 0.03);
  z-index: 600;
}
.map-toolbar__group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.map-select {
  appearance: none;
  -webkit-appearance: none;
  font-family: var(--font-sans);
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--white)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24'%3E%3Cpath fill='%2384909a' d='M7 10l5 5 5-5z'/%3E%3C/svg%3E")
    no-repeat right 12px center;
  border: 1.5px solid var(--line-cool);
  border-radius: 999px;
  padding: 9px 32px 9px 16px;
  cursor: pointer;
  transition: border-color var(--dur-1) var(--ease);
}
.map-select:hover {
  border-color: var(--blue-300);
}
.map-select:focus-visible {
  outline: none;
  border-color: var(--blue-500);
  box-shadow: 0 0 0 3px var(--blue-100);
}

.map-toggle-pill {
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink-2);
  background: var(--white);
  border: 1.5px solid var(--line-cool);
  border-radius: 999px;
  padding: 9px 16px;
  cursor: pointer;
  transition: all var(--dur-1) var(--ease);
}
.map-toggle-pill:hover {
  border-color: var(--blue-300);
  color: var(--blue-700);
}
.map-toggle-pill[aria-checked="true"] {
  background: var(--blue-600);
  border-color: var(--blue-600);
  color: #fff;
  box-shadow: 0 2px 8px rgba(70, 124, 153, 0.28);
}
.map-toggle-pill:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--blue-100);
}

.map-nearme {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--blue-700);
  background: var(--blue-50);
  border: 1.5px solid var(--blue-200);
  border-radius: 999px;
  padding: 9px 16px;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--dur-1) var(--ease);
}
.map-nearme:hover {
  background: var(--blue-100);
  border-color: var(--blue-300);
}
.map-nearme svg {
  display: block;
}
.map-nearme.is-busy {
  opacity: 0.6;
  pointer-events: none;
}
.map-nearme:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--blue-100);
}

.map-reset {
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink-3);
  background: none;
  border: 0;
  padding: 9px 8px;
  cursor: pointer;
  white-space: nowrap;
  transition: color var(--dur-1) var(--ease);
}
.map-reset:hover {
  color: var(--blue-700);
  text-decoration: underline;
}

/* Mobile Map | List switch (desktop hidden) */
.map-viewswitch {
  display: none;
  background: var(--blue-50);
  border: 1.5px solid var(--blue-200);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.map-viewswitch__btn {
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--blue-700);
  background: none;
  border: 0;
  border-radius: 999px;
  padding: 7px 18px;
  cursor: pointer;
}
.map-viewswitch__btn.is-active {
  background: var(--blue-600);
  color: #fff;
}

/* ===================== Split ===================== */
.map-split {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 1fr 420px;
  min-height: 0; /* let children own their scroll */
}
@media (min-width: 1500px) {
  .map-split {
    grid-template-columns: 1fr 460px;
  }
}

/* ---- Map pane ---- */
.map-pane {
  position: relative;
  min-height: 0;
  border-right: 1px solid var(--line-cool);
}
#er-map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #eef2f4;
  z-index: 1;
}

.map-loading {
  position: absolute;
  inset: 0;
  z-index: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--cream);
  color: var(--ink-2);
  transition: opacity var(--dur-2) var(--ease);
}
.map-loading.hidden {
  display: none;
}
.map-loading p {
  margin: 0;
  font-size: 0.96rem;
  max-width: 30ch;
  text-align: center;
}

/* Legend floating on map */
.map-legend {
  position: absolute;
  left: 14px;
  bottom: 22px;
  z-index: 500;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line-cool);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  font-size: 0.85rem;
  color: var(--ink-2);
  max-width: 220px;
}
.map-legend__toggle {
  display: none;
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--blue-700);
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}
.map-legend__body {
  display: grid;
  gap: 7px;
}
.legend-row {
  display: flex;
  align-items: center;
  gap: 9px;
  line-height: 1.2;
}
.legend-pin {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  flex: 0 0 auto;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(29, 55, 68, 0.2);
}
.legend-pin--verified {
  background: var(--blue-600);
}
.legend-pin--listed {
  background: var(--accent);
}
.legend-pin--indexed {
  background: var(--blue-300);
}
.legend-chip-mini {
  display: inline-grid;
  place-items: center;
  min-width: 26px;
  height: 18px;
  padding: 0 5px;
  font-size: 0.68rem;
  font-weight: 800;
  color: #fff;
  background: var(--accent);
  border-radius: 999px;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(189, 116, 64, 0.4);
}

/* ---- Results rail ---- */
.map-rail {
  position: relative;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--cream);
  overflow: hidden;
}
.map-rail__head {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 20px;
  background: rgba(249, 248, 244, 0.96);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line-cool);
  z-index: 5;
}
.map-rail__count {
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--blue-900);
  line-height: 1.25;
}
.map-rail__count .serif {
  font-family: var(--font-serif);
  font-weight: 600;
}
.map-rail__count b {
  color: var(--blue-700);
}
.map-rail__count small {
  display: block;
  font-weight: 500;
  font-size: 0.82rem;
  color: var(--ink-3);
  margin-top: 2px;
}
.map-rail__search {
  flex: 0 0 auto;
  font-family: var(--font-sans);
  font-size: 0.84rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(180deg, var(--blue-600), var(--blue-700));
  border: 0;
  border-radius: 999px;
  padding: 8px 15px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(70, 124, 153, 0.28);
  transition:
    transform var(--dur-1) var(--ease),
    box-shadow var(--dur-1) var(--ease);
}
.map-rail__search:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-blue);
}

.map-rail__list {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: grid;
  gap: 14px;
  align-content: start;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
.map-rail__hint {
  color: var(--ink-3);
  font-size: 0.92rem;
  text-align: center;
  padding: 40px 16px;
  margin: 0;
}

/* Rail cemetery card (compact horizontal, Zillow-style) */
.rail-card {
  display: grid;
  grid-template-columns: 122px 1fr;
  /* Floor the height so the row can never collapse. The photo image is
     absolutely positioned (below), so the row height is driven by the body
     content + this floor -- the old `img{height:100%}` created a circular
     dependency that collapsed the card to ~2px (it rendered as thin lines). */
  min-height: 116px;
  background: var(--white);
  border: 1px solid var(--line-cool);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition:
    box-shadow var(--dur-2) var(--ease-out),
    transform var(--dur-2) var(--ease-out),
    border-color var(--dur-1) var(--ease);
  scroll-margin: 14px;
}
.rail-card:hover,
.rail-card.is-hot {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
  border-color: var(--blue-300);
}
.rail-card.is-hot {
  outline: 2px solid var(--blue-500);
  outline-offset: -1px;
}
.rail-card__photo {
  position: relative;
  background: var(--blue-50);
  overflow: hidden;
}
.rail-card__photo img {
  /* Absolute fill: the image must NOT contribute to the grid row's intrinsic
     height (that was the collapse bug). The photo column stretches to the row
     height set by the body + .rail-card min-height, and the image covers it. */
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--dur-3) var(--ease-out);
}
.rail-card:hover .rail-card__photo img {
  transform: scale(1.06);
}
.rail-card__photo.is-placeholder {
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--blue-500), var(--blue-700));
}
.rail-card__photo.is-placeholder span {
  font-family: var(--font-serif);
  font-weight: 900;
  font-size: 1.5rem;
  color: rgba(255, 255, 255, 0.92);
  letter-spacing: 0.04em;
}
.rail-card__body {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}
.rail-card__top {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.rail-card__name {
  font-family: var(--font-serif);
  font-size: 1.02rem;
  font-weight: 600;
  color: var(--blue-900);
  line-height: 1.2;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.rail-card__loc {
  font-size: 0.86rem;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rail-card__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 2px;
}
.rail-card__view {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--blue-700);
}
.rail-card:hover .rail-card__view {
  text-decoration: underline;
}
.chip--avail.chip--mini {
  font-size: 0.74rem;
  padding: 3px 9px;
}

/* discreet honesty disclaimer at rail foot */
.map-rail__note {
  flex: 0 0 auto;
  padding: 10px 18px 12px;
  font-size: 0.76rem;
  color: var(--ink-3);
  border-top: 1px solid var(--line-cool);
  background: rgba(249, 248, 244, 0.9);
  text-align: center;
}

.rail-skeleton {
  height: 128px;
  border-radius: var(--radius);
  background: linear-gradient(
    100deg,
    var(--sand) 30%,
    var(--stone) 50%,
    var(--sand) 70%
  );
  background-size: 200% 100%;
  animation: rail-shimmer 1.2s linear infinite;
}
@keyframes rail-shimmer {
  to {
    background-position: -200% 0;
  }
}

/* ===================== Leaflet markers ===================== */
.er-pin-wrap,
.er-pill-wrap,
.er-cluster-wrap {
  background: none !important;
  border: 0 !important;
}

/* plain dot pin (cemeteries without available plots) */
.er-pin {
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(29, 55, 68, 0.35);
  transition:
    transform var(--dur-1) var(--ease),
    box-shadow var(--dur-1) var(--ease);
}
.er-pin--verified {
  background: var(--blue-600);
}
.er-pin--listed {
  background: var(--accent);
}
.er-pin--indexed {
  background: var(--blue-300);
}
.er-pin-wrap:hover .er-pin,
.er-pin.is-hot {
  transform: scale(1.5);
  box-shadow: 0 2px 8px rgba(29, 55, 68, 0.5);
  z-index: 500;
}

/* price/plots pill marker (Zillow signature) for cemeteries WITH plots */
.er-pill {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  font-family: var(--font-sans);
  font-weight: 800;
  font-size: 0.74rem;
  line-height: 1;
  color: #fff;
  background: var(--accent);
  border: 1.5px solid #fff;
  border-radius: 999px;
  padding: 5px 9px;
  box-shadow: 0 2px 6px rgba(29, 55, 68, 0.35);
  cursor: pointer;
  transition:
    transform var(--dur-1) var(--ease),
    box-shadow var(--dur-1) var(--ease),
    background var(--dur-1) var(--ease);
}
.er-pill--verified {
  background: var(--blue-600);
}
.er-pill-wrap:hover .er-pill,
.er-pill.is-hot {
  transform: scale(1.12) translateY(-1px);
  box-shadow: 0 6px 16px rgba(29, 55, 68, 0.4);
  z-index: 600;
}
.er-pill.is-hot {
  background: var(--blue-700);
}

/* cluster bubble */
.er-cluster {
  display: grid;
  place-items: center;
  font-family: var(--font-sans);
  font-weight: 800;
  color: #fff;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.92);
  box-shadow: 0 4px 14px rgba(29, 55, 68, 0.32);
  transition: transform var(--dur-1) var(--ease);
}
.er-cluster-wrap:hover .er-cluster {
  transform: scale(1.06);
}
.er-cluster--sm {
  background: rgba(90, 144, 172, 0.94);
  font-size: 0.82rem;
}
.er-cluster--md {
  background: rgba(70, 124, 153, 0.95);
  font-size: 0.9rem;
}
.er-cluster--lg {
  background: rgba(56, 99, 122, 0.95);
  font-size: 0.98rem;
}
.er-cluster--xl {
  background: rgba(39, 80, 95, 0.96);
  font-size: 1.05rem;
}

/* ===================== Leaflet popup (brand) ===================== */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--line-cool);
}
.leaflet-popup-content {
  margin: 0;
  width: 240px !important;
}
.leaflet-container {
  font-family: var(--font-sans);
}
.er-popup {
  padding: 0;
  border-radius: var(--radius);
  overflow: hidden;
}
.er-popup__photo {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--blue-50);
  overflow: hidden;
}
.er-popup__photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.er-popup__photo.is-placeholder {
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--blue-500), var(--blue-700));
}
.er-popup__photo.is-placeholder span {
  font-family: var(--font-serif);
  font-weight: 900;
  font-size: 1.6rem;
  color: rgba(255, 255, 255, 0.92);
}
.er-popup__body {
  padding: 12px 14px 14px;
}
.er-popup__name {
  font-family: var(--font-serif);
  font-size: 1.08rem;
  font-weight: 600;
  color: var(--blue-900);
  margin: 0 0 3px;
  line-height: 1.2;
}
.er-popup__loc {
  font-size: 0.86rem;
  color: var(--ink-3);
  margin: 0 0 9px;
}
.er-popup__row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 11px;
}
.er-popup .btn {
  width: 100%;
  justify-content: center;
}
.leaflet-popup-close-button {
  width: 26px !important;
  height: 26px !important;
  font-size: 20px !important;
  color: #fff !important;
  top: 6px !important;
  right: 6px !important;
  background: rgba(29, 55, 68, 0.45) !important;
  border-radius: 50% !important;
  line-height: 24px !important;
}

/* Leaflet controls tuned to brand */
.leaflet-control-zoom a {
  color: var(--blue-700);
}
.leaflet-bar {
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow);
}

/* ===================== Responsive: stack on mobile ===================== */
@media (max-width: 880px) {
  .map-toolbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .map-toolbar::-webkit-scrollbar {
    display: none;
  }
  .map-toolbar__group {
    flex-wrap: nowrap;
  }
  .map-viewswitch {
    display: inline-flex;
    flex: 0 0 auto;
  }

  .map-split {
    display: block;
    position: relative;
    height: 100%;
  }
  .map-pane {
    position: absolute;
    inset: 0;
    border-right: 0;
  }
  .map-rail {
    position: absolute;
    inset: 0;
    z-index: 400;
    transform: translateY(100%);
    transition: transform var(--dur-2) var(--ease-out);
    box-shadow: 0 -8px 30px rgba(29, 55, 68, 0.18);
  }

  /* view-mode classes toggled on .map-split by JS */
  .map-split.show-list .map-rail {
    transform: translateY(0);
  }
  .map-split.show-map .map-rail {
    transform: translateY(100%);
  }

  /* default: map on top, peek the list as a draggable sheet */
  .map-split.peek .map-rail {
    transform: translateY(calc(100% - 178px));
  }

  .map-rail__head {
    cursor: grab;
    padding-top: 20px;
    touch-action: none;
  }
  .map-rail__head::before {
    content: "";
    position: absolute;
    top: 7px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    border-radius: 999px;
    background: var(--line);
  }

  .map-legend {
    display: none;
  }
}

@media (min-width: 881px) {
  .map-viewswitch {
    display: none;
  }
}

/* tighter rail card on narrow rails */
@media (max-width: 1100px) and (min-width: 881px) {
  .map-split {
    grid-template-columns: 1fr 360px;
  }
  .rail-card {
    grid-template-columns: 104px 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .map-rail,
  .er-pin,
  .er-pill,
  .er-cluster,
  .rail-card,
  .rail-card__photo img {
    transition: none !important;
  }
  .rail-skeleton {
    animation: none;
  }
}

/* ============================================================
   DESIGN SYSTEM v2 (2026-06-03) -- premium map markers + rail.
   Translucent glass clusters (no more ink-stain rash), accent
   price/plot pills as the Zillow signature, rail cards lifted on
   a cool well with a soft brand glow. Appended last: source order
   wins. See DESIGN-SPEC-v2.md section (g).
   ============================================================ */

/* Cluster bubbles: translucent glass + soft halo ring, capped at --blue-800. */
.er-cluster {
  color: #fff;
  font-weight: 800;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.95);
  box-shadow:
    0 4px 14px rgba(29, 55, 68, 0.22),
    0 0 0 6px rgba(70, 124, 153, 0.12);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.er-cluster--sm {
  background: rgba(90, 144, 172, 0.86);
  font-size: 0.82rem;
}
.er-cluster--md {
  background: rgba(70, 124, 153, 0.9);
  font-size: 0.9rem;
}
.er-cluster--lg {
  background: rgba(56, 99, 122, 0.92);
  font-size: 0.98rem;
}
.er-cluster--xl {
  background: rgba(39, 80, 95, 0.94);
  font-size: 1.05rem;
  box-shadow:
    0 6px 18px rgba(29, 55, 68, 0.26),
    0 0 0 8px rgba(56, 99, 122, 0.12);
}

/* Plain dot pins: softer shadow, calmer hover (1.5 was jarring on a dense map). */
.er-pin {
  box-shadow: 0 1px 3px rgba(29, 55, 68, 0.3);
}
.er-pin-wrap:hover .er-pin,
.er-pin.is-hot {
  transform: scale(1.4);
}

/* Price / plot pills -- the Zillow signature. Accent = available inventory. */
.er-pill {
  background: var(--grad-accent);
  color: #fff;
  font-weight: 800;
  padding: 6px 10px;
  border: 1.5px solid #fff;
  border-radius: var(--radius-pill);
  font-variant-numeric: tabular-nums;
  box-shadow:
    0 2px 6px rgba(29, 55, 68, 0.28),
    var(--shadow-inset-top);
}
.er-pill--verified {
  background: var(--grad-brand);
  box-shadow:
    0 2px 6px rgba(70, 124, 153, 0.3),
    var(--shadow-inset-top);
}
.er-pill-wrap:hover .er-pill,
.er-pill.is-hot {
  transform: scale(1.08) translateY(-1px);
  box-shadow:
    0 8px 18px rgba(29, 55, 68, 0.34),
    var(--shadow-inset-top);
  z-index: 600;
}
.er-pill.is-hot {
  background: var(--grad-brand);
}

/* Rail: cool well, white cards lift off it, soft brand glow on the map<->rail link. */
.map-rail {
  background: var(--surface-3);
}
.map-rail__head {
  background: rgba(238, 241, 243, 0.96);
}
.map-rail__note {
  background: rgba(238, 241, 243, 0.9);
}
.rail-card {
  background: var(--surface-0);
  border-color: var(--line-cool);
}
.rail-card:hover,
.rail-card.is-hot {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
  border-color: var(--blue-300);
}
.rail-card.is-hot {
  outline: none;
  box-shadow: var(--shadow-lg), var(--ring);
}

/* Toolbar active toggle aligns to the brand gradient for button consistency. */
.map-toggle-pill[aria-checked="true"] {
  background: var(--grad-brand);
  border-color: var(--blue-700);
  box-shadow: var(--shadow-blue);
}

/* Legend + zoom controls: a touch more polish. */
.map-legend {
  box-shadow: var(--shadow);
  border-radius: var(--radius);
}
.leaflet-bar {
  box-shadow: var(--shadow);
}
