:root {
  --bg: #f4f6f8; --card: #ffffff; --text: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --accent: #0f766e; --accent-soft: #ccfbf1; --inc: #15803d; --exp: #b91c1c;
  --on-accent: #fff; --green: #22c55e; --yellow: #eab308; --red: #ef4444; --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120; --card: #131c2e; --text: #e2e8f0; --muted: #94a3b8; --line: #1e293b;
    --accent: #2dd4bf; --accent-soft: #134e4a; --inc: #4ade80; --exp: #f87171;
    --on-accent: #042f2e;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.page { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
h1 { font-size: 1.4rem; margin: 8px 0 12px; }
h2 { font-size: 1rem; margin: 0 0 10px; }
h3.day { font-size: .85rem; color: var(--muted); margin: 16px 4px 6px; font-weight: 600; }
small { display: block; color: var(--muted); font-size: .8rem; }
.muted { color: var(--muted); }
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
  box-shadow: 0 1px 2px rgb(0 0 0 / .05); }
.stack > * + * { margin-top: 8px; }
.row { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.row > input, .row > select { flex: 1 1 0; min-width: 0; }
.row > .btn { flex: none; }
.row > .icon-input, .row > input[type=color] { flex: none; }
.grow { flex: 1; min-width: 0; }
.inc { color: var(--inc); } .exp { color: var(--exp); }

.balance { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.balance strong { font-size: 1.05rem; white-space: nowrap; }

.flash { background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; }
.flash.err { background: #fee2e2; color: #7f1d1d; }

.tx { display: flex; gap: 10px; align-items: center; padding: 8px 0; color: inherit; text-decoration: none;
  border-bottom: 1px solid var(--line); }
.tx:last-child { border-bottom: 0; }
.tx .ic { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-size: 1.2rem; flex: none; }
.tx b { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .amt { font-weight: 600; white-space: nowrap; }

.budget + .budget { margin-top: 10px; }
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; border-radius: 99px; }
.bar .green { background: var(--green); } .bar .yellow { background: var(--yellow); } .bar .red { background: var(--red); }

.missing { display: flex; gap: 6px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.missing:last-child { border-bottom: 0; }
.missing input { width: 90px; flex: none; }
.missing.overdue .grow { color: var(--exp); }

input, select, button { font: inherit; color: inherit; }
input, select { width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
input[type=radio], input[type=checkbox] { width: auto; }
input[type=color] { width: 52px; padding: 4px; height: 46px; }
.icon-input { width: 60px; text-align: center; flex: none; }
label { display: block; font-size: .9rem; }
label.check { display: flex; gap: 8px; align-items: center; }
.btn { display: block; width: 100%; padding: 13px; border: 0; border-radius: 12px; background: var(--accent);
  color: var(--on-accent); font-weight: 600; text-align: center; text-decoration: none; cursor: pointer; }
.btn.sm { width: auto; padding: 10px 14px; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn.danger { background: transparent; color: var(--exp); border: 1px solid var(--exp); margin-top: 8px; }

.entry > * + * { margin-top: 10px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 12px; padding: 4px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 8px; border-radius: 9px; cursor: pointer; }
.seg input:checked + span { background: var(--card); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / .1); }
.amountwrap { display: flex; align-items: baseline; gap: 8px; }
.amount { font-size: 2.2rem; font-weight: 700; text-align: right; border: 0; background: transparent; padding: 4px 0; }
.amountwrap span { color: var(--muted); font-weight: 600; }
.cats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.cat input { position: absolute; opacity: 0; pointer-events: none; }
.cat span { display: block; text-align: center; font-size: 1.4rem; padding: 8px 2px; border-radius: 12px;
  border: 1px solid var(--line); cursor: pointer; }
.cat small { font-size: .68rem; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat input:checked + span { border-color: var(--accent); background: var(--accent-soft); }
.cat[hidden] { display: none; }
.thumb { width: 100%; max-height: 220px; object-fit: contain; border-radius: 12px; background: var(--bg); }
.upload { margin-bottom: 12px; }
.entry.saved { opacity: .6; pointer-events: none; }

.monthnav { display: flex; align-items: center; justify-content: space-between; }
.monthnav a { font-size: 1.8rem; text-decoration: none; color: var(--accent); padding: 0 12px; }
.filters { display: flex; gap: 8px; margin-bottom: 4px; }

.chart { position: relative; height: 240px; }
table.list { width: 100%; border-collapse: collapse; margin-top: 10px; }
table.list td { padding: 6px 0; border-bottom: 1px solid var(--line); }
td.num { text-align: right; white-space: nowrap; }

details.item { border-bottom: 1px solid var(--line); padding: 8px 0; }
details.item summary { cursor: pointer; list-style: none; }
details.item summary small { display: inline; margin-left: 4px; }
details.item form { margin-top: 10px; }

.login { max-width: 360px; margin: 18vh auto 0; text-align: center; }
.login form > * + * { margin-top: 10px; }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr);
  align-items: center; background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
.tabbar a { text-align: center; font-size: .68rem; color: var(--muted); text-decoration: none; }
.tabbar a span { display: block; font-size: 1.3rem; }
.tabbar a.on { color: var(--accent); font-weight: 600; }
.tabbar a.plus { justify-self: center; width: 56px; height: 56px; margin-top: -24px; border-radius: 50%;
  background: var(--accent); color: var(--on-accent); font-size: 2rem; line-height: 56px; box-shadow: 0 4px 12px rgb(0 0 0 / .2); }
