
:root {
  --paper: #F1EEE3;
  --paper-deep: #E8E3D3;
  --surface: #F7F5EE;
  --moss: #4E5D45;
  --moss-deep: #3E4B37;
  --moss-soft: #DDE0D3;
  --ink: #2E2B24;
  --ink-soft: #5C574B;
  --ink-faint: #8A8474;
  --seal: #8B4A3D;
  --seal-deep: #733C31;
  --line: #D8D2C0;
  --amber: #B8863F;
  --amber-soft: #F1E4C8;
  --brick: #A64B3F;
  --brick-soft: #F0DAD4;
  --success: #4E5D45;

  --serif: "Noto Serif TC", "Source Han Serif TC", "Songti TC", serif;
  --sans: "Inter", "Noto Sans TC", -apple-system, "PingFang TC", sans-serif;

  --radius: 4px;
  --gutter: 16px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--moss); text-underline-offset: 3px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.35; margin: 0 0 .5em; letter-spacing: .02em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 1em; }
.muted { color: var(--ink-faint); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .02em; }

/* ── 表單 ─────────────────────────── */
label { display: block; font-size: .85rem; color: var(--ink-soft); margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.field .hint { font-size: .8rem; color: var(--ink-faint); margin-top: 4px; }
input[type=text], input[type=password], input[type=email], input[type=tel], input[type=date], input[type=search], select, textarea {
  width: 100%;
  font: inherit;
  font-size: 16px; /* 避免 iOS 聚焦時自動放大 */
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  min-height: 44px;
  -webkit-appearance: none;
  appearance: none;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-soft) 50%), linear-gradient(135deg, var(--ink-soft) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--moss); outline-offset: 1px; border-color: var(--moss); }
input[readonly] { background: var(--paper-deep); color: var(--ink-soft); }
.grid-2 { display: grid; gap: 0 16px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
fieldset { border: 0; border-top: 1px solid var(--line); margin: 20px 0 0; padding: 16px 0 0; }
.form-title { color: var(--moss-deep); }
label > input, label > select, label > textarea { margin-top: 4px; }
legend { font-family: var(--serif); font-weight: 600; padding-right: 10px; color: var(--moss-deep); }

/* ── 按鈕 ─────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-size: .95rem; font-weight: 500;
  min-height: 44px; padding: 0 18px;
  border-radius: var(--radius);
  border: 1px solid var(--moss);
  background: var(--moss); color: #F7F5EE;
  cursor: pointer; text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--moss-deep); }
.btn.secondary { background: transparent; color: var(--moss); }
.btn.secondary:hover { background: var(--moss-soft); }
.btn.seal { background: var(--seal); border-color: var(--seal); }
.btn.seal:hover { background: var(--seal-deep); }
.btn.danger { background: transparent; color: var(--brick); border-color: var(--brick); }
.btn.danger:hover { background: var(--brick-soft); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: .85rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .4; cursor: not-allowed; pointer-events: none; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
form.inline { display: inline; }

/* ── 提示訊息 ─────────────────────── */
.notice { border-left: 3px solid var(--moss); background: var(--moss-soft); padding: 10px 14px; margin-bottom: 16px; font-size: .92rem; }
.notice.warn { border-color: var(--amber); background: var(--amber-soft); }
.notice.error { border-color: var(--brick); background: var(--brick-soft); }

/* ── 狀態標籤 ─────────────────────── */
.tag { display: inline-block; font-size: .78rem; line-height: 1; padding: 5px 8px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.tag.ok { color: var(--success); }
.tag.warn { color: var(--amber); }
.tag.err { color: var(--brick); }
.tag.muted { color: var(--ink-faint); }

/* ── 員工端／登入頁：寬鬆留白 ──────── */
.quiet {
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 48px var(--gutter) calc(48px + env(safe-area-inset-bottom));
}
.quiet-inner { width: 100%; max-width: 380px; }
.quiet .brand { text-align: center; margin-bottom: 36px; }
.quiet .brand svg { width: 76px; height: 76px; }
.quiet .brand .word { font-family: var(--serif); letter-spacing: .32em; margin-top: 12px; color: var(--moss-deep); padding-left: .32em; }
.quiet h1 { text-align: center; font-size: 1.3rem; margin-bottom: 1.2em; }
.quiet .foot { text-align: center; margin-top: 28px; font-size: .88rem; }
.temp-password { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 1.5rem; letter-spacing: .12em; padding: 14px; text-align: center; border: 1px dashed var(--seal); color: var(--seal); background: var(--surface); margin: 12px 0; user-select: all; -webkit-user-select: all; }

/* ── 後台：密度較高 ────────────────── */
.shell { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  padding: env(safe-area-inset-top) var(--gutter) 0;
}
.topbar-row { display: flex; align-items: center; gap: 10px; height: 52px; }
.topbar .logo { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--moss-deep); }
.topbar .logo svg { width: 30px; height: 30px; }
.topbar .logo span { font-family: var(--serif); letter-spacing: .22em; font-size: .95rem; }
.topbar .who { margin-left: auto; font-size: .82rem; color: var(--ink-soft); text-align: right; line-height: 1.3; }
.nav { display: flex; gap: 2px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; margin: 0 calc(-1 * var(--gutter)); padding: 0 var(--gutter); }
.nav::-webkit-scrollbar { display: none; }
.nav a { flex: none; padding: 10px 12px; font-size: .92rem; color: var(--ink-soft); text-decoration: none; border-bottom: 2px solid transparent; }
.nav a.on { color: var(--ink); border-bottom-color: var(--seal); }
.main { flex: 1; width: 100%; max-width: 1080px; margin: 0 auto; padding: 20px var(--gutter) calc(40px + env(safe-area-inset-bottom)); }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 16px; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.page-head .actions { margin: 0 0 0 auto; }
.crumb { font-size: .85rem; margin-bottom: 6px; }
.crumb a { color: var(--ink-faint); }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.panel > h2:first-child { margin-top: 0; }
.panel.narrow { max-width: 560px; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
@media (min-width: 720px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; background: var(--surface); }
.stat .n { font-family: var(--serif); font-size: 1.6rem; line-height: 1.2; }
.stat .l { font-size: .82rem; color: var(--ink-faint); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.filters > * { flex: 1 1 160px; }
.filters .btn { flex: 0 0 auto; }

/* 表格：寬螢幕為表格，窄螢幕為堆疊列表 */
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-weight: 500; color: var(--ink-faint); font-size: .8rem; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table a.row-link { font-weight: 500; }
@media (max-width: 719px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: 10px 0; border-bottom: 1px solid var(--line); }
  .table tr:last-child { border-bottom: 0; }
  .table td { border: 0; padding: 2px 0; }
  .table td[data-label]::before { content: attr(data-label) "　"; color: var(--ink-faint); font-size: .8rem; }
  .table td.primary { font-size: 1rem; padding-bottom: 4px; }
}

.dl { display: grid; grid-template-columns: 7.5em 1fr; gap: 6px 12px; margin: 0; font-size: .92rem; }
.dl dt { color: var(--ink-faint); }
.dl dd { margin: 0; word-break: break-all; }
@media (min-width: 720px) { .dl.two { grid-template-columns: 7.5em 1fr 7.5em 1fr; } }

.pager { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }
.empty { text-align: center; padding: 28px 0; color: var(--ink-faint); }
a.stat { text-decoration: none; color: inherit; display: block; }
a.stat:hover { border-color: var(--moss); }

/* ── 合約內文 ─────────────────────── */
.contract-body { font-size: .98rem; line-height: 1.95; }
.contract-body h3 { font-size: 1.02rem; margin: 1.4em 0 .35em; color: var(--moss-deep); }
.contract-body p { margin: 0 0 .9em; text-align: justify; white-space: pre-line; }
textarea { width: 100%; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }

/* ── 公開簽署頁 ───────────────────── */
.quiet.top { justify-content: flex-start; padding-top: 28px; }
.quiet-inner.wide { max-width: 620px; }
.quiet.top .brand { margin-bottom: 20px; }
.quiet.top .brand svg { width: 48px; height: 48px; }
.quiet .lead { text-align: center; color: var(--ink-soft); }

/* 印章式進度圓點 */
.steps { list-style: none; display: flex; justify-content: space-between; margin: 0 0 28px; padding: 0; position: relative; }
.steps::before { content: ""; position: absolute; left: 14px; right: 14px; top: 13px; border-top: 1px dashed var(--line); }
.steps li { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: .75rem; color: var(--ink-faint); flex: 1; }
.steps .dot { width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--line); background: var(--paper); display: grid; place-items: center; font-family: var(--serif); font-size: .8rem; }
.steps li.on { color: var(--seal); }
.steps li.on .dot { border: 2px solid var(--seal); color: var(--seal); }
.steps li.done .dot { background: var(--seal); border-color: var(--seal); color: var(--paper); }
.step h1 { text-align: left; font-size: 1.3rem; margin-bottom: .4em; }
.step .sub { color: var(--ink-soft); font-size: .92rem; margin-bottom: 18px; }
.step .contract-body { background: var(--surface); border: 1px solid var(--line); padding: 18px 16px; border-radius: var(--radius); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: .95rem; color: var(--ink); margin: 18px 0; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--moss); flex: none; }
.check.disabled { color: var(--ink-faint); }
.step-nav { display: flex; flex-direction: column; gap: 10px; margin-top: 22px; }
.linkish { background: none; border: 0; color: var(--ink-soft); font: inherit; font-size: .9rem; text-decoration: underline; text-underline-offset: 3px; padding: 8px; cursor: pointer; }
.msg { font-size: .9rem; min-height: 1.4em; margin: 10px 0 0; }
.msg.err { color: var(--brick); }
.msg.ok { color: var(--moss); }

/* 證件拍攝：預覽畫面加上「身分確認用」提示（不寫入原圖） */
.captures { display: grid; gap: 14px; }
@media (min-width: 560px) { .captures { grid-template-columns: 1fr 1fr; } }
.capture { border: 1px dashed var(--line); border-radius: var(--radius); padding: 12px; background: var(--surface); }
.capture h3 { font-size: .95rem; margin: 0 0 8px; }
.preview { position: relative; aspect-ratio: 1.586; background: var(--paper-deep); border-radius: 3px; overflow: hidden; display: grid; place-items: center; color: var(--ink-faint); font-size: .85rem; margin-bottom: 10px; }
.preview img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.preview .wm { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; pointer-events: none; }
.preview.has .wm { display: flex; }
.preview .wm span { transform: rotate(-18deg); color: rgba(139,74,61,.78); border: 2px solid rgba(139,74,61,.7); padding: 4px 12px; font-family: var(--serif); font-size: 1.05rem; letter-spacing: .12em; background: rgba(241,238,227,.35); white-space: nowrap; }

/* 合約全文（PDF.js 逐頁繪製） */
.pdf-pages { display: flex; flex-direction: column; gap: 10px; background: var(--paper-deep); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.pdf-page { display: block; width: 100%; height: auto; background: #fff; border: 1px solid var(--line); }
.pdf-loading { text-align: center; color: var(--ink-faint); padding: 40px 0; margin: 0; }

/* 相機實拍：全螢幕、身分證比例對齊框 */
html.cam-open, html.cam-open body { overflow: hidden; }
.camera { position: fixed; inset: 0; z-index: 100; background: #000; height: 100dvh; color: #fff; }
.camera[hidden] { display: none; }
.camera video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cam-frame { position: absolute; left: 50%; top: 46%; transform: translate(-50%, -50%); width: min(88vw, 62dvh * 1.6); aspect-ratio: 1.6; border-radius: 10px; box-shadow: 0 0 0 200vmax rgba(0, 0, 0, .55); pointer-events: none; }
.cam-frame[hidden] { display: none; }
.cam-frame i { position: absolute; width: 30px; height: 30px; border: 3px solid #fff; }
.cam-frame .tl { left: -2px; top: -2px; border-right: 0; border-bottom: 0; border-top-left-radius: 10px; }
.cam-frame .tr { right: -2px; top: -2px; border-left: 0; border-bottom: 0; border-top-right-radius: 10px; }
.cam-frame .bl { left: -2px; bottom: -2px; border-right: 0; border-top: 0; border-bottom-left-radius: 10px; }
.cam-frame .br { right: -2px; bottom: -2px; border-left: 0; border-top: 0; border-bottom-right-radius: 10px; }
.cam-hint { position: absolute; left: 16px; right: 16px; top: calc(env(safe-area-inset-top) + 18px); text-align: center; margin: 0; font-size: .95rem; text-shadow: 0 1px 3px rgba(0,0,0,.6); }
.cam-error { position: absolute; left: 16px; right: 16px; top: 50%; transform: translateY(-50%); margin: 0; padding: 14px; background: var(--brick); border-radius: var(--radius); font-size: .92rem; line-height: 1.6; }
.cam-error[hidden] { display: none; }
.cam-bar { position: absolute; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 24px); display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 0 24px; gap: 12px; }
.cam-bar[hidden] { display: none; }
.cam-text { background: none; border: 0; color: #fff; font: inherit; font-size: 1rem; padding: 12px; justify-self: start; cursor: pointer; }
.shutter { width: 72px; height: 72px; border-radius: 50%; background: #fff; border: 5px solid rgba(255,255,255,.45); background-clip: padding-box; cursor: pointer; }
.shutter:disabled { opacity: .4; }
.cam-review { position: absolute; inset: 0; background: #000; }
.cam-review[hidden] { display: none; }
.cam-review img { position: absolute; left: 16px; right: 16px; top: 50%; transform: translateY(-55%); width: calc(100% - 32px); aspect-ratio: 1.6; object-fit: contain; }
.cam-review .cam-bar { grid-template-columns: 1fr 1fr; }
.cam-review .btn { justify-self: end; }

/* 簽名板 */
.sigpad { position: relative; margin: 0 4px; border: 1px solid var(--line); border-radius: var(--radius); background: #FBFAF6; touch-action: none; -webkit-user-select: none; user-select: none; overscroll-behavior: contain; }
.sigpad canvas { display: block; width: 100%; height: 220px; touch-action: none; cursor: crosshair; }
.sigpad::after { content: ""; position: absolute; left: 20px; right: 20px; bottom: 44px; border-top: 1px solid var(--line); pointer-events: none; }
.sigpad .hint { position: absolute; left: 0; right: 0; bottom: 18px; text-align: center; font-size: .8rem; color: var(--ink-faint); pointer-events: none; }
.sig-preview { max-width: 240px; max-height: 90px; display: block; }
.summary { font-size: .95rem; }
.id-review { border: 1px solid var(--amber); background: var(--amber-soft); border-radius: var(--radius); padding: 12px; }
.id-figure { margin: 0; }
.id-figure img { width: 100%; aspect-ratio: 1.6; object-fit: cover; border-radius: 3px; display: block; background: var(--paper-deep); }
.id-figure figcaption { font-size: .8rem; color: var(--ink-soft); margin-top: 4px; }
details > summary::-webkit-details-marker { display: none; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; overflow-x: auto; }
.tabs a { padding: 8px 12px; text-decoration: none; color: var(--ink-soft); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--seal); }
.tabs .count { font-size: .75rem; margin-left: 6px; color: var(--ink-faint); }
form.register fieldset:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
.consent-text { margin: 18px 0 0; font-size: .9rem; }
.consent-text summary { cursor: pointer; color: var(--moss); }
.cf-turnstile { margin: 12px 0; }
.range-field { display: flex; flex-direction: column; font-size: .75rem; color: var(--ink-faint); margin: 0; }
.range-field input { margin-top: 2px; min-height: 40px; padding: 6px 10px; }
.filters .range-field { flex: 1 1 140px; }
.summary-bar { display: flex; flex-wrap: wrap; gap: 8px 20px; font-size: .9rem; margin: 0 0 12px; color: var(--ink-soft); }
.summary-bar strong { color: var(--ink); font-family: var(--serif); font-size: 1.05rem; }
.duration { font-family: var(--serif); font-size: 1.3rem; color: var(--moss-deep); margin: 4px 0 14px; }
.duration.long { color: var(--seal); }
.change-item { padding: 12px 0; border-bottom: 1px solid var(--line); }
.change-item:last-child { border-bottom: 0; }
.change-item h3 { margin: 0 0 6px; }
.done-mark { text-align: center; margin: 8px 0 18px; }
.done-mark svg { width: 110px; height: 110px; transform: rotate(-8deg); }
