:root {
  --bg: #f1f7f5; --surface: #ffffff; --surface-2: #e5f0ed; --text: #1b2b29; --muted: #5f7471;
  --line: #d6e6e2; --accent: #2f8f74; --accent-ink: #ffffff; --accent-soft: #dbefe7;
  --sky: #5d9cc9; --sky-soft: #dcecf7;
  --good: #2f9e5a; --bad: #d0453f; --radius: 16px;
  --shadow: 0 1px 2px rgba(31,77,66,.05), 0 6px 20px rgba(31,77,66,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1918; --surface: #162322; --surface-2: #1f2f2d; --text: #e7f2ef; --muted: #93aba6;
    --line: #253735; --accent: #7fd0b2; --accent-ink: #0b1f18; --accent-soft: #1c3a32;
    --sky: #8cc3e8; --sky-soft: #1b3040;
    --good: #6fd38f; --bad: #ff7b74; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1918; --surface: #162322; --surface-2: #1f2f2d; --text: #e7f2ef; --muted: #93aba6;
  --line: #253735; --accent: #7fd0b2; --accent-ink: #0b1f18; --accent-soft: #1c3a32;
  --sky: #8cc3e8; --sky-soft: #1b3040;
  --good: #6fd38f; --bad: #ff7b74; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 20px; margin: 0; letter-spacing: -.01em; }
.disp { display: flex; background: var(--surface-2); border-radius: 10px; padding: 2px; }
.disp button { border: 0; background: none; padding: 5px 10px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.disp button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

main { max-width: 760px; margin: 0 auto; padding: 14px 16px 24px; }
.banner { max-width: 760px; margin: 10px auto 0; padding: 8px 16px; font-size: 13px; color: var(--muted); text-align: center; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { border: 0; background: none; padding: 8px 0 9px; font-size: 11px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tabs .ic { font-size: 19px; line-height: 1; }
.tabs button.on { color: var(--accent); font-weight: 600; }
@media (min-width: 900px) {
  body { padding-bottom: 0; padding-left: 200px; }
  .tabs { top: 0; right: auto; width: 200px; display: flex; flex-direction: column; padding: 70px 10px 0; border-top: 0; border-right: 1px solid var(--line); }
  .tabs button { flex-direction: row; gap: 10px; font-size: 15px; padding: 10px 12px; border-radius: 10px; }
  .tabs button.on { background: var(--accent-soft); }
}

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; border: 1px solid var(--line); }
.card h2 { font-size: 15px; margin: 0 0 10px; }
.label { font-size: 12px; color: var(--muted); margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.label:first-child { margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.amount-row { display: flex; align-items: center; gap: 8px; }
.amount { flex: 1; min-width: 0; font-size: 34px; font-weight: 700; border: 0; background: none; padding: 4px 0; outline: none; letter-spacing: -.02em; }
.amount::placeholder { color: var(--line); }
.preview { font-size: 13px; color: var(--muted); min-height: 18px; margin-top: 2px; }
.preview b { color: var(--text); font-weight: 600; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 7px 12px; border-radius: 8px; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 12px; font-size: 14px;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.chip.on .dot { background: var(--accent-ink) !important; }
.chip small { opacity: .7; font-size: 11px; }

.input, select.input {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 12px; outline: none;
}
.input:focus { border-color: var(--accent); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 140px; }
.sugg { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.sugg button { border: 1px dashed var(--line); background: none; border-radius: 999px; padding: 5px 10px; font-size: 13px; }

.btn { border: 0; border-radius: 12px; padding: 13px 16px; font-weight: 700; background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); width: 100%; font-size: 16px; margin-top: 16px; }
.btn.danger { color: var(--bad); background: none; }
.btn.sm { padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .5; }

/* операции */
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.filters .input:first-child { grid-column: 1 / -1; }
.day { margin: 16px 0 6px; display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); font-weight: 600; }
.txs { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.tx { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--line); width: 100%; text-align: left; background: none; border-left: 0; border-right: 0; border-top: 0; }
.tx:last-child { border-bottom: 0; }
.tx .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.tx .main { flex: 1; min-width: 0; }
.tx .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .s { font-size: 12px; color: var(--muted); }
.tx .a { text-align: right; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tx .a small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.more { display: block; margin: 14px auto; }
.tx.inc .a { color: var(--good); }
.tx.inc .a::before { content: '+'; }
.tx.inc .a small::before { content: '+'; }
.kind-seg { display: flex; margin-bottom: 12px; }
.kind-seg button { flex: 1; }
.btn.primary.income { background: var(--good); }
.inc-kpis { grid-template-columns: 1fr 1fr !important; margin-bottom: 4px; }
.inc-kpis .kpi { background: var(--surface-2); border: 0; }

/* аналитика */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .k { font-size: 12px; color: var(--muted); }
.kpi .v { font-size: 22px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .d { font-size: 12px; }
.up { color: var(--bad); } .down { color: var(--good); }
@media (min-width: 640px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.chart-box { position: relative; height: 240px; }
.cat-list { margin-top: 10px; }
.cat-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 8px 0; border-bottom: 1px solid var(--line); cursor: pointer; background: none; border-left: 0; border-right: 0; border-top: 0; width: 100%; text-align: left; }
.cat-row:last-child { border-bottom: 0; }
.cat-row .n { display: flex; align-items: center; gap: 8px; }
.cat-row .n .dot { width: 10px; height: 10px; border-radius: 50%; }
.cat-row .v { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.cat-row .bar { grid-column: 1 / -1; height: 5px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.cat-row .bar i { display: block; height: 100%; border-radius: 3px; }
.cat-row .p { font-size: 12px; color: var(--muted); font-weight: 400; }
.dates { display: flex; gap: 8px; margin-top: 8px; }
.dates .input { flex: 1; }

/* настройки */
.set-row { display: grid; grid-template-columns: 1fr 90px auto; gap: 6px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.set-row.cat { grid-template-columns: 34px 1fr auto; }
.set-row:last-child { border-bottom: 0; }
.set-row.archived { opacity: .5; }
.set-row input[type=color] { width: 34px; height: 34px; border: 0; padding: 0; background: none; border-radius: 8px; }
.set-row .input { padding: 8px 10px; }
.hint { font-size: 13px; color: var(--muted); margin: 6px 0 10px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + env(safe-area-inset-bottom)); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 20; font-size: 14px; max-width: calc(100% - 32px); }
.modal { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; }
.modal > div { background: var(--bg); width: 100%; max-width: 760px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
@media (min-width: 700px) { .modal { align-items: center; } .modal > div { border-radius: 18px; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.x { border: 0; background: var(--surface-2); width: 32px; height: 32px; border-radius: 50%; font-size: 18px; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.conv { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; margin-top: 10px; }
.conv-f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.with-unit { display: flex; align-items: center; gap: 6px; }
.with-unit .input { padding: 8px 10px; }
.with-unit b { color: var(--text); font-weight: 600; min-width: 14px; }
.conv .small { margin-top: 8px; }
.linkbtn { border: 0; background: none; color: var(--accent); padding: 6px 0 0; font-size: 13px; }
.newbox { background: var(--surface-2); border-radius: 12px; padding: 10px; margin-top: 8px; }
.newbox input[type=color] { width: 38px; height: 38px; border: 0; padding: 0; background: none; border-radius: 8px; }
.chip.add { border-style: dashed; color: var(--muted); background: none; }
.btn.danger.sm { padding: 8px 10px; }
.set-row .name-cell { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.set-row .name-cell small { font-size: 11px; padding-left: 2px; }
.add-row input[type=color] { width: 34px; height: 34px; border: 0; padding: 0; background: none; border-radius: 8px; }
.add-row { margin-top: 10px; }
#rates-box a { color: var(--accent); }
@media (max-width: 520px) {
  .set-row:not(.cat) { grid-template-columns: 1fr 84px auto; }
}

.btn.primary.transfer { background: var(--sky); color: #fff; }
.tx .tr-ic { width: 18px; height: 18px; display: grid; place-items: center; font-size: 12px; background: var(--surface-2); color: var(--muted); }

/* прогноз */
.notice { background: var(--accent-soft); border-color: transparent; font-size: 14px; }
.kpi.gap.bad { background: var(--bad); border-color: var(--bad); color: #fff; }
.kpi.gap.bad .k, .kpi.gap.bad .d { color: rgba(255,255,255,.85); }
.kpi.gap.ok .v { color: var(--good); }
.ev-list { display: flex; flex-direction: column; }
.ev { display: grid; grid-template-columns: 50px 1fr auto 34px; gap: 8px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); }
.ev:last-child { border-bottom: 0; }
.ev-d { font-size: 13px; color: var(--muted); }
.ev-t { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.ev-t small, .ev-a small, .plan .s { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.ev-a { text-align: right; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ev.neg .ev-a small { color: var(--bad); font-weight: 600; }
.pos { color: var(--good); }
.ev-done { padding: 0; width: 34px; height: 34px; font-size: 15px; border-radius: 50%; }
.plans { display: flex; flex-direction: column; }
.plan { display: flex; align-items: center; gap: 10px; padding: 10px 0; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; width: 100%; }
.plan:last-child { border-bottom: 0; }
.plan.off { opacity: .45; }
.plan .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.plan .main { flex: 1; min-width: 0; }
.plan .a { font-weight: 600; white-space: nowrap; }
.suggest { display: flex; gap: 10px; align-items: center; background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; }
.suggest > div { flex: 1; }
.bal-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.bal-row > span:first-child { display: flex; flex-direction: column; }
.bal-row small { font-size: 11px; }
.bal-row .with-unit { max-width: 170px; }
.bal-row .input { text-align: right; }
.bal-total { display: flex; justify-content: space-between; padding-top: 10px; font-size: 16px; }

/* ---------- вход и регистрация ---------- */
body.auth-on { overflow: hidden; }
.auth {
  position: fixed; inset: 0; z-index: 40; overflow: auto; display: flex; align-items: center; justify-content: center;
  padding: calc(24px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, #cfe6f6 0%, #e2f1f4 45%, #def3e9 75%, #cdebdc 100%);
}
@media (prefers-color-scheme: dark) { .auth { background: linear-gradient(180deg, #13263a 0%, #142a2c 55%, #11261f 100%); } }
.clouds { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.cloud { position: absolute; left: 0; color: #fff; opacity: .9; animation: float-by linear infinite; will-change: transform; }
.cloud svg { display: block; width: 100%; height: auto; filter: drop-shadow(0 8px 18px rgba(80,130,150,.12)); }
@media (prefers-color-scheme: dark) { .cloud { color: #2a4456; opacity: .55; } }
/* облака проплывают слева направо через весь экран; отрицательная задержка — чтобы при открытии они уже были в пути */
.cloud.c1 { width: 260px; top: 7%;  animation-duration: 60s; animation-delay: -12s; }
.cloud.c2 { width: 170px; top: 24%; animation-duration: 45s; animation-delay: -30s; opacity: .75; }
.cloud.c3 { width: 340px; top: 68%; animation-duration: 80s; animation-delay: -55s; opacity: .8; }
.cloud.c4 { width: 140px; top: 50%; animation-duration: 38s; animation-delay: -8s; opacity: .7; }
.cloud.c5 { width: 210px; top: 85%; animation-duration: 52s; animation-delay: -40s; opacity: .65; }
.cloud.c6 { width: 120px; top: 14%; animation-duration: 34s; animation-delay: -20s; opacity: .6; }
@keyframes float-by { from { transform: translateX(-380px); } to { transform: translateX(calc(100vw + 40px)); } }
@media (prefers-reduced-motion: reduce) { .cloud { animation: none; } }
.auth-card {
  position: relative; width: 100%; max-width: 380px; background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent); border-radius: 24px;
  box-shadow: 0 20px 50px rgba(40,90,110,.14); padding: 28px 22px 22px; text-align: center;
}
.auth-logo { width: 60px; height: 60px; border-radius: 16px; display: block; margin: 0 auto 12px; box-shadow: 0 6px 16px rgba(47,143,116,.25); }
.auth-card h1 { font-size: 24px; margin: 0; letter-spacing: -.02em; }
.auth-sub { margin: 6px 0 18px; color: var(--muted); font-size: 14px; }
.auth-seg { display: flex; width: 100%; margin-bottom: 16px; }
.auth-seg button { flex: 1; padding: 9px 12px; }
.auth-field { display: block; text-align: left; margin-top: 12px; }
.auth-field > span:first-child { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 6px 2px; }
.auth-field .input { width: 100%; }
.pw-wrap { position: relative; display: block; }
.pw-wrap .input { padding-right: 92px; }
.pw-eye { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: none;
  color: var(--accent); font-size: 13px; font-weight: 600; padding: 6px 8px; border-radius: 8px; }
.auth-err { min-height: 20px; margin-top: 10px; color: var(--bad); font-size: 14px; text-align: left; }
.auth-card .btn.primary { margin-top: 6px; background: linear-gradient(135deg, var(--accent), var(--sky)); }
.auth-note { margin: 12px 0 0; font-size: 12px; color: var(--muted); }
.account-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.account-card h2 { margin-bottom: 4px; }

/* ---------- быстрый ввод ---------- */
.quick { display: flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 6px 6px 6px 14px; margin-bottom: 12px; box-shadow: var(--shadow); }
.quick:focus-within { border-color: var(--accent); }
.quick-in { flex: 1; min-width: 0; border: 0; background: none; outline: none; padding: 8px 0; font-size: 16px; }
.quick-mic, .quick-go { flex: none; width: 42px; height: 42px; border-radius: 12px; border: 0; display: grid; place-items: center; }
.quick-mic { background: linear-gradient(135deg, var(--accent), var(--sky)); color: #fff; }
.quick-mic.on { animation: mic-pulse 1.2s ease-in-out infinite; }
@keyframes mic-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; } }
.quick-go { background: var(--surface-2); color: var(--muted); }
.quick-live { margin: -4px 4px 12px; font-size: 14px; color: var(--accent); font-weight: 600; }
.q-heard { margin: -2px 0 10px; color: var(--muted); font-size: 14px; }
.q-kind { margin-bottom: 10px; }
.q-main .input { margin-top: 6px; }
.q-need { color: var(--bad); text-transform: none; letter-spacing: 0; }
.q-dinp { width: auto; padding: 6px 10px; border-radius: 999px; font-size: 14px; }
.q-more { display: block; margin: 12px auto 0; }
