: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;
}

/* ---------- map controls ---------- */

.leaflet-bar a.ctl-icon {
  display: grid;
  place-items: center;
  color: var(--ink);
}

.leaflet-bar a.ctl-icon:hover { color: #000; }

.ctl-icon.busy { opacity: .45; pointer-events: none; }

.ctl-icon.busy svg { animation: pulse 1s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: .3; } }

/* ---------- about popover ---------- */

#info-panel {
  position: absolute;
  right: 12px;
  bottom: 58px;
  z-index: 1200;
  width: min(320px, calc(100vw - 24px));
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .16);
  font-size: 12px;
  color: var(--ink-soft);
}

#info-panel[hidden] { display: none; }
#info-panel p { margin: 0 0 8px; }
#info-panel p:last-child { margin-bottom: 0; }
#info-panel b { font-family: "IBM Plex Mono", ui-monospace, monospace; color: var(--ink); font-weight: 500; }
#info-panel 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; }
#scrim { display: none; }

@media (max-width: 720px) {
  #map { inset: 0; }

  /* The panel becomes a drawer off the right edge, under the burger. */
  #rail {
    inset: 0 0 0 auto;
    width: min(340px, 86vw);
    padding: calc(22px + env(safe-area-inset-top)) 20px calc(18px + env(safe-area-inset-bottom));
    border-right: 0;
    border-left: 1px solid var(--line);
    box-shadow: -8px 0 28px rgba(0, 0, 0, .14);
    transform: translateX(100%);
    transition: transform .24s ease;
    z-index: 1000;
  }

  body.rail-open #rail { transform: none; }

  /* Keep the title clear of the burger. */
  .rail-head { padding-right: 54px; }

  #scrim {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 950;
    background: rgba(10, 12, 14, .38);
    opacity: 0;
    pointer-events: none;
    transition: opacity .24s ease;
  }

  body.rail-open #scrim { opacity: 1; pointer-events: auto; }

  #rail-toggle {
    display: grid;
    place-items: center;
    position: absolute;
    top: calc(12px + env(safe-area-inset-top));
    right: 12px;
    z-index: 1100;
    width: 42px;
    height: 42px;
    padding: 0;
    appearance: none;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--paper);
    box-shadow: 0 1px 4px rgba(0, 0, 0, .14);
    cursor: pointer;
  }

  #rail-toggle:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

  .burger, .burger::before, .burger::after {
    display: block;
    width: 18px;
    height: 2px;
    border-radius: 2px;
    background: var(--ink);
    transition: transform .2s ease, background .2s ease;
  }

  .burger { position: relative; }
  .burger::before, .burger::after { content: ''; position: absolute; }
  .burger::before { transform: translateY(-6px); }
  .burger::after { transform: translateY(6px); }

  /* Open: the same control becomes the close button. */
  body.rail-open .burger { background: transparent; }
  body.rail-open .burger::before { transform: rotate(45deg); }
  body.rail-open .burger::after { transform: rotate(-45deg); }
}

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