/* ==========================================================
   TRACKZERO - DESIGN SYSTEM & MODERN DARK THEME
   Tailored HSL Palette, Glassmorphism, Micro-animations
   ========================================================== */

:root {
  /* Color Tokens */
  --bg-primary: #0b0f19;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.75);
  --bg-card-hover: rgba(31, 41, 55, 0.85);
  --bg-glass: rgba(15, 23, 42, 0.65);
  
  --border-color: rgba(255, 255, 255, 0.08);
  --border-glow: rgba(56, 189, 248, 0.3);
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --accent-cyan: #06b6d4;
  --accent-cyan-glow: rgba(6, 182, 212, 0.35);
  --accent-blue: #3b82f6;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  
  --font-heading: 'Outfit', sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;
  
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
  --shadow-glow: 0 0 20px var(--accent-cyan-glow);
  
  --transition-fast: 0.15s ease;
  --transition-smooth: 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* App Wrapper */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

/* Top Navigation Bar */
.top-nav {
  height: 64px;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 1000;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-blue));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.1rem;
  box-shadow: 0 0 16px var(--accent-cyan-glow);
}

.brand-text h1 {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(to right, #fff, #94a3b8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.badge-free {
  font-size: 0.65rem;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  border-radius: var(--radius-full);
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

/* Select Device */
.device-selector-wrapper .select-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  padding: 6px 16px;
  color: var(--text-secondary);
  transition: var(--transition-fast);
}

.device-selector-wrapper .select-box:hover {
  border-color: var(--accent-cyan);
}

.device-selector-wrapper select {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 0.88rem;
  font-family: var(--font-body);
  font-weight: 500;
  outline: none;
  cursor: pointer;
}

.device-selector-wrapper select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* Header Actions & Pill */
.header-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.live-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 0.78rem;
  font-weight: 600;
}

.pulsing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--accent-emerald);
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: pulse-green 1.8s infinite;
}

.pulsing-dot.offline {
  background-color: var(--accent-rose);
  animation: none;
}

@keyframes pulse-green {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.btn-icon {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-fast);
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

/* Main Layout (Sidebar + Map) */
.main-layout {
  display: flex;
  flex: 1;
  height: calc(100vh - 64px);
  overflow: hidden;
  position: relative;
}

/* Sidebar Panel */
.sidebar-panel {
  width: 420px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 10;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
}

/* Navigation Tabs */
.nav-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  background: rgba(0, 0, 0, 0.2);
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 12px 4px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-fast);
}

.tab-btn i {
  font-size: 1rem;
}

.tab-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.02);
}

.tab-btn.active {
  color: var(--accent-cyan);
  border-bottom-color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.05);
}

/* Tab Pane Contents */
.tab-pane {
  display: none;
  padding: 18px;
  overflow-y: auto;
  flex: 1;
  flex-direction: column;
  gap: 16px;
}

.tab-pane.active {
  display: flex;
}

/* Card Base */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition-smooth);
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.12);
}

/* Telemetry Grid */
.telemetry-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Speedometer Card */
.speed-card {
  grid-column: 1 / -1;
  background: linear-gradient(145deg, rgba(17, 24, 39, 0.9), rgba(15, 23, 42, 0.95));
  border: 1px solid rgba(6, 182, 212, 0.2);
  position: relative;
  overflow: hidden;
}

.speed-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent-cyan), var(--accent-blue));
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.speed-display {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  padding: 14px 0 6px;
}

.huge-metric {
  font-family: var(--font-heading);
  font-size: 3.5rem;
  font-weight: 800;
  line-height: 1;
  color: #fff;
  letter-spacing: -2px;
}

.speed-display .unit {
  font-size: 1.1rem;
  color: var(--accent-cyan);
  font-weight: 600;
}

.speed-bar-track {
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin: 10px 0;
}

.speed-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-emerald), var(--accent-amber), var(--accent-rose));
  border-radius: var(--radius-full);
  transition: width 0.4s ease;
}

.speed-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Status Tags */
.tag-status {
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.tag-moving {
  background: rgba(16, 185, 129, 0.2);
  color: var(--accent-emerald);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.tag-parked {
  background: rgba(148, 163, 184, 0.15);
  color: var(--text-secondary);
  border: 1px solid rgba(148, 163, 184, 0.25);
}

/* Compact Stat Cards */
.stat-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
}

.stat-card.full-width {
  grid-column: 1 / -1;
}

.stat-icon-wrapper {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.stat-info {
  display: flex;
  flex-direction: column;
}

.stat-info .label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.stat-info .val {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
}

.compass-wrapper i {
  transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Quick Actions Box */
.quick-actions-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
}

.coords-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0, 0, 0, 0.25);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-family: monospace;
  color: var(--text-secondary);
}

.actions-row {
  display: flex;
  gap: 8px;
}

/* Buttons */
.btn-primary {
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-blue));
  border: none;
  color: #fff;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 12px var(--accent-cyan-glow);
  transition: var(--transition-fast);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(6, 182, 212, 0.5);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.82rem;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  flex: 1;
  transition: var(--transition-fast);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-tiny {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
}

.btn-tiny:hover {
  color: #fff;
}

.w-100 { width: 100%; }

/* Alerts Section */
.recent-alerts-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.badge-pill {
  background: rgba(244, 63, 94, 0.15);
  color: var(--accent-rose);
  border: 1px solid rgba(244, 63, 94, 0.3);
  padding: 1px 8px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
}

.alerts-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
}

.empty-alerts {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 0;
  color: var(--text-muted);
  font-size: 0.82rem;
  gap: 6px;
}

.empty-alerts i {
  font-size: 1.5rem;
  opacity: 0.5;
}

.alert-item {
  background: rgba(244, 63, 94, 0.08);
  border-left: 3px solid var(--accent-rose);
  padding: 10px 12px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.78rem;
}

.alert-item.enter {
  background: rgba(16, 185, 129, 0.08);
  border-left-color: var(--accent-emerald);
}

.alert-item-header {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
  color: #fff;
  margin-bottom: 2px;
}

.alert-time {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* History Controls & Player */
.filter-group {
  display: flex;
  gap: 8px;
  margin: 12px 0;
}

.btn-chip {
  flex: 1;
  padding: 6px 0;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition-fast);
}

.btn-chip.active {
  background: rgba(6, 182, 212, 0.15);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.history-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.hstat-item {
  background: rgba(0, 0, 0, 0.2);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
}

.hlabel {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.hval {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
}

.player-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--border-color);
}

.player-buttons {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.btn-player {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent-cyan);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
}

.btn-player:hover {
  transform: scale(1.05);
}

.custom-slider {
  width: 100%;
  accent-color: var(--accent-cyan);
  cursor: pointer;
}

.player-time-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: monospace;
}

/* Forms in Geofences and Settings */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.form-group label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-group input,
.form-group select {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: #fff;
  font-family: var(--font-body);
  font-size: 0.85rem;
  outline: none;
  transition: var(--transition-fast);
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 2px var(--accent-cyan-glow);
}

.checkbox-row {
  display: flex;
  gap: 16px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 14px;
}

.btn-duo {
  display: flex;
  gap: 8px;
}

.geofences-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.fence-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
}

/* Simulator Log Box */
.sim-header {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.sim-header i {
  font-size: 1.5rem;
  margin-top: 3px;
}

.sim-header h4 {
  font-size: 0.95rem;
  font-weight: 600;
}

.sim-header p {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 3px;
  line-height: 1.4;
}

.sim-log-box {
  background: #06090e;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-family: monospace;
  font-size: 0.72rem;
  max-height: 150px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 12px;
}

.log-line {
  color: #a5f3fc;
}

.log-line.warn { color: #fcd34d; }
.log-line.alert { color: #fda4af; }

/* Map Viewport */
.map-section {
  flex: 1;
  position: relative;
  height: 100%;
}

.map-viewport {
  width: 100%;
  height: 100%;
  background: #0f172a;
}

/* Floating Map Buttons */
.floating-map-controls {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 990;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.floating-btn {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: var(--transition-fast);
}

.floating-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: var(--accent-cyan);
}

.floating-btn.active {
  color: var(--accent-cyan);
  border-color: var(--accent-cyan);
  box-shadow: 0 0 14px var(--accent-cyan-glow);
}

/* Mobile Status Bar (Visible on smaller viewports) */
.mobile-status-bar {
  display: none;
  position: absolute;
  bottom: 20px;
  left: 20px;
  right: 20px;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 12px 18px;
  z-index: 990;
  box-shadow: var(--shadow-md);
  align-items: center;
  justify-content: space-between;
}

.m-speed {
  font-family: var(--font-heading);
  font-size: 1.8rem;
  font-weight: 800;
  color: #fff;
}

.m-speed small {
  font-size: 0.8rem;
  color: var(--accent-cyan);
  font-weight: 500;
}

.m-divider {
  width: 1px;
  height: 28px;
  background: var(--border-color);
}

.m-info {
  display: flex;
  flex-direction: column;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 480px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-close {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
}

.btn-close:hover { color: #fff; }

.modal-body {
  padding: 20px;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  background: rgba(0, 0, 0, 0.15);
}

.hidden {
  display: none !important;
}

/* Custom Marker Styling for Leaflet */
.car-marker-container {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.car-marker-halo {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--accent-cyan-glow);
  animation: marker-pulse 2s infinite ease-out;
}

.car-marker-body {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0284c7, #06b6d4);
  border: 2px solid #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  transition: transform 0.4s ease;
  z-index: 2;
}

@keyframes marker-pulse {
  0% { transform: scale(0.6); opacity: 1; }
  100% { transform: scale(1.4); opacity: 0; }
}

/* Responsive Media Queries */
@media (max-width: 900px) {
  .main-layout {
    flex-direction: column-reverse;
  }
  
  .sidebar-panel {
    width: 100%;
    height: 45vh;
    border-right: none;
    border-top: 1px solid var(--border-color);
  }

  .map-section {
    height: 55vh;
  }

  .mobile-status-bar {
    display: flex;
  }
}
