/**
 * Frontend Gallery Styles
 * Masonry layout with Litespeed optimization
 */

/* Critical overrides for page builder compatibility */
.pps-gallery-container,
.pps-gallery-container * {
    box-sizing: border-box;
}

/* Force override page builder inline styles */
.pps-gallery-container img,
.pps-photo-card img,
.pps-photo-image img,
.pps-gallery-img {
    width: 100% !important;
    height: auto !important;
    max-width: none !important;
    min-width: auto !important;
    max-height: none !important;
    min-height: auto !important;
    object-fit: cover !important;
    aspect-ratio: auto !important;
}

/* Specific override for the exact issue: 80px width, 200px height */
.pps-gallery-container img[style*="width: 80px"],
.pps-gallery-container img[style*="width:80px"],
.pps-photo-card img[style*="width: 80px"],
.pps-photo-card img[style*="width:80px"],
.pps-photo-image img[style*="width: 80px"],
.pps-photo-image img[style*="width:80px"],
.pps-gallery-img[style*="width: 80px"],
.pps-gallery-img[style*="width:80px"] {
    width: 100% !important;
    height: auto !important;
}

/* Override height: 200px specifically */
.pps-gallery-container img[style*="height: 200px"],
.pps-gallery-container img[style*="height:200px"],
.pps-photo-card img[style*="height: 200px"],
.pps-photo-card img[style*="height:200px"],
.pps-photo-image img[style*="height: 200px"],
.pps-photo-image img[style*="height:200px"],
.pps-gallery-img[style*="height: 200px"],
.pps-gallery-img[style*="height:200px"] {
    height: auto !important;
}

.pps-gallery-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.pps-gallery-header {
    text-align: center;
    margin-bottom: 30px;
    padding: 20px 0;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.pps-gallery-title {
    font-size: 2.5rem;
    color: #2c3e50;
    margin: 0 0 10px 0;
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    line-height: 1.2;
}

.pps-gallery-subtitle {
    font-size: 1.1rem;
    color: #7f8c8d;
    margin: 0;
}

.pps-gallery-filters {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.pps-filter-btn {
    padding: 10px 20px;
    border: 2px solid #e0e0e0;
    background: white;
    color: #555;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
    font-size: 0.9rem;
}

.pps-filter-btn:hover {
    border-color: #667eea;
    color: #667eea;
    transform: translateY(-2px);
}

.pps-filter-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-color: transparent;
    color: white;
}

.pps-masonry-container {
    margin-bottom: 40px;
}

.pps-masonry-grid {
    column-count: 4;
    column-gap: 20px;
    column-fill: balance;
}

/* Responsive column adjustments */
@media (max-width: 1200px) {
    .pps-masonry-grid {
        column-count: 3;
    }
}

@media (max-width: 768px) {
    .pps-masonry-grid {
        column-count: 2;
        column-gap: 15px;
    }
    
    .pps-gallery-img {
        min-height: 180px !important;
        max-height: 300px !important;
        width: 100% !important;
        height: auto !important;
    }
    
    /* Force override any page builder styles on tablets */
    .pps-gallery-container * img,
    .pps-photo-card * img {
        width: 100% !important;
        height: auto !important;
        min-width: auto !important;
        max-width: none !important;
        object-fit: cover !important;
    }
}

@media (max-width: 480px) {
    .pps-masonry-grid {
        column-count: 1;
    }
    
    .pps-gallery-img {
        min-height: 250px !important;
        max-height: 350px !important;
        width: 100% !important;
        height: auto !important;
    }
    
    /* Force override any page builder styles on mobile */
    .pps-gallery-container * img,
    .pps-photo-card * img {
        width: 100% !important;
        height: auto !important;
        min-width: auto !important;
        max-width: none !important;
        object-fit: cover !important;
    }
}

.pps-photo-item {
    break-inside: avoid;
    margin-bottom: 20px;
    display: inline-block;
    width: 100%;
}

.pps-photo-card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    transition: all 0.3s ease;
    position: relative;
}

.pps-photo-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.pps-photo-image {
    position: relative;
    overflow: hidden;
    border-radius: 12px 12px 0 0;
}

.pps-gallery-img {
    width: 100% !important;
    height: auto !important;
    min-height: 200px !important;
    max-height: 400px !important;
    display: block;
    transition: transform 0.3s ease;
    object-fit: cover;
    border-radius: 12px 12px 0 0;
}

.pps-photo-card:hover .pps-gallery-img {
    transform: scale(1.05);
}

.pps-photo-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    border-radius: 12px 12px 0 0;
}

.pps-photo-card:hover .pps-photo-overlay {
    opacity: 1;
}

.pps-photo-actions {
    display: flex;
    gap: 15px;
}

.pps-view-fullscreen,
.pps-download-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: none;
    background: white;
    color: #333;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    text-decoration: none;
}

.pps-view-fullscreen:hover,
.pps-download-btn:hover {
    background: #667eea;
    color: white;
    transform: scale(1.1);
}

.pps-photo-meta {
    padding: 15px;
}

.pps-entity-info {
    text-align: center;
}

.pps-entity-name {
    display: block;
    font-weight: 600;
    color: #2c3e50;
    font-size: 1rem;
    margin-bottom: 5px;
}

.pps-entity-type {
    display: inline-block;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 4px 12px;
    border-radius: 15px;
    font-size: 0.8rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pps-load-more-container {
    text-align: center;
    margin: 40px 0;
}

.pps-load-more-btn {
    padding: 15px 30px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 30px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.pps-load-more-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
}

.pps-load-more-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.pps-loading-spinner {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.pps-no-photos {
    text-align: center;
    padding: 60px 20px;
    color: #7f8c8d;
    font-size: 1.1rem;
}

.pps-gallery-footer {
    text-align: center;
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid #e0e0e0;
}

.pps-gallery-attribution {
    color: #7f8c8d;
    font-size: 0.9rem;
    margin: 0;
}

/* Fullscreen Modal */
.pps-fullscreen-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow-y: auto;
}

.pps-fullscreen-modal.active {
    display: flex;
}

/* Better body scroll handling when modal is open */
body.modal-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
}

.pps-modal-content {
    max-width: 90vw;
    max-height: 90vh;
    position: relative;
    margin-bottom: 100px; /* Extra space for caption */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.pps-modal-image {
    max-width: 100%;
    max-height: calc(90vh - 120px); /* Account for caption space */
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 8px;
}

.pps-modal-info {
    position: absolute;
    bottom: 20px;
    left: 0;
    right: 0;
    text-align: center;
    color: white;
    padding: 15px 20px;
    min-height: 60px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 8px;
    margin: 0 20px;
}

.pps-modal-entity-name {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 5px;
    word-wrap: break-word;
    line-height: 1.3;
}

.pps-modal-entity-type {
    font-size: 0.9rem;
    opacity: 0.8;
    word-wrap: break-word;
}

.pps-modal-close {
    position: absolute;
    top: -50px;
    right: 0;
    background: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Mobile responsive adjustments for modal */
@media (max-width: 768px) {
    .pps-modal-content {
        max-width: 95vw;
        max-height: 85vh;
        margin-bottom: 120px; /* More space on mobile */
    }
    
    .pps-modal-image {
        max-height: calc(85vh - 140px); /* More space for caption on mobile */
    }
    
    .pps-modal-info {
        bottom: 15px;
        padding: 12px 15px;
        margin: 0 15px;
    }
    
    .pps-modal-entity-name {
        font-size: 1.1rem;
        line-height: 1.4;
    }
    
    .pps-modal-entity-type {
        font-size: 0.85rem;
    }
}

/* Portrait orientation adjustments */
@media (max-width: 768px) and (orientation: portrait) {
    .pps-modal-content {
        max-height: 80vh;
        margin-bottom: 140px;
    }
    
    .pps-modal-image {
        max-height: calc(80vh - 160px);
        max-width: 95vw;
    }
}

/* Litespeed optimization styles */
.pps-gallery-img[data-src] {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.pps-gallery-img[data-src].loaded {
    opacity: 1;
}

/* Loading skeleton */
.pps-photo-skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: 12px;
    height: 200px;
    margin-bottom: 20px;
}

@keyframes loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Override page builder styles */
.pps-gallery-container img,
.pps-photo-card img,
.pps-photo-image img,
.pps-gallery-img {
    width: 100% !important;
    height: auto !important;
    min-width: auto !important;
    max-width: none !important;
}

.pps-gallery-container .pps-photo-card,
.pps-photo-item .pps-photo-card {
    width: 100% !important;
}

/* Accessibility improvements */
.pps-gallery-container:focus-within {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

.pps-filter-btn:focus,
.pps-load-more-btn:focus,
.pps-view-fullscreen:focus,
.pps-download-btn:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* Print styles */
@media print {
    .pps-gallery-filters,
    .pps-load-more-container,
    .pps-photo-overlay {
        display: none !important;
    }
    
    .pps-masonry-grid {
        column-count: 2 !important;
    }
    
    .pps-photo-card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ddd;
    }
}
