/* ===== Map Page Layout ===== */
/* The page is a full-height column — topbar, heading, map, footer — so the map takes
   exactly the room the others leave and the page does not scroll. Before this the map
   was a fixed calc(100vh - 62px) and the page ran ~260px long, so scrolling slid the
   map underneath the sticky topbar; both are navy, so it read as the map sitting on
   top of the nav. min-height keeps the map usable on short viewports, where the page
   is allowed to scroll again.
   z-index:0 makes the container its own stacking context, so Leaflet's panes (400)
   and controls (800, and .map-controls at 1000) can never paint over the topbar (200). */
body.map-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ⚠️ .wrap carries `margin: 0 auto`. Once body.map-page became a flex column that
   stopped centring a full-width block and started shrink-to-fitting the item, which
   indented the heading away from the page's left edge. Force it full width so the
   text sits on the same 56px margin as every other page. */
body.map-page > .wrap { width: 100%; }

/* The heading block was taking ~254px of an 800px viewport, leaving the map about
   392px and cropping the world top and bottom. Tightened on this page only — the
   collection and search pages keep the full-size treatment. The deck is given a wider
   measure so it sets in two lines rather than three. */
body.map-page .cat-head { padding: 18px 56px 10px; }
body.map-page .cat-head h1 { margin: 6px 0 0; font-size: 30px; }
body.map-page .map-deck { margin: 8px 0 0; font-size: 15px; line-height: 1.5; max-width: 900px; }

#map-container {
  position: relative;
  z-index: 0;
  height: calc(100vh - 62px);
}

body.map-page #map-container {
  flex: 1 1 auto;
  height: auto;
  min-height: 380px;
  /* #map is height:100%, which resolves to ZERO against a flex-auto parent — the map
     silently disappears while its SVG paths stay in the DOM, so scripted checks still
     pass. Make this a flex parent and let #map grow instead of measuring a percentage. */
  display: flex;
}

body.map-page #map {
  flex: 1 1 auto;
  height: auto;
}

#map {
  width: 100%;
  height: 100%;
  background: #1a2744;
}

/* ===== Filter Controls Panel ===== */
.map-controls {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 1000;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: 0 2px 12px rgba(0,0,0,0.25);
  padding: 1.25rem;
  width: 240px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}

.map-controls h3 {
  font-family: 'Playfair Display', serif;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 0.75rem;
  padding-bottom: 0.35rem;
  border-bottom: 2px solid var(--gold);
}

.map-filter-options {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.map-filter-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text);
  padding: 0.2rem 0;
  transition: color var(--transition);
}

.map-filter-option:hover {
  color: var(--navy);
}

.map-filter-option input[type="checkbox"] {
  accent-color: var(--gold);
  flex-shrink: 0;
}

.color-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 2px;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.15);
}

/* ===== Legend-only item (non-interactive) ===== */
.map-legend-divider {
  border-top: 1px solid var(--parchment-dark);
  margin: 0.5rem 0;
}

.map-legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-light);
  padding: 0.2rem 0;
}

/* ===== Map Stats ===== */
.map-stats {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--parchment-dark);
  font-size: 0.8rem;
  color: var(--text-light);
  line-height: 1.5;
}

/* ===== Leaflet Popup Styling ===== */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius) !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2) !important;
}

.leaflet-popup-content {
  margin: 0 !important;
  font-family: 'Source Sans 3', sans-serif !important;
  min-width: 200px;
}

.map-popup {
  padding: 1rem;
}

.map-popup-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 0.4rem;
}

.map-popup-count {
  font-size: 0.9rem;
  color: var(--text);
  margin-bottom: 0.6rem;
}

.map-popup-periods {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
}

.map-popup-period {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-light);
}

.map-popup-period .color-swatch {
  width: 10px;
  height: 10px;
}

.map-popup-link {
  display: inline-block;
  padding: 0.35rem 0.75rem;
  background: var(--navy);
  color: var(--white);
  text-decoration: none;
  border-radius: var(--radius);
  font-size: 0.82rem;
  font-weight: 500;
  transition: background var(--transition);
}

.map-popup-link:hover {
  background: var(--navy-light);
}

/* ===== Mobile Responsive ===== */
@media (max-width: 768px) {
  #map-container {
    height: calc(100vh - 52px);
  }

  .map-controls {
    top: auto;
    bottom: 1rem;
    right: 0.5rem;
    left: 0.5rem;
    width: auto;
    max-height: 40vh;
    padding: 1rem;
  }

  .map-controls h3 {
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .map-controls h3::after {
    content: '\25B2';
    font-size: 0.6rem;
    transition: transform var(--transition);
  }

  .map-controls.collapsed h3::after {
    transform: rotate(180deg);
  }

  .map-controls.collapsed .map-filter-options,
  .map-controls.collapsed .map-stats {
    display: none;
  }
}
