:root {
  --bg: #ffffff;
  --panel: #f6f7f9;
  --ink: #1b1f24;
  --muted: #5b6672;
  --line: #d9dee4;
  --accent: #0b5fff;
  --accent-ink: #ffffff;
  --dir0: #0b5fff;
  --dir1: #e8590c;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14181d;
    --panel: #1c2128;
    --ink: #e6e9ed;
    --muted: #9aa5b1;
    --line: #2f3741;
    --accent: #6ea0ff;
    --accent-ink: #0b1220;
    --dir0: #6ea0ff;
    --dir1: #ff9a5c;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", sans-serif;
}
a { color: var(--accent); }
.sub { color: var(--muted); font-size: 12px; font-weight: 400; }

/* ---- Map page */
html:has(body.map-page), body.map-page { height: 100%; }
body.map-page { display: flex; }
aside {
  width: 360px;
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
  min-height: 0;
}
header { padding: 12px 16px 8px; }
.app-title { font-size: 17px; font-weight: 700; margin: 0 0 2px; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
.crumbs { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.crumbs a { color: inherit; }
.links { display: flex; flex-wrap: wrap; gap: 4px 12px; margin: 0 0 8px; font-size: 12px; }
.bus-types { list-style: none; margin: 0 0 8px; padding: 0; font-size: 12px; color: var(--muted); }
.bus-types li { display: grid; grid-template-columns: 14px 1fr; gap: 6px; padding: 3px 0; }
.bus-types strong { color: var(--ink); font-weight: 600; }
.bus-types .swatch { margin-top: 3px; border: 1px solid #3a3833; }
/* Bus colors as in the BMTA data; same values as the bus icons on the line cards */
.bus-orange { background: #f4a340; }
.bus-cream-red { background: linear-gradient(#f3ebdb 55%, #b42318 55%); }
.bus-blue { background: #2f6fb3; }
.bus-light-blue { background: #8cc4ea; }
.bus-cream-blue { background: linear-gradient(#f3ebdb 55%, #2f6fb3 55%); }
.bus-unknown { background: #d4d1c8; }
#panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.filters { padding: 0 16px 10px; display: grid; gap: 6px; border-bottom: 1px solid var(--line); }
.filters .row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
input[type=search], select {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
}
label.chk { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 12px; }
#results { overflow: auto; flex: 1; min-height: 0; }
.item {
  display: grid;
  grid-template-columns: max(54px, var(--badge-col, 54px)) 1fr;
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  color: inherit;
  text-decoration: none;
  align-items: center;
}
.item:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.item:focus-visible, button:focus-visible, .tab:focus-visible, .back:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.item small { display: block; color: var(--muted); font-size: 12px; }
.empty { padding: 16px; color: var(--muted); }
.badge {
  display: inline-block;
  min-width: 44px;
  padding: 3px 6px;
  border-radius: 6px;
  color: #fff;
  text-align: center;
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
}
#detail { overflow: auto; flex: 1; min-height: 0; padding: 12px 16px; }
#detail h1 { font-size: 16px; margin: 10px 0 2px; }
#detail h3 { font-size: 14px; margin: 10px 0 0; }
.back {
  display: inline-block;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  border-radius: 6px;
  padding: 5px 10px;
  text-decoration: none;
}
.meta { color: var(--muted); font-size: 12px; margin: 4px 0 10px; }
.tabs { display: flex; gap: 6px; margin: 8px 0; flex-wrap: wrap; }
.tab {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  text-decoration: none;
}
.tab[aria-current=true] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }
.swatch.dir0 { background: var(--dir0); }
.swatch.dir1 { background: var(--dir1); }
ol.stops { margin: 6px 0 14px; padding: 0; list-style: none; }
ol.stops li button {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 6px;
  width: 100%;
  padding: 4px 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  font: inherit;
  cursor: pointer;
}
ol.stops li button:hover { color: var(--accent); }
ol.stops .n { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
ol.stops .alt { color: var(--muted); font-size: 12px; display: block; }
footer { padding: 8px 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; line-height: 1.5; }
footer summary { cursor: pointer; }
footer dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 8px 0 2px; }
footer dt { font-weight: 600; }
footer dd { margin: 0; }
#map { flex: 1; min-width: 0; }
/* MapLibre popups: stop details, and the line name under the pointer */
.maplibregl-popup-content { font: 13px/1.4 system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", sans-serif; color: #1b1f24; }
.line-tip .maplibregl-popup-content { padding: 4px 8px; font-size: 12px; }
.line-tip .maplibregl-popup-tip { display: none; }
.popup-lines a {
  display: inline-block;
  margin: 2px 2px 0 0; padding: 1px 7px; border: 1px solid #c8ced6;
  border-radius: 999px; background: #f4f6f8; color: #1b1f24; font-size: 12px; text-decoration: none;
}
@media (max-width: 800px) {
  body.map-page { flex-direction: column-reverse; }
  aside { width: 100%; height: 48vh; border-right: 0; border-top: 1px solid var(--line); }
  #map { height: 52vh; flex: none; }
  /* The sidebar has half the screen: keep the sources line slim, and scroll it when opened */
  footer { padding: 4px 16px; font-size: 11px; line-height: 1.4; }
  footer details[open] { max-height: 30vh; overflow: auto; }
  footer dl { gap: 4px 10px; margin: 4px 0 2px; }
}

/* ---- Report */
.doc { max-width: 980px; margin: 0 auto; padding: 16px; }
.doc h1 { font-size: 22px; margin: 8px 0; }
.doc h2 { font-size: 17px; margin: 28px 0 6px; }
.doc ul.cols { columns: 2 320px; padding-left: 18px; }
.doc table { border-collapse: collapse; width: 100%; font-size: 13px; }
.doc th, .doc td { border-bottom: 1px solid var(--line); padding: 4px 8px; text-align: left; }
.doc .num { text-align: right; font-variant-numeric: tabular-nums; }
.doc code { font-size: 12px; }
.doc h3 { font-size: 15px; margin: 20px 0 2px; }
.doc ul.to-check li { margin-bottom: 6px; }
.doc details { margin-top: 16px; }
