/* ColaBook — чёрно-белый, в духе iOS: светло-серый фон, белые группы, чёрные кнопки.
   Цвет только в иконках (--ic) и для «Просрочено» / «Удалить». */

:root {
  --bg: #F2F2F7;
  --side: #EBEBF0;
  --card: #FFFFFF;
  --tile-bg: #FFFFFF;
  --label: #000000;
  --secondary: rgba(60, 60, 67, 0.6);
  --tertiary: rgba(60, 60, 67, 0.3);
  --separator: rgba(60, 60, 67, 0.22);
  --fill: rgba(118, 118, 128, 0.12);
  --switch-off: rgba(120, 120, 128, 0.16);
  --seg-on: #FFFFFF;
  --ring: #C7C7CC;
  --bar: rgba(242, 242, 247, 0.86);
  --accent: #000000;
  --on-accent: #FFFFFF;
  --red: #E5342B;

  --gutter: 16px;
  --tabbar-h: calc(50px + env(safe-area-inset-bottom));
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Inter', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --side: #161618;
    --card: #1C1C1E;
    --tile-bg: #2C2C2E;
    --label: #FFFFFF;
    --secondary: rgba(235, 235, 245, 0.6);
    --tertiary: rgba(235, 235, 245, 0.3);
    --separator: rgba(84, 84, 88, 0.65);
    --fill: rgba(118, 118, 128, 0.24);
    --switch-off: rgba(120, 120, 128, 0.32);
    --seg-on: #636366;
    --ring: #48484A;
    --bar: rgba(10, 10, 12, 0.86);
    --accent: #FFFFFF;
    --on-accent: #000000;
    --red: #FF453A;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--label);
  font: 400 17px/1.3 var(--font);
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }
body:not([data-mode="tasks"]) .tasks-only,
body:not([data-mode="money"]) .money-only,
body:not([data-mode="debts"]) .debts-only,
body:not([data-mode="health"]) .health-only,
body[data-mode="debts"] .cat-nav,
body[data-mode="health"] .cat-nav { display: none !important; }

button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.spacer { flex: 1; }

.secondary { margin: 0; color: var(--secondary); font-size: 15px; line-height: 1.35; }
.form-error { margin: 8px 16px 0; color: var(--red); font-size: 15px; }
.form-error:empty { display: none; }

/* ---------- Кнопки ---------- */

.icon-btn {
  display: inline-grid; place-items: center; flex: none;
  width: 44px; height: 44px; padding: 0;
  border: 0; border-radius: 22px; background: none; color: var(--label);
}
.icon-btn svg { width: 24px; height: 24px; stroke-width: 1.7; }
.icon-btn:active, .link-btn:active, .back-btn:active { opacity: 0.5; }

.link-btn {
  flex: none; padding: 8px 0 8px 8px;
  border: 0; background: none; color: var(--label); font-size: 17px; font-weight: 600;
}

.btn-large {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 20px;
  border: 0; border-radius: 14px; background: var(--accent); color: var(--on-accent);
  font-size: 17px; font-weight: 600;
}
.btn-large:active { opacity: 0.8; }
.btn-large svg { stroke-width: 2.4; }
.btn-block { width: 100%; }

/* ---------- Группы в стиле настроек iOS ---------- */

.group {
  margin: 0; padding: 0; list-style: none;
  background: var(--card); border-radius: 12px; overflow: hidden;
}
.group > * { position: relative; }
/* Разделитель начинается от текста, а не от края — как в iOS. */
.group > * + *::before {
  content: ''; position: absolute; top: 0; right: 0; left: var(--inset, 16px);
  border-top: 0.5px solid var(--separator);
}
.group.with-icons { --inset: 57px; }

.group-header { margin: 28px 16px 7px; font-size: 13px; font-weight: 400; color: var(--secondary); }
.group-footer { margin: 7px 16px 0; font-size: 13px; line-height: 1.35; color: var(--secondary); }
.group-footer:empty { display: none; }

.group-input {
  display: block; width: 100%; min-height: 44px; padding: 11px 16px;
  border: 0; background: transparent; font-size: 17px; outline: none; resize: none;
}
.group-input::placeholder, .row-input::placeholder { color: var(--tertiary); }
.title-input { font-weight: 600; }

.row {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 44px; padding: 6px 16px;
  border: 0; background: none; text-align: left; font-size: 17px;
}
button.row:active { background: var(--fill); }
.row-text { flex: 1; min-width: 0; }
.row-value { color: var(--secondary); }
.row-action { color: var(--label); font-weight: 500; }
.row-action svg { width: 18px; height: 18px; stroke-width: 2.4; }
.row-danger { justify-content: center; color: var(--red); }

/* Цветная иконка без подложки — единственное место, где в интерфейсе есть цвет. */
.row-icon { display: grid; place-items: center; flex: none; width: 29px; height: 29px; color: var(--ic, var(--secondary)); }
.row-icon svg { width: 22px; height: 22px; stroke-width: 1.9; }

.row-select {
  min-width: 0; max-width: 58%; padding: 4px 18px 4px 0;
  border: 0; background: none; color: var(--secondary); font-size: 17px;
  text-align: right; text-align-last: right; appearance: none; outline: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 16'%3E%3Cpath d='M2 6l3-3 3 3M2 10l3 3 3-3' fill='none' stroke='%238E8E93' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right center; background-size: 9px 14px;
}
.row-select:focus-visible { outline: 2px solid var(--accent); border-radius: 6px; }
.row-select option { color: initial; }

.row-input {
  flex: 1; width: 0; min-width: 0; padding: 4px 0;
  border: 0; background: none; font-size: 17px; outline: none;
}

/* Дата и время — серые «таблетки», как компактный выбор даты в iOS. */
.pill {
  padding: 6px 10px; border: 0; border-radius: 8px;
  background: var(--fill); font-size: 17px; font-variant-numeric: tabular-nums; outline: none;
}
.pill:focus-visible { outline: 2px solid var(--accent); }
.pill::-webkit-calendar-picker-indicator { display: none; }

.switch {
  appearance: none; position: relative; flex: none;
  width: 51px; height: 31px; margin: 0;
  border-radius: 999px; background: var(--switch-off); cursor: pointer;
  transition: background-color 0.2s;
}
.switch::before {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 27px; height: 27px; border-radius: 50%; background: #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), 0 3px 1px rgba(0, 0, 0, 0.06);
  transition: transform 0.2s;
}
.switch:checked { background: var(--accent); }
.switch:checked::before { transform: translateX(20px); }
@media (prefers-color-scheme: dark) { .switch:checked::before { background: #000; } }

.delete-btn { display: grid; place-items: center; flex: none; width: 32px; height: 32px; padding: 0; border: 0; background: none; color: var(--red); }
.delete-btn svg { width: 22px; height: 22px; }

/* ---------- Переключатель сегментов ---------- */

.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  padding: 2px; border-radius: 9px; background: var(--fill);
}
.segmented > button, .segmented > label {
  position: relative; display: grid; place-items: center;
  min-height: 28px; padding: 3px 8px;
  border: 0; border-radius: 7px; background: none;
  font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer;
}
.segmented > button[aria-pressed="true"], .segmented > label:has(input:checked) {
  background: var(--seg-on); font-weight: 600;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12), 0 3px 1px rgba(0, 0, 0, 0.04);
}
.segmented input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.segmented > label:has(input:focus-visible) { outline: 2px solid var(--accent); }
.segmented-compact { flex: none; }
.segmented-compact > label { min-width: 44px; }

/* ---------- Вход ---------- */

.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px var(--gutter); }
.auth-card { width: min(360px, 100%); display: grid; gap: 16px; text-align: center; }
.app-icon { justify-self: center; }
.auth-card h1 { margin: 4px 0 -8px; font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.auth-card .group { text-align: left; }
.auth-card .form-error { margin: -4px 0 0; }

/* ---------- Каркас: телефон ---------- */

.shell { min-height: 100dvh; }
.side { display: none; }

.main { padding-bottom: calc(var(--tabbar-h) + 84px); }

.nav { padding: env(safe-area-inset-top) 8px 0 var(--gutter); }
.nav-row { display: flex; align-items: center; gap: 4px; min-height: 44px; }
.back-btn {
  display: inline-flex; align-items: center; gap: 2px; min-height: 44px; padding: 0 8px 0 0; margin-left: -6px;
  border: 0; background: none; color: var(--label); font-size: 17px;
}
.back-btn svg { width: 24px; height: 24px; stroke-width: 2.2; }

.large-title {
  display: flex; align-items: center; gap: 10px;
  margin: 0; font-size: 34px; line-height: 41px; font-weight: 700; letter-spacing: -0.02em;
}
.large-title .cat-glyph svg { width: 30px; height: 30px; stroke-width: 1.9; }
.subtitle { margin: 0 0 4px; font-size: 15px; color: var(--secondary); }
.subtitle:empty { display: none; }

.cat-select { position: relative; display: inline-flex; }
.cat-select select {
  appearance: none; max-width: 52vw; min-height: 32px; padding: 0 30px 0 12px;
  border: 0; border-radius: 999px; background: var(--fill);
  color: var(--label); font-size: 15px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cat-select select option { font-weight: 400; }
.cat-select::after {
  content: ''; position: absolute; right: 13px; top: 11px; pointer-events: none;
  width: 6px; height: 6px; border: solid var(--label); border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.seg-bar {
  position: sticky; top: 0; z-index: 5;
  display: grid; gap: 8px;
  padding: 10px var(--gutter);
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
}
.period-nav { display: flex; align-items: center; justify-content: space-between; margin: -6px -10px -8px; }
.period-nav span { font-size: 15px; font-weight: 600; }
.period-nav .icon-btn svg { width: 20px; height: 20px; stroke-width: 2.2; }
.period-range { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; font-size: 15px; color: var(--secondary); }
.period-range label { display: inline-flex; align-items: center; gap: 8px; }
.period-range .pill { font-size: 15px; color: var(--label); }

.notice {
  display: flex; align-items: center; gap: 12px;
  margin: 4px var(--gutter) 8px; padding: 10px 16px;
  background: var(--card); border-radius: 12px;
}
.notice p { flex: 1; margin: 0; font-size: 15px; line-height: 1.3; }

/* Иконка раздела: цветной контур, без подложки. */
.cat-glyph { display: inline-grid; place-items: center; flex: none; color: var(--ic, var(--secondary)); }
.cat-glyph svg { width: 18px; height: 18px; stroke-width: 2; }

/* ---------- Списки ---------- */

.list { padding: 4px 0 16px; }
.section-title { margin: 24px 20px 8px; font-size: 20px; line-height: 25px; font-weight: 700; letter-spacing: -0.015em; }
.section-title.late { color: var(--red); }
.list-header { margin: 24px 20px 7px; font-size: 13px; color: var(--secondary); }
.list > :first-child { margin-top: 8px; }
.card + .card { margin-top: 28px; }

.card { margin: 0 var(--gutter); background: var(--card); border-radius: 12px; overflow: hidden; }

.empty { margin: 72px 32px; text-align: center; font-size: 15px; line-height: 1.4; color: var(--secondary); }
.empty b { display: block; margin-bottom: 4px; font-size: 20px; font-weight: 600; color: var(--label); }
.card-empty { padding: 14px 16px; font-size: 15px; color: var(--secondary); }

/* Задача */
.task { display: flex; align-items: flex-start; }
.check {
  display: grid; place-items: center; flex: none;
  width: 24px; height: 24px; margin: 11px 12px 0 16px; padding: 0;
  border: 1.5px solid var(--ring); border-radius: 50%;
  background: none; color: transparent;
  transition: background-color 0.15s, border-color 0.15s;
}
.check svg { width: 14px; height: 14px; stroke-width: 3; }
.check:hover { border-color: var(--label); }
.task.is-completing .check, .task.is-done .check { border-color: var(--accent); background: var(--accent); color: var(--on-accent); }

.task-body {
  display: block; flex: 1; min-width: 0; padding: 12px 16px 12px 0;
  border: 0; background: none; text-align: left;
}
.task + .task .task-body { box-shadow: inset 0 0.5px 0 var(--separator); }
.task-body:focus-visible { outline-offset: -2px; border-radius: 8px; }

.task-title { display: block; font-size: 17px; line-height: 22px; overflow-wrap: anywhere; transition: color 0.15s; }
.task.is-completing .task-title, .task.is-done .task-title { color: var(--secondary); }
.prio { margin-right: 4px; color: var(--red); font-weight: 700; }

.task-notes {
  display: block; margin-top: 2px; font-size: 15px; line-height: 20px; color: var(--secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.task-meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px;
  margin-top: 2px; font-size: 15px; line-height: 20px; color: var(--secondary);
}
.task-meta > span { display: inline-flex; align-items: center; gap: 4px; }
.task-meta .late { color: var(--red); }
.task-meta svg { width: 14px; height: 14px; stroke-width: 2.2; }
.task-meta .cat-glyph svg { width: 15px; height: 15px; }

/* ---------- Расходы ---------- */

.sum-card { padding: 14px 16px; }
.sum-label { font-size: 13px; color: var(--secondary); }
.sum-value { margin-top: 2px; font-size: 30px; line-height: 36px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.sum-sub { margin-top: 4px; font-size: 15px; color: var(--secondary); }

.tree-row {
  position: relative; display: flex; align-items: center; gap: 10px;
  width: 100%; min-height: 44px; padding: 8px 16px 8px calc(16px + var(--depth, 0) * 22px);
  border: 0; background: none; text-align: left; font-size: 17px;
}
.tree-row:active { background: var(--fill); }
.card > * + .tree-row::before {
  content: ''; position: absolute; top: 0; right: 0; left: calc(16px + var(--depth, 0) * 22px);
  border-top: 0.5px solid var(--separator);
}
.tree-row[data-depth="0"] .tree-name { font-weight: 600; }
.tree-row[data-depth="2"] { font-size: 15px; color: var(--secondary); }
.tree-main { display: block; flex: 1; min-width: 0; }
.tree-line { display: flex; align-items: baseline; gap: 8px; }
.tree-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.amount { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tree-row[data-depth="1"] .amount, .tree-row[data-depth="2"] .amount { font-weight: 400; }
.chev { display: grid; flex: none; color: var(--tertiary); }
.chev svg { width: 14px; height: 14px; stroke-width: 2.4; }
.share { display: block; height: 4px; margin-top: 6px; border-radius: 2px; background: var(--fill); overflow: hidden; }
.share i { display: block; height: 100%; border-radius: 2px; background: var(--label); }

.entry {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 60px; padding: 0 0 0 16px;
  border: 0; background: none; text-align: left;
}
.entry:active { background: var(--fill); }
.entry-thumb {
  display: grid; place-items: center; flex: none; width: 40px; height: 40px;
  border-radius: 9px; background: var(--fill); overflow: hidden; color: var(--ic, var(--secondary));
}
.entry-thumb img { width: 100%; height: 100%; object-fit: cover; }
.entry-thumb svg { width: 20px; height: 20px; }
.entry-line { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; align-self: stretch; padding: 10px 16px 10px 0; }
.entry + .entry .entry-line { box-shadow: inset 0 0.5px 0 var(--separator); }
.entry-main { flex: 1; min-width: 0; }
.entry-title { display: block; font-size: 17px; line-height: 22px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-sub { display: block; margin-top: 2px; font-size: 15px; line-height: 20px; color: var(--secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .amount { font-size: 17px; }

/* ---------- Долги и копилка ---------- */

.debt-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 8px var(--gutter) 0; }
.debt-tile {
  display: grid; gap: 2px; align-content: start; min-width: 0; padding: 10px 12px;
  border: 0; border-radius: 12px; background: var(--card); text-align: left; color: var(--label);
}
.debt-tile svg { width: 22px; height: 22px; stroke-width: 2; color: var(--ic); margin-bottom: 4px; }
.debt-tile .tile-label { font-size: 13px; color: var(--secondary); }
.debt-tile .tile-sum { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.debt-tile[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.debt-tile[aria-pressed="true"] svg, .debt-tile[aria-pressed="true"] .tile-label { color: var(--on-accent); }

.debt { position: relative; display: flex; align-items: center; }
.card > .debt + .debt::before {
  content: ''; position: absolute; top: 0; right: 0; left: 16px; border-top: 0.5px solid var(--separator);
}
.debt-main { display: block; flex: 1; min-width: 0; padding: 11px 16px; border: 0; background: none; text-align: left; }
.debt-main:active { background: var(--fill); }
.debt-name { flex: 1; min-width: 0; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.debt-main .amount { font-size: 17px; }
.debt-main .entry-sub .late { color: var(--red); }
/* В долгах и курсах строки бывают длинными — пусть переносятся, а не обрезаются. */
.debt-main .entry-sub { white-space: normal; }
.debt-main .share { margin-top: 8px; }
.debt.is-closed .debt-name, .debt.is-closed .amount { color: var(--secondary); }
.share-btn { display: grid; place-items: center; flex: none; width: 44px; height: 44px; margin-right: 6px; padding: 0; border: 0; border-radius: 22px; background: none; color: var(--label); }
.share-btn svg { width: 21px; height: 21px; stroke-width: 1.9; }
.share-btn:active { background: var(--fill); }
.goal-plan { display: block; margin-top: 6px; font-size: 13px; color: var(--secondary); }
.goal-plan.done { color: var(--label); font-weight: 600; }

/* Здоровье: время приёма в карточке курса и отметки на сегодня */
.time-row .pill { font-size: 17px; }
.dose .task-title .who { color: var(--secondary); }
.course-day { flex: none; font-size: 15px; color: var(--secondary); white-space: nowrap; }
.entry-sub.low { color: var(--red); }

/* Строки возвратов и пополнений */
.move-row { gap: 8px; }
.move-row .pill { font-size: 15px; }
.move-row .sign { width: 12px; text-align: center; font-weight: 700; color: var(--secondary); }

/* Строки сумм в карточке записи */
.item-row { gap: 8px; }
.item-row .row-input { flex: 1.4; }
.amount-input {
  width: 0; flex: 1; min-width: 70px; padding: 4px 0;
  border: 0; background: none; font-size: 17px; font-weight: 600; text-align: right;
  font-variant-numeric: tabular-nums; outline: none;
}
.amount-input::placeholder { color: var(--tertiary); font-weight: 400; }
.currency { color: var(--secondary); }
.total-row b { font-size: 17px; font-variant-numeric: tabular-nums; }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.photo, .photo-add {
  position: relative; aspect-ratio: 1; padding: 0; overflow: hidden;
  border: 0; border-radius: 10px; background: var(--card);
}
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-add { display: grid; place-items: center; align-content: center; gap: 4px; color: var(--label); font-size: 13px; font-weight: 500; cursor: pointer; }
.photo-add svg { width: 24px; height: 24px; stroke-width: 1.8; }
.photo-add input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.photo-add:focus-within { outline: 2px solid var(--accent); }

.lightbox {
  width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0;
  border: 0; background: #000; color: #fff;
}
.lightbox[open] { display: flex; flex-direction: column; }
.lightbox img { flex: 1; min-height: 0; width: 100%; object-fit: contain; }
.lightbox-bar { display: flex; justify-content: space-between; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
.lightbox .bar-btn { color: #fff; }
.lightbox #lightbox-delete { color: #FF453A; }

/* Выбор иконки раздела */
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 4px; padding: 8px; margin-top: 4px; }
.icon-grid::before, .color-row::before { display: none; }
.icon-grid > * + *::before, .color-row > * + *::before { display: none; }
.icon-choice {
  display: grid; place-items: center; aspect-ratio: 1; padding: 0;
  border: 0; border-radius: 10px; background: none; color: var(--ic);
}
.icon-choice svg { width: 26px; height: 26px; stroke-width: 1.8; }
.icon-choice[aria-checked="true"] { background: var(--fill); box-shadow: inset 0 0 0 2px var(--label); }
.color-row { display: flex; flex-wrap: wrap; gap: 12px; padding: 14px 16px; }
.color-choice { width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%; background: var(--ic); }
.color-choice[aria-checked="true"] { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--label); }

/* Дерево разделов в настройках */
.cat-row { padding-left: calc(10px + var(--depth, 0) * 24px); gap: 8px; }
.cat-icon-btn { display: grid; place-items: center; flex: none; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 8px; background: none; color: var(--ic); }
.cat-icon-btn svg { width: 22px; height: 22px; stroke-width: 1.9; }
.cat-icon-btn:active { background: var(--fill); }
.add-sub-btn { display: grid; place-items: center; flex: none; width: 32px; height: 32px; padding: 0; border: 0; background: none; color: var(--secondary); }
.add-sub-btn svg { width: 20px; height: 20px; stroke-width: 2.2; }
#cat-group > .cat-row + *::before, #cat-group > .cat-row::before { left: calc(54px + var(--depth, 0) * 24px); }

/* ---------- Нижние панели: телефон ---------- */

.composer {
  position: fixed; left: 0; right: 0; bottom: var(--tabbar-h); z-index: 10;
  padding: 8px 8px 8px 4px;
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--separator);
}
.composer.money-only, .composer.debts-only, .composer.health-only { padding: 8px var(--gutter); }
.composer .btn-large { min-height: 44px; border-radius: 12px; }
.composer-row { display: flex; align-items: center; gap: 2px; }
.composer input {
  flex: 1; min-width: 0; height: 38px; padding: 0 16px;
  border: 0.5px solid var(--separator); border-radius: 19px; background: var(--card);
  font-size: 17px; outline: none;
}
.composer input::placeholder { color: var(--tertiary); }
.composer input:focus { border-color: var(--label); }
.send {
  display: grid; place-items: center; flex: none;
  width: 34px; height: 34px; margin-left: 6px; padding: 0;
  border: 0; border-radius: 50%; background: var(--accent); color: var(--on-accent);
}
.send svg { width: 18px; height: 18px; stroke-width: 2.6; }
.send:disabled { background: var(--fill); color: var(--tertiary); cursor: default; }
.composer-preview { display: flex; flex-wrap: wrap; gap: 4px 12px; padding: 0 12px 8px 50px; font-size: 13px; color: var(--secondary); }
.composer-preview:empty { display: none; }
.composer-preview b { font-weight: 600; color: var(--label); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  height: var(--tabbar-h); padding-bottom: env(safe-area-inset-bottom);
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--separator);
}
.tabbar button {
  display: grid; justify-items: center; align-content: center; gap: 2px;
  border: 0; background: none; color: var(--tertiary); font-size: 10px; font-weight: 500;
}
.tabbar svg { width: 26px; height: 26px; stroke-width: 1.8; }
.tabbar button[aria-pressed="true"] { color: var(--label); }

/* ---------- Окна ---------- */

.sheet {
  width: min(540px, calc(100vw - 32px)); max-width: none; max-height: min(88dvh, 820px);
  padding: 0; border: 0; border-radius: 14px; overflow: hidden;
  background: var(--bg); color: var(--label);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
}
.sheet::backdrop, .lightbox::backdrop { background: rgba(0, 0, 0, 0.35); }
.sheet > form, .sheet-inner { display: flex; flex-direction: column; max-height: min(88dvh, 820px); }

.sheet-bar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; flex: none;
  min-height: 56px; padding: 0 8px;
}
.sheet-bar h2 { max-width: 52vw; margin: 0; overflow: hidden; font-size: 17px; font-weight: 600; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.sheet-bar h2:focus { outline: none; }
.bar-btn { justify-self: start; padding: 10px 8px; border: 0; background: none; color: var(--label); font-size: 17px; }
.bar-btn.strong { justify-self: end; font-weight: 700; }
.bar-btn:disabled { color: var(--tertiary); cursor: default; }

/* Обычный блок, а не сетка: в сетке группы с overflow: hidden сжимались по высоте и обрезали нижние строки. */
.sheet-body { display: block; min-width: 0; overflow-y: auto; padding: 0 var(--gutter) calc(28px + env(safe-area-inset-bottom)); }
.sheet-body > .group, .sheet-body > .photo-grid { margin-top: 28px; }
.sheet-body > :first-child { margin-top: 4px; }
.sheet-body > .group-header + *, .sheet-body > .seg-wide + * { margin-top: 0; }
.seg-wide { margin-bottom: 20px; }
.seg-wide > label { min-height: 34px; font-size: 15px; }
#cat-group { --inset: 54px; }

@media (max-width: 599px) {
  .sheet {
    width: 100vw; margin: auto 0 0;
    border-radius: 12px 12px 0 0; max-height: 94dvh;
  }
  .sheet > form, .sheet-inner { max-height: 94dvh; }
}

@media (prefers-reduced-motion: no-preference) {
  .sheet[open] { animation: sheet-in 0.25s cubic-bezier(0.2, 0.8, 0.2, 1); }
  @keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }
}

/* ---------- Сообщение ---------- */

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 20;
  bottom: calc(var(--tabbar-h) + 72px);
  display: flex; align-items: center; gap: 16px;
  width: max-content; max-width: calc(100vw - 32px);
  padding: 12px 16px; border-radius: 14px;
  background: rgba(28, 28, 30, 0.94); color: #fff; font-size: 15px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}
.toast button { padding: 4px; border: 0; background: none; color: #fff; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Каркас: компьютер ---------- */

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 300px minmax(0, 1fr); }
  .tabbar { display: none; }

  .side {
    display: flex; flex-direction: column; gap: 12px;
    height: 100dvh; overflow-y: auto; padding: 20px 16px;
    background: var(--side); border-right: 0.5px solid var(--separator);
  }
  .mode-switch > button { min-height: 32px; padding: 3px 4px; font-size: 13px; }
  .tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .tile {
    display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 8px;
    padding: 10px 12px; border: 0; border-radius: 12px;
    background: var(--tile-bg); text-align: left; color: var(--label);
  }
  .tile svg { width: 26px; height: 26px; stroke-width: 1.9; color: var(--ic); }
  .tile-count { justify-self: end; font-size: 24px; line-height: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
  .tile-name { grid-column: 1 / -1; font-size: 15px; font-weight: 600; color: var(--secondary); }
  .tile[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
  .tile[aria-pressed="true"] svg, .tile[aria-pressed="true"] .tile-name { color: var(--on-accent); }

  .side-heading { margin: 12px 8px -4px; font-size: 13px; font-weight: 600; color: var(--secondary); }
  .side-list { background: var(--tile-bg); border-radius: 12px; overflow: hidden; }
  .side-list button {
    position: relative; display: flex; align-items: center; gap: 10px;
    width: 100%; min-height: 40px; padding: 0 14px 0 calc(12px + var(--depth, 0) * 20px);
    border: 0; background: none; text-align: left; font-size: 15px;
  }
  .side-list button + button::before {
    content: ''; position: absolute; top: 0; right: 0; left: calc(42px + var(--depth, 0) * 20px); border-top: 0.5px solid var(--separator);
  }
  .side-list .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .side-list .count { color: var(--secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }
  .side-list button[aria-pressed="true"] { background: var(--fill); font-weight: 600; }

  .main { display: flex; flex-direction: column; height: 100dvh; overflow-y: auto; padding-bottom: 0; }
  .main > * { max-width: 760px; }
  .nav { padding: 12px 24px 0 32px; }
  .cat-select, .seg-bar.tasks-only { display: none !important; }
  .seg-bar { padding: 10px 32px; background: var(--bg); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .subtitle { margin-bottom: 8px; }
  .notice { margin: 8px 32px; }
  .list { flex: 1; padding: 0 16px 24px; }
  .composer {
    position: sticky; left: auto; right: auto; bottom: 0;
    padding: 12px 32px 20px 24px; border-top: 0; background: var(--bg);
    -webkit-backdrop-filter: none; backdrop-filter: none;
  }
  .composer.money-only, .composer.debts-only, .composer.health-only { padding: 12px 32px 20px; }
  .composer-preview { padding-left: 62px; }
  .toast { left: calc(50% + 150px); bottom: 96px; }
  .debt-tiles { margin: 8px 16px 0; gap: 10px; }
  .debt-tile { padding: 12px 14px; }
  .debt-tile .tile-sum { font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .switch, .switch::before, .check, .task-title { transition: none; }
}
