/* #/map — owned by views/map.js. The basemap is dark in BOTH themes (BASEMAP_FLAVOR), so everything drawn ON
   the map (pins, rings, labels, count bubbles) uses marker colours from mapkit.css (--mk per .s-<state>) plus
   the dark outlines / scrims DESIGN.md allows on the map; panels (list, card, legend) are themed surfaces. */

.mapview { position: relative; height: 100%; display: grid; grid-template-columns: 320px minmax(0, 1fr); }
.mv-map { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
.mv-full { position: absolute; inset: 0; }
.mv-full .mapbox { height: 100%; }

/* ---- side list --------------------------------------------------------------------------------------------- */
.mv-side { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-right: 1px solid var(--line); }
.mv-head { display: flex; flex-direction: column; gap: var(--sp-3); padding: var(--sp-4) var(--sp-4) var(--sp-3); border-bottom: 1px solid var(--line); }
.mv-titlerow { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-2); }
.mv-title { font-size: var(--fs-xl); }
.mv-count { font-size: var(--fs-sm); }
.mv-search input { width: 100%; }
.mv-filter { margin: 0; }
.mv-grab { display: none; }
.mv-list { flex: 1; min-height: 0; overflow: auto; list-style: none; margin: 0; padding: var(--sp-2); }
.mv-item {
  display: grid; grid-template-columns: 16px minmax(0, 1fr); column-gap: 10px; row-gap: 1px; align-items: center;
  width: 100%; padding: var(--sp-2) 10px; border: 0; border-radius: var(--r-sm); background: none; color: var(--ink);
  text-align: left; font: inherit; cursor: pointer; transition: background-color var(--dur-1) var(--ease-out);
}
.mv-item .mv-shape { grid-row: span 2; align-self: start; margin-top: 2px; }
.mv-item:hover, .mv-item.hot { background: var(--surface-2); }
.mv-item.sel { background: var(--surface-3); box-shadow: inset 0 0 0 1px var(--line-strong); }
.mv-iname { font-weight: var(--fw-semibold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mv-imeta { grid-column: 2; font-size: var(--fs-sm); color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mv-imeta .mono { font-size: var(--fs-xs); }
.mv-tag { display: inline-block; margin-left: 4px; padding: 0 6px; border: 1px solid var(--line-strong); border-radius: var(--r-pill); font-size: var(--fs-2xs); font-weight: var(--fw-medium); color: var(--ink-2); vertical-align: 1px; }
.mv-red { color: var(--danger-ink); }
.mv-none { padding: var(--sp-6) var(--sp-3); text-align: center; color: var(--ink-2); font-size: var(--fs-sm); }

/* ---- state shapes (list, legend, card, pins) ------------------------------------------------------------------ */
.mv-shape { display: block; flex: none; overflow: visible; }
.mv-shape .f { fill: var(--mk); stroke: var(--map-outline); stroke-width: 1.5; stroke-linejoin: round; }
.mv-shape.s-disarmed .f { fill: none; stroke: var(--mk); stroke-width: 3; }
/* On a themed surface the map's pale grey ring is too faint: use the tertiary ink there. */
.mv-side .mv-shape.s-disarmed .f, .mv-legend .mv-shape.s-disarmed .f, .mv-card .mv-shape.s-disarmed .f { stroke: var(--ink-3); }

/* ---- markers (our layer inside MapLibre's canvas container; each marker is a 0×0 anchor) ------------------------ */
.mv-layer { position: absolute; inset: 0; pointer-events: none; }
.mv-pin, .mv-cluster, .mv-veh { position: absolute; left: 0; top: 0; width: 0; height: 0; padding: 0; border: 0; background: none; cursor: pointer; pointer-events: auto; will-change: transform; }
.mv-pin .mv-shape, .mv-cl-n, .mv-arrow, .mv-ring { position: absolute; left: 0; top: 0; transform: translate(-50%, -50%); }
.mv-pin .mv-shape { filter: drop-shadow(0 1px 2px var(--map-shadow)); transition: transform var(--dur-2) var(--ease-out); }
.mv-pin.hot .mv-shape, .mv-pin.sel .mv-shape { transform: translate(-50%, -50%) scale(1.3); }
.mv-pin.sel .mv-shape .f, .mv-cluster.sel .mv-cl-n { stroke: var(--map-select); stroke-width: 2.5; }
.mv-pin.dim, .mv-cluster.dim, .mv-veh.dim { opacity: 0.35; }
.mv-pin:focus-visible, .mv-cluster:focus-visible, .mv-veh:focus-visible { outline: none; }
.mv-label {
  position: absolute; left: 15px; top: 0; transform: translateY(-50%); display: none; align-items: center; gap: 4px;
  padding: 1px 6px; border-radius: var(--r-xs); background: var(--map-scrim); color: var(--map-ink);
  font: var(--fw-semibold) var(--fs-2xs)/1.35 var(--font-ui); white-space: nowrap; pointer-events: none;
}
.named .mv-label, .hot .mv-label, .sel .mv-label { display: inline-flex; }
.hot .mv-label, .sel .mv-label { background: var(--map-scrim-strong); }
.mv-pin.s-alarm .mv-label { left: 17px; }
/* Decluttered (map.js declutter): flipped to the pin's left, or hidden until hovered/selected. */
.mv-flip .mv-label { left: auto; right: 15px; }
.mv-pin.s-alarm.mv-flip .mv-label { left: auto; right: 17px; }
.mv-veh.mv-flip .mv-label { left: auto; right: 20px; }
.mv-nolab:not(.hot):not(.sel) .mv-label { display: none; }

/* New alarm: two rings expanding out of the pin; under reduced motion two static rings (the signal stays). */
.mv-ring { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--danger); pointer-events: none; animation: mv-pulse 2.2s var(--ease-out) infinite; }
.mv-ring.r2 { animation-delay: 1.1s; }
@keyframes mv-pulse { from { transform: translate(-50%, -50%) scale(0.8); opacity: 0.95; } to { transform: translate(-50%, -50%) scale(2.9); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .mv-ring { animation: none; transform: translate(-50%, -50%) scale(1.6); opacity: 0.9; }
  .mv-ring.r2 { transform: translate(-50%, -50%) scale(2.3); opacity: 0.45; }
}

/* Cluster: a count bubble ringed in the worst state inside, with that state's shape when it matters. */
.mv-cl-n {
  display: grid; place-items: center; min-width: 30px; height: 30px; padding: 0 6px; border-radius: var(--r-pill);
  background: var(--map-bubble); color: var(--map-ink); font: var(--fw-bold) var(--fs-sm)/1 var(--font-ui);
  box-shadow: 0 0 0 3px var(--mk), 0 2px 8px var(--map-shadow); transition: transform var(--dur-2) var(--ease-out);
}
.mv-cluster .mv-shape { position: absolute; left: 7px; top: -21px; filter: drop-shadow(0 1px 1px var(--map-shadow)); }
.mv-cluster.hot .mv-cl-n { transform: translate(-50%, -50%) scale(1.15); }

/* Vehicle: arrow in its heading, fix age under it (red past 5 min), name beside it. */
.mv-arrow { overflow: visible; filter: drop-shadow(0 1px 2px var(--map-shadow)); transform-origin: 50% 50%; margin: -15px 0 0 -15px; transform: none; }
.mv-arrow path { fill: var(--mk); stroke: var(--map-outline); stroke-width: 1.5; stroke-linejoin: round; }
.mv-veh.hot .mv-arrow path, .mv-veh.sel .mv-arrow path { stroke: var(--map-select); stroke-width: 2; }
.mv-veh .mv-label { left: 20px; }
.mv-fix {
  position: absolute; left: 0; top: 17px; transform: translateX(-50%); padding: 0 4px; border-radius: var(--r-xs); white-space: nowrap;
  background: var(--map-scrim); color: var(--map-ink); font-size: var(--fs-2xs); line-height: 1.4; pointer-events: none;
}
.mv-veh.stale .mv-arrow { opacity: 0.5; }
.mv-veh.stale .mv-fix { background: var(--danger); color: var(--on-danger); }
.mv-veh:not(.pulsing) .mv-ring { display: none; }

/* ---- legend + fit ---------------------------------------------------------------------------------------------- */
.mv-legend {
  position: absolute; left: 10px; top: 10px; z-index: var(--z-sticky); max-width: 250px;
  padding: 6px 12px; border-radius: var(--r-md); background: var(--glass); box-shadow: var(--shadow-2); color: var(--ink); font-size: var(--fs-sm);
}
.mv-legend summary { cursor: pointer; font-weight: var(--fw-semibold); padding: 2px 0; }
.mv-legend[open] summary { margin-bottom: 4px; }
.mv-legend .lg { display: flex; align-items: center; gap: var(--sp-2); padding: 2px 0; }
.mv-lg-ring { width: 16px; height: 16px; flex: none; border-radius: 50%; border: 2px solid var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.mv-lg-veh { flex: none; overflow: visible; }
.mv-lg-veh path { fill: var(--ink-2); }
.mv-lg-cl { display: grid; place-items: center; width: 18px; height: 18px; flex: none; border-radius: 50%; background: var(--ink); color: var(--bg); font-size: var(--fs-2xs); font-weight: var(--fw-bold); }
.mv-fit { position: absolute; top: 78px; right: 10px; z-index: var(--z-sticky); width: 29px; height: 29px; min-height: 0; padding: 0; background: var(--surface); box-shadow: var(--shadow-2); }

/* ---- the site card ---------------------------------------------------------------------------------------------- */
.mv-card {
  position: absolute; z-index: var(--z-dropdown); width: 330px; max-height: calc(100% - 16px); overflow: auto;
  padding: var(--sp-3) var(--sp-4) var(--sp-4); border: 1px solid var(--line-strong); border-radius: var(--r-lg);
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-3); animation: mv-card-in var(--dur-2) var(--ease-out);
}
.mv-card[hidden] { display: none; }
.mv-card.docked { left: 12px; bottom: 12px; top: auto; }
@keyframes mv-card-in { from { opacity: 0; transform: translateY(4px); } }
.mv-card-head { display: flex; align-items: center; gap: var(--sp-2); margin: calc(-1 * var(--sp-1)) calc(-1 * var(--sp-2)) 0 0; }
.mv-x { flex: none; }
.mv-card-head h2 { flex: 1; min-width: 0; font-size: var(--fs-lg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mv-card-sub { margin-top: 2px; font-size: var(--fs-sm); }
.mv-card-chips { margin-top: var(--sp-2); font-size: var(--fs-sm); }
.mv-card-sec { margin-top: var(--sp-3); padding-top: var(--sp-3); border-top: 1px solid var(--line); font-size: var(--fs-sm); }
.mv-card-sec h3 { margin-bottom: var(--sp-1); }
.mv-alarms, .mv-dark { list-style: none; margin: 0; padding: 0; }
.mv-alarm {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: var(--sp-2);
  margin: 0 calc(-1 * var(--sp-2)); padding: 5px var(--sp-2); border-radius: var(--r-sm); color: var(--ink); text-decoration: none;
}
.mv-alarm:hover { background: var(--surface-2); text-decoration: none; }
.mv-atext { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mv-more { display: inline-block; margin-top: var(--sp-1); font-size: var(--fs-sm); }
.mv-dark li { display: flex; align-items: center; gap: var(--sp-2); padding: 2px 0; }
.mv-card-note { margin-top: var(--sp-3); font-size: var(--fs-sm); }
.mv-card-actions { margin-top: var(--sp-4); }

/* ---- phones: full map, the list as a bottom sheet (peek = title + search) -------------------------------------- */
@media (max-width: 900px) {
  .mapview { display: block; }
  .mv-map { position: absolute; inset: 0; }
  .mv-side {
    position: absolute; left: 0; right: 0; bottom: 0; z-index: var(--z-drawer); max-height: 70%;
    border-right: 0; border-top: 1px solid var(--line-strong); border-radius: var(--r-xl) var(--r-xl) 0 0; box-shadow: var(--shadow-3);
  }
  .mv-head { gap: var(--sp-2); padding: 0 var(--sp-3) var(--sp-3); border-bottom: 0; }
  .mv-grab { display: grid; place-items: center; width: 100%; height: 28px; margin-bottom: -4px; padding: 0; border: 0; background: none; cursor: pointer; }
  .mv-grab span { width: 40px; height: 4px; border-radius: var(--r-pill); background: var(--line-strong); }
  .mv-title { font-size: var(--fs-lg); }
  .mapview[data-sheet="peek"] .mv-filter, .mapview[data-sheet="peek"] .mv-list { display: none; }
  .mapview[data-sheet="open"] .mv-head { border-bottom: 1px solid var(--line); }
  .mv-item { min-height: 48px; }
  .mv-legend { max-width: calc(100% - 64px); }
  .mv-card.docked { left: 8px; right: 8px; top: 8px; bottom: auto; width: auto; max-height: calc(100% - 200px); }
}
