/* ══════════════════════════════════════════════════════════════
   mybustop — clean iOS-style chrome + real bus-stop LED board
   Light app shell, and per card a dark amber-on-black display
   panel like the big sign at a real bus stop.
   ══════════════════════════════════════════════════════════════ */
:root {
  /* light canvas */
  --canvas: #f5f5f7;
  --card: #ffffff;
  --ink: #1d1d1f;
  --ink-2: #6e6e73;
  --ink-3: #aeaeb2;
  --hairline: #e3e3e6;
  --accent: #007aff;
  --fill: rgba(118,118,128,.12);
  --sep-lt: rgba(60,60,67,.12);

  /* LED board — amber on near-black, like the stop display */
  --led-panel: #0f1318;
  --led-panel-hi: #1a2129;
  --led: #ffb546;
  --led-dim: rgba(255,181,70,.62);
  --led-faint: rgba(255,181,70,.38);
  --led-glow: 0 0 10px rgba(255,165,50,.38), 0 0 2px rgba(255,165,50,.5);
  --led-red: #ff6a5c;
  --led-line: rgba(255,181,70,.16);

  /* operator data colors (functional only) */
  --kmb: #e4002b;
  --ctb: #c79100;
  --gmb: #00994d;
  --nlb: #0069c0;

  --r-lg: 18px;
  --r-md: 12px;
  --spring: cubic-bezier(.32,.72,0,1);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }

body {
  background: var(--canvas);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
    "PingFang HK", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overscroll-behavior-y: none;
}
body.sheet-open { overflow: hidden; }
::selection { background: rgba(0,122,255,.18); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ── Nav bar (iOS style: edit | title | refresh +) ────────────── */
.appbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(245,245,247,.78);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--hairline);
  padding: calc(6px + env(safe-area-inset-top)) 10px 8px;
}
.appbar-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 6px;
}
.nav-side { display: flex; align-items: center; gap: 10px; min-width: 0; }
.nav-side.right { justify-content: flex-end; }
.nav-btn {
  font-family: inherit;
  background: none;
  border: none;
  cursor: pointer;
  -webkit-user-select: none; user-select: none;
}
.nav-btn.text {
  color: var(--accent);
  font-size: 17px;
  font-weight: 400;
  padding: 10px 10px 10px 4px;
  min-height: 44px;
}
.nav-btn.text:active { opacity: .35; }
.nav-btn.icon {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--fill);
  color: var(--ink);
  display: flex; align-items: center; justify-content: center;
}
.nav-btn.icon:active { opacity: .4; }
.nav-btn.icon.add { background: var(--accent); color: #fff; }
.nav-title {
  text-align: center;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.2px;
  white-space: nowrap;
}
.appbar-sub {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin-top: 2px;
  font-size: 11px;
  color: var(--ink-3);
}
.sub-sep { color: var(--ink-3); }
.sync-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: #30d158;
  animation: pulse 2.2s ease infinite;
}
.sync-progress {
  position: absolute; left: 0; right: 0; bottom: -1px;
  height: 2px; background: transparent;
}
.sync-progress.run::after {
  content: ""; display: block; height: 100%;
  background: linear-gradient(90deg, var(--accent), #2997ff);
  border-radius: 2px;
  transform-origin: left;
  animation: syncbar 30s linear forwards;
}
@keyframes syncbar { from { transform: scaleX(0); } to { transform: scaleX(1); } }

/* pull-to-refresh indicator */
.ptr {
  position: absolute;
  top: 100%; left: 0; right: 0;
  height: 0;
  overflow: hidden;
  display: flex; align-items: flex-start; justify-content: center;
  transition: height .22s ease;
  z-index: 9;
}
.ptr .spinner { margin-top: 8px; }

/* ── Edit mode banner ─────────────────────────────────────────── */
.edit-bar {
  display: flex; align-items: center; justify-content: space-between;
  background: #fff8e6; border-bottom: 1px solid #f2e3b3;
  color: #7a5b00; font-size: 13px; font-weight: 500;
  padding: 10px 20px;
}
.edit-done {
  font-family: inherit; border: none; background: none;
  color: var(--accent); font-size: 15px; font-weight: 600;
  padding: 8px 10px; cursor: pointer; min-height: 44px;
}

/* ── Board ────────────────────────────────────────────────────── */
.board {
  flex: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Card: minimal white panel holding the LED screen */
.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  padding: 16px 16px 14px;
  content-visibility: auto;
  contain-intrinsic-size: auto 220px;
  animation: cardIn .5s cubic-bezier(.2,.7,.2,1) both;
  animation-delay: calc(var(--i, 0) * 55ms);
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(14px) scale(.985); }
}
.card.flash .lcd-screen { animation: lcdflash .5s ease-out; }
@keyframes lcdflash { 0% { filter: brightness(1.25); } }

/* card header: operator dot + route + destination + co chip */
.card-head { display: flex; align-items: center; gap: 10px; }
.co-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.co-dot.kmb { background: var(--kmb); }
.co-dot.ctb { background: var(--ctb); }
.co-dot.gmb { background: var(--gmb); }
.co-dot.nlb { background: var(--nlb); }
.route-no {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.3px;
  flex-shrink: 0;
}
.head-text { min-width: 0; flex: 1; }
.dest-tc {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dest-en {
  font-size: 12.5px;
  color: var(--ink-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.co-chip {
  flex-shrink: 0;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--ink-2);
  border: 1px solid var(--hairline);
  border-radius: 9999px;
  padding: 3px 9px;
}

/* ── THE BUS-STOP LED BOARD ───────────────────────────────────── */
.lcd-screen {
  position: relative;
  margin-top: 12px;
  background: linear-gradient(180deg, var(--led-panel-hi), var(--led-panel) 55%);
  border-radius: var(--r-md);
  padding: 12px 14px 12px;
  /* bezel: dark frame + recessed glass */
  box-shadow:
    inset 0 0 0 1px rgba(0,0,0,.85),
    inset 0 2px 8px rgba(0,0,0,.6),
    0 1px 0 rgba(255,255,255,.05);
  overflow: hidden;
}
/* dot-pitch grid + faint scanlines, like LED modules */
.lcd-screen::before {
  content: "";
  position: absolute; inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(rgba(255,181,70,.055) 1px, transparent 1.15px),
    repeating-linear-gradient(0deg, rgba(0,0,0,.16) 0 1px, transparent 1px 4px);
  background-size: 4px 4px, auto;
}
.lcd-stop {
  position: relative;
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  letter-spacing: .04em;
  color: var(--led-dim);
  padding: 0 2px 9px;
  border-bottom: 1px solid var(--led-line);
  margin-bottom: 4px;
}
.lcd-stop .stop-tc {
  color: var(--led);
  font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lcd-stop .stop-en {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  opacity: .75;
}

/* ETA row on the board: next bus huge, followers smaller */
.etas {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 6px;
}
.eta-tile {
  flex: 1 1 0;
  min-width: 0;
  text-align: center;
  padding: 10px 2px 8px;
  border-radius: 8px;
  color: var(--led);
}
/* the next departure — the hero tile */
.eta-tile.next {
  flex: 1.5 1 0;
  background: rgba(255,181,70,.08);
  box-shadow: inset 0 0 0 1px rgba(255,181,70,.28);
  padding: 12px 2px 10px;
}
.eta-num {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 30px;
  font-weight: 600;
  line-height: 1.02;
  letter-spacing: -0.5px;
  text-shadow: var(--led-glow);
}
.eta-tile.next .eta-num { font-size: 58px; font-weight: 700; }
.eta-num small {
  font-size: 12px;
  font-weight: 500;
  color: var(--led-dim);
  margin-left: 3px;
  letter-spacing: 0;
  text-shadow: none;
}
.eta-tile.next .eta-num small { font-size: 14px; }
.eta-clock {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
  color: var(--led-faint);
  margin-top: 5px;
  letter-spacing: .06em;
}
.eta-tile.sched .eta-num { color: var(--led-dim); text-shadow: none; }
.eta-tile.arriving {
  display: flex; flex-direction: column; justify-content: center;
}
.eta-tile.arriving .eta-num {
  font-size: 19px;
  letter-spacing: .02em;
  padding: 6px 0 4px;
}
.eta-tile.next.arriving .eta-num { font-size: 26px; }
.eta-live-dot {
  display: inline-block;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--led);
  box-shadow: 0 0 8px rgba(255,165,50,.8);
  margin-right: 7px;
  vertical-align: 2px;
  animation: pulse 1.4s ease infinite;
}
@keyframes pulse { 50% { opacity: .3; } }

/* status rows rendered inside the board */
.lcd-status {
  position: relative;
  text-align: center;
  color: var(--led-dim);
  font-family: var(--mono);
  font-size: 13.5px;
  font-weight: 500;
  padding: 20px 0 16px;
  letter-spacing: .08em;
}
.lcd-status.err { color: var(--led-red); }

/* skeleton tiles while loading */
.sk { border-radius: 6px; background: rgba(255,181,70,.14); animation: shimmer 1.4s ease-in-out infinite; }
.sk-big { height: 34px; width: 60px; margin: 8px auto 0; }
.sk-sm { height: 11px; width: 40px; margin: 8px auto 2px; }
@keyframes shimmer { 50% { opacity: .4; } }

/* ── Edit mode ────────────────────────────────────────────────── */
body.editing .card { outline: 2px dashed #c9c9ce; outline-offset: -2px; }
.card-actions {
  display: none;
  position: absolute;
  top: 10px; right: 10px;
  gap: 8px;
  z-index: 2;
}
body.editing .card-actions { display: flex; }
.mini-btn {
  font-family: inherit;
  font-size: 15px;
  line-height: 1;
  width: 42px; height: 42px;
  background: var(--card);
  color: var(--ink-2);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  cursor: pointer;
}
.mini-btn:active { opacity: .4; }
.mini-btn.del { color: #ff3b30; border-color: #f3c1c3; }

/* ── Empty state ──────────────────────────────────────────────── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
}
.empty-art { margin-bottom: 6px; }
.pulse-ring { transform-origin: 60px 60px; animation: ringPulse 2.4s ease-out infinite; }
@keyframes ringPulse { 0% { transform: scale(.6); opacity: .9; } 100% { transform: scale(1.5); opacity: 0; } }
.mini-bus { animation: busDrive 4.5s ease-in-out infinite; }
@keyframes busDrive { 0%, 25% { transform: translateX(0); } 55%, 100% { transform: translateX(52px); } }
.empty-title { font-size: 19px; font-weight: 600; letter-spacing: -0.3px; }
.empty-sub { font-size: 13px; color: var(--ink-3); margin-top: 4px; }
.empty-cta {
  margin-top: 24px;
  font-family: inherit; font-size: 17px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: var(--accent); color: #fff;
  border: none; border-radius: 14px;
  padding: 14px 36px;
  cursor: pointer; min-height: 54px;
}
.cta-sub { font-size: 11px; font-weight: 400; opacity: .8; }
.empty-cta:active { opacity: .55; }

/* ── Bottom sheet (add-stop wizard) ───────────────────────────── */
.sheet {
  position: fixed;
  top: auto;                    /* beat UA dialog inset:0 */
  left: 0; right: 0; bottom: 0;
  width: 100%;
  max-width: 520px;
  margin-left: auto; margin-right: auto;
  max-height: 92dvh;
  border: none;
  border-radius: 20px 20px 0 0;
  background: var(--card);
  color: var(--ink);
  padding: 8px 20px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 40px rgba(0,0,0,.14);
  animation: sheetIn .45s var(--spring);
  overflow: visible;
}
@keyframes sheetIn { from { transform: translateY(70%); } }
.sheet.closing { animation: sheetOut .3s ease-in forwards; }
@keyframes sheetOut { to { transform: translateY(100%); } }
.sheet::backdrop {
  background: rgba(29,29,31,.4);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  animation: fade .3s ease both;
}
@keyframes fade { from { opacity: 0; } }
.sheet-grab {
  width: 36px; height: 5px; border-radius: 3px;
  background: rgba(60,60,67,.3);
  margin: 4px auto 12px;
}
.sheet-head {
  position: relative;
  display: flex; justify-content: center; align-items: center;
  margin-bottom: 16px;
}
.sheet-head h2 { font-size: 17px; font-weight: 600; letter-spacing: -0.2px; }
.sheet-close {
  position: absolute; right: 0; top: 50%;
  transform: translateY(-50%);
  display: flex; align-items: center; justify-content: center;
  background: var(--fill); border: none;
  color: var(--ink-2);
  width: 38px; height: 38px; border-radius: 50%; cursor: pointer;
}
.step { animation: stepIn .28s var(--spring); }
@keyframes stepIn { from { opacity: 0; transform: translateX(24px); } }

.field-label {
  display: block;
  color: var(--ink-2);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 8px;
}
.fl-en { color: var(--ink-3); font-weight: 500; }
.route-row { display: flex; gap: 8px; }
.route-input {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 18px;
  font-weight: 500;
  color: var(--ink);
  background: var(--fill);
  border: none;
  border-radius: 11px;
  padding: 12px 14px;
  outline: none;
  text-transform: uppercase;
  transition: box-shadow .18s, background .18s;
}
.route-input:focus { background: #fff; box-shadow: 0 0 0 2px var(--accent); }
.btn-primary {
  font-family: inherit;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 0 22px;
  min-width: 92px;
  min-height: 52px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:active { opacity: .55; }
.field-error { color: #e5484d; font-size: 13.5px; margin-top: 10px; font-weight: 500; }

.op-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.op-chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12.5px; font-weight: 500; color: var(--ink-2);
  background: var(--canvas);
  border-radius: 9999px; padding: 7px 12px;
}
.op-chip i { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.op-chip i.ctb { background: var(--ctb); }
.op-chip i.kmb { background: var(--kmb); }
.op-chip i.gmb { background: var(--gmb); }
.op-chip i.nlb { background: var(--nlb); }

/* iOS grouped lists for direction + stop picking */
.dir-choices, .stop-list {
  background: #fff;
  border: 1px solid var(--hairline);
  border-radius: 12px;
  overflow: hidden;
}
.stop-list {
  max-height: 52dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.dir-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  text-align: left;
  background: #fff;
  border: none;
  border-bottom: 1px solid var(--sep-lt);
  padding: 12px 16px;
  min-height: 60px;
  cursor: pointer;
  font-family: inherit;
  position: relative;
}
.dir-btn:last-child { border-bottom: none; }
.dir-btn:active { background: var(--sep-lt); }
.dir-co { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.dir-text { min-width: 0; }
.dir-tc { font-size: 16px; font-weight: 600; letter-spacing: -0.2px; }
.dir-tc small { color: var(--ink-3); font-weight: 400; }
.dir-en {
  font-size: 12.5px;
  color: var(--ink-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dir-btn::after, .stop-item::after {
  content: "›";
  margin-left: auto;
  color: rgba(60,60,67,.3);
  font-size: 21px;
  font-weight: 400;
  padding-left: 6px;
  flex-shrink: 0;
}
.stop-item {
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: #fff;
  border: none;
  border-bottom: 1px solid var(--sep-lt);
  color: var(--ink);
  font-family: inherit;
  padding: 13px 16px;
  min-height: 56px;
  cursor: pointer;
  font-size: 15.5px;
  font-weight: 500;
}
.stop-item:last-child { border-bottom: none; }
.stop-item:active { background: var(--sep-lt); }
.s-seq {
  color: var(--ink-3);
  font-size: 12.5px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  min-width: 22px;
}
.s-en { color: var(--ink-2); font-size: 12.5px; font-weight: 400; }

.sheet-foot {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 52px;
}
.btn-back {
  background: none; border: none;
  color: var(--accent); font-size: 17px; font-weight: 400;
  cursor: pointer; font-family: inherit;
  padding: 12px 14px 12px 0; min-height: 48px;
}
.btn-back:active { opacity: .35; }
.foot-hint { display: none; }
.loading {
  margin-top: 14px;
  font-size: 14px; color: var(--ink-2); font-weight: 500;
  display: flex; align-items: center; gap: 8px;
}
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--hairline);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toasts ───────────────────────────────────────────────────── */
.toast-zone {
  position: fixed;
  left: 16px; right: 16px;
  bottom: calc(28px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  z-index: 60; pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 14px;
  background: rgba(29,29,31,.92);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  color: #f5f5f7;
  font-size: 14px; font-weight: 500;
  border-radius: 9999px;
  padding: 12px 18px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
  animation: toastIn .32s cubic-bezier(.2,.8,.2,1);
  max-width: 92vw;
}
.toast.out { animation: toastOut .25s ease-in forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(.94); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px) scale(.96); } }
.toast-action {
  font-family: inherit; border: none; background: none;
  color: #6cb6ff; font-size: 14px; font-weight: 600;
  cursor: pointer; padding: 4px 2px; white-space: nowrap;
}

/* refresh icon spin */
#refreshBtn.spinning .refresh-ico { animation: spin .8s linear infinite; }

/* ── Footer ───────────────────────────────────────────────────── */
.footer {
  text-align: center;
  color: var(--ink-3);
  font-size: 11px;
  line-height: 1.8;
  max-width: 420px;
  margin: 0 auto;
  padding: 8px 14px calc(24px + env(safe-area-inset-bottom));
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
