:root {
  --bg: #ffffff;
  --bg-sunk: #f4f5f7;
  --fg: #1a1d21;
  --fg-dim: #6b7280;
  --line: #e3e6ea;
  --accent: #2b6cb0;
  --accent-fg: #ffffff;
  --from: #2f9e44;
  --to: #e03131;
  --via: #f08c00;
  --reach: #7048e8;
  --shadow: 0 2px 16px rgba(16, 24, 40, .14);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --bg-sunk: #1e2127;
    --fg: #e8eaed;
    --fg-dim: #9aa2ad;
    --line: #2b2f37;
    --accent: #4c8fd6;
    --shadow: 0 2px 16px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
  overflow: hidden;
}
#map { position: absolute; inset: 0; }

/* ------------------------------------------------------------------ panel */
#panel {
  position: absolute;
  top: 12px; left: 12px; bottom: 12px;
  width: 360px;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  z-index: 10;
}
#panel.hidden { display: none; }

#panel header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
#panel h1 { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: .2px; }

#health { display: flex; gap: 5px; }
#health i {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--fg-dim); opacity: .35;
  transition: background .3s, opacity .3s;
}
#health i.up { background: var(--from); opacity: 1; }
#health i.down { background: var(--to); opacity: 1; }

#tabs { display: flex; border-bottom: 1px solid var(--line); }
#tabs button {
  flex: 1; padding: 9px; border: 0; background: none; cursor: pointer;
  color: var(--fg-dim); font: inherit; font-weight: 550;
  border-bottom: 2px solid transparent;
}
#tabs button.active { color: var(--fg); border-bottom-color: var(--accent); }

.tab { display: none; padding: 12px; overflow-y: auto; flex: 1; }
.tab.active { display: block; }

/* ----------------------------------------------------------------- fields */
.field { position: relative; display: flex; align-items: center; margin-bottom: 8px; }
.field input {
  width: 100%; padding: 9px 30px 9px 11px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg-sunk); color: var(--fg); font: inherit;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field .pin {
  flex: 0 0 22px; height: 22px; margin-right: 8px;
  display: grid; place-items: center;
  border-radius: 50%; color: #fff; font-size: 11px; font-weight: 700;
}
.pin.from { background: var(--from); }
.pin.to   { background: var(--to); }
.pin.reach { background: var(--reach); font-size: 13px; }
#q-clear {
  position: absolute; right: 6px; border: 0; background: none;
  color: var(--fg-dim); cursor: pointer; font-size: 13px; padding: 4px;
}

.row { display: flex; gap: 8px; margin-bottom: 10px; align-items: center; }
button {
  font: inherit; color: var(--fg); background: var(--bg-sunk);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 11px; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary {
  flex: 1; background: var(--accent); color: var(--accent-fg);
  border-color: var(--accent); font-weight: 600;
}
button.primary:disabled { opacity: .55; cursor: progress; }
button:disabled { opacity: .5; cursor: default; }
button:disabled:hover { border-color: var(--line); }
button.small { font-size: 12.5px; padding: 5px 10px; }

.segmented { display: flex; flex: 1; }
.segmented button {
  flex: 1; border-radius: 0; font-size: 16px; padding: 7px 0;
  border-left-width: 0;
}
.segmented button:first-child { border-radius: 8px 0 0 8px; border-left-width: 1px; }
.segmented button:last-child  { border-radius: 0 8px 8px 0; }
.segmented button.active { background: var(--accent); border-color: var(--accent); }
.segmented.text button { font-size: 13px; }
.segmented.text button.active { color: var(--accent-fg); }

/* ---------------------------------------------------------------- results */
#results { list-style: none; margin: 0; padding: 0; }
#results li {
  padding: 9px 10px; border-radius: 8px; cursor: pointer;
  border: 1px solid transparent;
}
#results li:hover, #results li.sel { background: var(--bg-sunk); border-color: var(--line); }
#results .name { font-weight: 550; }
#results .meta { color: var(--fg-dim); font-size: 12.5px; }
#results .kind {
  float: right; font-size: 11px; color: var(--fg-dim);
  background: var(--bg-sunk); border-radius: 4px; padding: 1px 5px;
}

.hint { color: var(--fg-dim); font-size: 12.5px; margin: 14px 2px 0; }

/* ----------------------------------------------------------------- route */
#summary { font-size: 13px; color: var(--fg-dim); margin-bottom: 8px; }
#summary strong { color: var(--fg); font-size: 17px; font-weight: 650; }
#steps { list-style: none; margin: 0; padding: 0; }
#steps li {
  padding: 8px 4px 8px 10px; border-left: 2px solid var(--line);
  cursor: pointer; font-size: 13px;
}
#steps li:hover { border-left-color: var(--accent); background: var(--bg-sunk); }
#steps .dist { color: var(--fg-dim); font-size: 12px; }
#steps li.leg {
  margin-top: 8px; border-left-color: var(--accent);
  background: var(--bg-sunk); border-radius: 0 6px 6px 0;
}
#steps li.leg:first-child { margin-top: 0; }

/* Stop list: lettered pins double as drag handles. */
#stops { list-style: none; margin: 0; padding: 0; }
#stops .pin { cursor: grab; }
#stops li.dragging { opacity: .45; }
#stops li.drop input { outline: 2px dashed var(--accent); outline-offset: -1px; }
.remove {
  flex: 0 0 auto; margin-left: 6px; padding: 5px 8px;
  background: none; border-color: transparent; color: var(--fg-dim); font-size: 12px;
}
.remove:hover { color: var(--to); }

/* Map pins for stops and the reach origin. The outer element is positioned
   by MapLibre (it owns `transform`), so all styling sits on the child. */
.stop-marker { cursor: grab; }
.stop-marker span {
  display: grid; place-items: center; width: 26px; height: 26px;
  border-radius: 50%; border: 2px solid #fff; background: var(--c);
  color: #fff; font: 700 12px system-ui, sans-serif;
  box-shadow: 0 1px 5px rgba(0, 0, 0, .4);
}
.stop-marker::after {
  content: ''; display: block; width: 0; height: 0; margin: -1px auto 0;
  border: 6px solid transparent; border-top: 8px solid var(--c); border-bottom: 0;
}

/* ----------------------------------------------------------------- reach */
#tab-reach h3 {
  margin: 16px 0 8px; font-size: 11.5px; font-weight: 650;
  text-transform: uppercase; letter-spacing: .5px; color: var(--fg-dim);
}
#tab-reach h3 small { text-transform: none; letter-spacing: 0; font-weight: 400; margin-left: 4px; }
#reach-summary { margin: 0 2px 4px; }
#reach-summary:empty { display: none; }

#contours { list-style: none; margin: 0 0 8px; padding: 0; }
#contours li { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
#contours input[type=color] {
  width: 34px; height: 30px; padding: 2px; border: 1px solid var(--line);
  border-radius: 6px; background: var(--bg-sunk); cursor: pointer;
}
#contours input[type=number] { width: 90px; }
#contours .unit { color: var(--fg-dim); font-size: 12.5px; flex: 1; }

#tab-reach input[type=number], #tab-reach select {
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg-sunk); color: var(--fg); font: inherit;
}
#tab-reach input[type=number]:focus, #tab-reach select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.opt {
  display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 13px;
}
.opt > span:first-child { flex: 0 0 104px; color: var(--fg-dim); }
.opt input[type=range] { flex: 1; accent-color: var(--accent); min-width: 0; }
.opt output { flex: 0 0 44px; text-align: right; font-size: 12px; color: var(--fg-dim); font-variant-numeric: tabular-nums; }
.opt .num { display: flex; align-items: center; gap: 6px; color: var(--fg-dim); font-size: 12.5px; }
.opt .num input { width: 100px; }
.opt select { flex: 1; }
.check {
  display: flex; align-items: center; gap: 8px; margin-bottom: 6px;
  font-size: 13px; cursor: pointer;
}
.check input { accent-color: var(--accent); margin: 0; }
[hidden] { display: none !important; }
#reach-reset { margin-top: 10px; }

#panel footer {
  padding: 8px 14px; border-top: 1px solid var(--line);
  color: var(--fg-dim); font-size: 11.5px;
}

/* --------------------------------------------------------------- overlays */
#panel-toggle {
  position: absolute; top: 12px; left: 12px; z-index: 11;
  display: none; box-shadow: var(--shadow); background: var(--bg);
}
#panel.hidden + #panel-toggle { display: block; }

#toast {
  position: absolute; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #23262d; color: #fff; padding: 9px 15px; border-radius: 8px;
  box-shadow: var(--shadow); z-index: 20; opacity: 0; pointer-events: none;
  transition: opacity .25s; font-size: 13px; max-width: 80vw;
}
#toast.show { opacity: 1; }

.maplibregl-popup-content {
  background: var(--bg); color: var(--fg);
  border-radius: 8px; box-shadow: var(--shadow); padding: 10px 12px;
}
.maplibregl-popup-content button { margin-top: 7px; margin-right: 5px; font-size: 12px; padding: 5px 9px; }
.maplibregl-popup-tip { border-top-color: var(--bg) !important; border-bottom-color: var(--bg) !important; }

@media (max-width: 640px) {
  #panel { top: 8px; left: 8px; right: 8px; bottom: 8px; width: auto; }
}

/* Suggestion dropdown under the stop / reach-origin fields (after the pin). */
.suggest {
  position: absolute; top: calc(100% + 2px); left: 30px; right: 0; z-index: 5;
  list-style: none; margin: 0; padding: 4px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow); max-height: 280px; overflow-y: auto;
}
.suggest li { padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.suggest li.sel, .suggest li:hover { background: var(--bg-sunk); }
.suggest .name { font-weight: 550; font-size: 13px; }
.suggest .meta { color: var(--fg-dim); font-size: 12px; }

/* Road-type breakdown (route) and colour key (reach). */
.roadlegend { margin: 2px 0 8px; font-size: 12.5px; }
.roadbar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; margin-bottom: 6px; gap: 1px; }
.roadbar span { flex-basis: 0; min-width: 2px; }
.roadlegend ul { list-style: none; margin: 0; padding: 0; }
.roadlegend li { display: flex; align-items: center; gap: 7px; padding: 1px 0; }
.roadlegend i { width: 10px; height: 10px; border-radius: 2px; flex: none; }
.roadlegend .dist { margin-left: auto; color: var(--fg-dim); font-variant-numeric: tabular-nums; }
#tab-route > .check { margin-bottom: 10px; }

/* --------------------------------------------------------------- planning */
#tabs button { padding: 9px 4px; }
.tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tools button { font-size: 12.5px; padding: 7px 4px; }
.tools button.active { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
#tab-plan h3 {
  margin: 16px 0 8px; font-size: 11.5px; font-weight: 650;
  text-transform: uppercase; letter-spacing: .5px; color: var(--fg-dim);
}
#tab-plan h3 small { text-transform: none; letter-spacing: 0; font-weight: 400; margin-left: 4px; }
#plan-hint { margin: 4px 2px 0; min-height: 2.9em; }

#plan-items { list-style: none; margin: 0 0 10px; padding: 0; }
.plan-item {
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px 4px; margin-bottom: 6px;
}
.plan-item.off { opacity: .55; }
.plan-item .head { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.plan-item .head input[type=checkbox] { accent-color: var(--accent); margin: 0; }
.plan-item .icon { width: 18px; text-align: center; }
.plan-item .name {
  flex: 1; min-width: 0; border: 1px solid transparent; border-radius: 6px;
  background: none; color: var(--fg); font: inherit; font-weight: 550; padding: 3px 5px;
}
.plan-item .name:hover, .plan-item .name:focus { border-color: var(--line); background: var(--bg-sunk); outline: none; }
.plan-item .remove { margin-left: 0; padding: 3px 6px; }
.plan-item .opt { margin-bottom: 5px; }
.plan-item .opt > span:first-child { flex-basis: 84px; }
.plan-item .check { font-size: 12.5px; }
.plan-item .meta { color: var(--fg-dim); font-size: 12px; margin-bottom: 4px; }
#tab-plan input[type=number] {
  padding: 5px 8px; width: 90px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg-sunk); color: var(--fg); font: inherit;
}

.plan-note { color: #ae3ec9; font-size: 12.5px; margin-top: 2px; }

.plan-marker { cursor: grab; display: grid; place-items: center; }
.plan-marker.block { font-size: 20px; line-height: 1; filter: drop-shadow(0 1px 2px rgba(0,0,0,.4)); }
.plan-marker.centre, .plan-marker.end {
  width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
.plan-marker.centre { background: #e03131; }
.plan-marker.end { background: var(--c); }
.plan-marker.off { opacity: .45; }

/* ---------------------------------------------------------------- vehicle */
.vehicle .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; margin-bottom: 8px; }
.vehicle .grid label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--fg-dim); }
.vehicle .grid label span { display: flex; align-items: center; gap: 5px; color: var(--fg-dim); }
#tab-plan .vehicle .grid input[type=number] { width: 100%; min-width: 0; }
#tab-plan select {
  flex: 1; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg-sunk); color: var(--fg); font: inherit; min-width: 0;
}
#tab-plan .opt > span:first-child { flex-basis: 64px; }
.vehicle .hint { margin-top: 6px; }

/* Route report: surfaces, vehicle checks, bridges and tunnels. */
#route-report h4 { margin: 12px 0 6px; font-size: 12px; font-weight: 650; }
#route-report .checks { list-style: none; margin: 0 0 6px; padding: 0; font-size: 12.5px; }
#route-report .checks li { padding: 2px 0; }
#route-report .checks li.sub { padding-left: 14px; }
#route-report .checks li.link { cursor: pointer; text-decoration: underline dotted; }
#route-report .checks .ok { color: var(--from); }
#route-report .checks .warn { color: var(--to); }
#route-report .checks .info { color: var(--fg-dim); }
#route-report details { margin: 6px 0; font-size: 12.5px; }
#route-report summary { cursor: pointer; font-weight: 550; }
#route-report details ul { list-style: none; margin: 4px 0 0; padding: 0; max-height: 220px; overflow-y: auto; }
#route-report details li {
  display: flex; justify-content: space-between; gap: 8px; padding: 3px 6px; border-radius: 4px; cursor: pointer;
}
#route-report details li:hover { background: var(--bg-sunk); }
#route-report details .dist { color: var(--fg-dim); font-variant-numeric: tabular-nums; }

/* Map / Satellite / Hybrid switcher (top right, under the other controls). */
.basemap-ctrl { display: flex; flex-direction: column; }
.maplibregl-ctrl-group.basemap-ctrl button {
  width: auto; height: auto; padding: 5px 9px; font: 600 11.5px system-ui, sans-serif;
  color: #333; border-radius: 0; border: 0; background: #fff;
}
.maplibregl-ctrl-group.basemap-ctrl button + button { border-top: 1px solid #ddd; }
.maplibregl-ctrl-group.basemap-ctrl button.active { background: var(--accent); color: #fff; }
.maplibregl-ctrl-group.basemap-ctrl button:disabled { color: #aaa; background: #f6f6f6; cursor: not-allowed; }
.plan-warn { color: var(--to); font-size: 12.5px; margin: 0 2px 8px; }
