:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #f7f8fa;
  --line: #e4e7ec;
  --text: #161a1f;
  --muted: #667085;
  --accent: #f5c400;
  --accent-ink: #161a1f;
  --ok: #12a150;
  --warn: #d98a00;
  --bad: #e5484d;
  --early: #2f7fd8;
  --none: #98a2b3;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .08);
  --mono: "JetBrains Mono", ui-monospace, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1116; --panel: #161a21; --panel-2: #1c212a; --line: #2a303b; --text: #e8ebf0;
    --muted: #8b95a5; --ok: #2fbf71; --warn: #f0a92a; --bad: #ff6b6f; --early: #5aa2f0; --none: #5d6675;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1116; --panel: #161a21; --panel-2: #1c212a; --line: #2a303b; --text: #e8ebf0;
  --muted: #8b95a5; --ok: #2fbf71; --warn: #f0a92a; --bad: #ff6b6f; --early: #5aa2f0; --none: #5d6675;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }

.app { display: grid; grid-template-columns: 400px minmax(0, 1fr); height: 100dvh; }
.map { height: 100%; background: var(--bg); }
.panel {
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
  background: var(--panel); border-right: 1px solid var(--line); z-index: 500;
}

.top { padding: 14px 16px 0; border-bottom: 1px solid var(--line); }
.brand { display: flex; gap: 12px; align-items: center; }
.logo {
  width: 36px; height: 36px; border-radius: 10px; flex: none; background: var(--accent);
  box-shadow: inset 0 -10px 0 rgba(0,0,0,.08);
  position: relative;
}
.logo::before { content: ""; position: absolute; inset: 8px 7px 15px; border-radius: 3px; background: var(--accent-ink); }
.logo::after {
  content: ""; position: absolute; left: 8px; right: 8px; bottom: 7px; height: 4px;
  background: radial-gradient(circle at 2px 2px, var(--accent-ink) 2px, transparent 2.5px) left / 4px 4px no-repeat,
              radial-gradient(circle at 2px 2px, var(--accent-ink) 2px, transparent 2.5px) right / 4px 4px no-repeat;
}
h1 { font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
h1 span { color: var(--muted); font-weight: 500; }
.status { margin: 1px 0 0; font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.status .dot.err { background: var(--bad); }

.tabs { display: flex; gap: 4px; margin-top: 12px; }
.tabs button {
  flex: 1; border: 0; background: none; padding: 9px 0 11px; cursor: pointer; color: var(--muted);
  font-weight: 600; border-bottom: 2px solid transparent;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }

.view { flex: 1; overflow-y: auto; padding: 12px 16px 24px; }

.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 12px; }
.tile { background: var(--panel-2); border-radius: 10px; padding: 8px 10px; }
.tile b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.tile span { font-size: 11.5px; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 3px 10px;
  cursor: pointer; font-size: 12.5px; font-weight: 600;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.list { display: flex; flex-direction: column; gap: 6px; }
.row {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; width: 100%;
  text-align: left; border: 1px solid var(--line); background: var(--panel); border-radius: 12px;
  padding: 10px 12px; cursor: pointer;
}
.row:hover { border-color: var(--muted); }
.row.dim { opacity: .55; }
.row .main { min-width: 0; }
.row .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.badge {
  display: inline-grid; place-items: center; min-width: 34px; height: 28px; padding: 0 7px; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink); font: 700 14px var(--mono);
}
.badge.sm { min-width: 26px; height: 22px; font-size: 12px; border-radius: 6px; }

.delay { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.delay small { display: block; font-weight: 500; font-size: 11.5px; color: var(--muted); }
.c-ok { color: var(--ok); } .c-warn { color: var(--warn); } .c-bad { color: var(--bad); }
.c-early { color: var(--early); } .c-none { color: var(--muted); }

.back {
  display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; padding: 4px 0;
  color: var(--muted); cursor: pointer; font-weight: 600; margin-bottom: 8px;
}
.back:hover { color: var(--text); }
.detail-head { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.detail-head h2 { font-size: 16px; line-height: 1.3; }
.detail-head p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.big-delay { border-radius: 12px; padding: 12px 14px; background: var(--panel-2); margin-bottom: 12px; }
.big-delay b { font-size: 22px; display: block; }
.big-delay span { color: var(--muted); font-size: 12.5px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin-bottom: 16px; }
.grid div span { display: block; font-size: 11.5px; color: var(--muted); }
.grid div b { font-weight: 600; font-variant-numeric: tabular-nums; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 16px 0 8px; }

.stops { list-style: none; margin: 0; padding: 0; position: relative; }
.stops li {
  display: grid; grid-template-columns: 14px 1fr auto; gap: 10px; align-items: center; padding: 5px 0;
  position: relative; cursor: pointer;
}
.stops li::before {
  content: ""; position: absolute; left: 6px; top: 0; bottom: 0; width: 2px; background: var(--line);
}
.stops li:first-child::before { top: 50%; } .stops li:last-child::before { bottom: 50%; }
.stops .pin { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--muted); background: var(--panel); z-index: 1; margin-left: 2px; }
.stops li.passed { color: var(--muted); }
.stops li.passed .pin { background: var(--line); border-color: var(--line); }
.stops li.next .pin { border-color: var(--accent); background: var(--accent); }
.stops li.next { font-weight: 600; }
.stops .eta { font-variant-numeric: tabular-nums; font-size: 12.5px; text-align: right; }
.stops .eta small { color: var(--muted); margin-left: 6px; }

.deps { display: flex; flex-wrap: wrap; gap: 4px; }
.dep {
  font: 500 12.5px var(--mono); padding: 3px 7px; border-radius: 6px; background: var(--panel-2);
  border: 1px solid transparent;
}
.dep.past { color: var(--muted); opacity: .6; }
.dep.next { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, transparent); font-weight: 700; }
.dep sup { color: var(--muted); font-size: 10px; margin-left: 1px; }
.notes { margin: 6px 0 0; padding: 0; list-style: none; font-size: 12px; color: var(--muted); }
.dirblock { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; }
.dirblock h4 { margin: 0 0 8px; font-size: 13.5px; display: flex; gap: 8px; align-items: center; }
.dirtag { font: 700 11px var(--mono); color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; }

table { width: 100%; border-collapse: collapse; font-size: 12.5px; font-variant-numeric: tabular-nums; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 11.5px; padding: 6px 4px; border-bottom: 1px solid var(--line); }
td { padding: 7px 4px; border-bottom: 1px solid var(--line); }
td.r, th.r { text-align: right; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar input {
  font: inherit; color: inherit; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px;
}
.empty { color: var(--muted); text-align: center; padding: 28px 8px; }
.foot { color: var(--muted); font-size: 11.5px; margin-top: 18px; }
.foot a { color: inherit; }

/* Map markers */
.busmk { position: relative; }
.busmk .pill {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  min-width: 30px; height: 24px; padding: 0 6px; border-radius: 8px; display: grid; place-items: center;
  font: 700 12.5px var(--mono); color: #fff; background: var(--none); border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.35); white-space: nowrap;
}
.busmk .arrow {
  position: absolute; left: 50%; top: 50%; width: 0; height: 0; margin: -27px 0 0 -6px;
  border: 6px solid transparent; border-bottom: 8px solid #fff; transform-origin: 6px 27px;
  filter: drop-shadow(0 0 1px rgba(0,0,0,.6));
}
.busmk.sel .pill { outline: 3px solid var(--accent); outline-offset: 1px; }
.busmk.stale .pill { opacity: .55; }
.bg-ok { background: var(--ok) !important; } .bg-warn { background: var(--warn) !important; }
.bg-bad { background: var(--bad) !important; } .bg-early { background: var(--early) !important; }
.bg-none { background: var(--none) !important; }

.leaflet-container { font: inherit; background: var(--bg); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.9) saturate(.6); }
}
:root[data-theme="dark"] .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.9) saturate(.6); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--text); }
.leaflet-control-attribution { font-size: 10px; }
.legend {
  background: var(--panel); color: var(--text); padding: 8px 10px; border-radius: 10px; box-shadow: var(--shadow);
  font-size: 11.5px; line-height: 1.7;
}
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: 42dvh minmax(0, 1fr); }
  .map { grid-row: 1; }
  .panel { grid-row: 2; border-right: 0; border-top: 1px solid var(--line); box-shadow: var(--shadow); }
  .top { padding: 10px 16px 0; }
  .brand .logo { width: 30px; height: 30px; }
  .summary { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .tile { padding: 7px 8px; }
  .tile span { font-size: 11px; }
  .legend { display: none; }
}
