/*
 * DriveOnly — galerie d'images produit (lightbox #product-modal)
 * Markup : templates/catalog/_partials/product-images-modal.tpl
 * Logique : assets/js/product-gallery.js
 */

#product-modal.dol-gallery {
    --dol-accent: #e31d27;
    --dol-ink: #141414;
    --dol-muted: #6b6f76;
    --dol-line: #ececec;
    --dol-soft: #f3f4f6;
    --dol-soft-hover: #e6e7ea;
    --dol-radius: 18px;
    z-index: 100001;
    /* calé sur le viewport, même si un contenu de la page déborde en largeur sur mobile */
    right: auto;
    bottom: auto;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    padding: 0 !important;
    overflow: hidden !important;
    overscroll-behavior: contain;
    font-family: inherit;
}

#product-modal.dol-gallery:focus {
    outline: 0;
}

/* Fond assombri + flou (le backdrop Bootstrap est un frère du modal) */
body.dol-open .modal-backdrop {
    z-index: 100000;
    background: rgba(12, 13, 16, .78);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}

body.dol-open .modal-backdrop.in {
    opacity: 1;
}

/* Cadre */
#product-modal.dol-gallery .modal-dialog {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: none;
    height: 100%;
    margin: 0;
    padding: 28px;
    pointer-events: none; /* un clic hors du panneau atteint .modal => fermeture Bootstrap */
}

#product-modal.dol-gallery.fade .modal-dialog {
    opacity: 0;
    -webkit-transform: scale(.96);
    transform: scale(.96);
    transition: opacity .2s ease, transform .28s cubic-bezier(.2, .8, .2, 1);
}

#product-modal.dol-gallery.in .modal-dialog {
    opacity: 1;
    -webkit-transform: none;
    transform: none;
}

#product-modal .dol-gallery__panel {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 1180px;
    height: 100%;
    max-height: 880px;
    overflow: hidden;
    background: #fff;
    border: 0;
    border-radius: var(--dol-radius);
    box-shadow: 0 30px 80px rgba(0, 0, 0, .45);
    pointer-events: auto;
}

/* Barre du haut */
#product-modal .dol-gallery__bar {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 0 0 auto;
    padding: 12px 14px 12px 22px;
    border-bottom: 1px solid var(--dol-line);
}

#product-modal .dol-gallery__counter {
    flex: 0 0 auto;
    padding: 5px 12px;
    border-radius: 999px;
    background: var(--dol-soft);
    color: var(--dol-ink);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.4;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

#product-modal .dol-gallery__title {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    color: var(--dol-ink);
    font-size: 15px;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
    text-overflow: ellipsis;
}

#product-modal .dol-gallery__tools {
    display: flex;
    flex: 0 0 auto;
    gap: 6px;
}

#product-modal .dol-gallery__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--dol-soft);
    color: var(--dol-ink);
    cursor: pointer;
    transition: background-color .15s ease, color .15s ease, opacity .15s ease;
}

#product-modal .dol-gallery__btn:hover {
    background: var(--dol-soft-hover);
}

#product-modal .dol-gallery__btn--close:hover {
    background: var(--dol-accent);
    color: #fff;
}

#product-modal .dol-gallery__btn:disabled {
    opacity: .35;
    cursor: default;
    background: var(--dol-soft);
}

#product-modal .dol-gallery__btn:focus,
#product-modal .dol-gallery__nav:focus,
#product-modal .dol-gallery__thumb:focus {
    outline: 0;
}

#product-modal .dol-gallery__btn:focus-visible,
#product-modal .dol-gallery__nav:focus-visible,
#product-modal .dol-gallery__thumb:focus-visible {
    outline: 2px solid var(--dol-accent);
    outline-offset: 2px;
}

/* Scène (image + zoom) */
#product-modal .dol-gallery__stage {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    background: #fff;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

#product-modal .dol-gallery__img {
    position: absolute;
    top: 0;
    left: 0;
    max-width: none;
    max-height: none;
    opacity: 0;
    -webkit-transform-origin: 50% 50%;
    transform-origin: 50% 50%;
    cursor: zoom-in;
    -webkit-user-drag: none;
    transition: opacity .22s ease;
}

#product-modal .dol-gallery__img.is-ready {
    opacity: 1;
}

#product-modal .dol-gallery__img.is-animating {
    transition: opacity .22s ease, transform .3s cubic-bezier(.2, .8, .2, 1);
}

#product-modal.is-zoomed .dol-gallery__img {
    cursor: grab;
}

#product-modal.is-dragging .dol-gallery__img {
    cursor: grabbing;
    will-change: transform; /* seulement pendant le geste : l'image reste nette une fois zoomée */
}

/* Chargement */
#product-modal .dol-gallery__loader {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 38px;
    height: 38px;
    margin: -19px 0 0 -19px;
    border: 3px solid var(--dol-line);
    border-top-color: var(--dol-accent);
    border-radius: 50%;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
    animation: dol-spin .8s linear infinite;
}

#product-modal.is-loading .dol-gallery__loader {
    opacity: 1;
    transition-delay: .15s; /* pas de clignotement si l'image est en cache */
}

@keyframes dol-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Flèches */
#product-modal .dol-gallery__nav {
    position: absolute;
    top: 50%;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    margin-top: -26px;
    padding: 0;
    border: 1px solid var(--dol-line);
    border-radius: 50%;
    background: rgba(255, 255, 255, .94);
    color: var(--dol-ink);
    box-shadow: 0 6px 20px rgba(0, 0, 0, .12);
    cursor: pointer;
    transition: background-color .15s ease, color .15s ease, border-color .15s ease, transform .15s ease, opacity .2s ease;
}

#product-modal .dol-gallery__nav--prev {
    left: 20px;
}

#product-modal .dol-gallery__nav--next {
    right: 20px;
}

#product-modal .dol-gallery__nav:active {
    transform: scale(.94);
}

@media (hover: hover) {
    #product-modal .dol-gallery__nav:hover {
        border-color: var(--dol-accent);
        background: var(--dol-accent);
        color: #fff;
        transform: scale(1.06);
    }
}

#product-modal.is-zoomed .dol-gallery__nav {
    opacity: .45;
}

#product-modal.is-zoomed .dol-gallery__nav:hover {
    opacity: 1;
}

/* Aide zoom */
#product-modal .dol-gallery__hint {
    position: absolute;
    bottom: 16px;
    left: 50%;
    z-index: 2;
    max-width: calc(100% - 32px);
    padding: 7px 14px;
    border-radius: 999px;
    background: rgba(20, 20, 20, .78);
    color: #fff;
    font-size: 12px;
    line-height: 1.4;
    white-space: nowrap;
    pointer-events: none;
    -webkit-transform: translateX(-50%);
    transform: translateX(-50%);
    transition: opacity .4s ease;
}

#product-modal .dol-gallery__hint.is-hidden {
    opacity: 0;
}

#product-modal .dol-gallery__hint-touch {
    display: none;
}

@media (hover: none) {
    #product-modal .dol-gallery__hint-mouse {
        display: none;
    }

    #product-modal .dol-gallery__hint-touch {
        display: inline;
    }
}

/* Miniatures */
#product-modal .dol-gallery__thumbs {
    flex: 0 0 auto;
    padding: 12px 16px;
    border-top: 1px solid var(--dol-line);
    background: #fafafa;
}

#product-modal .dol-gallery__thumbs ul {
    position: relative;
    display: flex;
    gap: 10px;
    margin: 0;
    padding: 3px;
    overflow-x: auto;
    list-style: none;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
}

/* centré tant que ça tient, défilable sinon */
#product-modal .dol-gallery__thumbs li:first-child {
    margin-left: auto;
}

#product-modal .dol-gallery__thumbs li:last-child {
    margin-right: auto;
}

#product-modal .dol-gallery__thumbs li {
    flex: 0 0 auto;
}

#product-modal .dol-gallery__thumb {
    display: block;
    width: 72px;
    height: 72px;
    padding: 4px;
    overflow: hidden;
    border: 2px solid transparent;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 0 0 1px #e3e4e7;
    opacity: .65;
    cursor: pointer;
    transition: opacity .15s ease, border-color .15s ease, box-shadow .15s ease;
}

#product-modal .dol-gallery__thumb img {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 7px;
    object-fit: contain;
}

#product-modal .dol-gallery__thumb:hover {
    opacity: 1;
}

#product-modal .dol-gallery__thumb.is-active {
    border-color: var(--dol-accent);
    box-shadow: 0 4px 12px rgba(227, 29, 39, .18);
    opacity: 1;
}

/* Une seule image : pas de navigation */
#product-modal.dol-gallery--single .dol-gallery__nav,
#product-modal.dol-gallery--single .dol-gallery__thumbs,
#product-modal.dol-gallery--single .dol-gallery__counter {
    display: none;
}

/* Mobile : plein écran */
@media (max-width: 767px) {
    #product-modal.dol-gallery .modal-dialog {
        padding: 0;
    }

    #product-modal .dol-gallery__panel {
        max-width: none;
        max-height: none;
        border-radius: 0;
        box-shadow: none;
    }

    #product-modal .dol-gallery__bar {
        gap: 10px;
        padding: 8px 8px 8px 14px;
    }

    #product-modal .dol-gallery__title {
        font-size: 13px;
    }

    #product-modal .dol-gallery__btn {
        width: 38px;
        height: 38px;
    }

    #product-modal .dol-gallery__nav {
        width: 42px;
        height: 42px;
        margin-top: -21px;
    }

    #product-modal .dol-gallery__nav--prev {
        left: 8px;
    }

    #product-modal .dol-gallery__nav--next {
        right: 8px;
    }

    #product-modal .dol-gallery__thumbs {
        padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
    }

    #product-modal .dol-gallery__thumb {
        width: 58px;
        height: 58px;
        border-radius: 10px;
    }
}

@media (max-width: 400px) {
    #product-modal .dol-gallery__title {
        display: none;
    }

    #product-modal .dol-gallery__tools {
        margin-left: auto;
    }
}

@media (prefers-reduced-motion: reduce) {
    #product-modal.dol-gallery.fade .modal-dialog,
    #product-modal .dol-gallery__img,
    #product-modal .dol-gallery__img.is-animating {
        transition: none;
    }
}

/* Image principale de la fiche : loupe visible au tactile (pas de survol) */
#main .product-cover .layer {
    cursor: zoom-in;
}

@media (hover: none) {
    #main .product-cover .layer,
    #main .product-cover .layer:hover {
        align-items: flex-end;
        justify-content: flex-end;
        padding: 12px;
        background: transparent;
        opacity: 1;
    }

    #main .product-cover .layer .zoom-in {
        width: 42px;
        height: 42px;
        border-radius: 50%;
        background: rgba(255, 255, 255, .92);
        box-shadow: 0 4px 14px rgba(0, 0, 0, .15);
        color: #141414;
        font-size: 24px;
        line-height: 42px;
        text-align: center;
    }
}

/* Fiche produit : vidéos intégrées (YouTube 640px) dans les descriptions — débordaient sur mobile */
#main iframe[src*="youtube"],
#main iframe[src*="vimeo"] {
    max-width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
}
