/* =====================================================================
   Льюис — «Тёплый дом»
   Все цвета, шрифты, отступы и радиусы — только через переменные ниже.
   Тема: в Telegram — атрибут data-theme (ставит app.js по теме Telegram),
   вне Telegram — системная тема через prefers-color-scheme.
   ===================================================================== */

:root {
  color-scheme: light;

  /* Цвета — светлая тема */
  --bg: #F7F5EF;
  --surface: #FFFFFF;
  --text: #202C27;
  --text-2: #626C65;            /* 5.0:1 на фоне, 5.4:1 на карточке */
  --accent: #24483D;            /* 10:1 на карточке */
  --on-accent: #FFFFFF;
  --accent-soft: #E4EBDF;
  --on-accent-soft: #24483D;    /* 8.3:1 на мягкой подложке */
  --peach: #F3D9CA;
  --on-peach: #202C27;
  --on-peach-2: #4F5751;        /* 5.5:1 на персиковом */
  --line: #E6E7DF;
  --track: #ECEDE6;
  --bar-muted: #C7CFC4;
  --danger: #A8321F;
  --danger-soft: #F8E4DE;
  --backdrop: rgba(32, 44, 39, 0.36);
  --shadow: 0 1px 2px rgba(32, 44, 39, 0.04), 0 2px 12px rgba(32, 44, 39, 0.04);
  --shadow-sheet: 0 -6px 28px rgba(32, 44, 39, 0.12);
  --focus: #24483D;

  /* Типографика */
  --font-display: Georgia, "Times New Roman", "Noto Serif", serif;
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --fs-display: 30px;
  --fs-hero: 38px;
  --fs-title: 17px;
  --fs-body: 16px;
  --fs-sub: 14px;
  --fs-caption: 13px;
  --fs-tiny: 11px;
  --lh: 1.4;

  /* Интервалы (сетка 4/8) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --gutter: clamp(16px, 5vw, 20px);

  /* Радиусы и размеры */
  --r-card: 20px;
  --r-control: 14px;
  --r-sm: 10px;
  --r-pill: 999px;
  --tap: 44px;
  --btn-h: 50px;
  --tabbar-h: 64px;
  --action-h: 74px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* Движение */
  --dur: 180ms;
  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);
}

/* Тёмная тема — тот же «Тёплый дом», своя палитра */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #171F1B;
  --surface: #222D26;
  --text: #F3F4EE;
  --text-2: #B6C1B8;            /* 7.7:1 на карточке */
  --accent: #B9D4BB;            /* 9:1 на карточке */
  --on-accent: #171F1B;         /* 10.6:1 на акценте */
  --accent-soft: #2F3F35;
  --on-accent-soft: #CFE3D0;
  --peach: #4A3A30;
  --on-peach: #F3F4EE;
  --on-peach-2: #D9C8BD;        /* 6.7:1 на персиковом */
  --line: #33413A;
  --track: #2E3A33;
  --bar-muted: #4A574F;
  --danger: #F2B8AE;
  --danger-soft: #3F2A25;
  --backdrop: rgba(0, 0, 0, 0.55);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-sheet: 0 -6px 28px rgba(0, 0, 0, 0.4);
  --focus: #B9D4BB;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #171F1B;
    --surface: #222D26;
    --text: #F3F4EE;
    --text-2: #B6C1B8;
    --accent: #B9D4BB;
    --on-accent: #171F1B;
    --accent-soft: #2F3F35;
    --on-accent-soft: #CFE3D0;
    --peach: #4A3A30;
    --on-peach: #F3F4EE;
    --on-peach-2: #D9C8BD;
    --line: #33413A;
    --track: #2E3A33;
    --bar-muted: #4A574F;
    --danger: #F2B8AE;
    --danger-soft: #3F2A25;
    --backdrop: rgba(0, 0, 0, 0.55);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-sheet: 0 -6px 28px rgba(0, 0, 0, 0.4);
    --focus: #B9D4BB;
  }
}

/* ============================ Основа ============================ */

*, *::before, *::after { box-sizing: border-box; }

html { background: var(--bg); -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--fs-body);
  line-height: var(--lh);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(var(--tabbar-h) + var(--action-h) + var(--safe-bottom) + var(--sp-4));
}
body.no-action { padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + var(--sp-6)); }
body.gated { padding-bottom: var(--sp-8); }
body.sheet-open { overflow: hidden; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }

.icon {
  width: 22px; height: 22px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.num { font-variant-numeric: tabular-nums; }

/* ============================ Шапка ============================ */

.app-header {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: calc(var(--sp-4) + env(safe-area-inset-top, 0px)) var(--gutter) 0;
}
.greeting { min-width: 0; }
.greeting-title { margin: 0; font-size: var(--fs-title); font-weight: 600; overflow-wrap: anywhere; }
.greeting-sub { margin: 2px 0 0; font-size: var(--fs-caption); color: var(--text-2); }
.greeting-sub:empty { display: none; }

.avatars { display: flex; flex: none; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 16px; font-weight: 600;
  border: 2px solid var(--bg);
  background: var(--accent-soft); color: var(--on-accent-soft);
}
.avatar + .avatar { margin-left: -8px; }
.avatar:nth-child(odd) { background: var(--peach); color: var(--on-peach); }

/* ============================ Разделы ============================ */

main { padding: 0 var(--gutter); }

.section-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-2);
  margin: var(--sp-5) 0 var(--sp-4);
}
.section-titles { min-width: 0; }
.display {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--fs-display);
  font-weight: 700;
  line-height: 1.12;
  letter-spacing: -0.01em;
  color: var(--accent);
  overflow-wrap: anywhere;
}
:root[data-theme="dark"] .display { color: var(--text); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .display { color: var(--text); } }
.subtitle { margin: var(--sp-1) 0 0; font-size: var(--fs-body); color: var(--text-2); }

.tab { animation: fade-in var(--dur) var(--ease); }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ============================ Карточки и списки ============================ */

.card {
  background: var(--surface);
  border-radius: var(--r-card);
  padding: var(--sp-4);
  box-shadow: var(--shadow);
  margin-bottom: var(--sp-3);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
  margin-bottom: var(--sp-3);
}
.card-title { margin: 0; font-size: var(--fs-body); font-weight: 600; }
.card-head .card-title { margin: 0; }

.group-label {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
  min-height: var(--tap);
  margin: var(--sp-3) var(--sp-1) 0;
  font-size: var(--fs-sub); font-weight: 600; color: var(--text);
}
.group-title { margin: 0; font-size: var(--fs-sub); font-weight: 600; }
.group-label .meta { font-size: var(--fs-sub); color: var(--text-2); font-variant-numeric: tabular-nums; }

.list {
  list-style: none; margin: 0 0 var(--sp-3); padding: 0;
  background: var(--surface);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.row {
  display: flex; align-items: center; gap: var(--sp-3);
  min-height: 56px;
  padding: var(--sp-2) var(--sp-2) var(--sp-2) var(--sp-4);
  position: relative;
}
.row + .row::before {
  content: ""; position: absolute; top: 0; right: var(--sp-4); left: var(--sp-4);
  border-top: 1px solid var(--line);
}
.row-main { flex: 1; min-width: 0; padding: var(--sp-1) 0; }
.row-title { display: block; font-size: var(--fs-body); overflow-wrap: anywhere; }
.row-sub { display: block; margin-top: 2px; font-size: var(--fs-caption); color: var(--text-2); overflow-wrap: anywhere; }
.row-end {
  flex: none; text-align: right; font-size: var(--fs-sub); color: var(--text-2);
  font-variant-numeric: tabular-nums; padding-right: var(--sp-2);
}
.row-end.strong { font-size: var(--fs-body); font-weight: 600; color: var(--text); }
.row-button {
  display: flex; align-items: center; gap: var(--sp-3);
  width: 100%; min-height: 56px; padding: var(--sp-2) var(--sp-4);
  border: 0; background: none; text-align: left;
  transition: background var(--dur) var(--ease);
}
.row-button:active { background: var(--accent-soft); }
.row-button > .icon { color: var(--text-2); width: 18px; height: 18px; }
.row.is-tappable { padding: 0; }
.row.is-tappable .row-button { padding-right: var(--sp-2); }

.row-icon {
  width: 40px; height: 40px; flex: none; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--on-accent-soft);
  font-size: 20px;
}
.row-icon .icon { width: 20px; height: 20px; }
.row-icon.peach { background: var(--peach); color: var(--on-peach); }

.tag {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 1px 8px; border-radius: var(--r-pill);
  font-size: var(--fs-tiny); font-weight: 600; letter-spacing: 0.02em;
  background: var(--accent-soft); color: var(--on-accent-soft);
  vertical-align: 2px; white-space: nowrap;
}
.tag .icon { width: 12px; height: 12px; stroke-width: 2; }
.tag.peach { background: var(--peach); color: var(--on-peach); }

/* ============================ Кнопки ============================ */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: var(--tap); padding: 0 var(--sp-4);
  border: 0; border-radius: var(--r-control);
  font-size: var(--fs-body); font-weight: 600;
  transition: background var(--dur) var(--ease), opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; }
.btn-primary { min-height: var(--btn-h); background: var(--accent); color: var(--on-accent); }
.btn-secondary { background: var(--accent-soft); color: var(--on-accent-soft); }
.btn-ghost { background: none; color: var(--accent); padding: 0 var(--sp-2); }
.btn-ghost-danger { background: none; color: var(--danger); min-height: var(--btn-h); }
.btn-block { width: 100%; }
.btn-grow { flex: 1; }
.btn .icon { width: 20px; height: 20px; stroke-width: 2; }

.icon-btn {
  width: var(--tap); height: var(--tap); flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: var(--r-control); background: none; color: var(--text-2);
  transition: background var(--dur) var(--ease);
}
.icon-btn:active:not(:disabled) { background: var(--accent-soft); }
.row > .icon-btn .icon { width: 19px; height: 19px; opacity: 0.8; }
.icon-btn:disabled { opacity: 0.35; }
.section-head .icon-btn { background: var(--surface); box-shadow: var(--shadow); color: var(--text); }

/* Переключатель месяца */
.period {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border-radius: var(--r-control); box-shadow: var(--shadow);
  padding: 2px; margin-bottom: var(--sp-3);
}
.period .icon-btn { color: var(--accent); }
.period-label { font-weight: 600; text-align: center; }

/* ============================ Чипы и сегменты ============================ */

.chips {
  display: flex; gap: var(--sp-2);
  overflow-x: auto; scrollbar-width: none;
  margin: 0 calc(-1 * var(--gutter)) var(--sp-3);
  padding: 2px var(--gutter);
}
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; margin: 0; padding: 0; }
.chip {
  flex: none;
  display: inline-flex; align-items: center; gap: var(--sp-2);
  min-height: var(--tap); padding: 0 var(--sp-4);
  border: 1px solid var(--line); border-radius: var(--r-control);
  background: var(--surface); color: var(--text);
  font-size: var(--fs-sub); font-weight: 500; white-space: nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.chip .icon { width: 20px; height: 20px; }
.chip .count { color: var(--text-2); font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"], .chip[aria-checked="true"] {
  background: var(--accent-soft); border-color: var(--accent); color: var(--on-accent-soft); font-weight: 600;
}
.chip[aria-pressed="true"] .count, .chip[aria-checked="true"] .count { color: var(--on-accent-soft); }
.chip.dashed { border-style: dashed; color: var(--text-2); }

.segmented {
  display: flex; gap: 2px; padding: 3px;
  background: var(--track); border-radius: var(--r-control);
}
.segmented button {
  flex: 1; min-height: 40px; border: 0; border-radius: 11px;
  background: none; color: var(--text-2); font-size: var(--fs-sub); font-weight: 500;
  transition: background var(--dur) var(--ease);
}
.segmented button[aria-checked="true"] { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }

/* ============================ Чекбокс ============================ */

.check {
  width: var(--tap); height: var(--tap); flex: none;
  margin-left: calc(-1 * var(--sp-3)); margin-right: calc(-1 * var(--sp-2));
  display: grid; place-items: center;
  border: 0; background: none; padding: 0;
}
.check-box {
  width: 22px; height: 22px; border-radius: 7px;
  border: 1.5px solid var(--text-2);
  display: grid; place-items: center;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.check-box .icon { width: 16px; height: 16px; stroke-width: 2.4; opacity: 0; color: var(--on-accent); }
.check[aria-checked="true"] .check-box { background: var(--accent); border-color: var(--accent); }
.check[aria-checked="true"] .check-box .icon { opacity: 1; }
.row.is-done .row-title { color: var(--text-2); text-decoration: line-through; text-decoration-thickness: 1px; }
.row.is-done .check[aria-checked="true"] .check-box { background: var(--text-2); border-color: var(--text-2); }

/* ============================ Прогресс ============================ */

.progress-card { padding: var(--sp-3) var(--sp-4) var(--sp-4); }
.progress-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: var(--sp-2); }
.progress-head b { font-weight: 600; }
.progress-head span { color: var(--text-2); font-size: var(--fs-sub); font-variant-numeric: tabular-nums; }
.progress { height: 8px; border-radius: var(--r-pill); background: var(--track); overflow: hidden; }
.progress-fill { height: 100%; border-radius: var(--r-pill); background: var(--accent); transition: width 300ms var(--ease); }

/* ============================ Поля ============================ */

.field-group { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label { font-size: var(--fs-sub); font-weight: 600; color: var(--text); }
.field {
  width: 100%; min-height: var(--btn-h);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--line); border-radius: var(--r-control);
  background: var(--surface); color: var(--text);
  font-size: var(--fs-body);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.field::placeholder { color: var(--text-2); opacity: 0.85; }
.field:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field[aria-invalid="true"] { border-color: var(--danger); }
select.field {
  appearance: none; -webkit-appearance: none; padding-right: 36px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
textarea.field { resize: vertical; line-height: var(--lh); }
input[type="date"].field, input[type="time"].field { min-width: 0; }
.field-amount { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.field-hint { margin: 0; font-size: var(--fs-caption); color: var(--text-2); }
.field-error {
  margin: 0; display: flex; align-items: center; gap: 6px;
  font-size: var(--fs-caption); color: var(--danger); font-weight: 500;
}
.field-row { display: flex; gap: var(--sp-2); }
.field-grow { flex: 1; }
.field-day { width: 76px; flex: none; }
.field-year { width: 92px; flex: none; }
.inline-form { display: flex; gap: var(--sp-2); }
.inline-form .field { flex: 1; min-width: 0; }

.search { position: relative; margin-bottom: var(--sp-3); }
.search .icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-2); pointer-events: none; }
.search .field { padding-left: 44px; min-height: 46px; background: var(--surface); }

/* ============================ Состояния ============================ */

.state {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--sp-2);
  padding: var(--sp-8) var(--sp-5);
  background: var(--surface); border-radius: var(--r-card); box-shadow: var(--shadow);
  margin-bottom: var(--sp-3);
}
.state-icon {
  width: 56px; height: 56px; border-radius: 18px;
  display: grid; place-items: center; margin-bottom: var(--sp-1);
  background: var(--accent-soft); color: var(--on-accent-soft);
}
.state-icon .icon { width: 28px; height: 28px; }
.state.is-error .state-icon { background: var(--danger-soft); color: var(--danger); }
.state h2 { margin: 0; font-size: var(--fs-title); font-weight: 600; }
.state p { margin: 0; color: var(--text-2); font-size: var(--fs-sub); max-width: 30ch; }
.state .btn { margin-top: var(--sp-2); }
.state.compact { padding: var(--sp-5); }

.gate { padding-top: var(--sp-8); }
.gate .state { padding: var(--sp-8) var(--sp-5); }

/* Загрузка: спокойные «плашки» вместо спиннера */
.skeleton { display: flex; flex-direction: column; gap: var(--sp-3); }
.skeleton-block {
  height: 56px; border-radius: var(--r-card); background: var(--surface);
  box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.skeleton-block.tall { height: 120px; }
.skeleton-block::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, var(--track), transparent);
  transform: translateX(-100%); animation: shimmer 1.4s infinite;
  opacity: 0.6;
}
@keyframes shimmer { to { transform: translateX(100%); } }

.footnote { margin: var(--sp-2) var(--sp-4) var(--sp-4); text-align: center; font-size: var(--fs-caption); color: var(--text-2); }

/* ============================ Траты ============================ */

.hero { text-align: left; padding: var(--sp-5) var(--sp-4); }
.hero-label { margin: 0; font-size: var(--fs-sub); color: var(--text-2); }
.hero-num {
  margin: var(--sp-1) 0 0; font-size: var(--fs-hero); font-weight: 700; line-height: 1.1;
  letter-spacing: -0.02em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere;
}
.hero-sub { margin: var(--sp-2) 0 0; font-size: var(--fs-sub); color: var(--text-2); }

.barlist { display: flex; flex-direction: column; gap: var(--sp-1); }
.bar-row {
  display: block; width: 100%; text-align: left;
  border: 0; background: none; padding: var(--sp-2) var(--sp-2); margin: 0 calc(-1 * var(--sp-2));
  width: calc(100% + 2 * var(--sp-2)); border-radius: var(--r-sm);
  transition: background var(--dur) var(--ease);
}
button.bar-row:active { background: var(--accent-soft); }
.bar-row[aria-pressed="true"] { background: var(--accent-soft); }
.bar-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--sp-2); margin-bottom: 6px; font-size: var(--fs-sub); }
.bar-name { min-width: 0; overflow-wrap: anywhere; }
.bar-val { flex: none; color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-val b { color: var(--text); font-weight: 600; }
.bar-track { position: relative; height: 8px; border-radius: var(--r-pill); background: var(--track); }
.bar-fill { height: 100%; border-radius: var(--r-pill); background: var(--accent); }
.barlist:has([aria-pressed="true"]) .bar-row:not([aria-pressed="true"]) .bar-fill { background: var(--bar-muted); }
.bar-limit {
  position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px;
  border-radius: 1px; background: var(--text); opacity: 0.5;
}
.bar-row.over .bar-fill { background: var(--danger); }
.over-note {
  display: flex; align-items: center; gap: 4px; margin-top: 6px;
  color: var(--danger); font-size: var(--fs-caption); font-weight: 600;
}
.over-note .icon { width: 14px; height: 14px; stroke-width: 2; }

.columns { display: flex; align-items: stretch; gap: var(--sp-2); height: 148px; }
.col {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: var(--sp-1);
  border: 0; background: none; padding: 0; color: var(--text-2); border-radius: var(--r-sm);
}
.col-val { font-size: var(--fs-tiny); white-space: nowrap; min-height: 15px; visibility: hidden; font-variant-numeric: tabular-nums; }
.col[aria-current="true"] .col-val { visibility: visible; color: var(--text); font-weight: 600; }
.col-bar-wrap { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; }
.col-bar { width: 70%; max-width: 32px; border-radius: 6px 6px 2px 2px; background: var(--bar-muted); }
.col[aria-current="true"] .col-bar { background: var(--accent); }
.col-label { font-size: var(--fs-caption); }
.col[aria-current="true"] .col-label { color: var(--text); font-weight: 600; }

.day-head {
  display: flex; justify-content: space-between; gap: var(--sp-2);
  margin: var(--sp-4) var(--sp-1) var(--sp-2);
  font-size: var(--fs-caption); color: var(--text-2); font-variant-numeric: tabular-nums;
}
.day-head b { color: var(--text); font-weight: 600; }

.mode-switch { margin-bottom: var(--sp-3); }
.budget-split {
  display: flex; justify-content: space-between; gap: var(--sp-3);
  margin: var(--sp-3) 0 var(--sp-2); font-size: var(--fs-sub); color: var(--text-2);
}
.budget-split b { color: var(--text); font-weight: 600; }
.progress.is-over .progress-fill { background: var(--danger); }
.hero .over-note { margin-top: var(--sp-2); }
.bar-left { display: block; margin-top: 6px; font-size: var(--fs-caption); color: var(--text-2); font-variant-numeric: tabular-nums; }
.budget-unplanned { margin-top: var(--sp-3); padding-top: var(--sp-3); border-top: 1px solid var(--line); }
.budget-unplanned b { color: var(--text); }
.pay-end { display: flex; flex-direction: column; align-items: flex-end; gap: var(--sp-1); }
.pay-end b { color: var(--text); font-size: var(--fs-body); }
.btn-small { min-height: 36px; padding: 0 var(--sp-3); font-size: var(--fs-caption); position: relative; }
.btn-small::after { content: ""; position: absolute; inset: -4px 0; }   /* зона нажатия 44px */
.sheet-foot.sheet-foot-total { flex-direction: column; align-items: stretch; }
.budget-total { display: flex; justify-content: space-between; margin: 0 var(--sp-1); font-size: var(--fs-sub); color: var(--text-2); }
.budget-total b { color: var(--text); font-size: var(--fs-body); }
.limits-list { display: flex; flex-direction: column; gap: var(--sp-2); }
.limit-row { display: flex; align-items: center; gap: var(--sp-3); }
.limit-row label { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: var(--fs-sub); }
.limit-row .field { width: 128px; flex: none; text-align: right; font-variant-numeric: tabular-nums; }

/* ============================ Дни рождения ============================ */

.feature {
  display: block; width: 100%; text-align: left; border: 0;
  background: var(--peach); color: var(--on-peach);
  border-radius: var(--r-card); padding: var(--sp-5);
  margin-bottom: var(--sp-3);
  transition: transform var(--dur) var(--ease);
}
.feature:active { transform: scale(0.99); }
.feature-kicker { display: flex; align-items: center; gap: 6px; margin: 0; font-size: var(--fs-caption); font-weight: 600; color: var(--on-peach-2); }
.feature-kicker .icon { width: 16px; height: 16px; }
.feature-name {
  margin: var(--sp-2) 0 0; font-family: var(--font-display); font-size: 26px; font-weight: 700;
  line-height: 1.15; overflow-wrap: anywhere;
}
.feature-date { margin: var(--sp-1) 0 0; font-size: var(--fs-body); }
.feature-date b { font-weight: 600; }
.feature-meta { margin: var(--sp-3) 0 0; font-size: var(--fs-sub); color: var(--on-peach-2); overflow-wrap: anywhere; }

.date-badge {
  width: 44px; flex: none; padding: 5px 0; border-radius: 12px;
  background: var(--accent-soft); color: var(--on-accent-soft);
  text-align: center; line-height: 1.1;
}
.date-badge b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.date-badge span { font-size: var(--fs-tiny); }
.date-badge.soon { background: var(--peach); color: var(--on-peach); }

/* ============================ Календарь ============================ */

.cal-card { padding: var(--sp-3); }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); row-gap: 2px; }
.cal-wd { text-align: center; font-size: var(--fs-tiny); font-weight: 600; color: var(--text-2); padding: var(--sp-1) 0 var(--sp-2); text-transform: uppercase; letter-spacing: 0.04em; }
.cal-day {
  min-height: 46px; border: 0; background: none; padding: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border-radius: 12px; color: var(--text);
  transition: background var(--dur) var(--ease);
}
.cal-num {
  width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center; font-size: var(--fs-body); font-variant-numeric: tabular-nums;
}
.cal-day.past .cal-num { color: var(--text-2); }
.cal-day[aria-current="date"] .cal-num { box-shadow: inset 0 0 0 1.5px var(--accent); font-weight: 700; color: var(--accent); }
.cal-day[aria-pressed="true"] .cal-num { background: var(--accent); color: var(--on-accent); font-weight: 700; box-shadow: none; }
.cal-dots { display: flex; gap: 3px; height: 5px; }
.cal-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.cal-dot.is-payment { background: none; box-shadow: inset 0 0 0 1.3px var(--accent); }
.cal-dot.is-birthday { border-radius: 1.5px; transform: rotate(45deg) scale(0.9); }

/* ============================ Заметки ============================ */

.notes-list { display: flex; flex-direction: column; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.note-card {
  display: flex; flex-direction: column; gap: 6px;
  width: 100%; text-align: left; border: 0;
  background: var(--surface); color: var(--text);
  border-radius: var(--r-card); padding: var(--sp-4);
  box-shadow: var(--shadow);
  transition: transform var(--dur) var(--ease);
}
.note-card:active { transform: scale(0.99); }
.note-card.is-pinned { box-shadow: var(--shadow), inset 3px 0 0 var(--accent); }
.note-card .tag { align-self: flex-start; }
.note-title { font-size: var(--fs-body); font-weight: 600; overflow-wrap: anywhere; }
.note-preview {
  margin: 0; font-size: var(--fs-sub); color: var(--text-2); white-space: pre-line; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.note-meta { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-caption); color: var(--text-2); }

.field-title { font-size: 20px; font-weight: 600; border-color: transparent; background: none; padding-left: var(--sp-1); }
.field-title:focus { box-shadow: none; border-color: transparent; }
.field-note { flex: 1; min-height: 220px; }
#note-pin[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }

/* ============================ Нижние панели ============================ */

.bottom-action {
  position: fixed; left: 0; right: 0; z-index: 5;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom));
  padding: var(--sp-3) var(--gutter);
  background: linear-gradient(to bottom, transparent, var(--bg) 35%);
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding: 0 var(--sp-1) var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tabbar button {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; background: none; padding: var(--sp-1) 0;
  color: var(--text-2);
}
.tab-icon {
  width: 48px; height: 28px; border-radius: var(--r-pill);
  display: grid; place-items: center;
  transition: background var(--dur) var(--ease);
}
.tab-label { font-size: var(--fs-tiny); line-height: 1.15; text-align: center; font-weight: 500; }
.tabbar button[aria-current="page"] { color: var(--accent); }
.tabbar button[aria-current="page"] .tab-icon { background: var(--accent-soft); color: var(--on-accent-soft); }
.tabbar button[aria-current="page"] .tab-label { font-weight: 700; }

/* ============================ Диалоги ============================ */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 20;
  background: var(--backdrop);
  display: flex; align-items: flex-end; justify-content: center;
  animation: backdrop-in var(--dur) var(--ease);
}
@keyframes backdrop-in { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 560px;
  max-height: calc(var(--vh, 100dvh) - 24px);
  display: flex; flex-direction: column;
  background: var(--bg);
  border-radius: 24px 24px 0 0;
  box-shadow: var(--shadow-sheet);
  animation: sheet-in 200ms var(--ease);
}
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0.6; } }
.sheet-tall { height: calc(var(--vh, 100dvh) - 24px); }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-3) 0 var(--gutter);
}
.sheet-head h2 { margin: 0; font-family: var(--font-display); font-size: 22px; font-weight: 700; overflow-wrap: anywhere; }
.sheet-body {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: var(--sp-4);
  padding: var(--sp-3) var(--gutter) var(--sp-4);
}
.sheet-foot {
  display: flex; gap: var(--sp-2); align-items: center;
  padding: var(--sp-3) var(--gutter) calc(var(--sp-3) + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg);
}
.sheet-foot .btn { min-height: var(--btn-h); }

.payment-only { display: none !important; }
.is-payment .payment-only { display: flex !important; }
.is-payment p.payment-only[hidden] { display: none !important; }

/* ============================ Знакомство ============================ */

.header-side { display: flex; align-items: center; gap: var(--sp-2); flex: none; }
.header-help { background: var(--surface); box-shadow: var(--shadow); color: var(--text-2); border-radius: 50%; width: 40px; height: 40px; }
.header-help .icon { width: 22px; height: 22px; }
/* Невидимое поле нажатия 44px вокруг круглой кнопки 40px */
.header-help { position: relative; }
.header-help::after { content: ''; position: absolute; inset: -2px; }

.guide-body { gap: 0; min-height: min(440px, calc(var(--vh, 100dvh) - 200px)); }
.guide-step { display: flex; flex-direction: column; gap: var(--sp-3); animation: guide-in 180ms var(--ease); }
@keyframes guide-in { from { opacity: 0; transform: translateX(12px); } }
@media (prefers-reduced-motion: reduce) { .guide-step { animation: none; } }
.guide-icon {
  width: 56px; height: 56px; border-radius: 18px;
  display: grid; place-items: center;
}
.guide-icon .icon { width: 28px; height: 28px; }
.guide-icon.tone-accent { background: var(--accent-soft); color: var(--on-accent-soft); }
.guide-icon.tone-peach { background: var(--peach); color: var(--on-peach); }
.guide-title { margin: 0; font-family: var(--font-display); font-size: 24px; font-weight: 700; overflow-wrap: anywhere; }
.guide-lead { margin: 0; color: var(--text-2); font-size: var(--fs-body); }
.guide-points { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: var(--sp-2); }
.guide-points li {
  position: relative; padding: var(--sp-3) var(--sp-3) var(--sp-3) calc(var(--sp-3) + 14px);
  background: var(--surface); border-radius: var(--r-control); box-shadow: var(--shadow);
  font-size: var(--fs-sub); line-height: 1.4;
}
.guide-points li::before {
  content: ''; position: absolute; left: var(--sp-3); top: calc(var(--sp-3) + 0.45em);
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
}
.guide-chat-label { margin: var(--sp-1) 0 var(--sp-2); font-size: var(--fs-caption); color: var(--text-2); }
.guide-chat-list { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.guide-chat-list code {
  padding: 6px 10px; border-radius: 10px;
  background: var(--surface); color: var(--text); border: 1px solid var(--line);
  font-family: inherit; font-size: var(--fs-sub); overflow-wrap: anywhere;
}
.guide-note { margin: 0; font-size: var(--fs-caption); color: var(--text-2); }

.guide-foot { flex-wrap: wrap; }
.guide-dots { display: flex; gap: 6px; flex: 1 0 100%; justify-content: center; padding-bottom: var(--sp-1); }
.guide-dots span { width: 6px; height: 6px; border-radius: 3px; background: var(--bar-muted); transition: width var(--dur) var(--ease); }
.guide-dots span.is-active { width: 18px; background: var(--accent); }
.guide-next { flex: 1; }

/* ============================ Узкие экраны ============================ */

@media (max-width: 359px) {
  :root { --fs-display: 28px; --fs-hero: 34px; }
  .tab-icon { width: 40px; }
  .field-day { width: 64px; }
  .field-year { width: 80px; }
  .limit-row .field { width: 108px; }
}

/* ============================ Спокойное движение ============================ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
