/* Carto Saigon — design language per R-DS1…R-DS9: rounded type (Nunito subset,
   ui-rounded first on Apple), capsule badges with coloured shadow, floating
   cards with concentric radii, 44 px touch targets, AA contrast, focus rings. */

@font-face {
  font-family: "Nunito";
  src: url("/fonts/nunito-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Nunito";
  src: url("/fonts/nunito-700.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

:root {
  --font: "Nunito", ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  --bg: #f6f7f9;
  --panel-bg: rgba(255, 255, 255, 0.92);
  --card-bg: #ffffff;
  --text: #1c1e21;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #2563eb;
  --radius: 18px;
  --shadow: 0 8px 28px rgba(16, 24, 40, 0.14);
  --tabular: "tnum" 1;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel-bg: rgba(22, 26, 34, 0.92);
    --card-bg: #1a1e27;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --line: #2a2f3a;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
  }
}
html.theme-dark {
  --bg: #0f1115; --panel-bg: rgba(22, 26, 34, 0.92); --card-bg: #1a1e27;
  --text: #e8eaee; --muted: #9aa1ad; --line: #2a2f3a; --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
}
html.theme-light {
  --bg: #f6f7f9; --panel-bg: rgba(255, 255, 255, 0.92); --card-bg: #ffffff;
  --text: #1c1e21; --muted: #6b7280; --line: #e5e7eb; --shadow: 0 8px 28px rgba(16, 24, 40, 0.14);
}

* { box-sizing: border-box; }
html, body, #app { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
#map { position: absolute; inset: 0; }
#map .dark-raster canvas { filter: invert(1) hue-rotate(180deg) saturate(0.7) brightness(0.95); }
.nogl { display: grid; place-items: center; height: 100%; font-size: 18px; }

/* ---- stats bar ---- */
#statsbar {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 5;
  background: var(--panel-bg); backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: 999px;
  box-shadow: var(--shadow); padding: 6px 14px;
  width: max-content; max-width: min(96vw, 900px); /* dynamic width: grows with content, caps at viewport */
  overflow-x: auto; scrollbar-width: none;
}
.stats-inner { display: flex; gap: 14px; align-items: center; white-space: nowrap; justify-content: center; }
.stat { display: inline-flex; gap: 5px; align-items: baseline; font-variant-numeric: var(--tabular); }
.stat-v { font-weight: 700; font-size: 14px; }
.stat-k { font-size: 11px; color: var(--muted); }
.stat.state { padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.stat.state-live { background: #dcfce7; color: #166534; }
.stat.state-delayed { background: #fef3c7; color: #92400e; }
.stat.state-offline, .stat.state-staticOnly, .stat.state-serviceEnded { background: #fee2e2; color: #991b1b; }
@media (prefers-color-scheme: dark) {
  .stat.state-live { background: #14532d; color: #bbf7d0; }
  .stat.state-delayed { background: #78350f; color: #fde68a; }
  .stat.state-offline, .stat.state-staticOnly, .stat.state-serviceEnded { background: #7f1d1d; color: #fecaca; }
}

/* ---- panel ---- */
#panel { position: absolute; z-index: 10; top: 12px; left: 12px; bottom: 64px; width: min(360px, calc(100vw - 24px)); display: flex; }
.panel {
  display: flex; flex-direction: column; width: 100%;
  background: var(--panel-bg); backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden;
}
.panel.closed { width: 44px; }
.panel.closed .tabbar, .panel.closed .panel-content, .panel.closed .panel-title, .panel.closed .panel-sub { display: none; }
.panel-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px 4px; }
.panel-title { font-weight: 700; font-size: 17px; }
.panel-sub { font-size: 12px; color: var(--muted); flex: 1; }
.tabbar { display: flex; gap: 4px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1 1 0; text-align: center; /* tabs span the full column width, centered */
  border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 700;
  font-size: 13px; padding: 8px 6px; border-radius: 10px; cursor: pointer; min-height: 44px;
}
.tab[aria-selected="true"] { background: var(--card-bg); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,0.08); }
.panel-content { flex: 1; overflow-y: auto; padding: 10px 12px; }

/* ---- controls & list ---- */
.list-controls { display: flex; gap: 6px; margin-bottom: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--card-bg); color: var(--text);
  font: inherit; font-size: 12px; font-weight: 700; border-radius: 999px;
  padding: 8px 12px; min-height: 44px; cursor: pointer;
}
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.text-filter {
  width: 100%; font: inherit; font-size: 14px; padding: 10px 12px; min-height: 44px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card-bg); color: var(--text);
  margin-bottom: 8px;
}
.hidden-count { font-size: 12px; color: var(--muted); margin: 2px 2px 6px; }
.group-head { font-size: 12px; font-weight: 700; color: var(--muted); margin: 10px 2px 4px; text-transform: none; }
.line-list { display: flex; flex-direction: column; gap: 2px; }
.line-row {
  display: flex; align-items: center; gap: 8px; padding: 6px; border-radius: 12px;
  cursor: pointer; min-height: 44px; border: 0; background: transparent; width: 100%; text-align: left; font: inherit; color: var(--text);
}
.line-row:hover, .line-row:focus-visible { background: var(--bg); outline: none; }
.line-row.hidden-line .line-name, .line-row.hidden-line .badge { opacity: 0.4; }
.line-check { width: 20px; height: 20px; accent-color: var(--accent); }
.line-name { font-size: 13px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- badge (R-DS1) ---- */
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 6px 10px; border-radius: 999px;
  font-weight: 700; font-size: 14px; line-height: 1; font-variant-numeric: var(--tabular);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.001); /* colour shadow set inline via filter below */
  flex: none;
}
.badge { filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.0)); }
.badge-lg { font-size: 18px; padding: 8px 14px; }
.badge-strip { display: inline-flex; gap: 4px; flex-wrap: wrap; align-items: center; min-width: 0; }
.badge-strip .badge { font-size: 11px; padding: 4px 7px; }
.badge-more { font-size: 11px; font-weight: 700; color: var(--muted); padding: 4px 6px; }

/* ---- search ---- */
.search-results { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.search-row {
  display: grid; grid-template-columns: 1fr; gap: 2px; text-align: left;
  background: var(--card-bg); border: 1px solid var(--line); border-radius: 14px;
  padding: 10px; cursor: pointer; font: inherit; color: var(--text); min-height: 44px;
}
.search-row:hover, .search-row:focus-visible { border-color: var(--accent); outline: none; }
.search-top { display: flex; gap: 8px; align-items: baseline; }
.stop-name { font-weight: 700; font-size: 14px; }
.stop-code { font-size: 11px; color: var(--muted); font-variant-numeric: var(--tabular); }
.stop-addr { font-size: 12px; color: var(--muted); }

/* ---- cards ---- */
#card-root { position: absolute; z-index: 20; inset: 0; pointer-events: none; }
.card {
  pointer-events: auto; position: absolute;
  background: var(--card-bg); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); width: min(340px, calc(100vw - 24px));
  max-height: min(70vh, 560px); overflow-y: auto;
}
/* line card sits on the opposite side of the screen from the left panel so
   they never overlap; stop card pops up at the stop itself (map popup) */
.line-card { right: 12px; left: auto; bottom: 64px; }
.stop-card { left: 12px; bottom: 64px; }
.seg { display: flex; gap: 6px; }
.seg .chip { flex: 1 1 0; text-align: center; }
.stops-head { margin: 8px 2px 0; font-size: 13px; }
.line-stops { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.line-stops .stop-row { width: 100%; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-bottom: 12px; }
.stat-cell { background: var(--card-bg); border: 1px solid var(--line); border-radius: 14px; padding: 10px; }
.stat-cell .stat-v { font-size: 18px; display: block; }
.arrival-row.static { cursor: default; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px 6px; }
.card-titles { flex: 1; min-width: 0; }
.card-title { font-weight: 700; font-size: 15px; }
.card-sub { font-size: 12px; color: var(--muted); }
.card-body { padding: 6px 14px 14px; display: flex; flex-direction: column; gap: 8px; }
.kv { display: flex; gap: 8px; font-size: 13px; }
.kv .k { color: var(--muted); flex: none; min-width: 110px; }
.kv .v { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.btn {
  border: 0; background: var(--accent); color: #fff; font: inherit; font-weight: 700;
  border-radius: 12px; padding: 10px 14px; min-height: 44px; cursor: pointer;
}
.icon-btn {
  border: 0; background: transparent; color: var(--muted); font-size: 20px;
  width: 44px; height: 44px; border-radius: 12px; cursor: pointer; flex: none;
}
.icon-btn:hover { background: var(--bg); }
.direction { align-self: flex-start; }
.via summary { cursor: pointer; font-size: 13px; color: var(--accent); min-height: 44px; display: flex; align-items: center; }
.via-text { font-size: 12px; color: var(--muted); }
.live-summary { font-size: 12px; background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.arrival-row {
  display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; align-items: center;
  border: 1px solid var(--line); background: transparent; border-radius: 12px;
  padding: 8px; cursor: pointer; font: inherit; color: var(--text); text-align: left; min-height: 44px;
}
.arrival-main { grid-column: 2; font-size: 13px; font-weight: 700; }
.arrival-row .badge { grid-row: span 3; }
.arrival-meta { grid-column: 2; font-size: 12px; color: var(--muted); font-variant-numeric: var(--tabular); }
.arrival-plate { grid-column: 2; font-size: 11px; color: var(--muted); font-variant-numeric: var(--tabular); }
.muted { color: var(--muted); font-size: 13px; }
.about { display: flex; flex-direction: column; gap: 12px; }
.about .row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.attribution { font-size: 11px; color: var(--muted); }
.bus-popup { min-width: 220px; }
.bus-popup .plate { font-weight: 700; font-variant-numeric: var(--tabular); }

/* ---- toast ---- */
#toast-root { position: absolute; z-index: 30; top: 12px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; }
.toast {
  background: var(--card-bg); border: 1px solid var(--line); border-radius: 999px;
  box-shadow: var(--shadow); padding: 8px 16px; font-size: 13px; font-weight: 700;
}

/* ---- focus & a11y (R-DS9) ---- */
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ---- phones: bottom sheet (R-P2) ---- */
@media (max-width: 720px) {
  #panel { top: auto; left: 0; right: 0; bottom: 0; width: 100%; height: 46vh; }
  .panel { border-radius: 20px 20px 0 0; }
  .line-card, .stop-card { left: 8px; right: 8px; bottom: calc(46vh + 10px); width: auto; }
  #statsbar { bottom: calc(46vh + 8px); max-width: 94vw; }
  /* map popups (stop cards) stack above the bottom sheet */
  .maplibregl-popup { bottom: calc(46vh + 12px) !important; }
}
