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

html, body {
  height: 100%;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  background: #1a1a1a;
  color: #e0e0e0;
}

body {
  display: flex;
  overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────────────── */
#sidebar {
  width: 270px;
  min-width: 270px;
  height: 100vh;
  background: #1e1e1e;
  border-right: 1px solid #333;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 16px;
  overflow-y: auto;
  z-index: 1000;
}

/* ── Sidebar header (title + language switcher) ──────────── */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

h1 {
  font-size: 16px;
  font-weight: 700;
  color: #f0a500;
  letter-spacing: .04em;
  text-transform: uppercase;
}

#lang-select {
  background: #2a2a2a;
  color: #ccc;
  border: 1px solid #3a3a3a;
  border-radius: 4px;
  font-size: 12px;
  padding: 3px 6px;
  cursor: pointer;
  transition: border-color .15s;
  outline: none;
}

#lang-select:hover,
#lang-select:focus { border-color: #f0a500; }

.field-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field-group label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #999;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ── Swap button (between start and end) ─────────────────── */
.swap-row {
  display: flex;
  justify-content: flex-end;
  margin: -4px 0;   /* tuck it between the two field-groups */
}

#btn-swap {
  background: transparent;
  border: 1px solid #3a3a3a;
  border-radius: 4px;
  color: #555;
  font-size: 14px;
  padding: 2px 7px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
  line-height: 1;
}

#btn-swap:hover { color: #f0a500; border-color: #f0a500; }

.field-group input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  background: #2a2a2a;
  border: 1px solid #3a3a3a;
  border-radius: 6px;
  color: #e0e0e0;
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}

.field-group input[type="text"]:focus {
  border-color: #f0a500;
}

.field-group input[type="text"].has-value {
  border-color: #4caf50;
}

.pin-btn {
  background: none;
  border: none;
  color: #666;
  cursor: pointer;
  font-size: 16px;
  padding: 0 2px;
  line-height: 1;
  transition: color .15s;
}

.pin-btn:hover { color: #f0a500; }
.pin-btn.active { color: #f0a500; }

/* ── Waypoint rows ───────────────────────────────────────── */
.wp-actions {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.wp-remove {
  background: none;
  border: none;
  color: #555;
  cursor: pointer;
  font-size: 14px;
  padding: 0 2px;
  line-height: 1;
  transition: color .15s;
}

.wp-remove:hover { color: #e53935; }

#btn-add-wp {
  width: 100%;
  padding: 6px;
  background: transparent;
  color: #555;
  border: 1px dashed #3a3a3a;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}

#btn-add-wp:hover { color: #f0a500; border-color: #f0a500; }

/* ── Fit-route floating button ───────────────────────────── */
#btn-fit-route {
  padding: 6px 10px;
  background: rgba(30,30,30,.88);
  color: #ccc;
  border: 1px solid #444;
  border-radius: 4px;
  font-size: 15px;
  cursor: pointer;
  transition: background .15s;
}

#btn-fit-route:hover { background: rgba(50,50,50,.95); color: #f0a500; }

/* ── Vary button + gear ───────────────────────────────────── */
.vary-row {
  display: flex;
  gap: 6px;
}

#btn-vary-gear {
  padding: 9px 10px;
  background: #252525;
  color: #666;
  border: 1px solid #444;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
  flex-shrink: 0;
}

#btn-vary-gear:hover,
#btn-vary-gear.active { color: #f0a500; border-color: #f0a500; }

/* ── Vary options panel ───────────────────────────────────── */
#vary-panel {
  background: #252525;
  border: 1px solid #333;
  border-radius: 6px;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.vopt-row {
  display: grid;
  grid-template-columns: 1fr auto 38px;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #aaa;
}

.vopt-row input[type="range"] {
  width: 80px;
  accent-color: #f0a500;
}

.vopt-row span:last-child {
  font-size: 11px;
  color: #888;
  text-align: right;
}

#btn-shuffle {
  flex: 1;
  padding: 9px;
  background: #252525;
  color: #f0a500;
  border: 1px solid #555;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

#btn-shuffle:hover:not(:disabled) { border-color: #f0a500; background: #2a2200; }
#btn-shuffle:disabled { opacity: .35; cursor: default; }

/* ── Stats ───────────────────────────────────────────────── */
#route-stats {
  background: #2a2a2a;
  border: 1px solid #333;
  border-radius: 6px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.stat-label {
  font-size: 11px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.stat-row span:last-child {
  font-size: 14px;
  font-weight: 600;
  color: #e0e0e0;
}

/* ── Download button ─────────────────────────────────────── */
#btn-download {
  width: 100%;
  padding: 8px;
  background: #2a2a2a;
  color: #4caf50;
  border: 1px solid #4caf50;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}

#btn-download:hover { background: #1e3a1e; }

/* ── Route Profile ───────────────────────────────────────── */
#route-profile {
  border: 1px solid #333;
  border-radius: 6px;
  /* no overflow:hidden here — it swallows the #profile-content scrollbar */
  flex-shrink: 0;
}

#profile-content {
  max-height: 220px;
  overflow-y: scroll;
  scrollbar-width: thin;
  scrollbar-color: #555 #252525;
  border-radius: 0 0 6px 6px;
}

#profile-content::-webkit-scrollbar { width: 6px; }
#profile-content::-webkit-scrollbar-track { background: #1e1e1e; }
#profile-content::-webkit-scrollbar-thumb { background: #555; border-radius: 3px; }

.profile-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: #252525;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #888;
  border-radius: 6px 6px 0 0;
}

#scenic-score {
  font-size: 13px;
  font-weight: 700;
  color: #4caf50;
  text-transform: none;
  letter-spacing: 0;
}

.profile-section {
  padding: 8px 12px 4px;
  border-top: 1px solid #2a2a2a;
  cursor: pointer;
  transition: background .12s;
  user-select: none;
}

.profile-section:first-child { border-top: none; }

.profile-section:hover { background: #242424; }

.profile-section.selected { background: #222; }

.profile-tag-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #666;
  margin-bottom: 5px;
  transition: color .12s;
}

.profile-section.selected .profile-tag-title {
  color: #f0a500;
}

.bar-row {
  display: grid;
  grid-template-columns: 90px 1fr 36px;
  align-items: center;
  gap: 5px;
  margin-bottom: 4px;
}

.bar-label {
  font-size: 11px;
  color: #bbb;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-track {
  height: 6px;
  background: #2a2a2a;
  border-radius: 3px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width .4s ease;
}

.bar-pct {
  font-size: 11px;
  color: #888;
  text-align: right;
}

/* ── Routing style segmented control ────────────────────── */
.opt-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #555;
  padding: 8px 12px 4px;
}

.style-seg {
  display: flex;
  margin: 0 12px 6px;
  border: 1px solid #3a3a3a;
  border-radius: 6px;
  overflow: hidden;
}

.seg-btn {
  flex: 1;
  padding: 7px 0;
  background: transparent;
  border: none;
  border-right: 1px solid #3a3a3a;
  color: #666;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s, color .12s;
}

.seg-btn:last-child { border-right: none; }
.seg-btn:hover { background: #2a2a2a; color: #bbb; }
.seg-btn.active { background: #252525; color: #f0a500; }

/* ── Options panel ───────────────────────────────────────── */
#options-panel {
  border: 1px solid #333;
  border-radius: 6px;
  overflow: hidden;
}

#options-panel summary {
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #888;
  cursor: pointer;
  user-select: none;
  background: #252525;
  list-style: none;
}

#options-panel summary::after {
  content: ' ▸';
  float: right;
}

#options-panel[open] summary::after {
  content: ' ▾';
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 13px;
  color: #ccc;
}

.toggle-row:hover { background: #2a2a2a; }

.toggle-row input[type="checkbox"] {
  accent-color: #f0a500;
  width: 15px;
  height: 15px;
  cursor: pointer;
}

/* ── Status message ──────────────────────────────────────── */
#status-msg {
  font-size: 12px;
  color: #aaa;
  min-height: 18px;
  line-height: 1.4;
}

#status-msg.error { color: #e57373; }

/* ── Map ─────────────────────────────────────────────────── */
#map {
  flex: 1;
  height: 100vh;
}

/* ── Floating map controls (Aa + fit-route) ──────────────── */
#map-controls {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 1001;
  display: flex;
  gap: 4px;          /* ~10 % of button height (~36 px) */
}

#btn-layer-toggle {
  padding: 6px 12px;
  background: rgba(30,30,30,.88);
  color: #ccc;
  border: 1px solid #444;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}

#btn-layer-toggle:hover { background: rgba(50,50,50,.95); }
#btn-layer-toggle.active { color: #f0a500; border-color: #f0a500; }

/* ── Leaflet scale bar (dark theme) ─────────────────────── */
.leaflet-control-scale-line {
  background: rgba(20,20,20,.82);
  border: 2px solid #aaa;
  border-top: none;
  color: #ddd;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 5px;
  line-height: 1.4;
}

/* ── Utilities ───────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Leaflet overrides ───────────────────────────────────── */
.leaflet-container { background: #111; }
