:root {
  --bg: var(--tg-theme-bg-color, #14161c);
  --card-bg: var(--tg-theme-secondary-bg-color, #1f222b);
  --text: var(--tg-theme-text-color, #eef0f5);
  --muted: var(--tg-theme-hint-color, #969cb0);
  --accent: var(--tg-theme-button-color, #6c7cff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); -webkit-tap-highlight-color: transparent; }
.app { max-width: 600px; margin: 0 auto; padding: 16px 16px 48px; display: flex; flex-direction: column; gap: 14px; }
.head { text-align: center; padding: 8px 0 0; }
.head h1 { margin: 0; font-size: 26px; }
.status { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.card { background: var(--card-bg); border-radius: 16px; padding: 16px; }
.card h2 { margin: 0 0 10px; font-size: 18px; }
.intro { margin: 0 0 12px; line-height: 1.45; }
textarea { width: 100%; padding: 12px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.1); background: var(--bg); color: var(--text); font-size: 16px; resize: vertical; font-family: inherit; margin-bottom: 10px; }
.examples { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip { padding: 8px 12px; border-radius: 999px; border: 1px solid rgba(255,255,255,0.12); background: var(--bg); color: var(--text); font-size: 13px; cursor: pointer; }
.chip:active { opacity: 0.7; }
.primary { width: 100%; padding: 14px; border: none; border-radius: 14px; background: var(--accent); color: var(--accent-text); font-size: 16px; font-weight: 600; cursor: pointer; }
.primary:disabled { opacity: 0.6; }
.muted { color: var(--muted); font-size: 14px; }
.reading { white-space: pre-wrap; line-height: 1.55; margin: 0; font-size: 15px; }
.copy { margin-top: 14px; }
.history-item { width: 100%; text-align: left; display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; margin-top: 8px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.1); background: var(--bg); color: var(--text); cursor: pointer; font-family: inherit; }
.history-date { font-size: 12px; color: var(--muted); }
.history-text { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pro h2 { margin: 0 0 8px; font-size: 18px; }
.plan { width: 100%; text-align: left; display: flex; flex-direction: column; gap: 3px; padding: 12px; margin-top: 8px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.1); background: var(--bg); color: var(--text); cursor: pointer; }
/* Иерархия пейволла: «★ популярный» выделен рамкой и фоном, бейджи выгоды/типа справа от названия. */
.plan-popular { border-color: var(--accent); background: rgba(108,124,255,0.10); }
.plan-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.plan-title { font-weight: 600; }
.plan-desc { font-size: 13px; color: var(--muted); }
.plan-price { font-weight: 600; color: var(--accent); }
.plan-badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.plan-badge.popular { background: var(--accent); color: var(--accent-text); }
.plan-badge.save { background: rgba(120,200,140,0.18); color: #79c98c; }
.plan-badge.neutral { background: rgba(255,255,255,0.10); color: var(--muted); }
/* Заголовки групп «Подписка» / «Без подписки» — чтобы SKU не валились в кучу. */
.plan-group { margin: 14px 0 2px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.plan-group:first-child { margin-top: 4px; }
/* Кратковременная подсветка нужной плашки (например, пакета при упоре в лимит). */
.plan-flash { animation: planFlash 1.2s ease-in-out 2; }
@keyframes planFlash { 0%, 100% { border-color: rgba(255,255,255,0.1); } 50% { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(108,124,255,0.35); } }
/* CTA «Купить пакет» под основной кнопкой на исчерпании лимита. */
.pack-cta { margin-top: 10px; }
/* «Подарить Pro другу» — вторичная кнопка под списком планов. */
.gift-pro-btn { margin-top: 16px; }
.gift-pro-hint { margin: 8px 0 0; font-size: 13px; line-height: 1.4; }
.hidden { display: none; }

/* Переключатель режима ввода */
.mode-switch { display: flex; gap: 8px; margin-bottom: 14px; }
.mode-btn { flex: 1; padding: 10px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.12); background: var(--bg); color: var(--muted); font-size: 14px; font-weight: 600; cursor: pointer; }
.mode-btn.active { color: var(--accent-text); background: var(--accent); border-color: var(--accent); }

/* Визард */
.wizard { display: flex; flex-direction: column; gap: 12px; margin-bottom: 12px; }
.wizard.hidden { display: none; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; color: var(--muted); }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; min-width: 0; }
.wizard input, .wizard select, .wizard textarea { width: 100%; padding: 11px 12px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.1); background: var(--bg); color: var(--text); font-size: 16px; font-family: inherit; }
.wizard textarea { resize: vertical; }
.wizard select { -webkit-appearance: none; appearance: none; }
.micro { font-size: 12px; margin: 4px 0 0; }

/* Карточка расчёта */
.calc-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid rgba(255,255,255,0.07); font-size: 14px; }
.calc-row span:first-child { color: var(--muted); }
.calc-row span:last-child { font-weight: 600; text-align: right; }
.calc-row.calc-total { border-bottom: none; font-size: 15px; }
.calc-row.calc-total span:last-child { color: var(--accent); }
/* Честное пояснение, почему расчёта нет (например, грейс ст. 22 ещё не истёк) — не молчим. */
.calc-note { line-height: 1.45; padding: 10px 12px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.1); background: var(--bg); }

/* Действия с результатом */
.result-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.secondary { width: 100%; padding: 13px; border-radius: 14px; border: 1px solid var(--accent); background: transparent; color: var(--accent); font-size: 15px; font-weight: 600; cursor: pointer; }
.secondary:disabled { opacity: 0.6; }
.copy { margin-top: 0; }

/* Аудит документа по фото */
.scan-row { display: flex; align-items: center; gap: 10px; margin: 6px 0 8px; }
.scan-btn { flex: 1; display: inline-flex; align-items: center; justify-content: center; padding: 12px; border-radius: 12px; border: 1px dashed rgba(255,255,255,0.25); background: var(--bg); color: var(--text); font-size: 14px; cursor: pointer; text-align: center; }
.scan-btn.locked { opacity: 0.7; }
.lock-badge { font-size: 12px; color: var(--muted); white-space: nowrap; }
.lock-inline { color: var(--accent); font-size: 12px; }
.scan-result { margin: 6px 0 10px; padding: 10px 12px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.1); background: var(--bg); }
.scan-doc-type { margin: 0 0 6px; font-weight: 600; font-size: 14px; }
.scan-audit { margin: 0 0 6px; padding-left: 18px; }
.scan-audit li { font-size: 13px; color: var(--text); margin: 3px 0; line-height: 1.4; }

/* Консультация */
.consult-answer { margin-top: 12px; padding: 12px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.1); background: var(--bg); white-space: pre-wrap; }

/* Жизненный цикл документа в истории */
.history-row { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.badge { margin-left: 8px; font-size: 11px; padding: 2px 7px; border-radius: 999px; vertical-align: middle; }
.badge.sent { background: rgba(108,124,255,0.18); color: var(--accent); }
.badge.overdue { background: rgba(255,90,90,0.18); color: #ff7676; }
.badge.complaint { background: rgba(120,200,140,0.18); color: #79c98c; }
.status-toggle { align-self: flex-start; padding: 6px 12px; border-radius: 999px; border: 1px solid rgba(255,255,255,0.18); background: var(--bg); color: var(--muted); font-size: 12px; cursor: pointer; font-family: inherit; }
.status-toggle.on { border-color: var(--accent); color: var(--accent); }
.status-toggle:disabled { opacity: 0.6; }
.overdue-note { margin: 0; font-size: 12px; color: #ff7676; line-height: 1.4; }
.complaint-btn { align-self: flex-start; padding: 8px 14px; border-radius: 12px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text); font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit; }
.complaint-btn:disabled { opacity: 0.6; }

/* Реферальная карточка «пригласи друга» */
.referral { background: linear-gradient(135deg, rgba(108,124,255,0.16), rgba(108,124,255,0.04)); border: 1px solid rgba(108,124,255,0.28); }
.referral-stats { margin: 10px 0 0; font-size: 13px; color: var(--accent); }

/* Прогресс дела (retention): вехи жизненного цикла спора */
.progress { background: linear-gradient(135deg, rgba(120,200,140,0.14), rgba(120,200,140,0.03)); border: 1px solid rgba(120,200,140,0.26); }
.progress-item { margin: 6px 0 0; font-size: 14px; }
#progressLevel { margin: 0 0 8px; font-size: 13px; color: var(--accent); }

/* Кросс-промо (виральность→рекомендация соседних ботов) */
.promo-item { display: block; width: 100%; text-align: left; padding: 10px 12px; margin-top: 8px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.1); background: var(--bg); color: var(--text); text-decoration: none; font-size: 14px; }
a.promo-item:active { opacity: 0.7; }

/* Лента истории (наглядность: ctx.history kind="doc") — карточки событий + спарклайн тренда */
.feed { background: linear-gradient(135deg, rgba(108,124,255,0.10), rgba(108,124,255,0.02)); border: 1px solid rgba(108,124,255,0.22); }
.feed-spark { margin: 0 0 12px; padding: 12px 12px 8px; border-radius: 12px; background: var(--bg); border: 1px solid rgba(255,255,255,0.08); }
.feed-spark-bars { display: flex; align-items: flex-end; gap: 6px; height: 56px; }
.feed-bar { flex: 1; min-width: 0; border-radius: 4px 4px 2px 2px; background: rgba(255,255,255,0.10); transition: height 0.3s ease; }
.feed-bar.on { background: rgba(108,124,255,0.55); }
.feed-bar.today.on { background: var(--accent); }
.feed-bar.today { box-shadow: 0 0 0 1px rgba(108,124,255,0.4); }
.feed-spark-cap { margin: 8px 0 0; font-size: 12px; color: var(--muted); text-align: right; }
.feed-list { display: flex; flex-direction: column; gap: 8px; }
.feed-item { padding: 10px 12px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.1); background: var(--bg); border-left: 3px solid var(--accent); }
.feed-item.complaint { border-left-color: #79c98c; }
.feed-row-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.feed-title { font-size: 14px; font-weight: 600; }
.feed-date { font-size: 12px; color: var(--muted); white-space: nowrap; }
.feed-snippet { margin: 5px 0 0; font-size: 13px; color: var(--text); line-height: 1.4; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.feed-amount { display: inline-block; margin-top: 6px; font-size: 12px; font-weight: 600; color: var(--accent); padding: 2px 8px; border-radius: 999px; background: rgba(108,124,255,0.14); }
.feed-empty { margin: 4px 0 0; line-height: 1.5; padding: 14px 12px; border-radius: 12px; border: 1px dashed rgba(255,255,255,0.18); background: var(--bg); text-align: center; }

/* Доска «Мои дела» (наглядность: статус-доска документов из ctx.history kind="doc") */
.cases { background: linear-gradient(135deg, rgba(108,124,255,0.10), rgba(108,124,255,0.02)); border: 1px solid rgba(108,124,255,0.22); }
.cases-lead { margin: 0 0 12px; line-height: 1.45; }
.cases-overdue { margin: 0 0 12px; padding: 10px 12px; border-radius: 12px; background: rgba(255,90,90,0.12); border: 1px solid rgba(255,90,90,0.32); color: #ff8a8a; font-size: 13px; font-weight: 600; line-height: 1.4; }
.cases-list { display: flex; flex-direction: column; gap: 10px; }
/* Карточка дела: цветная левая полоса = статус; «красная линия» (.urgent/.overdue) подсвечивает срок. */
.case-card { position: relative; padding: 12px 12px 12px 14px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.1); background: var(--bg); border-left: 4px solid var(--muted); }
.case-card.draft { border-left-color: #969cb0; }
.case-card.sent { border-left-color: var(--accent); }
.case-card.waiting { border-left-color: #e0a83a; }
.case-card.overdue { border-left-color: #ff5a5a; background: rgba(255,90,90,0.06); }
.case-card.urgent { border-left-color: #ff8a3a; }
.case-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.case-title { font-size: 14px; font-weight: 600; }
.case-date { font-size: 12px; color: var(--muted); white-space: nowrap; }
.case-snippet { margin: 6px 0 0; font-size: 13px; color: var(--text); line-height: 1.4; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.case-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }
.case-status { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.case-status.draft { background: rgba(255,255,255,0.10); color: var(--muted); }
.case-status.sent { background: rgba(108,124,255,0.18); color: var(--accent); }
.case-status.waiting { background: rgba(224,168,58,0.18); color: #e0a83a; }
.case-status.overdue { background: rgba(255,90,90,0.18); color: #ff7676; }
.case-amount { font-size: 11px; font-weight: 600; color: var(--accent); padding: 3px 9px; border-radius: 999px; background: rgba(108,124,255,0.14); }
/* Срок ответа: «красная линия» при близком дедлайне (.urgent) и при просрочке (.overdue). */
.case-deadline { font-size: 12px; color: var(--muted); }
.case-deadline.urgent, .case-deadline.overdue { color: #ff7676; font-weight: 600; }
.case-deadline-bar { height: 4px; border-radius: 999px; margin-top: 8px; background: rgba(255,255,255,0.08); overflow: hidden; }
.case-deadline-bar > span { display: block; height: 100%; border-radius: 999px; background: var(--accent); }
.case-deadline-bar.urgent > span { background: #ff8a3a; }
.case-deadline-bar.overdue > span { background: #ff5a5a; width: 100% !important; }
.case-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.case-btn { padding: 6px 12px; border-radius: 999px; border: 1px solid rgba(255,255,255,0.18); background: var(--bg); color: var(--muted); font-size: 12px; cursor: pointer; font-family: inherit; }
.case-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(108,124,255,0.10); }
.case-btn:disabled { opacity: 0.6; }
.cases-empty { margin: 4px 0 0; line-height: 1.5; padding: 14px 12px; border-radius: 12px; border: 1px dashed rgba(255,255,255,0.18); background: var(--bg); text-align: center; }

/* Экран согласия на обработку ПДн (152-ФЗ, П-2) — модальный оверлей до ввода данных */
.consent-overlay { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 18px; background: rgba(0,0,0,0.55); -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }
.consent-overlay.hidden { display: none; }
.consent-box { width: 100%; max-width: 440px; background: var(--card-bg); border-radius: 16px; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.consent-box h2 { margin: 0; font-size: 19px; }
.consent-text { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.consent-check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; line-height: 1.45; cursor: pointer; }
.consent-check input { margin-top: 2px; width: 18px; height: 18px; flex: 0 0 auto; }
.consent-check a { color: var(--accent); }
.consent-box .micro { margin: 0; }

/* Авторитетная утилита скрытия: объявлена ПОСЛЕДНЕЙ, чтобы при равной специфичности побеждать
   любые одноклассовые display-правила компонентов (корень бага .hidden-специфичности). 2-классовые
   show-правила и инлайн-стили НЕ перебивает (без !important). */
.hidden { display: none; }
