/* ══ Modulo Commerce — Swatches CSS (5 styles) ══ */

:root {
    --vpe-accent: #c47c32;
}

/* ── Conteneur ── */
.vpe-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 8px 0 4px;
    align-items: center;
}

/* Masquer le select natif WooCommerce */
.variations td.value > select,
.variations .value select {
    position: absolute !important;
    opacity: 0 !important;
    pointer-events: none !important;
    height: 0 !important;
    width: 0 !important;
    /* WooCommerce impose un min-width (75 %) : sans cela le select invisible
       déborde à droite et crée un défilement horizontal. */
    min-width: 0 !important;
    max-width: 0 !important;
    overflow: hidden !important;
}

/* Nom sélectionné */
.vpe-current-value {
    display: inline-block;
    font-size: 12px;
    color: #555;
    margin-left: 4px;
    font-style: italic;
    align-self: center;
}

/* ── Base swatch ── */
.vpe-swatch {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--vpe-size);
    height: var(--vpe-size);
    padding: 0;
    border: 2px solid #e0e0e0;
    background: #fff;
    cursor: pointer;
    /* Uniquement transform + opacity : propriétés composées, zéro reflow, zéro CLS */
    transition: transform 0.15s ease, opacity 0.15s ease, box-shadow 0.15s ease;
    box-sizing: border-box;
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    vertical-align: middle;
}

.vpe-swatch:hover { border-color: #888; }
.vpe-swatch:focus { outline: 2px solid var(--vpe-accent); outline-offset: 2px; }

.vpe-swatch.is-selected {
    border-color: var(--vpe-accent);
    box-shadow: 0 0 0 1px var(--vpe-accent);
}

.vpe-swatch.is-disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}
.vpe-swatch.is-disabled::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(
        to bottom right,
        transparent calc(50% - 1px),
        rgba(180, 30, 30, 0.55) calc(50% - 1px),
        rgba(180, 30, 30, 0.55) calc(50% + 1px),
        transparent calc(50% + 1px)
    );
    pointer-events: none;
}

/* Couleur */
.vpe-swatch.has-color { background-color: var(--vpe-color); }

/* Image */
.vpe-swatch.has-image {
    background-image: var(--vpe-bg);
    background-size: cover;
    background-position: center;
}

/* Dégradé bi-ton */
.vpe-swatch.has-gradient {
    background: linear-gradient(135deg, var(--vpe-color) 50%, var(--vpe-color-2) 50%);
}
.vpe-swatch.has-gradient .vpe-swatch-dot {
    background: linear-gradient(135deg, var(--vpe-color) 50%, var(--vpe-color-2) 50%);
}

/* ── Badge stock ── */
.vpe-stock-badge {
    position: absolute;
    bottom: -2px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 9px;
    font-weight: 700;
    line-height: 1;
    padding: 2px 4px;
    border-radius: 3px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 5;
}
.vpe-stock-badge--low { background: #f59e0b; color: #fff; }
.vpe-stock-badge--out { background: #ef4444; color: #fff; }
.vpe-style-label .vpe-stock-badge,
.vpe-style-pill .vpe-stock-badge,
.vpe-swatch.has-label .vpe-stock-badge {
    position: static;
    transform: none;
    display: inline-block;
    margin-left: 5px;
    vertical-align: middle;
    font-size: 9px;
    line-height: 1;
    padding: 2px 5px;
    border-radius: 3px;
}

/* ── Tooltip CSS ── */
.vpe-style-circle .vpe-swatch[title]::before,
.vpe-style-rounded .vpe-swatch[title]::before,
.vpe-style-image_circle .vpe-swatch[title]::before {
    content: attr(title);
    position: absolute;
    bottom: calc(100% + 7px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--vpe-accent);
    color: #fff;
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 20;
}
.vpe-style-circle .vpe-swatch:hover[title]::before,
.vpe-style-rounded .vpe-swatch:hover[title]::before,
.vpe-style-image_circle .vpe-swatch:hover[title]::before {
    opacity: 1;
}

/* ── Style 1 : Rond ── */
.vpe-style-circle .vpe-swatch,
.vpe-style-image_circle .vpe-swatch { border-radius: 50%; }

/* ── Style 2 : Carré arrondi ── */
.vpe-style-rounded .vpe-swatch { border-radius: 6px; }

/* ── Style 3 : Image ronde ── */
/* (hérite de circle) */

/* ── Style 4 : Bouton texte ── */
.vpe-style-label .vpe-swatch {
    width: auto;
    height: auto;
    padding: 6px 14px;
    border-radius: 4px;
    font-size: 14px;
    line-height: 1.4;
    overflow: visible;
}
.vpe-style-label .vpe-swatch.is-selected {
    background: var(--vpe-accent);
    color: #fff;
    border-color: var(--vpe-accent);
}
.vpe-swatch.has-label {
    width: auto;
    height: auto;
    padding: 6px 14px;
    border-radius: 4px;
    font-size: 13px;
    overflow: visible;
}
.vpe-swatch.has-label.is-selected {
    background: var(--vpe-accent);
    color: #fff;
}

/* ── Style 5 : Pilule ── */
.vpe-style-pill .vpe-swatch {
    width: auto;
    height: auto;
    padding: 6px 14px 6px 38px;
    border-radius: 50px;
    font-size: 14px;
    line-height: 1.4;
    overflow: visible;
}
.vpe-style-pill .vpe-swatch-dot {
    position: absolute;
    left: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background-color: var(--vpe-color, #ddd);
    border: 1px solid rgba(0,0,0,.1);
}
.vpe-style-pill .vpe-swatch.is-selected {
    background: #f5f5f5;
    border-color: var(--vpe-accent);
}

/* ── Texte masqué (accessibilité) ── */
.vpe-style-circle .vpe-swatch-text,
.vpe-style-rounded .vpe-swatch-text,
.vpe-style-image_circle .vpe-swatch-text {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    border: 0;
}
.vpe-swatch.has-label .vpe-swatch-text,
.vpe-style-label .vpe-swatch-text,
.vpe-style-pill .vpe-swatch-text {
    position: static;
    width: auto; height: auto;
    margin: 0; overflow: visible; clip: auto;
}

/* ── Archives ── */
.vpe-swatches--archive {
    margin: 6px 0 0;
    gap: 6px;
    pointer-events: none;
}
.vpe-swatches--archive.vpe-swatches--left   { justify-content: flex-start; }
.vpe-swatches--archive.vpe-swatches--center { justify-content: center; }
.vpe-swatches--archive.vpe-swatches--right  { justify-content: flex-end; }
.vpe-swatches--archive .vpe-swatch--archive {
    pointer-events: auto;
    border-width: 1px;
    transition: transform 0.12s ease, border-color 0.12s ease;
}
.vpe-swatches--archive .vpe-swatch--archive:hover {
    transform: scale(1.12);
    border-color: var(--vpe-accent);
    z-index: 1;
}
.vpe-swatches--archive .vpe-swatch--archive::before { display: none; }

/* ── Stock sur les cartes (boutique, catégories) ──
   Format compact : une pastille de carte est petite et voisine des autres.
   Épuisée : barrée et atténuée (reste cliquable, vers la fiche) ; stock faible :
   bulle orange avec la quantité. Texte complet dans l'infobulle. */
.vpe-swatches--archive .vpe-swatch--archive { position: relative; }
.vpe-swatches--archive .vpe-swatch--archive.is-out { opacity: 0.45; }
/* La pastille coupe ce qui dépasse (overflow: hidden) : la bulle doit pouvoir déborder.
   Le fond (couleur, image) suit toujours l'arrondi de la bordure. */
.vpe-swatches--archive .vpe-swatch--archive.is-low { overflow: visible; }
.vpe-swatches--archive:has(.is-low) { padding-top: 6px; padding-right: 6px; }
.vpe-swatches--archive .vpe-swatch--archive.is-out::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(
        to bottom right,
        transparent calc(50% - 1px),
        rgba(180, 30, 30, 0.7) calc(50% - 1px),
        rgba(180, 30, 30, 0.7) calc(50% + 1px),
        transparent calc(50% + 1px)
    );
    pointer-events: none;
}
.vpe-stock-dot {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 15px;
    height: 15px;
    padding: 0 3px;
    box-sizing: border-box;
    border-radius: 8px;
    background: #f59e0b;
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    line-height: 15px;
    text-align: center;
    pointer-events: none;
    z-index: 2;
}
