/* Наш бюджет — стили. Сначала мобильный экран, потом всё остальное. */

:root {
  color-scheme: light dark;
  --font: 'Geologica', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  --bg: #F2EFE9;
  --glow: rgba(242, 123, 58, .22);
  --surface: #FFFFFF;
  --surface-2: #F6F4EE;
  --surface-3: #E9E5DC;
  --seg-bg: #E9E5DC;
  --seg-on: #FFFFFF;
  --ink: #17181C;
  --ink-2: #4A4C55;
  --muted: #84868E;
  --line: rgba(23, 24, 28, .08);
  --line-strong: rgba(23, 24, 28, .18);

  /* «инверсная» поверхность: тёмная карточка на светлой теме и наоборот */
  --inv-bg: #17181C;
  --inv-surface: rgba(255, 255, 255, .08);
  --inv-ink: #F5F2EA;
  --inv-muted: rgba(245, 242, 234, .62);

  --income: #0F8F7E;
  --income-soft: rgba(15, 143, 126, .14);
  --expense: #E4572E;
  --expense-soft: rgba(228, 87, 46, .14);
  --inv-income: #25A9A0;
  --inv-expense: #E86A2E;
  --inv-income-soft: rgba(37, 169, 160, .22);
  --inv-expense-soft: rgba(232, 106, 46, .22);
  --danger: #D8383A;
  --danger-soft: rgba(216, 56, 58, .12);
  --inv-danger: #F06B6B;

  --r-l: 24px;
  --r-m: 16px;
  --r-s: 12px;
  --shadow: 0 1px 0 rgba(23, 24, 28, .03), 0 10px 30px -18px rgba(23, 24, 28, .32);
  --shadow-sheet: 0 -10px 40px -10px rgba(0, 0, 0, .35);
  --tabbar-h: 66px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --ease: cubic-bezier(.2, .8, .2, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121316;
    --glow: rgba(242, 123, 58, .14);
    --surface: #1C1D22;
    --surface-2: #25262C;
    --surface-3: #2E2F36;
    --seg-bg: #26272E;
    --seg-on: #3A3B44;
    --ink: #F3F1EA;
    --ink-2: #C6C4BD;
    --muted: #8B8C94;
    --line: rgba(255, 255, 255, .07);
    --line-strong: rgba(255, 255, 255, .18);

    --inv-bg: #F3F1EA;
    --inv-surface: rgba(23, 24, 28, .06);
    --inv-ink: #17181C;
    --inv-muted: rgba(23, 24, 28, .6);

    --income: #25A9A0;
    --income-soft: rgba(37, 169, 160, .18);
    --expense: #E86A2E;
    --expense-soft: rgba(232, 106, 46, .18);
    --inv-income: #0F8F7E;
    --inv-expense: #E4572E;
    --inv-income-soft: rgba(15, 143, 126, .16);
    --inv-expense-soft: rgba(228, 87, 46, .16);
    --danger: #F06B6B;
    --danger-soft: rgba(240, 107, 107, .14);
    --inv-danger: #D8383A;
    --shadow: 0 1px 0 rgba(0, 0, 0, .25), 0 10px 30px -18px rgba(0, 0, 0, .7);
  }
}

/* ---------- база */

*, *::before, *::after { box-sizing: border-box; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
}
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: radial-gradient(60% 38% at 50% -8%, var(--glow), transparent 70%);
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { background: none; border: 0; padding: 0; margin: 0; cursor: pointer; touch-action: manipulation; text-align: inherit; }
input { touch-action: manipulation; }
a { color: inherit; text-decoration: none; }
label { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
ul { list-style: none; margin: 0; padding: 0; }
svg { flex-shrink: 0; }
b { font-weight: 600; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

b.income, small.income, .op-amt.income { color: var(--income); }
b.expense, small.expense { color: var(--expense); }
.op-amt.expense { color: var(--ink); }

/* ---------- заставка и вход */

.splash {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: var(--bg);
}
.splash-mark {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: var(--ink);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 50% { transform: scale(.88); opacity: .6; } }

.auth {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-t)) 22px calc(24px + var(--safe-b));
}
.auth-card { width: 100%; max-width: 400px; animation: rise .5s var(--ease) both; }
.logo { display: flex; align-items: center; gap: 14px; }
.logo-name { font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.auth h1 { font-size: 34px; font-weight: 800; letter-spacing: -.035em; line-height: 1.05; margin: 28px 0 10px; }
.auth p { color: var(--ink-2); font-size: 15px; line-height: 1.45; margin-bottom: 22px; }
.auth-form { display: grid; gap: 10px; }
.auth-error { color: var(--danger); font-size: 14px; min-height: 20px; padding: 0 4px; }
.shake { animation: shake .4s var(--ease); }
@keyframes shake {
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* ---------- каркас приложения */

.app { position: relative; z-index: 1; min-height: 100vh; min-height: 100dvh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 8px;
  max-width: 600px;
  margin: 0 auto;
  padding: calc(10px + var(--safe-t)) 14px 10px;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}
.topbar-title { text-align: center; font-weight: 700; font-size: 17px; }
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--ink);
  transition: background .15s;
}
.icon-btn:active { background: var(--surface-3); }
.month { display: flex; align-items: center; justify-content: center; gap: 2px; }
.month-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--ink-2);
}
.month-btn:active { background: var(--surface-3); }
.month-title {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -.01em;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow);
  white-space: nowrap;
}

.view {
  max-width: 600px;
  margin: 0 auto;
  padding: 6px 16px calc(var(--tabbar-h) + var(--safe-b) + 48px);
}
.view.anim > * { animation: rise .45s var(--ease) both; animation-delay: calc(var(--i, 0) * 50ms); }
.view.slide-left > * { animation: slide-l .35s var(--ease) both; animation-delay: calc(var(--i, 0) * 30ms); }
.view.slide-right > * { animation: slide-r .35s var(--ease) both; animation-delay: calc(var(--i, 0) * 30ms); }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes slide-l { from { opacity: 0; transform: translateX(28px); } }
@keyframes slide-r { from { opacity: 0; transform: translateX(-28px); } }

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  padding-bottom: var(--safe-b);
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--line);
}
.tabbar-inner {
  max-width: 600px;
  margin: 0 auto;
  height: var(--tabbar-h);
  display: grid;
  grid-template-columns: 1fr 80px 1fr;
  align-items: center;
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 100%;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  transition: color .15s;
}
.tab.is-active { color: var(--ink); }
.tab svg { width: 24px; height: 24px; }
.fab {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  margin: 0 auto;
  transform: translateY(-16px);
  background: var(--ink);
  color: var(--inv-ink);
  display: grid;
  place-items: center;
  box-shadow: 0 12px 24px -8px rgba(23, 24, 28, .55);
  transition: transform .15s var(--ease);
}
.fab:active { transform: translateY(-16px) scale(.92); }

/* ---------- бюджет: герой */

.hero {
  position: relative;
  overflow: hidden;
  margin-top: 8px;
  padding: 22px 20px 18px;
  border-radius: var(--r-l);
  background: var(--inv-bg);
  color: var(--inv-ink);
  box-shadow: var(--shadow);
}
.hero::before, .hero::after {
  content: '';
  position: absolute;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  pointer-events: none;
}
.hero::before { right: -110px; top: -140px; background: radial-gradient(circle, var(--inv-expense-soft), transparent 68%); }
.hero::after { left: -120px; bottom: -160px; background: radial-gradient(circle, var(--inv-income-soft), transparent 68%); }
.hero > * { position: relative; }
.hero-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--inv-muted);
}
.hero-value {
  font-size: 46px;
  font-weight: 700;
  letter-spacing: -.035em;
  line-height: 1.05;
  margin: 8px 0 4px;
  overflow-wrap: anywhere;
}
.hero-value.long { font-size: 36px; }
.hero-value.neg { color: var(--inv-expense); }
.hero-sub { font-size: 13px; font-weight: 500; color: var(--inv-muted); }
.hero-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }
.stat { padding: 12px; border-radius: 16px; background: var(--inv-surface); }
.stat-income { --dot: var(--inv-income); --fill: var(--inv-income); --track: var(--inv-income-soft); }
.stat-expense { --dot: var(--inv-expense); --fill: var(--inv-expense); --track: var(--inv-expense-soft); }
.stat.is-over { --fill: var(--inv-danger); }
.stat-label { display: flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 600; color: var(--inv-muted); }
.stat-label::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--dot); }
.stat-value { font-size: 21px; font-weight: 700; letter-spacing: -.02em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat-plan { font-size: 12px; color: var(--inv-muted); margin-top: 1px; }
.meter { display: block; height: 6px; border-radius: 999px; background: var(--track, var(--surface-3)); overflow: hidden; margin-top: 10px; }
.meter i { display: block; height: 100%; border-radius: 999px; background: var(--fill, var(--ink)); transition: width .6s var(--ease); }
.hero-daily {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--inv-surface);
  font-size: 13px;
  color: var(--inv-muted);
}
.hero-daily b { color: var(--inv-ink); }
.hero-daily.is-over b { color: var(--inv-expense); }

.banner {
  margin-top: 14px;
  padding: 16px;
  border-radius: var(--r-l);
  background: var(--surface);
  box-shadow: var(--shadow);
  border: 1px dashed var(--line-strong);
}
.banner-text { display: grid; gap: 3px; }
.banner-text b { font-size: 15px; }
.banner-text span { font-size: 13px; color: var(--muted); line-height: 1.4; }
.banner-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* ---------- группы и строки */

.group { margin-top: 22px; }
.group-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 0 4px 8px; }
.group-title { font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.group-total { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.group-total b { color: var(--ink); }

.rows, .card {
  background: var(--surface);
  border-radius: var(--r-l);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card.pad { padding: 14px; }
.row, .op, .rows-add {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  color: var(--ink);
  transition: background .12s;
}
.rows > li:first-child > .row, .rows > li:first-child > .op, .rows > li:first-child > .rows-add { border-top: 0; }
.row:active, .op:active, .rows-add:active, .cell:active { background: var(--surface-2); }
.row-income { --fill: var(--income); --track: var(--income-soft); }
.row-expense { --fill: var(--expense); --track: var(--expense-soft); }
.row.is-over { --fill: var(--danger); }
.row.is-over .row-fact { color: var(--danger); }
.row.is-archived { opacity: .55; }
.row-ico {
  width: 40px;
  height: 40px;
  border-radius: 13px;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  font-size: 20px;
  line-height: 1;
}
.row-main { min-width: 0; }
.row-name { display: block; font-weight: 500; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-meter { height: 4px; margin-top: 7px; }
.row-nums { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-fact { display: block; font-weight: 600; font-size: 15px; }
.row-plan { display: block; font-size: 12px; color: var(--muted); margin-top: 1px; }
.rows-add { grid-template-columns: 40px 1fr; color: var(--ink-2); font-weight: 500; font-size: 14px; }
.rows-add svg { margin: 0 auto; }

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 52px;
  padding: 0 18px;
  border-radius: 16px;
  background: var(--ink);
  color: var(--inv-ink);
  font-weight: 600;
  font-size: 16px;
  transition: transform .12s var(--ease), opacity .12s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: default; }
.btn svg { width: 18px; height: 18px; }
.btn-secondary { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-ghost { background: transparent; color: var(--ink-2); height: 44px; }
.btn-small { display: inline-flex; width: auto; height: 42px; padding: 0 14px; font-size: 14px; border-radius: 13px; gap: 6px; }
.pill-btn { padding: 8px 12px; border-radius: 999px; background: var(--surface-3); font-weight: 600; font-size: 13px; color: var(--ink); }

/* ---------- операции */

.ops-tools { display: grid; gap: 10px; margin-top: 6px; }
.search {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 14px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--muted);
}
.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 15px;
  color: var(--ink);
  -webkit-appearance: none;
  appearance: none;
}
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }
.ops-summary { display: flex; justify-content: space-between; gap: 12px; margin: 14px 4px 0; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.day { margin-top: 16px; }
.day-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 0 4px 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.op { padding: 11px 14px; }
.op-main { min-width: 0; display: grid; gap: 1px; }
.op-title, .op-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.op-title { font-weight: 500; font-size: 15px; }
.op-sub { font-size: 12px; color: var(--muted); }
.op-amt { font-weight: 600; font-size: 15px; font-variant-numeric: tabular-nums; white-space: nowrap; }

.empty { display: grid; justify-items: center; gap: 10px; padding: 40px 16px 24px; text-align: center; }
.empty-emoji { font-size: 40px; line-height: 1; }
.empty-title { color: var(--muted); font-size: 15px; }

/* ---------- сегменты, чипы, поля */

.seg { display: flex; padding: 3px; border-radius: 999px; background: var(--seg-bg); }
.seg button {
  flex: 1;
  height: 38px;
  padding: 0 8px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 14px;
  color: var(--ink-2);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background .15s, color .15s;
}
.seg button.is-on { background: var(--seg-on); color: var(--ink); box-shadow: 0 1px 4px rgba(0, 0, 0, .08); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 13px 9px 11px;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
  color: var(--ink);
  transition: background .12s, color .12s, transform .12s;
}
.chip:active { transform: scale(.96); }
.chip.is-on { background: var(--ink); color: var(--inv-ink); }
.chip svg { width: 16px; height: 16px; }
.chip-ghost { background: transparent; box-shadow: none; border: 1.5px dashed var(--line-strong); color: var(--ink-2); }
.chip-date { position: relative; overflow: hidden; }
.chip-date input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  -webkit-appearance: none;
  appearance: none;
}

.field { margin-top: 16px; }
.label {
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
}
.input {
  width: 100%;
  height: 50px;
  padding: 0 14px;
  border-radius: 14px;
  border: 1.5px solid transparent;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 17px;
  outline: 0;
  color: var(--ink);
  -webkit-appearance: none;
  appearance: none;
  transition: border-color .15s;
}
.input::placeholder { color: var(--muted); opacity: 1; }
.input:focus { border-color: var(--ink); }
.input-row { position: relative; }
.input-row .input { padding-right: 44px; }
.input-suffix { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 600; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.card.pad .btn { margin-top: 10px; }

.amount-wrap { display: flex; align-items: baseline; justify-content: center; gap: 8px; padding: 16px 0 6px; }
.amount-input {
  width: 68%;
  max-width: 280px;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  text-align: right;
  font-size: 44px;
  font-weight: 700;
  letter-spacing: -.03em;
  color: var(--ink);
}
.amount-input::placeholder { color: var(--line-strong); }
.amount-wrap.income .amount-input { color: var(--income); }
.amount-cur { font-size: 26px; font-weight: 600; color: var(--muted); }

.sheet-actions { display: grid; gap: 8px; margin-top: 22px; }
.confirm-text { color: var(--ink-2); font-size: 15px; line-height: 1.45; padding: 2px 0; }
.fineprint { margin-top: 10px; font-size: 12.5px; line-height: 1.45; color: var(--muted); }
.fineprint.center { text-align: center; margin-top: 26px; }

/* ---------- листы (bottom sheets) */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(10, 10, 12, .45);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity .25s;
}
.sheet-backdrop.is-open { opacity: 1; }
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 41;
  max-width: 600px;
  max-height: 92vh;
  max-height: 92dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  border-radius: 28px 28px 0 0;
  background: var(--bg);
  box-shadow: var(--shadow-sheet);
  transform: translateY(100%);
  transition: transform .34s var(--ease);
}
.sheet.is-open { transform: none; }
.sheet-handle { width: 36px; height: 4px; margin: 8px auto 0; border-radius: 2px; background: var(--line-strong); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px 6px 20px; }
.sheet-title { display: flex; align-items: center; font-size: 19px; font-weight: 700; letter-spacing: -.015em; min-width: 0; }
.title-emoji { margin-right: 8px; font-size: 22px; }
.sheet-head-tools { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; padding: 4px 20px calc(20px + var(--safe-b)); -webkit-overflow-scrolling: touch; }

.cat-stats { padding: 4px 0 2px; }
.cat-stats.income { --fill: var(--income); --track: var(--income-soft); }
.cat-stats.expense { --fill: var(--expense); --track: var(--expense-soft); }
.cat-stats.is-over { --fill: var(--danger); }
.cat-stats.is-over .cat-sub { color: var(--danger); }
.cat-big { font-size: 34px; font-weight: 700; letter-spacing: -.03em; line-height: 1.1; }
.cat-sub { margin-top: 3px; font-size: 13px; color: var(--muted); }

.emoji-head { display: flex; align-items: center; gap: 10px; }
.emoji-preview {
  flex-shrink: 0;
  width: 50px;
  height: 50px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  font-size: 26px;
  line-height: 1;
}
.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.emoji { aspect-ratio: 1; border-radius: 10px; font-size: 22px; line-height: 1; display: grid; place-items: center; }
.emoji.is-on { background: var(--surface); box-shadow: inset 0 0 0 2px var(--ink); }

.plan-card { padding: 0; }
.plan-row {
  display: grid;
  grid-template-columns: 36px 1fr 118px;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 8px 12px;
  border-top: 1px solid var(--line);
}
.plan-row:first-child { border-top: 0; }
.plan-row .row-ico { width: 36px; height: 36px; font-size: 18px; border-radius: 11px; }
.plan-name { font-size: 14px; font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plan-input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1.5px solid transparent;
  background: var(--surface-2);
  text-align: right;
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  outline: 0;
  -webkit-appearance: none;
  appearance: none;
}
.plan-input:focus { border-color: var(--ink); background: var(--surface); }
.plan-input.is-bad { border-color: var(--danger); }
.plan-totals {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 12px;
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface-2);
  font-size: 13px;
  color: var(--muted);
}
.plan-totals b { color: var(--ink); }

.year-nav { display: flex; align-items: center; justify-content: center; gap: 14px; margin-bottom: 12px; font-size: 20px; font-weight: 700; }
.mgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mcell {
  display: grid;
  gap: 3px;
  padding: 12px 6px;
  border-radius: 16px;
  border: 1.5px solid transparent;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}
.mcell span { font-weight: 600; font-size: 14px; }
.mcell small { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.mcell.is-current { border-color: var(--ink); }
.mcell.is-selected { background: var(--ink); color: var(--inv-ink); }
.mcell.is-selected small { color: var(--inv-muted); }
.mcell.is-selected small.income { color: var(--inv-income); }
.mcell.is-selected small.expense { color: var(--inv-expense); }

/* ---------- настройки */

.cell {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  color: var(--ink);
  transition: background .12s;
}
.card > .cell:first-child { border-top: 0; }
.cell > svg { color: var(--ink-2); }
.cell-main { flex: 1; min-width: 0; display: grid; gap: 1px; text-align: left; }
.cell-title { font-weight: 500; font-size: 15px; }
.cell-sub { font-size: 12px; color: var(--muted); }
.cell-add { color: var(--ink-2); font-weight: 500; font-size: 14px; }
.cell-add svg { margin: 0 8px; }
.cell-cat { padding: 8px 8px 8px 14px; }
.cell-cat .cell-main { display: flex; align-items: center; gap: 12px; padding: 4px 0; }
.cell-cat .cell-main > span:last-child { display: grid; gap: 1px; min-width: 0; }
.cell-cat.is-archived .cell-title { color: var(--muted); }
.cell-tools { display: flex; gap: 2px; }
.mini-btn { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: var(--ink-2); }
.mini-btn:disabled { opacity: .3; cursor: default; }
.mini-btn:active:not(:disabled) { background: var(--surface-3); }

/* ---------- тост и офлайн */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 18px);
  z-index: 60;
  max-width: calc(100% - 32px);
  padding: 11px 16px;
  border-radius: 14px;
  background: var(--ink);
  color: var(--inv-ink);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translate(-50%, 12px);
  transition: opacity .2s, transform .25s var(--ease);
  pointer-events: none;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.toast-error { background: var(--danger); color: #fff; }
.offline {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 30;
  padding: calc(6px + var(--safe-t)) 12px 6px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  background: var(--danger);
  color: #fff;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- v2: таблица «этот месяц / следующий» */

.tbl-head {
  display: grid;
  grid-template-columns: 1fr 86px 86px;
  gap: 6px;
  align-items: end;
  padding: 0 4px 8px;
}
.tbl-col { text-align: right; line-height: 1.15; }
.tbl-col b { font-size: 13px; font-weight: 700; color: var(--muted); }
.tbl-col.is-cur b { color: var(--ink); }
.tbl-col small { display: block; font-size: 10px; color: var(--muted); letter-spacing: .02em; }
.tbl-row {
  display: grid;
  grid-template-columns: 1fr 86px 86px;
  gap: 6px;
  align-items: center;
  padding: 6px 8px 6px 10px;
  border-top: 1px solid var(--line);
}
.tbl > .tbl-row:first-child { border-top: 0; }
.tbl-name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.row-ico.sm { width: 30px; height: 30px; border-radius: 10px; font-size: 15px; flex-shrink: 0; }
.tbl-name-text { min-width: 0; display: grid; gap: 1px; }
.tbl-name-text .row-name {
  font-size: 13.5px;
  line-height: 1.2;
  white-space: normal;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}
.tbl-tag { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; color: var(--muted); }
.tbl-tag svg { width: 12px; height: 12px; }
.tcell {
  display: grid;
  gap: 1px;
  width: 100%;
  min-height: 44px;
  padding: 6px 8px;
  border-radius: 12px;
  text-align: right;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  transition: background .12s;
}
button.tcell:active { background: var(--surface-2); }
.cell-plan { font-weight: 600; font-size: 14px; white-space: nowrap; }
.cell-fact { display: inline-flex; justify-content: flex-end; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.cell-fact svg { width: 12px; height: 12px; }
.tcell.is-over .cell-fact { color: var(--danger); font-weight: 600; }
.cell-meter { height: 3px; margin-top: 4px; }
.tbl-income .tcell { --fill: var(--income); --track: var(--income-soft); }
.tbl-expense .tcell { --fill: var(--expense); --track: var(--expense-soft); }
.tbl-expense .tcell.is-over { --fill: var(--danger); }
.cell-proj .cell-plan { color: var(--muted); font-weight: 500; }
.cell-proj .cell-fact { font-size: 11px; }
.cell-empty .cell-plan { color: var(--muted); font-weight: 500; }
.cell-empty .cell-fact { font-size: 11px; color: var(--line-strong); }
.tbl-total { background: var(--surface-2); }
.tbl-total .tbl-name { font-weight: 700; font-size: 14px; padding-left: 2px; }
.tbl-total .cell-plan { font-weight: 700; }
.cell-add {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  color: var(--ink-2);
  font-weight: 500;
  font-size: 14px;
}
.cell-add:active { background: var(--surface-2); }
.cell-add svg { margin: 0 3px; }

.cell-edit { padding: 2px 0; gap: 4px; }
.cell-in {
  width: 100%;
  height: 34px;
  padding: 0 8px;
  border-radius: 10px;
  border: 1.5px solid transparent;
  background: var(--surface-2);
  text-align: right;
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  outline: 0;
  -webkit-appearance: none;
  appearance: none;
}
.cell-in::placeholder { color: var(--muted); font-weight: 400; }
.cell-in-fact { font-weight: 500; }
.cell-in:focus { border-color: var(--ink); background: var(--surface); }
.cell-in.is-bad { border-color: var(--danger); }
.is-editing .tbl-row { padding-top: 5px; padding-bottom: 5px; }

.editbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  padding: 10px 16px calc(10px + var(--safe-b));
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--line);
}
.editbar-inner { max-width: 600px; margin: 0 auto; display: grid; grid-template-columns: 1fr 2fr; gap: 8px; }

.banner-empty { text-align: left; }
.banner-emoji { font-size: 34px; line-height: 1; margin-bottom: 10px; }
.link-btn { color: var(--ink); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; font-size: 12.5px; margin-top: 6px; }

/* переключатель */
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.switch-text { display: grid; gap: 2px; min-width: 0; }
.switch-text span { font-weight: 500; font-size: 15px; }
.switch-text small { font-size: 12px; color: var(--muted); line-height: 1.35; }
.switch { position: relative; flex-shrink: 0; width: 50px; height: 30px; border-radius: 999px; background: var(--seg-bg); transition: background .2s; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.switch i { position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, .2); transition: transform .2s var(--ease); pointer-events: none; }
.switch.is-on, .switch:has(input:checked) { background: var(--income); }
.switch:has(input:checked) i { transform: translateX(20px); }

/* события: ожидаемые и подтверждение */
.ev-item { display: flex; align-items: stretch; }
.ev-item .op { flex: 1; min-width: 0; }
.rows > .ev-item:first-child > .op { border-top: 0; }
.ev-item.is-pending .op-amt { color: var(--muted); }
.ev-tag { display: inline-flex; vertical-align: middle; color: var(--muted); }
.ev-tag svg { width: 12px; height: 12px; }
.confirm-btn {
  width: 52px;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
  display: grid;
  place-items: center;
  color: var(--income);
  background: var(--income-soft);
}
.rows > .ev-item:first-child > .confirm-btn { border-top: 0; }
.confirm-btn:active { background: var(--income); color: #fff; }
.day-pending .day-head span:first-child { display: inline-flex; align-items: center; gap: 4px; color: var(--ink-2); }
.day-pending .fineprint { margin: 8px 4px 0; }
.hero-pending { display: flex; align-items: center; gap: 6px; margin-top: 10px; font-size: 13px; color: var(--inv-muted); }
.hero-pending svg { width: 14px; height: 14px; }

.hint { font-size: 13px; color: var(--muted); width: 100%; margin-bottom: 2px; }
.title-text { display: grid; gap: 0; min-width: 0; line-height: 1.15; }
.title-text small { font-size: 12px; font-weight: 500; color: var(--muted); }
.help p { font-size: 14px; line-height: 1.45; color: var(--ink-2); }
.help p + p { margin-top: 8px; }

/* ---------- удаление строк и событий */
.del-btn {
  width: 44px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
  transition: color .12s, background .12s;
}
.del-btn svg { width: 18px; height: 18px; }
.del-btn:active { color: var(--danger); background: var(--danger-soft); }
.rows > .ev-item:first-child > .del-btn { border-top: 0; }
.del-btn-sm {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: var(--danger);
  background: var(--danger-soft);
}
.del-btn-sm svg { width: 16px; height: 16px; }
button.tbl-name { text-align: left; border-radius: 12px; padding: 4px 4px 4px 0; margin-left: -2px; }
button.tbl-name:active { background: var(--surface-2); }
