/* ========== RESET & TOKENS ========== */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: #e2e8f0;
  background: #0a0e1a;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

:root {
  /* Dark (default) */
  --bg-0: #0a0e1a;
  --bg-1: #111827;
  --bg-2: #1a2238;
  --bg-3: #243049;
  --border: #2a3656;
  --border-light: #364263;
  --text-0: #f8fafc;
  --text-1: #e2e8f0;
  --text-2: #94a3b8;
  --text-3: #64748b;
  --accent: #3b82f6;
  --accent-light: #60a5fa;
  --accent-dark: #2563eb;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.35);
  --shadow-lg: 0 20px 50px rgba(0,0,0,0.5);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --map-overlay-bg: rgba(17,24,39,0.92);
  --grid-stroke: rgba(255,255,255,0.03);
}

body.light {
  --bg-0: #f1f5f9;
  --bg-1: #ffffff;
  --bg-2: #f8fafc;
  --bg-3: #e2e8f0;
  --border: #e2e8f0;
  --border-light: #cbd5e1;
  --text-0: #0f172a;
  --text-1: #1e293b;
  --text-2: #64748b;
  --text-3: #94a3b8;
  --accent: #2563eb;
  --accent-light: #3b82f6;
  --accent-dark: #1d4ed8;
  --shadow-sm: 0 1px 2px rgba(15,23,42,0.05);
  --shadow-md: 0 4px 12px rgba(15,23,42,0.08);
  --shadow-lg: 0 20px 50px rgba(15,23,42,0.15);
  --map-overlay-bg: rgba(255,255,255,0.96);
  --grid-stroke: rgba(15,23,42,0.04);
}

body.light .login-hero {
  background:
    radial-gradient(circle at 30% 20%, rgba(37,99,235,0.18), transparent 50%),
    radial-gradient(circle at 70% 80%, rgba(16,185,129,0.12), transparent 50%),
    linear-gradient(135deg, #eff6ff 0%, #f1f5f9 100%);
}
body.light .hero-logo,
body.light .hero-content h1 { color: var(--text-0); }
body.light .login-form-wrap { background: var(--bg-1); }
body.light .leaflet-control-zoom a {
  background: rgba(255,255,255,0.96) !important;
  color: var(--text-0) !important;
}
body.light .leaflet-control-zoom a:hover { background: var(--bg-2) !important; }
body.light .leaflet-popup-content-wrapper {
  background: var(--bg-1);
  color: var(--text-0);
  border: 1px solid var(--border);
}
body.light .leaflet-popup-tip { background: var(--bg-1); border: 1px solid var(--border); }
body.light .leaflet-control-attribution {
  background: rgba(255,255,255,0.85) !important;
  color: var(--text-2) !important;
}

.hidden { display: none !important; }

button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

/* ========== LOGIN ========== */
#login-view {
  height: 100%;
  width: 100%;
  background: var(--bg-0);
}
.login-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: 100%;
}
@media (max-width: 900px) {
  .login-split { grid-template-columns: 1fr; }
  .login-hero { display: none; }
}

.login-hero {
  position: relative;
  background:
    radial-gradient(circle at 30% 20%, rgba(59,130,246,0.25), transparent 50%),
    radial-gradient(circle at 70% 80%, rgba(16,185,129,0.15), transparent 50%),
    linear-gradient(135deg, #0f1a35 0%, #0a0e1a 100%);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px;
}
.login-hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--grid-stroke) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-stroke) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
}
.hero-content {
  position: relative;
  z-index: 1;
  max-width: 480px;
}
.hero-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 22px;
  font-weight: 700;
  color: var(--text-0);
  margin-bottom: 48px;
}
.hero-logo svg { width: 32px; height: 32px; color: var(--accent-light); }
.hero-content h1 {
  font-size: 42px;
  font-weight: 800;
  line-height: 1.15;
  margin: 0 0 20px;
  color: var(--text-0);
  letter-spacing: -0.02em;
}
.hero-content p {
  font-size: 16px;
  color: var(--text-2);
  margin: 0 0 36px;
  line-height: 1.65;
}
.hero-features { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.hero-features li {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-1);
  font-size: 15px;
}
.hero-features .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}

.login-form-wrap {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 40px;
  background: var(--bg-1);
}
#login-form {
  width: 100%;
  max-width: 380px;
}
#login-form h2 {
  font-size: 28px;
  font-weight: 700;
  margin: 0 0 8px;
  color: var(--text-0);
  letter-spacing: -0.01em;
}
#login-form .muted {
  color: var(--text-2);
  margin: 0 0 32px;
  font-size: 14px;
}
#login-form label {
  display: block;
  margin-bottom: 18px;
}
#login-form label > span {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-1);
  margin-bottom: 6px;
}
.input-wrap {
  position: relative;
}
.input-wrap .input-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-3);
  pointer-events: none;
}
.input-wrap input {
  width: 100%;
  padding: 12px 14px 12px 44px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-0);
  font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
.input-wrap input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
.btn-primary {
  width: 100%;
  padding: 13px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 8px;
  transition: background 0.15s, transform 0.05s;
  box-shadow: var(--shadow-md);
}
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary svg { width: 16px; height: 16px; }

#login-err {
  color: var(--danger);
  font-size: 13px;
  margin-top: 14px;
  text-align: center;
  min-height: 18px;
}
.login-footer {
  margin-top: 60px;
  color: var(--text-3);
  font-size: 12px;
}

/* ========== APP LAYOUT ========== */
#app-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg-0);
}
.topbar {
  height: 60px;
  display: flex;
  align-items: center;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  gap: 24px;
  flex-shrink: 0;
  z-index: 50;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-0);
  min-width: 200px;
}
.brand svg { width: 22px; height: 22px; color: var(--accent-light); }

.mode-tabs {
  display: flex;
  background: var(--bg-2);
  border-radius: var(--radius-md);
  padding: 4px;
  gap: 2px;
}
.mode-tabs .tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: transparent;
  border: none;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  border-radius: 7px;
  transition: all 0.15s;
}
.mode-tabs .tab svg { width: 15px; height: 15px; }
.mode-tabs .tab:hover { color: var(--text-0); }
.mode-tabs .tab.active {
  background: var(--bg-3);
  color: var(--text-0);
  box-shadow: var(--shadow-sm);
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px 6px 6px;
  background: var(--bg-2);
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-1);
  font-weight: 500;
}
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}
.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.btn-icon svg { width: 16px; height: 16px; }
.btn-icon:hover { background: var(--bg-3); color: var(--text-0); border-color: var(--border-light); }

/* ========== WORKSPACE ========== */
.workspace {
  display: flex;
  flex: 1;
  min-height: 0;
}

.sidebar {
  width: 320px;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 12px;
}
.sidebar-header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-0);
  letter-spacing: 0.02em;
}
.badge {
  background: var(--bg-3);
  color: var(--text-1);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.search-wrap {
  position: relative;
  padding: 0 20px 12px;
}
.search-wrap .input-icon {
  position: absolute;
  left: 32px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--text-3);
  pointer-events: none;
}
.search-wrap input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-0);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}
.search-wrap input:focus { border-color: var(--accent); }
.search-wrap input::placeholder { color: var(--text-3); }

.vehicle-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px 12px;
}
.vehicle-list::-webkit-scrollbar { width: 6px; }
.vehicle-list::-webkit-scrollbar-track { background: transparent; }
.vehicle-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.vehicle-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  margin-bottom: 6px;
  background: var(--bg-2);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}
.vehicle-card:hover {
  background: var(--bg-3);
  border-color: var(--border-light);
}
.vehicle-card.active {
  background: rgba(59,130,246,0.12);
  border-color: var(--accent);
}
.vehicle-card.active::before {
  content: '';
  position: absolute;
  left: -1px;
  top: 12px;
  bottom: 12px;
  width: 3px;
  background: var(--accent);
  border-radius: 2px;
}

.vehicle-avatar {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: #fff;
  flex-shrink: 0;
  position: relative;
}
.status-dot {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--bg-1);
}
.status-dot.online { background: var(--success); box-shadow: 0 0 8px var(--success); }
.status-dot.offline { background: var(--text-3); }
.status-dot.recent { background: var(--warning); }

.vehicle-info {
  flex: 1;
  min-width: 0;
}
.vehicle-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.vehicle-meta {
  font-size: 11.5px;
  color: var(--text-2);
  margin-top: 3px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.vehicle-meta .speed-pill {
  background: rgba(59,130,246,0.15);
  color: var(--accent-light);
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 11px;
}

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-3);
  font-size: 13px;
}

/* History panel */
.sidebar-section {
  border-top: 1px solid var(--border);
  padding: 16px 20px;
}
.sidebar-section h4 {
  margin: 0 0 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.quick-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
  margin-bottom: 14px;
}
.quick-buttons button {
  padding: 7px 8px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-1);
  font-size: 12px;
  font-weight: 500;
  transition: all 0.15s;
}
.quick-buttons button:hover { background: var(--bg-3); border-color: var(--accent); color: var(--text-0); }
.quick-buttons button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.date-input-wrap label {
  display: block;
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 6px;
}
.date-input-wrap input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-1);
  font-size: 13px;
  color-scheme: dark;
}
.history-stats {
  margin-top: 14px;
  padding: 12px;
  background: var(--bg-2);
  border-radius: var(--radius-md);
  font-size: 12px;
  color: var(--text-2);
  display: none;
}
.history-stats.visible { display: block; }
.history-stats .row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
}
.history-stats .row:last-child { margin-bottom: 0; }
.history-stats .value { color: var(--text-0); font-weight: 600; }

/* ========== MAP AREA ========== */
.map-area {
  flex: 1;
  position: relative;
  min-width: 0;
}
#map {
  position: absolute;
  inset: 0;
  background: #1a1f2e;
}
body.light #map { background: #dfe6f0; }

.map-overlay {
  position: absolute;
  z-index: 600;
  pointer-events: none;
}
.map-overlay > * { pointer-events: auto; }
.map-overlay.top-left { top: 16px; left: 16px; }
.map-overlay.bottom-left { bottom: 28px; left: 16px; }

.info-card {
  background: var(--map-overlay-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  min-width: 320px;
  box-shadow: var(--shadow-lg);
}
.info-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.info-avatar {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
}
.info-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-0);
}
.info-sub {
  font-size: 12px;
  color: var(--text-2);
  margin-top: 2px;
}
.info-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.stat {
  display: flex;
  align-items: center;
  gap: 10px;
}
.stat-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-2);
  flex-shrink: 0;
}
.stat-icon svg { width: 16px; height: 16px; }
.stat-icon.speed { background: rgba(59,130,246,0.15); color: var(--accent-light); }
.stat-icon.battery { background: rgba(16,185,129,0.15); color: var(--success); }
.stat-icon.location { background: rgba(245,158,11,0.15); color: var(--warning); }
.stat-icon.clock { background: rgba(148,163,184,0.15); color: var(--text-2); }
.stat-label {
  font-size: 11px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}
.stat-value {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-0);
  margin-top: 1px;
}
.stat-value.small { font-size: 12px; font-weight: 600; }

/* Legend (all-vehicles mode) */
#map-legend.has-items {
  background: var(--map-overlay-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  box-shadow: var(--shadow-md);
  max-width: 260px;
}
#map-legend h5 {
  margin: 0 0 8px;
  font-size: 11px;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
#map-legend .legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  font-size: 12.5px;
  color: var(--text-1);
}
#map-legend .legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Custom map markers */
.vehicle-marker {
  background: transparent !important;
  border: none !important;
}
.vehicle-marker-inner {
  width: 36px;
  height: 36px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  border: 3px solid #fff;
}
.vehicle-marker-inner > span {
  transform: rotate(45deg);
  color: #fff;
  font-weight: 700;
  font-size: 11px;
  font-family: 'Inter', sans-serif;
}

/* Custom icon marker — round, no rotation, status dot at corner */
.vehicle-marker.custom .vehicle-marker-img {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #fff;
  box-shadow: 0 3px 10px rgba(0,0,0,0.35);
  overflow: visible;
}
.vehicle-marker.custom .vehicle-marker-img img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}
.vehicle-marker-status {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* Avatar in sidebar can show an image */
.vehicle-avatar .avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}
.vehicle-avatar { overflow: hidden; }
.info-avatar { overflow: hidden; }

/* Leaflet tweaks */
.leaflet-popup-content-wrapper {
  background: rgba(17,24,39,0.95);
  color: var(--text-0);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.leaflet-popup-content {
  margin: 12px 14px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-1);
}
.leaflet-popup-content b { color: var(--text-0); }
.leaflet-popup-tip { background: rgba(17,24,39,0.95); border: 1px solid var(--border); }
.leaflet-control-zoom a {
  background: rgba(17,24,39,0.92) !important;
  color: var(--text-0) !important;
  border: 1px solid var(--border) !important;
}
.leaflet-control-zoom a:hover {
  background: var(--bg-3) !important;
}
.leaflet-control-attribution {
  background: rgba(17,24,39,0.7) !important;
  color: var(--text-3) !important;
  font-size: 10px;
}
.leaflet-control-attribution a { color: var(--text-2) !important; }

/* ========== LAYER SWITCHER ========== */
.leaflet-control-layers {
  background: var(--map-overlay-bg) !important;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-md) !important;
  color: var(--text-0);
  padding: 0 !important;
}
.leaflet-control-layers-expanded {
  padding: 10px 14px !important;
  min-width: 180px;
}
.leaflet-control-layers-list {
  margin: 0;
}
.leaflet-control-layers-base label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  color: var(--text-1);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 4px;
}
.leaflet-control-layers-base label:hover { color: var(--text-0); }
.leaflet-control-layers-base label span {
  display: flex;
  align-items: center;
  gap: 8px;
}
.leaflet-control-layers-base input[type="radio"] {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  margin: 0;
}
.leaflet-control-layers-separator { display: none; }
.leaflet-control-layers-toggle {
  background-color: var(--map-overlay-bg) !important;
  border-radius: var(--radius-md) !important;
  border: 1px solid var(--border) !important;
  width: 38px !important;
  height: 38px !important;
}
body.light .leaflet-control-layers-toggle {
  filter: none;
}
body:not(.light) .leaflet-control-layers-toggle {
  filter: invert(0.85) hue-rotate(180deg);
}

/* ========== ICON GRID PICKER (admin device modal) ========== */
.icon-grid-wrap {
  margin-top: 4px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px;
}
.icon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
}
.icon-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 4px;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
  background: var(--bg-1);
  transition: all 0.12s;
  user-select: none;
}
.icon-cell:hover { background: var(--bg-3); border-color: var(--border-light); }
.icon-cell.selected {
  border-color: var(--accent);
  background: rgba(59,130,246,0.12);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
.icon-cell-img {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--bg-2);
}
.icon-cell-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.icon-cell-img.default {
  background: var(--bg-3);
  color: var(--text-2);
}
.icon-cell-img.default svg { width: 22px; height: 22px; }
.icon-cell span {
  font-size: 10px;
  color: var(--text-2);
  text-align: center;
  text-transform: capitalize;
  line-height: 1.25;
  word-break: break-word;
  max-width: 100%;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* ========== STATE HISTORY (TIMELINE) ========== */
.state-history {
  margin-top: 14px;
  font-size: 12px;
}
.state-history h4 {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.timeline-summary {
  background: var(--bg-2);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin-bottom: 10px;
}
.sum-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}
.sum-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.sum-name {
  flex: 1;
  color: var(--text-1);
  font-weight: 500;
}
.sum-time {
  color: var(--text-0);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.sum-pct {
  color: var(--text-3);
  font-size: 11px;
  width: 38px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.timeline-bar {
  position: relative;
  height: 22px;
  background: var(--bg-2);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 12px;
}
.timeline-seg {
  position: absolute;
  top: 0;
  bottom: 0;
  opacity: 0.85;
  transition: opacity 0.15s;
  cursor: pointer;
}
.timeline-seg:hover { opacity: 1; }

.intervals-list h5 {
  margin: 12px 0 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.interval-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  margin-bottom: 4px;
  background: var(--bg-2);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.12s;
  font-size: 11.5px;
}
.interval-row:hover {
  background: var(--bg-3);
  border-color: var(--border-light);
}
.iv-time {
  flex: 1;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
}
.iv-status {
  padding: 2px 7px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 10.5px;
  white-space: nowrap;
}
.iv-dur {
  color: var(--text-0);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 60px;
  text-align: right;
}

/* Make sidebar scroll properly when state-history takes a lot of space */
.history-panel { max-height: calc(100vh - 200px); overflow-y: auto; }
.history-panel::-webkit-scrollbar { width: 6px; }
.history-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ========== STATUS BADGE ========== */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px 2px 6px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}
.status-pulse {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(0.85); }
}

/* ========== LICENSE PLATE BADGE ========== */
.plate-badge {
  display: inline-block;
  background: #fbbf24;
  color: #1c1917;
  padding: 2px 8px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.04em;
  border: 1.5px solid #1c1917;
  line-height: 1.3;
  white-space: nowrap;
}
.plate-badge.large {
  font-size: 14px;
  padding: 4px 10px;
  letter-spacing: 0.05em;
}
.vehicle-card .plate-badge {
  margin-left: auto;
  align-self: flex-start;
  flex-shrink: 0;
}
.vehicle-card { flex-wrap: wrap; }
.vehicle-card .vehicle-info { min-width: 0; flex: 1; }
.info-header .plate-badge { margin-left: auto; }

/* ========== EDIT BUTTON ========== */
.vehicle-edit-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-2);
  display: none;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.vehicle-edit-btn:hover { color: var(--text-0); background: var(--accent); border-color: var(--accent); }
.vehicle-edit-btn svg { width: 13px; height: 13px; }
.vehicle-card:hover .vehicle-edit-btn { display: flex; }

/* ========== MODAL ========== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5000;
  opacity: 0;
  transition: opacity 0.2s;
}
.modal-overlay.show { opacity: 1; }
.modal {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 420px;
  padding: 24px;
  box-shadow: var(--shadow-lg);
  transform: scale(0.96);
  transition: transform 0.2s;
}
.modal-overlay.show .modal { transform: scale(1); }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.modal-header h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--text-0);
}
.modal-close {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: transparent;
  border: none;
  color: var(--text-2);
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover { background: var(--bg-2); color: var(--text-0); }
.modal-close svg { width: 16px; height: 16px; }
.modal label {
  display: block;
  margin-bottom: 14px;
}
.modal label > span {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 5px;
}
.modal input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-0);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
.modal input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,0.15); }
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}
.btn-ghost {
  padding: 9px 16px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-1);
  font-size: 13px;
  font-weight: 500;
}
.btn-ghost:hover { background: var(--bg-2); color: var(--text-0); }
.btn-save {
  padding: 9px 18px;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}
.btn-save:hover { background: var(--accent-dark); }
.modal-hint {
  font-size: 11px;
  color: var(--text-3);
  margin-top: -8px;
  margin-bottom: 14px;
}

/* ========== ALERT BELL BADGE ========== */
#btn-alerts { position: relative; }
.alert-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid var(--bg-1);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
#btn-alerts.has-alerts svg { color: var(--warning); }
#btn-alerts.has-sos svg { color: var(--danger); animation: pulse-bell 1s ease-in-out infinite; }
@keyframes pulse-bell {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* Alert list items */
.alert-item {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 6px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  align-items: flex-start;
}
.alert-item.unseen { border-left: 3px solid var(--accent); background: rgba(59,130,246,0.06); }
.alert-item.type-sos { border-left: 3px solid var(--danger); background: rgba(239,68,68,0.08); }
.alert-item.type-over_speed { border-left: 3px solid var(--warning); }
.alert-item.type-power_off { border-left: 3px solid var(--text-2); }
.alert-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
}
.alert-icon.sos { background: rgba(239,68,68,0.2); color: var(--danger); }
.alert-icon.over_speed { background: rgba(245,158,11,0.2); color: var(--warning); }
.alert-icon.power_off, .alert-icon.power_on { background: rgba(148,163,184,0.2); color: var(--text-2); }
.alert-body { flex: 1; min-width: 0; }
.alert-title { font-size: 13px; font-weight: 600; color: var(--text-0); }
.alert-meta { font-size: 11px; color: var(--text-2); margin-top: 2px; }
.alert-time { font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }

/* Marker cluster overrides for dark theme */
.marker-cluster {
  background-clip: padding-box;
  border-radius: 20px;
}
.marker-cluster div {
  background: var(--accent) !important;
  color: #fff !important;
  font-weight: 700;
  font-family: 'Inter', sans-serif !important;
}
.marker-cluster-small { background: rgba(59,130,246,0.4) !important; }
.marker-cluster-medium { background: rgba(245,158,11,0.4) !important; }
.marker-cluster-large { background: rgba(239,68,68,0.4) !important; }
.marker-cluster-small div { background: var(--accent) !important; }
.marker-cluster-medium div { background: var(--warning) !important; }
.marker-cluster-large div { background: var(--danger) !important; }

/* ========== SYSTEM CLOCK ========== */
.system-clock {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-1);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.system-clock svg { width: 14px; height: 14px; color: var(--accent-light); }
.clock-text { letter-spacing: 0.02em; }

/* ========== DEVICE EXPIRY INDICATOR ========== */
.expiry-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  background: rgba(59,130,246,0.15);
  color: var(--accent-light);
  border: 1px solid rgba(59,130,246,0.3);
}
.expiry-pill.warning {
  background: rgba(245,158,11,0.18);
  color: #fbbf24;
  border-color: rgba(245,158,11,0.35);
}
.expiry-pill.danger {
  background: rgba(239,68,68,0.18);
  color: #f87171;
  border-color: rgba(239,68,68,0.45);
}
.expiry-pill.expired {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
body.light .expiry-pill { background: #dbeafe; color: #1d4ed8; border-color: #93c5fd; }
body.light .expiry-pill.warning { background: #fef3c7; color: #92400e; border-color: #fcd34d; }
body.light .expiry-pill.danger { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }
body.light .expiry-pill.expired { background: #dc2626; color: #fff; border-color: #dc2626; }

/* Vehicle card expired state */
.vehicle-card.expired { opacity: 0.75; }
.vehicle-card.expired .vehicle-avatar::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(0,0,0,0.35);
}

/* ========== EXPIRED INLINE (on map info area) ========== */
.expired-inline {
  background: var(--map-overlay-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(239,68,68,0.4);
  border-radius: var(--radius-lg);
  padding: 20px;
  min-width: 360px;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
}
.expired-inline-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.expired-icon-sm {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(239,68,68,0.15);
  color: var(--danger);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.expired-icon-sm svg { width: 22px; height: 22px; }
.expired-inline-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--danger);
}
.expired-inline-sub {
  font-size: 12px;
  color: var(--text-2);
  margin-top: 2px;
}
.expired-inline-msg {
  margin: 0 0 14px;
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--text-1);
  font-style: italic;
  text-align: justify;
}
.expired-inline-actions {
  display: flex;
  gap: 8px;
}
.expired-inline-actions .btn-save {
  flex: 1;
  padding: 10px 16px;
}

/* ========== USER MENU DROPDOWN ========== */
.user-chip { position: relative; cursor: pointer; user-select: none; }
.user-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 1000;
}
.user-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-1);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.user-menu-item:hover { background: var(--bg-2); color: var(--text-0); }
.user-menu-item svg { width: 15px; height: 15px; opacity: 0.7; }


/* ========== ADMIN PANEL ========== */
.admin-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-0);
  overflow: hidden;
}
.admin-tabs {
  display: flex;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  gap: 6px;
  flex-shrink: 0;
}
.adm-tab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 14px 16px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.adm-tab svg { width: 16px; height: 16px; }
.adm-tab:hover { color: var(--text-0); }
.adm-tab.active { color: var(--accent-light); border-bottom-color: var(--accent); }
.admin-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}
.admin-section h3 {
  margin: 0 0 18px;
  font-size: 18px;
  color: var(--text-0);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.admin-section h3 button { font-size: 13px; }

/* Data table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.data-table th, .data-table td {
  text-align: left;
  padding: 11px 14px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.data-table th {
  background: var(--bg-2);
  color: var(--text-2);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.05em;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--bg-2); }
.data-table .row-actions {
  display: flex;
  gap: 6px;
}
.row-actions button {
  padding: 5px 10px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-1);
  font-size: 12px;
  cursor: pointer;
}
.row-actions button:hover { background: var(--bg-3); color: var(--text-0); }
.row-actions .danger { color: #f87171; }
.row-actions .danger:hover { background: var(--danger); color: #fff; }
body.light .row-actions .danger { color: #dc2626; }

.role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.role-badge.admin { background: rgba(139,92,246,0.2); color: #a78bfa; }
.role-badge.user { background: rgba(59,130,246,0.2); color: var(--accent-light); }
body.light .role-badge.admin { background: #ede9fe; color: #6d28d9; }
body.light .role-badge.user { background: #dbeafe; color: #1d4ed8; }

.license-cell {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.license-cell.ok { color: var(--success); }
.license-cell.warning { color: var(--warning); }
.license-cell.danger { color: var(--danger); }
.license-cell.unlimited { color: var(--text-2); }

/* Donate modal */
.donate-modal { max-width: 460px; }
.donate-message {
  font-size: 14px;
  line-height: 1.65;
  color: var(--text-1);
  margin: 0 0 18px;
}
.donate-info {
  background: var(--bg-2);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
}
.donate-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13px;
  gap: 8px;
}
.donate-row .label { color: var(--text-2); }
.donate-row .value {
  color: var(--text-0);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  user-select: all;
}
.donate-row button {
  padding: 3px 9px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-1);
  font-size: 11px;
  cursor: pointer;
}
.donate-qr {
  text-align: center;
  margin-top: 10px;
}
.donate-qr img { max-width: 200px; border-radius: var(--radius-sm); }

/* Settings form */
.settings-form { max-width: 560px; }
.settings-form label {
  display: block;
  margin-bottom: 14px;
}
.settings-form label > span {
  display: block;
  font-size: 12px;
  color: var(--text-2);
  margin-bottom: 5px;
  font-weight: 500;
}
.settings-form input, .settings-form textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-0);
  font-size: 13px;
  outline: none;
  font-family: inherit;
}
.settings-form textarea { min-height: 70px; resize: vertical; }
.settings-form input:focus, .settings-form textarea:focus { border-color: var(--accent); }

/* Preset buttons for license days */
.preset-row {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.preset-row button {
  padding: 5px 11px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-1);
  font-size: 12px;
  cursor: pointer;
}
.preset-row button:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ========== TOAST ========== */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-0);
  box-shadow: var(--shadow-lg);
  min-width: 240px;
  max-width: 360px;
  pointer-events: auto;
  animation: slide-in 0.25s ease-out;
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }
.toast.warning { border-left-color: var(--warning); }
@keyframes slide-in {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ========== MOBILE / RESPONSIVE ========== */
.mobile-only { display: none; }
.sidebar-backdrop { display: none; }

/* ========== TABLET (≤ 1024px) ========== */
@media (max-width: 1024px) {
  .sidebar { width: 280px; }
  .info-card { min-width: 280px; }
  .topbar { padding: 0 14px; gap: 14px; }
}

/* ========== MOBILE (≤ 768px) ========== */
@media (max-width: 768px) {
  .mobile-only { display: flex; }
  .brand-text { display: none; }
  .brand { min-width: auto; }

  /* Topbar */
  .topbar {
    height: 56px;
    padding: 0 10px;
    gap: 6px;
    overflow: hidden;
  }
  .mode-tabs { padding: 3px; gap: 1px; flex: 1; justify-content: center; }
  .mode-tabs .tab {
    padding: 8px 10px;
    font-size: 0;
    min-width: 40px;
    min-height: 38px;
    justify-content: center;
  }
  .mode-tabs .tab svg { width: 18px; height: 18px; }
  /* Hide tab labels by making font-size 0 + show only svg */

  .topbar-right { gap: 4px; }
  .system-clock { padding: 5px 9px; font-size: 11px; }
  .system-clock svg { width: 12px; height: 12px; }
  /* Hide donation & theme buttons on smallest screens to save space */
  .user-chip {
    padding: 4px 8px 4px 4px;
    gap: 6px;
  }
  .user-chip span { display: none; }
  .user-chip svg:not(.user-avatar svg) { display: none; }
  .user-avatar { width: 32px; height: 32px; font-size: 11px; }
  .btn-icon {
    width: 38px;
    height: 38px;
    min-width: 38px;
  }

  /* Hamburger always shown on left of brand */
  #btn-hamburger { order: -1; }

  /* Sidebar becomes off-canvas drawer */
  .workspace { position: relative; }
  .sidebar {
    position: fixed;
    top: 56px;
    bottom: 0;
    left: 0;
    width: 86%;
    max-width: 360px;
    z-index: 1200;
    transform: translateX(-100%);
    transition: transform 0.25s ease-out;
    box-shadow: 8px 0 32px rgba(0,0,0,0.4);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    display: block;
    position: fixed;
    top: 56px;
    inset: 56px 0 0 0;
    background: rgba(0,0,0,0.55);
    z-index: 1100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
  }
  .sidebar-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }
  body.light .sidebar-backdrop { background: rgba(15,23,42,0.4); }

  /* Map area takes full workspace */
  .map-area { width: 100%; }

  /* License banner more compact */
  .license-banner {
    padding: 8px 12px;
    font-size: 12px;
    line-height: 1.4;
  }

  /* Info card on map: bottom-sheet style */
  .map-overlay.top-left { top: auto; bottom: 16px; left: 8px; right: 8px; }
  .info-card {
    min-width: 0;
    width: 100%;
    padding: 14px;
    border-radius: 12px;
    max-height: 50vh;
    overflow-y: auto;
  }
  .expired-inline {
    min-width: 0;
    width: 100%;
    padding: 16px;
  }
  .expired-inline-msg { font-size: 13px; }
  .info-card.collapsed .info-stats { display: none; }
  .info-card.collapsed { padding: 12px 14px; }
  .info-card.collapsed .info-header { padding-bottom: 0; border-bottom: none; margin-bottom: 0; }
  .info-collapse {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    background: var(--bg-2);
    border: none;
    border-radius: 50%;
    color: var(--text-2);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
    transition: transform 0.2s;
  }
  .info-collapse svg { width: 14px; height: 14px; }
  .info-card.collapsed .info-collapse { transform: rotate(180deg); }
  .info-stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .info-name { font-size: 14px; }

  .map-overlay.bottom-left { bottom: 16px; left: 8px; max-width: 60%; }
  #map-legend.has-items { padding: 8px 10px; max-width: 100%; font-size: 11px; }

  /* Leaflet zoom controls bigger for touch */
  .leaflet-control-zoom a {
    width: 36px !important;
    height: 36px !important;
    line-height: 34px !important;
    font-size: 18px !important;
  }
  .leaflet-control-layers-expanded { min-width: 160px; padding: 8px 12px !important; }
  .leaflet-control-layers-base label { padding: 8px 0 !important; min-height: 32px; }

  /* Vehicle cards: keep edit button visible on mobile (no hover) */
  .vehicle-edit-btn {
    display: flex;
    position: static;
    width: 36px;
    height: 36px;
    margin-left: 4px;
  }
  .vehicle-card {
    padding: 14px 12px;
    min-height: 56px;
  }
  .vehicle-card.active::before { left: 0; }

  /* History panel — full height inside drawer */
  .history-panel { max-height: none; }
  .quick-buttons button { padding: 9px 8px; min-height: 38px; font-size: 12px; }

  /* === Admin panel mobile === */
  .admin-tabs {
    padding: 0 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .admin-tabs::-webkit-scrollbar { display: none; }
  .adm-tab {
    padding: 13px 10px;
    font-size: 12px;
    flex-shrink: 0;
  }
  .adm-tab svg { width: 14px; height: 14px; }
  .admin-content { padding: 14px; }
  .admin-section h3 {
    font-size: 16px;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .admin-section h3 button { width: 100%; padding: 11px; }

  /* Admin tables → card layout */
  .data-table { border: none; background: transparent; }
  .data-table thead { display: none; }
  .data-table tr {
    display: block;
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    margin-bottom: 10px;
  }
  .data-table tr:hover { background: var(--bg-1); }
  .data-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 5px 0;
    border-bottom: none;
    font-size: 13px;
  }
  .data-table td::before {
    content: attr(data-label);
    color: var(--text-2);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex-shrink: 0;
  }
  .data-table td[data-label=""]::before { display: none; }
  .data-table .row-actions {
    width: 100%;
    margin-top: 6px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    justify-content: stretch;
  }
  .data-table .row-actions button {
    flex: 1;
    padding: 9px;
    font-size: 12px;
    min-height: 38px;
  }

  /* Modals: full-width on mobile */
  .modal { max-width: calc(100vw - 24px); padding: 20px; border-radius: 12px; }
  .modal-overlay { padding: 12px; }
  .modal input, .modal select, .modal textarea {
    padding: 11px 12px;
    font-size: 14px;
    min-height: 42px;
  }
  .modal-actions { flex-direction: column-reverse; gap: 8px; }
  .modal-actions button { width: 100%; padding: 12px; }

  /* Login mobile-friendly */
  .login-hero { display: none; }
  .login-split { grid-template-columns: 1fr; }
  .login-form-wrap { padding: 24px; }
  #login-form { max-width: 100%; }

  /* Expired overlay */
  .expired-card { padding: 28px 22px; }
  .expired-card h2 { font-size: 19px; }
  .expired-actions { flex-direction: column; }
  .expired-actions button { width: 100%; }

  /* Donate modal */
  .donate-row { flex-wrap: wrap; }
  .donate-row .value { flex: 1; word-break: break-all; }

  /* Settings form */
  .settings-form input, .settings-form textarea {
    min-height: 42px;
    font-size: 14px;
  }

  /* Toast bottom on mobile */
  #toast-container {
    bottom: 16px;
    right: 8px;
    left: 8px;
  }
  .toast { min-width: 0; max-width: 100%; }
}

/* ========== SMALL PHONES (≤ 380px) ========== */
@media (max-width: 380px) {
  .mode-tabs .tab { padding: 8px 6px; min-width: 36px; }
  .mode-tabs .tab svg { width: 16px; height: 16px; }
  /* Hide donate button on very small screens */
  #btn-donate { display: none; }
  .topbar-right { gap: 3px; }
  .system-clock { padding: 4px 8px; font-size: 10.5px; }
  /* On smallest screens show only time, hide date */
  .clock-text .clock-date { display: none; }
  .info-stats { grid-template-columns: 1fr; }
}

/* ========== TOUCH DEVICES (no hover) ========== */
@media (hover: none) {
  .vehicle-edit-btn { display: flex; }
}
