/**
 * Variation Swatches Styles
 *
 * @package Vime WooCommerce Widgets
 * @since 1.2.0
 */

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

.vime-swatches-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.vime-swatches-wrapper.inline {
    display: inline-flex;
}

.vime-swatches-wrapper.block {
    display: flex;
}

/* ============================================
   Base Swatch Styles
   ============================================ */

.vime-swatch {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    border: 2px solid transparent;
    box-sizing: border-box;
}

.vime-swatch:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.vime-swatch.selected {
    border-color: #000;
    box-shadow: 0 0 0 1px #000;
}

.vime-swatch.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    position: relative;
}

.vime-swatch.disabled::after {
    content: '';
    position: absolute;
    top: 50%;
    left: -5%;
    right: -5%;
    height: 2px;
    background: #ff0000;
    transform: rotate(-45deg);
}

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

.vime-swatch-small {
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
}

.vime-swatch-default {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
}

.vime-swatch-large {
    width: 52px;
    height: 52px;
    min-width: 52px;
    min-height: 52px;
}

/* Label swatches têm largura automática */
.vime-swatch-label.vime-swatch-small {
    width: auto;
    min-width: 40px;
    padding: 4px 12px;
    font-size: 12px;
}

.vime-swatch-label.vime-swatch-default {
    width: auto;
    min-width: 50px;
    padding: 8px 16px;
    font-size: 14px;
}

.vime-swatch-label.vime-swatch-large {
    width: auto;
    min-width: 60px;
    padding: 12px 20px;
    font-size: 16px;
}

/* ============================================
   Color Swatches
   ============================================ */

.vime-swatch-color {
    border-radius: 50%;
    border: 2px solid #e0e0e0;
}

.vime-swatch-color:hover {
    border-color: #333;
}

.vime-swatch-color.selected {
    border-color: #000;
    outline: 2px solid #000;
    outline-offset: 2px;
}

/* Para cores muito claras, adicionar borda visível */
.vime-swatch-color[style*="background-color: #fff"],
.vime-swatch-color[style*="background-color: #ffffff"],
.vime-swatch-color[style*="background-color: white"] {
    border-color: #ccc;
}

/* ============================================
   Image Swatches
   ============================================ */

.vime-swatch-image {
    border-radius: 4px;
    overflow: hidden;
    border: 2px solid #e0e0e0;
    background: #f8f8f8;
}

.vime-swatch-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.vime-swatch-image:hover {
    border-color: #333;
}

.vime-swatch-image.selected {
    border-color: #000;
    box-shadow: 0 0 0 2px #000;
}

/* ============================================
   Label Swatches
   ============================================ */

.vime-swatch-label {
    border-radius: 4px;
    border: 2px solid #e0e0e0;
    background: #fff;
    color: #333;
    font-weight: 500;
    text-align: center;
    white-space: nowrap;
    font-family: inherit;
    line-height: 1;
}

.vime-swatch-label:hover {
    border-color: #333;
    background: #f8f8f8;
}

.vime-swatch-label.selected {
    border-color: #000;
    background: #000;
    color: #fff;
}

/* ============================================
   Button Swatches
   ============================================ */

.vime-swatch-button {
    border-radius: 4px;
    border: 2px solid #e0e0e0;
    background: #fff;
    color: #333;
    font-weight: 500;
    text-align: center;
    white-space: nowrap;
    font-family: inherit;
    line-height: 1;
    height: auto;
}

.vime-swatch-button:hover {
    border-color: #333;
    background: #f8f8f8;
}

.vime-swatch-button.selected {
    border-color: #000;
    background: #000;
    color: #fff;
}

/* Button swatches têm largura automática */
.vime-swatch-button.vime-swatch-small {
    width: auto;
    min-width: 50px;
    padding: 6px 14px;
    font-size: 13px;
    height: auto;
}

.vime-swatch-button.vime-swatch-default {
    width: auto;
    min-width: 60px;
    padding: 10px 18px;
    font-size: 14px;
    height: auto;
}

.vime-swatch-button.vime-swatch-large {
    width: auto;
    min-width: 70px;
    padding: 14px 22px;
    font-size: 16px;
    height: auto;
}

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

.vime-swatch[data-tooltip] {
    position: relative;
}

.vime-swatch[data-tooltip]::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-8px);
    background: rgba(0, 0, 0, 0.9);
    color: #fff;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 13px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 1000;
    line-height: 1.4;
}

.vime-swatch[data-tooltip]::after {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-2px);
    border: 5px solid transparent;
    border-top-color: rgba(0, 0, 0, 0.9);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 1000;
}

.vime-swatch[data-tooltip]:hover::before,
.vime-swatch[data-tooltip]:hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ============================================
   Swatch Label (separado do swatch)
   ============================================ */

.vime-swatch-with-label {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.vime-swatch-with-label .vime-swatch-label-text {
    font-size: 13px;
    color: #666;
    text-align: center;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.vime-swatch-with-label .vime-swatch.selected + .vime-swatch-label-text {
    color: #000;
    font-weight: 600;
}

/* ============================================
   Attribute Group
   ============================================ */

.vime-attribute-group {
    margin-bottom: 20px;
}

.vime-attribute-group:last-child {
    margin-bottom: 0;
}

.vime-attribute-label {
    display: block;
    margin-bottom: 10px;
    font-weight: 600;
    font-size: 14px;
    color: #333;
}

.vime-attribute-label .selected-value {
    color: #666;
    font-weight: 400;
    margin-left: 8px;
}

/* ============================================
   Grid Layout
   ============================================ */

.vime-swatches-grid {
    display: grid;
    gap: 10px;
}

.vime-swatches-grid.cols-2 {
    grid-template-columns: repeat(2, 1fr);
}

.vime-swatches-grid.cols-3 {
    grid-template-columns: repeat(3, 1fr);
}

.vime-swatches-grid.cols-4 {
    grid-template-columns: repeat(4, 1fr);
}

.vime-swatches-grid.cols-5 {
    grid-template-columns: repeat(5, 1fr);
}

.vime-swatches-grid.cols-6 {
    grid-template-columns: repeat(6, 1fr);
}

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

@media (max-width: 768px) {
    .vime-swatches-grid.cols-6,
    .vime-swatches-grid.cols-5,
    .vime-swatches-grid.cols-4 {
        grid-template-columns: repeat(3, 1fr);
    }

    .vime-swatch-default {
        width: 36px;
        height: 36px;
        min-width: 36px;
        min-height: 36px;
    }

    .vime-swatch-large {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
    }
}

@media (max-width: 480px) {
    .vime-swatches-grid.cols-3 {
        grid-template-columns: repeat(2, 1fr);
    }

    .vime-swatch-small {
        width: 24px;
        height: 24px;
        min-width: 24px;
        min-height: 24px;
    }

    .vime-swatch-default {
        width: 32px;
        height: 32px;
        min-width: 32px;
        min-height: 32px;
    }

    .vime-swatch-large {
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
    }

    .vime-attribute-label {
        font-size: 13px;
    }
}

/* ============================================
   Archive/Loop Integration
   ============================================ */

.product .vime-swatches-wrapper {
    margin-top: 10px;
}

.product .vime-swatches-wrapper .vime-swatch {
    margin: 0;
}

/* ============================================
   Clear Selection
   ============================================ */

.vime-clear-selection {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    background: transparent;
    border: 1px solid #ddd;
    border-radius: 3px;
    color: #666;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-left: 10px;
}

.vime-clear-selection:hover {
    border-color: #999;
    color: #333;
}

.vime-clear-selection svg {
    width: 12px;
    height: 12px;
}

/* ============================================
   Loading State
   ============================================ */

.vime-swatches-wrapper.loading .vime-swatch {
    opacity: 0.5;
    pointer-events: none;
}

.vime-swatches-wrapper.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #333;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ============================================
   Accessibility
   ============================================ */

.vime-swatch:focus {
    outline: 2px solid #4A90E2;
    outline-offset: 2px;
}

.vime-swatch:focus:not(:focus-visible) {
    outline: none;
}

/* ============================================
   Integration with Variations Widget
   ============================================ */

.vime-variations-wrapper .vime-swatches-wrapper {
    margin-bottom: 15px;
}

.ts-buttons .vime-swatch {
    margin: 0;
}

/* Cor swatch no widget de variações */
.ts-swatch-color.vime-swatch-color {
    display: inline-flex;
}

/* ============================================
   Dark Mode Support (Optional)
   ============================================ */

@media (prefers-color-scheme: dark) {
    .vime-swatch-label {
        background: #2a2a2a;
        border-color: #444;
        color: #e0e0e0;
    }

    .vime-swatch-label:hover {
        border-color: #666;
        background: #333;
    }

    .vime-swatch-label.selected {
        background: #fff;
        border-color: #fff;
        color: #000;
    }

    .vime-attribute-label {
        color: #e0e0e0;
    }

    .vime-attribute-label .selected-value {
        color: #999;
    }
}

/* ============================================
   WooCommerce Native Form Integration
   ============================================ */

.vime-wc-variation-swatches-wrapper {
    margin-bottom: 20px;
}

.vime-variation-label {
    display: block;
    margin-bottom: 12px;
    font-weight: 600;
    font-size: 14px;
    color: #333;
}

.vime-variation-label .vime-selected-value {
    font-weight: 400;
    color: #666;
    margin-left: 8px;
}

.vime-swatches-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 8px;
}

.vime-swatch-option {
    cursor: pointer;
    transition: all 0.3s ease;
}

.vime-swatch-option.selected .vime-wc-swatch,
.vime-swatch-option.selected .vime-swatch {
    border-color: #000;
    box-shadow: 0 0 0 2px #000;
}

.vime-hidden-select {
    position: absolute !important;
    left: -9999px !important;
    width: 1px !important;
    height: 1px !important;
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
}

/* Integration with WooCommerce variations form */
.variations .vime-wc-variation-swatches-wrapper {
    display: block;
    width: 100%;
}

.variations tbody tr td.value .vime-wc-variation-swatches-wrapper {
    width: 100%;
}

/* Ensure swatches work in table layout */
table.variations td.value {
    display: block;
    width: 100%;
}

table.variations .vime-swatches-container {
    width: 100%;
}
