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

:root {
  --bg-primary: #0a0e1a;
  --bg-secondary: #131829;
  --bg-card: #1a2138;
  --bg-card-hover: #1f2742;
  --border: #252d47;
  --border-light: #2e3856;
  --text-primary: #f1f4f9;
  --text-secondary: #8892b0;
  --text-tertiary: #5a6380;
  --accent: #6366f1;
  --accent-hover: #5457e5;
  --accent-glow: rgba(99, 102, 241, 0.25);
  --success: #22c55e;
  --success-bg: rgba(34, 197, 94, 0.12);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.12);
  --warning: #f59e0b;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
input, textarea, select { font-size: 16px; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  height: 100dvh;
  height: 100svh;
  width: 100vw;
  user-select: none;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

#app { display: flex; flex-direction: column; height: 100dvh; }

/* ─── TOP HEADER ─── */
.header {
  background: var(--bg-secondary);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  z-index: 1000;
  flex-shrink: 0;
  min-height: 52px;
  gap: 8px;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-logo {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  box-shadow: 0 0 20px var(--accent-glow);
}
.header-title {
  font-size: 17px; font-weight: 700;
  background: linear-gradient(135deg, #fff, #a5b4fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.header-badge {
  font-size: 9px; font-weight: 700;
  background: var(--success-bg);
  color: var(--success);
  padding: 2px 8px;
  border-radius: 20px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  border: 1px solid rgba(34,197,94,0.25);
}
.header-actions { display: flex; gap: 6px; }

/* ─── BUTTONS ─── */
.btn {
  padding: 7px 14px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  white-space: nowrap;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  min-height: 36px;
}
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-success { background: var(--success); color: #052e16; }
.btn-success:hover { background: #16a34a; transform: translateY(-1px); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-card); color: var(--text-primary); border-color: var(--border-light); }
.btn-sm { padding: 5px 10px; font-size: 11px; }
.btn-icon {
  width: 34px; height: 34px; padding: 0;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
}
.btn-recording {
  animation: pulse-btn 1.5s ease-in-out infinite;
}
@keyframes pulse-btn {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.4); }
  50% { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
}

/* ─── MAIN LAYOUT ─── */
.main { display: flex; flex: 1; overflow: hidden; position: relative; }

/* ─── MAP ─── */
.map-container { flex: 1; position: relative; background: var(--bg-primary); }
#map { width: 100%; height: 100%; z-index: 1; }
#map .leaflet-control-zoom a {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
#map .leaflet-control-zoom a:hover { background: var(--bg-card-hover); }
#map .leaflet-control-attribution { background: rgba(10,14,26,0.85); color: var(--text-tertiary); font-size: 9px; padding: 2px 6px; }
#map .leaflet-control-attribution a { color: var(--text-secondary); }
#map .leaflet-control-zoom { border: none; }
#map .leaflet-control-zoom a { width: 30px; height: 30px; line-height: 30px; font-size: 16px; }

/* Map overlay buttons */
.map-overlay {
  position: absolute;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.map-overlay-top-right { top: 12px; right: 12px; }
.map-overlay-bottom-right { bottom: 100px; right: 12px; }
.map-overlay-bottom-left { bottom: 100px; left: 12px; }
.map-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  backdrop-filter: blur(8px);
  box-shadow: 0 2px 12px rgba(0,0,0,0.3);
}
.map-btn:hover { background: var(--bg-card-hover); border-color: var(--border-light); transform: scale(1.05); }
.map-btn svg { width: 20px; height: 20px; }

/* ─── LIVE INFO PANEL ─── */
.live-panel {
  position: absolute;
  bottom: 16px;
  left: 12px;
  right: 12px;
  z-index: 1000;
  background: rgba(19, 24, 41, 0.92);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  border: 1px solid var(--border);
  display: none;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  transition: var(--transition);
  max-height: 110px;
  overflow: hidden;
}
.live-panel.show { display: block; animation: slideUp 0.3s ease; }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
.live-panel-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px; padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.live-panel-title {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 1px; color: var(--text-tertiary);
  display: flex; align-items: center; gap: 6px;
}
.live-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--danger); display: inline-block;
  animation: blink 1s step-end infinite;
}
.live-dot.active { background: var(--success); }
@keyframes blink { 50% { opacity: 0.3; } }
.live-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.live-item { text-align: center; padding: 4px 2px; }
.live-value {
  font-size: 22px; font-weight: 800;
  background: linear-gradient(135deg, #e0e7ff, #a5b4fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  line-height: 1.2;
}
.live-unit { font-size: 10px; color: var(--text-tertiary); margin-left: 1px; -webkit-text-fill-color: var(--text-tertiary); }
.live-label { font-size: 9px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 2px; }

/* ─── SIDEBAR / DRAWER ─── */
.drawer {
  width: 380px;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}
.drawer-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  padding: 0 4px;
  background: var(--bg-primary);
}
.drawer-tab {
  flex: 1;
  padding: 10px 0 8px;
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}
.drawer-tab svg { width: 16px; height: 16px; opacity: 0.5; }
.drawer-tab.active { color: var(--accent); }
.drawer-tab.active svg { opacity: 1; }
.drawer-tab.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 20%;
  right: 20%;
  height: 2px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
}
.drawer-tab:hover { color: var(--text-secondary); }
.tab-content { flex: 1; overflow-y: auto; padding: 14px; display: none; }
.tab-content.active { display: block; }

/* Scrollbar */
.tab-content::-webkit-scrollbar { width: 3px; }
.tab-content::-webkit-scrollbar-track { background: transparent; }
.tab-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ─── TAB: VEHICLES ─── */
.section-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.8px; color: var(--text-tertiary);
  margin-bottom: 10px;
}
.vehicle-add-row {
  display: flex; gap: 6px; margin-bottom: 14px;
}
.vehicle-add-row input[type="text"] {
  flex: 1; padding: 9px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-primary);
  color: var(--text-primary); font-size: 13px; font-family: inherit;
  transition: var(--transition);
}
.vehicle-add-row input[type="text"]:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.vehicle-add-row input[type="color"] {
  width: 38px; height: 38px; padding: 2px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg-primary); cursor: pointer; flex-shrink: 0;
}
.vehicle-list { display: flex; flex-direction: column; gap: 6px; }
.vehicle-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid transparent;
}
.vehicle-card:hover { background: var(--bg-card-hover); border-color: var(--border); }
.vehicle-card.active {
  border-color: var(--accent);
  background: linear-gradient(135deg, rgba(99,102,241,0.08), transparent);
  box-shadow: 0 0 20px rgba(99,102,241,0.06);
}
.vehicle-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 18px;
  border: 2px solid transparent;
  transition: var(--transition);
}
.vehicle-card.active .vehicle-avatar { border-color: var(--accent); box-shadow: 0 0 16px rgba(99,102,241,0.2); }
.vehicle-info { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.vehicle-name { font-weight: 600; font-size: 14px; line-height: 1.3; }
.vehicle-meta { font-size: 11px; color: var(--text-tertiary); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vehicle-status {
  font-size: 10px; font-weight: 600; padding: 3px 10px;
  border-radius: 20px; text-transform: uppercase; letter-spacing: 0.3px;
  flex-shrink: 0;
}
.vehicle-status.online { background: var(--success-bg); color: var(--success); }
.vehicle-status.offline { background: rgba(100,116,139,0.1); color: var(--text-tertiary); }
.btn-delete-vehicle {
  background: transparent; border: none; color: var(--text-tertiary);
  cursor: pointer; padding: 6px; border-radius: 6px; opacity: 0;
  transition: var(--transition); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.vehicle-card:hover .btn-delete-vehicle { opacity: 1; }
.btn-delete-vehicle:hover { background: var(--danger-bg); color: var(--danger); }

/* ─── TAB: DASHBOARD ─── */
.stat-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px 12px;
  text-align: center;
  border: 1px solid var(--border);
  transition: var(--transition);
}
.stat-card:hover { border-color: var(--border-light); }
.stat-card-icon {
  font-size: 20px; margin-bottom: 4px;
}
.stat-card-value {
  font-size: 22px; font-weight: 800;
  background: linear-gradient(135deg, #e0e7ff, #a5b4fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.stat-card-label {
  font-size: 9px; color: var(--text-tertiary);
  text-transform: uppercase; letter-spacing: 0.8px;
  margin-top: 2px;
}

/* Trip list */
.trip-section-title {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.8px; color: var(--text-tertiary);
  margin-bottom: 8px; display: flex; align-items: center; gap: 6px;
}
.trip-list { display: flex; flex-direction: column; gap: 6px; }
.trip-card {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  font-size: 13px;
  transition: var(--transition);
  border: 1px solid transparent;
}
.trip-card:hover { background: var(--bg-card-hover); border-color: var(--border); }
.trip-left { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.trip-name { font-weight: 600; font-size: 13px; }
.trip-date { font-size: 10px; color: var(--text-tertiary); }
.trip-right { text-align: right; flex-shrink: 0; margin-left: 8px; }
.trip-distance { font-weight: 700; font-size: 13px; color: var(--accent); }
.trip-speed { font-size: 10px; color: var(--text-tertiary); }

.empty-state {
  text-align: center; padding: 32px 16px; color: var(--text-tertiary);
}
.empty-state-icon { font-size: 40px; margin-bottom: 8px; opacity: 0.5; }
.empty-state-text { font-size: 13px; }

/* ─── MODAL ─── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 5000;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s ease;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal-overlay.show { opacity: 1; pointer-events: auto; }
.modal-overlay.show .modal { transform: scale(1); opacity: 1; }
.modal {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 90%; max-width: 380px;
  border: 1px solid var(--border);
  transform: scale(0.95);
  opacity: 0;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal h2 {
  font-size: 17px; font-weight: 700; margin-bottom: 16px;
  display: flex; align-items: center; gap: 8px;
}
.modal-field {
  margin-bottom: 14px;
}
.modal-field label {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--text-secondary); margin-bottom: 4px;
}
.modal-field input[type="text"] {
  width: 100%; padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px; font-family: inherit;
  transition: var(--transition);
}
.modal-field input[type="text"]:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.modal-field input[type="color"] {
  width: 100%; height: 38px; padding: 2px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg-primary); cursor: pointer;
}
.modal .btn { width: 100%; justify-content: center; padding: 10px; }

/* ─── RESPONSIVE ─── */
@media (max-width: 820px) {
  .drawer { width: 100%; border-left: none; }
  .main { flex-direction: column-reverse; }
  .map-container { height: 55vh; flex: none; }
  .drawer { height: 45vh; }
  .header { padding: 6px 10px; min-height: 44px; gap: 4px; }
  .header-title { font-size: 14px; }
  .header-left { gap: 6px; flex-shrink: 1; min-width: 0; }
  .header-logo { width: 28px; height: 28px; flex-shrink: 0; }
  .header-logo svg { width: 15px; height: 15px; }
  .header-badge { display: none; }
  .header-actions { gap: 4px; flex-shrink: 0; }
  .header-actions .btn span { display: none; }
  .header-actions .btn { padding: 6px 8px; }
  .header-actions .btn-icon { width: 32px; height: 32px; padding: 0; }
  .live-panel { left: 8px; right: 8px; bottom: 8px; padding: 10px 12px; }
  .live-value { font-size: 18px; }
  .live-value .live-unit { font-size: 9px; }
  .live-grid { gap: 4px; }
  .stat-cards { gap: 6px; }
  .stat-card { padding: 10px 8px; }
  .stat-card-value { font-size: 17px; }
  .stat-card-label { font-size: 8px; }
  .map-overlay-top-right { top: 8px; right: 8px; }
  .map-btn { width: 36px; height: 36px; }
  .map-btn svg { width: 18px; height: 18px; }

  /* Trip card text wrapping */
  .trip-card { flex-wrap: wrap; gap: 4px; }
  .trip-left { min-width: 0; flex: 1 1 60%; }
  .trip-date { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .trip-right { flex-shrink: 0; }

  /* Vehicle add row wrapping */
  .vehicle-add-row { flex-wrap: wrap; }
  .vehicle-add-row input[type="text"] { flex: 1 1 100%; }
  .vehicle-add-row input[type="color"] { flex: 0 0 38px; }
  .vehicle-add-row .btn { flex: 1; }

  /* Status badge hidden when tracking */
  .vehicle-status { font-size: 9px; padding: 2px 7px; }
  .btn-delete-vehicle { opacity: 1; }
}

@media (max-width: 480px) {
  .drawer-tab { gap: 0; }
  .drawer-tab span { display: none; }
  .drawer-tab svg { width: 20px; height: 20px; }
  .live-value { font-size: 15px; }
  .live-label { font-size: 8px; }
  .live-grid { gap: 2px; }
  .vehicle-card { padding: 9px 10px; gap: 8px; }
  .vehicle-avatar { width: 30px; height: 30px; font-size: 13px; }
  .vehicle-name { font-size: 13px; }
  .vehicle-meta { font-size: 10px; }
  .stat-cards { grid-template-columns: 1fr 1fr; gap: 5px; }
  .stat-card { padding: 8px 6px; }
  .stat-card-value { font-size: 15px; }
  .stat-card-label { font-size: 7px; letter-spacing: 0.5px; }
  .trip-card { padding: 8px 10px; font-size: 12px; }
  .trip-name { font-size: 12px; }
  .trip-distance { font-size: 12px; }
  .empty-state { padding: 20px 12px; }
  .empty-state-text { font-size: 12px; }
  .modal { padding: 18px; }
  .modal h2 { font-size: 15px; }
}

@media (max-width: 360px) {
  .header-title { font-size: 12px; }
  .header-actions .btn { padding: 4px 6px; }
  .btn svg { width: 14px; height: 14px; }
  .stat-cards { grid-template-columns: 1fr 1fr; gap: 4px; }
  .stat-card-value { font-size: 13px; }
}

@media (min-height: 800px) and (max-width: 820px) {
  .map-container { height: 60vh; }
  .drawer { height: 40vh; }
}

@media (min-height: 900px) and (max-width: 820px) {
  .map-container { height: 50vh; }
  .drawer { height: 50vh; }
}

@media (max-height: 650px) and (max-width: 820px) {
  .map-container { height: 45vh; }
  .drawer { height: 55vh; }
  .map-btn { width: 32px; height: 32px; }
  .map-btn svg { width: 16px; height: 16px; }
  .drawer-tab { padding: 6px 0; }
  .tab-content { padding: 10px; }
  .vehicle-card { padding: 8px 10px; }
}

/* ─── TOAST ─── */
.toast-container {
  position: fixed; top: 60px; left: 50%; transform: translateX(-50%);
  z-index: 9999; display: flex; flex-direction: column; gap: 6px;
  pointer-events: none;
}
.toast {
  padding: 10px 18px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500;
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-primary);
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  animation: toastIn 0.3s ease;
  pointer-events: auto;
  backdrop-filter: blur(12px);
  display: flex; align-items: center; gap: 8px;
}
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }
.toast.warning { border-color: var(--warning); }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}
