/**
 * Caly-Quiz IRVE - Module Lightbox (Popup Redimensionnable)
 * Visionneuse d'images en popup ou nouvel onglet
 * Version 2.0.0
 */

/* ============================================
   POPUP CONTAINER
   ============================================ */
.caly-lightbox-popup {
    position: fixed;
    z-index: 100000;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: scale(0.95);
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
    min-width: 400px;
    min-height: 300px;
}

.caly-lightbox-popup.visible {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
}

.caly-lightbox-popup.dragging,
.caly-lightbox-popup.resizing {
    transition: none;
    user-select: none;
}

/* ============================================
   HEADER (Barre de titre)
   ============================================ */
.caly-lightbox-popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: linear-gradient(135deg, #f8f9fa, #ffffff);
    border-bottom: 1px solid #e5e7eb;
    cursor: move;
    flex-shrink: 0;
}

.caly-lightbox-popup-title {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #1f2937;
    font-size: 0.9rem;
    overflow: hidden;
}

.caly-lightbox-popup-counter {
    background: rgba(245, 158, 11, 0.2);
    color: #d97706;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    flex-shrink: 0;
}

.caly-lightbox-popup-counter .current {
    color: #f59e0b;
}

.caly-lightbox-popup-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 300px;
}

.caly-lightbox-popup-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.caly-lightbox-popup-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.05);
    color: #6b7280;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all 0.2s ease;
}

.caly-lightbox-popup-btn:hover {
    background: rgba(245, 158, 11, 0.2);
    color: #d97706;
    transform: scale(1.05);
}

.caly-lightbox-popup-btn.close-btn:hover {
    background: rgba(239, 68, 68, 0.3);
    color: #dc2626;
}

.caly-lightbox-popup-btn.newtab-btn:hover {
    background: rgba(16, 185, 129, 0.3);
    color: #34d399;
}

/* ============================================
   CONTENT (Zone image)
   ============================================ */
.caly-lightbox-popup-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    background: #f5f5f5;
    overflow: hidden;
    min-height: 200px;
}

.caly-lightbox-popup-image-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 15px;
}

.caly-lightbox-popup-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 4px;
    transition: opacity 0.2s ease;
}

/* ============================================
   NAVIGATION
   ============================================ */
.caly-lightbox-popup-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    color: #4b5563;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all 0.2s ease;
    z-index: 10;
}

.caly-lightbox-popup-nav:hover {
    background: rgba(245, 158, 11, 0.8);
    transform: translateY(-50%) scale(1.1);
}

.caly-lightbox-popup-nav:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: translateY(-50%);
}

.caly-lightbox-popup-nav.prev {
    left: 10px;
}

.caly-lightbox-popup-nav.next {
    right: 10px;
}

/* ============================================
   CAPTION (Légende)
   ============================================ */
.caly-lightbox-popup-caption {
    padding: 10px 15px;
    background: rgba(248, 249, 250, 0.9);
    border-top: 1px solid #e5e7eb;
    color: #6b7280;
    font-size: 0.85rem;
    text-align: center;
    flex-shrink: 0;
}

.caly-lightbox-popup-caption:empty {
    display: none;
}

/* ============================================
   LOADER
   ============================================ */
.caly-lightbox-popup-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 3px solid rgba(245, 158, 11, 0.2);
    border-top-color: #f59e0b;
    border-radius: 50%;
    animation: lightbox-popup-spin 0.8s linear infinite;
    display: none;
}

@keyframes lightbox-popup-spin {
    to {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

/* ============================================
   RESIZE HANDLES
   ============================================ */
.caly-lightbox-resize-handle {
    position: absolute;
    z-index: 20;
}

/* Côtés */
.caly-lightbox-resize-handle.resize-n {
    top: 0;
    left: 10px;
    right: 10px;
    height: 6px;
    cursor: n-resize;
}

.caly-lightbox-resize-handle.resize-s {
    bottom: 0;
    left: 10px;
    right: 10px;
    height: 6px;
    cursor: s-resize;
}

.caly-lightbox-resize-handle.resize-e {
    right: 0;
    top: 10px;
    bottom: 10px;
    width: 6px;
    cursor: e-resize;
}

.caly-lightbox-resize-handle.resize-w {
    left: 0;
    top: 10px;
    bottom: 10px;
    width: 6px;
    cursor: w-resize;
}

/* Coins */
.caly-lightbox-resize-handle.resize-ne {
    top: 0;
    right: 0;
    width: 15px;
    height: 15px;
    cursor: ne-resize;
}

.caly-lightbox-resize-handle.resize-se {
    bottom: 0;
    right: 0;
    width: 15px;
    height: 15px;
    cursor: se-resize;
}

.caly-lightbox-resize-handle.resize-sw {
    bottom: 0;
    left: 0;
    width: 15px;
    height: 15px;
    cursor: sw-resize;
}

.caly-lightbox-resize-handle.resize-nw {
    top: 0;
    left: 0;
    width: 15px;
    height: 15px;
    cursor: nw-resize;
}

/* Indicateur visuel au survol des coins */
.caly-lightbox-resize-handle.resize-se::after,
.caly-lightbox-resize-handle.resize-sw::after,
.caly-lightbox-resize-handle.resize-ne::after,
.caly-lightbox-resize-handle.resize-nw::after {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    border: 2px solid rgba(245, 158, 11, 0.5);
    opacity: 0;
    transition: opacity 0.2s;
}

.caly-lightbox-resize-handle.resize-se::after {
    bottom: 3px;
    right: 3px;
    border-top: none;
    border-left: none;
}

.caly-lightbox-resize-handle.resize-sw::after {
    bottom: 3px;
    left: 3px;
    border-top: none;
    border-right: none;
}

.caly-lightbox-resize-handle.resize-ne::after {
    top: 3px;
    right: 3px;
    border-bottom: none;
    border-left: none;
}

.caly-lightbox-resize-handle.resize-nw::after {
    top: 3px;
    left: 3px;
    border-bottom: none;
    border-right: none;
}

.caly-lightbox-popup:hover .caly-lightbox-resize-handle::after {
    opacity: 1;
}

/* ============================================
   INDICATEUR IMAGES CLIQUABLES
   ============================================ */
.caly-lightbox-enabled {
    cursor: zoom-in !important;
    position: relative;
    transition: transform 0.2s ease, box-shadow 0.2s ease, outline 0.2s ease;
}

.caly-lightbox-enabled:hover {
    transform: scale(1.01);
    box-shadow: 0 4px 20px rgba(245, 158, 11, 0.4);
    outline: 3px solid rgba(245, 158, 11, 0.5);
    outline-offset: 3px;
}

.caly-lightbox-enabled::after {
    content: '🔍 Cliquez pour agrandir';
    position: absolute;
    bottom: 10px;
    right: 10px;
    background: rgba(255, 255, 255, 0.95);
    color: #1f2937;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    z-index: 10;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.caly-lightbox-enabled:hover::after {
    opacity: 1;
}

/* Pour les images dans les slides/deck */
.slide .caly-lightbox-enabled:hover,
.deck .caly-lightbox-enabled:hover,
.media .caly-lightbox-enabled:hover {
    transform: scale(1.02);
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .caly-lightbox-popup {
        min-width: 320px;
        min-height: 250px;
    }

    .caly-lightbox-popup-header {
        padding: 8px 12px;
    }

    .caly-lightbox-popup-name {
        max-width: 150px;
        font-size: 0.85rem;
    }

    .caly-lightbox-popup-nav {
        width: 35px;
        height: 35px;
        font-size: 1rem;
    }

    .caly-lightbox-popup-btn {
        width: 28px;
        height: 28px;
        font-size: 0.9rem;
    }
}

/* ============================================
   MODE COMPARAISON
   ============================================ */
.caly-lightbox-comparison {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100001;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.caly-lightbox-comparison.visible {
    opacity: 1;
    visibility: visible;
}

.caly-lightbox-comparison-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
}

.caly-lightbox-comparison-container {
    position: relative;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15);
    max-width: 90vw;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.caly-lightbox-comparison-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: linear-gradient(135deg, #f8f9fa, #ffffff);
    border-bottom: 1px solid #e5e7eb;
}

.comparison-title {
    color: #1f2937;
    font-size: 1rem;
    font-weight: 600;
}

.comparison-close {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.05);
    color: #6b7280;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s ease;
}

.comparison-close:hover {
    background: rgba(239, 68, 68, 0.3);
    color: #dc2626;
}

.caly-lightbox-comparison-content {
    display: flex;
    align-items: stretch;
    position: relative;
    height: 60vh;
    min-height: 400px;
}

.comparison-side {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f5f5f5;
}

.comparison-side.before {
    position: absolute;
    top: 0;
    left: 0;
    width: 50%;
    height: 100%;
    z-index: 2;
    overflow: hidden;
}

.comparison-side.after {
    position: relative;
    width: 100%;
}

.comparison-side img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.comparison-label {
    position: absolute;
    bottom: 15px;
    padding: 6px 16px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.comparison-side.before .comparison-label {
    left: 15px;
}

.comparison-side.after .comparison-label {
    right: 15px;
}

.comparison-divider {
    position: absolute;
    top: 0;
    left: 50%;
    width: 4px;
    height: 100%;
    background: #f59e0b;
    transform: translateX(-50%);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.divider-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100%;
    background: linear-gradient(to bottom, transparent, #f59e0b, transparent);
}

.divider-icon {
    position: relative;
    width: 36px;
    height: 36px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #f59e0b;
    font-size: 1.2rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.caly-lightbox-comparison-slider {
    padding: 15px 20px;
    background: #f8f9fa;
    border-top: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    gap: 15px;
}

.comparison-slider-input {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: #e5e7eb;
    border-radius: 3px;
    cursor: pointer;
}

.comparison-slider-input::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: #f59e0b;
    border-radius: 50%;
    cursor: grab;
    box-shadow: 0 2px 6px rgba(245, 158, 11, 0.4);
}

.comparison-slider-input::-webkit-slider-thumb:active {
    cursor: grabbing;
}

.comparison-slider-value {
    min-width: 45px;
    text-align: center;
    color: #6b7280;
    font-size: 0.9rem;
    font-weight: 600;
}

/* ============================================
   MODE ANNOTATIONS
   ============================================ */
.lightbox-annotation {
    position: absolute;
    transform: translate(-50%, -50%);
    z-index: 50;
}

.annotation-marker {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    border: 2px solid white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 0.85rem;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    animation: annotation-pulse 2s infinite;
}

.annotation-marker:hover {
    transform: scale(1.15);
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.5);
}

@keyframes annotation-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);
    }
}

.annotation-tooltip {
    position: absolute;
    bottom: calc(100% + 15px);
    left: 50%;
    transform: translateX(-50%);
    background: #ffffff;
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: 8px;
    padding: 12px 15px;
    min-width: 200px;
    max-width: 300px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
    transform: translateX(-50%) translateY(10px);
}

.lightbox-annotation.active .annotation-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.tooltip-title {
    font-weight: 600;
    color: #d97706;
    margin-bottom: 6px;
    font-size: 0.9rem;
}

.tooltip-content {
    color: #6b7280;
    font-size: 0.85rem;
    line-height: 1.5;
}

.annotation-tooltip::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
    width: 12px;
    height: 12px;
    background: #ffffff;
    border-right: 1px solid rgba(245, 158, 11, 0.3);
    border-bottom: 1px solid rgba(245, 158, 11, 0.3);
}

/* ============================================
   PRINT - Masquer le popup
   ============================================ */
@media print {
    .caly-lightbox-popup,
    .caly-lightbox-comparison {
        display: none !important;
    }
}

/* ============================================
   RESPONSIVE - Comparaison et Annotations
   ============================================ */
@media (max-width: 768px) {
    .caly-lightbox-comparison-content {
        height: 50vh;
        min-height: 300px;
    }

    .comparison-label {
        font-size: 0.75rem;
        padding: 4px 12px;
    }

    .divider-icon {
        width: 30px;
        height: 30px;
        font-size: 1rem;
    }

    .annotation-marker {
        width: 28px;
        height: 28px;
        font-size: 0.75rem;
    }

    .annotation-tooltip {
        min-width: 180px;
        max-width: 250px;
    }
}
