:root {
  --hero-bg: #07101C;
  --hero-bg-deep: #030914;
  --hero-panel: #0A1422;
  --blue-primary: #3ABEF9;
  --blue-secondary: #5B7CFA;
  --cyan-glow: #25D7FF;
  --cyan-soft: rgba(37, 215, 255, 0.18);
  --hd-green: #31D98B;
  --hd-green-soft: rgba(49, 217, 139, 0.15);
  --hd-orange: #F6B73C;
  --hd-orange-soft: rgba(246, 183, 60, 0.16);
  --hd-red: #FF5C69;
  --hd-red-soft: rgba(255, 92, 105, 0.15);
  --hd-text-white: #F7F9FC;
  --hd-text-primary: #E9EEF5;
  --hd-text-secondary: #8E9AAA;
  --hd-text-muted: #687487;
  --hd-border: rgba(255, 255, 255, 0.10);
  --hd-border-strong: rgba(255, 255, 255, 0.16);
  --hd-glass: rgba(10, 20, 34, 0.78);
  --hd-glass-light: rgba(255, 255, 255, 0.04);
  --shadow-panel: 0 24px 80px rgba(0, 0, 0, 0.45);
  --shadow-blue: 0 0 40px rgba(37, 215, 255, 0.18);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--hero-bg-deep);
  color: var(--hd-text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}

/* ===== App shell ===== */
.app {
  display: grid;
  grid-template-columns: 232px 1fr;
  grid-template-rows: 56px 1fr;
  height: 100vh;
  width: 100vw;
}

/* ===== Top bar ===== */
.topbar {
  grid-column: 1 / 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--hero-panel);
  border-bottom: 1px solid var(--hd-border);
  z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.hamburger {
  display: none; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 8px;
  background: transparent; border: 1px solid var(--hd-border);
  color: var(--hd-text-primary); cursor: pointer; flex-shrink: 0;
}
.hamburger svg { width: 18px; height: 18px; }
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 56px 0 0 0; z-index: 24;
  background: rgba(0,0,0,0.55);
}
.sidebar-backdrop.show { display: block; }
.topbar-back {
  font-size: 12px; font-weight: 600; color: var(--hd-text-secondary);
  text-decoration: none; padding-right: 4px; border-right: 1px solid var(--hd-border);
  margin-right: 2px; transition: color 0.15s ease;
}
.topbar-back:hover { color: var(--hd-text-white); }
.topbar-title { font-size: 14px; font-weight: 600; color: var(--hd-text-white); letter-spacing: 0.2px; }
.topbar-sub { font-size: 12px; color: var(--hd-text-muted); }
.demo-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--hd-orange-soft);
  border: 1px solid rgba(246, 183, 60, 0.35);
  color: var(--hd-orange);
  font-size: 11px; font-weight: 700; letter-spacing: 0.6px;
}
.demo-badge .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--hd-orange); }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.conn-pill {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--hd-text-secondary);
}
.conn-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--hd-green); box-shadow: 0 0 8px var(--hd-green); }
.user-chip {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, var(--blue-primary), var(--blue-secondary));
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #04101c;
}

/* ===== Sidebar ===== */
.sidebar {
  background: var(--hero-panel);
  border-right: 1px solid var(--hd-border);
  display: flex; flex-direction: column;
  padding: 18px 12px;
  z-index: 15;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 22px; }
.brand img { height: 24px; width: auto; display: block; }
.nav { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--hd-text-secondary);
  font-size: 13.5px; font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  user-select: none;
  position: relative;
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.85; }
.nav-item:hover { background: var(--hd-glass-light); color: var(--hd-text-primary); }
.nav-item.active {
  background: var(--cyan-soft);
  color: var(--hd-text-white);
}
.nav-item.active::before {
  content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px;
  background: var(--cyan-glow); border-radius: 2px;
  box-shadow: 0 0 10px var(--cyan-glow);
}
.nav-item .soon {
  margin-left: auto; font-size: 9.5px; font-weight: 700; letter-spacing: 0.4px;
  color: var(--hd-text-muted); background: rgba(255,255,255,0.06);
  padding: 2px 6px; border-radius: 6px;
}
.sidebar-footer {
  border-top: 1px solid var(--hd-border);
  margin-top: 8px; padding-top: 14px;
  font-size: 11px; color: var(--hd-text-muted); line-height: 1.5;
  padding-left: 8px; padding-right: 8px;
}
.sidebar-back {
  display: block; margin-bottom: 8px;
  font-size: 12px; font-weight: 600; color: var(--hd-text-secondary);
  text-decoration: none;
}
.sidebar-back:hover { color: var(--hd-text-white); }

/* ===== Main workspace ===== */
.workspace {
  position: relative;
  overflow: hidden;
  background: var(--hero-bg);
}
.screen { display: none; height: 100%; width: 100%; }
.screen.active { display: flex; flex-direction: column; }

/* ===== Live Tracking ===== */
.tracking-layout { display: grid; grid-template-columns: 280px 1fr; height: 100%; }
.fleet-panel {
  border-right: 1px solid var(--hd-border);
  display: flex; flex-direction: column;
  background: var(--hero-panel);
}
.fleet-panel-head { padding: 16px 16px 10px; border-bottom: 1px solid var(--hd-border); }
.fleet-panel-head h2 { margin: 0 0 4px; font-size: 15px; color: var(--hd-text-white); }
.fleet-summary { display: flex; gap: 14px; font-size: 11.5px; color: var(--hd-text-secondary); }
.fleet-summary b { color: var(--hd-text-white); font-size: 13px; }
.fleet-list { flex: 1; overflow-y: auto; padding: 8px; }
.vehicle-card {
  padding: 10px 12px; border-radius: var(--radius-sm);
  cursor: pointer; margin-bottom: 4px;
  border: 1px solid transparent;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.vehicle-card:hover { background: var(--hd-glass-light); }
.vehicle-card.selected { background: var(--cyan-soft); border-color: rgba(37,215,255,0.3); }
.vc-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.vc-id { font-size: 13px; font-weight: 700; color: var(--hd-text-white); }
.status-pill { font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 999px; letter-spacing: 0.3px; }
.status-Moving { background: var(--hd-green-soft); color: var(--hd-green); }
.status-Idle { background: var(--hd-orange-soft); color: var(--hd-orange); }
.status-Parked { background: rgba(94,163,255,0.15); color: #7db8ff; }
.status-Offline { background: rgba(255,255,255,0.06); color: var(--hd-text-muted); }
.vc-meta { font-size: 11.5px; color: var(--hd-text-secondary); display: flex; justify-content: space-between; }

.map-area { position: relative; overflow: hidden; }
.map-canvas { width: 100%; height: 100%; display: block; }

/* ── Leaflet street map: dark-theme its default controls to match the
   rest of the demo, and nudge the zoom control below our own overlay
   chips so they never overlap. ── */
.leaflet-container { background: #0b1220 !important; font: inherit !important; }
/* Dark-theme the standard (light) OSM tiles with a colour-invert filter,
   applied to the tile pane only — markers/route/controls sit in separate
   Leaflet panes and are unaffected. Widely-used technique for a dark map
   look without depending on a paid/gated dark tile style. */
.leaflet-tile-pane {
  filter: invert(1) hue-rotate(180deg) brightness(0.95) contrast(0.92) saturate(0.6);
}
.leaflet-top.leaflet-right { top: 56px; }
.leaflet-control-zoom {
  border: 1px solid var(--hd-border) !important;
  background: var(--hd-glass) !important;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow-panel) !important;
  border-radius: 8px !important; overflow: hidden;
}
.leaflet-control-zoom a {
  background: transparent !important; color: var(--hd-text-white) !important;
  border-color: var(--hd-border) !important;
}
.leaflet-control-zoom a:hover { background: rgba(255,255,255,.06) !important; }
.leaflet-control-attribution {
  background: rgba(5,11,22,.65) !important;
  color: var(--hd-text-muted) !important;
  font-size: 10.5px !important;
}
.leaflet-control-attribution a { color: var(--hd-text-secondary) !important; }

/* Fleet vehicle markers on the street map */
.leaflet-marker-icon.vehicle-marker-wrap { background: none; border: none; }
.vehicle-marker {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  cursor: pointer;
  transform: translate(-50%, -50%); /* divIcon has no intrinsic size to anchor by */
  width: max-content;
}
.vm-dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--marker-color);
  border: 1.5px solid rgba(255,255,255,.65);
  box-shadow: 0 0 10px var(--marker-color);
  transition: transform .15s ease;
}
.vehicle-marker:hover .vm-dot { transform: scale(1.15); }
.vehicle-marker.selected .vm-dot {
  transform: scale(1.2);
  box-shadow: 0 0 0 6px rgba(37,215,255,.18), 0 0 12px var(--marker-color);
  border-color: #25D7FF;
}
.vm-label {
  font-size: 10.5px; font-weight: 700; color: rgba(255,255,255,.9);
  text-shadow: 0 1px 3px rgba(0,0,0,.85);
  white-space: nowrap;
  pointer-events: none;
}
.map-overlay-top {
  position: absolute; top: 14px; left: 14px; right: 14px;
  display: flex; justify-content: space-between; align-items: flex-start;
  pointer-events: none;
}
.map-chip {
  background: var(--hd-glass); border: 1px solid var(--hd-border);
  backdrop-filter: blur(10px);
  border-radius: var(--radius-sm);
  padding: 8px 12px; font-size: 11.5px; color: var(--hd-text-secondary);
  pointer-events: auto;
}
.map-chip b { color: var(--hd-text-white); }

.vehicle-detail {
  position: absolute; bottom: 16px; left: 16px;
  width: 300px;
  background: var(--hd-glass); border: 1px solid var(--hd-border);
  backdrop-filter: blur(14px);
  border-radius: var(--radius-md);
  padding: 16px; box-shadow: var(--shadow-panel);
  display: none;
}
.vehicle-detail.show { display: block; }
.vd-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.vd-head h3 { margin: 0; font-size: 15px; color: var(--hd-text-white); }
.vd-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.vd-item label { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--hd-text-muted); margin-bottom: 3px; }
.vd-item span { font-size: 13px; color: var(--hd-text-primary); font-weight: 600; }

/* ===== Live Video ===== */
.video-layout { display: flex; flex-direction: column; height: 100%; }
.video-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--hd-border);
  background: var(--hero-panel);
}
.video-vehicle-select { display: flex; align-items: center; gap: 10px; }
.video-vehicle-select select {
  background: var(--hd-glass-light); border: 1px solid var(--hd-border);
  color: var(--hd-text-white); font-size: 13px; padding: 7px 10px; border-radius: var(--radius-sm);
}
.video-stats { display: flex; gap: 22px; }
.video-stats .stat { font-size: 11px; color: var(--hd-text-muted); }
.video-stats .stat b { display: block; font-size: 13px; color: var(--hd-text-primary); margin-top: 2px; }
.video-body { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; }
.cam-grid {
  background: #000;
  width: min(100%, 1040px);
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-panel);
  border: 1px solid var(--hd-border-strong);
  position: relative;
}
/* fleet-cams.mp4 is itself a pre-composed, equal 2x2 FRONT/DRIVER/LEFT/RIGHT grid
   with labels + LIVE indicators already baked in — render it as a single surface. */
.cam-grid-single video { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-tile { position: relative; background: #000; overflow: hidden; }
.cam-tile video, .cam-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-label {
  position: absolute; top: 10px; left: 10px;
  display: flex; align-items: center; gap: 6px;
  background: rgba(0,0,0,0.55); backdrop-filter: blur(4px);
  padding: 4px 9px 4px 7px; border-radius: 6px;
  font-size: 11px; font-weight: 700; color: #fff; letter-spacing: 0.3px;
}
.cam-label .live-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--hd-red); animation: blink 1.4s infinite; }
.cam-play-overlay {
  position: absolute; inset: 0; width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(3, 9, 20, 0);
  border: none; padding: 0; margin: 0; cursor: pointer;
  transition: background 0.15s ease;
}
.cam-play-overlay:hover { background: rgba(3, 9, 20, 0.12); }
.cam-play-overlay svg {
  box-sizing: content-box;
  width: 40px; height: 40px; color: #fff;
  padding: 24px;
  border-radius: 50%;
  background: rgba(5, 12, 22, 0.72);
  border: 1.5px solid rgba(255,255,255,0.35);
  backdrop-filter: blur(4px);
  box-shadow: 0 10px 34px rgba(0,0,0,0.55);
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.cam-play-overlay:hover svg { transform: scale(1.06); }
.cam-grid-single.is-playing .cam-play-overlay svg { opacity: 0; }
.cam-grid-single.is-playing .cam-play-overlay:hover { background: transparent; }

.video-playback-controls {
  display: flex; justify-content: center; gap: 10px;
  padding: 12px 20px 0;
}
.playback-btn {
  display: flex; align-items: center; gap: 7px;
  font-size: 12.5px; font-weight: 600; color: var(--hd-text-primary);
  background: var(--hd-glass-light); border: 1px solid var(--hd-border);
  padding: 8px 16px; border-radius: 999px; cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.playback-btn:hover { background: rgba(255,255,255,0.09); border-color: var(--hd-border-strong); }
.playback-btn svg { width: 14px; height: 14px; }

.video-controls { display: flex; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--hd-border); background: var(--hero-panel); }
.vctrl-btn {
  font-size: 12px; color: var(--hd-text-secondary); background: var(--hd-glass-light);
  border: 1px solid var(--hd-border); padding: 7px 14px; border-radius: var(--radius-sm);
  cursor: pointer;
}
.vctrl-btn.active { background: var(--cyan-soft); color: var(--hd-text-white); border-color: rgba(37,215,255,0.35); }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0.25; } }

/* ===== AI Safety ===== */
.safety-layout { display: grid; grid-template-columns: 1fr 340px; height: 100%; }
.safety-main { padding: 20px 24px; overflow-y: auto; }
.safety-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.kpi-card {
  background: var(--hero-panel); border: 1px solid var(--hd-border); border-radius: var(--radius-md);
  padding: 14px 16px;
}
.kpi-card label { font-size: 11px; color: var(--hd-text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.kpi-card .val { font-size: 24px; font-weight: 700; color: var(--hd-text-white); margin-top: 6px; }
.kpi-card .val.orange { color: var(--hd-orange); }
.kpi-card .val.red { color: var(--hd-red); }
.kpi-card .val.green { color: var(--hd-green); }

.event-feed-title { font-size: 13px; color: var(--hd-text-secondary); margin: 10px 0 10px; text-transform: uppercase; letter-spacing: 0.5px; }
.event-row {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--hero-panel); border: 1px solid var(--hd-border);
  margin-bottom: 8px; cursor: pointer;
}
.event-row:hover { border-color: var(--hd-border-strong); }
.event-row.selected { border-color: rgba(37,215,255,0.4); background: var(--cyan-soft); }
.ev-sev { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.ev-sev.High { background: var(--hd-red); box-shadow: 0 0 8px var(--hd-red); }
.ev-sev.Moderate { background: var(--hd-orange); }
.ev-sev.Low { background: var(--hd-green); }
.ev-time { font-size: 11.5px; color: var(--hd-text-muted); width: 70px; flex-shrink: 0; }
.ev-veh { font-size: 12.5px; font-weight: 700; color: var(--hd-text-white); width: 70px; flex-shrink: 0; }
.ev-type { font-size: 13px; color: var(--hd-text-primary); flex: 1; }
.ev-sev-label { font-size: 11px; color: var(--hd-text-secondary); }

.safety-side { border-left: 1px solid var(--hd-border); background: var(--hero-panel); padding: 18px; overflow-y: auto; }
.safety-side h3 { font-size: 14px; color: var(--hd-text-white); margin: 0 0 14px; }
.detail-empty { font-size: 12.5px; color: var(--hd-text-muted); line-height: 1.6; }
.detail-grid .di { padding: 10px 0; border-bottom: 1px solid var(--hd-border); }
.detail-grid .di label { display: block; font-size: 10px; color: var(--hd-text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 3px; }
.detail-grid .di span { font-size: 13.5px; color: var(--hd-text-primary); font-weight: 600; }
.detail-desc { font-size: 12.5px; color: var(--hd-text-secondary); line-height: 1.6; margin-top: 12px; }

/* ===== Simple / lightweight screens ===== */
.simple-screen { padding: 24px; overflow-y: auto; }
.simple-screen h2 { margin: 0 0 4px; font-size: 18px; color: var(--hd-text-white); }
.simple-screen .sub { font-size: 12.5px; color: var(--hd-text-muted); margin-bottom: 20px; }
.table {
  width: 100%; border-collapse: collapse; background: var(--hero-panel);
  border: 1px solid var(--hd-border); border-radius: var(--radius-md); overflow: hidden;
}
.table th {
  text-align: left; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--hd-text-muted); padding: 12px 16px; border-bottom: 1px solid var(--hd-border);
}
.table td { padding: 12px 16px; font-size: 13px; color: var(--hd-text-primary); border-bottom: 1px solid var(--hd-border); }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--hd-glass-light); }

.report-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 4px; }
.report-card { background: var(--hero-panel); border: 1px solid var(--hd-border); border-radius: var(--radius-md); padding: 18px; }
.report-card h4 { margin: 0 0 4px; font-size: 13px; color: var(--hd-text-white); }
.report-card p { margin: 0; font-size: 11.5px; color: var(--hd-text-muted); line-height: 1.5; }
.report-card .bar-track { margin-top: 12px; height: 6px; border-radius: 4px; background: rgba(255,255,255,0.06); overflow: hidden; }
.report-card .bar-fill { height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--blue-primary), var(--cyan-glow)); }

/* scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* ===== Responsive ===== */
@media (max-width: 1000px) {
  .app { grid-template-columns: 72px 1fr; }
  .brand span, .nav-item span.label { display: none; }
  .nav-item { justify-content: center; }
  .nav-item svg { margin: 0; }
  .sidebar-footer { display: none; }
  .safety-layout { grid-template-columns: 1fr; }
  .safety-side { display: none; }
  .tracking-layout { grid-template-columns: 220px 1fr; }
}
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 56px 1fr; }
  .hamburger { display: flex; }
  .topbar-title { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar-sub { display: none; }
  .topbar-back { display: none; }
  .demo-badge { font-size: 10px; padding: 4px 8px; white-space: nowrap; }
  .demo-badge .demo-text { display: none; }
  .demo-badge::after { content: "DEMO"; }
  .conn-pill .conn-text { display: none; }
  .topbar-right { gap: 8px; }

  .sidebar {
    position: fixed; top: 56px; left: 0; bottom: 0; width: 232px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 25;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar .nav-item span.label, .sidebar .brand span { display: inline; }
  .sidebar .nav-item { justify-content: flex-start; }
  .sidebar-footer { display: block; }

  .tracking-layout { grid-template-columns: 1fr; grid-template-rows: 160px 1fr; }
  .fleet-panel { border-right: none; border-bottom: 1px solid var(--hd-border); }
  .fleet-list { display: flex; overflow-x: auto; gap: 8px; }
  .vehicle-card { min-width: 180px; }
  .safety-kpis { grid-template-columns: repeat(2, 1fr); }
  .report-grid { grid-template-columns: 1fr; }
  .video-stats { display: none; }
}
