/**
 * WC Uniform Grid Order - Styles
 * Ensures consistent product grid element ordering across all WooCommerce displays
 */

/* ===================================
   Product Grid Container Setup
   =================================== */

/* Target all WooCommerce product grid items */
.woocommerce ul.products li.product,
.woocommerce-page ul.products li.product,
ul.products li.product,
.wc-block-grid__products .wc-block-grid__product,
.wc-block-product,
li.wc-block-product,
.wp-block-woocommerce-product-template li,
ul.wc-block-product-template li,
.search ul.products li.product,
.search .wc-block-product {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
}

/* ===================================
   Element Ordering
   =================================== */

/* 1. Product Image - Always first */
.woocommerce ul.products li.product .wc-block-components-product-image,
.woocommerce ul.products li.product a.woocommerce-LoopProduct-link,
.wc-block-product .wc-block-components-product-image,
.wc-block-product>a:first-child,
.wp-block-woocommerce-product-template li .wc-block-components-product-image,
ul.products li.product>a:first-child {
    order: 1 !important;
}

/* 2. Product Title - Second */
.woocommerce ul.products li.product .woocommerce-loop-product__title,
.woocommerce ul.products li.product h2,
.woocommerce ul.products li.product h3,
.wc-block-product .wp-block-post-title,
.wc-block-product h2,
.wc-block-product h3,
.wp-block-woocommerce-product-template li .wp-block-post-title,
ul.products li.product h2,
ul.products li.product h3 {
    order: 2 !important;
    margin-top: 0.75rem !important;
    margin-bottom: 0.75rem !important;
}

/* 3. Producer Info - Third */
.woocommerce ul.products li.product .wcfmmp_sold_by_container,
.wc-block-product .wcfmmp_sold_by_container,
.wp-block-woocommerce-product-template li .wcfmmp_sold_by_container,
ul.products li.product .wcfmmp_sold_by_container {
    order: 3 !important;
}

/* 4. Star Rating - Fourth */
.woocommerce ul.products li.product .wcfmmp-store-rating,
.wc-block-product .wcfmmp-store-rating,
.wp-block-woocommerce-product-template li .wcfmmp-store-rating,
ul.products li.product .wcfmmp-store-rating,
.woocommerce ul.products li.product .star-rating,
.wc-block-product .star-rating {
    order: 4 !important;
}

/* 5. Price - Fifth */
.woocommerce ul.products li.product .price,
.wc-block-product .wp-block-woocommerce-product-price,
.wc-block-product .wc-block-components-product-price,
.wp-block-woocommerce-product-template li .wp-block-woocommerce-product-price,
ul.products li.product .price {
    order: 5 !important;
}

/* 6. Add to Cart / Go to Product Button - Last */
.woocommerce ul.products li.product .button,
.woocommerce ul.products li.product .add_to_cart_button,
.wc-block-product .wp-block-button,
.wc-block-product .wc-block-components-product-button,
.wc-block-product .wwbp-go-to-product,
.wp-block-woocommerce-product-template li .wp-block-button,
.wp-block-woocommerce-product-template li .wc-block-components-product-button,
ul.products li.product .button,
ul.products li.product .add_to_cart_button,
ul.products li.product .wwbp-go-to-product {
    order: 6 !important;
}

/* ===================================
   Additional Styling for Consistency
   =================================== */

/* Ensure producer info is properly styled */
.wcfmmp_sold_by_container {
    width: 100%;
    margin-bottom: 0.5rem;
}

/* Ensure star rating is visible and properly spaced */
.wcfmmp-store-rating {
    margin-bottom: 0.5rem;
}

/* Ensure price has proper spacing */
.wc-block-components-product-price,
.price {
    margin-bottom: 0.75rem;
}

/* Ensure buttons have proper spacing */
.wp-block-button,
.wc-block-components-product-button,
.button,
.wwbp-go-to-product {
    margin-top: auto;
}

/* ===================================
   WCFM Buttons (Edit/Delete) Override
   =================================== */

/* Keep WCFM admin buttons at the top */
.wcfm_buttons {
    order: 0 !important;
    position: absolute !important;
    top: 0 !important;
    right: 0 !important;
    z-index: 10 !important;
}

/* ===================================
   Price Suffix for Weight-Based Products
   =================================== */

/* Add "/lb" suffix to prices for products with "Go To Product" button text */
.wc-block-grid__product .wc-block-formatted-money-amount::after {
    content: "";
}

/* Only show suffix for weight-based products (those with "Go To Product" button) */
.wc-block-grid__product:has(.wc-block-components-product-button__button:not(.added)) .wc-block-formatted-money-amount::after {
    content: "/lb";
    font-size: inherit;
    font-weight: inherit;
}

/* Hide suffix for regular "Add to cart" products */
.wc-block-grid__product:has(.add_to_cart_button:not([aria-label*="Go To Product"])) .wc-block-formatted-money-amount::after {
    content: "";
}

/* ===================================
   FIX 1: Category Separator - ensure separator is visible
   =================================== */

/* Make sure the existing separator span is visible */
.wp-block-woocommerce-product-meta .taxonomy-product_cat .wp-block-post-terms__separator {
    display: inline !important;
}

/* ===================================
   FIX 2: Related Products - Equal height cards with buttons at bottom
   =================================== */

/* Parent container: FORCE equal height items with align-items: stretch */
ul.wc-block-product-template.is-flex-container,
.wc-block-product-template.is-flex-container,
.wc-block-grid__products {
    align-items: stretch !important;
}

/* Each card: flex column to stack content vertically */
ul.wc-block-product-template.is-flex-container>li.wc-block-product,
.wc-block-product-template.is-flex-container>li.wc-block-product,
li.wc-block-product {
    display: flex !important;
    flex-direction: column !important;
}

/* TITLE gets flex-grow:1 to fill available space - pushes everything below it to bottom */
li.wc-block-product h2.wp-block-post-title,
li.wc-block-product .wp-block-post-title,
.wc-block-grid__product .wc-block-components-product-title,
.wc-block-grid__product .wc-block-grid__product-title {
    flex-grow: 1 !important;
    margin-bottom: auto !important;
    padding-bottom: 0.75rem !important;
}

/* ===================================
   FIX 3: Go to Product button - prevent full width stretch
   =================================== */

/* Make Go to Product button centered and not 100% width */
li.wc-block-product a.wwbp-go-to-product,
.wc-block-product a.wwbp-go-to-product,
a.button.wwbp-go-to-product {
    width: auto !important;
    display: inline-block !important;
    align-self: center !important;
    text-align: center !important;
}

/* ===================================
   FIX 4: Store Grid - Force content stack to bottom
   disable margin:auto on button so Title flex-grow works
   =================================== */
.wc-block-grid__product .wp-block-button,
.wc-block-grid__product .wc-block-components-product-button,
.wc-block-grid__product .add_to_cart_button {
    margin-top: 0.5rem !important;
    margin-bottom: 0 !important;
}