/* 旅約電子簽 — 介面樣式（後台＋旅客簽署頁） */
:root {
  --bg: #f3f5f3; --surface: #ffffff; --sunk: #e9edea; --ink: #1b2320; --muted: #5d6a64; --line: #d8dfdb;
  --accent: #0e6a5b; --accent-soft: #dcefea; --accent-ink: #ffffff;
  --danger: #b3362a; --danger-soft: #f6e3e0;
  --ok: #22764a; --ok-soft: #dff1e6; --warn: #9a6200; --warn-soft: #f8ecd2; --info: #2d5d9a; --info-soft: #e1eaf6;
  --f-ui: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111614; --surface: #19201d; --sunk: #141a17; --ink: #e4ebe7; --muted: #97a69f; --line: #2b3531;
    --accent: #4fb8a3; --accent-soft: #18332d; --accent-ink: #0b1a16;
    --danger: #e46a5c; --danger-soft: #3a1f1c;
    --ok: #5cc386; --ok-soft: #17301f; --warn: #e3a740; --warn-soft: #352a14; --info: #7fa9e3; --info-soft: #1a2738;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--f-ui); font-size: 15px; line-height: 1.6; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; text-wrap: balance; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; }
.note, .sub, .crumb { color: var(--muted); font-size: 13px; }
.warn-t { color: var(--warn); }
.danger-t { color: var(--danger) !important; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.sp { flex: 1; }

/* 頂部 */
.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.top-in, .wrap { max-width: 1180px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.top-in { display: flex; align-items: center; gap: 8px 20px; flex-wrap: wrap; padding-block: 10px; }
.brand { display: flex; align-items: baseline; gap: 10px; text-decoration: none; color: var(--ink); min-width: 0; }
.brand b { font-size: 18px; letter-spacing: .04em; }
.brand span { color: var(--muted); font-size: 13px; }
.nav, .me { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a, .me a { text-decoration: none; color: var(--muted); padding: 6px 10px; border-radius: 8px; font-size: 14px; }
.nav a:hover, .me a:hover { background: var(--sunk); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.me { margin-left: auto; }
.wrap { padding-block: 24px 64px; display: flex; flex-direction: column; gap: 18px; }
.wrap.narrow { max-width: 460px; padding-top: 8vh; }

/* 按鈕 */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 14px; white-space: nowrap; text-decoration: none; }
.btn:hover { border-color: var(--muted); }
.btn.pri { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 500; }
.btn.pri:hover { filter: brightness(1.07); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent); }
.btn.block { width: 100%; padding: 12px; font-size: 15px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; filter: none; }
summary.btn { list-style: none; }
summary.btn::-webkit-details-marker { display: none; }

.bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.bar form { margin: 0; }
.summary { display: flex; flex-wrap: wrap; gap: 6px 28px; color: var(--muted); font-size: 14px; }
.summary b { color: var(--ink); font-size: 20px; margin-right: 4px; }
.tabs { display: flex; gap: 2px; background: var(--sunk); padding: 3px; border-radius: 999px; flex-wrap: wrap; }
.tabs a { padding: 5px 14px; border-radius: 999px; text-decoration: none; color: var(--muted); font-size: 14px; }
.tabs a[aria-current="page"] { background: var(--surface); color: var(--ink); font-weight: 500; box-shadow: 0 1px 2px rgba(0,0,0,.1); }
.search { display: flex; gap: 6px; }
.search input { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 10px; min-width: 0; width: 220px; max-width: 100%; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel.pad { padding: 20px; }
.tbl-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; min-width: 760px; }
.list th { text-align: left; font-weight: 500; font-size: 12px; letter-spacing: .06em; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.list td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.list tr:last-child td { border-bottom: 0; }
.list .acts { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.list .acts form { margin: 0; }
.empty-row { text-align: center; color: var(--muted); padding: 40px 14px !important; }
.tag { font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 6px; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 13px; white-space: nowrap; font-weight: 500; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.sent { background: var(--info-soft); color: var(--info); }
.pill.viewed { background: var(--warn-soft); color: var(--warn); }
.pill.signed { background: var(--ok-soft); color: var(--ok); }
.pill.void { background: var(--sunk); color: var(--muted); }

.flash { padding: 10px 14px; border-radius: 8px; background: var(--ok-soft); color: var(--ink); font-size: 14px; border-left: 3px solid var(--ok); }
.flash.err { background: var(--danger-soft); border-left-color: var(--danger); }
.callout { background: var(--sunk); border-radius: 8px; padding: 12px 14px; font-size: 14px; margin: 0; }
.callout.warn { background: var(--warn-soft); }
.checks { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.checks .ok { color: var(--ok); } .checks .bad { color: var(--danger); }

/* 表單 */
.form-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.form-main { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
fieldset { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); padding: 18px; margin: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; min-width: 0; }
legend { font-weight: 700; padding: 0 6px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.f { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.f.full { grid-column: 1 / -1; }
.f label, .lbl { font-size: 13px; font-weight: 500; }
.f input, .f select, .f textarea, .copyrow input, .copyrow textarea { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 9px 11px; width: 100%; }
.f textarea { resize: vertical; line-height: 1.6; }
.f input:focus, .f textarea:focus, .f select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.f small { color: var(--muted); font-size: 12px; }
.chk { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; line-height: 1.5; cursor: pointer; }
.chk input { margin-top: 2px; width: 18px; height: 18px; flex: none; accent-color: var(--accent); }
.chk.sm { font-size: 12px; }
details > summary { cursor: pointer; font-weight: 500; }
details.panel .grid2 { margin-top: 14px; }
.side { position: sticky; top: 76px; display: flex; flex-direction: column; gap: 12px; padding: 18px; }
.side h3 { font-size: 14px; color: var(--muted); font-weight: 500; }
.kv { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.kv b { font-weight: 500; }
.settings-form fieldset { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.seal-row { display: flex; flex-direction: row; gap: 20px; align-items: center; flex-wrap: wrap; }
.seal-preview { width: 140px; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 6px; }
.sticky-actions { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; border-top: 1px solid var(--line); }
.narrow-form { max-width: 640px; }

.copyrow { display: flex; gap: 8px; align-items: stretch; }
.copyrow input, .copyrow textarea { flex: 1; min-width: 0; background: var(--sunk); }
.copyrow textarea { resize: vertical; }
details.confirm { position: relative; }
.confirm-box { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px; width: 300px; max-width: 80vw; z-index: 5; box-shadow: 0 8px 24px rgba(0,0,0,.12); }

/* 檢視頁 */
.view-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.audit { position: sticky; top: 76px; max-height: calc(100vh - 100px); overflow: auto; }
.tl { list-style: none; margin: 0; padding: 0; }
.tl li { position: relative; padding: 0 0 14px 20px; font-size: 13px; word-break: break-word; }
.tl li::before { content: ""; position: absolute; left: 3px; top: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.tl li::after { content: ""; position: absolute; left: 6.5px; top: 17px; bottom: 0; width: 1px; background: var(--line); }
.tl li:last-child::after { display: none; }
.tl time { display: block; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.hash { word-break: break-all; background: var(--sunk); border-radius: 6px; padding: 8px 10px; }

/* 旅客端 */
.c-top { background: var(--surface); border-bottom: 1px solid var(--line); }
.c-top-in { max-width: 760px; margin: 0 auto; padding: 12px max(16px, env(safe-area-inset-right, 0px)) 12px max(16px, env(safe-area-inset-left, 0px)); display: flex; gap: 10px; align-items: center; }
.c-top b { display: block; font-size: 15px; line-height: 1.3; }
.c-top span { font-size: 12px; color: var(--muted); }
.lock { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); display: grid; place-items: center; font-size: 13px; flex: none; }
.c-wrap { max-width: 760px; margin: 0 auto; padding: 20px max(16px, env(safe-area-inset-right, 0px)) 60px max(16px, env(safe-area-inset-left, 0px)); display: flex; flex-direction: column; gap: 18px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 20px; }
.center-card { text-align: center; align-items: stretch; }
.deposit { display: flex; justify-content: space-between; align-items: baseline; background: var(--accent-soft); border-radius: 10px; padding: 12px 14px; text-align: left; }
.deposit b { font-size: 22px; color: var(--accent); }
.payinfo { text-align: left; background: var(--sunk); border-radius: 10px; padding: 12px 14px; font-size: 14px; }
.otp { letter-spacing: .5em; text-align: center; font-size: 22px !important; }
fieldset.choice { display: flex; flex-direction: column; gap: 8px; padding: 14px; }
fieldset.choice legend { font-size: 14px; }
.pad-wrap { border: 1px dashed var(--muted); border-radius: 12px; background: #fffdf7; position: relative; touch-action: none; }
.pad-wrap canvas { display: block; width: 100%; height: 200px; cursor: crosshair; border-radius: 12px; touch-action: none; }
.pad-wrap .hint { position: absolute; inset: 0; display: grid; place-items: center; color: #8a948f; pointer-events: none; font-size: 15px; }
.err { color: var(--danger); font-size: 14px; margin: 0; min-height: 1em; }
.done-mark { width: 64px; height: 64px; border-radius: 50%; background: var(--ok-soft); color: var(--ok); display: grid; place-items: center; font-size: 30px; margin: 4px auto 0; }

.paper-wrap { overflow-x: auto; }

/* PDF 產生中 */
.pdf-overlay { position: fixed; inset: 0; z-index: 9999; background: var(--bg); display: grid; place-items: center; padding: 20px; }
.pdf-overlay-box { text-align: center; }
.pdf-overlay-sub { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.spinner { width: 36px; height: 36px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; margin: 0 auto 12px; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .form-grid, .view-grid { grid-template-columns: minmax(0, 1fr); }
  .side, .audit { position: static; max-height: none; }
}
@media (max-width: 600px) {
  fieldset, .grid2, .settings-form fieldset { grid-template-columns: minmax(0, 1fr); }
  .me { margin-left: 0; }
  .search input { width: 100%; }
  .search { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
