/* Modal styles */
.modal-image {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    z-index: 2000;
    overflow-y: auto;
    /* Allow scrolling if content is tall */
}

/* Modal Container */
.modal-container {
    position: relative;
    width: 90%;
    max-width: 1200px;
    margin: 40px auto;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    animation: fadeIn 0.3s ease-out;
}

/* Modal Body - 3 Column Layout */
.modal-body {
    display: flex;
    flex-direction: row;
    height: 80vh;
    /* Fixed height for desktop */
    max-height: 800px;
}

/* 1. Thumbnails (Left) */
.modal-thumbnails {
    width: 100px;
    padding: 20px 10px;
    overflow-y: auto;
    border-right: 1px solid #eee;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex-shrink: 0;
}

.modal-thumbnail {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: 4px;
    transition: all 0.2s ease;
    opacity: 0.7;
}

.modal-thumbnail:hover {
    opacity: 1;
}

.modal-thumbnail.active {
    border-color: #333;
    opacity: 1;
}

/* 2. Main Image (Center) */
.modal-main-image {
    flex: 1;
    position: relative;
    background: #f9f9f9;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-main-image img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transition: opacity 0.3s ease;
}

/* Navigation Buttons */
.modal-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.8);
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    font-size: 1.2rem;
    color: #333;
    transition: all 0.2s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.modal-nav-btn:hover {
    background: #fff;
    transform: translateY(-50%) scale(1.1);
}

.modal-prev-btn {
    left: 20px;
}

.modal-next-btn {
    right: 20px;
}

/* 3. Details (Right) */
.modal-details {
    width: 350px;
    padding: 30px;
    overflow-y: auto;
    border-left: 1px solid #eee;
    background: #fff;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.modal-details h2 {
    margin-bottom: 10px;
    color: #333;
}

.modal-details .subtitle {
    color: #555;
    margin-bottom: 20px;
    font-size: 1.2rem;
}

.modal-details .content {
    font-size: 1rem;
    line-height: 1.6;
    color: #444;
}

/* Close button */
.modal-close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: transparent;
    border: none;
    font-size: 1.5rem;
    color: #333;
    cursor: pointer;
    z-index: 2002;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

.modal-close-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

/* Loading State */
.modal-image.loading::before {
    content: 'Loading...';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    z-index: 2005;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive Design */
@media (max-width: 900px) {
    .modal-container {
        width: 100%;
        height: 100%;
        margin: 0;
        border-radius: 0;
        max-width: none;
    }

    .modal-body {
        flex-direction: column;
        height: 100%;
        max-height: none;
        overflow-y: auto;
    }

    /* Mobile: Image on top, then thumbnails, then details */
    .modal-main-image {
        height: 50vh;
        flex: none;
        order: 1;
        background: #000;
        /* Dark background for image on mobile often looks better */
    }

    .modal-main-image img {
        max-height: 100%;
    }

    .modal-thumbnails {
        order: 2;
        width: 100%;
        height: auto;
        flex-direction: row;
        border-right: none;
        border-bottom: 1px solid #eee;
        padding: 10px;
        overflow-x: auto;
        white-space: nowrap;
    }

    .modal-thumbnail {
        width: 60px;
        height: 60px;
        flex-shrink: 0;
    }

    .modal-details {
        order: 3;
        width: 100%;
        border-left: none;
        padding: 20px;
        height: auto;
        flex: none;
    }

    .modal-close-btn {
        position: fixed;
        top: 10px;
        right: 10px;
        background: rgba(255, 255, 255, 0.8);
        color: #000;
        z-index: 2003;
    }
}