/**
 * Frontend CSS
 * 
 * @package IV_Gallery
 */

/* CSS Variables */
:root {
    --iv-gallery-cols-desktop: 4;
    --iv-gallery-cols-tablet: 3;
    --iv-gallery-cols-mobile: 2;
    --iv-gallery-gap: 15px;
    --iv-gallery-border-radius: 8px;
    --iv-gallery-primary-color: #93172f;
    --iv-gallery-hover-color: #720d21;
    --iv-gallery-overlay-bg: rgba(0, 0, 0, 0.9);
}

/* Gallery Container */
.iv-gallery-container {
    margin: 20px 0;
    clear: both;
}

.iv-gallery-description {
    margin-bottom: 20px;
    color: #666;
    font-size: 16px;
    line-height: 1.6;
}

/* Gallery Tabs */
.iv-gallery-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 2px solid #e5e5e5;
}

.iv-gallery-tab {
    background: none;
    border: none;
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 600;
    color: #666;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: all 0.3s ease;
}

.iv-gallery-tab:hover {
    color: var(--iv-gallery-primary-color);
}

.iv-gallery-tab.active {
    color: var(--iv-gallery-primary-color);
    border-bottom-color: var(--iv-gallery-primary-color);
}

.iv-gallery-tab:focus {
    outline: 2px solid var(--iv-gallery-primary-color);
    outline-offset: 4px;
}

/* Gallery Grid */
.iv-gallery-grid {
    display: grid;
    gap: var(--iv-gallery-gap);
    grid-template-columns: repeat(var(--iv-gallery-cols-desktop), 1fr);
}

.iv-gallery-grid[data-cols="1"] { grid-template-columns: repeat(1, 1fr) !important; }
.iv-gallery-grid[data-cols="2"] { grid-template-columns: repeat(2, 1fr) !important; }
.iv-gallery-grid[data-cols="3"] { grid-template-columns: repeat(3, 1fr) !important; }
.iv-gallery-grid[data-cols="4"] { grid-template-columns: repeat(4, 1fr) !important; }
.iv-gallery-grid[data-cols="5"] { grid-template-columns: repeat(5, 1fr) !important; }
.iv-gallery-grid[data-cols="6"] { grid-template-columns: repeat(6, 1fr) !important; }

.iv-gallery-grid .iv-gallery-item {
    height: 200px !important;
    width: 100% !important;
}

/* Masonry Layout */
.iv-gallery-layout-masonry {
    column-count: var(--iv-gallery-cols-desktop);
    column-gap: var(--iv-gallery-gap);
}

.iv-gallery-layout-masonry .iv-gallery-item {
    break-inside: avoid;
    margin-bottom: var(--iv-gallery-gap);
}

/* Justified Layout */
.iv-gallery-layout-justified {
    display: flex;
    flex-wrap: wrap;
    gap: var(--iv-gallery-gap);
}

.iv-gallery-layout-justified .iv-gallery-item {
    flex-grow: 1;
    height: 250px;
}

/* Gallery Item */
.iv-gallery-item {
    position: relative;
    overflow: hidden;
    border-radius: var(--iv-gallery-border-radius);
    background: #f5f5f5;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    height: 300px; /* Fixed height for all items */
    width: 100%; /* Force width */
}

.iv-gallery-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
}

.iv-gallery-item:focus-within {
    outline: 3px solid var(--iv-gallery-primary-color);
    outline-offset: 2px;
}

/* Gallery Link */
.iv-gallery-link {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    text-decoration: none;
    color: inherit;
    line-height: 0;
    height: 100%;
    width: 100%;
    overflow: hidden;
}

.iv-gallery-link:focus {
    outline: none;
}

/* Gallery Item Inner */
.iv-gallery-item-inner {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* Gallery Image */
.iv-gallery-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
    display: block;
    object-fit: cover !important;
    object-position: center !important;
    transition: transform 0.3s ease;
    background: #f5f5f5;
}

.iv-gallery-item:hover .iv-gallery-image {
    transform: scale(1.05);
}

/* Video Placeholder */
.iv-gallery-video-placeholder {
    width: 100%;
    height: 250px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.iv-gallery-video-placeholder .dashicons {
    font-size: 64px;
    width: 64px;
    height: 64px;
    color: rgba(255, 255, 255, 0.9);
}

/* Play Icon Overlay */
.iv-gallery-play-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    pointer-events: none;
}

.iv-gallery-item:hover .iv-gallery-play-icon {
    background: var(--iv-gallery-primary-color);
    transform: translate(-50%, -50%) scale(1.1);
}

.iv-gallery-play-icon .dashicons {
    font-size: 32px;
    width: 32px;
    height: 32px;
    color: #fff;
    margin-left: 3px;
}

/* Caption */
.iv-gallery-caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
    color: #fff;
    padding: 30px 15px 15px;
    font-size: 14px;
    line-height: 1.4;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.iv-gallery-item:hover .iv-gallery-caption {
    opacity: 1;
}

/* Load More Button */
.iv-gallery-load-more-wrap {
    text-align: center;
    margin-top: 30px;
}

.iv-gallery-load-more,
.iv-gallery-show-less {
    background: var(--iv-gallery-primary-color);
    color: #fff;
    border: none;
    padding: 12px 32px;
    font-size: 16px;
    font-weight: 600;
    border-radius: var(--iv-gallery-border-radius);
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.iv-gallery-load-more:hover,
.iv-gallery-show-less:hover {
    background: var(--iv-gallery-hover-color);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 115, 170, 0.3);
}

.iv-gallery-show-less {
    background: #666;
}

.iv-gallery-show-less:hover {
    background: #444;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.iv-gallery-load-more:disabled,
.iv-gallery-show-less:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

.iv-gallery-load-more:focus,
.iv-gallery-show-less:focus {
    outline: 3px solid var(--iv-gallery-primary-color);
    outline-offset: 4px;
}

/* Spinner */
.iv-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top: 2px solid #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Lightbox */
.iv-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Multi-gallery lightbox has higher priority */
.iv-lightbox-v2 {
    z-index: 9999999 !important;
}

.iv-lightbox-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--iv-gallery-overlay-bg);
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.iv-lightbox-content {
    position: relative;
    width: 90%;
    height: 90%;
    max-width: 1200px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    z-index: 1;
    animation: zoomIn 0.3s ease;
}

@keyframes zoomIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Lightbox Controls */
.iv-lightbox-close,
.iv-lightbox-prev,
.iv-lightbox-next {
    position: absolute;
    background: rgba(255, 255, 255, 0.95);
    border: none;
    color: #333;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
}

.iv-lightbox-close:hover,
.iv-lightbox-prev:hover,
.iv-lightbox-next:hover {
    background: #fff;
    transform: scale(1.15);
    box-shadow: 0 6px 30px rgba(0, 0, 0, 0.6);
}

.iv-lightbox-close {
    top: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
}

.iv-lightbox-close .dashicons {
    font-size: 28px;
    width: 28px;
    height: 28px;
    color: #333;
}

.iv-lightbox-prev,
.iv-lightbox-next {
    top: 50%;
    transform: translateY(-50%);
    width: 70px;
    height: 70px;
    border-radius: 50%;
}

.iv-lightbox-prev:hover,
.iv-lightbox-next:hover {
    transform: translateY(-50%) scale(1.15);
}

.iv-lightbox-prev {
    left: 30px;
}

.iv-lightbox-next {
    right: 30px;
}

.iv-lightbox-prev .dashicons,
.iv-lightbox-next .dashicons {
    font-size: 40px;
    width: 40px;
    height: 40px;
    color: #333;
    font-weight: bold;
}

/* Lightbox Media Container */
.iv-lightbox-media-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 100px 80px;
    overflow: hidden;
}

.iv-lightbox-media {
    max-width: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.iv-lightbox-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.iv-lightbox-image.loaded {
    opacity: 1;
}

.iv-lightbox-media iframe,
.iv-lightbox-media video {
    max-width: 100%;
    max-height: 100%;
    width: 100%;
    height: 100%;
}

/* Lightbox Info */
.iv-lightbox-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.8);
    padding: 20px 100px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.iv-lightbox-caption {
    color: #fff;
    font-size: 16px;
    line-height: 1.5;
    flex: 1;
}

.iv-lightbox-counter {
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
    font-weight: 600;
    margin-left: 20px;
}

/* Lightbox Share */
.iv-lightbox-share {
    display: none !important; /* Hidden as per user request */
    position: absolute;
    right: 30px;
    top: 50%;
    transform: translateY(-50%);
    flex-direction: column;
    gap: 12px;
    z-index: 10;
}

.iv-share-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.iv-share-btn {
    width: 56px;
    height: 56px;
    background: rgba(255, 255, 255, 0.95);
    border: none;
    border-radius: 50%;
    color: #333;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    position: relative;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
}

.iv-share-btn:hover {
    background: var(--iv-gallery-primary-color);
    color: #fff;
    transform: scale(1.15);
    box-shadow: 0 6px 30px rgba(0, 0, 0, 0.6);
}

.iv-share-btn .dashicons {
    font-size: 24px;
    width: 24px;
    height: 24px;
}

.iv-share-btn:hover .dashicons {
    color: #fff;
}

.iv-share-label {
    position: absolute;
    right: 70px;
    background: rgba(0, 0, 0, 0.9);
    color: #fff;
    padding: 10px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.iv-share-btn:hover .iv-share-label {
    opacity: 1;
}

/* Body Lock */
body.iv-lightbox-open {
    overflow: hidden;
}

/* Empty State */
.iv-gallery-empty,
.iv-gallery-error {
    padding: 40px 20px;
    text-align: center;
    color: #999;
    font-style: italic;
    background: #f9f9f9;
    border-radius: var(--iv-gallery-border-radius);
}

.iv-gallery-error {
    color: #c00;
    background: #ffe5e5;
}

/* Tablet Styles */
@media screen and (max-width: 1024px) {
    .iv-gallery-grid {
        grid-template-columns: repeat(var(--iv-gallery-cols-tablet), 1fr);
    }
    
    .iv-gallery-layout-masonry {
        column-count: var(--iv-gallery-cols-tablet);
    }
    
    .iv-lightbox-media-container {
        padding: 60px 80px;
    }
    
    .iv-lightbox-info {
        padding: 15px 80px;
    }
    
    .iv-lightbox-prev {
        left: 15px;
    }
    
    .iv-lightbox-next {
        right: 15px;
    }
}

/* Mobile Styles */
@media screen and (max-width: 768px) {
    .iv-gallery-grid {
        grid-template-columns: repeat(var(--iv-gallery-cols-mobile), 1fr);
    }
    
    .iv-gallery-layout-masonry {
        column-count: var(--iv-gallery-cols-mobile);
    }
    
    .iv-gallery-item {
        height: 250px; /* Smaller height on mobile */
    }
    
    .iv-gallery-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .iv-gallery-tab {
        padding: 10px 20px;
        font-size: 14px;
    }
    
    .iv-gallery-play-icon {
        width: 50px;
        height: 50px;
    }
    
    .iv-gallery-play-icon .dashicons {
        font-size: 24px;
        width: 24px;
        height: 24px;
    }
    
    /* Lightbox Mobile */
    .iv-lightbox-content {
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100vh;
    }
    
    .iv-lightbox-media-container {
        padding: 80px 20px 100px;
    }
    
    .iv-lightbox-info {
        padding: 15px 20px;
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .iv-lightbox-counter {
        margin-left: 0;
    }
    
    .iv-lightbox-close {
        top: 10px;
        right: 10px;
        width: 40px;
        height: 40px;
    }
    
    .iv-lightbox-prev,
    .iv-lightbox-next {
        width: 40px;
        height: 40px;
        bottom: 20px;
        top: auto;
        transform: none;
    }
    
    .iv-lightbox-prev {
        left: 20px;
    }
    
    .iv-lightbox-next {
        right: 20px;
    }
    
    .iv-lightbox-prev .dashicons,
    .iv-lightbox-next .dashicons {
        font-size: 24px;
        width: 24px;
        height: 24px;
    }
    
    .iv-lightbox-share {
        position: static;
        transform: none;
        flex-direction: row;
        justify-content: center;
        padding: 15px;
        background: rgba(0, 0, 0, 0.8);
    }
    
    .iv-share-buttons {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .iv-share-btn {
        width: 44px;
        height: 44px;
    }
    
    .iv-share-label {
        display: none;
    }
}

/* Small Mobile */
@media screen and (max-width: 480px) {
    :root {
        --iv-gallery-gap: 10px;
    }
    
    .iv-gallery-grid[data-cols-mobile="1"] {
        grid-template-columns: 1fr;
    }
    
    .iv-gallery-item {
        height: 200px; /* Even smaller on small screens */
    }
    
    .iv-gallery-load-more,
    .iv-gallery-show-less {
        padding: 10px 24px;
        font-size: 14px;
    }
    
    .iv-gallery-item:hover {
        transform: none;
    }
    
    .iv-gallery-caption {
        opacity: 1;
        background: linear-gradient(to top, rgba(0, 0, 0, 0.9), transparent);
        padding: 40px 10px 10px;
        font-size: 12px;
    }
}

/* Print Styles */
@media print {
    .iv-gallery-tabs,
    .iv-gallery-load-more-wrap,
    .iv-gallery-play-icon,
    .iv-lightbox {
        display: none !important;
    }
    
    .iv-gallery-item {
        break-inside: avoid;
        page-break-inside: avoid;
    }
    
    .iv-gallery-caption {
        opacity: 1;
        position: static;
        background: none;
        color: #000;
    }
}

/* Accessibility */
.iv-gallery-item:focus-visible,
.iv-gallery-link:focus-visible {
    outline: 3px solid var(--iv-gallery-primary-color);
    outline-offset: 2px;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .iv-gallery-item {
        border: 2px solid currentColor;
    }
    
    .iv-gallery-play-icon {
        border: 2px solid #fff;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .iv-gallery-item {
        background: #2a2a2a;
    }
    
    .iv-gallery-tab {
        color: #ccc;
    }
    
    .iv-gallery-tab:hover,
    .iv-gallery-tab.active {
        color: #fff;
    }
    
    .iv-gallery-empty,
    .iv-gallery-description {
        color: #ccc;
    }
}