:root {
  --product-youtube-height: 200px;
  --product-youtube-crop: 80px;
}

.product-item-photo.has-product-video {
  position: relative;
  display: flex;
  width: 100%;
  height: var(--product-youtube-height) !important;
  min-height: 0 !important;
  padding: 0 !important;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #090909;
}

.product-youtube-media {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: inherit;
  background: #090909;
}

.product-youtube-player,
.product-youtube-media iframe {
  position: absolute;
  top: 50%;
  right: 0;
  left: 0;
  width: 100%;
  height: calc(100% + var(--product-youtube-crop));
  border: 0;
  transform: translateY(-50%);
}

.product-youtube-media iframe {
  pointer-events: none;
}

.product-youtube-toggle {
  position: absolute;
  inset: 0;
  z-index: 2;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  touch-action: pan-y;
}

.product-youtube-play {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 3;
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: 50%;
  background: rgba(0, 0, 0, .62);
  color: #fff;
  font-size: 20px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%);
  transition: opacity .18s ease;
}

.product-youtube-media.is-video-paused .product-youtube-play {
  opacity: 1;
}

.product-youtube-sound,
.product-youtube-link {
  position: absolute;
  z-index: 4;
  border: 0;
  color: #fff;
  background: rgba(0, 0, 0, .66);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}

.product-youtube-sound {
  top: 7px;
  right: 7px;
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  padding: 0;
  border-radius: 50%;
  cursor: pointer;
}

.product-youtube-link {
  right: 7px;
  bottom: 7px;
  left: 7px;
  overflow: hidden;
  padding: 7px 8px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 700;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#pageDataX {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  width: 100%;
}

#pageDataX::before,
#pageDataX::after {
  display: none;
}

#pageDataX > .x-item {
  float: none !important;
  display: flex;
  align-self: stretch;
}

#pageDataX > .x-item > .product-item-info {
  display: flex;
  width: 100%;
  height: 100%;
  flex-direction: column;
}

#pageDataX .product-item-photo {
  width: 100%;
  height: var(--product-youtube-height) !important;
  min-height: var(--product-youtube-height) !important;
  padding: 0 !important;
  flex: 0 0 var(--product-youtube-height);
}

#pageDataX .product-item-img {
  display: flex;
  width: 100%;
  height: 100% !important;
  align-items: center;
  justify-content: center;
}

#pageDataX .product-item-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

#pageDataX .product-item-detail {
  width: 100%;
  flex: 1 1 auto;
}

/* แถวสินค้าใน product_detail.php ให้การ์ดรูปและวิดีโอสูงเท่ากัน */
.product-video-carousel .owl-stage {
  display: flex;
  align-items: stretch;
}

.product-video-carousel .owl-item,
.product-video-carousel .product-item {
  display: flex;
  height: auto;
}

.product-video-carousel .product-item {
  width: 100%;
}

.product-video-carousel .product-item-info {
  display: flex;
  width: 100%;
  height: 100%;
  flex-direction: column;
}

.product-video-carousel .product-item-photo {
  width: 100%;
  height: var(--product-youtube-height) !important;
  min-height: var(--product-youtube-height) !important;
  padding: 0 !important;
  flex: 0 0 var(--product-youtube-height);
}

.product-video-carousel .product-item-img {
  display: flex;
  width: 100%;
  height: 100% !important;
  align-items: center;
  justify-content: center;
}

.product-video-carousel .product-item-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.product-video-carousel .product-item-detail {
  width: 100%;
  flex: 1 1 auto;
}

/* วิดีโอสินค้าหลักใน desktop-gallery ของ product_detail.php */
.desktop-gallery .image_preview_container.has-main-product-video {
  position: relative;
  width: 100%;
  height: clamp(360px, 42vw, 520px);
  overflow: hidden;
  background-color: #fff;
}

.desktop-gallery .image_preview_container.is-showing-video {
  background-color: #090909;
  background-image: none !important;
  cursor: default;
}

.desktop-gallery .has-main-product-video .main-image {
  width: 100%;
  height: 100% !important;
  object-fit: contain;
  object-position: center;
}

.desktop-gallery .main-image.is-hidden,
.product-detail-youtube-shell.is-hidden {
  display: none !important;
}

.product-detail-youtube-shell {
  --product-youtube-crop: 180px;
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: 15px;
  background: #090909;
}

.product-detail-youtube-shell .product-youtube-media {
  width: 100%;
  height: 100%;
}

.product-video-thumbnail .play {
  z-index: 2;
  display: flex;
  width: 34px;
  height: 34px;
  padding: 7px;
  background: rgba(0, 0, 0, .68);
}

.product-video-thumbnail .play img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

@media (min-width: 769px) and (max-width: 991px) {
  .desktop-gallery .image_preview_container.has-main-product-video {
    height: 360px;
  }
}

@media (max-width: 768px) {
  .mobile-swiper .swiper {
    width: 100%;
    overflow: hidden;
    border-radius: 15px;
    background: #fff;
  }

  .mobile-swiper .swiper-slide {
    width: 100%;
    height: min(118vw, 540px);
    min-height: 390px;
    overflow: hidden;
    border-radius: 15px;
    background: #fff;
  }

  .mobile-swiper .product-detail-mobile-image-slide {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .mobile-swiper .product-detail-mobile-image-slide img {
    display: block;
    width: 100%;
    height: 100% !important;
    object-fit: contain;
    object-position: center;
    border-radius: 15px;
  }

  .mobile-swiper .product-detail-mobile-video-slide {
    --product-youtube-crop: 180px;
    background: #090909;
  }

  .mobile-swiper .product-detail-mobile-video-slide .product-youtube-media {
    width: 100%;
    height: 100%;
    border-radius: 15px;
  }

  .mobile-swiper .swiper-pagination-bullet {
    background: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .45);
    opacity: .7;
  }

  .mobile-swiper .swiper-pagination-bullet-active {
    background: #ed168c;
    opacity: 1;
  }
}

@media (max-width: 600px) {
  .product-youtube-sound {
    width: 28px;
    height: 28px;
  }
}
