:root, [data-bs-theme="light"] {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --raised: #f8fafc;
  --border: #e5e9f2;
  --text: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;
  --amber: #d97706;
  --teal: #059669;
  --danger: #dc2626;
  --primary: #2563eb;
  --primary-soft: rgba(37, 99, 235, 0.08);
  --brand: var(--primary);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 1px rgba(15, 23, 42, 0.03);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.10), 0 2px 8px rgba(15, 23, 42, 0.06);
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'Fira Code', monospace;
}
[data-bs-theme="dark"] {
  --bg: #090d16;
  --panel: #0f172a;
  --raised: #1e293b;
  --border: rgba(51, 65, 85, 0.6);
  --text: #f8fafc;
  --muted: #94a3b8;
  --faint: #64748b;
  --amber: #f59e0b;
  --teal: #10b981;
  --danger: #f43f5e;
  --primary: #3b82f6;
  --primary-soft: rgba(59, 130, 246, 0.12);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.45);
}

* { scrollbar-width: thin; scrollbar-color: var(--faint) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--faint); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

body {
  font-family: var(--font-sans);
  background-color: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
}

.font-monospace { font-family: var(--font-mono) !important; letter-spacing: 0; }

a { color: var(--primary); }

/* ---------- shell ---------- */
.app-shell { min-height: calc(100vh - 56px); }

.topbar {
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 1020;
  box-shadow: var(--shadow-sm);
}

.brand-badge {
  width: 32px;
  height: 32px;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

.brand-name { letter-spacing: -0.03em; color: var(--text); font-weight: 800; }

.admin-nav {
  width: 230px;
  min-height: calc(100vh - 56px);
  flex-shrink: 0;
  background: var(--panel);
  border-color: var(--border) !important;
}

.admin-tab {
  color: var(--muted);
  font-weight: 500;
  border-radius: 8px;
  transition: background 0.15s ease, color 0.15s ease;
}

.admin-tab:hover:not(.active) { background: var(--raised); color: var(--text); }

.admin-tab.active {
  background: var(--brand, var(--primary)) !important;
  color: #fff !important;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.role-badge { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; }

.alert-bell {
  position: relative;
  cursor: pointer;
  font-size: 18px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.alert-bell:hover { background: var(--raised); border-color: var(--faint); }
.alert-bell .badge { position: absolute; top: -8px; right: -8px; font-size: 10px; }

.admin-main {
  background-color: var(--bg) !important;
  background-image:
    radial-gradient(circle at 8% 0%, var(--primary-soft) 0%, transparent 40%),
    radial-gradient(circle at 92% 100%, rgba(245, 158, 11, 0.05) 0%, transparent 40%);
}

/* ---------- cards / kpi / empty ---------- */
.card {
  background-color: var(--panel) !important;
  border: 1px solid var(--border) !important;
  border-radius: 14px !important;
  box-shadow: var(--shadow-md);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

.kpi-card { border-left: 4px solid var(--brand, var(--primary)); }
.kpi-value { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.02em; }
.empty-state { padding: 2.5rem 1rem; text-align: center; color: var(--muted); }
.table-search { max-width: 280px; }
.toast-box .toast { min-width: 280px; box-shadow: var(--shadow-lg); border-radius: 10px; }

/* ---------- landing ---------- */
.hero {
  background: linear-gradient(160deg, #eef4ff 0%, #f8fafc 55%, #f4f6fb 100%);
  border-bottom: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}

[data-bs-theme="dark"] .hero {
  background: linear-gradient(160deg, #0f1a33 0%, #0b1120 55%, #090d16 100%);
}

.hero::before {
  content: '';
  position: absolute;
  inset: -20% -10% auto auto;
  width: 480px;
  height: 480px;
  background: radial-gradient(circle, var(--primary-soft) 0%, transparent 70%);
  pointer-events: none;
}

.feature-card { transition: transform .18s ease, box-shadow .18s ease; }
.feature-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }

/* ---------- forms & inputs ---------- */
.form-control, .form-select {
  background-color: var(--panel) !important;
  border: 1px solid var(--border) !important;
  color: var(--text) !important;
  border-radius: 8px !important;
  font-size: 13.5px;
  transition: all 0.2s ease;
}

.form-control::placeholder { color: var(--faint); }

.form-control:focus, .form-select:focus {
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 3px var(--primary-soft) !important;
}

.btn {
  border-radius: 8px !important;
  font-weight: 500;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

.btn-primary {
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}

.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(37, 99, 235, 0.3); }

.btn-dark {
  background: linear-gradient(135deg, #1e293b, #0f172a) !important;
  border-color: var(--border) !important;
  color: #fff !important;
}

.btn-dark:hover {
  background: linear-gradient(135deg, #334155, #1e293b) !important;
  border-color: var(--primary) !important;
  transform: translateY(-1px);
}

/* ---------- tables ---------- */
.table {
  --bs-table-bg: transparent;
  --bs-table-hover-bg: var(--raised);
  color: var(--text);
  border-color: var(--border);
}

.table th {
  background-color: var(--raised) !important;
  color: var(--muted) !important;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border) !important;
}

/* ---------- live indicator (navbar) ---------- */
.live-indicator { background-color: var(--raised) !important; border-color: var(--border) !important; }

.live-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber);
  animation: live-pulse 2s infinite ease-in-out;
}

.live-dot.lost {
  background: var(--danger);
  box-shadow: 0 0 8px var(--danger);
  animation: none;
}

@keyframes live-pulse {
  0% { transform: scale(0.9); opacity: 1; }
  50% { transform: scale(1.2); opacity: 0.6; }
  100% { transform: scale(0.9); opacity: 1; }
}

/* ---------- map sidebar rows (app.js renders these) ---------- */
.vehicle-list { flex: 1; overflow-y: auto; }

.vehicle-row {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  transition: background 0.15s ease;
}

.vehicle-row:hover { background: var(--raised); }
.vehicle-row.selected { background: var(--primary-soft); box-shadow: inset 3px 0 0 var(--primary); }

.row-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 6px var(--teal);
}

.row-dot.offline { background: var(--faint); box-shadow: none; }

.row-main { min-width: 0; }

.row-name {
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.vehicle-row.selected .row-name { color: var(--primary); }

.row-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  display: flex;
  gap: 10px;
  margin-top: 2px;
}

.row-meta .stale { color: var(--danger); }
.vehicle-row.offline .row-name { color: var(--faint); }

.no-vehicles {
  padding: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
}

/* ---------- map ---------- */
#map { width: 100%; height: 100%; background: var(--bg); }

.map-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
  z-index: 500;
  background: rgba(244, 246, 251, 0.85);
  backdrop-filter: blur(8px);
}

[data-bs-theme="dark"] .map-loading { background: rgba(9, 13, 22, 0.85); }

.leaflet-container { background: var(--raised) !important; }

[data-bs-theme="dark"] .leaflet-tile-pane {
  filter: brightness(0.85) contrast(1.1) hue-rotate(200deg) invert(1) saturate(0.3);
}

/* markers: live pulse */
#map .leaflet-marker-icon { transition: transform 1s linear; }
#map.leaflet-zoom-anim .leaflet-marker-icon { transition: none; }

.marker-dot {
  position: relative;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--teal);
  border: 2px solid var(--panel);
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.6);
}

.marker-dot.selected {
  background: var(--amber);
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.8);
}

.marker-dot.offline {
  background: var(--faint);
  opacity: 0.5;
  box-shadow: none;
}

.marker-dot.online .pulse {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid currentColor;
  color: var(--amber);
  animation: pulse 2s ease-out infinite;
  pointer-events: none;
}

/* heading arrow: centered on the marker, rotates around the dot center */
.marker-dot .arrow {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 12px;
  height: 18px;
  margin-left: -6px;
  margin-top: -9px;
  transform-origin: 6px 9px;
  pointer-events: none;
}
.marker-dot .arrow svg {
  width: 12px;
  height: 18px;
  fill: #fff;
  stroke: rgba(0, 0, 0, 0.45);
  stroke-width: 0.8;
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.6));
}

@keyframes pulse {
  0%   { transform: scale(0.6); opacity: 0.9; }
  70%  { transform: scale(1.6); opacity: 0; }
  100% { transform: scale(1.6); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .marker-dot.online .pulse { animation: none; opacity: 0.4; }
}

.marker-dot.selected { width: 18px; height: 18px; }

/* trail */
.trail { stroke: var(--teal); stroke-width: 3; stroke-opacity: 0.85; stroke-dasharray: 6 6; }

/* geofence zones */
.geofence {
  stroke: var(--amber);
  stroke-width: 1.5;
  stroke-dasharray: 4 4;
  fill: rgba(242, 169, 59, 0.12);
}

/* alert banners */
.alert-banner {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 600;
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid var(--teal);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 12px;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  animation: fade-in 0.2s ease-out;
}

.alert-banner.warn { border-color: var(--danger); }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* ---------- popups ---------- */
.leaflet-popup-content-wrapper {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
}

.leaflet-popup-content { margin: 10px 14px; font-size: 12.5px; }

.leaflet-popup-tip { background: var(--panel); border: 1px solid var(--border); }

.popup-name { font-weight: 700; font-size: 14px; margin-bottom: 4px; color: var(--primary); }
.popup-data { font-family: var(--font-mono); color: var(--muted); font-size: 11.5px; line-height: 1.7; }
.popup-data .online-tag { color: var(--teal); font-weight: 600; }
.popup-data .offline-tag { color: var(--danger); font-weight: 600; }

.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
.leaflet-bar a { background: var(--panel) !important; color: var(--text) !important; border-color: var(--border) !important; }
.leaflet-bar a:hover { background: var(--raised) !important; }
.leaflet-control-attribution { background: var(--panel) !important; color: var(--faint) !important; font-size: 10px !important; opacity: 0.85; }
.leaflet-control-attribution a { color: var(--primary) !important; }

/* ---------- misc ---------- */
.assign-list { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }

/* ==========================================================================
   MOBILE & RESPONSIVE BREAKPOINTS (UI/UX PRO MAX GUIDELINES)
   ========================================================================== */

@media (max-width: 768px) {
  /* Touch target accessibility (min 44px height) */
  .btn, .form-control, .form-select, .nav-link, .vehicle-row {
    min-height: 44px;
  }

  /* Flex Layout direction overrides for mobile screens */
  .d-flex:has(> .admin-nav) {
    flex-direction: column !important;
  }

  .admin-main {
    padding: 1rem !important;
    min-height: auto !important;
  }

  /* Admin Sidebar Nav -> Horizontal Scrollable Pill Bar on Mobile */
  .admin-nav {
    width: 100% !important;
    min-height: auto !important;
    flex-direction: row !important;
    overflow-x: auto;
    white-space: nowrap;
    border-end: none !important;
    border-bottom: 1px solid var(--border) !important;
    padding: 8px 12px !important;
    gap: 6px !important;
    -webkit-overflow-scrolling: touch;
  }

  .admin-tab {
    padding: 8px 14px !important;
    font-size: 13px;
    flex-shrink: 0;
  }

  .admin-tab svg {
    display: none;
  }

  /* Top Navbar Mobile Adjustments */
  .navbar {
    padding: 8px 12px !important;
    flex-wrap: wrap;
    gap: 8px;
  }

  .navbar-text {
    display: none !important;
  }

  /* Live Map & Vehicle Sidebar Responsive Layout */
  .fleet-map-container {
    flex-direction: column-reverse !important;
    height: calc(100vh - 56px) !important;
  }

  .map-wrap {
    height: 60vh !important;
    flex-grow: 1 !important;
  }

  .map-sidebar {
    width: 100% !important;
    height: 40vh !important;
    border-end: none !important;
    border-top: 1px solid var(--border) !important;
    padding: 10px !important;
  }

  /* Table Touch Scrolling & Spacing */
  .table {
    font-size: 12.5px;
  }

  .table th, .table td {
    padding: 8px 10px;
    white-space: nowrap;
  }

  .card {
    border-radius: 12px !important;
    margin-bottom: 1rem !important;
  }

  .card-body {
    padding: 1rem !important;
  }

  /* Modals on Mobile */
  .modal-dialog {
    margin: 0.5rem;
  }

  .alert-banner {
    left: 8px;
    right: 8px;
    bottom: 8px;
    max-width: none;
  }
}

@media (max-width: 480px) {
  .brand-badge {
    width: 28px !important;
    height: 28px !important;
  }
  .brand-badge svg {
    width: 16px !important;
    height: 16px !important;
  }
  .navbar-brand {
    font-size: 15px !important;
  }
  .btn-sm {
    padding: 6px 10px !important;
    font-size: 12px !important;
  }
  h1.h4 {
    font-size: 1.15rem !important;
  }
  .live-indicator {
    font-size: 11px !important;
    padding: 2px 8px !important;
  }
}

/* ==========================================================================
   SINGLE VEHICLE LIVE TRACKING HUD
   ========================================================================== */
.vehicle-live-container {
  height: calc(100vh - 56px);
  position: relative;
  display: flex;
  overflow: hidden;
}

.live-hud-panel {
  width: 360px;
  max-width: 100%;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
  transition: transform 0.3s ease;
}

.telemetry-card {
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}

.speed-display {
  font-size: 2.25rem;
  font-weight: 800;
  line-height: 1;
  font-family: var(--font-mono);
  color: var(--primary);
}

.compass-container {
  width: 48px;
  height: 48px;
  position: relative;
  border: 2px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--panel);
}

.compass-needle {
  width: 3px;
  height: 36px;
  position: absolute;
  top: 4px;
  left: calc(50% - 1.5px);
  transform-origin: center center;
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.compass-needle::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  border-left: 3px solid transparent;
  border-right: 3px solid transparent;
  border-bottom: 14px solid var(--danger);
}

.compass-needle::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 0;
  border-left: 3px solid transparent;
  border-right: 3px solid transparent;
  border-top: 14px solid var(--faint);
}

.fix-history-item {
  font-size: 11.5px;
  font-family: var(--font-mono);
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--raised);
  border: 1px solid var(--border);
  margin-bottom: 4px;
}

@media (max-width: 768px) {
  .vehicle-live-container {
    flex-direction: column-reverse;
  }
  .live-hud-panel {
    width: 100%;
    height: 45vh;
    border-right: none;
    border-top: 1px solid var(--border);
  }
  .vehicle-live-container .map-wrap {
    height: 55vh;
  }
}
