:root {
  --bg: #ffffff;
  --panel: #fbfbfa;
  --ink: #111214;
  --muted: #62666d;
  --line: #e3e3e0;
  --accent: #0b6bcb;
  --accent-ink: #ffffff;
  --a: #1a9e4b;
  --b: #d63a2f;
  --chip: #f0f0ee;
  --shadow: 0 2px 12px rgba(0, 0, 0, .12);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151618; --panel: #1c1d20; --ink: #ececea; --muted: #a0a3a8; --line: #2e3034;
    --accent: #4a9eff; --chip: #26282c; --shadow: 0 2px 12px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151618; --panel: #1c1d20; --ink: #ececea; --muted: #a0a3a8; --line: #2e3034;
  --accent: #4a9eff; --chip: #26282c; --shadow: 0 2px 12px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 14px/1.45 Inter, system-ui, -apple-system, Segoe UI, sans-serif; }
button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; color: inherit; }
a { color: var(--accent); }

#app { display: flex; height: 100dvh; }
#map { flex: 1; background: #e8eaea; }
#panel { width: 380px; flex: none; display: flex; flex-direction: column; gap: 14px;
  padding: 20px 18px 14px; overflow-y: auto; background: var(--panel); border-right: 1px solid var(--line); z-index: 500; }
#sheet-handle { display: none; }

header h1 { font: 700 30px/1.02 "Roboto Condensed", sans-serif; letter-spacing: -.3px; margin: 0; }
header .sub { margin: 6px 0 0; color: var(--muted); }

.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab { flex: 1; background: none; border: 0; padding: 8px 0 10px; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--ink); border-bottom-color: var(--ink); }

.filters { display: grid; gap: 6px; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; }
.switch span { width: 34px; height: 20px; border-radius: 10px; background: var(--line); position: relative; transition: .15s; flex: none; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(14px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.tabpane { display: flex; flex-direction: column; gap: 10px; }
.tabpane[hidden] { display: none; }

.field { position: relative; display: flex; align-items: center; gap: 8px; }
.field input { flex: 1; min-width: 0; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.pin { width: 24px; height: 24px; border-radius: 50%; color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: 12px; flex: none; }
.pin.a { background: var(--a); } .pin.b { background: var(--b); }
.icon-btn { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg);
  display: grid; place-items: center; color: var(--muted); flex: none; }
.icon-btn:hover { color: var(--ink); }
.suggest { position: absolute; top: 100%; left: 32px; right: 42px; margin: 4px 0 0; padding: 4px 0; list-style: none;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); z-index: 10; }
.suggest:empty { display: none; }
.suggest li { padding: 7px 10px; cursor: pointer; font-size: 13px; }
.suggest li small { display: block; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.suggest li:hover, .suggest li.active { background: var(--chip); }

.opts { display: grid; gap: 8px; }
.seg { display: flex; background: var(--chip); border-radius: 8px; padding: 3px; }
.seg button { flex: 1; border: 0; background: none; padding: 6px 4px; border-radius: 6px; font-size: 13px; color: var(--muted); }
.seg button.active { background: var(--bg); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }
.check { display: flex; gap: 8px; align-items: center; cursor: pointer; }

.status { color: var(--muted); font-size: 13px; min-height: 0; }
.status:empty { display: none; }
.progress { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; margin-top: 6px; }
.progress i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }

.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--chip); border-radius: 8px; padding: 8px 10px; }
.stat b { display: block; font: 700 20px/1.1 "Roboto Condensed", sans-serif; }
.stat span { color: var(--muted); font-size: 12px; }
.mix { display: flex; height: 8px; border-radius: 4px; overflow: hidden; margin: 10px 0 4px; background: var(--line); }
.mix i { display: block; height: 100%; }
.mix-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); }
.mix-legend span::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; background: var(--c); }
.steps { list-style: none; margin: 10px 0 0; padding: 0; border-top: 1px solid var(--line); }
.steps li { display: flex; gap: 10px; align-items: center; padding: 7px 2px; border-bottom: 1px solid var(--line); cursor: pointer; }
.steps li:hover { background: var(--chip); }
.steps .sw { width: 6px; align-self: stretch; border-radius: 3px; flex: none; }
.steps .sw.road { background: repeating-linear-gradient(180deg, #8a8f98 0 4px, transparent 4px 7px); }
.steps .nm { flex: 1; min-width: 0; }
.steps .nm small { color: var(--muted); display: block; font-size: 12px; }
.steps .km { color: var(--muted); font-variant-numeric: tabular-nums; }
.warn { color: #b26b00; font-size: 12px; margin-top: 6px; }
.link-btn { background: none; border: 0; color: var(--accent); padding: 0; justify-self: start; text-align: left; }

#trail-search { padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
#trail-list { list-style: none; margin: 0; padding: 0; }
#trail-list li { display: flex; align-items: center; gap: 10px; padding: 6px 4px; border-radius: 6px; cursor: pointer; }
#trail-list li:hover, #trail-list li.sel { background: var(--chip); }
#trail-list .sw { width: 18px; height: 5px; border-radius: 3px; flex: none; }
#trail-list .nm { flex: 1; min-width: 0; }
#trail-list .km { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
#trail-list .tag { font-size: 10px; padding: 1px 5px; border-radius: 4px; background: #f3e3c4; color: #7a4b00; margin-left: 6px; }

.legend { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; font-size: 12px; color: var(--muted);
  border-top: 1px solid var(--line); padding-top: 12px; margin-top: auto; }
.legend div { display: flex; align-items: center; gap: 8px; }
.ln { width: 26px; height: 0; border-top: 4px solid #3a7bd5; display: inline-block; }
.ln.unsealed { border-top-style: dashed; }
.ln.unknown { opacity: .5; }
.ln.road { border-top: 3px dashed #8a8f98; }
footer { font-size: 11px; color: var(--muted); }

/* Leaflet */
.basemap { filter: grayscale(1) brightness(1.06) contrast(.82); }
@media (prefers-color-scheme: dark) { .basemap { filter: grayscale(1) invert(1) brightness(.85) contrast(.85); } }
.leaflet-container { font: inherit; }
.leaflet-tooltip.trail-tip { font-weight: 600; border-radius: 6px; padding: 4px 8px; }
.leaflet-popup-content { margin: 12px 14px; }
.popup h3 { margin: 0 0 4px; font: 700 17px/1.15 "Roboto Condensed", sans-serif; }
.popup p { margin: 2px 0; color: #555; }
.marker-pin { width: 28px; height: 28px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.4); display: grid; place-items: center; }
.marker-pin b { transform: rotate(45deg); color: #fff; font-size: 12px; }
.pick-hint { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); z-index: 600; background: var(--ink);
  color: var(--bg); padding: 6px 12px; border-radius: 16px; font-size: 13px; pointer-events: none; }

@media (max-width: 760px) {
  #app { flex-direction: column-reverse; }
  #map { flex: 1; }
  #panel { position: fixed; left: 0; right: 0; bottom: 0; width: auto; max-height: 55dvh; border-right: 0;
    border-top: 1px solid var(--line); border-radius: 14px 14px 0 0; box-shadow: var(--shadow);
    padding: 6px 16px calc(14px + env(safe-area-inset-bottom)); transition: max-height .2s; gap: 12px; }
  #panel.collapsed { max-height: 132px; overflow: hidden; }
  #sheet-handle { display: block; background: none; border: 0; padding: 6px 0 2px; align-self: center; }
  #sheet-handle span { display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--line); }
  header h1 { font-size: 22px; }
  header h1 br { display: none; }
  header .sub { display: none; }
  .legend, footer { display: none; }
  #map { height: 100dvh; }
  .leaflet-control-zoom { display: none; }
  .leaflet-bottom.leaflet-right { top: 0; bottom: auto; }
  .filters { grid-template-columns: 1fr 1fr; font-size: 13px; }
}
