:root {
  --bg: #f4f6f8; --card: #fff; --text: #1d2733; --muted: #6b7785; --line: #e3e7ec;
  --primary: #06a34b; --primary-d: #058a40; --danger: #d64545; --warn: #d88a00; --info: #2f6fdb;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Sarabun", "Noto Sans Thai", -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.5;
}
button, input, select, textarea { font: inherit; }
.wrap { max-width: 520px; margin: 0 auto; padding: 16px; }
.wrap.wide { max-width: 1200px; }
.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: 0 1px 3px rgba(0,0,0,.06); margin-bottom: 14px; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.muted { color: var(--muted); font-size: 14px; }
.hidden { display: none !important; }
label { display: block; font-weight: 600; margin: 12px 0 6px; }
input, select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(6,163,75,.25); border-color: var(--primary); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 10px;
  padding: 10px 16px; background: #e9edf1; color: var(--text); cursor: pointer; font-weight: 600; white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-d); }
.btn.danger { background: #fdecec; color: var(--danger); }
.btn.ok { background: #e6f6ec; color: var(--primary-d); }
.btn.sm { padding: 6px 10px; font-size: 14px; border-radius: 8px; }
.btn.block { width: 100%; padding: 13px; font-size: 17px; margin-top: 16px; }
.profile { display: flex; align-items: center; gap: 12px; }
.profile img { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; background: #ddd; }
.amount-preview { margin-top: 12px; padding: 12px; border-radius: 10px; background: #eef9f2; color: var(--primary-d); font-weight: 700; text-align: center; font-size: 18px; }
.msg { padding: 10px 12px; border-radius: 10px; margin-top: 12px; font-size: 15px; }
.msg.err { background: #fdecec; color: var(--danger); }
.msg.ok { background: #e6f6ec; color: var(--primary-d); }
.msg.warn { background: #fff5e0; color: #8a5a00; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.badge.pending { background: #fff5e0; color: var(--warn); }
.badge.approved { background: #e6f6ec; color: var(--primary-d); }
.badge.rejected { background: #fdecec; color: var(--danger); }
.hist-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.hist-item:last-child { border-bottom: 0; }
.hist-item .right { text-align: right; flex-shrink: 0; }
.stat { display: flex; justify-content: space-between; align-items: baseline; }
.stat b { font-size: 22px; color: var(--primary-d); }
.center { text-align: center; }
.spinner { width: 32px; height: 32px; border: 3px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- admin ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs button { border: 0; background: #e9edf1; padding: 9px 16px; border-radius: 999px; cursor: pointer; font-weight: 600; color: var(--text); }
.tabs button.active { background: var(--primary); color: #fff; }
.tabs .count { background: var(--danger); color: #fff; border-radius: 999px; padding: 0 7px; font-size: 12px; margin-left: 4px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; margin-bottom: 12px; }
.toolbar .field { display: flex; flex-direction: column; gap: 4px; min-width: 140px; flex: 0 1 auto; }
.toolbar .field span { font-size: 13px; color: var(--muted); font-weight: 600; }
.toolbar input, .toolbar select { padding: 8px 10px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { background: #f7f9fa; font-weight: 700; font-size: 14px; color: #3b4652; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; text-align: right; }
td.actions .btn { margin-left: 4px; }
tr.total td { font-weight: 700; background: #f7f9fa; }
.who { display: flex; align-items: center; gap: 8px; }
.who img { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; background: #ddd; }
.who small { display: block; color: var(--muted); font-size: 12px; }
.warn-text { color: var(--danger); font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
dialog { border: 0; border-radius: var(--radius); padding: 20px; width: min(440px, calc(100vw - 32px)); box-shadow: 0 10px 40px rgba(0,0,0,.2); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog .row-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.check input { width: auto; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- print ---------- */
#printArea { display: none; }
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; font-size: 13px; }
  body > *:not(#printArea) { display: none !important; }
  #printArea { display: block !important; }
  #printArea h1 { font-size: 18px; text-align: center; margin-bottom: 2px; }
  #printArea .sub { text-align: center; margin-bottom: 12px; }
  #printArea table { font-size: 12px; page-break-inside: auto; }
  #printArea tr { page-break-inside: avoid; }
  #printArea th, #printArea td { border: 1px solid #999; padding: 4px 6px; }
  #printArea th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #printArea .person { page-break-inside: avoid; margin-top: 14px; }
  #printArea .sign { display: flex; justify-content: space-around; margin-top: 40px; text-align: center; }
}
