/*
 * Robbie Rose Gallery - Generic Modal Styles
 * For cinematic, centered popups.
 */

/* --- Modal Container & Overlay --- */
.modal-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    pointer-events: none;
    opacity: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.4s ease;
}

.modal-overlay {
    position: absolute;
    inset: 0; /* Use your site's dark blue-gray for the overlay */
    background-color: rgba(15, 23, 42, 0.6); /* --color-silver-900 at 60% opacity */
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    cursor: pointer;
}

.modal-container.is-open {
    pointer-events: auto;
    opacity: 1;
}

/* --- Modal Panel --- */
.modal-panel {
    position: relative;
    background: var(--background-color, #FDFCF8); /* Use site primary, with fallback */
    border-radius: 8px; /* Keep 8px to match other site components */
    box-shadow: 0 40px 80px rgba(20,15,10,0.12); /* Warm, deep, architectural shadow */
    border: 1px solid rgba(0,0,0,0.08); /* Hairline border for definition */

    /* Mobile-first dimensions */
    width: 94vw;
    height: 92vh;

    /* REMOVED PADDING: Panel is now brimless. Padding will be applied to child elements. */
    padding: 0;

    display: flex;
    flex-direction: column;
    overflow: hidden; /* Prevent content from spilling past rounded corners */

    /* Subtle paper/noise texture overlay */
}
.modal-panel::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg width='6' height='6' viewBox='0 0 6 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23000000' fill-opacity='0.02' fill-rule='evenodd'%3E%3Cpath d='M5 0h1L0 6V5zM6 5v1H5z'/%3E%3C/g%3E%3C/svg%3E");
    pointer-events: none;

    /* Animation */
    transform: scale(0.95);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-container.is-open .modal-panel {
    transform: scale(1);
}

/* --- Modal Controls --- */
.modal-close-btn {
    position: absolute;
    top: 24px; /* Tighter, more deliberate composition */
    right: 24px;
    z-index: 20;
    background: none;
    border: none;
    font-size: 28px;
    line-height: 1;
    font-weight: 300; /* Light weight */
    cursor: pointer;
    color: #fff; /* Set base color to white for the blend mode to work effectively */
    padding: 0.5rem;
    transition: color 0.2s ease;
    /* THE MAGIC: This makes the button color the inverse of what's behind it. */
    mix-blend-mode: difference;
}

.modal-close-btn:hover {
    /* The blend mode handles the color, so we can use opacity for the hover effect */
    opacity: 0.7;
}

/* --- Modal Content --- */
.modal-content {
    flex: 1 1 0; /* CHANGE: Use 0 as flex-basis to force proper shrinking */
    display: flex;
    flex-direction: column;
    min-height: 0; /* Critical for nested flex containers to shrink properly */
    overflow: hidden;
}

/* Carousel specific styles inside the modal */
.modal-carousel {
    flex: 1 1 0; /* CHANGE: Use 0 as flex-basis */
    min-height: 0; /* Important for flex children to shrink properly */
    position: relative; /* CRITICAL: Establishes a containing block for the track and slides. */
    overflow: hidden; /* ADD THIS: Prevent overflow */
    border-radius: 8px 8px 0 0; /* Round the top corners to match the panel */
}

.modal-carousel .carousel__track {
    display: flex;
    height: 100%; /* Track fills the carousel area */
    width: 100%;
}

.modal-carousel .carousel__slide {
    min-width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    overflow: hidden; /* ADD THIS */
}

/* Increased specificity to override global `!important` rule in style.css */
.modal-carousel .carousel__slide img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto; /* Let the browser decide the best fit based on object-fit */
    object-fit: contain; /* This is key for fitting different aspect ratios */
    display: block;
}

/* Faster transition for this specific carousel */
.modal-carousel.carousel--fast .carousel__track {
    transition: transform 0.3s ease-out;
}

.modal-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0; /* ADD THIS: Prevent footer from shrinking */
    /* ADDED PADDING: Apply padding here instead of the main panel */
    padding: var(--space-lg);
}

.modal-footer-left {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-sm);
    max-width: 70%;
}

.modal-caption {
    font-family: var(--secondary-font);
    font-size: var(--font-sm);
    color: var(--color-silver-600);
    line-height: 1.5;
    min-height: 40px; /* Reserve space to prevent layout shifts */
    transition: opacity 0.3s ease;
}

.modal-footer .cta-link--accented {
    font-family: var(--primary-font);
    font-weight: var(--weight-regular);
    border: 1.5px solid #00bfff; /* Your signature bright blue */
    padding: 8px 16px;
    border-radius: 50px;
    transition: background-color 0.2s, color 0.2s;
    color: #00bfff;
}

.modal-footer .cta-link--accented:hover {
    background-color: #00bfff;
    color: var(--background-color);
}

/* On wider screens, push the modal to the right */
/* The breakpoint is now based on the modal's max-width + padding */ @media (min-width: 900px) {
    .modal-container {
        justify-content: flex-end;
        padding-right: 5vw;
    }
    .modal-panel {
        /* On wide screens, the width is no longer tied to the viewport */ width: auto;
    }
}

/* NEW: Special case for horizontally-oriented mobile screens (constrained height) */
@media (max-height: 450px) {
    .modal-panel .modal-carousel {
        display: none;
        /* "Deny preview" of images */
    }
    .modal-panel .modal-footer {
        /* Make the footer the main content in this state */
        flex-grow: 1;
        flex-direction: column;
        justify-content: center;
        gap: var(--space-md);
    }
    .modal-panel .modal-footer::before {
        content: 'Rotate device to view images';
        font-size: var(--font-sm);
        color: var(--color-silver-500);
    }
}