:root {
  --bg: #f4f7f6; --card: #fff; --text: #1c2b29; --muted: #6b7c79; --line: #e3eae8;
  --brand: #0f766e; --brand2: #14b8a6; --out: #dc2626; --in: #16a34a;
  font-family: system-ui, -apple-system, "Noto Sans Lao", "Lao Sangam MN", "Phetsarath OT", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); padding-bottom: calc(84px + env(safe-area-inset-bottom)); -webkit-tap-highlight-color: transparent; }
button, input { font: inherit; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 4px 0 10px; }
[hidden] { display: none !important; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px; background: var(--brand); color: #fff; }
.month { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.month button { width: 36px; height: 36px; border-radius: 50%; border: 0; background: rgba(255,255,255,.2); color: #fff; font-size: 22px; }

main { max-width: 560px; margin: 0 auto; padding: 14px; }
.card { background: var(--card); border-radius: 18px; padding: 14px 16px; margin-bottom: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.muted { color: var(--muted); margin: 0; } .small { font-size: 13px; } .center { text-align: center; }
.big { font-size: 34px; font-weight: 800; margin: 2px 0 0; color: var(--out); }
.mid { font-size: 15px; font-weight: 700; margin: 4px 0 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.out { color: var(--out); } .in { color: var(--in); }
.today { text-align: center; padding: 18px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grid3 .card { padding: 12px 10px; text-align: center; margin-bottom: 12px; }
.row { display: flex; align-items: center; justify-content: space-between; }
.gap { gap: 8px; } .stack { display: grid; gap: 8px; }
.bar { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.bar span { display: block; height: 100%; background: var(--brand2); border-radius: 99px; }
.bar span.over { background: var(--out); }

.list { list-style: none; margin: 0; padding: 0; }
.item { display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: 14px; padding: 10px 12px; margin-bottom: 8px; cursor: pointer; }
.item .ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 20px; flex-shrink: 0; }
.item .txt { flex: 1; min-width: 0; } .item .txt b { display: block; font-weight: 600; }
.item .txt small { color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .amt { font-weight: 700; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.dayhead { display: flex; justify-content: space-between; font-weight: 700; margin: 14px 4px 6px; font-size: 14px; }

.cats { list-style: none; margin: 0; padding: 0; }
.cats li { margin-bottom: 10px; } .cats .row span:last-child { font-weight: 700; }
.days { display: flex; align-items: flex-end; gap: 2px; height: 120px; }
.days div { flex: 1; background: var(--brand2); border-radius: 3px 3px 0 0; min-height: 2px; position: relative; }
.days div.today-bar { background: var(--brand); }

.btn { border: 0; border-radius: 14px; padding: 12px 16px; background: var(--brand); color: #fff; font-weight: 700; text-align: center; cursor: pointer; }
.btn.ghost { background: #e6f2f0; color: var(--brand); } .btn.red { background: var(--out); } .btn.wide { flex: 1; }
.link { border: 0; background: none; padding: 10px; width: 100%; font-weight: 600; } .link.red { color: var(--out); }
input { width: 100%; border: 1.5px solid var(--line); border-radius: 14px; padding: 12px; background: #fff; color: var(--text); }
input:focus { outline: none; border-color: var(--brand2); }
.danger h2 { color: var(--out); }

.fab { position: fixed; right: 18px; bottom: calc(86px + env(safe-area-inset-bottom)); width: 62px; height: 62px; border-radius: 50%;
  border: 0; background: var(--brand); color: #fff; font-size: 34px; box-shadow: 0 8px 20px rgba(15,118,110,.4); z-index: 6; }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); z-index: 6; }
.tabs button { flex: 1; border: 0; background: none; padding: 8px 0 10px; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tabs button span { font-size: 20px; } .tabs button.on { color: var(--brand); font-weight: 700; }

.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 10; display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; background: var(--bg); border-radius: 22px 22px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  display: grid; gap: 12px; max-height: 92vh; overflow-y: auto; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: #e3eae8; border-radius: 14px; padding: 4px; }
.seg button { border: 0; background: none; padding: 10px; border-radius: 11px; font-weight: 700; color: var(--muted); }
.seg button.on { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.amount { display: flex; align-items: baseline; gap: 8px; background: #fff; border-radius: 16px; padding: 6px 14px; }
.amount input { border: 0; font-size: 34px; font-weight: 800; padding: 6px 0; text-align: right; }
.amount span { color: var(--muted); font-weight: 600; }
.catgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.catgrid button { border: 2px solid transparent; background: #fff; border-radius: 14px; padding: 8px 2px; font-size: 11px; color: var(--text);
  display: flex; flex-direction: column; align-items: center; gap: 2px; line-height: 1.2; }
.catgrid button span { font-size: 22px; } .catgrid button.on { border-color: var(--brand2); background: #e6f7f5; font-weight: 700; }
.err { color: var(--out); margin: 0; font-size: 14px; }
.toast { position: fixed; left: 50%; bottom: calc(160px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #1c2b29; color: #fff;
  padding: 10px 18px; border-radius: 99px; font-size: 14px; z-index: 20; white-space: nowrap; }
