:root {
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #f8f9fb; --line: #e3e6eb; --line-2: #d3d8df;
  --text: #1c2330; --muted: #677285; --faint: #9aa3b2;
  --brand: #2f5bd3; --brand-ink: #ffffff; --brand-soft: #e8eefc;
  --ok: #1b8a4b; --ok-soft: #e3f4ea; --warn: #b26a00; --warn-soft: #fff2d9; --bad: #c62f2f; --bad-soft: #fde6e6;
  --busy: #c2410c; --busy-soft: #ffedd5; --free: #15803d; --free-soft: #dcfce7;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --radius: 12px; --radius-sm: 8px;
  --font: "Sarabun", "Noto Sans Thai", "Leelawadee UI", "Thonburi", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11151c; --surface: #191f29; --surface-2: #1f2633; --line: #2a3342; --line-2: #364052;
    --text: #e8ecf2; --muted: #9aa6b8; --faint: #6b7688;
    --brand: #6b8cff; --brand-ink: #0b1020; --brand-soft: #222c47;
    --ok: #4ade80; --ok-soft: #173325; --warn: #fbbf24; --warn-soft: #3a2e12; --bad: #f87171; --bad-soft: #3d1c1c;
    --busy: #fb923c; --busy-soft: #3b2414; --free: #4ade80; --free-soft: #15301f;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11151c; --surface: #191f29; --surface-2: #1f2633; --line: #2a3342; --line-2: #364052;
  --text: #e8ecf2; --muted: #9aa6b8; --faint: #6b7688;
  --brand: #6b8cff; --brand-ink: #0b1020; --brand-soft: #222c47;
  --ok: #4ade80; --ok-soft: #173325; --warn: #fbbf24; --warn-soft: #3a2e12; --bad: #f87171; --bad-soft: #3d1c1c;
  --busy: #fb923c; --busy-soft: #3b2414; --free: #4ade80; --free-soft: #15301f;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
.num, td.n, th.n { font-variant-numeric: tabular-nums; text-align: right; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 13px; } .tiny { font-size: 12px; }
.bad { color: var(--bad); } .ok { color: var(--ok); } .warn { color: var(--warn); }
.hidden { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 18px; } h3 { font-size: 15px; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar .inner { display: flex; align-items: center; gap: 12px; padding: 8px 16px; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); }
.brand .dot.live { background: var(--ok); }
nav.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
nav.tabs a { padding: 8px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; white-space: nowrap; font-weight: 600; }
nav.tabs a.active { background: var(--brand-soft); color: var(--brand); }
.datebox { display: flex; align-items: center; gap: 4px; }
.datebox input { width: 150px; }
.userbox { display: flex; align-items: center; gap: 6px; }

main { padding: 16px; max-width: 1400px; margin: 0 auto; }

/* ---------- controls ---------- */
a.btn { text-decoration: none; color: inherit; }
.btn { border: 1px solid var(--line-2); background: var(--surface); padding: 8px 14px; border-radius: 10px; cursor: pointer;
  font-weight: 600; min-height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: 13px; border-radius: 8px; }
.btn.lg { min-height: 52px; font-size: 17px; padding: 10px 20px; }
input.in, select.in, textarea.in { border: 1px solid var(--line-2); background: var(--surface); border-radius: 10px; padding: 8px 10px; min-height: 40px; width: 100%; }
input.in:focus, select.in:focus, textarea.in:focus, .btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
input.in.n { text-align: right; font-variant-numeric: tabular-nums; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
label.f > span { display: flex; justify-content: space-between; }
.grid { display: grid; gap: 10px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.steps { grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); }
.steps.wide { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.course-item { display: flex; flex-direction: column; gap: 6px; }
.line-edit { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 0 2px; }
.line-edit .btn { grid-column: span 2; justify-self: start; }
.line-edit label.f { font-size: 12px; }
input.in.custom { border-color: var(--warn); background: var(--warn-soft); font-weight: 700; }
.stepper .sub.warn { color: var(--warn); font-weight: 700; }
table.t tr.sel td { background: var(--brand-soft); }
.member > .hd { padding: 10px 14px; }
.member > .bd { padding: 12px 14px; }
details.extras { margin-top: 10px; }
details.extras > summary { cursor: pointer; font-size: 13px; color: var(--muted); font-weight: 600; }
.fields { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); } .g6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
@media (max-width: 720px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g6 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card > .hd { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card > .bd { padding: 14px; }
.card + .card, .stack > * + * { margin-top: 14px; }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--line); white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.chip.busy { background: var(--busy-soft); color: var(--busy); border-color: transparent; }
.chip.tg { background: #e3f2fd; color: #1769aa; border-color: transparent; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chip.tg { background: #15324a; color: #7cc4ff; } }
.tg-out { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 13px; white-space: pre-wrap; margin: 0; font-family: inherit; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 14px; font-weight: 700; cursor: pointer; min-height: 36px; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line-2); }
.seg button.on { background: var(--brand); color: var(--brand-ink); }
.slips { display: flex; flex-wrap: wrap; gap: 10px; }
.slip { width: 132px; display: flex; flex-direction: column; gap: 2px; }
.slip-img { width: 132px; height: 176px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); display: block; }
.slip-img.none { display: flex; align-items: center; justify-content: center; color: var(--faint); font-size: 13px; }
.status-cell { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.bill-members { display: flex; flex-direction: column; gap: 3px; }
.chip.brand { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
button.chip { cursor: pointer; min-height: 34px; padding: 4px 12px; font-size: 14px; }
button.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; }
.stat .k { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.bad .v { color: var(--bad); } .stat.warn .v { color: var(--warn); }

/* ---------- room board ---------- */
.rooms { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.room { border-radius: 12px; padding: 8px 10px; border: 1px solid transparent; cursor: pointer; text-align: left; min-height: 78px;
  display: flex; flex-direction: column; gap: 2px; background: var(--free-soft); }
.room .nm { font-weight: 800; font-size: 16px; display: flex; justify-content: space-between; }
.room .st { font-size: 12.5px; font-weight: 600; color: var(--free); }
.room.busy { background: var(--busy-soft); }
.room.busy .st { color: var(--busy); }
.room.over { background: var(--bad-soft); border-color: var(--bad); }
.room.over .st { color: var(--bad); }
.room.sub { opacity: .75; }
.room .who { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-size: 12.5px; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--line-2);
  background: var(--surface-2); position: sticky; top: 0; white-space: nowrap; }
table.t td.n, table.t td.num { white-space: nowrap; }
table.t td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: var(--surface-2); }
table.t tfoot td { font-weight: 700; border-top: 2px solid var(--line-2); background: var(--surface-2); }
table.t tr.dim td { color: var(--faint); }
table.t td.c, table.t th.c { text-align: center; }
table.t input.in { min-height: 34px; padding: 4px 8px; }

/* ---------- modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10,14,22,.45); z-index: 50; display: flex; justify-content: center; align-items: flex-start;
  padding: 24px 12px; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 16px; width: min(860px, 100%); box-shadow: 0 20px 50px rgba(0,0,0,.25); margin-bottom: 40px; }
.modal.sm { width: min(440px, 100%); }
.modal > .hd { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.modal > .bd { padding: 16px 18px; }
.modal > .ft { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  position: sticky; bottom: 0; background: var(--surface); border-radius: 0 0 16px 16px; }
.sec { margin-bottom: 16px; }
.sec > .tt { font-weight: 700; font-size: 14px; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }

.stepper { display: flex; align-items: center; justify-content: space-between; gap: 6px; border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px;
  background: var(--surface-2); }
.stepper.on { border-color: var(--brand); background: var(--brand-soft); }
.stepper .nm { font-weight: 700; font-size: 14px; }
.stepper .sub { font-size: 11.5px; color: var(--muted); }
.stepper .ctl { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--surface); font-size: 18px; font-weight: 700; cursor: pointer; }
.stepper .q { min-width: 22px; text-align: center; font-weight: 800; font-variant-numeric: tabular-nums; }

.summary-bar { display: flex; gap: 14px; flex-wrap: wrap; font-size: 14px; }
.summary-bar b { font-variant-numeric: tabular-nums; }
.due-big { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }

.combo { position: relative; }
.combo .list { position: absolute; left: 0; right: 0; top: 100%; margin-top: 4px; background: var(--surface); border: 1px solid var(--line-2);
  border-radius: 10px; max-height: 260px; overflow-y: auto; z-index: 5; box-shadow: var(--shadow); }
.combo .opt { padding: 8px 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.combo .opt.act, .combo .opt:hover { background: var(--brand-soft); }

.alert { border-radius: 10px; padding: 10px 12px; font-size: 14px; border: 1px solid transparent; }
.alert.bad { background: var(--bad-soft); color: var(--bad); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.info { background: var(--brand-soft); color: var(--brand); }

/* ---------- toast ---------- */
#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #1c2330; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-weight: 600; max-width: 90vw; }
.toast.bad { background: var(--bad); }

/* ---------- login ---------- */
.login { max-width: 420px; margin: 8vh auto; padding: 0 16px; }
.login .users { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.login .u { padding: 16px 10px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--surface); cursor: pointer; text-align: center; font-weight: 700; }
.login .u.on { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.pinpad button { min-height: 58px; font-size: 22px; font-weight: 700; border-radius: 12px; border: 1px solid var(--line-2); background: var(--surface); cursor: pointer; }
.pindots { display: flex; gap: 10px; justify-content: center; margin: 14px 0 4px; min-height: 16px; }
.pindots i { width: 14px; height: 14px; border-radius: 50%; background: var(--line-2); }
.pindots i.on { background: var(--brand); }

.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }
.kv { width: 100%; border-collapse: collapse; font-size: 14px; }
.kv td { padding: 6px 4px; border-bottom: 1px dashed var(--line); }
.kv td:last-child { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.kv tr.total td { font-weight: 800; border-bottom: none; border-top: 2px solid var(--line-2); font-size: 16px; }

.sign { display: none; }
@media print {
  .topbar, .no-print, #toasts, .btn { display: none !important; }
  body, main { background: #fff; color: #000; padding: 0; }
  .card { box-shadow: none; border-color: #999; break-inside: avoid; }
  .sign { display: flex; gap: 40px; margin-top: 30px; }
  .sign div { flex: 1; border-top: 1px solid #000; padding-top: 6px; text-align: center; }
  table.t th { background: #eee; }
}
.pos-ref { margin-top: 3px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.pos-in { font-variant-numeric: tabular-nums; letter-spacing: .02em; text-transform: uppercase; }
.stat.ok .v { color: var(--ok); }
.pos-ref.ok { color: var(--ok); font-weight: 600; } .pos-ref.bad { color: var(--bad); font-weight: 600; }
.in.sm { padding: 5px 8px; font-size: 13px; min-height: 0; }
.in.bad { border-color: var(--bad); }
th.mapped, td.mapped { background: var(--brand-soft); }
th .chip.tiny { font-size: 11px; padding: 0 6px; margin-top: 2px; display: inline-block; }
/* ---------- ชำระเงิน: ประเภท + ยอดโอนพร้อมสลิป ---------- */
.pay-types { margin-top: 6px; gap: 6px; }
.chip.pay-type { padding: 7px 14px; font-size: 14px; cursor: pointer; }
.xfer:not(:empty) { margin-top: 12px; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); display: flex; flex-direction: column; gap: 8px; }
.xfer-row { display: grid; grid-template-columns: minmax(150px, 1.3fr) minmax(90px, .8fr) minmax(170px, 1.2fr) auto 1fr; gap: 8px; align-items: end;
  padding-bottom: 8px; border-bottom: 1px dashed var(--line); }
.xfer-row:last-of-type { border-bottom: 0; }
.xfer-row .lbl { font-size: 12.5px; color: var(--muted); font-weight: 600; display: block; margin-bottom: 4px; }
.xfer-slip { display: flex; align-items: center; gap: 6px; min-height: 38px; }
.xfer-slip img { width: 38px; height: 50px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); }
.btn.attach { border-color: var(--brand); color: var(--brand); font-weight: 600; }
.xfer-meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; justify-content: flex-end; }
@media (max-width: 720px) { .xfer-row { grid-template-columns: 1fr 1fr; } .xfer-meta { grid-column: span 2; justify-content: flex-start; } }
.acc-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; margin-bottom: 14px; }
.acc-card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; }
.acc-card.dim { opacity: .7; }
.click-text { cursor: pointer; margin-top: 4px; } .click-text:hover b { text-decoration: underline; }
.chip.strong { font-weight: 700; }
tr.dup td { opacity: .45; text-decoration: line-through; text-decoration-color: var(--line-2); }
tr.dup td:last-child { opacity: 1; text-decoration: none; }
/* ---------- สมาชิก ---------- */
.plan-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.plan-card { text-align: left; border: 1px solid var(--line-2); background: var(--surface); border-radius: 12px; padding: 10px 12px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; color: var(--text); font: inherit; }
.plan-card.on { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
.hold-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.hold-card { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--surface-2); display: flex; flex-direction: column; gap: 4px; }
.hold-card.dim { opacity: .6; }
.big-num { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.plan-edit { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--surface-2); }
tr.strike td { text-decoration: line-through; text-decoration-color: var(--line-2); }
.mem-box { margin-top: 12px; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); display: flex; flex-direction: column; gap: 8px; }
.mem-results { display: flex; flex-direction: column; gap: 4px; }
.mem-results button { text-align: left; }
.stepper.mini { padding: 2px 4px; gap: 4px; min-width: 0; flex: 0 0 auto; }
.stepper.mini button { width: 28px; height: 28px; }
.stepper.mini .q { min-width: 22px; text-align: center; font-weight: 700; }
