/**
 * FD add to cart — Frontend Styles
 *
 * 1. Forces the Add to Cart button to always be visible.
 * 2. Toast notification UI.
 *
 * @version 1.2.0
 */

/* =======================================================================
   PRODUCT INNER — strip flex gap that creates space above the button
   ======================================================================= */

ul.products li.product .product-inner {
    display: flex !important;
    flex-direction: column !important;
    gap: 0 !important;          /* remove any flex gap between info and actions */
    padding-bottom: 0 !important;
}

/* Product info layout resets — keeps the button flush */
ul.products li.product .product-info,
ul.products li.product .woocommerce-loop-product__link,
ul.products li.product .product-details {
    padding-bottom: 0 !important;
    margin-bottom: 0 !important;
}

ul.products li.product .price,
ul.products li.product .product-price {
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
}

/* Product info alignment is now handled dynamically via settings */


/* =======================================================================
   PRODUCT ACTION WRAPPER — flush, always visible, zero gap
   ======================================================================= */

ul.products li.product .product-actions {
    opacity: 1 !important;
    visibility: visible !important;
    display: block !important;

    /* Kill ALL spacing between price and button */
    margin: 0 !important;
    padding: 0 !important;

    /* Full width, flush left — no centering */
    width: 100% !important;
    max-width: 100% !important;
    align-self: stretch !important;

    /* Override any theme absolute/fixed positioning */
    position: relative !important;
    top: auto !important;
    bottom: auto !important;
    left: 0 !important;
    right: 0 !important;
    transform: none !important;

    float: none !important;
    text-align: left !important;
}

/* =======================================================================
   ADD TO CART BUTTON — full-width, centred text, no margin
   ======================================================================= */

ul.products li.product .product-actions a.button,
ul.products li.product .product-actions a.add_to_cart_button,
ul.products li.product .product-actions .button {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;

    /* True 100% of the card — box-sizing prevents padding overflow */
    width: 100% !important;
    box-sizing: border-box !important;

    height: 48px !important;
    min-height: 44px !important;

    /* Zero gap — no margin-top at all */
    margin: 0 !important;
    padding: 0 20px !important;

    text-align: center !important;
    line-height: normal !important;

    /* Stay in the normal flow */
    position: static !important;
    float: none !important;

    opacity: 1 !important;
    visibility: visible !important;
    transform: none !important;

    border: none !important;
    box-shadow: none !important;
}

/* =======================================================================
   REMOVE HOVER ANIMATION — keep button visible at all times
   ======================================================================= */

ul.products li.product:hover .product-actions,
ul.products li.product:hover .product-actions a.button {
    opacity: 1 !important;
    visibility: visible !important;
    transform: none !important;
}

/* =======================================================================
   HIDE "SELECT OPTIONS" link for variable products
   ======================================================================= */

ul.products li.product a.product_type_variable:not(.vivid-atc-button) {
    display: none !important;
}

/* Ensure only ONE custom Add to Cart button renders visible at the product card footer */
.vivid-atc-loop-footer ~ .product-actions,
.vivid-atc-loop-footer ~ .add_to_cart_button,
.vivid-atc-loop-footer .vivid-atc-button ~ .vivid-atc-button {
    display: none !important;
}

/* =======================================================================
   REMOVE ALL BORDERS / SHADOWS / DIVIDER LINES
   ======================================================================= */

ul.products li.product .product-actions,
ul.products li.product .product-actions *,
ul.products li.product .product-inner,
ul.products li.product {
    border-bottom: none !important;
    box-shadow: none !important;
}

ul.products li.product::after,
ul.products li.product::before,
ul.products li.product .product-inner::after,
ul.products li.product .product-inner::before,
ul.products li.product .product-actions::after,
ul.products li.product .product-actions::before {
    display: none !important;
    border: none !important;
    box-shadow: none !important;
    content: none !important;
}

/* =======================================================================
   MOTTA THEME — specific overrides
   Motta adds padding/margin via .product-inner and positions
   .product-actions absolutely or via flex order.
   ======================================================================= */

/* Suppress duplicate overlay Add to Cart buttons appearing over the product image on hover */
body ul.products li.product .product-thumbnail .product-actions,
body ul.products li.product .product-thumbnail .add_to_cart_button,
body ul.products li.product .product-thumbnail .vivid-atc-button,
body ul.products li.product .motta-product-thumbnail__actions .add_to_cart_button,
body ul.products li.product .motta-product-thumbnail__actions .vivid-atc-button,
body ul.products li.product .product-image .product-actions,
body ul.products li.product .product-image .add_to_cart_button,
body ul.products li.product .product-image .vivid-atc-button,
body ul.products li.product .woocommerce-loop-product__header .product-actions,
body ul.products li.product .woocommerce-loop-product__header .add_to_cart_button,
body ul.products li.product .woocommerce-loop-product__header .vivid-atc-button,
body ul.products li.product .product-media .product-actions,
body ul.products li.product .product-media .add_to_cart_button,
body ul.products li.product .product-media .vivid-atc-button,
body ul.products li.product .motta-loop-product__header .product-actions,
body ul.products li.product .motta-loop-product__header .add_to_cart_button,
body ul.products li.product .motta-loop-product__header .vivid-atc-button,
body ul.products li.product .motta-product-image .product-actions,
body ul.products li.product .motta-product-image .add_to_cart_button,
body ul.products li.product .motta-product-image .vivid-atc-button {
    display: none !important;
}

/* Prevent duplicate/stacked buttons from appearing at the bottom of the product card */
.product-actions ~ .vivid-atc-loop-footer,
.add_to_cart_button ~ .vivid-atc-loop-footer,
.vivid-atc-loop-footer ~ .product-actions,
.vivid-atc-loop-footer ~ .add_to_cart_button,
.vivid-atc-button ~ .vivid-atc-button {
    display: none !important;
}

/* Remove Motta's flex-grow spacer that pushes the button to the bottom */
ul.products li.product .product-info {
    flex-grow: 0 !important;
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
}

/* Motta sometimes gives product-actions a fixed margin-top */
ul.products li.product .product-footer,
ul.products li.product .product-actions {
    margin-top: 0 !important;
    padding-top: 0 !important;
}

/* =======================================================================
   REMOVE PRODUCT GRID BORDER
   ======================================================================= */

.catalog-grid-has-border-bottom:not(.catalog-view-list) ul.products li {
    border-top: none !important;
}

ul.products li.product {
    border: none !important;
    box-shadow: none !important;
}

/* =======================================================================
   TOAST NOTIFICATION
   ======================================================================= */

#vivid-atc-toast {
    position: fixed;
    z-index: 999999;

    display: flex;
    align-items: center;
    gap: 10px;

    max-width: 340px;
    padding: 14px 20px;
    border-radius: 8px;

    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;

    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.18);
    cursor: pointer;
    pointer-events: auto;

    /* Default colours — overridden by inline style from JS */
    background-color: #2e7d32;
    color: #ffffff;

    /* Hidden by default */
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

/* ── Positions ── */
#vivid-atc-toast.toast-bottom-center  { bottom: 32px; left: 50%; transform: translateX(-50%) translateY(20px); }
#vivid-atc-toast.toast-bottom-right   { bottom: 32px; right: 24px; }
#vivid-atc-toast.toast-bottom-left    { bottom: 32px; left: 24px; }
#vivid-atc-toast.toast-top-center     { top: 80px; left: 50%; transform: translateX(-50%) translateY(-20px); }
#vivid-atc-toast.toast-top-right      { top: 80px; right: 24px; }
#vivid-atc-toast.toast-top-left       { top: 80px; left: 24px; }

/* ── Show state ── */
#vivid-atc-toast.vivid-atc-toast-show {
    opacity: 1;
}
#vivid-atc-toast.vivid-atc-toast-show.toast-bottom-center,
#vivid-atc-toast.vivid-atc-toast-show.toast-top-center {
    /* For centred positions the transform already handles X offset,
       so we only clear the Y part. */
    transform: translateX(-50%) translateY(0);
}
#vivid-atc-toast.vivid-atc-toast-show.toast-bottom-right,
#vivid-atc-toast.vivid-atc-toast-show.toast-bottom-left,
#vivid-atc-toast.vivid-atc-toast-show.toast-top-right,
#vivid-atc-toast.vivid-atc-toast-show.toast-top-left {
    transform: translateY(0);
}

/* ── Hide state ── */
#vivid-atc-toast.vivid-atc-toast-hide {
    opacity: 0;
    pointer-events: none;
}
#vivid-atc-toast.vivid-atc-toast-hide.toast-bottom-center,
#vivid-atc-toast.vivid-atc-toast-hide.toast-top-center {
    transform: translateX(-50%) translateY(20px);
}
#vivid-atc-toast.vivid-atc-toast-hide.toast-bottom-right,
#vivid-atc-toast.vivid-atc-toast-hide.toast-bottom-left {
    transform: translateY(20px);
}
#vivid-atc-toast.vivid-atc-toast-hide.toast-top-right,
#vivid-atc-toast.vivid-atc-toast-hide.toast-top-left {
    transform: translateY(-20px);
}

/* ── Icon (checkmark) ── */
#vivid-atc-toast .vivid-atc-toast-icon::before {
    content: '✓';
    font-size: 16px;
    font-weight: 700;
    flex-shrink: 0;
}

/* =======================================================================
   BUTTON LOADING STATE & ANIMATION
   ======================================================================= */

@keyframes vivid_atc_spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

body ul.products li.product .product-actions a.button.loading,
body ul.products li.product .product-actions a.add_to_cart_button.loading,
body ul.products li.product .product-actions .button.loading,
body .vivid-atc-direct.loading {
    opacity: 0.8 !important;
    pointer-events: none !important;
    color: transparent !important;
    position: relative !important;
}

/* Hide child elements inside the button during loading so text/icons disappear cleanly */
body ul.products li.product .product-actions a.button.loading > *,
body ul.products li.product .product-actions a.add_to_cart_button.loading > *,
body ul.products li.product .product-actions .button.loading > * {
    opacity: 0 !important;
}

/* Hide any theme/WooCommerce default unstyled/broken loading pseudo-elements */
body ul.products li.product .product-actions a.button.loading::before,
body ul.products li.product .product-actions a.add_to_cart_button.loading::before,
body ul.products li.product .product-actions .button.loading::before {
    display: none !important;
    content: none !important;
    animation: none !important;
}

/* Custom Premium Pure CSS Dead-Center Spinning Loader */
body ul.products li.product .product-actions a.button.loading::after,
body ul.products li.product .product-actions a.add_to_cart_button.loading::after,
body ul.products li.product .product-actions .button.loading::after {
    content: "" !important;
    display: block !important;
    position: absolute !important;
    left: 50% !important;
    top: 50% !important;
    width: 20px !important;
    height: 20px !important;
    margin-left: -10px !important;
    margin-top: -10px !important;
    border: 3px solid currentColor !important;
    border-bottom-color: transparent !important;
    border-left-color: transparent !important;
    border-radius: 50% !important;
    animation: vivid_atc_spin 0.6s linear infinite !important;
    opacity: 1 !important;
    visibility: visible !important;
    box-sizing: border-box !important;
}

/* =======================================================================
   MOBILE VERSION FIXES — Force visibility and proper layout on mobile grids
   ======================================================================= */

@media (max-width: 767px) {
    body ul.products li.product .product-inner {
        display: flex !important;
        flex-direction: column !important;
    }
    body ul.products li.product .product-actions,
    body ul.products li.product:hover .product-actions,
    body .catalog-grid ul.products li.product .product-actions {
        display: block !important;
        opacity: 1 !important;
        visibility: visible !important;
        position: relative !important;
        bottom: auto !important;
        left: auto !important;
        right: auto !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        transform: none !important;
    }
    body ul.products li.product .product-actions a.button,
    body ul.products li.product .product-actions a.add_to_cart_button,
    body ul.products li.product .product-actions .button {
        display: flex !important;
        width: 100% !important;
        box-sizing: border-box !important;
        white-space: normal !important;
        word-break: break-word !important;
        line-height: 1.2 !important;
        height: auto !important;
        min-height: 40px !important;
        padding-top: 8px !important;
        padding-bottom: 8px !important;
    }
}
