:root {
  --bg: #f7f3ee; --card: #fff; --ink: #2b2118; --muted: #7a6d62; --line: #e8dfd5; --soft: #f1ebe4;
  --brand: #7a4b2a; --brand-ink: #fff; --brand-soft: #f3e7dc;
  --inc: #1d7f54; --exp: #c0392f; --pro: #2c67a8; --cash: #6b5a8e;
  --ok: #1d7f54; --warn: #c98a0b; --bad: #c0392f;
  --radius: 14px; --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 2px 10px rgba(60, 40, 20, .05);
  font-family: 'IBM Plex Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink); background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100dvh; font-size: 16px; line-height: 1.45; }
body.has-nav main { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
main { max-width: 560px; margin: 0 auto; padding: 12px 16px 32px; }
h1 { font-size: 1.45rem; margin: 0; line-height: 1.2; }
h2 { font-size: 1rem; margin: 0 0 8px; }
a { color: var(--brand); }
small { font-size: .82rem; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .85rem; margin: 4px 0 12px; display: block; }
.center { text-align: center; }
.mono { font-family: ui-monospace, Menlo, monospace; letter-spacing: .05em; }
.loading, .empty { color: var(--muted); text-align: center; padding: 32px 8px; }
.empty.small { padding: 10px 0; font-size: .9rem; }

/* ---------- ฟอร์ม ---------- */
.stack { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: .95rem; }
label small { font-weight: 400; color: var(--muted); }
input, select, textarea {
  font: inherit; font-size: 16px; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 12px;
  background: #fff; color: var(--ink); width: 100%; min-height: 48px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.money-input { font-size: 1.35rem; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
label.check { flex-direction: row; align-items: center; gap: 10px; font-weight: 400; }
label.check input { width: 22px; height: 22px; min-height: 0; accent-color: var(--brand); }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 500; font-size: .95rem; margin-bottom: 6px; padding: 0; }
details { background: var(--card); border-radius: 12px; padding: 10px 14px; border: 1px solid var(--line); }
details[open] { display: flex; flex-direction: column; gap: 12px; }
summary { cursor: pointer; color: var(--muted); font-size: .92rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: end; }

.seg { display: flex; background: var(--soft); border-radius: 12px; padding: 4px; gap: 4px; }
.seg label { flex: 1; font-weight: 500; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 10px 6px; border-radius: 9px; font-size: .88rem; cursor: pointer; }
.seg input:checked + span { background: #fff; box-shadow: var(--shadow); color: var(--brand); font-weight: 600; }
.seg.small { margin-bottom: 12px; }

.stepper { display: flex; align-items: stretch; border: 1.5px solid var(--line); border-radius: 12px; overflow: hidden; background: #fff; }
.stepper input { border: 0; border-radius: 0; text-align: center; min-width: 0; padding: 10px 4px; font-weight: 600; }
.stepper button { border: 0; background: var(--soft); width: 44px; font-size: 1.3rem; color: var(--brand); cursor: pointer; }

/* ---------- ปุ่ม ---------- */
.btn {
  font: inherit; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 18px; min-height: 46px; border-radius: 12px; border: 1.5px solid var(--line);
  background: #fff; color: var(--ink); text-decoration: none; cursor: pointer;
}
.btn:disabled { opacity: .55; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger.ghost { color: var(--bad); border-color: #f1c9c5; background: transparent; }
.btn.big { min-height: 56px; font-size: 1.08rem; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .88rem; }
.grow { flex: 1; }
.actions { display: flex; gap: 10px; align-items: stretch; }
.row { display: flex; align-items: center; justify-content: space-between; }
.row.gap { gap: 8px; justify-content: flex-start; }
.row.end { justify-content: flex-end; gap: 8px; }
.row.gap input { flex: 1; }
.icon-btn { border: 0; background: var(--card); width: 44px; height: 44px; border-radius: 12px; box-shadow: var(--shadow); cursor: pointer; }
.icon-btn svg { width: 22px; fill: var(--muted); }

/* ---------- ส่วนหัว ---------- */
.top { display: flex; align-items: center; gap: 10px; justify-content: space-between; margin: 4px 0 12px; }
.top > div { flex: 1; }
.top small { color: var(--muted); }
.back { font-size: 2rem; line-height: 1; text-decoration: none; color: var(--ink); padding: 0 6px 4px 0; }
.top:has(.back) { justify-content: flex-start; }

.chips { display: flex; gap: 8px; margin-bottom: 12px; }
.chips.scroll { overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips.wrap { flex-wrap: wrap; }
.chip {
  white-space: nowrap; padding: 8px 14px; border-radius: 999px; background: var(--card); border: 1.5px solid var(--line);
  font: inherit; font-size: .92rem; color: var(--ink); text-decoration: none; cursor: pointer;
}
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.chip input[type=date] { border: 0; padding: 0; min-height: 0; font-size: .9rem; background: transparent; }

/* ---------- การ์ดและรายการ ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 12px; display: block; color: inherit; text-decoration: none; }
.card h2 { margin-bottom: 10px; }
.card.closing { display: flex; align-items: center; justify-content: space-between; border-left: 5px solid var(--line); }
.card.closing small { display: block; color: var(--muted); }
.card.closing.ok { border-left-color: var(--ok); } .card.closing.warn { border-left-color: var(--warn); }
.card.closing.bad { border-left-color: var(--bad); } .card.closing.open { border-left-color: var(--brand); background: var(--brand-soft); }
.pill { font-size: .8rem; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--soft); color: var(--brand); white-space: nowrap; }
.pill.ok { background: #e3f3eb; color: var(--ok); } .pill.warn { background: #fbf0d9; color: #8a5d00; } .pill.bad { background: #fbe4e2; color: var(--bad); }

.quick { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.quick .btn.big { flex-basis: 100%; }
.quick-btn { flex: 1; flex-direction: column; gap: 0; min-height: 56px; font-weight: 500; }
.quick-btn b { color: var(--brand); }

.list { margin-bottom: 16px; }
.list-head { display: flex; justify-content: space-between; align-items: baseline; margin: 6px 2px 8px; }
.list-head h2 { margin: 0; }
.list-head span, .list-head a { font-size: .85rem; color: var(--muted); }
.row-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%;
  background: var(--card); padding: 12px 14px; border-radius: 12px; margin-bottom: 6px; text-decoration: none; color: inherit;
  border: 0; font: inherit; text-align: left; cursor: pointer; box-shadow: var(--shadow);
}
div.row-item { cursor: default; }
.row-item b { font-weight: 500; display: block; }
.row-item small { color: var(--muted); display: block; }
.row-item.strong { font-weight: 600; background: var(--soft); box-shadow: none; }
.row-item.off { opacity: .5; }
.amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amt.pos { color: var(--inc); } .amt.neg { color: var(--exp); }
.note { background: var(--soft); padding: 10px 12px; border-radius: 10px; font-size: .9rem; }

/* ---------- ฟอร์มจ่ายเงิน ---------- */
.picker { display: flex; flex-direction: column; gap: 10px; }
.picker input[type=search] { font-size: 1.05rem; }
.results { display: flex; flex-direction: column; }
.chosen { display: flex; align-items: center; justify-content: space-between; margin: 0; border: 2px solid var(--brand); }
.chosen small { color: var(--muted); display: block; } .chosen b { font-size: 1.15rem; }

/* ---------- ปิดยอด ---------- */
.steps { display: flex; gap: 8px; list-style: none; padding: 0; margin: 0 0 14px; counter-reset: s; }
.steps li { flex: 1; font-size: .85rem; color: var(--muted); border-top: 4px solid var(--line); padding-top: 6px; counter-increment: s; }
.steps li::before { content: counter(s) '. '; }
.steps li.on { border-color: var(--brand); color: var(--ink); font-weight: 600; }
.steps li.done { border-color: var(--ok); }
.denoms { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.denom { display: grid; grid-template-columns: 64px 1fr 84px; gap: 10px; align-items: center; }
.denom .stepper input { font-size: 1.1rem; }
.face { text-align: center; font-weight: 700; padding: 8px 0; border-radius: 8px; font-variant-numeric: tabular-nums; }
.face.note { background: #e7efe1; color: #3b5b2a; } .face.coin { background: #efe7da; color: #6b4e1f; border-radius: 999px; }
.sub { text-align: right; color: var(--muted); font-size: .9rem; font-variant-numeric: tabular-nums; }
.total-bar {
  position: sticky; bottom: calc(76px + env(safe-area-inset-bottom)); display: flex; align-items: baseline; gap: 8px; justify-content: flex-end;
  background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 12px; margin: 8px 0 12px;
}
.total-bar span:first-child { margin-right: auto; }
.total-bar b { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.result { text-align: center; padding: 22px 16px; border: 2px solid var(--line); }
.result.ok { border-color: var(--ok); background: #eef8f2; } .result.warn { border-color: var(--warn); background: #fdf6e6; } .result.bad { border-color: var(--bad); background: #fdeeec; }
.big-label { display: block; font-size: 1.5rem; font-weight: 700; }
.result.ok .big-label { color: var(--ok); } .result.warn .big-label { color: #8a5d00; } .result.bad .big-label { color: var(--bad); }

/* ---------- แดชบอร์ด ---------- */
.month-nav { display: flex; align-items: center; justify-content: space-between; background: var(--card); border-radius: 12px; padding: 6px; margin-bottom: 12px; box-shadow: var(--shadow); }
.month-nav a { text-decoration: none; font-size: 1.5rem; padding: 2px 16px; color: var(--ink); }
.month-nav span { width: 48px; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi { border-radius: var(--radius); padding: 14px; color: #fff; position: relative; min-height: 104px; }
.kpi small { opacity: .9; display: block; } .kpi b { font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.kpi .unit { font-size: .8rem; margin-left: 4px; opacity: .9; }
.kpi .delta { display: block; font-size: .78rem; margin-top: 4px; background: rgba(255,255,255,.18); width: fit-content; padding: 2px 8px; border-radius: 999px; }
.kpi.inc { background: var(--inc); } .kpi.exp { background: var(--exp); } .kpi.pro { background: var(--pro); } .kpi.cash { background: var(--cash); }
.target .bar { margin: 8px 0 4px; }
.bar { height: 10px; background: var(--soft); border-radius: 999px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.bar.inc i { background: var(--inc); } .bar.exp i { background: var(--exp); }
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 34% 1fr auto; gap: 10px; align-items: center; font-size: .9rem; }
.bar-row .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; min-width: 74px; }
.bar-row .val small { display: block; color: var(--muted); font-weight: 400; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.dow { font-size: .78rem; color: var(--muted); padding-bottom: 4px; }
.day { display: flex; flex-direction: column; align-items: center; padding: 6px 0 4px; border-radius: 10px; text-decoration: none; color: var(--ink); min-height: 54px; font-variant-numeric: tabular-nums; }
.day small { font-size: .66rem; color: var(--muted); }
.day.today { outline: 2px solid var(--brand); }
.day.future { color: #c9bfb4; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin: 2px 0; background: var(--line); }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }
.dot.none { background: transparent; border: 1.5px solid #c9bfb4; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; font-size: .78rem; color: var(--muted); }
.legend span { display: flex; align-items: center; gap: 5px; }

/* ---------- ตั้งค่า ---------- */
.tabs { display: flex; gap: 4px; overflow-x: auto; margin-bottom: 14px; background: var(--soft); padding: 4px; border-radius: 12px; }
.tabs a { flex: 1; text-align: center; white-space: nowrap; padding: 9px 10px; border-radius: 9px; text-decoration: none; color: var(--muted); font-size: .9rem; }
.tabs a.on { background: #fff; color: var(--brand); font-weight: 600; box-shadow: var(--shadow); }
#pane > .row.gap { margin-bottom: 12px; }
#pane form.row.gap { margin: 10px 0; }
.invite input { margin: 8px 0; font-size: .85rem; }
.big-code { font-size: 1.4rem; }

/* ---------- ล็อกอิน / PIN ---------- */
.auth { max-width: 400px; margin: 6vh auto 0; display: flex; flex-direction: column; gap: 14px; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.brand img { width: 52px; height: 52px; border-radius: 14px; }
.brand b { display: block; font-size: 1.2rem; } .brand small { color: var(--muted); }
.pin-input { letter-spacing: .6em; text-align: center; font-size: 1.4rem; }
.pin { text-align: center; align-items: center; }
.dots { display: flex; gap: 16px; justify-content: center; margin: 10px 0 18px; }
.dots i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--brand); }
.dots i.on { background: var(--brand); }
.dots.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.keypad { display: grid; grid-template-columns: repeat(3, 76px); gap: 14px; justify-content: center; }
.keypad button { height: 76px; border-radius: 50%; border: 0; background: var(--card); box-shadow: var(--shadow); font: inherit; font-size: 1.6rem; font-weight: 500; cursor: pointer; }
.keypad button:active { background: var(--brand-soft); }

/* ---------- แถบล่าง สถานะ แจ้งเตือน ---------- */
#nav { position: fixed; left: 0; right: 0; bottom: 0; background: rgba(255,255,255,.96); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line); display: flex; justify-content: center; padding-bottom: env(safe-area-inset-bottom); z-index: 10; }
#nav:empty { display: none; }
#nav a { flex: 1; max-width: 140px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 10px; color: var(--muted); text-decoration: none; font-size: .78rem; }
#nav svg { width: 24px; height: 24px; fill: currentColor; }
#nav a.on { color: var(--brand); font-weight: 600; }
.status-bar { background: #3a2e25; color: #fff; text-align: center; font-size: .82rem; padding: 6px; }
#toasts { position: fixed; left: 0; right: 0; bottom: calc(86px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; z-index: 20; padding: 0 16px; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; display: flex; gap: 14px; align-items: center; pointer-events: auto; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 520px; font-size: .95rem; animation: up .2s; }
.toast.error { background: var(--bad); }
.toast button { background: none; border: 0; color: #ffd9a8; font: inherit; font-weight: 600; cursor: pointer; }
@keyframes up { from { transform: translateY(12px); opacity: 0; } }
dialog.sheet { border: 0; border-radius: 18px; padding: 18px; width: min(520px, 94vw); max-height: 90dvh; }
dialog.sheet::backdrop { background: rgba(30, 20, 10, .45); }

.mpick { position: relative; cursor: pointer; }
.mpick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; min-height: 0; padding: 0; }

.small-check { font-size: .85rem; gap: 6px; white-space: nowrap; }
.small-check input { width: 18px; height: 18px; }
#pane .list .row-item { flex-wrap: wrap; }
