/**
 * British Dragon - WooCommerce Blocks Layout Stability Locks (Hardened v1.0.5)
 * Target: /cart/ and /checkout/
 * Purpose: Completely eliminates CLS across all Cart & Checkout states (Desktop & Mobile).
 * Preserves WooCommerce native proportions, responsive grid, and sticky sidebar behavior.
 */

/* ==========================================================================
   1. Critical Responsive Display Locks (Header/Nav Shift Elimination CLS 0.033)
   ========================================================================== */
@media (min-width: 1025px) {
  .elementor-hidden-desktop {
    display: none !important;
  }
}
@media (min-width: 768px) and (max-width: 1024px) {
  .elementor-hidden-tablet {
    display: none !important;
  }
}
@media (max-width: 767px) {
  .elementor-hidden-mobile {
    display: none !important;
  }
}

/* ==========================================================================
   2. Page Header Navigation Button Reservation (Eliminates Mobile Pushdown CLS 0.053)
   ========================================================================== */
@media (max-width: 600px) {
  :is(body.woocommerce-cart, body.woocommerce-checkout) .site-main > .page-header {
    min-height: 164px;
    box-sizing: border-box;
  }
}

/* ==========================================================================
   3. Root Block Containment & Box Sizing
   ========================================================================== */
.wp-block-woocommerce-cart,
.wc-block-cart,
.wp-block-woocommerce-checkout,
.wc-block-checkout {
  contain: layout;
  box-sizing: border-box;
}

/* ==========================================================================
   4. SSR Empty vs Filled Cart Mutually Exclusive Display
   Active strictly while .is-loading is present and explicit SSR state is known.
   If session state is missing, neither block is hidden by default.
   ========================================================================== */
:root[data-has-cart-items="false"] .wp-block-woocommerce-cart.is-loading .wp-block-woocommerce-filled-cart-block,
body.cart-empty.woocommerce-cart .wp-block-woocommerce-cart.is-loading .wp-block-woocommerce-filled-cart-block {
  display: none !important;
}

:root[data-has-cart-items="true"] .wp-block-woocommerce-cart.is-loading .wp-block-woocommerce-empty-cart-block,
body.cart-filled.woocommerce-cart .wp-block-woocommerce-cart.is-loading .wp-block-woocommerce-empty-cart-block {
  display: none !important;
}

/* ==========================================================================
   5. Desktop Two-Column Cart Architecture (Eliminates 0.2291 Totals Jump)
   ========================================================================== */
@media (min-width: 768px) {
  .wp-block-woocommerce-filled-cart-block,
  .wc-block-components-sidebar-layout.is-large {
    display: flex !important;
    flex-direction: row !important;
    align-items: flex-start !important;
    gap: 32px !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  .wp-block-woocommerce-cart-items-block,
  .wc-block-components-sidebar-layout.is-large .wc-block-components-main {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }

  .wp-block-woocommerce-cart-totals-block,
  .wc-block-components-sidebar-layout.is-large .wc-block-components-sidebar {
    flex: 0 0 360px !important;
    width: 360px !important;
    max-width: 360px !important;
    position: -webkit-sticky !important;
    position: sticky !important;
    top: 32px !important;
    align-self: flex-start !important;
    box-sizing: border-box !important;
  }

  /* Desktop Height Reservations during is-loading only (Keeps footer below 768px fold) */
  .wp-block-woocommerce-cart.is-loading {
    min-height: 520px !important;
  }
  .wp-block-woocommerce-checkout.is-loading,
  .wc-block-checkout.is-loading {
    min-height: 600px !important;
  }
}

/* ==========================================================================
   6. Mobile Cart & Checkout Layout Locks (Eliminates 0.6363 & 0.6329 Shifts)
   ========================================================================== */
@media (max-width: 767px) {
  /* On populated mobile cart, reserve line item height so totals block does not jump from y:165 to y:405 */
  :root[data-has-cart-items="true"] .wp-block-woocommerce-cart.is-loading .wp-block-woocommerce-cart-items-block,
  body.cart-filled.woocommerce-cart .wp-block-woocommerce-cart.is-loading .wp-block-woocommerce-cart-items-block {
    min-height: 240px !important;
    box-sizing: border-box !important;
  }

  /* Mobile Root Height Reservations during is-loading only (Keeps footer below 844px fold) */
  .wp-block-woocommerce-cart.is-loading {
    min-height: 680px !important;
  }
  .wp-block-woocommerce-checkout.is-loading,
  .wc-block-checkout.is-loading {
    min-height: 750px !important;
  }
}

/* ==========================================================================
   7. Empty Cart Cross-Sells / New in Store Grid Locks
   ========================================================================== */
.wc-block-grid__products {
  display: flex !important;
  flex-wrap: wrap !important;
  margin: 0 -8px 16px !important;
  padding: 0 !important;
  box-sizing: border-box !important;
}

@media (min-width: 768px) {
  .wc-block-grid.has-4-columns .wc-block-grid__product {
    flex: 0 0 25% !important;
    max-width: 25% !important;
    width: 25% !important;
    padding: 0 8px 16px !important;
    box-sizing: border-box !important;
  }
}

.wp-block-woocommerce-empty-cart-block .wc-block-grid {
  min-height: 420px;
  contain: layout;
  box-sizing: border-box !important;
}

/* ==========================================================================
   8. Skeleton Height Normalization & Notices Reservation
   ========================================================================== */
.wc-block-components-skeleton__element {
  min-height: 44px;
  border-radius: 4px;
  box-sizing: border-box;
}

.wc-block-components-notices {
  box-sizing: border-box !important;
}
