/* Fail: final_grid.css (LÕPLIK PARANDUS: COLUMNS DESKTOPIS, GRID MOBIILIS) */

/* ============================================= */
/* VAIKIMISI (DESKTOP > 768px): COLUMNS-PAIGUTUS */
/* ============================================= */

.card-grid-masonry {
    column-count: 4;
    column-gap: 20px;
}

.card-item {
    /* Need reeglid on VAJALIKUD desktopi columns-vaate jaoks */
    display: inline-block;
    width: 100%;
    margin-bottom: 20px;
    break-inside: avoid;
    
    /* Üldised visuaalsed stiilid */
    background-color: #ffffff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    text-decoration: none;
    color: #333;
}

.card-item.landscape .card-image-wrapper {
    aspect-ratio: 16 / 9;
}


/* ============================================= */
/* KAARDI SISEMINE SISU                          */
/* ============================================= */

.card-image-wrapper {
    overflow: hidden;
    width: 100%;
    aspect-ratio: 1 / 1;
}

.card-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.card-title-container {
    padding: 20px 15px;
    text-align: center;
    border-top: 1px solid #f0f0f0;
}

.card-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}


/* ============================================= */
/* MUUD STIILID (JÄÄVAD SAMAKS)                  */
/* ============================================= */
#scrollToTopBtn { display: none; position: fixed; bottom: 20px; right: 30px; z-index: 99; border: none; outline: none; background-color: #555; color: white; cursor: pointer; padding: 15px; border-radius: 50%; font-size: 18px; line-height: 1; width: 50px; height: 50px; box-shadow: 0 4px 8px rgba(0,0,0,0.2); transition: background-color 0.3s, opacity 0.3s; }
#scrollToTopBtn:hover { background-color: #e7c4a4; }
.category-nav, .subcategory-navigation { width: 100%; margin-top: 20px; margin-bottom: 40px; display: flex; justify-content: center; }
.category-nav ul, .subcategory-navigation ul, .name-links { display: flex; flex-wrap: wrap; justify-content: center; list-style-type: none; padding: 0; margin: 0; gap: 10px; }
.category-nav a, .subcategory-navigation a, .name-links a { display: block; padding: 10px 18px; background-color: #e7c4a4; color: #fff; text-decoration: none; border-radius: 6px; font-size: 15px; font-family: 'Roboto', sans-serif; font-weight: 500; transition: background-color 0.2s ease, transform 0.2s ease; white-space: nowrap; }
.category-nav a:hover, .subcategory-navigation a:hover, .name-links a:hover { background-color: #c2966c; color: #fff; transform: translateY(-2px); }
.category-nav a.active, .subcategory-navigation a.active { background-color: #c2966c; color: #fff; pointer-events: none; }
.name-statistics { text-align: center; padding: 40px 20px; margin-top: 60px; background-color: #f8f9fa; border-radius: 8px; }
.name-statistics h2 { margin-top: 0; margin-bottom: 0.5rem; font-size: 1.75rem; }
.name-statistics p { margin-bottom: 1.5rem; font-size: 1.1rem; color: #6c757d; }

/* ============================================= */
/* RESPONSIVE MUUDATUSED                         */
/* ============================================= */

@media (max-width: 1200px) {
    .card-grid-masonry { column-count: 3; }
}
@media (max-width: 992px) {
    .card-grid-masonry { column-count: 2; }
}

/* === MOBIILIVAADE (< 768px): LÄHME TAGASI SINU ALGSE GRID-VAATE JUURDE === */
@media (max-width: 768px) {
    .category-nav ul, .subcategory-navigation ul, .name-links ul { gap: 8px; }
    .category-nav a, .subcategory-navigation a, .name-links a { padding: 8px 12px; font-size: 14px; border-radius: 4px; }
    
    /* 1. TAASTAME GRID KONTEINERI (see on juba õige) */
    .card-grid-masonry { 
        display: grid;
        grid-template-columns: repeat(2, 1fr); 
        gap: 15px; 
        column-count: auto; /* Tühistame desktopi reegli */
    }
    
    /* 2. TAASTAME KAARDI ALGSED STIILID (see on juba õige) */
    .card-item {
        display: flex;
        flex-direction: column;
        width: auto;        /* Tühistame desktopi 'width: 100%' */
        margin-bottom: 0;   /* Tühistame desktopi 'margin-bottom' */
        break-inside: auto; /* Tühistame desktopi reegli */
    }
    
    /* 3. PARANDATUD REEGLID SOOVITUD PAIGUTUSE JAOKS */
    .card-item.landscape { 
        /* See on peamine parandus: käsime elemendil võtta enda alla 2 veergu */
        grid-column: span 2; 
    }
    .card-item.landscape .card-image-wrapper { 
        /* Taastame laiema kuvasuhte, et pilt näeks parem välja */
        aspect-ratio: 16 / 9; 
    }
}

/* Väike mobiil */
@media (max-width: 480px) {
    .category-nav ul, .subcategory-navigation ul, .name-links ul { gap: 6px; }
    .category-nav a, .subcategory-navigation a, .name-links a { padding: 6px 10px; font-size: 13px; }
    .card-grid-masonry {
        grid-template-columns: 1fr;
    }
}

/* ============================================= */
/* KUTSE MUUTMISE NUPU STIILID (JÄÄB SAMAKS)     */
/* ============================================= */
.card-item-wrapper { position: relative; }
.card-title-container { padding: 20px 15px; }
.card-edit-button { display: inline-block; margin-top: 15px; padding: 10px 25px; background-color: #e7c4a4; color: #fff !important; text-decoration: none; border-radius: 6px; font-size: 15px; font-family: 'Roboto', sans-serif; font-weight: 500; transition: background-color 0.2s ease, transform 0.2s ease; white-space: nowrap; }
.card-edit-button:hover { background-color: #c2966c; transform: translateY(-2px); }