/* ========================================
   GALLERY STYLES - Kaiapoi Community
   Comprehensive gallery styling with responsive design
   ======================================== */

/* ========================
   CSS VARIABLES & IMPORTS
   ======================== */

/* Import existing design system */
@import url('global.css');

/* Gallery-specific variables */
:root {
    /* Gallery Layout */
    --gallery-max-width: 1400px;
    --gallery-padding: 20px;
    --gallery-gap: 24px;
    --gallery-item-min-width: 280px;
    --gallery-item-aspect-ratio: 4/3;

    /* Category Navigation */
    --category-nav-height: 60px;
    --category-btn-padding: 12px 24px;
    --category-btn-border-radius: 30px;
    --category-btn-gap: 12px;

    /* Image Presentation */
    --image-border-radius: 12px;
    --image-overlay-bg: rgba(var(--primary-rgb), 0.8);
    --image-overlay-text: rgba(var(--white-rgb), 0.95);
    --image-hover-scale: 1.05;
    --image-hover-shadow: var(--shadow-large);

    /* Lightbox Modal */
    --lightbox-bg: rgba(var(--black-rgb), 0.95);
    --lightbox-close-size: 48px;
    --lightbox-nav-size: 60px;
    --lightbox-nav-bg: rgba(var(--white-rgb), 0.1);
    --lightbox-nav-hover-bg: rgba(var(--white-rgb), 0.2);

    /* Loading States */
    --skeleton-bg: var(--gray-lighter-border);
    --skeleton-shimmer: linear-gradient(90deg, var(--gray-lighter-border) 25%, var(--gray-light-bg) 50%, var(--gray-lighter-border) 75%);

    /* Transitions */
    --transition-fast: 0.2s ease;
    --transition-medium: 0.3s ease;
    --transition-slow: 0.5s ease;

    /* Responsive Breakpoints */
    --bp-mobile: 480px;
    --bp-tablet: 768px;
    --bp-desktop: 1024px;
    --bp-large: 1200px;
}

/* ========================
   GALLERY BODY OVERRIDES
   ======================== */

/* Override global body centering for gallery pages */
body {
    align-items: flex-start !important;
    justify-content: flex-start !important;
}

/* Ensure gallery container uses full width */
.gallery-container {
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding-left: 20px !important;
    padding-right: 20px !important;
    box-sizing: border-box !important;
}

/* Override section centering that affects gallery grid */
.gallery-container section {
    max-width: none !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    align-items: flex-start !important;
    justify-content: flex-start !important;
}

/* Ensure gallery grid uses full width properly */
.gallery-grid {
    width: 100% !important;
    max-width: none !important;
    margin: 0 auto !important;
    padding: 0 20px !important;
    box-sizing: border-box !important;
    display: grid !important;
    grid-template-columns: repeat(auto-fill, minmax(var(--gallery-item-min-width), 1fr)) !important;
    gap: var(--gallery-gap) !important;
    justify-items: center !important;
    align-items: start !important;
}

/* Ensure gallery items are properly sized and centered */
.gallery-item {
    width: 100% !important;
    max-width: 350px !important;
    margin: 0 auto !important;
    justify-self: center !important;
}

/* ========================
   GALLERY CONTAINER
   ======================== */

.gallery-container {
    max-width: var(--gallery-max-width);
    margin: 0 auto;
    padding: var(--gallery-padding);
    background-color: var(--background-color);
    min-height: 100vh;
}

/* ========================
   GALLERY HEADER
   ======================== */

.gallery-header {
    text-align: center;
    margin-bottom: 40px;
    padding: 40px 0;
}

.gallery-header h1 {
    font-family: var(--font-family-sans-serif);
    font-size: clamp(2rem, 5vw, 3.5rem);
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 16px;
    text-shadow: var(--shadow-small);
}

.gallery-header p {
    font-size: 1.1rem;
    color: var(--text-color2);
    max-width: 600px;
    margin: 0 auto;
    line-height: 1.6;
}

/* ========================
   BREADCRUMB NAVIGATION
   ======================== */

.breadcrumb {
    font-size: 0.9rem;
    color: var(--gray-medium);
    margin-bottom: 24px;
    font-weight: 500;
}

.breadcrumb a {
    color: var(--primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.breadcrumb a:hover {
    color: var(--secondary);
    text-decoration: underline;
}

/* ========================
   CATEGORY NAVIGATION
   ======================== */

.category-navigation {
    margin-bottom: 40px;
    padding: 0 20px;
}

.category-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: var(--category-btn-gap);
    justify-content: center;
    align-items: center;
    min-height: var(--category-nav-height);
    padding: 16px;
    background: rgba(var(--white-rgb), 0.8);
    border-radius: 16px;
    box-shadow: var(--shadow-small);
    backdrop-filter: blur(10px);
}

.category-btn {
    position: relative;
    padding: var(--category-btn-padding);
    background: var(--background-color);
    border: 2px solid var(--gray-light-border);
    border-radius: var(--category-btn-border-radius);
    color: var(--text-color);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.95rem;
    transition: all var(--transition-medium);
    white-space: nowrap;
    overflow: hidden;
    z-index: 1;
}

.category-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(var(--white-rgb), 0.3), transparent);
    transition: left var(--transition-slow);
    z-index: -1;
}

.category-btn:hover {
    background: var(--secondary);
    color: var(--white);
    border-color: var(--secondary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

.category-btn:hover::before {
    left: 100%;
}

.category-btn.active {
    background: var(--primary);
    color: var(--white);
    border-color: var(--primary);
    font-weight: 600;
    box-shadow: var(--shadow-medium);
}

.category-btn:focus {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

/* ========================
   GALLERY GRID SYSTEM
   ======================== */

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--gallery-item-min-width), 1fr));
    gap: var(--gallery-gap);
    margin-bottom: 60px;
    padding: 0 20px;
}

/* ========================
   GALLERY ITEMS
   ======================== */

.gallery-item {
    position: relative;
    background: var(--white);
    border-radius: var(--image-border-radius);
    box-shadow: var(--shadow-small);
    overflow: hidden;
    transition: all var(--transition-medium);
    cursor: pointer;
    aspect-ratio: var(--gallery-item-aspect-ratio);
}

.gallery-item:hover {
    transform: translateY(-8px) scale(var(--image-hover-scale));
    box-shadow: var(--image-hover-shadow);
}

.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform var(--transition-slow);
}

.gallery-item:hover img {
    transform: scale(1.1);
}

/* ========================
   GALLERY ITEM OVERLAY
   ======================== */

.gallery-item-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 20px;
    background: var(--image-overlay-bg);
    backdrop-filter: blur(8px);
    color: var(--image-overlay-text);
    transform: translateY(100%);
    transition: transform var(--transition-medium);
}

.gallery-item:hover .gallery-item-info {
    transform: translateY(0);
}

.gallery-item-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 8px;
    line-height: 1.3;
}

.gallery-item-category {
    font-size: 0.85rem;
    opacity: 0.9;
    font-weight: 400;
}

/* ========================
   LIGHTBOX MODAL
   ======================== */

.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: var(--lightbox-bg);
    backdrop-filter: blur(8px);
    animation: modalFadeIn var(--transition-medium) ease-out;
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: var(--image-border-radius);
    box-shadow: 0 20px 40px rgba(var(--black-rgb), 0.3);
    animation: modalContentScale var(--transition-medium) ease-out;
}

.modal-close {
    position: absolute;
    top: 20px;
    right: 20px;
    color: var(--white);
    font-size: var(--lightbox-close-size);
    font-weight: bold;
    cursor: pointer;
    width: var(--lightbox-close-size);
    height: var(--lightbox-close-size);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--lightbox-nav-bg);
    border-radius: 50%;
    transition: all var(--transition-fast);
    z-index: 2001;
}

.modal-close:hover {
    background: var(--lightbox-nav-hover-bg);
    transform: scale(1.1);
}

/* ========================
   LIGHTBOX NAVIGATION
   ======================== */

.modal-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: var(--lightbox-nav-bg);
    border: none;
    color: var(--white);
    width: var(--lightbox-nav-size);
    height: var(--lightbox-nav-size);
    border-radius: 50%;
    cursor: pointer;
    font-size: 24px;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-nav:hover {
    background: var(--lightbox-nav-hover-bg);
    transform: translateY(-50%) scale(1.1);
}

.modal-prev {
    left: 20px;
}

    .modal-next {
        right: 20px;
}

/* ========================
   MODAL COUNTER
   ======================== */

.modal-counter {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--lightbox-nav-bg);
    color: var(--white);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 500;
    backdrop-filter: blur(8px);
    z-index: 2001;
}

/* ========================
   LOADING STATES
   ======================== */

.gallery-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px;
    color: var(--text-color2);
    font-size: 1.1rem;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--gray-light-border);
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 16px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Skeleton Loading */
.gallery-item-skeleton {
    animation: skeletonPulse 1.5s ease-in-out infinite;
}

.gallery-item-skeleton .skeleton-image {
    height: 200px;
    background: var(--skeleton-bg);
    background: var(--skeleton-shimmer);
    background-size: 200% 100%;
    animation: skeletonShimmer 1.5s infinite;
}

.gallery-item-skeleton .skeleton-title {
    height: 20px;
    background: var(--skeleton-bg);
    margin: 16px 16px 8px;
    border-radius: 4px;
}

.gallery-item-skeleton .skeleton-category {
    height: 16px;
    background: var(--skeleton-bg);
    margin: 0 16px 16px;
    border-radius: 4px;
    width: 60%;
}

@keyframes skeletonPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

@keyframes skeletonShimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* ========================
   NO IMAGES STATE
   ======================== */

.no-images {
    text-align: center;
    padding: 80px 40px;
    color: var(--text-color2);
    background: var(--white);
    border-radius: var(--image-border-radius);
    box-shadow: var(--shadow-small);
    margin: 40px auto;
    max-width: 600px;
}

.no-images h3 {
    color: var(--primary);
    margin-bottom: 16px;
    font-size: 1.5rem;
}

.no-images p {
    margin-bottom: 16px;
    line-height: 1.6;
}

.no-images a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    transition: color var(--transition-fast);
}

.no-images a:hover {
    color: var(--secondary);
    text-decoration: underline;
}

/* ========================
   ANIMATIONS
   ======================== */

@keyframes modalFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes modalContentScale {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========================
   RESPONSIVE DESIGN
   ======================== */

/* Mobile First - Base styles above are mobile */

/* ========================
   RESPONSIVE OVERRIDES
   ======================== */

/* Small Mobile */
@media (max-width: 480px) {
    .gallery-container {
        padding: 16px;
    }

    .gallery-header {
        padding: 24px 0;
        margin-bottom: 24px;
    }

    .category-navigation {
        padding: 0 16px;
    }

    .category-buttons {
        padding: 12px;
        gap: 8px;
        flex-direction: column;
        align-items: stretch;
    }

    .category-btn {
        padding: 12px 20px;
        text-align: center;
        border-radius: 25px;
    }

    .gallery-grid {
        grid-template-columns: 1fr;
        gap: 16px;
        padding: 0 16px;
    }

    .gallery-item {
        aspect-ratio: 3/2;
    }

    .gallery-item-info {
        padding: 16px;
    }

    .gallery-item-title {
        font-size: 1rem;
    }

    .gallery-item-category {
        font-size: 0.8rem;
    }

    .modal-close {
        top: 16px;
        right: 16px;
        width: 40px;
        height: 40px;
        font-size: 32px;
    }

    .modal-nav {
        width: 48px;
        height: 48px;
        font-size: 20px;
    }

    .modal-prev {
        left: 16px;
    }

    .modal-next {
        right: 16px;
    }

    /* Mobile-specific overrides for gallery width fix */
    .gallery-container {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }

    .gallery-grid {
        padding: 0 16px !important;
        gap: 16px !important;
        grid-template-columns: 1fr !important;
    }

    .gallery-item {
        max-width: none !important;
    }
}

/* Tablet */
@media (min-width: 481px) and (max-width: 768px) {
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
        gap: 20px;
    }

    .category-buttons {
        gap: 10px;
    }

    .category-btn {
        padding: 10px 20px;
        font-size: 0.9rem;
    }

    /* Tablet-specific overrides for gallery width fix */
    .gallery-container {
        padding-left: 20px !important;
        padding-right: 20px !important;
    }

    .gallery-grid {
        padding: 0 20px !important;
        gap: 20px !important;
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)) !important;
    }
}

/* Desktop */
@media (min-width: 769px) and (max-width: 1024px) {
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
        gap: 24px;
    }
}

/* Large Desktop */
@media (min-width: 1025px) {
    .gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
        gap: 28px;
    }

    .gallery-container {
        padding: 32px;
    }
}

/* ========================
   ACCESSIBILITY FEATURES
   ======================== */

/* Focus styles for keyboard navigation */
.category-btn:focus-visible,
.gallery-item:focus-visible,
.modal-close:focus-visible,
.modal-nav:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .category-btn {
        border-width: 3px;
    }

    .gallery-item {
        border: 2px solid var(--text-color);
    }

    .modal {
        background: var(--black);
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .gallery-item:hover {
        transform: none;
    }

    .gallery-item:hover img {
        transform: none;
    }
}

/* Dark mode support (if implemented) */
@media (prefers-color-scheme: dark) {
    .gallery-container {
        background-color: var(--gray-dark-alt);
    }

    .category-buttons {
        background: rgba(68, 74, 84, 0.8);
    }

    .gallery-item {
        background: var(--gray-dark);
    }

    .gallery-item-info {
        background: rgba(0, 0, 0, 0.8);
    }
}

/* ========================
   PRINT STYLES
   ======================== */

@media print {
    .category-navigation,
    .modal,
    .modal-close,
    .modal-nav {
        display: none !important;
    }

    .gallery-container {
        max-width: none;
        padding: 0;
        background: var(--white);
    }

    .gallery-grid {
        display: block;
        padding: 0;
    }

    .gallery-item {
        page-break-inside: avoid;
        margin-bottom: 20px;
        box-shadow: none;
        border: 1px solid var(--gray-light);
    }

    .gallery-item-info {
        position: static;
        background: var(--white);
        color: var(--black);
        transform: none;
    }
}

/* ========================
   PERFORMANCE OPTIMIZATIONS
   ======================== */

/* GPU acceleration for smooth animations */
.gallery-item,
.category-btn,
.modal-content,
.modal-nav {
    will-change: transform;
}

/* Optimize font rendering */
.gallery-header h1,
.category-btn,
.gallery-item-title {
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Contain layout shifts */
.gallery-item {
    contain: layout style paint;
}

/* ========================
   ADVANCED FEATURES
   ======================== */

/* Lazy loading support */
.gallery-item img[loading="lazy"] {
    opacity: 0;
    transition: opacity var(--transition-medium);
}

.gallery-item img[loading="lazy"].loaded {
    opacity: 1;
}

/* Intersection observer animation */
.gallery-item.animate-in {
    animation: fadeInUp var(--transition-medium) ease-out;
}

/* Filter effects for categories */
.category-filter-active .gallery-item:not(.category-match) {
    opacity: 0.3;
    pointer-events: none;
}

/* Search functionality support */
.gallery-search-highlight {
    background: rgba(var(--yellow-warning-rgb), 0.3);
    padding: 2px 4px;
    border-radius: 4px;
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .gallery-item-info {
        transform: translateY(0);
        background: rgba(var(--primary-rgb), 0.9);
    }

    .category-btn {
        min-height: 44px; /* Touch target size */
        min-width: 44px;
    }
}

/* High DPI display optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .gallery-item img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* ========================
   UTILITY CLASSES
   ======================== */

.gallery-hidden {
    display: none !important;
}

.gallery-fade-in {
    animation: fadeInUp var(--transition-medium) ease-out;
}

.gallery-slide-in {
    animation: slideInFromLeft var(--transition-medium) ease-out;
}

@keyframes slideInFromLeft {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Debug mode (remove in production) */
.gallery-debug .gallery-item {
    outline: 2px dashed var(--red-danger);
}

.gallery-debug .gallery-item::after {
    content: attr(data-category);
    position: absolute;
    top: 4px;
    left: 4px;
    background: rgba(var(--red-danger-rgb), 0.8);
    color: var(--white);
    padding: 2px 6px;
    font-size: 10px;
    border-radius: 3px;
}
