/**
 * WP Mobile Lightbox CSS
 * Stili per lightbox con zoom, su dispositivi touch e desktop
 * Version: 1.4.0
 */

/* Immagini della gallery: touch-action manipulation elimina il ritardo
   e lo zoom nativo del doppio tap, rendendo affidabile il doppio tap custom */
.image-gallery img {
    touch-action: manipulation;
}

/* Lightbox principale */
.wlb-lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.95);
    z-index: 999999;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
    -webkit-user-select: none;
    outline: none;
}

.wlb-lightbox.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Container principale */
.wlb-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* Wrapper immagine */
.wlb-image-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* Immagine principale.
   Nessuna transizione sul transform di default: durante pinch e pan
   renderebbe i gesti laggy. Viene abilitata solo per lo zoom da doppio
   tap tramite la classe .wlb-anim aggiunta temporaneamente dal JS. */
.wlb-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    user-select: none;
    -webkit-user-drag: none;
    opacity: 0;
    transition: opacity 0.3s;
    transform-origin: center;
}

.wlb-image.wlb-anim {
    transition: opacity 0.3s, transform var(--wlb-anim-duration, 0.2s) ease-out;
}

.wlb-image.loaded {
    opacity: 1;
}

/* Layer compositor dedicato mentre il lightbox è aperto:
   pan e zoom girano interamente su GPU */
.wlb-lightbox.active .wlb-image {
    will-change: transform;
}

/* Cursori desktop */
.wlb-lightbox .wlb-image {
    cursor: zoom-in;
}

.wlb-lightbox.wlb-zoomed .wlb-image {
    cursor: grab;
}

.wlb-lightbox.wlb-grabbing .wlb-image,
.wlb-lightbox.wlb-grabbing .wlb-image-wrapper {
    cursor: grabbing;
}

/* Durante i gesti: niente blur, la ricomposizione dei backdrop-filter
   sopra un'immagine in trasformazione pesa sui dispositivi economici */
.wlb-lightbox.wlb-gesturing .wlb-close,
.wlb-lightbox.wlb-gesturing .wlb-prev,
.wlb-lightbox.wlb-gesturing .wlb-next,
.wlb-lightbox.wlb-gesturing .wlb-goto-btn,
.wlb-lightbox.wlb-gesturing .wlb-goto-input-wrapper,
.wlb-lightbox.wlb-gesturing .wlb-counter {
    backdrop-filter: none;
}

/* Indicatore di caricamento */
.wlb-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border: 3px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: wlb-spin 0.8s linear infinite;
    display: none;
    pointer-events: none;
}

.wlb-loading.active {
    display: block;
}

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

/* Pulsanti di controllo */
.wlb-close,
.wlb-prev,
.wlb-next {
    position: absolute;
    background: rgba(255,255,255,0.1);
    border: none;
    color: #fff;
    font-size: 36px;
    width: 50px;
    height: 50px;
    opacity: 0.7;
    transition: opacity 0.2s, background 0.2s;
    -webkit-tap-highlight-color: transparent;
    border-radius: 50%;
    line-height: 1;
    padding: 0;
    z-index: 10;
    backdrop-filter: blur(10px);
    cursor: pointer;
}

.wlb-close:active,
.wlb-prev:active,
.wlb-next:active {
    opacity: 1;
    background: rgba(255,255,255,0.2);
}

.wlb-close:hover,
.wlb-prev:hover,
.wlb-next:hover {
    opacity: 1;
    background: rgba(255,255,255,0.15);
}

/* Focus visibile per navigazione da tastiera */
.wlb-close:focus-visible,
.wlb-prev:focus-visible,
.wlb-next:focus-visible,
.wlb-goto-btn:focus-visible,
.wlb-goto-ok:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
    opacity: 1;
}

/* Posizionamento pulsanti */
.wlb-close {
    top: 15px;
    right: 15px;
}

.wlb-prev {
    left: 15px;
    top: 50%;
    margin-top: -25px;
}

.wlb-next {
    right: 15px;
    top: 50%;
    margin-top: -25px;
}

.wlb-prev:disabled,
.wlb-next:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Barra inferiore con controlli */
.wlb-bottom-bar {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    z-index: 10;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    max-width: 90vw;
    flex-wrap: nowrap;
}

/* Pulsante "Vai a" */
.wlb-goto-btn {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
    backdrop-filter: blur(10px);
    white-space: nowrap;
}

.wlb-goto-btn:active {
    background: rgba(255,255,255,0.25);
    transform: scale(0.95);
}

/* Wrapper input (nascosto di default) */
.wlb-goto-input-wrapper {
    display: none;
    align-items: center;
    gap: 6px;
    background: rgba(0,0,0,0.6);
    padding: 5px 10px;
    border-radius: 18px;
    backdrop-filter: blur(10px);
    flex-shrink: 0;
}

/* Input numerico */
.wlb-goto-input {
    width: 40px;
    max-width: 40px;
    min-width: 40px;
    flex: 0 0 40px;
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.4);
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    padding: 5px 4px;
    border-radius: 8px;
    text-align: center;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: textfield;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    box-sizing: border-box;
    flex-shrink: 0;
}

.wlb-goto-input:focus {
    outline: none;
    border-color: rgba(255,255,255,0.7);
    background: rgba(255,255,255,0.2);
}

/* Rimuovi spinner dai number input */
.wlb-goto-input::-webkit-inner-spin-button,
.wlb-goto-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Pulsante OK */
.wlb-goto-ok {
    background: rgba(76, 175, 80, 0.9);
    border: none;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    padding: 5px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.wlb-goto-ok:active {
    background: rgba(76, 175, 80, 1);
    transform: scale(0.95);
}

/* Stato attivo: mostra input, nascondi bottone "Vai a" */
.wlb-bottom-bar.goto-active .wlb-goto-btn {
    display: none;
}

.wlb-bottom-bar.goto-active .wlb-goto-input-wrapper {
    display: flex;
    animation: wlb-fade-in 0.2s ease;
}

/* Contatore immagini */
.wlb-counter {
    color: #fff;
    font-size: 14px;
    background: rgba(0,0,0,0.5);
    padding: 6px 14px;
    border-radius: 20px;
    pointer-events: none;
    backdrop-filter: blur(10px);
    white-space: nowrap;
}

/* Animazione fade in */
@keyframes wlb-fade-in {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Hint per doppio tap: elemento DOM reale creato dal JS
   (esiste solo mentre è visibile, niente spazio vuoto residuo) */
.wlb-hint {
    display: block;
    margin-bottom: 15px;
    padding: 12px 16px;
    border-radius: 8px;
    background: linear-gradient(135deg, rgba(33, 150, 243, 0.1), rgba(33, 150, 243, 0.05));
    border: 1px solid rgba(33, 150, 243, 0.2);
    color: #1976d2;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    letter-spacing: 0.01em;
    opacity: 0;
    transform: translateY(-10px);
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(33, 150, 243, 0.1);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    animation: wlb-hint-fade 0.4s ease forwards,
               wlb-hint-glow 2s ease-in-out 0.4s infinite alternate;
}

.wlb-hint.wlb-hint-hide {
    animation: wlb-hint-hide 0.4s ease forwards;
}

/* Animazioni hint */
@keyframes wlb-hint-fade {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes wlb-hint-glow {
    from {
        box-shadow: 0 2px 8px rgba(33, 150, 243, 0.1);
        border-color: rgba(33, 150, 243, 0.2);
    }
    to {
        box-shadow: 0 4px 16px rgba(33, 150, 243, 0.2);
        border-color: rgba(33, 150, 243, 0.3);
    }
}

@keyframes wlb-hint-hide {
    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

/* Media queries per tablet e desktop */
@media (min-width: 768px) {
    .wlb-close,
    .wlb-prev,
    .wlb-next {
        width: 60px;
        height: 60px;
        font-size: 42px;
    }

    .wlb-prev {
        left: 25px;
    }

    .wlb-next {
        right: 25px;
    }

    .wlb-counter {
        font-size: 16px;
    }

    .wlb-goto-btn {
        font-size: 14px;
        padding: 7px 14px;
    }

    .wlb-goto-input {
        width: 45px;
        max-width: 45px;
        min-width: 45px;
        flex-basis: 45px;
        font-size: 14px;
        padding: 5px 8px;
    }

    .wlb-goto-ok {
        font-size: 12px;
        padding: 5px 12px;
    }
}

/* Accessibilità: riduci movimento.
   L'hint resta visibile (opacity 1 diretta), senza animazioni né glow. */
@media (prefers-reduced-motion: reduce) {
    .wlb-image,
    .wlb-image.wlb-anim,
    .wlb-loading,
    .wlb-hint,
    .wlb-hint.wlb-hint-hide,
    .wlb-bottom-bar.goto-active .wlb-goto-input-wrapper {
        animation: none;
        transition: none;
    }

    .wlb-hint {
        opacity: 1;
        transform: none;
    }

    .wlb-hint.wlb-hint-hide {
        opacity: 0;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .wlb-hint {
        background: linear-gradient(135deg, rgba(33, 150, 243, 0.15), rgba(33, 150, 243, 0.08));
        border-color: rgba(33, 150, 243, 0.3);
        color: #64b5f6;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .wlb-lightbox {
        background: rgba(0,0,0,0.98);
    }

    .wlb-close,
    .wlb-prev,
    .wlb-next {
        background: rgba(255,255,255,0.2);
        border: 1px solid rgba(255,255,255,0.5);
    }

    .wlb-counter {
        background: rgba(0,0,0,0.8);
        border: 1px solid rgba(255,255,255,0.3);
    }
}
