/* ============================================================
   GPX Viewer — Stylesheet
   ============================================================ */

/* --- Google Font --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* --- Design Tokens (Light) --- */
:root {
  --accent:       #3b82f6;
  --accent-dark:  #2563eb;
  --accent-light: #93c5fd;

  --bg-base:      #f8f9fa;
  --bg-surface:   #ffffff;
  --bg-elevated:  #f1f3f5;
  --bg-inset:     #e9ecef;
  --bg-overlay:   rgba(255,255,255,0.85);

  --border:       #dee2e6;
  --border-light: #e9ecef;

  --text-primary:   #111827;
  --text-secondary: #4b5563;
  --text-muted:     #9ca3af;
  --text-inverse:   #ffffff;

  --success:  #22c55e;
  --warning:  #f59e0b;
  --danger:   #ef4444;
  --info:     #06b6d4;

  /* Track palette */
  --track-0: #3b82f6;
  --track-1: #f97316;
  --track-2: #22c55e;
  --track-3: #a855f7;
  --track-4: #ec4899;
  --track-5: #14b8a6;
  --track-6: #eab308;
  --track-7: #6366f1;

  --radius-sm:  4px;
  --radius-md:  6px;
  --radius-lg:  10px;
  --radius-xl:  14px;

  --shadow-sm:  0 1px 2px rgba(0,0,0,0.06);
  --shadow-md:  0 2px 8px rgba(0,0,0,0.10);
  --shadow-lg:  0 4px 20px rgba(0,0,0,0.13);

  --header-h:   48px;
  --sidebar-w:  300px;
  --panel-min:  220px;

  --font-mono: 'JetBrains Mono', 'Fira Mono', monospace;
  --font-ui:   'Inter', system-ui, sans-serif;

  --transition: 150ms ease;
}

/* --- Dark Mode Tokens --- */
[data-theme="dark"] {
  --bg-base:      #0f1117;
  --bg-surface:   #1a1d27;
  --bg-elevated:  #222535;
  --bg-inset:     #2a2e40;
  --bg-overlay:   rgba(26,29,39,0.90);

  --border:       #2e3348;
  --border-light: #252839;

  --text-primary:   #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted:     #4b5563;
  --text-inverse:   #0f1117;

  --shadow-sm:  0 1px 3px rgba(0,0,0,0.4);
  --shadow-md:  0 2px 10px rgba(0,0,0,0.5);
  --shadow-lg:  0 6px 24px rgba(0,0,0,0.6);
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-base);
  -webkit-font-smoothing: antialiased;
}

/* --- Scrollbars --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* --- Focus Visible --- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ============================================================
   Layout Shell
   ============================================================ */

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* --- Header --- */
#header {
  height: var(--header-h);
  min-height: var(--header-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
  z-index: 100;
  flex-shrink: 0;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
  margin-right: 4px;
}

.header-brand svg {
  color: var(--accent);
}

.header-spacer { flex: 1; }

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

/* --- Main Content Grid --- */
#main {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* --- Sidebar --- */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  max-width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

#sidebar-inner {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 0 16px;
}

/* --- Content Area --- */
#content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* --- Map --- */
#map-container {
  flex: 1;
  min-height: 0;
  position: relative;
}

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

/* --- Bottom Panel --- */
#bottom-panel {
  height: 240px;
  min-height: 240px;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#bottom-tabs {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  flex-shrink: 0;
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 12px;
  height: 32px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
  white-space: nowrap;
}

.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: var(--bg-surface);
}

.tab-panel {
  display: none;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: auto;
}
.tab-panel.active { display: flex; flex-direction: column; }

#resize-handle {
  height: 4px;
  background: var(--border);
  cursor: ns-resize;
  flex-shrink: 0;
  transition: background var(--transition);
  position: relative;
}
#resize-handle:hover,
#resize-handle.dragging { background: var(--accent); }

/* ============================================================
   Components
   ============================================================ */

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  text-decoration: none;
}

.btn svg { flex-shrink: 0; }

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.btn-outline {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-outline:hover { background: var(--bg-elevated); }

.btn-icon {
  padding: 5px;
  border-radius: var(--radius-md);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: transparent;
}
.btn-danger:hover { background: rgba(239,68,68,0.1); }

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* --- Section Header --- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px 6px;
  border-bottom: 1px solid var(--border-light);
  position: sticky;
  top: 0;
  background: var(--bg-surface);
  z-index: 10;
}

.section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

/* --- Upload Area --- */
#upload-section {
  padding: 8px;
  border-bottom: 1px solid var(--border-light);
}

#drop-zone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 12px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  position: relative;
}

#drop-zone:hover,
#drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(59,130,246,0.04);
}

#drop-zone.drag-over { background: rgba(59,130,246,0.08); }

#drop-zone svg { color: var(--text-muted); margin-bottom: 4px; }
#drop-zone p {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 2px;
}
#drop-zone span { font-size: 11px; color: var(--text-muted); }

#file-input { display: none; }

/* --- Track Cards --- */
#track-list {
  padding: 6px 0;
}

.track-card {
  margin: 4px 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: border-color var(--transition);
  cursor: pointer;
}

.track-card:hover { border-color: var(--border); }
.track-card.selected {
  border-color: var(--accent);
  background: rgba(59,130,246,0.04);
}

.track-card-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
}

.track-color-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.track-card-name {
  flex: 1;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.track-card-meta {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.track-card-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.track-card-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 8px;
  padding: 4px 8px 8px;
  font-size: 11px;
}

.stat-pair { display: flex; flex-direction: column; gap: 1px; }
.stat-label { color: var(--text-muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { color: var(--text-primary); font-weight: 600; font-variant-numeric: tabular-nums; }

.track-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 5px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 500;
}

.badge-has { background: rgba(34,197,94,0.15); color: #16a34a; }
.badge-no { background: rgba(156,163,175,0.15); color: var(--text-muted); }
[data-theme="dark"] .badge-has { color: #4ade80; }

/* --- Visibility Toggle --- */
.vis-toggle {
  width: 20px;
  height: 20px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: color var(--transition), background var(--transition);
  flex-shrink: 0;
}
.vis-toggle:hover { color: var(--text-primary); background: var(--bg-inset); }
.vis-toggle.hidden { color: var(--border); }

/* --- Metrics Panel --- */
#metrics-panel {
  padding: 10px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 6px;
}

.metric-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 8px 10px;
}

.metric-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.metric-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.metric-unit {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-secondary);
  margin-left: 2px;
}

.metric-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}

.metrics-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 8px 0 4px;
}

/* --- Map Controls (overlay) --- */
.map-overlay {
  position: absolute;
  z-index: 500;
  pointer-events: all;
}

/* --- Location Search --- */
.map-search-container {
  position: absolute;
  top: 8px;
  left: 50px;
  z-index: 1000;
  width: 280px;
  font-family: var(--font-ui);
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 0 8px;
  height: 30px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

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

.search-icon {
  color: var(--text-secondary);
  margin-right: 6px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}

#map-search-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 11px;
  font-family: inherit;
  outline: none;
  width: 100%;
  padding: 4px 0;
}

#map-search-input::placeholder {
  color: var(--text-muted);
}

.search-clear-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  margin-left: 4px;
  transition: background var(--transition), color var(--transition);
}

.search-clear-btn:hover {
  background: var(--bg-inset);
  color: var(--text-primary);
}

.search-spinner {
  color: var(--accent);
  margin-left: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Spinner rotation animation */
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.search-results-list {
  list-style: none;
  margin: 4px 0 0 0;
  padding: 4px 0;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 200px;
  overflow-y: auto;
}

.search-result-item {
  padding: 6px 10px;
  font-size: 11px;
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--transition);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-item:hover,
.search-result-item.highlighted {
  background: var(--bg-elevated);
}

.search-result-item .result-type {
  font-size: 9px;
  text-transform: uppercase;
  color: var(--text-muted);
  display: block;
  margin-top: 1px;
}

.search-result-no-results {
  padding: 8px 12px;
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
}

@media (max-width: 576px) {
  .map-search-container {
    width: auto;
    left: 8px;
    right: 8px;
    top: 8px;
  }
  .leaflet-top.leaflet-left {
    top: 48px !important;
  }
}

#map-top-right {
  top: 8px;
  right: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#basemap-controls {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  box-shadow: var(--shadow-md);
}

.basemap-btn {
  padding: 3px 7px;
  font-size: 11px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition);
}
.basemap-btn:hover { background: var(--bg-elevated); color: var(--text-primary); }
.basemap-btn.active { background: var(--accent); color: #fff; }

.zoom-to-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.zoom-to-btn:hover { background: var(--bg-elevated); }

/* --- Elevation Chart Container --- */
#elevation-panel {
  flex: 1;
  position: relative;
  padding: 8px 12px 6px;
  min-height: 0;
}

#elevation-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

#elevation-tooltip {
  position: absolute;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 5px 8px;
  font-size: 11px;
  color: var(--text-primary);
  pointer-events: none;
  display: none;
  z-index: 10;
  box-shadow: var(--shadow-md);
  white-space: nowrap;
}

#elevation-crosshair {
  position: absolute;
  top: 8px;
  bottom: 6px;
  width: 1px;
  background: var(--accent);
  pointer-events: none;
  display: none;
  opacity: 0.6;
}

.elevation-no-data {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 12px;
  gap: 6px;
}

/* --- Points Table --- */
#points-panel {
  flex: 1;
  overflow: auto;
  padding: 0;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  font-family: var(--font-mono);
}

.data-table thead th {
  position: sticky;
  top: 0;
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 5px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  z-index: 5;
  white-space: nowrap;
}

.data-table tbody tr { border-bottom: 1px solid var(--border-light); }
.data-table tbody tr:hover { background: var(--bg-elevated); }
.data-table tbody td {
  padding: 4px 10px;
  color: var(--text-primary);
  white-space: nowrap;
}
.data-table tbody td.muted { color: var(--text-muted); }

/* --- Metadata Panel --- */
#metadata-panel {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
}

.meta-group {
  margin-bottom: 14px;
}

.meta-group-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border-light);
}

.meta-row {
  display: flex;
  gap: 8px;
  padding: 3px 0;
  font-size: 12px;
}

.meta-key {
  color: var(--text-muted);
  flex-shrink: 0;
  min-width: 120px;
}

.meta-val {
  color: var(--text-primary);
  word-break: break-all;
  font-family: var(--font-mono);
  font-size: 11px;
}

/* --- Export Panel --- */
#export-panel {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
}

.export-group {
  margin-bottom: 14px;
}

.export-group-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.export-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 0;
  border-bottom: 1px solid var(--border-light);
}

.export-row:last-child { border-bottom: none; }

.export-desc {
  font-size: 12px;
  color: var(--text-secondary);
}

/* --- Comparison Panel --- */
#comparison-panel {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  padding: 10px 12px;
}

#comparison-table-wrapper { overflow-x: auto; }

.compare-table {
  border-collapse: collapse;
  font-size: 11px;
  min-width: 400px;
}

.compare-table th {
  text-align: left;
  padding: 5px 10px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  white-space: nowrap;
}

.compare-table td {
  padding: 5px 10px;
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.compare-table tr:hover td { background: var(--bg-elevated); }

.compare-track-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  color: var(--text-primary);
}

/* --- Scrubber --- */
#scrubber-container {
  padding: 4px 12px 0;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-light);
}

#scrubber {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  border-radius: 2px;
  background: var(--bg-inset);
  outline: none;
  cursor: pointer;
}

#scrubber::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 0 2px var(--bg-surface);
}

#scrubber::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg-surface);
}

#scrubber-label {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  white-space: nowrap;
}

/* --- Empty State --- */
#empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 10px;
  color: var(--text-muted);
  text-align: center;
  padding: 24px;
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 1;
}

#empty-state svg { opacity: 0.3; }
#empty-state h3 { font-size: 14px; font-weight: 600; color: var(--text-secondary); }
#empty-state p { font-size: 12px; max-width: 220px; }

/* --- Error / Status Messages --- */
.parse-error {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  margin: 4px 8px;
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.2);
  border-radius: var(--radius-md);
  font-size: 11px;
  color: var(--danger);
}

.parse-success {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  margin: 2px 8px;
  background: rgba(34,197,94,0.08);
  border: 1px solid rgba(34,197,94,0.2);
  border-radius: var(--radius-md);
  font-size: 11px;
  color: var(--success);
}

/* --- Collapsible --- */
.collapsible-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 6px 8px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  text-align: left;
  transition: background var(--transition);
}

.collapsible-trigger:hover { background: var(--bg-elevated); }

.collapsible-arrow {
  transition: transform var(--transition);
  flex-shrink: 0;
}

.collapsible-trigger.open .collapsible-arrow { transform: rotate(90deg); }

.collapsible-body {
  display: none;
}

.collapsible-body.open { display: block; }

/* --- Toggle Switch --- */
.toggle-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
}

.toggle-switch {
  position: relative;
  width: 28px;
  height: 16px;
  flex-shrink: 0;
}

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

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--bg-inset);
  border-radius: 8px;
  border: 1px solid var(--border);
  transition: background var(--transition);
}

.toggle-switch input:checked + .toggle-track { background: var(--accent); border-color: var(--accent); }

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 10px;
  height: 10px;
  background: white;
  border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: var(--shadow-sm);
}

.toggle-switch input:checked ~ .toggle-thumb { transform: translateX(12px); }

/* --- Split Markers control --- */
.control-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

.control-row label { flex: 1; }

select.compact-select {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 2px 5px;
  font-size: 11px;
  font-family: var(--font-ui);
  outline: none;
  cursor: pointer;
}

/* --- Map track popup --- */
.leaflet-popup-content-wrapper {
  background: var(--bg-surface) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-lg) !important;
  padding: 0 !important;
}

.leaflet-popup-content {
  margin: 0 !important;
  font-family: var(--font-ui) !important;
  font-size: 12px !important;
}

.map-popup {
  padding: 8px 12px;
  min-width: 140px;
}

.map-popup-title { font-weight: 600; margin-bottom: 4px; }

.map-popup-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 11px;
  color: var(--text-secondary);
}

.leaflet-popup-tip { background: var(--bg-surface) !important; }
.leaflet-popup-close-button { color: var(--text-muted) !important; }

/* --- Loading Spinner --- */
.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

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

/* --- Smooth elevation chart cursor marker --- */
#elevation-hover-marker { display: none; }

/* --- Map sidebar toggle on small desktop --- */
#sidebar-toggle {
  display: none;
}

/* ============================================================
   Elevation chart axis labels
   ============================================================ */

.elev-axes {
  position: absolute;
  inset: 8px 12px 6px;
  pointer-events: none;
}

/* ============================================================
   Reduced Motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
   Mobile Layout
   ============================================================ */
@media (max-width: 768px) {
  :root {
    --header-h: 44px;
    --sidebar-w: 100%;
  }

  body { font-size: 14px; }

  #main {
    flex-direction: column;
  }

  #sidebar {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    flex-shrink: 0;
  }

  #sidebar.open {
    max-height: 360px;
  }

  #sidebar-toggle {
    display: inline-flex;
  }

  #content {
    flex: 1;
    min-height: 0;
  }

  #map-container {
    min-height: 220px;
  }

  #bottom-panel {
    height: 200px;
    min-height: 200px;
  }

  .metric-value { font-size: 15px; }
  .metrics-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 480px) {
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .header-brand span { display: none; }
}

/* --- Mode Switcher Segmented Control --- */
.mode-switcher {
  display: flex;
  background: var(--bg-inset);
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  margin-right: 8px;
}
.mode-btn {
  background: transparent;
  border: none;
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-ui);
}
.mode-btn:hover {
  color: var(--text-primary);
}
.mode-btn.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

/* Hide/Show by App Mode */
#app:not(.build-mode) .build-mode-only {
  display: none !important;
}
#app.build-mode .view-mode-only {
  display: none !important;
}

/* --- Route Builder Panel Styles --- */
.route-metrics-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 10px 12px;
  margin-bottom: 8px;
}
.route-metrics-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-light);
}
.route-metrics-row:last-child {
  border-bottom: none;
}
.route-metric-label {
  color: var(--text-secondary);
  font-size: 11px;
}
.route-metric-value {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 12px;
  font-family: var(--font-mono);
}
.validation-error {
  font-size: 11px;
  color: var(--danger);
  margin-top: 4px;
}

/* Custom styling for Route Draggable Markers */
.route-marker-start {
  background: var(--success);
  border: 2px solid white;
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
}
.route-marker-finish {
  background: var(--danger);
  border: 2px solid white;
  border-radius: 2px;
  transform: rotate(45deg);
  box-shadow: var(--shadow-sm);
}
.route-marker-mid {
  background: var(--accent);
  border: 2px solid white;
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
}
.route-marker-hover {
  transform: scale(1.2);
  transition: transform 0.1s ease;
}
.route-point-delete-btn {
  background: transparent;
  border: none;
  color: var(--danger);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
}
.route-point-delete-btn:hover {
  background: rgba(239, 68, 68, 0.1);
}
.route-point-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border-light);
}
.route-point-row:hover {
  background: var(--bg-elevated);
}

/* --- Geolocation pulse marker --- */
.pulse-marker {
  width: 14px;
  height: 14px;
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 50%;
  position: relative;
  box-shadow: 0 0 4px rgba(0,0,0,0.5);
}

.pulse-marker::after {
  content: '';
  width: 30px;
  height: 30px;
  background: rgba(59, 130, 246, 0.4);
  border-radius: 50%;
  position: absolute;
  top: -10px;
  left: -10px;
  animation: pulse-ring 1.5s cubic-bezier(0.215, 0.610, 0.355, 1) infinite;
}

@keyframes pulse-ring {
  0% {
    transform: scale(0.3);
    opacity: 0.8;
  }
  80%, 100% {
    transform: scale(1.5);
    opacity: 0;
  }
}

.route-arrow-icon {
  background: transparent !important;
  border: none !important;
}

