:root {
  color-scheme: light;
  --ink: #0e1b24;
  --ink-2: #33444f;
  --muted: #64748b;
  --line: rgba(15, 30, 40, 0.1);
  --glass: rgba(255, 255, 255, 0.84);
  --glass-strong: rgba(255, 255, 255, 0.94);
  --teal: #0f766e;
  --teal-2: #14b8a6;
  --sky: #0ea5e9;
  --orange: #f97316;
  --amber: #d97706;
  --green: #15803d;
  --red: #dc2626;
  --slate: #64748b;
  --shadow: 0 12px 40px rgba(10, 25, 35, 0.16), 0 2px 6px rgba(10, 25, 35, 0.06);
  --radius: 14px;
  --font-body: "IBM Plex Sans Thai", "Noto Sans Thai", "Sukhumvit Set", system-ui, sans-serif;
  --font-display: "Sora", "IBM Plex Sans Thai", system-ui, sans-serif;
  --gutter: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-body);
  color: var(--ink);
  background: #c9d6df;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* ---------- map */
.map { position: fixed; inset: 0; }
.twin-canvas { display: block; position: absolute; inset: 0; touch-action: none; outline: none; }
.twin-labels { position: absolute; inset: 0; pointer-events: none; }

.glass {
  background: var(--glass);
  backdrop-filter: blur(16px) saturate(1.3);
  -webkit-backdrop-filter: blur(16px) saturate(1.3);
  border: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
}

/* ---------- loading */
.loading {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: radial-gradient(1200px 700px at 30% 20%, #e7f3f1, #c7d7de 60%, #aebfca);
  transition: opacity 0.6s ease;
}
.loading.done { opacity: 0; pointer-events: none; }
.loading-card { display: grid; justify-items: center; gap: 8px; text-align: center; padding: 28px 32px; }
.loading-card strong { font-family: var(--font-display); font-size: 22px; letter-spacing: 0.04em; }
.loading-card span { color: var(--ink-2); }
.loading-card small { color: var(--muted); min-height: 1.4em; }
.loading-bar { width: 260px; height: 6px; border-radius: 99px; background: rgba(15, 118, 110, 0.15); overflow: hidden; margin-top: 10px; }
.loading-bar i { display: block; height: 100%; width: 100%; transform-origin: left center; transform: scaleX(0.04); background: linear-gradient(90deg, var(--teal), var(--teal-2)); border-radius: 99px; transition: transform 0.35s ease; }

/* ---------- top bar */
.topbar {
  position: fixed; z-index: 10;
  top: var(--gutter); left: var(--gutter); right: var(--gutter);
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 16px;
  padding: 8px 10px 8px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand strong { display: block; font-family: var(--font-display); font-weight: 800; letter-spacing: 0.03em; font-size: 15px; }
.brand small { display: block; color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.brand-short { display: none; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px; flex: none;
  display: grid; place-items: center; color: #fff; font-family: var(--font-display); font-weight: 800; font-size: 18px;
  background: linear-gradient(140deg, var(--teal) 10%, var(--sky));
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.15);
}
.brand-mark.lg { width: 64px; height: 64px; font-size: 30px; border-radius: 18px; margin-bottom: 6px; }
.tabs { display: flex; justify-content: center; gap: 4px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.tab {
  border: 0; background: transparent; border-radius: 10px; padding: 9px 14px; font-weight: 600; color: var(--ink-2); white-space: nowrap;
}
.tab:hover { background: rgba(15, 118, 110, 0.08); }
.tab.active { background: var(--ink); color: #fff; }
.top-right { display: flex; align-items: center; gap: 8px; }
/* live indicator: red pulse while the stream is connected, grey while reconnecting */
.live-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-display); font-weight: 800; font-size: 11px; letter-spacing: 0.12em;
  color: #fff; background: #dc2626; padding: 5px 8px; border-radius: 7px;
}
.live-badge i { width: 7px; height: 7px; border-radius: 99px; background: #fff; animation: live-pulse 1.6s ease-in-out infinite; }
.live-badge.offline { background: #9ca3af; }
.live-badge.offline i { animation: none; opacity: 0.6; }
@keyframes live-pulse { 50% { opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) { .live-badge i { animation: none; } }
.clock { font-family: var(--font-display); font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink-2); font-size: 14px; }
.service-pill { padding: 8px 12px; border-radius: 10px; font-weight: 700; font-size: 13.5px; color: #fff; background: var(--slate); white-space: nowrap; }
.service-pill.open { background: var(--green); }
.service-pill.closed { background: var(--amber); }
.lang-btn { border: 1px solid var(--line); background: #fff; border-radius: 9px; padding: 7px 9px; font-weight: 700; font-size: 12.5px; }

/* ---------- side panels */
.panel {
  position: fixed; z-index: 8;
  top: calc(var(--gutter) + 70px); bottom: 92px;
  width: 340px; padding: 14px; overflow: auto;
  scrollbar-width: thin;
}
.panel.left { left: var(--gutter); }
.panel.right { right: var(--gutter); width: 360px; }
.panel.left.collapsed { width: 54px; padding: 10px 6px; overflow: hidden; }
.panel.left.collapsed > :not(.panel-head) { display: none; }
.panel.left.collapsed .panel-head > div { display: none; }
.panel.left.collapsed #collapseLeft { transform: rotate(180deg); }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.panel h2 { margin: 0; font-size: 18px; }
.panel-head p { margin: 2px 0 0; font-size: 13px; }
.direction-legend { display: flex; flex-wrap: wrap; gap: 6px 12px; margin: 10px 0 12px; font-size: 12.5px; color: var(--ink-2); }
.direction-legend > span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 99px; display: inline-block; }
.dot.ab { background: var(--sky); }
.dot.ba { background: var(--orange); }

.icon-btn {
  min-width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: #fff;
  display: inline-grid; place-items: center; font-size: 17px; font-weight: 700; padding: 0 8px;
}
.icon-btn:hover { border-color: rgba(15, 118, 110, 0.4); }
.icon-btn.ghost { background: transparent; border-color: transparent; }
.chip-btn {
  height: 32px; border-radius: 99px; border: 1px solid var(--line); background: #fff; padding: 0 12px; font-weight: 600; font-size: 13px; white-space: nowrap;
}
.chip-btn.on { background: #e6f6f4; border-color: rgba(15, 118, 110, 0.35); color: var(--teal); }
.chip-btn.warn { color: #b45309; }
.chip-btn.warn.on { background: #fff7ed; border-color: #fdba74; }

.vehicle-list { display: grid; gap: 8px; }
.vcard {
  width: 100%; text-align: left; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.92);
  border-radius: 12px; padding: 10px; display: grid; grid-template-columns: 44px 1fr auto; gap: 10px; align-items: center;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.vcard:hover { border-color: rgba(15, 118, 110, 0.35); }
.vcard.selected { border-color: var(--sky); box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.18); }
.vnum {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 800; font-size: 19px; color: #fff; position: relative;
}
.vnum::after { content: ""; position: absolute; right: -3px; bottom: -3px; width: 13px; height: 13px; border-radius: 99px; border: 2px solid #fff; background: var(--st, var(--green)); }
.vmain { min-width: 0; }
.vmain strong { display: block; font-size: 14.5px; }
.vmain .vdir { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vtags { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 5px; }
.tag { font-size: 11.5px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: #ecfdf5; color: #047857; white-space: nowrap; }
.tag.info { background: #e0f2fe; color: #0369a1; }
.tag.warn { background: #fff7ed; color: #b45309; }
.tag.off { background: #f1f5f9; color: #475569; }
.tag.bad { background: #fef2f2; color: #b91c1c; }
.veta { text-align: right; }
.veta b { display: block; font-family: var(--font-display); font-size: 15px; font-variant-numeric: tabular-nums; }
.veta small { color: var(--muted); font-size: 11.5px; }

/* ---------- detail */
.detail-photo { width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: 12px; display: block; }
.detail-title { display: flex; align-items: center; gap: 10px; margin: 12px 0 2px; }
.detail-title h2 { font-size: 20px; }
.kicker { font-size: 11px; font-weight: 800; letter-spacing: 0.08em; color: #c2410c; font-family: var(--font-display); }
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.metric { border: 1px solid var(--line); border-radius: 11px; padding: 9px 10px; background: rgba(255, 255, 255, 0.85); }
.metric small { display: block; color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin-top: 2px; font-size: 14.5px; }
.metric.wide { grid-column: 1 / -1; }
.conf { font-size: 11.5px; font-weight: 700; margin-left: 6px; }
.conf.high { color: var(--green); }
.conf.medium { color: var(--sky); }
.conf.low { color: var(--amber); }
.org { display: grid; grid-template-columns: 42px 1fr; gap: 10px; align-items: center; border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-top: 8px; background: rgba(255, 255, 255, 0.85); }
.org-logo { width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; color: #fff; background: var(--teal); font-size: 14px; }
.org b { display: block; font-size: 14px; }
.org span { font-size: 12.5px; color: var(--muted); }
.primary-btn { width: 100%; height: 44px; border: 0; border-radius: 12px; background: var(--teal); color: #fff; font-weight: 700; margin-top: 12px; }
.primary-btn.outline { background: #fff; color: var(--teal); border: 1px solid rgba(15, 118, 110, 0.35); margin-top: 8px; }
.history { margin-top: 10px; font-size: 12.5px; color: var(--ink-2); display: grid; gap: 3px; max-height: 120px; overflow: auto; }

/* ---------- sheet (nav views) */
.sheet {
  position: fixed; z-index: 12;
  left: 50%; top: calc(var(--gutter) + 74px); transform: translateX(-50%);
  width: min(940px, calc(100vw - 2 * var(--gutter) - 2 * 356px));
  max-height: calc(100vh - 190px); overflow: auto; padding: 18px 20px; background: var(--glass-strong);
}
.sheet h2 { margin: 0 0 4px; font-size: 21px; }
.sheet h3 { margin: 0 0 6px; font-size: 15.5px; }
.sheet p { margin: 0; line-height: 1.6; color: var(--ink-2); }
.sheet-close { position: sticky; float: right; top: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; margin-top: 12px; }
.card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: #fff; }
.card .row { display: flex; justify-content: space-between; gap: 8px; padding: 5px 0; border-bottom: 1px dashed var(--line); font-size: 13.5px; }
.card .row:last-child { border-bottom: 0; }
.arrivals { display: grid; gap: 6px; margin-top: 8px; }
.arrival { display: grid; grid-template-columns: 34px 1fr auto; gap: 8px; align-items: center; font-size: 13.5px; }
.arrival .vnum { width: 34px; height: 34px; font-size: 15px; border-radius: 9px; }
.arrival .vnum::after { display: none; }
table.sched { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 14px; }
table.sched td, table.sched th { padding: 9px 8px; border-bottom: 1px solid var(--line); text-align: left; }
table.sched tr.today { background: #ecfdf5; font-weight: 700; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 700; }
.badge.ok { background: #ecfdf5; color: #047857; }
.badge.est { background: #fff7ed; color: #b45309; }
.badge.pend { background: #fef2f2; color: #b91c1c; }

/* ---------- map controls */
.map-controls {
  position: fixed; z-index: 9; left: 50%; bottom: var(--gutter); transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px; padding: 8px; max-width: calc(100vw - 2 * var(--gutter));
}
.segmented { display: inline-flex; background: rgba(15, 30, 40, 0.06); border-radius: 11px; padding: 3px; gap: 2px; }
.segmented button { border: 0; background: transparent; border-radius: 9px; padding: 6px 11px; font-weight: 700; font-size: 13px; white-space: nowrap; }
.segmented button.on { background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); color: var(--teal); }
.segmented.small button { padding: 5px 9px; font-size: 12.5px; }
.sep { width: 1px; height: 26px; background: var(--line); margin: 0 2px; }
.tod { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 700; color: var(--ink-2); }
.tod input { width: 110px; accent-color: var(--teal); }
#todText { min-width: 42px; font-family: var(--font-display); font-variant-numeric: tabular-nums; }


.attribution {
  position: fixed; z-index: 7; left: calc(var(--gutter) + 352px); bottom: 66px;
  font-size: 11px; color: rgba(14, 27, 36, 0.75); background: rgba(255, 255, 255, 0.6); padding: 3px 8px; border-radius: 6px;
}
#perf { font-family: var(--font-display); font-variant-numeric: tabular-nums; margin-right: 8px; color: var(--teal); font-weight: 700; }

/* ---------- map labels (CSS2D) */
.map-label {
  display: flex; align-items: center; gap: 7px; padding: 6px 10px 6px 8px; border-radius: 10px;
  background: rgba(255, 255, 255, 0.92); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18); font-size: 12.5px; white-space: nowrap;
  transform: translateY(-50%);
}
.map-label b { display: block; font-weight: 700; }
.map-label small { display: block; color: var(--muted); font-size: 11px; }
.map-label-dot { width: 10px; height: 10px; border-radius: 3px; background: #7c3aed; flex: none; }
.map-label.terminal .map-label-dot { background: var(--teal); border-radius: 99px; }
.map-label.stop { background: var(--teal); color: #fff; }
.map-label.stop small { color: rgba(255, 255, 255, 0.8); }
.map-label.stop .map-label-dot { background: #fde047; border-radius: 99px; }
/* each tram's own icon floats above it; the chosen one grows with a blue ring */
.tram-tag { pointer-events: auto; border: 0; padding: 0; background: none; cursor: pointer; }
.tt-in {
  position: relative; display: block; padding: 3px; border-radius: 11px; background: #fff;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.28); transform-origin: 50% 100%; transition: transform 0.15s ease;
}
.tt-in::after { content: ""; position: absolute; left: 50%; bottom: -5px; margin-left: -5px; border: 5px solid transparent; border-bottom: 0; border-top-color: #fff; }
.tt-in .tram-icon { display: block; }
.tram-tag-dot { position: absolute; right: -3px; top: -3px; width: 11px; height: 11px; border-radius: 99px; background: var(--dot, #16a34a); border: 2px solid #fff; }
.tram-tag.selected { z-index: 2; }
.tram-tag.selected .tt-in { transform: scale(1.45); box-shadow: 0 0 0 3px var(--sky), 0 6px 16px rgba(0, 0, 0, 0.3); }
.tram-tag.stale { opacity: 0.55; }
.vnum-ic { flex: none; display: grid; place-items: center; }
.vnum-ic .tram-icon { display: block; filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, 0.18)); }
.vmain strong small { font-weight: 500; color: var(--muted); font-size: 12px; margin-left: 4px; }

.toast {
  position: fixed; z-index: 30; left: 50%; top: 92px; transform: translateX(-50%);
  background: rgba(14, 27, 36, 0.92); color: #fff; padding: 10px 14px; border-radius: 11px; font-size: 14px; box-shadow: var(--shadow);
}

/* ---------- responsive */
@media (max-width: 1280px) {
  .tab { padding: 8px 10px; }
  .sheet { width: min(860px, calc(100vw - 2 * var(--gutter) - 360px)); left: calc(50% + 176px); }
}
@media (max-width: 1100px) {
  .topbar { grid-template-columns: 1fr auto; }
  .tabs { grid-column: 1 / -1; justify-content: flex-start; order: 3; }
  .panel { top: calc(var(--gutter) + 112px); }
  .sheet { top: calc(var(--gutter) + 116px); left: 50%; width: calc(100vw - 2 * var(--gutter)); }
  .map-controls .tod, .map-controls #todAuto { display: none; }
  .attribution { display: none; }
}
@media (max-width: 760px) {
  :root { --gutter: 8px; }
  .topbar { grid-template-columns: minmax(0, 1fr) auto; gap: 6px 8px; padding: 6px 8px; }
  .brand { gap: 8px; }
  .brand small { display: none; }
  .brand-mark { width: 30px; height: 30px; font-size: 14px; border-radius: 9px; }
  .brand strong { font-size: 12.5px; white-space: nowrap; }
  .brand-long { display: none; }
  .brand-short { display: inline; }
  .top-right { gap: 6px; min-width: 0; }
  .live-badge { font-size: 10px; padding: 4px 6px; }
  .clock, .lang-btn { display: none; }
  .service-pill { font-size: 11.5px; padding: 6px 8px; max-width: 44vw; overflow: hidden; text-overflow: ellipsis; }
  .map-label { font-size: 11px; padding: 4px 8px 4px 6px; }
  .map-label small { display: none; }
  .tabs { justify-content: flex-start; }
  .tab { padding: 7px 10px; font-size: 13.5px; }
  .panel.left {
    top: auto; bottom: 0; left: 0; right: 0; width: auto; height: 34vh; border-radius: 18px 18px 0 0;
    padding: 12px 12px 72px;
  }
  .panel.left.collapsed { height: 64px; width: auto; }
  .panel.left.collapsed .panel-head > div { display: block; }
  .panel.left.collapsed #collapseLeft { transform: rotate(-90deg); }
  #collapseLeft { transform: rotate(90deg); }
  .panel.right { top: auto; bottom: 0; left: 0; right: 0; width: auto; max-height: 62vh; border-radius: 18px 18px 0 0; z-index: 11; padding-bottom: 76px; }
  .panel.right .detail-photo { aspect-ratio: 21 / 8; }
  .sheet { top: auto; bottom: 0; transform: none; left: 0; width: 100vw; max-height: 72vh; border-radius: 18px 18px 0 0; z-index: 13; padding-bottom: 80px; }
  .map-controls { bottom: auto; top: 100px; left: auto; right: 8px; transform: none; flex-direction: column; padding: 4px; gap: 4px; }
  .map-controls .segmented { flex-direction: column; }
  .map-controls .segmented button { padding: 6px 7px; font-size: 12px; }
  .map-controls .icon-btn { min-width: 34px; height: 34px; }
  .map-controls .sep, .map-controls #rotL, .map-controls #rotR, .map-controls .chip-btn { display: none; }
  .grid { grid-template-columns: 1fr; }
}



/* ---------- map-first layout (Arm 2026-10-16): the map fills the screen; chrome is small
   floating pills that stay readable but step back until needed */
:root { --glass: rgba(255, 255, 255, 0.78); --shadow: 0 6px 22px rgba(10, 25, 35, 0.14), 0 1px 3px rgba(10, 25, 35, 0.06); }

/* top bar: three separate pills, the map stays draggable between them */
.topbar {
  background: transparent; border: 0; box-shadow: none; backdrop-filter: none; -webkit-backdrop-filter: none;
  padding: 0; pointer-events: none; grid-template-columns: auto 1fr auto; gap: 10px;
}
.topbar > * { pointer-events: auto; }
.topbar .brand, .topbar .tabs, .topbar .top-right {
  background: var(--glass); backdrop-filter: blur(14px) saturate(1.3); -webkit-backdrop-filter: blur(14px) saturate(1.3);
  border: 1px solid rgba(255, 255, 255, 0.7); box-shadow: var(--shadow); border-radius: 13px;
}
.topbar .brand { padding: 5px 12px 5px 6px; }
.brand-mark { width: 32px; height: 32px; font-size: 15px; border-radius: 9px; }
.brand strong { font-size: 13.5px; }
.brand small { font-size: 11px; }
.topbar .tabs { justify-self: center; padding: 4px; gap: 2px; }
.tab { padding: 6px 11px; font-size: 13px; border-radius: 9px; }
.topbar .top-right { padding: 4px 4px 4px 8px; gap: 6px; }
.service-pill { font-size: 12px; padding: 5px 9px; }
.lang-btn { padding: 5px 8px; font-size: 12px; }

/* tram list: folded to a small pill by default, opens as a compact card */
.panel { top: calc(var(--gutter) + 56px); bottom: auto; max-height: calc(100vh - var(--gutter) * 2 - 96px); padding: 12px; }
.panel.left { width: 310px; }
.panel.left.collapsed { width: auto; max-width: 300px; height: auto; padding: 7px 8px 7px 12px; overflow: hidden; cursor: pointer; border-radius: 12px; }
.panel.left.collapsed .panel-head { align-items: center; }
.panel.left.collapsed .panel-head > div { display: block; }
.panel.left.collapsed h2 { font-size: 13.5px; }
.panel.left.collapsed .panel-head p { font-size: 11.5px; margin: 0; }
.panel.left.collapsed #collapseLeft { transform: rotate(180deg); }
.panel.left.collapsed:hover { background: var(--glass-strong); }
.panel.right { width: 340px; }

/* map controls: slim rail on the right edge, semi-transparent until used */
.map-controls {
  left: auto; right: var(--gutter); top: 50%; bottom: auto; transform: translateY(-50%);
  flex-direction: column; align-items: flex-end; gap: 8px; padding: 0; background: none; border: 0; box-shadow: none;
}
.map-controls .rail { display: flex; flex-direction: column; gap: 3px; padding: 4px; opacity: 0.82; transition: opacity 0.2s; border-radius: 12px; }
.map-controls .rail:hover, .map-controls .rail:focus-within { opacity: 1; }
.map-controls .segmented { flex-direction: column; background: none; padding: 0; }
.map-controls .segmented button { padding: 6px 8px; font-size: 12px; }
.map-controls .icon-btn { width: 34px; height: 34px; min-width: 34px; padding: 0; font-size: 16px; }
.view-pop { position: absolute; right: calc(100% + 8px); bottom: 0; display: grid; gap: 8px; padding: 10px; width: 250px; }
.view-pop .tod { display: flex; align-items: center; gap: 8px; }
.view-pop .tod input { flex: 1; }
.view-pop-row { display: flex; gap: 6px; flex-wrap: wrap; }
.panel.right:not(.hidden) ~ .map-controls { right: calc(var(--gutter) + 352px); }


.sheet { top: calc(var(--gutter) + 56px); width: min(900px, calc(100vw - 2 * var(--gutter) - 140px)); left: 50%; }

.attribution { left: var(--gutter); bottom: var(--gutter); font-size: 10.5px; background: rgba(255, 255, 255, 0.55); }
.attribution .route-audit-link { color: #92400e; font-weight: 600; text-decoration: none; }

@media (max-width: 1280px) {
  .sheet { left: 50%; width: calc(100vw - 2 * var(--gutter) - 120px); }
}
@media (max-width: 1100px) {
  .topbar { grid-template-columns: auto 1fr auto; }
  .topbar .tabs { grid-column: 1 / -1; justify-self: start; order: 3; max-width: 100%; }
  .panel { top: calc(var(--gutter) + 98px); }
  .sheet { top: calc(var(--gutter) + 100px); width: calc(100vw - 2 * var(--gutter)); }
  .attribution { display: block; }
}
@media (max-width: 760px) {
  .topbar { grid-template-columns: minmax(0, 1fr) auto; gap: 6px; }
  .topbar .brand { padding: 4px 10px 4px 4px; min-width: 0; }
  .topbar .brand > div { min-width: 0; }
  .brand strong { overflow: hidden; text-overflow: ellipsis; }
  .service-pill { max-width: 38vw; }
  .brand-mark { width: 28px; height: 28px; font-size: 13px; }
  .topbar .tabs { padding: 3px; }
  .tab { padding: 5px 9px; font-size: 12.5px; }
  .panel.left { top: auto; bottom: 0; left: 0; right: 0; width: auto; max-width: none; max-height: 46vh; }
  .panel.left.collapsed { left: var(--gutter); right: auto; bottom: var(--gutter); border-radius: 12px; padding: 6px 8px 6px 12px; }
  .panel.left.collapsed #collapseLeft { transform: rotate(90deg); }
  .panel.right { top: auto; max-height: 62vh; }
  .map-controls { top: auto; bottom: 64px; transform: none; }
  .map-controls .rail:first-child { display: none; }
  .map-controls #rotL, .map-controls #rotR { display: none; }
  .map-controls .icon-btn { width: 32px; height: 32px; min-width: 32px; }
  .view-pop { width: min(250px, calc(100vw - 70px)); }
  .attribution { display: none; }
}
/* the time slider and layer chips now live in the ☰ pop-over at every width */
.map-controls .view-pop .tod { display: flex; }
.map-controls .view-pop .chip-btn, .map-controls .view-pop #todAuto { display: inline-flex; }
.tag.full { background: #fef3c7; color: #92400e; }
.tram-tag.estimated .tt-in { outline: 2px dashed rgba(14, 27, 36, 0.7); outline-offset: 1px; }
.empty-list { display: grid; gap: 4px; padding: 18px 14px; text-align: center; background: rgba(255, 255, 255, 0.7); border-radius: 14px; }
.empty-list small { color: var(--muted); }

/* ---------- pastel tokens (same family as driver/admin pages and Downloads/trip) */
:root {
  --teal: #007aff; --teal-2: #4a90d9; --sky: #4a90d9; --orange: #f5a623;
  --ink: #1c1c1e; --ink-2: #3a3a3c; --muted: #8e8e93;
  --radius: 20px;
  --font-body: "Noto Sans Thai", system-ui, sans-serif;
  --font-display: "Noto Sans Thai", system-ui, sans-serif;
}
.icon-btn svg, .tod svg { width: 18px; height: 18px; }
.brand-mark { background: #007aff; }
.tab.active { background: #007aff; }
.segmented button.on { color: #007aff; }
.chip-btn.on { background: #e5f1ff; border-color: rgba(0, 122, 255, 0.35); color: #007aff; }
@media (max-width: 760px) {
  .topbar .brand, .topbar .tabs, .topbar .top-right, .panel.left.collapsed, .map-controls .rail { border-radius: 16px; background: rgba(255, 255, 255, 0.92); }
  .panel.left:not(.collapsed), .panel.right, .sheet { border-radius: 24px 24px 0 0; background: #f2f3f5; }
  .panel.left:not(.collapsed)::before, .panel.right::before { content: ""; display: block; width: 40px; height: 5px; border-radius: 99px; background: #d1d1d6; margin: -4px auto 10px; }
  .vcard { border-radius: 18px; background: #fff; box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04); border: 0; }
}
@media (max-width: 760px) {
  .panel.left:not(.collapsed) ~ .map-controls { display: none; }
}

/* ---------- Grab-style ride card (selected tram) */
.panel.right .ride-top { display: flex; align-items: center; gap: 10px; }
.panel.right .ride-top div { flex: 1; min-width: 0; }
.panel.right .ride-top b { display: block; font-size: 17px; }
.panel.right .ride-top small { display: block; color: var(--muted); font-size: 12.5px; }
.ride-eta { display: grid; gap: 2px; margin: 12px 0 6px; }
.ride-eta small { color: var(--muted); font-size: 13px; }
.ride-eta b { font-size: 34px; line-height: 1.1; color: #007aff; font-weight: 700; }
.ride-eta span { color: var(--ink-2); font-size: 13px; }
.ride-track { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px; margin: 8px 0 10px; font-size: 12px; color: var(--muted); }
.ride-track .bar { position: relative; height: 8px; border-radius: 99px; background: #e5e5ea; }
.ride-track .bar i { position: absolute; inset: 0 auto 0 0; border-radius: 99px; background: #007aff; transition: width 1s linear; }
.ride-track .bar em { position: absolute; top: 50%; width: 28px; height: 28px; margin: -14px 0 0 -14px; border-radius: 50%; background: #fff; color: #007aff; display: grid; place-items: center; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2); transition: left 1s linear; }
.ride-track .bar em svg { width: 16px; height: 16px; }
.ride-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.panel.right .primary-btn { display: flex; align-items: center; justify-content: center; gap: 8px; }
.panel.right .primary-btn svg { width: 18px; height: 18px; }
.ride-more { margin-top: 10px; font-size: 13px; }
.ride-more summary { cursor: pointer; color: var(--muted); }
.panel.right .icon-btn svg { width: 18px; height: 18px; }

/* staff entrance: one quiet button, the rest lives on staff.html */
.staff-btn { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line); background: #fff; border-radius: 9px; padding: 5px 9px; font-weight: 600; font-size: 12px; color: var(--ink-2); text-decoration: none; }
.staff-btn svg { width: 16px; height: 16px; }
.staff-btn:hover { border-color: rgba(0, 122, 255, 0.4); color: #007aff; }
@media (max-width: 760px) { .staff-label { display: none; } .staff-btn { padding: 6px; } }
.staff-links { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; margin: 10px 0 4px; }
.staff-links a { display: flex; align-items: center; gap: 8px; padding: 12px; border-radius: 14px; background: #f2f3f5; color: var(--ink); text-decoration: none; font-weight: 600; font-size: 14px; }
.staff-links a svg { width: 20px; height: 20px; color: #007aff; flex: none; }

/* ==========================================================================================
   Layout v3 (Arm, 2026-11-13): the map sits in its own frame. Filters, the tram list, a tram's
   details and the menu pages live outside it, so nothing covers the map; toggles act on the map;
   the map can go full screen. This block owns the page layout and is loaded last on purpose.
   ========================================================================================== */
body.app { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; background: #eef1f5; }

/* header: brand · menu · live status, in the page (not over the map) */
.app-header {
  position: relative; z-index: 5; flex: none;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px 16px;
  padding: 10px 16px; background: #fff; border-bottom: 1px solid rgba(16, 42, 90, 0.07);
}
.app-header .brand strong { font-size: 15px; }
.app-header .brand small { font-size: 12px; }
.app-header .tabs { justify-self: center; background: #f2f3f5; border-radius: 14px; padding: 4px; gap: 2px; max-width: 100%; }
.app-header .tab { padding: 7px 14px; font-size: 14px; border-radius: 10px; color: #3a3a3c; }
.app-header .tab:hover { background: rgba(255, 255, 255, 0.7); }
.app-header .tab.active { background: #fff; color: #007aff; box-shadow: 0 1px 4px rgba(16, 42, 90, 0.1); }
.app-header .top-right { gap: 8px; }

.stage { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 384px; gap: 14px; padding: 14px; }
.map-col { display: flex; flex-direction: column; gap: 12px; min-width: 0; min-height: 0; }

/* toolbar: what the map shows, outside the frame */
.map-toolbar {
  flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 0;
  background: #fff; border-radius: 18px; padding: 8px 10px; box-shadow: 0 2px 12px rgba(16, 42, 90, 0.06);
}
/* each group: a small caption above its controls */
.tb-group { display: grid; grid-auto-flow: column; grid-template-rows: auto auto; align-items: center; justify-content: start; gap: 4px 8px; padding: 0 16px; min-width: 0; }
.tb-group + .tb-group { border-left: 1px solid rgba(16, 42, 90, 0.08); }
.tb-group:first-child { padding-left: 6px; }
.tb-label { grid-row: 1; grid-column: 1 / span 2; font-size: 11.5px; font-weight: 600; color: #8e8e93; white-space: nowrap; padding-left: 2px; }
.tb-group > :not(.tb-label) { grid-row: 2; }
.map-toolbar .segmented { background: #f2f3f5; border-radius: 12px; padding: 3px; }
.map-toolbar .segmented button { padding: 7px 13px; font-size: 13.5px; font-weight: 600; color: #3a3a3c; border-radius: 9px; }
.map-toolbar .segmented button.on { background: #fff; color: #007aff; box-shadow: 0 1px 4px rgba(16, 42, 90, 0.12); }
.toggles { display: flex; gap: 6px; }
.toggle {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 13px 0 10px; border-radius: 99px;
  border: 1px solid rgba(16, 42, 90, 0.1); background: #fff; color: #8e8e93; font-weight: 600; font-size: 13px; white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.toggle svg { width: 16px; height: 16px; flex: none; }
.toggle.on { background: #e5f1ff; border-color: rgba(0, 122, 255, 0.3); color: #007aff; }
.toggle:hover { border-color: rgba(0, 122, 255, 0.4); }
#todAuto { padding: 0 12px; }
.map-toolbar .tod { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: #3a3a3c; }
.map-toolbar .tod input { width: 130px; accent-color: #007aff; }
.map-toolbar .tod svg { width: 18px; height: 18px; color: #f5a623; }

/* the map's own frame */
.map-frame {
  position: relative; flex: 1; min-height: 0; border-radius: 22px; overflow: hidden; isolation: isolate;
  background: #c9d6df; box-shadow: 0 10px 30px rgba(16, 42, 90, 0.12), 0 0 0 1px rgba(16, 42, 90, 0.06);
}
.map-host { position: absolute; inset: 0; }
.map-frame.hide-trams .tram-tag { display: none; }
/* zoomed in close enough to see the real tram: its icon steps aside (set per tram in src/twin/index.js) */
.tram-tag .tt-in { transition: transform 0.2s ease, opacity 0.2s ease; }
.tram-tag.near { pointer-events: none; }
.tram-tag.near .tt-in, .tram-tag.near.selected .tt-in { opacity: 0; transform: scale(0.5); }
/* zoom, turn and full screen: one small column in the corner */
.map-nav { position: absolute; right: 12px; bottom: 12px; z-index: 3; display: grid; gap: 8px; justify-items: end; }
.nav-stack { display: grid; background: rgba(255, 255, 255, 0.94); border-radius: 12px; box-shadow: 0 2px 10px rgba(16, 42, 90, 0.16); overflow: hidden; }
.nav-stack .nav-btn + .nav-btn { border-top: 1px solid rgba(16, 42, 90, 0.08); }
.nav-btn { width: 38px; height: 38px; border: 0; background: transparent; display: grid; place-items: center; color: #3a3a3c; }
.nav-btn.solo { background: rgba(255, 255, 255, 0.94); border-radius: 12px; box-shadow: 0 2px 10px rgba(16, 42, 90, 0.16); }
.nav-btn svg { width: 18px; height: 18px; }
.nav-btn:hover { color: #007aff; }
.map-frame .attribution { position: absolute; z-index: 2; left: 10px; bottom: 10px; right: auto; top: auto; font-size: 10.5px; background: rgba(255, 255, 255, 0.7); border-radius: 8px; padding: 3px 8px; }
/* full screen: the browser's own, or a fixed frame where the browser has none (iPhone) */
.map-frame:fullscreen { border-radius: 0; box-shadow: none; }
.map-frame.is-full { position: fixed; inset: 0; z-index: 60; border-radius: 0; box-shadow: none; }
body.map-full { overflow: hidden; }
.map-frame:fullscreen .map-nav, .map-frame.is-full .map-nav { right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom)); }
.map-frame:fullscreen #fullBtn, .map-frame.is-full #fullBtn { background: #007aff; color: #fff; }

/* side column: a tram's details, the tram list, menu pages */
.side { min-height: 0; overflow: auto; display: grid; align-content: start; gap: 12px; scrollbar-width: thin; padding-bottom: 4px; }
.side-card { background: #fff; border-radius: 20px; padding: 16px; box-shadow: 0 2px 12px rgba(16, 42, 90, 0.06); }
.fleet-card h2 { margin: 0; font-size: 17px; }
.fleet-card .panel-head p { margin: 2px 0 0; font-size: 13px; }
.fleet-card .vcard { background: #f7f8fa; border: 1px solid transparent; border-radius: 16px; box-shadow: none; }
.fleet-card .vcard:hover { border-color: rgba(0, 122, 255, 0.3); }
.fleet-card .vcard.selected { background: #fff; border-color: #007aff; box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.14); }
.fleet-card .empty-list { background: #f7f8fa; }
.side-view h2 { margin: 0 0 4px; font-size: 20px; }
.side-view h3 { margin: 0 0 6px; font-size: 15px; }
.side-view p { margin: 0; line-height: 1.6; color: var(--ink-2); }
.side-view .grid { grid-template-columns: 1fr; }
.side-view .card { border-radius: 14px; }
.ride-card .ride-top { display: flex; align-items: center; gap: 10px; }
.ride-card .ride-top div { flex: 1; min-width: 0; }
.ride-card .ride-top b { display: block; font-size: 17px; }
.ride-card .ride-top small { display: block; color: var(--muted); font-size: 12.5px; }
.ride-card .primary-btn { display: flex; align-items: center; justify-content: center; gap: 8px; background: #007aff; border-radius: 14px; }
.ride-card .primary-btn svg, .ride-card .icon-btn svg, .side-view .icon-btn svg { width: 18px; height: 18px; }

@media (max-width: 1180px) {
  .stage { grid-template-columns: minmax(0, 1fr) 340px; }
  .app-header { grid-template-columns: auto 1fr; }
  .app-header .tabs { grid-column: 1 / -1; order: 3; justify-self: start; }
}
/* phones and narrow tablets: one column that scrolls — header, toolbar, map, then the lists */
@media (max-width: 860px) {
  body.app { display: block; height: auto; min-height: 100dvh; overflow: auto; }
  .app-header { padding: 8px 10px; gap: 8px; grid-template-columns: minmax(0, 1fr) auto; }
  .app-header .tabs { grid-column: 1 / -1; justify-self: stretch; overflow-x: auto; scrollbar-width: none; }
  .app-header .tab { padding: 7px 11px; font-size: 13.5px; }
  .stage { display: block; padding: 10px; }
  .map-col { gap: 10px; }
  .map-toolbar { display: grid; gap: 8px; padding: 8px; border-radius: 16px; }
  .tb-group, .tb-group:first-child { padding: 0; border-left: 0 !important; }
  .tb-group { display: flex; align-items: center; gap: 8px; }
  .tb-label { display: none; }
  .map-toolbar .segmented { display: grid; grid-template-columns: repeat(4, 1fr); width: 100%; }
  .map-toolbar .segmented button { padding: 8px 4px; font-size: 13px; }
  .tb-show, .tb-tod { overflow-x: auto; scrollbar-width: none; }
  .tb-tod .tod { flex: 1; }
  .map-toolbar .tod input { flex: 1; width: auto; min-width: 90px; }
  .map-frame { flex: none; height: clamp(320px, 56svh, 620px); border-radius: 18px; }
  .map-frame .attribution { display: none; }
  .nav-btn { width: 36px; height: 36px; }
  .side { overflow: visible; margin-top: 10px; }
  .side-card { border-radius: 18px; padding: 14px; }
  .app-header .brand { min-width: 0; overflow: hidden; }
  .app-header .brand strong { overflow: hidden; text-overflow: ellipsis; }
  .app-header .top-right { min-width: 0; }
}
/* small phones: the logo alone, so the service status has room */
@media (max-width: 480px) {
  .app-header .brand > div { display: none; }
  .app-header .service-pill { max-width: none; }
}
