/* Тема: светлая и тёмная; выбирается по настройке Telegram/системы */
:root {
  /* Палитра: #9BBB8A #76A37A #2C6459 #154C46 #062D34 #F8F5EE */
  --bg: #F8F5EE; --surface: #FFFFFF; --ink: #062D34; --muted: #5B706C; --line: #E4E0D3;
  --accent: #2C6459; --on-accent: #F8F5EE; --tint: #E5EDDD;
  --hero: #154C46; --on-hero: #F8F5EE; --sage: #9BBB8A;
  --pos: #2C6459; --neg: #B23A25; --warn: #8A5A00; --on-neg: #F8F5EE;
  --pos-bg: #DDEBD5; --neg-bg: #F6E1DA; --warn-bg: #F5E8C8;
  --radius: 16px; --tab-h: 62px;
  --num: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
:root[data-theme="dark"] {
  --bg: #062D34; --surface: #0D3A40; --ink: #F8F5EE; --muted: #9DB5AE; --line: #1B4A4C;
  --accent: #9BBB8A; --on-accent: #062D34; --tint: #154C46;
  --hero: #154C46; --on-hero: #F8F5EE; --sage: #9BBB8A;
  --pos: #9BBB8A; --neg: #FF8F78; --warn: #E6B04A; --on-neg: #062D34;
  --pos-bg: #174A40; --neg-bg: #3E2320; --warn-bg: #3A2E12;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); }
body { margin: 0; font: 16px/1.4 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
.num { font-family: var(--num); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

#app { max-width: 560px; margin: 0 auto; padding: 0 16px calc(var(--tab-h) + 96px + env(safe-area-inset-bottom)); min-height: 100vh; }

/* шапка */
.top { display: flex; align-items: center; gap: 10px; padding: calc(14px + env(safe-area-inset-top)) 0 10px; }
.top h1 { font-size: 19px; margin: 0; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who { display: flex; }
.who span { width: 28px; height: 28px; border-radius: 50%; background: var(--tint); color: var(--accent); font-size: 13px; font-weight: 700; display: grid; place-items: center; border: 2px solid var(--bg); margin-left: -6px; }
.who span:first-child { margin-left: 0; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: var(--muted); }
.icon-btn:active { background: var(--tint); }
svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* главный блок: сколько можно тратить в день */
.hero { background: var(--hero); color: var(--on-hero); border-radius: 24px; padding: 20px 20px 18px; margin: 4px 0 22px; }
.hero .lead { font-size: 15px; opacity: .9; margin: 0; }
.hero .big { font-size: 46px; line-height: 1.1; font-weight: 800; margin: 4px 0 2px; }
.hero .sub { font-size: 14px; opacity: .85; margin: 0 0 16px; }
.hero.bad { background: var(--neg); color: var(--on-neg); }
.days { display: flex; gap: 2px; height: 22px; align-items: flex-end; margin-bottom: 16px; }
.days i { flex: 1; background: currentColor; opacity: .22; border-radius: 2px; height: 55%; }
.hero:not(.bad) .days i.past { background: var(--sage); opacity: 1; }
.hero.bad .days i.past { opacity: .85; }
.days i.now { opacity: 1; height: 100%; }
.hero-figs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.hero-figs div { min-width: 0; }
.hero-figs small { display: block; font-size: 12px; opacity: .8; }
.hero-figs b { font-size: 16px; font-weight: 700; white-space: nowrap; }

/* разделы без карточек: заголовок + строки с линиями */
.sec { margin: 0 0 26px; }
.sec-h { display: flex; align-items: baseline; justify-content: space-between; margin: 0 0 6px; }
.sec-h h2 { font-size: 17px; margin: 0; font-weight: 700; }
.link { color: var(--accent); font-size: 14px; font-weight: 600; padding: 6px 0; }
.rows { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; width: 100%; text-align: left; min-height: 54px; }
.row + .row { border-top: 1px solid var(--line); }
button.row:active { background: var(--tint); }
.row .main { flex: 1; min-width: 0; }
.row .t { font-weight: 600; overflow-wrap: anywhere; }
.row .s { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .amt { font-weight: 700; white-space: nowrap; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .muted { color: var(--muted); }
.day-h { font-size: 13px; color: var(--muted); margin: 18px 4px 6px; font-weight: 600; }

/* полоски категорий */
.cat { padding: 11px 14px; }
.cat + .cat { border-top: 1px solid var(--line); }
.cat-top { display: flex; justify-content: space-between; gap: 8px; font-size: 15px; }
.cat-top span:first-child { font-weight: 600; }
.bar { height: 6px; border-radius: 3px; background: var(--tint); margin-top: 7px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bar i.over { background: var(--neg); }
.cat small { color: var(--muted); font-size: 12px; }

/* статусы платежей */
.pill { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 99px; white-space: nowrap; }
.pill.paid { background: var(--pos-bg); color: var(--pos); }
.pill.soon { background: var(--warn-bg); color: var(--warn); }
.pill.overdue { background: var(--neg-bg); color: var(--neg); }
.pill.upcoming { background: var(--tint); color: var(--muted); }
.btn-s { background: var(--accent); color: var(--on-accent); font-weight: 700; font-size: 14px; padding: 8px 14px; border-radius: 12px; white-space: nowrap; }

/* задачи */
.add-row { display: flex; gap: 8px; margin-bottom: 8px; }
.field { width: 100%; background: var(--surface); border: 1.5px solid transparent; border-radius: 14px; padding: 13px 14px; outline: none; min-height: 48px; }
.field:focus { border-color: var(--accent); }
.field::placeholder { color: var(--muted); opacity: .8; }
.btn { background: var(--accent); color: var(--on-accent); font-weight: 700; border-radius: 14px; padding: 13px 18px; min-height: 48px; }
.btn.wide { width: 100%; }
.btn.ghost { background: var(--tint); color: var(--accent); }
.btn.danger { background: var(--neg-bg); color: var(--neg); }
.btn[disabled] { opacity: .5; }
.seg { display: inline-flex; background: var(--surface); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { padding: 7px 14px; border-radius: 10px; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.seg.full { display: flex; } .seg.full button { flex: 1; padding: 10px; }
.task-opts { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
select.field { width: auto; min-height: 38px; padding: 7px 12px; font-size: 14px; }
.check { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--muted); flex: none; display: grid; place-items: center; color: transparent; }
.check.on { background: var(--pos); border-color: var(--pos); color: var(--on-accent); }
.done .t { text-decoration: line-through; color: var(--muted); }
.x { color: var(--muted); width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; flex: none; }

/* ИИ и подсказки */
.saving-big { margin: 4px 0 18px; }
.saving-big .num { font-size: 34px; font-weight: 800; color: var(--pos); line-height: 1.15; }
.saving-big p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.tip { padding: 13px 14px; display: flex; gap: 12px; }
.tip + .tip { border-top: 1px solid var(--line); }
.dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; flex: none; }
.dot-warn { background: var(--neg); } .dot-tip { background: var(--warn); } .dot-good { background: var(--pos); }
.tip h3 { margin: 0 0 2px; font-size: 15px; }
.tip p { margin: 0; font-size: 14px; color: var(--muted); }
.tip .sv { margin-top: 4px; font-size: 13px; font-weight: 700; color: var(--pos); }
.ai-box { background: var(--surface); border-radius: var(--radius); padding: 16px; }
.ai-text p { margin: 0 0 10px; } .ai-text ul { margin: 0 0 10px; padding-left: 20px; } .ai-text li { margin-bottom: 4px; }
.ai-text > :last-child { margin-bottom: 0; }
.ai-meta { font-size: 12px; color: var(--muted); margin: 10px 0 0; }
.note { background: var(--tint); border-radius: 14px; padding: 12px 14px; font-size: 14px; color: var(--ink); }
.spin { display: inline-block; width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: sp .8s linear infinite; vertical-align: -3px; margin-right: 8px; }
@keyframes sp { to { transform: rotate(360deg); } }

/* пустые состояния */
.empty { text-align: center; padding: 34px 20px; color: var(--muted); }
.empty b { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }
.empty .btn { margin-top: 14px; }

/* месяц */
.month-nav { display: flex; align-items: center; justify-content: space-between; margin: 0 0 6px; }
.month-nav b { font-size: 17px; }
.month-nav b::first-letter { text-transform: uppercase; }
.totals { display: flex; gap: 18px; margin: 0 4px 4px; font-size: 14px; color: var(--muted); }
.totals b { font-family: var(--num); font-size: 15px; }

/* нижняя панель */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); display: flex; justify-content: center; padding-bottom: env(safe-area-inset-bottom); z-index: 10; }
.tabbar nav { display: flex; width: 100%; max-width: 560px; }
.tab { flex: 1; height: var(--tab-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; color: var(--muted); font-weight: 600; position: relative; }
.tab[aria-current="page"] { color: var(--accent); }
.tab .badge { position: absolute; top: 8px; left: calc(50% + 6px); background: var(--neg); color: var(--on-neg); font-size: 10px; min-width: 16px; height: 16px; border-radius: 8px; display: grid; place-items: center; padding: 0 4px; }
.fab { position: fixed; right: max(16px, calc(50% - 264px)); bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom)); width: 58px; height: 58px; border-radius: 20px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; box-shadow: 0 6px 18px rgba(6, 45, 52, .32); z-index: 9; }
.fab svg { width: 28px; height: 28px; stroke-width: 2.4; }

/* нижние шторки */
.scrim { position: fixed; inset: 0; background: rgba(6, 45, 52, .5); z-index: 20; animation: fade .18s ease-out; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; max-height: 92vh; overflow-y: auto; background: var(--bg); border-radius: 24px 24px 0 0; padding: 10px 16px calc(18px + env(safe-area-inset-bottom)); z-index: 21; max-width: 560px; margin: 0 auto; animation: up .22s ease-out; }
.grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { font-size: 19px; margin: 0 0 14px; }
.sheet label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; font-weight: 600; }
.amount { margin-top: 12px; font-size: 40px; font-weight: 800; text-align: center; padding: 14px; font-family: var(--num); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--surface); padding: 8px 13px; border-radius: 99px; font-size: 14px; font-weight: 600; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.sheet .gap { height: 14px; }
.stack { display: grid; gap: 10px; margin-top: 18px; }
.lim { display: flex; align-items: center; gap: 10px; padding: 8px 14px; }
.lim + .lim { border-top: 1px solid var(--line); }
.lim span { flex: 1; font-size: 15px; }
.lim input { width: 110px; text-align: right; padding: 9px 12px; min-height: 40px; background: var(--bg); }
.switch { width: 50px; height: 30px; border-radius: 15px; background: var(--line); position: relative; flex: none; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #F8F5EE; transition: transform .15s; }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }
.invite { word-break: break-all; font-size: 13px; color: var(--muted); }

/* уведомление */
#toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + 86px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 14px; font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: .2s; z-index: 40; display: flex; gap: 14px; align-items: center; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast button { color: var(--sage); font-weight: 800; }
:root[data-theme="dark"] #toast button { color: #2C6459; }

/* вход */
.welcome { padding-top: calc(48px + env(safe-area-inset-top)); }
.welcome h1 { font-size: 30px; line-height: 1.15; margin: 0 0 10px; }
.welcome p { color: var(--muted); margin: 0 0 24px; }
.welcome .stack { margin-top: 0; }
.or { text-align: center; color: var(--muted); font-size: 14px; margin: 4px 0; }
.err { color: var(--neg); font-size: 14px; margin: 8px 0 0; }

@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
