/* =============================================================
   Page: /dispatch (Fleet Live)
   ============================================================= */

.dispatch-page {
  height: calc(100vh - 44px);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* preset bar: named user-facing presets, helpdesk §G.2 */
.preset-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-7);
  background: var(--surface);
  border-bottom: 1px solid var(--border-soft);
  overflow-x: auto;
}
.preset {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
  height: 26px;
  padding: 0 var(--sp-5);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--fg-muted);
  font-size: var(--fs-11);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.preset:hover { background: var(--surface-hover); color: var(--fg); }
.preset[aria-pressed="true"] {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-fg);
}
.preset .count {
  background: rgba(255,255,255,0.18);
  border-radius: var(--r-pill);
  padding: 0 5px;
  font-family: var(--font-mono);
  font-size: 10px;
}
.preset[aria-pressed="false"] .count { background: var(--surface-sunk); color: var(--fg-subtle); }
/* AFD-12 B6 / F-022 — honest «presets overlap» note, right-aligned in the bar. */
.preset-hint {
  margin-left: auto;
  color: var(--fg-subtle);
  font-size: var(--fs-11);
  white-space: nowrap;
  cursor: help;
}

/* main split: map | sidebar */
.live-main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 380px;
  min-height: 0;
  border-top: 1px solid var(--border);
}
.live-main.tableOpen { grid-template-rows: 1fr 320px; grid-template-columns: 1fr 380px; }
.live-main.tableOpen .map-wrap,
.live-main.tableOpen .sidebar { grid-row: 1; }
.live-main.tableOpen .table-drawer { grid-row: 2; grid-column: 1 / -1; display: flex; }

.map-wrap {
  position: relative;
  background: var(--bg-canvas);
  border-right: 1px solid var(--border);
  min-height: 0;
}
#fleetMap { position: absolute; inset: 0; }

/* map overlay legend + counters */
.map-legend {
  position: absolute;
  top: var(--sp-5);
  left: var(--sp-5);
  z-index: 500;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  padding: var(--sp-4) var(--sp-5);
  box-shadow: var(--shadow-2);
  display: flex;
  gap: var(--sp-6);
  font-size: var(--fs-11);
  color: var(--fg-muted);
}
.map-legend .lg {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
}
.map-legend .lg::before {
  content: "";
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--idle);
  box-shadow: 0 0 0 2px var(--surface);
}
.map-legend .lg[data-s="ok"]::before    { background: var(--ok); }
.map-legend .lg[data-s="warn"]::before  { background: var(--warn); }
.map-legend .lg[data-s="bad"]::before   { background: var(--bad); }
.map-legend .lg[data-s="idle"]::before  { background: var(--idle); }
.map-legend .lg .n { color: var(--fg-strong); font-weight: 600; font-variant-numeric: tabular-nums; }

.map-tools {
  position: absolute;
  top: var(--sp-5);
  right: var(--sp-5);
  z-index: 500;
  display: flex;
  gap: var(--sp-3);
}
.map-tools .btn { box-shadow: var(--shadow-2); }

.map-staleness {
  position: absolute;
  bottom: var(--sp-5);
  left: var(--sp-5);
  z-index: 500;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  padding: 4px var(--sp-5);
  font-size: var(--fs-11);
  color: var(--fg-muted);
  box-shadow: var(--shadow-2);
  font-family: var(--font-mono);
}

/* fleet marker */
.fleet-marker {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--ok);
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.15), 0 1px 3px rgba(0,0,0,0.2);
  display: grid; place-items: center;
  color: var(--surface);
  font-family: var(--font-mono);
  font-size: 8px;
  font-weight: 700;
  transition: transform 1s linear;
}
.fleet-marker.s-warn { background: var(--warn); }
.fleet-marker.s-bad  { background: var(--bad); animation: marker-pulse-bad 1.6s ease-out infinite; }
.fleet-marker.s-idle { background: var(--idle); opacity: 0.65; }
.fleet-marker.s-speed{ background: var(--speed); }
@keyframes marker-pulse-bad {
  0%   { box-shadow: 0 0 0 0 rgba(181, 53, 65, 0.55), 0 0 0 1px rgba(0,0,0,0.15); }
  100% { box-shadow: 0 0 0 12px rgba(181, 53, 65, 0), 0 0 0 1px rgba(0,0,0,0.15); }
}

.cluster-marker {
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--r-pill);
  padding: 2px 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--fg);
  box-shadow: var(--shadow-2);
  white-space: nowrap;
}

/* sidebar */
.sidebar {
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.sidebar .feed-head {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-5) var(--sp-6);
  border-bottom: 1px solid var(--border);
}
.sidebar .feed-head h3 {
  font-size: var(--fs-12);
  font-weight: 600;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-strong);
}
.sidebar .feed-head .count {
  font-family: var(--font-mono);
  font-size: var(--fs-11);
  color: var(--fg-subtle);
}
.sidebar .feed-head .spacer { flex: 1; }
.sidebar .feed-head .live-pulse {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  color: var(--ok);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.sidebar .feed-head .live-pulse::before {
  content: "";
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ok);
  animation: pulse-ok 1.6s ease-out infinite;
}
.sidebar .filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: var(--sp-4) var(--sp-6);
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface-alt);
}
.sidebar .filter-chips .chip {
  background: var(--surface);
  color: var(--fg-muted);
  border: 1px solid var(--border);
  cursor: pointer;
  font-weight: 500;
}
.sidebar .filter-chips .chip[aria-pressed="true"] {
  background: var(--primary-bg);
  color: var(--primary);
  border-color: var(--primary-bg-2);
}
.feed { flex: 1; overflow-y: auto; min-height: 0; }

/* bus list as bottom drawer */
.table-drawer {
  display: none;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-direction: column;
  min-height: 0;
}
.drawer-head {
  display: flex; align-items: center; gap: var(--sp-5);
  padding: var(--sp-4) var(--sp-7);
  border-bottom: 1px solid var(--border-soft);
}
.drawer-head h3 {
  font-size: var(--fs-12); font-weight: 600; margin: 0;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--fg-strong);
}
.drawer-head .count { font-family: var(--font-mono); font-size: var(--fs-11); color: var(--fg-subtle); }
.drawer-head .spacer { flex: 1; }
.drawer-body { flex: 1; overflow: auto; min-height: 0; padding: 0; }

/* column widths */
.bus-table { width: 100%; }
.bus-table th, .bus-table td { padding-left: 12px; padding-right: 12px; }
.bus-table .c-plate { width: 96px; }
.bus-table .c-city { width: 130px; }
.bus-table .c-route { width: 86px; }
.bus-table .c-status { width: 116px; }
.bus-table .c-fsm { width: 132px; }
.bus-table .c-partner { width: 168px; }
.bus-table .c-viol { width: 64px; text-align: right; }
.bus-table .c-seen { width: 110px; }
.bus-table .c-dev  { width: 156px; }

/* AFD-12 B4a / F-002 — reactive virtual table.
   Selected row persists across SSE deltas (selection is re-applied on every
   window render, never wiped by a rebuild). */
.bus-table tbody tr.is-selected,
.bus-table tbody tr.is-selected:hover {
  background: var(--primary-bg);
  box-shadow: inset 2px 0 0 var(--primary);
}
/* Virtualization spacer rows hold the full scroll height; the empty-state row
   spans the table when there are no rows for the current filter (AC-7). */
.bus-table tbody tr.vt-spacer { pointer-events: none; }
.bus-table tbody tr.vt-spacer td { padding: 0; border: 0; }
.bus-table tbody tr.vt-empty td {
  text-align: center;
  color: var(--fg-muted);
  padding: 24px 12px;
  height: auto;
}

/* Operator text search in the drawer head — also the Ctrl+F / a11y mitigation
   for virtualization (filters the full model, not just the rendered window). */
.bus-search {
  height: 24px;
  min-width: 220px;
  padding: 0 var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  background: var(--surface);
  color: var(--fg);
  font-size: var(--fs-11);
}
.bus-search:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-bg);
}

.toggle-table {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-5);
  height: 26px;
  border: 1px solid var(--border);
  border-radius: var(--r-3);
  background: var(--surface);
  font-size: var(--fs-11);
  color: var(--fg);
  cursor: pointer;
}
.toggle-table[aria-pressed="true"] {
  background: var(--primary-bg);
  color: var(--primary);
  border-color: var(--primary-bg-2);
}
