/* ==========================================================================
   Map controls, stations and walk lines (BUY-025)
   The style and station buttons sit at the top left below the floating
   header, the legend at the bottom left above the zoom buttons; both are
   Leaflet controls, so Leaflet stacks them with its own. Colours come from
   the theme variables, so the three themes need nothing of their own.
   ========================================================================== */

#map .leaflet-top {
  top: var(--header-clearance, 68px);
}

.map-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 0 12px;
  max-width: calc(100vw - 24px);
}

.map-tool-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(8px);
}

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

.map-tool-group.is-busy {
  opacity: 0.7;
  pointer-events: none;
}

.map-tool-btn {
  min-height: 32px;
  padding: 5px 12px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font: 600 13px/1.2 inherit;
  font-family: inherit;
  cursor: pointer;
}

.map-tool-btn:hover {
  color: var(--text-main);
}

.map-tool-btn.active {
  background: var(--panel-pressed);
  color: var(--text-strong);
}

.map-tool-btn--sub {
  font-size: 12px;
}

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

.map-tool-btn:focus-visible,
.map-legend-summary:focus-visible,
.map-legend-mode:focus-visible,
.map-legend-close:focus-visible {
  outline: 2px solid var(--info);
  outline-offset: 2px;
}

/* --- Legend ---------------------------------------------------------- */

.map-legend {
  margin-bottom: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(8px);
  color: var(--text-main);
}

.map-legend.is-open {
  width: 260px;
  max-width: calc(100vw - 24px);
  padding: 8px 10px 10px;
}

.map-legend-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 6px 12px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-main);
  font: 600 12px/1.2 inherit;
  font-family: inherit;
  cursor: pointer;
}

.map-legend-summary[hidden],
.map-legend-panel[hidden] {
  display: none;
}

.map-legend-swatches {
  display: inline-flex;
  gap: 3px;
}

.map-legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid rgba(var(--overlay-rgb), 0.35);
}

.map-legend-caret {
  color: var(--text-muted);
}

.map-legend-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 8px;
}

.map-legend-modes {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  background: var(--bg-inset);
  border-radius: var(--radius-sm);
}

.map-legend-mode {
  min-height: 28px;
  padding: 4px 8px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  font: 600 11px/1.2 inherit;
  font-family: inherit;
  cursor: pointer;
}

.map-legend-mode.active {
  background: var(--segment-active);
  color: var(--text-strong);
}

.map-legend-mode:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.map-legend-close {
  min-width: 28px;
  min-height: 28px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.map-legend-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* --- Stations ------------------------------------------------------------ */

.station-icon {
  background: transparent;
  border: none;
}

.station-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
  font: 800 11px/1 Arial, sans-serif;
  cursor: pointer;
}

.station-badge--rail {
  background: #1d4ed8;
  color: #ffffff;
}

/* Zoomed out, a station is a dot so the pins stay readable. */
.is-far .station-badge {
  width: 9px;
  height: 9px;
  margin: 5px;
  border-width: 1.5px;
  font-size: 0;
}

.station-badge--tram {
  background: #facc15;
  color: #0f172a;
}

/* The app's popups bring their own padding (style.css zeroes Leaflet's). */
.station-popup {
  min-width: 200px;
  padding: 12px 14px;
}

.station-name {
  padding-right: 20px; /* clear of the close button */
  font-size: 14px;
  font-weight: 700;
}

.station-kind {
  display: inline-block;
  margin: 4px 0 8px;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.station-kind--rail {
  background: #dbeafe;
  color: #1e3a8a;
}

.station-kind--tram {
  background: #fef08a;
  color: #713f12;
}

.station-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.btn-station-near,
.btn-station-anchor {
  width: 100%;
  min-height: 34px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font: 600 12px/1.2 inherit;
  font-family: inherit;
  cursor: pointer;
}

.btn-station-near {
  border: none;
  background: var(--accent);
  color: #ffffff;
}

.btn-station-anchor {
  border: 1px solid var(--border-color);
  background: var(--panel-raised);
  color: var(--text-main);
}

.station-none,
.station-note {
  font-size: 11px;
  color: var(--text-muted);
}

.station-note {
  margin-top: 8px;
}

/* --- Walk lines (the selected home to its nearest stops) ----------------- */

.walk-label-icon {
  background: transparent;
  border: none;
}

.walk-label {
  position: absolute;
  transform: translate(-50%, -50%);
  padding: 2px 6px;
  border-radius: 4px;
  font: 700 11px/1.3 inherit;
  font-family: inherit;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

.walk-label--up {
  transform: translate(-50%, calc(-50% - 14px));
}

.walk-label--down {
  transform: translate(-50%, calc(-50% + 14px));
}

.walk-label--rail,
.walk-label--interchange {
  background: #1d4ed8;
  color: #ffffff;
  border: 1px solid #ffffff;
}

.walk-label--tram {
  background: #facc15;
  color: #0f172a;
  border: 1px solid #ca8a04;
}

/* A bus label sits on the stop, so it starts just past it. */
.walk-label--bus {
  transform: translate(8px, -50%);
  background: #e0f2fe;
  color: #0c4a6e;
  border: 1px solid #0284c7;
}

/* --- Distance anchor ----------------------------------------------------- */

.anchor-pin {
  background: transparent;
  border: none;
  cursor: grab;
}

.anchor-pin:active {
  cursor: grabbing;
}

.anchor-pin-dot {
  display: block;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #f59e0b;
  border: 3px solid #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}

.anchor-pin-hint {
  font-size: 12px;
  color: var(--text-muted);
}

.btn-locate-anchor {
  margin-top: 6px;
  padding: 5px 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #ffffff;
  font: 600 12px/1.2 inherit;
  font-family: inherit;
  cursor: pointer;
}

:root[data-view="list"] .map-tools,
:root[data-view="list"] .map-legend {
  display: none;
}

/* --- Phone ------------------------------------------------------------ */

@media (max-width: 600px) {
  .map-tools {
    margin: 6px 0 0 8px;
    max-width: calc(100vw - 16px);
  }

  .map-tool-btn {
    min-height: 36px;
    padding: 6px 10px;
    font-size: 12px;
  }

  .map-legend.is-open {
    max-width: calc(100vw - 16px);
  }

  .map-legend-summary {
    min-height: 44px;
  }

  .map-legend-mode,
  .map-legend-close {
    min-height: 36px;
  }
}
