/**
 * Universal Product Card Styling - Afriyah
 * Single source of truth for all product cards across Shop, Best Sellers, Related, Upsells, Search
 * Backup architecture: content-product.php used everywhere for consistency
 */

/* === UNIVERSAL CARD STRUCTURE === */
.af-product-card,
ul.products li.product .af-product-card,
#af-bestsellers-grid .af-product-card,
.woocommerce ul.products li.product .af-product-card,
.woocommerce .related.products ul.products li.product .af-product-card,
.woocommerce .upsells.products ul.products li.product .af-product-card {
    background: #fff !important;
    border-radius: 16px !important;
    overflow: hidden !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
    transition: transform 0.3s, box-shadow 0.3s !important;
    display: flex !important;
    flex-direction: column !important;
    height: 100% !important;
    min-height: auto !important;
    border: 1px solid #eee !important;
}

.af-product-card:hover,
ul.products li.product:hover .af-product-card {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12) !important;
}

/* === IMAGE CONTAINER - 1:1 Aspect === */
.af-product-image,
.af-product-card .af-product-image,
ul.products li.product .af-product-image {
    position: relative !important;
    padding-top: 100% !important;
    overflow: hidden !important;
    background: #f0f0f0 !important;
}

.af-product-image img,
.af-product-card .af-product-image img {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
}

/* === INFO BLOCK === */
.af-product-info,
.af-product-card .af-product-info {
    padding: 16px !important;
    display: flex !important;
    flex-direction: column !important;
    flex: 1 !important;
    min-height: 0 !important;
}

.af-product-title,
.af-product-card .af-product-title,
.woocommerce-loop-product__title {
    margin: 0 0 8px !important;
    font-size: clamp(12px, 2.2vw, 16px) !important;
    line-height: 1.4 !important;
    font-weight: 600 !important;
    color: #333 !important;
}

.af-product-actions {
    margin-top: auto !important;
}

/* Quick actions: one icon only (theme woo-styles adds ::after on .compare.button — causes double icon). */
.af-quick-actions .af-compare-btn::before,
.af-quick-actions .af-compare-btn::after,
.af-quick-actions a.compare::before,
.af-quick-actions a.compare::after,
.af-quick-actions .compare.button::before,
.af-quick-actions .compare.button::after,
.af-quick-actions .yith-woocompare-add-to-compare::before,
.af-quick-actions .yith-woocompare-add-to-compare::after {
    content: none !important;
    display: none !important;
}

.af-quick-actions .af-compare-btn,
.af-quick-actions a.compare,
.af-quick-actions .compare.button {
    position: relative !important;
    border-radius: 50% !important;
    background: #fff !important;
    border: 1px solid #eee !important;
}

.af-quick-actions .af-compare-btn i,
.af-quick-actions a.compare i {
    margin: 0 !important;
    font-size: 14px !important;
    line-height: 1 !important;
    color: #333 !important;
    opacity: 1 !important;
    visibility: visible !important;
}

/* Compare: woo-styles sets red icon on hover while quick-action bg is also red */
.af-quick-actions .af-compare-btn:hover,
.af-quick-actions .af-compare-btn:focus,
.af-quick-actions a.compare.button:hover,
.af-quick-actions a.compare.button:focus,
.woocommerce ul.products li.product .af-quick-actions a.compare.button:hover,
.woocommerce ul.products li.product .af-quick-actions a.compare.button:focus {
    background: #fe4322 !important;
    color: #fff !important;
}

.af-quick-actions .af-compare-btn:hover i,
.af-quick-actions .af-compare-btn:focus i,
.af-quick-actions a.compare.button:hover i,
.af-quick-actions a.compare.button:focus i {
    color: #fff !important;
    opacity: 1 !important;
    visibility: visible !important;
}

/* === QUICK ACTIONS - Fixed dimensions to prevent overlapping === */
.af-quick-actions,
#af-bestsellers-grid .af-quick-actions,
.af-product-card .af-quick-actions,
li.product .af-quick-actions {
    position: absolute !important;
    right: 8px !important;
    top: 8px !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 6px !important;
    z-index: 10 !important;
    opacity: 1 !important;
    visibility: visible !important;
}

/* Fixed-size buttons - no overlap */
.af-quick-actions>*,
.af-quick-actions button,
.af-quick-actions a,
.af-quick-actions .af-quick-btn,
.af-quick-actions .af-quick-action-btn,
.af-quick-actions .yith-wcqv-button,
.af-quick-actions .yith-wcwl-add-to-wishlist,
.af-quick-actions .compare,
.af-quick-actions .af-compare-btn,
.af-quick-actions .af-wishlist-btn,
.af-quick-actions .af-whatsapp-btn {
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    min-height: 36px !important;
    max-width: 36px !important;
    max-height: 36px !important;
    padding: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex-shrink: 0 !important;
    border-radius: 50% !important;
}

/* === GRID LAYOUTS === */
#af-bestsellers-grid,
.af-products-grid.products,
.woocommerce ul.products,
.woocommerce-page ul.products {
    display: grid !important;
    /* Explicitly define variables with numerical fallbacks to prevent CSS parser invalidation */
    grid-template-columns: repeat(var(--af-cols-desktop, 4), minmax(0, 1fr)) !important;
    gap: 24px !important;
    list-style: none !important;
    padding: 0 !important;
    margin: 0 0 40px !important;
}

#af-bestsellers-grid::before,
#af-bestsellers-grid::after,
.af-products-grid.products::before,
.af-products-grid.products::after,
.woocommerce ul.products::before,
.woocommerce ul.products::after {
    display: none !important;
}

.woocommerce ul.products li.product,
.woocommerce-page ul.products li.product,
#af-bestsellers-grid li.product,
.af-products-grid li.product {
    width: 100% !important;
    margin: 0 !important;
    float: none !important;
    clear: none !important;
}

@media (max-width: 768px) {
    #af-bestsellers-grid,
    .af-products-grid.products,
    .woocommerce ul.products,
    .woocommerce-page ul.products {
        grid-template-columns: repeat(var(--af-cols-mobile, 2), minmax(0, 1fr)) !important;
        gap: 16px !important;
    }
}

/* Mobile: match featured-product placement — vertical stack, top-right on image (not bottom bar). */
@media (max-width: 767px) {
    .af-product-image .af-quick-actions,
    .woocommerce ul.products li.product .af-product-image .af-quick-actions,
    .af-featured-product-section .af-quick-actions {
        top: 8px !important;
        right: 8px !important;
        left: auto !important;
        bottom: auto !important;
        flex-direction: column !important;
        flex-wrap: nowrap !important;
        justify-content: flex-start !important;
        align-items: center !important;
        gap: 6px !important;
        z-index: 25 !important;
        max-width: none !important;
        opacity: 1 !important;
        visibility: visible !important;
        transform: none !important;
        pointer-events: auto !important;
    }

    .af-product-image .af-quick-actions > *,
    .woocommerce ul.products li.product .af-product-image .af-quick-actions > *,
    .af-featured-product-section .af-quick-actions > * {
        width: 32px !important;
        height: 32px !important;
        min-width: 32px !important;
        min-height: 32px !important;
        max-width: 32px !important;
        max-height: 32px !important;
        font-size: 13px !important;
    }

    .af-mobile-bottom-nav {
        z-index: 900 !important;
    }
}

/* Featured hero: mobile CTA + image column */
@media (max-width: 768px) {
    .af-featured-product-card {
        overflow: visible !important;
    }

    .af-featured-product-card .af-featured-image {
        min-width: 0 !important;
        flex: 0 0 auto !important;
        width: 100% !important;
    }

    .af-featured-product-card .af-featured-main {
        min-height: 220px !important;
        max-height: 42vh !important;
        padding: 12px !important;
    }

    .af-featured-product-card .af-featured-info {
        min-width: 0 !important;
        width: 100% !important;
        flex: 0 0 auto !important;
        padding: 20px 16px calc(24px + env(safe-area-inset-bottom, 0px)) !important;
        box-sizing: border-box !important;
    }

    .af-featured-product-card .af-featured-cta-row {
        flex-direction: column !important;
        gap: 10px !important;
        width: 100% !important;
        position: relative !important;
        z-index: 6 !important;
    }

    .af-featured-product-card .af-featured-cta-row > .af-btn-primary,
    .af-featured-product-card .af-featured-cta-row > .af-btn-buy-now,
    .af-featured-product-card .af-featured-cta-row > a.af-btn-primary,
    .af-featured-product-card .af-featured-cta-row > a.af-btn-buy-now,
    .af-featured-product-card .af-featured-cta-row > .af-btn-out-of-stock {
        width: 100% !important;
        flex: 1 1 auto !important;
        min-width: 0 !important;
        max-width: 100% !important;
        display: flex !important;
        justify-content: center !important;
    }

    .af-featured-product-card .af-featured-variable-wrap .woocommerce-variation-add-to-cart {
        flex-direction: column !important;
    }

    .af-featured-product-card .af-featured-variable-wrap .single_add_to_cart_button,
    .af-featured-product-card .af-featured-variable-wrap .af-featured-buy-now {
        width: 100% !important;
        flex: 1 1 auto !important;
    }
}

/* Shop main column must shrink inside Bootstrap-style row (prevents grid clipping) */
.af-shop-main {
    min-width: 0 !important;
}

/* Best Sellers — desktop: match homepage Top Rated width (full content band, not narrow wf-container). */
@media (min-width: 992px) {
    body.page-template-page-best-sellers #page,
    body.page-template-page-best-sellers .site-content,
    body.page-template-page-best-sellers #primary,
    body.page-template-page-best-sellers main.site-main {
        max-width: none !important;
        width: 100% !important;
    }

    body.page-template-page-best-sellers .af-shop-catalog-main-only {
        max-width: 100% !important;
        width: 100% !important;
    }

    body.page-template-page-sponsored-products #page,
    body.page-template-page-sponsored-products .site-content,
    body.page-template-page-sponsored-products #primary,
    body.page-template-page-sponsored-products main.site-main,
    body.page-template-page-sponsored-products .af-shop-catalog-main-only {
        max-width: none !important;
        width: 100% !important;
    }

    body.page-template-page-sponsored-products .af-shop-catalog-main-only > .wf-container,
    body.page-template-page-best-sellers .af-shop-catalog-main-only > .wf-container {
        max-width: min(98vw, 100%) !important;
        width: 100% !important;
        margin-left: auto !important;
        margin-right: auto !important;
        padding-left: clamp(16px, 2.5vw, 40px) !important;
        padding-right: clamp(16px, 2.5vw, 40px) !important;
    }

    body.page-template-page-best-sellers .af-shop-catalog-main-only {
        width: 100vw;
        max-width: 100vw;
        margin-left: calc(50% - 50vw);
        margin-right: calc(50% - 50vw);
        box-sizing: border-box;
    }

    body.page-template-page-best-sellers .woocommerce ul.products {
        grid-template-columns: repeat(var(--af-cols-desktop, 4), minmax(0, 1fr)) !important;
    }
}

/* Best Sellers uses main-only layout — let the product grid span the full viewport width (no 1140px cap). */
.page-template-page-best-sellers .af-shop-catalog-main-only > .wf-container {
    max-width: 100% !important;
    width: 100% !important;
}

.page-template-page-best-sellers .af-shop-catalog-main-only.woo-products {
    max-width: 100% !important;
}

.page-template-page-best-sellers main#main.site-main,
.page-template-page-best-sellers #main.site-main {
    max-width: 100% !important;
    overflow-x: hidden;
}

.page-template-page-best-sellers .af-shop-quick-links-inner {
    max-height: 5.75rem;
    overflow-y: auto;
    align-content: flex-start;
    -webkit-overflow-scrolling: touch;
}

/* Best Sellers: prevent 2-col grid overflow on narrow viewports (min 200px tracks broke 375px layouts). */
.page-template-page-best-sellers .best-sellers-products,
.page-template-page-best-sellers .af-shop-main {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
}

.page-template-page-best-sellers .af-shop-catalog-main-only > .wf-container,
.page-template-page-best-sellers .woo-products > .wf-container {
    width: 100% !important;
    max-width: 100% !important;
    padding-left: clamp(12px, 3vw, 40px) !important;
    padding-right: clamp(12px, 3vw, 40px) !important;
    box-sizing: border-box !important;
}

/* Constrain Best Sellers layout to match homepage Top Rated section */
.page-template-page-best-sellers .af-shop-catalog-main-only > .wf-container,
.page-template-page-sponsored-products .af-shop-catalog-main-only > .wf-container {
    max-width: 100% !important;
    width: 100% !important;
}

/* The Best Sellers page should use full width, overriding the 1200px limit below if needed */
.page-template-page-best-sellers-php .af-shop-catalog-main-only,
.page-template-page-best-sellers-php .site-main,
body[class*="best-sellers"] .af-shop-catalog-main-only,
body[class*="best-sellers"] .site-main {
    max-width: 100% !important;
    width: 100% !important;
}

/* Shop catalog main-only layout cap (Best Sellers overrides below). */
body:not(.page-template-page-best-sellers):not(.page-template-page-best-sellers-php) .af-shop-catalog-main-only {
    max-width: 1200px !important;
    margin: 0 auto !important;
    padding-left: 15px !important;
    padding-right: 15px !important;
}

/* Best Sellers: full-width band — overrides the 1200px cap and parent 1140px wf-container */
body.page-template-page-best-sellers .af-shop-catalog-main-only,
body.page-template-page-best-sellers-php .af-shop-catalog-main-only,
body[class*="page-template-page-best-sellers"] .af-shop-catalog-main-only {
    max-width: none !important;
    width: 100% !important;
    margin-left: auto !important;
    margin-right: auto !important;
    padding-left: clamp(12px, 2.5vw, 48px) !important;
    padding-right: clamp(12px, 2.5vw, 48px) !important;
    box-sizing: border-box !important;
}

body.page-template-page-best-sellers .af-shop-catalog-main-only > .wf-container,
body.page-template-page-best-sellers-php .af-shop-catalog-main-only > .wf-container {
    max-width: min(98vw, 1680px) !important;
    width: 100% !important;
    margin-left: auto !important;
    margin-right: auto !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
}

/*
 * Theme customizer prints `#wf-main.af-shop-main { max-width: 72%; flex: 0 0 72% }`
 * unconditionally. Best Sellers uses the main-only template (no sidebar) — that 72%
 * leaves a huge empty band on the right. Force full-width on Best Sellers / Sponsored.
 */
@media (min-width: 992px) {
    body.page-template-page-best-sellers #wf-main.af-shop-main,
    body.page-template-page-best-sellers-php #wf-main.af-shop-main,
    body[class*="page-template-page-best-sellers"] #wf-main.af-shop-main,
    body.page-template-page-sponsored-products #wf-main.af-shop-main,
    body.page-template-page-sponsored-products-php #wf-main.af-shop-main,
    body[class*="page-template-page-sponsored-products"] #wf-main.af-shop-main {
        max-width: 100% !important;
        flex: 0 0 100% !important;
        width: 100% !important;
    }
}

/* Bootstrap wf-g-5 uses 4.8rem gutters — overflows 375px and clips the 2nd product column */
.page-template-page-best-sellers .af-shop-catalog-main-only .wf-row.wf-g-5,
.page-template-page-sponsored-products .af-shop-catalog-main-only .wf-row.wf-g-5 {
    --wf-gutter-x: 12px !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    max-width: 100% !important;
}

.page-template-page-best-sellers .af-shop-catalog-main-only .wf-row.wf-g-5 > *,
.page-template-page-sponsored-products .af-shop-catalog-main-only .wf-row.wf-g-5 > * {
    padding-left: 0 !important;
    padding-right: 0 !important;
}

/* Homepage Top Rated grid — same catalogue as /best-sellers/ */
.af-featured-products-section .af-container,
.af-featured-products-section #af-bestsellers-grid {
    max-width: 100% !important;
    box-sizing: border-box !important;
}

body.home #af-bestsellers-grid {
    overflow-x: hidden;
}

.page-template-page-best-sellers .woocommerce ul.products {
    width: 100% !important;
    max-width: 100% !important;
    grid-template-columns: repeat(var(--af-cols-desktop, 4), minmax(0, 1fr)) !important;
    box-sizing: border-box !important;
}

.page-template-page-best-sellers .woocommerce ul.products li.product {
    min-width: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
    box-sizing: border-box !important;
}

.page-template-page-best-sellers .woocommerce ul.products li.product .af-product-card {
    min-width: 0 !important;
    max-width: 100% !important;
}

@media (max-width: 768px) {
    .page-template-page-best-sellers .woocommerce ul.products {
        grid-template-columns: repeat(var(--af-cols-mobile, 2), minmax(0, 1fr)) !important;
        gap: 12px !important;
    }
}

/* === Afriyah loop CTAs — green pill (single look everywhere ul.products uses content-product) === */
.woocommerce ul.products li.product .af-product-actions a.button,
.woocommerce ul.products li.product .af-product-actions button.button,
.woocommerce-page ul.products li.product .af-product-actions a.button,
.woocommerce-page ul.products li.product .af-product-actions button.button,
ul.products li.product .af-product-actions a.add_to_cart_button,
ul.products li.product .af-product-actions a.product_type_simple,
ul.products li.product .af-product-actions a.product_type_variable,
ul.products li.product .af-product-actions a.product_type_grouped,
ul.products li.product .af-product-actions a.product_type_external,
ul.products li.product .af-product-actions a.added_to_cart,
.single-product .related.products ul.products li.product .af-product-actions a.button,
.single-product .upsells.products ul.products li.product .af-product-actions a.button,
.woocommerce-cart .cross-sells ul.products li.product .af-product-actions a.button,
.woocommerce-cart .afriyah-cross-sells ul.products li.product .af-product-actions a.button,
.search .woocommerce ul.products li.product .af-product-actions a.button,
.tax-product_cat .woocommerce ul.products li.product .af-product-actions a.button,
.post-type-archive-product .woocommerce ul.products li.product .af-product-actions a.button,
.page-template-page-best-sellers .woocommerce ul.products li.product .af-product-actions a.button,
.woocommerce-checkout .afriyah-upsell-products-row ul.products li.product .af-product-actions a.button,
.page-template-page-sponsored-products .woocommerce ul.products li.product .af-product-actions a.button {
    background: #fe4322 !important;
    color: #fff !important;
    border: none !important;
    border-radius: 50px !important;
    font-weight: 700 !important;
    text-transform: none !important;
    padding: 12px 20px !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    justify-content: center !important;
    display: inline-flex !important;
    align-items: center !important;
    text-align: center !important;
    line-height: 1.2 !important;
}

.woocommerce ul.products li.product .af-product-actions a.button:hover,
.woocommerce ul.products li.product .af-product-actions button.button:hover,
.woocommerce-page ul.products li.product .af-product-actions a.button:hover,
ul.products li.product .af-product-actions a.add_to_cart_button:hover,
.single-product .related.products ul.products li.product .af-product-actions a.button:hover,
.woocommerce-cart .cross-sells ul.products li.product .af-product-actions a.button:hover {
    background: #004d00 !important;
    color: #fff !important;
}

/* WooCommerce Blocks — product grid buttons */
.wc-block-grid__product-add-to-cart.wp-block-button .wp-block-button__link,
.wc-block-grid .wc-block-grid__product .wp-block-button__link {
    background: #fe4322 !important;
    color: #fff !important;
    border-radius: 50px !important;
    font-weight: 700 !important;
    border: none !important;
}

.wc-block-grid__product-add-to-cart.wp-block-button .wp-block-button__link:hover {
    background: #004d00 !important;
    color: #fff !important;
}

/* Afriyah Enhancements — PDP “You May Also Like” cards (not using content-product) */
.afriyah-upsells .upsell-add-to-cart,
.afriyah-upsells button.upsell-add-to-cart {
    background: #fe4322 !important;
    color: #fff !important;
    border: none !important;
    border-radius: 50px !important;
    font-weight: 700 !important;
    width: 100% !important;
    box-shadow: none !important;
}

.afriyah-upsells .upsell-add-to-cart:hover {
    background: #004d00 !important;
    color: #fff !important;
    transform: none !important;
}

/* After AJAX add: stack Add to cart + View basket with clear gap */
ul.products li.product .af-product-actions,
.woocommerce ul.products li.product .af-product-actions,
.woocommerce-page ul.products li.product .af-product-actions {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
    gap: 12px !important;
    row-gap: 12px !important;
}

ul.products li.product .af-product-actions > .button,
ul.products li.product .af-product-actions > a,
.woocommerce ul.products li.product .af-product-actions > .button,
.woocommerce ul.products li.product .af-product-actions > a {
    margin: 0 !important;
    flex: 0 0 auto !important;
}

ul.products li.product .af-product-actions a.added_to_cart,
ul.products li.product .af-product-actions a.added_to_cart.wc-forward,
.woocommerce ul.products li.product .af-product-actions a.added_to_cart,
.woocommerce ul.products li.product .af-product-actions a.wc-forward.added_to_cart {
    margin-top: 0 !important;
    margin-left: 0 !important;
    position: static !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    flex: 0 0 auto !important;
    line-height: 1.2 !important;
    padding: 12px 20px !important;
}
