/* 巴士到站 — 樣式（跟系統深色 / 淺色） */

:root {
  color-scheme: dark light;
  --bg: #14161a;
  --surface: #1e2126;
  --row: #262930;
  --row-border: transparent;
  --line: #3a3f4b;
  --text: #f3f4f6;
  --dim: #a3aab8;
  --more: #d1d5db;
  --sched: #8b93a3;
  --soon: #fbbf24;
  --err: #f87171;
  --accent: #7ab4ff;
  --accent-text: #0b1220;
  --hover: #30343d;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #eef0f3;
    --surface: #ffffff;
    --row: #ffffff;
    --row-border: #d9dde4;
    --line: #d5d9e0;
    --text: #111827;
    --dim: #566070;
    --more: #374151;
    --sched: #6b7280;
    --soon: #b45309;
    --err: #c81e1e;
    --accent: #1d4ed8;
    --accent-text: #ffffff;
    --hover: #e9ecf1;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "PingFang HK", "PingFang TC", "Microsoft JhengHei UI", "Microsoft JhengHei", "Noto Sans TC", "Noto Sans CJK TC", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, p, ul { margin: 0; }
ul { padding: 0; list-style: none; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}

#sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- 頂部 ---------- */

.top, main { max-width: 560px; margin: 0 auto; }

.top { display: flex; align-items: center; gap: 4px; padding: 8px 6px 4px 16px; }
.top h1 { font-size: 1.0625rem; font-weight: 600; white-space: nowrap; }
.spacer { flex: 1; }

.status { min-width: 0; margin-left: 8px; overflow: hidden; text-overflow: ellipsis; font-size: 0.8125rem; color: var(--dim); font-variant-numeric: tabular-nums; white-space: nowrap; }
.status.is-err { color: var(--err); }

.icon-btn {
  display: grid; place-items: center; flex: none;
  width: 44px; height: 44px; padding: 0;
  border: 0; border-radius: 10px; background: none; color: var(--dim); cursor: pointer;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn:disabled { opacity: 0.35; cursor: default; background: none; }
.icon-btn[aria-pressed="true"] { color: var(--accent); }

@media (max-width: 359px) {
  .top { padding-left: 12px; }
  .top .status .pre { display: none; }
  .top .icon-btn { width: 40px; }
}

main { padding: 4px 12px 28px; }

/* ---------- 到站清單 ---------- */

.pipbar { display: none; }
.list { display: grid; gap: 6px; }

.row { background: var(--row); border: 1px solid var(--row-border); border-radius: 12px; overflow: hidden; }

.row-main {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px;
  width: 100%; min-height: 62px; padding: 8px 14px 8px 8px;
  border: 0; background: none; text-align: left; cursor: pointer;
}
.row-main:hover { background: var(--hover); }
.row-main:focus-visible { outline-offset: -2px; border-radius: 12px; }

.badge {
  display: grid; place-items: center;
  min-width: 60px; height: 46px; padding: 0 6px; border-radius: 8px;
  font-size: 1.0625rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: 0.01em;
}
.co-KMB { background: #d7282f; color: #ffffff; }
.co-CTB { background: #ffd200; color: #1a1a1a; }
.co-GMB { background: #15803d; color: #ffffff; }
.co-NLB { background: #0f6fa8; color: #ffffff; }

.info { display: grid; gap: 1px; min-width: 0; }
.dest, .stop { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.dest { font-weight: 500; }
.stop { font-size: 0.8125rem; color: var(--dim); }

.eta { display: grid; justify-items: end; gap: 1px; text-align: right; font-variant-numeric: tabular-nums; }
.eta-first { font-size: 1.375rem; font-weight: 700; line-height: 1.2; white-space: nowrap; }
.eta-more { display: flex; gap: 8px; min-height: 1.15em; font-size: 0.8125rem; color: var(--more); white-space: nowrap; }

.is-sched { color: var(--sched); }
.is-soon { color: var(--soon); }
.is-none { color: var(--dim); }
.is-err { color: var(--err); }

.detail { display: grid; gap: 3px; padding: 8px 14px 10px 80px; border-top: 1px solid var(--line); font-size: 0.875rem; }
.detail .line { display: flex; gap: 12px; }
.detail .t { font-variant-numeric: tabular-nums; min-width: 3.1em; }
.detail .r, .detail .msg { color: var(--dim); }

/* ---------- 空白狀態、提示 ---------- */

.empty { padding: 36px 12px 8px; text-align: center; }
.empty h2 { font-size: 1.125rem; font-weight: 600; }
.empty p { margin-top: 6px; color: var(--dim); }

.note { margin-top: 12px; padding: 16px; border: 1px dashed var(--line); border-radius: 12px; text-align: center; color: var(--dim); }
.note .btn { margin-top: 10px; }

.main-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }

/* ---------- 按鈕、輸入 ---------- */

.btn {
  min-height: 44px; padding: 0 18px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--row); color: var(--text);
  font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn.primary { border-color: transparent; background: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 0.875rem; }
.btn:disabled { opacity: 0.55; cursor: default; }

input[type="text"], select {
  min-height: 44px; width: 100%; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text);
  font-size: 16px; /* iOS：細過 16px 會自動放大畫面 */
}
input::placeholder { color: var(--dim); opacity: 1; }

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-row.end { justify-content: flex-end; }

/* ---------- 對話框 ---------- */

dialog { padding: 0; border: 0; background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }

.sheet {
  width: min(560px, 100%); max-width: 100%;
  max-height: 92vh; max-height: min(92dvh, 780px);
  margin: auto auto 0; border-radius: 16px 16px 0 0;
}
.sheet[open] { display: flex; flex-direction: column; }
@media (min-width: 600px) {
  .sheet { margin: auto; border-radius: 16px; }
}

.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 6px 8px 16px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { font-size: 1.0625rem; font-weight: 600; }

.sheet-body { display: grid; gap: 14px; align-content: start; overflow: auto; padding: 14px 16px calc(18px + env(safe-area-inset-bottom)); }
.sheet-body section { display: grid; gap: 10px; }
.sheet-body section + section { padding-top: 14px; border-top: 1px solid var(--line); }
.sheet-body h3 { font-size: 0.9375rem; font-weight: 600; }

.hint { font-size: 0.875rem; color: var(--dim); }
.hint:empty { display: none; }
.hint.is-err { color: var(--err); }

.field { display: grid; gap: 4px; }
.field label { font-size: 0.875rem; color: var(--dim); }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg button {
  min-height: 44px; padding: 0 8px;
  border: 1px solid var(--line); border-radius: 10px; background: none; color: var(--text); cursor: pointer;
}
.seg button:hover { background: var(--hover); }
.seg button[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); font-weight: 600; }

.search-row { display: flex; gap: 8px; }
.search-row input { flex: 1; min-width: 0; }

.stops li { display: flex; align-items: center; gap: 10px; min-height: 50px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.stops li:last-child { border-bottom: 0; }
.stops .n { flex: none; width: 1.8em; text-align: right; color: var(--dim); font-variant-numeric: tabular-nums; }
.stops .name { flex: 1; min-width: 0; }

.manage li { display: flex; align-items: center; gap: 2px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.manage li:last-child { border-bottom: 0; }
.manage .label { flex: 1; min-width: 0; display: grid; gap: 1px; padding-right: 6px; }
.manage .l1, .manage .l2 { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.manage .l2 { font-size: 0.8125rem; color: var(--dim); }
.manage .icon-btn { width: 40px; height: 44px; }

.share-box { display: grid; gap: 10px; }
.qr { justify-self: center; width: min(260px, 100%); padding: 0; border-radius: 8px; background: #ffffff; line-height: 0; }
.qr svg { display: block; width: 100%; height: auto; }

.modal { width: min(440px, calc(100% - 32px)); margin: auto; padding: 18px; border-radius: 16px; }
.modal[open] { display: grid; gap: 12px; }
.modal h2 { font-size: 1.0625rem; font-weight: 600; }
.imp-list { max-height: 34vh; overflow: auto; font-size: 0.875rem; color: var(--dim); display: grid; gap: 3px; }

/* ---------- 提示訊息 ---------- */

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 20;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 10px;
  background: var(--text); color: var(--bg); font-size: 0.9375rem; text-align: center;
  transform: translateX(-50%); opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity 0.2s, visibility 0.2s;
}
.toast.show { opacity: 1; visibility: visible; }

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}

/* ---------- 置頂小窗（Document Picture-in-Picture） ---------- */

body.pip { min-height: 0; padding: 4px 6px 6px; }
body.pip .pipbar { display: flex; align-items: center; justify-content: space-between; min-height: 32px; padding-left: 4px; }
body.pip .pipbar .status { margin-left: 0; }
body.pip .pipbar .icon-btn { width: 32px; height: 32px; }
body.pip .pipbar .icon { width: 18px; height: 18px; }
body.pip .list { gap: 4px; }
body.pip .row { border-radius: 10px; }
body.pip .row-main { min-height: 54px; padding: 5px 10px 5px 5px; gap: 10px; }
body.pip .badge { min-width: 52px; height: 42px; font-size: 1rem; }
body.pip .dest { font-size: 0.9375rem; }
body.pip .eta-first { font-size: 1.25rem; }
body.pip .detail { padding-left: 67px; }
