/* ══════════════════════════════════════════════════════════
   MAP
══════════════════════════════════════════════════════════ */
#map {
  position: fixed;
  inset: 0;
}

.leaflet-tile-pane { filter: grayscale(1) contrast(1.08); }

.leaflet-control-zoom {
  border: 1px solid var(--line) !important;
  border-radius: var(--r-panel) !important;
  overflow: hidden;
  box-shadow: var(--shadow-sm) !important;
}

.leaflet-control-zoom a {
  font-family: var(--font) !important;
  color: var(--ink) !important;
  background: var(--surface) !important;
  width: 32px !important;
  height: 32px !important;
  line-height: 32px !important;
  border-bottom: 1px solid var(--line) !important;
}

.leaflet-control-zoom a:last-child { border-bottom: none !important; }
.leaflet-control-zoom a:hover { background: var(--wash) !important; }
.leaflet-control-attribution { font-family: inherit; font-size: 10px; }

/* Map markers — rings (zoomed in) and dots (zoomed out) */

/* Fade in markers after zoom mode swap */
@keyframes markerFadeIn {
  from { opacity: 0; transform: scale(0.7); }
  to   { opacity: 1; transform: scale(1); }
}

.bw-crossfade .map-ring,
.bw-crossfade .map-dot {
  animation: markerFadeIn 0.28s ease-out both;
}

/* During active zoom, hide markers to prevent scaling artifacts */
.bw-zooming .bw-marker-ring,
.bw-zooming .bw-marker-dot {
  opacity: 0;
  transition: opacity 0.1s ease-out;
}

.bw-marker-ring,
.bw-marker-dot {
  background: none !important;
  border: none !important;
}

.bw-marker-ring {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.map-ring,
.map-dot {
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
  box-sizing: border-box;
  opacity: 1;
  transition: opacity 0.15s ease, transform 0.25s cubic-bezier(.34,1.56,.64,1), box-shadow 0.25s ease;
}

.map-ring {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2.5px solid var(--ring, #18181b);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.14);
}

.map-ring.is-selected {
  transform: scale(1.22);
  box-shadow:
    0 6px 20px rgba(0, 0, 0, 0.28),
    0 2px 6px rgba(0, 0, 0, 0.12),
    0 0 0 4px rgba(0, 0, 0, 0.05);
  animation: ringHover 1.8s ease-in-out infinite;
}

@keyframes ringHover {
  0%, 100% { transform: scale(1.22) translateY(0); }
  50% { transform: scale(1.26) translateY(-2px); }
}

.map-ring-count {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--ring, #18181b);
  line-height: 1;
  pointer-events: none;
  letter-spacing: -.3px;
}

.bw-marker-dot .map-dot {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.map-dot.is-selected {
  transform: scale(1.5);
  box-shadow:
    0 4px 12px rgba(0, 0, 0, 0.3),
    0 0 0 3px rgba(0, 0, 0, 0.1);
  animation: dotHover 1.8s ease-in-out infinite;
}

@keyframes dotHover {
  0%, 100% { transform: scale(1.5) translateY(0); }
  50% { transform: scale(1.6) translateY(-1px); }
}

.map-marker-bolt {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 14px;
  height: 14px;
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.map-marker-bolt svg {
  width: 7px;
  height: 7px;
}

@media (hover: hover) {
  .map-ring:hover { transform: scale(1.06); }
  .bw-marker-dot:hover .map-dot { transform: scale(1.15); }
}

/* Clusters — override MarkerCluster.Default.css */
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
  background: none !important;
  box-shadow: none !important;
  border: none !important;
}

.map-cluster {
  width: 42px;
  height: 42px;
  background: var(--ink) !important;
  border: 2.5px solid white !important;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  color: white;
  box-shadow: 0 2px 8px rgba(0,0,0,.2) !important;
}

.bw-marker-ring,
.bw-marker-dot {
  background: none !important;
  border: none !important;
  box-shadow: none !important;
}

/* Route mode — dim all station markers */
#map.route-active .leaflet-marker-pane {
  opacity: 0.12;
  transition: opacity 0.3s ease;
}

#map.route-active .leaflet-overlay-pane .route-overlay-layer {
  opacity: 1;
}

/* Bottom dock */
.map-dock {
  position: fixed;
  bottom: max(20px, env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1100;
  max-width: calc(100vw - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
  pointer-events: auto;
}

.dock-inner {
  display: flex;
  align-items: center;
  gap: var(--gap-md);
  padding: 8px 10px;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur)) saturate(1.4);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.4);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  box-shadow: var(--glass-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  animation: fadeUp .45s var(--ease) .12s both;
  transition: box-shadow .2s var(--ease);
}

@media (hover: hover) {
  .dock-inner:hover {
    box-shadow: var(--glass-shadow), 0 6px 20px rgba(0, 0, 0, 0.06), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  }
}

.dock-stats {
  display: flex;
  align-items: center;
  gap: var(--gap-md);
  flex-shrink: 0;
}

.live-pill {
  display: flex;
  align-items: center;
  gap: var(--gap-xs);
  height: 36px;
  padding: 0 12px 0 10px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 999px;
  font-size: var(--t-xs);
  font-weight: 600;
  color: var(--ink-2);
  letter-spacing: .02em;
  flex-shrink: 0;
  transition: background .15s var(--ease), border-color .15s var(--ease);
}

.net-stat strong.num {
  display: inline-block;
  transition: transform .2s var(--ease), color .2s var(--ease);
}

.net-stat strong.num.is-updating {
  animation: softPulse .45s ease;
}

@media (hover: hover) {
  .net-stat:hover strong.num { transform: scale(1.05); }
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--avail);
  animation: blink 2.5s ease-in-out infinite;
}

.net-stats {
  display: flex;
  align-items: center;
  gap: var(--gap-md);
  flex-shrink: 0;
}

.net-stat {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: var(--t-xs);
  color: var(--ink-2);
  white-space: nowrap;
}

.net-stat strong {
  font-weight: 500;
  color: var(--ink);
}

.net-stat strong.num { font-size: var(--t-sm); }

.dock-sep {
  width: 1px;
  height: 28px;
  background: rgba(0, 0, 0, 0.12);
  flex-shrink: 0;
}

.dock-route {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  min-width: 0;
}

.route-fields {
  display: flex;
  align-items: center;
  gap: var(--gap-xs);
}

.route-field {
  position: relative;
}

.route-dot {
  position: absolute;
  left: 12px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  z-index: 1;
}

.route-dot.a {
  background: var(--surface);
  border: 2px solid var(--ink);
  box-sizing: border-box;
}

.route-dot.b { background: var(--ink); }

.route-field input {
  position: relative;
  z-index: 2;
  width: 148px;
  height: 36px;
  padding: 0 30px 0 28px;
  border: 1.5px solid rgba(0, 0, 0, 0.12);
  border-radius: 999px;
  font-family: inherit;
  font-size: var(--t-sm);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.7);
  outline: none;
  pointer-events: auto;
  transition: border-color .14s var(--ease), background .14s var(--ease);
}

.route-field input:focus {
  border-color: rgba(0, 0, 0, 0.25);
  background: rgba(255, 255, 255, 0.85);
}

.route-field input::placeholder { color: var(--ink-3); }

.route-actions {
  display: flex;
  align-items: center;
  gap: var(--gap-xs);
  flex-shrink: 0;
}

.plan-btn {
  height: 36px;
  padding: 0 16px;
  background: var(--ink);
  color: #fff;
  border: none;
  border-radius: 999px;
  font-family: inherit;
  font-size: var(--t-sm);
  font-weight: 600;
  letter-spacing: -.1px;
  cursor: pointer;
  white-space: nowrap;
  transition: transform .14s var(--ease), box-shadow .14s var(--ease), opacity .14s var(--ease);
}

@media (hover: hover) {
  .plan-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
  }
}

.plan-btn:active:not(:disabled) { transform: translateY(0) scale(0.97); }
.plan-btn:disabled { opacity: .4; cursor: not-allowed; }

.clear-btn {
  width: 36px;
  height: 36px;
  background: rgba(255, 255, 255, 0.7);
  border: 1.5px solid rgba(0, 0, 0, 0.12);
  border-radius: 50%;
  color: var(--ink-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all .14s var(--ease);
}

.clear-btn:hover { background: rgba(0, 0, 0, 0.08); color: var(--ink); }
.clear-btn:active { transform: scale(0.94); }

.route-swap-btn {
  width: 24px;
  height: 24px;
  border: none;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-3);
  cursor: pointer;
  flex-shrink: 0;
  transition: all .14s var(--ease);
}

.route-swap-btn:hover { color: var(--ink); background: rgba(0, 0, 0, 0.06); }
.route-swap-btn:active { transform: scale(0.92); }
.route-swap-btn.is-spinning svg { animation: swapTurn .35s var(--ease); }

.route-loc-btn {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  z-index: 3;
  width: 24px;
  height: 24px;
  border: none;
  background: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-3);
  cursor: pointer;
  transition: all .14s var(--ease);
}

.route-loc-btn:hover { color: var(--ink); background: rgba(0, 0, 0, 0.06); }
.route-loc-btn:active { transform: translateY(-50%) scale(0.9); }
.route-loc-btn.is-locating { animation: softPulse 1s ease infinite; }

.route-share-btn {
  width: 36px;
  height: 36px;
  background: rgba(255, 255, 255, 0.7);
  border: 1.5px solid rgba(0, 0, 0, 0.12);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-2);
  cursor: pointer;
  flex-shrink: 0;
  transition: all .14s var(--ease);
}

.route-share-btn:hover { background: rgba(0, 0, 0, 0.06); color: var(--ink); }
.route-share-btn:active { transform: scale(0.94); }
.route-share-btn.is-copied { color: var(--avail); border-color: rgba(22, 163, 74, 0.3); }

.map-dock .route-result {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  width: max(100%, 320px);
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows .22s ease;
  overflow: hidden;
  pointer-events: none;
}

.map-dock .route-result.open {
  grid-template-rows: 1fr;
  pointer-events: auto;
}
.route-result-inner { overflow: hidden; }

.route-result-body {
  padding: var(--gap-lg);
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur)) saturate(1.4);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.4);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-panel);
  box-shadow: var(--glass-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.map-dock .route-result.open .route-result-body {
  animation: fadeUp .28s var(--ease) both;
}

.map-dock .route-result.open .r-seg {
  animation: fadeUp .3s var(--ease) both;
}

.map-dock .route-result.open .r-seg:nth-child(1) { animation-delay: .04s; }
.map-dock .route-result.open .r-seg:nth-child(3) { animation-delay: .1s; }
.map-dock .route-result.open .r-seg:nth-child(5) { animation-delay: .16s; }

.map-dock .route-result.open .r-station-row {
  animation: fadeUp .28s var(--ease) both;
}

.map-dock .route-result.open .r-station-row:nth-child(1) { animation-delay: .18s; }
.map-dock .route-result.open .r-station-row:nth-child(2) { animation-delay: .24s; }

.r-steps {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  font-size: var(--t-sm);
  flex-wrap: wrap;
}

.r-seg {
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
  color: var(--ink);
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  transition: transform .15s var(--ease), background .15s var(--ease);
}

@media (hover: hover) {
  .r-seg:hover { transform: translateY(-1px); background: rgba(255, 255, 255, 0.9); }
}

.r-seg .ico { color: var(--ink-2); display: flex; align-items: center; }
.r-time { color: var(--ink); font-weight: 600; }
.r-dist { color: var(--ink-3); font-size: 11px; font-weight: 400; }
.r-arrow { color: var(--ink-3); display: flex; align-items: center; }

.r-divider {
  margin-top: var(--gap-md);
  border: none;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.r-stations {
  margin-top: var(--gap-md);
  font-size: var(--t-xs);
  color: var(--ink-3);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.r-station-row {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
}

.r-label {
  color: var(--ink-3);
  font-weight: 500;
  min-width: 52px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.r-stations strong { color: var(--ink); font-weight: 500; }

.r-avail {
  margin-left: auto;
  color: var(--avail);
  font-weight: 600;
  font-size: 11px;
}

@media (max-width: 900px) {
  .dock-inner {
    flex-wrap: wrap;
    justify-content: center;
    border-radius: var(--r-panel);
    padding: 10px 12px;
    max-width: calc(100vw - 24px);
  }

  .dock-sep { display: none; }

  .dock-stats,
  .dock-route {
    flex-wrap: wrap;
    justify-content: center;
  }

  .route-field input { width: 120px; }
}

@media (max-width: 600px) {
  .leaflet-bottom.leaflet-right {
    bottom: auto !important;
    top: max(12px, env(safe-area-inset-top, 0px)) !important;
    right: max(12px, env(safe-area-inset-right, 0px)) !important;
  }

  .leaflet-control-zoom a {
    width: 40px !important;
    height: 40px !important;
    line-height: 40px !important;
  }

  .map-toast {
    top: auto;
    bottom: calc(168px + env(safe-area-inset-bottom, 0px));
    left: max(16px, env(safe-area-inset-left, 0px));
    right: max(16px, env(safe-area-inset-right, 0px));
    transform: translateY(6px);
    max-width: none;
    white-space: normal;
    text-align: center;
    justify-content: center;
    z-index: 1200;
  }

  .map-toast.on {
    transform: translateY(0);
  }

  .route-field input,
  .plan-btn,
  .clear-btn,
  .route-share-btn,
  .live-pill {
    min-height: 44px;
    height: 44px;
    font-size: 16px;
  }

  .p-item {
    min-height: 44px;
    padding: 12px 14px;
  }
}

@media (max-width: 480px) {
  .map-dock {
    left: max(12px, env(safe-area-inset-left, 0px));
    right: max(12px, env(safe-area-inset-right, 0px));
    transform: none;
    max-width: none;
  }

  .dock-inner { width: 100%; }

  .route-fields { width: 100%; flex-wrap: wrap; justify-content: center; }
  .route-field { flex: 1; min-width: 0; }
  .route-field input { width: 100%; }
  .route-swap-btn { width: 28px; height: 28px; }

  .route-actions { width: 100%; }
  .plan-btn { flex: 1; }
  .route-share-btn { width: 44px; height: 44px; }

  .map-dock .route-result {
    left: 0;
    right: 0;
    transform: none;
    width: auto;
  }

  .net-stats { gap: var(--gap-sm); }
}

/* Toast */
.map-toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(-6px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 7px 14px;
  font-size: var(--t-sm);
  font-weight: 500;
  color: var(--ink-2);
  box-shadow: var(--shadow-sm);
  z-index: 850;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
}

.map-toast.on {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  animation: toastIn .22s var(--ease);
}

.mini-spin {
  width: 12px; height: 12px;
  border: 2px solid var(--line);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin .65s linear infinite;
}

/* Portal */
.portal {
  position: fixed;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur)) saturate(1.4);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.4);
  border: 1px solid var(--glass-border);
  border-radius: var(--r);
  box-shadow: var(--glass-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  overflow: hidden auto;
  z-index: 9999;
  display: block;
  max-height: 220px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(4px) scale(0.98);
  transition: opacity .16s var(--ease), transform .16s var(--ease), visibility .16s;
}

.portal.on {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: none;
}

.p-item {
  padding: 9px 14px;
  font-size: var(--t-base);
  cursor: pointer;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  display: flex;
  align-items: center;
  gap: 9px;
  transition: background .1s var(--ease), transform .1s var(--ease);
  overflow: hidden;
}

.portal.on .p-item {
  animation: fadeUp .2s var(--ease) both;
}

.portal.on .p-item:nth-child(1) { animation-delay: .02s; }
.portal.on .p-item:nth-child(2) { animation-delay: .05s; }
.portal.on .p-item:nth-child(3) { animation-delay: .08s; }
.portal.on .p-item:nth-child(4) { animation-delay: .11s; }
.portal.on .p-item:nth-child(5) { animation-delay: .14s; }

.p-item:last-child { border-bottom: none; }

@media (hover: hover) {
  .p-item:hover {
    background: rgba(255, 255, 255, 0.55);
    transform: translateX(2px);
  }
}

.p-item:active { transform: scale(0.99); }

.p-dot  { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.p-name { font-weight: 500; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.p-meta { font-size: var(--t-xs); color: var(--ink-3); white-space: nowrap; display:flex;align-items:center;gap:5px; }

/* Attribution */
.attribution {
  position: fixed;
  bottom: 6px;
  left: 6px;
  font-size: 11px;
  color: var(--ink-3);
  z-index: 800;
  pointer-events: auto;
}

.attribution a {
  color: var(--ink-2);
  text-decoration: none;
  font-weight: 500;
}

.attribution a:hover { text-decoration: underline; }

.ai-badge-wrapper {
  position: fixed;
  bottom: 110px;
  right: 0;
  z-index: 9000;
  width: 280px;
  overflow: hidden;
}

.ai-badge {
  display: flex;
  align-items: center;
  width: 280px;
  padding: 12px 20px;
  text-decoration: none;
  background: #fff;
  color: #1a1a1a;
  border: none;
  border-radius: 6px 0 0 6px;
  font-family: "ivypresto-headline", Georgia, "Times New Roman", serif;
  font-size: 14px;
  font-weight: 400;
  letter-spacing: 0.5px;
  line-height: 1.2;
  cursor: pointer;
  box-sizing: border-box;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  transform: translateX(226px);
  transition: transform 0.3s ease;
}

.ai-badge-wrapper:hover .ai-badge {
  transform: translateX(0);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.ai-badge-content {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
  font-family: "ivypresto-headline", Georgia, "Times New Roman", serif;
}

.ai-badge-prefix,
.ai-badge-name {
  font-family: "ivypresto-headline", Georgia, "Times New Roman", serif;
}

.ai-badge-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: block;
  margin-right: 1rem;
}

.ai-badge-name {
  color: #6a6a6a;
}
