:root {
  --bg: #f4f6f5; --card: #fff; --text: #1d2b27; --muted: #7a8985; --line: #e3e9e7;
  --brand: #2f6f5e; --brand-soft: #e1efea; --expense: #d6554d; --income: #2f8f5b;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121816; --card: #1b2421; --text: #e6eeeb; --muted: #8fa09b; --line: #2a3733;
    --brand: #4fae93; --brand-soft: #24362f; --expense: #ef7b73; --income: #5cc58a;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
input, select { font: inherit; color: inherit; }

#view { padding: 12px 16px calc(150px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }
h2 { font-size: 18px; margin: 20px 0 10px; }
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.muted { color: var(--muted); font-size: 13px; }
.expense { color: var(--expense); } .income { color: var(--income); }

/* month bar + summary */
.monthbar { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 12px; }
.monthbar button { font-size: 22px; padding: 6px 14px; border-radius: 10px; }
.monthbar b { font-size: 18px; }
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.summary div { background: var(--card); border-radius: var(--radius); padding: 10px 12px; }
.summary b { display: block; font-size: 17px; margin-top: 2px; }

/* list */
.day { display: flex; justify-content: space-between; padding: 14px 4px 6px; font-size: 13px; color: var(--muted); }
.item { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--card); padding: 11px 14px; border-bottom: 1px solid var(--line); }
.day + .item { border-radius: var(--radius) var(--radius) 0 0; }
.item:last-child, .item:has(+ .day) { border-bottom: 0; border-radius: 0 0 var(--radius) var(--radius); }
.day + .item:last-child, .day + .item:has(+ .day) { border-radius: var(--radius); }
.ico { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-size: 19px; flex: none; }
.item .mid { flex: 1; min-width: 0; }
.item .mid div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .amt { font-weight: 600; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* stats */
.donut-wrap { display: flex; align-items: center; gap: 16px; }
.donut { width: 140px; height: 140px; flex: none; }
.donut text { fill: var(--text); }
.legend { flex: 1; font-size: 14px; }
.legend div { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.bars { display: flex; align-items: flex-end; gap: 10px; height: 130px; padding-top: 8px; }
.bars .col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; font-size: 11px; color: var(--muted); }
.bars .bar { width: 100%; max-width: 34px; background: var(--brand); border-radius: 6px 6px 0 0; min-height: 2px; }
.bars .col.cur .bar { background: var(--expense); }
.catrow { margin: 10px 0; }
.catrow .top { display: flex; justify-content: space-between; font-size: 14px; }
.track { height: 7px; background: var(--line); border-radius: 4px; margin-top: 5px; overflow: hidden; }
.track i { display: block; height: 100%; background: var(--brand); border-radius: 4px; }

/* goals */
.goal .head { display: flex; justify-content: space-between; align-items: baseline; }
.goal .head b { font-size: 17px; }
.goal .pct { font-size: 26px; font-weight: 700; color: var(--brand); margin: 6px 0 2px; }
.goal .track { height: 10px; }
.goal .actions { display: flex; gap: 8px; margin-top: 12px; }

/* buttons & forms */
.btn { padding: 10px 16px; border-radius: 10px; background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.danger { color: var(--expense); background: transparent; }
.btn.block { width: 100%; margin-top: 8px; }
.row { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row.tap { width: 100%; text-align: left; }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; }

#fab { position: fixed; right: 18px; bottom: calc(76px + env(safe-area-inset-bottom)); width: 56px; height: 56px;
  border-radius: 50%; background: var(--brand); color: #fff; font-size: 30px; line-height: 1;
  box-shadow: 0 4px 14px rgba(0,0,0,.28); z-index: 5; }
#nav { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 4; }
#nav button { flex: 1; padding: 8px 0 6px; font-size: 12px; color: var(--muted); }
#nav button span { display: block; font-size: 21px; }
#nav button.on { color: var(--brand); font-weight: 600; }

dialog { border: 0; padding: 0; width: 100%; max-width: 560px; margin: auto auto 0; border-radius: 20px 20px 0 0;
  background: var(--card); color: var(--text); max-height: 92vh; }
dialog::backdrop { background: rgba(0,0,0,.45); }
.sheet-in { padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); }
.sheet-in h3 { margin: 0 0 12px; }
.seg { display: grid; grid-auto-flow: column; gap: 4px; background: var(--bg); padding: 4px; border-radius: 12px; margin-bottom: 12px; }
.seg button { padding: 8px; border-radius: 9px; }
.seg button.on { background: var(--card); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.amount { width: 100%; font-size: 34px; font-weight: 700; border: 0; border-bottom: 2px solid var(--line);
  background: none; padding: 6px 0; margin-bottom: 12px; outline: none; }
.amount:focus { border-color: var(--brand); }
.cats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.cat { padding: 8px 2px; border-radius: 12px; background: var(--bg); font-size: 12px; border: 2px solid transparent; }
.cat span { display: block; font-size: 22px; }
.cat.on { border-color: var(--brand); background: var(--brand-soft); }
.field { display: block; margin-bottom: 10px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.field input, .field select { width: 100%; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
