/* GALERIJAS KONTEINERS */
.gallery-container {
    display: grid;
    /* Mainām no 'repeat(3, 1fr)' uz 'auto-fill'. 
       Tas automātiski pielāgos kolonnu skaitu ekrāna izmēram. */
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); 
    grid-auto-rows: 300px; 
    grid-auto-flow: dense; 
    gap: 30px; 
    
    /* ATSTARPES NO MALĀM */
    max-width: 1200px; 
    margin: 0 auto;
    padding: 80px 25px;
    
    /* Šis nodrošinās, ka, ja pēdējā rindā ir mazāk bilžu, tās būs centrā */
    justify-content: center; 
}

/* Ja bildei pieliksi klasi 'wide', tā aizņems 2 vietas */
.gallery-item.wide {
    grid-column: span 2;
}

/* --- JAUNĀ MOZAĪKAS LOGIKA --- */

/* 1. elements: HORIZONTĀLS (Plats) */
.project-wrapper:nth-child(1) {
    grid-column: span 2;
}

/* 2. elements: VERTIKĀLS (Garš) */
/* Šis izstiepsies cauri 2 rindām uz leju */
.project-wrapper:nth-child(2) {
    grid-row: span 2;
}

/* 5. elements: VERTIKĀLS */
.project-wrapper:nth-child(5) {
    grid-row: span 2;
}

/* 6. elements: HORIZONTĀLS */
.project-wrapper:nth-child(6) {
    grid-column: span 2;
}

/* --- KARTĪŠU STILS --- */
.gallery-item {
    display: block;
    height: 100%;
    width: 100%;
    border-radius: 32px; /* Saskaņots ar citām lapām */
    overflow: hidden;
    position: relative;
    text-decoration: none;
    background: var(--bg-subtle);
    transition: var(--transition-smooth);
}

.image-box {
    width: 100%;
    height: 100%;
}

.image-box img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.8s cubic-bezier(0.2, 0, 0.2, 1);
}

/* Informācijas parādīšanās uz hover */
.project-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 30px;
    background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
    backdrop-filter: blur(1px);
    color: white;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.4s ease;
    z-index: 2;
}

.gallery-item:hover .project-info {
    opacity: 1;
    transform: translateY(0);
}

.gallery-item:hover img {
    transform: scale(1.08);
}

/* RESPONSĪVAIS DIZAINS */
@media (max-width: 1100px) {
    .gallery-container {
        grid-template-columns: repeat(2, 1fr);
        padding: 60px 20px;
    }
    /* Noņemam specifiskos izmērus uz vidējiem ekrāniem, lai nesalauztu režģi */
    .project-wrapper:nth-child(n) {
        grid-column: span 1;
        grid-row: span 1;
    }
    /* Bet pirmais joprojām var palikt liels */
    .project-wrapper:nth-child(1) {
        grid-column: span 2;
    }
}

/* Ik pēc 5 bildēm viena būs lielāka un izcelsies */
.project-wrapper:nth-child(5n) {
    grid-column: span 2;
    grid-row: span 2;
}

@media (max-width: 700px) {
    .gallery-container {
        grid-template-columns: 1fr;
        grid-auto-rows: 350px;
    }
    .project-wrapper:nth-child(n) {
        grid-column: span 1 !important;
        grid-row: span 1 !important;
    }
}

.stat h4 {
    display: inline-block; /* Lai skaitlis un + zīme būtu blakus */
    font-size: 2.5rem;
    color: var(--primary);
    font-weight: 800;
}

.unit {
    margin-left: -5px; /* Pievelk zīmi tuvāk skaitlim */
}

/* Fancybox video pielāgošana mobilajiem ekrāniem */
.fancybox__slide.has-html5video .fancybox__content {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    padding: 0 !important; /* Noņemam liekās malas */
}

.fancybox__html5video {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important; /* Saglabā video proporcijas, nenogriežot malas */
    background: #000; /* Melns fons, lai saplūstu ar galeriju */
}

/* Neitrāls video priekšskatījums Fancybox joslai apakšā */
.fancybox__thumbs .fancybox__thumb.has-video .fancybox__thumb-label {
    background: #2a2a2a; /* Neitrāls, tumši pelēks fons */
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    border-radius: 4px;
    overflow: hidden;
}

/* Uzzīmējam balto "Play" trijstūri ar CSS */
.fancybox__thumbs .fancybox__thumb.has-video .fancybox__thumb-label::after {
    content: '';
    display: block;
    width: 0;
    height: 0;
    border-top: 10px solid transparent;
    border-bottom: 10px solid transparent;
    border-left: 16px solid #fff; /* Baltā trijstūra krāsa */
    margin-left: 4px; /* Nedaudz pabīdām, lai vizuāli būtu centrā */
    opacity: 0.8;
}

/* Pievienojam nelielu ēnu un efektu, kad uziet ar peli */
.fancybox__thumbs .fancybox__thumb.has-video:hover .fancybox__thumb-label::after {
    opacity: 1;
    transform: scale(1.1);
    transition: all 0.2s ease;
}

