:root {
  --bg: #f7f7f5; --card: #ffffff; --text: #1c1c1a; --muted: #6b6b66; --line: #e6e6e1;
  --green: #16a34a; --green-soft: #dcfce7; --red: #dc2626; --bar: #d4d4cf; --shadow: 0 1px 2px rgb(0 0 0 / .06);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111211; --card: #1b1c1b; --text: #ececea; --muted: #9a9a94; --line: #2b2c2b; --green: #22c55e; --green-soft: #14361f; --red: #f87171; --bar: #3a3b3a; --shadow: none; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Heebo, Arial, sans-serif; -webkit-tap-highlight-color: transparent; }
button, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.error { color: var(--red); font-size: 14px; }
code { font-size: 13px; }

#app { max-width: 560px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 12px) 16px 0; }
.top { display: flex; justify-content: space-between; align-items: center; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.balance { font-size: 32px; font-weight: 700; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.icon-btn { background: none; border: 0; font-size: 22px; padding: 6px 10px; border-radius: 10px; cursor: pointer; }
.icon-btn:active { background: var(--line); }
.sync { width: 9px; height: 9px; border-radius: 50%; background: var(--green); }
.sync.pending { background: #f59e0b; }
.sync.offline { background: var(--muted); }

.month { display: flex; justify-content: space-between; align-items: center; margin: 14px 0 8px; font-weight: 600; }
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--card); border-radius: 14px; padding: 10px 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.stat b { font-size: 18px; font-variant-numeric: tabular-nums; }

.breakdown { background: var(--card); border-radius: 14px; padding: 6px 12px; margin-top: 10px; box-shadow: var(--shadow); }
.breakdown:empty { display: none; }
.bk { display: grid; grid-template-columns: 26px 1fr auto; gap: 4px 8px; align-items: center; padding: 6px 0; }
.bk .track { grid-column: 2 / 4; height: 5px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bk .fill { height: 100%; background: var(--bar); border-radius: 3px; }
.bk:first-child .fill { background: var(--green); }
.bk .amt { font-variant-numeric: tabular-nums; }

.list { margin-top: 14px; }
.day { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; padding: 10px 4px 4px; }
.tx { display: grid; grid-template-columns: 36px 1fr auto; gap: 10px; align-items: center; width: 100%; text-align: start; background: var(--card); border: 0; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.day + .tx { border-radius: 14px 14px 0 0; }
.tx.last { border-radius: 0 0 14px 14px; border-bottom: 0; }
.day + .tx.last { border-radius: 14px; }
.tx .emo { font-size: 20px; text-align: center; }
.tx .main { min-width: 0; }
.tx .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .sub { font-size: 12px; color: var(--muted); }
.tx .amt { font-variant-numeric: tabular-nums; font-weight: 600; }
.tx.queued { opacity: .65; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

.spacer { height: calc(96px + env(safe-area-inset-bottom)); }
.actions { position: fixed; inset: auto 0 0 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px); background: linear-gradient(transparent, var(--bg) 30%); max-width: 560px; margin: 0 auto; }
.btn { border: 0; border-radius: 14px; padding: 13px 16px; font-weight: 600; cursor: pointer; background: var(--card); box-shadow: var(--shadow); }
.btn:active { transform: scale(.98); }
.btn.in { background: var(--green); color: #fff; }
.btn.out { background: var(--text); color: var(--bg); }
.btn.ghost { background: transparent; box-shadow: none; border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--red); box-shadow: none; margin-inline-end: auto; }
.actions .btn { padding: 16px; font-size: 18px; }

.sheet { width: 100%; max-width: 560px; margin: auto auto 0; border: 0; border-radius: 22px 22px 0 0; padding: 18px 16px calc(env(safe-area-inset-bottom) + 16px); background: var(--bg); color: var(--text); max-height: 92vh; }
.sheet::backdrop { background: rgb(0 0 0 / .35); }
.sheet h2 { margin: 0 0 12px; font-size: 20px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--line); border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: none; padding: 8px; border-radius: 10px; font-weight: 600; cursor: pointer; }
.seg button.on { background: var(--card); box-shadow: var(--shadow); }
.amount { display: flex; align-items: baseline; justify-content: center; gap: 6px; margin: 14px 0 8px; font-size: 40px; font-weight: 700; }
.amount input { width: 7ch; border: 0; background: none; font-size: 44px; font-weight: 700; text-align: center; outline: none; font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; margin-top: 12px; }
.col { display: flex; flex-direction: column; gap: 8px; }
.row input, .field input, .login input { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 11px 12px; }
#date { flex: 0 0 auto; }
.hint { margin: 12px 2px 6px; }
.cats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cat { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 2px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); cursor: pointer; font-size: 12px; }
.cat .emo { font-size: 22px; }
.cat.on { border-color: var(--green); background: var(--green-soft); }
.field { display: flex; flex-direction: column; gap: 6px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

.login { max-width: 360px; margin: 0 auto; padding: 18vh 24px 0; text-align: center; }
.login img { border-radius: 18px; }
.login h1 { margin: 10px 0 4px; }
.login form { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }

.warn { color: #d97706; }
.grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.howto summary { font-weight: 600; cursor: pointer; padding: 4px 0; }
.howto .row { margin: 8px 0; }
.howto ol { padding-inline-start: 20px; line-height: 1.6; }
.sheet { overflow-y: auto; }
