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

:root {
  --bg: #0b1118;
  --surface: #111827;
  --surface2: #1a2332;
  --border: #1e2d3d;
  --lime: #c8ff2c;
  --blue: #209cff;
  --text: #f1f5f9;
  --text-muted: #64748b;
  --text-dim: #94a3b8;
  --red: #ef4444;
  --header-h: 54px;
  --sidebar-w: 290px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  height: 100vh;
  overflow: hidden;
}

/* ── Header ── */
.gpx-header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  position: relative;
  z-index: 500;
  flex-shrink: 0;
}
.gpx-brand img { height: 26px; display: block; }
.gpx-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
}
.gpx-nav { display: flex; align-items: center; gap: 4px; flex: 1; }
.gpx-nav a {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
  white-space: nowrap;
}
.gpx-nav a:hover { color: var(--text); background: var(--surface2); }
.gpx-nav a.active { color: var(--lime); }
.gpx-header-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.header-distance {
  font-size: 17px;
  font-weight: 700;
  color: var(--lime);
  font-variant-numeric: tabular-nums;
  min-width: 72px;
  text-align: right;
}
.btn-unit {
  background: var(--surface2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 9px;
  cursor: pointer;
  font-family: inherit;
  transition: color 0.15s, border-color 0.15s;
  width: auto;
}
.btn-unit:hover, .btn-unit.is-miles { color: var(--lime); border-color: var(--lime); }

/* ── Layout ── */
.gpx-layout {
  display: flex;
  height: calc(100vh - var(--header-h));
}

/* ── Sidebar ── */
.gpx-sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}
.sb-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.sb-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sb-hint { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.sb-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  padding: 8px 10px;
  font-family: inherit;
}
.sb-input:focus { outline: none; border-color: var(--lime); }

/* ── Toggle ── */
.sb-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  margin-bottom: 10px;
  user-select: none;
}
.toggle-wrap { position: relative; flex-shrink: 0; }
.toggle-wrap input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle-track {
  display: block;
  width: 38px;
  height: 22px;
  background: var(--border);
  border-radius: 11px;
  position: relative;
  transition: background 0.2s;
  cursor: pointer;
}
.toggle-thumb {
  position: absolute;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  top: 3px;
  left: 3px;
  transition: transform 0.2s;
}
.toggle-wrap input:checked + .toggle-track { background: var(--lime); }
.toggle-wrap input:checked + .toggle-track .toggle-thumb { transform: translateX(16px); }

/* ── Profile select ── */
.sb-select-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.sb-select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  padding: 5px 8px;
  font-family: inherit;
}
.sb-select:focus { outline: none; border-color: var(--lime); }
.sb-select:disabled { opacity: 0.4; }
.routing-status { font-size: 11px; color: var(--text-muted); min-height: 16px; margin-top: 6px; }

/* ── Waypoints ── */
.sb-waypoints { flex: 0 0 auto; }
.wp-count {
  background: var(--surface2);
  color: var(--text-dim);
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 600;
}
.waypoint-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
}
.wp-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--surface2);
  border-radius: 6px;
  font-size: 11px;
  color: var(--text-dim);
}
.wp-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--lime);
  color: #0b1118;
  font-size: 9px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.wp-dot.is-end { background: var(--blue); color: #fff; }
.wp-label { flex: 1; font-variant-numeric: tabular-nums; line-height: 1.3; }
.wp-label span { display: block; font-size: 10px; color: var(--text-muted); }
.wp-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 5px;
  font-size: 15px;
  line-height: 1;
  border-radius: 4px;
  flex-shrink: 0;
  font-family: inherit;
}
.wp-remove:hover { background: rgba(239,68,68,.15); color: var(--red); }

/* ── Stops ── */
.stop-filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.stop-filter-row { display: flex; align-items: center; gap: 0; cursor: pointer; }
.stop-filter-row input { display: none; }
.stop-chip {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 12px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: var(--surface2);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  user-select: none;
}
.stop-filter-row input:checked + .stop-chip { border-color: currentColor; }
.stop-chip.cafe { color: #f59e0b; }
.stop-chip.toilets { color: #06b6d4; }
.stop-chip.repair { color: #10b981; }
.stop-chip.shop { color: #10b981; }
.stop-chip.pub { color: #8b5cf6; }
.stop-chip.restaurant { color: #ec4899; }
.stop-filter-row input:not(:checked) + .stop-chip { opacity: 0.45; }

/* ── Stats ── */
.sb-stats { display: flex; flex-direction: column; gap: 8px; }
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  color: var(--text-dim);
}
.stat-row strong { color: var(--text); font-size: 15px; font-variant-numeric: tabular-nums; }

/* ── Buttons ── */
.sb-actions { display: flex; flex-direction: column; gap: 8px; }
button, .btn-export {
  cursor: pointer;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  padding: 9px 14px;
  font-family: inherit;
  transition: opacity 0.12s, background 0.12s;
  text-align: center;
}
button:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-primary { background: var(--lime); color: #0b1118; width: 100%; }
.btn-primary:not(:disabled):hover { opacity: 0.85; }
.btn-secondary { background: var(--surface2); color: var(--text-dim); width: 100%; }
.btn-secondary:not(:disabled):hover { color: var(--text); }
.btn-danger { background: rgba(239,68,68,.1); color: var(--red); width: 100%; }
.btn-danger:not(:disabled):hover { background: rgba(239,68,68,.2); }
.btn-export {
  background: var(--lime);
  color: #0b1118;
  padding: 7px 14px;
  font-size: 12px;
}
.btn-export:not(:disabled):hover { opacity: 0.85; }

/* ── Map + right column ── */
.gpx-right { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
#map { flex: 1; min-height: 0; }
.leaflet-container { background: #1a2332; }

/* ── Elevation panel ── */
.elev-panel {
  height: 160px;
  flex-shrink: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: height 0.2s;
}
.elev-panel.hidden { display: none; }
.elev-panel.collapsed { height: 36px; }
.elev-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  height: 36px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.elev-title { font-size: 11px; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; }
.elev-meta { font-size: 11px; color: var(--text-muted); flex: 1; }
.elev-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
  width: auto;
  transition: transform 0.2s;
}
.elev-panel.collapsed .elev-toggle { transform: rotate(180deg); }
.elev-body {
  flex: 1;
  position: relative;
  overflow: hidden;
  padding: 8px 14px 6px;
}
.elev-panel.collapsed .elev-body { display: none; }
.elev-svg { width: 100%; height: 100%; display: block; }
.elev-tooltip {
  position: absolute;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
  color: var(--text);
  pointer-events: none;
  white-space: nowrap;
  z-index: 10;
}
.elev-tooltip.hidden { display: none; }

/* ── Stop popup ── */
.leaflet-popup-content-wrapper {
  background: var(--surface) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5) !important;
}
.leaflet-popup-tip { background: var(--surface) !important; }
.leaflet-popup-content { font-size: 13px; line-height: 1.5; margin: 10px 14px !important; }
.stop-popup-name { font-weight: 700; margin-bottom: 2px; }
.stop-popup-type { font-size: 11px; color: var(--text-muted); }

/* ── Responsive ── */
@media (max-width: 700px) {
  :root { --header-h: 50px; }
  .gpx-nav { display: none; }
  .gpx-title { flex: 1; }
  .gpx-layout { flex-direction: column; }
  .gpx-sidebar { width: 100%; max-height: 220px; flex-direction: row; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; }
  .sb-section { flex-shrink: 0; border-bottom: none; border-right: 1px solid var(--border); }
  .sb-waypoints, .sb-stats, .sb-actions { display: none; }
  .elev-panel { height: 120px; }
}
