/**
 * Frontend Styles for WooCommerce Swatches.
 *
 * @package WooCommerceSwatches
 */

:root {
    --wc-swatch-size: 38px;
    --wc-swatch-spacing: 10px;
    --wc-swatch-border-color: #d1d5db;
    --wc-swatch-border-active-color: #111827;
    --wc-swatch-radius: 6px;
    --wc-swatch-tooltip-bg: #111827;
    --wc-swatch-tooltip-text: #ffffff;
}

/* ==========================================================================
   Wrapper & Item Layout
   ========================================================================== */

.wc-swatches-select-replacement {
    display: block;
    width: 100%;
    margin-bottom: 8px;
    clear: both;
}

.wc-swatches-wrapper {
    display: block;
    margin: 6px 0 12px 0;
}

.wc-swatches-items {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--wc-swatch-spacing);
}

/* Base Swatch Item */
.wc-swatch-item {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    background-color: #ffffff;
    border: 1px solid var(--wc-swatch-border-color);
    box-sizing: border-box;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1),
                border-color 0.2s ease,
                box-shadow 0.2s ease,
                opacity 0.2s ease;
    padding: 2px;
}

/* ==========================================================================
   Shapes & Fixed 1:1 Aspect Ratio (Prevents Oval Distortions)
   ========================================================================== */

/* Ensure color and image swatches are ALWAYS strictly 1:1 square / circle (never oval) */
.wc-swatch-item.wc-swatch-color,
.wc-swatch-item.wc-swatch-image,
.wc-swatches-items .wc-swatch-color,
.wc-swatches-items .wc-swatch-image {
    width: var(--wc-swatch-size, 38px) !important;
    height: var(--wc-swatch-size, 38px) !important;
    min-width: var(--wc-swatch-size, 38px) !important;
    max-width: var(--wc-swatch-size, 38px) !important;
    min-height: var(--wc-swatch-size, 38px) !important;
    max-height: var(--wc-swatch-size, 38px) !important;
    aspect-ratio: 1 / 1 !important;
    flex: 0 0 var(--wc-swatch-size, 38px) !important;
    padding: 2px !important;
    box-sizing: border-box !important;
}

/* Shape: Rounded (Strictly rounded square, never oval) */
.wc-swatches-shape-rounded .wc-swatch-item.wc-swatch-color,
.wc-swatches-shape-rounded .wc-swatch-item.wc-swatch-image,
.wc-swatches-shape-rounded .wc-swatch-item:not(.wc-swatch-button):not(.wc-swatch-radio),
.wc-swatches-shape-rounded .wc-swatch-inner,
.wc-swatches-shape-rounded .wc-swatch-color-bullet,
.wc-swatches-shape-rounded .wc-swatch-inner img {
    border-radius: 6px !important;
}

/* Shape: Circle (Perfect symmetrical circle) */
.wc-swatches-shape-circle .wc-swatch-item.wc-swatch-color,
.wc-swatches-shape-circle .wc-swatch-item.wc-swatch-image,
.wc-swatches-shape-circle .wc-swatch-item:not(.wc-swatch-button):not(.wc-swatch-radio),
.wc-swatches-shape-circle .wc-swatch-inner,
.wc-swatches-shape-circle .wc-swatch-color-bullet,
.wc-swatches-shape-circle .wc-swatch-inner img {
    border-radius: 50% !important;
}

/* Shape: Square (Crisp square corners) */
.wc-swatches-shape-square .wc-swatch-item.wc-swatch-color,
.wc-swatches-shape-square .wc-swatch-item.wc-swatch-image,
.wc-swatches-shape-square .wc-swatch-item:not(.wc-swatch-button):not(.wc-swatch-radio),
.wc-swatches-shape-square .wc-swatch-inner,
.wc-swatches-shape-square .wc-swatch-color-bullet,
.wc-swatches-shape-square .wc-swatch-inner img {
    border-radius: 0 !important;
}

/* ==========================================================================
   Sizes
   ========================================================================== */

.wc-swatches-size-small .wc-swatch-item.wc-swatch-color,
.wc-swatches-size-small .wc-swatch-item.wc-swatch-image {
    width: 28px !important;
    height: 28px !important;
    min-width: 28px !important;
    max-width: 28px !important;
    min-height: 28px !important;
    max-height: 28px !important;
    flex: 0 0 28px !important;
}

.wc-swatches-size-medium .wc-swatch-item.wc-swatch-color,
.wc-swatches-size-medium .wc-swatch-item.wc-swatch-image {
    width: 38px !important;
    height: 38px !important;
    min-width: 38px !important;
    max-width: 38px !important;
    min-height: 38px !important;
    max-height: 38px !important;
    flex: 0 0 38px !important;
}

.wc-swatches-size-large .wc-swatch-item.wc-swatch-color,
.wc-swatches-size-large .wc-swatch-item.wc-swatch-image {
    width: 48px !important;
    height: 48px !important;
    min-width: 48px !important;
    max-width: 48px !important;
    min-height: 48px !important;
    max-height: 48px !important;
    flex: 0 0 48px !important;
}

/* Inner Container */
.wc-swatch-inner {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    overflow: hidden;
    border-radius: inherit;
}

/* ==========================================================================
   Swatch Types
   ========================================================================== */

/* 1. Color Swatch */
.wc-swatch-color .wc-swatch-inner {
    width: 100% !important;
    height: 100% !important;
    border-radius: inherit !important;
    display: flex !important;
    overflow: hidden !important;
}

.wc-swatch-color .wc-swatch-color-bullet {
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    border-radius: inherit !important;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12) !important;
    flex-shrink: 0 !important;
}

/* 2. Image Swatch */
.wc-swatch-image .wc-swatch-inner img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.wc-swatch-image-fallback {
    font-size: 11px;
    color: #6b7280;
}

/* 3. Button / Label Swatch */
.wc-swatch-button {
    min-width: var(--wc-swatch-size);
    height: var(--wc-swatch-size);
    padding: 0 14px;
    background-color: #f9fafb;
    border: 1px solid var(--wc-swatch-border-color);
}

.wc-swatches-shape-rounded .wc-swatch-button {
    border-radius: 6px;
}

.wc-swatches-shape-circle .wc-swatch-button {
    border-radius: 20px;
}

.wc-swatches-shape-square .wc-swatch-button {
    border-radius: 0;
}

.wc-swatch-button .wc-swatch-text {
    font-size: 13px;
    font-weight: 500;
    color: #1f2937;
    white-space: nowrap;
}

/* 4. Radio Swatch */
.wc-swatch-radio {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: 6px;
    background-color: #ffffff;
    border: 1px solid var(--wc-swatch-border-color);
    cursor: pointer;
    font-size: 13px;
    color: #1f2937;
    font-weight: 500;
}

.wc-swatch-radio input[type="radio"] {
    display: none !important;
}

.wc-swatch-radio-indicator {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid #9ca3af;
    position: relative;
    box-sizing: border-box;
    transition: border-color 0.2s ease;
}

.wc-swatch-radio.selected .wc-swatch-radio-indicator {
    border-color: var(--wc-swatch-border-active-color);
}

.wc-swatch-radio.selected .wc-swatch-radio-indicator::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--wc-swatch-border-active-color);
}

/* ==========================================================================
   States (Hover, Selected, Disabled)
   ========================================================================== */

/* Hover Effects */
.wc-swatches-hover-scale .wc-swatch-item:not(.disabled):hover {
    transform: scale(1.08);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.12);
    border-color: #9ca3af;
}

.wc-swatches-hover-glow .wc-swatch-item:not(.disabled):hover {
    box-shadow: 0 0 0 3px rgba(17, 24, 39, 0.15);
    border-color: var(--wc-swatch-border-active-color);
}

/* Selected State */
.wc-swatch-item.selected {
    border-color: var(--wc-swatch-border-active-color) !important;
    box-shadow: 0 0 0 2px var(--wc-swatch-border-active-color);
}

.wc-swatch-color.selected,
.wc-swatch-image.selected {
    background-color: transparent !important;
}

.wc-swatch-button.selected {
    background-color: var(--wc-swatch-border-active-color, #111827);
    border-color: var(--wc-swatch-border-active-color, #111827) !important;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.wc-swatch-button.selected .wc-swatch-text {
    color: #ffffff;
}

/* Out of Stock / Disabled State */
.wc-swatch-item.disabled {
    opacity: 0.35;
    cursor: not-allowed !important;
    pointer-events: none;
}

/* Crossed out behavior */
.wc-swatch-item.disabled.out-of-stock {
    position: relative;
    overflow: hidden;
}

.wc-swatch-item.disabled.out-of-stock::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 141%;
    height: 1.5px;
    background-color: #ef4444;
    transform-origin: 0 0;
    transform: rotate(45deg);
    z-index: 5;
}

/* ==========================================================================
   Tooltips
   ========================================================================== */

.wc-swatch-tooltip {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    background-color: var(--wc-swatch-tooltip-bg);
    color: var(--wc-swatch-tooltip-text);
    padding: 4px 8px;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.2;
    border-radius: 4px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    z-index: 100;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}

.wc-swatch-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 4px;
    border-style: solid;
    border-color: var(--wc-swatch-tooltip-bg) transparent transparent transparent;
}

.wc-swatch-item:hover .wc-swatch-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* ==========================================================================
   Selected Label in Title
   ========================================================================== */

.wc-swatches-selected-label-wrap {
    font-weight: 600;
    color: #111827;
}

.wc-swatches-selected-label-value {
    color: #374151;
    font-weight: 500;
}

/* ==========================================================================
   Catalog / Shop Loop Swatches
   ========================================================================== */

.wc-swatches-loop-wrapper {
    margin: 8px 0;
    display: block;
    clear: both;
}

.wc-swatches-loop-items {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.wc-swatches-loop-item {
    width: 22px;
    height: 22px;
    box-sizing: border-box;
    border: 1px solid #d1d5db;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, border-color 0.15s ease;
    padding: 1px;
    background: #fff;
}

.wc-swatches-shape-circle .wc-swatches-loop-item,
.wc-swatches-shape-circle .wc-swatches-loop-item .wc-swatch-color-bullet,
.wc-swatches-shape-circle .wc-swatches-loop-item img {
    border-radius: 50% !important;
}

.wc-swatches-shape-rounded .wc-swatches-loop-item,
.wc-swatches-shape-rounded .wc-swatches-loop-item .wc-swatch-color-bullet,
.wc-swatches-shape-rounded .wc-swatches-loop-item img {
    border-radius: 4px;
}

.wc-swatches-shape-square .wc-swatches-loop-item,
.wc-swatches-shape-square .wc-swatches-loop-item .wc-swatch-color-bullet,
.wc-swatches-shape-square .wc-swatches-loop-item img {
    border-radius: 0;
}

.wc-swatches-loop-item .wc-swatch-color-bullet {
    width: 100%;
    height: 100%;
    display: block;
}

.wc-swatches-loop-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.wc-swatches-loop-item.wc-swatch-button {
    width: auto;
    min-width: 22px;
    padding: 0 6px;
    font-size: 11px;
}

.wc-swatches-loop-item:hover,
.wc-swatches-loop-item.active {
    border-color: var(--wc-swatch-border-active-color);
    transform: scale(1.12);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

/* ==========================================================================
   Modernized Reset Variations ("Clear") Button
   ========================================================================== */

.woocommerce .reset_variations,
.reset_variations.wc-swatches-reset-btn {
    display: inline-flex !important;
    align-items: center !important;
    gap: 6px !important;
    margin: 8px 0 2px 0 !important;
    padding: 5px 12px !important;
    font-size: 12px !important;
    font-weight: 500 !important;
    line-height: 1 !important;
    color: #4b5563 !important;
    background-color: #f3f4f6 !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 9999px !important;
    text-decoration: none !important;
    cursor: pointer !important;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05) !important;
    vertical-align: middle !important;
}

.woocommerce .reset_variations svg,
.reset_variations.wc-swatches-reset-btn svg {
    display: inline-block !important;
    vertical-align: middle !important;
    transition: transform 0.3s ease !important;
    color: currentColor !important;
}

.woocommerce .reset_variations:hover,
.reset_variations.wc-swatches-reset-btn:hover {
    background-color: #fee2e2 !important;
    border-color: #fca5a5 !important;
    color: #ef4444 !important;
    transform: translateY(-1px) !important;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.15) !important;
}

.woocommerce .reset_variations:hover svg,
.reset_variations.wc-swatches-reset-btn:hover svg {
    transform: rotate(-90deg) !important;
}

.woocommerce .reset_variations:active,
.reset_variations.wc-swatches-reset-btn:active {
    transform: translateY(0) !important;
}

/* Ensure it is hidden when WooCommerce sets visibility hidden or display none */
.woocommerce .reset_variations[style*="visibility: hidden"],
.reset_variations[style*="visibility: hidden"],
.woocommerce .reset_variations[style*="display: none"],
.reset_variations[style*="display: none"] {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* ==========================================================================
   Responsive Adaptations
   ========================================================================== */

@media (max-width: 768px) {
    .wc-swatches-items {
        gap: 8px;
    }

    .wc-swatch-item {
        min-height: 36px;
    }

    .wc-swatches-size-small .wc-swatch-item:not(.wc-swatch-button):not(.wc-swatch-radio) {
        width: 32px;
        height: 32px;
    }
}

/* ==========================================================================
   Label Position Layouts (Left / Above)
   ========================================================================== */

/* Stacked Layout: Above (Label on top, swatches below) */
body.wc-swatches-label-above table.variations,
body.wc-swatches-label-above .variations {
    width: 100% !important;
}

body.wc-swatches-label-above table.variations tbody,
body.wc-swatches-label-above .variations tbody {
    display: block !important;
    width: 100% !important;
}

body.wc-swatches-label-above table.variations tr,
body.wc-swatches-label-above .variations tr {
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    width: 100% !important;
    margin-bottom: 14px !important;
    border: none !important;
}

body.wc-swatches-label-above table.variations th.label,
body.wc-swatches-label-above table.variations th,
body.wc-swatches-label-above .variations th,
body.wc-swatches-label-above .variations .label {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 0 6px 0 !important;
    text-align: left !important;
    border: none !important;
    line-height: 1.4 !important;
}

body.wc-swatches-label-above table.variations th label,
body.wc-swatches-label-above .variations label {
    display: inline-block !important;
    font-weight: 600 !important;
    margin-bottom: 2px !important;
}

body.wc-swatches-label-above table.variations td.value,
body.wc-swatches-label-above .variations td.value {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    border: none !important;
}

/* Side-by-Side Layout: Left (Label on left, swatches on right) */
body.wc-swatches-label-left table.variations th.label,
body.wc-swatches-label-left .variations th.label {
    vertical-align: middle !important;
    padding-right: 18px !important;
    white-space: nowrap !important;
    text-align: left !important;
}

body.wc-swatches-label-left table.variations td.value,
body.wc-swatches-label-left .variations td.value {
    vertical-align: middle !important;
}
