/*
   style.css - Фирменные стили Mini App RENOVEX.

   ПАЛИТРА - из логотипа RENOVEX (tg_bot/resources/welcome.jpg):
   тёмный коричневый фон и золото. Цвета зафиксированы в ТЗ (00-overview
   5.5) - не менять самовольно, чтобы бот, PDF и Mini App были одним стилем.

   Требования: мобильная анкета от 320 px, только вертикальная прокрутка,
   нижние кнопки видны при открытой клавиатуре.
*/

:root {
  /* Фирменная палитра (снято с логотипа) */
  --bg: #241811;          /* тёмный коричневый фон */
  --bg-deep: #1a100a;     /* глубокий коричневый (шапка/градиенты) */
  --surface: #33241b;     /* карточки и поля */
  --surface-2: #3e2c20;   /* приподнятые элементы */
  --gold: #e3bb72;        /* золото (акценты, кнопки) */
  --gold-deep: #c79a4e;   /* тёмное золото (градиенты) */
  --text: #f5ede2;        /* тёплый белый */
  --muted: #b5a08a;       /* приглушённый текст */
  --error: #e4736a;       /* ошибки */

  /* Отступы под системные кнопки и обёртку Telegram (их заполняет app.js
     из Telegram.WebApp.safeAreaInset / contentSafeAreaInset; в браузере
     остаются env(safe-area-inset-*)) - чтобы ничего не перекрывалось */
  --safe-top: 0px;
  --safe-bottom: 0px;
  --safe-left: 0px;
  --safe-right: 0px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(180deg, var(--bg-deep) 0%, var(--bg) 220px);
  color: var(--text);
  min-width: 320px;
  overflow-x: hidden;
}

/* --- Шапка: как шапка логотипа (тёмный коричневый + золото) --- */
/* Отступы «под систему»: максимум из Telegram-insets и env(safe-area-inset) */
.app-header {
  position: sticky;
  top: 0;
  background: linear-gradient(135deg, var(--bg-deep), var(--bg));
  padding: calc(14px + max(env(safe-area-inset-top, 0px), var(--safe-top))) 16px 0;
  z-index: 10;
  border-bottom: 1px solid rgba(227, 187, 114, 0.25);
}
.app-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 4px;
  background: linear-gradient(90deg, var(--gold), var(--gold-deep));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.app-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.app-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  margin-top: 6px;
  color: var(--muted);
}
.header-actions { margin-left: auto; display: flex; gap: 6px; }
.chat-link {
  background: rgba(227, 187, 114, 0.12);
  border: 1px solid rgba(227, 187, 114, 0.4);
  color: var(--gold);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
}
/* DEV-кнопка (только APP_ENV=dev): быстрый тест одной кнопкой */
.dev-quick {
  border-color: var(--gold-deep);
  background: rgba(199, 154, 78, 0.18);
}
.dev-quick:disabled { opacity: 0.5; }
.dev-pdf-link { color: var(--gold); text-decoration: underline; }

/* --- Пользователь: аватар + имя (кто открыл анкету) --- */
.user-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  padding: 0;
  max-width: 92px;
  cursor: pointer;
}
.user-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2px solid var(--gold-deep); /* золото = initData подтверждён */
  background: var(--surface-2);
  color: var(--gold);
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.user-avatar.auth-dev { border-color: var(--error); } /* красный = initData нет */
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-name {
  font-size: 10px;
  color: var(--muted);
  max-width: 92px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Панель отладки входа: открывается по аватарке (top ставит app.js) */
.user-popover {
  position: fixed;
  right: 12px;
  z-index: 200;
  width: min(280px, calc(100vw - 24px));
  background: var(--surface);
  border: 1px solid rgba(227, 187, 114, 0.35);
  border-radius: 12px;
  padding: 12px;
  font-size: 12px;
  color: var(--text);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}
.user-popover.hidden { display: none; }
.user-popover .row { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; }
.user-popover .k { color: var(--muted); flex: none; }
.user-popover .v { text-align: right; word-break: break-all; }
.user-popover .ok { color: var(--gold); }
.user-popover .warn { color: var(--error); }

.progress-bar {
  height: 4px;
  background: rgba(227, 187, 114, 0.15);
  margin: 12px -16px 0;
}
#progress-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--gold-deep), var(--gold));
  transition: width 0.3s;
}

/* --- Контент --- */
/* Снизу - запас под нижнюю панель: контент не прячется за кнопками */
.app-body {
  padding: 18px
    calc(16px + max(env(safe-area-inset-left, 0px), var(--safe-left)))
    calc(110px + max(env(safe-area-inset-bottom, 0px), var(--safe-bottom)))
    calc(16px + max(env(safe-area-inset-right, 0px), var(--safe-right)));
}
.screen h2 {
  font-size: 21px;
  margin-bottom: 14px;
  background: linear-gradient(90deg, var(--gold), var(--gold-deep));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hidden { display: none; }

/* --- Экран «Ответы подтверждены» --- */
#screen-done h2 { margin-bottom: 18px; }
#screen-done p {
  margin-bottom: 28px;
  line-height: 1.6;
  font-size: 15px;
  color: var(--muted);
}
#screen-done .btn-primary {
  width: 100%;
  margin-top: 8px;
}

/* --- Экран блокировки (нет оплаты / расчёт использован) --- */
#screen-lock h2 { margin-bottom: 18px; }
#screen-lock p {
  margin-bottom: 28px;
  line-height: 1.6;
  font-size: 15px;
  color: var(--muted);
}
#screen-lock .btn-primary {
  width: 100%;
  margin-top: 8px;
}

.question-card {
  background: var(--surface);
  border: 1px solid rgba(227, 187, 114, 0.14);
  border-radius: 16px;
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}
.question-text { font-size: 17px; font-weight: 700; line-height: 1.35; }

/* Ошибка заполнения: красная обводка ДЕРЖИТСЯ, пока поле не заполнят */
.question-card.has-error {
  border-color: var(--error);
  box-shadow: 0 0 0 3px rgba(228, 115, 106, 0.22);
}
.question-card.has-error .question-text { color: var(--error); }
.question-card.has-error input[type="text"],
.question-card.has-error input[type="number"],
.question-card.has-error select {
  border-color: var(--error);
}
.question-help {
  font-size: 13px;
  color: var(--muted);
  margin: 8px 0 12px;
  line-height: 1.5;
}
.field-label {
  font-size: 13px;
  color: var(--gold);
  margin: 12px 0 6px;
  font-weight: 600;
}

/* --- Поля ввода --- */
input[type="text"], input[type="number"], select {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid rgba(227, 187, 114, 0.25);
  border-radius: 12px;
  font-size: 16px; /* 16px - iOS не зумит страницу при фокусе */
  background: var(--surface-2);
  color: var(--text);
}
input::placeholder { color: var(--muted); }
input:focus, select:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(227, 187, 114, 0.2);
}

/* --- Варианты (radio/checkbox) --- */
.option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(227, 187, 114, 0.18);
  border-radius: 12px;
  margin-top: 10px;
  cursor: pointer;
  background: var(--surface-2);
  transition: border-color 0.15s, background 0.15s;
}
.option:active { transform: scale(0.99); }
.option:has(input:checked) {
  border-color: var(--gold);
  background: rgba(227, 187, 114, 0.12);
}
.option input {
  width: 22px;
  height: 22px;
  accent-color: var(--gold-deep);
  flex-shrink: 0;
}

/* --- Карточки и строки (санузлы, шкафы, позиции) --- */
.item-row {
  border: 1px dashed rgba(227, 187, 114, 0.35);
  border-radius: 12px;
  padding: 14px;
  margin-top: 12px;
  background: rgba(0, 0, 0, 0.12);
}
.item-head { display: flex; align-items: center; gap: 12px; font-weight: 600; }
.item-head input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--gold-deep); }
.item-head .qty { width: 95px; }

/* Внутренняя часть позиции (количество, параметры, строки) -
   flex-раскладка с отступами, чтобы ничего не наезжало */
.item-detail {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.item-detail select { width: auto; min-width: 130px; flex: 1; }
.item-detail .qty { width: 95px; flex: none; }
.rows-list { flex-basis: 100%; }

/* Убрать лишний отступ у первой подписи поля внутри карточки/строки */
.item-row .field-label:first-child { margin-top: 0; }
/* Кнопка «Удалить» - с отступом от полей */
.item-row > .btn-small { margin-top: 10px; }

.row-actions { display: flex; gap: 8px; margin-top: 10px; }
.btn-small {
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--gold-deep);
  background: transparent;
  color: var(--gold);
}
.btn-small:active { background: rgba(227, 187, 114, 0.15); }

/* --- Нижняя навигация --- */
.nav-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  gap: 12px;
  /* Панель кнопок живёт НАД системными кнопками/обёрткой Telegram */
  padding: 14px
    calc(16px + max(env(safe-area-inset-left, 0px), var(--safe-left)))
    calc(14px + max(env(safe-area-inset-bottom, 0px), var(--safe-bottom)))
    calc(16px + max(env(safe-area-inset-right, 0px), var(--safe-right)));
  background: linear-gradient(180deg, transparent, var(--bg-deep) 30%);
}
.btn-primary, .btn-secondary {
  flex: 1;
  padding: 15px;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 700;
  border: none;
  cursor: pointer;
}
.btn-primary {
  background: linear-gradient(135deg, var(--gold), var(--gold-deep));
  color: var(--bg-deep);
  box-shadow: 0 6px 16px rgba(199, 154, 78, 0.35);
}
.btn-primary:active { transform: translateY(1px); }
.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid rgba(227, 187, 114, 0.25);
}

/* --- Сводка и уведомления --- */
.review-item {
  background: var(--surface);
  border: 1px solid rgba(227, 187, 114, 0.14);
  border-radius: 14px;
  padding: 14px 16px;
  margin-bottom: 10px;
}
.review-item .label { font-size: 13px; color: var(--muted); }
.review-item .value { font-size: 15px; margin-top: 4px; font-weight: 600; }
.review-item .edit {
  float: right;
  color: var(--gold);
  background: none;
  border: none;
  font-size: 14px;
  font-weight: 600;
}

.error-text { color: var(--error); font-size: 13px; margin-top: 8px; }
.toast {
  position: fixed;
  bottom: calc(92px + max(env(safe-area-inset-bottom, 0px), var(--safe-bottom)));
  left: 16px;
  right: 16px;
  background: linear-gradient(135deg, var(--gold), var(--gold-deep));
  color: var(--bg-deep);
  padding: 14px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  white-space: pre-line; /* переносы строк \n в подсказках ошибок */
  display: flex; /* текст + крестик закрытия */
  align-items: flex-start;
  gap: 10px;
}
#toast-text { flex: 1; }

/* Крестик: постоянные тосты (ошибки) закрываются только им */
.toast-close {
  flex: none;
  width: 28px;
  height: 28px;
  margin: -4px -4px 0 0;
  border: none;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.18);
  color: inherit;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.toast-close:active { transform: scale(0.92); }

/* .toast ставит display:flex и перебивает .hidden (равная специфичность,
   позже - сильнее). Скрываем явно - по образцу .modal.hidden */
.toast.hidden { display: none; }

/* --- Анимации: лёгкие и современные ---
   Только transform/opacity (GPU, без нагрузки), короткие тайминги */
@keyframes stepInNext {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: none; }
}
@keyframes stepInBack {
  from { opacity: 0; transform: translateX(-20px); }
  to { opacity: 1; transform: none; }
}
@keyframes screenIn {
  /* Без transform: transform на .screen ломает position:fixed у .nav-bar
     (создаёт containing block - панель «уезжает» вниз) */
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes pop {
  0% { transform: scale(0.98); }
  60% { transform: scale(1.012); }
  100% { transform: scale(1); }
}

/* Смена шага: плавный слайд всего контейнера (одна анимация, без мерцания).
   Классы перезапускает app.js через reflow при каждом переходе */
.anim-next { animation: stepInNext 0.25s ease-out both; }
.anim-back { animation: stepInBack 0.25s ease-out both; }

/* Смена экранов: мягкое появление (класс .screen-in добавляет app.js) */
.screen-in { animation: screenIn 0.28s ease-out both; }

/* Выбор варианта: мягкое нажатие и «подтверждение» выбора */
.option { transition: border-color 0.18s ease, background 0.18s ease, transform 0.18s ease; }
.option:active { transform: scale(0.98); }
.option:has(input:checked) { animation: pop 0.22s ease-out; }

/* Кнопки: живое нажатие */
.btn-primary, .btn-secondary { transition: transform 0.15s ease, box-shadow 0.15s ease; }
.btn-primary:active, .btn-secondary:active { transform: translateY(1px) scale(0.99); }

/* --- Попап редактирования ответа (сводка «Проверьте ответы») ---
   Выезжает снизу как шторка, затемнение сзади, скролл внутри */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal.hidden { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  animation: backdropIn 0.25s ease-out;
}
.modal-body {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: 82vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 20px
    calc(16px + max(env(safe-area-inset-left, 0px), var(--safe-left)))
    calc(20px + max(env(safe-area-inset-bottom, 0px), var(--safe-bottom)))
    calc(16px + max(env(safe-area-inset-right, 0px), var(--safe-right)));
  animation: modalIn 0.3s ease-out;
}
.modal-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 14px;
  color: var(--gold);
}
.modal-done { width: 100%; margin-top: 16px; }
@keyframes modalIn {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
@keyframes backdropIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Уважение к системной настройке «меньше движения» */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
