:root {
  --bg: #FBF1E8; --card: #FFFFFF; --ink: #3B2A24; --muted: #8A7466; --line: #EBDDD0;
  --primary: #C8553D; --on-primary: #FFFFFF; --sand: #E9B872; --deep: #8E3322;
  --good: #6B7F3E; --bad: #B8432F; --soft: #F6E7D8; --shadow: 0 1px 2px rgba(59,42,36,.06), 0 4px 14px rgba(59,42,36,.06);
  --r: 16px;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1D1511; --card: #2A1F19; --ink: #F6E9DD; --muted: #B39C8C; --line: #3C2E26;
    --primary: #E0735A; --on-primary: #1D1511; --sand: #D9A441; --deep: #F0A08C;
    --good: #A3B96A; --bad: #F0836E; --soft: #34271F; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 14px rgba(0,0,0,.25);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); }
body { font-family: 'Heebo', system-ui, -apple-system, 'Segoe UI', sans-serif; font-size: 16px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
body.noscroll { overflow: hidden; }
h1, h2, h3 { font-family: 'Frank Ruhl Libre', 'Heebo', serif; font-weight: 700; margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
.num { direction: ltr; unicode-bidi: isolate; display: inline-block; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.right { margin-inline-start: auto; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.shell { max-width: 560px; margin: 0 auto; min-height: 100vh; padding: calc(var(--sat) + 8px) 16px calc(96px + var(--sab)); }
.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 0 12px; }
.brand { display: flex; align-items: center; gap: 8px; font-family: 'Frank Ruhl Libre', serif; font-weight: 700; font-size: 24px; }
.brand svg { width: 30px; height: 30px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 4px 10px; font-size: 13px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.sync-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--good); }
.sync-dot.pending { background: var(--sand); }
.sync-dot.offline { background: var(--bad); }

.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card h3 { font-size: 18px; margin-bottom: 10px; }
.card.tint { background: var(--soft); box-shadow: none; }
.hero { background: var(--primary); color: var(--on-primary); }
.hero .muted { color: inherit; opacity: .85; }

.monthbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.monthbar .title { font-family: 'Frank Ruhl Libre', serif; font-size: 22px; font-weight: 700; text-align: center; }
.iconbtn { border: 0; background: var(--card); width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; box-shadow: var(--shadow); }
.iconbtn svg { width: 20px; height: 20px; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); border-radius: 14px; padding: 12px 10px; box-shadow: var(--shadow); text-align: center; }
.stat .v { font-size: 19px; font-weight: 700; }
.stat .l { font-size: 12px; color: var(--muted); }
.neg { color: var(--bad); } .pos { color: var(--good); }

/* ---------- lists ---------- */
.list { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); width: 100%; background: none; border-inline: 0; border-top: 0; text-align: start; }
.item:last-child { border-bottom: 0; }
.item .t { font-weight: 500; }
.item .s { font-size: 13px; color: var(--muted); }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 13px; font-weight: 700; flex: none; }
.dayhead { font-size: 13px; color: var(--muted); padding: 14px 2px 4px; font-weight: 500; }
.bar { height: 8px; border-radius: 99px; background: var(--soft); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px; }
.legend-row { padding: 9px 0; }
.legend-row .top { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.legend-row .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donutwrap { position: relative; width: 200px; height: 200px; margin: 4px auto 10px; }
.donutwrap svg { width: 100%; height: 100%; transform: rotate(0deg); }
.donutwrap .mid { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.empty { text-align: center; color: var(--muted); padding: 26px 8px; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--soft); color: var(--muted); }
.badge.warn { background: #F9E3B7; color: #6B4A0F; }
@media (prefers-color-scheme: dark) { .badge.warn { background: #4A3A18; color: #F3D9A0; } }

/* ---------- nav ---------- */
.nav { position: fixed; inset-inline: 0; bottom: 0; background: var(--card); border-top: 1px solid var(--line); padding: 6px 8px calc(6px + var(--sab)); z-index: 20; }
.nav-in { max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: 1fr 1fr 84px 1fr 1fr; align-items: center; }
.nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; color: var(--muted); padding: 6px 0; }
.nav a svg { width: 24px; height: 24px; }
.nav a.on { color: var(--primary); font-weight: 700; }
.fab { width: 60px; height: 60px; border-radius: 50%; border: 0; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; margin: -26px auto 0; box-shadow: 0 6px 18px rgba(200,85,61,.45); }
.fab svg { width: 30px; height: 30px; }

/* ---------- forms ---------- */
label.f { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 5px; }
.in, select.in, textarea.in { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px 12px; font-size: 16px; }
.in:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.amount { font-size: 34px; font-weight: 700; text-align: center; padding: 12px; font-family: 'Heebo', sans-serif; direction: ltr; }
.seg { display: flex; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 9px; padding: 9px 6px; font-weight: 500; }
.seg button.on { background: var(--primary); color: var(--on-primary); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.cat { border: 1.5px solid var(--line); background: var(--bg); border-radius: 999px; padding: 7px 12px; display: inline-flex; align-items: center; gap: 7px; font-size: 14px; }
.cat.on { border-color: var(--primary); background: var(--soft); font-weight: 700; }
.btn { border: 0; border-radius: 14px; padding: 14px 18px; font-weight: 700; background: var(--primary); color: var(--on-primary); width: 100%; font-size: 17px; }
.btn.alt { background: var(--soft); color: var(--ink); }
.btn.danger { background: transparent; color: var(--bad); border: 1.5px solid var(--bad); }
.btn.sm { width: auto; padding: 8px 14px; font-size: 14px; border-radius: 10px; }
.actions { display: grid; gap: 10px; margin-top: 18px; }
.err { color: var(--bad); font-size: 14px; margin-top: 8px; min-height: 18px; }
.hint { font-size: 13px; color: var(--muted); margin-top: 6px; }
.chk { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.chk input { width: 20px; height: 20px; accent-color: var(--primary); }
.search { margin-bottom: 8px; }
.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters .cat { white-space: nowrap; }

/* ---------- sheet ---------- */
#sheet { position: fixed; inset: 0; z-index: 50; pointer-events: none; }
#sheet.open { pointer-events: auto; }
.backdrop { position: absolute; inset: 0; background: rgba(30,18,12,.5); animation: fade .15s ease-out; }
.sheet { position: absolute; inset-inline: 0; bottom: 0; max-width: 560px; margin: 0 auto; background: var(--card); border-radius: 22px 22px 0 0; padding: 14px 18px calc(22px + var(--sab)); max-height: 92vh; overflow-y: auto; animation: rise .2s ease-out; }
.sheet .grab { width: 42px; height: 5px; background: var(--line); border-radius: 9px; margin: 0 auto 10px; }
.sheet h2 { font-size: 22px; margin-bottom: 4px; }
@keyframes rise { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
#toast { position: fixed; inset-inline: 0; bottom: calc(100px + var(--sab)); margin: 0 auto; width: max-content; max-width: 88%; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; transform: translateY(10px); transition: .2s; z-index: 80; pointer-events: none; }
#toast.show { opacity: 1; transform: none; }

/* ---------- login ---------- */
.login { max-width: 420px; margin: 0 auto; padding: calc(var(--sat) + 48px) 20px 40px; text-align: center; }
.login .logo { width: 96px; height: 96px; margin: 0 auto 14px; }
.login h1 { font-size: 40px; }
.login .who { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 26px 0 16px; }
.login .who button { border: 2px solid var(--line); background: var(--card); border-radius: 18px; padding: 18px 8px; font-size: 18px; font-weight: 700; display: grid; gap: 8px; justify-items: center; }
.login .who button.on { border-color: var(--primary); background: var(--soft); }
.pin { letter-spacing: 10px; text-align: center; font-size: 26px; direction: ltr; }

.tbl { width: 100%; border-collapse: collapse; }
.tbl td { padding: 8px 4px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl input { width: 100px; text-align: center; padding: 8px; }
