/* refine.css — модалка «Мы всё подобрали — просто проверьте»
   Открывается ПЕРЕД генерацией (после Vision-анализа), рендерится внутри pdp.html.
   Дизайн — «Экслибрис»: кремовая карточка-паспарту на бумаге, Playfair Display +
   Golos Text, синий CTA, латунные акценты-искры. Токены — из theme.css (--skz-*).
   Разметку и всю логику модалки держит refine-modal.js — здесь только визуал. */

:root {
  --re-paper:      var(--skz-bg, #F7F1E4);       /* бумага-фон                    */
  --re-card:       var(--skz-surface, #FCF8EE);  /* карточка / светлые окна        */
  --re-endpaper:   var(--skz-sand, #EFE7D2);     /* форзац: вставки, hover-подложки */
  --re-ink:        var(--skz-chocolate, #232E47);/* основной текст / заголовки      */
  --re-ink-soft:   var(--skz-gray-warm, #545D70);/* вторичный текст                 */
  --re-brass:      var(--skz-gold, #A67C2E);     /* латунь: искра, декор            */
  --re-brass-soft: var(--skz-light-tan, #C9B87E);/* светлая латунь: кромки          */
  --re-brass-text: var(--skz-gold-hover, #6E5316);/* текст-золото: ссылки, кикеры   */
  --re-blue:       var(--skz-coral, #24406E);    /* CTA / фокус (имя legacy — синий) */
  --re-blue-press: var(--skz-coral-hover, #1B3355);/* CTA hover/pressed             */
  --re-line:       var(--skz-line, #DCD1B8);     /* линии, рамки                    */
  --re-line-deep:  var(--skz-line-deep, #C9BFA9);/* контрастная линия / пунктир     */
  --re-success:    var(--success-text, var(--skz-success, #355E3B));
  --re-danger:     var(--danger-text, var(--skz-warning, #8C3B2E));
  --re-serif:      var(--skz-font-serif, "Playfair Display", Georgia, serif);
  --re-sans:       var(--skz-font-sans, "Golos Text", system-ui, sans-serif);
}

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

/* Standalone-подложка (модалка использует .refine-modal-overlay из refine-modal.js;
   правило сохранено на случай прямого рендера карточки вне модалки). */
.refine-body {
  background: var(--re-endpaper);
  color: var(--re-ink);
  font-family: var(--re-sans);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

/* ── Карточка-паспарту ─────────────────────────────────────────────────── */
.refine-card {
  background: var(--re-card);
  border: 1px solid var(--re-line);
  border-radius: 8px;
  padding: 20px 22px;
  max-width: 600px;
  width: 100%;
  box-shadow: 0 24px 64px rgba(35, 46, 71, .16);
  font-family: var(--re-sans);
  color: var(--re-ink);
}

/* ── Шапка: искра-навершие + заголовок + лид ───────────────────────────── */
.refine-card__head { text-align: left; margin-bottom: 14px; }
.refine-kick { display: block; line-height: 0; margin: 0 0 9px; }
.refine-spark { width: 22px; height: 22px; fill: var(--re-brass); }
.refine-card__title {
  font-family: var(--re-serif);
  font-weight: 800;
  font-size: clamp(1.35rem, 2.2vw, 1.6rem);
  line-height: 1.2;
  color: var(--re-ink);
  margin: 0 0 6px;
  text-wrap: balance;
}
/* Гасим двойной тап-зум/задержку на интерактиве модалки */
.refine-swatch,
.refine-slot,
.refine-slot__remove,
.refine-foot__cancel,
.refine-foot__cta { touch-action: manipulation; }
.refine-card__lead {
  margin: 0;
  color: var(--re-ink-soft);
  font-size: .9rem;
  line-height: 1.5;
}

/* ── Hero: аватар ребёнка + книга / имя / возраст ──────────────────────── */
.refine-hero {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  background: var(--re-endpaper);
  border: 1px solid var(--re-line);
  border-radius: 8px;
  margin-bottom: 14px;
}
.refine-hero__avatar {
  width: 52px; height: 52px;
  border-radius: 50%;
  overflow: hidden;
  background-color: var(--re-card);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23A67C2E'%3E%3Ccircle cx='12' cy='8' r='4'/%3E%3Cpath d='M4 20c0-4 3.6-6 8-6s8 2 8 6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 58%;
  border: 2px solid var(--re-brass-soft);
  flex-shrink: 0;
}
.refine-hero__avatar img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.refine-hero__avatar img.is-broken { display: none; }
.refine-hero__info { min-width: 0; }
.refine-hero__book {
  margin: 0 0 3px;
  font-family: var(--re-serif);
  font-weight: 800;
  font-size: 1.02rem;
  line-height: 1.2;
  color: var(--re-ink);
  block-size: 2.4em;
  display: -webkit-box;
  overflow: hidden;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.refine-hero__child {
  margin: 0;
  font-size: .88rem;
  color: var(--re-ink);
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.refine-hero__child strong { font-weight: 600; }
.refine-hero__sep { color: var(--re-brass-text); }

/* ── Поле: цвет глаз (латунная каталожная подпись + палитра-свотчи) ─────── */
.refine-fields { margin-bottom: 14px; }
.refine-field { min-width: 0; }
.refine-field__label {
  display: block;
  font-family: var(--re-sans);
  font-weight: 500;
  font-size: .72rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--re-brass-text);
  margin-bottom: 10px;
}
.refine-swatches {
  display: grid;
  gap: 8px 6px;
}
#reEyeColor { grid-template-columns: repeat(5, 1fr); }
.refine-swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  border: 0;
  background: none;
  cursor: pointer;
  border-radius: 6px;
}
.refine-swatch__dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  /* тонкий тёмный кант, чтобы светлые оттенки не сливались с фоном */
  box-shadow: inset 0 0 0 1px rgba(35, 46, 71, .22),
              inset 0 3px 5px rgba(255, 255, 255, .18);
  transition: box-shadow .16s ease, transform .16s ease;
}
.refine-swatch__name {
  font-size: .7rem;
  line-height: 1.15;
  text-align: center;
  color: var(--re-ink-soft);
  transition: color .16s ease;
}
.refine-swatch:hover .refine-swatch__dot {
  transform: scale(1.08);
  box-shadow: inset 0 0 0 1px rgba(35, 46, 71, .22),
              0 0 0 2px var(--re-card), 0 0 0 3px var(--re-brass-soft);
}
/* Выбор — латунное кольцо + латунная подпись (два признака, не только цвет) */
.refine-swatch.is-selected .refine-swatch__dot {
  box-shadow: inset 0 0 0 1px rgba(35, 46, 71, .25),
              0 0 0 2px var(--re-card), 0 0 0 3px var(--re-brass);
}
.refine-swatch.is-selected .refine-swatch__name {
  color: var(--re-brass-text);
  font-weight: 600;
}
/* Клавиатурный фокус — синяя обводка (без outline:none) */
.refine-swatch:focus-visible {
  outline: 2px solid var(--re-blue);
  outline-offset: 2px;
}

/* ── Совет: добавить ещё фото ──────────────────────────────────────────── */
.refine-tip {
  padding: 16px;
  background: var(--re-endpaper);
  border: 1px solid var(--re-line);
  border-radius: 8px;
  margin-bottom: 14px;
}
.refine-tip__body { min-width: 0; }
.refine-tip__title {
  margin: 0 0 4px;
  font-size: .9rem;
  color: var(--re-ink);
  line-height: 1.35;
}
.refine-tip__title strong { color: var(--re-brass-text); font-weight: 600; }
.refine-tip__text {
  margin: 0 0 4px;
  font-size: .82rem;
  color: var(--re-ink-soft);
  line-height: 1.4;
}
.refine-tip__note {
  margin: 0 0 14px;
  font-size: .76rem;
  color: var(--re-ink-soft);
  line-height: 1.4;
}

/* ── Слот главного фото (анфас) — замена основного снимка ───────────────
   Доп. ракурсы (профиль / полоборота / полный рост) временно убраны, остался
   один слот. Сетка одноколоночная фиксированной ширины, чтобы квадрат превью
   не растягивался на всю карточку. */
.refine-slots {
  display: grid;
  grid-template-columns: 108px;
  gap: 12px;
}
.refine-slot {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  touch-action: manipulation;
}
/* Файл-инпут: sr-only, НО фокусируемый — клавиатурный доступ к загрузке
   (раньше был hidden → недоступен с клавиатуры). Логика чтения .files не меняется. */
.refine-slot__input {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
/* Название роли — НАД окошком; min-height резервирует 2 строки, чтобы квадраты
   превью у всех 4 слотов стояли на одной линии независимо от длины заголовка. */
.refine-slot__role {
  min-height: 2.1em;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .76rem;
  font-weight: 600;
  color: var(--re-ink);
  text-align: center;
  line-height: 1.15;
}
.refine-slot__frame {
  position: relative; /* база для «×» и badge в углу превью */
  display: block;
  width: 100%;
}
.refine-slot__preview {
  position: relative; /* для badge на анфас-слоте */
  width: 100%;
  aspect-ratio: 1 / 1; /* квадрат: без max-height, иначе landscape при широкой колонке */
  border: 1.5px dashed var(--re-line-deep);
  border-radius: 6px;
  background: var(--re-card) center / cover no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .2s, background-color .2s;
}
.refine-slot__plus {
  color: var(--re-brass-text);
  font-family: var(--re-sans);
  font-size: 2rem;
  font-weight: 500;
  line-height: 1;
  pointer-events: none;
}
.refine-slot:hover .refine-slot__preview {
  border-color: var(--re-brass);
  background-color: var(--re-endpaper);
}
.refine-slot.is-filled .refine-slot__preview {
  border-style: solid;
  border-color: var(--re-line);
}
.refine-slot.is-filled .refine-slot__plus { display: none; }
/* Клавиатурный фокус инпута → видимая обводка на его окошке-превью */
.refine-slot__input:focus-visible ~ .refine-slot__frame .refine-slot__preview {
  outline: 2px solid var(--re-blue);
  outline-offset: 2px;
}
/* Анфас-слот: бейдж «поменять» в углу превью (виден, когда фото есть) — усиливает
   подпись-кнопку «Поменять фото» под окошком. */
.refine-slot__replace-badge {
  position: absolute;
  right: 5px; bottom: 5px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--re-brass);
  color: var(--re-card);
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(35, 46, 71, .28);
}
.refine-slot__replace-badge svg { width: 13px; height: 13px; }
.refine-slot--face.is-filled .refine-slot__replace-badge { display: flex; }
.refine-slot--face:hover .refine-slot__preview { filter: brightness(.95); }
/* Подпись-кнопка под окошком: «Загрузить фото» (пусто) → «Поменять фото» (есть фото). */
.refine-slot__action {
  font-size: .74rem;
  font-weight: 600;
  color: var(--re-brass-text);
  text-align: center;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}
.refine-slot:hover .refine-slot__action { color: var(--re-brass); }
.refine-slot__action-change { display: none; }
.refine-slot.is-filled .refine-slot__action-upload { display: none; }
.refine-slot.is-filled .refine-slot__action-change { display: inline; }
.refine-slot__hint {
  font-size: .68rem;
  color: var(--re-ink-soft);
  text-align: center;
  line-height: 1.2;
}
.refine-slot__validation {
  display: none;
  font-size: .68rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-wrap: pretty;
}
.refine-slot.has-validation .refine-slot__hint { display: none; }
.refine-slot.has-validation .refine-slot__validation { display: block; }
.refine-slot.is-validation-accepted .refine-slot__validation { color: var(--re-success); }
.refine-slot.is-validation-rejected .refine-slot__validation { color: var(--re-danger); }
.refine-slot.is-validation-unavailable .refine-slot__validation { color: var(--re-ink-soft); }
.refine-photos__validation-detail {
  display: grid;
  gap: 4px;
  margin-top: 8px;
  color: var(--re-danger);
  font: 500 13px/1.45 var(--re-sans);
}
.refine-photos__validation-detail:empty { display: none; }
.refine-photos__validation-detail p { margin: 0; }
.refine-photos__validation-detail p.is-unavailable { color: var(--re-ink-soft); }
.refine-slot__remove {
  position: absolute;
  top: -7px; right: -7px;
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 0;
  background: var(--re-ink);
  color: var(--re-card);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(35, 46, 71, .25);
}
.refine-slot__remove:hover { background: var(--re-blue-press); }
/* display:flex перебивает атрибут hidden — вернуть скрытие для пустого слота */
.refine-slot__remove[hidden] { display: none; }

/* ── Footer (CTA) ──────────────────────────────────────────────────────── */
.refine-foot {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  border-top: 1px solid var(--re-line);
  padding-top: 16px;
}
.refine-foot__cancel {
  min-height: 44px;
  padding: 11px 18px;
  border: 1px solid var(--re-line);
  border-radius: 6px;
  background: transparent;
  color: var(--re-ink-soft);
  font: 500 .9rem/1.2 var(--re-sans);
  cursor: pointer;
  transition: color .2s, background-color .2s, border-color .2s;
}
.refine-foot__cancel:hover {
  color: var(--re-ink);
  background: var(--re-endpaper);
  border-color: var(--re-brass-soft);
}
.refine-foot__cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 15px 32px;
  border-radius: 6px;
  background: var(--re-blue);
  color: var(--re-card);
  border: 1px solid transparent;
  font-family: var(--re-sans);
  font-weight: 600;
  font-size: .98rem;
  cursor: pointer;
  transition: background .2s, box-shadow .2s, transform .15s;
}
.refine-foot__cta:hover:not(:disabled) {
  background: var(--re-blue-press);
  box-shadow: inset 0 0 0 1px var(--re-brass-soft);
}
.refine-foot__cta:active:not(:disabled) { transform: scale(.99); }
.refine-foot__cta:disabled { opacity: .5; cursor: not-allowed; }

/* Общий видимый фокус для кнопок модалки */
.refine-slot__remove:focus-visible,
.refine-foot__cancel:focus-visible,
.refine-foot__cta:focus-visible {
  outline: 2px solid var(--re-blue);
  outline-offset: 2px;
}

/* ── Оверрайд модалки (OVERLAY_CSS инжектится refine-modal.js; перебиваем
   повышенной специфичностью — бумажный бэкдроп/тень + reduced-motion, без !important). */
body.refine-modal-open .refine-modal-overlay {
  background: rgba(35, 46, 71, .45);
  overscroll-behavior: contain;
}
body.refine-modal-open .refine-modal-overlay .refine-card {
  max-width: 600px;
  box-shadow: 0 24px 64px rgba(35, 46, 71, .16);
}

/* ── Mobile ────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .refine-card {
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: max(12px, env(safe-area-inset-top)) 14px max(12px, env(safe-area-inset-bottom));
    overflow: hidden;
  }
  .refine-card__head { margin-bottom: 16px; }
  .refine-hero { margin-bottom: 16px; }
  .refine-fields { margin-bottom: 16px; }
  .refine-tip { margin-bottom: 0; }
  .refine-kick { display: none; }
  .refine-card__title {
    margin-bottom: 6px;
    font-size: 1.22rem;
    line-height: 1.16;
  }
  .refine-card__lead { font-size: .78rem; line-height: 1.4; }
  .refine-hero { gap: 12px; padding: 10px 12px; }
  .refine-hero__avatar { width: 44px; height: 44px; }
  .refine-hero__info { flex: 1; overflow: hidden; }
  .refine-hero__book {
    margin-bottom: 2px;
    font-size: .88rem;
  }
  .refine-hero__child { font-size: .78rem; }
  .refine-field__label { margin-bottom: 6px; font-size: .66rem; }
  .refine-swatches { gap: 0 4px; }
  .refine-swatch { min-height: 48px; gap: 4px; padding: 2px 0; }
  .refine-swatch__dot { width: 28px; height: 28px; }
  .refine-swatch__name { font-size: .62rem; }
  .refine-tip {
    min-height: 0;
    padding: 12px;
    display: flex;
    align-items: stretch;
  }
  .refine-tip__body {
    width: 100%;
    display: flex;
    min-height: 0;
    flex-direction: column;
  }
  .refine-tip__title {
    flex: 0 0 auto;
    margin-bottom: 4px;
    font-size: .78rem;
    line-height: 1.3;
    font-weight: 600;
  }
  .refine-tip__text {
    margin-bottom: 4px;
    font-size: .74rem;
    line-height: 1.35;
  }
  .refine-tip__note {
    margin-bottom: 12px;
    font-size: .7rem;
    line-height: 1.3;
  }
  .refine-slots { min-height: 0; gap: 8px; grid-template-columns: 120px; }
  .refine-slot { min-width: 0; gap: 4px; }
  .refine-slot__role {
    min-height: 1.2em;
    font-size: clamp(.58rem, 2.7vw, .68rem);
    line-height: 1.1;
    white-space: nowrap;
  }
  .refine-slot__frame { width: 120px; }
  .refine-slot__action {
    min-height: 22px;
    display: flex;
    align-items: center;
    font-size: .66rem;
    line-height: 1.1;
  }
  .refine-slot__hint {
    min-height: 2.3em;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    font-size: .61rem;
    line-height: 1.15;
  }
  .refine-slot__validation {
    min-height: 2.3em;
    font-size: .61rem;
    line-height: 1.15;
  }
  .refine-slot__replace-badge { width: 22px; height: 22px; }
  .refine-foot { margin-top: auto; gap: 8px; padding-top: 12px; }
  .refine-foot__cancel,
  .refine-foot__cta { min-height: 44px; padding: 10px 12px; }
  .refine-foot__cancel { flex: 0 0 auto; }
  .refine-foot__cta { flex: 1 1 auto; font-size: .86rem; }
}

/* На невысоких телефонах сохраняем группировку, но уменьшаем только межсекционный
   ритм. Внутренние touch-target и читаемость не сжимаются. */
@media (max-width: 640px) and (max-height: 700px) {
  .refine-card__head,
  .refine-hero,
  .refine-fields { margin-bottom: 12px; }
  .refine-card__title { margin-bottom: 4px; }
  .refine-card__lead { line-height: 1.3; }
  .refine-hero { gap: 10px; padding: 8px 10px; }
  .refine-field__label { margin-bottom: 4px; }
  .refine-swatch { min-height: 44px; gap: 2px; padding: 0; }
  .refine-tip { padding: 10px; }
  .refine-tip__title { margin-bottom: 2px; }
  .refine-tip__text { margin-bottom: 2px; }
  .refine-tip__note { margin-bottom: 8px; }
  .refine-foot { padding-top: 8px; }
}

@media (max-width: 640px) and (max-height: 620px) {
  .refine-card__head,
  .refine-hero,
  .refine-fields { margin-bottom: 8px; }
  .refine-hero { padding: 6px 10px; }
  .refine-tip { padding: 8px; }
  .refine-foot { padding-top: 4px; }
}

@media (max-width: 640px) and (max-height: 560px) {
  .refine-card { height: auto; overflow: visible; }
}

/* ── Reduced motion ────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .refine-swatch__dot,
  .refine-swatch__name,
  .refine-slot__preview,
  .refine-slot__action,
  .refine-foot__cancel,
  .refine-foot__cta { transition: none; }
  .refine-swatch:hover .refine-swatch__dot,
  .refine-foot__cta:active:not(:disabled) { transform: none; }
  body.refine-modal-open .refine-modal-overlay,
  body.refine-modal-open .refine-modal-overlay .refine-card { animation: none; }
}
