@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;700&display=swap');

:root {
  --bg: #0c1220;
  --panel: #121a2b;
  --panel-line: #23304a;
  --ink: #e7ecf5;
  --ink-dim: #8695b3;
  --amber: #ffb020;
  --teal: #39d0d8;
  --red: #ff5d5d;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --sans: 'Inter', system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
}

.app {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: 100vh;
}

@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .panel { max-height: 46vh; }
}

/* ---------- side panel ---------- */
.panel {
  background: var(--panel);
  border-right: 1px solid var(--panel-line);
  display: flex;
  flex-direction: column;
  padding: 20px 18px;
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.brand-mark {
  font-size: 22px;
  color: var(--amber);
  line-height: 1;
}

.brand h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--ink-dim);
}

.fleet-summary {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
}

.stat {
  flex: 1;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  padding: 10px 12px;
}

.stat-value {
  display: block;
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 700;
  color: var(--teal);
}

.stat-label {
  display: block;
  font-size: 11px;
  color: var(--ink-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 2px;
}

.list-head {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
  padding: 0 4px 8px;
  border-bottom: 1px solid var(--panel-line);
}

.device-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.device-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 11px 4px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  cursor: pointer;
  font-size: 13px;
}

.device-list li:hover { background: rgba(255,255,255,0.03); }
.device-list li.selected { background: rgba(57,208,216,0.08); }

.device-list .empty-row {
  color: var(--ink-dim);
  cursor: default;
  font-style: italic;
}

.device-name {
  display: flex;
  flex-direction: column;
}

.device-id {
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.device-meta {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-dim);
}

.badge {
  font-family: var(--mono);
  font-size: 10px;
  padding: 3px 7px;
  border-radius: 100px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.badge.live {
  color: #0c1220;
  background: var(--teal);
}

.badge.stale {
  color: var(--ink-dim);
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--panel-line);
}

.trail-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 4px 4px;
  font-size: 12.5px;
  color: var(--ink-dim);
  cursor: pointer;
}

.switch {
  position: relative;
  width: 36px;
  height: 20px;
  display: inline-block;
  flex-shrink: 0;
}

.switch input { opacity: 0; width: 0; height: 0; }

.switch-track {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.12);
  border-radius: 100px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.switch-track::before {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  left: 3px;
  top: 3px;
  background: var(--ink);
  border-radius: 50%;
  transition: transform 0.15s ease;
}

.switch input:checked + .switch-track { background: var(--teal); }
.switch input:checked + .switch-track::before { transform: translateX(16px); background: #0c1220; }

.panel-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 14px;
  margin-top: 10px;
  border-top: 1px solid var(--panel-line);
  font-size: 12px;
  color: var(--ink-dim);
}

.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red);
  flex-shrink: 0;
}

.conn-dot.connected {
  background: var(--teal);
  box-shadow: 0 0 0 0 rgba(57,208,216,0.6);
  animation: pulse 2s infinite;
}

.admin-link {
  margin-left: auto;
  color: var(--teal);
  text-decoration: none;
  font-weight: 600;
}

.admin-link:hover { text-decoration: underline; }

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(57,208,216,0.5); }
  70%  { box-shadow: 0 0 0 8px rgba(57,208,216,0); }
  100% { box-shadow: 0 0 0 0 rgba(57,208,216,0); }
}

/* ---------- map ---------- */
.map-wrap { position: relative; }
#map { position: absolute; inset: 0; }

.map-fab {
  position: absolute;
  bottom: 24px;
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--panel-line);
  background: var(--panel);
  color: var(--ink);
  font-size: 17px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.35);
  z-index: 5;
}
.map-fab:hover { background: rgba(255,255,255,0.06); }

.bus-marker {
  width: 30px;
  height: 50px;
  cursor: pointer;
  position: relative;
  will-change: transform;
}

.pulse-ring {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  border-radius: 50%;
  border: 2px solid var(--teal);
  opacity: 0;
  pointer-events: none;
  animation: marker-pulse 2.4s ease-out infinite;
}

.bus-marker.stale .pulse-ring { animation: none; opacity: 0; }

@keyframes marker-pulse {
  0%   { transform: scale(0.6); opacity: 0.55; }
  70%  { transform: scale(2.1); opacity: 0; }
  100% { transform: scale(2.1); opacity: 0; }
}

.bus-body {
  width: 100%;
  height: 100%;
  transition: transform 0.2s ease;
}

.bus-marker.selected-marker .bus-body { transform: scale(1.18); }

.bus-icon {
  width: 100%;
  height: 100%;
  transform-origin: 50% 50%;
  transition: transform 0.25s ease;
  filter: drop-shadow(0 2px 5px rgba(0,0,0,0.45));
}

.bus-icon svg { width: 100%; height: 100%; display: block; }

.bus-marker.stale .bus-icon { filter: grayscale(0.85) opacity(0.55) drop-shadow(0 2px 5px rgba(0,0,0,0.3)); }

.bus-marker.selected-marker .bus-icon {
  filter: drop-shadow(0 0 8px var(--teal)) drop-shadow(0 2px 5px rgba(0,0,0,0.45));
}

.replay-marker {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 3px solid var(--teal);
  box-shadow: 0 0 0 4px rgba(57,208,216,0.25), 0 2px 6px rgba(0,0,0,0.4);
}

/* ---------- app layout with right panel ---------- */
.app { grid-template-columns: 340px 1fr; }

/* ---------- right-side vehicle detail panel ---------- */
.detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: 360px;
  max-width: 92vw;
  background: var(--panel);
  border-left: 1px solid var(--panel-line);
  padding: 22px 20px 30px;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.28s ease;
  z-index: 20;
}

.detail-panel.open { transform: translateX(0); }

.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 18px;
}

.detail-title { display: flex; align-items: center; gap: 12px; }

.dot-lg { width: 14px; height: 14px; margin-top: 3px; flex-shrink: 0; }

.detail-title h2 { margin: 0; font-size: 16px; }
#detail-sub { margin: 2px 0 0; }

.icon-btn {
  background: transparent;
  border: 1px solid var(--panel-line);
  color: var(--ink-dim);
  width: 28px;
  height: 28px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
.icon-btn:hover { color: var(--ink); background: rgba(255,255,255,0.05); }

.detail-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.dstat {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  padding: 10px 12px;
}

.dstat-label {
  display: block;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-dim);
  margin-bottom: 3px;
}

.dstat-value { font-family: var(--mono); font-size: 15px; font-weight: 600; }

.detail-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-top: 1px solid var(--panel-line);
  font-size: 12.5px;
}

.detail-row-label { color: var(--ink-dim); }
.detail-device-id { font-family: var(--mono); font-size: 11.5px; color: var(--ink); }

.detail-admin-btn {
  display: block;
  text-align: center;
  margin-top: 14px;
  font-size: 12.5px;
}

.detail-divider { border: none; border-top: 1px solid var(--panel-line); margin: 20px 0 16px; }

.replay-heading { margin: 0 0 12px; font-size: 13.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-dim); }

.replay-tabs { display: flex; gap: 8px; margin-bottom: 12px; }

.replay-tab {
  flex: 1;
  padding: 8px 6px;
  border-radius: 8px;
  border: 1px solid var(--panel-line);
  background: transparent;
  color: var(--ink-dim);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.replay-tab:hover { color: var(--ink); }
.replay-tab.active { background: var(--teal); color: #0c1220; border-color: var(--teal); }

.replay-custom {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
}
.replay-custom label { font-size: 11.5px; color: var(--ink-dim); display: flex; flex-direction: column; gap: 5px; }
.replay-custom input {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--panel-line);
  border-radius: 7px;
  color: var(--ink);
  padding: 7px 8px;
  font-size: 12.5px;
  color-scheme: dark;
}

.btn.small { padding: 7px 12px; font-size: 12.5px; }

.replay-empty {
  font-size: 12.5px;
  color: var(--ink-dim);
  font-style: italic;
  padding: 10px 2px;
}

.replay-player {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  padding: 14px;
}

.replay-scrub-row {
  display: flex;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-dim);
  margin-bottom: 6px;
}

.replay-scrub { width: 100%; accent-color: var(--teal); }

.replay-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
}

.replay-speeds { display: flex; gap: 6px; }

.speed-btn {
  background: transparent;
  border: 1px solid var(--panel-line);
  color: var(--ink-dim);
  border-radius: 6px;
  padding: 6px 9px;
  font-size: 11.5px;
  font-family: var(--mono);
  cursor: pointer;
}
.speed-btn:hover { color: var(--ink); }
.speed-btn.active { background: var(--amber); color: #1a1200; border-color: var(--amber); }

.replay-live-stat {
  margin-top: 12px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-dim);
  text-align: center;
}

@media (max-width: 720px) {
  .detail-panel { width: 100vw; max-width: 100vw; }
}

.maplibregl-popup-content {
  background: var(--panel);
  color: var(--ink);
  font-family: var(--sans);
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  font-size: 12px;
}

.maplibregl-popup-content strong { color: var(--teal); }
.maplibregl-popup-tip { border-top-color: var(--panel) !important; }
