/**
 * Product gallery: large photo + thumbnails + lightbox
 * SwimShark — gallery black / brand accent #2b4392
 */

:root {
  --ss-gallery-bg: #fafafa;
  --ss-gallery-ink: #09090b;
  --ss-gallery-muted: #52525b;
  --ss-gallery-accent: #2b4392;
  --ss-gallery-border: #e4e4e7;
  --ss-gallery-lightbox: rgba(9, 9, 11, 0.92);
  --ss-gallery-radius: 12px;
  --ss-gallery-ease: 200ms ease;
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --ss-gallery-ease: 0ms;
  }
}

/* ---------- Inline gallery ---------- */

.ss-product-gallery {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ss-product-gallery__stage {
  position: relative;
  background: transparent;
  border-radius: 0;
  overflow: hidden;
  border: none;
}

.ss-product-gallery__main {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 280px;
  max-height: 520px;
  padding: 16px;
  margin: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
}

.ss-product-gallery[data-lightbox="false"] .ss-product-gallery__main {
  cursor: default;
}

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

.ss-product-gallery__main-img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 480px;
  object-fit: contain;
  transition: opacity var(--ss-gallery-ease), transform var(--ss-gallery-ease);
  will-change: transform;
}

.ss-product-gallery__thumbs {
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 2px 8px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  overscroll-behavior-x: contain;
}

.ss-product-gallery__thumb {
  flex: 0 0 auto;
  width: 72px;
  height: 72px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  margin: 0;
  border: 2px solid transparent;
  border-radius: 8px;
  background: var(--ss-gallery-bg);
  overflow: hidden;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color var(--ss-gallery-ease), box-shadow var(--ss-gallery-ease);
}

.ss-product-gallery__thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ss-product-gallery__thumb:hover {
  border-color: #a1a1aa;
}

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

.ss-product-gallery__thumb.is-active {
  border-color: var(--ss-gallery-accent);
  box-shadow: 0 0 0 1px var(--ss-gallery-accent);
}

.ss-product-gallery__thumbs--hidden {
  display: none;
}

/* Не даём старым max-height/min-height с страницы товара схлопывать галерею —
   иначе миниатюры вылезают из потока и текст наезжает поверх фото на мобилке */
.product-detail-page .product-gallery {
  position: relative;
  z-index: 1;
  min-height: 0 !important;
  max-height: none !important;
  height: auto !important;
  overflow: visible !important;
  margin-bottom: 1.5rem;
}

.product-detail-page .product-des {
  position: relative;
  z-index: 2;
  clear: both;
  margin-top: 0.25rem;
}

@media (max-width: 991.98px) {
  .product-detail-page .product-gallery {
    margin-bottom: 1.25rem;
    /* галерея в потоке контейнера — миниатюры с отступами сайта */
    width: auto;
    max-width: none;
    margin-left: 0;
    margin-right: 0;
  }

  .product-detail-page .ss-product-gallery {
    gap: 10px;
  }

  /* На всю ширину экрана — только большое фото */
  .product-detail-page .ss-product-gallery__stage {
    width: 100vw;
    max-width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
    border: none;
    border-radius: 0;
    background: transparent;
  }

  .product-detail-page .ss-product-gallery__main {
    min-height: 260px;
    max-height: min(70vh, 520px);
    padding: 0;
    touch-action: pan-y;
    user-select: none;
    -webkit-user-select: none;
  }

  .product-detail-page .ss-product-gallery__main-img {
    width: 100%;
    max-width: 100%;
    max-height: min(70vh, 520px);
    object-fit: contain;
    pointer-events: none;
  }

  .product-detail-page .ss-product-gallery__main.is-swiping .ss-product-gallery__main-img {
    transition: none;
  }

  /* Миниатюры — по боковым отступам контейнера сайта */
  .product-detail-page .ss-product-gallery__thumbs {
    padding: 0 0 4px;
    margin: 0;
  }

  .product-detail-page .shop.single .product-des {
    margin-top: 0;
  }

  .product-detail-page .row > .col-lg-6.col-12 {
    flex: 0 0 100%;
    max-width: 100%;
    width: 100%;
  }
}

@media (min-width: 992px) {
  /* Десктоп: миниатюры слева, большое фото справа */
  .ss-product-gallery:not(.ss-product-gallery--single) {
    flex-direction: row;
    align-items: stretch;
    gap: 14px;
  }

  .ss-product-gallery:not(.ss-product-gallery--single) .ss-product-gallery__thumbs:not(.ss-product-gallery__thumbs--hidden) {
    order: -1;
    flex: 0 0 auto;
    flex-direction: column;
    width: 92px;
    max-height: 560px;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 0;
    overscroll-behavior-y: contain;
  }

  .ss-product-gallery__stage {
    flex: 1 1 auto;
    min-width: 0;
  }

  .ss-product-gallery__main {
    min-height: 360px;
    max-height: 560px;
    height: 100%;
  }

  .ss-product-gallery__main-img {
    max-height: 520px;
  }

  .ss-product-gallery__thumb {
    width: 80px;
    height: 80px;
  }

  .product-detail-page .product-gallery {
    margin-bottom: 0;
  }

  .product-detail-page .product-des {
    margin-top: 0;
  }
}

/* ---------- Lightbox ---------- */

.ss-lightbox {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: stretch;
  justify-content: center;
  background: var(--ss-gallery-lightbox);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity var(--ss-gallery-ease), visibility var(--ss-gallery-ease);
}

.ss-lightbox.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.ss-lightbox__inner {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: min(1100px, 100%);
  height: 100%;
  max-height: 100dvh;
  padding: 12px 12px 16px;
  gap: 12px;
}

.ss-lightbox__toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.ss-lightbox__close {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 999px;
  background: rgba(250, 250, 250, 0.12);
  color: #fafafa;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  transition: background var(--ss-gallery-ease);
}

.ss-lightbox__close:hover,
.ss-lightbox__close:focus-visible {
  background: rgba(250, 250, 250, 0.22);
  outline: none;
}

.ss-lightbox__stage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: hidden;
}

.ss-lightbox__img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  user-select: none;
  -webkit-user-select: none;
}

.ss-lightbox__thumbs {
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-start;
  gap: 10px;
  overflow-x: auto;
  padding: 4px 2px 8px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  overscroll-behavior-x: contain;
}

.ss-lightbox__thumb {
  flex: 0 0 auto;
  width: 64px;
  height: 64px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 8px;
  background: rgba(250, 250, 250, 0.08);
  overflow: hidden;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color var(--ss-gallery-ease);
}

.ss-lightbox__thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ss-lightbox__thumb.is-active {
  border-color: #fafafa;
}

.ss-lightbox__thumb:focus-visible {
  outline: 2px solid #fafafa;
  outline-offset: 2px;
}

.ss-lightbox__thumbs--hidden {
  display: none;
}

body.ss-lightbox-open {
  overflow: hidden;
}

@media (min-width: 992px) {
  .ss-lightbox__inner {
    grid-template-columns: 108px 1fr;
    grid-template-rows: auto 1fr;
    padding: 24px;
    gap: 20px;
  }

  .ss-lightbox__toolbar {
    grid-column: 1 / -1;
  }

  .ss-lightbox__thumbs {
    grid-column: 1;
    grid-row: 2;
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    max-height: 100%;
    padding: 0;
    align-self: stretch;
  }

  .ss-lightbox__stage {
    grid-column: 2;
    grid-row: 2;
  }

  .ss-lightbox__thumb {
    width: 88px;
    height: 88px;
  }
}
