/* gallery.css: Gallery Specific Styles */

/* --- 1. SEARCH/FILTER SECTION --- */
.filter-section {
    padding: 20px 0;
    text-align: center;
}

#gallery-search {
    width: 90%;
    max-width: 500px;
    padding: 12px 15px;
    margin-top: 15px;
    /* Match the site's dark theme and border style */
    background-color: var(--color-secondary);
    color: var(--color-primary);
    border: 1px solid var(--border-color);
    font-family: var(--font-family-body);
    font-size: 1rem;
}

/* Override the 5vw padding for large screens to keep it reasonable */
@media (min-width: 900px) {
    .content-container {
        /* Reduce the padding to a fixed value when the max-width is hit */
        padding: 0 40px; 
    }
}

/* --- 2. MOBILE-FIRST SYMMETRICAL GRID LAYOUT --- */
.gallery-grid {
    display: grid;
    /* Mobile-First: Two equal columns at the smallest size (320px) */
    grid-template-columns: repeat(2, 1fr); 
    gap: 15px; /* Tighter spacing for mobile */
    padding-bottom: 20px;
}

/* Define the gallery item container */
.gallery-item {
    /* Uses the semantic figure element */
    overflow: hidden; /* Contains the image */
    background-color: var(--color-secondary); /* Dark background */
    border: 1px solid var(--border-color);
    cursor: pointer;
    text-align: left;
    margin: 0;
}

.gallery-item img {
    /* Ensure image fills its container while maintaining aspect ratio */
    max-width: 100%;
    height: auto;
    display: block;
    /* Apply transition to the filter property for smooth grayscale/color change */
    transition: filter 0.3s ease;
    object-fit: cover;
}

/* Grayscale to Color Transition Logic (Primary Site-Specific Design Rule) */

/* 1. On Hover: Override the global grayscale(100%) defined in common.css */
/* Target the image when its parent item is hovered */
.gallery-item:hover img {
    filter: none; /* Full color */
}

/* 2. Caption Styling */
.gallery-caption {
    padding: 10px;
    font-size: 0.9rem;
    line-height: 1.2;
}

.gallery-caption p {
    margin: 0;
    padding: 0;
}

#scroll-sentinel {
    width: 1px; /* Minimal width to avoid conflicts */
    height: 1px; /* Minimal height to avoid conflicts */
    visibility: hidden; /* Prevent visual display */
    flex-shrink: 0; /* Important if the gallery is also a flex container */
}

/* --- 3. MODAL STYLES (Dialog & Carousel Base) --- */
/* The native dialog element */
#image-modal {
    border: none;
    padding: 0;
    background: rgba(0, 0, 0, 0.9); /* Semi-transparent black overlay */
    color: var(--color-primary);
    max-width: 98vw;
    max-height: 98vh;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.2);
    overflow: hidden;
}

/* Ensures the backdrop darkens the rest of the page */
#image-modal::backdrop {
    background: rgba(0, 0, 0, 0.85);
}

/* Full Color Override for Modal Image */
#image-modal img {
    filter: none; /* Crucial override to ensure full color */
    max-width: 100%;
    max-height: 100%;
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    margin: 0 auto;
}

.modal-content-container {
    display: flex;
    flex-direction: column; /* MOBILE-FIRST: Vertically stacked content */
    width: 100%; 
    height: 100%;
    overflow-y: auto; /* Allows scrolling on mobile if content is tall */
    padding: 0;
}

.modal-view.image-view {
    flex-shrink: 0;
    flex-grow: 1; 
    width: 100%; 
    height: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    position: relative;
    object-fit: contain;
    padding: 25px 25px 25px 25px; 
}

/* State management: Slides the Info View into the viewport */
.modal-content-wrapper.show-info {
    transform: translateX(-50%); 
}

/* Info View Alignment */
.info-view {
    /* Align content toward the top/center, not just center */
    justify-content: flex-start;
}

.info-view h3 {
    margin-top: 5vh;
}

#modal-close-btn {
    /* Style for all modes: White button on dark modal background */
    display: block;
    position: absolute;
    /* WARNING: Using your current offsets for now. You may need to increase these to 40px later (Phase E) to fix clipping. */
    top: 10px;
    right: 10px;
    font-size: 1.5rem;
    
    /* Fixed Colors for High Contrast */
    background: transparent;
    border: 1px solid transparent; /* White border */
    color: var(--color-primary); /* White text */
    text-shadow: 1px 1px var(--color-secondary);

    cursor: pointer;
    z-index: 20;
    transition: all 0.2s ease-in-out;
    backdrop-filter: blur(1px);
    opacity: 0.9;
}

#modal-close-btn:hover,
#modal-close-btn:focus {
    /* Hover/Focus state: Black text on White background */
    color: var(--color-primary); /* Black text */
    background: var(--color-secondary); /* White background */
    border-color: var(--color-secondary); /* Keep border white */
    opacity: 1.0;
    outline: none;
    box-shadow: 1px 1px var(--color-primary)
}

/* Vertically stacked metadata */
.modal-metadata {
    text-align: center;
    display: flex;
    flex-direction: column;
    padding-bottom: 20px;
}

.modal-nav {
    position: relative;
    text-align: center;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    margin: 0px 40px 0px 40px;
}

.modal-nav button { 
    background: var(--color-secondary); 
    border: 1px solid transparent; 
    color: var(--color-primary); 
    cursor: pointer; 
    font-size: 1rem;
    font-family: var(--font-family-body);
    flex-grow: 1; 
    padding: 0px 5px;
    box-shadow: 1px 1px var(--border-color);
}

.modal-nav button:hover {
    opacity: 1; 
    border: 1px solid var(--border-color); 
    background: rgba(255, 255, 255, 0.2); 
}

.modal-metadata h3, 
.modal-metadata p, 
.modal-metadata a {
    margin: 1px auto; /* Reduced margin */
    padding: 0 10px 0 10px;
    max-width: 90%;
    text-align: center;
}

.modal-metadata h3 {
    font-size: 1.2rem;
}

.modal-metadata p {
    font-weight: bold;
}

.modal-metadata a:hover,
.modal-metadata a:active {
    background-color: var(--color-primary);
    color: var(--color-secondary);
    transition: background-color 0.1s, color 0.1s; 
}

/* ------------------------------------------------------------------- */
/* --- 4. MODAL LIGHT MODE OVERRIDES (Applied when data-theme="light") --- */
/* ------------------------------------------------------------------- */

/* 1. Backdrop and Main Dialog Surface */

/* When in light mode, the dialog's main container flips to the light background color (white) */
html[data-theme="light"] #image-modal {
    background-color: var(--color-secondary); /* Flips to #ffffff */
}

/* The backdrop should flip from a dark semi-transparent overlay to a light semi-transparent one. */
html[data-theme="light"] dialog::backdrop {
    /* Using a semi-transparent light black/dark grey overlay (for a standard fade effect) */
    background-color: rgba(0, 0, 0, 0.4); 
}

/* 2. Metadata Text and Overlay Backgrounds */

/* All text elements inside the modal metadata flip to the primary (black) color */
html[data-theme="light"] .modal-metadata h3,
html[data-theme="light"] .modal-metadata p,
html[data-theme="light"] .modal-metadata a {
    color: var(--color-primary); /* Flips to #000000 */
}

html[data-theme="light"] .modal-metadata a:hover {
    background-color: var(--color-primary);
    color: var(--color-secondary); 
}

/* 3. Close Button and Navigation Buttons */

/* Close Button (#modal-close-btn) */
html[data-theme="light"] #modal-close-btn {
    text-shadow: 1px 1px var(--color-primary);
    color: var(--color-secondary); /* Button symbol flips to black */
    background-color: transparent; /* Button background flips to white */
    border: 1px solid transparent; /* Border flips to black */
}

/* Close Button (#modal-close-btn) */
html[data-theme="light"] 
    #modal-close-btn:hover, 
    #modal-close-btn:focus {
        color: var(--color-primary);
        background-color: var(--color-secondary);
        box-shadow: 1px 1px var(--color-primary);
}

/* Navigation Buttons (.modal-nav button) */
html[data-theme="light"] .modal-nav button {
    color: var(--color-primary); /* Button text flips to black */
    /* Add a visible, semi-transparent white background for better contrast against the image */
    background: rgba(255, 255, 255, 0.6); 
    border: 1px solid transparent; /* Border flips to black */
    text-shadow: none; /* Remove text shadow */
}

html[data-theme="light"] .modal-nav button:hover {
    background: rgba(0, 0, 0, 0.15); /* Use a low opacity black overlay */
    border: 1px solid var(--border-color); /* Retains the black border */
    color: var(--color-primary); /* Retains the black text */
}

/* --- 5. RESPONSIVENESS (Desktop/Larger Screens) --- */
@media (min-width: 768px) {
    /* Standard grid for larger tablets/desktops */
    .gallery-grid {
        /* Adaptive grid: items are between 250px and 1fr */
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
        gap: 30px; /* Increase gap for more breathing room */
        max-width: 1200px;
        padding-bottom: 20px;
        margin: 0 auto;
    }
 
    /* Ensure the image is the primary element */
    #modal-image {
        margin: 0; /* Remove mobile margin */
        position: relative;
    }

    /* 1. OVERLAY: Title at the top */
    #modal-artwork-title {
        position: absolute;
        top: 20px;
        left: 50%;
        transform: translateX(-50%);
        width: 90%;
        color: var(--color-primary); /* Ensure high contrast */
        background: rgba(0, 0, 0, 0.7); /* Subtle background for readability */
        padding: 10px 20px;
        z-index: 10; 
        font-size: 1.5rem;
    }
    
    /* 2. OVERLAY: Artist Name and Link at the bottom */
    #modal-artist-name, 
    #modal-portfolio-link {
        position: absolute;
        bottom: 20px;
        width: 90%;
        text-align: right;
        color: var(--color-primary);
        background: rgba(0, 0, 0, 0.7);
        padding: 10px 20px;
        box-sizing: border-box;
        z-index: 10;
        /* Position as a single block at the bottom */
        left: 50%; 
        transform: translateX(-50%);
    }

    #modal-artist-name {
        font-family: var(--font-family-header);
        /* Pull name up slightly above the link if needed, or remove margin to stack */
        bottom: 80px;
        padding-top: 0px;
        padding-bottom: 0px;
        font-weight: bolder;
    }
    
    #modal-portfolio-link {
        bottom: 50px;
        display: block;
        padding-top: 0px;
        padding-bottom: 0px;
        position: absolute;
        z-index: 20;
    }

    /* Hide the mobile vertical metadata which is now the overlay */
    .modal-view h3, .modal-view p, .modal-view a {
        /* This rule now hides the metadata when the overlays are active on desktop */
        position: absolute; 
        clip-path: none;
        padding: 0;
        border: 0;
        height: 1px;
        width: 1px;
        overflow: hidden;
        white-space: nowrap;
    }
    
    /* Re-show the specific elements needed for the overlay and style them */
    #modal-artwork-title,
    #modal-artist-name,
    #modal-portfolio-link {
        /* Override the hidden state for the elements that *are* the overlay */
        position: absolute;
        clip-path: none;
        width: auto;
        height: auto;
        overflow: visible;
    }

    /* The metadata overlays (for desktop view) flip their background from dark-transparent to light-transparent */
    html[data-theme="light"] #modal-artwork-title,
    html[data-theme="light"] #modal-artist-name,
    html[data-theme="light"] #modal-portfolio-link {
        /* Background flips to light semi-transparent */
        background: rgba(255, 255, 255, 0.8);
        /* Ensures the white text-shadow for dark mode is removed */
        text-shadow: none;
    }

    .modal-nav {
        position: relative;
        text-align: center;
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        margin: 0px;
        text-shadow: 1px 1px #aaaaaa;
    }

    .modal-metadata .modal-nav { 
        position: absolute; 
        top: 0; 
        left: 0; 
        width: 100%; 
        height: 100%; 
        z-index: 10; 
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    /* Navigation Buttons (.modal-nav button) */
    html[data-theme="light"] .modal-nav button {
        font-weight: bold;
        color: var(--color-primary); /* Button text flips to black */
        /* Add a visible, semi-transparent white background for better contrast against the image */
        background: rgba(255, 255, 255, 0.15); /* Use a low opacity black overlay */
        border: 1px solid transparent; /* Border flips to black */
        text-shadow: none; /* Remove text shadow */
    }

    html[data-theme="light"] .modal-nav button:hover {
        font-weight: bolder;
        background: rgba(255, 255, 255, 0.6); 
        border: 1px solid var(--border-color); /* Retains the black border */
        color: var(--color-primary); /* Retains the black text */
    }
    
    .modal-nav button { 
        height: 10%; 
        width: auto;
        flex-grow: 0; 
        text-shadow: 0 0 5px rgba(0, 0, 0, 0.8); 
        opacity: 0; 
        transition: opacity 0.2s; 
        font-size: 1.25rem;
        padding: 20px;
        box-shadow: 1px 1px transparent;
        pointer-events: auto;
    }

    .modal-nav:hover button { 
        opacity: 1; 
        background: rgba(0, 0, 0, 0.2); 
    }

    .modal-nav button:first-child { 
        text-align: left; 
    } 
    
    .modal-nav button:last-child { 
        text-align: right; 
    }
}

