/* === CamAlert — Dark Automotive Theme === */

@font-face {
  font-family: 'JetBrains Mono';
  src: url('/assets/fonts/jetbrains-mono-bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Outfit';
  src: url('/assets/fonts/outfit-regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Outfit';
  src: url('/assets/fonts/outfit-semibold.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-surface: #1a1a2e;
  --accent-blue: #00d4ff;
  --accent-green: #00e676;
  --accent-amber: #ffb800;
  --accent-red: #ff3344;
  --text-primary: #e8e8f0;
  --text-secondary: #8888aa;
  --border: #2a2a3e;
  --glow-blue: 0 0 20px rgba(0, 212, 255, 0.3);
  --glow-red: 0 0 20px rgba(255, 51, 68, 0.4);
  --glow-green: 0 0 20px rgba(0, 230, 118, 0.3);
  --glow-amber: 0 0 20px rgba(255, 184, 0, 0.3);
  --nav-height: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Outfit', sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

/* === App Container === */
#app {
  position: fixed;
  inset: 0;
}

/* === Views === */
.view {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
  display: none;
  overflow-y: auto;
}
.view.active { display: flex; flex-direction: column; }

/* === Setup Wizard === */
#setup-wizard {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg-primary);
  bottom: 0 !important;
}
.setup-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 40px 24px;
  text-align: center;
}
.setup-step { display: none; width: 100%; max-width: 360px; }
.setup-step.active { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.setup-icon { margin-bottom: 8px; }
.setup-container h1 { font-size: 32px; font-weight: 600; color: var(--accent-blue); }
.setup-container h2 { font-size: 22px; font-weight: 600; }
.setup-subtitle { color: var(--text-secondary); font-size: 16px; }
.setup-desc { color: var(--text-secondary); font-size: 14px; line-height: 1.5; }
.setup-status { font-size: 13px; color: var(--text-secondary); min-height: 20px; }

.tile-options { display: flex; gap: 8px; width: 100%; }
.tile-option {
  flex: 1;
  background: var(--bg-surface);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 12px 8px;
  color: var(--text-primary);
  font-family: 'Outfit', sans-serif;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: center;
  transition: border-color 0.2s;
}
.tile-option.selected { border-color: var(--accent-blue); }
.tile-option strong { font-size: 14px; }
.tile-desc { font-size: 11px; color: var(--text-secondary); }

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--bg-surface);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent-blue);
  border-radius: 3px;
  transition: width 0.3s ease;
}

/* === Buttons === */
.btn-primary {
  width: 100%;
  max-width: 280px;
  padding: 14px 24px;
  background: var(--accent-blue);
  color: var(--bg-primary);
  border: none;
  border-radius: 12px;
  font-family: 'Outfit', sans-serif;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  margin-top: 8px;
}
.btn-primary:active { opacity: 0.8; }
.btn-secondary {
  padding: 10px 20px;
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: 'Outfit', sans-serif;
  font-size: 14px;
  cursor: pointer;
}

/* === Bottom Navigation === */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: 'Outfit', sans-serif;
  font-size: 11px;
  cursor: pointer;
  transition: color 0.2s;
  padding: 8px 0;
}
.nav-btn.active { color: var(--accent-blue); }
.nav-icon { width: 24px; height: 24px; fill: currentColor; pointer-events: none; }
.nav-btn span { pointer-events: none; }

/* === Alert Overlay === */
.alert-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  padding-top: var(--safe-top);
  pointer-events: none;
  transition: opacity 0.3s;
}
.alert-overlay.hidden { opacity: 0; }

.alert-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  margin: 8px;
  background: rgba(26, 26, 46, 0.95);
  border: 2px solid var(--accent-blue);
  border-radius: 16px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.alert-banner.alert-far { border-color: var(--accent-blue); }
.alert-banner.alert-medium { border-color: var(--accent-amber); }
.alert-banner.alert-near { border-color: var(--accent-red); animation: pulse-red 1s ease-in-out infinite; }

@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 51, 68, 0.4); }
  50% { box-shadow: 0 0 20px 4px rgba(255, 51, 68, 0.6); }
}

.alert-icon { width: 40px; height: 40px; flex-shrink: 0; }
.alert-icon svg { width: 100%; height: 100%; }
.alert-info { flex: 1; }
.alert-type { font-weight: 600; font-size: 14px; }
.alert-road { font-size: 12px; color: var(--text-secondary); }
.alert-speed-limit { font-size: 12px; color: var(--accent-amber); }
.alert-distance {
  font-family: 'JetBrains Mono', monospace;
  font-size: 20px;
  font-weight: 700;
  white-space: nowrap;
}

/* === Average Speed Banner === */
.avg-speed-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: calc(8px + var(--safe-top)) 16px 8px;
  background: rgba(255, 184, 0, 0.15);
  border-bottom: 2px solid var(--accent-amber);
  font-weight: 600;
  font-size: 14px;
  color: var(--accent-amber);
}
.avg-speed-banner.hidden { display: none; }
.avg-limit { font-family: 'JetBrains Mono', monospace; }

/* === Status Indicators === */
.offline-indicator, .gps-indicator {
  position: fixed;
  top: calc(8px + var(--safe-top));
  z-index: 40;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.offline-indicator {
  right: 8px;
  background: rgba(255, 51, 68, 0.2);
  color: var(--accent-red);
  border: 1px solid var(--accent-red);
}
.gps-indicator {
  right: 80px;
  background: rgba(255, 184, 0, 0.2);
  color: var(--accent-amber);
  border: 1px solid var(--accent-amber);
}
.hidden { display: none !important; }

.pending-badge {
  position: fixed;
  top: calc(8px + var(--safe-top));
  left: 8px;
  z-index: 40;
  background: var(--accent-amber);
  color: var(--bg-primary);
  width: 24px;
  height: 24px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
}

/* === Map View === */
#map-container {
  flex: 1;
  width: 100%;
  height: 100%;
}
.maplibregl-map { font-family: 'Outfit', sans-serif; }
.maplibregl-popup-content {
  background: var(--bg-surface) !important;
  color: var(--text-primary) !important;
  border-radius: 8px !important;
  padding: 10px 14px !important;
  font-size: 13px;
  border: 1px solid var(--border);
}
.maplibregl-popup-tip { border-top-color: var(--bg-surface) !important; }

/* === HUD View === */
#view-hud {
  background: var(--bg-primary);
  justify-content: center;
  align-items: center;
}
.hud-container {
  width: 100%;
  max-width: 400px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.hud-speed-limit {
  display: flex;
  align-items: center;
  gap: 8px;
}
.speed-limit-circle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 3px solid var(--accent-red);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 51, 68, 0.1);
}
.speed-limit-circle span {
  font-family: 'JetBrains Mono', monospace;
  font-size: 22px;
  font-weight: 700;
}
.speed-limit-label { font-size: 14px; color: var(--text-secondary); }

.hud-current-speed {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.speed-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 96px;
  font-weight: 700;
  line-height: 1;
  transition: color 0.3s, text-shadow 0.3s;
}
.speed-unit { font-size: 20px; color: var(--text-secondary); }

.speed-green { color: var(--accent-green); text-shadow: var(--glow-green); }
.speed-amber { color: var(--accent-amber); text-shadow: var(--glow-amber); }
.speed-red { color: var(--accent-red); text-shadow: var(--glow-red); }
.speed-white { color: var(--text-primary); }

.hud-camera-info {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--bg-surface);
  border-radius: 16px;
  border: 1px solid var(--border);
}
.hud-camera-icon { width: 36px; height: 36px; flex-shrink: 0; }
.hud-camera-icon svg { width: 100%; height: 100%; }
.hud-camera-details { flex: 1; }
.hud-camera-type { font-weight: 600; font-size: 14px; }
.hud-camera-road { font-size: 12px; color: var(--text-secondary); }
.hud-camera-distance { text-align: right; }

.distance-bar {
  width: 80px;
  height: 6px;
  background: var(--bg-primary);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 4px;
}
.distance-fill {
  height: 100%;
  background: var(--accent-blue);
  border-radius: 3px;
  transition: width 0.5s ease, background-color 0.3s;
}

#hud-distance-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 16px;
  font-weight: 700;
}

/* === Settings View === */
#view-settings {
  background: var(--bg-primary);
  overflow-y: auto;
}
.settings-container {
  padding: 24px 16px;
  max-width: 400px;
  margin: 0 auto;
  width: 100%;
}
.settings-title { font-size: 22px; margin-bottom: 20px; }
.settings-group {
  margin-bottom: 24px;
  background: var(--bg-surface);
  border-radius: 12px;
  padding: 16px;
  border: 1px solid var(--border);
}
.settings-group h3 {
  font-size: 13px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 14px;
}
.setting-row + .setting-row { border-top: 1px solid var(--border); }
.setting-control { display: flex; align-items: center; gap: 8px; }
.setting-control input[type="range"] { width: 100px; accent-color: var(--accent-blue); }
.setting-control span { font-family: 'JetBrains Mono', monospace; font-size: 13px; min-width: 48px; text-align: right; }
.setting-info { font-size: 12px; color: var(--text-secondary); }

select {
  background: var(--bg-primary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-family: 'Outfit', sans-serif;
  font-size: 14px;
}

/* Toggle switch */
.toggle { position: relative; display: inline-block; width: 44px; height: 24px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--bg-primary);
  border-radius: 12px;
  border: 1px solid var(--border);
  transition: 0.3s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  height: 18px;
  width: 18px;
  left: 2px;
  bottom: 2px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: 0.3s;
}
.toggle input:checked + .toggle-slider { background: var(--accent-blue); border-color: var(--accent-blue); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); background: white; }

.settings-footer { text-align: center; padding: 24px 0 16px; color: var(--text-secondary); font-size: 12px; }

/* === Simulator Panel === */
.simulator-panel {
  position: fixed;
  bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px));
  left: 0;
  right: 0;
  z-index: 60;
  background: var(--bg-secondary);
  border-top: 2px solid var(--accent-amber);
  padding: 8px 16px;
}
.sim-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}
.sim-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sim-btn:disabled { opacity: 0.4; }
.sim-speed { flex: 1; display: flex; align-items: center; gap: 8px; margin-left: 8px; }
.sim-speed input { flex: 1; accent-color: var(--accent-amber); }
#sim-speed-label { font-family: 'JetBrains Mono', monospace; font-size: 13px; min-width: 56px; }

/* === Screen flash for near alerts === */
.screen-flash {
  position: fixed;
  inset: 0;
  z-index: 200;
  pointer-events: none;
  animation: flash 0.6s ease-out;
}
@keyframes flash {
  0% { background: rgba(255, 51, 68, 0.3); }
  100% { background: transparent; }
}

/* === Responsive === */
@media (max-width: 374px) {
  .speed-value { font-size: 72px; }
  .hud-container { padding: 16px; gap: 16px; }
}
