/* =====================================================================
   Cabsby Tracking — Dispatcher Console
   Apple Polish aesthetic. Calm, premium, dispatcher-focused.
   ===================================================================== */

/* ---------- Design tokens ---------- */
:root {
  /* Apple system-inspired spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  /* Corner radii — always a little soft, never aggressive */
  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  /* Brand */
  --brand:         #F5C842;
  --brand-hover:   #FFD85A;
  --brand-dim:     #B5933A;

  /* Apple-style semantic colors */
  --green:  #30D158;
  --amber:  #FF9F0A;
  --red:    #FF453A;
  --blue:   #0A84FF;
  --grey:   #8E8E93;

  /* Motion — Apple's preferred curves */
  --ease-apple: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-out:   cubic-bezier(0.16, 1, 0.3, 1);
  --dur-fast:   120ms;
  --dur:        200ms;
  --dur-slow:   320ms;

  /* Fonts */
  --font-ui: -apple-system, BlinkMacSystemFont, 'SF Pro Display',
             'SF Pro Text', 'Segoe UI', Roboto, 'Helvetica Neue',
             Arial, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'JetBrains Mono',
               'Menlo', 'Consolas', monospace;
}

/* ---------- Dark theme (default) ---------- */
:root,
[data-theme="dark"] {
  --surface-0:  #0A0C10;  /* app background */
  --surface-1:  #11141A;  /* elevated panel */
  --surface-2:  #181C24;  /* secondary panel */
  --surface-3:  #222834;  /* hovered element */

  --line:       rgba(255, 255, 255, 0.08);
  --line-soft:  rgba(255, 255, 255, 0.05);
  --line-strong: rgba(255, 255, 255, 0.14);

  --text:       #F2F4F7;
  --text-dim:   #98A0AD;
  --text-faint: #5C6575;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow:    0 4px 14px rgba(0, 0, 0, 0.4),
               0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.55),
               0 4px 12px rgba(0, 0, 0, 0.4);

  --ring: 0 0 0 3px rgba(245, 200, 66, 0.32);
  --map-filter: invert(0.92) hue-rotate(180deg) brightness(0.82)
                saturate(0.75) contrast(0.92);

  --danger-glow: 0 0 0 4px rgba(255, 69, 58, 0.16);
}

/* ---------- Light theme ---------- */
[data-theme="light"] {
  --surface-0:  #F7F8FA;
  --surface-1:  #FFFFFF;
  --surface-2:  #F2F3F6;
  --surface-3:  #E8EAEF;

  --line:       rgba(0, 0, 0, 0.08);
  --line-soft:  rgba(0, 0, 0, 0.05);
  --line-strong: rgba(0, 0, 0, 0.14);

  --text:       #0A0E16;
  --text-dim:   #5B6472;
  --text-faint: #8E96A3;

  --green:  #248A3D;
  --amber:  #C15900;
  --red:    #D70015;
  --blue:   #0040DD;
  --grey:   #6E6E73;

  --shadow-sm: 0 1px 2px rgba(10, 14, 22, 0.06);
  --shadow:    0 4px 14px rgba(10, 14, 22, 0.08),
               0 1px 2px rgba(10, 14, 22, 0.04);
  --shadow-lg: 0 20px 48px rgba(10, 14, 22, 0.14),
               0 4px 12px rgba(10, 14, 22, 0.06);

  --ring: 0 0 0 3px rgba(217, 167, 26, 0.35);
  --map-filter: none;

  --danger-glow: 0 0 0 4px rgba(215, 0, 21, 0.15);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--surface-0);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  transition: background-color var(--dur) var(--ease-apple),
              color var(--dur) var(--ease-apple);
}

button, input, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

::-webkit-scrollbar        { width: 10px; height: 10px; }
::-webkit-scrollbar-track  { background: transparent; }
::-webkit-scrollbar-thumb  { background: var(--line-strong); border-radius: 5px; border: 2px solid var(--surface-1); }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

.hidden { display: none !important; }
.view { width: 100%; height: 100%; }

/* ---------- Logo (shown variant switches with theme) ---------- */
.cabsby-wordmark {
  height: 32px;
  width: auto;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  flex-shrink: 0;
}
.cabsby-wordmark.lg { height: 48px; }
.cabsby-wordmark.sm { height: 24px; }

.cabsby-wordmark.light-only { display: none; }
[data-theme="light"] .cabsby-wordmark.dark-only  { display: none; }
[data-theme="light"] .cabsby-wordmark.light-only { display: block; }

/* =====================================================================
   LOGIN VIEW
   ===================================================================== */

#view-login {
  display: grid;
  place-items: center;
  min-height: 100vh;
  position: relative;
  background:
    radial-gradient(1200px 600px at 50% -20%,
      rgba(245, 200, 66, 0.06), transparent 60%),
    var(--surface-0);
}

.login-card {
  position: relative;
  z-index: 1;
  width: min(400px, 92vw);
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  padding: 40px 36px 28px;
  box-shadow: var(--shadow-lg);
}

.login-brand {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}
.login-brand .cabsby-wordmark { height: 56px; }

.login-subtitle {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  margin: 0 0 28px;
  font-weight: 500;
}

#login-form label {
  display: block;
  margin-bottom: 14px;
}
#login-form label > span {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 500;
}
#login-form input {
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 14px;
  font-size: 14px;
  transition: border-color var(--dur-fast) var(--ease-apple),
              box-shadow var(--dur-fast) var(--ease-apple),
              background var(--dur-fast) var(--ease-apple);
}
#login-form input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--ring);
  background: var(--surface-1);
}

.btn {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  padding: 10px 16px;
  font-weight: 600;
  font-size: 14px;
  transition: transform 80ms var(--ease-apple),
              background var(--dur-fast) var(--ease-apple),
              box-shadow var(--dur-fast) var(--ease-apple),
              color var(--dur-fast) var(--ease-apple);
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--brand);
  color: #111;
  box-shadow: var(--shadow-sm);
  width: 100%;
  padding: 12px 16px;
  margin-top: 6px;
}
.btn-primary:hover { background: var(--brand-hover); }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
  padding: 8px 14px;
}
.btn-ghost:hover {
  background: var(--surface-2);
  border-color: var(--line-strong);
}

.btn-icon {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  width: 36px; height: 36px;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  color: var(--text-dim);
  padding: 0;
  transition: all var(--dur-fast) var(--ease-apple);
}
.btn-icon:hover {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--line-strong);
}
.btn-icon svg { width: 17px; height: 17px; stroke-width: 2; }

.error-msg {
  margin: 12px 0 0;
  color: var(--red);
  font-size: 13px;
  min-height: 1.2em;
}

.footnote {
  margin-top: 26px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
  color: var(--text-faint);
  font-size: 11px;
  text-align: center;
  font-weight: 500;
}

/* =====================================================================
   TRACKING VIEW
   ===================================================================== */

#view-tracking {
  display: grid;
  grid-template-rows: 56px 1fr;
  height: 100vh;
}

/* ---------- Top bar ---------- */
.top-bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  padding: 0 16px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--line);
  gap: 20px;
  z-index: 100;
  min-width: 0;
}

.top-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}
.top-left .divider {
  width: 1px; height: 22px;
  background: var(--line);
}
.tagline {
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: 0.08em;
  font-weight: 600;
  text-transform: uppercase;
  white-space: nowrap;
}

/* Counter chips: soft, subtle, no loud borders */
.top-center {
  display: flex;
  justify-content: center;
  gap: 6px;
  flex-wrap: nowrap;
  overflow: hidden;
}
.top-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.user-name {
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  margin-right: 4px;
  white-space: nowrap;
}

.chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 12px;
  background: var(--surface-2);
  border-radius: var(--radius);
  min-width: 62px;
  transition: background var(--dur-fast) var(--ease-apple);
}
.chip-label {
  font-size: 10px;
  color: var(--text-faint);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.chip-value {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-top: 1px;
  font-variant-numeric: tabular-nums;
}
.chip-value.count-bump { animation: count-bump 260ms var(--ease-apple); }

@keyframes count-bump {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.18); color: var(--brand); }
  100% { transform: scale(1); }
}

/* SOS chip — calm when nothing's wrong, urgent when there is */
.chip-alert .chip-value { color: var(--text-faint); }
.chip-alert.active {
  background: rgba(255, 69, 58, 0.14);
  animation: sos-chip-glow 1.2s ease-in-out infinite;
}
.chip-alert.active .chip-label { color: var(--red); }
.chip-alert.active .chip-value { color: var(--red); }

@keyframes sos-chip-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 69, 58, 0.26); }
  50%      { box-shadow: 0 0 0 6px rgba(255, 69, 58, 0); }
}

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  min-height: 0;
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto auto auto 1fr;
  background: var(--surface-1);
  border-right: 1px solid var(--line);
  min-height: 0;
  overflow: hidden;
}

.sidebar-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft);
}
#vehicle-search {
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 13px;
  transition: all var(--dur-fast) var(--ease-apple);
}
#vehicle-search::placeholder { color: var(--text-faint); }
#vehicle-search:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--ring);
  background: var(--surface-1);
}

/* Toggle row (Show disconnected) */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 12px;
  color: var(--text-dim);
}
.toggle-row label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}
.toggle-switch {
  position: relative;
  width: 34px; height: 20px;
  background: var(--surface-3);
  border-radius: 999px;
  transition: background var(--dur) var(--ease-apple);
  flex-shrink: 0;
}
.toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur) var(--ease-apple);
}
input[type="checkbox"].toggle-checkbox { display: none; }
input[type="checkbox"].toggle-checkbox:checked + .toggle-switch {
  background: var(--green);
}
input[type="checkbox"].toggle-checkbox:checked + .toggle-switch::after {
  transform: translateX(14px);
}

/* Group filter */
.filter-row {
  display: flex;
  gap: 6px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
  overflow-x: auto;
  scrollbar-width: none;
}
.filter-row::-webkit-scrollbar { display: none; }

.filter-chip {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text-dim);
  font-size: 11px;
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--dur-fast) var(--ease-apple);
  font-weight: 600;
  flex-shrink: 0;
}
.filter-chip:hover { background: var(--surface-2); color: var(--text); }
.filter-chip.active {
  background: var(--text);
  color: var(--surface-1);
  border-color: var(--text);
}
.filter-chip .count {
  font-family: var(--font-mono);
  font-weight: 700;
  margin-left: 6px;
  opacity: 0.65;
  font-variant-numeric: tabular-nums;
}

/* Tabs */
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--line);
  position: relative;
}
.tab {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 12px 0;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  position: relative;
  transition: color var(--dur-fast) var(--ease-apple);
}
.tab.active { color: var(--text); }
.tab:hover:not(.active) { color: var(--text); }
.tab::after {
  content: '';
  position: absolute;
  left: 20%; right: 20%; bottom: 0;
  height: 2px;
  background: var(--brand);
  border-radius: 2px 2px 0 0;
  transform: scaleX(0);
  transition: transform var(--dur) var(--ease-apple);
}
.tab.active::after { transform: scaleX(1); }

.badge {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 6px;
  margin-left: 6px;
  background: var(--red);
  color: #fff;
  border-radius: 9px;
  font-size: 10px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.pane { overflow-y: auto; min-height: 0; }

.vehicle-list, .alarm-list {
  list-style: none;
  margin: 0;
  padding: 4px 0;
}

/* ---------- Vehicle card ---------- */
.vehicle-item {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-apple);
  position: relative;
}
.vehicle-item:hover { background: var(--surface-2); }
.vehicle-item.selected {
  background: var(--surface-2);
}
.vehicle-item.selected::before {
  content: '';
  position: absolute;
  left: 0; top: 6px; bottom: 6px;
  width: 3px;
  background: var(--brand);
  border-radius: 0 3px 3px 0;
}

.vehicle-icon {
  width: 32px; height: 32px;
  flex-shrink: 0;
  transition: transform var(--dur-fast) var(--ease-apple);
}
.vehicle-item:hover .vehicle-icon { transform: scale(1.08); }
.vehicle-icon svg { width: 100%; height: 100%; display: block; }

.vehicle-meta-main { display: flex; flex-direction: column; min-width: 0; }
.vehicle-plate {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.003em;
}
.vehicle-driver {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.vehicle-state {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
  white-space: nowrap;
}
.vehicle-state-value {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.vehicle-state-label {
  font-size: 9px;
  color: var(--text-faint);
  margin-top: 2px;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.vehicle-item[data-state="moving"]       .vehicle-state-value { color: var(--green); }
.vehicle-item[data-state="idle"]         .vehicle-state-value { color: var(--amber); }
.vehicle-item[data-state="engine-off"]   .vehicle-state-value { color: var(--text-dim); }
.vehicle-item[data-state="disconnected"] .vehicle-state-value { color: var(--text-faint); }
.vehicle-item[data-state="sos"] {
  background: rgba(255, 69, 58, 0.10);
}
.vehicle-item[data-state="sos"]::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--red);
}
.vehicle-item[data-state="sos"] .vehicle-state-value { color: var(--red); }

.empty-list {
  padding: 28px 20px;
  color: var(--text-faint);
  font-size: 12px;
  text-align: center;
  line-height: 1.6;
}

/* ---------- Alarms ---------- */
.alarm-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-apple);
  position: relative;
}
.alarm-item:hover { background: var(--surface-2); }
.alarm-item.sos {
  background: rgba(255, 69, 58, 0.08);
}
.alarm-item.sos::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--red);
}
.alarm-item.acked { opacity: 0.55; }
.alarm-top { display: flex; gap: 8px; align-items: center; }
.alarm-type {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.alarm-item.sos .alarm-type { color: var(--red); font-weight: 700; }
.alarm-vehicle {
  font-weight: 600;
  color: var(--text);
  margin-top: 3px;
  font-size: 13px;
}
.alarm-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.alarm-ack-mark {
  font-size: 10px;
  color: var(--green);
  margin-top: 4px;
  font-weight: 600;
}

/* =====================================================================
   MAP
   ===================================================================== */

.map-wrap {
  position: relative;
  background: var(--surface-0);
  min-height: 0;
}
#map {
  position: absolute;
  inset: 0;
  background: var(--surface-0);
}

.leaflet-tile {
  filter: var(--map-filter);
  transition: filter var(--dur) var(--ease-apple);
}

.leaflet-container {
  background: var(--surface-0);
  font-family: var(--font-ui);
}
.leaflet-control-attribution {
  background: rgba(17, 20, 26, 0.72) !important;
  color: var(--text-faint) !important;
  font-size: 10px !important;
  padding: 2px 6px !important;
  border-radius: 4px !important;
}
[data-theme="light"] .leaflet-control-attribution {
  background: rgba(255, 255, 255, 0.88) !important;
  color: #6B6B70 !important;
}
.leaflet-control-attribution a { color: var(--text-dim) !important; }
.leaflet-control-zoom {
  border: none !important;
  box-shadow: var(--shadow) !important;
  border-radius: var(--radius) !important;
  overflow: hidden;
}
.leaflet-control-zoom a {
  background: var(--surface-1) !important;
  color: var(--text) !important;
  border: none !important;
  border-bottom: 1px solid var(--line) !important;
  font-size: 18px !important;
  width: 34px !important;
  height: 34px !important;
  line-height: 34px !important;
  transition: background var(--dur-fast) var(--ease-apple) !important;
}
.leaflet-control-zoom a:hover {
  background: var(--surface-2) !important;
  color: var(--text) !important;
}
.leaflet-control-zoom a:last-child { border-bottom: none !important; }

.leaflet-popup-content-wrapper {
  background: var(--surface-1) !important;
  color: var(--text) !important;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-lg) !important;
  padding: 0 !important;
}
.leaflet-popup-tip { background: var(--surface-1) !important; border: 1px solid var(--line); }
.leaflet-popup-content {
  margin: 14px 16px !important;
  font-size: 13px;
  line-height: 1.55;
}
.leaflet-popup-content strong { color: var(--text); font-weight: 600; }
.leaflet-popup-content .popup-label {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  letter-spacing: -0.003em;
  margin-bottom: 6px;
}
.leaflet-popup-content .popup-row {
  display: flex;
  gap: 6px;
  margin-top: 4px;
  color: var(--text-dim);
}
.leaflet-popup-content .popup-row b { color: var(--text); font-weight: 500; }
.leaflet-popup-content .popup-state {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  margin-top: 4px;
}
.leaflet-popup-content .popup-state.moving       { background: rgba(48, 209, 88, 0.2); color: var(--green); }
.leaflet-popup-content .popup-state.idle         { background: rgba(255, 159, 10, 0.2); color: var(--amber); }
.leaflet-popup-content .popup-state.engine-off   { background: var(--surface-3); color: var(--text-dim); }
.leaflet-popup-content .popup-state.disconnected { background: var(--surface-3); color: var(--text-faint); }
.leaflet-popup-content .popup-state.sos          { background: rgba(255, 69, 58, 0.2); color: var(--red); }
.leaflet-popup-content .popup-addr {
  color: var(--text-dim);
  font-size: 12px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line-soft);
}
.leaflet-popup-content a { color: var(--blue); text-decoration: none; font-weight: 500; }
.leaflet-popup-content a:hover { text-decoration: underline; }
.leaflet-popup-close-button {
  color: var(--text-dim) !important;
  font-size: 20px !important;
  padding: 6px 8px !important;
}

/* Taxi marker */
.cabsby-marker {
  display: block;
  width: 44px; height: 44px;
  transform: translate(-50%, -50%);
}
.cabsby-marker svg {
  width: 100%; height: 100%;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.45));
}
.cabsby-marker.sos svg {
  animation: marker-pulse 0.9s ease-in-out infinite;
  filter: drop-shadow(0 0 10px rgba(255, 69, 58, 0.8));
}

@keyframes marker-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.18); }
}

/* Map legend */
.legend {
  position: absolute;
  bottom: 14px; left: 14px;
  z-index: 400;
  display: flex;
  gap: 12px;
  padding: 8px 14px;
  background: rgba(17, 20, 26, 0.85);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 11px;
  color: var(--text-dim);
  flex-wrap: wrap;
  box-shadow: var(--shadow);
}
[data-theme="light"] .legend { background: rgba(255, 255, 255, 0.9); }

.legend .dot {
  display: inline-block;
  width: 9px; height: 9px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.dot-moving      { background: var(--green); }
.dot-idle        { background: var(--amber); }
.dot-engineoff   { background: #2D2D33; border: 1px solid #8A8F9A; }
.dot-disconnected{ background: var(--grey); }
.dot-sos         { background: var(--red); }

/* =====================================================================
   SOS OVERLAY — the ONE loud moment
   ===================================================================== */

.sos-overlay {
  position: fixed; inset: 0;
  background: radial-gradient(ellipse at center,
    rgba(255, 69, 58, 0.22),
    rgba(0, 0, 0, 0.82));
  z-index: 9999;
  display: grid; place-items: center;
  animation: sos-bg 1.2s ease-in-out infinite;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.sos-card {
  width: min(480px, 92vw);
  background: var(--surface-1);
  border: 2px solid var(--red);
  border-radius: var(--radius-xl);
  padding: 28px 28px 22px;
  box-shadow:
    0 30px 80px rgba(255, 69, 58, 0.4),
    0 10px 28px rgba(0, 0, 0, 0.4);
}
.sos-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.sos-pulse {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 14px var(--red);
  animation: sos-dot 0.9s ease-in-out infinite;
}
.sos-head h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--red);
}
.sos-body {
  padding: 16px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--text);
  line-height: 1.55;
  font-size: 15px;
}
.sos-body > p { margin: 6px 0; }
.sos-body strong { color: var(--text); font-weight: 600; }
.sos-body .sos-plate {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.005em;
  margin: 4px 0 8px !important;
  color: var(--text);
}
.sos-body a {
  color: var(--blue);
  text-decoration: none;
  font-weight: 500;
}
.sos-body a:hover { text-decoration: underline; }
.sos-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 18px;
}
.sos-actions .btn-primary {
  width: auto;
  margin: 0;
  background: var(--red);
  color: #fff;
  padding: 10px 22px;
  box-shadow: 0 0 0 4px rgba(255, 69, 58, 0.16);
}
.sos-actions .btn-primary:hover { background: #FF5A50; }

@keyframes sos-bg {
  0%, 100% { background: radial-gradient(ellipse at center, rgba(255, 69, 58, 0.22), rgba(0, 0, 0, 0.82)); }
  50%      { background: radial-gradient(ellipse at center, rgba(255, 69, 58, 0.38), rgba(0, 0, 0, 0.82)); }
}
@keyframes sos-dot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.25); opacity: 0.75; }
}

/* =====================================================================
   PLAYBACK PANEL
   ===================================================================== */

.playback-panel {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  width: min(680px, 94vw);
  background: rgba(17, 20, 26, 0.92);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  box-shadow: var(--shadow-lg);
  color: var(--text);
}
[data-theme="light"] .playback-panel { background: rgba(255, 255, 255, 0.96); }

.playback-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.playback-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: -0.003em;
  color: var(--text);
}
.playback-subtitle {
  font-size: 12px;
  color: var(--text-dim);
  margin-left: 8px;
  font-weight: 400;
}
.playback-close {
  background: transparent; border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 22px;
  padding: 0 6px;
  line-height: 1;
  transition: color var(--dur-fast) var(--ease-apple);
}
.playback-close:hover { color: var(--text); }

.playback-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
  align-items: flex-end;
}
.playback-controls label {
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-weight: 500;
}
.playback-controls input[type="datetime-local"],
.playback-controls select {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  padding: 7px 10px;
  font-size: 12px;
  font-family: var(--font-ui);
  transition: border-color var(--dur-fast) var(--ease-apple);
}
.playback-controls input[type="datetime-local"]:focus,
.playback-controls select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--ring);
}

.playback-slider-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
}
#playback-slider {
  width: 100%;
  accent-color: var(--brand);
}
.playback-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  min-width: 140px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* =====================================================================
   RESPONSIVE
   ===================================================================== */
@media (max-width: 960px) {
  .top-center { gap: 4px; }
  .chip { padding: 3px 8px; min-width: 54px; }
  .chip-value { font-size: 13px; }
  .chip-label { font-size: 9px; }
}
@media (max-width: 860px) {
  .top-bar { grid-template-columns: auto 1fr auto; gap: 8px; }
  .top-center { display: none; }
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: absolute;
    top: 56px; left: 0; bottom: 0;
    width: 88vw;
    max-width: 340px;
    z-index: 500;
    transform: translateX(-100%);
    transition: transform var(--dur) var(--ease-apple);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .legend { display: none; }
}
