/* ============================================================
   NavGo — Stylesheet
   ============================================================ */

/* ============ CSS VARIABLES — DARK (default) ============ */
:root {
  --bg-base:           #0f172a;
  --bg-surface:        rgba(30,41,59,0.95);
  --bg-surface-mid:    rgba(30,41,59,0.6);
  --bg-overlay:        rgba(15,23,42,0.98);
  --bg-overlay-90:     rgba(15,23,42,0.90);
  --bg-overlay-70:     rgba(15,23,42,0.70);
  --border:            rgba(148,163,184,0.15);
  --border-focus:      #38bdf8;
  --text-primary:      #f1f5f9;
  --text-secondary:    #cbd5e1;
  --text-muted:        #94a3b8;
  --text-placeholder:  #64748b;
  --accent:            #0ea5e9;
  --accent-dark:       #0284c7;
  --accent-ring:       rgba(56,189,248,0.15);
  --accent-glow:       rgba(14,165,233,0.4);
  --success-text:      #86efac;
  --success-border:    rgba(34,197,94,0.5);
  --error-text:        #fca5a5;
  --error-border:      rgba(239,68,68,0.5);
  --toast-bg:          rgba(30,41,59,0.95);
  --scrollbar-thumb:   rgba(148,163,184,0.3);
  --gradient-top:      linear-gradient(180deg, rgba(15,23,42,0.97) 0%, rgba(15,23,42,0.75) 70%, transparent 100%);
  --gradient-bottom:   linear-gradient(180deg, rgba(15,23,42,0.9) 0%, rgba(15,23,42,0.98) 100%);

  /* speed ring color */
  --speed-color:       #22d3ee;
}

/* ============ LIGHT THEME OVERRIDES ============ */
[data-theme="light"] {
  --bg-base:           #f0f4f8;
  --bg-surface:        rgba(255,255,255,0.97);
  --bg-surface-mid:    rgba(240,244,248,0.85);
  --bg-overlay:        rgba(255,255,255,0.98);
  --bg-overlay-90:     rgba(255,255,255,0.92);
  --bg-overlay-70:     rgba(255,255,255,0.80);
  --border:            rgba(100,116,139,0.18);
  --border-focus:      #0284c7;
  --text-primary:      #0f172a;
  --text-secondary:    #1e293b;
  --text-muted:        #475569;
  --text-placeholder:  #94a3b8;
  --accent:            #0284c7;
  --accent-dark:       #0369a1;
  --accent-ring:       rgba(2,132,199,0.12);
  --accent-glow:       rgba(2,132,199,0.3);
  --success-text:      #166534;
  --success-border:    rgba(34,197,94,0.5);
  --error-text:        #991b1b;
  --error-border:      rgba(239,68,68,0.5);
  --toast-bg:          rgba(255,255,255,0.97);
  --scrollbar-thumb:   rgba(100,116,139,0.3);
  --gradient-top:      linear-gradient(180deg, rgba(240,244,248,0.97) 0%, rgba(240,244,248,0.75) 70%, transparent 100%);
  --gradient-bottom:   linear-gradient(180deg, rgba(240,244,248,0.88) 0%, rgba(240,244,248,0.98) 100%);
}

/* ============ RESET & BASE ============ */
* {
  margin: 0; padding: 0; box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
html, body { height: 100%; overflow: hidden; font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; }
body { background: var(--bg-base); color: var(--text-primary); transition: background 0.4s ease; }

/* ============ DARK MAP FILTER ============ */
/* Applied to the OSM raster layer via canvas filter when dark mode is active */
#map.dark-tiles {
  filter: invert(1) hue-rotate(180deg) brightness(0.85) contrast(1.05) saturate(0.9);
}
/* Re-correct the user/destination markers so they don't get inverted */
#map.dark-tiles .maplibregl-marker {
  filter: invert(1) hue-rotate(180deg);
}
/* Keep route lines natural — they use GL layers so they're unaffected by CSS filter */

/* ============ DESKTOP BLOCKER ============ */
#desktop-blocker {
  position: fixed; inset: 0; z-index: 9999;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  display: none; align-items: center; justify-content: center;
  padding: 2rem; text-align: center;
}
#desktop-blocker.active { display: flex; }
#desktop-blocker .icon { font-size: 4rem; margin-bottom: 1rem; }
#desktop-blocker h1 { font-size: 1.5rem; margin-bottom: 0.5rem; color: #f1f5f9; }
#desktop-blocker p { color: #94a3b8; max-width: 320px; line-height: 1.5; }

/* ============ APP SHELL ============ */
#app { height: 100vh; width: 100vw; position: relative; overflow: hidden; }
#map { position: absolute; inset: 0; z-index: 1; }

/* ============ TOP BAR ============ */
.top-bar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 100;
  padding: 12px 16px;
  background: var(--gradient-top);
  padding-bottom: 40px;
  transition: transform 0.3s ease;
}
.top-bar.hidden { transform: translateY(-120%); }

.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.brand-dot {
  width: 32px; height: 32px; border-radius: 10px;
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  display: flex; align-items: center; justify-content: center; font-size: 1.1rem;
}
.brand h1 { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); letter-spacing: -0.02em; }
.brand .tag { font-size: 0.7rem; color: var(--accent); font-weight: 500; margin-left: auto; }

/* ============ SEARCH ============ */
.search-wrap { position: relative; }
.search-input {
  width: 100%; padding: 14px 44px 14px 44px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text-primary); font-size: 0.95rem;
  font-family: inherit;
  backdrop-filter: blur(10px);
  outline: none;
  transition: background 0.3s, border-color 0.2s, box-shadow 0.2s;
}
.search-input:focus { border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--accent-ring); }
.search-input::placeholder { color: var(--text-placeholder); }
.search-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 1.1rem; }
.search-clear {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  width: 28px; height: 28px; border-radius: 50%;
  background: rgba(148,163,184,0.2); border: none;
  color: var(--text-secondary); cursor: pointer; display: none;
  align-items: center; justify-content: center; font-size: 1rem;
}
.search-clear.show { display: flex; }

.results-list {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  backdrop-filter: blur(10px);
  max-height: 40vh; overflow-y: auto;
  display: none; z-index: 200;
}
.results-list.show { display: block; }
.result-item { padding: 14px 16px; border-bottom: 1px solid var(--border); cursor: pointer; }
.result-item:last-child { border-bottom: none; }
.result-item:active { background: var(--accent-ring); }
.result-name { font-size: 0.9rem; font-weight: 500; color: var(--text-primary); margin-bottom: 2px; }
.result-addr { font-size: 0.75rem; color: var(--text-muted); }

/* ============ FAB BUTTONS ============ */
.fab {
  position: absolute; z-index: 100;
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(10px);
  color: var(--text-primary); font-size: 1.3rem;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  transition: all 0.2s;
}
.fab:active { transform: scale(0.92); }

/* --nav-bottom-h is set by JS when nav-bottom is shown/hidden          */
/* Default (no overlay): 28px above screen bottom                       */
/* During navigation: automatically lifts above nav-bottom panel height */
:root { --nav-bottom-h: 0px; }

.fab.recenter {
  bottom: calc(28px + var(--nav-bottom-h));
  right: 16px;
  transition: bottom 0.3s ease, opacity 0.2s, transform 0.2s;
}
.fab.recenter.hidden { opacity: 0; pointer-events: none; }

/* Compass — always stacked 68px above recenter */
.fab.compass {
  bottom: calc(96px + var(--nav-bottom-h));
  right: 16px;
  font-size: 1rem;
  transition: bottom 0.3s ease;
}
.fab.compass.hidden  { display: none; }
.fab.compass.active  { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Theme toggle — above compass */
.fab.theme-toggle {
  bottom: calc(164px + var(--nav-bottom-h));
  right: 16px;
  font-size: 1.1rem;
  transition: bottom 0.3s ease;
}

/* ============ NAVIGATION ARROW MARKER ============ */
.nav-arrow-marker {
  width: 0; height: 0;
  border-left: 14px solid transparent;
  border-right: 14px solid transparent;
  border-bottom: 28px solid var(--accent);
  filter: drop-shadow(0 2px 6px var(--accent-glow));
  transform-origin: 50% 85%;
  transition: transform 0.4s ease;
  position: relative;
}
.nav-arrow-marker::after {
  content: '';
  position: absolute;
  bottom: -28px; left: -8px;
  width: 16px; height: 16px;
  background: var(--accent);
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  opacity: 0.6;
}

/* ============ MANEUVER CARD ============ */
.maneuver-card {
  position: absolute; top: 0; left: 0; right: 0; z-index: 100;
  background: var(--bg-overlay-90);
  backdrop-filter: blur(20px);
  padding: calc(env(safe-area-inset-top) + 12px) 16px 16px;
  display: none;
  border-bottom: 1px solid var(--border);
  transition: background 0.3s;
}
.maneuver-card.show { display: block; }

.maneuver-main { display: flex; align-items: center; gap: 16px; padding-bottom: 12px; }
.maneuver-icon {
  width: 64px; height: 64px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 2.2rem; color: #fff;
  box-shadow: 0 4px 12px var(--accent-glow);
  transition: background 0.3s;
}
.maneuver-icon.arrive  { background: linear-gradient(135deg, #ef4444, #dc2626); box-shadow: 0 4px 12px rgba(239,68,68,0.4); }
.maneuver-icon.warning { background: linear-gradient(135deg, #f59e0b, #d97706); box-shadow: 0 4px 12px rgba(245,158,11,0.4); }

.maneuver-info { flex: 1; min-width: 0; }
.maneuver-distance {
  font-size: 2rem; font-weight: 800; color: var(--text-primary);
  letter-spacing: -0.03em; line-height: 1;
}
.maneuver-unit { font-size: 0.9rem; font-weight: 500; color: var(--text-muted); margin-left: 4px; }
.maneuver-street {
  font-size: 0.9rem; color: var(--text-secondary); margin-top: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.maneuver-action {
  font-size: 0.8rem; color: var(--accent); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em; margin-top: 2px;
}

.maneuver-secondary {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  background: var(--bg-surface-mid);
  border-radius: 10px;
  font-size: 0.8rem;
}
.maneuver-secondary .next-icon {
  width: 28px; height: 28px;
  background: var(--accent-ring);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.95rem;
}
.maneuver-secondary .next-text { flex: 1; color: var(--text-secondary); }
.maneuver-secondary .next-dist  { color: var(--text-muted); font-weight: 500; }

/* ============ REROUTE BANNER ============ */
.reroute-banner {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  z-index: 150;
  background: rgba(245,158,11,0.95);
  color: #fff;
  padding: 12px 20px;
  border-radius: 12px;
  font-weight: 600; font-size: 0.95rem;
  display: none; align-items: center; gap: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}
.reroute-banner.show { display: flex; animation: bannerPulse 1.5s ease-in-out infinite; }

@keyframes bannerPulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50%       { transform: translate(-50%, -50%) scale(1.03); }
}

.reroute-spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ============ NAV BOTTOM BAR ============ */
.nav-bottom {
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 100;
  background: var(--gradient-bottom);
  backdrop-filter: blur(20px);
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  display: none;
  border-top: 1px solid var(--border);
  transition: background 0.3s;
}
.nav-bottom.show { display: block; }

.nav-stats { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.nav-stat {
  flex: 1; text-align: center;
  padding: 8px;
  background: var(--bg-surface-mid);
  border-radius: 10px;
}
.nav-stat-value { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); }
.nav-stat-label { font-size: 0.65rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 2px; }
.nav-stat.speed .nav-stat-value { color: var(--speed-color); }
.nav-stat.fuel .nav-stat-value { color: #fbbf24; }

.stop-btn {
  width: 100%; padding: 14px;
  background: linear-gradient(135deg, #ef4444, #dc2626);
  border: none; border-radius: 12px;
  color: #fff; font-size: 1rem; font-weight: 600;
  font-family: inherit; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 4px 12px rgba(239,68,68,0.3);
}
.stop-btn:active { transform: scale(0.98); }

/* ============ PREVIEW PANEL ============ */
.preview-panel {
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 100;
  background: var(--gradient-bottom);
  backdrop-filter: blur(20px);
  border-radius: 20px 20px 0 0;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.4,0,0.2,1), background 0.3s;
  max-height: 55vh;
  display: flex; flex-direction: column;
}
.preview-panel.show { transform: translateY(0); }
.panel-handle { width: 36px; height: 4px; border-radius: 2px; background: var(--border); margin: 0 auto 12px; }

.route-summary {
  display: flex; align-items: center; gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.stat { flex: 1; min-width: 0; }
.stat-value { font-size: 1.2rem; font-weight: 700; color: var(--text-primary); letter-spacing: -0.02em; white-space: nowrap; }
.stat-label { font-size: 0.62rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 2px; }
.stat-divider { width: 1px; height: 36px; background: var(--border); flex-shrink: 0; }
.stat.fuel .stat-value { color: #f59e0b; }

.start-nav-btn {
  margin-top: 12px;
  padding: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  border: none; border-radius: 12px;
  color: #fff; font-size: 1rem; font-weight: 600;
  font-family: inherit; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 4px 12px var(--accent-glow);
}
.start-nav-btn:active { transform: scale(0.98); }

.instructions { overflow-y: auto; flex: 1; padding: 8px 0; margin-top: 8px; }
.instruction { display: flex; gap: 12px; padding: 10px; border-radius: 10px; }
.instruction.active { background: var(--accent-ring); }
.instruction .step-icon {
  width: 32px; height: 32px; flex-shrink: 0;
  background: var(--accent-ring);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
}
.instruction.active .step-icon { background: var(--accent); color: #fff; }
.instruction .step-maneuver { font-size: 0.85rem; color: var(--text-primary); font-weight: 500; }
.instruction .step-distance  { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }

/* ============ LANE GUIDANCE STRIP ============ */
.lane-guidance {
  display: none;
  gap: 6px; justify-content: center; align-items: center;
  padding: 8px 12px;
  background: var(--bg-surface-mid);
  border-radius: 10px;
  margin-bottom: 8px;
}
.lane-guidance.show { display: flex; }
.lane-arrow {
  width: 28px; height: 28px;
  border-radius: 6px; background: var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; color: var(--text-muted);
  transition: background 0.2s;
}
.lane-arrow.active { background: var(--accent); color: #fff; }

/* ============ TOAST ============ */
.toast {
  position: absolute; top: 140px; left: 50%;
  transform: translateX(-50%) translateY(-20px);
  z-index: 300;
  background: var(--toast-bg);
  border: 1px solid var(--border);
  backdrop-filter: blur(10px);
  padding: 10px 16px; border-radius: 10px;
  font-size: 0.85rem; color: var(--text-primary);
  opacity: 0; pointer-events: none;
  transition: all 0.3s;
  white-space: nowrap; max-width: 90%;
}
.toast.show    { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error   { border-color: var(--error-border);   color: var(--error-text);   }
.toast.success { border-color: var(--success-border); color: var(--success-text); }

/* ============ LOADER ============ */
.loader { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 50; display: none; }
.loader.show { display: block; }
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--accent-ring);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ============ VOICE INDICATOR ============ */
.voice-indicator {
  position: absolute; top: calc(env(safe-area-inset-top) + 12px); right: 16px;
  z-index: 150;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  display: none; align-items: center; justify-content: center;
  font-size: 1rem;
}
.voice-indicator.speaking { display: flex; animation: voicePulse 1s ease-in-out infinite; }

@keyframes voicePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0.5); }
  50%       { box-shadow: 0 0 0 8px rgba(34,197,94,0); }
}

/* ============ SPEED LIMIT BADGE ============ */
.speed-limit-badge {
  position: absolute; bottom: 170px; left: 16px;
  z-index: 100;
  width: 52px; height: 64px;
  background: #fff;
  border: 4px solid #cc0000;
  border-radius: 50%;
  display: none; flex-direction: column;
  align-items: center; justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.speed-limit-badge.show { display: flex; }
.speed-limit-badge .slb-label { font-size: 0.5rem; font-weight: 700; color: #cc0000; letter-spacing: 0.04em; }
.speed-limit-badge .slb-value { font-size: 1.1rem; font-weight: 900; color: #000; line-height: 1; }

/* ============ ARRIVED OVERLAY ============ */
.arrived-overlay {
  position: absolute; inset: 0; z-index: 200;
  background: rgba(15,23,42,0.85);
  display: none; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px; text-align: center;
  backdrop-filter: blur(8px);
}
.arrived-overlay.show { display: flex; animation: fadeIn 0.5s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.arrived-icon { font-size: 4rem; }
.arrived-title { font-size: 1.8rem; font-weight: 800; color: #f1f5f9; letter-spacing: -0.02em; }
.arrived-sub   { font-size: 0.9rem; color: #94a3b8; max-width: 240px; line-height: 1.5; }
.arrived-close {
  margin-top: 8px; padding: 14px 32px;
  background: linear-gradient(135deg, #0ea5e9, #0284c7);
  border: none; border-radius: 12px;
  color: #fff; font-size: 1rem; font-weight: 600;
  font-family: inherit; cursor: pointer;
}

/* ============ THEME TRANSITIONS ============ */
.top-bar, .search-input, .results-list, .result-item,
.fab, .maneuver-card, .nav-bottom, .preview-panel,
.toast, .maneuver-secondary, .nav-stat,
.instruction, .voice-indicator {
  transition: background 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

/* ============ MAP LIBRARY OVERRIDES ============ */
.maplibregl-ctrl-attrib { font-size: 9px !important; background: rgba(15,23,42,0.7) !important; color: #94a3b8 !important; }
.maplibregl-ctrl-attrib a { color: #38bdf8 !important; }
.maplibregl-ctrl-group { display: none !important; }

/* ============ SCROLLBAR ============ */
.instructions::-webkit-scrollbar { width: 4px; }
.instructions::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 2px; }