/* ============================================================
   AR-модалка примерки — РЕДИЗАЙН v2 (TZ_ar_modal_redesign.md)
   Изолирована: грузится ТОЛЬКО под флагом ?new_tryon=1 / TRYON_REDESIGN_ENABLED.
   Все классы .ar-* — не конфликтуют со старой .tryon-modal.
   Откат: выключить флаг в header.php (файл .tryon_v2_off / ENV OT_NEW_TRYON_OFF=1).
   ============================================================ */

/* Переменные заскоуплены на backdrop — НЕ протекают в глобальный :root сайта */
.ar-modal-backdrop {
  --ar-text: #1a1a1a;
  --ar-text-muted: #6b6b6b;
  --ar-text-soft: #8a8a8a;
  --ar-border: #e5e5e5;
  --ar-border-soft: #efefef;
  --ar-bg: #f3f3f3;
  --ar-hover: #f5f5f5;
  --ar-accent: #1c3d6e;
  --ar-accent-bg: #eef4ff;
  --ar-sale: #c63131;
  --ar-in-stock: #1a7a3e;
  --ar-popular-bg: #fff7e8;
  --ar-popular-text: #8a5e15;
  --ar-tg: #229ED9;

  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ar-text);
}
.ar-modal-backdrop.ar-open { opacity: 1; visibility: visible; }

.ar-modal-backdrop * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Блокировка скролла + скрытие плашки AI-консультанта пока модалка открыта (ТЗ §6.2) */
body.tryon-modal-open { overflow: hidden; }
body.tryon-modal-open .assistant-widget,
body.tryon-modal-open .ai-consultant-fab,
body.tryon-modal-open .ai-consultant-bubble { display: none !important; }

.ar-modal {
  background: #fff;
  border-radius: 20px;
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 100px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.18);
  transform: translateY(8px);
  transition: transform 0.2s ease;
}
.ar-modal-backdrop.ar-open .ar-modal { transform: translateY(0); }

.ar-modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid var(--ar-border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ar-text);
  z-index: 10;
  cursor: pointer;
  padding: 0;
  transition: background 0.1s, border-color 0.1s;
}
.ar-modal-close:hover { background: #fff; border-color: var(--ar-text); }
.ar-modal-close svg { width: 16px; height: 16px; }

/* ==== ОБЩИЕ ЭЛЕМЕНТЫ ==== */
.ar-content {
  padding: 36px 32px 24px;
  overflow-y: auto;
  flex: 1;
}
.ar-header { text-align: center; margin-bottom: 24px; }
.ar-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.4px;
  margin: 0 0 6px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.ar-title svg { width: 22px; height: 22px; color: var(--ar-accent); }
.ar-subtitle { font-size: 14px; color: var(--ar-text-muted); margin: 0; }

/* Кнопки */
.ar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 24px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s, transform 0.1s;
  width: 100%;
  text-decoration: none;
  color: inherit;
  line-height: 1;
}
.ar-btn:active { transform: translateY(1px); }
.ar-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.ar-btn:disabled:active { transform: none; }
.ar-btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.ar-btn-primary { background: var(--ar-text); color: #fff; border-color: var(--ar-text); }
.ar-btn-primary:not(:disabled):hover { background: #000; border-color: #000; }
.ar-btn-secondary { background: var(--ar-accent-bg); color: var(--ar-accent); border-color: var(--ar-accent); }
.ar-btn-secondary:not(:disabled):hover { background: #dde8f7; }
.ar-btn-ghost { background: #fff; color: var(--ar-text); border-color: var(--ar-border); }
.ar-btn-ghost:not(:disabled):hover { border-color: var(--ar-text); }

/* Видимость состояний */
.ar-state { display: none; }
.ar-state.active { display: block; }

/* ============================================
   STATE 1: СТАРТ — выбор способа загрузки
   ============================================ */
.ar-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.ar-option {
  padding: 22px 14px;
  background: var(--ar-bg);
  border: 1px solid transparent;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s, opacity 0.1s;
  text-align: center;
  margin: 0;
}
.ar-option:hover { background: #ebebeb; border-color: var(--ar-border); }
.ar-option-icon {
  width: 44px;
  height: 44px;
  background: #fff;
  border: 1px solid var(--ar-border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ar-text);
}
.ar-option-icon svg { width: 20px; height: 20px; }
.ar-option-label { font-size: 14px; font-weight: 600; color: var(--ar-text); }
.ar-option-hint { font-size: 11.5px; color: var(--ar-text-muted); text-align: center; }

/* Опции заблокированы пока не отмечено согласие */
.ar-options.ar-disabled .ar-option {
  opacity: 0.5;
  pointer-events: none;
}

/* Подсказка про освещение */
.ar-tip {
  background: var(--ar-popular-bg);
  border: 1px solid #e8d8a8;
  border-radius: 12px;
  padding: 12px 16px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 16px;
}
.ar-tip-icon { color: var(--ar-popular-text); flex-shrink: 0; margin-top: 1px; display: inline-flex; }
.ar-tip-icon svg { width: 16px; height: 16px; }
.ar-tip-text { font-size: 13px; color: var(--ar-popular-text); line-height: 1.45; margin: 0; }

/* Чекбокс согласия */
.ar-consent {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 12px;
  color: var(--ar-text-muted);
  margin-bottom: 6px;
  line-height: 1.5;
  cursor: pointer;
}
.ar-consent input { margin: 2px 0 0; accent-color: var(--ar-text); flex-shrink: 0; }
.ar-consent a { color: var(--ar-text); border-bottom: 1px solid var(--ar-text-soft); }

/* ============================================
   STATE 2: КАМЕРА (десктоп getUserMedia)
   ============================================ */
.ar-camera {
  position: relative;
  aspect-ratio: 4/3;
  background: #1a1a1a;
  border-radius: 14px;
  overflow: hidden;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.5);
}
.ar-camera video { width: 100%; height: 100%; object-fit: cover; display: block; }
.ar-camera-frame {
  position: absolute;
  inset: 20px;
  border: 2px dashed rgba(255, 255, 255, 0.4);
  border-radius: 12px;
  pointer-events: none;
}
.ar-camera-frame-tip {
  position: absolute;
  bottom: 16px;
  left: 16px;
  right: 16px;
  background: rgba(0, 0, 0, 0.6);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 12px;
  padding: 8px 14px;
  border-radius: 18px;
  text-align: center;
}
.ar-camera-actions { display: flex; gap: 10px; margin-bottom: 4px; }
.ar-camera-actions .ar-btn-primary { flex: 2; }
.ar-camera-actions .ar-btn-ghost { flex: 1; }

/* ============================================
   STATE 3: ЛОАДЕР
   ============================================ */
.ar-loader-header { text-align: center; padding: 8px 0 18px; }
.ar-spinner {
  width: 52px;
  height: 52px;
  margin: 0 auto 18px;
  border: 3px solid var(--ar-border);
  border-top-color: var(--ar-accent);
  border-radius: 50%;
  animation: ar-spin 0.9s linear infinite;
}
@keyframes ar-spin { to { transform: rotate(360deg); } }
.ar-loader-title { font-size: 18px; font-weight: 700; margin: 0 0 4px; }
.ar-loader-time { font-size: 13px; color: var(--ar-text-muted); margin: 0; }
.ar-loader-time strong { color: var(--ar-text); font-weight: 600; }

.ar-loader-suggest {
  margin-top: 24px;
  padding-top: 22px;
  border-top: 1px solid var(--ar-border-soft);
}
.ar-loader-suggest[hidden] { display: none; }
.ar-loader-suggest-title {
  font-size: 11px;
  color: var(--ar-text-soft);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
  margin: 0 0 12px;
}
.ar-suggest-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 -32px;
  padding: 0 32px 4px;
}
.ar-suggest-strip::-webkit-scrollbar { display: none; }
.ar-suggest-card {
  background: var(--ar-bg);
  border-radius: 10px;
  overflow: hidden;
  flex: 0 0 130px;
  display: flex;
  flex-direction: column;
  border: 1px solid transparent;
  transition: border-color 0.1s, transform 0.1s;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}
.ar-suggest-card:hover { border-color: var(--ar-text); transform: translateY(-2px); }
.ar-suggest-card.queued { border-color: var(--ar-accent); }
.ar-suggest-thumb {
  aspect-ratio: 4/3;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #c0c0c0;
  overflow: hidden;
}
.ar-suggest-thumb img { width: 100%; height: 100%; object-fit: contain; }
.ar-suggest-info { padding: 8px 10px 10px; }
.ar-suggest-brand {
  font-size: 9.5px;
  color: var(--ar-text-soft);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 500;
}
.ar-suggest-name {
  font-size: 11px;
  color: var(--ar-text);
  font-weight: 600;
  line-height: 1.25;
  margin: 2px 0 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.ar-suggest-price { font-size: 12px; font-weight: 700; color: var(--ar-text); margin-top: 4px; }

.ar-loader-note { margin-top: 18px; text-align: center; font-size: 11.5px; color: var(--ar-text-soft); }

/* ============================================
   STATE 4: РЕЗУЛЬТАТ
   ============================================ */
.ar-result-header { text-align: center; margin-bottom: 18px; }
.ar-result-title { font-size: 22px; font-weight: 700; letter-spacing: -0.4px; margin: 0 0 4px; }
.ar-result-subtitle { font-size: 13px; color: var(--ar-text-muted); margin: 0; }

/* Фото результата показываем ЦЕЛИКОМ в натуральных пропорциях (AR возвращает вертикальный портрет),
   без кропа/зума: contain + ограничение по высоте, обёртка ужимается под фото и центрируется. */
.ar-result-image {
  position: relative;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto 16px;
  border-radius: 14px;
  overflow: hidden;
  background: var(--ar-bg);
  line-height: 0;
}
.ar-result-image img {
  display: block;
  max-width: 100%;
  width: auto;
  height: auto;
  max-height: 58vh;
  object-fit: contain;
}

.ar-result-you-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  background: rgba(26, 26, 26, 0.9);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: #fff;
  padding: 6px 12px 6px 8px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 500;
}
.ar-result-you-badge svg { width: 13px; height: 13px; color: var(--ar-in-stock); }

.ar-result-product {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--ar-bg);
  border-radius: 12px;
  margin-bottom: 16px;
}
.ar-result-product-thumb {
  width: 52px;
  height: 40px;
  background: #fff;
  border-radius: 6px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #c0c0c0;
  overflow: hidden;
}
.ar-result-product-thumb img { width: 100%; height: 100%; object-fit: contain; }
.ar-result-product-thumb svg { width: 20px; height: 20px; }
.ar-result-product-info { flex: 1; min-width: 0; }
.ar-result-product-brand {
  font-size: 10px;
  color: var(--ar-text-soft);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
}
.ar-result-product-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--ar-text);
  line-height: 1.3;
  margin: 1px 0 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ar-result-product-price { font-size: 14px; font-weight: 700; color: var(--ar-text); flex-shrink: 0; }
.ar-result-product-price s { color: var(--ar-text-soft); font-weight: 500; font-size: 11px; margin-right: 4px; }

.ar-result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.ar-result-actions .ar-btn { padding: 13px 16px; font-size: 13px; }
.ar-btn.ar-saved { background: var(--ar-in-stock); border-color: var(--ar-in-stock); color: #fff; }

.ar-result-extra { display: flex; gap: 8px; }
.ar-btn-icon {
  flex: 1;
  height: 42px;
  background: #fff;
  border: 1px solid var(--ar-border);
  border-radius: 21px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--ar-text);
  cursor: pointer;
  text-decoration: none;
  transition: border-color 0.1s, color 0.1s;
}
.ar-btn-icon:hover { border-color: var(--ar-text); }
.ar-btn-icon svg { width: 14px; height: 14px; }
.ar-btn-icon.tg svg { color: var(--ar-tg); }
.ar-btn-icon.tg:hover { border-color: var(--ar-tg); color: var(--ar-tg); }

/* ============================================
   СТАТУС-СОСТОЯНИЯ: error / banned / limit
   ============================================ */
.ar-status { text-align: center; padding: 12px 0 8px; }
.ar-status-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: var(--ar-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ar-accent);
}
.ar-status-icon svg { width: 26px; height: 26px; }
.ar-status-title { font-size: 19px; font-weight: 700; margin: 0 0 8px; }
.ar-status-text { font-size: 14px; color: var(--ar-text-muted); margin: 0 0 20px; line-height: 1.5; }

/* ============================================
   TOAST
   ============================================ */
.ar-toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(12px);
  background: #1a1a1a;
  color: #fff;
  padding: 12px 18px;
  border-radius: 24px;
  font-size: 13.5px;
  z-index: 100010;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, transform 0.2s, visibility 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100vw - 32px);
}
.ar-toast.ar-show { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0); }
.ar-toast a { color: #7fb2ff; text-decoration: none; white-space: nowrap; font-weight: 600; }

/* ============================================
   RESPONSIVE — bottom sheet на мобиле
   ============================================ */
@media (max-width: 600px) {
  .ar-modal-backdrop { padding: 0; align-items: flex-end; }
  .ar-modal {
    max-width: 100%;
    max-height: 92vh;
    border-radius: 18px 18px 0 0;
    transform: translateY(100%);
  }
  .ar-modal-backdrop.ar-open .ar-modal { transform: translateY(0); }
  .ar-content { padding: 28px 20px 20px; }
  .ar-title { font-size: 19px; }
  .ar-subtitle { font-size: 13px; }
  .ar-options { gap: 8px; }
  .ar-option { padding: 18px 10px; }
  .ar-option-icon { width: 40px; height: 40px; }
  .ar-result-image img { max-height: 50vh; }
  .ar-result-actions { grid-template-columns: 1fr; gap: 6px; }
  .ar-result-actions .ar-btn { padding: 12px 14px; }
  .ar-loader-title { font-size: 16px; }
}
