/**
 * CC Variant Viewer — Cerrajería Central
 * Componente propio: visor de variantes + carrusel de swatches.
 * Desacoplado de Elementor y de Astra. Depende únicamente de WooCommerce.
 *
 * @package Cerrajeria_Central_Child
 */

/* === Contenedor principal del visor de variantes === */
#cc-variant-viewer {
    width: 100%;
    max-width: 520px;
    margin: 0 auto 16px auto;
    font-family: inherit;
    box-sizing: border-box;
    touch-action: pan-x pan-y;
}

/* === Imagen principal grande === */
#cc-main-img-wrap {
    width: 100%;
    aspect-ratio: 1 / 1;
    background: #f8f8f8;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}
#cc-main-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    transition: opacity 0.2s ease;
}
#cc-main-img.cc-loading {
    opacity: 0.4;
}

/* === Etiqueta variante activa === */
#cc-variant-label {
    font-size: 13px;
    color: #555;
    margin-bottom: 8px;
    line-height: 1.4;
}
#cc-variant-label strong {
    color: #F97316;
    font-weight: 700;
}

/* === Tira de swatches — scroll horizontal nativo === */
#cc-swatches-strip {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    width: 100%;
    overflow-x: scroll;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
    overscroll-behavior-x: contain;
    padding: 4px 0 10px 0;
    scrollbar-width: thin;
    scrollbar-color: #F97316 #eee;
    user-select: none;
    -webkit-user-select: none;
    box-sizing: border-box;
    -ms-overflow-style: -ms-autohiding-scrollbar;
    will-change: scroll-position;
}
#cc-swatches-strip:active {
    cursor: grabbing;
}
#cc-swatches-strip::-webkit-scrollbar {
    height: 4px;
}
#cc-swatches-strip::-webkit-scrollbar-track {
    background: #eee;
    border-radius: 4px;
}
#cc-swatches-strip::-webkit-scrollbar-thumb {
    background: #F97316;
    border-radius: 4px;
}

/* === Swatch individual === */
.cc-sv-item {
    flex: 0 0 auto;
    width: 68px;
    height: 68px;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #e0e0e0;
    cursor: pointer;
    position: relative;
    transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
    background: #fff;
    touch-action: pan-x;
    -webkit-tap-highlight-color: transparent;
}
.cc-sv-item:hover {
    border-color: #F97316;
    transform: scale(1.06);
    box-shadow: 0 2px 8px rgba(249, 115, 22, 0.3);
}
.cc-sv-item.cc-sv-active {
    border-color: #F97316;
    box-shadow: 0 0 0 2px #F97316;
}
.cc-sv-item.cc-sv-active::after {
    content: '';
    position: absolute;
    top: 4px;
    right: 4px;
    width: 10px;
    height: 10px;
    background: #F97316;
    border-radius: 50%;
    border: 1.5px solid #fff;
    z-index: 2;
}
.cc-sv-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    pointer-events: none;
}
.cc-sv-fallback {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    text-align: center;
    color: #555;
    padding: 4px;
    background: #f5f5f5;
    line-height: 1.3;
    word-break: break-word;
    pointer-events: none;
}

/* === Móvil (<= 768px) === */
@media (max-width: 768px) {
    #cc-variant-viewer {
        max-width: 100%;
        margin: 0 0 10px 0;
    }
    #cc-main-img-wrap {
        aspect-ratio: 3 / 2;
        border-radius: 8px;
        margin-bottom: 8px;
    }
    #cc-variant-label {
        font-size: 12px;
        margin-bottom: 6px;
    }
    .cc-sv-item {
        width: 56px;
        height: 56px;
    }
    #cc-swatches-strip {
        overflow-x: scroll;
        overflow-y: hidden;
        touch-action: pan-x;
        -webkit-overflow-scrolling: touch;
        gap: 6px;
        padding: 3px 0 8px 0;
        pointer-events: auto;
    }
}

/* === Escritorio (>= 769px): fila única + scroll horizontal + etiqueta bajo la imagen === */
@media (min-width: 769px) {
    #cc-variant-viewer {
        max-width: 460px;
    }
    #cc-swatches-strip {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        gap: 8px;
        padding: 4px 0 14px;
        cursor: grab;
        -webkit-overflow-scrolling: touch;
    }
    #cc-swatches-strip:active {
        cursor: grabbing;
    }
    .cc-sv-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        flex-shrink: 0;
        overflow: hidden;
        width: 82px;
        height: auto;
        min-height: 82px;
        padding: 6px 6px 5px;
        border-radius: 10px;
    }
    .cc-sv-img {
        width: 62px;
        height: 62px;
        border-radius: 6px;
        object-fit: contain;
        display: block;
        flex-shrink: 0;
    }
    .cc-sv-label {
        display: block;
        font-size: 10px;
        line-height: 1.2;
        text-align: center;
        max-width: 78px;
        white-space: normal;
        overflow: hidden;
        text-overflow: ellipsis;
        margin-top: 4px;
    }
    #cc-variant-name {
        text-transform: uppercase;
    }
}
