/**
 * AmSouviner — WooCommerce Variation Radio Buttons
 *
 * Styles for the custom radio-button groups that replace WooCommerce's
 * default variation <select> dropdowns.
 *
 * Design principles:
 *  • Pill/chip shape — common e-commerce pattern, instantly recognisable.
 *  • Minimum 44 × 44 px touch target (WCAG 2.5.5).
 *  • Visible focus indicator for keyboard users (WCAG 2.4.7).
 *  • Clear disabled + out-of-stock appearance.
 *  • Responsive: wraps naturally on small screens.
 *  • Uses CSS custom properties so theme colours apply automatically.
 *
 * @package AmSouviner
 */

/* ============================================================================
   Container
   ============================================================================ */

.ami-variation-radios {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 6px;
    /* Full width so it sits inside the existing .d-flex wrapper */
    width: 100%;
}

/* ============================================================================
   Individual item wrapper
   ============================================================================ */

.ami-radio-item {
    position: relative;
    display: inline-flex;
}

/* ============================================================================
   Hidden <input type="radio">
   Screen-reader-accessible but visually invisible.
   DO NOT use display:none or visibility:hidden — those break keyboard access.
   ============================================================================ */

.ami-radio-input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    margin: 0;
    padding: 0;
    border: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    pointer-events: none;
}

/* ============================================================================
   Label — the visible clickable chip
   ============================================================================ */

.ami-radio-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 7px 18px;
    min-width: 44px;
    min-height: 44px;
    line-height: 1.2;
    border: 1.5px solid var(--ami-border, #EEEEEE);
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--ami-text, #333333);
    background-color: #ffffff;
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
    transition:
        background-color 0.15s ease,
        border-color 0.15s ease,
        color 0.15s ease,
        box-shadow 0.15s ease;
}

/* ============================================================================
   Hover state (only on enabled items)
   ============================================================================ */

.ami-radio-item:not(.ami-disabled) .ami-radio-label:hover {
    border-color: var(--ami-primary, #FF8C42);
    color: var(--ami-primary, #FF8C42);
    background-color: rgba(255, 140, 66, 0.06);
}

/* ============================================================================
   Selected / checked state
   Applied via both :checked (CSS) and .selected class (JS fallback)
   ============================================================================ */

.ami-radio-input:checked + .ami-radio-label,
.ami-radio-item.selected .ami-radio-label {
    background-color: var(--ami-primary, #FF8C42);
    border-color: var(--ami-primary, #FF8C42);
    color: #ffffff;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(255, 140, 66, 0.30);
}

/* Subtle inner highlight for depth */
.ami-radio-input:checked + .ami-radio-label::before,
.ami-radio-item.selected .ami-radio-label::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.1);
    pointer-events: none;
}

/* ============================================================================
   Focus-visible — keyboard navigation indicator (WCAG 2.4.7)
   ============================================================================ */

.ami-radio-input:focus-visible + .ami-radio-label {
    outline: 3px solid var(--ami-primary, #FF8C42);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(255, 140, 66, 0.20);
}

/* Firefox / older browsers fallback */
.ami-radio-input:focus + .ami-radio-label {
    outline: 2px solid var(--ami-primary, #FF8C42);
    outline-offset: 2px;
}

/* ============================================================================
   Disabled state — unavailable combination (greyed out + strikethrough)
   ============================================================================ */

.ami-radio-item.ami-disabled .ami-radio-label,
.ami-radio-input:disabled + .ami-radio-label {
    opacity: 0.40;
    cursor: not-allowed;
    text-decoration: line-through;
    text-decoration-color: rgba(0, 0, 0, 0.25);
    border-color: #DDDDDD;
    color: #888888;
    background-color: #f5f5f5;
    box-shadow: none;
    pointer-events: none;
}

/* Remove hover effect from disabled items */
.ami-radio-item.ami-disabled .ami-radio-label:hover {
    border-color: #DDDDDD;
    color: #888888;
    background-color: #f5f5f5;
}

/* ============================================================================
   Out-of-stock state (if WooCommerce adds an oos class in the future)
   ============================================================================ */

.ami-radio-item.oos .ami-radio-label,
.ami-radio-item.outofstock .ami-radio-label {
    opacity: 0.35;
    cursor: not-allowed;
    text-decoration: line-through;
    border-color: #DDDDDD;
    color: #999999;
    background-color: #f9f9f9;
    position: relative;
}

/* Diagonal cross to reinforce out-of-stock */
.ami-radio-item.oos .ami-radio-label::after,
.ami-radio-item.outofstock .ami-radio-label::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: rgba(0, 0, 0, 0.2);
    transform: rotate(-18deg);
    pointer-events: none;
}

/* ============================================================================
   Colour swatch variant (optional: add 'swatch' class via filter)
   ============================================================================ */

.ami-radio-item.ami-swatch .ami-radio-label {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    padding: 0;
    border-radius: 50%;
    overflow: hidden;
    /* background-color set via inline style from PHP */
}

.ami-radio-item.ami-swatch.selected .ami-radio-label {
    box-shadow:
        0 0 0 2px #ffffff,
        0 0 0 4px var(--ami-primary, #FF8C42);
    background-color: inherit; /* keep swatch colour */
    color: transparent;        /* hide any text */
}

/* ============================================================================
   Integration: hide WooCommerce's default "reset variations" link when
   using radios (we show our own Clear button).
   ============================================================================ */

/* Keep the WooCommerce .reset_variations link visible — it triggers
   WooCommerce's reset_data event which we listen for.
   We just ensure its display state is still controlled by WC's JS. */

/* ============================================================================
   Responsive / mobile
   ============================================================================ */

@media (max-width: 480px) {
    .ami-variation-radios {
        gap: 6px;
    }

    .ami-radio-label {
        padding: 6px 12px;
        font-size: 0.8125rem;
        min-height: 40px;
    }
}

/* ============================================================================
   Integration with Bootstrap form layout
   .variations wrapper from our variable.php already uses .d-flex.flex-wrap
   ============================================================================ */

/* Move the "Clear" link to its own row below the radio group */
.variations .d-flex.flex-wrap .reset_variations {
    width: 100%;
    margin-top: 4px;
    order: 9999; /* always last */
}
