/* PCS product photo grid + lightbox. Loaded only on product pages where
   pcs-product-gallery.php is switched on. Colours, radii and type come from
   pcs-design-tokens/tokens.css; the fallbacks are the same live values. */

/* ---- Grid (tablet and desktop) ------------------------------------------ */
div.woocommerce-product-gallery.pcs-pg{
  --pcs-pg-gap:8px;
  /* Blocksy sets overflow:hidden on the gallery wrapper, which would clip the
     keyboard focus ring drawn outside a tile. */
  overflow:visible;
  opacity:1;
  /* The site Additional CSS frames the old gallery as one rounded card with a
     drop shadow (.single-product .woocommerce-product-gallery). The grid is
     several tiles, each with its own corners, so that frame comes off here. */
  border-radius:0;
  box-shadow:none;
  background:none;
}
.pcs-pg .pcs-pg-grid{
  display:grid;
  grid-template-columns:repeat(4,minmax(0,1fr));
  gap:var(--pcs-pg-gap);
  margin:0;
  padding:0;
}
.pcs-pg .pcs-pg-tile{
  position:relative;
  min-width:0;
  margin:0;
  padding:0;
  aspect-ratio:4 / 3;
  border-radius:10px;
  overflow:hidden;
  background:#E9EEF2; /* shown while a photo loads */
}
.pcs-pg .pcs-pg-tile--hero{
  grid-column:1 / -1;
  aspect-ratio:var(--pcs-pg-hero,1.5);
  border-radius:var(--radius-image,14px);
}
.pcs-pg .pcs-pg-tile--rest{display:none}

.pcs-pg .pcs-pg-open{
  -webkit-appearance:none;
  appearance:none;
  display:block;
  position:absolute;
  inset:0;
  width:100%;
  height:100%;
  min-height:0;
  margin:0;
  padding:0;
  border:0;
  border-radius:inherit;
  background:none;
  box-shadow:none;
  color:inherit;
  font:inherit;
  line-height:0;
  cursor:zoom-in;
  overflow:hidden;
}
.pcs-pg .pcs-pg-open .pcs-pg-img{
  display:block;
  width:100%;
  height:100%;
  max-width:none;
  margin:0;
  border-radius:0;
  object-fit:cover;
  /* Faces sit in the upper half of most of these photos, so a tile that has to
     trim height trims more from the bottom than from the top. */
  object-position:50% 38%;
  transition:transform .5s cubic-bezier(.2,.6,.2,1);
}
@media (hover:hover){
  .pcs-pg .pcs-pg-open:hover .pcs-pg-img{transform:scale(1.03)}
}

/* Keyboard focus: a navy ring outside the tile, plus a white inner line so the
   ring still reads against a dark photo. */
.pcs-pg .pcs-pg-open:focus{outline:none}
.pcs-pg .pcs-pg-open:focus-visible{
  outline:2px solid #fff;
  outline-offset:-5px;
}
.pcs-pg .pcs-pg-tile:has(.pcs-pg-open:focus-visible){
  outline:2px solid var(--pcs-navy,#0A2E4D);
  outline-offset:2px;
}

/* "View all N photos" on the last thumbnail */
.pcs-pg .pcs-pg-more{
  position:absolute;
  inset:0;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:8px;
  background:rgba(10,46,77,.66);
  color:#fff;
  font-family:var(--font-body,"Manrope",sans-serif);
  font-size:13px;
  font-weight:700;
  line-height:1.3;
  letter-spacing:.01em;
  text-align:center;
  transition:background-color .2s ease-out;
}
.pcs-pg .pcs-pg-more > span{max-width:9em}
@media (hover:hover){
  .pcs-pg .pcs-pg-open:hover .pcs-pg-more{background:rgba(10,46,77,.78)}
}

.pcs-pg .pcs-pg-badge{display:none}

/* ---- Phone slider -------------------------------------------------------- */
@media (max-width:767px){
  /* Edge to edge: the wrapper is centred in its column, so half the difference
     between its own width and the viewport is the gutter on each side. */
  div.woocommerce-product-gallery.pcs-pg.pcs-pg{
    position:relative;
    width:100vw;
    max-width:100vw;
    margin-left:calc(50% - 50vw);
    margin-right:calc(50% - 50vw);
    margin-bottom:28px;
    overflow:hidden;
  }
  .pcs-pg .pcs-pg-grid{
    display:flex;
    gap:0;
    overflow-x:auto;
    overflow-y:hidden;
    scroll-snap-type:x mandatory;
    overscroll-behavior-x:contain;
    -webkit-overflow-scrolling:touch;
    scrollbar-width:none;
  }
  .pcs-pg .pcs-pg-grid::-webkit-scrollbar{display:none}
  .pcs-pg .pcs-pg-tile,
  .pcs-pg .pcs-pg-tile--hero,
  .pcs-pg .pcs-pg-tile--rest{
    display:block;
    flex:0 0 100%;
    aspect-ratio:var(--pcs-pg-slide,1.5);
    border-radius:0;
    scroll-snap-align:center;
    scroll-snap-stop:always;
  }
  .pcs-pg .pcs-pg-more{display:none}
  .pcs-pg .pcs-pg-open:hover .pcs-pg-img{transform:none}
  .pcs-pg .pcs-pg-open:focus-visible{outline-offset:-4px}
  .pcs-pg .pcs-pg-tile:has(.pcs-pg-open:focus-visible){outline:none}
  .pcs-pg .pcs-pg-badge{
    display:block;
    position:absolute;
    right:12px;
    bottom:12px;
    padding:4px 11px;
    border-radius:999px;
    background:rgba(10,46,77,.78);
    color:#fff;
    font-family:var(--font-body,"Manrope",sans-serif);
    font-size:13px;
    font-weight:600;
    line-height:1.5;
    letter-spacing:.02em;
    font-variant-numeric:tabular-nums;
    pointer-events:none;
  }
}

/* ---- Lightbox ------------------------------------------------------------ */
html.pcs-lb-open{overflow:hidden}

dialog.pcs-lb{
  position:fixed;
  inset:0;
  width:100vw;
  height:100vh;
  height:100dvh;
  max-width:none;
  max-height:none;
  margin:0;
  padding:0;
  border:0;
  background:#07141F;
  color:#fff;
  overflow:hidden;
  font-family:var(--font-body,"Manrope",sans-serif);
}
dialog.pcs-lb:not([open]){display:none}
dialog.pcs-lb::backdrop{background:#07141F}
dialog.pcs-lb[open]{animation:pcs-lb-in .2s ease-out}
@keyframes pcs-lb-in{from{opacity:0}to{opacity:1}}

.pcs-lb .pcs-lb-track{
  position:absolute;
  inset:0;
  display:flex;
  overflow-x:auto;
  overflow-y:hidden;
  scroll-snap-type:x mandatory;
  overscroll-behavior:contain;
  -webkit-overflow-scrolling:touch;
  scrollbar-width:none;
  outline:none;
}
.pcs-lb .pcs-lb-track::-webkit-scrollbar{display:none}
.pcs-lb .pcs-lb-slide{
  flex:0 0 100%;
  width:100%;
  height:100%;
  margin:0;
  padding:68px 84px 40px;
  box-sizing:border-box;
  display:flex;
  align-items:center;
  justify-content:center;
  scroll-snap-align:center;
  scroll-snap-stop:always;
}
/* The whole photo, at its own shape: never cropped. */
/* The box is sized from the photo's own width / height (set per image by
   gallery.js), so it is the right shape before the file arrives and can never
   be taller than the space between the bar and the bottom edge. */
.pcs-lb .pcs-lb-slide img{
  display:block;
  aspect-ratio:var(--pcs-lb-r,1.5);
  width:min(100%,calc((100vh - var(--pcs-lb-pad-y,108px)) * var(--pcs-lb-r,1.5)),var(--pcs-lb-w,100%));
  width:min(100%,calc((100dvh - var(--pcs-lb-pad-y,108px)) * var(--pcs-lb-r,1.5)),var(--pcs-lb-w,100%));
  height:auto;
  max-width:100%;
  max-height:100%;
  margin:0;
  object-fit:contain;
  background:rgba(255,255,255,.05);
  border-radius:4px;
  -webkit-user-select:none;
  user-select:none;
}

.pcs-lb .pcs-lb-bar{
  position:absolute;
  z-index:2;
  top:0;
  left:0;
  right:0;
  height:68px;
  padding:0 16px 0 24px;
  box-sizing:border-box;
  display:flex;
  align-items:center;
  justify-content:space-between;
  pointer-events:none;
}
.pcs-lb .pcs-lb-count{
  font-size:14px;
  font-weight:600;
  line-height:1;
  letter-spacing:.06em;
  font-variant-numeric:tabular-nums;
  color:rgba(255,255,255,.92);
}
.pcs-lb .pcs-lb-btn{
  -webkit-appearance:none;
  appearance:none;
  pointer-events:auto;
  display:grid;
  place-items:center;
  width:44px;
  height:44px;
  min-height:0;
  margin:0;
  padding:0;
  border:1px solid rgba(255,255,255,.28);
  border-radius:50%;
  background:rgba(7,20,31,.55);
  box-shadow:none;
  color:#fff;
  cursor:pointer;
  transition:background-color .16s ease-out,border-color .16s ease-out;
}
.pcs-lb .pcs-lb-btn svg{display:block;width:20px;height:20px}
.pcs-lb .pcs-lb-btn:hover{background:rgba(255,255,255,.16);border-color:rgba(255,255,255,.5)}
.pcs-lb .pcs-lb-btn:focus{outline:none}
.pcs-lb .pcs-lb-btn:focus-visible{outline:2px solid #fff;outline-offset:3px}
.pcs-lb .pcs-lb-btn[disabled]{opacity:.28;cursor:default;background:rgba(7,20,31,.55);border-color:rgba(255,255,255,.28)}
.pcs-lb .pcs-lb-prev,
.pcs-lb .pcs-lb-next{position:absolute;z-index:2;top:50%;margin-top:-22px}
.pcs-lb .pcs-lb-prev{left:20px}
.pcs-lb .pcs-lb-next{right:20px}

.pcs-lb .pcs-lb-sr{
  position:absolute;
  width:1px;
  height:1px;
  margin:-1px;
  padding:0;
  overflow:hidden;
  clip:rect(0 0 0 0);
  clip-path:inset(50%);
  white-space:nowrap;
  border:0;
}

@media (max-width:767px){
  dialog.pcs-lb{--pcs-lb-pad-y:120px}
  .pcs-lb .pcs-lb-slide{padding:60px 0 60px}
  .pcs-lb .pcs-lb-slide img{border-radius:0}
  .pcs-lb .pcs-lb-bar{height:60px;padding:0 10px 0 18px}
  .pcs-lb .pcs-lb-prev,
  .pcs-lb .pcs-lb-next{top:auto;bottom:10px;margin-top:0;width:40px;height:40px}
  .pcs-lb .pcs-lb-prev{left:calc(50% - 52px)}
  .pcs-lb .pcs-lb-next{right:calc(50% - 52px)}
}

/* ---- Reduced motion ------------------------------------------------------ */
@media (prefers-reduced-motion:reduce){
  .pcs-pg .pcs-pg-open .pcs-pg-img{transition:none}
  .pcs-pg .pcs-pg-open:hover .pcs-pg-img{transform:none}
  .pcs-pg .pcs-pg-more,
  .pcs-lb .pcs-lb-btn{transition:none}
  dialog.pcs-lb[open]{animation:none}
  .pcs-pg .pcs-pg-grid,
  .pcs-lb .pcs-lb-track{scroll-behavior:auto}
}
