:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #8e8e93;
  --line: #e5e5ea;
  --accent: #007aff;
  --expense: #e5484d;
  --income: #1f9d55;
  --transfer: #6e56cf;
  --tile: #f2f2f7;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f2f2f7;
    --muted: #8e8e93;
    --line: #2c2c2e;
    --accent: #0a84ff;
    --expense: #ff6369;
    --income: #3dd68c;
    --transfer: #9e8cfc;
    --tile: #2c2c2e;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 0 calc(64px + env(safe-area-inset-bottom));
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-align: inherit; }
input { font: inherit; color: inherit; }
small { display: block; color: var(--muted); font-size: 13px; }

.screen { max-width: 640px; margin: 0 auto; padding: 12px 16px 24px; }

/* ---------- нижнее меню ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  padding: 6px 0 calc(6px + 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: .5px solid var(--line);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px;
  font-size: 11px; color: var(--muted); text-decoration: none; padding: 2px 0;
}
.tabbar a.active { color: var(--accent); font-weight: 600; }
.tab-icon { font-size: 22px; filter: grayscale(1); opacity: .6; }
.tabbar a.active .tab-icon { filter: none; opacity: 1; }

/* ---------- главная ---------- */
.hero { text-align: center; padding: 12px 0 18px; }
.hero-label { color: var(--muted); font-size: 15px; }
.hero-amount { font-size: 38px; font-weight: 700; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.hero-note { color: var(--muted); font-size: 13px; margin-top: 2px; }

.quick-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.quick {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 14px 6px; border-radius: 16px; background: var(--card); box-shadow: var(--shadow);
  font-size: 15px; font-weight: 600; text-align: center;
}
.quick b { font-size: 28px; line-height: 1; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: #fff; }
.quick.expense b { background: var(--expense); }
.quick.income b { background: var(--income); }
.quick.transfer b { background: var(--transfer); font-size: 22px; }
.quick:active { transform: scale(.97); }

.section-title { font-size: 20px; margin: 22px 4px 8px; }

/* ---------- карточки и списки ---------- */
.card { background: var(--card); border-radius: 14px; margin-bottom: 14px; box-shadow: var(--shadow); overflow: hidden; }
.card:not(.list) { padding: 4px 0; }
.card-title { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; padding: 12px 16px 4px; }
.list-row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: 54px; padding: 8px 16px; position: relative;
}
.list-row + .list-row::before, .card-title + .list-row::before { content: ''; position: absolute; top: 0; left: 60px; right: 0; border-top: .5px solid var(--line); }
.card-title + .list-row::before { display: none; }
.list-row:active:not(.static) { background: var(--tile); }
.list-row.selected { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.list-row.indent { padding-left: 32px; }
.list-row.archived { opacity: .5; }
.list-row.more { justify-content: center; color: var(--accent); font-size: 15px; min-height: 44px; }
.list-icon { font-size: 24px; width: 32px; text-align: center; flex: none; }
.list-icon.small { font-size: 20px; }
.list-main { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.list-main small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-amount { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; font-weight: 500; }
.list-amount small { text-align: right; }
.list-amount.expense, b.expense { color: var(--expense); }
.list-amount.income, b.income { color: var(--income); }
.list-amount.transfer { color: var(--transfer); }
.muted { color: var(--muted); }
.chevron { color: var(--muted); font-size: 22px; transition: transform .15s; }
.chevron.open { transform: rotate(90deg); }

.welcome { text-align: center; padding: 18vh 24px 0; }
.welcome-icon {
  width: 88px; height: 88px; margin: 0 auto 16px; border-radius: 22px; display: grid; place-items: center;
  font-size: 52px; font-weight: 600; color: #fff; background: linear-gradient(#34c778, #148c5a);
}
.welcome h1 { margin: 0 0 8px; }
.welcome p { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }
.note { color: var(--muted); font-size: 13px; padding: 0 16px; margin: -4px 0 16px; }
.footer-note { color: var(--muted); font-size: 13px; text-align: center; }
.total-line { text-align: right; padding: 0 8px; font-weight: 600; }

/* ---------- отчёт и история ---------- */
.month-switch { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.month-switch button { font-size: 28px; width: 48px; height: 44px; color: var(--accent); text-align: center; }
.month-switch .month-title { font-size: 20px; font-weight: 600; flex: 1; text-align: center; color: var(--text); width: auto; }
.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.summary div { background: var(--card); border-radius: 14px; padding: 10px 8px; text-align: center; box-shadow: var(--shadow); min-width: 0; }
.summary div.wide { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: baseline; padding: 10px 16px; }
.summary div.wide small { font-size: 15px; }
.summary b { font-size: 17px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar { display: block; height: 5px; background: var(--tile); border-radius: 3px; margin-top: 5px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 3px; background: var(--expense); }
.bar i.income { background: var(--income); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip { background: var(--card); border-radius: 16px; padding: 6px 12px; font-size: 15px; box-shadow: var(--shadow); }
.chip span { color: var(--muted); }

/* ---------- переключатель ---------- */
.segmented { display: flex; background: var(--tile); border-radius: 10px; padding: 2px; margin: 0 0 14px; }
.card .segmented { margin: 6px 16px 10px; }
.segmented button { flex: 1; text-align: center; padding: 8px 4px; border-radius: 8px; font-size: 15px; font-weight: 500; color: var(--muted); }
.segmented button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.segmented button.active.expense { color: var(--expense); }
.segmented button.active.income { color: var(--income); }
.segmented button.active.transfer { color: var(--transfer); }

/* ---------- листы (модальные экраны) ---------- */
.sheet-layer { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .3); animation: fade .2s; }
.sheet {
  position: absolute; inset: 0; background: var(--bg); display: flex; flex-direction: column;
  padding-top: env(safe-area-inset-top); animation: slide-up .25s cubic-bezier(.2, .8, .2, 1);
}
.sheet-layer.closing { animation: fade .2s reverse forwards; }
.sheet.closing { animation: slide-up .22s reverse forwards; }
@keyframes fade { from { opacity: 0; } }
@keyframes slide-up { from { transform: translateY(100%); } }
.sheet-content { display: flex; flex-direction: column; height: 100%; }
.sheet-header {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 10px 16px; border-bottom: .5px solid var(--line); background: var(--card);
}
.sheet-header h2 { margin: 0; font-size: 17px; font-weight: 600; text-align: center; }
.sheet-header-side.right { text-align: right; }
.sheet-body {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
  max-width: 640px; width: 100%; margin: 0 auto;
}
.link-button { color: var(--accent); font-size: 17px; padding: 6px 0; }
.link-button.bold { font-weight: 600; }
.card > .link-button { display: block; padding: 8px 16px 12px; font-size: 15px; }

/* ---------- форма операции ---------- */
.amount-wrap { display: flex; align-items: baseline; justify-content: center; gap: 6px; margin: 4px 0 16px; }
.amount-input {
  width: 100%; max-width: 280px; border: 0; background: none; outline: none; text-align: right;
  font-size: 44px; font-weight: 700; font-variant-numeric: tabular-nums; padding: 0;
}
.amount-input.expense { color: var(--expense); }
.amount-input.income { color: var(--income); }
.amount-input.transfer { color: var(--transfer); }
.amount-currency { font-size: 32px; font-weight: 600; color: var(--muted); min-width: 40px; }

.row-button { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 52px; padding: 8px 16px; }
.row-button + .row-button, .row-button + .field, .field + .field { border-top: .5px solid var(--line); }
.row-label { color: var(--muted); min-width: 70px; }
.row-value { flex: 1; text-align: right; font-weight: 500; }
.row-value small { text-align: right; }

.field { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 6px 16px; }
.field > span { color: var(--muted); white-space: nowrap; }
.field input[type=text], .field input[type=date], .field-input input {
  flex: 1; min-width: 0; border: 0; background: none; outline: none; text-align: right; font-size: 17px; padding: 6px 0;
}
.field input[type=date] { -webkit-appearance: none; appearance: none; min-height: 34px; }
.field-input { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; }
.field-input input { width: 100%; }
.field-input em { font-style: normal; color: var(--muted); }
.field.switch { justify-content: space-between; }
.field.switch > span { color: var(--text); }
.field input[type=checkbox] {
  appearance: none; -webkit-appearance: none; width: 51px; height: 31px; border-radius: 16px; flex: none;
  background: var(--line); position: relative; transition: background .2s; margin: 0;
}
.field input[type=checkbox]::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, .2); transition: transform .2s;
}
.field input[type=checkbox]:checked { background: var(--income); }
.field input[type=checkbox]:checked::after { transform: translateX(20px); }

.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 6px 10px 12px; }
.cat-tile {
  display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 2px;
  border-radius: 12px; background: var(--tile); min-height: 70px; text-align: center;
}
.cat-tile.selected { box-shadow: inset 0 0 0 2px var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--card)); }
.cat-tile.selected.expense { box-shadow: inset 0 0 0 2px var(--expense); background: color-mix(in srgb, var(--expense) 10%, var(--card)); }
.cat-tile.selected.income { box-shadow: inset 0 0 0 2px var(--income); background: color-mix(in srgb, var(--income) 10%, var(--card)); }
.cat-icon { font-size: 26px; line-height: 1.1; }
.cat-name { font-size: 12px; line-height: 1.15; word-break: break-word; hyphens: auto; }
.cat-tile.more .cat-icon { color: var(--muted); }

.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 8px; }
.icon-tile { font-size: 28px; height: 52px; border-radius: 12px; background: var(--card); text-align: center; }
.icon-tile.selected { box-shadow: inset 0 0 0 2px var(--accent); }
.icon-tile.big { width: 56px; height: 56px; flex: none; background: var(--tile); }
.name-with-icon { display: flex; align-items: center; gap: 12px; padding: 8px 16px; }
.name-with-icon input { flex: 1; border: 0; background: none; outline: none; font-size: 20px; padding: 8px 0; min-width: 0; }

.btn { display: block; width: 100%; text-align: center; padding: 12px; border-radius: 12px; font-weight: 600; background: var(--card); }
.btn.big { padding: 15px; font-size: 17px; margin-bottom: 12px; color: #fff; background: var(--accent); }
.btn.big.expense { background: var(--expense); }
.btn.big.income { background: var(--income); }
.btn.big.transfer { background: var(--transfer); }
.btn.big.danger-outline { background: var(--card); color: var(--expense); }
.btn.primary { color: var(--accent); }
.btn.danger { color: var(--expense); }
.btn:active { opacity: .8; }

/* ---------- диалог и уведомления ---------- */
.dialog-layer { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .35); display: grid; place-items: center; padding: 24px; animation: fade .15s; }
.dialog { background: var(--card); border-radius: 16px; max-width: 320px; width: 100%; overflow: hidden; text-align: center; }
.dialog p { padding: 20px 18px 16px; margin: 0; }
.dialog-buttons { display: grid; grid-template-columns: 1fr 1fr; border-top: .5px solid var(--line); }
.dialog-buttons .btn { border-radius: 0; background: none; padding: 13px; }
.dialog-buttons .btn + .btn { border-left: .5px solid var(--line); }
.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; transition: all .25s;
  background: rgba(28, 28, 30, .92); color: #fff; padding: 10px 16px; border-radius: 12px;
  font-size: 15px; max-width: calc(100% - 32px); text-align: center; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
