:root {
  --bg: #f4f6f9; --card: #fff; --ink: #1d2433; --mute: #667085; --line: #e3e7ee;
  --blue: #1f5fbf; --blue-soft: #e8f0fc; --red: #d92d20; --red-soft: #fdecea;
  --green: #16803c; --green-soft: #e6f6ec; --amber: #b54708; --amber-soft: #fef4e6;
  --radius: 12px;
  font-family: "Sarabun", "Noto Sans Thai", "Leelawadee UI", "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.5; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 18px;
  background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.logoimg { height: 48px; width: auto; display: block; flex-shrink: 0; }
.sys { font-weight: 700; font-size: 16px; border-left: 1px solid var(--line); padding-left: 14px; }
.paper .plogo { height: 60px; width: auto; display: block; }
.lang { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex-shrink: 0; }
.lang button { border: 0; background: #fff; padding: 6px 10px; cursor: pointer; font-size: 14px; }
.lang button.on { background: var(--blue); color: #fff; }

main { max-width: 980px; margin: 0 auto; padding: 20px 16px 80px; overflow-x: auto; }
h1 { font-size: 22px; margin: 4px 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
h2 .num { background: var(--blue); color: #fff; border-radius: 50%; width: 26px; height: 26px; display: inline-grid; place-items: center; font-size: 14px; flex-shrink: 0; }
.lead { color: var(--mute); margin: 0 0 18px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 14px; }
.grid .wide { grid-column: 1 / -1; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 14px; font-weight: 600; }
label.f .hint { font-weight: 400; color: var(--mute); font-size: 13px; }
.req::after { content: " *"; color: var(--red); }
input[type=text], input[type=tel], input[type=email], input[type=date], input[type=time], input[type=number], input[type=password], select, textarea {
  width: 100%; border: 1px solid #cfd5df; border-radius: 8px; padding: 9px 10px; background: #fff; font-weight: 400; min-height: 42px; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: -1px; border-color: var(--blue); }
.bad input, .bad textarea, input.bad, textarea.bad { border-color: var(--red); background: var(--red-soft); }
.warn-text { color: var(--amber); font-size: 12px; font-weight: 400; }
.err-text { color: var(--red); font-size: 13px; font-weight: 400; }

.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.chk { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; cursor: pointer; background: #fff; font-size: 15px; }
.chk input { width: 18px; height: 18px; flex-shrink: 0; accent-color: var(--blue); }
.chk:has(input:checked) { border-color: var(--blue); background: var(--blue-soft); }
.bad .chk, .chk.bad { border-color: var(--red); }

table.rows { width: 100%; border-collapse: collapse; }
table.rows th { text-align: left; font-size: 13px; color: var(--mute); font-weight: 600; padding: 4px 6px; }
table.rows td { padding: 4px; vertical-align: top; }
table.rows td.n { width: 32px; text-align: center; color: var(--mute); padding-top: 12px; }
table.rows td.x { width: 40px; }
@media (max-width: 640px) {
  table.rows.stack thead { display: none; }
  table.rows.stack tr { display: grid; grid-template-columns: 28px 1fr 40px; gap: 4px; border-bottom: 1px dashed var(--line); padding: 6px 0; }
  table.rows.stack td { padding: 0; } table.rows.stack td.n { padding-top: 10px; grid-row: span 4; }
  table.rows.stack td.x { grid-column: 3; grid-row: 1; }
  table.rows.stack td:not(.n):not(.x) { grid-column: 2; }
}
.btn { border: 1px solid #cfd5df; background: #fff; border-radius: 8px; padding: 9px 16px; cursor: pointer; font-weight: 600; min-height: 42px; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--ink); }
.btn:hover { background: #f2f4f7; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: #1a4fa0; }
.btn.green { background: var(--green); border-color: var(--green); color: #fff; }
.btn.red { background: #fff; border-color: var(--red); color: var(--red); }
.btn.big { padding: 13px 26px; font-size: 17px; }
.btn.icon { padding: 6px 10px; min-height: 38px; color: var(--mute); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }

.toggle-card { display: flex; gap: 12px; align-items: flex-start; border: 2px dashed #f0b4a8; background: #fff8f6; border-radius: var(--radius); padding: 14px; cursor: pointer; }
.toggle-card input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--red); }
.toggle-card b { color: var(--red); }
.hot { border-color: #f0b4a8; background: #fffbfa; }

.declare { background: #f8fafc; border-left: 4px solid var(--blue); padding: 12px 14px; border-radius: 6px; margin-bottom: 12px; }
.sigwrap { border: 1px solid #cfd5df; border-radius: 8px; background: #fff; position: relative; touch-action: none; }
.sigwrap canvas { display: block; width: 100%; height: 160px; cursor: crosshair; }
.sigwrap .ph { position: absolute; inset: 0; display: grid; place-items: center; color: #b0b8c4; pointer-events: none; }
.sigwrap.bad { border-color: var(--red); }
.sigwrap .ph[hidden] { display: none; }

.files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.file { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; font-size: 13px; background: #fff; }
.file img { width: 36px; height: 36px; object-fit: cover; border-radius: 4px; }
.file.up { opacity: .6; }
.dropzone { border: 2px dashed #cfd5df; border-radius: 10px; padding: 16px; text-align: center; color: var(--mute); cursor: pointer; background: #fafbfc; display: block; }
.dropzone input { display: none; }

.submitbar { display: flex; gap: 12px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.errbox { background: var(--red-soft); color: var(--red); border-radius: 8px; padding: 10px 14px; margin-bottom: 12px; display: none; }
.errbox.show { display: block; }

.badge { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.s-submitted { background: var(--amber-soft); color: var(--amber); }
.s-approved { background: var(--green-soft); color: var(--green); }
.s-in_progress { background: var(--blue-soft); color: var(--blue); }
.s-rejected { background: var(--red-soft); color: var(--red); }
.s-closed { background: #eef0f3; color: #344054; }
.s-cancelled { background: #eef0f3; color: #98a2b3; text-decoration: line-through; }
.hotflag { background: var(--red); color: #fff; border-radius: 6px; padding: 1px 6px; font-size: 12px; font-weight: 700; }

.done { text-align: center; padding: 30px 18px; }
.done .ref { font-size: 30px; font-weight: 800; letter-spacing: .04em; color: var(--blue); margin: 8px 0; }
.done .tick { width: 64px; height: 64px; border-radius: 50%; background: var(--green-soft); color: var(--green); display: grid; place-items: center; font-size: 36px; margin: 0 auto 10px; }
.linkbox { display: flex; gap: 6px; max-width: 560px; margin: 10px auto; }
.linkbox input { font-size: 13px; }

/* staff */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 14px; }
.tabs button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.tabs .c { font-weight: 700; margin-left: 4px; opacity: .8; }
.list { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.list th, .list td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; vertical-align: top; }
.list th { background: #f8fafc; color: var(--mute); font-weight: 600; }
.list tr.click { cursor: pointer; } .list tr.click:hover td { background: #f8fbff; }
.list .sub { color: var(--mute); font-size: 13px; }
@media (max-width: 720px) { .list .hide-sm { display: none; } }
.empty { text-align: center; color: var(--mute); padding: 30px; }
dl.kv { display: grid; grid-template-columns: 170px 1fr; gap: 6px 14px; margin: 0; }
dl.kv dt { color: var(--mute); font-size: 14px; } dl.kv dd { margin: 0; font-weight: 600; word-break: break-word; }
@media (max-width: 600px) { dl.kv { grid-template-columns: 1fr; } dl.kv dd { margin-bottom: 6px; } }
.pill { display: inline-block; background: #eef2f7; border-radius: 6px; padding: 1px 8px; margin: 2px 4px 2px 0; font-size: 13px; font-weight: 600; }
.timeline { list-style: none; padding: 0; margin: 0; font-size: 14px; }
.timeline li { padding: 6px 0 6px 14px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 12px; width: 10px; height: 10px; border-radius: 50%; background: var(--blue); }
.timeline .when { color: var(--mute); font-size: 13px; }
.thumbs { display: flex; flex-wrap: wrap; gap: 10px; }
.thumbs a { display: block; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; width: 130px; text-decoration: none; color: var(--ink); font-size: 12px; background: #fff; }
.thumbs img { width: 130px; height: 100px; object-fit: cover; display: block; }
.thumbs .pdf { width: 130px; height: 100px; display: grid; place-items: center; background: var(--red-soft); color: var(--red); font-weight: 800; }
.thumbs span { display: block; padding: 4px 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sigimg { max-width: 260px; max-height: 110px; border-bottom: 1px solid var(--ink); }
.action { border: 2px solid var(--blue); }
.login { max-width: 380px; margin: 40px auto; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0; background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; transition: .25s; pointer-events: none; z-index: 20; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%); }

/* print — A4 replica of the paper form */
.paper { background: #fff; width: 210mm; min-height: 297mm; padding: 14mm 14mm 12mm; margin: 0 auto 16px; box-shadow: 0 2px 12px rgba(0,0,0,.08); font-size: 12.5px; line-height: 1.55; color: #000; }
.paper .ph { display: flex; align-items: center; gap: 14px; border-bottom: 2px solid #000; padding-bottom: 6px; margin-bottom: 10px; }
.paper .ph .t { flex: 1; text-align: center; } .paper .ph .t b { font-size: 15px; display: block; }
.paper .ph .no { font-size: 11px; text-align: right; }
.paper h3 { font-size: 13px; margin: 10px 0 4px; }
.paper table { width: 100%; border-collapse: collapse; margin: 4px 0; }
.paper td, .paper th { border: 1px solid #000; padding: 3px 6px; font-size: 12px; vertical-align: top; }
.paper th { background: #eee; }
.paper .u { border-bottom: 1px dotted #000; padding: 0 6px; font-weight: 600; }
.paper .box { display: inline-block; width: 12px; height: 12px; border: 1px solid #000; margin-right: 4px; vertical-align: -1px; text-align: center; line-height: 10px; font-size: 11px; font-weight: 700; }
.paper .ppe { display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px 8px; }
.paper .signs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.paper .sbox { border: 1px solid #000; padding: 8px; min-height: 110px; }
.paper .signs img { max-height: 60px; max-width: 220px; display: block; margin: 2px auto; }
.paper .sbox img { max-height: 55px; max-width: 200px; display: block; margin: 2px auto; }
.paper .c { text-align: center; }
.printbar { max-width: 210mm; margin: 0 auto 12px; }
@media print {
  @page { size: A4; margin: 0; }
  body { background: #fff; }
  .no-print, .top, .printbar { display: none !important; }
  main { padding: 0; max-width: none; }
  .paper { box-shadow: none; margin: 0; page-break-after: always; }
  .paper:last-child { page-break-after: auto; }
}

@media (max-width: 480px) { .logoimg { height: 36px; } .sys { font-size: 13px; padding-left: 10px; } .brand { gap: 10px; } .top { padding: 8px 10px; } .lang button { padding: 6px 8px; } }
.formnav { margin-bottom: 16px; }
.formnav a { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 16px; text-decoration: none; color: var(--ink); font-weight: 600; font-size: 15px; }
.formnav a.on { background: var(--blue); border-color: var(--blue); color: #fff; }
.formnav a[href="#/hot"].on { background: var(--red); border-color: var(--red); }
.kindtabs button { font-size: 15px; font-weight: 700; padding: 8px 16px; }
.kindtabs .pend { background: var(--red); color: #fff; border-radius: 999px; padding: 0 7px; margin-left: 6px; font-size: 12px; }

/* QR card + posters */
.qrcard { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.qrthumb { width: 104px; height: 104px; border: 1px solid var(--line); border-radius: 8px; padding: 4px; background: #fff; }
.qrpaper { display: flex; flex-direction: column; }
.qrhead { display: flex; align-items: center; gap: 16px; border-bottom: 3px solid #111827; padding-bottom: 10px; }
.qrhead img { height: 70px; width: auto; }
.qrhead b { font-size: 22px; } .qrhead span { color: #475467; font-size: 14px; }
.qrgrid { flex: 1; display: grid; place-items: center; padding: 8mm 0 4mm; }
.qrgrid.four { grid-template-columns: 1fr 1fr; gap: 6mm; align-items: stretch; }
.qrbox { text-align: center; width: 100%; }
.qrbox .qrtitle { font-size: 34px; font-weight: 800; }
.qrbox .qrsub { font-size: 16px; color: #475467; margin-top: 2px; }
.qrbox .qrwho { font-size: 18px; margin: 10px 0 6px; } .qrbox .qrwho span { font-size: 13px; color: #475467; }
.qrbox img { width: 125mm; height: 125mm; display: block; margin: 4mm auto; }
.qrbox .qrscan { font-size: 22px; font-weight: 700; } .qrbox .qrscan span { font-size: 13px; font-weight: 400; color: #475467; }
.qrbox .qrurl { font-family: monospace; font-size: 14px; margin-top: 6px; color: #344054; }
.qrbox.small { border: 1.5px dashed #98a2b3; border-radius: 10px; padding: 4mm 3mm; }
.qrbox.small .qrtitle { font-size: 20px; } .qrbox.small .qrsub { font-size: 11px; }
.qrbox.small .qrwho { font-size: 12px; margin: 6px 0 2px; } .qrbox.small .qrwho span { font-size: 10px; }
.qrbox.small img { width: 54mm; height: 54mm; margin: 2mm auto; }
.qrbox.small .qrscan { font-size: 13px; } .qrbox.small .qrscan span { font-size: 9px; }
.qrbox.small .qrurl { font-size: 10px; }
.qrfoot { text-align: center; font-size: 12px; color: #475467; border-top: 1px solid #d0d5dd; padding-top: 6px; }

/* sample printouts (#/samples) */
.sampleh { max-width: 210mm; margin: 22px auto 8px; font-size: 18px; }
.paper.sample { position: relative; overflow: hidden; }
.paper.sample::after { content: "ตัวอย่าง · SAMPLE · 見本"; position: absolute; top: 45%; left: 50%; transform: translate(-50%, -50%) rotate(-30deg);
  font-size: 64px; font-weight: 800; color: rgba(217, 45, 32, .13); white-space: nowrap; pointer-events: none;
  -webkit-print-color-adjust: exact; print-color-adjust: exact; }
