/** Frontend styles for VUIHS Variation Swatches */

/* --- General WooCommerce Overrides (for themes that might interfere) --- */
/*
 * THE DEFINITIVE FIX:
 * These rules hide the theme's default buttons on products where our swatches are active.
 * The rules are separated for clarity and robustness, as requested.
*/

/* 1. Hide the default "Select options" button. This selector is broad to catch it
      regardless of its container within the product card. */
.woocommerce ul.products li.product:has(.vuihs-vs-archive-product-wrap) a.add_to_cart_button.product_type_variable {
    display: none !important;
}

/* 2. Hide the theme's specific "View" button (from .ct-woo-card-actions) to prevent duplicates,
      allowing the plugin's dynamic button to appear correctly. */
.woocommerce ul.products li.product:has(.vuihs-vs-archive-product-wrap) .ct-woo-card-actions a.view-product-button {
    
}

/* Ensure product image wrapper is the positioning and overflow context for the overlay. */
.woocommerce ul.products li.product .woocommerce-loop-product__link,
.woocommerce ul.products li.product .ct-media-container { 
    position: relative;
    display: block; /* Ensure it takes up space for the image to scale */
    overflow: hidden; /* Hide the button when it's outside the bounds */
}

/* --- Wrappers --- */

/* Single Product Page Swatch Wrapper: Horizontal layout */
.vuihs-vs-wrap { 
    display: flex; 
    gap: .5rem; 
    flex-wrap: wrap; 
    align-items: center; 
    margin: .5rem 0; 
}

/* Shop/Archive Page Main Wrapper: Contains all swatch rows and dynamic content for a single product card */
.vuihs-vs-archive-product-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .5rem;
    margin: .75rem 0;
    text-align: center; 
}

/* Shop/Archive Page Swatch Row Wrapper: A single row of swatches for one attribute */
.vuihs-vs-archive-swatch-row {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    margin-bottom: 5px; 
}

/* Hide the dynamically created variations form (it's only for JS interaction) */
.vuihs-vs-archive-product-wrap .variations_form {
    display: none !important;
}

/* Hide original WooCommerce dropdown on single product via parent class */
.variations_form .variations select[name^="attribute_"] {
    display: none !important;
}

/* --- Base Swatch Styling --- */
.vuihs-vs-swatch {
    border: 1px solid var(--vuihs-vs-border, #ddd);
    background: transparent;
    padding: 2px;
    cursor: pointer;
    position: relative;
    line-height: 0; 
    box-sizing: border-box;
    transition: transform .12s ease, box-shadow .12s ease, opacity .12s ease, border-color .12s ease;
}

/* Effects */
.vuihs-vs-swatch:hover {
    transform: translateY(-2px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.vuihs-vs-swatch:active {
    transform: translateY(0);
    box-shadow: none;
}
.vuihs-vs-swatch.is-disabled {
    opacity: .35;
    cursor: not-allowed;
    transform: none; 
    box-shadow: none;
    pointer-events: none;
}
.vuihs-vs-swatch.is-selected {
    border-color: var(--vuihs-vs-border-selected, #555); 
    box-shadow: 0 0 0 1px var(--vuihs-vs-border-selected, #555);
}

/* Shapes - FIXED CORNER RADIUS with more specific selectors and CSS variables */
.vuihs-vs-wrap .vuihs-vs-shape-circle, .vuihs-vs-archive-swatch-row .vuihs-vs-shape-circle { border-radius: 999px; }
.vuihs-vs-wrap .vuihs-vs-shape-rounded, .vuihs-vs-archive-swatch-row .vuihs-vs-shape-rounded { border-radius: var(--vuihs-shape-rounded-radius, 8px); }
.vuihs-vs-wrap .vuihs-vs-shape-square, .vuihs-vs-archive-swatch-row .vuihs-vs-shape-square { border-radius: var(--vuihs-shape-square-radius, 4px); }

/* Inner visuals */
.vuihs-vs-color, .vuihs-vs-img, .vuihs-vs-img--placeholder, .vuihs-vs-label {
    display: block;
    border-radius: inherit;
}

/* Sizes - Color / Image */
.vuihs-vs-size-small .vuihs-vs-color, .vuihs-vs-size-small .vuihs-vs-img, .vuihs-vs-size-small .vuihs-vs-img--placeholder { width:28px; height:28px; }
.vuihs-vs-size-medium .vuihs-vs-color, .vuihs-vs-size-medium .vuihs-vs-img, .vuihs-vs-size-medium .vuihs-vs-img--placeholder { width:36px; height:36px; }
.vuihs-vs-size-large .vuihs-vs-color, .vuihs-vs-size-large .vuihs-vs-img, .vuihs-vs-size-large .vuihs-vs-img--placeholder { width:44px; height:44px; }

/* Sizes - Label */
.vuihs-vs-size-small .vuihs-vs-label { font-size:.8rem; padding: .3rem .6rem; line-height: 1.2; }
.vuihs-vs-size-medium .vuihs-vs-label { font-size:.875rem; padding: .4rem .8rem; line-height: 1.2; }
.vuihs-vs-size-large .vuihs-vs-label { font-size:.95rem; padding: .5rem 1rem; line-height: 1.2; }

/* Specifics */
.vuihs-vs-img { width:100%; height:100%; object-fit:cover; }
.vuihs-vs-img--placeholder { background:#eee; }
.vuihs-vs-label { background:var(--vuihs-vs-btn-bg,#f7f7f7); color: #444; white-space: nowrap; }

/* --- Add to Cart Overlay on Image --- */
.vuihs-vs-add-to-cart-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 10px;
    box-sizing: border-box;
    background: linear-gradient(to top, rgba(0,0,0,0.6), transparent);
    transform: translateY(100%);
    transition: transform 0.25s ease-out;
    display: flex;
    justify-content: center;
}
/* Slide overlay into view when it has the .is-visible class */
.vuihs-vs-add-to-cart-overlay.is-visible {
    transform: translateY(0);
}
.vuihs-vs-add-to-cart-overlay .button {
    margin: 0 !important;
    width: auto;
    flex-grow: 0;
    padding-left: 2em;
    padding-right: 2em;
    border: none;
    /* Use CSS variables from settings, with fallbacks to plugin defaults */
    background-color: var(--vuihs-atc-bg, #2271b1);
    color: var(--vuihs-atc-text, #ffffff);
    transition: background-color 0.2s ease, color 0.2s ease, transform 0.1s ease-out;
}
.vuihs-vs-add-to-cart-overlay .button:hover {
    background-color: var(--vuihs-atc-bg-hover, #185f9a);
    color: var(--vuihs-atc-text-hover, #ffffff);
}
.vuihs-vs-add-to-cart-overlay .button:active {
    transform: scale(0.97);
}
.vuihs-vs-add-to-cart-overlay .button.disabled,
.vuihs-vs-add-to-cart-overlay .button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}


/* --- Dynamic Content in Actions Area --- */
.vuihs-vs-archive-dynamic-content {
    min-height: 20px;
    width: 100%;
    margin-top: 5px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

/* Style for the 'Out of stock' message */
.vuihs-vs-archive-dynamic-content .stock.out-of-stock {
    font-weight: 600;
    color: #b00020;
    font-size: 0.9em;
    display: block;
}

/* Style the dynamically generated add-to-cart button */
.woocommerce ul.products li.product .single_add_to_cart_button.vuihs-vs-proxy-add-to-cart {
    display: inline-block;
    padding: .618em 1.414em;
    border: none;
    border-radius: 5px;
    font-weight: 700;
    line-height: 1;
    text-align: center;
    cursor: pointer;
    background-color: var(--vuihs-atc-bg, #2271b1);
    color: var(--vuihs-atc-text, #ffffff) !important;
    transition: background-color 0.2s ease, color 0.2s ease, transform 0.1s ease-out;
}
.woocommerce ul.products li.product .single_add_to_cart_button.vuihs-vs-proxy-add-to-cart:hover {
    background-color: var(--vuihs-atc-bg-hover, #185f9a);
    color: var(--vuihs-atc-text-hover, #ffffff) !important;
}
.woocommerce ul.products li.product .single_add_to_cart_button.vuihs-vs-proxy-add-to-cart:active {
    transform: scale(0.97);
}
.woocommerce ul.products li.product .single_add_to_cart_button.vuihs-vs-proxy-add-to-cart.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* NEW: Style the dynamically generated "View Product" button */
.vuihs-vs-archive-dynamic-content a.button.view-product-button {
    display: inline-block;
    padding: .618em 1.414em;
    font-weight: 700;
    line-height: 1;
    text-align: center;
    cursor: pointer;
    text-decoration: none;
    border-width: 1px;
    border-style: solid;
    background-color: var(--vuihs-vp-bg, #6c757d);
    color: var(--vuihs-vp-text, #ffffff) !important;
    border-color: var(--vuihs-vp-border, #6c757d);
    border-radius: var(--vuihs-vp-radius, 5px);
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
.vuihs-vs-archive-dynamic-content a.button.view-product-button:hover {
    background-color: var(--vuihs-vp-bg-hover, #5a6268);
    color: var(--vuihs-vp-text-hover, #ffffff) !important;
    border-color: var(--vuihs-vp-bg-hover, #5a6268);
}


/* --- Clear Variations Link --- */
.vuihs-vs-archive-product-wrap .vuihs-vs-clear-variations {
    font-size: 0.85em;
    color: #888;
    text-decoration: none;
    display: inline-block;
}
.vuihs-vs-archive-product-wrap .vuihs-vs-clear-variations:hover {
    color: #333;
}

/* --- Tooltip styles --- */
.vuihs-vs-tooltip {
    position: absolute;
    background-color: #333;
    color: #fff;
    padding: 5px 8px;
    border-radius: 3px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 9999;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity .2s ease, visibility .2s ease;
}
.vuihs-vs-tooltip.active {
    opacity: 1;
    visibility: visible;
}