:root {
  --bg: #F3F4F1;
  --surface: #FFFFFF;
  --surface-2: #EEF0EC;
  --text: #121614;
  --text-2: #59615C;
  --text-3: #8B938E;
  --line: rgba(18, 22, 20, 0.08);
  --accent: #0E7A55;
  --accent-ink: #FFFFFF;
  --accent-soft: #DFF1E8;
  --danger: #C8372D;
  --danger-soft: #FBE7E5;
  --warn: #A86512;
  --warn-soft: #FCF0DC;
  --track: #E4E7E2;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.05);
  --radius: 20px;
  --radius-sm: 14px;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --num: ui-rounded, "SF Pro Rounded", -apple-system, system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0B0F0D;
    --surface: #151A17;
    --surface-2: #1E2521;
    --text: #EEF2EF;
    --text-2: #A5AFA9;
    --text-3: #75807A;
    --line: rgba(255, 255, 255, 0.08);
    --accent: #3CC48F;
    --accent-ink: #06130D;
    --accent-soft: #143325;
    --danger: #FF6B5E;
    --danger-soft: #3A1714;
    --warn: #F0B04C;
    --warn-soft: #382811;
    --track: #262E29;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: inherit; text-decoration: none; }
.num { font-family: var(--num); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

#app { max-width: 560px; margin: 0 auto; min-height: 100dvh; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(var(--safe-t) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.topbar h1 { font-size: 28px; line-height: 1.1; margin: 0; letter-spacing: -0.02em; font-weight: 750; }
.topbar .brand { display: flex; align-items: center; gap: 10px; }
.topbar .logo { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font: 800 13px/1 var(--num); letter-spacing: -0.03em; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); box-shadow: var(--shadow); color: var(--text-2); }
.icon-btn svg { width: 20px; height: 20px; }

.month-switch { display: inline-flex; align-items: center; gap: 2px; background: var(--surface); border-radius: 999px; padding: 3px; box-shadow: var(--shadow); }
.month-switch button { width: 32px; height: 32px; border-radius: 50%; color: var(--text-2); font-size: 18px; display: grid; place-items: center; }
.month-switch button:active { background: var(--surface-2); }
.month-switch span { font-weight: 600; font-size: 15px; padding: 0 6px; min-width: 116px; text-align: center; }

/* ---------- view ---------- */
.view { padding: 4px 16px calc(var(--tabbar-h) + var(--safe-b) + 28px); }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 26px 4px 10px; }
.section-title h2 { font-size: 20px; margin: 0; letter-spacing: -0.01em; font-weight: 700; }
.section-title a, .section-title button { color: var(--accent); font-weight: 600; font-size: 15px; }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 12px; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.pos { color: var(--accent); }
.neg { color: var(--danger); }

/* hero */
.hero { padding: 20px 20px 18px; }
.hero-label { font-size: 15px; color: var(--text-2); font-weight: 500; }
.hero-amount { font: 750 44px/1.05 var(--num); letter-spacing: -0.03em; margin: 6px 0 14px; font-variant-numeric: tabular-nums; }
.hero-sub { display: flex; justify-content: space-between; gap: 8px; margin-top: 10px; font-size: 14px; color: var(--text-2); }

/* progress bars */
.bar { position: relative; height: 8px; border-radius: 99px; background: var(--track); overflow: visible; }
.bar.big { height: 12px; }
.bar > span { position: absolute; inset: 0 auto 0 0; border-radius: inherit; background: var(--c, var(--accent)); max-width: 100%; transition: width .4s ease; }
.bar.over > span { background: var(--danger); }
.bar .pace { position: absolute; top: -4px; bottom: -4px; width: 2px; border-radius: 2px; background: var(--text); opacity: .55; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.stat { background: var(--surface); border-radius: var(--radius-sm); padding: 12px; box-shadow: var(--shadow); min-width: 0; }
.stat .k { font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.stat .v { font: 700 17px/1.2 var(--num); margin-top: 4px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.balance-line { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; padding: 12px 16px; border-radius: var(--radius-sm); background: var(--surface-2); font-size: 15px; }
.balance-line b { font: 700 17px var(--num); font-variant-numeric: tabular-nums; }

/* alerts */
.alert { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border-radius: var(--radius-sm); font-size: 14.5px; margin-top: 10px; }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.danger { background: var(--danger-soft); color: var(--danger); }
.alert b { font-weight: 650; }

/* list rows */
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; width: 100%; text-align: left; position: relative; }
.row + .row::before { content: ""; position: absolute; top: 0; left: 64px; right: 0; height: 1px; background: var(--line); }
button.row:active, a.row:active { background: var(--surface-2); }
.bubble { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-size: 19px; flex: none; background: color-mix(in srgb, var(--c, var(--accent)) 16%, transparent); }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 560; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { font-size: 13.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .end { text-align: right; flex: none; }
.row .amt { font: 650 16px var(--num); font-variant-numeric: tabular-nums; }
.row .bar { margin-top: 8px; height: 6px; }
.day-head { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .03em; margin: 20px 6px 8px; }

/* accounts strip */
.strip { display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory; margin: 0 -16px; padding: 2px 16px 6px; scrollbar-width: none; }
.strip::-webkit-scrollbar { display: none; }
.acct { flex: 0 0 auto; min-width: 150px; scroll-snap-align: start; background: var(--surface); border-radius: var(--radius-sm); padding: 14px; box-shadow: var(--shadow); }
.acct .name { font-size: 14px; color: var(--text-2); display: flex; gap: 6px; align-items: center; }
.acct .v { font: 700 19px var(--num); margin-top: 6px; font-variant-numeric: tabular-nums; }

/* goal */
.goal-top { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.goal-top .bubble { width: 46px; height: 46px; font-size: 24px; border-radius: 14px; }
.goal-top h3 { margin: 0; font-size: 17px; }
.goal-nums { display: flex; justify-content: space-between; align-items: baseline; margin-top: 10px; font-size: 14px; color: var(--text-2); }
.goal-nums b { font: 750 22px var(--num); color: var(--text); font-variant-numeric: tabular-nums; }
.goal-actions { display: flex; gap: 10px; margin-top: 16px; }

/* empty */
.empty { text-align: center; padding: 30px 20px; }
.empty .big { font-size: 40px; }
.empty p { color: var(--text-2); margin: 8px 0 18px; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 48px; padding: 0 20px; border-radius: 14px; font-weight: 650; background: var(--surface-2); color: var(--text); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.block { width: 100%; }
.btn.small { height: 38px; padding: 0 14px; font-size: 15px; border-radius: 12px; }
.btn[disabled] { opacity: .45; }
.link { color: var(--accent); font-weight: 600; }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 38px; padding: 0 13px; border-radius: 12px; background: var(--surface-2); font-size: 15px; font-weight: 520; border: 1.5px solid transparent; white-space: nowrap; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--text); font-weight: 620; }
.chip .e { font-size: 16px; }
.filters { display: flex; gap: 8px; overflow-x: auto; margin: 4px -16px 0; padding: 4px 16px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters .chip { background: var(--surface); box-shadow: var(--shadow); }
.filters .chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }

/* segmented */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); padding: 3px; border-radius: 12px; gap: 2px; }
.seg button { height: 34px; border-radius: 9px; font-size: 14.5px; font-weight: 560; color: var(--text-2); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); font-weight: 650; }

/* inputs */
.field { margin-top: 18px; }
.field > label, .label { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; margin: 0 2px 8px; }
.input { width: 100%; height: 48px; border-radius: 14px; border: 1.5px solid transparent; background: var(--surface-2); padding: 0 14px; font-size: 16px; outline: none; }
.input:focus { border-color: var(--accent); background: var(--surface); }
textarea.input { height: auto; padding: 12px 14px; resize: none; line-height: 1.35; }
.search { background: var(--surface); box-shadow: var(--shadow); }

.quick { position: relative; margin-top: 16px; }
.quick textarea { font-size: 18px; min-height: 64px; padding-right: 56px; background: var(--surface-2); }
.quick .mic { position: absolute; right: 8px; top: 8px; width: 44px; height: 44px; border-radius: 12px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.quick .mic svg { width: 22px; height: 22px; }
.quick .mic.live { animation: pulse 1.2s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 45%, transparent); } 50% { box-shadow: 0 0 0 10px transparent; } }
.hint { font-size: 13px; color: var(--text-3); margin: 8px 4px 0; }

.amount-wrap { display: flex; align-items: center; justify-content: center; gap: 4px; margin-top: 18px; }
.amount-wrap .cur { font: 700 34px var(--num); color: var(--text-3); }
.amount-input { border: 0; background: none; outline: none; text-align: center; font: 750 44px/1.1 var(--num); letter-spacing: -0.03em; width: 100%; max-width: 330px; font-variant-numeric: tabular-nums; }
.amount-input::placeholder { color: var(--text-3); }

.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  max-width: 560px; margin: 0 auto;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-top: 1px solid var(--line);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10.5px; font-weight: 560; color: var(--text-3); }
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a.on { color: var(--accent); }
.fab { justify-self: center; width: 56px; height: 56px; border-radius: 18px; background: var(--accent); color: var(--accent-ink); font-size: 32px; font-weight: 400; line-height: 1; display: grid; place-items: center; box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 40%, transparent); transform: translateY(-10px); }
.fab:active { transform: translateY(-10px) scale(.94); }

/* ---------- sheet ---------- */
.backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .38); opacity: 0; transition: opacity .25s ease; }
.backdrop.in { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51; max-width: 560px; margin: 0 auto;
  max-height: calc(100dvh - var(--safe-t) - 24px); overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border-radius: 24px 24px 0 0;
  padding: 8px 18px calc(18px + var(--safe-b));
  transform: translateY(100%); transition: transform .32s cubic-bezier(.2, .9, .25, 1);
}
.sheet.in { transform: translateY(0); }
.sheet .grab { width: 38px; height: 5px; border-radius: 3px; background: var(--track); margin: 0 auto 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.sheet-head .x { width: 32px; height: 32px; border-radius: 50%; background: var(--surface-2); color: var(--text-2); font-size: 15px; display: grid; place-items: center; }
.sheet-foot { position: sticky; bottom: calc(-18px - var(--safe-b)); margin: 22px -18px calc(-18px - var(--safe-b)); padding: 12px 18px calc(18px + var(--safe-b)); background: var(--surface); border-top: 1px solid var(--line); display: grid; gap: 10px; }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; background: var(--c); border: 3px solid var(--surface); box-shadow: 0 0 0 1.5px var(--line); }
.swatch.on { box-shadow: 0 0 0 2.5px var(--c); }
.emoji-input { width: 64px; text-align: center; font-size: 26px; padding: 0; }
.inline { display: flex; gap: 10px; align-items: flex-end; }
.inline > .grow { flex: 1; }

/* ---------- cloud sync ---------- */
.icon-btn { position: relative; }
.icon-btn[data-sync]::after { content: ""; position: absolute; top: 3px; right: 3px; width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--surface); background: transparent; }
.icon-btn[data-sync="ok"]::after, .icon-btn[data-sync="idle"]::after { background: var(--accent); }
.icon-btn[data-sync="pending"]::after, .icon-btn[data-sync="syncing"]::after { background: var(--warn); }
.icon-btn[data-sync="offline"]::after { background: var(--text-3); }
.icon-btn[data-sync="error"]::after { background: var(--danger); }
.readonly .fab { visibility: hidden; }
.readonly [data-edit-only] { display: none !important; }
.code-input { text-align: center; font: 700 28px var(--num); letter-spacing: .3em; height: 60px; }
.role-chip { font-size: 12.5px; font-weight: 650; padding: 3px 9px; border-radius: 99px; background: var(--surface-2); color: var(--text-2); }
.role-chip.owner { background: var(--accent-soft); color: var(--accent); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 18px); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); border-radius: 14px; padding: 12px 16px;
  display: flex; gap: 14px; align-items: center; font-size: 15px; font-weight: 550;
  transition: all .25s ease; max-width: calc(100% - 32px); white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { color: var(--accent); font-weight: 700; filter: brightness(1.3); }

.settings-group { margin-top: 8px; }
.kv { display: flex; justify-content: space-between; gap: 12px; }
.version { text-align: center; font-size: 13px; color: var(--text-3); margin-top: 28px; }

@media (min-width: 600px) {
  .view { padding-left: 20px; padding-right: 20px; }
}
