:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #16181d;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #0f766e;
  --accent-soft: #ccfbf1;
  --neg: #b91c1c;
  --pos: #15803d;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .06);
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #20242c;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --line: #2a2f38;
    --accent: #2dd4bf;
    --accent-soft: #134e4a;
    --neg: #f87171;
    --pos: #4ade80;
    --danger: #f87171;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 18px; margin: 0; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 20px 16px 8px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pad { padding: 12px 16px; }
.error { color: var(--danger); margin: 8px 0; }
.boot { padding: 40vh 0; text-align: center; color: var(--muted); }

/* раскладка: снизу меню на телефоне, слева — на компьютере */
.layout { min-height: 100vh; }
main { max-width: 760px; margin: 0 auto; padding-bottom: calc(var(--nav-h) + 96px + env(safe-area-inset-bottom)); }
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--muted); text-decoration: none; }
.nav a.on { color: var(--accent); }
.nav-icon { font-size: 20px; line-height: 1; }
.brand { display: none; }
@media (min-width: 900px) {
  .nav { top: 0; right: auto; width: 220px; height: auto; flex-direction: column; justify-content: flex-start; padding: 20px 12px; gap: 4px; border-top: 0; border-right: 1px solid var(--line); }
  .nav a { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; font-size: 15px; padding: 10px 12px; border-radius: 10px; }
  .nav a.on { background: var(--accent-soft); }
  .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 0 12px 20px; }
  main { margin-left: max(240px, calc(50vw - 380px + 110px)); padding-bottom: 96px; }
}

.view-head { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 14px 16px 10px; display: flex; flex-direction: column; gap: 10px; }
.month-nav { display: flex; align-items: center; justify-content: space-between; font-weight: 600; font-size: 17px; }
.summary { display: flex; gap: 12px; }
.summary > div { flex: 1; background: var(--surface); border-radius: var(--radius); padding: 10px 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 2px; font-size: 18px; font-weight: 600; }
.summary .muted { font-size: 12px; font-weight: 500; }
.filter { font-size: 14px; }
.empty { text-align: center; color: var(--muted); padding: 48px 24px; }

.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.money small { font-size: .75em; color: var(--muted); }
.money.neg { color: var(--neg); }
.money.pos { color: var(--pos); }
.money.big { font-size: 20px; font-weight: 600; }
.totals { display: inline-flex; flex-direction: column; align-items: inherit; }
.totals .money + .money { font-size: .8em; }

.icon-btn { background: none; border: 0; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; font-size: 20px; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-size: 13px; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 16px; cursor: pointer; font-weight: 500; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; flex: 1; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #042f2e; } }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .6; }

/* операции */
.day { margin: 0 12px 12px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.day-head { display: flex; justify-content: space-between; padding: 10px 14px 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.tx { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 14px; background: none; border: 0; border-top: 1px solid var(--line); text-align: left; cursor: pointer; }
.tx:first-of-type { border-top: 0; }
.tx:hover { background: var(--surface-2); }
.tx-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tx-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { flex: none; width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: #fff; font-weight: 600; font-size: 14px; }
.dot.transfer { background: var(--muted); }

.fab {
  position: fixed; right: 20px; bottom: calc(var(--nav-h) + 20px + env(safe-area-inset-bottom)); z-index: 11;
  width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 32px; line-height: 1;
  box-shadow: 0 6px 20px rgba(15, 118, 110, .4); cursor: pointer;
}
@media (min-width: 900px) { .fab { bottom: 32px; right: 32px; } }

/* окно-шторка */
.overlay { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .4); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 20px 20px 0 0; padding: 8px 16px calc(16px + env(safe-area-inset-bottom)); }
@media (min-width: 700px) { .overlay { align-items: center; } .sheet { border-radius: 20px; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 0 10px; }

.tx-form { display: flex; flex-direction: column; gap: 12px; }
.tx-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); flex: 1; min-width: 0; }
.tx-form input, .tx-form select, .inline-form input, .panel select {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-size: 15px; color: var(--text); width: 100%;
}
.tx-form label.check, label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
label.check input { width: auto; }
.row2 { display: flex; gap: 10px; }
@media (max-width: 480px) { .row2 { flex-direction: column; } }
.amount { position: relative; }
.amount input { font-size: 34px !important; font-weight: 600; text-align: center; padding: 14px 56px !important; }
.amount span { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); font-size: 15px; color: var(--muted); }
.amount.expense input { color: var(--neg); }
.amount.income input { color: var(--pos); }

.segmented { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.segmented button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 8px; cursor: pointer; font-weight: 500; color: var(--muted); }
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented button.on.expense { color: var(--neg); }
.segmented button.on.income { color: var(--pos); }
.segmented.small { align-self: center; min-width: 220px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 12px 4px 4px; cursor: pointer; font-size: 14px; }
.chip .dot { width: 24px; height: 24px; font-size: 11px; }
.chip.on { border-color: var(--accent); background: var(--accent-soft); }

.lines, .receipt { background: var(--surface-2); border-radius: 10px; padding: 8px 12px; }
.lines .label { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.line { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 14px; }
.line > span:first-of-type, .line > span:nth-child(2) { flex: 1; min-width: 0; }
.line .dot { width: 22px; height: 22px; font-size: 10px; }
.receipt summary { cursor: pointer; font-size: 14px; padding: 2px 0; }
.actions { display: flex; gap: 10px; margin-top: 4px; }

/* счета */
.cards { display: grid; gap: 10px; padding: 0 12px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.card { display: flex; align-items: flex-start; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.archived { opacity: .55; }
.card-main { flex: 1; display: flex; flex-direction: column; gap: 4px; padding: 14px; background: none; border: 0; text-align: left; cursor: pointer; }
.card-title { font-weight: 600; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* статистика */
.bars { margin: 0 12px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px 0; }
.bar { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; width: 100%; padding: 10px 14px; background: none; border: 0; text-align: left; cursor: pointer; }
.bar:disabled { cursor: default; }
.bar:not(:disabled):hover { background: var(--surface-2); }
.bar-label { display: flex; align-items: center; gap: 8px; min-width: 0; }
.bar-label .dot { width: 22px; height: 22px; font-size: 10px; }
.bar-track { grid-column: 1 / -1; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 3px; }

/* настройки */
.panel { margin: 0 12px 12px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px 14px 14px; }
.panel h3 { margin: 12px 0 8px; }
.panel label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); margin-top: 8px; }
.cat-list { display: flex; flex-direction: column; }
.cat { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.cat:first-child { border-top: 0; }
.cat > span:nth-child(2) { flex: 1; }
.cat .dot { width: 26px; height: 26px; font-size: 12px; }
.cat.archived { opacity: .5; }
.cat-actions { display: flex; gap: 12px; }
.inline-form { display: flex; gap: 8px; margin-top: 10px; }

/* подкатегории */
.picker { display: flex; flex-direction: column; gap: 8px; }
.chips.sub { padding: 8px 10px; border-radius: 12px; background: var(--surface-2); }
.chips.sub .chip { padding: 4px 12px; }
.bar-group.open { background: var(--surface-2); }
.sub-bars { padding: 0 0 6px 28px; display: flex; flex-direction: column; }
.bar.sub { padding: 6px 14px; font-size: 14px; }
.bar.sub .bar-track { height: 4px; }
.cat.sub { padding-left: 18px; border-top: 0; }
.cat .tree { width: 26px; text-align: center; color: var(--muted); }

/* быстрый ввод */
.quick { display: flex; flex-direction: column; gap: 4px; }
.quick .inline-form { margin-top: 0; }
.quick p { margin: 0; }
.btn.mic { min-width: 48px; padding: 10px 12px; }
.btn.mic.on { background: var(--danger); border-color: var(--danger); color: #fff; font-variant-numeric: tabular-nums; }
.draft { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); border-left: 4px solid var(--neg); }
.draft.income { border-left-color: var(--pos); }
.draft input, .draft select { background: var(--surface) !important; }
.draft .note { flex: 1; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; background: var(--surface); color: var(--text); }

/* чек, очередь без сети */
.quick-receipt { display: flex; gap: 8px; flex-wrap: wrap; }
.quick-receipt .chip { padding: 6px 14px; }
.scanner { position: relative; border-radius: 14px; overflow: hidden; background: #000; aspect-ratio: 1; max-height: 60vh; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner-frame { position: absolute; inset: 18%; border: 3px solid rgba(255, 255, 255, .9); border-radius: 18px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .35); }
.receipt-result { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.receipt-result p { margin: 0; }
.center { text-align: center; }
.hidden { display: none; }
.btn.wide { width: 100%; }
.day.pending { border: 1px dashed var(--muted); box-shadow: none; }
.tx-sub.error { color: var(--danger); }
.offline-banner { margin: 10px 12px 0; padding: 10px 14px; border-radius: 10px; background: #fef3c7; color: #78350f; font-size: 14px; }
@media (prefers-color-scheme: dark) { .offline-banner { background: #422006; color: #fde68a; } }

.login { max-width: 420px; margin: 18vh auto 0; padding: 24px; text-align: center; }
.login h1 { margin: 16px 0 8px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 90px); z-index: 30; background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 14px; }
