/* Подключите этот файл ПОСЛЕ основного CSS/Tailwind, чтобы правила карточек имели приоритет. */

.product-grid,
.product-grid * {
  box-sizing: border-box;
}

.product-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: clamp(16px, 2vw, 24px);
  width: 100%;
  max-width: 1320px;
  margin-inline: auto;
}

/* Карточка повторяет пропорции исходника: 316 × 391 px. */
.product-card {
  position: relative;
  isolation: isolate;
  container-type: inline-size;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  aspect-ratio: 316 / 391;
  padding: 14px 24px 20px;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.055);
  border-radius: 32px;
  background: #f1f1ee;
  color: #111;
}

.product-actions {
  position: absolute;
  z-index: 10;
  top: 14px;
  right: 14px;
  display: flex;
  gap: 7px;
}

.product-action-button {
  display: grid;
  flex: 0 0 35px;
  place-items: center;
  width: 35px;
  height: 35px;
  padding: 0;
  border: 1px solid rgba(0, 0, 0, 0.13);
  border-radius: 50%;
  background: #f1f1ee;
  color: #171717;
  cursor: pointer;
  transition: background-color 180ms ease, color 180ms ease, border-color 180ms ease;
}

.product-action-button:hover,
.product-action-button:focus-visible {
  border-color: #111;
  background: #111;
  color: #fff;
}

.product-card svg {
  display: block;
  width: 16px;
  height: 16px;
  stroke-width: 1.6;
}

.product-image {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-width: 0;
  min-height: 0;
  margin: 10px 0 12px;
  padding: 0;
  overflow: hidden;
  border: 0;
  outline-offset: 3px;
  background: transparent;
  cursor: pointer;
}

.product-image img {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  object-fit: contain;
  object-position: center;
  mix-blend-mode: multiply;
  transform: translateZ(0);
  transition: transform 500ms cubic-bezier(0.2, 0.65, 0.3, 1);
}

.product-card:hover .product-image img {
  transform: scale(1.025);
}

.product-footer {
  position: relative;
  z-index: 5;
  display: flex;
  flex: 0 0 auto;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-width: 0;
  margin-top: auto;
}

.product-info {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.product-category {
  display: block;
  max-width: 100%;
  overflow: hidden;
  color: #888;
  font-size: 9px;
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0.15em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.product-name {
  display: block;
  max-width: 100%;
  margin: 0;
  overflow: hidden;
  color: #111;
  font-size: clamp(16px, 6.35cqw, 21px);
  font-weight: 500;
  line-height: 1.06;
  letter-spacing: -0.045em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.product-price {
  display: block;
  margin-top: 1px;
  color: #888;
  font-size: 15px;
  font-weight: 400;
  line-height: 1;
  white-space: nowrap;
}

.product-switcher {
  display: flex;
  flex: 0 0 74px;
  align-items: center;
  justify-content: space-between;
  width: 74px;
  height: 34px;
  margin: 0 0 0 auto;
  padding: 1px;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.13);
  border-radius: 999px;
  background: transparent;
}

.product-switcher button {
  display: grid;
  flex: 1 1 0;
  place-items: center;
  width: 30px;
  min-width: 0;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #aaa;
  cursor: pointer;
  transition: color 180ms ease, background-color 180ms ease;
}

.product-switcher button:hover,
.product-switcher button:focus-visible {
  color: #111;
}

.product-switcher-divider {
  flex: 0 0 1px;
  width: 1px;
  height: 14px;
  background: rgba(0, 0, 0, 0.13);
}

/* Затемнение/выбор размера остаётся внутри самой карточки. */
.product-card .size-overlay {
  position: absolute;
  z-index: 20;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  box-sizing: border-box;
  padding: auto;
  overflow: auto;
  border-radius: inherit;
  background: #111;
  color: #fff;
  transition: opacity 300ms ease;
}

.product-card .btn-close-size {
  position: absolute;
  top: 14px;
  right: 14px;
  display: grid;
  place-items: center;
  width: 35px;
  height: 35px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  background: transparent;
  color: #fff;
  cursor: pointer;
}

.product-card .btn-close-size:hover,
.product-card .btn-close-size:focus-visible {
  background: #fff;
  color: #111;
}

.size-options {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 100%;
  margin-bottom: 16px;
}

.size-option {
  display: grid;
  flex: 0 0 40px;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  background: transparent;
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}

.size-option:hover,
.size-option:focus-visible,
.size-option.is-selected {
  background: #fff;
  color: #111;
}

.size-hint {
  margin: 0 0 5px;
  color: #999;
  font-size: 13px;
  line-height: 1.3;
  text-align: center;
}

.product-card .btn-guide {
  padding: 4px 0;
  border: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.35);
  background: transparent;
  color: #999;
  font-size: 11px;
  line-height: 1.4;
  cursor: pointer;
}

.product-card .btn-guide:hover,
.product-card .btn-guide:focus-visible {
  color: #fff;
  border-bottom-color: #fff;
}

/* 1 / 2 / 3 / 4 колонки по доступной ширине. */
@media (min-width: 620px) {
  .product-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 900px) {
  .product-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 1200px) {
  .product-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* Компактная карточка не даёт подписи и кнопкам выходить за границы. */
@container (max-width: 290px) {
  .product-actions {
    top: 11px;
    right: 11px;
    gap: 6px;
  }

  .product-action-button {
    flex-basis: 32px;
    width: 32px;
    height: 32px;
  }

  .product-switcher {
    flex-basis: 66px;
    width: 66px;
    height: 32px;
  }

  .product-switcher button {
    height: 28px;
  }

  .product-image {
    margin-top: 8px;
    margin-bottom: 10px;
  }
}

@media (max-width: 360px) {
  .product-card {
    padding: 13px 18px 18px;
    border-radius: 29px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .product-image img,
  .product-action-button,
  .product-switcher button,
  .product-card .size-overlay {
    transition: none;
  }
}

/* Правки карточки товара */


/* ----- Мобильная версия: детали товара ----- */
@media (max-width: 600px) {

  /* Окно карточки: отступ от краёв и безопасное положение */
  .product-detail-dialog {
    display: flex;
    flex-direction: column;

    width: 100%;
    min-width: 0;
    min-height: 0;

    /* Учитываем динамическую высоту мобильного браузера */
    max-height: calc(100vh - 48px);
    max-height: calc(100dvh - 48px);

    overflow-x: hidden;
    overflow-y: auto;

    border-radius: 26px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  /* Колонка с изображением */
  .detail-media-column {
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;

    width: 100%;
    min-width: 0;
    padding: 12px 12px 0;
  }

  /* Большая квадратная область изображения */
  .detail-image-stage {
    flex: 0 0 auto;

    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    min-height: 0;

    overflow: hidden;
  }

  .detail-image {
    display: block;

    width: 100%;
    height: 100%;
    min-height: 0;

    object-fit: contain;
    object-position: center;
  }

  /* Переключение фотографий */
  .detail-gallery-controls {
    flex: 0 0 auto;
    height: 38px;
    margin-top: 4px;
    margin-bottom: 4px;
  }

  .detail-gallery-controls button {
    width: 30px;
    height: 30px;
  }

  /* Информация о товаре */
  .detail-info-column {
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;

    width: 100%;
    min-width: 0;
    padding: 12px 20px 22px;
  }

  .detail-title {
    font-size: clamp(25px, 7vw, 31px);
  }

  .detail-price {
    margin-bottom: 12px;
  }

  .detail-size-help {
    margin-top: 10px;
    margin-bottom: 12px;
  }

  .detail-actions {
    margin-top: 12px;
    padding-top: 0;
  }

  /* Выбор размера не должен выходить за границы окна */
  .modal-size-picker {
    max-width: 100%;
    box-sizing: border-box;
  }
}

/* ----- Мобильное позиционирование модальных окон ----- */
@media (max-width: 600px) {

  /*
    Если родительский контейнер использует flex для центрирования,
    карточка останется с отступом сверху и снизу.
  */
  .product-detail-dialog,
  .size-guide-dialog {
    scroll-margin-top: 24px;
    scroll-margin-bottom: 24px;
  }
}

/* Очень узкие экраны */
@media (max-width: 380px) {
  .detail-info-column {
    padding-right: 16px;
    padding-left: 16px;
  }
}

