/* styles/views/map.css — the Places map segment: scope chips, day scrubber, the map frame and its corner
   tools. Markers and leg styles live in features/map-markers.css, the tile switcher in features/basemaps.css;
   Leaflet's own chrome is restyled to the token system here. */

.view-places-map .places-controls { margin-bottom: var(--s-3); }
.map-chips { padding-block: var(--s-1); }
/* 44px of touch on a 32px chip / 36px stop pill, without taking the height from the map */
.map-chips .chip, .map-day-stop { position: relative; }
.map-chips .chip::after, .map-day-stop::after { content: ''; position: absolute; inset: -6px 0; }

/* ── Day scrubber ── */
.map-day { min-width: 0; }   /* a grid item: the stop strip scrolls inside it, never widens the page */
.map-day[hidden] { display: none; }
.map-day-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: var(--s-1);
  padding: var(--s-1);
  border: 1px solid var(--line); border-radius: var(--r-3);
  background: var(--surface);
}
.map-day-step {
  display: grid; place-items: center;
  width: var(--tap-min); height: var(--tap-min); padding: 0;
  border: 0; border-radius: var(--r-2);
  background: none; color: var(--text); cursor: pointer;
}
.map-day-step:active { background: var(--surface-pressed); }
.map-day-step:disabled { color: var(--text-3); opacity: 0.45; cursor: default; }
.map-day-step:focus-visible { outline: 2px solid var(--text); outline-offset: -2px; }
.map-day-what {
  display: flex; align-items: center; gap: var(--s-3); min-width: 0;
  padding: var(--s-1) var(--s-2); border-radius: var(--r-2);
  color: inherit; text-decoration: none;
}
.map-day-what:active { background: var(--surface-pressed); }
.map-day-what .stamp { flex: none; }
.map-day-text { display: grid; min-width: 0; }
.map-day-eyebrow {
  font: 600 var(--fs-micro)/var(--lh-micro) var(--font-sans);
  letter-spacing: var(--track-label, 0.06em); text-transform: uppercase;
  color: var(--tone-ink, var(--text-2));
}
.map-day-title { font: 600 var(--fs-body)/var(--lh-body) var(--font-serif); color: var(--text); }
.map-day-sub { font: var(--fs-caption)/var(--lh-caption) var(--font-sans); color: var(--text-2); }
.map-day-missing {
  display: flex; align-items: flex-start; gap: var(--s-2);
  margin: var(--s-2) var(--s-1) 0;
  font: var(--fs-caption)/var(--lh-caption) var(--font-sans); color: var(--text-2);
}
.map-day-missing .icon { flex: none; margin-top: 1px; color: var(--text-3); }
.map-day-missing-lead { font-weight: 600; color: var(--text); }

/* ── Frame ── */
.map-frame { position: relative; }
.map-canvas {
  height: 60dvh; /* replaced by JS with the exact viewport remainder */
  background: var(--bg); /* offline ground under the vector layers */
  outline: none;
  isolation: isolate;
  border-top: 1px solid var(--line);
}
.map-frame .leaflet-container {
  background: var(--bg);
  font-family: var(--font-sans);
  font-size: var(--fs-caption);
  color: var(--text);
}

/* The frame is fitted at fractional zooms, so base tiles are scaled: a 1px overlap, drawn opaque (not with the
   blend Leaflet uses), closes the hairline seams between them. The translucent relief pane is left alone. */
.map-frame .leaflet-tile-pane .leaflet-tile-container img.leaflet-tile { width: 257px !important; height: 257px !important; mix-blend-mode: normal; }

/* ── Corner tools (above the panes ≤ 700, below the place sheet) ── */
.map-tools {
  position: absolute; z-index: 800;
  top: var(--s-3); right: var(--gutter);
  display: grid;
  border: 1px solid var(--line-strong); border-radius: var(--r-2);
  background: var(--surface);
  box-shadow: var(--shadow-float);
  overflow: hidden;
}
.map-tool {
  display: grid; place-items: center;
  width: var(--tap-min); height: var(--tap-min); padding: 0;
  border: 0; border-top: 1px solid var(--line);
  background: var(--surface); color: var(--text);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.map-tool:first-child { border-top: 0; }
.map-tool[hidden] { display: none; }
.map-tool:active { background: var(--surface-pressed); }
.map-tool.is-on { background: var(--text); color: var(--surface); }
.map-tool:focus-visible { outline: 2px solid var(--text); outline-offset: -3px; }

.map-panel {
  position: absolute; z-index: 801;
  top: var(--s-3); right: calc(var(--gutter) + var(--tap-min) + var(--s-2));
  width: max-content; max-width: min(300px, calc(100% - 2 * var(--gutter) - var(--tap-min) - var(--s-2)));
  max-height: calc(100% - var(--s-3) - var(--s-6));
  overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  border: 1px solid var(--line-strong); border-radius: var(--r-3);
  background: var(--surface);
  box-shadow: var(--shadow-float);
}
.map-panel[hidden] { display: none; }
.map-panel-layers { padding: var(--s-2); }
/* the switcher and the legend bring their own cards — inside a panel they sit flat */
.map-panel .bm-switch.is-compare .bm-panel { padding: 0; border: 0; box-shadow: none; background: none; }
.map-panel .mk-legend { border: 0; box-shadow: none; background: none; max-width: none; }
/* the panel's own button opens and closes it: the card's fold is switched off here */
.map-panel .mk-legend-summary { pointer-events: none; }
.map-panel .mk-legend-chevron { display: none; }

.map-locate {
  position: absolute; z-index: 800;
  right: var(--gutter); bottom: var(--s-4);
  box-shadow: var(--shadow-float);
}

/* ── Paths owned by the map (leg styles come from map-markers.css) ── */
.map-frame .map-leg.is-faint { stroke-opacity: 0.5; }
.map-frame .map-leg-casing.is-faint { stroke-opacity: 0.35; }
/* trail start / end: a small open square in the region's ink */
.map-trailend {
  box-sizing: border-box;
  background: var(--surface);
  border: 2px solid var(--tone-ink, var(--text));
  border-radius: 1px;
}

/* ── Leaflet chrome in the house style ── */
.map-frame .leaflet-top.leaflet-left { top: var(--s-1); left: calc(var(--gutter) - 10px); }
.map-frame .leaflet-control-zoom.leaflet-bar {
  border: 1px solid var(--line-strong);
  border-radius: var(--r-2);
  box-shadow: var(--shadow-float);
  overflow: hidden;
}
.map-frame .leaflet-control-zoom a,
.leaflet-touch .map-frame .leaflet-control-zoom a {
  width: 40px;
  height: 40px;
  line-height: 40px;
  background: var(--surface);
  color: var(--text);
  border-bottom-color: var(--line);
  font-family: var(--font-sans);
}
.map-frame .leaflet-control-zoom a:hover,
.map-frame .leaflet-control-zoom a:focus-visible { background: var(--surface-pressed); color: var(--text); }
.map-frame .leaflet-control-zoom a.leaflet-disabled { background: var(--surface); color: var(--text-3); }
.map-frame .leaflet-container .leaflet-control-attribution {
  max-width: calc(100vw - 190px);          /* never runs under "Where am I" */
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  color: var(--text-3);
  font-family: var(--font-sans);
  font-size: 10px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.map-frame .leaflet-control-attribution a { color: var(--text-2); }

/* Pinch does the zooming on a phone — the +/− bar would only crowd the corner. */
@media (pointer: coarse) and (max-width: 600px) {
  .map-frame .leaflet-control-zoom { display: none; }
}

/* ── Day scope: the stops in order, by name (numbers match the map) ── */
.map-day-stops { margin-block: var(--s-2) 0; padding-left: calc(var(--gutter) + var(--safe-left)); padding-block: 2px; list-style: none; }
.map-day-stops > li { flex: none; display: flex; }
.map-day-stop {
  display: inline-flex; align-items: center; gap: var(--s-2);
  min-height: 36px; max-width: 220px; padding: 0 var(--s-3) 0 var(--s-1);
  border: 1px solid var(--line); border-radius: var(--r-pill);
  background: var(--surface); color: var(--text);
  font: var(--fs-caption)/var(--lh-caption) var(--font-sans);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.map-day-stop:active { background: var(--surface-pressed); }
.map-day-stop.is-current { border-color: var(--tone-ink, var(--text)); box-shadow: inset 0 0 0 1px var(--tone-ink, var(--text)); }
.map-day-stop:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.map-day-stop-n {
  flex: none; display: grid; place-items: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--tone, var(--text)); color: var(--on-tone, var(--surface));
  font: 600 var(--fs-micro)/1 var(--font-sans); font-variant-numeric: tabular-nums;
}
.map-day-stop-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* wide screens: the strip stays one scrolling line so the map keeps its height */
@media (min-width: 1024px) { .map-day-stops.chip-row { flex-wrap: nowrap; overflow-x: auto; padding-inline: 0; } }

/* ── Day scope: blocks in the strip, their lettered places, the walking total ── */
.map-day-stop.is-optional { border-style: dashed; }
.map-day-stop.is-optional .map-day-stop-n {
  background: none; color: var(--tone-ink, var(--text));
  box-shadow: inset 0 0 0 1px var(--tone-ink, var(--text));
}
.map-day-stop.is-block { padding-right: var(--s-2); gap: var(--s-1); }
.map-day-stop.is-block .map-day-stop-name { margin-left: var(--s-1); font-weight: 600; }
.map-day-stop.is-block .icon { flex: none; color: var(--text-3); }
.map-day-stop.is-block.is-open { background: var(--tone-wash, var(--surface-pressed)); border-color: var(--tone-ink, var(--text)); border-style: solid; }
.map-day-stop-count { flex: none; color: var(--text-2); font-variant-numeric: tabular-nums; }
/* the open block's places: one indented line under the strip, hung from a rule in the region's ink */
.map-day-members {
  margin-block: var(--s-1) 0; padding-left: calc(var(--gutter) + var(--safe-left) + var(--s-3)); padding-block: 2px;
  list-style: none; position: relative;
}
.map-day-members::before {
  content: ''; position: absolute; left: calc(var(--gutter) + var(--safe-left)); top: 6px; bottom: 6px;
  width: 2px; border-radius: 1px; background: var(--tone-ink, var(--line-strong)); opacity: 0.55;
}
.map-day-members > li { flex: none; display: flex; }
.map-day-stop.is-member { min-height: 32px; }
.map-day-stop.is-member .map-day-stop-n {
  width: auto; min-width: 20px; height: 20px; padding: 0 4px; box-sizing: border-box; border-radius: var(--r-pill);
  background: var(--surface); color: var(--tone-ink, var(--text));
  box-shadow: inset 0 0 0 1.5px var(--tone-ink, var(--text));
  text-transform: lowercase;
}
.map-day-walk {
  display: flex; align-items: center; gap: var(--s-2);
  margin: var(--s-2) var(--s-1) 0;
  font: var(--fs-caption)/var(--lh-caption) var(--font-sans); font-variant-numeric: tabular-nums;
  color: var(--text-2);
}
.map-day-walk .icon { flex: none; color: var(--text-3); }
@media (min-width: 1024px) { .map-day-members.chip-row { flex-wrap: nowrap; overflow-x: auto; padding-inline: var(--s-3) 0; } .map-day-members::before { left: 0; } }

/* ── Chapter scope: neighbourhood bubbles below the detail zoom, their pins from there (cross-fade) ── */
.map-frame .leaflet-marker-icon.map-tier-pin,
.map-frame .leaflet-marker-icon.map-tier-area { transition: opacity var(--dur-2, 200ms) ease; }
.map-canvas[data-detail='areas'] .map-tier-pin,
.map-canvas[data-detail='pins'] .map-tier-area { opacity: 0; pointer-events: none; }
.map-canvas[data-detail='areas'] .map-tier-pin *,
.map-canvas[data-detail='pins'] .map-tier-area * { pointer-events: none; }
@media (prefers-reduced-motion: reduce) {
  .map-frame .leaflet-marker-icon.map-tier-pin, .map-frame .leaflet-marker-icon.map-tier-area { transition: none; }
}

/* ── Phones: every line above the map is a line of map lost ── */
@media (max-width: 599px) {
  /* the page title stays for screen readers; the List | Map switch already says where we are */
  .view-places-map .map-head {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
    overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }
  .view-places-map .places-controls { margin-top: var(--s-2); gap: var(--s-2); margin-bottom: var(--s-2); }
  /* the day bar is one row: stamp, title, ‹ › (the stamp carries the date, the strip the stops) */
  .map-day-row { padding: 0 var(--s-1); border-radius: var(--r-2); }
  .map-day-what { gap: var(--s-2); padding: 2px var(--s-1); }
  .map-day-what .stamp { --stamp-size: 32px; }
  .map-day-what .stamp .stamp-num { font-size: 15px; }
  .map-day-what .stamp .stamp-wd { font-size: 8px; }
  .map-day-eyebrow, .map-day-sub {
    position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }
  .map-day-text { position: relative; }
  .map-day-stops { margin-top: var(--s-1); }
  .map-day-stop { min-height: 32px; max-width: 200px; }
  .map-day-walk, .map-day-missing { margin-top: var(--s-1); }
  .map-day-missing .clamp-2 { -webkit-line-clamp: 1; line-clamp: 1; }
}

/* Leaflet lifts every svg inside the map pane to z-index 200 (meant for its own overlay): inside a marker that
   would paint an ink frame over the text it frames. Marks stack in their own DOM order. */
.map-frame .leaflet-marker-pane svg { z-index: auto; }
