/* Tesla Supercharger Route Planner - Stylesheet */

:root {
  --bg-primary: #121418;
  --bg-secondary: #1a1e24;
  --bg-tertiary: #232931;
  --bg-card: #20262e;
  --bg-input: #15191f;
  
  --text-main: #f0f3f6;
  --text-muted: #8c9ba8;
  --text-dim: #5c6773;

  --tesla-red: #e82127;
  --tesla-red-hover: #c4181e;
  --tesla-red-subtle: rgba(232, 33, 39, 0.15);
  
  --accent-cyan: #00b4d8;
  --accent-green: #10b981;
  --accent-orange: #f59e0b;
  --border-color: #2c3540;
  --border-subtle: rgba(255, 255, 255, 0.08);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body, html {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background-color: var(--bg-primary);
  color: var(--text-main);
}

.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  position: relative;
}

/* Sidebar */
.sidebar {
  width: 440px;
  min-width: 400px;
  height: 100%;
  background-color: var(--bg-primary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.sidebar-header {
  padding: 18px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  background-color: var(--bg-secondary);
}

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

.logo-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--tesla-red), #ff4d4f);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.15rem;
  box-shadow: 0 4px 12px rgba(232, 33, 39, 0.4);
}

.brand h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: #fff;
}

.subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.dataset-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  padding: 5px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
}

.pulse-dot {
  width: 7px;
  height: 7px;
  background-color: var(--accent-green);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--accent-green);
}

/* Tabs */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  background-color: var(--bg-secondary);
}

.tab-btn {
  flex: 1;
  padding: 12px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-bottom: 2px solid transparent;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  color: var(--text-main);
  background-color: var(--bg-tertiary);
}

.tab-btn.active {
  color: #fff;
  border-bottom: 2px solid var(--tesla-red);
  background-color: var(--bg-primary);
}

/* Tab Content */
.tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Inputs & Form */
.form-group {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.input-header label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.marker-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.origin-dot { background-color: var(--accent-green); box-shadow: 0 0 6px var(--accent-green); }
.dest-dot { background-color: var(--tesla-red); box-shadow: 0 0 6px var(--tesla-red); }

.link-btn {
  background: none;
  border: none;
  color: var(--accent-cyan);
  font-size: 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}
.link-btn:hover { text-decoration: underline; }

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-wrapper:focus-within {
  border-color: var(--tesla-red);
  box-shadow: 0 0 0 2px var(--tesla-red-subtle);
}

.input-icon {
  margin-left: 12px;
  font-size: 0.9rem;
}
.text-green { color: var(--accent-green); }
.text-red { color: var(--tesla-red); }

.input-wrapper input {
  flex: 1;
  background: none;
  border: none;
  padding: 12px 10px;
  color: var(--text-main);
  font-size: 0.88rem;
  outline: none;
}

.input-wrapper input::placeholder {
  color: var(--text-dim);
}

.clear-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 8px 12px;
  cursor: pointer;
}

/* Swap button */
.swap-container {
  display: flex;
  justify-content: flex-end;
  margin: -6px 12px -6px 0;
}

.swap-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.swap-btn:hover {
  background: var(--tesla-red);
  color: #fff;
  border-color: var(--tesla-red);
  transform: rotate(180deg);
}

/* Autocomplete Suggestions */
.suggestions-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin-top: 4px;
  z-index: 1050;
  box-shadow: var(--shadow-lg);
  max-height: 220px;
  overflow-y: auto;
  display: none;
}

.suggestion-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.82rem;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 0.15s;
}

.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover { background-color: var(--bg-tertiary); }
.suggestion-item i { color: var(--text-muted); font-size: 0.8rem; }

/* Presets */
.quick-presets {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 0;
}

.preset-label {
  font-size: 0.72rem;
  color: var(--text-dim);
  font-weight: 500;
}

.preset-tag {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.72rem;
  padding: 4px 8px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.preset-tag:hover {
  background: var(--border-color);
  color: #fff;
  border-color: var(--text-muted);
}

.preset-tag:active {
  background: var(--tesla-red);
  color: #fff;
  border-color: var(--tesla-red);
  transform: scale(0.97);
}

/* Strategy Toggle & Routing Goal */
.routing-goal-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.strategy-toggle {
  display: flex;
  gap: 8px;
  background: var(--bg-input);
  padding: 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.strategy-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.2s;
}

.strategy-btn:hover {
  color: #fff;
  background: var(--bg-tertiary);
}

.strategy-btn:active {
  color: #fff;
  background: var(--bg-card);
}

.strategy-btn.active {
  background: var(--bg-card);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: var(--shadow-sm);
}

.strategy-params {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.param-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.param-row label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.param-row select {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  outline: none;
}

/* Map Mode Notification Banner — stay clear of top-right floating tools (BUG-1) */
.map-mode-banner {
  position: absolute;
  top: 18px;
  left: 16px;
  right: 72px; /* room for .map-floating-bar (~52px + gutter) */
  width: auto;
  max-width: none;
  transform: none;
  background: rgba(26, 30, 36, 0.95);
  backdrop-filter: blur(8px);
  border: 2px solid var(--accent-cyan);
  box-shadow: 0 6px 20px rgba(0, 180, 216, 0.3);
  padding: 10px 18px;
  border-radius: 30px;
  color: #fff;
  font-size: 0.82rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 12px;
  /* Below floating tools so Layers / Locate / Reset stay clickable */
  z-index: calc(var(--map-chrome-z, 1100) - 10);
  pointer-events: auto;
  animation: bannerSlideDown 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.map-mode-banner > span {
  flex: 1 1 auto;
  min-width: 0;
}

@keyframes bannerSlideDown {
  from { transform: translateY(-12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.pulse-icon {
  color: var(--accent-cyan);
  animation: pulseCyan 1.5s infinite;
}

@keyframes pulseCyan {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.cancel-banner-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  border-radius: 14px;
  padding: 4px 10px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
}

.cancel-banner-btn:hover {
  background: #ff4d4f;
  color: #fff;
  border-color: #ff4d4f;
}

/* Forced Marker & Legend */
.legend-color.forced {
  background: var(--accent-cyan);
  border: 2px solid #fff;
}

.timeline-item.supercharger.forced .timeline-marker {
  background: var(--accent-cyan) !important;
  border-color: #fff !important;
  color: #fff !important;
  box-shadow: 0 0 10px rgba(0, 180, 216, 0.6) !important;
}

.timeline-item.supercharger.forced .timeline-content {
  border-color: rgba(0, 180, 216, 0.5);
  background: rgba(0, 180, 216, 0.05);
}

.badge-forced {
  background: rgba(0, 180, 216, 0.2) !important;
  color: var(--accent-cyan) !important;
  border: 1px solid rgba(0, 180, 216, 0.4) !important;
}

/* Advanced Accordion */
.advanced-settings {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 14px;
}

.advanced-settings summary {
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  list-style: none;
}

.advanced-settings summary::-webkit-details-marker { display: none; }
.advanced-settings[open] summary .toggle-icon { transform: rotate(180deg); }

.settings-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border-subtle);
}

.setting-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.setting-item label {
  font-size: 0.68rem;
  color: var(--text-muted);
}

.setting-item-slider {
  gap: 2px;
}

.setting-item select {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 5px 7px;
  border-radius: var(--radius-sm);
  font-size: 0.74rem;
  outline: none;
}

.range-display {
  display: flex;
  align-items: center;
  gap: 6px;
}

.range-display input[type="range"] {
  flex: 1;
  height: 18px;
  accent-color: var(--tesla-red);
}

.range-display span {
  font-size: 0.72rem;
  font-weight: 600;
  width: 28px;
  flex-shrink: 0;
}

/* Primary Button */
.primary-btn {
  background: linear-gradient(135deg, var(--tesla-red), #d61a20);
  border: none;
  color: #fff;
  font-size: 0.92rem;
  font-weight: 600;
  padding: 13px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 14px rgba(232, 33, 39, 0.35);
  transition: all 0.2s;
}

.primary-btn:hover {
  background: linear-gradient(135deg, #f52d33, #e82127);
  box-shadow: 0 6px 20px rgba(232, 33, 39, 0.5);
  transform: translateY(-1px);
}

.primary-btn:active {
  transform: translateY(1px);
}

.secondary-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  transition: all 0.2s;
}

.secondary-btn:hover {
  background: var(--border-color);
  color: #fff;
}

/* Route Results */
.route-results {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stats-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.stat-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--tesla-red);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

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

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

.stat-val {
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
}

.corridor-banner {
  background: rgba(0, 180, 216, 0.12);
  border: 1px solid rgba(0, 180, 216, 0.3);
  color: var(--accent-cyan);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Timeline / Itinerary */
.itinerary-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-title h3 {
  font-size: 0.88rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
}

.timeline {
  display: flex;
  flex-direction: column;
  position: relative;
  padding-left: 20px;
}

.timeline::before {
  content: '';
  position: absolute;
  top: 14px;
  bottom: 14px;
  left: 9px;
  width: 2px;
  background: var(--border-color);
}

.timeline-item {
  position: relative;
  padding: 10px 0 10px 14px;
}

.timeline-marker {
  position: absolute;
  left: -20px;
  top: 14px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  z-index: 2;
}

.timeline-item.origin .timeline-marker {
  background: var(--accent-green);
  border-color: #fff;
  color: #fff;
}

.timeline-item.dest .timeline-marker {
  background: var(--tesla-red);
  border-color: #fff;
  color: #fff;
}

.timeline-item.supercharger .timeline-marker {
  background: #fff;
  border-color: var(--tesla-red);
  color: var(--tesla-red);
}

.timeline-content {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
  transition: border-color 0.2s, background-color 0.2s;
}

.timeline-content:hover {
  border-color: var(--tesla-red);
  background-color: var(--bg-tertiary);
}

.item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.item-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: #fff;
}

.item-badge {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
}

/* Destination arrival SOC — not always danger-red */
.item-badge.battery-ok {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-green);
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.item-badge.battery-warn {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-orange);
  border: 1px solid rgba(245, 158, 11, 0.4);
}

.item-badge.battery-danger {
  background: var(--tesla-red-subtle);
  color: var(--tesla-red);
  border: 1px solid rgba(232, 33, 39, 0.35);
}

.badge-charge {
  background: var(--tesla-red-subtle);
  color: var(--tesla-red);
  border: 1px solid rgba(232, 33, 39, 0.3);
}

.item-details {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.74rem;
  color: var(--text-muted);
}

.battery-tag {
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 500;
}

/* Explore Tab */
.explore-filters {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.filter-row {
  display: flex;
  gap: 10px;
}

.filter-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-col label {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.filter-col select {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 8px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  outline: none;
}

.charger-list-header {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  font-weight: 600;
}

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

.charger-list-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: all 0.2s;
}

.charger-list-item:hover {
  border-color: var(--tesla-red);
  background-color: var(--bg-tertiary);
}

.charger-list-title {
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.charger-list-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.charger-list-tags {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.chip {
  font-size: 0.68rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-tertiary);
  color: var(--text-muted);
}
.chip.red { color: var(--tesla-red); background: var(--tesla-red-subtle); }
.chip.green { color: var(--accent-green); background: rgba(16, 185, 129, 0.15); }

/* Map View */
.map-container {
  flex: 1;
  position: relative;
  height: 100%;
  /* Keep floating chrome above Leaflet panes while panning/zooming */
  isolation: isolate;
  --map-chrome-z: 1100;
}

#map {
  width: 100%;
  height: 100%;
  background: #242424;
  /* Tiles/markers stay below absolute chrome siblings */
  z-index: 0;
}

/*
 * Darken OSM tiles without CSS filter on the tile pane.
 * filter + Leaflet's CSS transform zoom/pinch re-rasterizes every frame → flicker
 * (Tesla Chromium, mobile, desktop). Opacity composites cleanly during zoomanim.
 */
.leaflet-tile-pane {
  opacity: 0.88;
}

/* Topographic basemap: keep terrain colors readable under dark chrome */
#map.basemap-topo .leaflet-tile-pane {
  opacity: 0.96;
}

.leaflet-control-attribution {
  background: rgba(26, 30, 36, 0.85) !important;
  color: var(--text-dim);
  font-size: 0.65rem;
}

.leaflet-control-attribution a {
  color: var(--text-muted);
}

/* Layers panel (opened by map layers button) */
.layers-panel {
  position: absolute;
  top: 18px;
  right: 68px;
  z-index: calc(var(--map-chrome-z, 1100) + 20);
  width: 240px;
  max-width: calc(100% - 90px);
  padding: 12px 14px;
  background: rgba(26, 30, 36, 0.96);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  color: var(--text-muted);
}

.layers-panel-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 8px;
}

.layers-section-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin: 10px 0 4px;
}

.layers-option {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: 4px 0;
  cursor: pointer;
}

.layers-option:hover {
  color: var(--text-main);
}

.layers-option input {
  accent-color: var(--tesla-red);
  margin: 0;
}

.map-btn.is-active {
  background: var(--tesla-red);
  color: #fff;
  border-color: var(--tesla-red);
}

/* Live follow-me (client-side geolocation) — cyan, not Tesla red */
.map-btn.is-live-follow,
.map-btn.is-active.is-live-follow {
  background: rgba(14, 165, 233, 0.28);
  color: #7dd3fc;
  border-color: rgba(56, 189, 248, 0.75);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.25);
}

.map-btn.is-live-paused {
  color: #7dd3fc;
  border-color: rgba(56, 189, 248, 0.45);
}

/* Blue-dot user marker (driving follow-me) */
.user-location-icon {
  background: transparent !important;
  border: none !important;
}

.user-location-pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(56, 189, 248, 0.35);
  animation: user-loc-pulse 2.2s ease-out infinite;
  pointer-events: none;
}

.user-location-dot {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border-radius: 50%;
  background: #0ea5e9;
  border: 2.5px solid #f8fafc;
  box-shadow: 0 0 0 1px rgba(14, 165, 233, 0.55), 0 2px 8px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.user-location-heading {
  position: absolute;
  left: 50%;
  top: -7px;
  width: 0;
  height: 0;
  margin-left: -5px;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 8px solid #e0f2fe;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35));
}

@keyframes user-loc-pulse {
  0% {
    transform: scale(0.55);
    opacity: 0.7;
  }
  70% {
    transform: scale(1.55);
    opacity: 0;
  }
  100% {
    transform: scale(1.55);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .user-location-pulse {
    animation: none;
    opacity: 0.35;
  }
}

/* Client-Side Live Driving HUD (speed/heading, next Supercharger distance, Re-center pill) */
.live-drive-hud {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: var(--map-chrome-z, 1100);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  max-width: calc(100% - 88px);
  pointer-events: none;
}

.live-drive-hud[hidden] {
  display: none !important;
}

.live-hud-pill {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(20, 24, 30, 0.92);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(56, 189, 248, 0.55);
  box-shadow: var(--shadow-md);
  color: var(--text-main);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.2;
}

.live-hud-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #38bdf8;
  box-shadow: 0 0 8px #38bdf8;
  flex-shrink: 0;
}

.live-hud-speed {
  color: #e0f2fe;
  white-space: nowrap;
}

.live-hud-sep {
  color: var(--text-dim);
}

.live-hud-next {
  color: #7dd3fc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

.live-recenter-btn,
.live-replan-btn {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(56, 189, 248, 0.8);
  background: rgba(14, 165, 233, 0.28);
  backdrop-filter: blur(8px);
  color: #f0f9ff;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.live-replan-btn {
  border-color: rgba(245, 158, 11, 0.85);
  background: rgba(245, 158, 11, 0.25);
  color: #fef3c7;
}

.live-recenter-btn:hover,
.live-recenter-btn:active {
  background: #0284c7;
  color: #fff;
}

.live-replan-btn:hover,
.live-replan-btn:active {
  background: #d97706;
  color: #fff;
}

body.car-shell .live-drive-hud {
  top: 36px;
  left: 8px;
  gap: 6px;
  max-width: calc(100% - 70px);
}

body.car-shell .live-recenter-btn,
body.car-shell .live-replan-btn {
  min-height: 40px;
  padding: 6px 12px;
  font-size: 0.74rem;
}

body.ui-mobile .live-drive-hud {
  top: calc(10px + var(--safe-top));
  left: calc(10px + var(--safe-left));
  max-width: calc(100% - 62px);
  gap: 5px;
}

body.ui-mobile.sheet-open .live-drive-hud {
  top: calc(64px + var(--safe-top));
}

body.ui-mobile .live-hud-next {
  max-width: 155px;
}

@media (max-width: 720px) {
  .layers-panel {
    top: 12px;
    right: 58px;
    width: 210px;
  }
}

/* Map Floating Tools — viewport-fixed siblings of #map (do not pan with tiles) */
.map-floating-bar {
  position: absolute;
  top: 18px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: var(--map-chrome-z, 1100);
  pointer-events: none;
  max-height: calc(100% - 36px);
  overflow: visible;
}

.map-floating-bar > * {
  pointer-events: auto;
}

.map-area-tools,
.map-view-tools {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px;
  border-radius: var(--radius-md);
  background: rgba(26, 30, 36, 0.82);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  flex-shrink: 0;
}

.map-view-tools {
  gap: 6px;
}

.map-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.map-area-tools .map-btn,
.map-view-tools .map-btn {
  box-shadow: none;
}

.map-btn:hover {
  background: var(--tesla-red);
  color: #fff;
  border-color: var(--tesla-red);
}

.map-btn:active {
  background: var(--tesla-red-hover);
  color: #fff;
  border-color: var(--tesla-red-hover);
  transform: scale(0.96);
}

/* Active = currently drawing only (not a resting “preferred tool” look) */
.map-btn.area-mode-btn.active,
.map-btn.area-mode-btn.drawing {
  background: #00b4d8;
  color: #fff;
  border-color: #00b4d8;
}

.map-btn.map-btn-danger:hover:not(:disabled) {
  background: #b91c1c;
  border-color: #b91c1c;
}

.map-btn:disabled,
.map-btn[aria-disabled="true"] {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* Hide Clear until there is something to clear — quieter toolbar */
#btnClearSelection:disabled,
#btnClearSelection[aria-disabled="true"] {
  display: none;
}

/* Map Legend */
.map-legend {
  position: absolute;
  bottom: 24px;
  right: 20px;
  background: rgba(26, 30, 36, 0.9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 16px;
  z-index: var(--map-chrome-z, 1100);
  box-shadow: var(--shadow-md);
  pointer-events: none;
}

.map-legend .legend-item[hidden] {
  display: none !important;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
}

.legend-color {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.legend-color.orig { background: var(--accent-green); }
.legend-color.stop { background: var(--tesla-red); border: 2px solid #fff; }
.legend-color.corridor { background: #ffaa00; }
.legend-color.dest { background: #e82127; }

/* Charger Drawer */
.charger-drawer {
  position: absolute;
  bottom: 24px;
  left: 24px;
  width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-lg);
  z-index: 1050;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.close-drawer-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
}

.drawer-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-green);
  border: 1px solid rgba(16, 185, 129, 0.3);
  margin-bottom: 4px;
}

.drawer-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
}

.drawer-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.drawer-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  background: var(--bg-secondary);
  padding: 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.drawer-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.d-label {
  font-size: 0.65rem;
  color: var(--text-dim);
  text-transform: uppercase;
}

.d-val {
  font-size: 0.85rem;
  font-weight: 700;
  color: #fff;
  margin-top: 2px;
}

.drawer-amenities {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.drawer-actions {
  display: flex;
  gap: 10px;
}

.drawer-actions .primary-btn {
  flex: 1;
  padding: 10px;
  font-size: 0.82rem;
}

.drawer-actions .secondary-btn {
  flex: 1;
  padding: 10px;
  font-size: 0.82rem;
}

/* Custom Leaflet Dark Mode styling */
.leaflet-container {
  background-color: #191a1a !important;
}

.leaflet-popup-content-wrapper {
  background: var(--bg-card) !important;
  color: var(--text-main) !important;
  border-radius: var(--radius-md) !important;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg) !important;
}

.leaflet-popup-tip {
  background: var(--bg-card) !important;
}

.custom-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

/* Responsive — phone / narrow (NOT when car-shell is active) */
@media (max-width: 860px) {
  body:not(.car-shell) .app-container {
    flex-direction: column;
  }
  body:not(.car-shell) .sidebar {
    width: 100%;
    min-width: unset;
    height: 50vh;
  }
  body:not(.car-shell) .map-container {
    height: 50vh;
  }
  body:not(.car-shell) .charger-drawer {
    left: 12px;
    right: 12px;
    bottom: 12px;
    width: auto;
  }
}

/* ------------------------------------------------------------------ */
/* Tesla car shell — map-first + bottom plan sheet (773×601 primary)  */
/* Activated via body.car-shell (JS detect / ?car=1). Not phone /mobile */
/* ------------------------------------------------------------------ */

.app-toast {
  position: fixed;
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  z-index: 4000;
  max-width: min(520px, calc(100vw - 24px));
  padding: 14px 18px;
  border-radius: 12px;
  background: rgba(32, 38, 46, 0.96);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.35;
  box-shadow: var(--shadow-lg);
  text-align: center;
  pointer-events: none;
}

.app-toast[hidden] {
  display: none !important;
}

.car-sheet-chrome {
  display: none;
}

body.car-shell {
  /* peek → half(plan) → nearly-full(itinerary); map dominates in peek */
  --car-sheet-h: 72px;
  /* Compact visual; hit ≥40px (smaller buttons/gaps, more map) */
  --car-touch: 40px;
  --car-icon-font: 0.85rem;
  --car-gap: 3px;
}

body.car-shell .car-sheet-chrome {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  gap: 0;
  padding: 4px 6px 4px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

body.car-shell .app-container {
  display: block;
  position: relative;
}

body.car-shell .map-container {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

body.car-shell .sidebar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  min-width: 0;
  height: var(--car-sheet-h) !important;
  max-height: var(--car-sheet-h) !important;
  z-index: 1200;
  border-right: none;
  border-top: 1px solid var(--border-color);
  border-radius: 12px 12px 0 0;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.4);
  background: var(--bg-primary);
  /* Instant expand — animated height made taps feel “stuck” at peek */
  transition: none;
  overflow: hidden;
}

body.car-shell[data-sheet="plan"] .sidebar,
body.car-shell[data-sheet="itinerary"] .sidebar {
  overflow-x: hidden;
  overflow-y: auto;
}

body.car-shell[data-sheet="peek"] {
  /* Single row ≈12% @ 601px (was 88px/~15%, earlier ~148px/~25%) */
  --car-sheet-h: 72px;
}

body.car-shell[data-sheet="plan"] {
  /* Half sheet — denser form, still usable */
  --car-sheet-h: min(280px, 48vh);
}

body.car-shell[data-sheet="itinerary"] {
  /* Nearly full under browser chrome; leave a map strip */
  --car-sheet-h: min(520px, 86vh);
}

/* Brand header always gone in car mode — peek chip is enough */
body.car-shell .sidebar-header {
  display: none !important;
}

/* Peek no longer has route chips — keep compact presets in Edit/plan form */
body.car-shell[data-sheet="peek"] .route-form > .quick-presets {
  display: none !important;
}

body.car-shell[data-sheet="plan"] .route-form > .quick-presets,
body.car-shell[data-sheet="itinerary"] .route-form > .quick-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 2px 0;
}

body.car-shell[data-sheet="plan"] .route-form > .quick-presets .preset-tag,
body.car-shell[data-sheet="itinerary"] .route-form > .quick-presets .preset-tag {
  min-height: 36px;
  padding: 4px 8px;
  font-size: 0.7rem;
}

body.car-shell[data-sheet="peek"] .tab-content {
  display: none !important;
}

body.car-shell[data-sheet="plan"] .route-results {
  display: none !important;
}

/* Full sheet: keep form + results stacked and scrollable */
body.car-shell[data-sheet="itinerary"] .route-results {
  display: block;
}

/* Peek tabs (Route | Explore) — replace suggested-route chips */
body.car-shell .car-peek-tabs {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  align-items: stretch;
  gap: 0;
  height: 40px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-tertiary);
}

body.car-shell .car-peek-tab {
  flex: 1 1 0;
  min-width: 0;
  min-height: 40px;
  height: 40px;
  padding: 0 6px;
  border: none;
  border-right: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  white-space: nowrap;
}

body.car-shell .car-peek-tab:last-child {
  border-right: none;
}

body.car-shell .car-peek-tab.active {
  background: rgba(232, 33, 39, 0.18);
  color: #fff;
  box-shadow: inset 0 -2px 0 var(--tesla-red);
}

body.car-shell .car-peek-tab:active {
  background: var(--border-color);
}

body.car-shell .car-sheet-handle {
  flex: 0 0 auto;
  width: 36px;
  min-width: 36px;
  min-height: 40px;
  margin: 0;
  padding: 2px 2px;
  border: none;
  background: transparent;
  cursor: pointer;
  touch-action: none; /* pointer drag expand/collapse */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
}

body.car-shell .car-sheet-grip {
  width: 22px;
  height: 3px;
  border-radius: 999px;
  background: var(--text-dim);
}

body.car-shell .car-sheet-hint {
  font-size: 0.5rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-muted);
  line-height: 1;
}

body.car-shell .car-sheet-handle:active .car-sheet-grip {
  background: var(--text-muted);
}

body.car-shell .car-peek-bar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 4px;
  min-height: 40px;
  height: 40px;
}

body.car-shell .car-peek-brand {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  flex: 0 1 auto;
  max-width: 28%;
}

body.car-shell .car-peek-text {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-width: 0;
}

body.car-shell .car-peek-text strong {
  font-size: 0.68rem;
  color: #fff;
  line-height: 1.05;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
}

body.car-shell .car-mode-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 14px;
  padding: 0 4px;
  border-radius: 3px;
  background: var(--tesla-red);
  color: #fff;
  font-size: 0.55rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

body.car-shell .car-mode-badge {
  display: flex !important;
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: var(--map-chrome-z, 1100);
  min-height: 20px;
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(232, 33, 39, 0.78);
  color: #fff;
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  box-shadow: var(--shadow-sm);
  pointer-events: none;
  opacity: 0.9;
}

.car-mode-badge[hidden] {
  display: none !important;
}

body.car-shell .car-peek-summary {
  font-size: 0.58rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 22vw;
  line-height: 1.1;
}

body.car-shell .car-peek-actions {
  display: flex;
  gap: var(--car-gap);
  flex-shrink: 0;
  margin-left: auto;
}

body.car-shell .car-peek-btn {
  min-height: 40px;
  height: 40px;
  min-width: 40px;
  padding: 0 7px;
  border-radius: 7px;
  border: 1px solid var(--border-color);
  background: var(--bg-tertiary);
  color: var(--text-main);
  font-weight: 700;
  font-size: 0.7rem;
  cursor: pointer;
  touch-action: manipulation;
  line-height: 1;
}

body.car-shell .car-peek-btn.car-peek-locate {
  min-width: 40px;
  width: 40px;
  padding: 0;
  font-size: 0.8rem;
}

body.car-shell .car-peek-btn.car-peek-locate.is-locating,
body.car-shell #btnLocateMe.is-locating,
body.car-shell .car-peek-btn.car-peek-locate.is-live-follow,
body.car-shell .car-peek-btn.car-peek-locate.is-live-paused {
  color: #7dd3fc;
  border-color: rgba(0, 180, 216, 0.55);
}

body.car-shell .car-peek-btn.car-peek-locate.is-live-follow {
  background: rgba(14, 165, 233, 0.22);
  border-color: rgba(56, 189, 248, 0.7);
}

body.car-shell .car-peek-btn:active {
  transform: scale(0.97);
  background: var(--border-color);
}

body.car-shell .car-peek-btn-primary {
  background: var(--tesla-red);
  border-color: #ff4d52;
  color: #fff;
}

body.car-shell .car-peek-btn-primary:active {
  background: var(--tesla-red-hover);
}

body.car-shell .subtitle {
  display: none;
}

/* Sidebar tabs hidden — peek bar owns Route | Explore */
body.car-shell .tabs {
  display: none !important;
}

body.car-shell .tab-btn {
  min-height: 36px;
  font-size: 0.72rem;
  padding: 4px 6px;
  gap: 4px;
}

/* Map tap hid the sheet — full-bleed map + restore FAB */
body.car-shell.car-chrome-hidden .sidebar {
  display: none !important;
  height: 0 !important;
  max-height: 0 !important;
}

body.car-shell .car-show-sheet {
  display: none;
}

body.car-shell.car-chrome-hidden .car-show-sheet {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  position: absolute;
  z-index: 1300;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  min-height: 44px;
  min-width: 88px;
  padding: 8px 16px;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background: rgba(26, 30, 36, 0.94);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  touch-action: manipulation;
}

body.car-shell.car-chrome-hidden .car-show-sheet:active {
  background: var(--tesla-red);
  border-color: var(--tesla-red);
}

body.car-shell .tab-content {
  padding: 4px 8px 8px;
  gap: 4px;
}

/* Expanded: allow switchTab() inline display; peek rule above forces hide */

body.car-shell .route-form {
  gap: 4px;
}

body.car-shell .form-group {
  margin: 0;
  gap: 2px;
}

/* Compact compose: placeholders only — labels ate the map in the photo */
body.car-shell[data-sheet="plan"] .input-header label {
  display: none;
}

body.car-shell[data-sheet="plan"] .input-header {
  justify-content: flex-end;
  min-height: 0;
  margin-bottom: 0;
  padding: 0;
}

body.car-shell[data-sheet="plan"] .swap-container {
  display: none;
}

body.car-shell[data-sheet="plan"] .advanced-settings {
  display: none;
}

body.car-shell[data-sheet="plan"] .routing-goal-section {
  padding: 4px 6px;
  gap: 4px;
  margin: 0;
}

body.car-shell[data-sheet="plan"] .routing-goal-section .input-header {
  display: none;
}

body.car-shell .input-wrapper input {
  min-height: 40px;
  height: 40px;
  font-size: 0.85rem;
  padding-top: 4px;
  padding-bottom: 4px;
}

body.car-shell .clear-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

body.car-shell .link-btn {
  min-height: 32px;
  padding: 4px 8px;
  font-size: 0.72rem;
  border-radius: 7px;
  background: rgba(0, 180, 216, 0.12);
}

body.car-shell .link-btn:active {
  background: rgba(0, 180, 216, 0.28);
  text-decoration: none;
}

body.car-shell .quick-presets {
  gap: 4px;
}

body.car-shell .preset-label {
  width: 100%;
  font-size: 0.68rem;
}

body.car-shell .strategy-toggle {
  gap: 4px;
}

body.car-shell .strategy-btn {
  min-height: 40px;
  font-size: 0.7rem;
  padding: 4px 6px;
}

body.car-shell .primary-btn {
  min-height: 40px;
  font-size: 0.85rem;
  padding: 8px;
  margin-top: 2px;
}

body.car-shell[data-sheet="plan"] .strategy-params {
  display: none; /* max-stops stays at default; reclaim height */
}

body.car-shell .primary-btn:hover {
  transform: none;
}

body.car-shell .primary-btn:active {
  transform: scale(0.98);
  filter: brightness(0.92);
}

body.car-shell .swap-btn {
  width: 40px;
  height: 40px;
}

body.car-shell .map-floating-bar {
  top: 8px;
  right: 8px;
  gap: 5px;
  /* Stay above tiles; never scroll/clip — My Location must remain visible */
  z-index: var(--map-chrome-z, 1100);
  max-height: none;
  overflow: visible;
  flex-shrink: 0;
}

body.car-shell .map-area-tools,
body.car-shell .map-view-tools {
  gap: 3px;
  padding: 3px;
  flex-shrink: 0;
}

/* Prefer horizontal area cluster on short Tesla panes — less vertical collision */
body.car-shell .map-area-tools {
  flex-direction: row;
}

body.car-shell .map-btn {
  /* Familiar/small visual; 40px hit */
  width: var(--car-touch);
  height: var(--car-touch);
  min-width: var(--car-touch);
  min-height: var(--car-touch);
  flex-shrink: 0;
  font-size: var(--car-icon-font);
  border-radius: 8px;
  box-sizing: border-box;
}

/* Top-right My Location (#btnLocateMe) stays visible in car-shell (peek duplicate OK) */
body.car-shell #btnLocateMe {
  display: flex;
}

body.car-shell .map-btn:hover {
  /* Prefer active/pressed feedback in car — keep hover subtle */
  background: var(--bg-tertiary);
  color: var(--text-main);
  border-color: var(--border-color);
}

body.car-shell .map-btn:active,
body.car-shell .map-btn.is-active:active {
  background: var(--tesla-red);
  color: #fff;
  border-color: var(--tesla-red);
}

/* Tesla: no +/- zoom chrome — pinch / scroll / double-tap still work; desktop keeps control */
body.car-shell .leaflet-control-zoom {
  display: none !important;
}

/* Legend competed with tools at 773×601 — hide in car mode */
body.car-shell .map-legend {
  display: none !important;
}

body.car-shell .layers-panel {
  top: 12px;
  right: calc(12px + var(--car-touch) + 12px);
  width: min(260px, calc(100vw - 100px));
  max-height: calc(100% - var(--car-sheet-h) - 28px);
  overflow-y: auto;
  padding: 14px;
}

body.car-shell .layers-option {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
  padding: 6px 0;
}

body.car-shell .map-mode-banner {
  top: 12px;
  left: 12px;
  /* Clear horizontal area tools + view tools cluster */
  right: calc(12px + (var(--car-touch) * 3) + 28px);
  transform: none;
  font-size: 0.85rem;
  padding: 10px 12px;
  gap: 10px;
  z-index: calc(var(--map-chrome-z, 1100) - 10);
}

body.car-shell .cancel-banner-btn {
  min-height: 44px;
  min-width: 88px;
  padding: 8px 12px;
}

body.car-shell .charger-drawer {
  left: 12px;
  right: 12px;
  bottom: calc(var(--car-sheet-h) + 10px);
  width: auto;
  max-height: calc(100% - var(--car-sheet-h) - 24px);
  overflow-y: auto;
  padding: 16px;
  /* Above map tools (1100) so close/add-stop stay tappable */
  z-index: 1400;
}

body.car-shell .close-drawer-btn {
  width: 48px;
  height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: var(--bg-tertiary);
}

body.car-shell .close-drawer-btn:active {
  background: var(--border-color);
}

body.car-shell .drawer-actions .primary-btn,
body.car-shell .drawer-actions .secondary-btn {
  min-height: 48px;
  font-size: 0.9rem;
  padding: 12px;
}

body.car-shell .timeline-item.supercharger .timeline-content {
  min-height: 52px;
  padding: 10px 8px;
}

body.car-shell .suggestion-item {
  min-height: 48px;
  padding: 12px 10px;
}

body.car-shell .suggestion-item:active {
  background: var(--bg-tertiary);
}

/* Taller car canvas: keep peek ~12% of height */
@media (min-height: 720px) {
  body.car-shell[data-sheet="peek"] {
    --car-sheet-h: 78px;
  }
  body.car-shell[data-sheet="plan"] {
    --car-sheet-h: min(300px, 46vh);
  }
  body.car-shell[data-sheet="itinerary"] {
    --car-sheet-h: min(580px, 84vh);
  }
}

/* --------------------------------------------------------------------------
   Mobile shell (/mobile or ?ui=mobile) — map-first, planner as bottom sheet.
   Explicit entry preferred over User-Agent sniffing (see server MOBILE_UA_REDIRECT).
   Safari: viewport-fit=cover + env(safe-area-inset-*) + --vv-bottom (visualViewport).
   -------------------------------------------------------------------------- */
.mobile-sheet-toggle {
  display: none;
}

body.ui-mobile {
  /* Prefer dynamic viewport units on mobile browsers when available */
  height: 100%;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  /* JS updateMobileViewportInsets() sets --vv-bottom for Safari URL/toolbar overlay */
  --vv-bottom: 0px;
  --mobile-chrome-bottom: calc(var(--safe-bottom) + var(--vv-bottom));
  --mobile-plan-h: 48px;
  --mobile-fab-gap: 12px;
  /* Brand row removed — shorter sheet, more map (/mobile photo) */
  --mobile-sheet-h: min(42dvh, 340px);
}

body.ui-mobile .app-container {
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  box-sizing: border-box;
  position: relative;
}

body.ui-mobile .map-container {
  flex: 1 1 auto;
  width: 100%;
  height: auto;
  min-height: 42dvh;
  order: 1;
  position: relative;
}

body.ui-mobile .sidebar {
  order: 2;
  width: 100%;
  min-width: unset;
  height: 0;
  max-height: 0;
  border-right: none;
  border-top: 1px solid var(--border-color);
  box-shadow: none;
  overflow: hidden;
  transition: max-height 0.22s ease, height 0.22s ease;
}

body.ui-mobile.sheet-open .sidebar {
  height: var(--mobile-sheet-h);
  max-height: var(--mobile-sheet-h);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  /* Lift sheet above Safari toolbar so Destination is not clipped */
  margin-bottom: var(--mobile-chrome-bottom);
  padding-bottom: 16px;
  box-sizing: border-box;
}

/* Map-first: Plan clears home indicator + Safari toolbar overlay */
body.ui-mobile .mobile-sheet-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  position: absolute;
  z-index: 1200;
  left: 50%;
  bottom: calc(var(--mobile-fab-gap) + var(--mobile-chrome-bottom));
  transform: translateX(-50%);
  min-height: var(--mobile-plan-h);
  min-width: 96px;
  padding: 12px 22px;
  border: 1px solid var(--border-color);
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--text-main);
  font-size: 1rem;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Sheet open: Map FAB top-left — never overlaps legend / sheet seam */
body.ui-mobile.sheet-open .mobile-sheet-toggle {
  top: calc(10px + var(--safe-top));
  bottom: auto;
  left: calc(10px + var(--safe-left));
  right: auto;
  transform: none;
  background: var(--tesla-red);
  border-color: var(--tesla-red);
  color: #fff;
  min-width: 88px;
}

body.ui-mobile .map-floating-bar {
  top: calc(10px + var(--safe-top));
  right: calc(10px + var(--safe-right));
  gap: 4px;
  z-index: var(--map-chrome-z, 1100);
  max-height: calc(100% - var(--mobile-plan-h, 56px) - var(--mobile-chrome-bottom, 0px) - 24px);
}

body.ui-mobile .map-area-tools,
body.ui-mobile .map-view-tools {
  gap: 3px;
  padding: 2px;
}

/*
 * Legend sits above Plan (+ chrome). Kept tiny — no need for a big key on phones.
 * When sheet is open, hide legend — map strip is short; Map FAB owns that space.
 */
body.ui-mobile .map-legend {
  left: calc(8px + var(--safe-left));
  right: auto;
  bottom: calc(var(--mobile-plan-h) + var(--mobile-fab-gap) + var(--mobile-chrome-bottom) + 8px);
  max-width: min(118px, calc(100vw - 100px));
  flex-wrap: wrap;
  gap: 2px 5px;
  padding: 3px 5px;
  border-radius: 6px;
  z-index: 1000;
  pointer-events: none;
  opacity: 0.85;
}

/* Keep only Origin / Stop / Destination on phones — drop the long labels */
body.ui-mobile .map-legend .legend-item:nth-child(2),
body.ui-mobile .map-legend .legend-item:nth-child(4) {
  display: none;
}

body.ui-mobile .map-legend .legend-item {
  gap: 3px;
  font-size: 0.55rem;
  line-height: 1.1;
  font-weight: 500;
}

body.ui-mobile .map-legend .legend-color {
  width: 5px;
  height: 5px;
  flex-shrink: 0;
}

body.ui-mobile .map-legend .legend-color.stop,
body.ui-mobile .map-legend .legend-color.forced {
  border-width: 1px;
}

body.ui-mobile.sheet-open .map-legend {
  display: none;
}

/* Smaller map tools on /mobile (Plan FAB stays full-size for Safari tap clearance) */
body.ui-mobile .map-btn,
body.ui-mobile .map-area-tools .map-btn,
body.ui-mobile .map-view-tools .map-btn {
  width: 30px;
  height: 30px;
  font-size: 0.72rem;
  border-radius: 8px;
}

body.ui-mobile .leaflet-control-zoom a {
  width: 28px !important;
  height: 28px !important;
  line-height: 28px !important;
  font-size: 14px !important;
}

body.ui-mobile .charger-drawer {
  left: calc(10px + var(--safe-left));
  right: calc(10px + var(--safe-right));
  bottom: calc(10px + var(--mobile-chrome-bottom));
  width: auto;
  max-height: 50dvh;
}

body.ui-mobile.sheet-open .charger-drawer {
  bottom: calc(var(--mobile-sheet-h) + 8px + var(--mobile-chrome-bottom));
  max-height: 36dvh;
}

body.ui-mobile .layers-panel {
  max-width: calc(100vw - 72px);
  top: calc(10px + var(--safe-top));
}

/*
 * In-car /mobile photo: kill "Supercharge Route" brand row.
 * Tabs (Route Planner | Explore) own the top of the bottom sheet.
 */
body.ui-mobile .sidebar-header {
  display: none !important;
}

body.ui-mobile .tabs {
  gap: 0;
  padding: 0;
  margin: 0;
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-secondary, var(--bg-card));
  border-bottom: 1px solid var(--border-color);
}

body.ui-mobile .tab-btn {
  min-height: 40px;
  font-size: 0.78rem;
  padding: 6px 8px;
  gap: 5px;
}

body.ui-mobile .route-form,
body.ui-mobile .tab-content {
  padding: 6px 10px 8px;
  gap: 6px;
}

body.ui-mobile .form-group {
  margin: 0;
  gap: 2px;
}

body.ui-mobile .input-header {
  margin-bottom: 2px;
  min-height: 0;
}

body.ui-mobile .input-header label {
  font-size: 0.68rem;
  letter-spacing: 0.02em;
}

body.ui-mobile .link-btn {
  min-height: 32px;
  padding: 2px 6px;
  font-size: 0.72rem;
}

body.ui-mobile .input-wrapper input,
body.ui-mobile .input-wrapper select,
body.ui-mobile input[type="text"],
body.ui-mobile select {
  min-height: 40px;
  height: 40px;
  font-size: 16px; /* avoid iOS zoom-on-focus */
  padding-top: 6px;
  padding-bottom: 6px;
}

body.ui-mobile .swap-container {
  margin: 2px 0;
}

body.ui-mobile .swap-btn {
  width: 36px;
  height: 36px;
  min-height: 36px;
  min-width: 36px;
}

body.ui-mobile .quick-presets {
  gap: 4px;
  margin: 2px 0;
}

body.ui-mobile .preset-label {
  font-size: 0.68rem;
}

body.ui-mobile .preset-tag {
  min-height: 36px;
  padding: 4px 8px;
  font-size: 0.72rem;
}

body.ui-mobile .clear-btn {
  width: 36px;
  height: 36px;
  min-height: 36px;
  min-width: 36px;
}

body.ui-mobile .strategy-toggle button {
  min-height: 40px;
  font-size: 0.72rem;
  padding: 6px;
}

body.ui-mobile .routing-goal-section {
  padding: 6px 8px;
  gap: 4px;
}

body.ui-mobile .primary-btn {
  min-height: 42px;
  font-size: 0.9rem;
  width: 100%;
  padding: 8px;
  margin-top: 2px;
}

body.ui-mobile #mapModeBanner {
  left: calc(10px + var(--safe-left));
  /* Keep Clear of right floating toolbar */
  right: calc(58px + var(--safe-right));
  top: calc(10px + var(--safe-top));
  width: auto;
  transform: none;
  font-size: 0.82rem;
  padding: 10px 12px;
  line-height: 1.35;
  z-index: calc(var(--map-chrome-z, 1100) - 10);
}

/*
 * Leaflet owns pan + pinch (default touch-action: none on .leaflet-container).
 * pan-x pan-y blocks pinch-zoom and fights touchZoom → janky / flickering zoom.
 */
body.ui-mobile .map-container,
body.ui-mobile #map,
body.car-shell .map-container,
body.car-shell #map {
  touch-action: none;
}

body.ui-mobile.area-drawing .map-container,
body.ui-mobile.area-drawing #map {
  touch-action: none;
}

/* Very short landscape / split Safari: keep sheet scrollable, map visible */
@media (max-height: 560px) {
  body.ui-mobile {
    --mobile-sheet-h: min(55dvh, 320px);
  }
  body.ui-mobile .map-legend .legend-item:nth-child(n + 4) {
    display: none;
  }
}
