/* R3: preserve the original full-width gallery and equally sized thumbnails. */
@media (min-width: 992px) and (orientation: landscape) {
  html body.single-product div.product div.images.woocommerce-product-gallery {
    overflow-anchor: none;
  }
  html:not(.mfc-gallery-first-frame-active) body.single-product div.product div.images.woocommerce-product-gallery[data-mbvg-viewport-fit="natural"] {
    transform: translate3d(0, var(--mbvg-aesthetic-follow-y, 0px), 0) !important;
  }
  html:not(.mfc-gallery-first-frame-active) body.single-product .woocommerce-product-gallery[data-mbvg-viewport-fit="natural"] > .flex-viewport,
  html:not(.mfc-gallery-first-frame-active) body.single-product .woocommerce-product-gallery[data-mbvg-viewport-fit="natural"] > .flex-viewport > .woocommerce-product-gallery__wrapper > .woocommerce-product-gallery__image,
  html:not(.mfc-gallery-first-frame-active) body.single-product .woocommerce-product-gallery[data-mbvg-viewport-fit="natural"] > .flex-viewport > .woocommerce-product-gallery__wrapper > .woocommerce-product-gallery__image > a {
    height: var(--mbvg-fit-main-height) !important;
    min-height: 0 !important;
    max-height: var(--mbvg-fit-main-height) !important;
  }
  html:not(.mfc-gallery-first-frame-active) body.single-product .woocommerce-product-gallery[data-mbvg-viewport-fit="natural"] > .flex-viewport > .woocommerce-product-gallery__wrapper > .woocommerce-product-gallery__image > a > img:not(.zoomImg) {
    width: 100% !important;
    height: 100% !important;
    max-height: 100% !important;
    object-fit: contain !important;
    object-position: center !important;
  }
  html body.single-product .woocommerce-product-gallery[data-mbvg-viewport-fit="natural"][data-mbvg-trigger-fit="1"] > .woocommerce-product-gallery__trigger {
    left: var(--mbvg-fit-trigger-left) !important;
    top: var(--mbvg-fit-trigger-top) !important;
    right: auto !important;
    bottom: auto !important;
  }
  /* Match/beat the bridge's div.product div.images selector. The previous
     fixed-height tiles lost the column-width cascade and left empty cells. */
  html body.single-product div.product div.images.woocommerce-product-gallery[data-mbvg-viewport-fit="natural"] > .flex-control-thumbs {
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 14px !important;
    justify-items: stretch !important;
    align-items: stretch !important;
    margin-top: 16px !important;
  }
  html body.single-product div.product div.images.woocommerce-product-gallery[data-mbvg-viewport-fit="natural"] > .flex-control-thumbs > li {
    float: none !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    margin: 0 !important;
    min-height: 0 !important;
    height: auto !important;
    max-height: none !important;
    aspect-ratio: 1 / 1 !important;
    border-radius: 16px !important;
    overflow: hidden !important;
  }
  html body.single-product div.product div.images.woocommerce-product-gallery[data-mbvg-viewport-fit="natural"] > .flex-control-thumbs > li > img {
    width: 100% !important;
    height: 100% !important;
    max-height: none !important;
    object-fit: cover !important;
  }
}

@media (min-width: 992px) and (orientation: landscape) {
  html:not(.mfc-gallery-first-frame-active) body.single-product div.product div.images.woocommerce-product-gallery[data-mbvg-viewport-fit="natural"][data-mbvg-native-sticky]:not([data-mbvg-native-ended]) {
    position: sticky !important;
    top: var(--mbvg-native-top) !important;
    bottom: auto !important;
    margin-bottom: var(--mbvg-native-end-space) !important;
    transform: none !important;
    will-change: auto !important;
  }
  html:not(.mfc-gallery-first-frame-active) body.single-product:has(header.meblovo-smart-header:is(.is-hidden, .is-at-top)) div.product div.images.woocommerce-product-gallery[data-mbvg-viewport-fit="natural"][data-mbvg-native-sticky]:not([data-mbvg-native-ended]) {
    top: var(--mbvg-native-hidden-top) !important;
  }
  html:not(.mfc-gallery-first-frame-active) body.single-product div.product div.images.woocommerce-product-gallery[data-mbvg-native-sticky][data-mbvg-native-ended] {
    position: relative !important;
    top: 0 !important;
    bottom: auto !important;
    margin-bottom: 0 !important;
    transform: translateY(var(--mbvg-native-end-y)) !important;
  }
}

/* While MFC shows its first photo, preserve the space of the actual compact rail.
   At four columns the tile is (100% - 3 * 8px) / 4. Keep the existing 15px above it. */
@media (max-width: 767px) {
  html.mfc-gallery-first-frame-active body.single-product div.product > .mbvg-phone-rail {
    margin-bottom: 2em !important;
  }
  html.mfc-gallery-first-frame-active body.single-product div.product > .mbvg-phone-rail::after {
    content: "";
    display: block;
    clear: both;
    padding-top: calc(25% + 9px);
    pointer-events: none;
  }
  html.mfc-gallery-first-frame-active body.single-product div.product > .mbvg-phone-rail-eight::after {
    padding-top: calc(50% + 11px);
  }
  html.mfc-gallery-first-frame-active body.single-product div.product > .mbvg-phone-rail > .flex-viewport {
    margin-bottom: 0 !important;
  }
  html.mfc-gallery-first-frame-active body.single-product div.product > .mbvg-phone-rail > .flex-control-thumbs {
    position: absolute !important;
    bottom: 0;
    inset-inline: 0;
    width: 100% !important;
    margin: 0 !important;
  }
  html body.single-product div.product > .mbvg-phone-rail[data-mbvg-compact-ready="1"] > .flex-control-thumbs {
    justify-items: stretch !important;
  }
  html.mfc-gallery-first-frame-active body.single-product.meblovo-gallery-bridge-ready div.product > .mbvg-phone-rail:not(.mbvg-phone-rail-eight)[data-mbvg-compact-ready="1"] > .flex-control-thumbs,
  html.mfc-gallery-first-frame-active body.single-product.meblovo-gallery-bridge-ready div.product > .mbvg-phone-rail-eight[data-mbvg-visible-photos="8"] > .flex-control-thumbs {
    visibility: visible !important;
    pointer-events: auto !important;
  }
}

/* The JS-built purchase panel appears before it receives the phone layout class. */
@media (max-width: 767px) {
  html body.single-product div.product > .mbvg-phone-rail ~ .summary.entry-summary > .mfc-purchase-panel {
    margin-block-start: 0 !important;
  }
  html body.single-product div.product > .mbvg-phone-rail ~ .summary.entry-summary > .mfc-purchase-panel:not(.mfc-panel-phone) {
    padding: 0 !important;
    border-width: 0 !important;
  }
}
