/* Gallery Modal Styles - Fixed for Mobile Browser UI and Close Button Overlap */

/* Remove all focus outlines and orange boxes */
button:focus,
button:active,
button:focus-visible,
button:focus-within {
    outline: none !important;
    box-shadow: none !important;
}

*:focus,
*:active,
*:focus-visible {
    outline: none !important;
    box-shadow: none !important;
}

/* Body scroll lock when modal is open */
html.no-scroll {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

/* Prevent body scrolling when modal is open */
body.modal-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
    top: 0 !important;
    left: 0 !important;
}

/* Modal Overlay - Fixed for mobile browser UI */
.project-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile browsers */
    z-index: 10001;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    /* Ensure modal works with mobile browser UI */
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

.project-modal.active {
    display: flex !important;
    opacity: 1 !important;
    animation: modalFadeIn 0.3s ease-out;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Modal Backdrop */
.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    cursor: pointer;
}

/* Modal Container - Fixed for mobile viewport and browser UI */
.modal-container {
    position: relative;
    width: 80%;
    max-width: 1000px;
    height: 70%;
    max-height: 85vh;
    min-height: 400px;
    display: flex;
    flex-direction: column;
    background-color: #fff;
    margin: auto;
    border-radius: 0;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    min-height: 0;
    max-height: 90vh;
    /* Enhanced mobile browser UI safe areas */
    padding-top: max(env(safe-area-inset-top, 0px), 20px);
    padding-bottom: max(env(safe-area-inset-bottom, 0px), 20px);
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    /* Ensure container respects mobile browser UI */
    box-sizing: border-box;
    /* Prevent content from being hidden behind browser UI */
    margin-top: max(env(safe-area-inset-top, 0px), 20px);
    margin-bottom: max(env(safe-area-inset-bottom, 0px), 20px);
}

/* Modal Header - Fixed for close button overlap and mobile browser UI */
.modal-header {
    position: sticky;
    top: 0;
    background-color: #fff;
    border-bottom: 1px solid #e5e5e5;
    padding: 1.5rem 5rem 1.5rem 2rem; /* Added right padding for close button */
    display: flex;
    justify-content: space-between;
    align-items: flex-start; /* Changed from center to flex-start */
    z-index: 10;
    flex-shrink: 0;
    min-height: 80px; /* Ensure consistent header height */
    /* Enhanced mobile browser UI protection */
    padding-top: max(1.5rem, env(safe-area-inset-top, 0px) + 1rem);
    margin-top: 0;
    /* Ensure header is never cut off */
    position: sticky !important;
    top: 0 !important;
    z-index: 1000 !important;
}

.modal-title-section {
    flex: 1;
    padding-right: 1rem; /* Extra padding to prevent overlap */
    max-width: calc(100% - 80px); /* Reserve space for close button */
}

.modal-title {
    font-size: 1.75rem;
    font-weight: 300;
    color: #333;
    margin: 0 0 0.25rem 0;
    letter-spacing: 1px;
    text-transform: uppercase;
    font-family: 'Inter', sans-serif;
    line-height: 1.2;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

.modal-project-type {
    font-size: 0.9rem;
    font-weight: 300;
    color: #FF7900;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-family: 'Inter', sans-serif;
}

/* Close Button - Fixed positioning to prevent overlap */
.modal-close-btn {
    position: absolute !important;
    top: 1.5rem !important;
    right: 1.5rem !important;
    background: none !important;
    border: none;
    color: #FF7900 !important;
    font-size: 50px !important;
    cursor: pointer;
    padding: 0;
    border-radius: 0;
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 60px !important;
    height: 60px !important;
    font-weight: bold;
    visibility: visible !important;
    opacity: 1 !important;
    outline: none !important;
    box-shadow: none !important;
    z-index: 11 !important; /* Higher than header */
    flex-shrink: 0;
}

.modal-close-btn:focus,
.modal-close-btn:active,
.modal-close-btn:focus-visible {
    outline: none !important;
    box-shadow: none !important;
    background: none !important;
}

.close-x {
    font-size: 50px !important;
    font-weight: bold !important;
    color: #FF7900 !important;
    line-height: 1 !important;
    display: block !important;
}

.arrow-left,
.arrow-right {
    font-size: 50px !important;
    font-weight: bold !important;
    color: white !important;
    line-height: 1 !important;
    display: block !important;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.8) !important;
}

/* Modal Content */
.modal-content {
    flex: 1;
    display: grid;
    grid-template-columns: 70% 30%;
    gap: 0;
    height: calc(100% - 80px);
    overflow: hidden;
    min-height: 0;
    min-height: 300px;
}

/* Main Image Column */
.main-image-column {
    display: flex;
    flex-direction: column;
    background-color: #f8f8f8;
    position: relative;
    padding-left: 1rem;
    min-width: 0;
    flex: 1;
    min-height: 400px;
    height: 100%;
}

.main-image-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
    padding: 1rem;
    box-sizing: border-box;
    min-height: 0;
    flex: 1;
    max-width: none;
    max-height: none;
    overflow: auto;
    min-height: 400px;
    min-width: 100%;
    flex-shrink: 0;
}

.main-image {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain !important;
    object-position: center;
    cursor: pointer;
    border-radius: 0;
    display: block;
    margin: 0 auto;
    min-width: 0;
    min-height: 0;
    flex-shrink: 0;
    object-fit: contain !important;
    image-rendering: auto;
    transform: none !important;
    position: relative;
    z-index: 1;
}

/* Navigation Arrows */
.nav-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: transparent !important;
    border: none;
    color: white;
    font-size: 50px;
    cursor: pointer;
    padding: 0;
    border-radius: 0;
    z-index: 20;
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    box-shadow: none !important;
    visibility: visible !important;
    opacity: 0.7 !important;
    outline: none !important;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    position: absolute !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
}

.nav-arrow:focus,
.nav-arrow:active,
.nav-arrow:focus-visible,
.nav-arrow:hover,
.nav-arrow:focus-within {
    outline: none !important;
    box-shadow: none !important;
    background: transparent !important;
    border: none !important;
    color: white !important;
    opacity: 0.7 !important;
    transform: translateY(-50%) !important;
}

.nav-prev {
    left: 1rem !important;
}

.nav-next {
    right: 1rem !important;
}

/* Lightbox Toggle */
.lightbox-toggle {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    color: #333;
    font-size: 1rem;
    cursor: pointer;
    padding: 0.75rem;
    border-radius: 0;
    transition: all 0.3s ease;
    z-index: 10;
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    visibility: visible !important;
    opacity: 1 !important;
}

.lightbox-toggle:hover,
.lightbox-toggle:focus {
    background: rgba(255, 255, 255, 1);
    color: #FF7900;
    outline: 2px solid #FF7900;
    outline-offset: 2px;
}

/* Thumbnails Column */
.thumbnails-column {
    background-color: #fff;
    border-left: 1px solid #e5e5e5;
    display: flex;
    flex-direction: column;
    position: relative;
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

/* See More Work Button */
.see-more-work-container {
    padding: 1rem;
    border-top: 1px solid #e5e5e5;
    background-color: #fff;
    flex-shrink: 0;
}

/* Hide See More Work button on portfolio page */
body.portfolio-page .see-more-work-container {
    display: none;
}

.see-more-work-btn {
    display: inline-block;
    background-color: #FF7900;
    color: #fff;
    text-decoration: none;
    padding: 0.75rem 1.5rem;
    border-radius: 0;
    font-size: 0.9rem;
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: all 0.3s ease;
    border: none;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    width: 100%;
    text-align: center;
    box-sizing: border-box;
}

.see-more-work-btn:hover {
    background-color: #e55a00;
    color: #fff;
    text-decoration: none;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 121, 0, 0.3);
}

.see-more-work-btn:focus {
    outline: 2px solid #FF7900;
    outline-offset: 2px;
    background-color: #e55a00;
    color: #fff;
    text-decoration: none;
}

/* Scroll indicators for thumbnails */
.thumbnails-column::before,
.thumbnails-column::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    height: 20px;
    pointer-events: none;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.thumbnails-column::before {
    top: 0;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.9), transparent);
}

.thumbnails-column::after {
    bottom: 0;
    background: linear-gradient(to top, rgba(255, 255, 255, 0.9), transparent);
}

.thumbnails-column.scrollable-top::before,
.thumbnails-column.scrollable-bottom::after {
    opacity: 1;
}

.thumbnails-container {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    overflow-x: hidden;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 0.5rem;
    align-content: start;
    max-height: 100%;
    scroll-behavior: smooth;
    min-height: 0;
    height: 100%;
    max-height: calc(100vh - 200px);
    overflow-y: scroll;
    padding-bottom: 0.5rem;
}

/* Custom scrollbar for thumbnails */
.thumbnails-container::-webkit-scrollbar {
    width: 8px;
}

.thumbnails-container::-webkit-scrollbar-track {
    background: #f8f8f8;
    border-radius: 4px;
    border: 1px solid #e5e5e5;
}

.thumbnails-container::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
    border: 1px solid #bbb;
    transition: background 0.2s ease;
}

.thumbnails-container::-webkit-scrollbar-thumb:hover {
    background: #FF7900;
    border-color: #e55a00;
}

.thumbnails-container::-webkit-scrollbar-thumb:active {
    background: #e55a00;
}

.thumbnails-container {
    scrollbar-width: thin;
    scrollbar-color: #ccc #f8f8f8;
}

/* Thumbnail Images */
.thumbnail {
    width: 100%;
    height: 60px;
    object-fit: cover;
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: 0;
    transition: all 0.3s ease;
    opacity: 0.7;
    aspect-ratio: 1;
    background-color: #f0f0f0;
}

.thumbnail:not([src]) {
    background-color: #e0e0e0;
    opacity: 0.5;
}

.thumbnail.active {
    opacity: 1;
    border-color: #FF7900;
    box-shadow: 0 0 0 2px rgba(255, 121, 0, 0.2);
    transform: scale(1.05);
}

/* Lightbox Mode */
.project-modal.lightbox-mode .modal-content {
    grid-template-columns: 100%;
    position: relative;
}

.project-modal.lightbox-mode .thumbnails-column {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.8);
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    max-height: 100px;
    z-index: 20;
}

.project-modal.lightbox-mode .thumbnails-container {
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0.75rem;
    gap: 0.5rem;
}

.project-modal.lightbox-mode .thumbnail {
    height: 50px;
    width: 50px;
    flex-shrink: 0;
}

.project-modal.lightbox-mode .main-image-column {
    background-color: #000;
}

.project-modal.lightbox-mode .main-image {
    max-width: 95%;
    max-height: 95%;
    width: auto;
    height: auto;
    object-fit: contain;
    object-position: center;
    min-width: 0;
    min-height: 0;
}

.project-modal.lightbox-mode .nav-arrow {
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    width: 60px;
    height: 60px;
    font-size: 1.5rem;
}

.project-modal.lightbox-mode .nav-arrow:hover,
.project-modal.lightbox-mode .nav-arrow:focus {
    background: rgba(0, 0, 0, 0.9);
    color: #FF7900;
}

.project-modal.lightbox-mode .lightbox-toggle {
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
}

.project-modal.lightbox-mode .lightbox-toggle:hover,
.project-modal.lightbox-mode .lightbox-toggle:focus {
    background: rgba(0, 0, 0, 0.9);
    color: #FF7900;
}

/* Loading State */
.main-image.loading {
    opacity: 0.3;
    filter: blur(1px);
    transition: opacity 0.3s ease, filter 0.3s ease;
}

.main-image.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #FF7900;
    border-radius: 0;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Focus Management */
.project-modal *:focus {
    outline: 2px solid #FF7900;
    outline-offset: 2px;
}

/* Touch/Swipe Support */
.main-image-container {
    touch-action: pan-x;
}

/* Responsive Design - Enhanced Mobile Support */
@media (max-width: 1024px) {
    .modal-content {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr auto;
        height: calc(100% - 80px);
    }
    
    .main-image-column {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    .main-image-container {
        padding: 0.75rem;
    }
    
    .thumbnails-column {
        border-left: none;
        border-top: 1px solid #e5e5e5;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
    }
    
    .thumbnails-column.expanded {
        max-height: 120px;
        overflow: visible;
    }
    
    .see-more-work-container {
        padding: 0.75rem;
        border-top: 1px solid #e5e5e5;
    }
    
    .see-more-work-btn {
        padding: 0.5rem 1rem;
        font-size: 0.8rem;
    }
    
    .thumbnails-container {
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 1rem;
        gap: 0.5rem;
        scroll-behavior: smooth;
        min-width: 0;
        height: auto;
        max-height: none;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }
    
    .thumbnails-column::before,
    .thumbnails-column::after {
        width: 20px;
        height: 100%;
        top: 0;
        bottom: 0;
    }
    
    .thumbnails-column::before {
        left: 0;
        background: linear-gradient(to right, rgba(255, 255, 255, 0.9), transparent);
    }
    
    .thumbnails-column::after {
        right: 0;
        background: linear-gradient(to left, rgba(255, 255, 255, 0.9), transparent);
    }
    
    .thumbnail {
        height: 50px;
        width: 50px;
        flex-shrink: 0;
        min-width: 50px;
        min-height: 50px;
    }
    
    .modal-header {
        padding: 1rem 5rem 1rem 1.5rem; /* Adjusted for mobile */
    }
    
    .modal-title {
        font-size: 1.5rem;
    }
    
    .nav-arrow {
        width: 45px;
        height: 45px;
        font-size: 1.1rem;
    }
    
    .nav-prev {
        left: 0.5rem;
    }
    
    .nav-next {
        right: 0.5rem;
    }
    
    /* Close button mobile adjustments */
    .modal-close-btn {
        top: 1rem !important;
        right: 1rem !important;
        font-size: 40px !important;
        width: 50px !important;
        height: 50px !important;
    }
    
    .close-x {
        font-size: 40px !important;
    }
}

@media (max-width: 768px) {
    /* Mobile: Fixed viewport handling to prevent top cutoff */
    .project-modal {
        height: 100vh;
        height: 100dvh; /* Use dynamic viewport height */
        /* Handle iOS Safari and other mobile browsers */
        height: calc(var(--vh, 1vh) * 100);
        /* Prevent scrolling on the modal itself */
        overflow: hidden;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }
    
    .modal-container {
        width: 100%;
        height: 100vh;
        height: 100dvh;
        height: calc(var(--vh, 1vh) * 100);
        max-width: none;
        max-height: none;
        margin: 0;
        border-radius: 0;
        /* Enhanced safe area handling - ensure top is never cut off */
        padding-top: max(env(safe-area-inset-top, 0px), 0px);
        padding-bottom: max(env(safe-area-inset-bottom, 0px), 0px);
        padding-left: env(safe-area-inset-left, 0px);
        padding-right: env(safe-area-inset-right, 0px);
        box-sizing: border-box;
        overflow: hidden;
        /* Ensure container fills the entire viewport */
        position: relative;
        display: flex;
        flex-direction: column;
    }
    
    .main-image-column {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
        /* Calculate height based on available space after header and thumbnails */
        height: calc(100vh - 270px);
        height: calc(100dvh - 270px);
        height: calc((var(--vh, 1vh) * 100) - 270px);
        overflow-y: auto;
        /* Prevent horizontal scrolling */
        overflow-x: hidden;
        /* Ensure proper scrolling behavior */
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        flex: 1;
    }
    
    .main-image-container {
        padding: 0.5rem;
    }
    
    .modal-header {
        padding: 1rem 4rem 1rem 1.5rem; /* Even more space for close button on mobile */
        position: sticky !important;
        top: 0 !important;
        background-color: #fff !important;
        border-bottom: 1px solid #e5e5e5 !important;
        /* Safe area padding for mobile - ensure header is never cut off */
        padding-top: max(1rem, env(safe-area-inset-top, 0px) + 0.5rem) !important;
        min-height: 100px; /* Increased for mobile */
        /* Ensure header stays at the top */
        z-index: 1000 !important;
        flex-shrink: 0;
    }
    
    .modal-title-section {
        max-width: calc(100% - 60px); /* More conservative space reservation */
    }
    
    /* Close button - enhanced mobile positioning */
    .modal-close-btn {
        top: calc(1rem + max(env(safe-area-inset-top, 0px) - 20px, 0px)) !important;
        right: 1rem !important;
        font-size: 35px !important;
        width: 45px !important;
        height: 45px !important;
        z-index: 1000 !important;
    }
    
    .close-x {
        font-size: 35px !important;
    }
    
    .modal-title {
        font-size: 1.25rem;
        line-height: 1.3;
        /* Better text wrapping on mobile */
        word-break: break-word;
        overflow-wrap: break-word;
        hyphens: auto;
    }
    
    .modal-project-type {
        font-size: 0.85rem;
        margin-top: 0.5rem;
    }
    
    .modal-content {
        height: calc(100vh - 200px);
        height: calc(100dvh - 200px);
        height: calc((var(--vh, 1vh) * 100) - 200px);
        display: flex;
        flex-direction: column;
    }
    
    .thumbnails-column {
        max-height: 150px;
        min-height: 120px;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        padding: 0.5rem;
    }
    
    .see-more-work-container {
        padding: 0.5rem;
    }
    
    .see-more-work-btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.75rem;
    }
    
    .thumbnail {
        height: 60px;
        width: 60px;
        margin: 0.25rem;
        border-radius: 4px;
        object-fit: cover;
    }
    
    .nav-arrow {
        width: 40px;
        height: 40px;
        font-size: 1rem;
        padding: 0.75rem;
    }
    
    .lightbox-toggle {
        width: 35px;
        height: 35px;
        font-size: 0.9rem;
        padding: 0.5rem;
    }
}

@media (max-width: 480px) {
    .modal-header {
        padding: 0.75rem 3.5rem 0.75rem 1rem; /* Compact but safe spacing */
        min-height: 90px;
    }
    
    .modal-title {
        font-size: 1.1rem;
        line-height: 1.25;
    }
    
    .modal-project-type {
        font-size: 0.8rem;
    }
    
    .main-image-column {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
    
    .main-image-container {
        padding: 0.25rem;
    }
    
    .modal-content {
        height: calc(100vh - 110px);
        height: calc(100dvh - 110px);
        height: calc((var(--vh, 1vh) * 100) - 110px);
    }
    
    .thumbnails-container {
        padding: 0.5rem;
        gap: 0.25rem;
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        scrollbar-color: #ccc #f8f8f8;
    }
    
    .thumbnails-container::-webkit-scrollbar {
        height: 4px;
    }
    
    .thumbnails-container::-webkit-scrollbar-track {
        background: #f8f8f8;
        border-radius: 2px;
    }
    
    .thumbnails-container::-webkit-scrollbar-thumb {
        background: #ccc;
        border-radius: 2px;
    }
    
    .thumbnails-container::-webkit-scrollbar-thumb:hover {
        background: #FF7900;
    }
    
    .thumbnail {
        height: 45px;
        width: 60px;
    }
    
    .nav-arrow {
        width: 35px;
        height: 35px;
        font-size: 0.9rem;
        padding: 0.5rem;
    }
    
    .nav-prev {
        left: 0.25rem;
    }
    
    .nav-next {
        right: 0.25rem;
    }
    
    /* Close button - smallest screens */
    .modal-close-btn {
        font-size: 30px !important;
        width: 40px !important;
        height: 40px !important;
        top: 0.75rem !important;
        right: 0.75rem !important;
    }
    
    .close-x {
        font-size: 30px !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .modal-backdrop {
        background-color: rgba(0, 0, 0, 1);
    }
    
    .nav-arrow,
    .lightbox-toggle,
    .modal-close-btn {
        background: #fff;
        border: 2px solid #000;
    }
    
    .thumbnail.active {
        border-color: #000;
        box-shadow: 0 0 0 2px #000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .project-modal,
    .main-image,
    .thumbnail,
    .nav-arrow,
    .modal-close-btn,
    .lightbox-toggle {
        transition: none;
    }
    
    .main-image:hover {
        transform: none;
    }
    
    .thumbnail:hover {
        transform: none;
    }
    
    .nav-arrow:hover,
    .nav-arrow:focus {
        transform: translateY(-50%);
    }
}

/* Fullscreen Mode */
.fullscreen-mode .modal-container {
    width: 95vw !important;
    height: 95vh !important;
    max-width: none !important;
    max-height: none !important;
}

.fullscreen-mode .modal-content {
    grid-template-columns: 100% !important;
}

.fullscreen-mode .main-image-column {
    width: 100% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

.fullscreen-mode .thumbnails-column {
    display: none !important;
}

.fullscreen-mode .main-image {
    max-height: 90vh !important;
    max-width: 90vw !important;
    width: auto !important;
    height: auto !important;
    object-fit: contain !important;
    object-position: center !important;
    min-width: 0 !important;
    min-height: 0 !important;
}

/* Fullscreen body state */
body.fullscreen-active {
    overflow: hidden;
}

/* JavaScript viewport height fix for mobile browsers */
:root {
    --vh: 1vh;
}

/* CRITICAL: Ensure modal header is never cut off on any device */
.project-modal .modal-header {
    /* Force header to always be visible */
    position: sticky !important;
    top: 0 !important;
    z-index: 1000 !important;
    background-color: #fff !important;
    border-bottom: 1px solid #e5e5e5 !important;
    /* Enhanced mobile browser UI protection */
    padding-top: max(1.5rem, env(safe-area-inset-top, 0px) + 1rem) !important;
    margin-top: 0 !important;
    /* Ensure minimum height for touch targets */
    min-height: max(80px, env(safe-area-inset-top, 0px) + 60px) !important;
    /* Prevent any overflow issues */
    overflow: visible !important;
    /* Ensure header stays above all content */
    transform: translateZ(0) !important;
    will-change: transform !important;
    /* Additional mobile fixes */
    flex-shrink: 0 !important;
    width: 100% !important;
    box-sizing: border-box !important;
}

/* Ensure modal container respects mobile browser UI on all devices */
.project-modal .modal-container {
    /* Enhanced safe area handling */
    padding-top: max(env(safe-area-inset-top, 0px), 0px) !important;
    padding-bottom: max(env(safe-area-inset-bottom, 0px), 0px) !important;
    /* Prevent content from being hidden */
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    /* Ensure proper box sizing */
    box-sizing: border-box !important;
    /* Prevent overflow issues */
    overflow: hidden !important;
    /* Ensure container fills the entire viewport */
    position: relative !important;
    display: flex !important;
    flex-direction: column !important;
    height: 100vh !important;
    height: 100dvh !important;
    height: calc(var(--vh, 1vh) * 100) !important;
}