:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #ffffff;
  --surface-2: #f0efec;
  --line: #e7e6e2;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #8a897f;
  --accent: #2a78d6;
  --accent-soft: #e3eefb;
  --accent-ink: #1c5cab;
  --pos: #0a7a0a;
  --warn: #b77a00;
  --warn-bg: #fff4dc;
  --crit: #d03b3b;
  --crit-bg: #fdeaea;
  --goal: #6250d6;
  --goal-bg: #efedfc;
  --bar-track: #ecebe7;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --radius: 20px;
  --tab-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f0f0e;
    --surface: #1a1a19;
    --surface-2: #242422;
    --line: #2c2c2a;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #8f8e86;
    --accent: #3987e5;
    --accent-soft: #17283d;
    --accent-ink: #86b6ef;
    --pos: #3fbf4f;
    --warn: #fab219;
    --warn-bg: #2e2513;
    --crit: #e66767;
    --crit-bg: #331b1b;
    --goal: #9085e9;
    --goal-bg: #23203d;
    --bar-track: #2a2a28;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f0f0e; --surface: #1a1a19; --surface-2: #242422; --line: #2c2c2a;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #8f8e86;
  --accent: #3987e5; --accent-soft: #17283d; --accent-ink: #86b6ef; --pos: #3fbf4f;
  --warn: #fab219; --warn-bg: #2e2513; --crit: #e66767; --crit-bg: #331b1b;
  --goal: #9085e9; --goal-bg: #23203d; --bar-track: #2a2a28; --shadow: none;
}

* { 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", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
.num { font-variant-numeric: tabular-nums; }
svg.i { width: 22px; height: 22px; flex: none; display: block; }
svg.i.sm { width: 18px; height: 18px; }
svg.i.xs { width: 15px; height: 15px; }
svg.i.lg { width: 28px; height: 28px; }

#app { max-width: 560px; margin: 0 auto; min-height: 100vh; }
.page { padding: calc(var(--safe-t) + 12px) 16px calc(var(--tab-h) + var(--safe-b) + 24px); }
.page.no-tabs { padding-bottom: 32px; }

/* шапка */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; margin-bottom: 8px; }
.top h1 { font-size: 28px; line-height: 1.15; font-weight: 700; letter-spacing: -.02em; margin: 0; }
.month { display: inline-flex; align-items: center; gap: 2px; background: var(--surface); border-radius: 999px; padding: 4px; box-shadow: var(--shadow); }
.month span { font-size: 14px; font-weight: 600; min-width: 92px; text-align: center; text-transform: capitalize; }
.icon-btn { width: 36px; height: 36px; border-radius: 999px; display: grid; place-items: center; color: var(--text-2); }
.icon-btn:active { background: var(--surface-2); }
.icon-btn[disabled] { opacity: .3; }

/* карточки */
.card { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 12px; }
.card h2 { font-size: 13px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; margin: 0 0 12px; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 22px 4px 10px; }
.section-title h2 { font-size: 20px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.link { color: var(--accent); font-size: 15px; font-weight: 500; }

.hero .label { color: var(--text-2); font-size: 15px; }
.hero .big { font-size: 40px; font-weight: 700; letter-spacing: -.03em; line-height: 1.1; margin: 4px 0 2px; }
.hero .sub { color: var(--text-3); font-size: 14px; }
.hero .split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.pill { background: var(--surface-2); border-radius: 14px; padding: 10px 12px; }
.pill .t { font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.pill .v { font-size: 18px; font-weight: 650; margin-top: 2px; }
.pos { color: var(--pos); }

.bar { height: 8px; background: var(--bar-track); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--accent); }
.bar.warn > i { background: var(--warn); }
.bar.crit > i { background: var(--crit); }
.bar.goal > i { background: var(--goal); }
.bar-meta { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-3); margin-top: 6px; }

.accounts { display: flex; gap: 10px; overflow-x: auto; margin: 0 -16px 12px; padding: 2px 16px 6px; scrollbar-width: none; }
.accounts::-webkit-scrollbar { display: none; }
.acc { flex: none; min-width: 160px; background: var(--surface); border-radius: 18px; padding: 12px 14px; box-shadow: var(--shadow); }
.acc .n { font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.acc .b { font-size: 19px; font-weight: 650; margin-top: 4px; }

/* советы */
.tip { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: 16px; background: var(--accent-soft); margin-bottom: 8px; font-size: 15px; }
.tip .ic { color: var(--accent-ink); margin-top: 1px; }
.tip.warning { background: var(--warn-bg); } .tip.warning .ic { color: var(--warn); }
.tip.critical { background: var(--crit-bg); } .tip.critical .ic { color: var(--crit); }
.tip.goal { background: var(--goal-bg); } .tip.goal .ic { color: var(--goal); }
.tip b { font-weight: 600; }

/* строки */
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 12px; }
.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); }
.row:active { background: var(--surface-2); }
.tile { width: 38px; height: 38px; border-radius: 12px; background: var(--surface-2); color: var(--text-2); display: grid; place-items: center; flex: none; }
.tile.accent { background: var(--accent-soft); color: var(--accent-ink); }
.tile.goal { background: var(--goal-bg); color: var(--goal); }
.row .main { flex: 1; min-width: 0; }
.row .title { font-size: 16px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { font-size: 13px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .amt { font-size: 16px; font-weight: 600; white-space: nowrap; text-align: right; }
.row .amt small { display: block; font-size: 12px; font-weight: 400; color: var(--text-3); }
.row.muted .title, .row.muted .amt { color: var(--text-3); }
.row.muted .amt { text-decoration: line-through; }
.row .bar { margin-top: 7px; height: 6px; }
.chev { color: var(--text-3); }

.day-head { display: flex; justify-content: space-between; color: var(--text-3); font-size: 13px; font-weight: 600; margin: 18px 6px 8px; text-transform: uppercase; letter-spacing: .04em; }

/* график */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis { fill: var(--text-3); font-size: 11px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .b { fill: var(--accent); }
.chart .b.inc { fill: var(--pos); opacity: .85; }
.chart .b.dim { opacity: .35; }
.chart .hit { fill: transparent; }
.chart-tip { position: absolute; top: -6px; transform: translate(-50%, -100%); background: var(--text); color: var(--bg); font-size: 12px; padding: 6px 9px; border-radius: 10px; white-space: nowrap; pointer-events: none; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--text-2); margin-bottom: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* цели */
.goal-card { display: flex; gap: 14px; align-items: center; }
.ring { width: 64px; height: 64px; flex: none; position: relative; }
.ring svg { width: 64px; height: 64px; transform: rotate(-90deg); }
.ring .pct { position: absolute; inset: 0; display: grid; place-items: center; font-size: 14px; font-weight: 700; }
.goal-card .gt { font-size: 17px; font-weight: 600; }
.goal-card .gs { font-size: 14px; color: var(--text-2); margin-top: 2px; }
.goal-card .gm { font-size: 13px; color: var(--text-3); margin-top: 4px; }

/* таб-бар */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
.tabs nav { max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); height: var(--tab-h); }
.tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; color: var(--text-3); text-decoration: none; font-weight: 500; }
.tabs a.on { color: var(--accent); }

.fab { position: fixed; right: max(16px, calc(50% - 264px)); bottom: calc(var(--tab-h) + var(--safe-b) + 16px); z-index: 15;
  width: 56px; height: 56px; border-radius: 999px; background: var(--accent); color: #fff; display: grid; place-items: center;
  box-shadow: 0 6px 20px rgba(42,120,214,.35); }

/* формы */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--text-2); margin: 0 4px 6px; font-weight: 500; }
.input { width: 100%; background: var(--surface-2); border: 1px solid transparent; border-radius: 14px; padding: 13px 14px; font-size: 17px; outline: none; }
.input:focus { border-color: var(--accent); background: var(--surface); }
.input.big { font-size: 32px; font-weight: 700; text-align: center; letter-spacing: -.02em; }
.btn { width: 100%; height: 52px; border-radius: 16px; background: var(--accent); color: #fff; font-size: 17px; font-weight: 600; display: flex; align-items: center; justify-content: center; gap: 8px; }
.btn:active { filter: brightness(.95); }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--crit-bg); color: var(--crit); }
.btn[disabled] { opacity: .5; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border-radius: 12px; padding: 3px; margin-bottom: 14px; }
.seg button { height: 34px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--text-2); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--bar-track); border-radius: 999px; transition: .2s; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 999px; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.2); transition: .2s; }
.switch input:checked + span { background: var(--pos); }
.switch input:checked + span::after { transform: translateX(20px); }
.check { display: flex; align-items: center; gap: 10px; font-size: 15px; padding: 6px 4px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.icon-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.icon-grid button { border-radius: 14px; padding: 10px 4px; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 11px; color: var(--text-2); background: var(--surface-2); line-height: 1.15; text-align: center; min-height: 72px; }
.icon-grid button.on { background: var(--accent-soft); color: var(--accent-ink); outline: 2px solid var(--accent); }
.icon-grid.only-icons { grid-template-columns: repeat(6, 1fr); }
.icon-grid.only-icons button { min-height: 48px; padding: 12px 0; }

/* шторка */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; opacity: 0; transition: opacity .2s; }
.sheet-bg.show { opacity: 1; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-width: 560px; margin: 0 auto; background: var(--surface);
  border-radius: 24px 24px 0 0; max-height: 92vh; overflow-y: auto; padding: 8px 16px calc(var(--safe-b) + 20px);
  transform: translateY(100%); transition: transform .25s cubic-bezier(.2,.8,.2,1); }
.sheet.show { transform: none; }
.sheet .grab { width: 40px; height: 5px; border-radius: 999px; background: var(--line); margin: 4px auto 12px; }
.sheet h3 { font-size: 20px; margin: 0 0 16px; text-align: center; }
.sheet .amount-head { text-align: center; margin: 4px 0 18px; }
.sheet .amount-head .a { font-size: 36px; font-weight: 700; letter-spacing: -.02em; }
.sheet .amount-head .m { color: var(--text-2); margin-top: 2px; }
.kv { display: flex; justify-content: space-between; padding: 9px 4px; font-size: 15px; border-bottom: 1px solid var(--line); }
.kv span:first-child { color: var(--text-2); }

.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 20px); transform: translateX(-50%); z-index: 60;
  background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 14px; font-size: 15px; max-width: 90vw; box-shadow: 0 8px 24px rgba(0,0,0,.2); }

/* вход */
.auth { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px; max-width: 400px; margin: 0 auto; }
.auth .logo { width: 72px; height: 72px; border-radius: 20px; margin: 0 auto 16px; display: block; }
.auth h1 { text-align: center; font-size: 28px; margin: 0 0 4px; }
.auth p { text-align: center; color: var(--text-2); margin: 0 0 28px; }
.err { color: var(--crit); font-size: 14px; text-align: center; min-height: 20px; margin: 4px 0 10px; }

.empty { text-align: center; color: var(--text-3); padding: 28px 16px; font-size: 15px; }
.empty svg { margin: 0 auto 10px; width: 36px; height: 36px; }
.hint { font-size: 14px; color: var(--text-2); line-height: 1.5; }
.hint ol { padding-left: 20px; margin: 8px 0; }
.hint li { margin-bottom: 6px; }
.code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; background: var(--surface-2); padding: 10px 12px; border-radius: 12px; word-break: break-all; display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.search { position: relative; margin-bottom: 4px; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); }
.search .input { padding-left: 40px; font-size: 16px; }
.chips { display: flex; gap: 8px; overflow-x: auto; margin: 10px -16px 0; padding: 0 16px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 7px 12px; border-radius: 999px; background: var(--surface); font-size: 14px; color: var(--text-2); box-shadow: var(--shadow); display: inline-flex; gap: 6px; align-items: center; }
.chip.on { background: var(--accent); color: #fff; }
