/**
 * Caly-Quiz IRVE - Styles Image Gallery & Image Modules
 * Styles pour galeries, lazy loading, captions interactives et comparateur
 * Version 1.0.0
 *
 * @author MvFormateur
 * @license MIT
 */

/* ============================================
   VARIABLES CSS
   ============================================ */
:root {
    /* Couleurs principales */
    --caly-img-primary: #f59e0b;
    --caly-img-primary-light: #fbbf24;
    --caly-img-primary-dark: #d97706;

    /* Couleurs de surface */
    --caly-img-surface: #ffffff;
    --caly-img-surface-light: #f8f9fa;
    --caly-img-surface-dark: #f5f5f5;

    /* Texte */
    --caly-img-text: #1f2937;
    --caly-img-text-muted: #4b5563;

    /* États */
    --caly-img-success: #22c55e;
    --caly-img-warning: #f59e0b;
    --caly-img-danger: #ef4444;

    /* Dimensions */
    --caly-img-border-radius: 8px;
    --caly-img-transition: 0.3s ease;

    /* Ombres */
    --caly-img-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    --caly-img-shadow-hover: 0 8px 25px rgba(245, 158, 11, 0.15);
}

/* ============================================
   IMAGE LOADER - LAZY LOADING
   ============================================ */

/* Image en cours de chargement */
.caly-img-lazy,
.caly-img-loading {
    background: var(--caly-img-surface);
    min-height: 100px;
    position: relative;
}

.caly-img-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 32px;
    height: 32px;
    margin: -16px 0 0 -16px;
    border: 3px solid var(--caly-img-surface-light);
    border-top-color: var(--caly-img-primary);
    border-radius: 50%;
    animation: caly-img-spin 0.8s linear infinite;
}

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

/* Image chargée */
.caly-img-loaded {
    animation: caly-img-fadeIn 0.3s ease;
}

@keyframes caly-img-fadeIn {
    from {
        opacity: 0;
        transform: scale(0.98);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Image en erreur */
.caly-img-error {
    background: var(--caly-img-surface);
    border: 2px dashed var(--caly-img-danger);
}

/* ============================================
   IMAGE GALLERY
   ============================================ */

.caly-gallery {
    position: relative;
    background: var(--caly-img-surface-dark);
    border-radius: var(--caly-img-border-radius);
    overflow: hidden;
    box-shadow: var(--caly-img-shadow);
}

.caly-gallery:fullscreen {
    background: #000;
}

/* Zone principale de l'image */
.caly-gallery-main {
    position: relative;
    aspect-ratio: 16 / 10;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.caly-gallery-image-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-in;
}

.caly-gallery-image-wrapper.zoomed {
    cursor: zoom-out;
}

.caly-gallery-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transition: transform var(--caly-img-transition), opacity 0.2s ease;
}

.caly-gallery-image-wrapper.zoomed .caly-gallery-image {
    transform: scale(2);
}

/* Animation d'entrée/sortie */
.caly-gallery-image-exit {
    opacity: 0;
    transform: translateX(-20px);
}

.caly-gallery-image-enter {
    animation: caly-gallery-slideIn 0.3s ease forwards;
}

@keyframes caly-gallery-slideIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Loader */
.caly-gallery-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: none;
}

.caly-gallery-loader.active {
    display: block;
}

.caly-gallery-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--caly-img-surface-light);
    border-top-color: var(--caly-img-primary);
    border-radius: 50%;
    animation: caly-img-spin 0.8s linear infinite;
}

/* Indicateur de zoom */
.caly-gallery-zoom-indicator {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    opacity: 0;
    transition: opacity var(--caly-img-transition);
    pointer-events: none;
}

.caly-gallery-image-wrapper:hover .caly-gallery-zoom-indicator,
.caly-gallery-zoom-indicator:not(.hidden) {
    opacity: 1;
}

.caly-gallery-zoom-indicator.hidden {
    display: none;
}

/* Navigation */
.caly-gallery-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.5);
    border: none;
    color: white;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity var(--caly-img-transition), background var(--caly-img-transition);
    z-index: 10;
}

.caly-gallery:hover .caly-gallery-nav {
    opacity: 1;
}

.caly-gallery-nav:hover {
    background: var(--caly-img-primary);
}

.caly-gallery-nav.disabled {
    opacity: 0.3 !important;
    cursor: not-allowed;
}

.caly-gallery-prev {
    left: 15px;
}

.caly-gallery-next {
    right: 15px;
}

/* Contrôles */
.caly-gallery-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 15px;
    background: var(--caly-img-surface);
    border-top: 1px solid var(--caly-img-surface-light);
}

.caly-gallery-counter {
    font-size: 0.9rem;
    color: var(--caly-img-text-muted);
}

.caly-gallery-current {
    color: var(--caly-img-text);
    font-weight: 600;
}

.caly-gallery-separator {
    margin: 0 4px;
}

.caly-gallery-actions {
    display: flex;
    gap: 8px;
}

.caly-gallery-action-btn {
    background: var(--caly-img-surface-light);
    border: none;
    color: var(--caly-img-text-muted);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--caly-img-transition);
}

.caly-gallery-action-btn:hover {
    background: var(--caly-img-primary);
    color: white;
}

/* Caption */
.caly-gallery-caption {
    padding: 12px 15px;
    font-size: 0.9rem;
    color: var(--caly-img-text-muted);
    text-align: center;
    font-style: italic;
    background: var(--caly-img-surface-dark);
}

/* Thumbnails */
.caly-gallery-thumbnails {
    padding: 10px;
    background: var(--caly-img-surface);
    border-top: 1px solid var(--caly-img-surface-light);
    overflow-x: auto;
}

.caly-gallery-thumbnails-track {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.caly-gallery-thumb {
    flex-shrink: 0;
    width: 60px;
    height: 45px;
    border: 2px solid transparent;
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    opacity: 0.6;
    transition: all var(--caly-img-transition);
    padding: 0;
    background: none;
}

.caly-gallery-thumb:hover {
    opacity: 0.9;
}

.caly-gallery-thumb.active {
    opacity: 1;
    border-color: var(--caly-img-primary);
}

.caly-gallery-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.caly-gallery-thumb-more {
    flex-shrink: 0;
    width: 60px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--caly-img-surface-light);
    border-radius: 4px;
    font-size: 0.8rem;
    color: var(--caly-img-text-muted);
}

/* ============================================
   INTERACTIVE CAPTIONS
   ============================================ */

.caly-captions-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 20;
}

/* Marqueur */
.caly-caption-marker {
    position: absolute;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    cursor: pointer;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    z-index: 1;
}

.caly-caption-marker:hover {
    transform: translate(-50%, -50%) scale(1.15);
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.5);
    z-index: 10;
}

.caly-caption-marker:focus {
    outline: 2px solid white;
    outline-offset: 2px;
}

.caly-caption-marker-icon,
.caly-caption-marker-number {
    font-size: 0.85rem;
    line-height: 1;
}

/* Animation pulse */
.caly-caption-marker-pulse {
    animation: caly-caption-pulse 2s infinite;
}

@keyframes caly-caption-pulse {
    0%, 100% {
        box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3);
    }
    50% {
        box-shadow: 0 2px 8px rgba(245, 158, 11, 0.3),
                    0 0 0 8px rgba(245, 158, 11, 0.1);
    }
}

/* Popover */
.caly-caption-popover {
    position: absolute;
    background: var(--caly-img-surface);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    z-index: 100;
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: auto;
}

.caly-caption-popover.visible {
    opacity: 1;
    transform: translateY(0);
}

/* Positions du popover */
.caly-caption-popover.position-top {
    bottom: calc(100% + 15px);
    left: 50%;
    transform: translateX(-50%);
}

.caly-caption-popover.position-top.visible {
    transform: translateX(-50%) translateY(0);
}

.caly-caption-popover.position-bottom {
    top: calc(100% + 15px);
    left: 50%;
    transform: translateX(-50%);
}

.caly-caption-popover.position-left {
    right: calc(100% + 15px);
    top: 50%;
    transform: translateY(-50%);
}

.caly-caption-popover.position-right {
    left: calc(100% + 15px);
    top: 50%;
    transform: translateY(-50%);
}

/* Contenu du popover */
.caly-caption-popover-header {
    font-weight: 600;
    color: #92400e;
    padding: 12px 15px 8px;
    font-size: 0.95rem;
    border-bottom: 1px solid var(--caly-img-surface-light);
}

.caly-caption-popover-body {
    padding: 10px 15px;
    color: var(--caly-img-text-muted);
    font-size: 0.85rem;
    line-height: 1.5;
}

.caly-caption-popover-image {
    width: 100%;
    height: auto;
    border-radius: 0 0 6px 6px;
    margin-top: 10px;
}

.caly-caption-popover-specs {
    padding: 8px 15px;
    background: var(--caly-img-surface-dark);
    border-top: 1px solid var(--caly-img-surface-light);
    font-size: 0.8rem;
}

.caly-caption-spec {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
}

.spec-label {
    color: var(--caly-img-text-muted);
}

.spec-value {
    color: var(--caly-img-text);
    font-weight: 500;
}

.caly-caption-popover-link {
    display: block;
    padding: 10px 15px;
    color: #92400e;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    border-top: 1px solid var(--caly-img-surface-light);
    transition: background var(--caly-img-transition);
}

.caly-caption-popover-link:hover {
    background: var(--caly-img-surface-light);
}

/* Flèche du popover */
.caly-caption-popover-arrow {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--caly-img-surface);
    border-right: 1px solid rgba(245, 158, 11, 0.3);
    border-bottom: 1px solid rgba(245, 158, 11, 0.3);
}

.position-top .caly-caption-popover-arrow {
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
}

.position-bottom .caly-caption-popover-arrow {
    top: -6px;
    left: 50%;
    transform: translateX(-50%) rotate(-135deg);
}

.position-left .caly-caption-popover-arrow {
    right: -6px;
    top: 50%;
    transform: translateY(-50%) rotate(-45deg);
}

.position-right .caly-caption-popover-arrow {
    left: -6px;
    top: 50%;
    transform: translateY(-50%) rotate(135deg);
}

/* ============================================
   BEFORE/AFTER SLIDER
   ============================================ */

.caly-ba-slider {
    position: relative;
    width: 100%;
    overflow: hidden;
    border-radius: var(--caly-img-border-radius);
    box-shadow: var(--caly-img-shadow);
    user-select: none;
    -webkit-user-select: none;
}

.caly-ba-slider:focus {
    outline: 2px solid var(--caly-img-primary);
    outline-offset: 2px;
}

/* Images */
.caly-ba-before,
.caly-ba-after {
    position: relative;
    width: 100%;
}

.caly-ba-before img,
.caly-ba-after img {
    display: block;
    width: 100%;
    height: auto;
    pointer-events: none;
}

.caly-ba-after {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    clip-path: inset(0 50% 0 0);
}

/* Transition fluide */
.caly-ba-slider.animating .caly-ba-after,
.caly-ba-slider.animating .caly-ba-handle {
    transition: all 0.3s ease;
}

/* Labels */
.caly-ba-label {
    position: absolute;
    bottom: 15px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.caly-ba-label-before {
    left: 15px;
}

.caly-ba-label-after {
    right: 15px;
}

/* Curseur/Handle */
.caly-ba-handle {
    position: absolute;
    top: 0;
    left: 50%;
    width: var(--handle-width, 4px);
    height: 100%;
    background: var(--handle-color, #f59e0b);
    transform: translateX(-50%);
    cursor: ew-resize;
    z-index: 10;
}

.caly-ba-slider.vertical .caly-ba-handle {
    top: 50%;
    left: 0;
    width: 100%;
    height: var(--handle-width, 4px);
    transform: translateY(-50%);
    cursor: ns-resize;
}

/* Bouton du curseur */
.caly-ba-handle-knob {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: var(--knob-size, 44px);
    height: var(--knob-size, 44px);
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    color: var(--handle-color, #f59e0b);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.caly-ba-slider:hover .caly-ba-handle-knob,
.caly-ba-slider.dragging .caly-ba-handle-knob {
    transform: translate(-50%, -50%) scale(1.1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
}

/* Hint de direction */
.caly-ba-direction-hint {
    position: absolute;
    bottom: 50px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 16px;
    border-radius: 25px;
    font-size: 0.8rem;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 15;
}

.caly-ba-direction-hint.hidden {
    opacity: 0;
}

.hint-left,
.hint-right {
    opacity: 0.7;
}

.hint-text {
    font-weight: 500;
}

/* Orientation verticale */
.caly-ba-slider.vertical .caly-ba-after {
    clip-path: inset(0 0 50% 0);
}

.caly-ba-slider.vertical .caly-ba-label-before {
    bottom: auto;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
}

.caly-ba-slider.vertical .caly-ba-label-after {
    bottom: 15px;
    right: auto;
    left: 50%;
    transform: translateX(-50%);
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 768px) {
    /* Gallery */
    .caly-gallery-main {
        aspect-ratio: 4 / 3;
    }

    .caly-gallery-nav {
        width: 40px;
        height: 40px;
        opacity: 0.7;
    }

    .caly-gallery-prev {
        left: 8px;
    }

    .caly-gallery-next {
        right: 8px;
    }

    .caly-gallery-controls {
        padding: 10px;
    }

    .caly-gallery-thumbnails {
        padding: 8px;
    }

    .caly-gallery-thumb {
        width: 50px;
        height: 38px;
    }

    /* Captions */
    .caly-caption-marker {
        width: 28px !important;
        height: 28px !important;
    }

    .caly-caption-popover {
        width: 240px !important;
        max-width: 90vw !important;
    }

    /* Before/After */
    .caly-ba-handle-knob {
        width: 36px !important;
        height: 36px !important;
    }

    .caly-ba-label {
        font-size: 0.7rem;
        padding: 4px 10px;
    }

    .caly-ba-direction-hint {
        font-size: 0.7rem;
        padding: 6px 12px;
    }
}

@media (max-width: 480px) {
    .caly-gallery-thumbnails-track {
        justify-content: flex-start;
    }

    .caly-gallery-thumb {
        width: 45px;
        height: 34px;
    }

    .caly-caption-marker {
        width: 24px !important;
        height: 24px !important;
    }

    .caly-caption-marker-number,
    .caly-caption-marker-icon {
        font-size: 0.7rem;
    }
}

/* ============================================
   ANIMATIONS GLOBALES
   ============================================ */

@keyframes caly-fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes caly-slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes caly-scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Utilitaires d'animation */
.caly-animate-fadeIn {
    animation: caly-fadeIn 0.3s ease forwards;
}

.caly-animate-slideUp {
    animation: caly-slideUp 0.4s ease forwards;
}

.caly-animate-scaleIn {
    animation: caly-scaleIn 0.3s ease forwards;
}

/* ============================================
   MODE SOMBRE AUTOMATIQUE
   ============================================ */

/* Light theme is now the default - no media query override needed */

/* ============================================
   ACCESSIBILITÉ
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    .caly-caption-marker-pulse {
        animation: none;
    }

    .caly-gallery-image,
    .caly-ba-after,
    .caly-ba-handle {
        transition: none !important;
    }
}

/* Focus visible */
.caly-gallery:focus-visible,
.caly-gallery-nav:focus-visible,
.caly-gallery-action-btn:focus-visible,
.caly-gallery-thumb:focus-visible,
.caly-caption-marker:focus-visible,
.caly-ba-slider:focus-visible {
    outline: 2px solid var(--caly-img-primary);
    outline-offset: 2px;
}
