/* Hide the original select dropdowns and theme custom selects more aggressively */
.variations_form select,
table.variations select,
.variations select,
.variations_form .theme-select,
table.variations .theme-select,
.variations .theme-select {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    position: absolute !important;
    z-index: -999 !important;
}

/* Container */
.fw-swatches-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 0 !important;
    margin-right: 15px !important;
    justify-content: flex-start !important;
    align-items: center !important;
    width: auto !important;
    flex: 0 1 auto !important;
}

/* Fix the large gap between the label and the swatches */
.woocommerce div.product table.variations tbody,
.woocommerce div.product table.variations {
    display: block !important;
    border: none !important;
}
.woocommerce div.product table.variations tr {
    display: flex !important;
    align-items: center !important;
    margin-bottom: 15px !important;
}
.woocommerce div.product table.variations th.label {
    width: auto !important;
    padding: 0 15px 0 0 !important;
    margin: 0 !important;
    background: transparent !important;
    border: none !important;
    line-height: 1 !important;
}
.woocommerce div.product table.variations td.value {
    width: auto !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    background: transparent !important;
    flex: 1 !important;
    display: flex !important;
    align-items: center !important;
}
.fw-swatches-wrapper {
    margin-bottom: 0 !important;
}

.woocommerce div.product table.variations .reset_variations {
    margin-top: 0 !important;
    margin-bottom: 0 !important;
}

/* Base Swatch Styling - Theme adaptive */
.fw-swatch {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(128, 128, 128, 0.3); /* Adaptive subtle border */
    border-radius: var(--wp--preset--spacing--20, 4px); /* Adaptive radius */
    cursor: pointer;
    overflow: visible; /* To allow tooltips to show outside */
    background-color: transparent;
    min-width: 40px;
    height: 40px;
    padding: 0 10px;
    font-size: 14px;
    font-weight: 500;
    color: inherit;
    transition: all 0.2s ease;
    user-select: none;
    position: relative;
    box-sizing: border-box;
}

.fw-swatch:hover {
    border-color: rgba(128, 128, 128, 0.8);
}

/* Image Swatch */
.fw-swatch.is-image {
    padding: 0;
    width: 50px;
    height: 50px;
}

.fw-swatch.is-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
    border-radius: calc(var(--wp--preset--spacing--20, 4px) - 1px);
}

/* Selected state */
.fw-swatch.active {
    border-color: currentColor; /* Matches theme text color */
    box-shadow: 0 0 0 1px currentColor; /* Makes border look 2px thick */
    pointer-events: none; /* Make selected unclickable as requested */
}

/* Checkmark on active image swatches */
.fw-swatch.active.is-image::after {
    content: '';
    position: absolute;
    bottom: -4px;
    right: -4px;
    width: 16px;
    height: 16px;
    background-color: currentColor;
    border-radius: 50%;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E");
    background-size: 10px;
    background-repeat: no-repeat;
    background-position: center;
    box-shadow: 0 0 0 2px #fff;
}

/* --- Beautiful Custom Tooltip --- */
.fw-swatch[data-tooltip]::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    background-color: #222;
    color: #fff;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    line-height: 1.2;
    white-space: nowrap;
    z-index: 99;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s cubic-bezier(0.165, 0.84, 0.44, 1);
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.fw-swatch[data-tooltip]::after {
    content: '';
    position: absolute;
    bottom: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    border-width: 4px;
    border-style: solid;
    border-color: #222 transparent transparent transparent;
    z-index: 99;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s cubic-bezier(0.165, 0.84, 0.44, 1);
}
.fw-swatch[data-tooltip]:hover::before,
.fw-swatch[data-tooltip]:hover::after {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* Clear button styling */
.reset_variations {
    display: inline-block;
    margin-top: 10px;
    font-size: 13px;
    color: inherit;
    opacity: 0.6;
    text-decoration: underline;
}
.reset_variations:hover {
    opacity: 1;
}
