/* POOMWIWAT V8 - screen styles (colours come from theme.css) */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); font-size: 15px; color: var(--ink); background: var(--bg); line-height: 1.5; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; font-weight: 600; }
h2 { font-size: 17px; margin: 0 0 10px; font-weight: 600; }
h3 { font-size: 16px; margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pre { white-space: pre-wrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.err { color: var(--rust); font-size: 13px; margin: 4px 0 0; min-height: 0; }
.warn-text { color: #8a5a00; }
.ico { width: 20px; height: 20px; flex: none; }
[hidden] { display: none !important; }

.trial-banner { background: var(--amber); color: var(--ink); text-align: center; font-size: 13px; font-weight: 600; padding: 3px 8px; }

/* ---------- shell */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: var(--side-w); background: var(--side-bg); color: var(--side-ink); flex: none; position: sticky; top: 0; height: 100vh; overflow-y: auto; transition: width .15s; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 52px; display: flex; align-items: center; gap: 12px; padding: 0 18px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.crumb { font-size: 14px; color: var(--muted); }
.topbar-right { margin-left: auto; display: flex; gap: 10px; align-items: center; }
.view { padding: 18px 22px 40px; max-width: 1400px; width: 100%; }

.brand { display: flex; align-items: center; gap: 10px; padding: 14px 16px; color: #fff; font-weight: 600; border-bottom: 1px solid #262c36; }
.brand-mark { width: 32px; height: 32px; border-radius: 7px; background: var(--blue); color: var(--amber); display: grid; place-items: center; font-weight: 700; flex: none; }
.brand small { display: block; color: var(--side-ink); font-weight: 400; font-size: 11px; }
.nav { list-style: none; margin: 0; padding: 8px 0; }
.nav-item > a, .nav-item > button { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 18px; color: var(--side-ink); background: none; border: 0; font: inherit; cursor: pointer; text-align: left; }
.nav-item > a:hover, .nav-item > button:hover { background: #1f252f; color: #fff; text-decoration: none; }
.nav-item.active > a, .nav-item.active > button { color: #fff; box-shadow: inset 3px 0 0 var(--amber); background: #1b212a; }
.nav-item .chev { margin-left: auto; width: 16px; height: 16px; transition: transform .15s; }
.nav-item.open .chev { transform: rotate(90deg); }
.subnav { list-style: none; margin: 0; padding: 0 0 6px; display: none; }
.nav-item.open .subnav { display: block; }
.subnav a { display: block; padding: 6px 18px 6px 50px; color: var(--side-ink); font-size: 14px; }
.subnav a:hover { color: #fff; text-decoration: none; background: #1f252f; }
.subnav a.active { color: var(--amber); }
.nav .soon { font-size: 11px; color: #7d8592; margin-left: auto; }

body.side-mini .sidebar { width: var(--side-w-mini); overflow: visible; }
body.side-mini .brand-text, body.side-mini .nav-label, body.side-mini .nav-item .chev, body.side-mini .soon { display: none; }
body.side-mini .nav-item { position: relative; }
body.side-mini .nav-item > a, body.side-mini .nav-item > button { justify-content: center; padding: 12px 0; }
body.side-mini .subnav { position: absolute; left: var(--side-w-mini); top: 0; min-width: 210px; background: var(--side-bg); border-radius: 0 8px 8px 0; box-shadow: var(--shadow); z-index: 50; padding: 6px 0; }
body.side-mini .nav-item.open .subnav { display: none; }
body.side-mini .nav-item:hover .subnav { display: block; }
body.side-mini .subnav a { padding-left: 18px; }

/* ---------- buttons & inputs */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-size: 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #c5cad3; text-decoration: none; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: #194f9f; }
.btn-accent { background: var(--amber); border-color: var(--amber); color: var(--ink); font-weight: 600; }
.btn-danger { background: var(--rust); border-color: var(--rust); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; border: 0; background: transparent; color: inherit; cursor: pointer; font: inherit; }
.icon-btn:hover { background: var(--bg); }
input, select, textarea { font: inherit; font-size: 14px; color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; background: #fff; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue-soft); border-color: var(--blue); }
input[readonly] { background: var(--bg); }
input.invalid { border-color: var(--rust); background: var(--rust-soft); }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--blue); }
.fld { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--muted); }
.fld > span { font-weight: 600; }
.fld input, .fld select, .fld textarea { color: var(--ink); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.switch { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: 14px; color: var(--ink); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg label { padding: 5px 12px; cursor: pointer; font-size: 14px; background: #fff; }
.seg input { display: none; }
.seg label:has(input:checked) { background: var(--blue); color: #fff; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; box-shadow: var(--shadow); }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.net { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 3px 12px 3px 10px; font: inherit; font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.net::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: var(--green); }
.net.off { background: var(--rust-soft); border-color: var(--rust); color: var(--rust); }
.net.off::before { background: var(--rust); }

/* ---------- list */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters select, .filters input { width: auto; }
.filters .search { width: 260px; }
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow-x: auto; box-shadow: var(--shadow); }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th { text-align: left; font-weight: 600; color: var(--muted); background: #fafbfc; border-bottom: 1px solid var(--line); padding: 9px 10px; white-space: nowrap; font-size: 13px; }
table.list td { border-bottom: 1px solid var(--line); padding: 8px 10px; vertical-align: top; }
table.list tr:last-child td { border-bottom: 0; }
table.list tbody tr:hover { background: #f8fafd; }
table.list tr.clickable { cursor: pointer; }
table.list tr.cancelled td { opacity: .5; }
table.list tr.cancelled td.docno a { text-decoration: line-through; }
.docno { white-space: nowrap; }
.docno a { font-weight: 600; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot-grey { background: var(--grey-dot); } .dot-blue { background: var(--blue); } .dot-green { background: var(--green); } .dot-red { background: var(--rust); }
.rel { color: var(--muted); margin-left: 4px; vertical-align: middle; }
.rel .ico { width: 15px; height: 15px; }
.sub { font-size: 12px; color: var(--muted); }
.list-foot { display: flex; align-items: center; gap: 12px; padding: 10px 2px; font-size: 14px; color: var(--muted); flex-wrap: wrap; }
.list-foot .spacer { flex: 1; }
.list-foot select { width: auto; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px !important; }

.status-btn { display: inline-flex; align-items: center; gap: 4px; border-radius: 99px; padding: 2px 10px; font: inherit; font-size: 13px; border: 1px solid transparent; cursor: pointer; white-space: nowrap; background: var(--bg); color: var(--ink); }
.status-btn::after { content: '▾'; font-size: 10px; opacity: .7; }
.status-btn.no-menu { cursor: default; } .status-btn.no-menu::after { content: none; }
.st-grey { background: #EEF0F3; } .st-blue { background: var(--blue-soft); color: var(--blue); } .st-green { background: var(--green-soft); color: var(--green); } .st-red { background: var(--rust-soft); color: var(--rust); } .st-amber { background: var(--amber-soft); color: #7a5300; }

.menu { position: absolute; z-index: 100; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 28px rgba(20, 24, 31, .18); padding: 5px 0; min-width: 220px; max-width: 360px; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 7px 14px; font: inherit; font-size: 14px; cursor: pointer; color: var(--ink); }
.menu button:hover { background: var(--bg); }
.menu button.danger { color: var(--rust); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.menu .menu-title { font-size: 12px; color: var(--muted); padding: 4px 14px; }

/* ---------- modal & toast */
.modal-back { position: fixed; inset: 0; background: rgba(20, 24, 31, .45); display: grid; place-items: center; z-index: 200; padding: 16px; }
.modal { background: #fff; border-radius: 12px; width: min(520px, 100%); max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal-wide { width: min(820px, 100%); }
.modal-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head .icon-btn { margin-left: auto; }
.modal-body { padding: 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 300; }
.toast { background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 8px; max-width: 420px; white-space: pre-wrap; box-shadow: var(--shadow); font-size: 14px; }
.toast-err { background: var(--rust); } .toast-warn { background: var(--amber); color: var(--ink); } .toast-ok { background: var(--green); }
.callout { padding: 10px 12px; border-radius: 8px; font-size: 14px; }
.callout-warn { background: var(--amber-soft); color: #6b4900; }
.callout-err { background: var(--rust-soft); color: var(--rust); }
.callout-ok { background: var(--green-soft); color: var(--green); }
.callout-info { background: var(--blue-soft); color: #173f7a; }
.sumtbl { width: 100%; font-size: 14px; border-collapse: collapse; }
.sumtbl td { padding: 3px 0; }
.sumtbl td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.sumtbl tr.big td { font-weight: 600; font-size: 16px; border-top: 1px solid var(--line); padding-top: 6px; }

/* ---------- document form */
.form-top { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; }
.grand-box { background: var(--blue-soft); border-radius: 10px; padding: 12px 16px; text-align: right; margin-bottom: 12px; }
.grand-box .lbl { font-size: 13px; color: var(--muted); }
.grand-box .amt { font-size: 30px; font-weight: 600; color: var(--blue); font-variant-numeric: tabular-nums; line-height: 1.2; }
.grand-box .unit { font-size: 15px; color: var(--muted); margin-left: 4px; }
.picker { position: relative; }
.picker-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 60; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); max-height: 280px; overflow-y: auto; }
.picker-list button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 7px 10px; font: inherit; font-size: 14px; cursor: pointer; }
.picker-list button:hover, .picker-list button.hl { background: var(--blue-soft); }
.picker-list .sub { display: block; }
table.lines { width: 100%; border-collapse: collapse; font-size: 14px; }
table.lines th { background: #fafbfc; color: var(--muted); font-size: 13px; font-weight: 600; text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.lines td { padding: 5px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.lines td.no { width: 36px; color: var(--muted); text-align: center; padding-top: 12px; }
table.lines input.num { text-align: right; }
table.lines .c-qty { width: 90px; } table.lines .c-unit { width: 90px; } table.lines .c-price { width: 120px; } table.lines .c-disc { width: 100px; } table.lines .c-total { width: 120px; } table.lines .c-act { width: 92px; white-space: nowrap; }
table.lines td.c-total { padding-top: 12px; font-weight: 600; }
table.lines textarea { resize: vertical; min-height: 36px; }
.line-desc { display: flex; flex-direction: column; gap: 4px; }
.form-bottom { display: grid; grid-template-columns: 1fr 380px; gap: 18px; margin-top: 14px; }
.summary .r { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 14px; }
.summary .r .v { margin-left: auto; font-variant-numeric: tabular-nums; min-width: 110px; text-align: right; }
.summary .r.big { font-weight: 600; font-size: 16px; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 9px; }
.summary .r.pay { font-weight: 600; font-size: 17px; color: var(--blue); }
.summary .r select, .summary .r input { width: auto; }
.summary .disc-in { width: 100px !important; text-align: right; }
.form-actions { position: sticky; bottom: 0; background: rgba(244, 245, 247, .95); backdrop-filter: blur(4px); padding: 12px 0; margin-top: 16px; display: flex; gap: 8px; justify-content: flex-end; border-top: 1px solid var(--line); z-index: 10; }
.attach-list { list-style: none; padding: 0; margin: 6px 0 0; font-size: 13px; }
.attach-list li { display: flex; gap: 8px; align-items: center; padding: 2px 0; }
.adjust-box { background: var(--amber-soft); border-radius: 10px; padding: 12px 16px; margin-top: 14px; }

/* ---------- view page */
.view-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
.paper-stage { background: #d9dde3; border-radius: 10px; padding: 18px; overflow-x: auto; }
.side-panel { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 70px; }
.chain { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.chain li { padding: 6px 0; border-bottom: 1px dashed var(--line); display: flex; gap: 8px; align-items: baseline; }
.chain li:last-child { border-bottom: 0; }
.chain li.me { font-weight: 600; }
.history { list-style: none; margin: 0; padding: 0; font-size: 13px; max-height: 320px; overflow-y: auto; }
.history li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.history .when { color: var(--muted); font-size: 12px; }

/* ---------- dashboard */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.kpi .lbl { color: var(--muted); font-size: 13px; }
.kpi .amt { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 13px; }
.kpi.k-blue { border-top: 3px solid var(--blue); } .kpi.k-amber { border-top: 3px solid var(--amber); } .kpi.k-rust { border-top: 3px solid var(--rust); } .kpi.k-green { border-top: 3px solid var(--green); }
.quick { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }

.settings-img { display: flex; gap: 14px; flex-wrap: wrap; }
.settings-img .slot { border: 1px dashed var(--line); border-radius: 10px; padding: 10px; width: 200px; text-align: center; font-size: 13px; }
.settings-img img { max-width: 100%; max-height: 90px; display: block; margin: 6px auto; }

/* ---------- iPad / narrow */
@media (max-width: 1100px) {
  .view-layout { grid-template-columns: 1fr; }
  .side-panel { position: static; }
  .form-bottom { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 820px) {
  .form-top, .grid3, .grid4 { grid-template-columns: 1fr 1fr; }
  .view { padding: 12px; }
  .filters .search { width: 100%; }
}

/* ---------- Thai date field */
.datefield { position: relative; display: flex; align-items: center; width: 100%; }
.datefield .date-text { padding-right: 34px; }
.datefield .date-iso { position: absolute; right: 0; bottom: 0; width: 34px; height: 100%; opacity: 0; pointer-events: none; }
.datefield .date-btn { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); border: 0; background: none; cursor: pointer; font-size: 15px; padding: 4px 6px; line-height: 1; }
.datefield.is-ro .date-text { background: var(--bg); }
.filters .datefield { width: 150px; }
table.lines tr.sys-line td { background: var(--amber-soft); }
table.lines tr.sys-line input[readonly] { background: transparent; border-color: transparent; }

/* ---------- login / roles */
body.auth-page .sidebar, body.auth-page .topbar { display: none; }
.login-wrap { min-height: 80vh; display: grid; place-items: center; }
.login-card { width: min(420px, 100%); display: flex; flex-direction: column; gap: 10px; }
.brand-mark.big { width: 52px; height: 52px; font-size: 20px; border-radius: 12px; }
.role-sel { width: auto; height: 30px; padding: 2px 6px; font-size: 13px; }
.user-chip { font-size: 13px; color: var(--muted); }
.queue-badge { background: var(--amber-soft); color: #6b4900; border-color: var(--amber); }
.data-mode { display: flex; flex-direction: column; gap: 8px; }
.pay-items input { width: 120px; }

/* ---------- dashboard chart + reports */
.kpis-6 { grid-template-columns: repeat(6, 1fr); }
a.kpi { color: inherit; text-decoration: none; }
a.kpi:hover { border-color: var(--blue); text-decoration: none; }
.kpi .amt small { font-size: 14px; font-weight: 400; color: var(--muted); }
.dash-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; }
svg.bars { width: 100%; height: auto; display: block; }
svg.bars .grid { stroke: var(--line); stroke-width: 1; }
svg.bars .ax { font-size: 11px; fill: var(--muted); font-family: var(--font); }
svg.bars .val { font-size: 10px; fill: var(--ink); font-family: var(--font); }
svg.bars .bar { fill: #9DB8E3; }
svg.bars .bar.cur { fill: var(--blue); }
svg.bars g:hover .bar { fill: var(--amber); }
.report-index { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.report-card { display: flex; flex-direction: column; gap: 4px; color: inherit; text-decoration: none; }
.report-card:hover { border-color: var(--blue); text-decoration: none; }
.report-head { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 10px; align-items: start; margin: 4px 0 10px; }
.report-title { text-align: center; }
.report-title h2 { margin: 0; }
table.report-table tfoot td { font-weight: 600; border-top: 2px solid var(--ink); background: #fafbfc; padding: 8px 10px; }
@media (max-width: 1250px) { .kpis-6 { grid-template-columns: repeat(3, 1fr); } .dash-grid { grid-template-columns: 1fr; } }
@media print {
  .report-sheet .table-wrap { box-shadow: none; border: 0; overflow: visible; }
  .report-sheet table.list { font-size: 10.5px; }
  .report-sheet table.list th, .report-sheet table.list td { padding: 3px 5px; }
  .report-sheet thead { display: table-header-group; }
  .report-sheet tr { break-inside: avoid; }
  .report-sheet a { color: inherit; text-decoration: none; }
}

/* ---------- import wizard */
.steps { display: flex; gap: 6px; list-style: none; padding: 0; margin: 0 0 14px; counter-reset: st; flex-wrap: wrap; }
.steps li { counter-increment: st; padding: 6px 12px 6px 8px; border-radius: 99px; background: #EEF0F3; color: var(--muted); font-size: 13px; }
.steps li::before { content: counter(st); display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: #fff; margin-right: 6px; font-weight: 600; }
.steps li.on { background: var(--blue-soft); color: var(--blue); }
.imp-step { margin-bottom: 14px; }
table.preview td, table.preview th { white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; font-size: 13px; padding: 4px 8px; }
table.preview tr.hdr td { background: var(--amber-soft); font-weight: 600; }
table.preview tr.skip td { color: #aab; }
table.preview tbody tr { cursor: pointer; }
table.map-table select { max-width: 360px; }
.imp-summary { gap: 8px; }
tr.row-err td { background: #fff6f3; }
tr.row-warn td { background: #fffbef; }
#preset-bar select { width: auto; min-width: 220px; }

/* ---------- bill inbox / LINE employees */
.kpis-6 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 5px 12px; font: inherit; font-size: 13px; cursor: pointer; }
.chip.on { background: var(--blue); border-color: var(--blue); color: #fff; }
.chip b { margin-left: 4px; }
.bill-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.bill-card { padding: 0; overflow: hidden; color: inherit; text-decoration: none; display: flex; flex-direction: column; }
.bill-card:hover { border-color: var(--blue); text-decoration: none; }
.bill-card.is-returned { opacity: .75; }
.bill-thumb { height: 170px; background: #eef0f3; display: grid; place-items: center; position: relative; overflow: hidden; }
.bill-thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.bill-thumb .pdf { font-weight: 700; color: var(--rust); font-size: 28px; }
.bill-thumb .n-files { position: absolute; right: 8px; bottom: 8px; background: rgba(20,24,31,.75); color: #fff; font-size: 12px; padding: 1px 8px; border-radius: 99px; }
.bill-meta { padding: 10px 12px; display: flex; flex-direction: column; gap: 3px; }
.bill-detail { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(320px, 1fr); gap: 16px; align-items: start; }
.viewer-card { padding: 10px; }
.viewer { height: 560px; background: #2a2f38; border-radius: 8px; overflow: hidden; display: grid; place-items: center; cursor: grab; touch-action: none; user-select: none; }
.viewer img { max-width: 100%; max-height: 100%; transform-origin: center; transition: transform .05s; }
.viewer iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.viewer-bar { display: flex; gap: 6px; align-items: center; margin-top: 8px; }
.thumbs { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.thumbs button { width: 64px; height: 64px; border: 2px solid var(--line); border-radius: 6px; padding: 0; overflow: hidden; background: #fff; cursor: pointer; }
.thumbs button.on { border-color: var(--blue); }
.thumbs img { width: 100%; height: 100%; object-fit: cover; }
.link-code { font-size: 48px; font-weight: 700; letter-spacing: 10px; text-align: center; color: var(--blue); background: var(--blue-soft); border-radius: 12px; padding: 14px; font-variant-numeric: tabular-nums; }
.big-instr { font-size: 22px; }
@media (max-width: 1100px) { .bill-detail { grid-template-columns: 1fr; } .viewer { height: 420px; } }

/* =====================================================================
   iPad / touch (round 8)
   ===================================================================== */
html { -webkit-text-size-adjust: 100%; }
body { padding-bottom: env(safe-area-inset-bottom); }
.update-banner { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 400; background: var(--ink); color: #fff; border: 0; border-radius: 99px; padding: 12px 22px; font: inherit; font-weight: 600; box-shadow: var(--shadow); cursor: pointer; min-height: 44px; }
.offline-note { margin-bottom: 12px; }
.lock-screen { position: fixed; inset: 0; z-index: 500; background: rgba(20,24,31,.92); display: grid; place-items: center; }
.lock-screen .card { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 30px 40px; }
.btn-big { min-height: 52px; font-size: 17px; padding: 0 22px; justify-content: center; }
.btn-ok { background: var(--green); border-color: var(--green); color: #fff; }

/* hide amounts for viewing in public */
body.hide-amounts .num, body.hide-amounts .amt, body.hide-amounts #grand, body.hide-amounts .p-sum td:last-child, body.hide-amounts .p-words,
body.hide-amounts .sumtbl td:last-child, body.hide-amounts .summary .v, body.hide-amounts .bill-meta b, body.hide-amounts svg.bars .val, body.hide-amounts svg.bars .ax[text-anchor="end"] {
  filter: blur(7px); user-select: none;
}
@media print { body.hide-amounts * { filter: none !important; } }

/* bottom sheet (reason) */
.modal-back.as-sheet { place-items: end center; padding: 0; }
.modal-back.as-sheet .modal { width: min(680px, 100%); border-radius: 16px 16px 0 0; padding-bottom: env(safe-area-inset-bottom); animation: sheet-up .18s ease-out; }
@keyframes sheet-up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }

/* bottom tab bar (exec mode) */
.tabbar { display: none; }
body.exec-mode .sidebar, body.exec-mode #toggle-side { display: none; }
body.exec-mode .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 90; background: #fff; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -2px 12px rgba(20,24,31,.06); }
body.exec-mode .tabbar a, body.exec-mode .tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 58px; font: inherit; font-size: 12px; color: var(--muted); text-decoration: none; background: none; border: 0; cursor: pointer; }
body.exec-mode .tabbar .ti { font-size: 20px; line-height: 1; }
body.exec-mode .tabbar a.on { color: var(--blue); font-weight: 600; }
body.exec-mode .view { padding-bottom: 90px; }
body.exec-mode .form-actions { bottom: calc(58px + env(safe-area-inset-bottom)); }

/* executive home */
.ptr { height: 0; overflow: hidden; text-align: center; color: var(--muted); font-size: 13px; transition: height .15s; display: flex; align-items: flex-end; justify-content: center; }
.exec-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.exec-kpis .amt { font-size: 26px; }
.exec-h2 { margin: 20px 0 10px; font-size: 19px; }
.exec-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; align-items: start; }
.exec-sec h3 { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.exec-side { display: flex; flex-direction: column; gap: 14px; }
.exec-tile { color: inherit; text-decoration: none; }
.exec-tile .amt { font-size: 34px; font-weight: 600; color: #7a5300; }
.decide-list { display: flex; flex-direction: column; gap: 10px; }
.decide-card { position: relative; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); touch-action: pan-y; }
.decide-card .swipe-bg { position: absolute; inset: 0; display: flex; justify-content: space-between; align-items: center; padding: 0 18px; font-weight: 600; color: #fff; background: var(--line); }
.decide-card.to-ok .swipe-bg { background: var(--green); }
.decide-card.to-no .swipe-bg { background: var(--rust); }
.decide-card .decide-body { position: relative; background: #fff; padding: 12px 14px; display: flex; flex-direction: column; gap: 3px; transition: transform .12s; }
.decide-actions { display: flex; gap: 10px; margin-top: 8px; }
.decide-actions .btn { flex: 1; }
.quick-links { display: flex; flex-direction: column; gap: 8px; }
.quick-links .btn { justify-content: flex-start; min-height: 46px; }
ul.plain { list-style: none; padding: 0; margin: 0; } ul.plain li { padding: 8px 0; border-bottom: 1px solid var(--line); }
@media (max-width: 1000px) { .exec-grid { grid-template-columns: 1fr; } .exec-kpis { grid-template-columns: repeat(2, 1fr); } }

/* paper fit-to-screen (doc view) */
.paper-stage.is-fit .paper { zoom: var(--paper-zoom, 1); }
.fit-btn { display: none; }
@media (max-width: 1100px) { .fit-btn { display: inline-flex; } }

/* touch targets >= 44 px, no hover-only actions */
@media (pointer: coarse), (max-width: 1180px) {
  .btn { min-height: 44px; }
  .btn-sm { min-height: 40px; padding: 0 12px; }
  .icon-btn { width: 44px; height: 44px; }
  input, select, textarea { min-height: 44px; font-size: 16px; } /* 16 px stops iOS zoom-on-focus */
  input[type=checkbox], input[type=radio] { min-height: 0; width: 22px; height: 22px; }
  .status-btn { min-height: 36px; padding: 4px 14px; }
  .menu button { padding: 12px 16px; font-size: 16px; }
  .chip { min-height: 40px; padding: 6px 14px; }
  .seg label { padding: 10px 14px; }
  .nav-item > a, .nav-item > button { min-height: 48px; }
  .subnav a { padding-top: 12px; padding-bottom: 12px; }
  .picker-list button { padding: 12px; }
  .datefield .date-btn { width: 44px; height: 100%; font-size: 18px; }
  .datefield .date-iso { pointer-events: auto; width: 44px; z-index: 2; } /* tap opens the native (touch) date wheel */
  .datefield .date-text { padding-right: 48px; }
  table.lines .c-act { width: 140px; }
  .modal-foot .btn { min-width: 100px; justify-content: center; }
}
/* mini sidebar: flyouts open on tap (hover only where a mouse exists) */
body.side-mini .nav-item.open .subnav { display: none; }
body.side-mini .nav-item.flyout .subnav { display: block; }
@media (hover: none) { body.side-mini .nav-item:hover .subnav { display: none; } body.side-mini .nav-item.flyout .subnav { display: block; } }

/* tables -> card lists under 900 px (screen only: printing keeps real tables) */
@media screen and (max-width: 900px) {
  table.list.cardable, table.list.cardable tbody, table.list.cardable tfoot { display: block; }
  table.list.cardable thead { display: none; }
  table.list.cardable tr { display: block; border: 1px solid var(--line); border-radius: 10px; margin: 0 8px 10px; padding: 6px 10px; background: #fff; }
  table.list.cardable tbody tr:first-child { margin-top: 8px; }
  table.list.cardable td { display: block; position: relative; border: 0; padding: 7px 2px 7px 42%; text-align: right; min-height: 34px; }
  table.list.cardable td::before { content: attr(data-label); position: absolute; left: 2px; top: 8px; width: 40%; color: var(--muted); font-size: 13px; text-align: left; }
  table.list.cardable td:not([data-label]), table.list.cardable td[data-label=""] { padding-left: 2px; }
  table.list.cardable td:not([data-label])::before, table.list.cardable td[data-label=""]::before { content: none; }
  table.list.cardable td.empty { text-align: center; padding-left: 2px; }
  table.list.cardable td:has(> input.chk), table.list.cardable td:has(> input[type=checkbox]:only-child):first-child { display: none; }
  table.list.cardable tr { position: relative; }
  table.list.cardable td:last-child:has(> [data-more]) { position: absolute; bottom: 6px; left: 4px; padding: 0; min-height: 0; text-align: left; }
  .table-wrap { background: transparent; border: 0; box-shadow: none; overflow: visible; }
  .filters { gap: 8px; }
  .filters select, .filters input, .filters .search { flex: 1 1 45%; }
  .page-head h1 { font-size: 20px; }
  .form-top { grid-template-columns: 1fr; }
  .card[style*="padding:0"] > table.lines, .card > table.lines { display: block; overflow-x: auto; }
  table.lines { min-width: 760px; }
  .view-layout { grid-template-columns: 1fr; }
  .report-head { grid-template-columns: 1fr; text-align: left; }
  .report-title { text-align: left; }
}
@media print { table.list.cardable thead { display: table-header-group !important; } }
@media (pointer: coarse), (max-width: 1180px) { .net { min-height: 44px; } .badge { line-height: 1.6; } }
@media (max-width: 1180px) { #toasts { top: calc(60px + env(safe-area-inset-top)); bottom: auto; right: 12px; } }

/* ---------- accountant access / tax reports (round 9) */
.ro-banner { background: #5B6472; color: #fff; text-align: center; font-size: 13px; font-weight: 600; padding: 4px 8px; }
.role-help { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.role-help .card p { margin: 4px 0 0; }
.role-opt { display: block; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-top: 6px; cursor: pointer; color: var(--ink); }
.role-opt:has(input:checked) { border-color: var(--blue); background: var(--blue-soft); }
.tax-head { display: grid; grid-template-columns: 1fr 1.6fr; gap: 16px; align-items: start; margin-bottom: 12px; }
.tax-title h2 { margin: 0; font-size: 20px; }
.tax-company { border-collapse: collapse; font-size: 13px; width: 100%; }
.tax-company th { text-align: left; color: var(--muted); font-weight: 600; padding: 2px 8px 2px 0; white-space: nowrap; }
.tax-company td { padding: 2px 12px 2px 0; }
table.tax-table th { white-space: normal; font-size: 12px; vertical-align: bottom; }
.gap-banner { border-radius: 10px; padding: 14px 18px; font-size: 18px; font-weight: 600; margin-bottom: 12px; }
.gap-banner.ok { background: var(--green-soft); color: var(--green); border: 2px solid var(--green); }
.gap-banner.bad { background: var(--rust-soft); color: var(--rust); border: 2px solid var(--rust); }
.gap-list { font-size: 14px; font-weight: 400; margin-top: 6px; }
.pack-card { max-width: 720px; display: flex; flex-direction: column; gap: 10px; }
.pack-list { margin: 0; padding-left: 18px; color: var(--muted); }
.print-only { display: none; }
@media print { .print-only { display: block; } .tax-head { grid-template-columns: 1fr 1.6fr; } }
@media (max-width: 900px) { .role-help, .tax-head { grid-template-columns: 1fr; } }
.progress { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--blue); transition: width .2s; }

/* round 11: ปิดเดือนภาษี */
.lock-badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; background: #fdecea; color: #a5281b; border: 1px solid #f3b8b0; font-size: 12px; font-weight: 600; white-space: nowrap; vertical-align: middle; }
.lock-hint { color: #a5281b; max-width: 520px; }
.menu .menu-note { padding: 6px 14px; font-size: 12px; color: #a5281b; max-width: 300px; white-space: normal; }
.toast .err-detail { margin-top: 6px; font-size: 12px; }
.toast .err-detail summary { cursor: pointer; opacity: .85; }
.toast .err-detail pre { white-space: pre-wrap; word-break: break-word; max-height: 140px; overflow: auto; margin: 4px 0 0; font-size: 11px; opacity: .9; }

/* round 13: document action bar, settings panel, share dialog, envelope */
.doc-bar { display: inline-flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.doc-settings .switch { display: flex; gap: 8px; align-items: baseline; margin: 8px 0; flex-wrap: wrap; }
.doc-settings h3 { margin: 4px 0 2px; font-size: 14px; }
.summary .whtg small { font-weight: 400; }
input.ro { background: var(--bg, #f4f5f7); color: var(--muted, #667); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line, #dde); margin-bottom: 12px; }
.tabs .tab { border: 0; background: none; padding: 8px 14px; font: inherit; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted, #667); }
.tabs .tab.on { border-bottom-color: var(--brand, #1f5fbf); color: var(--ink, #222); font-weight: 600; }
.share-out { margin-top: 10px; }
.share-list { list-style: none; padding: 0; margin: 0; }
.share-list li { display: flex; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line, #eee); }
.share-list li span { flex: 1; }
#envelope-print { display: none; }
.envelope { position: relative; box-sizing: border-box; padding: 10mm 12mm; font-size: 12pt; color: #111; background: #fff; }
.envelope .env-from { font-size: 10pt; max-width: 45%; }
.envelope .env-to { position: absolute; left: 45%; top: 45%; max-width: 50%; font-size: 13pt; }
.envelope .env-lbl { font-size: 10pt; color: #555; }
.envelope .env-post { letter-spacing: 3px; font-weight: 700; margin-top: 2mm; }
@media print {
  body.print-envelope > *:not(#envelope-print) { display: none !important; }
  body.print-envelope #envelope-print { display: block !important; }
}
.theme-pick { gap: 10px; flex-wrap: wrap; }
.theme-opt .swatch { display: inline-block; width: 16px; height: 16px; border-radius: 4px; vertical-align: middle; margin: 0 4px; border: 1px solid rgba(0,0,0,.2); }
.theme-opt input[type=color] { width: 34px; height: 24px; padding: 0; border: 1px solid #ccc; margin-left: 4px; }
.overdue-head { display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 12px 16px 6px; }
.overdue-head select { font-weight: 600; font-size: 15px; max-width: 100%; }
.overdue-card tr.is-overdue td.docno a { color: var(--rust, #b3261e); }
.overdue-foot { padding: 8px 16px 12px; }
/* company logo (static file: works offline and before login) */
.brand-logo { width: 40px; height: 40px; border-radius: 9px; background: #fff; display: grid; place-items: center; flex: none; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.brand-logo img { width: 32px; height: auto; display: block; }
.brand-full { display: block; margin: 0 auto 8px; width: 150px; height: auto; }
.nav-badge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: #d93a2b; color: #fff; font-size: 11px; font-weight: 700; margin-left: auto; }
.subnav a .nav-badge { margin-left: 6px; }
a.callout.line-wait { display: block; margin-bottom: 12px; text-decoration: none; color: inherit; }
.line-pending h2 .badge-alert, .badge-alert { background: #d93a2b; color: #fff; }
.pend-row { display: grid; grid-template-columns: minmax(180px, 1fr) auto auto; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line, #eee); }
.pend-thumbs { display: flex; gap: 6px; }
.pend-thumbs img { width: 54px; height: 54px; object-fit: cover; border-radius: 6px; border: 1px solid #ddd; background: #fff; }
.pend-act { display: flex; gap: 6px; }
@media (max-width: 700px) { .pend-row { grid-template-columns: 1fr; } }
.schema-banner { background: #fdecea; color: #8a1c12; border-bottom: 1px solid #f3b8b0; padding: 6px 16px; font-size: 13px; font-weight: 600; text-align: center; }

/* dashboard hero banner (owner-approved "แบบ A"); fonts come from css/fonts (tools/vendor-fonts.ps1), never Google at runtime */
@font-face { font-family: 'Bebas Neue'; font-style: normal; font-weight: 400; font-display: swap; src: local('Bebas Neue'), local('BebasNeue-Regular'), url('fonts/BebasNeue-Regular.ttf') format('truetype'); }
@font-face { font-family: 'Anuphan'; font-style: normal; font-weight: 100 700; font-display: swap; src: local('Anuphan'), url('fonts/Anuphan-wght.ttf') format('truetype'); }
.hero { position: relative; overflow: hidden; border-radius: 20px; height: 220px; margin-bottom: 16px; box-shadow: 0 12px 30px rgba(10, 25, 50, .18); background: #dfe6f2 url('../img/dashboard-hero.jpg') center / cover no-repeat; }
.hero .fade { position: absolute; inset: 0; background: linear-gradient(90deg, rgba(255, 255, 255, .96) 0%, rgba(255, 255, 255, .86) 38%, rgba(255, 255, 255, 0) 64%); }
.hero .box { position: absolute; left: 40px; top: 0; bottom: 0; display: flex; gap: 26px; align-items: center; }
.hero .logo3d { width: 118px; height: 118px; flex: none; border-radius: 26px; display: grid; place-items: center; background: linear-gradient(145deg, #fff, #e3e9f3);
  box-shadow: 0 14px 26px rgba(0, 0, 0, .28), inset 0 2px 0 #fff, inset 0 -4px 8px rgba(20, 40, 90, .15); transform: perspective(500px) rotateY(-12deg) rotateX(4deg); }
.hero .logo3d img { width: 92px; height: auto; filter: drop-shadow(3px 5px 3px rgba(10, 30, 90, .35)); }
.hero .en { font: 400 56px 'Bebas Neue', 'Oswald', Impact, sans-serif; letter-spacing: .06em; line-height: 1; color: #0d2a6b; white-space: nowrap; }
.hero .th { font: 400 16px 'Anuphan', var(--font); color: #3b4a66; margin-top: 8px; }
.hero .tag { font: 400 17px 'Bebas Neue', 'Oswald', Impact, sans-serif; letter-spacing: .4em; color: #2a5bd7; margin-top: 10px; }
@media (max-width: 1180px), (max-width: 900px) {
  .hero { height: 170px; }
  .hero .box { left: 24px; gap: 18px; }
  .hero .logo3d { width: 84px; height: 84px; border-radius: 20px; }
  .hero .logo3d img { width: 66px; }
  .hero .en { font-size: 40px; }
}
@media (max-width: 600px) { .hero .tag { display: none; } .hero .en { font-size: 30px; } .hero .th { font-size: 14px; } }

/* r14 iPad polish: touch targets >= 44px on touch screens / iPad widths; no sideways page scroll */
.lines-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
@media (pointer: coarse), (max-width: 1180px) {
  .btn, .btn-sm, .doc-bar .btn, .tabs .tab, .status-btn:not(.no-menu), #view select, .modal select, #view input:not([type=checkbox]):not([type=radio]):not([type=file]):not(.date-iso), .modal input:not([type=checkbox]):not([type=radio]) { min-height: 44px; }
  .btn-sm { padding: 0 12px; }
  .switch { min-height: 44px; padding: 0 4px; }
  .switch input[type=checkbox], .switch input[type=radio] { width: 22px; height: 22px; }
  .seg label { min-height: 44px; display: inline-flex; align-items: center; padding: 0 14px; }
  .doc-bar { gap: 8px; }
  .page-head { flex-wrap: wrap; row-gap: 8px; }
  .doc-settings .switch { padding: 6px 4px; }
  .pend-act .btn { min-width: 88px; justify-content: center; }
  .share-list li .btn { min-width: 88px; justify-content: center; }
}
table.lines .c-wht { width: 96px; }
@media (max-width: 900px) {
  table.lines .c-qty, table.lines .c-unit { width: 70px; } table.lines .c-price, table.lines .c-total { width: 100px; } table.lines .c-disc { width: 84px; }
  table.lines .c-act { width: 1%; } table.lines td.c-act .icon-btn { width: 30px; }
  table.lines td, table.lines th { padding-left: 4px; padding-right: 4px; }
}
