:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1a1d21;
  --text-dim: #5f6570;
  --border: #dde1e6;
  --accent: #2a6df4;
  --accent-text: #ffffff;
  --danger: #d64545;
  --ok: #1e9e5a;
}

:root[data-theme="dark"] {
  --bg: #14161a;
  --surface: #1e2126;
  --text: #eceef1;
  --text-dim: #9aa1ac;
  --border: #2c3038;
  --accent: #4c8dff;
  --accent-text: #0b1220;
  --danger: #ff6b6b;
  --ok: #35c281;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161a;
    --surface: #1e2126;
    --text: #eceef1;
    --text-dim: #9aa1ac;
    --border: #2c3038;
    --accent: #4c8dff;
    --accent-text: #0b1220;
    --danger: #ff6b6b;
    --ok: #35c281;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 20px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

header h1 { font-size: 18px; margin: 0; }

header nav { display: flex; gap: 8px; align-items: center; }

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

button {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  cursor: pointer;
}

button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

button.danger { background: var(--danger); color: white; }

button:disabled { opacity: 0.5; cursor: default; }

input, select, textarea {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  width: 100%;
}

.container { max-width: 1200px; margin: 0 auto; padding: 20px; }

/* Full-screen overlay panels (vehicles/fatigue/reports/security), opened
   from the hamburger drawer. They escape .container's max-width/padding
   via fixed positioning so they cover the whole viewport like the map. */
.overlay-panel {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 30;
  overflow-y: auto;
  padding: calc(20px + env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom));
}
.overlay-header {
  display: flex; align-items: center; gap: 16px;
  max-width: 1200px; margin: 0 auto 16px;
}
.overlay-header h2 { margin: 0; }
.overlay-header .link-btn { width: auto; white-space: nowrap; }
.overlay-panel .grid, .overlay-panel > div:not(.overlay-header) { max-width: 1200px; margin-left: auto; margin-right: auto; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
}

.grid { display: grid; grid-template-columns: 340px 1fr; gap: 16px; }
@media (max-width: 900px) { .grid { grid-template-columns: 1fr; } }

.form-row { margin-bottom: 10px; }
.form-row label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 4px; }

.error { color: var(--danger); font-size: 13px; margin-top: 6px; }
.hint { color: var(--text-dim); font-size: 12px; }

.field-icon-btn, .link-btn { flex-shrink: 0; }
.field-icon-btn.armed, .link-btn.armed { outline: 2px solid var(--accent); }

.tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
.tabs button { background: none; color: var(--text-dim); border-radius: 0; padding: 8px 12px; }
.tabs button.active { color: var(--accent); border-bottom: 2px solid var(--accent); }

.vtype-toggle { display: flex; gap: 4px; margin-bottom: 4px; }
.vtype-toggle button { background: none; color: var(--text-dim); border: 1px solid var(--border); padding: 6px 10px; }
.vtype-toggle button.active { color: var(--accent-text); background: var(--accent); border-color: var(--accent); }

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.list-item:last-child { border-bottom: none; }

/* ---------- Route planner: floating cards over a full-bleed map ---------- */

.route-map-area {
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 1;
}

/* Oversized so rotating it heading-up during nav never exposes blank
   corners past the edge of the (overflow:hidden) .route-map-area mask. */
#map-rotor {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 150vmax;
  height: 150vmax;
  margin-top: -75vmax;
  margin-left: -75vmax;
  transform: rotate(0deg);
  transition: transform 0.25s linear;
}
#map { position: absolute; inset: 0; width: 100%; height: 100%; }

.route-card.floating {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top));
  left: 16px;
  width: 340px;
  max-width: calc(100% - 32px);
  max-height: calc(100% - 32px);
  overflow-y: auto;
  background: var(--surface);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  z-index: 10;
}

.route-card.results-card { top: 16px; bottom: auto; }

.location-field {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
}
.location-field input {
  border: none;
  background: transparent;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
}
.location-field input:focus { outline: none; border-bottom-color: var(--accent); }

.marker-dot {
  width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}
.marker-pin {
  width: 12px; height: 12px; flex-shrink: 0;
  background: var(--danger);
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
}

.field-icon-btn {
  background: none; border: none; padding: 4px; font-size: 15px; line-height: 1;
}

.swap-fab {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  margin: -4px 0 -4px 20px;
  padding: 0; font-size: 14px;
}

.link-btn {
  background: none; color: var(--accent); border: none; padding: 6px 0;
  font-size: 13px; text-align: left; width: 100%;
}

.route-options { margin: 8px 0; border-top: 1px solid var(--border); padding-top: 8px; }
.route-options summary { cursor: pointer; color: var(--text-dim); font-size: 13px; padding: 4px 0; }
.route-options[open] summary { margin-bottom: 6px; }

.plan-btn { width: 100%; padding: 10px; font-weight: 600; }

.fab {
  position: absolute;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; z-index: 10;
}
.fab.hud-btn { position: static; width: 40px; height: 40px; font-size: 16px; flex-shrink: 0; }

/* Top-left stack: hamburger, then compass/recenter, then satellite toggle */
.compass-fab { top: calc(72px + env(safe-area-inset-top)); left: 16px; }
.satellite-fab { top: calc(128px + env(safe-area-inset-top)); left: 16px; }
.satellite-fab.active { background: #2a6df4; color: #fff; border-color: #2a6df4; }
/* Top-right: persistent voice toggle */
.mute-fab { top: calc(16px + env(safe-area-inset-top)); right: 16px; }
/* Bottom-right: quick report shortcut — lifted clear of the bottom sheet's peek height */
.report-fab {
  right: 16px;
  bottom: calc(210px + env(safe-area-inset-bottom));
  background: #ffc632; color: #3a2c00; border-color: #e0ab00;
}

.speed-badge {
  position: absolute;
  left: 16px;
  bottom: calc(210px + env(safe-area-inset-bottom));
  width: 64px; height: 64px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 10;
}
.speed-badge span { font-size: 20px; font-weight: 700; line-height: 1; }
.speed-badge small { font-size: 10px; color: var(--text-dim); }

/* ---------- Hamburger menu + slide-out drawer (Waze-style) ---------- */

.menu-fab { top: calc(16px + env(safe-area-inset-top)); left: 16px; z-index: 40; font-size: 20px; }

.side-drawer { position: fixed; inset: 0; z-index: 100; }
.side-drawer.hidden { display: none; }

.side-drawer-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.4); }

.side-drawer-panel {
  position: absolute; top: 0; left: 0; bottom: 0;
  width: 280px; max-width: 85vw;
  background: var(--surface);
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 2px;
  overflow-y: auto;
}

.side-drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: 12px; margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
  font-size: 16px;
}
.side-drawer-header .link-btn { width: auto; font-size: 18px; padding: 0; }

.drawer-item {
  background: none; border: none; color: var(--text);
  text-align: left; padding: 12px 8px; border-radius: 8px;
  font-size: 15px; width: 100%;
}
.drawer-item:hover { background: var(--bg); }
.side-drawer-panel hr { border: none; border-top: 1px solid var(--border); margin: 8px 0; width: 100%; }

/* ---------- Waze-style bottom sheet ---------- */

.bottom-sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-height: 75%;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.25);
  z-index: 10;
}

.bottom-sheet-handle {
  width: 40px; height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 4px auto 12px;
}

.where-to-bar {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg);
  border-radius: 999px;
  padding: 10px 14px;
}
.where-to-bar input {
  border: none; background: transparent; padding: 0;
}
.where-to-bar input:focus { outline: none; }
.where-to-icon { font-size: 15px; flex-shrink: 0; }

.waze-quick-row { margin-top: 12px; }
.quick-dest-btn {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 6px;
  font-size: 12px;
}
.quick-dest-btn span { font-size: 20px; }

.sheet-section-label { font-size: 13px; color: var(--text-dim); margin: 14px 0 4px; }

/* ---------- Route options picker (Google Maps style list) ---------- */

.route-option-row {
  display: flex; flex-direction: column; gap: 2px;
  width: 100%; text-align: left;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 8px;
}
.route-option-row.recommended { border-color: var(--accent); border-width: 2px; }
.route-option-row .option-time { font-size: 18px; font-weight: 700; }
.route-option-row .option-detail { font-size: 13px; color: var(--text-dim); }
.route-option-row .option-badge {
  display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 999px;
  background: var(--accent); color: var(--accent-text); margin-left: 8px;
}

/* ---------- Waze-style driving HUD (shown only during active navigation) ---------- */

.nav-hud { position: absolute; inset: 0; z-index: 15; pointer-events: none; }

.nav-hud-top {
  position: absolute; top: 0; left: 0; right: 0;
  pointer-events: auto;
  background: var(--accent);
  color: var(--accent-text);
  display: flex; align-items: center; gap: 16px;
  padding: 18px 20px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}
.nav-hud-arrow { font-size: 40px; line-height: 1; flex-shrink: 0; }
.nav-hud-text { min-width: 0; }
.nav-hud-distance { font-size: 26px; font-weight: 700; line-height: 1.2; }
.nav-hud-instruction {
  font-size: 15px; opacity: 0.9;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.nav-hud-bottom {
  position: absolute; bottom: 0; left: 0; right: 0;
  pointer-events: auto;
  background: var(--surface);
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.2);
}
.nav-hud-eta { text-align: center; }
.nav-hud-eta-value { font-size: 18px; font-weight: 700; }
.nav-hud-eta-label { font-size: 11px; color: var(--text-dim); }
.nav-hud-remaining { flex: 1; font-size: 14px; color: var(--text-dim); }

.quick-row { display: flex; gap: 8px; margin-bottom: 12px; }
.quick-row button { flex: 1; }

.maneuver { padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }

.hidden { display: none !important; }

.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--border);
  color: var(--text-dim);
}

/* ---------- Desktop: Google-Maps-style left sidebar ---------- */
/* Reuses the same bottom-sheet/route-card markup as the mobile Waze-style
   layout — just re-docked into a full-height left column instead of a
   bottom sheet or floating top-left card. Only one of {bottom-sheet,
   route-options-card, route-summary-card} is ever visible at a time (see
   closeRoutePanels/showRouteOptions/renderRoute/setDrivingModeUI in
   app.js), so they can safely share the exact same box. */
@media (min-width: 900px) {
  .bottom-sheet,
  .route-card.floating.results-card {
    top: 16px;
    left: 16px;
    right: auto;
    bottom: 16px;
    width: 400px;
    max-width: 400px;
    max-height: none;
    border-radius: 14px;
  }
  .bottom-sheet-handle { display: none; }

  /* The sidebar occupies the whole left column, so the bottom-left speed
     badge needs to clear it instead of sitting underneath; the bottom-
     right report FAB was never under it and just needs its mobile
     above-the-sheet offset cleared (done in JS, see
     repositionFabsAboveSheet). */
  .speed-badge, .report-fab { bottom: 16px; }
  .speed-badge { left: calc(400px + 32px); }
}
