/* Pastille et plaquette de finition (swatch.php, plaquette de la fiche, finishSwatch() de cart.js) :
   image de l'API s'il y en a une (swatch_image_url pour la pastille, image_url pour la plaquette),
   sinon la couleur swatch_hex */
.finish-swatch {
    background: linear-gradient(135deg, rgb(255 255 255 / .45), rgb(0 0 0 / .08)), var(--swatch, #DCE1E6);

    &[data-ral="1"] {
        background: conic-gradient(#74BD5B, #02469A, #C62828, #F2C94C, #74BD5B);
    }

    /* Le visuel par-dessus la couleur : si l'image ne charge pas, la pastille garde sa couleur */
    &[data-image] {
        background: var(--swatch-image) center / cover no-repeat, var(--swatch, #DCE1E6);
    }
}

/* Jauge de stock : trois crans, du bas vers le haut */
.stock-gauge {
    display: inline-flex;
    flex-direction: column-reverse;
    gap: 2px;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 20px;
    height: 40px;
    padding: 3px;
    background: var(--color-white);
    border: 1px solid var(--color-grey-light);
    border-radius: 2px;

    i {
        width: 14px;
        height: 10px;
        background: var(--color-grey-lighter);
        border-radius: 2px;
    }

    &:not([data-level="0"]) i:nth-child(1) { background: var(--color-stock-medium); }
    &[data-level="2"] i:nth-child(2),
    &[data-level="3"] i:nth-child(2) { background: var(--color-green); }
    &[data-level="3"] i:nth-child(3) { background: var(--color-success); }
}

/* Grille d'une gamme : tableau en desktop */
.range-matrix {
    background: var(--color-white);

    table {
        width: 100%;
        min-width: 1100px;
        table-layout: fixed;
        border-collapse: collapse;
    }

    thead th {
        height: 64px;
        padding: 8px;
        background: var(--color-blue-light);
        font-size: 12px;
        line-height: 1.5;
        font-weight: 400;
        color: var(--color-grey);
    }

    .range-matrix__col-name,
    .range-matrix__col-ref {
        font-size: 16px;
        line-height: 20px;
        font-weight: 500;
        color: var(--color-anthracite);
        text-align: left;
    }

    .range-matrix__col-name { width: 130px; }
    .range-matrix__col-ref { width: 104px; }

    tbody th,
    .range-matrix__ref {
        height: 80px;
        padding: 8px;
        font-size: 14px;
        line-height: 22px;
        font-weight: 400;
        text-align: left;
    }
}

.range-matrix__scroll {
    overflow-x: auto;
}

.range-matrix__toggle,
.range-matrix__finish,
.range-matrix__tip {
    display: none;
}

.range-matrix__cell {
    position: relative;
    height: 80px;
    padding: 4px 28px 4px 4px;
    border: 1px solid var(--color-grey-light);
    background: var(--color-white);
    font-size: 14px;
    line-height: 18px;
    text-align: center;

    &[data-state="in_stock"] {
        background: var(--color-stock-low);
    }

    .stock-gauge {
        position: absolute;
        top: 50%;
        right: 5px;
        transform: translateY(-50%);
    }

    .idalu-offer {
        display: block;
        margin-top: 4px;
        text-wrap: balance;
    }

    &:not([data-state="in_stock"]) .idalu-offer {
        color: var(--color-grey);
    }

    &[data-state="loading"] .idalu-offer {
        min-height: 18px;
    }
}

/* Détail du stock écrit par range-matrix.js : au survol (title) en desktop, sous le prix en mobile */
.range-matrix__stock {
    display: none;
}

.range-matrix__qty {
    display: inline-flex;
    align-items: center;
    gap: 4px;

    input {
        width: 56px;
        height: 28px;
        background: var(--color-white);
        border: 1px solid var(--color-grey-light);
        text-align: center;
        appearance: textfield;

        &::-webkit-inner-spin-button,
        &::-webkit-outer-spin-button {
            appearance: none;
            margin: 0;
        }

        &:disabled {
            color: var(--color-grey);
            background: var(--color-grey-lighter);
        }
    }
}

.range-matrix__count,
.range-matrix__note {
    display: inline;
}

.range-matrix__note::before {
    content: " · ";
}

.range-matrix__total {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 24px;
    background: var(--color-blue-light);
}

/* Mobile : références dépliables, récapitulatif toujours accessible */
@media screen and (max-width: 1023px) {
    .range-matrix {
        background: transparent;

        table {
            min-width: 0;
        }

        table, tbody, tr, tbody th, td {
            display: block;
            width: 100%;
        }

        thead {
            position: absolute;
            width: 1px;
            height: 1px;
            overflow: hidden;
            clip-path: inset(50%);
        }

        tbody tr {
            margin-bottom: 16px;
            overflow: hidden;
            background: var(--color-white);
            border: 1px solid var(--color-grey-light);
            border-radius: 4px;
        }

        tbody th {
            height: auto;
            padding: 0;
        }
    }

    .range-matrix__scroll {
        overflow: visible;
    }

    .range-matrix__label,
    .range-matrix .range-matrix__ref {
        display: none;
    }

    tr.is-open .range-matrix__tip {
        display: block;
        padding: 0 16px 8px;
    }

    .range-matrix__toggle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        padding: 16px;
        cursor: pointer;
        text-align: left;
    }

    .range-matrix__toggle-icon {
        position: relative;
        width: 12px;
        height: 2px;
        background: var(--color-blue);

        &::after {
            content: "";
            position: absolute;
            inset: 0;
            background: var(--color-blue);
            transform: rotate(90deg);
            transition: transform .2s;
        }
    }

    tr.is-open .range-matrix__toggle-icon::after {
        transform: rotate(0);
    }

    .range-matrix tbody tr:not(.is-open) .range-matrix__cell {
        display: none;
    }

    .range-matrix tbody .range-matrix__cell {
        display: grid;
        grid-template-columns: 1fr auto auto;
        align-items: center;
        gap: 4px 12px;
        height: auto;
        padding: 12px 16px;
        border-width: 1px 0 0;
        text-align: left;

        .stock-gauge {
            position: static;
            grid-column: 3;
            grid-row: 1 / span 3;
            transform: none;
        }

        .idalu-offer {
            grid-column: 1;
            grid-row: 2;
            margin-top: 0;
            white-space: normal;
        }

        .range-matrix__stock {
            display: block;
            grid-column: 1;
            grid-row: 3;
            font-size: 12px;
            line-height: 18px;
            color: var(--color-grey);

            &:empty {
                display: none;
            }
        }

        .range-matrix__qty {
            grid-column: 2;
            grid-row: 1 / span 3;
        }
    }

    .range-matrix__finish {
        display: flex;
        align-items: center;
        gap: 8px;
        grid-column: 1;
        grid-row: 1;
        font-size: 14px;
        color: var(--color-grey);
    }

    .range-matrix__qty input {
        width: 88px;
        height: 44px;
    }

    /* Récapitulatif collé au bas de l'écran : sélection et total, bouton pleine largeur, mention dessous */
    .range-matrix__total {
        position: sticky;
        bottom: 0;
        z-index: 2;
        display: grid;
        grid-template-columns: 1fr auto;
        gap: 8px 16px;
        padding: 12px 16px;
        background: var(--color-white);
        border-top: 1px solid var(--color-grey-light);
        box-shadow: 0 -4px 12px rgb(0 0 0 / .06);

        .range-matrix__summary { display: contents; }
        .range-matrix__amount-label { display: none; }
        .range-matrix__count { grid-column: 1; grid-row: 1; align-self: center; }
        .range-matrix__amount { grid-column: 2; grid-row: 1; }
        .range-matrix__note { grid-column: 1 / -1; grid-row: 3; display: block; font-size: 12px; line-height: 18px; }
        .range-matrix__note::before { content: none; }
        .range-matrix__note::first-letter { text-transform: uppercase; }
        .range-matrix__add { grid-column: 1 / -1; grid-row: 2; width: 100%; min-height: 48px; }
    }
}

/* Bulle de commentaire d'une référence (comment-tip.js) */
.comment-tip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    margin-left: 6px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--color-blue);
    vertical-align: middle;
    cursor: help;

    svg {
        width: 16px;
        height: 16px;
    }

    &:focus-visible {
        outline: 2px solid var(--color-blue);
        outline-offset: 2px;
    }
}

.comment-tip__bubble {
    position: fixed;
    z-index: 200;
    max-width: min(320px, calc(100vw - 16px));
    padding: 8px 12px;
    background: var(--color-anthracite);
    color: var(--color-white);
    font-size: 14px;
    line-height: 20px;
    pointer-events: none;

    &[hidden] {
        display: none;
    }
}
