.gallery-modal-overlay{
    position:fixed;
    inset:0;
    background:rgba(0,0,0,0.65);
    display:flex;
    align-items:center;
    justify-content:center;
    padding:24px;
    opacity:0;
    visibility:hidden;
    transition:0.35s ease;
    z-index:9999;
    overscroll-behavior:contain;
}

.gallery-modal-overlay.active{
    opacity:1;
    visibility:visible;
}

.gallery-modal-box{
    width:min(100%, 1120px);
    max-height:88dvh;
    background:#fff;
    border-radius:24px;
    padding:28px;
    position:relative;
    overflow:hidden;
    transform:translateY(40px);
    transition:0.35s ease;
    display:flex;
    flex-direction:column;
    gap:24px;
}

.gallery-modal-overlay.active .gallery-modal-box{
    transform:translateY(0);
}

.gallery-modal-close{
    position:absolute;
    top:18px;
    right:18px;
    width:42px;
    height:42px;
    border:none;
    background:#d20f20;
    color:#fff;
    border-radius:50%;
    font-size:26px;
    line-height:1;
    cursor:pointer;
    z-index:20;
    transition:0.3s ease;
}

.gallery-modal-close:hover{
    background:#b50d1b;
    transform:rotate(90deg);
}

.gallery-modal-header{
    padding-right:58px;
}

.gallery-modal-header span{
    color:#d20f20;
    font-size:14px;
    font-weight:700;
    letter-spacing:2px;
}

.gallery-modal-header h2{
    margin-top:8px;
    font-size:34px;
    line-height:1.2;
    font-weight:800;
    color:#111;
}

.gallery-modal-body{
    min-height:0;
    display:grid;
    grid-template-columns:minmax(280px, 0.9fr) minmax(360px, 1.25fr);
    gap:22px;
}

.gallery-modal-grid{
    min-height:0;
    max-height:calc(88dvh - 148px);
    overflow-y:auto;
    padding-right:6px;
    display:grid;
    grid-template-columns:repeat(2,minmax(0,1fr));
    grid-auto-rows:138px;
    gap:12px;
}

.gallery-modal-grid::-webkit-scrollbar{
    width:6px;
}

.gallery-modal-grid::-webkit-scrollbar-thumb{
    background:#d20f20;
    border-radius:20px;
}

.gallery-modal-thumb{
    border:none;
    padding:0;
    border-radius:14px;
    overflow:hidden;
    background:#f5f5f5;
    cursor:pointer;
    position:relative;
}

.gallery-modal-thumb img{
    width:100%;
    height:100%;
    object-fit:cover;
    display:block;
    transition:0.35s ease;
}

.gallery-modal-thumb:hover img,
.gallery-modal-thumb.active img{
    transform:scale(1.05);
}

.gallery-modal-thumb.active{
    outline:3px solid #d20f20;
    outline-offset:2px;
}

.gallery-preview{
    min-height:420px;
    border-radius:18px;
    overflow:hidden;
    background:#111;
    position:relative;
}

.gallery-preview img{
    width:100%;
    height:100%;
    object-fit:cover;
    display:block;
}

.gallery-preview-caption{
    position:absolute;
    left:18px;
    right:18px;
    bottom:18px;
    background:#fff;
    color:#111;
    border-radius:12px;
    padding:12px 16px;
    font-size:15px;
    font-weight:600;
    box-shadow:0 10px 25px rgba(0,0,0,0.14);
}

@media (max-width:1024px){
    .gallery-modal-box{
        width:min(100%, 860px);
        max-height:calc(100dvh - 36px);
        padding:24px;
    }

    .gallery-modal-body{
        grid-template-columns:1fr;
        overflow-y:auto;
        padding-right:4px;
    }

    .gallery-preview{
        order:1;
        min-height:360px;
    }

    .gallery-modal-grid{
        order:2;
        max-height:none;
        overflow:visible;
        padding-right:0;
        grid-template-columns:repeat(3,minmax(0,1fr));
        grid-auto-rows:150px;
    }
}

@media (max-width:768px){
    .gallery-modal-overlay{
        align-items:flex-start;
        padding:10px;
        overflow-y:auto;
    }

    .gallery-modal-box{
        width:100%;
        max-height:none;
        min-height:calc(100dvh - 20px);
        border-radius:18px;
        padding:22px 16px 18px;
    }

    .gallery-modal-close{
        top:10px;
        right:10px;
        width:40px;
        height:40px;
    }

    .gallery-modal-header{
        padding-right:48px;
    }

    .gallery-modal-header h2{
        font-size:28px;
    }

    .gallery-preview{
        min-height:260px;
        border-radius:14px;
    }

    .gallery-modal-grid{
        grid-template-columns:repeat(2,minmax(0,1fr));
        grid-auto-rows:128px;
        gap:10px;
    }

    .gallery-preview-caption{
        left:12px;
        right:12px;
        bottom:12px;
        padding:10px 12px;
        font-size:13px;
    }
}

@media (max-width:420px){
    .gallery-preview{
        min-height:220px;
    }

    .gallery-modal-grid{
        grid-auto-rows:112px;
    }
}
