/* ตรวจคู่ฉบับ: หน้าวางไฟล์แบบ A + ผลตรวจสามช่องแบบ C + ตราประทับแบบ B */
:root {
  --desk: #EEF0F2;
  --paper: #FFFFFF;
  --ink: #1C2430;
  --muted: #5B6573;
  --line: #DDE1E6;
  --line-soft: #EEF0F2;
  --blue: #2347A8;
  --blue-deep: #1A3580;
  --blue-wash: #E8EEFB;
  --blue-select: #EEF2FB;
  --ochre: #B54708;
  --ochre-wash: #FEF0E6;
  --seal-red: #C2410C;
  --seal-green: #1E5B4A;
  --off: #C9CED6;
  --well: #F6F7F8;
  --shadow-sheet: 0 1px 2px rgba(28, 36, 48, .06), 0 18px 40px -12px rgba(28, 36, 48, .14);
  --font-ui: 'Anuphan', system-ui, sans-serif;
  --font-doc: 'Sarabun', 'TH Sarabun New', sans-serif;
  --font-seal: 'Trirong', serif;
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --bar-h: 72px;
}
* { box-sizing: border-box; }
html, body { overflow-x: clip; }
body { margin: 0; background: var(--desk); color: var(--ink); font: 16px/1.6 var(--font-ui); }
a { color: var(--blue); text-decoration: none; }
a:hover { color: var(--blue-deep); text-decoration: underline; }
button { font: inherit; cursor: pointer; color: inherit; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }
[hidden] { display: none !important; }
kbd { font: inherit; font-size: 12px; border: 1px solid var(--off); border-bottom-width: 2px; border-radius: 4px; padding: 0 6px; background: var(--paper); color: var(--ink); }
.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- ปุ่ม ---------- */
.btn { height: 44px; padding: 0 22px; border-radius: 22px; border: 1px solid transparent; background: var(--ink); color: #fff; font-size: 15px; font-weight: 500; white-space: nowrap; transition: background-color .15s var(--ease-out), transform .1s var(--ease-out); }
.btn:hover:not(:disabled) { background: #2C3747; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { background: var(--off); color: #fff; }
.btn.blue { background: var(--blue); }
.btn.blue:hover:not(:disabled) { background: var(--blue-deep); }
.btn.line { background: var(--paper); border-color: var(--off); color: var(--ink); }
.btn.line:hover:not(:disabled) { background: var(--well); }
.btn.text { background: transparent; color: var(--blue); padding: 0 12px; }
.btn.text:hover:not(:disabled) { background: transparent; text-decoration: underline; }
a.btn { display: inline-flex; align-items: center; color: #fff; text-decoration: none; }
a.btn:hover { color: #fff; text-decoration: none; }
.btn.big { height: 52px; padding: 0 32px; border-radius: 26px; font-size: 17px; }
.btn.sm { height: 36px; padding: 0 14px; font-size: 14px; border-radius: 18px; }

/* ---------- แถบบน ---------- */
.bar { min-height: var(--bar-h); display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 12px 32px; }
.bar .brand { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; color: var(--ink); }
.bar nav { display: flex; gap: 28px; font-size: 15px; }
.bar.solid { background: var(--paper); border-bottom: 1px solid var(--line); padding: 10px 24px; }
.bar .left { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; min-width: 0; }
.bar .actions { display: flex; align-items: center; gap: 10px; }
.bar .status-main { font-size: 16px; font-weight: 500; }
.bar .status-sub { font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }

/* ---------- ตราประทับ ---------- */
.stamp { flex: none; transform: rotate(-9deg); display: block; }
.stamp.press { animation: press .24s var(--ease-out) both; }
@keyframes press { from { opacity: 0; transform: rotate(-14deg) scale(1.35); } to { opacity: 1; transform: rotate(-9deg) scale(1); } }
@media (prefers-reduced-motion: reduce) {
  .stamp.press { animation: fade .15s linear both; }
  @keyframes fade { from { opacity: 0; } to { opacity: 1; } }
}

/* ---------- หน้าวางไฟล์ ---------- */
.upload { max-width: 1120px; margin: 0 auto; padding: 24px 32px 80px; }
.upload h1 { margin: 0; font-size: 40px; line-height: 1.3; font-weight: 500; letter-spacing: -0.015em; max-width: 680px; overflow-wrap: anywhere; }
.upload .lead { margin: 16px 0 48px; font-size: 17px; line-height: 1.7; color: var(--muted); max-width: 640px; }
.sheets { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 48px; max-width: 920px; }
.slot { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.slot-label { font-size: 15px; color: var(--muted); }
.sheet { position: relative; background: var(--paper); aspect-ratio: 1 / 1.414; border-radius: 2px; box-shadow: var(--shadow-sheet); overflow: hidden; transition: box-shadow .2s var(--ease-out), transform .2s var(--ease-out); }
.sheet.over { box-shadow: 0 0 0 2px var(--blue), var(--shadow-sheet); transform: translateY(-2px); }
.sheet input[type=file] { display: none; }
.sheet .empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 32px; text-align: center; }
.sheet .empty .t { font-size: 17px; line-height: 1.6; }
.sheet .empty .s { font-size: 14px; color: var(--muted); }
.sheet .preview { position: absolute; inset: 0; overflow: hidden; }
.sheet .preview canvas { width: 100%; height: auto; display: block; }
.sheet .preview .doc-text { padding: 9% 10%; font: 12px/1.85 var(--font-doc); color: #222; white-space: pre-wrap; overflow-wrap: anywhere; }
.sheet .foot { position: absolute; left: 0; right: 0; bottom: 0; padding: 40px 20px 18px; background: linear-gradient(rgba(255,255,255,0), #fff 45%); display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.sheet .foot .name { font-size: 16px; font-weight: 500; overflow-wrap: anywhere; }
.sheet .foot .info { font-size: 14px; color: var(--muted); margin-top: 2px; }
.sheet .busy { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 32px; text-align: center; font-size: 15px; color: var(--blue); background: rgba(255,255,255,.85); }
.sheet .err { color: #B42318; font-size: 14px; }
.opts { display: flex; flex-wrap: wrap; gap: 10px 28px; margin: 40px 0 0; font-size: 15px; }
.opts label { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; min-height: 32px; }
.opts input { width: 18px; height: 18px; accent-color: var(--blue); }
.go { display: flex; align-items: center; gap: 24px; padding-top: 32px; flex-wrap: wrap; }
.go .hint { font-size: 15px; color: var(--muted); }
.privacy { margin-top: 56px; font-size: 14px; color: var(--muted); }

/* ---------- หน้าผลตรวจ ---------- */
.workspace { display: flex; flex-wrap: wrap; height: calc(100vh - 89px); min-height: 520px; }
.pane-list { flex: 1 1 260px; max-width: 300px; background: var(--paper); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.chips { display: flex; gap: 6px; padding: 14px 14px 10px; flex-wrap: wrap; }
.chip { height: 32px; padding: 0 12px; border-radius: 16px; border: 1px solid var(--line); background: var(--paper); font-size: 13px; }
.chip[aria-pressed=true] { background: var(--ink); border-color: var(--ink); color: #fff; }
.items { overflow-y: auto; flex: 1; min-height: 0; }
.item { width: 100%; text-align: left; border: 0; border-left: 3px solid transparent; border-top: 1px solid var(--line-soft); background: transparent; padding: 13px 16px 13px 13px; display: flex; gap: 12px; align-items: flex-start; }
.item:hover { background: var(--well); }
.item[aria-current=true] { border-left-color: var(--blue); background: var(--blue-select); }
.item .dot { width: 18px; height: 18px; border: 1.5px solid #8A93A0; border-radius: 50%; margin-top: 3px; flex: none; }
.item .tick { width: 18px; height: 18px; margin-top: 3px; flex: none; color: var(--seal-green); }
.item .meta { font-size: 12px; color: var(--muted); display: block; }
.item .title { font-size: 15px; font-weight: 500; display: block; overflow-wrap: anywhere; }
.item.done .title { color: var(--muted); }
.keys { padding: 12px 16px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); line-height: 1.9; }

.pane-center { flex: 999 1 520px; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.center-tools { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 14px 24px; }
.seg { display: inline-flex; background: #E2E6EA; border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { height: 32px; padding: 0 14px; border: 0; border-radius: 8px; background: transparent; font-size: 13px; color: var(--muted); }
.seg button[aria-pressed=true] { background: var(--paper); color: var(--ink); box-shadow: 0 1px 2px rgba(28,36,48,.12); }
.seg button:disabled { opacity: .45; }
.pager { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.pager button { width: 32px; height: 32px; border: 1px solid var(--line); background: var(--paper); border-radius: 8px; }
.center-body { flex: 1; min-height: 0; overflow: auto; padding: 0 24px 32px; }
.pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.pair .cap { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.page-sheet { background: var(--paper); box-shadow: var(--shadow-sheet); border-radius: 2px; }
.page-sheet canvas { width: 100%; height: auto; display: block; }
.overlay-wrap canvas { width: 100%; height: auto; display: block; background: var(--paper); box-shadow: var(--shadow-sheet); cursor: crosshair; }
.textview { background: var(--paper); box-shadow: var(--shadow-sheet); padding: 40px 48px; font: 16px/1.95 var(--font-doc); white-space: pre-wrap; overflow-wrap: anywhere; max-width: 820px; }
.textview .m { cursor: pointer; border-radius: 3px; }
.textview .m.sel { outline: 2px solid var(--blue); outline-offset: 3px; }
.del { color: var(--ochre); text-decoration: line-through; text-decoration-thickness: 1.5px; background: var(--ochre-wash); padding: 0 2px; border-radius: 2px; }
.ins { color: var(--blue); background: var(--blue-wash); border-bottom: 2px solid var(--blue); padding: 0 2px; }
.legend { display: flex; gap: 24px; font-size: 13px; color: var(--muted); flex-wrap: wrap; margin-top: 14px; }
.legend .del, .legend .ins { background: none; padding: 0; }
.center-note { font-size: 14px; color: var(--muted); padding: 32px 0; }

.pane-insp { flex: 1 1 280px; max-width: 340px; background: var(--paper); border-left: 1px solid var(--line); padding: 20px; display: flex; flex-direction: column; gap: 16px; overflow-y: auto; min-height: 0; }
.pane-insp .n { font-size: 12px; color: var(--muted); }
.pane-insp h2 { margin: 2px 0 0; font-size: 19px; font-weight: 600; line-height: 1.45; overflow-wrap: anywhere; }
.pane-insp .where { margin: 4px 0 0; font-size: 14px; color: var(--muted); }
.crop-lbl { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.crop { background: var(--well); border-radius: 8px; padding: 8px; min-height: 40px; }
.crop canvas { max-width: 100%; height: auto; display: block; background: #fff; border-radius: 4px; }
.crop .txt { font: 15px/1.8 var(--font-doc); padding: 4px 6px; overflow-wrap: anywhere; }
.note-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.note-field textarea { font: inherit; font-size: 14px; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 10px; resize: vertical; min-height: 64px; }

@media (max-width: 860px) {
  .workspace { height: auto; }
  .pane-list, .pane-insp { max-width: none; flex-basis: 100%; border: 0; border-bottom: 1px solid var(--line); }
  .items { max-height: 260px; }
  .center-body { overflow: visible; }
  .keys { display: none; }
}

/* ---------- หน้ายืนยันครบ ---------- */
.done { max-width: 1040px; margin: 0 auto; padding: 64px 32px 80px; display: flex; gap: 56px; align-items: center; flex-wrap: wrap; }
.done .body { flex: 1 1 420px; min-width: 0; display: flex; flex-direction: column; gap: 24px; }
.done h1 { margin: 0; font-size: 36px; line-height: 1.35; font-weight: 500; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.done p { margin: 0; font-size: 16px; line-height: 1.75; color: var(--muted); }
.summary { list-style: none; margin: 0; padding: 0; background: var(--paper); border-radius: 12px; border: 1px solid var(--line); }
.summary li { display: flex; justify-content: space-between; gap: 16px; padding: 14px 18px; font-size: 15px; flex-wrap: wrap; }
.summary li + li { border-top: 1px solid var(--line-soft); }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); max-width: 360px; }
.field input { font: inherit; font-size: 16px; color: var(--ink); height: 44px; border: 1px solid var(--off); border-radius: 10px; padding: 0 12px; background: var(--paper); }
.row-btns { display: flex; gap: 12px; flex-wrap: wrap; }

@media (max-width: 640px) {
  .bar { padding: 12px 20px; }
  .upload { padding: 16px 20px 64px; }
  .upload h1 { font-size: 30px; }
  .sheets { grid-template-columns: minmax(0, 1fr); gap: 32px; }
  .pair { grid-template-columns: minmax(0, 1fr); }
  .done { padding: 40px 20px; }
  .done h1 { font-size: 28px; }
}

/* ---------- รายงาน (พิมพ์เท่านั้น) ---------- */
#report { display: none; }
@media print {
  body { background: #fff; }
  body > *:not(#report) { display: none !important; }
  #report { display: block; font: 13px/1.7 var(--font-ui); color: #000; }
  #report h1 { font-size: 22px; margin: 0 0 4px; font-weight: 600; }
  #report table { width: 100%; border-collapse: collapse; margin-top: 14px; }
  #report th, #report td { border: 1px solid #999; padding: 6px 8px; vertical-align: top; text-align: left; }
  #report img { max-width: 100%; max-height: 90px; display: block; }
  #report .hash { font-size: 10.5px; overflow-wrap: anywhere; }
  #report tr { break-inside: avoid; }
}

/* ---------- หน้าแปลง PDF เป็น Word ---------- */
.convert { max-width: 720px; margin: 0 auto; padding: 24px 32px 80px; }
.convert h1 { margin: 0; font-size: 36px; line-height: 1.3; font-weight: 500; letter-spacing: -0.015em; }
.convert .lead { margin: 14px 0 36px; font-size: 16px; line-height: 1.75; color: var(--muted); }
.convert .sheet { max-width: 380px; }
.convert .settings { display: flex; flex-direction: column; gap: 12px; margin-top: 32px; font-size: 15px; }
.convert .settings label { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.convert select { font: inherit; height: 40px; border: 1px solid var(--off); border-radius: 10px; padding: 0 10px; background: var(--paper); }
.convert .settings input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--blue); }
.convert .result { margin-top: 28px; display: flex; flex-direction: column; gap: 12px; }
.convert details summary { cursor: pointer; font-size: 14px; color: var(--muted); }
.convert pre { white-space: pre-wrap; font: 14px/1.8 var(--font-doc); background: var(--paper); padding: 20px; border-radius: 8px; max-height: 50vh; overflow: auto; }
