/* เซ็นออนไลน์ — สไตล์กลางของ index.html และ sign.html (โหมด Operate: อ่านง่าย กดง่าย มือถือก่อน) */
@font-face { font-family: "SarabunUI"; font-weight: 400; font-display: swap; src: url("../fonts/Sarabun-Regular.ttf") format("truetype"); }
@font-face { font-family: "SarabunUI"; font-weight: 700; font-display: swap; src: url("../fonts/Sarabun-Bold.ttf") format("truetype"); }

:root {
  color-scheme: light;
  --ground: #f5f6ff;
  --surface: #ffffff;
  --ink: #150d45;
  --ink-2: #352e66;
  --muted: #5b5882;
  --line: #e2e4f5;
  --line-strong: #c9ccea;
  --primary: #2d5bf0;
  --primary-hover: #2249cc;
  --primary-press: #1a3aa6;
  --primary-tint: #e8edff;
  --coral: #ff7a59;
  --coral-hover: #ff6a45;
  --mint: #3ee0b2;
  --primary-ring: rgba(45, 91, 240, .30);
  --amber: #7d4a00; --amber-bg: #ffefc8;
  --green: #0d6a3a; --green-bg: #d7f3e2;
  --red: #a3241b;   --red-bg: #fde4e0;
  --gray: #46544f;  --gray-bg: #e8eeec;
  --r: 14px; --r-sm: 10px;
  --shadow-1: 0 1px 2px rgba(21, 13, 69, .07), 0 1px 1px rgba(21, 13, 69, .04);
  --shadow-2: 0 10px 28px -10px rgba(21, 13, 69, .26), 0 3px 8px rgba(21, 13, 69, .07);
  --font: "SarabunUI", "Sarabun", "Noto Sans Thai", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0; font: 16px/1.65 var(--font); color: var(--ink); background: var(--ground);
  font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased;
}
::selection { background: var(--primary-ring); color: var(--ink); }
input, textarea, select { caret-color: var(--primary); accent-color: var(--primary); }
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
a { color: var(--primary); text-underline-offset: 3px; }
a:hover { color: var(--primary-hover); }
:focus-visible { outline: 3px solid var(--primary-ring); outline-offset: 2px; border-radius: 6px; }

/* ---------- แถบบน ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; background: rgba(255, 255, 255, .9);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-in { max-width: 1280px; margin: 0 auto; height: 60px; padding: 0 16px; display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; color: var(--ink); text-decoration: none; letter-spacing: -.01em; }
.brand:hover { color: var(--ink); }
.topbar .spacer { flex: 1; }
.plan-pill {
  font: inherit; font-size: 13px; font-weight: 700; min-height: 32px; padding: 0 12px; border-radius: 999px;
  background: var(--primary-tint); color: var(--primary-press); border: 0; display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
}
.plan-pill:hover { background: #d6e0ff; }
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 999px; background: var(--ink); color: #fff; font-weight: 700; }
.menu > summary::-webkit-details-marker { display: none; }
.menu[open] > summary { box-shadow: 0 0 0 3px var(--primary-ring); }
.menu-panel {
  position: absolute; right: 0; top: 48px; min-width: 220px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-sm); box-shadow: var(--shadow-2); padding: 8px; animation: pop .16s cubic-bezier(.16, 1, .3, 1);
}
.menu-panel .who { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; font-weight: 700; word-break: break-all; }
.menu-panel button { width: 100%; justify-content: flex-start; background: transparent; color: var(--ink); box-shadow: none; min-height: 42px; font-weight: 400; }
.menu-panel button:hover { background: var(--gray-bg); }

/* ---------- เนื้อหา ---------- */
main { max-width: 680px; margin: 0 auto; padding: 22px 16px 56px; }
main.wide { max-width: 1280px; }
.view { animation: rise .3s cubic-bezier(.16, 1, .3, 1); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 4px 0 16px; }
h1 { font-size: 26px; line-height: 1.3; margin: 0; letter-spacing: -.02em; text-wrap: balance; }
h2 { font-size: 20px; line-height: 1.35; margin: 0 0 4px; letter-spacing: -.01em; text-wrap: balance; }
h3 { font-size: 17px; margin: 22px 0 4px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); font-size: 14.5px; }
.back { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; color: var(--ink-2); background: transparent; border: 0; padding: 6px 8px 6px 2px; min-height: 40px; cursor: pointer; box-shadow: none; }
.back:hover { color: var(--primary); background: transparent; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 22px; margin-bottom: 14px; box-shadow: var(--shadow-1);
}
.split { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); align-items: start; }
.split > .card { margin-bottom: 0; }
@media (min-width: 1000px) {
  .split { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); }
  .preview-col { position: sticky; top: 76px; max-height: calc(100vh - 92px); overflow: auto; padding-right: 2px; }
}

/* ---------- ฟอร์ม ---------- */
label { display: block; font-weight: 700; font-size: 15px; color: var(--ink-2); margin: 18px 0 6px; }
input[type=text], input[type=email], input[type=password], input[type=date], input:not([type]), select, textarea {
  width: 100%; min-height: 48px; padding: 0 14px; font: inherit; color: var(--ink); background: var(--surface);
  border: 1.5px solid var(--line-strong); border-radius: var(--r-sm);
  transition: border-color .15s, box-shadow .15s;
}
textarea { padding: 11px 14px; min-height: 100px; line-height: 1.55; resize: vertical; }
select {
  appearance: none; -webkit-appearance: none; padding-right: 40px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%235b5882' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
input::placeholder, textarea::placeholder { color: #67658f; }
input:hover, select:hover, textarea:hover { border-color: #9ea3d6; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-ring); }
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; margin: 0; flex: none; }
input[type=file] { font: inherit; width: 100%; padding: 10px; border: 1.5px dashed var(--line-strong); border-radius: var(--r-sm); background: var(--ground); }
input[type=file]::file-selector-button { font: inherit; font-weight: 700; margin-right: 12px; padding: 8px 14px; border: 0; border-radius: 8px; background: var(--ink); color: #fff; cursor: pointer; }
.check { display: flex; gap: 12px; align-items: flex-start; font-weight: 400; font-size: 15.5px; margin: 18px 0 0; color: var(--ink); cursor: pointer; }
.check input { margin-top: 4px; }
.hint { margin: 6px 0 0; font-size: 14px; color: var(--primary-press); font-weight: 700; min-height: 1.2em; }
.err { display: flex; gap: 8px; align-items: flex-start; color: var(--red); background: var(--red-bg); border-radius: var(--r-sm); padding: 10px 12px; margin: 14px 0 0; font-size: 15px; }
.err:empty { display: none; }

/* ---------- ปุ่ม ---------- */
button {
  font: inherit; font-weight: 700; min-height: 46px; padding: 0 20px; border: 0; border-radius: var(--r-sm);
  background: var(--primary); color: #fff; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: var(--shadow-1); transition: background .15s, transform .08s, box-shadow .15s; -webkit-tap-highlight-color: transparent;
}
button:hover { background: var(--primary-hover); }
button:active { background: var(--primary-press); transform: translateY(1px); }
button.ghost { background: var(--surface); color: var(--ink); border: 1.5px solid var(--line-strong); box-shadow: none; }
button.ghost:hover { background: var(--primary-tint); border-color: var(--primary); }
button.danger { background: var(--surface); color: var(--red); border: 1.5px solid #e6b8b2; box-shadow: none; }
button.danger:hover { background: var(--red-bg); }
button.sm { min-height: 38px; padding: 0 14px; font-size: 14.5px; }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 14px; }
a.btn-link { text-decoration: none; }

.actionbar {
  position: sticky; bottom: 0; z-index: 10; display: flex; gap: 10px; align-items: center; margin: 26px -22px -22px;
  padding: 14px 22px calc(14px + env(safe-area-inset-bottom)); background: rgba(255, 255, 255, .95);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-top: 1px solid var(--line); border-radius: 0 0 var(--r) var(--r);
}
.actionbar button { flex: 1 0 auto; min-height: 52px; font-size: 17px; white-space: nowrap; }
.actionbar .note { flex: 1 1 0; min-width: 0; font-size: 14px; line-height: 1.4; }

/* ---------- ลายเซ็น ---------- */
.sigbox { position: relative; }
canvas {
  display: block; width: 100%; height: 180px; border: 1.5px dashed var(--line-strong); border-radius: var(--r-sm); background-color: #fff;
  background-image: linear-gradient(to top, transparent 44px, #e6e8f7 44px, #e6e8f7 45px, transparent 45px); cursor: crosshair; touch-action: none;
}
canvas:hover { border-color: #9ea3d6; }
.sig-label { display: flex; justify-content: space-between; align-items: baseline; }

/* ---------- รายการเอกสาร ---------- */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-1); overflow: hidden; }
.doc { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 16px 18px; }
.doc + .doc { border-top: 1px solid var(--line); }
.doc-ico { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--primary-tint); color: var(--primary-press); }
.doc-title { font-weight: 700; line-height: 1.35; overflow-wrap: anywhere; }
.doc-meta { color: var(--muted); font-size: 14px; margin-top: 2px; }
.doc-act { display: flex; gap: 8px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
@media (max-width: 560px) {
  .doc { grid-template-columns: 44px minmax(0, 1fr); align-items: start; }
  .doc-act { grid-column: 1 / -1; justify-content: flex-start; }
}
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 700; padding: 2px 10px 2px 7px; border-radius: 999px; white-space: nowrap; background: var(--gray-bg); color: var(--gray); vertical-align: middle; }
.chip.pending { background: var(--amber-bg); color: var(--amber); }
.chip.signed { background: var(--green-bg); color: var(--green); }
.chip.cancelled { background: var(--red-bg); color: var(--red); }

.quota { display: flex; align-items: center; gap: 12px; padding: 12px 16px; margin: 0 0 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); font-size: 14.5px; }
.quota-bar { flex: 0 0 96px; height: 8px; border-radius: 999px; background: var(--gray-bg); overflow: hidden; }
.quota-bar > i { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
.quota.full { background: var(--amber-bg); border-color: #f0d79a; }
.quota.full .quota-bar { background: #f5dfa8; }
.quota.full .quota-bar > i { background: var(--amber); }
.quota .grow { flex: 1; color: var(--ink-2); }
.quota a, .quota button.link { color: var(--primary); font-weight: 700; }
button.link { background: none; border: 0; box-shadow: none; padding: 0; min-height: 0; color: var(--primary); text-decoration: underline; text-underline-offset: 3px; font-weight: 700; }
button.link:hover { background: none; color: var(--primary-hover); }

.empty { text-align: center; padding: 40px 20px 34px; }
.empty svg { color: var(--primary); margin-bottom: 8px; }
.empty h2 { margin-bottom: 6px; }
.empty .row { justify-content: center; }

/* ---------- ผลลัพธ์/ลิงก์/สถานะเต็มหน้า ---------- */
.result { text-align: center; padding: 30px 22px; }
.result .badge { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 14px; background: var(--green-bg); color: var(--green); }
.result .badge.warn { background: var(--amber-bg); color: var(--amber); }
.result .badge.bad { background: var(--red-bg); color: var(--red); }
.linkbox { display: flex; gap: 8px; margin: 14px 0 6px; text-align: left; }
.linkbox input { font-size: 14px; color: var(--ink-2); background: var(--ground); }
.linkbox button { flex: none; }

/* ---------- แผนและชำระเงิน ---------- */
.price { font-size: 34px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; }
.price small { font-size: 16px; font-weight: 400; color: var(--muted); letter-spacing: 0; }
.pay { display: grid; gap: 16px; margin-top: 8px; }
.pay > section { border: 1.5px solid var(--line); border-radius: var(--r); padding: 18px; background: var(--surface); }
.pay > section.primary { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-tint); }

/* ---------- ขั้นตอนของหน้าผู้เซ็น ---------- */
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.step { padding: 22px 0; border-top: 1px solid var(--line); }
.step:first-child { border-top: 0; padding-top: 4px; }
.step-h { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.step-n { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--ink); color: #fff; font-weight: 700; font-size: 15px; }
.step-h h2 { margin: 0; font-size: 18px; }
.from { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; color: var(--ink-2); }
.from b { color: var(--ink); }

footer { max-width: 680px; margin: 0 auto; padding: 8px 16px 40px; text-align: center; }
footer a { color: var(--muted); font-size: 14px; }

/* ---------- อื่น ๆ ---------- */
pre { white-space: pre-wrap; font: 14px/1.6 var(--font); background: var(--ground); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px 14px; overflow: auto; }
.loading { display: flex; align-items: center; gap: 12px; color: var(--muted); padding: 40px 0; justify-content: center; }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 3px solid var(--line-strong); border-top-color: var(--primary); animation: spin .8s linear infinite; }
.sigtools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 10px 0 0; }
.sigtools label { font-weight: 400; font-size: 14.5px; margin: 0; }
.pens { display: flex; gap: 6px; align-items: center; margin: 12px 0 0; flex-wrap: wrap; font-size: 14.5px; color: var(--muted); }
.pens > span { margin-right: 4px; }
.pens button { width: 38px; height: 38px; min-height: 0; padding: 0; border-radius: 50%; }

@keyframes rise { from { opacity: .2; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
@media (max-width: 480px) {
  main { padding-top: 16px; }
  .card { padding: 18px; border-radius: 12px; }
  .actionbar { margin: 22px -18px -18px; padding-left: 18px; padding-right: 18px; }
  h1 { font-size: 24px; }
}

/* ปุ่มสลับประเภท (ช่องลายเซ็น) */
button.ghost[aria-pressed="true"] { background: var(--primary-tint); border-color: var(--primary); color: var(--primary-press); }
[hidden] { display: none !important; }

.filepick { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px; border: 1.5px dashed var(--line-strong); border-radius: var(--r-sm); background: var(--ground); }

/* ข้อมูลบัญชีรับโอน */
.acct { margin: 10px 0 4px; padding: 6px 14px; background: var(--ground); border: 1px solid var(--line); border-radius: var(--r-sm); }
.acct button { white-space: nowrap; }
.acct-r { display: grid; grid-template-columns: 6.5em 1fr; gap: 8px; align-items: center; padding: 8px 0; }
.acct-r + .acct-r { border-top: 1px solid var(--line); }
.acct dt { color: var(--muted); font-size: 14.5px; }
.acct dd { margin: 0; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-weight: 400; }
.acct dd b { font-size: 18px; letter-spacing: .02em; }

/* แนบสำเนาบัตรประชาชน */
.idbox { margin: 18px 0 0; padding: 16px; border: 1.5px solid var(--primary); border-radius: var(--r); background: var(--primary-tint); }
.idnotes { margin: 6px 0 12px; padding-left: 1.2em; color: var(--ink-2); font-size: 14.5px; }
.idnotes li { margin: 2px 0; }
.idprev { display: block; width: 100%; max-height: 260px; object-fit: contain; margin: 12px 0 0; border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: #fff; }
.idprev[hidden] { display: none; }
.idbox .filepick { background: #fff; }
.seg { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 0; }
.seg button[aria-pressed="true"] { background: var(--primary); color: #fff; border-color: var(--primary); }
