/**
 * UruShop Variation Swatches
 *
 * Pill-style button swatches for WooCommerce variable product attributes.
 * Uses UruShop design tokens from theme.json / style.css.
 *
 * @see mu-plugins/specs/urushop-variation-swatches.spec.md
 */

/* --------------------------------------------------------------------------
   Container
   -------------------------------------------------------------------------- */
.urushop-swatches {
    margin-bottom: 8px;
}

/* --------------------------------------------------------------------------
   Attribute Label — hidden; highlighted pill is sufficient indicator
   -------------------------------------------------------------------------- */
.urushop-swatches__label {
    display: none;
}

/* --------------------------------------------------------------------------
   Pills Container
   -------------------------------------------------------------------------- */
.urushop-swatches__pills {
    display: flex;
    flex-wrap: wrap;
    gap: var(--urushop-spacing-xs, 8px);
}

/* --------------------------------------------------------------------------
   Individual Pill (Default State)
   -------------------------------------------------------------------------- */
.urushop-swatch {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    min-height: 44px; /* WCAG touch target */
    padding: 8px 16px;
    border: 1.5px solid #D1D5DB;
    border-radius: var(--urushop-radius-sm, 6px);
    background: var(--urushop-white, #FFFFFF);
    color: var(--urushop-deep-forest, #1B4332);
    font-family: var(--urushop-font-body, 'Inter', sans-serif);
    font-size: 14px;
    font-weight: 500;
    line-height: 1.2;
    cursor: pointer;
    transition: all var(--urushop-transition-fast, 0.15s) ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* --------------------------------------------------------------------------
   Hover State
   -------------------------------------------------------------------------- */
.urushop-swatch:hover:not(.urushop-swatch--disabled) {
    border-color: var(--urushop-mate-green, #00A86B);
    background: #F0FDF9;
    color: var(--urushop-deep-forest, #1B4332);
}

/* --------------------------------------------------------------------------
   Active/Selected State
   -------------------------------------------------------------------------- */
.urushop-swatch--active {
    border-color: var(--urushop-mate-green, #00A86B);
    border-width: 2px;
    background: #ECFDF5;
    color: var(--urushop-mate-green, #00A86B);
    font-weight: 600;
    /* Compensate for thicker border to prevent layout shift */
    padding: 7px 15px;
}

/* --------------------------------------------------------------------------
   Disabled/Out-of-Stock State
   -------------------------------------------------------------------------- */
.urushop-swatch--disabled {
    border-color: #E5E7EB;
    background: #F9FAFB;
    color: #9CA3AF;
    cursor: not-allowed;
    opacity: 0.6;
    text-decoration: line-through;
}

/* --------------------------------------------------------------------------
   Focus State (Keyboard Navigation)
   -------------------------------------------------------------------------- */
.urushop-swatch:focus-visible {
    outline: 2px solid var(--urushop-mate-green, #00A86B);
    outline-offset: 2px;
    border-color: var(--urushop-mate-green, #00A86B);
}

/* --------------------------------------------------------------------------
   Image Swatches — thumbnail per variation
   -------------------------------------------------------------------------- */
.urushop-swatch--image {
    flex-direction: column;
    gap: 4px;
    padding: 4px;
    min-width: auto;
    min-height: auto;
    border-radius: var(--urushop-radius-sm, 6px);
}

.urushop-swatch--image img {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 4px;
    display: block;
}

.urushop-swatch--image .urushop-swatch__label {
    font-size: 11px;
    font-weight: 500;
    line-height: 1.1;
    text-align: center;
    max-width: 56px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.urushop-swatch--image.urushop-swatch--active {
    padding: 3px;
}

.urushop-swatch--image.urushop-swatch--active .urushop-swatch__label {
    font-weight: 600;
    color: var(--urushop-mate-green, #00A86B);
}

.urushop-swatch--image.urushop-swatch--disabled img {
    opacity: 0.4;
}

.urushop-swatch--image.urushop-swatch--disabled {
    text-decoration: none;
}

/* Image swatches container — tighter gap */
.urushop-swatches--images .urushop-swatches__pills {
    gap: 6px;
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    .urushop-swatches__pills {
        gap: 6px;
    }

    .urushop-swatch {
        min-height: 44px;
        padding: 8px 12px;
        font-size: 13px;
    }

    .urushop-swatch--active {
        padding: 7px 11px;
    }

    .urushop-swatch--image img {
        width: 40px;
        height: 40px;
    }

    .urushop-swatch--image .urushop-swatch__label {
        font-size: 10px;
        max-width: 48px;
    }
}

/* --------------------------------------------------------------------------
   Integration: WooCommerce variations table layout
   (Clean up default table layout, hide duplicate labels)
   -------------------------------------------------------------------------- */

/* Hide WC's "Size" row label — our swatch component has its own */
.variations td.label,
.variations th.label,
.variations td.label label,
.variations > tbody > tr > td:first-child:not(.value),
.variations > tbody > tr > th {
    display: none !important;
}

/* Also hide any label element WC/GreenShift puts above the table */
table.variations > caption,
.woocommerce-variation-form > label {
    display: none !important;
}

/* Make the value cell full width */
.variations td.value {
    display: block;
    width: 100%;
    padding: 0;
}

/* Collapse table structure into simple block flow */
.variations,
.variations tbody,
.variations tr {
    display: block;
}

.variations tr {
    margin-bottom: 4px;
}

/* Hide "Clear" link — pill deselection handles this */
.variations .reset_variations {
    display: none !important;
}

/* Hide variation price below swatches — main price block shows it instead */
.woocommerce-variation-price {
    display: none !important;
}

/* --------------------------------------------------------------------------
   Fix: Variable product add-to-cart layout
   GreenShift's grid layout constrains the quantity widget to 45px on
   variable products. Override to flex to match simple product styling.
   -------------------------------------------------------------------------- */
/* Override GreenShift's grid layout on variable product add-to-cart */
.variations_form .woocommerce-variation-add-to-cart {
    display: flex !important;
    flex-wrap: nowrap;
    align-items: center;
    gap: 12px;
    position: relative;
}

.variations_form .woocommerce-variation-add-to-cart .quantity {
    display: inline-flex;
    width: 144px;
    flex-shrink: 0;
}

/* YITH WAPO container has only hidden inputs — remove from flow */
.variations_form .woocommerce-variation-add-to-cart #yith-wapo-container {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* Wishlist button inline with Add to basket */
.variations_form .woocommerce-variation-add-to-cart .urushop-wishlist-btn {
    flex: 0 0 auto;
    width: auto;
}

/* --------------------------------------------------------------------------
   Bundle Pills: two-line layout (label + unit price)
   -------------------------------------------------------------------------- */
.urushop-swatch--bundle {
    flex-direction: column;
    gap: 2px;
    padding: 6px 12px;
    min-width: 64px;
}

.urushop-swatch--bundle.urushop-swatch--active {
    padding: 5px 11px;
}

.urushop-swatch__label {
    display: block;
    font-weight: 600;
    font-size: 14px;
    line-height: 1.2;
}

.urushop-swatch__unit-price {
    display: block;
    font-weight: 400;
    font-size: 11px;
    line-height: 1.2;
    opacity: 0.7;
}

.urushop-swatch--active .urushop-swatch__unit-price {
    opacity: 0.85;
}

/* --------------------------------------------------------------------------
   Bundle Mode: hide quantity widget, keep qty input in DOM for form submit
   -------------------------------------------------------------------------- */
.urushop-swatches--bundles ~ .quantity,
form.cart:has(.urushop-swatches--bundles) .quantity {
    display: none !important;
}

/* --------------------------------------------------------------------------
   Bundle Mode: pills + Add to basket inline (wrap if needed)
   -------------------------------------------------------------------------- */
form.cart:has(.urushop-swatches--bundles) {
    display: flex !important;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 8px;
}

/* Pills container sits inline */
form.cart:has(.urushop-swatches--bundles) .urushop-swatches--bundles {
    flex: 0 0 auto;
    margin-bottom: 0;
}

/* Tighter gap between bundle pills */
.urushop-swatches--bundles .urushop-swatches__pills {
    gap: 6px;
}

/* Add to basket button inline after pills */
form.cart:has(.urushop-swatches--bundles) .single_add_to_cart_button {
    flex: 0 0 auto;
}

/* Wishlist button inline */
form.cart:has(.urushop-swatches--bundles) .urushop-wishlist-btn {
    flex: 0 0 auto;
}

/* YITH WAPO container — collapse on bundle products too */
form.cart:has(.urushop-swatches--bundles) #yith-wapo-container {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* --------------------------------------------------------------------------
   Bundle Mode: strikethrough price styling
   -------------------------------------------------------------------------- */
.wc-block-components-product-price del {
    opacity: 0.5;
    font-weight: 400;
    text-decoration: line-through;
}

.wc-block-components-product-price ins {
    text-decoration: none;
    font-weight: 700;
}

