/* Layout stability (CLS). CSS only: no JavaScript is needed to reserve space. Loaded as a normal render-blocking stylesheet on product and cart pages. */

/* ---- single product gallery ----
   Before WooCommerce's FlexSlider runs, every gallery image is stacked on screen; FlexSlider then collapses them to one slide and inserts the thumbnail strip,
   which pushed the rest of the page down (CLS ~0.5 on phones). Until the slider exists (.flex-viewport), show only the first image (its width/height attributes
   give the browser its aspect ratio); until its thumbnails exist, reserve the exact height of the thumbnail strip: rows of square cells in a 4-column grid with a 12px (8px <=800px) gap.
   --r (thumbnail rows) comes from the class apl-gal-rows-N added in PHP from the real image count. Percent padding is relative to the gallery width. */
.apl-pdp-gallery .woocommerce-product-gallery{--g:12px;--r:0}
.apl-pdp-gallery .woocommerce-product-gallery:not(:has(.flex-viewport)) .woocommerce-product-gallery__wrapper>.woocommerce-product-gallery__image:nth-child(n+2){display:none}
.apl-pdp-gallery .woocommerce-product-gallery.apl-gal-rows-1{--r:1}
.apl-pdp-gallery .woocommerce-product-gallery.apl-gal-rows-2{--r:2}
.apl-pdp-gallery .woocommerce-product-gallery.apl-gal-rows-3{--r:3}
/* the slider viewport keeps the main image's aspect ratio (--ar is set per product in PHP) so the transient state while FlexSlider sizes its 400%-wide track cannot grow the page (observed 1134px for ~8s on a throttled phone) */
.apl-pdp-gallery .woocommerce-product-gallery .flex-viewport{aspect-ratio:var(--ar);max-height:644px}
.apl-pdp-gallery .woocommerce-product-gallery:not(:has(.flex-control-thumbs)):is(.apl-gal-rows-1,.apl-gal-rows-2,.apl-gal-rows-3)::after{content:"";display:block;margin-top:14px;height:0;padding-top:calc(var(--r)*25% + (.25*var(--r) - 1)*var(--g))}
@media(max-width:800px){.apl-pdp-gallery .woocommerce-product-gallery{--g:8px}}

/* ---- cart ----
   WooCommerce server-renders both cart layouts; the "empty cart" one (message + "New in store" product grid) stayed visible until the cart script hydrated,
   then vanished and pulled everything below it up (CLS 0.3-0.6). Keep it hidden while the cart block is loading; a genuinely empty cart still shows it once loaded. */
.wp-block-woocommerce-cart.is-loading .wp-block-woocommerce-empty-cart-block{display:none}

/* ---- cart + checkout: keep the footer below the fold until the content exists ----
   WooCommerce's block/checkout stylesheets and scripts arrive after the footer markup, so the footer first rendered right under the header and was pushed down when the
   content appeared (CLS 0.37-0.7). A minimum height on the main area (standard sticky-footer pattern) keeps the footer out of the first screen. */
body.woocommerce-cart main#content,body.woocommerce-checkout main#content{min-height:calc(100vh - 150px)}
@supports (height:100svh){body.woocommerce-cart main#content,body.woocommerce-checkout main#content{min-height:calc(100svh - 150px)}}

/* ---- checkout: the "Returning customer? login" and coupon forms ----
   WooCommerce's checkout script hides both forms with JavaScript, so until it ran they were on screen (482px + 150px) and the whole checkout form jumped up when they
   disappeared (CLS 0.25-0.38). Hide them from the first paint when JavaScript is available (html.apl-js is set by a one-line script in <head>; WooCommerce's own body.woocommerce-js swap only runs in wp_footer, too late); the
   "Click here to ..." toggles still open them (jQuery slideToggle), and visitors without JavaScript still see them (no apl-js class). */
html.apl-js body.woocommerce-checkout form.woocommerce-form-login,html.apl-js body.woocommerce-checkout form.checkout_coupon{display:none}
/* WooCommerce's own no-JS fallback (.woocommerce-no-js form.woocommerce-form-login{display:block!important}) stays in force until its footer script swaps the body class,
   which on a slow load is long after first paint. Counter it only while that class is present and our html.apl-js flag proves JavaScript is available; once the class is
   swapped this rule stops applying and WooCommerce's normal inline show/hide (the "Click here to..." toggles) works as before. */
html.apl-js body.woocommerce-no-js.woocommerce-checkout form.woocommerce-form-login,html.apl-js body.woocommerce-no-js.woocommerce-checkout form.checkout_coupon{display:none!important}
