/* Тема в духе Obsidian: тёмная база, фиолетовый акцент, карточки-заметки,
   callout-блоки с цветной левой границей, моноширинные цифры. */
:root {
  --bg: #1e1e1e;
  --bg-alt: #161616;
  --bg-sec: #242424;
  --bg-sec-alt: #1a1a1a;
  --bg-hover: #2a2a2a;
  --border: #383838;
  --border-soft: #2c2c2c;
  --text: #dadada;
  --text-muted: #9a9a9a;
  --text-faint: #6a6a6a;
  --accent: #7f6df2;
  --accent-2: #a882ff;
  --accent-soft: rgba(127, 109, 242, .14);
  --green: #4caf7d;
  --red: #e05561;
  --orange: #e0a355;
  --blue: #5a9ded;
  --gold: #d4a52a;
  --shadow: 0 8px 32px rgba(0, 0, 0, .45);
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  --mono: "SF Mono", ui-monospace, "JetBrains Mono", "Cascadia Code", Consolas, monospace;
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --tabbar-h: 64px;
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --bg-alt: #f6f6f6;
  --bg-sec: #f2f3f5;
  --bg-sec-alt: #ebebeb;
  --bg-hover: #e9e9e9;
  --border: #ddd;
  --border-soft: #e6e6e6;
  --text: #222;
  --text-muted: #5c5c5c;
  --text-faint: #999;
  --accent: #6c58e6;
  --accent-2: #7f6df2;
  --accent-soft: rgba(108, 88, 230, .1);
  --shadow: 0 8px 32px rgba(0, 0, 0, .12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  overscroll-behavior-y: none;
}

.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- каркас ---------- */
.app { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }

.titlebar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg-alt) 88%, transparent);
  backdrop-filter: blur(14px) saturate(1.2);
  border-bottom: 1px solid var(--border-soft);
}

.crumbs { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 13px; }
.vault { color: var(--text-faint); flex: none; }
.crumb-sep { width: 13px; height: 13px; color: var(--text-faint); }
.crumb-title { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumb-title.swap { animation: crumb-swap .32s var(--ease-out); }
@keyframes crumb-swap { from { opacity: 0; transform: translateY(-6px); } }

.titlebar-actions { display: flex; gap: 8px; }

.content {
  flex: 1;
  padding: 16px 16px calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom));
  max-width: 640px; width: 100%; margin: 0 auto;
}

/* ---------- нижние вкладки ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; align-items: stretch;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--bg-alt) 92%, transparent);
  backdrop-filter: blur(16px) saturate(1.2);
  border-top: 1px solid var(--border-soft);
}

.tab {
  position: relative; z-index: 1;
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 0; background: none; cursor: pointer; padding: 0;
  color: var(--text-faint); font-family: inherit; font-size: 10.5px; font-weight: 500;
  transition: color .25s var(--ease-out);
}
.tab .ic { transition: transform .4s var(--ease-spring); }
.tab.active { color: var(--accent-2); }
.tab.active .ic { animation: tab-pop .45s var(--ease-spring); }
.tab:active .ic { transform: scale(.86); }
@keyframes tab-pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.28) translateY(-2px); }
  100% { transform: scale(1); }
}

/* «таблетка» под активной вкладкой едет за выбором.
   Высота подобрана так, чтобы подложка накрывала и иконку, и подпись целиком. */
.tab-pill {
  position: absolute; top: 8px; height: 50px; z-index: 0;
  border-radius: 10px; background: var(--accent-soft);
  transition: transform .42s var(--ease-spring), width .42s var(--ease-spring), opacity .2s;
  pointer-events: none;
}

/* ---------- карточки-заметки ---------- */
.card {
  background: var(--bg-sec);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-title { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-faint); margin: 0; }

/* заголовок как в заметке Obsidian: # с приглушённой решёткой */
.h-note { display: flex; align-items: baseline; gap: 8px; margin: 22px 2px 10px; font-size: 17px; font-weight: 650; }
.h-note::before { content: "#"; color: var(--accent); opacity: .55; font-family: var(--mono); font-weight: 500; }

/* callout — фирменный блок Obsidian */
.callout {
  display: flex; gap: 10px;
  border-left: 3px solid var(--c, var(--accent));
  background: color-mix(in srgb, var(--c, var(--accent)) 9%, transparent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 12px 14px; margin-bottom: 12px;
  font-size: 14px;
}
.callout .ic { color: var(--c, var(--accent)); margin-top: 1px; }
.callout b { color: var(--c, var(--accent)); }
.callout.warn { --c: var(--orange); }
.callout.danger { --c: var(--red); }
.callout.ok { --c: var(--green); }

/* ---------- типографика чисел ---------- */
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.hero-balance { font-size: 34px; font-weight: 700; margin: 2px 0 4px; }
.hero-balance.pos { color: var(--green); }
.hero-balance.neg { color: var(--red); }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: 13px; }
.tiny { font-size: 11.5px; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--bg-sec-alt); border: 1px solid var(--border-soft); border-radius: var(--radius-sm); padding: 12px; }
.tile .label { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .05em; }
.tile .val { font-size: 18px; font-weight: 650; margin-top: 4px; }
.tile .val.inc { color: var(--green); }
.tile .val.exp { color: var(--red); }

/* ---------- кнопки ---------- */
.btn {
  position: relative; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); background: var(--bg-sec-alt); color: var(--text);
  border-radius: var(--radius-sm); padding: 11px 16px;
  font-family: inherit; font-size: 14px; font-weight: 550; cursor: pointer;
  transition: transform .12s var(--ease-out), background .2s, border-color .2s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:disabled { opacity: .5; }
.btn.ghost { background: none; border-color: var(--border); }
.btn.danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, transparent); background: none; }
.btn.wide { width: 100%; }
.btn:disabled { cursor: default; }

/* «Новая цель/лимит/напоминание» — пунктирная, чтобы не сливаться со сплошной
   фиолетовой «Пополнить» в карточке прямо над ней */
.btn.add-new {
  background: none; border-style: dashed; border-color: var(--accent);
  color: var(--accent-2); margin-top: 4px;
}

/* ряд действий в карточке: иконки одной высоты с основной кнопкой */
.actions { display: flex; gap: 8px; margin-top: 14px; }
.actions .btn { height: 44px; padding: 0 16px; }
.actions .icon-btn { width: 44px; height: 44px; }
.actions .icon-btn .ic { width: 18px; height: 18px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-soft); background: var(--bg-sec-alt);
  color: var(--text-muted); cursor: pointer;
  transition: transform .12s var(--ease-out), color .2s, background .2s;
}
.icon-btn:active { transform: scale(.9); }
.icon-btn.accent { color: var(--accent-2); }

/* волна по нажатию */
.ripple { position: absolute; border-radius: 50%; transform: scale(0); background: rgba(255, 255, 255, .3); pointer-events: none; animation: ripple .55s var(--ease-out) forwards; }
@keyframes ripple { to { transform: scale(2.6); opacity: 0; } }

/* ---------- поля ввода ---------- */
.field { margin-bottom: 14px; }
/* align-items:end — чтобы поля выровнялись по нижнему краю, даже если подпись
   в одной колонке переносится на 2 строки, а в другой — на 1 */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; }
.two-col .field { margin-bottom: 14px; }
.two-col .field label { min-height: 2.2em; }
.field label { display: block; font-size: 12px; color: var(--text-faint); margin-bottom: 6px; letter-spacing: .04em; text-transform: uppercase; }
.input {
  width: 100%; padding: 12px 14px;
  background: var(--bg-alt); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-family: inherit; font-size: 15px;
  transition: border-color .2s, box-shadow .25s;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.amount { font-family: var(--mono); font-size: 26px; font-weight: 650; text-align: center; padding: 16px; letter-spacing: -.02em; }
select.input { appearance: none; }
/* выпадающий фильтр доски (юрлицо/счёт): свой шеврон вместо нативной стрелки */
.select-filter {
  cursor: pointer; padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236a6a6a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
/* кнопка-триггер кастомного выбора юрлица: текст слева, длинное имя — с многоточием */
.select-filter.ent-picker {
  display: block; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  height: 46px; line-height: 22px;
}
/* строки списка в шторке выбора юрлица */
.ent-pick .sel { margin-left: auto; color: var(--accent); width: 18px; height: 18px; }
.ent-pick.on { border-color: color-mix(in srgb, var(--accent) 45%, transparent); background: var(--accent-soft); }
.ent-pick.on span { color: var(--accent-2); font-weight: 600; }
/* без сброса appearance webview даёт полю даты собственную ширину — оно вылезает
   за карточку и не совпадает с «Названием» и «Суммой» */
.input[type="date"] { appearance: none; -webkit-appearance: none; min-width: 0; max-width: 100%; height: 46px; font-family: var(--mono); }
.input[type="date"]::-webkit-date-and-time-value { text-align: left; }
.input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(.7); cursor: pointer; }

/* переключатель доход/расход */
.segmented { position: relative; display: flex; background: var(--bg-alt); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 3px; margin-bottom: 16px; }
.segmented .seg-thumb {
  position: absolute; top: 3px; bottom: 3px; left: 3px; width: calc(50% - 3px);
  border-radius: 6px; background: var(--seg-color, var(--accent));
  transition: transform .38s var(--ease-spring), background .3s;
}
.segmented button {
  position: relative; z-index: 1; flex: 1; padding: 9px; border: 0; background: none; cursor: pointer;
  font-family: inherit; font-size: 14px; font-weight: 600; color: var(--text-muted);
  transition: color .25s;
}
.segmented button.on { color: #fff; }

/* чипы категорий */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 13px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg-alt); color: var(--text-muted);
  font-family: inherit; font-size: 13.5px;
  transition: transform .14s var(--ease-spring), background .2s, color .2s, border-color .2s;
  animation: chip-in .35s var(--ease-out) backwards;
  animation-delay: calc(var(--i, 0) * 35ms);
}
.chip:active { transform: scale(.93); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-2); }
@keyframes chip-in { from { opacity: 0; transform: scale(.8); } }

/* компактная «+» рядом с топ-8 категорий */
.chip.add { display: inline-flex; align-items: center; justify-content: center; width: 36px; padding: 8px; border-style: dashed; color: var(--accent-2); }
.chip.add .ic { width: 16px; height: 16px; }

/* периоды: 4 в ряд, «Не выбрано» — во всю ширину под ними */
.chips.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.chips.grid4 .chip { padding: 9px 4px; text-align: center; }
.chips.grid4 .chip.wide { grid-column: 1 / -1; }

/* ---------- прогресс ---------- */
.bar { position: relative; height: 8px; border-radius: 999px; background: var(--bg-alt); overflow: hidden; border: 1px solid var(--border-soft); }
.bar > i {
  display: block; height: 100%; border-radius: 999px; width: 0;
  background: var(--c, var(--accent));
  transition: width 1s var(--ease-out);
}
/* блик, пробегающий по заполненной части */
.bar > i::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .28), transparent);
  transform: translateX(-100%);
  animation: sheen 2.2s ease-in-out .6s infinite;
}
@keyframes sheen { to { transform: translateX(100%); } }

.row-line { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 7px; }
.row-line .name { font-weight: 550; }

/* ---------- списки ---------- */
.list { display: flex; flex-direction: column; }
.item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 4px; border-bottom: 1px solid var(--border-soft);
  animation: item-in .4s var(--ease-out) backwards;
  animation-delay: calc(var(--i, 0) * 28ms);
}
.item:last-child { border-bottom: 0; }
@keyframes item-in { from { opacity: 0; transform: translateY(8px); } }

.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--c, var(--accent)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c, var(--accent)) 18%, transparent); }
.item .body { flex: 1; min-width: 0; }
.item .body .t { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .amt { font-weight: 650; }
.item .amt.inc { color: var(--green); }
.item .amt.exp { color: var(--text); }
.date-sep { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .06em; margin: 16px 4px 4px; }
/* маяк для подгрузки следующей порции операций (оконный рендер большого списка) */
.tx-more { height: 1px; }
/* экранная кнопка «назад» для веб-версии (в шапке слева) */
.app-back { margin-right: 6px; flex: none; }
.app-back .back { transform: rotate(180deg); }
/* разделитель «или» на экране входа сайта */
.or-sep { display: flex; align-items: center; gap: 10px; margin: 16px 2px; color: var(--text-faint); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.or-sep::before, .or-sep::after { content: ''; flex: 1; height: 1px; background: var(--border-soft); }
/* модальный диалог подтверждения в стиле сайта (замена системного confirm) */
.confirm-root { position: fixed; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center; padding: 24px; }
.confirm-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .5); backdrop-filter: blur(2px); animation: cfm-fade .2s var(--ease-out); }
.confirm-box {
  position: relative; width: 100%; max-width: 340px;
  background: var(--bg-sec); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); animation: cfm-in .3s var(--ease-spring);
}
.confirm-text { font-size: 15px; line-height: 1.5; color: var(--text); margin-bottom: 18px; }
.confirm-actions { display: flex; gap: 10px; }
.confirm-actions .btn { flex: 1; }
.confirm-root.closing .confirm-box { animation: cfm-out .16s var(--ease-out) forwards; }
.confirm-root.closing .confirm-backdrop { animation: cfm-fade .16s var(--ease-out) reverse forwards; }
@keyframes cfm-fade { from { opacity: 0; } }
@keyframes cfm-in { from { opacity: 0; transform: translateY(12px) scale(.96); } }
@keyframes cfm-out { to { opacity: 0; transform: scale(.97); } }

.empty { text-align: center; padding: 44px 20px; color: var(--text-faint); }
.empty .ic { width: 40px; height: 40px; opacity: .35; margin-bottom: 12px; stroke-width: 1.5; }
.empty p { margin: 0 0 4px; }

/* ---------- графики ---------- */
.donut-wrap { display: flex; align-items: center; gap: 18px; }
.donut { flex: none; position: relative; width: 132px; height: 132px; }
.donut svg { transform: rotate(-90deg); overflow: visible; }
.donut circle { fill: none; stroke-width: 13; stroke-linecap: round; }
.donut .seg { transition: stroke-dashoffset 1.1s var(--ease-out), opacity .25s; }
.donut .seg.dim { opacity: .28; }
.donut .center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.donut .center .v { font-size: 14px; font-weight: 700; letter-spacing: -.02em; max-width: 96px; }
.donut .center .l { font-size: 10px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .05em; }
.legend { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; animation: item-in .4s var(--ease-out) backwards; animation-delay: calc(var(--i, 0) * 60ms + .25s); }
.legend-row .nm { flex: 1; min-width: 0; overflow: hidden; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.25; }
.legend-row .num.small { flex: none; white-space: nowrap; }
.legend-row .pc { flex: none; color: var(--text-faint); font-size: 12px; }

/* на узких экранах (телефон) легенда уходит под кольцо во всю ширину —
   иначе названия категорий не помещаются рядом со 132px-кольцом */
@media (max-width: 480px) {
  .donut-wrap { flex-direction: column; align-items: center; gap: 14px; }
  .legend { width: 100%; }
}

.spark { display: flex; align-items: flex-end; gap: 2px; height: 56px; margin-top: 6px; }
.spark i {
  flex: 1; border-radius: 2px 2px 0 0; min-height: 2px;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  transform-origin: bottom; transform: scaleY(0);
  animation: bar-grow .55s var(--ease-out) forwards;
  animation-delay: calc(var(--i, 0) * 14ms);
  opacity: .85;
}
.spark i.zero { background: var(--border); }
@keyframes bar-grow { to { transform: scaleY(1); } }

/* столбчатый график доход/расход по месяцам (обзор) */
.barschart { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; height: 118px; margin-top: 4px; }
.bc-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.bc-pair { display: flex; align-items: flex-end; justify-content: center; gap: 3px; width: 100%; height: 96px; }
.bc-bar {
  width: 42%; max-width: 18px; border-radius: 3px 3px 0 0; min-height: 2px; height: 0;
  transition: height .7s var(--ease-out); transition-delay: calc(var(--i, 0) * 40ms);
}
.bc-bar.inc { background: linear-gradient(180deg, var(--green), color-mix(in srgb, var(--green) 70%, #000)); }
.bc-bar.exp { background: linear-gradient(180deg, var(--red), color-mix(in srgb, var(--red) 70%, #000)); }
.bc-lbl { font-size: 10px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .03em; }
.bc-legend { display: flex; gap: 16px; justify-content: center; margin-top: 12px; font-size: 12px; color: var(--text-faint); }
.bc-legend span { display: inline-flex; align-items: center; gap: 6px; }
.bc-legend .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); }

/* дельта к прошлому месяцу на плитках */
.delta { font-size: 10px; font-weight: 650; padding: 1px 5px; border-radius: 6px; letter-spacing: 0; margin-left: 4px; vertical-align: middle; }
.delta.ok { color: var(--green); background: color-mix(in srgb, var(--green) 16%, transparent); }
.delta.bad { color: var(--red); background: color-mix(in srgb, var(--red) 16%, transparent); }

/* доска компании (Adesk): компактная сводка в списке + карточка по тапу */
.tx-sum { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.item.tappable { cursor: pointer; }
.item .chev { width: 16px; height: 16px; flex: none; color: var(--text-faint); opacity: .6; }
.tx-detail { display: flex; flex-direction: column; gap: 12px; }
.td-row { display: flex; gap: 14px; justify-content: space-between; align-items: baseline; }
.td-row .k { color: var(--text-faint); font-size: 13px; flex: none; }
.td-row .v { color: var(--text); text-align: right; min-width: 0; word-break: break-word; }

/* кольцо цели */
.ring { position: relative; width: 54px; height: 54px; flex: none; }
.ring svg { transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 5; stroke-linecap: round; }
.ring .track { stroke: var(--bg-alt); }
.ring .val { stroke: var(--gold); transition: stroke-dashoffset 1.2s var(--ease-out); }
.ring .pct { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 650; }

/* ---------- смена экранов ---------- */
.view { animation: view-in .34s var(--ease-out); }
@keyframes view-in { from { opacity: 0; transform: translateY(10px); } }
.stagger > * { animation: item-in .42s var(--ease-out) backwards; }
.stagger > *:nth-child(1) { animation-delay: .02s; }
.stagger > *:nth-child(2) { animation-delay: .07s; }
.stagger > *:nth-child(3) { animation-delay: .12s; }
.stagger > *:nth-child(4) { animation-delay: .17s; }
.stagger > *:nth-child(5) { animation-delay: .22s; }
.stagger > *:nth-child(6) { animation-delay: .27s; }
.stagger > *:nth-child(n+7) { animation-delay: .3s; }

/* скелет загрузки */
.skel { border-radius: var(--radius); background: linear-gradient(90deg, var(--bg-sec) 25%, var(--bg-hover) 37%, var(--bg-sec) 63%); background-size: 400% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* ---------- нижний лист ---------- */
.sheet-root { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
/* display:flex выше перебивает браузерное [hidden]{display:none} — гасим явно */
.sheet-root[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); backdrop-filter: blur(3px); animation: fade-in .28s var(--ease-out); }
.sheet-root.closing .sheet-backdrop { animation: fade-in .22s var(--ease-out) reverse forwards; }
@keyframes fade-in { from { opacity: 0; } }

.sheet {
  position: relative; width: 100%; max-width: 640px;
  max-height: 88dvh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg-sec); border: 1px solid var(--border); border-bottom: 0;
  border-radius: 18px 18px 0 0; box-shadow: var(--shadow);
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  animation: sheet-up .42s var(--ease-spring);
}
.sheet-root.closing .sheet { animation: sheet-down .26s var(--ease-out) forwards; }
@keyframes sheet-up { from { transform: translateY(100%); } }
@keyframes sheet-down { to { transform: translateY(100%); opacity: .6; } }

.sheet-grip { width: 38px; height: 4px; border-radius: 999px; background: var(--border); margin: 4px auto 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.sheet-head h2 { font-size: 17px; font-weight: 650; margin: 0; }

/* ---------- уведомления ---------- */
.toasts { position: fixed; left: 12px; right: 12px; bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); z-index: 60; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 10px;
  margin: 0 auto; max-width: 480px; width: 100%;
  padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--bg-sec); border: 1px solid var(--border);
  border-left: 3px solid var(--c, var(--accent));
  box-shadow: var(--shadow); font-size: 14px;
  animation: toast-in .4s var(--ease-spring);
}
.toast.out { animation: toast-out .3s var(--ease-out) forwards; }
.toast.ok { --c: var(--green); }
.toast.err { --c: var(--red); }
.toast.warn { --c: var(--orange); }
.toast .ic { color: var(--c, var(--accent)); }
@keyframes toast-in { from { opacity: 0; transform: translateY(16px) scale(.96); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(10px) scale(.97); } }

/* ---------- справка по законам ---------- */
.topic { border: 1px solid var(--border-soft); border-radius: var(--radius-sm); margin-bottom: 8px; background: var(--bg-sec); overflow: hidden; }
.topic > summary { display: flex; align-items: center; gap: 10px; padding: 13px 14px; cursor: pointer; list-style: none; font-weight: 550; font-size: 14px; }
.topic > summary::-webkit-details-marker { display: none; }
.topic > summary .ic { color: var(--accent); transition: transform .3s var(--ease-out); margin-left: auto; width: 16px; height: 16px; }
.topic[open] > summary .ic { transform: rotate(90deg); }
.topic .topic-body { padding: 0 14px 14px; font-size: 14px; color: var(--text-muted); white-space: pre-wrap; animation: topic-open .35s var(--ease-out); }
.topic .topic-body b { color: var(--text); }
@keyframes topic-open { from { opacity: 0; transform: translateY(-6px); } }

.answer { white-space: pre-wrap; font-size: 14px; }
.answer b { color: var(--accent-2); }

/* инструкция 1С: пронумерованные шаги */
.guide-step { display: flex; gap: 12px; padding: 14px; align-items: flex-start; }
.guide-num {
  flex: none; width: 26px; height: 26px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent-2); font-size: 13px; font-weight: 700;
}
.guide-title { font-weight: 600; font-size: 14px; }
.topic .guide-step .topic-body { white-space: pre-wrap; }

.thinking { display: inline-flex; gap: 4px; align-items: center; }
.thinking i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: blink 1.2s ease-in-out infinite; }
.thinking i:nth-child(2) { animation-delay: .18s; }
.thinking i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 100% { opacity: .25; transform: scale(.8); } 50% { opacity: 1; transform: scale(1); } }

/* ---------- меню «Ещё» ---------- */
.menu-row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 15px 14px; margin-bottom: 8px; cursor: pointer; text-align: left;
  background: var(--bg-sec); border: 1px solid var(--border-soft); border-radius: var(--radius);
  color: var(--text); font-family: inherit; font-size: 15px; font-weight: 550;
  transition: transform .14s var(--ease-out), background .2s;
}
.menu-row:active { transform: scale(.985); background: var(--bg-hover); }
.menu-row > .ic:first-child { color: var(--accent-2); }
.menu-row .arrow { margin-left: auto; color: var(--text-faint); width: 16px; height: 16px; }
.menu-row .sub { display: block; font-size: 12px; font-weight: 400; color: var(--text-faint); margin-top: 2px; }
/* пока формируется файл — приглушаем строку и мягко «пульсируем» иконкой */
.menu-row.busy { opacity: .6; pointer-events: none; }
.menu-row.busy > .ic:first-child { animation: pulse-fade 1s var(--ease-out) infinite; }
@keyframes pulse-fade { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

/* ---------- выбор роли на входе ---------- */
.gate { padding-top: 5vh; }
.gate-head { text-align: center; margin-bottom: 26px; }
.gate-logo { font-size: 26px; font-weight: 750; letter-spacing: -.02em; }
.gate-sub { color: var(--text-faint); font-size: 13px; margin-top: 4px; }
.role-card {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  padding: 16px; margin-bottom: 12px; cursor: pointer;
  background: var(--bg-sec); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-family: inherit;
  transition: transform .14s var(--ease-spring), border-color .2s, background .2s;
  animation: item-in .4s var(--ease-out) backwards; animation-delay: calc(var(--i, 0) * 70ms);
}
.role-card:active { transform: scale(.98); }
.role-card.sel { border-color: var(--accent); background: var(--accent-soft); }
.role-emoji { flex: none; width: 46px; height: 46px; display: flex; align-items: center; justify-content: center; font-size: 24px; background: var(--bg-alt); border-radius: 12px; }
.role-card .role-t { flex: 1; min-width: 0; font-size: 16px; font-weight: 650; display: flex; flex-direction: column; gap: 3px; }
.role-card .role-s { font-weight: 400; font-size: 12.5px; color: var(--text-faint); }
.role-card .arrow { flex: none; width: 18px; height: 18px; color: var(--text-faint); }
.role-pass { margin-top: 4px; animation: item-in .32s var(--ease-out); }

/* ---------- тумблер (напр. «с работниками») ---------- */
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 2px; margin-bottom: 4px; cursor: pointer; user-select: none; }
.switch .lbl { font-size: 14px; color: var(--text); }
.switch .track { position: relative; flex: none; width: 46px; height: 27px; border-radius: 999px; background: var(--bg-alt); border: 1px solid var(--border); transition: background .22s, border-color .22s; }
.switch.on .track { background: var(--accent); border-color: var(--accent); }
.switch .knob { position: absolute; top: 2px; left: 2px; width: 21px; height: 21px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .24s var(--ease-spring); }
.switch.on .knob { transform: translateX(19px); }

/* ---------- чипы равной ширины (срок патента и т.п.) ---------- */
.chips.seg3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.chips.seg3 .chip { text-align: center; padding: 10px 4px; }
.chips.seg2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.chips.seg2 .chip { text-align: center; padding: 10px 4px; }

/* ---------- карточки систем налогообложения (доска компании) ---------- */
/* активная — только по цветному контуру, без плашек */
.sys-card.active { border-color: var(--accent); box-shadow: inset 0 0 0 1.5px var(--accent); }

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