:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --ink: #17181c;
  --muted: #62666f;
  --line: #e3e1d9;
  --accent: #6d28d9;
  --late: #b45309;
  --cancel: #b91c1c;
  --ok: #15803d;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131418; --surface: #1c1d23; --ink: #f1f1f4; --muted: #9a9ea8; --line: #2c2e36;
    --accent: #a78bfa; --late: #fbbf24; --cancel: #f87171; --ok: #4ade80;
  }
}
* { box-sizing: border-box; }
html { font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--ink); }
body { margin: 0; min-height: 100vh; display: flex; flex-direction: column; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
a { color: var(--accent); }

.top { max-width: 760px; width: 100%; margin: 0 auto; padding: 20px 20px 0; }
.brand { font-weight: 800; font-size: 1.15rem; letter-spacing: -.02em; color: var(--ink); text-decoration: none; }
.brand span { color: var(--accent); }

.banner { max-width: 720px; margin: 16px auto 0; width: calc(100% - 40px); background: color-mix(in srgb, var(--late) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--late) 40%, var(--line)); padding: 10px 14px; border-radius: var(--radius); font-size: .9rem; }
.banner[hidden] { display: none; }
code { background: var(--line); padding: 1px 5px; border-radius: 4px; font-size: .9em; }

main { flex: 1; max-width: 760px; width: 100%; margin: 0 auto; padding: 28px 20px 40px; }
h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); line-height: 1.15; letter-spacing: -.02em; margin: 0 0 6px; }
.lead { color: var(--muted); margin: 0 0 20px; }
.muted { color: var(--muted); font-size: .9rem; margin: 0; }
[hidden] { display: none !important; }

.search input {
  width: 100%; font: inherit; font-size: 1.1rem; padding: 14px 16px;
  border: 2px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink);
}
.search input:focus { outline: none; border-color: var(--accent); }

.results { list-style: none; margin: 10px 0 0; padding: 0; border-radius: var(--radius); overflow: hidden; }
.results:empty { display: none; }
.results li a {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
  color: var(--ink); text-decoration: none;
}
.results li:last-child a { border-bottom: 0; }
.results li a:hover, .results li a:focus-visible { background: color-mix(in srgb, var(--accent) 10%, var(--surface)); outline: none; }
.chips { display: flex; gap: 6px; flex-shrink: 0; }
.chip { font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--line); color: var(--muted); }

.msg { color: var(--muted); margin: 14px 2px 0; min-height: 1.5em; }
.msg.error { color: var(--cancel); }

.back { display: inline-block; margin-bottom: 14px; text-decoration: none; font-size: .95rem; }
.board-head { margin-bottom: 14px; }

.alerts { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 8px; }
.alerts:empty { display: none; }
.alerts li { background: color-mix(in srgb, var(--late) 14%, var(--surface)); border-left: 4px solid var(--late); padding: 10px 12px; border-radius: 6px; font-size: .92rem; }
.alerts strong { display: block; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.filters button {
  font: inherit; font-size: .88rem; padding: 6px 14px; border-radius: 99px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.filters button[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }

.board { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.board th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); }
.board td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.board tr:last-child td { border-bottom: 0; }
.num { text-align: right; white-space: nowrap; }
.line { display: inline-block; min-width: 3.2em; text-align: center; font-weight: 800; font-size: .9rem; padding: 3px 8px; border-radius: 6px; color: #fff; background: #52525b; }
.line.TRAIN { background: #1d4ed8; }
.line.METRO { background: #0f766e; }
.line.BUS { background: #b91c1c; }
.line.TRAM { background: #7c3aed; }
.line.BOAT { background: #0369a1; }
.dest { font-weight: 600; }
.sub { display: block; font-size: .8rem; color: var(--muted); font-weight: 400; }
.when { font-weight: 800; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.when small { display: block; font-weight: 500; font-size: .78rem; color: var(--muted); }
.late { color: var(--late); }
.canceled td { color: var(--muted); }
.canceled .dest, .canceled .when span { text-decoration: line-through; }
.tag-cancel { color: var(--cancel); font-weight: 800; }
.live { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); margin-right: 5px; vertical-align: middle; }
.plat-changed { color: var(--late); font-weight: 800; }

footer { padding: 20px; text-align: center; font-size: .82rem; color: var(--muted); border-top: 1px solid var(--line); }
footer p { margin: 0; }
.footnav { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 20px; margin: 0 0 10px; font-size: .9rem; }
.footnav a { color: var(--muted); text-decoration: none; }
.footnav a:hover { color: var(--accent); text-decoration: underline; }

@media (max-width: 520px) {
  .board th:nth-child(3), .board td:nth-child(3) { display: none; }
  .board td { padding: 10px 8px; }
}

.more { display: block; width: 100%; margin-top: 12px; font: inherit; padding: 12px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); color: var(--accent); font-weight: 700; cursor: pointer; }
.more:hover { background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }

h2 { font-size: 1.1rem; margin: 28px 0 8px; letter-spacing: -.01em; }
.intro { color: var(--muted); max-width: 62ch; margin: 22px 0 0; }
.linklist { list-style: none; margin: 0 0 8px; padding: 0; columns: 2 230px; column-gap: 28px; }
.linklist li { break-inside: avoid; padding: 4px 0; }
.linklist a { text-decoration: none; }
.linklist a:hover { text-decoration: underline; }

/* ---------- karta ---------- */
.mapbar { margin: 0 0 12px; }
.mapbtn { font: inherit; font-weight: 700; padding: 9px 18px; border-radius: 99px; cursor: pointer; border: 1px solid var(--accent); background: var(--surface); color: var(--accent); }
.mapbtn:hover { background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.mapbtn:disabled { opacity: .6; cursor: progress; }
.mappanel { margin: 0 0 16px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.map { height: 380px; position: relative; z-index: 0; background: #e5e3df; }
@media (max-width: 520px) { .map { height: 320px; } }
.mapinfo { padding: 12px 14px; font-size: .92rem; }
.mapinfo p { margin: 6px 0 0; }
.mapinfo .info-note { color: var(--late); }
.mapinfo .gps { color: var(--ok); font-weight: 600; }
.info-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.linkbtn { margin-left: auto; font: inherit; font-size: .88rem; color: var(--accent); background: none; border: 0; cursor: pointer; text-decoration: underline; padding: 0; }

/* mörkt läge: invertera kartrutorna så att kartan inte lyser */
@media (prefers-color-scheme: dark) {
  .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.88); }
  .map { background: #2b2b2e; }
  .leaflet-container .leaflet-control-attribution { background: rgba(28, 29, 35, .8); color: #9a9ea8; }
  .leaflet-container .leaflet-control-attribution a { color: #c4b5fd; }
}

/* markörer */
.leaflet-div-icon.stopicon, .stopicon { background: none; border: 0; }
.stopicon span { display: block; width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 6px solid #111827; box-shadow: 0 0 0 2px #fff, 0 1px 6px rgba(0,0,0,.5); box-sizing: border-box; }
.veh { background: none; border: 0; --c: #52525b; transition: transform 1s linear; }
.veh.TRAIN { --c: #1d4ed8; } .veh.METRO { --c: #0f766e; } .veh.BUS { --c: #b91c1c; } .veh.TRAM { --c: #7c3aed; } .veh.BOAT { --c: #0369a1; }
.zooming .veh { transition: none; }
.veh > div { position: relative; width: 36px; height: 36px; }
.veh-label { position: absolute; inset: 6px; display: flex; align-items: center; justify-content: center; border-radius: 50%; background: var(--c); color: #fff; font: 800 12px/1 system-ui, sans-serif; border: 2px solid #fff; box-shadow: 0 1px 5px rgba(0,0,0,.5); box-sizing: border-box; }
.veh-label.long { font-size: 10px; }
.veh-arrow { position: absolute; left: 50%; top: 0; width: 0; height: 0; margin-left: -6px; border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 10px solid var(--c); transform-origin: 50% 18px; }
.veh.selected .veh-label { box-shadow: 0 0 0 3px #facc15, 0 1px 6px rgba(0,0,0,.6); }
.veh.est .veh-label { background: #fff; color: var(--c); border: 2px dashed var(--c); }
.veh.est .veh-arrow { opacity: .6; }
@media (prefers-reduced-motion: reduce) { .veh { transition: none; } }

/* kartknapp i tavlan */
.rowmap { display: block; margin-top: 8px; font: inherit; font-size: .78rem; font-weight: 700; padding: 5px 12px; border-radius: 99px; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--muted); white-space: nowrap; }
.rowmap:hover { border-color: var(--accent); color: var(--accent); }
.rowmap.gps::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; background: var(--ok); vertical-align: middle; }
.rowmap.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.board tr.selected td { background: color-mix(in srgb, var(--accent) 9%, var(--surface)); }

/* ---------- huvudmeny ---------- */
.top { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 16px; }
.topnav { display: flex; gap: 18px; font-size: .95rem; }
.topnav a { color: var(--muted); text-decoration: none; }
.topnav a:hover { color: var(--accent); }

/* ---------- störningar ---------- */
.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.tabs button { font: inherit; font-size: .9rem; padding: 7px 14px; border-radius: 99px; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.tabs button[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.alert-filters { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 12px; }
.alert-filters select, .alert-filters input { font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); }
.alert-filters input { flex: 1 1 220px; min-width: 0; }
.alert-filters select:focus, .alert-filters input:focus { outline: none; border-color: var(--accent); }
.alert { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 0 0 10px; }
.alert h3 { margin: 8px 0 4px; font-size: 1.02rem; line-height: 1.3; }
.alert-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: .8rem; color: var(--muted); }
.alert .op { font-weight: 800; color: var(--ink); background: var(--line); border-radius: 99px; padding: 2px 10px; }
.alert .cause { font-weight: 700; border-radius: 99px; padding: 2px 10px; background: color-mix(in srgb, var(--late) 18%, var(--surface)); color: var(--late); }
.alert .cause.c6 { background: color-mix(in srgb, var(--cancel) 16%, var(--surface)); color: var(--cancel); }
.alert .times { font-weight: 800; }
.alert-text { margin: 0; white-space: pre-line; font-size: .93rem; overflow-wrap: anywhere; }
.alert-text.clamp { display: -webkit-box; -webkit-line-clamp: 4; line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.alert .linkbtn { margin: 6px 0 0; }
.empty { color: var(--muted); padding: 18px 2px; }
.alert-foot { margin-top: 24px; font-size: .85rem; }

/* ---------- störningar på hållplatssidan ---------- */
.stop-alerts { margin: 0 0 16px; }
.stop-alerts h2 { margin: 0 0 10px; font-size: 1.05rem; }
.stop-alerts .more { margin-top: 0; }
.alert-note { margin: 6px 0 0; font-size: .85rem; font-weight: 700; color: var(--accent); }

/* ---------- brödsmulor, fakta, register ---------- */
.crumbs { margin: 0 0 16px; font-size: .88rem; }
.crumbs ol { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 2px 8px; }
.crumbs li + li::before { content: "›"; margin-right: 8px; color: var(--muted); }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent); text-decoration: underline; }
.crumbs [aria-current] { color: var(--ink); overflow-wrap: anywhere; }

.place { margin: -2px 0 6px; color: var(--muted); font-size: 1rem; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 20px; margin: 0 0 8px; font-size: .95rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.linklist.near .muted { white-space: nowrap; }

.browse { margin: 22px 0 0; }
.plain { margin: 0 0 8px; padding-left: 1.2em; }
.plain li { margin: 0 0 8px; }
#content-view h1 { margin-bottom: 8px; }
#content-view p { max-width: 62ch; }

.alpha { list-style: none; margin: 0 0 20px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.alpha a { display: inline-flex; align-items: baseline; gap: 6px; padding: 7px 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 800; text-decoration: none; }
.alpha a small { font-weight: 500; font-size: .72rem; color: var(--muted); }
.alpha a:hover { border-color: var(--accent); color: var(--accent); }
.alpha a[aria-current="page"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.alpha a[aria-current="page"] small { color: inherit; opacity: .85; }

.ranges { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 10px; }
.ranges li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 8px; }
.ranges strong { min-width: 1.7em; }
.ranges a { padding: 4px 12px; border: 1px solid var(--line); border-radius: 99px; background: var(--surface); color: var(--ink); font-size: .88rem; text-decoration: none; }
.ranges a:hover { border-color: var(--accent); color: var(--accent); }

.alert-about { margin-top: 32px; }
.alert-about h2 { margin-top: 0; }
.alert-about p { max-width: 62ch; }
