:root {
  --bg: #f5f6f8; --panel: #fff; --ink: #1d2433; --muted: #667085; --line: #e3e6eb; --line2: #eef0f3;
  --brand: #1f5fbf; --brand-ink: #fff; --brand-soft: #e8f0fc; --ok: #137a4b; --ok-soft: #e6f4ec;
  --warn: #9a6200; --warn-soft: #fff4dc; --bad: #b42318; --bad-soft: #fdecea; --side: #14213d;
  --radius: 8px; --font: 'IBM Plex Sans Thai', 'Sarabun', system-ui, sans-serif; --mono: 'IBM Plex Mono', ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.55 var(--font); color: var(--ink); background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; font-weight: 600; }
h2 { font-size: 17px; margin: 24px 0 10px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { text-align: right; font-family: var(--mono); font-size: 14px; white-space: nowrap; }
.boot { padding: 40px; color: var(--muted); }

/* ---------- โครงหน้า ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: var(--side); color: #c9d2e3; padding: 16px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .logo { color: #fff; font-weight: 700; font-size: 18px; padding: 4px 10px 14px; letter-spacing: .3px; }
.side .logo span { color: #7fb0ff; }
.side .grp { font-size: 12px; text-transform: uppercase; color: #7c89a6; margin: 16px 10px 4px; letter-spacing: .5px; }
.side a, .side .soon { display: flex; justify-content: space-between; align-items: center; color: #d6deec; padding: 7px 10px; border-radius: 6px; font-size: 14.5px; }
.side a:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.side a.on { background: var(--brand); color: #fff; }
.side .soon { color: #6f7c99; cursor: default; }
.side .soon em { font-style: normal; font-size: 11px; border: 1px solid #44507a; border-radius: 10px; padding: 0 6px; }
.main { min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; padding: 10px 24px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top select { max-width: 360px; }
.top .sp { flex: 1; }
.page { padding: 22px 24px 60px; max-width: 1200px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.menu-btn { display: none; }

/* ---------- ส่วนประกอบ ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.stat .v { font-size: 24px; font-weight: 600; margin-top: 4px; }
button, .btn { font: inherit; font-size: 14.5px; border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 6px; padding: 7px 14px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { background: #f3f5f8; text-decoration: none; }
button.pri, .btn.pri { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
button.pri:hover { background: #194f9f; }
button.danger { color: var(--bad); border-color: #f1c4bf; }
button.link { border: 0; background: none; color: var(--brand); padding: 2px 4px; }
button:disabled { opacity: .5; cursor: not-allowed; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.right { margin-left: auto; }
label { display: block; font-size: 13.5px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea { font: inherit; font-size: 15px; border: 1px solid #cfd4dc; border-radius: 6px; padding: 7px 10px; background: #fff; color: var(--ink); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #b9d0f3; border-color: var(--brand); }
input[type=checkbox], input[type=radio] { width: auto; }
.form { display: grid; gap: 14px 16px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.form .full { grid-column: 1 / -1; }
.check { display: flex; gap: 8px; align-items: center; color: var(--ink); font-size: 15px; }
.hint { font-size: 13px; color: var(--muted); margin-top: 4px; }
.badge { display: inline-block; font-size: 12.5px; padding: 1px 8px; border-radius: 10px; background: var(--line2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.blue { background: var(--brand-soft); color: var(--brand); }
.note { border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; font-size: 14px; }
.note.warn { background: var(--warn-soft); color: #6b4600; }
.note.info { background: var(--brand-soft); color: #173f7a; }
.note.bad { background: var(--bad-soft); color: var(--bad); }

table.t { width: 100%; border-collapse: collapse; background: var(--panel); }
.tbl { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; margin-bottom: 16px; }
table.t th, table.t td { padding: 8px 10px; border-bottom: 1px solid var(--line2); text-align: left; vertical-align: top; }
table.t .num { text-align: right; }
table.t th { font-size: 13px; font-weight: 600; color: var(--muted); background: #fafbfc; white-space: nowrap; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: #f7f9fc; }
table.t tfoot td { font-weight: 600; background: #fafbfc; border-top: 1px solid var(--line); }
table.t tr.grp td { font-weight: 600; background: #fbfcfd; }
table.t tr.off td { color: #a0a7b4; }
table.t tr.sub td { color: var(--muted); font-size: 13.5px; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* ฟอร์มสมุดรายวัน */
table.lines td { padding: 5px 6px; }
table.lines input { padding: 6px 8px; }
table.lines .amt { width: 140px; text-align: right; font-family: var(--mono); }
table.lines .del { color: var(--muted); border: 0; background: none; padding: 4px 8px; }
.balance { font-size: 14px; }
.balance.ok { color: var(--ok); } .balance.bad { color: var(--bad); }

/* หน้าเข้าสู่ระบบ */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #14213d 0%, #1f3d77 100%); }
.auth .box { background: #fff; border-radius: 12px; padding: 32px; width: 100%; max-width: 420px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.auth .logo { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.auth .logo span { color: var(--brand); }
.auth form > * + * { margin-top: 14px; }
.auth button.pri { width: 100%; justify-content: center; padding: 10px; }

dialog { border: 0; border-radius: 12px; padding: 0; width: min(720px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(16,24,40,.45); }
.dlg-h { padding: 16px 20px; border-bottom: 1px solid var(--line); font-weight: 600; font-size: 17px; }
.dlg-b { padding: 18px 20px; max-height: 70vh; overflow-y: auto; }
.dlg-f { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1d2433; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 100; font-size: 14.5px; max-width: 90vw; }
#toast.bad { background: var(--bad); }

table.perm th, table.perm td { text-align: center; }
table.perm td:first-child, table.perm th:first-child { text-align: left; }

/* ---------- พิมพ์ ---------- */
#print { display: none; }
@media print {
  body { background: #fff; }
  body.printing > *:not(#print) { display: none !important; }
  body.printing #print { display: block; }
  .noprint { display: none !important; }
  .shell { display: block; } .side, .top { display: none; } .page { padding: 0; max-width: none; }
  .card, .tbl { border: 0; padding: 0; }
}
.voucher { font-family: 'Sarabun', var(--font); font-size: 14px; color: #000; padding: 10mm; }
.voucher h2 { text-align: center; margin: 6px 0 2px; font-size: 20px; }
.voucher .co { text-align: center; }
.voucher table { width: 100%; border-collapse: collapse; margin-top: 12px; }
.voucher th, .voucher td { border: 1px solid #000; padding: 5px 8px; }
.voucher .meta { display: flex; justify-content: space-between; margin-top: 10px; }
.voucher .sign { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-top: 50px; text-align: center; }
.voucher .sign div { border-top: 1px dotted #000; padding-top: 4px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 20; left: -260px; width: 250px; transition: left .2s; }
  .side.open { left: 0; }
  .menu-btn { display: inline-flex; }
  .page { padding: 16px 12px 60px; }
  .top { padding: 8px 12px; flex-wrap: wrap; }
  .top select { flex: 1; min-width: 0; }
  .top .badge, .top .small { display: none; }
  .grid { grid-template-columns: 1fr 1fr; }
}
