/* Polaris — map styles. */

/* ---------- map ---------- */
.map-container {
  position: relative;
  isolation: isolate;
  flex: 1;
  min-width: 0;
  min-height: 0;
  height: 100%;
}

#map { position: absolute; inset: 0; height: 100%; background: var(--bg); }

/* Dark-mode a light tile provider (see the basemap section of api.py). Applied
   to the tile pane only: overlay panes sit above it and keep their own colour —
   inverting the whole map would turn every truck colour into its opposite.
   hue-rotate puts the inverted blues back where they started (a plain invert
   turns water orange), and the low saturation pulls OSM's green landcover back
   toward the near-monochrome ground the route colours need to read against. */
#map.basemap-darken .leaflet-tile-pane {
  filter: invert(1) hue-rotate(180deg) brightness(0.82) contrast(1.05) saturate(0.4);
}

.leaflet-container { font: inherit; }

#map .leaflet-control-attribution {
  padding: 3px 8px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-bottom: 0;
  border-right: 0;
  border-radius: var(--r-sm) 0 0 0;
  color: var(--text-muted);
  font-size: 10px;
}

#map .leaflet-control-attribution a { display: inline-flex; align-items: center; color: var(--accent-text); }
#map .leaflet-control-attribution a:hover { color: var(--text); }

#map .leaflet-control-zoom {
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
}

#map .leaflet-control-zoom a {
  width: 38px;
  height: 38px;
  line-height: 38px;
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
  border-radius: 0;
  font-size: 22px;
}

#map .leaflet-control-zoom a:first-child { border-radius: var(--r-md) var(--r-md) 0 0; }
#map .leaflet-control-zoom a:last-child { border-radius: 0 0 var(--r-md) var(--r-md); }
#map .leaflet-control-zoom a:hover { background: var(--surface-hover); color: var(--accent-text); }
#map .leaflet-control-zoom a:active { background: var(--surface-3); }
#map .leaflet-control-zoom a.leaflet-disabled { background: var(--surface-2); color: var(--text-faint); }

.depot-icon { display: grid; justify-items: center; background: none; border: 0; }

.depot-pin {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 2px solid var(--accent);
  border-radius: 50% 50% 50% 4px;
  background: var(--surface-2);
  transform: rotate(-45deg);
  box-shadow: 0 0 0 2px var(--bg), var(--shadow-1), 0 0 16px var(--accent-glow);
}

.depot-pin svg {
  width: 22px;
  height: 22px;
  transform: rotate(45deg);
  fill: var(--accent-text);
  filter: drop-shadow(0 0 5px var(--accent-glow));
}

.stop-icon {
  display: grid;
  place-items: center;
  background: var(--accent-text);
  border: 3px solid var(--surface-2);
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--border-strong), 0 3px 10px rgba(0, 0, 0, 0.65);
  color: var(--bg);
  font: 700 12px var(--font-ui);
  font-variant-numeric: tabular-nums;
}

.route-casing { stroke: var(--bg); }

#map .map-tooltip {
  max-width: 240px;
  white-space: normal;
  overflow-wrap: anywhere;
  padding: 7px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-2);
  color: var(--text);
  font: 12px/1.4 var(--font-ui);
}

#map .map-tooltip.leaflet-tooltip-top::before { border-top-color: var(--border-strong); }

#map-hint, #map-legend {
  position: absolute;
  z-index: 1100;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-2);
}

/* On desktop the overlays retain their independent map anchors. */
.map-overlays { display: contents; }

#map-hint {
  left: var(--s-4);
  bottom: 56px;
  max-width: calc(100% - 32px);
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--accent-text);
  font-size: 12px;
  pointer-events: none;
}

#map-legend {
  top: var(--s-4);
  right: var(--s-4);
  width: 200px;
  max-width: calc(100% - 76px);
  padding: var(--s-2);
  border-radius: var(--r-md);
}

#map-legend-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  padding: 4px 6px 8px;
  color: var(--text);
  font-size: 10px;
  letter-spacing: 0.08em;
}

#map-legend-title span { color: var(--text-muted); font-size: 10px; letter-spacing: 0; text-transform: none; }
#map-legend-items { max-height: min(36vh, 260px); overflow-y: auto; overscroll-behavior: contain; padding: 4px; }

.map-legend-route {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  width: 100%;
  min-height: 32px;
  padding: 6px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}

.map-legend-route:hover { background: var(--surface-hover); }
.map-legend-route.soloed { background: var(--surface-3); border-color: var(--truck-color); }
.map-legend-route.dimmed { color: var(--text-muted); }
.map-legend-route.dimmed .map-legend-dot { opacity: 0.3; }
.map-legend-dot { width: 9px; height: 9px; flex-shrink: 0; border-radius: 50%; background: var(--truck-color); }
.map-legend-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
