/* เรดาร์รถไฟ — สไตล์หลัก (ธีมเรดาร์มืดเป็นค่าเริ่มต้น + ธีมสว่าง) */

/* ---------- tokens ---------- */
:root {
  --font: "IBM Plex Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", menlo, monospace;
  --radius: 16px;
  --panel-w: 384px;
  --detail-w: 408px;
  --peek: 244px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --bg: #0b1220;
  --panel: rgb(13 20 34 / 90%);
  --panel-solid: #0f1727;
  --card: rgb(148 163 184 / 7%);
  --card-hover: rgb(148 163 184 / 13%);
  --line: rgb(148 163 184 / 17%);
  --text: #e8eef7;
  --muted: #8fa0b6;
  --accent: #38bdf8;
  --accent-ink: #04202f;
  --ok: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --idle: #94a3b8;
  --ok-t: #4ade80;
  --warn-t: #fbbf24;
  --bad-t: #f87171;
  --rail: #36557a;
  --halo: #0b1220;
  --cargo: #a47551;
  --cargo-t: #d9ad83;
  --shadow: 0 12px 32px rgb(0 0 0 / 38%), 0 2px 8px rgb(0 0 0 / 24%);

  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #e9eef5;
  --panel: rgb(255 255 255 / 92%);
  --panel-solid: #fff;
  --card: rgb(15 23 42 / 4%);
  --card-hover: rgb(15 23 42 / 8%);
  --line: rgb(15 23 42 / 11%);
  --text: #0f172a;
  --muted: #5b6b82;

  /* #0369a1: ≥ 4.5:1 ทั้งเป็นตัวอักษรบนพื้นขาว/การ์ด และพื้นหลังของตัวอักษรขาว (#0284c7 ได้แค่ 4.1) */
  --accent: #0369a1;
  --accent-ink: #fff;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --idle: #64748b;
  --ok-t: #15803d;
  --warn-t: #b45309;
  --bad-t: #b91c1c;
  --rail: #6f86a6;
  --halo: #fff;
  --cargo: #9a6a44;
  --cargo-t: #7c4f24;
  --shadow: 0 12px 30px rgb(15 23 42 / 14%), 0 2px 6px rgb(15 23 42 / 8%);

  color-scheme: light;
}

/* ---------- base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

[hidden] {
  display: none !important;
}

/* ไอคอนทุกตัวใช้ขนาดจาก --i ของคอนเทนเนอร์ที่ใกล้ที่สุด */
svg {
  flex: none;
  width: var(--i, 20px);
  height: var(--i, 20px);
}

button {
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  background: none;
  border: 0;
}

button:disabled {
  cursor: not-allowed;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 13px;
}

.pad {
  padding: 16px;
}

.noscript {
  position: fixed;
  inset: 40% 16px auto;
  z-index: 2000;
  padding: 16px;
  text-align: center;
  background: var(--panel-solid);
  border-radius: 12px;
}

/* สีตามระดับความตรงเวลา: --c = สีหลัก, --ct = สีตัวอักษร */
.lv0 {
  --c: var(--ok);
  --ct: var(--ok-t);
}

.lv1 {
  --c: var(--warn);
  --ct: var(--warn-t);
}

.lv2 {
  --c: var(--bad);
  --ct: var(--bad-t);
}

.idle {
  --c: var(--idle);
  --ct: var(--muted);
}

.cargo {
  --c: var(--cargo);
  --ct: var(--cargo-t);
}

/* ซ่อนจากสายตา แต่โปรแกรมอ่านหน้าจอยังอ่านได้ */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  white-space: nowrap;
  clip-path: inset(50%);
  border: 0;
}

/* ลิงก์ข้ามไปช่องค้นหา (คีย์บอร์ด): ซ่อนจนกว่าจะได้โฟกัส — ไม่ต้องกด Tab ผ่านหมุดขบวนทุกหมุดบนแผนที่ */
.skip-link {
  position: fixed;
  top: 10px;
  left: 50%;
  z-index: 1400;
  padding: 10px 18px;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent);
  border-radius: 12px;
  box-shadow: var(--shadow);
  transform: translate(-50%, -160%);
}

.skip-link:focus {
  transform: translate(-50%, 0);
}

/* ---------- แผนที่ ---------- */
.map {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: var(--bg);
}

.leaflet-container {
  font-family: var(--font);
  background: var(--bg);
}

/* ซูมทศนิยมทำให้เห็นรอยต่อ tile → ขยาย tile ครึ่งพิกเซลให้ซ้อนกัน
   และปิด plus-lighter ของ Leaflet (ส่วนที่ซ้อนจะบวกสีกลายเป็นเส้นสว่าง) */
.leaflet-container img.leaflet-tile {
  width: 256.5px !important;
  height: 256.5px !important;
  mix-blend-mode: normal;
}

/* แผนที่พื้นสีเทา → โทนน้ำเงินเรดาร์ */
:root[data-theme="dark"] .leaflet-tile-pane {
  filter: brightness(1.25) contrast(0.92) sepia(0.45) hue-rotate(178deg) saturate(1.9);
}

.leaflet-control-attribution {
  max-width: min(660px, 60vw);
  padding: 2px 8px !important;
  font-size: 10.5px;
  line-height: 1.5;
  color: var(--muted) !important;
  background: color-mix(in srgb, var(--panel-solid) 80%, transparent) !important;
  border-radius: 8px 0 0;
}

.leaflet-control-attribution a {
  color: var(--muted);
}

.leaflet-tooltip {
  padding: 6px 10px;
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.45;
  color: var(--text);
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.leaflet-tooltip-top::before {
  border-top-color: var(--panel-solid);
}

.st-tip b {
  display: block;
  font-weight: 600;
}

.st-tip small {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
}

.tm-tip small {
  color: var(--muted);
}

.tm-tip .lv0,
.tm-tip .lv1,
.tm-tip .lv2 {
  font-weight: 600;
  color: var(--ct);
}

.tm-tip .tip-stale {
  font-weight: 600;
  color: var(--muted);
}

/* หมุดขบวนรถ — ขนาดตามซูม: .zs จุดเล็ก, .zm กลาง, .zl เต็ม (ขบวนที่เลือกเต็มเสมอ) */
.tm-icon {
  outline: none;
}

.tx .tm-icon {
  transition: transform 1s linear;
}

.tm {
  --c: var(--ok);
  --s: 26px;

  position: absolute;
  top: calc(var(--s) / -2);
  left: calc(var(--s) / -2);
  width: var(--s);
  height: var(--s);
  transition: opacity 0.25s;
}

.tm.lv1 {
  --c: var(--warn);
}

.tm.lv2 {
  --c: var(--bad);
}

.tm.is-idle {
  --c: var(--idle);
}

.tm.is-cargo {
  --c: var(--cargo);
}

/* ตำแหน่งโดยประมาณ: วงประรอบหมุด */
.tm.is-rough::after {
  position: absolute;
  inset: -5px;
  content: "";
  border: 1.5px dashed color-mix(in srgb, var(--c) 70%, #fff);
  border-radius: 9px;
  pointer-events: none;
}

.zs .tm.is-rough::after {
  inset: -3px;
  border-radius: 5px;
}

.zm .tm {
  --s: 20px;
}

.zs .tm {
  --s: 16px;
}

.zs .tm.is-sel,
.zm .tm.is-sel {
  --s: 26px;
}

.tm-puck {
  --i: 14px;

  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--c);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 32%, transparent), 0 0 14px color-mix(in srgb, var(--c) 70%, transparent), 0 2px 6px rgb(0 0 0 / 45%);
  transition: transform 0.25s var(--ease);
}

.zm .tm-puck {
  --i: 11px;
}

.zs .tm-puck {
  --i: 0;

  border-width: 1.5px;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--c) 30%, transparent), 0 1px 3px rgb(0 0 0 / 55%);
}

.tm.is-cargo .tm-puck {
  background: linear-gradient(160deg, color-mix(in srgb, var(--cargo) 80%, #fff), var(--cargo));
  border-radius: 7px;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--cargo) 30%, transparent), 0 2px 6px rgb(0 0 0 / 45%);
}

.tm-icon:focus-visible .tm-puck {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.tm.is-stop .tm-puck {
  color: var(--c);
  background: #fff;
  border: 3px solid var(--c);
}

.tm.is-sel .tm-puck {
  --i: 14px;

  border-width: 2px;
  transform: scale(1.3);
}

/* ขาดการรายงาน: เทา โปร่ง เส้นประ ไม่มีลูกศร (ไม่รู้ว่าอยู่ไหน/ไปทางไหนแล้ว) */
.tm.is-stale {
  --c: var(--idle);
}

.tm.is-stale .tm-puck {
  color: var(--idle);
  background: color-mix(in srgb, var(--panel-solid) 72%, transparent);
  border: 2px dashed var(--idle);
  box-shadow: 0 1px 4px rgb(0 0 0 / 35%);
}

.zs .tm.is-stop .tm-puck {
  border-width: 3px;
}

.zs .tm.is-cargo .tm-puck {
  border-radius: 3px;
}

.tm-arrow {
  position: absolute;
  inset: -9px;
  pointer-events: none;
  transform: rotate(var(--h, 0deg));
}

.tm-arrow::before {
  position: absolute;
  top: 0;
  left: 50%;
  margin-left: -5px;
  content: "";
  border-right: 5px solid transparent;
  border-bottom: 7px solid var(--c);
  border-left: 5px solid transparent;
  filter: drop-shadow(0 0 1px rgb(0 0 0 / 70%));
}

.tm.is-stop .tm-arrow,
.tm.is-stale .tm-arrow,
.tm.is-stale.is-rough::after {
  display: none;
}

.zs .tm:not(.is-sel) .tm-arrow {
  display: none;
}

.tm-label {
  position: absolute;
  top: 50%;
  left: calc(100% + 3px);
  padding: 3px 6px;
  font: 600 11.5px/1 var(--mono);
  color: #fff;
  white-space: nowrap;
  pointer-events: none;
  background: rgb(8 13 24 / 86%);
  border: 1px solid rgb(255 255 255 / 12%);
  border-radius: 6px;
  box-shadow: 0 2px 6px rgb(0 0 0 / 35%);
  transform: translateY(-50%);
}

.tm.is-sel .tm-label {
  left: calc(100% + 8px);
  font-size: 13px;
  color: #04202f;
  background: #fff;
}

.zm .tm:not(.is-sel, .is-fav) .tm-label,
.zs .tm:not(.is-sel) .tm-label {
  display: none;
}

.tm-star {
  display: none;
  margin-left: 3px;
  font-size: 10px;
  color: #fcd34d;
}

.tm.is-fav .tm-star {
  display: inline;
}

.tm.is-sel::before {
  position: absolute;
  inset: -10px;
  content: "";
  border: 2px solid var(--c);
  border-radius: 50%;
  animation: halo 1.6s ease-out infinite;
}

.has-sel .tm:not(.is-sel) {
  opacity: 0.5;
}

/* ป้ายชื่อสถานีบนแผนที่ */
.st-label-icon {
  pointer-events: none;
}

.st-label {
  position: absolute;
  top: -9px;
  left: 7px;
  font: 500 11.5px/18px var(--font);
  color: var(--muted);
  white-space: nowrap;
  text-shadow: 0 0 2px var(--halo), 0 0 3px var(--halo), 0 0 5px var(--halo);
}

.st-label.t1 {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
}

.st-hl {
  position: absolute;
  top: -17px;
  left: -17px;
  width: 34px;
  height: 34px;
  border: 3px solid var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent), 0 0 18px var(--accent);
  animation: ring 1.8s ease-out infinite;
}

.me-dot {
  position: absolute;
  top: -9px;
  left: -9px;
  width: 18px;
  height: 18px;
  background: #3b82f6;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgb(59 130 246 / 55%);
  animation: me-pulse 2s ease-out infinite;
}

/* ---------- ส่วนประกอบทั่วไป ---------- */
.icon-btn {
  --i: 20px;

  display: inline-grid;
  flex: none;
  place-items: center;
  width: 40px;
  height: 40px;
  color: var(--muted);
  border-radius: 12px;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
  color: var(--text);
  background: var(--card-hover);
}

.icon-btn.sm {
  --i: 16px;

  width: 32px;
  height: 32px;
  border-radius: 10px;
}

.pill {
  flex: none;
  max-width: 96px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--ct, var(--muted));
  text-align: center;
  background: color-mix(in srgb, var(--c, var(--idle)) 16%, transparent);
  border-radius: 10px;
}

.pill.none {
  --c: var(--idle);
  --ct: var(--muted);
}

.pill.stale-pill {
  max-width: 112px;
  border: 1px dashed color-mix(in srgb, var(--idle) 60%, transparent);
}

.pill.cargo-pill {
  --c: var(--cargo);
  --ct: var(--cargo-t);
  --i: 13px;

  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.badge {
  --bs: 21px;

  position: relative;
  display: flex;
  flex: none;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 52px;
  color: var(--tfg, #fff);
  background: var(--tbg, #1968ab);
  border-radius: 12px;
  box-shadow: inset 0 -3px 0 rgb(0 0 0 / 18%), 0 1px 3px rgb(0 0 0 / 25%);
}

.badge.long {
  --bs: 17px;
}

.badge.xl {
  --bs: 13px;
}

.badge.sm {
  --bs: 15px;

  width: 46px;
  height: 34px;
  border-radius: 9px;
}

.badge.ghost {
  color: var(--muted);
  background: var(--card-hover);
  box-shadow: none;
}

.badge b {
  font: 600 var(--bs)/1 var(--mono);
}

.badge small {
  max-width: 56px;
  overflow: hidden;
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge-star {
  --i: 17px;

  position: absolute;
  top: -6px;
  right: -6px;
  color: #fcd34d;
  filter: drop-shadow(0 1px 1px rgb(0 0 0 / 55%));
}

.empty {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  padding: 32px 20px;
  color: var(--muted);
  text-align: center;
}

.empty-ico {
  --i: 32px;

  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  margin-bottom: 6px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border-radius: 50%;
}

.empty b {
  font-size: 16px;
  color: var(--text);
}

.empty p {
  max-width: 290px;
  margin: 0;
  font-size: 13.5px;
}

.notice {
  margin: 0;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  background: var(--card);
  border-radius: 10px;
}

.hint {
  margin: 6px 8px 10px;
  font-size: 12.5px;
  color: var(--muted);
}

/* ---------- แผงหลัก ---------- */
.panel {
  position: fixed;
  top: 16px;
  bottom: 16px;
  left: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  width: var(--panel-w);
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  backdrop-filter: blur(16px) saturate(140%);
}

.panel-grip {
  display: none;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 16px 12px 12px 16px;
}

.brand-logo {
  --i: 22px;

  position: relative;
  display: grid;
  flex: none;
  place-items: center;
  width: 46px;
  height: 46px;
  overflow: hidden;
  color: var(--accent);
  background:
    radial-gradient(circle at center, transparent 0 33%, color-mix(in srgb, var(--accent) 32%, transparent) 34% 36%, transparent 37% 63%, color-mix(in srgb, var(--accent) 32%, transparent) 64% 66%, transparent 67%),
    color-mix(in srgb, var(--accent) 12%, var(--panel-solid));
  border-radius: 50%;
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--accent) 55%, transparent), 0 0 18px color-mix(in srgb, var(--accent) 28%, transparent);
}

.brand-logo::before {
  position: absolute;
  inset: 0;
  content: "";
  background: conic-gradient(from 0deg, transparent 70%, color-mix(in srgb, var(--accent) 70%, transparent));
  border-radius: 50%;
  animation: sweep 3.2s linear infinite;
}

.brand-logo > svg {
  position: relative;
}

.brand-text {
  flex: 1;
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 21px;
  font-weight: 700;
  line-height: 1.25;
}

/* ปุ่มสลับภาษา TH/EN — ตัวที่ใช้อยู่ไฮไลต์ตาม <html lang> */
.lang-btn {
  display: inline-flex;
  flex: none;
  gap: 1px;
  align-items: center;
  padding: 2px;
  font: 600 11.5px/1 var(--mono);
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  transition: border-color 0.15s;
}

.lang-btn:hover {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
}

.lang-btn span {
  padding: 7px 8px;
  border-radius: 999px;
  transition: background 0.15s, color 0.15s;
}

html[lang="th"] .lang-th,
html[lang="en"] .lang-en {
  color: var(--accent-ink);
  background: var(--accent);
}

.live {
  display: flex;
  gap: 7px;
  align-items: center;
  margin: 3px 0 0;
  overflow: hidden;
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
}

.live-dot {
  --c: var(--ok);

  position: relative;
  flex: none;
  width: 8px;
  height: 8px;
  background: var(--c);
  border-radius: 50%;
}

.live-dot::after {
  position: absolute;
  inset: 0;
  content: "";
  background: inherit;
  border-radius: 50%;
  animation: ping 1.8s ease-out infinite;
}

.live.wait {
  --c: var(--idle);
}

.live.warn {
  --c: var(--warn);

  color: var(--warn-t);
}

.live.bad {
  --c: var(--bad);

  color: var(--bad-t);
}

/* --c ต้องตั้งที่ตัวจุดเอง (.live-dot ตั้ง --c: ok ไว้ ค่าจากแม่ส่งลงมาไม่ถึง) */
.live.wait .live-dot {
  --c: var(--idle);
}

.live.warn .live-dot {
  --c: var(--warn);
}

.live.bad .live-dot {
  --c: var(--bad);
}

.live.bad .live-dot::after,
.live.wait .live-dot::after {
  animation: none;
}

/* ค้นหา */
.search {
  --i: 19px;

  position: relative;
  margin: 0 16px;
}

.search > svg {
  position: absolute;
  top: 50%;
  left: 14px;
  color: var(--muted);
  pointer-events: none;
  transform: translateY(-50%);
}

.search input {
  width: 100%;
  height: 46px;
  padding: 0 44px 0 42px;
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none;
}

.search input::placeholder {
  color: var(--muted);
}

.search input::-webkit-search-cancel-button {
  display: none;
}

.search input:where(:focus) {
  background: var(--panel-solid);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}

.search .icon-btn {
  position: absolute;
  top: 50%;
  right: 7px;
  transform: translateY(-50%);
}

.search-results {
  position: absolute;
  inset: calc(100% + 6px) 0 auto;
  z-index: 30;
  max-height: min(470px, 62vh);
  padding: 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.sr-sec {
  padding: 8px 10px 4px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
}

.sr-item {
  display: flex;
  gap: 10px;
  align-items: center;
  min-height: 48px;
  padding: 7px 8px;
  cursor: pointer;
  border-radius: 10px;
}

.sr-item[aria-selected="true"] {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}

.sr-item:hover {
  background: var(--card-hover);
}

.sr-main {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}

.sr-main b {
  overflow: hidden;
  font-size: 14px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sr-main small {
  overflow: hidden;
  font-size: 12px;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sr-ico {
  --i: 20px;

  display: grid;
  flex: none;
  place-items: center;
  width: 46px;
  height: 34px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 13%, transparent);
  border-radius: 9px;
}

.sr-none {
  padding: 16px 12px;
  font-size: 13.5px;
  color: var(--muted);
  text-align: center;
}

/* ตัวเลขสรุป */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 12px 16px 0;
}

.stat {
  --c: var(--accent);
  --ct: var(--accent);

  display: flex;
  flex-direction: column;
  gap: 1px;
  align-items: flex-start;
  min-width: 0;
  padding: 8px 10px 7px;
  text-align: left;
  background: var(--card);
  border: 1px solid transparent;
  border-radius: 12px;
  transition: background 0.15s, border-color 0.15s;
}

.stat.ok {
  --c: var(--ok);
  --ct: var(--ok-t);
}

.stat.warn {
  --c: var(--warn);
  --ct: var(--warn-t);
}

.stat.bad {
  --c: var(--bad);
  --ct: var(--bad-t);
}

.stat b {
  font: 600 23px/1.15 var(--mono);
  color: var(--ct);
}

.stat span {
  max-width: 100%;
  overflow: hidden;
  font-size: 11px;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat:hover {
  background: var(--card-hover);
}

.stat[aria-pressed="true"] {
  background: color-mix(in srgb, var(--c) 16%, transparent);
  border-color: var(--c);
}

/* ปุ่มลัด 2–4 ปุ่ม: ตาราง 2 คอลัมน์ (ปุ่มสุดท้ายที่เหลือเดี่ยวยืดเต็มแถว) */
.quick {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 10px 16px 0;
}

.quick > :last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

.chip-btn {
  --i: 19px;

  display: inline-flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  min-width: 0;
  height: 42px;
  padding: 0 10px;
  overflow: hidden;
  font-size: 14px;
  white-space: nowrap;
  font-weight: 500;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  transition: background 0.15s, transform 0.1s;
}

.chip-btn > svg {
  color: var(--accent);
}

.chip-btn:hover {
  background: var(--card-hover);
}

.chip-btn:active {
  transform: scale(0.97);
}

.chip-btn:where(.is-busy) > svg {
  animation: spin 1s linear infinite;
}

/* แท็บ */
.tabs {
  display: flex;
  gap: 3px;
  margin: 12px 12px 0;
  padding: 4px;
  background: var(--card);
  border-radius: 14px;
}

.tab {
  --i: 16px;

  position: relative;
  display: inline-flex;
  flex: 1 1 auto;
  gap: 5px;
  align-items: center;
  justify-content: center;
  height: 38px;
  padding: 0 6px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  border-radius: 10px;
  transition: background 0.15s, color 0.15s;
}

.tab:hover {
  color: var(--text);
}

.tab[aria-selected="true"] {
  color: var(--text);
  background: var(--panel-solid);
  box-shadow: 0 1px 4px rgb(0 0 0 / 22%);
}

.tab-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font: 600 11px/18px var(--mono);
  color: #fff;
  text-align: center;
  background: #dc2626;
  border-radius: 9px;
}

.views {
  flex: 1;
  min-height: 0;
  margin-top: 6px;
  padding: 0 8px 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: var(--line) transparent;
  scrollbar-width: thin;
}

/* ตัวกรองประเภท */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 8px 8px;
}

.fchip {
  --n: var(--muted);

  display: inline-flex;
  gap: 6px;
  align-items: center;
  height: 32px;
  padding: 0 11px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 999px;
  transition: background 0.15s;
}

.fchip i {
  width: 9px;
  height: 9px;
  background: var(--c);
  border-radius: 50%;
}

.fchip span {
  font: 500 11.5px var(--mono);
  color: var(--n);
}

.fchip:hover {
  background: var(--card-hover);
}

.fchip[aria-pressed="true"] {
  --n: var(--accent-ink);

  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}

.list-head {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
  padding: 2px 8px 6px;
  font-size: 12.5px;
  color: var(--muted);
}

.switches {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  justify-content: flex-end;
}

.switch {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  font-size: 12.5px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.switch input {
  position: relative;
  flex: none;
  width: 36px;
  height: 22px;
  margin: 0;
  cursor: pointer;
  background: var(--line);
  border-radius: 999px;
  transition: background 0.2s;
  appearance: none;
}

.switch input::before {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  content: "";
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgb(0 0 0 / 35%);
  transition: transform 0.2s var(--ease);
}

.switch input:where(:checked) {
  background: var(--accent);
}

.switch input:checked::before {
  transform: translateX(14px);
}

/* รายการขบวน */
.train-list {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 8px;
  text-align: left;
  border-radius: 14px;
  transition: background 0.15s;
}

.row:hover {
  background: var(--card-hover);
}

.row.is-sel {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 45%, transparent);
}

.row.is-done {
  opacity: 0.62;
}

.row.is-stale {
  opacity: 0.78;
}

.row.is-ghost {
  cursor: default;
}

.row-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.row-route {
  overflow: hidden;
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.5;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-route i {
  font-style: normal;
  color: var(--muted);
}

/* ภาษาอังกฤษ: ชื่อสถานียาว ("Bangkok (Krung Thep Aphiwat)") → ขึ้นได้ 2 บรรทัด ให้เห็นปลายทางเสมอ */
html[lang="en"] .row-route {
  display: -webkit-box;
  line-height: 1.3;
  white-space: normal;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.row-where {
  overflow: hidden;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.warn-text {
  font-weight: 600;
  color: var(--warn-t);
}

.ico-alert {
  --i: 13px;

  margin-right: 3px;
  color: var(--warn-t);
  vertical-align: -2px;
}

/* ---------- สถานะเดินรถ ---------- */
.status-body {
  padding: 6px 6px 8px;
}

.sec {
  margin-bottom: 18px;
}

.sec-title {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 8px 4px;
  font-size: 14.5px;
  font-weight: 700;
}

.count {
  min-width: 20px;
  height: 18px;
  padding: 0 6px;
  font: 600 11px/18px var(--mono);
  color: #fff;
  text-align: center;
  background: var(--bad);
  border-radius: 9px;
}

.zones,
.incs,
.cxls {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.zone {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 9px 12px;
  background: var(--card);
  border-radius: 12px;
}

.zdot {
  flex: none;
  width: 12px;
  height: 12px;
  background: var(--c);
  border-radius: 50%;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 22%, transparent);
}

.zone-main,
.cxl-main,
.inc-main {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}

.zone-main b,
.cxl-main b {
  font-size: 14px;
  font-weight: 600;
}

.zone-main small,
.inc-main small {
  font-size: 12px;
  color: var(--muted);
}

.cxl-main small {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ct);
}

.inc {
  --tone: var(--warn);
  --tone-t: var(--warn-t);

  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  color: var(--text);
  text-decoration: none;
  background: color-mix(in srgb, var(--tone) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--tone) 30%, transparent);
  border-radius: 12px;
  transition: background 0.15s;
}

.inc:hover {
  background: color-mix(in srgb, var(--tone) 17%, transparent);
}

.inc.is-resolved {
  --tone: var(--idle);
  --tone-t: var(--ok-t);

  border-color: transparent;
  opacity: 0.78;
}

.inc-ico {
  --i: 18px;

  margin-top: 2px;
  color: var(--tone-t);
}

.inc-main b {
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.5;
}

.inc-ext {
  --i: 16px;

  margin-top: 3px;
  color: var(--muted);
}

.incs-done {
  margin-top: 8px;
}

.incs-done summary {
  padding: 6px 4px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}

.cxl {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 8px 10px;
  background: var(--card);
  border-radius: 12px;
}

.cxl-no {
  --tbg: var(--card-hover);
  --tfg: var(--text);
}

.credit {
  margin: 20px 6px 6px;
  font-size: 12px;
  line-height: 1.7;
  color: var(--muted);
  text-align: center;
}

.credit a {
  color: var(--accent);
}

/* ---------- แผงรายละเอียด ---------- */
.detail {
  position: fixed;
  top: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  width: var(--detail-w);
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  backdrop-filter: blur(16px) saturate(140%);
  animation: detail-in 0.28s var(--ease);
}

.dt-head {
  position: relative;
  flex: none;
  padding: 12px 16px 16px;
}

.train-head {
  color: var(--tfg, #fff);
  background: linear-gradient(135deg, var(--tbg, #1968ab), color-mix(in srgb, var(--tbg, #1968ab) 60%, #000));
}

.dt-grip {
  display: none;
}

.dt-bar {
  display: flex;
  gap: 8px;
  align-items: center;
}

.dt-sp {
  flex: 1;
}

.dt-btn {
  --i: 20px;

  display: inline-flex;
  flex: none;
  gap: 6px;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 40px;
  padding: 0 10px;
  font-size: 14px;
  font-weight: 600;
  background: color-mix(in srgb, currentcolor 15%, transparent);
  border-radius: 12px;
  transition: background 0.15s, transform 0.1s;
}

.dt-btn:hover {
  background: color-mix(in srgb, currentcolor 24%, transparent);
}

.dt-btn:active {
  transform: scale(0.95);
}

.dt-btn.wide {
  padding: 0 14px;
}

.dt-btn[aria-pressed="true"] {
  color: var(--tbg, #1968ab);
  background: var(--tfg, #fff);
}

.dt-btn:disabled {
  opacity: 0.45;
}

.dt-kicker {
  margin: 12px 0 2px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0.88;
}

.dt-title {
  display: flex;
  gap: 14px;
  align-items: center;
  margin: 0;
  font-size: inherit;
  font-weight: inherit;
}

.dt-no {
  flex: none;
  max-width: 62%;
  overflow: hidden;
  font: 600 54px/1 var(--mono);
  letter-spacing: -0.03em;
  text-overflow: ellipsis;
}

.dt-no.long {
  font-size: 42px;
}

.dt-route {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.dt-route b {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.4;
}

.dt-route i {
  font-style: normal;
  opacity: 0.85;
}

.dt-route small {
  font-size: 12px;
  line-height: 1.4;
  opacity: 0.92;
}

/* การ์ดสรุปปักไว้ด้านบน ไม่เลื่อนตามไทม์ไลน์ */
.dt-summary {
  flex: none;
  padding: 12px 14px 0;
}

.dt-summary:empty {
  display: none;
}

.dt-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  padding: 12px 14px 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: var(--line) transparent;
  scrollbar-width: thin;
  mask-image: linear-gradient(to bottom, transparent 0, #000 12px);
}

.dt-note:empty {
  display: none;
}

/* ข้อมูลไม่อัปเดต (ออฟไลน์/ต้นทางล่ม) — อยู่ใต้หัวแผงเสมอ ไม่เลื่อนหาย */
.dt-stale {
  flex: none;
  margin: 10px 14px 0;
  padding: 7px 12px;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.45;
  color: var(--warn-t);
  background: color-mix(in srgb, var(--warn) 13%, var(--panel-solid));
  border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent);
  border-radius: 12px;
}

.loc-body .dt-stale {
  margin: 0;
}

.empty-act {
  display: flex;
  justify-content: center;
  margin: -12px 0 16px;
}

.empty-act .chip-btn {
  padding: 0 18px;
  color: var(--accent);
  font-weight: 600;
}

.card {
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.sum-card {
  padding: 12px 16px 10px;
  background: var(--panel-solid);
  box-shadow: 0 6px 16px rgb(0 0 0 / 12%);
}

.st-big {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.35;
  color: var(--ct, var(--text));
}

.st-sub {
  margin: 1px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.alert {
  --i: 20px;

  display: flex;
  gap: 10px;
  margin-top: 10px;
  padding: 8px 12px;
  color: var(--warn-t);
  background: color-mix(in srgb, var(--warn) 13%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  border-radius: 12px;
}

.alert > svg {
  margin-top: 2px;
}

.alert b {
  font-weight: 700;
}

.alert p {
  margin: 1px 0 0;
  font-size: 13px;
  color: var(--text);
}

.info {
  --i: 18px;

  display: flex;
  gap: 10px;
  margin-top: 10px;
  padding: 8px 12px;
  font-size: 12.5px;
  background: color-mix(in srgb, var(--cargo) 13%, transparent);
  border: 1px solid color-mix(in srgb, var(--cargo) 32%, transparent);
  border-radius: 12px;
}

.info > svg {
  margin-top: 2px;
  color: var(--cargo-t);
}

.info p {
  margin: 0;
}

.st-big.stale {
  --ct: var(--muted);
}

.info.stale-info {
  background: color-mix(in srgb, var(--idle) 12%, transparent);
  border: 1px dashed color-mix(in srgb, var(--idle) 45%, transparent);
}

.info.stale-info > svg {
  color: var(--muted);
}

.sum-next {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.next-main {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-width: 0;
}

.k {
  font-size: 12px;
  color: var(--muted);
}

.next-name {
  overflow: hidden;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.next-time {
  display: flex;
  flex: 0 1 auto;
  flex-direction: column;
  align-items: flex-end;
  max-width: 52%;
  text-align: right;
}

.next-time b {
  font-size: 26px;
  font-weight: 600;
  line-height: 1.1;
  color: var(--accent);
}

.next-time span {
  margin-top: 2px;
  font-size: 13px;
  font-weight: 600;
}

.prog {
  margin-top: 12px;
}

.prog-bar {
  --i: 15px;

  position: relative;
  height: 8px;
  margin: 12px 14px 8px;
  background: var(--line);
  border-radius: 999px;
}

.prog-fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 35%, transparent), var(--accent));
  border-radius: inherit;
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 1s linear;
}

/* รางของไอคอนขบวน: เลื่อนทั้งรางด้วย translateX(%) = สัดส่วนของความยาวแถบ */
.prog-track {
  position: absolute;
  inset: 0;
  pointer-events: none;
  transition: transform 1s linear;
}

.prog.no-anim .prog-fill,
.prog.no-anim .prog-track {
  transition: none;
}

.prog-train {
  position: absolute;
  top: 50%;
  left: 0;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  color: var(--accent-ink);
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 25%, transparent), 0 3px 10px rgb(0 0 0 / 30%);
}

.prog-ends {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 8px;
  align-items: baseline;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.prog-ends span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prog-ends b {
  font-weight: 600;
  color: var(--accent);
}

.prog-ends span:where(:last-child) {
  text-align: right;
}

.prog.is-unknown .prog-fill,
.prog.is-unknown .prog-track {
  display: none;
}

/* ไทม์ไลน์ */
.tl-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.tl-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.switch.sm {
  font-size: 12px;
}

.tl {
  margin: 0;
  padding: 0;
  list-style: none;
}

.tl-row {
  --tb: 14px;
  --tbw: 600;

  display: grid;
  grid-template-columns: 50px 26px minmax(0, 1fr);
  column-gap: 8px;
  min-height: 46px;
}

.tl-row.is-through {
  --tb: 12.5px;
  --tbw: 500;
  --ct: var(--muted);
}

.tl-time {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding-top: 11px;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
}

.tl-time b {
  font-size: var(--tb);
  font-weight: var(--tbw);
  color: var(--ct, var(--text));
}

.tl-time s {
  font-size: 11.5px;
  color: var(--muted);
}

.tl-rail {
  position: relative;
  display: flex;
  justify-content: center;
}

.tl-rail::before {
  position: absolute;
  inset: 0 auto 0 50%;
  width: 4px;
  margin-left: -2px;
  content: "";
  background: var(--line);
}

.tl-row.is-first .tl-rail::before {
  top: 18px;
}

.tl-row.is-last .tl-rail::before {
  bottom: calc(100% - 18px);
}

.tl-row.is-passed .tl-rail::before {
  background: var(--accent);
}

.tl-row.tl-train .tl-rail::before {
  background: linear-gradient(var(--accent), var(--line));
}

.tl-dot {
  position: relative;
  z-index: 1;
  width: 14px;
  height: 14px;
  margin-top: 12px;
  background: var(--panel-solid);
  border: 3px solid var(--muted);
  border-radius: 50%;
}

.tl-row.is-passed .tl-dot {
  background: var(--accent);
  border-color: var(--accent);
}

.tl-row.is-next .tl-dot {
  border-color: var(--accent);
}

.tl-row.is-first .tl-dot,
.tl-row.is-last .tl-dot {
  width: 18px;
  height: 18px;
  margin-top: 10px;
  border-radius: 5px;
}

.tl-row.is-through .tl-dot {
  width: 9px;
  height: 9px;
  margin-top: 15px;
  border-width: 2px;
}

.tl-row.is-cur .tl-dot {
  width: 20px;
  height: 20px;
  margin-top: 9px;
  background: var(--accent);
  border-color: #fff;
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 30%, transparent), 0 0 16px var(--accent);
}

.tl-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: flex-start;
  min-width: 0;
  padding: 9px 0 10px;
}

.tl-name {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.45;
}

.tl-row.is-passed .tl-name {
  font-weight: 500;
  color: var(--muted);
}

.tl-row.is-through .tl-name {
  font-size: 13px;
  font-weight: 400;
  color: var(--muted);
}

.tl-row.is-cur .tl-name,
.tl-row.is-next .tl-name {
  font-size: 16px;
  font-weight: 700;
}

.tl-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.pf {
  padding: 1px 7px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--card-hover);
  border-radius: 6px;
}

.pf.gate {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 15%, transparent);
}

.tl-status {
  font-size: 12px;
  font-weight: 600;
  color: var(--ct, var(--muted));
}

.tl-tag {
  padding: 0 6px;
  font-size: 11px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 6px;
}

.tl-tag.cur {
  font-weight: 600;
  color: var(--accent);
  border: 1px solid var(--accent);
}

.tl-cause {
  font-size: 12px;
  color: var(--warn-t);
}

.tl-bob {
  --i: 16px;

  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  margin-top: 8px;
  color: var(--accent-ink);
  background: var(--accent);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 25%, transparent), 0 4px 12px rgb(0 0 0 / 30%);
  animation: bob 1.4s ease-in-out infinite;
}

.tl-now {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
}

.tl-train small {
  font-size: 12.5px;
  color: var(--muted);
}

/* ป้ายสถานี */
.station-head {
  color: #fff;
  background: linear-gradient(160deg, #173b66, #0b1f3a);
}

.dt-chip {
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 600;
  background: rgb(0 0 0 / 22%);
  border: 1px solid rgb(255 255 255 / 20%);
  border-radius: 999px;
}

.sign {
  position: relative;
  margin: 12px 18px 14px;
  padding: 8px 16px 10px;
  font-size: inherit;
  font-weight: inherit;
  color: #0f172a;
  text-align: center;
  background: #fff;
  border-top: 8px solid #1968ab;
  border-radius: 12px;
  box-shadow: 0 8px 20px rgb(0 0 0 / 35%);
}

.sign::before,
.sign::after {
  position: absolute;
  bottom: -16px;
  width: 6px;
  height: 16px;
  content: "";
  background: #c8d3e3;
  border-radius: 0 0 2px 2px;
}

.sign::before {
  left: 22%;
}

.sign::after {
  right: 22%;
}

.sign-th {
  display: block;
  font-size: 30px;
  font-weight: 700;
  line-height: 1.35;
}

.sign-en {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: #475569;
}

.sign-abbr {
  position: absolute;
  top: 6px;
  right: 10px;
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
}

.board {
  --bd-cols: 64px 60px minmax(0, 1fr) 46px;

  padding: 4px 4px 6px;
  color: #e8eef7;
  background: #05080f;
  border: 1px solid #1a2436;
  border-radius: 14px;
  box-shadow: inset 0 0 30px rgb(0 0 0 / 60%);
}

.bd-head {
  display: grid;
  grid-template-columns: var(--bd-cols);
  gap: 8px;
  padding: 6px 10px;
  font-size: 11px;
  color: #7c8aa0;
  white-space: nowrap;
  border-bottom: 1px solid #1a2436;
}

.bd-head span:where(:last-child) {
  text-align: right;
}

.bd-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.bd-list li + li {
  border-top: 1px dashed #1a2436;
}

.bd-row {
  display: grid;
  grid-template-columns: var(--bd-cols);
  gap: 8px;
  align-items: center;
  width: 100%;
  padding: 9px 10px;
  text-align: left;
  border-radius: 8px;
  transition: background 0.15s;
}

.bd-row:hover {
  background: rgb(255 194 51 / 7%);
}

.bd-time {
  --led: #ffc233;
  --glow: rgb(255 194 51 / 45%);

  display: flex;
  flex-direction: column;
  font-family: var(--mono);
  line-height: 1.2;
}

.bd-time b {
  font-size: 17px;
  font-weight: 600;
  color: var(--led);
  text-shadow: 0 0 8px var(--glow);
}

.bd-time s {
  font-size: 11px;
  color: #6b7a90;
}

/* จอดนานกว่า 1 นาที: เวลาออกใต้เวลาถึง */
.bd-time .bd-dep {
  font-size: 11px;
  color: #9aa7ba;
  white-space: nowrap;
}

/* เส้นคั่น "พรุ่งนี้" ก่อนแถวของวันถัดไป */
.bd-list li.bd-day {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 10px 4px;
  font-size: 12px;
  font-weight: 600;
  color: #ffc233;
  border-top: 0;
}

.bd-list li.bd-day::before,
.bd-list li.bd-day::after {
  flex: 1;
  height: 1px;
  content: "";
  background: #3a4a66;
}

.bd-list li.bd-day + li {
  border-top: 0;
}

.bd-train {
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: flex-start;
  min-width: 0;
}

.bd-pill {
  padding: 3px 7px;
  font: normal 600 14px/1.1 var(--mono);
  color: var(--tfg);
  background: var(--tbg);
  border-radius: 6px;
}

.bd-train small {
  max-width: 100%;
  overflow: hidden;
  font-size: 10.5px;
  color: #9aa7ba;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bd-dest {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

/* ชื่อปลายทางยาว (เช่นภาษาอังกฤษ "Ubon Ratchathani") ขึ้นบรรทัดใหม่ได้ 2 บรรทัด ไม่ตัดทิ้ง */
.bd-dest b {
  display: -webkit-box;
  overflow: hidden;
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.3;
  color: #f1f5f9;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.bd-dest small {
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ป้าย LED มืดเสมอ → ใช้สีสว่างคงที่ไม่ขึ้นกับธีม */
.board .lv0 {
  --led: #ffc233;

  color: #4ade80;
}

.board .lv1 {
  --led: #ff9f1a;
  --glow: rgb(255 159 26 / 45%);

  color: #fbbf24;
}

.board .lv2 {
  --led: #ff5a4f;
  --glow: rgb(255 90 79 / 45%);

  color: #f87171;
}

.bd-pf {
  display: grid;
  place-items: center;
  justify-self: end;
  width: 34px;
  height: 30px;
  font: 600 15px var(--mono);
  color: #ffc233;
  background: #101a2a;
  border: 1px solid #25324a;
  border-radius: 6px;
}

.bd-row.is-cxl .bd-dest b {
  text-decoration: line-through;
}

.board-hint {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
}

/* ---------- แผนที่: ปุ่ม/คำอธิบาย/แจ้งเตือน ---------- */
.map-ctl {
  position: fixed;
  right: 16px;
  bottom: 30px;
  z-index: 900;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: right 0.28s var(--ease);
}

.fab {
  width: 44px;
  height: 44px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.legend {
  position: fixed;
  bottom: 16px;
  left: calc(32px + var(--panel-w));
  z-index: 900;
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 8px 16px;
  font-size: 12.5px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.legend span {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
}


.legend em {
  font-style: normal;
}

.lg-short {
  display: none;
}

.dot {
  --c: var(--ok);

  width: 12px;
  height: 12px;
  margin-right: 7px;
  background: var(--c);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgb(0 0 0 / 25%), 0 0 6px var(--c);
}

.dot.warn {
  --c: var(--warn);
}

.dot.bad {
  --c: var(--bad);
}

.dot.idle,
.dot.hollow {
  --c: var(--idle);

  background: #fff;
  border: 3px solid var(--c);
  box-shadow: 0 0 0 1px rgb(0 0 0 / 25%);
}

.dot.hollow {
  --c: var(--ok);
}

.dot.cargo {
  --c: var(--cargo);

  border-radius: 3px;
}

.dot.stale {
  --c: var(--idle);

  background: transparent;
  border: 2px dashed var(--idle);
  box-shadow: none;
}

/* คำอธิบาย "ขาดรายงาน" เฉพาะจอกว้างที่มีที่ (จอเล็ก: อธิบายใน tooltip/รายละเอียดขบวนแทน) */
.legend .lg-wide {
  display: none;
}

.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  z-index: 1300;
  max-width: min(92vw, 460px);
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  pointer-events: none;
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translate(-50%, -12px);
  transition: opacity 0.25s, transform 0.25s var(--ease);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* แชร์ไม่ได้/คัดลอกไม่ได้ → ให้เลือกข้อความลิงก์คัดลอกเองได้ */
.toast.is-select {
  overflow-wrap: anywhere;
  pointer-events: auto;
  user-select: text;
}

/* ---------- desktop: ขยับปุ่มเมื่อเปิดรายละเอียด ---------- */
@media (min-width: 900px) {
  .has-detail .map-ctl {
    right: calc(32px + var(--detail-w));
  }

  .has-detail .leaflet-bottom.leaflet-right {
    right: calc(32px + var(--detail-w));
  }
}

@media (min-width: 900px) and (max-width: 1299px) {
  .has-detail .legend {
    display: none;
  }
}

/* จอเตี้ย (เช่น 1280×720): ย่อหัวรายละเอียดให้ไทม์ไลน์มีที่ */
@media (min-width: 900px) and (max-height: 780px) {
  .dt-no {
    font-size: 44px;
  }

  .dt-kicker {
    margin-top: 6px;
  }

  .dt-head {
    padding-bottom: 12px;
  }

  .sign-th {
    font-size: 26px;
  }
}

/* ---------- มือถือ/แท็บเล็ต: แผ่นเลื่อนด้านล่าง ---------- */
@media (max-width: 899px) {
  body {
    font-size: 14.5px;
  }

  .panel {
    inset: auto 0 0;
    width: auto;
    height: calc(100dvh - 48px);
    padding-bottom: env(safe-area-inset-bottom);
    border-bottom: 0;
    border-radius: 22px 22px 0 0;
    transform: translateY(calc(100% - var(--peek) - env(safe-area-inset-bottom)));
    transition: transform 0.34s var(--ease);
  }

  .panel[data-snap="half"] {
    transform: translateY(calc(44dvh - 48px));
  }

  .panel[data-snap="full"] {
    transform: none;
  }

  .panel[data-snap="half"] .views {
    padding-bottom: calc(44dvh - 32px);
  }

  .panel.is-dragging,
  .detail.is-dragging {
    transition: none;
  }

  .panel-grip {
    display: flex;
    flex: none;
    justify-content: center;
    padding: 9px 0 3px;
    cursor: grab;
    touch-action: none;
  }

  .panel-grip span,
  .dt-grip span {
    width: 42px;
    height: 5px;
    background: var(--grip, var(--muted));
    border-radius: 3px;
    opacity: 0.55;
  }

  .brand {
    padding: 2px 10px 10px 16px;
    touch-action: none;
  }

  .brand-logo {
    width: 40px;
    height: 40px;
  }

  .brand h1 {
    font-size: 19px;
  }

  .search input {
    height: 44px;
    font-size: 16px;
  }

  .stats {
    gap: 6px;
    margin-top: 10px;
  }

  .stat {
    padding: 6px 8px;
  }

  .stat b {
    font-size: 20px;
  }

  .fchip {
    height: 36px;
  }

  .detail {
    inset: auto 0 0;
    width: auto;
    height: calc(100dvh - 48px);
    background: var(--panel-solid);
    border-bottom: 0;
    border-radius: 22px 22px 0 0;
    transform: translateY(calc(30dvh - 48px));
    transition: transform 0.3s var(--ease);
    animation: sheet-in 0.32s var(--ease);
  }

  .detail[data-snap="full"] {
    transform: none;
  }


  .dt-head {
    padding: 0 14px 12px;
    touch-action: none;
  }

  .dt-grip {
    display: flex;
    justify-content: center;
    padding: 9px 0 7px;
    cursor: grab;
  }

  .train-head .dt-grip {
    --grip: currentcolor;
  }

  .station-head .dt-grip {
    --grip: #fff;
  }

  .dt-kicker {
    margin-top: 6px;
    font-size: 13px;
  }

  .dt-no {
    font-size: 42px;
  }

  .dt-route b {
    font-size: 15.5px;
  }

  .dt-summary {
    padding: 10px 12px 0;
  }

  .dt-body {
    padding: 10px 12px 20px;
  }

  .detail[data-snap="half"] .dt-body {
    padding-bottom: calc(30dvh - 24px);
  }

  .sign-th {
    font-size: 24px;
  }

  .map-ctl {
    top: calc(10px + env(safe-area-inset-top));
    right: 10px;
    bottom: auto;
  }

  .map-ctl .zoom-btn {
    display: none;
  }

  /* ไม่ทับปุ่มดูทั้งประเทศ (ขวาบน 44px) — ข้อความยาว (อังกฤษ/จอแคบ) ขึ้น 2 แถวแทน */
  .legend {
    top: calc(10px + env(safe-area-inset-top));
    bottom: auto;
    left: 10px;
    flex-wrap: wrap;
    gap: 2px 10px;
    max-width: calc(100vw - 72px);
    min-height: 44px;
    padding: 5px 12px;
    font-size: 11.5px;
    border-radius: 22px;
  }

  /* แผ่นเลื่อนเต็มจอ: ซ่อนคำอธิบายหมุด/ปุ่มแผนที่ที่โผล่เหนือแผ่น (ไม่ทับขอบแผ่น และแตะผิดไม่ได้) */
  .panel[data-snap="full"] ~ .legend,
  .panel[data-snap="full"] ~ .map-ctl,
  .detail:not([hidden])[data-snap="full"] ~ .legend,
  .detail:not([hidden])[data-snap="full"] ~ .map-ctl {
    visibility: hidden;
  }


  .legend .lg-long {
    display: none;
  }

  .legend .lg-short {
    display: inline;
  }

  .dot {
    width: 10px;
    height: 10px;
    margin-right: 5px;
  }

  .toast {
    top: calc(64px + env(safe-area-inset-top));
  }

  /* เครดิตแผนที่: ย่อเป็นปุ่ม ⓘ เหนือแผ่นเลื่อน แตะเพื่อขยาย */
  .leaflet-bottom.leaflet-right {
    bottom: var(--peek);
  }

  .leaflet-control-attribution {
    max-width: calc(100vw - 20px);
    margin: 0 8px 6px 0 !important;
    font-size: 10px;
    border-radius: 10px;
  }

  .leaflet-control-attribution:not(.is-open) {
    position: relative;
    width: 26px;
    height: 26px;
    padding: 0 !important;
    overflow: hidden;
    color: transparent !important;
    white-space: nowrap;
    cursor: pointer;
    border-radius: 50%;
  }

  .leaflet-control-attribution:not(.is-open) > * {
    visibility: hidden;
  }

  .leaflet-control-attribution:not(.is-open)::after {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font: italic 700 14px/1 Georgia, serif;
    color: var(--text);
    content: "i";
  }
}

/* แท็บเล็ตแนวตั้ง: แผ่นเลื่อนไม่กว้างเต็มจอ */
@media (min-width: 640px) and (max-width: 899px) {
  .panel,
  .detail {
    max-width: 620px;
    margin-inline: auto;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 380px) {
  .legend {
    gap: 2px 8px;
    padding: 5px 10px;
    font-size: 11px;
  }

  .stat span {
    font-size: 10.5px;
  }

  .tab {
    --i: 0;

    gap: 3px;
  }
}

/* ---------- มือถือแนวนอน / จอเตี้ย: แผ่นด้านซ้ายที่เลื่อนได้ทั้งแผ่น แผนที่อยู่ด้านขวา ----------
   (แผ่นเลื่อนด้านล่างสูงไม่พอ: รายการ/แท็บ/ตารางเวลาหลุดจอ) — ตรงกับ LAND_MQ ใน util.js */
@media (max-width: 899px) and (max-height: 500px) {
  :root {
    --side-w: clamp(280px, 46vw, 380px);
    --side-l: calc(8px + env(safe-area-inset-left));
  }

  .panel,
  .panel[data-snap] {
    inset: 8px auto 8px var(--side-l);
    width: var(--side-w);
    max-width: none;
    height: auto;
    margin: 0;
    padding-bottom: 6px;
    overflow-y: auto;
    overscroll-behavior: contain;
    border: 1px solid var(--line);
    border-radius: 18px;
    transform: none;
    transition: none;
    scrollbar-color: var(--line) transparent;
    scrollbar-width: thin;
  }

  /* ย่อ = การ์ดมุมบนซ้าย (ยังเลื่อนดูต่อได้) · แตะ grip = เต็มความสูง */
  .panel[data-snap="peek"] {
    bottom: auto;
    max-height: min(var(--peek), calc(100dvh - 16px));
  }

  .panel .views,
  .panel[data-snap="half"] .views {
    flex: none;
    padding-bottom: 8px;
    overflow: visible;
  }

  .panel-grip {
    padding: 6px 0 2px;
  }

  .brand {
    padding: 2px 10px 6px 14px;
    touch-action: auto;
  }

  .brand-logo {
    width: 34px;
    height: 34px;
  }

  .brand h1 {
    font-size: 17px;
  }

  .search input {
    height: 40px;
  }

  .stats {
    margin-top: 8px;
  }

  .stat {
    padding: 4px 8px;
  }

  .stat b {
    font-size: 18px;
  }

  .quick {
    gap: 6px;
    margin-top: 8px;
  }

  .chip-btn {
    height: 38px;
    font-size: 13px;
  }

  .tabs {
    margin-top: 8px;
  }

  /* รายละเอียดขบวน/สถานี: ทับแผงหลักด้านซ้าย เลื่อนทั้งแผ่น (หัว + สรุป + ตารางเวลา) */
  .detail,
  .detail[data-snap] {
    display: block;
    inset: 8px auto 8px var(--side-l);
    width: var(--side-w);
    max-width: none;
    height: auto;
    margin: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    border: 1px solid var(--line);
    border-radius: 18px;
    transform: none;
    transition: none;
    animation: detail-in 0.28s var(--ease);
    scrollbar-color: var(--line) transparent;
    scrollbar-width: thin;
  }

  .detail .dt-body,
  .detail[data-snap="half"] .dt-body {
    padding-bottom: 16px;
    overflow: visible;
    mask-image: none;
  }

  .dt-grip {
    display: none;
  }

  .dt-head {
    padding-top: 10px;
    touch-action: auto;
  }

  .dt-kicker {
    margin-top: 4px;
  }

  .dt-no {
    font-size: 34px;
  }

  /* คำอธิบายหมุด/ปุ่ม อยู่บนแผนที่ด้านขวาของแผ่น (ไม่ซ่อนตอนแผ่นเต็มความสูง) */
  .legend {
    top: calc(8px + env(safe-area-inset-top));
    left: calc(var(--side-l) + var(--side-w) + 8px);
    max-width: calc(100vw - var(--side-l) - var(--side-w) - 72px);
    min-height: 36px;
    padding: 4px 10px;
  }

  .map-ctl {
    top: calc(8px + env(safe-area-inset-top));
    right: calc(8px + env(safe-area-inset-right));
  }

  .panel[data-snap="full"] ~ .legend,
  .panel[data-snap="full"] ~ .map-ctl,
  .detail:not([hidden])[data-snap="full"] ~ .legend,
  .detail:not([hidden])[data-snap="full"] ~ .map-ctl {
    visibility: visible;
  }

  .toast {
    top: 56px;
    left: calc(var(--side-l) + var(--side-w) + (100vw - var(--side-l) - var(--side-w)) / 2);
    max-width: calc(100vw - var(--side-l) - var(--side-w) - 24px);
  }

  .leaflet-bottom.leaflet-right {
    bottom: 0;
  }
}

/* ---------- จอสัมผัส: พื้นที่แตะอย่างน้อย ~40px (ขยายด้วย pseudo-element ภาพเท่าเดิม) ---------- */
@media (pointer: coarse) {
  .lang-btn,
  .fchip {
    position: relative;
  }

  .lang-btn::after,
  .fchip::after {
    position: absolute;
    inset: -5px -2px;
    content: "";
  }

  .fchip::after {
    inset: -3px 0;
  }

  .switch {
    min-height: 40px;
  }

  .tab {
    height: 40px;
  }

  /* หมุดขบวนที่ซูมไกลเป็นจุดเล็ก → ขยายพื้นที่แตะรอบจุด (ไม่เปลี่ยนภาพ) */
  .tm-puck::after {
    position: absolute;
    inset: -12px;
    content: "";
    border-radius: 50%;
  }

  .zs .tm-puck::after {
    inset: -14px;
  }

  .leaflet-control-attribution:not(.is-open) {
    width: 32px;
    height: 32px;
  }
}

/* ---------- animations ---------- */
@keyframes sweep {
  to {
    transform: rotate(1turn);
  }
}

@keyframes ping {
  from {
    opacity: 0.7;
    transform: scale(1);
  }

  to {
    opacity: 0;
    transform: scale(2.8);
  }
}

@keyframes halo {
  from {
    opacity: 0.9;
    transform: scale(0.6);
  }

  to {
    opacity: 0;
    transform: scale(1.7);
  }
}

@keyframes ring {
  0% {
    transform: scale(0.85);
  }

  50% {
    transform: scale(1.1);
  }

  100% {
    transform: scale(0.85);
  }
}

@keyframes me-pulse {
  0% {
    box-shadow: 0 0 0 0 rgb(59 130 246 / 55%);
  }

  100% {
    box-shadow: 0 0 0 18px rgb(59 130 246 / 0%);
  }
}

@keyframes bob {
  50% {
    transform: translateY(-4px);
  }
}

@keyframes spin {
  to {
    transform: rotate(1turn);
  }
}

@keyframes detail-in {
  from {
    opacity: 0;
    transform: translateX(24px);
  }
}

@keyframes sheet-in {
  from {
    transform: translateY(100%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .brand-logo::before,
  .live-dot::after,
  .tm.is-sel::before,
  .st-hl,
  .me-dot,
  .tl-bob {
    animation: none;
  }

  .tx .tm-icon,
  .prog-fill,
  .prog-track {
    transition: none;
  }

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* ภาษาอังกฤษ: คำอธิบายหมุดยาวกว่าไทย → ตอนเปิดแผงรายละเอียดบนจอกว้าง ใช้แบบสั้น (ไม่ทับแผง) */
@media (min-width: 1300px) {
  .legend .lg-wide {
    display: inline-flex;
  }

  .has-detail .legend .lg-wide,
  .has-locate .legend .lg-wide {
    display: none;
  }

  html[lang="en"] .has-detail .legend .lg-long,
  html[lang="en"] .has-locate .legend .lg-long {
    display: none;
  }

  html[lang="en"] .has-detail .legend .lg-short,
  html[lang="en"] .has-locate .legend .lg-short {
    display: inline;
  }
}
