:root { --bb-primary: #0d6efd; --bb-sheet-h: 46vh; }
html, body { font-family: "IBM Plex Sans Thai", system-ui, sans-serif; }
body { background: #fff; }

/* ── admin ─────────────────────────────────────────── */
body.admin.full { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
body.admin.full main { flex: 1; min-height: 0; display: flex; padding: 0 !important; }
.map-fill { flex: 1; min-height: 300px; }
.side { width: 360px; max-width: 45vw; overflow-y: auto; border-right: 1px solid #dee2e6; background: #fafbfc; }
@media (max-width: 768px) {
  body.admin.full main { flex-direction: column-reverse; }
  .side { width: 100%; max-width: none; max-height: 45vh; border-right: 0; border-top: 1px solid #dee2e6; }
}
.table-sm td, .table-sm th { vertical-align: middle; }
.route-chip { display: inline-block; min-width: 2.2em; padding: .05em .45em; border-radius: .4em; color: #fff;
  font-weight: 600; text-align: center; font-size: .85em; line-height: 1.5; white-space: nowrap; }
.dot { display: inline-block; width: .7em; height: .7em; border-radius: 50%; }
.dot.moving { background: #198754; } .dot.stopped { background: #fd7e14; }
.dot.stale { background: #adb5bd; } .dot.offline { background: #dc3545; }
.list-group-item.active-row { background: #e7f1ff; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; }

/* ── vehicle marker ───────────────────────────────── */
.bus-marker { position: relative; }
.bus-marker .b { width: 30px; height: 30px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; color: #fff; font-size: 11px; font-weight: 700; }
.bus-marker .arrow { position: absolute; left: 50%; top: 50%; width: 0; height: 0; margin-left: -6px; margin-top: -25px;
  border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 9px solid; transform-origin: 6px 25px; }
.bus-marker.oos .b { background: repeating-linear-gradient(45deg, #6c757d, #6c757d 4px, #adb5bd 4px, #adb5bd 8px) !important; }
.bus-marker.stale .b { opacity: .5; }
.stop-marker { width: 14px; height: 14px; border-radius: 50%; background: #fff; border: 3px solid #0d6efd; }
.stop-marker.terminal { width: 18px; height: 18px; border-radius: 4px; border-color: #212529; }
.me-marker { width: 18px; height: 18px; border-radius: 50%; background: #0d6efd; border: 3px solid #fff;
  box-shadow: 0 0 0 6px rgba(13,110,253,.25); }
.dest-marker { font-size: 30px; color: #dc3545; line-height: 1; text-shadow: 0 1px 2px rgba(0,0,0,.4); }
.leaflet-popup-content { font-family: inherit; margin: 10px 12px; }

/* ── public app ──────────────────────────────────── */
body.pub { height: 100dvh; overflow: hidden; }
#pubmap { position: absolute; inset: 0 0 var(--bb-sheet-h) 0; }
.pub-top { position: absolute; top: max(8px, env(safe-area-inset-top)); left: 8px; right: 8px; z-index: 1000; display: flex; gap: 6px; }
.pub-top .search { flex: 1; position: relative; }
.pub-top .search input { border-radius: 2em; padding-left: 2.2em; box-shadow: 0 2px 8px rgba(0,0,0,.2); border: 0; height: 44px; }
.pub-top .search .bi-search { position: absolute; left: .9em; top: 50%; transform: translateY(-50%); color: #6c757d; }
.pub-top .rbtn { width: 44px; height: 44px; border-radius: 50%; border: 0; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.2); font-size: 1.2rem; }
.search-results { position: absolute; top: 48px; left: 0; right: 0; background: #fff; border-radius: .6em; box-shadow: 0 4px 16px rgba(0,0,0,.2);
  max-height: 50vh; overflow-y: auto; }
.map-fab { position: absolute; right: 10px; bottom: calc(var(--bb-sheet-h) + 12px); z-index: 1000; display: flex; flex-direction: column; gap: 8px; }
.map-fab button { width: 44px; height: 44px; border-radius: 50%; border: 0; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.25); font-size: 1.2rem; }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; height: var(--bb-sheet-h); background: #fff; z-index: 1001;
  border-radius: 14px 14px 0 0; box-shadow: 0 -2px 12px rgba(0,0,0,.18); display: flex; flex-direction: column; transition: height .2s; }
.sheet.tall { --bb-sheet-h: 82vh; height: 82vh; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: #ced4da; margin: 6px auto 2px; cursor: pointer; }
.sheet .tabs { display: flex; border-bottom: 1px solid #e9ecef; }
.sheet .tabs button { flex: 1; border: 0; background: none; padding: .45em 0 .4em; color: #6c757d; font-size: .9rem; border-bottom: 3px solid transparent; }
.sheet .tabs button.on { color: var(--bb-primary); border-bottom-color: var(--bb-primary); font-weight: 600; }
.sheet .tabs button .bi { display: block; font-size: 1.15rem; }
.sheet .body { flex: 1; overflow-y: auto; padding: .6em .8em calc(.8em + env(safe-area-inset-bottom)); }
.route-item { display: flex; align-items: center; gap: .6em; padding: .55em .2em; border-bottom: 1px solid #f1f3f5; cursor: pointer; }
.route-item:hover { background: #f8f9fa; }
.route-item .meta { flex: 1; min-width: 0; }
.route-item .meta .n { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.eta-big { font-size: 1.35rem; font-weight: 700; line-height: 1.1; }
.eta-row { display: flex; align-items: center; gap: .6em; padding: .5em 0; border-bottom: 1px solid #f1f3f5; }
.eta-row .eta { margin-left: auto; text-align: right; }
.leg { display: flex; gap: .6em; padding: .35em 0; }
.leg .ic { width: 2em; text-align: center; color: #6c757d; }
.opt { border: 1px solid #e9ecef; border-radius: .6em; padding: .6em .7em; margin-bottom: .6em; cursor: pointer; }
.opt.sel { border-color: var(--bb-primary); box-shadow: 0 0 0 2px rgba(13,110,253,.2); }
.tt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(4.2em, 1fr)); gap: .3em; }
.tt-grid span { text-align: center; background: #f1f3f5; border-radius: .35em; padding: .15em 0; font-variant-numeric: tabular-nums; }
.tt-grid span.past { color: #adb5bd; text-decoration: line-through; background: #f8f9fa; }
.tt-grid span.next { background: #198754; color: #fff; font-weight: 600; }
.tt-grid span.running { background: #0d6efd; color: #fff; }
.small-muted { font-size: .82rem; color: #6c757d; }
.pill { display: inline-block; padding: .05em .55em; border-radius: 1em; font-size: .78rem; background: #e9ecef; }
.pill.late { background: #f8d7da; color: #842029; } .pill.ontime { background: #d1e7dd; color: #0f5132; }
.pill.early { background: #fff3cd; color: #664d03; }

/* ปุ่มติดตั้งแอป */
.pub-top .install-btn { width: auto; border-radius: 2em; padding: 0 .9em; display: flex; align-items: center; gap: .3em;
  background: #0d6efd; color: #fff; font-size: .95rem; font-weight: 600; white-space: nowrap; }
.pub-top .install-btn .bi { font-size: 1.05rem; }
@media (max-width: 360px) { .pub-top .install-btn span { display: none; } }
.install-step { display: flex; gap: .7em; align-items: flex-start; margin-bottom: .8em; }
.install-step .n { flex: 0 0 1.7em; height: 1.7em; border-radius: 50%; background: #0d6efd; color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: .9rem; }
.ios-share { display: inline-block; padding: 0 .3em; border: 1px solid #ced4da; border-radius: .3em; color: #0d6efd; }
.pub .leaflet-top.leaflet-right { top: calc(max(8px, env(safe-area-inset-top)) + 52px); }

/* รถที่ส่งตำแหน่งสด: วงกระเพื่อม + ขอบเข้ม ให้เด่นจากเส้นสายสีเดียวกัน */
.bus-marker .b { position: relative; z-index: 2; box-shadow: 0 0 0 2px #212529, 0 2px 6px rgba(0,0,0,.5); }
.bus-marker .pulse { position: absolute; left: 50%; top: 50%; width: 30px; height: 30px; margin: -15px 0 0 -15px;
  border-radius: 50%; border: 3px solid; animation: bbPulse 1.8s ease-out infinite; z-index: 1; pointer-events: none; }
@keyframes bbPulse { 0% { transform: scale(1); opacity: .9 } 100% { transform: scale(2.6); opacity: 0 } }
.live-chip { position: absolute; top: calc(max(8px, env(safe-area-inset-top)) + 54px); left: 50%; transform: translateX(-50%);
  z-index: 1000; border: 0; border-radius: 2em; padding: .35em 1em; background: #198754; color: #fff; font-weight: 600;
  box-shadow: 0 2px 8px rgba(0,0,0,.25); font-size: .95rem; white-space: nowrap; }

/* ขนาดไอคอนรถ: คันที่เลือก (sel) ใหญ่+วงกระเพื่อม · คันอื่น (small) เล็กและจางลง */
.bus-marker.sel .b { width: 34px; height: 34px; font-size: 12px; box-shadow: 0 0 0 2px #212529, 0 2px 8px rgba(0,0,0,.55); }
.bus-marker.sel .pulse { width: 34px; height: 34px; margin: -17px 0 0 -17px; }
.bus-marker.sel .arrow { margin-left: -6px; margin-top: -28px; transform-origin: 6px 28px; }
.bus-marker.small .b { width: 22px; height: 22px; font-size: 9px; border-width: 2px; opacity: .78;
  box-shadow: 0 1px 3px rgba(0,0,0,.35); }
.bus-marker.small .arrow { margin-left: -4px; margin-top: -18px; border-left-width: 4px; border-right-width: 4px;
  border-bottom-width: 6px; transform-origin: 4px 18px; opacity: .78; }

/* ลูกศรทิศที่รถวิ่ง (เหลือง) — หมุนรอบจุดกลางรถ วางนอกวงไอคอน */
.bus-marker .hd { position: absolute; left: 50%; top: 50%; z-index: 3; pointer-events: none; }
.bus-marker .hd svg { display: block; filter: drop-shadow(0 1px 1.5px rgba(0,0,0,.45)); }
.bus-marker.small .hd { opacity: .85; }
