:root {
  --radius: 22px;
  --blue: #3d7cff;
  --violet: #8b5cf6;
  --teal: #14b8a6;
  --orange: #f59e0b;
  --red: #ef4444;
  --pos: #22c55e;
  --neg: #f43f5e;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Inter, Roboto, sans-serif;
}
html[data-theme="dark"] {
  --bg: #0a0a0f;
  --card: #17171d;
  --card2: #202029;
  --text: #f5f5f7;
  --muted: #8e8e99;
  --line: #2a2a33;
  --hero1: #2b3bff;
  --hero2: #7b2ff7;
  --shadow: none;
}
html[data-theme="light"] {
  --bg: #f2f3f7;
  --card: #ffffff;
  --card2: #f0f1f5;
  --text: #111118;
  --muted: #6e6e7a;
  --line: #e4e5ea;
  --hero1: #3d5cff;
  --hero2: #8a3ffc;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --pos: #16a34a;
  --neg: #e11d48;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); }
body { min-height: 100vh; font-size: 15px; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
a { color: inherit; text-decoration: none; }
.ic { width: 22px; height: 22px; flex: none; }
.pos { color: var(--pos) !important; }
.neg { color: var(--neg) !important; }

/* ---------- каркас ---------- */
#app { max-width: 760px; margin: 0 auto; padding: 0 16px calc(96px + env(safe-area-inset-bottom)); }
.top { display: flex; align-items: center; justify-content: space-between; padding: calc(14px + env(safe-area-inset-top)) 2px 12px; position: sticky; top: 0; z-index: 5; background: linear-gradient(var(--bg) 70%, transparent); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand-name b { background: linear-gradient(135deg, var(--hero1), var(--hero2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.login-box h2 b { background: linear-gradient(135deg, var(--hero1), var(--hero2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 800; background: linear-gradient(135deg, var(--hero1), var(--hero2)); }
.logo.big { width: 64px; height: 64px; font-size: 30px; margin: 0 auto 8px; }
.top-right { display: flex; align-items: center; gap: 10px; }
.mode { font-size: 12px; padding: 4px 10px; border-radius: 99px; background: var(--card2); color: var(--muted); }
.mode.local { color: var(--orange); }
.mode.cloud { color: var(--teal); }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--card); box-shadow: var(--shadow); }
.icon-btn.on { color: var(--blue); }

.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: center; gap: 4px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border-top: 1px solid var(--line); }
.nav a { flex: 1; min-width: 0; max-width: 120px; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10.5px; letter-spacing: -.1px; color: var(--muted); padding: 4px 0; border-radius: 12px; }
.nav a.on { color: var(--blue); }

/* ---------- hero ---------- */
.hero { border-radius: 28px; padding: 26px 20px 20px; margin-bottom: 14px; color: #fff; text-align: center;
  background: radial-gradient(120% 140% at 0% 0%, var(--hero1), transparent 60%), radial-gradient(120% 140% at 100% 100%, var(--hero2), transparent 60%), #2a1f8f; }
.hero.violet { background: radial-gradient(120% 140% at 0% 0%, #7c3aed, transparent 60%), radial-gradient(120% 140% at 100% 100%, #db2777, transparent 60%), #4c1d95; }
.hero.orange { background: radial-gradient(120% 140% at 0% 0%, #f97316, transparent 60%), radial-gradient(120% 140% at 100% 100%, #e11d48, transparent 60%), #9a3412; }
.hero-label { font-size: 13px; opacity: .8; }
.hero-value { font-size: 42px; font-weight: 700; letter-spacing: -1px; margin: 6px 0 4px; }
.hero-sub { font-size: 13px; opacity: .85; }
.hero .pos, .hero .neg { color: #fff !important; background: rgba(255,255,255,.18); padding: 1px 7px; border-radius: 99px; }
.actions { display: flex; justify-content: center; gap: 14px; margin-top: 20px; }
.action { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; color: #fff; flex: 0 1 64px; min-width: 0; }
.action-ic { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,.18); transition: background .15s; }
.action:hover .action-ic { background: rgba(255,255,255,.28); }

/* ---------- карточки ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.card h3 { margin: 0; font-size: 16px; font-weight: 650; }
.page-title { margin: 6px 4px 14px; font-size: 26px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.tile { background: var(--card); border-radius: var(--radius); padding: 14px; cursor: pointer; box-shadow: var(--shadow); }
.tile-label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.tile-label .ic { width: 16px; height: 16px; }
.tile-value { font-size: 22px; font-weight: 700; margin: 8px 0 4px; }
.tile-sub { font-size: 12px; color: var(--muted); line-height: 1.5; }

.stats4 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--card2); border-radius: 16px; padding: 10px 12px; }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 16px; font-weight: 650; margin-top: 4px; }

.list { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-radius: 14px; }
.row.click { cursor: pointer; }
.row.click:hover { background: var(--card2); }
.av { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 15px; flex: none; }
.av .ic { width: 19px; height: 19px; }
.av.blue { background: color-mix(in srgb, var(--blue) 18%, transparent); color: var(--blue); }
.av.violet { background: color-mix(in srgb, var(--violet) 18%, transparent); color: var(--violet); }
.av.teal { background: color-mix(in srgb, var(--teal) 18%, transparent); color: var(--teal); }
.av.orange { background: color-mix(in srgb, var(--orange) 18%, transparent); color: var(--orange); }
.av.red { background: color-mix(in srgb, var(--red) 18%, transparent); color: var(--red); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; }
.row-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-right { font-weight: 650; white-space: nowrap; }
.group-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); padding: 12px 4px 4px; font-weight: 600; }
.empty { color: var(--muted); padding: 14px 4px; font-size: 14px; }
.note { display: flex; gap: 8px; align-items: flex-start; font-size: 12.5px; color: var(--muted); background: var(--card2); border-radius: 14px; padding: 10px 12px; margin-top: 12px; line-height: 1.45; }
.note .ic { width: 16px; height: 16px; margin-top: 1px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 10px; line-height: 1.45; }
.badge { font-size: 10.5px; padding: 1px 6px; border-radius: 99px; background: var(--card2); color: var(--muted); }
.link { color: var(--blue); font-weight: 600; }
.welcome p { color: var(--muted); }

.month-nav { display: flex; align-items: center; justify-content: space-between; margin: 2px 0 12px; }
.month-title { font-size: 20px; font-weight: 700; }

.seg { display: flex; gap: 4px; background: var(--card2); padding: 4px; border-radius: 14px; margin-bottom: 14px; overflow-x: auto; }
.card .seg { margin-bottom: 4px; }
.seg button { flex: 1; padding: 8px 12px; border-radius: 10px; font-size: 14px; color: var(--muted); white-space: nowrap; }
.seg button.on { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.seg.small { margin-bottom: 8px; }

.chart-box { position: relative; height: 230px; }

.goal { cursor: pointer; }
.goal-top { display: flex; justify-content: space-between; margin-bottom: 8px; }
.bar { height: 10px; border-radius: 99px; background: var(--card2); overflow: hidden; margin-bottom: 6px; }
.bar i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--violet), #db2777); }

.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; white-space: nowrap; }
th, td { padding: 9px 8px; text-align: right; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--card2); }

/* ---------- кнопки ---------- */
.btn { padding: 12px 18px; border-radius: 14px; font-weight: 600; }
.btn.primary { background: var(--blue); color: #fff; }
.btn.ghost { background: var(--card2); }
.btn.danger { background: color-mix(in srgb, var(--red) 15%, transparent); color: var(--red); margin-right: auto; }
.btn.wide { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: .6; }
.ver { text-align: center; color: var(--muted); font-size: 12px; margin: 10px 0; }

/* ---------- модальное окно ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: none; }
.modal.open { display: block; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0,0,0,.5); animation: fade .2s; }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 520px; background: var(--card); border-radius: 26px 26px 0 0;
  padding: 10px 18px calc(18px + env(safe-area-inset-bottom)); animation: up .25s ease-out; max-height: 92vh; overflow-y: auto; }
.sheet-grip { width: 40px; height: 5px; border-radius: 99px; background: var(--line); margin: 0 auto 12px; }
.sheet h3 { margin: 0 0 14px; font-size: 20px; }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
input { width: 100%; font: inherit; font-size: 16px; color: var(--text); background: var(--card2); border: 1.5px solid transparent; border-radius: 14px; padding: 12px 14px; outline: none; }
input:focus { border-color: var(--blue); }
input[type="date"] { min-height: 48px; }
.preview { background: var(--card2); border-radius: 14px; padding: 12px 14px; margin-bottom: 12px; color: var(--muted); }
.preview b { color: var(--text); }
.sheet-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
@media (min-width: 700px) {
  .sheet { bottom: auto; top: 50%; transform: translateY(-50%); border-radius: 26px; animation: fade .2s; }
  .sheet-grip { display: none; }
}
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- вход ---------- */
.login { min-height: 100vh; align-items: center; justify-content: center; padding: 20px; }
.login-box { width: 100%; max-width: 360px; background: var(--card); border-radius: 28px; padding: 28px 22px; text-align: center; display: flex; flex-direction: column; gap: 10px; }
.login-box h2 { margin: 0 0 8px; }
.login-err { color: var(--neg); font-size: 13px; min-height: 18px; }

.login-err.ok { color: var(--pos); }
.login-box .seg { margin: 0 0 4px; }
.btn.google { display: flex; align-items: center; justify-content: center; gap: 10px; background: var(--card2); border: 1px solid var(--line); margin-top: 0; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 4px 0; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.privacy { font-size: 11.5px; color: var(--muted); margin: 4px 0 0; line-height: 1.4; }

/* ---------- расходы ---------- */
.hero.red { background: radial-gradient(120% 140% at 0% 0%, #f43f5e, transparent 60%), radial-gradient(120% 140% at 100% 100%, #7c3aed, transparent 60%), #881337; }
.av.emoji { font-size: 19px; background: var(--card2); }
.flow-head { display: flex; justify-content: space-between; align-items: baseline; margin: 4px 0 8px; color: var(--muted); }
.flow-head b { color: var(--text); font-size: 20px; }
.flow-bar { display: flex; height: 14px; border-radius: 99px; overflow: hidden; background: var(--card2); gap: 2px; }
.flow-bar i { display: block; height: 100%; }
.flow-legend { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; margin-top: 12px; }
.flow-item { display: grid; grid-template-columns: 10px 1fr auto; grid-template-rows: auto auto; column-gap: 8px; align-items: center; }
.flow-item .dot { width: 10px; height: 10px; border-radius: 50%; grid-row: 1 / 3; }
.flow-label { font-size: 13px; color: var(--muted); }
.flow-item b { grid-column: 2; font-size: 15px; }
.flow-pct { grid-column: 3; grid-row: 1 / 3; font-size: 13px; font-weight: 600; color: var(--muted); }
.chart-box.donut { height: 210px; margin-bottom: 8px; }
.cats { display: flex; flex-direction: column; }
.cat-row { display: flex; gap: 12px; align-items: center; padding: 9px 4px; border-radius: 14px; cursor: pointer; }
.cat-row:hover, .cat-row.on { background: var(--card2); }
.cat-top { display: flex; justify-content: space-between; gap: 8px; }
.bar.thin { height: 6px; margin: 6px 0 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span { display: inline-block; padding: 7px 11px; border-radius: 99px; background: var(--card2); font-size: 13.5px; cursor: pointer; border: 1.5px solid transparent; }
.chip input:checked + span { border-color: var(--blue); background: color-mix(in srgb, var(--blue) 14%, var(--card2)); font-weight: 600; }

/* ---------- профиль ---------- */
.avatar { width: 40px; height: 40px; border-radius: 50%; display: inline-grid; place-items: center; flex: none; object-fit: cover;
  font-weight: 700; font-size: 14px; color: #fff; background: linear-gradient(135deg, var(--hero1), var(--hero2)); }
.avatar.big { width: 76px; height: 76px; font-size: 26px; }
.avatar-btn { padding: 0; overflow: hidden; }
.avatar-btn .avatar { width: 40px; height: 40px; }
.avatar-btn.on { box-shadow: 0 0 0 2px var(--blue); }
.profile-card { text-align: center; }
.profile-card .avatar.big { margin: 6px auto 10px; display: grid; }
.profile-name { font-size: 20px; font-weight: 700; }
.viewing { display: flex; align-items: center; gap: 10px; background: color-mix(in srgb, var(--orange) 16%, var(--card)); color: var(--text);
  border-radius: 16px; padding: 10px 12px; margin-bottom: 14px; font-size: 13.5px; }
.viewing .ic { color: var(--orange); width: 18px; height: 18px; }
.viewing span { flex: 1; }
.btn.small { padding: 7px 12px; font-size: 13px; background: var(--card); border-radius: 10px; }

/* ---------- уведомления ---------- */
.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; z-index: 60;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 14px; font-size: 14px; transition: .25s; max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--neg); color: #fff; }

@media (max-width: 480px) {
  .stats4 { grid-template-columns: repeat(2, 1fr); }
  .hero-value { font-size: 36px; }
  .actions { gap: 4px; }
  .action { font-size: 11px; }
}
@media (min-width: 900px) {
  .top { gap: 16px; }
  .brand { flex: none; }
  .top-right { flex: none; }
  .nav { position: static; flex: 1; min-width: 0; justify-content: center; gap: 2px; padding: 0; border: 0; background: transparent; backdrop-filter: none; -webkit-backdrop-filter: none; }
  .nav a { flex: none; flex-direction: row; font-size: 14px; padding: 8px 12px; gap: 6px; max-width: none; white-space: nowrap; }
  .nav a .ic { width: 18px; height: 18px; }
  .nav a.on { background: var(--card); box-shadow: var(--shadow); }
  #app { padding-bottom: 40px; max-width: 1180px; }
  #view { max-width: 760px; margin: 0 auto; }
  .top { z-index: 9; }
}
@media (min-width: 900px) and (max-width: 1180px) {
  .brand-name { font-size: 16px; }
  .nav a .ic { display: none; }
  .nav a { padding: 8px 9px; font-size: 13px; }
  .top-right .mode { display: none; }
}
