/* BillWai — โทเคนและคอมโพเนนต์หน้าจอ (โทนเดียวกับระบบ iMAN: เทาอุ่น ตัวอักษรเข้ม สีสถานะแยกชัด) */
@font-face { font-family: Sarabun; src: url(fonts/Sarabun-Regular.ttf); font-weight: 400; }
@font-face { font-family: Sarabun; src: url(fonts/Sarabun-Medium.ttf); font-weight: 500; }
@font-face { font-family: Sarabun; src: url(fonts/Sarabun-SemiBold.ttf); font-weight: 600; }
@font-face { font-family: Sarabun; src: url(fonts/Sarabun-Bold.ttf); font-weight: 700; }
:root {
  --bg: #F5F4F0; --sf: #fff; --s2: #EFEFEB; --bd: #E0DED8; --bd2: #CCCAC3;
  --tx: #1A1A18; --tx2: #6B6A65; --tx3: #9E9D98;
  --blue: #1D4ED8; --bbg: #EFF6FF; --btx: #1E40AF;
  --green: #15803D; --gbg: #F0FDF4; --gtx: #166534;
  --amber: #B45309; --abg: #FFFBEB; --atx: #92400E;
  --red: #DC2626; --rbg: #FEF2F2; --rtx: #991B1B;
  --pur: #7C3AED; --pbg: #F5F3FF; --ptx: #5B21B6;
  --font: Sarabun, "Sukhumvit Set", "Thonburi", Tahoma, system-ui, sans-serif;
  --mono: "IBM Plex Mono", Menlo, Consolas, monospace;
  --r: 8px; --rl: 12px;
  --shadow: 0 1px 2px rgba(26,26,24,.05), 0 8px 24px -14px rgba(26,26,24,.25);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: var(--font); font-size: 14px; background: var(--bg); color: var(--tx); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); }
.num, .mono { font-variant-numeric: tabular-nums; }
.muted { color: var(--tx2); } .faint { color: var(--tx3); } .small { font-size: 12.5px; } .xs { font-size: 11.5px; }
.hide { display: none !important; }
.row { display: flex; align-items: center; gap: 8px; } .wrap { flex-wrap: wrap; } .grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }
.r { text-align: right; } .c { text-align: center; }

/* shell */
.shell { display: flex; height: 100vh; overflow: hidden; }
.side { width: 212px; flex: none; background: var(--sf); border-right: 1px solid var(--bd); display: flex; flex-direction: column; }
.logo { padding: 16px 14px 12px; border-bottom: 1px solid var(--bd); }
.logo b { display: block; font-size: 15px; font-weight: 700; letter-spacing: .02em; }
.logo span { font-size: 11px; color: var(--tx3); display: block; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav { padding: 8px; flex: 1; overflow-y: auto; }
.nav .grp { font-size: 10.5px; font-weight: 600; color: var(--tx3); letter-spacing: .08em; text-transform: uppercase; padding: 12px 10px 4px; }
.ni { display: flex; align-items: center; gap: 9px; width: 100%; padding: 8px 10px; border: 0; background: none; border-radius: var(--r); font-size: 13px; color: var(--tx2); cursor: pointer; text-align: left; }
.ni svg { width: 17px; height: 17px; flex: none; }
.ni:hover { background: var(--s2); color: var(--tx); }
.ni.on { background: var(--tx); color: #fff; font-weight: 500; }
.ni .cnt { margin-left: auto; font-size: 11px; background: var(--s2); color: var(--tx2); border-radius: 99px; padding: 1px 7px; }
.ni.on .cnt { background: rgba(255,255,255,.2); color: #fff; }
.side .foot { padding: 10px; border-top: 1px solid var(--bd); font-size: 11.5px; color: var(--tx3); }
.side .foot b { color: var(--tx2); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top { height: 54px; flex: none; background: var(--sf); border-bottom: 1px solid var(--bd); display: flex; align-items: center; gap: 10px; padding: 0 18px; }
.top h1 { font-size: 16px; font-weight: 600; }
.content { flex: 1; overflow: auto; padding: 18px; }
.content.flush { padding: 0; }
.mtop { display: none; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 13px; border-radius: var(--r); border: 1px solid var(--bd2); background: var(--sf); color: var(--tx); font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover { background: var(--s2); } .btn:disabled { opacity: .45; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn.bp { background: var(--tx); border-color: var(--tx); color: #fff; } .btn.bp:hover { background: #000; }
.btn.bg { background: var(--green); border-color: var(--green); color: #fff; }
.btn.bl { background: var(--bbg); border-color: #BFDBFE; color: var(--btx); }
.btn.bd { color: var(--rtx); } .btn.bd:hover { background: var(--rbg); }
.btn.ghost { border-color: transparent; background: transparent; } .btn.ghost:hover { background: var(--s2); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn.lg { height: 42px; padding: 0 18px; font-size: 14px; }
.btn.block { width: 100%; }
.ibtn { width: 32px; height: 32px; padding: 0; border-radius: 7px; }

/* inputs */
.f { display: block; }
.f > span { display: block; font-size: 11.5px; color: var(--tx2); margin-bottom: 4px; font-weight: 500; }
.in, select.in, textarea.in { width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--bd2); border-radius: var(--r); background: var(--sf); outline: 0; font-size: 13.5px; }
textarea.in { height: auto; min-height: 64px; padding: 8px 10px; resize: vertical; line-height: 1.45; }
.in:focus { border-color: var(--tx); box-shadow: 0 0 0 3px rgba(26,26,24,.08); }
.in.sm { height: 30px; font-size: 12.5px; padding: 0 8px; }
.in.r { text-align: right; }
select.in { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%236B6A65' stroke-width='1.8'%3E%3Cpath d='M1 1.5l5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 9px center; padding-right: 28px; }
.sw { position: relative; width: 38px; height: 22px; flex: none; }
.sw input { opacity: 0; width: 0; height: 0; position: absolute; }
.sw i { position: absolute; inset: 0; background: var(--bd2); border-radius: 99px; cursor: pointer; transition: .2s; }
.sw i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.sw input:checked + i { background: var(--green); } .sw input:checked + i::after { transform: translateX(16px); }
.g2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; } .g3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; } .g4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }

/* cards & tables */
.card { background: var(--sf); border: 1px solid var(--bd); border-radius: var(--rl); }
.card.pad { padding: 16px 18px; }
.sec { padding: 16px 18px; border-top: 1px solid var(--bd); display: grid; grid-template-columns: 220px 1fr; gap: 20px; }
.sec:first-child { border-top: 0; }
.sec h3 { font-size: 14px; font-weight: 600; } .sec .sd p { font-size: 12px; color: var(--tx2); margin-top: 3px; line-height: 1.45; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-size: 11.5px; font-weight: 600; color: var(--tx2); padding: 9px 10px; border-bottom: 1px solid var(--bd); background: var(--s2); white-space: nowrap; }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--bd); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.click { cursor: pointer; } .tbl tr.click:hover td { background: #FAFAF7; }
.tbl .r { text-align: right; } .tbl .c { text-align: center; }
.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 6px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.badge i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st-draft { background: var(--s2); color: var(--tx2); } .st-issued { background: var(--bbg); color: var(--btx); } .st-paid { background: var(--gbg); color: var(--gtx); } .st-void { background: var(--rbg); color: var(--rtx); } .st-overdue { background: var(--rbg); color: var(--rtx); } .st-sent { background: var(--abg); color: var(--atx); }
.tag { display: inline-block; font-size: 11px; font-weight: 600; color: #fff; border-radius: 5px; padding: 1px 7px; white-space: nowrap; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.kpi { background: var(--sf); border: 1px solid var(--bd); border-radius: var(--rl); padding: 14px 16px; }
.kpi .l { font-size: 12px; color: var(--tx2); } .kpi .v { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; } .kpi .s { font-size: 11.5px; color: var(--tx3); margin-top: 2px; }
.empty { text-align: center; padding: 36px 16px; color: var(--tx3); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { height: 30px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--bd2); background: var(--sf); font-size: 12.5px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.chip.on { background: var(--tx); color: #fff; border-color: var(--tx); }
.chip .n { font-size: 11px; opacity: .7; }
.ph { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.ph h2 { font-size: 17px; font-weight: 600; margin-right: auto; }
.help { font-size: 12px; color: var(--tx2); background: var(--abg); border: 1px solid #FDE68A; border-radius: var(--r); padding: 8px 12px; line-height: 1.5; }
.help.info { background: var(--bbg); border-color: #BFDBFE; }
.help.danger { background: var(--rbg); border-color: #FECACA; color: var(--rtx); }

/* editor */
.ed { display: grid; grid-template-columns: minmax(0, 1fr) 420px; height: 100%; }
.ed .form { overflow: auto; padding: 16px 18px 0; display: flex; flex-direction: column; }
.ed .form > .body { flex: 1; padding-bottom: 24px; }
.ed .prev { border-left: 1px solid var(--bd); background: #e9e9e6; overflow: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.ed .prev iframe { border: 0; width: 100%; aspect-ratio: 210 / 297; background: #fff; box-shadow: 0 10px 30px -14px rgba(0,0,0,.4); border-radius: 3px; flex: none; }
.ed .prev .pl { font-size: 11.5px; color: var(--tx2); }
.edbar { position: sticky; bottom: 0; margin: 0 -18px; padding: 12px 18px; background: rgba(255,255,255,.96); backdrop-filter: blur(8px); border-top: 1px solid var(--bd); display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; z-index: 5; }
.edbar .grpL, .edbar .grpR { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.sel { height: 36px; padding: 0 30px 0 12px; border: 1px solid var(--bd2); border-radius: var(--r); background: var(--sf) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none' stroke='%236B6A65' stroke-width='1.8'%3E%3Cpath d='M1 1.5l5 5 5-5'/%3E%3C/svg%3E") no-repeat right 10px center; appearance: none; font-size: 13px; font-weight: 500; cursor: pointer; }
.items-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
.items { width: 100%; min-width: 640px; border-collapse: collapse; font-size: 13px; table-layout: fixed; }
.items th { font-size: 11.5px; color: var(--tx2); font-weight: 600; padding: 6px 6px; text-align: left; border-bottom: 1px solid var(--bd); }
.items td { padding: 4px 3px; border-bottom: 1px solid var(--bd); vertical-align: top; position: relative; }
.items td .in { height: 34px; }
.items td textarea.in { min-height: 34px; height: 34px; padding: 6px 8px; overflow: hidden; line-height: 1.4; }
.items .amt { text-align: right; font-weight: 600; padding-top: 11px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.items .del { border: 0; background: none; color: var(--tx3); cursor: pointer; font-size: 16px; padding: 8px 4px; }
.items .del:hover { color: var(--red); }
.tot { margin-left: auto; width: 320px; font-size: 13.5px; }
.tot .l { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; gap: 10px; }
.tot .l span:first-child { color: var(--tx2); }
.tot .g { border-top: 1.5px solid var(--tx); margin-top: 4px; padding-top: 8px; font-size: 17px; font-weight: 700; }
.tot .in { width: 110px; height: 30px; }
.sug { position: absolute; left: 0; right: 0; top: 100%; z-index: 30; background: var(--sf); border: 1px solid var(--bd2); border-radius: var(--r); box-shadow: 0 12px 30px -10px rgba(0,0,0,.25); max-height: 240px; overflow: auto; }
.sug div { padding: 7px 10px; cursor: pointer; border-bottom: 1px solid var(--bd); font-size: 13px; }
.sug div:last-child { border-bottom: 0; } .sug div:hover, .sug div.on { background: var(--s2); }
.sug small { display: block; color: var(--tx3); font-size: 11px; }
.cust-card { background: var(--s2); border-radius: var(--r); padding: 10px 12px; font-size: 12.5px; line-height: 1.5; }
.lock { background: var(--gbg); border: 1px solid #BBF7D0; color: var(--gtx); border-radius: var(--r); padding: 10px 12px; font-size: 13px; }

/* modal / toast */
.mbd { position: fixed; inset: 0; background: rgba(26,26,24,.45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; animation: fade .15s; }
.modal { background: var(--sf); border-radius: 14px; width: 100%; max-width: 520px; max-height: 92vh; overflow: auto; box-shadow: 0 30px 80px -20px rgba(0,0,0,.45); animation: up .2s cubic-bezier(.2,.8,.2,1); }
.modal.wide { max-width: 760px; } .modal.wide:has(#pf) { max-width: 900px; }
.mh { display: flex; align-items: center; gap: 10px; padding: 16px 18px 10px; } .mh h3 { font-size: 15.5px; font-weight: 600; flex: 1; }
.mb { padding: 4px 18px 18px; } .mf { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px 16px; border-top: 1px solid var(--bd); }
@keyframes fade { from { opacity: 0; } } @keyframes up { from { transform: translateY(14px); opacity: 0; } }
.toasts { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 200; display: grid; gap: 6px; }
.toast { background: #1A1A18; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13.5px; box-shadow: var(--shadow); animation: up .2s; }
.toast.err { background: #991B1B; }
.trial { background: var(--abg); border-bottom: 1px solid #FDE68A; color: var(--atx); font-size: 12.5px; padding: 6px 18px; display: flex; gap: 10px; align-items: center; }
.trial.backup { background: var(--bbg); border-color: #BFDBFE; color: var(--btx); }
.trial .btn.sm { height: 26px; font-size: 12px; } .btn.ghost { border-color: transparent; background: transparent; }
.trial.over { background: var(--rbg); border-color: #FECACA; color: var(--rtx); }
.timeline { font-size: 12px; color: var(--tx2); display: grid; gap: 6px; }
.timeline b { color: var(--tx); font-weight: 500; }
.linkchip { display: inline-flex; align-items: center; gap: 6px; background: var(--s2); border-radius: 6px; padding: 3px 8px; font-size: 12px; cursor: pointer; }
.linkchip:hover { background: var(--bd); }

@media (max-width: 1100px) { .ed { grid-template-columns: 1fr; } .ed .prev { display: none; } }
@media (max-width: 820px) {
  .side { display: none; } .mtop { display: flex; align-items: center; gap: 8px; padding: 10px 14px; background: var(--sf); border-bottom: 1px solid var(--bd); overflow-x: auto; }
  .mtop .ni { width: auto; white-space: nowrap; padding: 6px 10px; font-size: 12.5px; }
  .content { padding: 12px; } .g3, .g4 { grid-template-columns: 1fr 1fr; } .sec { grid-template-columns: 1fr; gap: 10px; } .tot { width: 100%; }
}
@media (max-width: 560px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } .top h1 { font-size: 14px; } }
:focus-visible { outline: 2px solid var(--tx); outline-offset: 2px; }

/* ===== 1.3.0 · iPad / จอสัมผัส (PWA) ===== */
/* safe-area: iPad รุ่นจอขอบมน + แถบสถานะเมื่อเปิดจากหน้าจอโฮม */
.shell { padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left); }
.side { padding-bottom: env(safe-area-inset-bottom); }
.content { padding-bottom: max(18px, env(safe-area-inset-bottom)); }
.edbar { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.toasts { bottom: max(22px, calc(env(safe-area-inset-bottom) + 12px)); }
html.standalone, html.standalone body { overscroll-behavior: none; }
.items-wrap { -webkit-overflow-scrolling: touch; }

/* iPad แนวนอน 11" (1180) / แนวตั้ง 13" (1024) / จอกลาง: เมนูซ้ายยุบเหลือไอคอน */
@media (min-width: 821px) and (max-width: 1180px) {
  .side { width: 64px; }
  .logo b { font-size: 0; } .logo b::before { content: "TB"; font-size: 15px; } .logo span { display: none; }
  .nav .grp { display: none; }
  .ni { justify-content: center; padding: 10px 0; font-size: 0; position: relative; }
  .ni svg { width: 21px; height: 21px; }
  .ni .cnt { position: absolute; top: 2px; right: 4px; font-size: 9.5px; padding: 0 4px; }
  .side .foot { font-size: 0; padding: 6px; } .side .foot b { display: none; }
}

/* จอสัมผัส: เป้ากดอย่างน้อย 44px · ช่องกรอก 16px (Safari ไม่ซูมเมื่อโฟกัส) · ไม่พึ่ง hover */
@media (pointer: coarse) {
  .btn, .chip, .sel { min-height: 44px; }
  .btn.sm, .trial .btn.sm { min-height: 40px; height: auto; padding-top: 6px; padding-bottom: 6px; }
  .ibtn { width: 44px; height: 44px; }
  .ni { min-height: 44px; }
  .mtop .ni { min-height: 40px; }
  .in, select.in, textarea.in, .in.sm, .sel { font-size: 16px; }
  .in, select.in, .in.sm { height: 44px; }
  .items td .in { height: 44px; } .items td textarea.in { min-height: 44px; height: 44px; padding: 10px 8px; }
  .items .amt { padding-top: 14px; } .items .del { padding: 12px 8px; font-size: 20px; }
  .tot .in { height: 40px; }
  .sw { width: 46px; height: 28px; } .sw i::after { width: 22px; height: 22px; } .sw input:checked + i::after { transform: translateX(18px); }
  .sug div { padding: 11px 12px; font-size: 15px; }
  .linkchip { padding: 8px 10px; }
  .tbl td { padding: 12px 10px; }
  .tbl tr.click:hover td { background: none; } .tbl tr.click:active td { background: #FAFAF7; }
  input[type=checkbox], input[type=radio] { width: 22px; height: 22px; }
  .modal { max-height: calc(100dvh - 40px); }
}
/* iPad แนวตั้ง (768–820): ใช้แถบเมนูด้านบนเลื่อนแนวนอน (มีอยู่แล้ว) + ฟอร์มเต็มกว้าง */
@media (min-width: 700px) and (max-width: 820px) { .g4 { grid-template-columns: 1fr 1fr; } .ed .form { padding: 14px 16px 0; } }

/* พิมพ์ในหน้าเดียวกัน (iPad / แอปหน้าจอโฮม) */
#printroot { position: fixed; inset: 0; z-index: 150; background: #e9e9e6; display: flex; flex-direction: column; }
#printroot .pr-bar { display: flex; gap: 10px; align-items: center; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; background: #1A1A18; color: #fff; }
#printroot .pr-doc { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; }
html.printing .shell { visibility: hidden; }
@media print {
  html.printing body { background: #fff; }
  html.printing .shell, html.printing #modal, html.printing .toasts, html.printing #printroot .pr-bar { display: none !important; }
  html.printing #printroot { position: static; background: #fff; display: block; }
  html.printing #printroot .pr-doc { overflow: visible; }
}
/* iOS: ตรึงโครงหน้าไว้กับจอ (ไม่ให้ทั้งหน้าเลื่อนหลบคีย์บอร์ดจนแถบเมนูหายใต้แถบสถานะ) · เนื้อหาเลื่อนใน .content แทน */
html.ios, html.ios body { height: 100%; overflow: hidden; }
html.ios .shell { position: fixed; inset: 0; height: auto; }
/* iOS: ช่องวันที่มีความกว้างในตัว ทำให้ล้นคอลัมน์ข้าง ๆ → บังคับให้เต็มช่องของตัวเอง */
input[type=date].in { min-width: 0; max-width: 100%; -webkit-appearance: none; appearance: none; display: block; text-align: left; }
#printroot .pr-bar .btn { background: #fff; color: #111; border-color: #fff; font-weight: 600; }
/* iOS Safari ไม่เปิดตัวเลือกไฟล์ถ้า <input type=file> ถูก display:none → ซ่อนแบบมองไม่เห็นแต่ยังอยู่ในหน้า (นำเข้าไฟล์สำรอง/โลโก้/ลายเซ็น) */
label:has(> input[type=file].hide) { position: relative; overflow: hidden; }
input[type=file].hide { display: block !important; position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; font-size: 0; }

/* ===== 1.4.0 · โทรศัพท์ (< 768px) ===== */
.mtop .sl { display: none; }
.quick { display: none; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
@media (max-width: 767px) {
  /* แถบเมนูล่าง (bottom tab) */
  .mtop { position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; display: grid !important; grid-template-columns: repeat(7, 1fr); gap: 0; padding: 4px 2px calc(4px + env(safe-area-inset-bottom)); border-top: 1px solid var(--bd); border-bottom: 0; background: rgba(255,255,255,.97); backdrop-filter: blur(10px); overflow: visible; }
  .mtop .ni { flex-direction: column; gap: 2px; padding: 6px 0 4px; min-height: 52px; font-size: 10.5px; border-radius: 10px; justify-content: center; position: relative; white-space: nowrap; }
  .mtop .ni svg { width: 22px; height: 22px; }
  .mtop .ni .lb { display: none; } .mtop .ni .sl { display: block; }
  .mtop .ni.on { background: transparent; color: var(--tx); font-weight: 700; } .mtop .ni.on svg { color: var(--blue); }
  .mtop .ni .cnt { position: absolute; top: 2px; right: calc(50% - 22px); margin: 0; font-size: 9.5px; padding: 0 5px; background: var(--red); color: #fff; }
  .content { padding: 12px 12px calc(84px + env(safe-area-inset-bottom)); }
  body.editing .mtop { display: none !important; }
  body.editing .content { padding-bottom: 0; }
  /* หัวหน้า: ชื่อหน้า + ปุ่มขึ้นบรรทัดใหม่เต็มกว้าง */
  .top { height: auto; min-height: 50px; flex-wrap: wrap; padding: 8px 12px; gap: 6px; }
  .top h1 { font-size: 16px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; max-width: 100%; }
  .top .grow { display: none; }
  #topact { width: 100%; } #topact .row { width: 100%; } #topact .row > select { flex: 1; width: auto !important; } #topact > .btn { margin-left: auto; }
  body.editing #topact { width: auto; margin-left: auto; }
  .trial { padding: 8px 12px; flex-wrap: wrap; font-size: 12.5px; }
  .quick { display: grid; grid-template-columns: 1fr 1fr; }
  .quick .btn:first-child { grid-column: 1 / -1; height: 56px; font-size: 16px; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi { padding: 10px 12px; } .kpi .v { font-size: 18px; } .kpi .l { font-size: 11.5px; }
  .card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .ph { gap: 8px; } .ph h2 { flex: 1; }
  .ph .chips { flex-wrap: nowrap; overflow-x: auto; width: 100%; padding-bottom: 2px; }
  .ph > select.in, .ph > input.in { width: 100% !important; }
  .ph > select.in { width: calc(50% - 4px) !important; }
  /* รายการเอกสาร → การ์ด */
  .doctbl thead { display: none; }
  .doctbl, .doctbl tbody { display: block; }
  .doctbl tr { display: grid; grid-template-columns: auto 1fr auto; grid-template-areas: "no no tot" "cu cu st" "tg dt pr"; align-items: center; gap: 4px 10px; padding: 10px 14px; border-bottom: 1px solid var(--bd); }
  .doctbl td { padding: 0 !important; border: 0 !important; }
  .doctbl td:nth-child(1) { grid-area: no; font-size: 14px; }
  .doctbl td:nth-child(2) { grid-area: tg; }
  .doctbl td:nth-child(3) { grid-area: dt; font-size: 12px; color: var(--tx2); }
  .doctbl td:nth-child(4) { grid-area: cu; font-size: 13.5px; }
  .doctbl td:nth-child(5) { grid-area: tot; font-weight: 700; font-size: 15px; justify-self: end; }
  .doctbl td:nth-child(6) { grid-area: st; justify-self: end; }
  .doctbl td:nth-child(7) { grid-area: pr; justify-self: end; } .doctbl td:nth-child(7) .btn { min-height: 34px; height: 34px; width: 40px; }
  .doctbl td:nth-child(4) .xs { display: inline; margin-left: 6px; }
  /* ฟอร์มเอกสาร: หน้าเดียวเลื่อนลง · รายการเป็นการ์ด */
  .ed .form { padding: 12px 12px 0; }
  .g4, .g3, .g2 { grid-template-columns: 1fr; }
  .g4 > label:nth-child(3), .g4 > label:nth-child(4) { } 
  .items-wrap { margin: 0; padding: 0; overflow: visible; }
  .items { min-width: 0; table-layout: auto; }
  .items thead { display: none; }
  .items, .items tbody { display: block; }
  .items tr { display: grid; grid-template-columns: 1fr 1fr 1fr 44px; grid-template-areas: "desc desc desc del" "qty unit price price" "disc code amt amt"; gap: 8px 8px; padding: 12px; margin-bottom: 10px; background: var(--sf); border: 1px solid var(--bd); border-radius: var(--rl); }
  .items td { border: 0; padding: 0; }
  .items td:nth-child(1) { grid-area: code; } .items td:nth-child(2) { grid-area: desc; } .items td:nth-child(3) { grid-area: qty; } .items td:nth-child(4) { grid-area: unit; }
  .items td:nth-child(5) { grid-area: price; } .items td:nth-child(6) { grid-area: disc; } .items td:nth-child(7) { grid-area: amt; } .items td:nth-child(8) { grid-area: del; text-align: right; }
  .items td:nth-child(n+1):nth-child(-n+6)::before { display: block; font-size: 11px; color: var(--tx2); margin-bottom: 3px; font-weight: 500; }
  .items td:nth-child(1)::before { content: "รหัส"; } .items td:nth-child(2)::before { content: "รายละเอียด"; } .items td:nth-child(3)::before { content: "จำนวน"; }
  .items td:nth-child(4)::before { content: "หน่วย"; } .items td:nth-child(5)::before { content: "ราคา/หน่วย"; } .items td:nth-child(6)::before { content: "ส่วนลด"; }
  .items .amt { align-self: end; padding: 0 0 10px; font-size: 17px; }
  .items .amt::before { content: "จำนวนเงิน "; font-size: 11px; font-weight: 500; color: var(--tx2); }
  .items td textarea.in { height: auto; min-height: 44px; }
  [data-a="addrow"] { width: 100%; height: 50px !important; font-size: 15px; border-style: dashed; }
  .ed .form .row[style*="align-items:flex-start"] { flex-direction: column; }
  .tot { width: 100%; margin: 0; }
  .ph[style*="margin:18px 0 6px"] .row { flex-wrap: wrap; }
  /* ปุ่มออกเอกสารติดล่างจอ */
  .edbar { position: sticky; bottom: 0; margin: 0 -12px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  .edbar .grpL, .edbar .grpR { width: 100%; }
  .edbar .grpL .btn.bp { flex: 1; height: 50px; font-size: 16px; }
  .edbar .grpR:empty { display: none; }
  .edbar .grpR .sel { width: 100%; }
  /* ตั้งค่า */
  .sec { padding: 14px; }
  /* modal เต็มกว้างแบบ bottom sheet */
  .mbd { align-items: flex-end; padding: 0; }
  .modal { max-width: none !important; border-radius: 16px 16px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  /* หน้าพิมพ์/แชร์ */
  #printroot .pr-bar { flex-wrap: wrap; gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 10px 8px; }
  #printroot .pr-bar .pr-t { order: -1; width: 100%; color: #ccc; }
  #printroot .pr-bar #pr-pdf { flex: 1; height: 46px; }
  .toasts { bottom: calc(90px + env(safe-area-inset-bottom)); width: calc(100% - 24px); }
  .toast { text-align: center; }
}
#printroot .pr-bar .btn.ghost-l { background: transparent; color: #fff; border-color: rgba(255,255,255,.35); }
#printroot .pr-bar .btn:disabled { opacity: .7; }
.trial svg { width: 16px; height: 16px; vertical-align: -3px; display: inline-block; }
@media (max-width: 767px) {
  body.editing #installbar { display: none; }
  body.editing .top { flex-wrap: nowrap; }
  body.editing .top h1 { flex: 1; min-width: 0; flex-wrap: nowrap; white-space: nowrap; overflow: hidden; }
  body.editing .top h1 .badge { flex: none; }
  body.editing #topact .btn { padding: 0 10px; }
  .ed .form .g4 { grid-template-columns: 1fr 1fr; }
  .ed .form .g4 > label:first-child { grid-column: 1 / -1; }
}
details.more { margin-top: 8px; } details.more > summary { cursor: pointer; font-size: 13px; color: var(--blue); padding: 10px 0; list-style: none; } details.more > summary::before { content: "＋ "; } details.more[open] > summary::before { content: "－ "; }
details.more > .g2:first-of-type > div:empty { display: none; }
.items .del svg { width: 18px; height: 18px; }
@media (max-width: 767px) {
  .items tr { grid-template-areas: "desc desc desc del" "qty unit price price" "disc disc amt amt"; }
  .items td:nth-child(1) { display: none; }
  .items .del { width: 44px; height: 44px; display: grid; place-items: center; border: 1px solid var(--bd); border-radius: 10px; margin-top: 18px; }
}
@media (max-width: 767px) {
  #printroot .pr-bar .pr-t { flex: 0 0 100%; }
  .doctbl td:nth-child(7) .btn { min-height: 44px !important; height: 44px !important; width: 44px; margin: -6px -8px -6px 0; }
}
@media (max-width: 767px) {
  .ed .form .row[style*="align-items:flex-start"] { align-items: stretch !important; }
  .ed .form .row[style*="align-items:flex-start"] > .grow { min-width: 0 !important; width: 100%; }
  .items td .sug { position: absolute; left: 0; right: 0; top: 100%; z-index: 40; }
  html.kb body.editing .edbar { padding-bottom: 8px; }
  html.kb .mtop { display: none !important; }
}
.pplist { display: grid; gap: 8px; }
.pp { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 56px; padding: 10px 12px; border: 1px solid var(--bd); border-radius: 12px; background: var(--sf); text-align: left; cursor: pointer; font-size: 15px; }
.pp:active { background: var(--s2); }
.pp .pn { flex: 1; min-width: 0; font-weight: 600; } .pp small { display: block; font-weight: 400; font-size: 12.5px; color: var(--tx2); margin-top: 2px; }
.pp .pq { flex: none; min-width: 44px; height: 36px; border-radius: 99px; background: var(--bbg); color: var(--btx); display: grid; place-items: center; font-weight: 700; padding: 0 10px; }
.pickbtn svg { width: 16px; height: 16px; }
@media (max-width: 767px) { .pickbtn { flex: 1; height: 50px !important; font-size: 15px; } [data-a="addrow"] { flex: 1; width: auto; } .modal .mh .btn.bp.sm { min-height: 40px; } }
/* แตะซ้ำเร็ว ๆ (เช่นเพิ่มสินค้าทีละชิ้น) ต้องไม่ซูมหน้าจอแบบ double-tap ของ iOS */
html, button, a, input, select, textarea, label, .pp { touch-action: manipulation; }
.pp.bump .pq { animation: ppbump .25s ease-out; background: var(--blue); color: #fff; }
@keyframes ppbump { 0% { transform: scale(1); } 50% { transform: scale(1.18); } 100% { transform: scale(1); } }
@media (max-width: 767px) { .ph .chips .chip { flex: none; white-space: nowrap; height: 40px; } }
.convbtns { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; width: 100%; }
.convbtns .xs { width: 100%; }
.convbtns .btn { flex: 1 1 30%; min-width: 0; padding: 0 8px; font-size: 14px; }
#installbar .trial { flex-wrap: nowrap; align-items: center; } #installbar .trial > span:first-child { flex: 1; min-width: 0; } #installbar .trial .grow { display: none; } #installbar .trial .btn { flex: none; }
