:root {
  --font: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --bg: #F6F4EF; --card: #FFFFFF; --ink: #1F2A27; --muted: #6B746F; --line: #E6E2D9;
  --brand: #2F7D6D; --brand-soft: #E3EFEB; --accent: #E9A23B;
  --inc: #2F7D6D; --exp: #D9645A; --bad: #B23A30; --good: #2F7D6D;
  --radius: 16px; --tab-h: 64px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; color: inherit; }
h2 { font-size: 1.2rem; margin: 0; } h3 { font-size: 1rem; margin: 0 0 12px; }
.muted { color: var(--muted); font-size: .85rem; line-height: 1.45; } .center { text-align: center; } .empty { text-align: center; padding: 16px 0; }
.inc { color: var(--inc); } .exp { color: var(--exp); } .bad { color: var(--bad); font-weight: 600; } .good { color: var(--good); }

#app { max-width: 920px; margin: 0 auto; }
.card, .kpi, .grid2 > * { min-width: 0; }
main { padding: 8px 16px calc(var(--tab-h) + 32px + env(safe-area-inset-bottom)); }
.top { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 6px; }
.brand { font-weight: 700; color: var(--brand); } .beta { font-size: .65rem; background: var(--accent); color: #fff; border-radius: 6px; padding: 2px 6px; vertical-align: middle; }
.who { font-size: .8rem; color: var(--muted); }
.page-title { margin: 8px 0 14px; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; border: 1px solid var(--line); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.card-head h3 { margin: 0; }
.grid2 { display: grid; gap: 0 14px; }
@media (min-width: 760px) { .grid2 { grid-template-columns: 1fr 1fr; } }

/* buttons */
.btn { border: 0; border-radius: 12px; padding: 12px 18px; font-weight: 600; cursor: pointer; background: var(--brand-soft); color: var(--brand); }
.btn.primary { background: var(--brand); color: #fff; } .btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.btn.small { padding: 8px 12px; font-size: .85rem; } .btn.wide { width: 100%; margin: 6px 0 14px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.scan { width: 100%; margin: 4px 0 14px; background: #FBF3E4; color: #9A6614; } .btn.scan small { font-weight: 400; }

/* inputs */
.field { display: block; font-size: .8rem; color: var(--muted); font-weight: 600; margin: 0 0 14px; }
.field > input, .field > .t-input, .field > .chips, .field > .seg { margin-top: 6px; }
input, select { width: 100%; border: 1px solid var(--line); background: #FCFBF8; border-radius: 10px; padding: 11px 12px; color: var(--ink); font-weight: 500; }
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
select { width: auto; padding: 8px 10px; }
.row2 { display: grid; grid-template-columns: 1fr; gap: 0 12px; }
@media (min-width: 420px) { .row2 { grid-template-columns: 1fr 1fr; } }

.seg { display: flex; background: #EFECE5; border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 6px; border-radius: 9px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.seg.type button.on.exp { color: var(--exp); } .seg.type button.on.inc { color: var(--inc); }
.seg.small button { padding: 7px 4px; font-size: .85rem; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 7px 12px; font-size: .85rem; cursor: pointer; color: var(--ink); }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.add-row { display: flex; gap: 8px; margin-top: 10px; } .add-row input { flex: 1; padding: 8px 10px; font-size: .85rem; }

.amount { display: flex; align-items: center; gap: 8px; border-bottom: 2px solid var(--line); margin: 16px 0 14px; }
.amount span { font-size: 1.4rem; font-weight: 600; color: var(--muted); }
.amount input { border: 0; background: transparent; font-size: 2rem; font-weight: 700; padding: 6px 0; outline: none; }
.actions { display: flex; gap: 10px; } .actions .btn { flex: 1; }

/* onboarding */
.onb { min-height: 100vh; display: flex; flex-direction: column; padding: 20px 16px 0; max-width: 640px; margin: 0 auto; }
.onb-top h2 { margin: 18px 0 4px; font-size: 1.4rem; } .onb-top .muted { margin: 0 0 16px; }
.steps { display: flex; gap: 6px; margin-top: 14px; } .steps span { flex: 1; height: 4px; border-radius: 4px; background: var(--line); } .steps span.on { background: var(--brand); }
.onb-body { flex: 1; }
.onb-actions { position: sticky; bottom: 0; display: flex; gap: 10px; padding: 14px 0 calc(14px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); }
.onb-actions .btn { flex: 1; }
.cat-block { border-top: 1px solid var(--line); padding: 12px 0; } .cat-block:first-child { border-top: 0; padding-top: 0; }
.cat-block.off .cat-head b { color: var(--muted); }
.cat-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; cursor: pointer; }
.cat-head input { width: 18px; height: 18px; accent-color: var(--brand); }

/* targets */
.t-row { display: grid; grid-template-columns: 1fr 150px; grid-template-areas: "name input" "name hint"; gap: 2px 10px; align-items: center; padding: 8px 0; border-top: 1px dashed var(--line); }
.t-row.big { border-top: 0; } .t-row.big .t-name { font-weight: 700; }
.t-name { grid-area: name; font-size: .9rem; } .t-input { grid-area: input; display: flex; align-items: center; gap: 0; }
.t-hint { grid-area: hint; font-size: .75rem; color: var(--muted); text-align: right; min-height: 1em; }
.t-input input { border-radius: 0 10px 10px 0; padding: 8px 10px; text-align: right; }
.unit { border: 1px solid var(--line); border-right: 0; background: var(--brand-soft); color: var(--brand); font-weight: 700; padding: 8px 10px; border-radius: 10px 0 0 10px; cursor: pointer; min-width: 42px; font-size: .85rem; }
.unit.fixed { cursor: default; }
.t-group { margin-top: 12px; } .t-group-head { display: flex; justify-content: space-between; font-size: .9rem; padding: 6px 0; } .t-group-head span { color: var(--muted); font-size: .8rem; }
.t-group .t-name { padding-left: 10px; color: #3B4541; }
.alloc { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: var(--brand-soft); font-size: .85rem; line-height: 1.5; }
.alloc.warn { background: #FBE9E7; color: var(--bad); }

/* reports */
.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.month-nav h2, .month-nav h3 { margin: 0; text-align: center; flex: 1; }
.month-nav button { border: 1px solid var(--line); background: #fff; width: 36px; height: 36px; border-radius: 50%; font-size: 1.2rem; cursor: pointer; }
.month-nav.sticky { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 8px 0; margin: 0 0 6px; }
.start-pick { display: flex; gap: 8px; align-items: center; justify-content: center; font-size: .85rem; color: var(--muted); margin-bottom: 14px; }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.kpis > .kpi:first-child:nth-last-child(3) { grid-column: 1 / -1; }
@media (min-width: 640px) { .kpis { grid-template-columns: repeat(3, 1fr); } .kpis > .kpi:first-child:nth-last-child(3) { grid-column: auto; } }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 3px; }
.kpi span { font-size: .75rem; color: var(--muted); font-weight: 600; } .kpi b { font-size: 1.15rem; } .kpi small { font-size: .75rem; color: var(--muted); }
.kpis.small { margin: 0 0 12px; } .kpis.small .kpi { background: #FCFBF8; }

.chart { position: relative; margin-bottom: 12px; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 0 4px; }
.tbl { width: 100%; border-collapse: collapse; font-size: .82rem; }
.tbl th { text-align: right; color: var(--muted); font-weight: 600; font-size: .72rem; padding: 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { text-align: right; padding: 7px 6px; border-bottom: 1px solid #F0EDE6; white-space: nowrap; }
.tbl th:first-child, .tbl td:first-child { text-align: left; white-space: normal; }
.tbl.wide td:first-child { position: sticky; left: 0; background: #fff; min-width: 110px; }
.tbl tr.strong td { font-weight: 700; }
.balance { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (min-width: 640px) { .balance { grid-template-columns: repeat(4, 1fr); } }
.balance div { background: #FCFBF8; border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.balance span { font-size: .72rem; color: var(--muted); font-weight: 600; } .balance b { font-size: .95rem; }
.balance .end { background: var(--brand-soft); }

/* history */
.tx-list { list-style: none; margin: 0; padding: 0; }
.tx-list li { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "main amt" "main act"; gap: 2px 8px; padding: 10px 0; border-top: 1px solid #F0EDE6; }
.tx-main { grid-area: main; display: flex; flex-direction: column; gap: 2px; min-width: 0; } .tx-main small { color: var(--muted); font-size: .75rem; }
.tx-amt { grid-area: amt; font-weight: 700; text-align: right; } .tx-amt.income { color: var(--inc); } .tx-amt.expense { color: var(--exp); }
.tx-act { grid-area: act; text-align: right; } .tx-act button { border: 0; background: none; cursor: pointer; font-size: .9rem; padding: 2px 6px; opacity: .6; }

/* settings */
.menu-list { list-style: none; padding: 4px 16px; }
.menu-list li { display: flex; align-items: center; gap: 12px; padding: 14px 0; border-top: 1px solid #F0EDE6; cursor: pointer; }
.menu-list li:first-child { border-top: 0; }
.menu-list li div { flex: 1; display: flex; flex-direction: column; gap: 2px; } .menu-list small { color: var(--muted); font-size: .78rem; }
.menu-list .ic { font-size: 1.2rem; } .menu-list .chev { color: var(--muted); } .menu-list li.danger b { color: var(--bad); }
.sub-head { display: flex; align-items: center; gap: 10px; margin: 6px 0 14px; } .back { border: 0; background: none; color: var(--brand); font-weight: 600; cursor: pointer; padding: 4px 0; }

/* tab bar + toast */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; background: #fff; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 10; }
.tabbar button { flex: 1; max-width: 160px; height: var(--tab-h); border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: .72rem; font-weight: 600; cursor: pointer; }
.tabbar svg { width: 22px; height: 22px; } .tabbar button.on { color: var(--brand); }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom)); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: .85rem; z-index: 20; }
.add-row.tight { margin-top: 6px; }

/* auth + cloud */
.loading { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; }
.spinner { width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--brand-soft); border-top-color: var(--brand); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.or { display: flex; align-items: center; gap: 10px; margin: 16px 0; color: var(--muted); font-size: .8rem; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.note { background: var(--brand-soft); border-radius: 10px; padding: 10px 12px; font-size: .85rem; line-height: 1.45; }
.note.bad { background: #FBE9E7; color: var(--bad); }
.tips { padding-left: 18px; margin: 10px 0 16px; } .tips li { margin-bottom: 6px; }
.linkbox { background: #FCFBF8; border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; font-size: .8rem; word-break: break-all; margin: 12px 0; }
a.btn { display: block; text-align: center; text-decoration: none; }
.auth .btn.wide { margin: 6px 0; }

/* brand + admin */
.brand small { display: block; font-size: .68rem; font-weight: 500; color: var(--muted); margin-top: 1px; }
.code-list { list-style: none; padding: 0; margin: 10px 0 0; }
.code-list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid #F0EDE6; }
.code-list li b { flex: 1; letter-spacing: .04em; }
.linkbtn { border: 0; background: none; color: var(--bad); cursor: pointer; font-size: .8rem; padding: 0; }

/* allowance, voice, goals, WA */
.allow { background: linear-gradient(135deg, #2F7D6D, #3E9483); color: #fff; border: 0; }
.allow .muted, .allow small { color: rgba(255,255,255,.8); }
.allow.over { background: linear-gradient(135deg, #B23A30, #D9645A); }
.allow.muted-card { background: #FBF3E4; color: var(--ink); } .allow.muted-card .muted { color: var(--muted); }
.allow-top { display: flex; flex-direction: column; gap: 2px; }
.allow-top span { font-size: .8rem; font-weight: 600; opacity: .9; } .allow-top b { font-size: 1.8rem; } .allow-top small { font-size: .78rem; }
.allow-meta { display: flex; justify-content: space-between; font-size: .8rem; margin: 12px 0 6px; }
.bar { height: 8px; background: rgba(0,0,0,.08); border-radius: 8px; overflow: hidden; margin: 6px 0; }
.allow .bar { background: rgba(255,255,255,.25); } .allow .bar i { background: #fff; }
.bar i { display: block; height: 100%; background: var(--brand); border-radius: 8px; }
.btn.mic { width: 100%; margin: 4px 0 8px; background: var(--brand-soft); color: var(--brand); }
.btn.mic.on { background: #FBE9E7; color: var(--bad); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .6; } }
.heard { font-style: italic; color: var(--muted); font-size: .85rem; margin: 0 0 10px; }
.goal { padding: 8px 0; border-top: 1px solid #F0EDE6; } .goal:first-of-type { border-top: 0; }
.goal-head { display: flex; justify-content: space-between; font-size: .9rem; } .goal-head span { color: var(--muted); font-size: .8rem; }
.btn.wa { background: #25D366; color: #fff; margin-bottom: 0; }

.add-row input.quota { flex: 0 0 72px; text-align: center; }
