/**
 * Megabox Gallery Frontend Styles
 * 
 * @package Megabox_Gallery
 */

/* Custom properties */
:root {
    --megabox-overlay-bg: rgba(0, 0, 0, 0.95);
    --megabox-text-color: #ffffff;
    --megabox-button-bg: rgba(255, 255, 255, 0.1);
    --megabox-button-hover-bg: rgba(255, 255, 255, 0.2);
    --megabox-thumbnail-border: #ffffff;
    --megabox-animation-speed: 300ms;
    --megabox-thumbnail-size: 80px;
    --megabox-z-index: 999999;
}

/* Hide WordPress lightbox elements */
.wp-block-gallery .lightbox-trigger,
.wp-block-image .lightbox-trigger {
    display: none !important;
}

.wp-block-gallery[data-wp-interactive],
.wp-block-image[data-wp-interactive] {
    pointer-events: none !important;
}

.wp-block-gallery img,
.wp-block-image img {
    pointer-events: auto !important;
    cursor: pointer !important;
}

/* Gallery container styles */
.megabox-gallery {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 0 -5px;
}

.megabox-gallery .gallery-item {
    flex: 1 1 calc(33.333% - 10px);
    margin: 5px;
    position: relative;
    overflow: hidden;
}

.megabox-gallery .gallery-icon {
    position: relative;
    overflow: hidden;
    border-radius: 4px;
    cursor: pointer;
}

.megabox-gallery .gallery-icon img {
    width: 100%;
    height: auto;
    display: block;
    transition: transform var(--megabox-animation-speed) ease;
}

.megabox-gallery .gallery-icon:hover img {
    transform: scale(1.05);
}

.megabox-gallery-link {
    display: block;
    position: relative;
}

.megabox-gallery-link::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0);
    transition: background var(--megabox-animation-speed) ease;
}

.megabox-gallery-link:hover::after {
    background: rgba(0, 0, 0, 0.1);
}

/* Overlay and container */
.megabox-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--megabox-overlay-bg);
    z-index: var(--megabox-z-index);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--megabox-animation-speed) ease,
                visibility var(--megabox-animation-speed) ease;
}

.megabox-overlay.megabox-active {
    opacity: 1;
    visibility: visible;
}

.megabox-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* Close button */
.megabox-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    background: var(--megabox-button-bg);
    border: none;
    border-radius: 50%;
    color: var(--megabox-text-color);
    font-size: 30px;
    line-height: 1;
    cursor: pointer;
    transition: background var(--megabox-animation-speed) ease,
                transform var(--megabox-animation-speed) ease;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.megabox-close:hover {
    background: var(--megabox-button-hover-bg);
    transform: rotate(90deg);
}

.megabox-close:focus {
    outline: 2px solid var(--megabox-text-color);
    outline-offset: 2px;
}

/* Content area */
.megabox-content {
    position: relative;
    max-width: 90vw;
    max-height: 80vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Image wrapper */
.megabox-image-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    touch-action: none;
    overflow: hidden;
}

.megabox-image {
    max-width: 90vw;
    max-height: 80vh;
    width: auto;
    height: auto;
    object-fit: contain;
    transition: transform var(--megabox-animation-speed) ease,
                opacity var(--megabox-animation-speed) ease;
    cursor: grab;
}

.megabox-image.megabox-fade-in {
    animation: megaboxFadeIn var(--megabox-animation-speed) ease forwards;
}

@keyframes megaboxFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

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

.megabox-loader.megabox-loading {
    display: block;
}

.megabox-spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: var(--megabox-text-color);
    border-radius: 50%;
    animation: megaboxSpin 1s linear infinite;
}

@keyframes megaboxSpin {
    to {
        transform: rotate(360deg);
    }
}

/* Navigation buttons */
.megabox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    background: var(--megabox-button-bg);
    border: none;
    border-radius: 50%;
    color: var(--megabox-text-color);
    cursor: pointer;
    transition: background var(--megabox-animation-speed) ease,
                transform var(--megabox-animation-speed) ease;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
}

.megabox-nav:hover {
    background: var(--megabox-button-hover-bg);
}

.megabox-nav:focus {
    outline: 2px solid var(--megabox-text-color);
    outline-offset: 2px;
}

.megabox-nav svg {
    width: 24px;
    height: 24px;
}

.megabox-prev {
    left: 20px;
}

.megabox-next {
    right: 20px;
}

/* Caption */
.megabox-caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 20px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
    color: var(--megabox-text-color);
    text-align: center;
    font-size: 16px;
    line-height: 1.5;
    display: none;
}

/* Counter */
.megabox-counter {
    position: absolute;
    top: 20px;
    left: 20px;
    color: var(--megabox-text-color);
    font-size: 16px;
    background: var(--megabox-button-bg);
    padding: 10px 20px;
    border-radius: 25px;
    backdrop-filter: blur(10px);
}

/* Thumbnails */
.megabox-thumbnails {
    position: absolute;
    padding: 10px;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.5) rgba(255, 255, 255, 0.1);
}

.megabox-thumbnails::-webkit-scrollbar {
    height: 8px;
}

.megabox-thumbnails::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.megabox-thumbnails::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.5);
    border-radius: 4px;
}

.megabox-thumbnails::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.7);
}

.megabox-thumbnails-bottom {
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--megabox-thumbnail-size) + 30px);
}

.megabox-thumbnails-top {
    top: 80px;
    left: 0;
    right: 0;
    height: calc(var(--megabox-thumbnail-size) + 30px);
}

.megabox-thumbnails-left {
    top: 80px;
    bottom: 0;
    left: 0;
    width: calc(var(--megabox-thumbnail-size) + 30px);
    overflow-x: hidden;
    overflow-y: auto;
}

.megabox-thumbnails-right {
    top: 80px;
    bottom: 0;
    right: 0;
    width: calc(var(--megabox-thumbnail-size) + 30px);
    overflow-x: hidden;
    overflow-y: auto;
}

.megabox-thumbnails-wrapper {
    display: flex;
    gap: 10px;
    padding: 5px;
}

.megabox-thumbnails-left .megabox-thumbnails-wrapper,
.megabox-thumbnails-right .megabox-thumbnails-wrapper {
    flex-direction: column;
}

.megabox-thumbnail {
    flex-shrink: 0;
    width: var(--megabox-thumbnail-size);
    height: var(--megabox-thumbnail-size);
    padding: 0;
    border: 2px solid transparent;
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    background: none;
    transition: border-color var(--megabox-animation-speed) ease,
                transform var(--megabox-animation-speed) ease;
}

.megabox-thumbnail:hover {
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(1.05);
}

.megabox-thumbnail.megabox-active {
    border-color: var(--megabox-thumbnail-border);
}

.megabox-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Responsive design */
@media (max-width: 768px) {
    .megabox-gallery .gallery-item {
        flex: 1 1 calc(50% - 10px);
    }
    
    .megabox-close {
        width: 40px;
        height: 40px;
        font-size: 24px;
        top: 10px;
        right: 10px;
    }
    
    .megabox-nav {
        width: 40px;
        height: 40px;
    }
    
    .megabox-prev {
        left: 10px;
    }
    
    .megabox-next {
        right: 10px;
    }
    
    .megabox-counter {
        top: 10px;
        left: 10px;
        font-size: 14px;
        padding: 8px 16px;
    }
    
    .megabox-caption {
        font-size: 14px;
        padding: 15px;
    }
    
    .megabox-image {
        max-width: 95vw;
        max-height: 85vh;
    }
    
    /* Hide thumbnails on mobile when on sides */
    .megabox-thumbnails-left,
    .megabox-thumbnails-right {
        display: none;
    }
}

@media (max-width: 480px) {
    .megabox-gallery .gallery-item {
        flex: 1 1 100%;
    }
}

/* Accessibility */
.megabox-overlay:focus-within {
    outline: none;
}

.megabox-nav:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Print styles */
@media print {
    .megabox-overlay {
        display: none !important;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .megabox-close,
    .megabox-nav {
        background: #000;
        color: #fff;
        border: 2px solid #fff;
    }
    
    .megabox-close:hover,
    .megabox-nav:hover {
        background: #fff;
        color: #000;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}