/* =============================================================================
   Map: MapLibre overrides, markers, labels, trails
   ========================================================================== */

#map {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: var(--bg);
}

.maplibregl-map {
  font-family: var(--font);
  background: var(--bg);
}
.maplibregl-canvas { outline: none; }
.maplibregl-canvas-container.maplibregl-interactive { cursor: default; }

/* Attribution is required by every provider — keep it legible but out of the
   thumb zone and clear of the home indicator. */
.maplibregl-ctrl-bottom-right {
  bottom: var(--safe-b);
  right: var(--safe-r);
  z-index: 1;
}
.maplibregl-ctrl-attrib {
  background: var(--surface-glass) !important;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--text-faint) !important;
  font-size: 10px !important;
  border-radius: var(--r-sm) 0 0 0;
  max-width: 70vw;
}
.maplibregl-ctrl-attrib a { color: var(--text-dim) !important; }
.maplibregl-ctrl-attrib-button {
  background-color: var(--surface-3) !important;
  border-radius: 50%;
}
.maplibregl-ctrl-attrib.maplibregl-compact { min-height: 24px; }

/* MapLibre's own popup chrome, restyled to match the app. */
.maplibregl-popup.stop-tip .maplibregl-popup-content {
  background: var(--surface-glass);
  backdrop-filter: blur(10px) saturate(140%);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-2);
  padding: 6px 10px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.45;
  text-align: center;
}
.maplibregl-popup.stop-tip .maplibregl-popup-tip { display: none; }

/* ------------------------------- Markers --------------------------------- */
/* One element per device. markers.js mutates its classes and CSS variables and
   never recreates the icon, which is what keeps presence colour and heading in
   sync — the previous build had two competing code paths for this. */

/* MapLibre does not size a custom marker element, so the box is set here from
   --mk-size (markers.js writes it per element). Every layer inside is placed
   with absolute insets: percentage sizing inside nested grids is a cyclic
   constraint the browser may resolve as an ellipse, insets never are — so the
   disc is round at any marker size. */
/* MapLibre writes `transform: translate(...)` onto this exact element on every
   frame of a pan. It must therefore carry no transform and no transform
   transition of its own — a transition here makes every marker ease towards its
   new position and visibly float behind the map, and a transform here replaces
   MapLibre's positioning outright. Scaling and animation live on the children. */
.mk {
  /* Must match .maplibregl-marker's own `position: absolute`. This rule has the
     same specificity and map.css loads later, so `relative` here would win and
     drop the marker back into normal flow — which is what made the icons drift
     around while panning. It also gives the absolutely-placed children below
     their containing block. */
  position: absolute;
  width: var(--mk-size, 16px);
  height: var(--mk-size, 16px);
  color: var(--accent);          /* presence colour flows from here */
  transition: color var(--dur) var(--ease);
}
.mk--ok   { color: var(--ok); }
.mk--warn { color: var(--warn); }
.mk--bad  { color: var(--bad); }

/* Body: a disc when stopped, a heading chevron when moving. */
.mk-body {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: currentColor;
  border: 2px solid var(--surface);
  box-shadow: var(--shadow-1);
  transition: transform var(--dur) var(--ease);
}
/* Square by construction: equal insets on a square parent. */
.mk-arrow {
  position: absolute;
  inset: 24%;
  opacity: 0;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
  fill: var(--surface);
  stroke: none;
  overflow: visible;
}
.mk--moving .mk-arrow { opacity: 1; }

/* Ignition on: a ring around the marker. */
.mk-ring {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  opacity: 0;
  transition: opacity var(--dur) var(--ease);
}
.mk--ignition .mk-ring { opacity: 0.5; }

/* Live heartbeat, only while the device is genuinely online. */
.mk-pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: currentColor;
  opacity: 0;
}
.mk--ok .mk-pulse { animation: mk-pulse 2.6s var(--ease) infinite; }
@keyframes mk-pulse {
  0%   { opacity: 0.35; transform: scale(1); }
  70%  { opacity: 0;    transform: scale(2.1); }
  100% { opacity: 0;    transform: scale(2.1); }
}

/* Selected: halo + lift. */
/* Scale the body, never .mk — see the note above. */
.mk--selected .mk-body { transform: scale(1.15); }
.mk--selected .mk-body { border-color: var(--accent); border-width: 2.5px; }
.mk--selected .mk-halo {
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  opacity: 0.5;
}

/* Speed badge, only above ~3 km/h. */
.mk-speed {
  position: absolute;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 1px 6px;
  border-radius: var(--r-full);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 10px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  box-shadow: var(--shadow-1);
  pointer-events: none;
}

/* --------------------------------- Labels -------------------------------- */
/* Part of the marker element, so a label moves with its marker and can never be
   orphaned. Opt-in: showing every one at once is what turned four cars parked
   together into unreadable overlapping text. */

.mk-name {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: 2px 7px;
  border-radius: var(--r-sm);
  background: var(--surface-glass);
  backdrop-filter: blur(10px) saturate(140%);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-1);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  pointer-events: none;
}
.mk-name.is-selected {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}
/* The speed badge and the name would otherwise sit on top of each other. */
.mk--moving .mk-name { bottom: calc(100% + 20px); }

/* Markers are never displaced to avoid overlap — a marker's position on screen
   is always the vehicle's real position. Overlapping units separate by zooming
   in, not by the map moving them. */

/* --------------------------------- Trails -------------------------------- */
/* The path itself is drawn by MapLibre from GeoJSON, so its colour and width are
   style expressions in trails.js, not CSS. Only the DOM pins are styled here. */

.trail-start {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--surface);
  border: 3px solid var(--text-dim);
  box-shadow: var(--shadow-1);
}
/* Where the vehicle was parked. This element is handed straight to a MapLibre
   Marker too, so the tap feedback is a ring rather than a transform — scaling it
   would fight the positioning transform and make the dot drift while panning. */
.trail-stop {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--warn);
  border: 2px solid var(--surface);
  box-shadow: var(--shadow-1);
  cursor: pointer;
  transition: box-shadow var(--dur-fast) var(--ease);
}
.trail-stop:hover, .trail-stop:active {
  box-shadow: 0 0 0 5px var(--warn-soft), var(--shadow-1);
}

/* Speed legend shown under the trail toggle. */
.speed-legend {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: 10px;
  color: var(--text-faint);
  padding: var(--sp-2) 0 0;
}
.speed-legend-bar {
  flex: 1 1 auto;
  height: 6px;
  border-radius: var(--r-full);
  background: linear-gradient(90deg,
    var(--speed-0), var(--speed-1), var(--speed-2), var(--speed-3), var(--speed-4));
}

/* ------------------------------ User location ---------------------------- */

.me-dot {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 1px var(--accent), var(--shadow-2);
}
/* The accuracy halo is a GeoJSON fill layer, styled in map.js. */
