/* Colors meet WCAG AA (4.5:1) against the panel background, #0f1318 at 92%
   over the dark basemap. */
:root {
  --panel-bg: rgba(15, 19, 24, 0.92);
  --panel-solid: #0f1318;
  --fg: #ffffff; /* primary text, 18.6:1 */
  --fg-2: #c9d1d9; /* secondary text, 12.1:1 */
  --rule: rgba(255, 255, 255, 0.16);
  --off: #8b949e; /* switch outline when off, 6.1:1 (non-text, needs 3:1) */
  --warn: #ffd24d; /* 12.9:1 */
  --good: #7ee2a8; /* 11.8:1 */
  --bad: #ff8a7a; /* 8.1:1 */
  --focus: #ffffff;
  --left-w: 340px;
  --right-w: 310px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0d1014;
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#map { position: absolute; inset: 0; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

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

/* ---- Panels ------------------------------------------------------------ */

.panel {
  position: absolute;
  top: 12px;
  max-height: calc(100% - 60px);
  overflow-y: auto;
  padding: 12px 14px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--panel-bg);
  color: var(--fg);
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.45);
  z-index: 2;
}
.panel-left { left: 12px; width: var(--left-w); }
.panel-right { right: 12px; width: var(--right-w); }

.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.panel h1, .panel h2 { margin: 0; font-size: 16px; font-weight: 700; }
.panel-head .close { display: none; }

.close, .collapse, .drawer-btn {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}
.close { font-size: 22px; line-height: 1; padding: 2px 8px; color: var(--fg-2); border-radius: 6px; }
.collapse { display: flex; align-items: center; gap: 8px; padding: 2px 0; flex: 1; text-align: left; border-radius: 6px; }
.chev { width: 8px; height: 8px; border-right: 2px solid var(--fg-2); border-bottom: 2px solid var(--fg-2); transform: rotate(45deg); margin-top: -4px; transition: transform 0.15s; }
.collapse[aria-expanded="false"] .chev { transform: rotate(-45deg); margin-top: 0; }

.divider { height: 1px; margin: 10px 0 8px; background: var(--rule); }

/* ---- Switches: on = filled, knob right; off = gray outline, knob left --- */

.switch { position: relative; display: flex; align-items: center; gap: 10px; padding: 4px 0; cursor: pointer; user-select: none; font-weight: 600; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  position: relative;
  flex: none;
  width: 34px;
  height: 20px;
  border-radius: 999px;
  border: 2px solid var(--off);
  background: transparent;
  transition: background 0.15s, border-color 0.15s;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--off);
  transition: transform 0.15s, background 0.15s;
}
.switch input:checked + .track { background: var(--line, #3d8bd4); border-color: #ffffff; }
.switch input:checked + .track::after { transform: translateX(14px); background: #ffffff; }
.switch input:focus-visible + .track { outline: 2px solid var(--focus); outline-offset: 3px; }
.switch input:disabled + .track { opacity: 0.45; }
.switch input:disabled ~ span:last-child { color: var(--off); }
.switch input:disabled { cursor: not-allowed; }
.switch.small { color: var(--fg-2); }
.switch.small .track { width: 30px; height: 18px; }
.switch.small .track::after { width: 10px; height: 10px; }
.switch.small input:checked + .track::after { transform: translateX(12px); }

.line-group { border: 0; margin: 10px 0 0; padding: 0; }
.line-name { font-weight: 700; }
.dir-switches { margin: 2px 0 0 16px; padding-left: 10px; border-left: 3px solid var(--line); }
.line-group.off .dir-switches { border-left-color: var(--rule); }

.legend-trains { list-style: none; display: flex; gap: 14px; flex-wrap: wrap; margin: 10px 0 0; padding: 0; color: var(--fg-2); font-weight: 600; }
.legend-trains li { display: flex; align-items: center; gap: 6px; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: #6e7781; border: 2.5px solid #fff; box-shadow: 0 0 0 1px #000; }
.dot.ghost { background: rgba(110, 119, 129, 0.35); border-style: dashed; }
.dot.fill { background: linear-gradient(to top, #6e7781 0 55%, #0f1318 55% 100%); }
.legend-sim { list-style: none; margin: 10px 0 0; padding: 0; color: var(--fg-2); font-weight: 600; }
.legend-sim li { display: flex; align-items: center; gap: 8px; }
.mk.sim { border: 2.5px solid #ffffff; box-shadow: 0 0 0 1px #000; background: linear-gradient(to top, #b678d9 0 50%, #0f1318 50% 100%); }
.tip .mapboxgl-popup-content { padding: 6px 10px; font-size: 13px; }
.tip .mapboxgl-popup-tip { display: none; }

/* ---- Headways ---------------------------------------------------------- */

.hw-note { margin: 4px 0 2px; color: var(--fg-2); }
.hw-row { padding: 9px 0; border-top: 1px solid var(--rule); }
.hw-row:first-child { border-top: 0; }
.hw-title { display: flex; align-items: center; gap: 7px; font-weight: 700; }
.hw-dot { flex: none; width: 12px; height: 12px; border-radius: 50%; border: 2px solid #fff; }
.hw-values { margin-top: 2px; font-variant-numeric: tabular-nums; }
.hw-diff { margin-left: 4px; font-weight: 700; }
.hw-diff.warn { color: var(--warn); }
.hw-meta, .hw-footer, .hw-empty { color: var(--fg-2); }
.hw-meta { margin-top: 1px; }
.hw-footer { margin: 8px 0 0; }
.hw-footer:empty { display: none; }

/* ---- Status chips (top center, between the panels) --------------------- */

.chips {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 2 * (var(--right-w) + 24px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  z-index: 1;
}
.chip-status {
  margin: 0;
  padding: 5px 12px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--panel-bg);
  color: var(--fg);
  font-weight: 600;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}
.chip-status:empty, .chip-status[hidden] { display: none; }
.chip-status.error, .chip-status.banner { color: var(--bad); }
.chip-status.live { color: var(--good); }
.chip-status.pin { font-size: 13px; color: var(--fg); border-color: #ffffff; }

/* ---- Drawers at phone and narrow tablet widths ------------------------- */

.drawer-btn {
  display: none;
  position: absolute;
  top: 12px;
  z-index: 3;
  padding: 8px 14px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--panel-bg);
  color: var(--fg);
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}
.drawer-btn.left { left: 16px; }
.drawer-btn.right { right: 16px; }
.drawer-btn[aria-expanded="true"] { border-color: #ffffff; }

@media (max-width: 959px) {
  .drawer-btn { display: block; }
  .panel {
    display: none;
    top: 60px;
    width: min(360px, calc(100% - 32px));
    max-height: calc(100% - 124px);
    z-index: 4;
  }
  .panel.open { display: block; }
  .panel-left { left: 16px; }
  .panel-right { right: 16px; }
  .panel-head .close { display: block; }
  .chips { top: 60px; max-width: calc(100% - 32px); }
}

/* ---- Popups (dark, to match the panels) -------------------------------- */

.mapboxgl-popup-content {
  padding: 12px 14px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--panel-solid);
  color: var(--fg);
  font: inherit;
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.5);
}
.mapboxgl-popup-close-button { color: var(--fg-2); font-size: 20px; padding: 2px 8px; }
.mapboxgl-popup-anchor-top .mapboxgl-popup-tip, .mapboxgl-popup-anchor-top-left .mapboxgl-popup-tip, .mapboxgl-popup-anchor-top-right .mapboxgl-popup-tip { border-bottom-color: var(--panel-solid); }
.mapboxgl-popup-anchor-bottom .mapboxgl-popup-tip, .mapboxgl-popup-anchor-bottom-left .mapboxgl-popup-tip, .mapboxgl-popup-anchor-bottom-right .mapboxgl-popup-tip { border-top-color: var(--panel-solid); }
.mapboxgl-popup-anchor-left .mapboxgl-popup-tip { border-right-color: var(--panel-solid); }
.mapboxgl-popup-anchor-right .mapboxgl-popup-tip { border-left-color: var(--panel-solid); }

.popup-name { font-weight: 700; font-size: 16px; margin: 0 18px 4px 0; }
.popup-lines { display: flex; gap: 6px; }
.popup-field { margin-top: 2px; }
.field-name { font-weight: 700; }
.popup-note { margin-top: 6px; color: var(--fg-2); }
.popup-updated { margin-top: 6px; }
.muted { color: var(--fg-2); }
.train-status { font-weight: 700; margin: 4px 0 6px; font-variant-numeric: tabular-nums; }
.train-status.ontime { color: var(--fg); }
.train-status.late { color: var(--warn); }
.train-status.very-late { color: var(--bad); }
.train-status.early { color: #9ad8ff; }
.popup-name .chip { margin-right: 6px; }
/* Line chips: white on the official colors (1 Line 4.9:1, 2 Line 4.7:1) */
.chip { color: #fff; font-size: 14px; font-weight: 700; padding: 1px 9px; border-radius: 999px; }

/* ---- Layer tree -------------------------------------------------------- */

.group-head { display: flex; align-items: center; gap: 8px; }
.group-head .collapse { min-height: 32px; }
.group-head .switch { padding: 0 2px; min-height: 32px; flex: none; }
.group-name { font-size: 15px; font-weight: 700; }
.group-body { padding-left: 4px; }
.group-body.off { opacity: 0.55; }
.error-text { color: var(--bad); font-weight: 600; }

button.link {
  font: inherit;
  color: var(--fg);
  background: none;
  border: 0;
  padding: 2px 0;
  min-height: 24px;
  text-decoration: underline;
  text-decoration-color: var(--off);
  text-underline-offset: 3px;
  cursor: pointer;
  border-radius: 4px;
}
button.link:hover { text-decoration-color: var(--fg); }
button.link:disabled { color: var(--off); cursor: not-allowed; }
button.link[aria-pressed="true"] { color: var(--warn); text-decoration-color: var(--warn); font-weight: 700; }

.swatch { width: 20px; height: 0; border-top: 5px solid var(--line); border-radius: 3px; box-shadow: 0 0 0 1px #000; flex: none; }
.sub { display: block; color: var(--fg-2); font-weight: 400; }

.legend-st3 { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.legend-st3 li { display: flex; align-items: flex-start; gap: 8px; }
.legend-st3 .mk, .legend-st3 .swatch { margin-top: 4px; }
.mk { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.mk.st3 { background: #ffffff; border: 3px solid var(--line); }
.st3-note { margin: 10px 0 0; color: var(--fg-2); }
/* Disclaimers: small, muted, next to what they describe. #a8b1bb is 8.0:1. */
.note { margin: 4px 0 0; font-size: 12px; line-height: 1.35; color: #a8b1bb; font-weight: 400; }

.rt-num {
  display: inline-block;
  min-width: 34px;
  padding: 0 6px;
  border-radius: 5px;
  background: #ffe066;
  color: #0f1318; /* 13.9:1 on the yellow, 6.9:1 on the BRT pink */
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
}
.rt-num.rapid { background: #ff6b81; }

/* ---- Station card ---------------------------------------------------- */

.card {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 400px;
  max-height: calc(100% - 60px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--panel-solid);
  color: var(--fg);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.6);
  z-index: 5;
}
.card[hidden] { display: none; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 10px 8px 14px; border-bottom: 1px solid var(--rule); }
.card-head h2 { margin: 0; font-size: 17px; }
.card-head .close { display: block; }
.card-body { overflow: auto; padding: 8px 14px 14px; }
.sc-lines { display: flex; gap: 6px; margin: 2px 0 8px; }
.sc-st3 { margin: 2px 0 4px; font-weight: 600; }
.sc-future { display: inline-block; margin-right: 4px; padding: 0 7px; border: 1px dashed var(--fg-2); border-radius: 999px; color: var(--fg-2); font-weight: 600; }
.sc-h { margin: 6px 0 4px; font-size: 14px; }
.sc-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-variant-numeric: tabular-nums; }
.sc-table caption { text-align: left; font-weight: 700; padding: 4px 0; color: var(--fg); }
.sc-table th { text-align: left; color: var(--fg-2); font-weight: 600; padding: 2px 6px 4px 0; border-bottom: 1px solid var(--rule); }
.sc-table td { padding: 5px 6px 5px 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
.sc-table .num { text-align: right; padding-right: 0; }
.sc-table tr[data-route] { cursor: default; }
.sc-table tr[data-route]:hover, .sc-table tr[data-route]:focus-visible { background: rgba(255, 255, 255, 0.1); outline: none; }
.sc-name { min-width: 0; overflow-wrap: anywhere; }
.sc-stop { display: block; color: var(--fg-2); font-size: 13px; }
.brt-tag { font-weight: 700; color: #ff9eae; }
.sc-foot { margin: 10px 0 0; font-size: 13px; }

/* ---- How this works ---------------------------------------------------- */

.methods-link { margin: 12px 0 0; }
button.link.small-link { font-size: 12px; color: #a8b1bb; min-height: 20px; }
.card.methods { left: calc(var(--left-w) + 24px); right: auto; width: min(640px, calc(100% - var(--left-w) - 36px)); z-index: 7; }
.methods-body { font-size: 14px; }
.methods-body h1 { font-size: 18px; margin: 10px 0 6px; }
.methods-body h2 { font-size: 15px; margin: 14px 0 4px; }
.methods-body h3 { font-size: 14px; margin: 12px 0 4px; }
.methods-body ul, .methods-body ol { padding-left: 20px; }
.methods-body li { margin: 3px 0; }
.methods-body a { color: #9ad8ff; overflow-wrap: anywhere; }
.methods-body code { font-size: 13px; background: rgba(255, 255, 255, 0.08); padding: 0 3px; border-radius: 3px; }
.methods-body table { border-collapse: collapse; font-size: 13px; }
.methods-body th, .methods-body td { border-bottom: 1px solid var(--rule); padding: 3px 6px; text-align: left; vertical-align: top; }
.methods-body hr { border: 0; border-top: 1px solid var(--rule); margin: 16px 0; }

/* ---- Bus reach box ----------------------------------------------------- */

.reach-box {
  position: absolute;
  left: 12px;
  bottom: 40px;
  width: 340px;
  padding: 10px 12px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--panel-bg);
  color: var(--fg);
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.45);
  z-index: 2;
}
.reach-box[hidden] { display: none; }
.rb-title { margin: 0 0 6px; font-weight: 700; }
.rb-picker { display: flex; gap: 6px; }
.rb-picker label { flex: 1; min-width: 0; }
.rb-picker label:first-child { flex: 0 0 112px; }
.rb-picker select {
  width: 100%;
  min-height: 32px;
  padding: 4px 6px;
  border: 1px solid var(--off);
  border-radius: 6px;
  background: var(--panel-solid);
  color: var(--fg);
  font: inherit;
}
.rb-summary { margin: 8px 0 0; min-height: 20px; }
.rb-legend { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 12px; margin: 8px 0 0; padding: 0; color: var(--fg-2); font-size: 13px; font-weight: 600; }
.rb-legend li { display: flex; align-items: center; gap: 5px; }
.sw { width: 18px; height: 4px; border-radius: 2px; box-shadow: 0 0 0 1px #fff; flex: none; }
.sw.area { height: 10px; border-radius: 2px; box-shadow: none; }
.sw.dashed { background: repeating-linear-gradient(90deg, var(--fg-2) 0 5px, transparent 5px 9px); box-shadow: none; }

/* Leave room for the reach box under the layer panel. */
@media (min-width: 960px) {
  .panel-left { max-height: calc(100% - 300px); }
}

@media (max-width: 959px) {
  .card { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 40%; z-index: 6; }
  .card.methods { top: 60px; left: 8px; right: 8px; width: auto; max-height: none; z-index: 7; }
  /* Below the status and pinned chips. */
  .reach-box { left: 16px; right: 16px; bottom: auto; top: 136px; width: auto; padding: 8px 10px; }
  .rb-legend { gap: 2px 10px; font-size: 12px; }
  .rb-title { display: none; }
  .rb-summary { margin-top: 6px; }
  .rb-legend { margin-top: 6px; }
}
