:root {
  --bg: #f2f4f7;
  --card: #ffffff;
  --ink: #1b1f24;
  --muted: #5d6673;
  --line: #d5dae1;
  --brand: #1f4e79;
  --brand-ink: #ffffff;
  --ok: #1b7f3b;
  --ok-bg: #e3f4e8;
  --ng: #c62828;
  --ng-bg: #fde7e7;
  --na: #59636e;
  --na-bg: #eceff2;
  --warn: #8a5a00;
  --warn-bg: #fff4d6;
  --ai: #6b3fa0;
  --ai-bg: #f1eafa;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  background: var(--brand); color: var(--brand-ink);
}
.top-title { font-weight: 700; font-size: 18px; }
.top-btn { background: transparent; color: var(--brand-ink); border: 1px solid rgba(255,255,255,.6); border-radius: 8px; padding: 6px 10px; font-size: 14px; }
main { max-width: 720px; margin: 0 auto; padding: 16px 16px 120px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card h2 { margin: 0 0 10px; font-size: 18px; }
.card h3 { margin: 14px 0 8px; font-size: 16px; }
.muted { color: var(--muted); font-size: 14px; }
.stepper { display: flex; gap: 6px; margin-bottom: 14px; overflow-x: auto; }
.stepper span { flex: 0 0 auto; font-size: 13px; padding: 4px 10px; border-radius: 999px; background: var(--na-bg); color: var(--muted); }
.stepper span.on { background: var(--brand); color: #fff; }
.stepper span.done { background: var(--ok-bg); color: var(--ok); }

label.f { display: block; font-size: 14px; color: var(--muted); margin: 10px 0 4px; }
input[type=text], input[type=date], input[type=password], textarea, select {
  width: 100%; font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
textarea { min-height: 64px; resize: vertical; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; border-radius: 10px; padding: 12px 16px; border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.ai { background: var(--ai); border-color: var(--ai); color: #fff; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.sm { padding: 6px 10px; font-size: 14px; font-weight: 500; }
.row-btns { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.row-btns .btn { flex: 1 1 140px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { font: inherit; font-size: 15px; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip.ai-sug { border: 2px dashed var(--ai); }

.tpl-list { display: grid; gap: 8px; }
.tpl { text-align: left; font: inherit; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: #fff; cursor: pointer; }
.tpl.on { border: 2px solid var(--brand); background: #eef4fa; }
.tpl.ai-sug { border: 2px dashed var(--ai); }
.tpl small { display: block; color: var(--muted); }

.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.ph { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: #dde2e8; }
.ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph .x { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 16px; }
.ph .rot { position: absolute; bottom: 4px; right: 4px; border: 0; border-radius: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; padding: 3px 6px; }
.ph .idx { position: absolute; top: 4px; left: 4px; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; border-radius: 6px; padding: 1px 6px; }
.add-photo { display: flex; align-items: center; justify-content: center; aspect-ratio: 1; border: 2px dashed var(--line); border-radius: 8px; color: var(--muted); font-size: 14px; cursor: pointer; text-align: center; padding: 6px; }

.item { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; background: #fff; }
.item.missing { border-color: var(--warn); background: var(--warn-bg); }
.item .path { font-size: 13px; color: var(--muted); }
.item .name { font-weight: 700; margin: 2px 0; }
.item .std { font-size: 14px; white-space: pre-line; background: var(--na-bg); border-radius: 8px; padding: 6px 8px; margin: 6px 0; }
.item .ai-note { font-size: 13px; color: var(--ai); background: var(--ai-bg); border-radius: 8px; padding: 6px 8px; margin: 6px 0; }
.res { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0; }
.res button { font: inherit; font-size: 17px; font-weight: 700; padding: 12px 4px; border-radius: 10px; border: 1px solid var(--line); background: #fff; cursor: pointer; }
.res button.sug { border: 2px dashed var(--ai); }
.res button.on.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.res button.on.ng { background: var(--ng); border-color: var(--ng); color: #fff; }
.res button.on.na { background: var(--na); border-color: var(--na); color: #fff; }
.phrases { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.phrases button { font: inherit; font-size: 13px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--na-bg); cursor: pointer; }
.grid-in { width: 100%; border-collapse: collapse; margin-top: 6px; }
.grid-in th, .grid-in td { border: 1px solid var(--line); padding: 2px; font-size: 13px; text-align: center; }
.grid-in input { width: 100%; border: 0; padding: 6px 2px; font: inherit; font-size: 14px; text-align: center; min-width: 0; }

.notice { border-radius: 10px; padding: 10px 12px; font-size: 14px; margin: 10px 0; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.ai { background: var(--ai-bg); color: var(--ai); }
.notice.err { background: var(--ng-bg); color: var(--ng); }
.notice ul { margin: 4px 0 0; padding-left: 20px; }

.sig-wrap { border: 1px solid var(--line); border-radius: 10px; background: #fff; position: relative; }
.sig-wrap canvas { display: block; width: 100%; height: 180px; touch-action: none; }
.sig-wrap .hint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #b3bac4; pointer-events: none; font-size: 15px; }

.bottom-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: #fff; border-top: 1px solid var(--line); padding: 10px 16px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.bottom-bar .inner { max-width: 720px; margin: 0 auto; display: flex; gap: 10px; }
.bottom-bar .btn { flex: 1; }

.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid rgba(255,255,255,.4); border-top-color: #fff; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.preview img { width: 100%; border: 1px solid var(--line); margin-bottom: 10px; display: block; }

/* ---------- 輸出用 A4 頁面（產生 PDF 時用） ---------- */
#printArea { position: fixed; left: -10000px; top: 0; }
.a4 {
  width: 794px; min-height: 1123px; padding: 48px 48px 40px; background: #fff; color: #000;
  font-family: "DFKai-SB", "BiauKai", "標楷體", "Kaiti TC", "Noto Serif TC", serif; font-size: 13.5px; line-height: 1.35;
}
.a4 .form-title { display: flex; justify-content: space-between; font-size: 17px; font-weight: 700; margin-bottom: 6px; }
.a4 table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.a4 td, .a4 th { border: 1px solid #000; padding: 4px 5px; vertical-align: middle; word-break: break-all; white-space: pre-line; font-weight: normal; }
.a4 .c { text-align: center; }
.a4 .res-cell { text-align: center; font-size: 17px; }
.a4 .grid-out { width: 100%; border-collapse: collapse; }
.a4 .grid-out td { border: 1px solid #555; padding: 1px 2px; font-size: 12px; text-align: center; }
.a4 .sig-line { display: flex; justify-content: space-between; align-items: flex-end; margin-top: 14px; font-size: 15px; }
.a4 .sig-line img { height: 56px; vertical-align: bottom; }
.a4 .sig-line span { display: inline-flex; align-items: flex-end; gap: 4px; min-width: 300px; }
.a4 .ph-title { text-align: center; font-size: 16px; }
.a4 .ph-title.big { font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.a4 .ph-cell { height: 306px; text-align: center; padding: 4px; }
.a4 .ph-box { position: relative; display: inline-block; }
.a4 .ph-box img { display: block; }
.a4 .ph-date { position: absolute; right: 6px; bottom: 4px; color: #e00000; font-family: Arial, sans-serif; font-weight: 700; font-size: 16px; text-shadow: 0 0 2px #fff, 0 0 2px #fff; }
.a4 .ph-note { vertical-align: top; font-size: 13px; }
