:root {
  --ink: #16191c;
  --ink-soft: #5c6360;
  --paper: #ffffff;
  --rail: #f4f5f3;
  --line: #dcdfda;
  --focus: #1f5fd0;

  /* Operator colours live in app.js (COLOUR), which sets --c and --fill. */

  --rail-w: 330px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--rail);
}

#map {
  position: absolute;
  inset: 0 0 0 var(--rail-w);
  background: #e9ebe7;
}

/* ---------- rail ---------- */

#rail {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--rail-w);
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px 20px 18px;
  overflow-y: auto;
  background: var(--paper);
  border-right: 1px solid var(--line);
  z-index: 800;
}

.rail-head h1 {
  margin: 0;
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.rail-head p {
  margin: 3px 0 0;
  color: var(--ink-soft);
  font-size: 13.5px;
}

.block { display: flex; flex-direction: column; gap: 10px; }

.block h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
}

.block-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

/* ---------- operator filters ---------- */

.ops { display: flex; flex-direction: column; gap: 2px; }

.op {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  margin: 0 -8px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
}

.op:hover { background: var(--rail); }

.op input { position: absolute; opacity: 0; pointer-events: none; }

.op .swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .22);
}

.op input:not(:checked) ~ .swatch { background: transparent; }
.op input:not(:checked) ~ .name { color: var(--ink-soft); text-decoration: line-through; }
.op input:focus-visible ~ .name { outline: 2px solid var(--focus); outline-offset: 3px; }

.op .count {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 12.5px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

/* ---------- basemap switch ---------- */

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
}

.segmented button {
  appearance: none;
  border: 0;
  border-left: 1px solid var(--line);
  background: var(--paper);
  padding: 7px 4px;
  font: inherit;
  font-size: 13px;
  color: var(--ink-soft);
  cursor: pointer;
}

.segmented button:first-child { border-left: 0; }
.segmented button[aria-checked="true"] { background: var(--ink); color: #fff; }
.segmented button:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }

/* ---------- nearest ---------- */

button.ghost {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  padding: 4px 10px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

button.ghost:hover { border-color: var(--ink-soft); }
button.ghost:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
button.ghost[disabled] { opacity: .55; cursor: progress; }

.nearest { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }

.nearest .empty {
  color: var(--ink-soft);
  font-size: 13.5px;
  padding: 2px 0;
}

.nearest .row {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px;
  margin: 0 -8px;
  border-radius: 6px;
  border: 0;
  background: none;
  font: inherit;
  text-align: left;
  cursor: pointer;
  width: calc(100% + 16px);
}

.nearest .row:hover { background: var(--rail); }
.nearest .row:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }

.nearest .dial { display: block; }
.nearest .dial circle { fill: none; stroke: var(--line); stroke-width: 1; }
.nearest .dial path { fill: var(--ink); }

.nearest .who { font-size: 13.5px; }
.nearest .who span { color: var(--ink-soft); }

.nearest .dist {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- footer ---------- */

.rail-foot {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink-soft);
}

.rail-foot p { margin: 0 0 6px; }
.rail-foot b { font-family: "IBM Plex Mono", ui-monospace, monospace; color: var(--ink); font-weight: 500; }
.rail-foot a { color: inherit; }
.fineprint { font-style: italic; }

/* ---------- markers ---------- */

.pin-wrap { background: none; border: 0; }

.pin {
  display: block;
  border-radius: 50%;
  background: var(--fill);
  box-shadow: 0 0 0 1.5px #fff, 0 0 0 2.5px rgba(22, 25, 28, .55);
}

.leaflet-marker-icon:hover .pin { box-shadow: 0 0 0 1.5px #fff, 0 0 0 3.5px var(--ink); }

/* ---------- popup ---------- */

.leaflet-popup-content-wrapper { border-radius: 8px; }
.leaflet-popup-content { margin: 12px 14px; font-family: "IBM Plex Sans", system-ui, sans-serif; }

.pop h3 { margin: 0 0 8px; font-size: 14px; font-weight: 600; }

.pop ul { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-wrap: wrap; gap: 5px; }

.pop li {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px 2px 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12.5px;
}

.pop li i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }

.pop dl {
  margin: 0 0 10px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 12px;
  font-size: 12.5px;
}

.pop dt { color: var(--ink-soft); }
.pop dd { margin: 0; font-family: "IBM Plex Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; }
.pop a.detail { font-size: 12.5px; }

/* ---------- responsive ---------- */

#rail-toggle { display: none; }

@media (max-width: 720px) {
  :root { --rail-w: 100%; }

  #map { inset: 0; }

  #rail {
    inset: auto 0 0 0;
    width: 100%;
    max-height: 68vh;
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
    border-right: 0;
    border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -6px 24px rgba(0, 0, 0, .12);
    transition: transform .22s ease;
  }

  body.rail-closed #rail { transform: translateY(calc(100% - 0px)); }

  #rail-toggle {
    display: block;
    position: absolute;
    left: 50%;
    bottom: 0;
    transform: translate(-50%, 0);
    z-index: 900;
    appearance: none;
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 8px 8px 0 0;
    background: var(--paper);
    padding: 6px 18px calc(6px + env(safe-area-inset-bottom));
    font: inherit;
    font-size: 13px;
    cursor: pointer;
  }

  body:not(.rail-closed) #rail-toggle { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
