/* Agent A — gallery và liên quan. Không thay đổi card/mua hàng dùng chung. */
.template-product .pd3-gal { min-width: 0; margin-bottom: 24px; }
.template-product .pd3-gal #ProductPhoto {
  position: relative; padding: 0; background: #fff; border: 1px solid #dce4e8;
  border-radius: 16px; aspect-ratio: 1; box-shadow: none;
}
.template-product .pd3-gal #ProductPhoto .pd3-gal-trigger {
  display: flex; position: relative; width: 100%; height: 100%; align-items: center;
  justify-content: center; border-radius: 16px; background: #fff; overflow: hidden; touch-action: pan-y pinch-zoom;
}
.template-product .pd3-gal #ProductPhotoImg {
  display: block; width: 100%; height: 100%; max-height: none; padding: 4%;
  box-sizing: border-box; object-fit: contain; transform: none !important; filter: none;
}
.template-product .pd3-gal-hint {
  position: absolute; right: 12px; bottom: 12px; padding: 8px 12px;
  background: #fff; color: #0b1118; border: 1px solid #dce4e8; border-radius: 24px; font-size: 12px; line-height: 18px;
}
.template-product .pd3-gal #ProductThumbs {
  display: flex; justify-content: flex-start; gap: 10px; width: 100%; margin: 12px 0 0;
  padding: 2px 2px 6px; list-style: none; overflow-x: auto; scroll-snap-type: x proximity;
  max-height: none; scrollbar-width: thin; box-sizing: border-box;
}
.template-product .pd3-gal-thumb { display: block; flex: 0 0 64px; width: 64px; height: 64px; margin: 0; padding: 0; scroll-snap-align: start; }
.template-product .pd3-gal #ProductThumbs .pd3-gal-thumb-link {
  display: block; width: 100%; height: 100%; padding: 3px; border: 1px solid #dce4e8;
  border-radius: 10px; box-sizing: border-box; overflow: hidden; background: #fff;
}
.template-product .pd3-gal #ProductThumbs .pd3-gal-thumb-link[aria-current="true"] { border: 2px solid #007fae; padding: 2px; }
.template-product .pd3-gal #ProductThumbs img { display: block; width: 100%; height: 100%; object-fit: contain; transform: none; }
.template-product .pd3-gal a:focus-visible,
.template-product .pd3-gal button:focus-visible,
.template-product .pd3-rel :focus-visible { outline: 3px solid #007fae; outline-offset: 3px; }
.template-product .pd3-gal-dialog:not([open]) { display: none; }
.template-product .pd3-gal-dialog[open] {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 100%; max-width: none; height: 100%; height: 100dvh; max-height: none;
  margin: 0; padding: 64px 24px 16px; box-sizing: border-box; border: 0;
  background: rgba(3,8,13,.94); color: #fff; overflow: auto; overscroll-behavior: contain;
}
.template-product .pd3-gal-dialog::backdrop { background: #03080d; }
.template-product .pd3-gal-stage {
  display: flex; align-items: center; justify-content: center; flex: 0 1 auto;
  width: min(100%, 1000px, calc(100dvh - 152px)); aspect-ratio: 1;
  min-height: 0; margin: 0; padding: 0; background: #fff; border-radius: 16px;
  overflow: hidden; touch-action: pan-y pinch-zoom;
}
.template-product .pd3-gal-large { display: block; width: 100%; height: 100%; object-fit: contain; transform: none; padding: 2%; box-sizing: border-box; }
.template-product .pd3-gal-dialog button {
  display: inline-flex; flex: 0 0 44px; align-items: center; justify-content: center;
  width: 44px; height: 44px; min-width: 44px; min-height: 44px; margin: 0; padding: 0;
  border: 1px solid #75818b; border-radius: 50%; background: #15212c; color: #fff;
  font: 32px/1 Arial,sans-serif; cursor: pointer;
}
.template-product .pd3-gal-dialog button[hidden] { display: none; }
.template-product .pd3-gal-dialog .pd3-gal-close { position: absolute; top: 12px; right: 16px; }
.template-product .pd3-gal-controls { display: flex; flex: 0 0 60px; align-items: center; justify-content: center; gap: 20px; }
.template-product .pd3-gal-count { min-width: 48px; text-align: center; font-size: 14px; font-variant-numeric: tabular-nums; }
.template-product .pd3-rel { clear: both; width: 100%; padding: 0; margin-top: 64px; margin-bottom: 24px; }
.template-product .pd3-rel-title { margin: 0 0 24px; text-align: left; color: #0b1118; font-size: 32px; line-height: 40px; font-weight: 700; letter-spacing: -.025em; }
.template-product .pd3-rel-rail { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 20px; margin: 0; padding: 0; }
.template-product .pd3-rel-item { display: flex; min-width: 0; }
.template-product .pd3-rel-item > .product-container { width: 100%; margin: 0; }
.template-product .pd3-rel .product-container { border-radius: 16px; box-shadow: none; transform: none; }
.template-product .pd3-rel .product-image { background: #fff; }
.template-product .pd3-rel .product-thumbnail img { transform: none !important; object-fit: contain; padding: 12px; box-sizing: border-box; }
.template-product .pd3-rel .product-container { height: 100%; }
.template-product .pd3-rel .product-tags { flex-wrap: wrap; overflow: visible; white-space: normal; }
.template-product .pd3-rel .product-tags > * { max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
.template-product .pd3-rel .product-actions > a,
.template-product .pd3-rel .product-actions > button { min-height: 44px; }
@media (min-width: 1440px) { .template-product .pd3-rel-rail { grid-template-columns: repeat(5,minmax(0,1fr)); } }
@media (min-width: 769px) and (max-width: 1023px) { .template-product .pd3-rel-rail { grid-template-columns: repeat(3,minmax(0,1fr)); gap: 16px; } }
@media (max-width: 768px) {
  .template-product .pd3-gal-thumb { flex-basis: 56px; width: 56px; height: 56px; }
  .template-product .pd3-gal-dialog[open] { padding: 60px 12px 12px; }
  .template-product .pd3-rel { margin-top: 40px; }
  .template-product .pd3-rel-title { font-size: 24px; line-height: 31px; margin-bottom: 16px; }
  .template-product .pd3-rel-rail {
    display: flex; gap: 12px; overflow-x: auto; overscroll-behavior-x: contain;
    scroll-snap-type: x proximity; scroll-padding-inline: 15px; scrollbar-width: thin; padding: 4px 15px 12px; margin-inline: -15px; width: calc(100% + 30px);
  }
  .template-product .pd3-rel-item { flex: 0 0 172px; width: 172px; scroll-snap-align: start; }
  html[data-mobile-theme="dark"] .template-product .pd3-rel-title { color: #f1f6f8; }
  html[data-mobile-theme="dark"] .template-product .pd3-gal #ProductPhoto,
  html[data-mobile-theme="dark"] .template-product .pd3-gal #ProductPhoto .pd3-gal-trigger,
  html[data-mobile-theme="dark"] .template-product .pd3-rel .product-image,
  html[data-mobile-theme="dark"] .template-product .pd3-rel .product-thumbnail,
  html[data-mobile-theme="dark"] .template-product .pd3-gal #ProductThumbs .pd3-gal-thumb-link { background: #fff !important; border-color: #2c3a45; }
  html[data-mobile-theme="dark"] .template-product .pd3-gal #ProductThumbs .pd3-gal-thumb-link[aria-current="true"] { border-color: #007fae; }
  html[data-mobile-theme="dark"] .template-product .pd3-gal a:focus-visible,
  html[data-mobile-theme="dark"] .template-product .pd3-rel :focus-visible { outline-color: #7dd3f5; }
}

/* Khoảng trống trước dải "Mua sắm theo danh mục" (footer): Tùng báo 16/10. Nội dung cuối → tiêu đề dải ≈ 80px desktop / 56px mobile. */
.template-product .site-footer { margin-top: 0 !important; }
.template-product main.main-content { padding-bottom: 0 !important; margin-bottom: 0 !important; }
.template-product .pd3-rel { margin-bottom: 40px !important; padding-bottom: 0 !important; }
.template-product .site-footer__top .space-padding-tb-40 { padding-top: 40px !important; }
@media (max-width: 768px) {
  .template-product .pd3-rel { margin-bottom: 20px !important; }
  .template-product .site-footer__top .space-padding-tb-40 { padding-top: 28px !important; }
}

/* Sản phẩm liên quan desktop: 1 hàng đầy, không còn card lẻ ở hàng cuối (5+5+1). Mobile vẫn rail đủ tất cả. 16/10. */
@media (min-width: 1440px) { .template-product .pd3-rel-rail > :nth-child(n+6) { display: none !important; } }
@media (min-width: 1024px) and (max-width: 1439px) { .template-product .pd3-rel-rail > :nth-child(n+5) { display: none !important; } }
@media (min-width: 769px) and (max-width: 1023px) { .template-product .pd3-rel-rail > :nth-child(n+4) { display: none !important; } }
