:root {
  --ink: #172d2b; --muted: #6b7b77; --paper: #f5f7f4; --line: #e3e9e5; --row: #eff2ef;
  --green: #1d7560; --green-dark: #173c35; --mint: #e5f3ed;
  --amber: #a86718; --amber-bg: #fff1dd; --rose: #b84c45; --rose-bg: #fde9e7; --blue: #2d5f9a; --blue-bg: #e6eef8;
  --shadow: 0 8px 28px #193b3010;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 14px/1.5 "IBM Plex Sans Thai", ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Leelawadee UI", sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--green); }
h1, h2, h3 { letter-spacing: -.3px; }
h3 { font-size: 14px; margin: 18px 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mt { margin-top: 24px; }
.late-text { color: var(--rose); }

/* Layout */
.layout { display: grid; grid-template-columns: 224px 1fr; min-height: 100vh; }
.sidebar { background: var(--green-dark); color: #fff; padding: 24px 14px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { font-size: 21px; font-weight: 700; letter-spacing: -.5px; padding: 0 12px 22px; }
.brand span { color: #8ed5b9; }
.brand.dark { color: var(--green-dark); padding: 0 0 8px; }
.brand.dark span { color: var(--green); }
.nav { display: grid; gap: 3px; }
.nav button { background: transparent; border: 0; color: #c7d8d2; text-align: left; padding: 10px 12px; border-radius: 9px; display: flex; gap: 10px; align-items: center; }
.nav button.active, .nav button:hover { background: #ffffff18; color: #fff; }
.nav i { width: 18px; font-style: normal; text-align: center; }
.side-foot { margin-top: auto; padding: 14px 12px 0; color: #afc5bd; font-size: 12px; border-top: 1px solid #ffffff20; }
.side-foot b { color: #fff; display: block; }
.main { min-width: 0; }
.topbar { height: 60px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 32px; gap: 12px; }
.topbar .who { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.sync { font-size: 12px; color: var(--muted); }
.live { font-size: 12px; color: var(--green); font-weight: 600; white-space: nowrap; }
.live.off { color: var(--amber); }
.sync.error { color: var(--rose); font-weight: 600; }
.demo-banner { background: var(--amber-bg); color: var(--amber); padding: 8px 32px; font-size: 13px; border-bottom: 1px solid #f3dfbf; }
.content { max-width: 1280px; margin: auto; padding: 28px 32px 60px; }
.heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.heading h1 { font-size: 26px; letter-spacing: -.6px; margin: 0 0 2px; }
.heading p { margin: 0; color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Controls */
.btn { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 9px 14px; font-weight: 600; white-space: nowrap; }
.btn:hover { border-color: #c4d0ca; }
.btn.primary { background: var(--green); color: #fff; border-color: var(--green); }
.btn.primary:hover { background: #17644f; }
.btn.danger { color: var(--rose); }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; margin-top: 16px; padding: 11px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.link { border: 0; background: none; color: var(--green); font-weight: 600; padding: 0 4px; text-decoration: underline; }
.inline { border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: #fff; }
.search { min-width: 240px; }
.check { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 13px; }
.month-nav { display: flex; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 4px; }
.month-nav b { min-width: 130px; text-align: center; }
.month-nav .btn { border: 0; font-size: 16px; padding: 3px 12px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.panel-head .tabs, .actions .tabs { margin: 0; }
.tabs button { border: 1px solid var(--line); background: #fff; border-radius: 20px; padding: 5px 14px; font-size: 13px; }
.tabs button.active { background: var(--green); color: #fff; border-color: var(--green); }

/* Cards */
.card { background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.panel { padding: 20px; margin-bottom: 16px; }
.panel h2 { font-size: 15px; margin: 0 0 4px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.panel-head h2 { margin: 0; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.stats.three { grid-template-columns: repeat(3, 1fr); }
.stat { padding: 15px 18px; }
.stat small { color: var(--muted); font-size: 12px; }
.stat strong { display: block; font-size: 23px; letter-spacing: -.5px; margin: 4px 0 0; }
.stat span { font-size: 12px; color: var(--muted); }
.stat.bad strong { color: var(--rose); }
.stat.warn strong { color: var(--amber); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid2.top { align-items: start; }
.grid2 > .panel { margin-bottom: 0; }
.grid2 + .grid2, .grid2 + .card, .card + .grid2 { margin-top: 16px; }
.progress { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.bar { flex: 1; min-width: 120px; height: 8px; background: #edf1ee; border-radius: 5px; overflow: hidden; }
.bar span { display: block; height: 100%; background: #48a982; border-radius: 5px; }
.empty { color: var(--muted); padding: 14px 0; text-align: center; margin: 0; }
.note { background: var(--paper); border-radius: 8px; padding: 10px 12px; font-size: 13px; margin: 8px 0; }
.note.bad { background: var(--rose-bg); color: var(--rose); }
.list-row { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--row); }
.list-row:last-child { border: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row small { display: block; color: var(--muted); font-size: 12px; }
.click { cursor: pointer; }
.list-row.click:hover, .grow.click:hover b { color: var(--green); }

/* Badges & room chips */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 600; background: var(--mint); color: var(--green); white-space: nowrap; }
.badge.unpaid, .badge.open { background: var(--blue-bg); color: var(--blue); }
.badge.partial, .badge.in_progress { background: var(--amber-bg); color: var(--amber); }
.badge.overdue, .badge.high { background: var(--rose-bg); color: var(--rose); }
.badge.void { background: #eee; color: #777; }
.chip-group { margin-bottom: 12px; }
.chip-title { font-size: 13px; margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { border: 0; border-radius: 6px; background: var(--mint); color: var(--green); font-size: 11px; padding: 3px 7px; font-weight: 600; }
.chip.vacant { background: var(--amber-bg); color: var(--amber); }
.chip.late { background: var(--rose-bg); color: var(--rose); }
.legend { display: flex; gap: 14px; color: var(--muted); font-size: 11px; }
.legend span::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #48a982; margin-right: 5px; }
.legend .v::before { background: #e2a646; }
.legend .l::before { background: #d86b62; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; font-weight: 600; }
td { padding: 10px; border-bottom: 1px solid var(--row); font-size: 13px; white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.click:hover td { background: #f7faf8; }
tr.voided td { color: #999; text-decoration: line-through; }
tr.voided td:last-child, tr.voided td:nth-last-child(2) { text-decoration: none; }
.row-actions { text-align: right; }
.row-actions .btn + .btn { margin-left: 6px; }
table.compact td, table.compact th { padding: 6px 8px; }

/* Rooms */
.room-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.room-tile { border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; background: #fff; text-align: left; display: grid; gap: 1px; align-content: start; min-height: 96px; }
.room-tile:hover { border-color: var(--green); }
.room-tile b { font-size: 15px; }
.room-tile.vacant { background: #fffaf2; border-style: dashed; border-color: #ead7b8; }
.room-tile .t { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 7px 18px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; font-weight: 500; }

/* Billing */
.billing-bar { display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; }
.bill-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 12px; }
.bill-card { border: 1px solid var(--line); border-radius: 12px; background: #fff; padding: 14px; box-shadow: var(--shadow); }
.bill-card.done { background: #f8fbf9; box-shadow: none; }
.bill-card header { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.bill-card header b { font-size: 16px; }
.meter { display: grid; grid-template-columns: 66px 1fr 1fr 66px; gap: 6px; align-items: end; margin-bottom: 8px; }
.meter > span { font-size: 12px; font-weight: 600; padding-bottom: 9px; }
.meter label, .extra-row label, .note-in { font-size: 11px; color: var(--muted); display: block; }
.bill-card input { display: block; width: 100%; margin-top: 2px; padding: 8px; border: 1px solid var(--line); border-radius: 7px; background: #fff; font-variant-numeric: tabular-nums; }
.bill-card input:disabled { background: var(--paper); }
.bill-card input.bad { border-color: var(--rose); background: var(--rose-bg); }
.meter output { font-size: 11px; text-align: right; line-height: 1.3; padding-bottom: 4px; }
.meter output b { font-size: 12px; }
.extras { font-size: 12px; margin: 4px 0 0; }
.extras summary { cursor: pointer; color: var(--ink); padding: 2px 0; }
.extra-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 6px 0; }
.bill-total { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); min-height: 40px; }
.bill-total b { font-size: 16px; }
.bill-lines { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; font-size: 12px; color: var(--muted); }
.bill-lines span:nth-child(even) { text-align: right; color: var(--ink); }

/* Invoice modal */
.inv-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.inv-body { display: flex; gap: 18px; align-items: flex-start; }
.breakdown { flex: 1; }
.breakdown td { padding: 6px 4px; white-space: normal; }
.breakdown td.muted { font-size: 12px; }
.breakdown tr.sum td { font-weight: 700; border-top: 1px solid var(--line); }
.qr { width: 150px; text-align: center; flex-shrink: 0; }
.qr svg { width: 140px; height: 140px; }
.qr small { display: block; color: var(--muted); font-size: 11px; }

/* Forms & modals */
.form { display: grid; gap: 12px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label.f { display: block; font-size: 12px; color: var(--muted); }
label.f input, label.f select, label.f textarea { display: block; width: 100%; margin-top: 4px; border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; background: #fff; color: var(--ink); resize: vertical; }
label.f input:disabled, label.f select:disabled, label.f textarea:disabled { background: var(--paper); }
input:focus, select:focus, textarea:focus { outline: 2px solid #1d756033; border-color: var(--green); }
.methods { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.method input { position: absolute; opacity: 0; }
.method span { display: block; border: 1px solid var(--line); border-radius: 8px; padding: 8px; text-align: center; font-size: 13px; font-weight: 600; cursor: pointer; }
.method small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }
.method input:checked + span { border-color: var(--green); background: var(--mint); color: var(--green); }
.method input:focus-visible + span { outline: 2px solid var(--green); }
.modalback { position: fixed; inset: 0; background: #10251f77; display: grid; place-items: center; padding: 16px; z-index: 30; overflow: auto; }
.modal { background: #fff; width: min(480px, 100%); border-radius: 14px; padding: 22px; max-height: calc(100vh - 32px); overflow: auto; }
.modal.wide { width: min(700px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 10px; }
.modal-head h2 { margin: 0; font-size: 19px; }
.x { border: 0; background: none; font-size: 24px; color: var(--muted); line-height: 1; padding: 0 4px; }
.formfoot { display: flex; gap: 8px; margin-top: 18px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.error { color: var(--rose); font-size: 13px; margin-top: 10px; }
.steps { padding-left: 20px; margin: 0 0 14px; font-size: 13px; }
.steps li { margin-bottom: 4px; }
.toast { position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 30px); background: var(--green-dark); color: #fff; padding: 11px 18px; border-radius: 10px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: .2s; z-index: 40; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--rose); }
.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: min(400px, 100%); padding: 28px; }
.login.wide { width: min(520px, 100%); }
.login h1 { margin: 6px 0 4px; font-size: 24px; }
.login h2 { font-size: 16px; margin: 22px 0 10px; }

/* Responsive */
@media (max-width: 1200px) { .hide-md { display: none; } }
@media (max-width: 1000px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid2 { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  /* env(safe-area-*) keeps the bar clear of the notch when opened from the home screen */
  .sidebar { min-width: 0; position: sticky; top: 0; z-index: 10; height: auto; padding: calc(8px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) 8px calc(10px + env(safe-area-inset-left)); flex-direction: row; align-items: center; gap: 6px; }
  .brand { padding: 0 6px 0 4px; font-size: 18px; }
  .nav { display: flex; overflow-x: auto; gap: 2px; min-width: 0; scrollbar-width: none; }
  .nav button { white-space: nowrap; padding: 8px 10px; }
  .nav i, .side-foot, .hide-sm { display: none; }
  .topbar { padding: 0 16px; height: 52px; }
  .content { padding: 20px 16px calc(50px + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(22px + env(safe-area-inset-bottom)); }
  .demo-banner { padding: 8px 16px; }
  .heading h1 { font-size: 22px; }
  .form-row, .stats.three { grid-template-columns: 1fr; }
  .stats { gap: 10px; }
  .stat strong { font-size: 19px; }
  .methods { grid-template-columns: repeat(2, 1fr); }
  .search { min-width: 0; width: 100%; }
  .bill-grid { grid-template-columns: 1fr; }
  .inv-body { flex-direction: column; align-items: stretch; }
  .qr { width: auto; }
  .panel { padding: 16px; }
}

/* ── Printed bills and receipts: two per A4 page, cut along the dashed line ── */
#print { display: none; }
@media print {
  @page { size: A4; margin: 0; }
  body { background: #fff; }
  body > *:not(#print) { display: none !important; }
  #print { display: block; }
}
.doc { width: 210mm; height: 148.4mm; padding: 9mm 13mm 7mm; font: 11.5px/1.4 Sarabun, "Leelawadee UI", Tahoma, sans-serif; color: #111; overflow: hidden; border-bottom: 1px dashed #999; background: #fff; display: flex; flex-direction: column; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.doc:nth-child(2n) { border-bottom: 0; break-after: page; }
.doc:last-child { break-after: auto; }
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid #1d7560; padding-bottom: 5px; margin-bottom: 7px; gap: 12px; }
.doc-biz { font-size: 17px; font-weight: 700; }
.doc-sub { color: #444; font-size: 10.5px; line-height: 1.35; }
.doc-title { text-align: right; font-size: 20px; font-weight: 700; color: #1d7560; line-height: 1.1; white-space: nowrap; }
.doc-title small { display: block; font-size: 10px; letter-spacing: 3px; color: #555; margin-top: 2px; }
.doc-meta { display: grid; grid-template-columns: 1fr 1.4fr 1fr; gap: 3px 16px; margin-bottom: 7px; }
.doc-meta span { display: block; color: #666; font-size: 9.5px; }
.doc-meta b { font-size: 12px; }
.doc-table { width: 100%; border-collapse: collapse; }
.doc-table th { font-size: 9.5px; text-transform: none; letter-spacing: 0; color: #222; background: #eaf3ee; border: 1px solid #c9d5cf; padding: 3px 5px; text-align: center; white-space: normal; line-height: 1.25; font-weight: 600; }
.doc-table th.item { text-align: left; width: 34%; }
.doc-table td { font-size: 11.5px; border: 1px solid #c9d5cf; padding: 3px 6px; white-space: nowrap; }
.doc-table td small { color: #666; font-size: 9.5px; }
.doc-table td.r { text-align: right; font-variant-numeric: tabular-nums; }
.doc-table tfoot td { font-weight: 700; font-size: 12.5px; background: #f3f8f5; }
.doc-table tfoot tr.sub td { font-weight: 400; font-size: 11px; background: #fff; }
.doc-table .words { font-weight: 400; font-size: 10.5px; white-space: normal; }
.doc-foot { display: flex; justify-content: space-between; align-items: flex-end; gap: 14px; margin-top: auto; padding-top: 6px; }
.doc-note { font-size: 10.5px; color: #333; flex: 1; }
.doc-qr { text-align: center; font-size: 9.5px; line-height: 1.25; }
.doc-qr svg { width: 27mm; height: 27mm; display: block; margin: 0 auto 1px; }
.doc-sign { text-align: center; font-size: 10.5px; width: 62mm; }
.doc-sign .line { border-bottom: 1px dotted #333; height: 14mm; margin-bottom: 3px; }
