/* ============================================================
   BAF Color Swatches v2 — color-swatches.css
   /wp-content/themes/rey-child/assets/color-swatches.css
   ============================================================ */

:root {
    --baf-teal:        #13731f;
    --baf-teal-dark:   #0f5a18;
    --baf-teal-light:  #e8f5ea;
    --baf-red:         #e04444;
    --baf-border:      #e2e8e6;
    --baf-bg:          #f7faf9;
    --baf-text:        #1a2421;
    --baf-text-muted:  #6b7c79;
    --baf-radius:      8px;
    --baf-shadow:      0 4px 20px rgba(19,115,31,.12);
}

/* ── Wrapper principale ───────────────────────────────────── */
.baf-product-swatches {
    margin-top: 24px;
}

/* ── Header ───────────────────────────────────────────────── */
.baf-swatches-header {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    align-items: center;
    gap: 2px 16px;
    margin-bottom: 14px;
}

.baf-swatches-header__count {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .06em;
    color: var(--baf-text);
    text-transform: uppercase;
    grid-column: 1;
    grid-row: 1;
}

.baf-swatches-header__hint {
    font-size: 12px;
    color: var(--baf-text-muted);
    grid-column: 1;
    grid-row: 2;
}

.baf-swatches-filter {
    grid-column: 2;
    grid-row: 1 / 3;
    align-self: center;
}

.baf-swatches-filter__input {
    border: 1px solid var(--baf-border);
    border-radius: 20px;
    padding: 6px 14px 6px 32px;
    font-size: 13px;
    color: var(--baf-text);
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b7c79' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E") no-repeat 10px center;
    outline: none;
    width: 190px;
    transition: border-color .2s, box-shadow .2s;
}

.baf-swatches-filter__input:focus {
    border-color: var(--baf-teal);
    box-shadow: 0 0 0 3px rgba(19,115,31,.1);
}

/* ── Griglia swatches ─────────────────────────────────────── */
.baf-swatches-wrapper {
    position: relative;
}

.baf-swatches-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 6px;
    margin-bottom: 4px;
}

/* ── Singolo swatch ───────────────────────────────────────── */
.baf-swatch {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 7px 4px;
    border: 2px solid transparent;
    border-radius: var(--baf-radius);
    cursor: pointer;
    transition: border-color .18s, background .18s, transform .15s;
    background: transparent;
    user-select: none;
}

.baf-swatch:hover {
    background: var(--baf-teal-light);
    border-color: var(--baf-teal);
    transform: translateY(-1px);
}

.baf-swatch.is-active {
    background: var(--baf-teal-light);
    border-color: var(--baf-teal);
}

.baf-swatch.is-hidden {
    display: none;
}

/* Pallino — versione colore hex */
.baf-swatch__dot {
    display: block;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 2px solid rgba(0,0,0,.08);
    box-shadow: 0 2px 6px rgba(0,0,0,.15);
    flex-shrink: 0;
    transition: transform .15s;
}

/* Pallino — versione immagine (quadrato arrotondato come nello screenshot) */
.baf-swatch__dot--img {
    border-radius: 6px;
    width: 48px;
    height: 48px;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    border: 1px solid rgba(0,0,0,.08);
    box-shadow: 0 2px 6px rgba(0,0,0,.1);
}

.baf-swatch:hover .baf-swatch__dot,
.baf-swatch:hover .baf-swatch__dot--img,
.baf-swatch.is-active .baf-swatch__dot,
.baf-swatch.is-active .baf-swatch__dot--img {
    transform: scale(1.08);
    box-shadow: 0 3px 10px rgba(0,0,0,.2);
}

/* Nome colore */
.baf-swatch__name {
    font-size: 11px;
    text-align: center;
    color: var(--baf-text);
    line-height: 1.3;
    word-break: break-word;
    hyphens: auto;
    max-width: 76px;
}

/* ── Pannello inline (si inserisce dentro la griglia dopo la riga) ── */
.baf-inline-panel {
    /* Occupa tutta la larghezza della griglia saltando tutte le colonne */
    grid-column: 1 / -1;
    margin: 4px 0 8px;
    border-radius: var(--baf-radius);
    overflow: hidden;
    box-shadow: var(--baf-shadow);
    background: #fff;
    border: 1px solid var(--baf-border);
}

/* ── Pannello formati (legacy, non più usato ma tenuto per compatibilità) ── */
.baf-formats-panel {
    margin-top: 6px;
    border-radius: var(--baf-radius);
    overflow: hidden;
    box-shadow: var(--baf-shadow);
    background: #fff;
    border: 1px solid var(--baf-border);
    animation: bafSlideDown .2s ease-out;
}

@keyframes bafSlideDown {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Intestazione pannello */
.baf-formats-panel__color-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--baf-bg);
    border-bottom: 1px solid var(--baf-border);
    font-size: 13px;
    color: var(--baf-text);
}

.baf-formats-panel__close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    color: var(--baf-text-muted);
    padding: 0 0 0 8px;
    line-height: 1;
    transition: color .15s;
}

.baf-formats-panel__close:hover {
    color: var(--baf-red);
}

/* Loading bar */
.baf-formats-panel--loading::after,
.baf-inline-panel.baf-formats-panel--loading::after {
    content: '';
    display: block;
    height: 3px;
    background: linear-gradient(90deg, var(--baf-teal), var(--baf-teal-light), var(--baf-teal));
    background-size: 200% 100%;
    animation: bafLoading 1s infinite;
}

@keyframes bafLoading {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ── Tabella formati ──────────────────────────────────────── */
.baf-formats-table__header {
    display: grid;
    grid-template-columns: 90px 1fr 1fr 1fr 120px 110px;
    background: var(--baf-teal);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.baf-formats-table__header span {
    padding: 10px 12px;
}

.baf-formats-table__row {
    display: grid;
    grid-template-columns: 90px 1fr 1fr 1fr 120px 110px;
    align-items: center;
    border-bottom: 1px solid var(--baf-border);
    transition: background .15s;
}

.baf-formats-table__row:last-child {
    border-bottom: none;
}

.baf-formats-table__row:hover {
    background: var(--baf-bg);
}

.baf-formats-table__row > span {
    padding: 10px 12px;
    font-size: 13px;
    color: var(--baf-text);
}

.baf-formats-table__formato {
    font-weight: 700 !important;
}

.baf-formats-table__price del {
    color: var(--baf-text-muted);
    font-size: 12px;
    text-decoration: line-through;
    display: block;
}

.baf-formats-table__price ins {
    text-decoration: none;
    color: var(--baf-red);
    font-weight: 700;
}

.baf-formats-table__sku {
    font-size: 11px !important;
    color: var(--baf-text-muted) !important;
    font-family: monospace;
}

.baf-stock {
    display: inline-block;
    font-size: 12px;
    font-weight: 500;
    border-radius: 4px;
    padding: 3px 7px;
}

.baf-stock--in  { background: #e6f4ea; color: #1e7e34; }
.baf-stock--out { background: #fff3e0; color: #e65100; }

/* ── Quantità ─────────────────────────────────────────────── */
.baf-formats-table__qty {
    display: flex !important;
    align-items: center;
    gap: 4px;
    padding: 8px 12px !important;
}

.baf-qty__btn {
    width: 26px;
    height: 26px;
    border: 1px solid var(--baf-border);
    background: #fff;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    color: var(--baf-text);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .15s, border-color .15s, color .15s;
}

.baf-qty__btn:hover {
    background: var(--baf-teal-light);
    border-color: var(--baf-teal);
    color: var(--baf-teal);
}

.baf-qty__input {
    width: 40px !important;
    height: 26px !important;
    padding: 0 !important;
    text-align: center;
    border: 1px solid var(--baf-border);
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
    color: var(--baf-text) !important;
    -moz-appearance: textfield;
    box-sizing: border-box;
}

.baf-qty__input::-webkit-outer-spin-button,
.baf-qty__input::-webkit-inner-spin-button {
    -webkit-appearance: none;
}

/* ── Bottone Aggiungi ─────────────────────────────────────── */
.baf-formats-table__action {
    padding: 8px 12px !important;
}

.baf-add-to-cart {
    background: transparent;
    color: #000 !important;
    border: none;
    border-radius: 6px;
    padding: 7px 10px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    letter-spacing: .03em;
    text-transform: uppercase;
    width: 100%;
    transition: color .18s;
}

.baf-add-to-cart:hover {
    background: transparent;
    color: var(--baf-teal) !important;
}

.baf-add-to-cart:active { transform: none; }

.baf-add-to-cart.is-added {
    background: transparent;
    color: var(--baf-teal) !important;
}

/* ── Toast ────────────────────────────────────────────────── */
.baf-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--baf-teal);
    color: #fff;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 6px 24px rgba(0,0,0,.2);
    z-index: 99999;
    max-width: 300px;
    animation: bafToastIn .25s ease-out;
}

.baf-toast.is-error { background: var(--baf-red); }

@keyframes bafToastIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Riga esaurita ───────────────────────────────────────── */
.baf-formats-table__row.is-out-of-stock {
    opacity: .5;
    pointer-events: none;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 900px) {
    .baf-formats-table__header,
    .baf-formats-table__row {
        grid-template-columns: 80px 1fr 100px 110px;
    }
    .baf-formats-table__header span:nth-child(3),
    .baf-formats-table__row .baf-formats-table__sku { display: none; }
}

@media (max-width: 600px) {
    .baf-swatches-grid {
        grid-template-columns: repeat(auto-fill, minmax(62px, 1fr));
    }

    .baf-swatches-filter__input { width: 130px; }

    /* ── 4 celle in una riga: Nome | Prezzo | Qty | Aggiungi ── */

    /* Header: 4 colonne uguali */
    .baf-formats-table__header {
        display: grid;
        grid-template-columns: 2fr 1fr 1fr 1fr;
    }

    /* Nascondi le colonne extra nell'header (Riferimento, Disponibilità) */
    .baf-formats-table__header span:nth-child(3),
    .baf-formats-table__header span:nth-child(4) {
        display: none;
    }

    /* Intestazione: font piccolo */
    .baf-formats-table__header span {
        padding: 8px 6px;
        font-size: 10px;
    }

    /* Row: flexbox con 4 celle esatte — ignora le celle nascoste */
    .baf-formats-table__row {
        display: flex;
        flex-wrap: nowrap;
        align-items: center;
    }

    /* Nascondi celle non necessarie nella row */
    .baf-formats-table__sku,
    .baf-formats-table__stock,
    .baf-formats-table__reference { display: none !important; }

    /* Nome: occupa lo spazio disponibile */
    .baf-formats-table__formato {
        flex: 2;
        font-size: 12px !important;
        padding: 8px 6px !important;
        min-width: 0;
        word-break: break-word;
    }

    /* Prezzo: fisso */
    .baf-formats-table__price {
        flex: 1;
        font-size: 12px;
        padding: 8px 4px !important;
        white-space: nowrap;
        text-align: center;
    }

    /* Qty: fisso */
    .baf-formats-table__qty {
        flex: 1;
        gap: 2px !important;
        padding: 6px 4px !important;
        justify-content: center;
    }

    .baf-qty__btn {
        width: 26px;
        height: 26px;
        font-size: 15px;
    }

    .baf-qty__input {
        width: 28px !important;
        height: 26px !important;
        padding: 0 !important;
        font-size: 12px !important;
        color: var(--baf-text) !important;
        box-sizing: border-box;
    }

    /* Aggiungi: fisso */
    .baf-formats-table__action {
        flex: 1;
        padding: 6px 4px !important;
    }

    .baf-add-to-cart {
        padding: 7px 4px;
        font-size: 11px;
        white-space: nowrap;
        width: 100%;
        min-height: 36px;
    }
}