:root {
  --tmb: #da291c;
  --amb: #f2a900;
  --both: #7b3fa0;
  --live: #0a8f3c;
  --muted: #6b7280;
  --border: #e5e7eb;
  --bg: #ffffff;
  --panel-w: 400px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: #111827;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #f3f4f6; overflow: hidden; }
#map { position: absolute; inset: 0; }
.hidden { display: none !important; }

.card {
  position: absolute; z-index: 1000; background: var(--bg);
  border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,.2);
}

/* --- search ------------------------------------------------------------ */
#search { top: 12px; left: 56px; width: 340px; max-width: calc(100vw - 72px); }
#search-input {
  width: 100%; border: 0; border-bottom: 1px solid var(--border); padding: 12px;
  font-size: 15px; border-radius: 8px 8px 0 0; outline: none;
}
.search-filters { display: flex; gap: 6px; padding: 6px 8px; }
.search-filters button {
  border: 1px solid var(--border); background: #fff; border-radius: 14px;
  padding: 3px 10px; cursor: pointer; font-size: 12px;
}
.search-filters button.active { background: #111827; color: #fff; border-color: #111827; }
#search-results { list-style: none; margin: 0; padding: 0; max-height: 55vh; overflow-y: auto; }
#search-results:empty { display: none; }
#search-results li {
  padding: 8px 12px; border-top: 1px solid var(--border); cursor: pointer;
  display: flex; gap: 8px; align-items: center;
}
#search-results li:hover, #search-results li.focus { background: #f3f4f6; }
#search-results li.section {
  cursor: default; background: #f9fafb; font-size: 11px; text-transform: uppercase;
  color: var(--muted); letter-spacing: .04em; padding: 4px 12px;
}
.result-main { flex: 1; min-width: 0; }
.result-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- line badges ------------------------------------------------------- */
.badge {
  display: inline-block; min-width: 34px; text-align: center; font-weight: 700;
  border-radius: 4px; padding: 2px 5px; font-size: 12px; line-height: 16px;
}
.badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; border: 1px solid #fff; box-shadow: 0 0 0 1px #0003; }
.dot.tmb { background: var(--tmb); } .dot.amb { background: var(--amb); } .dot.multi { background: var(--both); }
.dot.gen { background: #00838f; } .dot.mat { background: #1e88e5; }

#legend { bottom: 24px; left: 12px; padding: 8px 10px; font-size: 12px; line-height: 20px; }
#data-info { color: var(--muted); font-size: 11px; margin-top: 4px; max-width: 220px; }

#line-chip {
  top: 12px; left: 408px; padding: 6px 8px 6px 10px; display: flex; align-items: center; gap: 8px;
}
#line-chip button { border: 0; background: none; cursor: pointer; font-size: 14px; color: var(--muted); }

/* --- side panel -------------------------------------------------------- */
#panel {
  position: absolute; top: 0; right: 0; bottom: 0; z-index: 1100;
  width: var(--panel-w); max-width: 100vw; background: var(--bg);
  box-shadow: -4px 0 16px rgba(0,0,0,.18);
  transform: translateX(105%); transition: transform .25s ease;
  display: flex; flex-direction: column;
}
#panel.open { transform: translateX(0); }
#panel-close {
  position: absolute; top: 10px; right: 10px; border: 0; background: #f3f4f6;
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer; font-size: 14px; z-index: 2;
}
#panel-body { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.panel-head { padding: 16px 48px 12px 16px; border-bottom: 1px solid var(--border); }
.panel-head h2 { margin: 0; font-size: 18px; }
.panel-head .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.tabs { display: flex; border-bottom: 1px solid var(--border); }
.tabs button {
  flex: 1; padding: 10px; border: 0; background: none; cursor: pointer; font-size: 14px;
  border-bottom: 3px solid transparent; color: var(--muted);
}
.tabs button.active { color: #111827; border-bottom-color: #111827; font-weight: 600; }
.tab-content { flex: 1; overflow-y: auto; padding: 8px 0; min-height: 0; }
.note { color: var(--muted); font-size: 12px; padding: 6px 16px; }
.note.warn { color: #92400e; background: #fffbeb; margin: 4px 12px; border-radius: 6px; padding: 6px 8px; }
.legend-row { display: flex; gap: 14px; padding: 4px 16px 8px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }

/* --- arrivals ---------------------------------------------------------- */
.arr-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 16px; border-bottom: 1px solid var(--border);
}
.arr-dest { flex: 1; min-width: 0; }
.arr-dest .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.arr-dest .src { color: var(--muted); font-size: 11px; }
.arr-times { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; max-width: 55%; }
.eta { border-radius: 6px; padding: 3px 7px; font-size: 13px; white-space: nowrap; }
/* GPS-tracked: big live countdown */
.eta.live { background: #ecfdf5; color: var(--live); font-weight: 700; }
.eta.live::before {
  content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--live); margin-right: 5px; vertical-align: middle; animation: pulse 1.4s infinite;
}
.eta .late { font-weight: 400; font-size: 11px; color: #b45309; margin-left: 3px; }
/* Timetable only: clock time, muted */
.eta.sched { background: #f3f4f6; color: #374151; font-style: italic; }
.eta.sched::before { content: "🕒 "; font-style: normal; font-size: 11px; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }

/* --- schedule ---------------------------------------------------------- */
.sched-controls { display: flex; gap: 8px; align-items: center; padding: 4px 16px 8px; }
.sched-controls input { padding: 4px 6px; border: 1px solid var(--border); border-radius: 6px; }
details.sched-line { border-bottom: 1px solid var(--border); }
details.sched-line summary {
  list-style: none; cursor: pointer; padding: 8px 16px; display: flex; gap: 10px; align-items: center;
}
details.sched-line summary::-webkit-details-marker { display: none; }
details.sched-line summary .count { margin-left: auto; color: var(--muted); font-size: 12px; }
table.hours { border-collapse: collapse; margin: 0 16px 10px; font-variant-numeric: tabular-nums; }
table.hours th { text-align: right; padding: 2px 8px 2px 0; color: var(--muted); font-weight: 600; vertical-align: top; }
table.hours td { padding: 2px 0; word-spacing: 6px; }
table.hours tr.past { opacity: .4; }

/* --- line panel -------------------------------------------------------- */
.dir-select { display: flex; gap: 6px; padding: 8px 16px; flex-wrap: wrap; }
.dir-select button {
  border: 1px solid var(--border); background: #fff; border-radius: 14px; padding: 4px 10px; cursor: pointer;
}
.dir-select button.active { background: #111827; color: #fff; }
ol.line-stops { list-style: none; margin: 0; padding: 0 16px 16px; }
ol.line-stops li { position: relative; padding: 6px 0 6px 22px; cursor: pointer; }
ol.line-stops li:hover { background: #f9fafb; }
ol.line-stops li::before {
  content: ""; position: absolute; left: 4px; top: 11px; width: 8px; height: 8px;
  border-radius: 50%; background: #fff; border: 2px solid var(--c, #333);
}
ol.line-stops li::after {
  content: ""; position: absolute; left: 9px; top: 0; bottom: 0; width: 2px; background: var(--c, #333); z-index: -1;
}
ol.line-stops li .code { color: var(--muted); font-size: 11px; margin-left: 4px; }

.spinner { padding: 20px 16px; color: var(--muted); }

@media (max-width: 760px) {
  #line-chip { top: auto; bottom: 24px; left: auto; right: 12px; }
  #legend { display: none; }
  #search { left: 12px; top: 64px; width: calc(100vw - 24px); max-width: none; }
}
