/* Layout. Phones + tablets (below 62rem): the controls (search, List/Map
   switch, status), then EITHER the list of cards OR a full-width map with the
   tapped venue's cards under it — .map-layout[data-view], set by map.js; the
   page scrolls, no inner scroll box. Desktop: controls + list on the left (the
   list scrolls inside the map's height), the map on the right. */
.map-layout {
  --map-h: clamp(20rem, 60svh, 27.5rem);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-md-lg-d);
}

.map-controls {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  min-width: 0;
}

.map {
  width: 100%;
  height: var(--map-h);
  /* Keep the map (and Leaflet's panes) beneath the sticky header. */
  z-index: 0;
}

/* Under the tapped venue's bar: --space-sm (the layout gap above it is the
   map → bar space). */
.map-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  min-width: 0;
}

@media (max-width: 61.99rem) {
  /* The map runs edge to edge (cancels the container's --space-md sides). */
  .map {
    width: auto;
    margin-inline: calc(-1 * var(--space-md));
  }

  /* List view hides the map; Map view hides the list until a pin is tapped. */
  .map-layout[data-view="list"] .map,
  .map-layout[data-view="map"]:not(.has-selection) .map-list {
    display: none;
  }
}

/* Tablets: the search row stays the standard form width and the switch is
   capped so its two halves don't stretch across the page (full width on phones). */
@media (min-width: 48rem) and (max-width: 61.99rem) {
  .map-search {
    max-width: var(--form-width);
  }

  .map-views {
    max-width: 20rem;
  }
}

/* --- Desktop: controls + list left, map right --- */
@media (min-width: 62rem) {
  .map-layout {
    --map-h: clamp(20rem, 80vh, 725px);
    grid-template-columns: var(--grid-narrow) var(--grid-wide);
    grid-template-rows: auto minmax(0, 1fr);
    gap: var(--space-sm) var(--space-md-lg-d);
    height: var(--map-h); /* a definite height, so the list row scrolls */
  }

  .map-controls {
    grid-column: 1;
    grid-row: 1;
  }

  .map-list {
    grid-column: 1;
    grid-row: 2;
    min-height: 0;
  }

  .map {
    grid-column: 2;
    grid-row: 1 / span 2;
    border-radius: var(--br-md);
    box-shadow: var(--shadow);
    overflow: hidden;
  }
}

/* List / Map switch: a pink-outlined pill of two halves; the pressed one is
   filled. */
.map-views {
  display: flex;
  padding: 0.2rem;
  border: var(--border-width) solid var(--primary-color);
  border-radius: var(--br-rounded);
  background: var(--white);
}

.map-views__button {
  flex: 1 1 0;
  padding: 0.6rem;
  border: 0;
  border-radius: var(--br-rounded);
  background: none;
  color: var(--primary-color);
  font: inherit;
  font-size: var(--font-sm);
  font-weight: 700;
  line-height: 1.5;
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease);
}

.map-views__button[aria-pressed="true"] {
  background: var(--primary-color);
  color: var(--white);
}

/* The global pink ring would vanish on the pressed (pink) half — white inside it. */
.map-views__button[aria-pressed="true"]:focus-visible {
  outline-color: var(--white);
}

.map-views__button:focus-visible {
  outline-offset: -2px;
}

/* Desktop shows the list and the map together. */
@media (min-width: 62rem) {
  .map-views {
    display: none;
  }
}

/* Search row: combined postcode + radius pill, then the locate button */

.map-search {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.map-field {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: 3rem;
  padding: 0 0.3rem 0 0.95rem;
  border: 1px solid var(--grey-40);
  border-radius: var(--br-rounded);
  background: var(--white);
}

#map-postcode {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 1rem; /* >=16px stops iOS zooming the field on focus */
  color: var(--text-color);
}

.map-postcode:focus {
  outline: none;
}

/* The input is borderless inside the pill, so focus goes on the pill — drawn
   over its border (same treatment as form fields, see forms.css). */
.map-field:has(:focus-visible) {
  border-color: var(--primary-color);
  outline-offset: -2px;
}

/* Hide the native type=search clear button — the pill provides its own controls */
#map-postcode::-webkit-search-decoration,
#map-postcode::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

/* Filled brand disc + white glass submit — matches the site search (forms.css) */
.map-submit {
  position: relative;
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  margin-left: 0.4rem;
  border: 0;
  border-radius: 50%;
  background: var(--primary-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}

.map-search-glyph {
  position: relative;
  width: 0.95rem;
  height: 0.95rem;
  border: 2.5px solid var(--white);
  border-radius: 50%;
  transition:
    transform var(--duration-fast) var(--ease),
    opacity var(--duration-fast) var(--ease);
}

/* Glass handle */
.map-search-glyph::after {
  content: "";
  position: absolute;
  right: -0.32rem;
  bottom: -0.04rem;
  width: 0.45rem;
  height: 2.5px;
  border-radius: var(--br-rounded);
  background: var(--white);
  transform: rotate(45deg);
  transform-origin: left center;
  transition:
    transform var(--duration-fast) var(--ease),
    opacity var(--duration-fast) var(--ease);
}

/* X bars (white) — hidden until a search is active, then morph in */
.map-submit::before,
.map-submit::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1.1rem;
  height: 2.5px;
  border-radius: var(--br-rounded);
  background: var(--white);
  opacity: 0;
  transform: translate(-50%, -50%) rotate(0deg);
  z-index: 1;
  transition:
    transform var(--duration-fast) var(--ease),
    opacity var(--duration-fast) var(--ease);
}

/* ACTIVE STATE → morph glass to X (mirrors the site search in forms.css) */
.map-field.is-searched .map-search-glyph {
  opacity: 0;
  transform: scale(0.7);
}

.map-field.is-searched .map-search-glyph::after {
  opacity: 0;
  transform: rotate(45deg) scale(0.5);
}

.map-field.is-searched .map-submit::before {
  opacity: 1;
  transform: translate(-50%, -50%) rotate(45deg);
}

.map-field.is-searched .map-submit::after {
  opacity: 1;
  transform: translate(-50%, -50%) rotate(-45deg);
}


/* The locate button (.locate-button) is shared with the groups list — its
   rules live in forms.css. */

/* Status line ("Groups meeting within 20 miles of PR1 (Preston)") */
.map-status {
  margin: 0;
  font-size: var(--font-sm);
  color: var(--text-color);
}

/* A tapped pin's bar: "1 group meets at …" + Clear selection. */
.map-selection {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
}

.map-selection[hidden] {
  display: none;
}

.map-selection__text {
  margin: 0;
  font-size: var(--font-sm);
  color: var(--text-color);
}

.map-reset {
  flex-shrink: 0;
  border: var(--border-width-sm) solid var(--grey-40);
  border-radius: var(--br-rounded);
  padding: 0.3rem 0.9rem;
  background: var(--white);
  font-size: var(--font-sm);
  color: var(--text-color);
  cursor: pointer;
}

.map-reset:hover {
  border-color: var(--primary-color);
  color: var(--primary-color);
}

/* "See these groups as a list" (→ /groups, same search): desktop only — below
   62rem the page has its own List view. A dotted rule above it parts it from
   the scrolling cards; the link is the shared .link-cue (elements.css). */
.map-list-foot {
  display: none;
  padding-top: var(--space-sm);
  border-top: var(--border-width) dotted var(--grey-30);
}

@media (min-width: 62rem) {
  .map-list-foot {
    display: block;
  }
}

/* --- Results list (lazy loaded) ---------------------------------------- */

/* Phones: one column of cards in the page scroll; tablets two (top-aligned,
   so an open card leaves a gap under its closed neighbour). */
.map-results {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  gap: var(--card-gap);
}

@media (min-width: 48rem) and (max-width: 61.99rem) {
  .map-results {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Desktop: one column scrolling inside the map's height. */
@media (min-width: 62rem) {
  .map-results {
    display: flex;
    flex-direction: column;
    align-items: stretch; /* undo the grid's start, which here shrinks cards to their text */
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
    /* Negative side margins + matching side padding give the cards' box-shadows
       room (overflow-y forces overflow-x to clip too), while keeping the cards
       aligned to the column's content edges — mirrors .event-scroll. */
    margin: 0 -0.75rem;
    padding: 0.75rem;
    scrollbar-width: thin; /* Firefox */
    scrollbar-color: var(--primary-color) transparent;
  }
}

/* Thin brand scrollbar (WebKit/Blink) — persists even with OS auto-hide bars. */
.map-results::-webkit-scrollbar {
  width: 8px;
}

.map-results::-webkit-scrollbar-thumb {
  background: var(--primary-color);
  border-radius: var(--br-rounded);
}

.map-results::-webkit-scrollbar-track {
  background: transparent;
}

.map-empty {
  grid-column: 1 / -1;
  color: var(--grey-70);
  font-size: var(--font-sm);
}

/* Map result card styles live in cards.css (.info-card*) so they can be
   reused on the group single's events list — cards.css loads sitewide. */


/* --- Map overlays ------------------------------------------------------ */

/* Radius circle + "you are here" overlays (Leaflet vector paths) */
.map-radius {
  stroke: var(--primary-color);
  stroke-width: 2;
  stroke-opacity: 0.5;
  fill: var(--primary-color);
  fill-opacity: 0.1;
}

/* "You are here" — a purple dot in a white ring, so it can't be taken for a
   (pink) venue pin or lost among them. */
.map-origin {
  stroke: var(--white);
  stroke-width: 3;
  fill: var(--secondary-color);
  fill-opacity: 1;
  filter: var(--pin-shadow);
}

.map-radius-handle {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 2px solid var(--primary-color);
  border-radius: 50%;
  background: var(--white);
  box-shadow: var(--shadow);
  cursor: grab;
}

.map-radius-handle__icon {
  width: 16px;
  height: auto;
  fill: var(--primary-color);
  pointer-events: none;
}

.map-radius-handle:active {
  cursor: grabbing;
}

/* Brand-coloured marker pin */
.map-marker {
  background: none;
  border: 0;
}

.map-marker-pin {
  display: block;
  filter: var(--pin-shadow);
  cursor: pointer;
}

.map-marker-pin path {
  fill: var(--primary-color);
}

/* A cluster of pins (Leaflet.markercluster, map.js clusterIcon()): a pink
   disc in a white ring with the venue count. Size (36 / 42 / 48px) is set
   by the script. No transform here — Leaflet positions markers with one. */
.map-cluster {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  border: var(--border-width-lg) solid var(--white);
  border-radius: var(--br-rounded);
  background: var(--primary-color);
  color: var(--white);
  font-family: var(--heading-font);
  font-size: var(--font-sm);
  font-weight: 700;
  line-height: 1;
  filter: var(--pin-shadow);
  cursor: pointer;
  transition: box-shadow var(--duration-fast) var(--ease);
}

/* Hovered, or holding the pin of the card being hovered / focused or of the
   tapped venue (map.js ringClusters()): a solid pink ring outside the white
   one — a pale tint was too faint on the faded tiles. */
.map-cluster:hover,
.map-cluster.is-highlighted {
  box-shadow: 0 0 0 calc(var(--border-width-lg) * 2) var(--primary-color);
}

/* The split / merge animation on zoom (from the plugin's MarkerCluster.css,
   which isn't loaded). The plugin only adds the class when motion is allowed. */
.leaflet-cluster-anim .leaflet-marker-icon {
  transition: transform var(--duration-fast) var(--ease), opacity var(--duration-fast) var(--ease);
}
