/* ───── CSS Variables for Light/Dark Mode ───── */
:root {
  /* Background colors */
  --bg-primary: #ffffff;
  --bg-secondary: #f9fafb;
  --bg-tertiary: #f3f4f6;
  --bg-code: #f5f5f5;
  --bg-hover: rgba(0, 0, 0, 0.05);
  --bg-active: #f0f0f0;
  
  /* Text colors */
  --text-primary: #111827;
  --text-secondary: #374151;
  --text-tertiary: #6b7280;
  --text-muted: #999;
  --text-code: #333;
  
  /* Border colors */
  --border-primary: #e5e7eb;
  --border-secondary: #d1d5db;
  --border-tertiary: #ccc;
  --border-muted: #ddd;
  
  /* Shadow */
  --shadow-sm: rgba(0, 0, 0, 0.1);
  --shadow-md: rgba(0, 0, 0, 0.15);
  --shadow-lg: rgba(0, 0, 0, 0.2);
  
  /* Link colors */
  --link-color: #3b82f6;
  --link-hover: #2563eb;
}

/* Dark mode - System preference (only if no manual override) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    /* Background colors */
    --bg-primary: #1f2937;
    --bg-secondary: #111827;
    --bg-tertiary: #374151;
    --bg-code: #374151;
    --bg-hover: rgba(255, 255, 255, 0.1);
    --bg-active: #4b5563;
    
    /* Text colors */
    --text-primary: #f9fafb;
    --text-secondary: #e5e7eb;
    --text-tertiary: #d1d5db;
    --text-muted: #9ca3af;
    --text-code: #e5e7eb;
    
    /* Border colors */
    --border-primary: #4b5563;
    --border-secondary: #6b7280;
    --border-tertiary: #6b7280;
    --border-muted: #4b5563;
    
    /* Shadow */
    --shadow-sm: rgba(0, 0, 0, 0.3);
    --shadow-md: rgba(0, 0, 0, 0.4);
    --shadow-lg: rgba(0, 0, 0, 0.5);
    
    /* Link colors */
    --link-color: #60a5fa;
    --link-hover: #93c5fd;
  }
}

/* Manual dark mode toggle - higher specificity than media query */
html[data-theme="dark"] {
  /* Background colors */
  --bg-primary: #1f2937;
  --bg-secondary: #111827;
  --bg-tertiary: #374151;
  --bg-code: #374151;
  --bg-hover: rgba(255, 255, 255, 0.1);
  --bg-active: #4b5563;
  
  /* Text colors */
  --text-primary: #f9fafb;
  --text-secondary: #e5e7eb;
  --text-tertiary: #d1d5db;
  --text-muted: #9ca3af;
  --text-code: #e5e7eb;
  
  /* Border colors */
  --border-primary: #4b5563;
  --border-secondary: #6b7280;
  --border-tertiary: #6b7280;
  --border-muted: #4b5563;
  
  /* Shadow */
  --shadow-sm: rgba(0, 0, 0, 0.3);
  --shadow-md: rgba(0, 0, 0, 0.4);
  --shadow-lg: rgba(0, 0, 0, 0.5);
  
  /* Link colors */
  --link-color: #60a5fa;
  --link-hover: #93c5fd;
}

/* Manual light mode override (forces light mode even if system prefers dark) */
html[data-theme="light"] {
  /* Background colors */
  --bg-primary: #ffffff;
  --bg-secondary: #f9fafb;
  --bg-tertiary: #f3f4f6;
  --bg-code: #f5f5f5;
  --bg-hover: rgba(0, 0, 0, 0.05);
  --bg-active: #f0f0f0;
  
  /* Text colors */
  --text-primary: #111827;
  --text-secondary: #374151;
  --text-tertiary: #6b7280;
  --text-muted: #999;
  --text-code: #333;
  
  /* Border colors */
  --border-primary: #e5e7eb;
  --border-secondary: #d1d5db;
  --border-tertiary: #ccc;
  --border-muted: #ddd;
  
  /* Shadow */
  --shadow-sm: rgba(0, 0, 0, 0.1);
  --shadow-md: rgba(0, 0, 0, 0.15);
  --shadow-lg: rgba(0, 0, 0, 0.2);
  
  /* Link colors */
  --link-color: #3b82f6;
  --link-hover: #2563eb;
}

/* ───── General Layout ───── */
html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* ───── Code Formatting ───── */
code {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.95em;
  background-color: var(--bg-code);
  padding: 2px 4px;
  border-radius: 3px;
  color: var(--text-code);
}

/* ───── Interactive Legend Styles ───── */
.legend-category {
  transition: all 0.2s ease;
  user-select: none;
  padding: 2px 4px;
  margin: 2px -4px;
  border-radius: 3px;
}

.legend-category:hover {
  opacity: 0.7;
  background-color: var(--bg-hover);
}

.legend-category.disabled {
  opacity: 0.3;
}

.legend-category.disabled .legend-color {
  opacity: 0.3;
  border-color: var(--text-muted) !important;
}

.legend-category.disabled .legend-text {
  text-decoration: line-through;
  color: var(--text-muted);
}

.legend-subcategory {
  margin-left: 20px;
  font-size: 11px;
}

/* ───── Tab Styles ───── */
.tab-button {
  transition: all 0.2s ease;
}

.tab-button:hover {
  background: var(--bg-tertiary) !important;
}

.tab-button.active {
  background: var(--bg-active) !important;
  font-weight: bold;
}

.tab-content {
  transition: opacity 0.2s ease;
}

/* ───── Popup Styles ───── */
.reachability-popup .maplibregl-popup-content {
  border-radius: 8px;
  box-shadow: 0 4px 12px var(--shadow-md);
  border: 1px solid var(--border-muted);
  background-color: var(--bg-primary);
  color: var(--text-primary);
}

.reachability-popup .maplibregl-popup-tip {
  border-top-color: var(--bg-primary);
}

/* MapLibre Popup (route hover tooltip) - Dark Mode Support */
.maplibregl-popup-content {
  background-color: var(--bg-primary) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border-primary) !important;
  border-radius: 8px !important;
  box-shadow: 0 4px 12px var(--shadow-md) !important;
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease !important;
}

.maplibregl-popup-tip {
  border-top-color: var(--bg-primary) !important;
  transition: border-top-color 0.3s ease !important;
}

.maplibregl-popup-content strong {
  color: var(--text-primary) !important;
}

/* Heightgraph Tooltip - Dark Mode Support */
#heightgraph-tooltip {
  position: absolute;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 11px;
  pointer-events: none;
  z-index: 1000;
  display: none;
  white-space: normal;
  max-width: 250px;
  word-wrap: break-word;
  border: 1px solid var(--border-primary);
  box-shadow: 0 2px 8px var(--shadow-md);
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

#map {
  width: 100%;
  height: 100%;
}

/* ────────────── Legend Style ────────────── */

.legend-heading {
  font-size: 24px;
  font-weight: bold;
  display: flex;
  align-items: center;
  gap: 12px;
}

.legend-heading img {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.legend-subtext {
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.4;
}

.legend-subtext a {
  color: var(--link-color);
  text-decoration: none;
  border-bottom: 1px solid #0066cc;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.legend-subtext a:hover {
  color: #004499;
  border-bottom-color: #004499;
}

.info-icon {
  display: inline-block;
  font-size: 14px;
  cursor: help;
  color: #555;
  line-height: 1;
  margin-left: 6px;
  vertical-align: middle;
  opacity: 0.7;
  transition: opacity 0.2s ease;
}

.info-icon:hover {
  opacity: 1;
}

.legend {
  position: absolute;
  top: 60px;
  right: 10px;
  width: 320px;
  max-width: 100%;
  max-height: calc(100dvh - 160px);
  /* 60 top + 80 bottom */
  /* background: rgb(254, 253, 255); */
  background: white;
  padding: 10px;
  font-size: 12px;
  border-radius: 5px;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
  /* overflow-y: auto; */
  overflow-y: scroll;
  scrollbar-gutter: stable;
}


.legend .legend-title .info-icon {
  font-size: 14px;
  cursor: help;
  color: #555;
}

.legend-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0 6px;
  cursor: pointer;
  gap: 12px;
  min-height: 48px;
}

.legend-header label {
  font-size: 12px;
}


.legend-section-divider {
  border-top: 1px solid #ccc;
  margin: 12px 0 6px;
}

.legend-subsection-divider {
  border-top: 1px solid #ddd;
  margin: 2px 0;
  margin-left: 16px;
  /* Einrückung nach rechts */
  width: calc(100% - 16px);
  /* Optional: macht's proportional */
}

/* Items and layout */
.legend-items {
  margin-left: 8px;
}

.legend-items.collapsed {
  display: none;
}


.legend-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.label-wrapper {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  /* ← This is the key part */
  min-width: 0;
  /* prevents overflow on long labels */
}


/* .legend-section {
    margin-top: 10px;
} */



.legend-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: bold;
  font-size: 14px;
  margin-bottom: 6px;
  color: #333;
  cursor: pointer;
  gap: 6px;
}

.legend-section-title label {
  display: flex;
  align-items: center;
  gap: 6px;
}



.legend.collapsed>.legend-section,
.legend.collapsed>.scenario-legend-section,
.legend.collapsed>.legend-subsection-divider {
  display: none;
}


/* ─── Cluster Legend Layout ─── */



.legend-section-allcontent {
  display: flex;
  gap: 20px;
  margin-top: 14px; 

}


/* ─── Linke Spalte: Cluster Entries ─── */

.cluster-legend-entry {
  display: grid;
  grid-template-columns: 35px 1fr;
  align-items: center;
  column-gap: 6px;
  margin-bottom: 6px;
  padding-left: 8px;
}

.cluster-dot {
  justify-self: center;
  background-color: #999;
  border-radius: 50%;
  border: 0.5px solid #e6e6e6;
  box-sizing: border-box;
}

.cluster-label {
  text-align: center;
  white-space: nowrap;
}


/* ─── Rechte Spalte: Verletztenanteile ─── */

#cluster-legend-color {
  margin-left: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cluster-color-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cluster-color-item svg {
  width: 30px;
  height: 30px;
  display: block;
  /* wichtig! */
  min-width: 30px;
  /* stellt konsistente Breite sicher */
}



/* ─────  ───── */
.color-box {
  width: 14px;
  height: 14px;
  display: inline-block;
  border-radius: 2px;
}



/* ───── Count Badges ───── */

.count-badge {
  font-size: 10px;
  padding: 0 4px;
  background: #eee;
  border-radius: 10px;
  min-width: 24px;
  text-align: center;
  white-space: nowrap;
  color: #333;
  display: inline-block;
  flex-shrink: 0;
}

/* ───── Toggle Arrows ───── */

/* Basis-Pfeil-Logik */
.toggle-arrow {
  display: inline-block;
  transform: rotate(135deg);
  transition: transform 0.2s ease;
}

/* Offener Zustand */
.toggle-arrow.open {
  transform: rotate(45deg);
}

/* Großer Root-Pfeil (nur bei legend-root) */
[data-arrow="legend-root"] {
  width: 14px !important;
  height: 14px !important;
  border-right: 5px solid #000 !important;
  border-bottom: 5px solid #000 !important;
  margin-left: auto;
  cursor: pointer !important;
  z-index: 1000 !important;
  position: relative !important;
  flex-shrink: 0 !important;
}

/* Mittlere Section-Pfeile */
.section-arrow {
  width: 10px;
  height: 10px;
  border-right: 4px solid #000;
  border-bottom: 4px solid #000;
  margin-left: 8px;
}

/* Kleine Pfeile bei legend-header */
.legend-header .toggle-arrow {
  width: 6px;
  height: 6px;
  border-right: 3px solid #000;
  border-bottom: 3px solid #000;
  margin-left: 6px;
}



/* Einklappbare Sektionen */
.legend-section.collapsed .legend-section-content {
  display: none;
}

.legend-section.collapsed .legend-section-allcontent {
  display: none;
}




/* ───── Hidden Section Defaults ───── */
#mapillary-legend,
#movebis-legend,
#hvs-legend,
#maxspeed-legend,
#obs-legend,
#schools-legend {
  display: none;
}




/* ────────────── Feature Count ────────────── */

#feature-count {
  display: flex;
  flex-direction: column;
  justify-content: center;
  line-height: 1.3;
}

#feature-count-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
}


/* ────────────── zoomlock ────────────── */
.zoom-lock {
  font-size: 0.8em;
  vertical-align: middle;
  opacity: 0.8;
}

/* ────────────── Photon Geocoder ────────────── */
.geocoder {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 1;
  width: 320px;
  max-width: calc(100vw - 20px);
  font-family: sans-serif;
}

.geocoder-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  box-shadow: 0 0 0 2px var(--shadow-sm);
  transition: all 0.2s, background-color 0.3s ease, border-color 0.3s ease;
}

.geocoder-input-wrapper:focus-within {
  border-color: var(--link-color);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.geocoder-icon {
  position: absolute;
  left: 10px;
  color: var(--text-tertiary);
  pointer-events: none;
  flex-shrink: 0;
}

#search {
  width: 100%;
  padding: 8px 36px 8px 36px;
  font-size: 14px;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text-primary);
  box-sizing: border-box;
}

#search::placeholder {
  color: var(--text-tertiary);
}

.geocoder-clear,
.geocoder-loading {
  position: absolute;
  right: 8px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-tertiary);
  padding: 0;
  border-radius: 4px;
  transition: all 0.2s;
  flex-shrink: 0;
}

.geocoder-clear:hover {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.geocoder-loading {
  pointer-events: none;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.geocoder-results {
  margin-top: 4px;
  max-height: 300px;
  overflow-y: auto;
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  box-shadow: 0 4px 12px var(--shadow-md);
  display: none;
  z-index: 10;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.geocoder-result-item {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-primary);
  transition: background-color 0.15s;
}

.geocoder-result-item:last-child {
  border-bottom: none;
}

.geocoder-result-item:hover,
.geocoder-result-item.selected {
  background: var(--bg-tertiary);
}

.geocoder-result-primary {
  font-size: 14px;
  color: var(--text-primary);
  font-weight: 500;
  margin-bottom: 2px;
}

.geocoder-result-secondary {
  font-size: 12px;
  color: var(--text-tertiary);
}

.geocoder-no-results {
  padding: 12px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 13px;
}

/* Geocoder results for routing inputs */
.routing-input-geocoder-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  max-height: 250px;
  overflow-y: auto;
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  box-shadow: 0 4px 12px var(--shadow-md);
  z-index: 1000;
  font-family: sans-serif;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.input-with-button {
  position: relative;
}

/* Mobile responsive */
@media (max-width: 768px) {
  .geocoder {
    position: absolute;
    top: auto;
    bottom: 40px; /* Above attribution (~30px) with some padding */
    left: auto;
    right: 10px;
    width: calc(100vw - 20px);
    max-width: calc(100vw - 200px); /* Leave space for controls on left */
    z-index: 2; /* Above attribution, below panels */
  }
  
  .geocoder-results {
    max-height: 250px;
    /* Position results above input when open */
    position: absolute;
    bottom: 100%;
    margin-bottom: 4px;
    margin-top: 0;
  }
  
  .routing-input-geocoder-results {
    max-height: 200px;
  }
}

/* ───── Container Bottom Left ───── */
#bottom-left-ui-container {
  position: absolute;
  bottom: 10px;
  left: 10px;
  display: flex;
  gap: 12px;
  z-index: 2;
  font-family: sans-serif;
  align-items: flex-end;
  /* 👈 keeps thumbs and box aligned at bottom */
}

/* Wrapper for nav controls and dark mode toggle */
#custom-nav-control-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

/* Dark Mode Toggle - positioned above nav controls */
#dark-mode-toggle {
  margin-bottom: 0;
}

/* ───── Map Settings Menu ───── */
#map-settings-menu {
  position: relative;
}

.map-settings-btn {
  width: 30px;
  height: 30px;
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 2px var(--shadow-sm);
  transition: all 0.2s, background-color 0.3s ease, border-color 0.3s ease;
  color: var(--text-primary);
  padding: 0;
}

.map-settings-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--border-secondary);
}

.map-settings-btn:active {
  transform: scale(0.95);
}

.map-settings-panel {
  position: absolute;
  bottom: 50px;
  left: 0;
  background: var(--bg-primary);
  border: 2px solid var(--border-tertiary);
  border-radius: 8px;
  box-shadow: 0 4px 12px var(--shadow-md);
  padding: 12px;
  min-width: 140px;
  z-index: 10;
  font-size: 13px;
  transition: opacity 0.2s, transform 0.2s, background-color 0.3s ease, border-color 0.3s ease;
  transform-origin: bottom left;
  color: var(--text-primary);
}

.map-settings-panel.hidden {
  display: none;
}

.map-settings-section {
  margin-bottom: 12px;
}

.map-settings-section:last-child {
  margin-bottom: 0;
}

.map-settings-label {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.map-settings-divider {
  height: 1px;
  background: var(--border-primary);
  margin: 12px 0;
}

/* Basemap Buttons */
.basemap-buttons {
  display: flex;
  gap: 6px;
}

.basemap-btn {
  width: 60px;
  height: 60px;
  padding: 0;
  background-size: cover;
  background-position: center;
  background-color: #f8f8f8;
  border: 2px solid #ddd;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  display: block;
}

.basemap-btn:hover {
  border-color: #bbb;
  opacity: 0.9;
}

.basemap-btn.selected {
  border-color: #0077ff;
  border-width: 3px;
}

/* Switch Controls */
.switch-control {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.switch-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}

.switch-label span:first-child {
  font-size: 13px;
  color: var(--text-primary);
}

/* Toggle Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  margin-left: 12px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: 0.3s;
  border-radius: 24px;
}

.switch-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
}

.switch input:checked + .switch-slider {
  background-color: #0077ff;
}

.switch input:checked + .switch-slider:before {
  transform: translateX(20px);
}

.switch input:focus + .switch-slider {
  box-shadow: 0 0 1px #0077ff;
}

/* Responsive: Smaller on mobile */
@media (max-width: 768px) {
  .map-settings-panel {
    min-width: 120px;
    padding: 10px;
  }
  
  .basemap-btn {
    width: 50px;
    height: 50px;
  }
  
  .switch-label span:first-child {
    font-size: 12px;
  }
}



/* ─── ─── */

.spacer {
  /* width: 160px; */
  display: none;
  /* Erzwingt Breite für rechte Spalte */
}


/* slider */
#scenario1-slider,
#scenario8-slider,
#scenario2-slider {
  --progress: 0%;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right, #ccc var(--progress), orange var(--progress));
  outline: none;
}

#scenario1-slider::-webkit-slider-thumb,
#scenario8-slider::-webkit-slider-thumb,
#scenario2-slider::-webkit-slider-thumb {
  appearance: none;
  height: 16px;
  width: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid orange;
  cursor: pointer;
  /* margin-top: -1px; */
  /* zentrieren */
}

#scenario1-slider::-moz-range-thumb,
#scenario8-slider::-moz-range-thumb,
#scenario2-slider::-moz-range-thumb {
  height: 12px;
  width: 12px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid orange;
  cursor: pointer;
}

#scenario-legend-section {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}


.legend-section-subtitle {
  font-weight: 600;
  font-size: 12px;
  margin: 12px 10px 4px 10px;
  color: #333;
}

/* ───── Routing Panel ───── */
.routing-panel {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 320px;
  max-width: calc(100% - 10px);
  /* max-height is set dynamically in main.js */
  background: var(--bg-primary);
  border-radius: 8px;
  box-shadow: 0 2px 8px var(--shadow-md);
  z-index: 2;
  font-family: sans-serif;
  transition: width 0.3s ease, max-height 0.3s ease, background-color 0.3s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--text-primary);
}

.routing-panel.collapsed {
  width: 320px;
  display: flex !important; /* Ensure panel is visible when collapsed */
  visibility: visible !important;
}

.routing-panel.collapsed .routing-content {
  display: none !important;
}

.routing-panel.collapsed .routing-header {
  border-bottom: none;
  padding: 12px 16px;
  display: flex !important; /* Ensure header is visible when collapsed */
}

/* Ensure profile selector is visible when collapsed */
.routing-panel.collapsed .profile-selector {
  display: flex !important;
  flex: 1;
  visibility: visible !important;
}

/* Ensure profile buttons are visible when collapsed */
.routing-panel.collapsed .profile-btn {
  display: flex !important;
  visibility: visible !important;
}

/* Quick action buttons in header (only visible when collapsed) */
.header-quick-actions {
  display: none;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
}

.routing-panel.collapsed .header-quick-actions {
  display: flex !important;
}

.routing-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.routing-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  display: none; /* Hide title, use profile selector instead */
}

.header-right-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-action-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border-secondary);
  border-radius: 6px;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.header-action-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-primary);
  color: var(--text-secondary);
}

.header-action-btn svg {
  width: 18px;
  height: 18px;
}

.profile-selector {
  display: flex;
  gap: 4px;
  align-items: center;
  flex: 1;
}

.profile-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border-secondary);
  border-radius: 6px;
  background: var(--bg-primary);
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.profile-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--border-primary);
  color: var(--text-secondary);
}

.profile-btn.active {
  background: #3b82f6;
  border-color: #3b82f6;
  color: white;
}

.profile-btn svg {
  width: 20px;
  height: 20px;
}

.btn-close {
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-close svg {
  transition: transform 0.2s;
}

.btn-close.collapsed svg {
  transform: rotate(90deg);
}

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

.routing-content {
  padding: 16px;
  display: block;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: background-color 0.3s ease, color 0.3s ease;
}

.routing-content::-webkit-scrollbar {
  width: 8px;
}

.routing-content::-webkit-scrollbar-track {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

.routing-content::-webkit-scrollbar-thumb {
  background: var(--border-secondary);
  border-radius: 4px;
}

.routing-content::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

.routing-input-group {
  margin-bottom: 10px;
}

.routing-input-group label {
  display: none; /* Hide labels, using icons instead */
}

.input-with-icon {
  display: flex;
  align-items: center;
  gap: 8px;
}

.input-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 24px;
  height: 24px;
}

.input-icon svg {
  width: 24px;
  height: 24px;
}

.input-with-button {
  display: flex;
  gap: 4px;
  align-items: stretch;
  flex: 1;
  min-width: 0;
}

.input-with-button input {
  flex: 1;
  padding: 6px 10px;
  font-size: 13px;
  border: 1px solid var(--border-tertiary);
  border-radius: 4px;
  outline: none;
  transition: border-color 0.2s, background-color 0.3s ease, color 0.3s ease;
  background: var(--bg-primary);
  color: var(--text-primary);
}

.input-with-button input:focus {
  border-color: var(--link-color);
}

.input-with-button input::placeholder {
  color: var(--text-tertiary);
}

.btn-set-point {
  padding: 6px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-tertiary);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  width: 32px;
  height: 32px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-set-point:hover {
  background: var(--bg-hover);
  border-color: var(--border-secondary);
}

.btn-set-point.active {
  background: #3b82f6;
  border-color: #3b82f6;
}

.btn-set-point.active svg {
  stroke: white;
}

.btn-set-start > svg {
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
}

.btn-set-start > svg > path:first-child {
  fill: #10b981;
  stroke: white;
}

.btn-set-end > svg {
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
}

.btn-set-end > svg > path:first-child {
  fill: #ef4444;
  stroke: white;
}

/* Header quick action buttons (collapsed state) */
.btn-set-point-header,
.btn-add-waypoint-header {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border-secondary);
  border-radius: 6px;
  background: var(--bg-tertiary);
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.btn-set-point-header:hover,
.btn-add-waypoint-header:hover {
  background: var(--bg-hover);
  border-color: var(--border-primary);
}

.btn-set-point-header.active,
.btn-add-waypoint-header.active {
  background: #3b82f6;
  border-color: #3b82f6;
}

.btn-set-point-header.active svg,
.btn-add-waypoint-header.active svg {
  stroke: white;
}

.btn-set-start-header > svg {
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
}

.btn-set-start-header > svg > path:first-child {
  fill: #10b981;
  stroke: white;
}

.btn-set-end-header > svg {
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
}

.btn-set-end-header > svg > path:first-child {
  fill: #ef4444;
  stroke: white;
}

.btn-add-waypoint-header svg {
  stroke: #f59e0b;
}

/* ───── Waypoints ───── */
/* Waypoints header field (styled like input field) */
.waypoints-header-field {
  flex: 1;
  padding: 4px 8px;
  font-size: 13px;
  border: 1px solid var(--border-tertiary);
  border-radius: 4px;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-secondary);
  min-height: 32px;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  gap: 8px;
  transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

/* Waypoint optimization toggle */
.waypoint-optimization-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  font-size: 12px;
  color: var(--text-tertiary);
  transition: color 0.3s ease;
}

.waypoint-optimization-toggle input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
  width: 16px;
  height: 16px;
  accent-color: var(--link-color);
}

.waypoint-optimization-toggle .toggle-label {
  font-size: 12px;
  color: var(--text-tertiary);
}

.waypoint-optimization-toggle:hover .toggle-label {
  color: var(--text-secondary);
}

/* Waypoints container (for the list below header) */
.waypoints-container {
  margin-bottom: 10px;
  padding: 0 0 0 32px; /* Left padding to align with input fields */
  background: transparent;
  border: none;
  border-radius: 0;
}

/* Add waypoint button */
.btn-add-waypoint {
  padding: 6px;
  width: 32px;
  height: 32px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-tertiary);
  border-radius: 4px;
  color: #f59e0b;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  flex-shrink: 0;
  transition: all 0.2s;
}

.btn-add-waypoint:hover {
  background: var(--bg-hover);
  border-color: var(--border-secondary);
}

.btn-add-waypoint svg {
  stroke: #f59e0b;
}

/* Waypoints list */
.waypoints-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Individual waypoint item */
.waypoint-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  font-size: 12px;
  cursor: move;
  transition: all 0.2s, background-color 0.3s ease, border-color 0.3s ease;
  user-select: none;
  width: calc(100% - 36px); /* Match header field width: 100% - button width (32px) - gap (4px) */
  box-sizing: border-box;
}

.waypoint-item:hover {
  background: var(--bg-secondary);
  border-color: var(--border-secondary);
}

.waypoint-item.dragging {
  opacity: 0.5;
  cursor: grabbing;
}

.waypoint-item.drag-over {
  border-top: 2px solid #3b82f6;
  border-top-style: dashed;
}

.waypoint-item.drag-over.drag-over-after {
  border-top: none;
  border-bottom: 2px solid #3b82f6;
  border-bottom-style: dashed;
}

.waypoint-item.drag-over.drag-over-before {
  border-top: 2px solid #3b82f6;
  border-top-style: dashed;
  border-bottom: none;
}

.waypoint-drag-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  cursor: grab;
  padding: 2px;
  flex-shrink: 0;
}

.waypoint-drag-handle:active {
  cursor: grabbing;
}

.waypoint-item:hover .waypoint-drag-handle {
  color: var(--text-tertiary);
}

.waypoint-svg-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.waypoint-svg-icon img {
  width: 18px;
  height: 18px;
  object-fit: contain;
  transition: filter 0.3s ease;
}

/* Make waypoint icons brighter in dark mode - invert and brighten */
html[data-theme="dark"] .waypoint-svg-icon img {
  filter: invert(1) brightness(1.2) saturate(0.8);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .waypoint-svg-icon img {
    filter: invert(1) brightness(1.2) saturate(0.8);
  }
}

/* Waypoint marker icons on map - invert only when dark map is active */
.waypoint-marker-img {
  filter: none; /* Reset filter for light mode */
  transition: filter 0.3s ease;
}

/* Make waypoint marker icons white/gray only when dark map is selected */
body[data-dark-map="true"] .waypoint-marker-img {
  filter: invert(1) brightness(1.2) saturate(0.8);
}

.waypoint-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  background: #f59e0b;
  color: white;
  border-radius: 50%;
  font-weight: bold;
  font-size: 10px;
  flex-shrink: 0;
}

.waypoint-coords {
  flex: 1;
  color: var(--text-tertiary);
  font-family: sans-serif;
  font-size: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.btn-remove-waypoint {
  padding: 2px 4px;
  background: transparent;
  border: none;
  color: #ef4444;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  flex-shrink: 0;
  transition: all 0.2s;
}

.btn-remove-waypoint:hover {
  background: #fee2e2;
  color: #dc2626;
}

.routing-buttons {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  width: 100%;
  box-sizing: border-box;
}

.customizable-slider-container {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 10px 12px;
  background: var(--bg-tertiary);
  border-radius: 6px;
  box-sizing: border-box;
  transition: background-color 0.3s ease;
}

.customizable-slider-container .slider-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.customizable-slider-container .slider-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
}

.customizable-slider-container .slider-label {
  min-width: auto;
  flex-shrink: 0;
}

.customizable-slider-container .slider-value {
  flex-shrink: 0;
  text-align: right;
}

.slider-label {
  font-size: 12px;
  color: var(--text-tertiary);
  white-space: nowrap;
  min-width: auto;
}

input[type="range"].slider,
.customizable-slider-container .slider {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: #e5e7eb;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

input[type="range"].slider::-webkit-slider-thumb,
.customizable-slider-container .slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #3b82f6;
  cursor: pointer;
  border: 2px solid white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

input[type="range"].slider::-moz-range-thumb,
.customizable-slider-container .slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #3b82f6;
  cursor: pointer;
  border: 2px solid white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.car-access-container {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-secondary);
}

.car-access-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
}

.car-access-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--text-tertiary);
  stroke-width: 2;
}

.car-access-text {
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.4;
  flex: 1;
}

/* Smaller switch for car access */
.car-access-switch.switch-toggle {
  width: 24px !important;
  height: 14px !important;
  flex-shrink: 0;
}

.car-access-switch .switch-slider {
  border-radius: 14px;
}

.car-access-switch .switch-slider:before {
  height: 10px !important;
  width: 10px !important;
  left: 2px !important;
  bottom: 2px !important;
}

.car-access-switch input:checked + .switch-slider:before {
  transform: translateX(10px) !important;
}

.unpaved-roads-container {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-secondary);
}

.unpaved-roads-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
}

.unpaved-roads-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--text-tertiary);
  stroke-width: 2;
}

.unpaved-roads-text {
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.4;
  flex: 1;
}

/* Smaller switch for unpaved roads */
.unpaved-roads-switch.switch-toggle {
  width: 24px !important;
  height: 14px !important;
  flex-shrink: 0;
}

.unpaved-roads-switch .switch-slider {
  border-radius: 14px;
}

.unpaved-roads-switch .switch-slider:before {
  height: 10px !important;
  width: 10px !important;
  left: 2px !important;
  bottom: 2px !important;
}

.unpaved-roads-switch input:checked + .switch-slider:before {
  transform: translateX(10px) !important;
}

.avoid-pushing-container {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-secondary);
}

.avoid-pushing-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avoid-pushing-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--text-tertiary);
  stroke-width: 2;
}

.avoid-pushing-text {
  font-size: 12px;
  color: var(--text-tertiary);
  line-height: 1.4;
  flex: 1;
}

/* Smaller switch for avoid pushing */
.avoid-pushing-switch.switch-toggle {
  width: 24px !important;
  height: 14px !important;
  flex-shrink: 0;
}

.avoid-pushing-switch .switch-slider {
  border-radius: 14px;
}

.avoid-pushing-switch .switch-slider:before {
  height: 10px !important;
  width: 10px !important;
  left: 2px !important;
  bottom: 2px !important;
}

.avoid-pushing-switch input:checked + .switch-slider:before {
  transform: translateX(10px) !important;
}

.mapillary-weight-comparison {
  margin-top: 10px;
  padding-top: 10px;
  font-size: 11px;
  line-height: 1.4;
}

.mapillary-weight-comparison .comparison-divider {
  height: 1px;
  background: var(--border-secondary);
  margin-bottom: 10px;
}

.mapillary-weight-comparison .comparison-values {
  display: flex;
  flex-direction: row;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.mapillary-weight-comparison .comparison-label {
  color: var(--text-tertiary);
  font-size: 10px;
  font-weight: 500;
  margin-right: 0px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.mapillary-weight-comparison .comparison-item {
  display: flex;
  align-items: center;
  gap: 3px;
  color: var(--text-tertiary);
  font-size: 11px;
}

.mapillary-weight-comparison .comparison-item svg {
  flex-shrink: 0;
}

.mapillary-weight-comparison .comparison-icon-combined {
  position: relative;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mapillary-weight-comparison .comparison-icon-overlay {
  position: absolute;
  top: -2px;
  right: -2px;
  background: var(--bg-primary);
  border-radius: 50%;
  padding: 1px;
}

.mapillary-weight-comparison .comparison-text {
  color: var(--text-tertiary);
  font-size: 11px;
  white-space: nowrap;
}

.slider-value {
  font-size: 12px;
  font-weight: 600;
  color: #3b82f6;
  min-width: 30px;
  text-align: right;
}

.btn-primary {
  flex: 1;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  box-sizing: border-box;
  background: #3b82f6;
  color: white;
  white-space: nowrap;
}

.btn-primary:hover:not(:disabled) {
  background: #2563eb;
}

.btn-primary:disabled {
  background: #9ca3af;
  cursor: not-allowed;
}

.btn-icon {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-secondary);
  border-radius: 4px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  box-sizing: border-box;
}

.btn-icon:hover {
  background: var(--bg-hover);
  border-color: var(--border-primary);
}

.btn-icon svg {
  width: 18px;
  height: 18px;
}

.route-info {
  margin-top: 12px;
  padding: 0;
}

.route-info-compact {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px 24px;
  padding: 10px 12px;
  background: var(--bg-secondary);
  border-radius: 6px;
  font-size: 13px;
  transition: background-color 0.3s ease;
}

.route-info-row {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-start;
}

.route-info-row svg {
  flex-shrink: 0;
  color: #3b82f6;
}

.route-info-compact-label {
  color: var(--text-tertiary);
  font-weight: 500;
}

.route-info-compact-value {
  color: var(--text-primary);
  font-weight: 700;
}

/* Heightgraph Styles */
.heightgraph-container {
  margin-top: 12px;
  padding: 12px;
  background: var(--bg-secondary);
  border-radius: 6px;
  border: 1px solid var(--border-primary);
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.heightgraph-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.heightgraph-select {
  font-size: 12px;
  padding: 4px 8px;
  border: 1px solid var(--border-secondary);
  border-radius: 4px;
  background: var(--bg-primary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.heightgraph-select:hover {
  border-color: var(--border-primary);
  background: var(--bg-tertiary);
}

.heightgraph-select:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

.heightgraph-container canvas {
  width: 100%;
  height: 150px;
  display: block;
  border-radius: 4px;
}

.heightgraph-container div[style*="position: relative"] {
  position: relative;
  width: 100%;
  border-radius: 4px;
}

.heightgraph-stats {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border-top: 1px solid var(--border-primary);
  font-size: 13px;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.heightgraph-stat-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  border-radius: 4px;
  margin: 2px 0;
}

.heightgraph-stat-label {
  color: var(--text-tertiary);
  font-weight: 500;
  line-height: 1.4;
}

.heightgraph-stat-value {
  color: var(--text-primary);
  font-weight: 600;
}

#heightgraph-indicator-canvas {
  width: 100%;
  height: 150px;
  display: block;
}

/* GitHub Links */
.github-links {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 12px;
  padding: 0 16px 0 16px;
}

.status-badge {
  height: 20px;
  display: block;
}

.github-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  color: var(--text-tertiary);
  font-size: 12px;
  transition: color 0.2s;
  gap: 4px;
}

.github-link:hover {
  color: var(--text-secondary);
}

.github-link svg {
  flex-shrink: 0;
}

/* ───── Context Panel (Bike Lanes) ───── */
.context-panel {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 320px;
  max-width: calc(100% - 10px);
  max-height: calc(100vh - 20px); /* Prevent going outside viewport */
  background: var(--bg-primary);
  border-radius: 8px;
  box-shadow: 0 2px 8px var(--shadow-md);
  z-index: 1;
  font-family: sans-serif;
  overflow: hidden; /* Let content handle scrolling */
  transition: width 0.3s ease, max-height 0.3s ease, background-color 0.3s ease;
  display: flex;
  flex-direction: column;
  color: var(--text-primary);
}

.context-panel.collapsed {
  width: 320px;
}

.context-panel.collapsed .context-content {
  display: none !important;
}

.context-panel.collapsed .context-header {
  border-bottom: none;
  padding: 12px 16px;
}

/* Ensure attribution control doesn't overlap with context panel */
.maplibregl-ctrl-attrib {
  z-index: 0 !important;
  pointer-events: auto !important;
}

/* MapLibre Navigation Controls - Dark Mode */
.maplibregl-ctrl-group {
  background: var(--bg-primary) !important;
  border: 1px solid var(--border-primary) !important;
  box-shadow: 0 2px 4px var(--shadow-md) !important;
  transition: background-color 0.3s ease, border-color 0.3s ease !important;
}

.maplibregl-ctrl-group button {
  background-color: var(--bg-primary) !important;
  color: var(--text-primary) !important;
  border-color: var(--border-primary) !important;
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease !important;
}

.maplibregl-ctrl-group button:hover {
  background-color: var(--bg-tertiary) !important;
  color: var(--text-primary) !important;
}

.maplibregl-ctrl-group button:active {
  background-color: var(--bg-hover) !important;
}

.maplibregl-ctrl-compass {
  background-color: var(--bg-primary) !important;
  color: var(--text-primary) !important;
  border-color: var(--border-primary) !important;
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease !important;
}

.maplibregl-ctrl-compass:hover {
  background-color: var(--bg-tertiary) !important;
}

/* Position context panel below routing panel using JavaScript */

.context-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-primary);
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.context-title {
  display: flex;
  align-items: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.btn-close-small {
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-close-small:hover {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.btn-close-small.collapsed {
  transform: rotate(-90deg);
}

.context-content {
  padding: 0;
  overflow-y: auto;
}

.context-content.collapsed {
  display: none;
}

/* Context Segments */
.context-segment {
  border-bottom: 1px solid var(--border-primary);
  transition: border-color 0.3s ease;
}

.context-segment:last-child {
  border-bottom: none;
}

.context-segment-header {
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background-color 0.2s;
}

.context-segment-header:hover {
  background-color: var(--bg-secondary);
}

.context-segment-title {
  display: flex;
  align-items: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
  gap: 6px;
}

.context-icon {
  margin-right: 6px;
  flex-shrink: 0;
}

.context-segment-title .info-icon-small {
  margin-left: 4px;
  font-size: 12px;
  color: var(--text-tertiary);
  cursor: help;
}

/* Switch Toggle */
.switch-toggle {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
  cursor: pointer;
}

.switch-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: 0.3s;
  border-radius: 24px;
}

.switch-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
}

.switch-toggle input:checked + .switch-slider {
  background-color: #3b82f6;
}

.switch-toggle input:checked + .switch-slider:before {
  transform: translateX(20px);
}

.switch-toggle:hover .switch-slider {
  background-color: #b0b0b0;
}

.switch-toggle input:checked:hover + .switch-slider {
  background-color: #2563eb;
}

/* ───── Mobile Optimizations ───── */
@media (max-width: 768px) {
  /* Panels: Full width on mobile, less padding */
  .routing-panel,
  .context-panel {
    width: calc(100% - 10px);
    max-width: calc(100% - 10px);
    top: 5px;
    right: 5px;
    left: 5px;
  }

  /* Larger touch targets for buttons */
  .profile-btn {
    min-width: 44px;
    min-height: 44px;
    padding: 10px;
  }

  .btn-set-point,
  .btn-add-waypoint {
    min-width: 44px;
    min-height: 44px;
    width: 44px;
    height: 44px;
  }

  .btn-close {
    min-width: 44px;
    min-height: 44px;
    width: 44px;
    height: 44px;
  }

  /* Keep input fields same height on mobile */
  .input-with-button input {
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 6px 10px; /* Same as desktop */
  }

  .waypoints-header-field {
    font-size: 16px;
    padding: 10px 8px;
    min-height: 44px;
  }

  /* Larger text in panels */
  .routing-header {
    padding: 14px 12px;
  }

  .routing-content {
    padding: 12px;
  }

  .context-segment-header {
    padding: 14px 12px;
  }

  .context-segment-content {
    padding: 12px;
  }

  /* Larger switches for context panel */
  .switch-toggle {
    width: 52px;
    height: 28px;
  }

  .switch-toggle .switch-slider:before {
    height: 22px;
    width: 22px;
  }
  
  /* Ensure map-settings switches don't get affected by switch-toggle styles */
  .map-settings-panel .switch-slider:before {
    height: 18px;
    width: 18px;
  }
  
  .map-settings-panel .switch input:checked + .switch-slider:before {
    transform: translateX(20px);
  }

  .switch-toggle input:checked + .switch-slider:before {
    transform: translateX(24px);
  }
  
  /* Keep map-settings switches aligned properly on mobile */
  .map-settings-panel .switch {
    margin-left: 12px;
    flex-shrink: 0;
  }
  
  .map-settings-panel .switch-label {
    align-items: center;
    justify-content: space-between;
  }

  /* Bottom-left UI: Keep horizontal on mobile */
  #bottom-left-ui-container {
    flex-direction: row;
    gap: 8px;
    bottom: 5px;
    left: 5px;
    flex-wrap: wrap;
  }
  
  /* Ensure panels don't overlap with bottom geocoder and controls */
  .routing-panel,
  .context-panel {
    /* 
     * top: 5px
     * Geocoder: bottom: 40px + height ~50px = 90px from bottom
     * Controls: bottom: 10px + height ~50px = 60px from bottom
     * Use the higher value (Geocoder) + padding: 10px = 100px total
     * Reduced to 100px to give context panel more space
     */
    max-height: calc(100vh - 5px - 170px); /* Give more space for context panel */
    overflow-y: auto;
  }

  /* Smaller basemap thumbs on mobile */
  .basemap-thumb {
    width: 50px;
    height: 50px;
  }

  #terrain-controls {
    height: 55px;
    font-size: 11px;
    padding: 3px 5px;
  }

  /* Larger select dropdowns */
  .heightgraph-select {
    font-size: 16px;
    padding: 10px 8px;
    min-height: 44px;
  }

  /* Adjust route info spacing */
  .route-info-compact {
    padding: 12px;
    gap: 10px 16px;
  }

  /* Larger waypoint items */
  .waypoint-item {
    padding: 8px 10px;
    min-height: 44px;
    width: calc(100% - 48px); /* Match header field width on mobile: 100% - button width (44px) - gap (4px) */
  }

  .waypoint-number {
    width: 24px;
    height: 24px;
    font-size: 12px;
  }

  /* Context panel segments - larger touch areas */
  .context-segment-title {
    font-size: 15px;
  }

  /* GitHub links - keep horizontal on mobile */
  .github-links {
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 12px;
  }
}

/* Very small screens (phones in portrait) */
@media (max-width: 480px) {
  .routing-panel,
  .context-panel {
    width: calc(100% - 8px);
    max-width: calc(100% - 8px);
    top: 4px;
    right: 4px;
    left: 4px;
  }

  .routing-header {
    padding: 12px 10px;
  }

  .routing-content {
    padding: 10px;
  }

  .profile-selector {
    gap: 3px;
  }

  .profile-btn {
    min-width: 40px;
    min-height: 40px;
    padding: 8px;
  }

  .profile-btn svg {
    width: 18px;
    height: 18px;
  }
}

.context-segment-content {
  padding: 8px 16px;
  transition: max-height 0.3s ease, opacity 0.3s ease;
  overflow: hidden;
}

.context-segment-content.collapsed {
  max-height: 0;
  padding: 0 16px;
  opacity: 0;
}

.context-segment-content .context-toggle {
  margin-bottom: 6px;
  margin-top: 0;
}

.context-toggle label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #374151;
  cursor: pointer;
}

.context-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.info-icon-small {
  display: inline-block;
  font-size: 12px;
  cursor: help;
  color: #6b7280;
  opacity: 0.7;
  margin-left: 4px;
}

.info-icon-small:hover {
  opacity: 1;
}

.bikelanes-legend {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#missing-streets-legend {
  display: flex; /* Visible by default, but layer not activated */
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 1px 0;
}

.legend-line {
  display: inline-block;
  width: 32px;
  height: 4px;
  border-radius: 2px;
  flex-shrink: 0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}


.legend-line.dashed {
  background: repeating-linear-gradient(
    to right,
    var(--line-color, #000) 0px,
    var(--line-color, #000) 6px,
    transparent 6px,
    transparent 9px
  ) !important;
}

.legend-text {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.3;
}

/* ───── Context Menu ───── */
.context-menu {
  position: fixed;
  background: #2d2d2d;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  padding: 4px 0;
  min-width: 200px;
  z-index: 1000;
  font-family: sans-serif;
  font-size: 14px;
  color: white;
  display: flex;
  flex-direction: column;
  pointer-events: auto;
}

.context-menu.hidden {
  display: none;
}

.context-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  cursor: pointer;
  color: white;
  text-decoration: none;
  transition: background-color 0.15s;
}

.context-menu-item:hover {
  background-color: #3d3d3d;
}

.context-menu-item svg {
  flex-shrink: 0;
  color: white;
  stroke: white;
}

.context-menu-item#context-menu-set-waypoint svg {
  stroke: #f59e0b;
}

.context-menu-item span {
  flex: 1;
}

.context-menu-separator {
  height: 1px;
  background-color: #4d4d4d;
  margin: 4px 0;
}

.context-footer {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #e0e0e0;
  font-size: 11px;
  color: #6b7280;
}

.context-footer a {
  color: #3b82f6;
  text-decoration: none;
  font-weight: 500;
}

.context-footer a:hover {
  text-decoration: underline;
}

/* ───── Waypoint Context Menu ───── */
.waypoint-context-menu {
  position: fixed;
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: 6px;
  box-shadow: 0 4px 12px var(--shadow-md);
  padding: 4px;
  min-width: 120px;
  z-index: 1001;
  font-family: sans-serif;
  font-size: 13px;
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  pointer-events: auto;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.waypoint-context-menu.hidden {
  display: none;
}

.waypoint-context-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  color: var(--text-primary);
  transition: background-color 0.15s;
  border-radius: 4px;
}

.waypoint-context-menu-item:hover {
  background-color: var(--bg-tertiary);
}

.waypoint-context-menu-item svg {
  flex-shrink: 0;
  color: #ef4444;
  stroke: #ef4444;
}

.waypoint-context-menu-item span {
  flex: 1;
}