/* ==========================================================================
   旅程手帳 — 視覺方向：紙本票根 / 車票存根
   資料類文字（日期、時間、金額、班次）一律使用等寬字，
   敘述類文字使用系統 CJK 無襯線字。不載入外部字型，離線與各裝置都穩定。
   ========================================================================== */

:root {
  --ink: #16202b;
  --ink-2: #3d4d5f;
  --ink-3: #74869a;
  --paper: #e9edf1;
  --card: #ffffff;
  --card-2: #f5f7f9;
  --line: #d6dde5;
  --line-strong: #b9c4cf;
  --indigo: #2e5aac;
  --indigo-soft: #e6ecf9;
  --stamp: #c0392b;
  --stamp-soft: #fbe9e7;
  --mustard: #b8860b;
  --mustard-soft: #fbf1d8;
  --green: #1e7a5f;
  --shadow: 0 1px 2px rgba(22, 32, 43, .06), 0 6px 20px rgba(22, 32, 43, .07);
  --shadow-lift: 0 10px 34px rgba(22, 32, 43, .18);
  --r: 12px;
  --r-lg: 18px;
  --sans: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Hiragino Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e7edf3;
    --ink-2: #b3c0cd;
    --ink-3: #8496a8;
    --paper: #0e1620;
    --card: #18232f;
    --card-2: #1f2c3a;
    --line: #2b3a4a;
    --line-strong: #3d4f62;
    --indigo: #7fa4ee;
    --indigo-soft: #1c2c47;
    --stamp: #f0857a;
    --stamp-soft: #38221f;
    --mustard: #e8b02a;
    --mustard-soft: #33290f;
    --green: #5cc4a2;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .28);
    --shadow-lift: 0 10px 34px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--indigo); }

:focus-visible {
  outline: 2px solid var(--indigo);
  outline-offset: 2px;
  border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ---------- 版面 ---------- */

.wrap {
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 0 16px;
}

.page {
  padding-bottom: calc(96px + var(--safe-b));
  min-height: 100vh;
}

.boot {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  color: var(--ink-3);
  font-family: var(--mono);
  font-size: 13px;
}

.spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--indigo);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 頁首 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--ink);
  color: #f3f6f9;
  padding-top: env(safe-area-inset-top, 0px);
  box-shadow: 0 1px 0 rgba(0,0,0,.2);
}
.topbar .wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding-block: 8px;
}
.topbar .brand {
  font-size: 12px;
  letter-spacing: .22em;
  font-family: var(--mono);
  color: rgba(243,246,249,.6);
  text-transform: uppercase;
}
.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: .01em;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar h1.tappable { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.topbar .sub {
  font-family: var(--mono);
  font-size: 11px;
  color: rgba(243,246,249,.55);
  white-space: nowrap;
}
.icon-btn {
  background: rgba(255,255,255,.1);
  border: 0;
  color: inherit;
  width: 36px; height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  flex: none;
}
.icon-btn:hover { background: rgba(255,255,255,.2); }
.icon-btn svg { width: 18px; height: 18px; }

/* 頁首上的行程資訊條 */
.tripmeta {
  background: var(--ink);
  color: rgba(243,246,249,.7);
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: .04em;
  border-top: 1px dashed rgba(255,255,255,.18);
}
.tripmeta .wrap { display: flex; flex-wrap: wrap; gap: 4px 16px; padding-block: 7px; }

/* ---------- 主導覽（手機置底、桌機置頂） ---------- */

.mainnav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 25;
  background: var(--card);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  -webkit-backdrop-filter: saturate(1.6) blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.mainnav .wrap { display: flex; padding: 0; }
.mainnav a {
  flex: 1;
  text-decoration: none;
  color: var(--ink-3);
  display: grid;
  gap: 2px;
  justify-items: center;
  padding: 9px 2px 8px;
  font-size: 11px;
  border-top: 2px solid transparent;
  margin-top: -1px;
}
.mainnav a svg { width: 21px; height: 21px; }
.mainnav a[aria-current="page"] { color: var(--indigo); border-top-color: var(--indigo); }

@media (min-width: 760px) {
  .topbar { position: static; }
  .mainnav {
    position: sticky; top: 0; bottom: auto;
    border-top: 0; border-bottom: 1px solid var(--line);
    padding-bottom: 0;
  }
  .mainnav .wrap { max-width: 880px; margin: 0 auto; padding: 0 16px; gap: 4px; }
  .mainnav a {
    flex: none;
    grid-auto-flow: column;
    align-items: center;
    gap: 8px;
    padding: 13px 14px;
    font-size: 14px;
    border-top: 0;
    border-bottom: 2px solid transparent;
    margin: 0;
  }
  .mainnav a[aria-current="page"] { border-bottom-color: var(--indigo); }
  .page { padding-bottom: 64px; }
}

/* ---------- 區段標題 ---------- */

.section { padding-top: 22px; }
.section-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 0 0 12px;
}
.section-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .02em;
}
.eyebrow {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.section-head .rest { margin-left: auto; }

/* ---------- 票根式分頁（招牌元素） ---------- */

.stubs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  padding: 14px 16px 16px;
  margin: 0 -16px;
  scrollbar-width: none;
}
.stubs::-webkit-scrollbar { display: none; }

.stub {
  position: relative;
  flex: none;
  scroll-snap-align: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 1px dashed var(--line-strong);
  border-radius: 4px 12px 12px 4px;
  padding: 8px 14px 8px 16px;
  display: grid;
  gap: 1px;
  text-align: left;
  min-width: 78px;
  color: var(--ink-3);
  box-shadow: var(--shadow);
}
/* 撕線上的兩個缺口 */
.stub::before, .stub::after {
  content: "";
  position: absolute;
  left: -5px;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--paper);
  border: 1px solid var(--line);
}
.stub::before { top: -5px; }
.stub::after { bottom: -5px; }
.stub .n { font-family: var(--mono); font-size: 10px; letter-spacing: .14em; }
.stub .d { font-family: var(--mono); font-size: 15px; font-weight: 600; color: var(--ink); letter-spacing: .02em; }
.stub .w { font-size: 10.5px; }
.stub[aria-selected="true"] {
  background: var(--ink);
  border-color: var(--ink);
  border-left-color: rgba(255,255,255,.4);
  color: rgba(243,246,249,.65);
}
.stub[aria-selected="true"] .d { color: #fff; }
.stub[aria-selected="true"]::before, .stub[aria-selected="true"]::after { border-color: var(--ink); }
.stub .badge {
  position: absolute; top: -6px; right: -6px;
  min-width: 18px; height: 18px;
  border-radius: 9px;
  background: var(--mustard);
  color: #1b1400;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  display: grid; place-items: center;
  padding: 0 5px;
}

/* 一般膠囊分頁（指南 / 管理 / 成員） */
.pills {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 12px 16px;
  margin: 0 -16px;
  scrollbar-width: none;
}
.pills::-webkit-scrollbar { display: none; }
.pill {
  flex: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink-2);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13.5px;
  white-space: nowrap;
}
.pill[aria-selected="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }

/* ---------- 卡片 ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
}
.stack { display: grid; gap: 10px; }

/* 行程景點卡：左側虛線路徑軸 */
.spot {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 12px 14px 12px 14px;
}
.spot-line { position: relative; padding-left: 26px; }
.spot-line::before {
  content: "";
  position: absolute;
  left: 7px; top: 6px; bottom: 6px;
  border-left: 2px dashed var(--line-strong);
}
.spot-line > .stack > * { position: relative; }
.spot-line > .stack > *::before {
  content: "";
  position: absolute;
  left: -25px; top: 20px;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--card);
  border: 2px solid var(--line-strong);
}
.spot-line > .stack > .spot[data-cat="交通"]::before { border-color: var(--indigo); }
.spot-line > .stack > .spot[data-cat="住宿"]::before { border-color: #6b4e9b; }

.spot-top {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 4px 10px;
  align-items: start;
}
.spot-time {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  padding-top: 1px;
  min-width: 40px;
}
.spot-time.empty { color: var(--ink-3); font-weight: 400; }
.spot-name { margin: 0; font-size: 15.5px; font-weight: 600; line-height: 1.4; }
.spot-sub {
  grid-column: 2 / -1;
  display: flex; flex-wrap: wrap; gap: 6px 10px;
  align-items: center;
  font-size: 12px;
  color: var(--ink-3);
  font-family: var(--mono);
}
.chev { color: var(--ink-3); transition: transform .18s ease; }
.spot[aria-expanded="true"] .chev { transform: rotate(180deg); }

.tag {
  font-size: 11px;
  font-family: var(--mono);
  letter-spacing: .04em;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid currentColor;
  flex: none;
}
.tag[data-cat="吃"] { color: #b8541a; }
.tag[data-cat="交通"] { color: var(--indigo); }
.tag[data-cat="住宿"] { color: #7a5ab0; }
.tag[data-cat="逛街"] { color: #a83a63; }
.tag[data-cat="活動"] { color: var(--green); }
.tag[data-cat="景點"] { color: #0f7b8a; }
.tag.lock { color: var(--ink-3); }

.spot-body {
  display: none;
  border-top: 1px dashed var(--line);
  margin-top: 12px;
  padding-top: 12px;
  gap: 10px;
}
.spot[aria-expanded="true"] .spot-body { display: grid; }

.field { display: grid; gap: 2px; }
.field dt {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.field dd { margin: 0; font-size: 14px; white-space: pre-wrap; }
dl { margin: 0; display: grid; gap: 10px; }

.linkbox {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--indigo-soft);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 11px;
  color: var(--ink);
  font-size: 13.5px;
}
.linkbox:hover { border-color: var(--indigo); }
.linkbox .k {
  display: block;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--indigo);
  margin-bottom: 2px;
}

.row-actions { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 2px; }

/* ---------- 按鈕 ---------- */

.btn {
  border: 1px solid var(--line-strong);
  background: var(--card);
  color: var(--ink);
  border-radius: 9px;
  padding: 7px 13px;
  font-size: 13.5px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
}
.btn:hover { background: var(--card-2); }
.btn svg { width: 15px; height: 15px; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { opacity: .9; }
.btn.danger { color: var(--stamp); border-color: var(--line-strong); border-color: color-mix(in srgb, var(--stamp) 45%, transparent); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--card-2); }
.btn.sm { padding: 4px 10px; font-size: 12.5px; }
.btn.block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn.add {
  border-style: dashed;
  border-color: var(--line-strong);
  color: var(--ink-2);
  background: transparent;
  justify-content: center;
  width: 100%;
  padding: 12px;
}
.btn.add:hover { border-color: var(--indigo); color: var(--indigo); background: var(--card); }

.fab {
  position: fixed;
  right: 16px;
  bottom: calc(70px + var(--safe-b) + 12px);
  z-index: 22;
  background: var(--ink);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 13px 19px;
  font-size: 14.5px;
  font-weight: 600;
  display: inline-flex;
  gap: 7px;
  align-items: center;
  box-shadow: var(--shadow-lift);
}
.fab svg { width: 17px; height: 17px; }
@media (min-width: 760px) { .fab { bottom: 24px; right: calc(50vw - 440px + 16px); } }
@media (min-width: 760px) and (max-width: 928px) { .fab { right: 24px; } }

/* ---------- 空狀態 ---------- */

.empty {
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-lg);
  padding: 30px 20px;
  text-align: center;
  color: var(--ink-3);
  background: transparent;
  background: color-mix(in srgb, var(--card) 55%, transparent);
}
.empty strong { display: block; color: var(--ink); font-size: 15px; margin-bottom: 4px; }
.empty p { margin: 0 0 14px; font-size: 13.5px; }

/* ---------- 首頁行程卡 ---------- */

.trip {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 12px 12px 12px 6px;
  touch-action: pan-y;
}
.trip.dragging { box-shadow: var(--shadow-lift); transform: rotate(-.35deg); opacity: .97; }
.drag-ph {
  border: 1px dashed var(--indigo);
  border-radius: var(--r);
  background: var(--indigo-soft);
}
.handle {
  border: 0;
  background: transparent;
  color: var(--ink-3);
  width: 34px; height: 42px;
  display: grid; place-items: center;
  touch-action: none;
  border-radius: 8px;
}
.handle:hover { background: var(--card-2); color: var(--ink); }
.handle svg { width: 16px; height: 16px; }
.trip-link { text-decoration: none; color: inherit; display: grid; gap: 3px; min-width: 0; }
.trip-link h3 { margin: 0; font-size: 16.5px; font-weight: 700; }
.trip-link .meta { font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); letter-spacing: .02em; }
.trip-link .where { font-size: 12.5px; color: var(--ink-2); }
.trip-tools { display: flex; gap: 2px; }

/* ---------- 收付結算 ---------- */

.balances {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.bal {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line-strong);
  border-radius: var(--r);
  padding: 10px 12px;
  box-shadow: var(--shadow);
}
.bal .who { font-size: 13.5px; font-weight: 600; }
.bal .amt { font-family: var(--mono); font-size: 19px; font-weight: 700; letter-spacing: -.01em; }
.bal .note { font-family: var(--mono); font-size: 10.5px; color: var(--ink-3); letter-spacing: .08em; text-transform: uppercase; }
.bal.pos { border-left-color: var(--green); } .bal.pos .amt { color: var(--green); }
.bal.neg { border-left-color: var(--stamp); } .bal.neg .amt { color: var(--stamp); }

.settle-hint {
  font-size: 13px;
  color: var(--ink-2);
  background: var(--mustard-soft);
  border-radius: 10px;
  padding: 10px 12px;
  display: grid;
  gap: 4px;
}
.settle-hint b { font-family: var(--mono); }

/* 明細列 */
.line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  align-items: baseline;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 10px 12px;
  box-shadow: var(--shadow);
}
.line .name { font-size: 14.5px; font-weight: 600; }
.line .amount { font-family: var(--mono); font-size: 15px; font-weight: 700; text-align: right; }
.line .meta { grid-column: 1; font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); }
.line .tools { grid-column: 2; justify-self: end; display: flex; gap: 2px; }
.line .note { grid-column: 1 / -1; font-size: 13px; color: var(--ink-2); white-space: pre-wrap; }

.daymark {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .14em;
  color: var(--ink-3);
  margin: 18px 0 8px;
}
.daymark::after { content: ""; flex: 1; border-top: 1px dashed var(--line-strong); }

/* ---------- 清單（行李、規範…） ---------- */

.item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
}
.item:last-child { border-bottom: 0; }
.item .qty { font-family: var(--mono); font-size: 13px; color: var(--ink-3); }
.item .tools { display: flex; gap: 2px; }
.item .txt { font-size: 14.5px; }
.item .txt small { display: block; color: var(--ink-3); font-size: 12px; }

.catgroup { margin-bottom: 12px; }
.cathead {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px;
  font-family: var(--mono);
  letter-spacing: .1em;
  color: var(--ink-2);
  padding: 0 2px 6px;
}
.cathead .count { color: var(--ink-3); }

.numbered { counter-reset: r; display: grid; gap: 8px; }
.numbered .rule {
  counter-increment: r;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: start;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 11px 12px;
  box-shadow: var(--shadow);
}
.numbered .rule::before {
  content: counter(r, decimal-leading-zero);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--stamp);
  padding-top: 3px;
  letter-spacing: .06em;
}
.numbered .rule p { margin: 0; font-size: 14.5px; white-space: pre-wrap; }

/* 緊急資訊 */
.sos { display: grid; gap: 10px; }
.sos .row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--stamp);
  border-radius: var(--r);
  padding: 11px 12px;
  box-shadow: var(--shadow);
}
.sos .row.plain { border-left-color: var(--line-strong); }
.sos .label { font-size: 14.5px; font-weight: 600; }
.sos .note { font-size: 12.5px; color: var(--ink-3); white-space: pre-wrap; }
.call {
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
  color: var(--stamp);
  border: 1px solid var(--line-strong);
  border-color: color-mix(in srgb, var(--stamp) 40%, transparent);
  background: var(--stamp-soft);
  border-radius: 9px;
  padding: 6px 12px;
  white-space: nowrap;
}

/* 票券住宿檢視 */
.ticket {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  display: grid;
  gap: 10px;
}
.ticket.focus { border-color: var(--mustard); box-shadow: 0 0 0 3px var(--mustard-soft), var(--shadow); }
.ticket-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  align-items: baseline;
  border-bottom: 1px dashed var(--line);
  padding-bottom: 9px;
}
.ticket-head .t { font-size: 15.5px; font-weight: 700; margin: 0; }
.ticket-head .code { font-family: var(--mono); font-size: 11.5px; color: var(--ink-3); letter-spacing: .06em; }
.leg {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  font-size: 14px;
  align-items: baseline;
}
.leg .tm { font-family: var(--mono); font-weight: 600; }
.leg .arrow { grid-column: 1; color: var(--ink-3); font-family: var(--mono); font-size: 11px; }
.kv { display: grid; grid-template-columns: 88px 1fr; gap: 4px 10px; font-size: 13.5px; }
.kv dt { font-family: var(--mono); font-size: 11px; letter-spacing: .08em; color: var(--ink-3); text-transform: uppercase; }
.kv dd { margin: 0; white-space: pre-wrap; }

/* ---------- 表單 / 對話框 ---------- */

.scrim {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(12, 20, 28, .55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  animation: fade .16s ease;
}
@keyframes fade { from { opacity: 0 } }
@keyframes rise { from { transform: translateY(18px); opacity: .6 } }

.sheet {
  background: var(--card);
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  animation: rise .2s ease;
  box-shadow: var(--shadow-lift);
}
@media (min-width: 620px) {
  .scrim { align-items: center; padding: 24px; }
  .sheet { border-radius: var(--r-lg); max-height: 88vh; }
}
.sheet-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.sheet-head h2 { margin: 0; font-size: 16px; font-weight: 700; flex: 1; }
.sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  display: grid;
  gap: 14px;
}
.sheet-foot {
  display: flex;
  gap: 10px;
  padding: 12px 16px calc(12px + var(--safe-b));
  border-top: 1px solid var(--line);
  background: var(--card-2);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
}
.sheet-foot .btn { flex: 1; justify-content: center; padding: 10px; }

.f { display: grid; gap: 6px; }
.f > label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.f .req { color: var(--stamp); }
.f .hint { font-size: 11.5px; color: var(--ink-3); }
.f input[type=text], .f input[type=number], .f input[type=date], .f input[type=time], .f textarea, .f select {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 10px 11px;
  font-size: 16px; /* iOS Safari 聚焦時不會自動放大 */
  appearance: none;
  -webkit-appearance: none;
  min-height: 44px;
}
.f input[type=date], .f input[type=time], .f input[type=number] { font-family: var(--mono); }
.f textarea { min-height: 88px; resize: vertical; line-height: 1.55; }
.f select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%2374869a' stroke-width='1.6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 11px;
  padding-right: 32px;
}
.f input:focus, .f textarea:focus, .f select:focus { border-color: var(--indigo); outline: none; box-shadow: 0 0 0 3px var(--indigo-soft); }
.f .pair { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; }
.f .pair .tilde { color: var(--ink-3); font-family: var(--mono); }
.f .err { color: var(--stamp); font-size: 12px; }
.f .readonly {
  background: var(--card-2);
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
  padding: 10px 11px;
  font-size: 14px;
  color: var(--ink-2);
  white-space: pre-wrap;
}
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.checks label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 14px;
  background: var(--card);
  min-height: 40px;
}
.checks input { accent-color: var(--indigo); width: 16px; height: 16px; }
.checks label:has(input:checked) { border-color: var(--indigo); background: var(--indigo-soft); }

.dialog-msg { font-size: 14.5px; color: var(--ink-2); white-space: pre-wrap; }

/* ---------- 密碼閘 ---------- */

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.gate form {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 26px 22px;
  display: grid;
  gap: 14px;
  position: relative;
}
.gate .mark {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .26em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.gate h1 { margin: 0; font-size: 21px; letter-spacing: .02em; }
.gate p { margin: 0; font-size: 13.5px; color: var(--ink-3); }
.gate input {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 12px;
  font-size: 16px;
  font-family: var(--mono);
  background: var(--card);
  min-height: 46px;
}
.gate input:focus { border-color: var(--indigo); outline: none; box-shadow: 0 0 0 3px var(--indigo-soft); }
.gate .err { color: var(--stamp); font-size: 13px; min-height: 19px; }
.gate .perf { border-top: 1px dashed var(--line-strong); padding-top: 14px; }

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

#toast-root {
  position: fixed;
  left: 50%;
  bottom: calc(84px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 80;
  display: grid;
  gap: 8px;
  width: max-content;
  max-width: calc(100vw - 32px);
  pointer-events: none;
}
.toast {
  background: var(--ink);
  color: #f2f6fa;
  border-radius: 10px;
  padding: 10px 15px;
  font-size: 13.5px;
  box-shadow: var(--shadow-lift);
  animation: rise .18s ease;
}
@media (prefers-color-scheme: dark) { .toast { background: #2c3d4f; } }
.toast.bad { background: var(--stamp); color: #fff; }

/* ---------- 同步狀態 ---------- */

.syncdot {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: .1em;
  color: rgba(243,246,249,.5);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}
.syncdot i { width: 6px; height: 6px; border-radius: 50%; background: var(--green); display: block; }
.syncdot[data-state="saving"] i { background: var(--mustard); animation: pulse 1s ease-in-out infinite; }
.syncdot[data-state="error"] i { background: var(--stamp); }
@keyframes pulse { 50% { opacity: .25 } }

.locknote {
  font-size: 12px;
  color: var(--ink-3);
  background: var(--card-2);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  gap: 7px;
  align-items: flex-start;
}
.locknote svg { width: 13px; height: 13px; flex: none; margin-top: 3px; }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
