/* ---------- Страница товара ---------- */

/* Контейнер карточки товара */
.product-detail-container {
  display: grid;
  /* галерея не шире 640px, остальное место — под информацию */
  grid-template-columns: minmax(0, 640px) minmax(0, 1fr);
  gap: 48px;
  padding: 40px 0 80px;
  align-items: start;
}

/* Галерея: главное фото крупно слева (3:4), до двух фото столбиком справа.
   Высоту задаёт главное фото, боковые делят её поровну */
.product-gallery {
  --gallery-gap: 8px;
  width: 100%;
}

.gallery-grid {
  position: relative;
  display: grid;
  grid-template-columns: 2fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: var(--gallery-gap);
}

.gallery-item {
  position: relative;
  display: block;
  width: 100%;
  min-height: 0;
  padding: 0;
  background-color: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: zoom-in;
}

.gallery-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* главное фото: на две строки, пропорции 3:4, но не выше окна
   (68px — шапка, 40px — верхний отступ страницы, 24px — запас снизу) */
.gallery-item:first-child {
  grid-row: span 2;
  aspect-ratio: 3 / 4;
  max-height: calc(100svh - 68px - 40px - 24px);
}

/* фото абсолютно внутри блока — иначе его собственный размер растягивает строки */
.gallery-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.gallery-item:hover .gallery-image {
  transform: scale(1.03);
}

/* одно фото — не растягиваем на всю колонку: по ширине как главное фото
   в сетке из трёх (2/3 от 640px), а колонку галереи сужаем под него */
.gallery-grid--1 {
  grid-template-columns: 1fr;
}

@media (min-width: 641px) {
  .product-detail-container:has(.gallery-grid--1) {
    grid-template-columns: minmax(0, 440px) minmax(0, 1fr);
  }
}

/* два — второе тоже на всю высоту */

.gallery-grid--2 .gallery-item:nth-child(2) {
  grid-row: span 2;
}

/* «⋯» в правом нижнем углу последнего фото, когда фото больше трёх */
.gallery-more {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 36px;
  height: 24px;
  padding: 0;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
  cursor: pointer;
  transition: transform 0.15s ease;
}

.gallery-more span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--ink);
}

.gallery-more:hover {
  transform: scale(1.08);
}

.gallery-more:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Просмотр фото ---------- */
.lightbox {
  width: 100vw;
  height: 100svh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: none;
  background: rgba(10, 10, 10, 0.94);
  color: #fff;
}

.lightbox::backdrop {
  background: transparent;
}

.lightbox-track {
  display: flex;
  width: 100%;
  height: 100%;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  overscroll-behavior: contain;
}

.lightbox-track::-webkit-scrollbar {
  display: none;
}

.lightbox-slide {
  flex: 0 0 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 56px 72px;
  scroll-snap-align: center;
}

.lightbox-slide img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--radius);
}

.lightbox-counter {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 14px;
  font-weight: 600;
  opacity: 0.8;
}

.lightbox-btn {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease;
}

.lightbox-btn:hover {
  background: rgba(255, 255, 255, 0.24);
}

.lightbox-btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.lightbox-close {
  top: 10px;
  right: 12px;
}

.lightbox-prev,
.lightbox-next {
  top: 50%;
  transform: translateY(-50%);
}

.lightbox-prev {
  left: 12px;
}

.lightbox-next {
  right: 12px;
}

.image-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-2);
  text-transform: uppercase;
  font-size: 14px;
  cursor: default;
}

/* Информация о товаре */
.product-info-detail {
  display: flex;
  flex-direction: column;
  gap: 28px;
  /* галерея бывает длинной — инфо и кнопка остаются на экране (68px — высота шапки) */
  position: sticky;
  top: calc(68px + 24px);
}

.title-price-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.detail-title {
  font-family: Archivo, Inter, sans-serif;
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
  color: var(--ink);
}

.detail-price {
  font-size: 24px;
  font-weight: 700;
  color: var(--ink);
}

/* Выбор размера */
.size-selector {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.selector-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ink-2);
}

/* Сами кнопки размеров (.size-options, .size-btn) — в base.css,
   они же используются в окне выбора размера в карточке товара */
.size-empty {
  font-size: 14px;
  color: var(--ink-2);
}

/* Размер + количество + кнопка */
.add-to-cart-form {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* ---------- Количество (форма добавления в корзину) ---------- */
.quantity-selector {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Степпер: [ − ] [ input ] [ + ] одной рамкой, в духе .size-btn */
.quantity-stepper {
  display: inline-flex;
  align-items: stretch;
  width: fit-content;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.qty-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 48px;
  flex-shrink: 0;
  font-size: 18px;
  font-weight: 600;
  line-height: 1;
  color: var(--ink);
  background: var(--bg);
  cursor: pointer;
  transition: background 0.15s ease;
}

.qty-btn:hover {
  background: var(--bg-soft);
}

.qty-btn:active {
  background: var(--line);
}

.qty-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* Инпут количества — Django-виджет с классом quantity-input */
.quantity-input {
  width: 54px;
  height: 48px;
  padding: 0;
  border: none;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  -moz-appearance: textfield;
  appearance: textfield;
}

.quantity-input:focus {
  outline: none;
  background: var(--bg-soft);
}

.quantity-input::-webkit-outer-spin-button,
.quantity-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}

/* Django рендерит ошибки валидации количества стандартным списком — приводим к общему виду */
.quantity-selector ul.errorlist {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}

/* Главная кнопка "В корзину" */
.btn-large {
  width: 100%;
  padding: 16px;
  background: var(--ink);
  color: var(--bg);
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: opacity 0.15s ease;
  margin-top: 8px;
}

.btn-large:hover {
  opacity: 0.9;
}

.btn-large:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Блок описания */
.detail-description {
  margin-top: 8px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.detail-description h3 {
  font-family: Archivo, Inter, sans-serif;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 12px;
  font-weight: 700;
  color: var(--ink-2);
}

.description-text {
  font-size: 15px;
  color: var(--ink);
  line-height: 1.6;
}

.description-text p {
  margin-bottom: 12px;
}

.description-text p:last-child {
  margin-bottom: 0;
}

/* свёрнутое описание: ~8 строк с плавным затуханием снизу (класс ставит JS) */
.description-text.is-collapsed {
  max-height: calc(15px * 1.6 * 8);
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, #000 60%, transparent);
  mask-image: linear-gradient(to bottom, #000 60%, transparent);
}

.description-toggle {
  margin-top: 12px;
  padding: 0 0 2px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.description-toggle:hover {
  border-color: var(--ink);
}

.description-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Похожие товары ---------- */
.related-products {
  padding: 24px 0 80px;
  border-top: 1px solid var(--line);
}

.related-title {
  font-family: Archivo, Inter, sans-serif;
  font-size: clamp(22px, 3vw, 30px);
  font-weight: 700;
  text-align: center;
  margin-bottom: 24px;
}

.related-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 40px 20px;
}

@media (max-width: 960px) {
  .related-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 28px 14px;
  }
}

/* ---------- Мобильная адаптивность ---------- */
@media (max-width: 640px) {
  .product-detail-container {
    grid-template-columns: 1fr;
    gap: 24px;
    padding: 20px 0 40px;
  }

  .product-info-detail {
    position: static;
  }

  .product-gallery {
    --gallery-gap: 6px;
  }

  /* на телефоне листают свайпом — стрелки только мешают */
  .lightbox-prev,
  .lightbox-next {
    display: none;
  }

  .lightbox-slide {
    padding: 56px 12px;
  }

  .detail-title {
    font-size: 24px;
  }

  .detail-price {
    font-size: 20px;
  }

  .btn-large {
    padding: 14px;
    font-size: 15px;
  }

  .related-products {
    padding-bottom: 40px;
  }
}