/* Shared, accessible product color choices for every viewport. */
body.single-product .variation-box.color {
    --ts-variant-option-size: 42px;
    --ts-variant-option-surface: var(--product-variant-option-surface, var(--surface-card));
    --ts-variant-option-border: var(--product-variant-border, var(--border-control));
    --ts-variant-out-surface: var(--state-danger-surface);
    --ts-variant-stop-surface: var(--state-neutral-surface);
}

body.single-product .product-panel .left-panel .left-panel-box .purchase-panel .variations .variation-box.color .thumbs ul li.ts-product-color-option,
body.single-product #site-main .purchase-p .purchase-panel .variations .variation-box.color .thumbs ul li.ts-product-color-option {
    position: relative;
    isolation: isolate;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    flex: 0 0 var(--ts-variant-option-size);
    width: var(--ts-variant-option-size);
    min-width: var(--ts-variant-option-size);
    height: var(--ts-variant-option-size);
    min-height: var(--ts-variant-option-size);
    overflow: visible;
    padding: 3px;
    border: 1px solid var(--ts-variant-option-border);
    border-radius: 50%;
    background: var(--ts-variant-option-surface);
    box-shadow: inset 0 1px 0 color-mix(in srgb, var(--text-strong) 10%, transparent);
    cursor: pointer;
    opacity: 1;
    outline: 0;
    transition:
        border-color 140ms var(--theme-motion-ease),
        box-shadow 180ms var(--theme-motion-ease),
        transform 160ms var(--theme-motion-ease);
}

body.single-product .variation-box.color .ts-product-color-option > img {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    transition:
        filter 180ms var(--theme-motion-ease),
        opacity 180ms var(--theme-motion-ease),
        transform 180ms var(--theme-motion-ease);
}

body.single-product .variation-box.color .ts-product-color-option:hover {
    transform: translateY(-1px);
}

body.single-product .variation-box.color .ts-product-color-option:hover > img {
    transform: scale(1.04);
}

body.single-product .variation-box.color .ts-product-color-option:active {
    transform: translateY(0) scale(.97);
}

body.single-product .variation-box.color .ts-product-color-option:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 3px;
}

body.single-product main#site-main .purchase-panel.box-panel .variation-box.color .thumbs ul li.ts-product-color-option.active {
    border-color: var(--theme-accent) !important;
    box-shadow:
        inset 0 1px 0 color-mix(in srgb, var(--text-strong) 12%, transparent),
        0 0 0 2px color-mix(in srgb, var(--theme-accent) 34%, transparent);
}

/* Unavailable options stay selectable so the existing gallery/AJAX flow works. */
body.single-product .variation-box.color .ts-product-color-option.notStock {
    opacity: 1;
}

/*
 * Out-of-stock: keep the real product color fully visible in the circle,
 * and signal "unavailable" with a high-contrast slash + danger border.
 * No grayscale wash and no solid tint that hides the swatch color.
 */
body.single-product main#site-main .purchase-panel.box-panel .variation-box.color .thumbs ul li.ts-product-color-option.is-out-of-stock {
    border-color: color-mix(in srgb, var(--state-danger) 88%, var(--ts-variant-option-border)) !important;
    border-width: 2px;
}

body.single-product main#site-main .purchase-panel.box-panel .variation-box.color .thumbs ul li.ts-product-color-option.is-discontinued {
    border-color: color-mix(in srgb, var(--state-neutral) 74%, var(--ts-variant-option-border)) !important;
    border-style: dashed;
}

/* True color stays readable — only a light dim, never desaturate. */
body.single-product .variation-box.color .ts-product-color-option.is-out-of-stock > img {
    filter: none;
    opacity: 1;
}

body.single-product .variation-box.color .ts-product-color-option.is-discontinued > img {
    filter: grayscale(1) saturate(0) contrast(.9);
    opacity: .52;
}

body.single-product .product-panel .left-panel .left-panel-box .purchase-panel .variations .variation-box.color .thumbs ul li.ts-product-color-option.notStock .outstock,
body.single-product #site-main .purchase-p .purchase-panel .variations .variation-box.color .thumbs ul li.ts-product-color-option.notStock .outstock {
    position: absolute;
    inset: 3px;
    z-index: 2;
    display: grid;
    place-items: center;
    width: auto;
    height: auto;
    overflow: hidden;
    border: 0;
    border-radius: 50%;
    color: inherit !important;
    pointer-events: none;
}

/*
 * Transparent overlay so the color circle stays pure.
 * Specificity must beat theme-system's generic .outstock surface rule
 * (body.single-product #site-main .purchase-panel ... li .outstock).
 */
body.single-product #site-main .purchase-panel .variations .variation-box.color .thumbs ul li.ts-product-color-option.is-out-of-stock .outstock {
    background: transparent !important;
    color: inherit !important;
}

body.single-product #site-main .purchase-panel .variations .variation-box.color .thumbs ul li.ts-product-color-option.is-discontinued .outstock {
    background: color-mix(in srgb, var(--ts-variant-stop-surface) 56%, transparent) !important;
}

body.single-product .variation-box.color .ts-product-color-option.notStock .outstock > span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

body.single-product .variation-box.color .ts-product-color-option.notStock .outstock::before,
body.single-product .variation-box.color .ts-product-color-option.notStock .outstock::after {
    grid-area: 1 / 1;
    display: block;
    width: calc(var(--ts-variant-option-size) - 10px);
    height: 2px;
    border-radius: 999px;
    content: "";
}

/*
 * Dual-stroke slash: light outline (readable on dark colors) + danger line
 * (readable on light colors). Works on black, white, and saturated swatches.
 */
body.single-product .variation-box.color .ts-product-color-option.is-out-of-stock .outstock::before {
    height: 3.5px;
    background: color-mix(in srgb, var(--ts-variant-option-surface) 92%, var(--text-strong));
    box-shadow:
        0 0 0 1px color-mix(in srgb, var(--text-strong) 18%, transparent),
        0 1px 2px color-mix(in srgb, var(--text-strong) 28%, transparent);
    transform: rotate(-45deg);
}

body.single-product .variation-box.color .ts-product-color-option.is-out-of-stock .outstock::after {
    display: block;
    height: 2px;
    background: var(--state-danger);
    box-shadow: 0 0 0 0.5px color-mix(in srgb, var(--state-danger) 40%, transparent);
    transform: rotate(-45deg);
}

body.single-product .variation-box.color .ts-product-color-option.is-discontinued .outstock::before,
body.single-product .variation-box.color .ts-product-color-option.is-discontinued .outstock::after {
    background: var(--state-neutral);
    box-shadow: 0 1px 0 color-mix(in srgb, var(--ts-variant-option-surface) 82%, transparent);
}

body.single-product .variation-box.color .ts-product-color-option.is-discontinued .outstock::before {
    transform: rotate(-45deg);
}

body.single-product .variation-box.color .ts-product-color-option.is-discontinued .outstock::after {
    transform: rotate(45deg);
}

body.single-product main#site-main .purchase-panel.box-panel .variation-box.color .thumbs ul li.ts-product-color-option.notStock.active {
    box-shadow:
        0 0 0 2px var(--ts-variant-option-surface),
        0 0 0 4px color-mix(in srgb, var(--theme-accent) 78%, transparent);
}

body.single-product main#site-main .purchase-panel.box-panel .variation-box.color .thumbs ul li.ts-product-color-option.is-out-of-stock.active {
    border-color: var(--state-danger) !important;
}

body.single-product main#site-main .purchase-panel.box-panel .variation-box.color .thumbs ul li.ts-product-color-option.is-discontinued.active {
    border-color: var(--state-neutral) !important;
}

@media (max-width: 767px) {
    body.single-product .variation-box.color {
        --ts-variant-option-size: 44px;
    }
}

@media (prefers-reduced-motion: reduce) {
    body.single-product .variation-box.color .ts-product-color-option,
    body.single-product .variation-box.color .ts-product-color-option > img {
        transition: none;
    }

    body.single-product .variation-box.color .ts-product-color-option:hover,
    body.single-product .variation-box.color .ts-product-color-option:active,
    body.single-product .variation-box.color .ts-product-color-option:hover > img {
        transform: none;
    }
}
