/**
 * ForgR Homepage Layout: MOSAIC
 * Based on fluenzr blog design
 * Supports wide, tall, and full-width card variants
 */

/* Hide page title on homepage */
.home .entry-title,
.blog .entry-title,
.home .page-header,
.blog .page-header,
.home h1.entry-title,
.blog h1.entry-title,
body.home .site-main > article > header,
body.blog .site-main > article > header {
    display: none !important;
}

/* =====================================================================
 * 1. STYLES DE BASE POUR TOUS LES BLOCS WP-BLOCK-LATEST-POSTS
 * ===================================================================== */

.wp-block-latest-posts.is-grid li {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: left;
    background-color: inherit !important;
    border-radius: 0.2rem;
    box-shadow: rgba(149, 157, 165, 0.2) 0px 8px 24px;
    padding: 1rem;
    margin-bottom: 1rem;
    position: relative;
}

.wp-block-latest-posts__post-title {
    font-size: 2rem;
    line-height: 2.5rem;
    color: var(--font-color, #000);
    text-decoration: none;
    position: static;
    display: inline;
    z-index: 2;
}

.wp-block-latest-posts__post-title:hover {
    color: var(--forgr-primary, #2029d9);
    text-decoration: underline;
}

/* =====================================================================
 * 2. SYSTÈME DE LIENS ÉTIRÉS (STRETCHED LINKS)
 * ===================================================================== */

.wp-block-latest-posts .wp-block-latest-posts__post-title::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    cursor: pointer;
}

.wp-block-latest-posts .read-more {
    position: relative;
    z-index: 3;
}

/* =====================================================================
 * 3. MOSAÏQUE PRINCIPALE (home-mosaic)
 * ===================================================================== */

.home-mosaic.wp-block-latest-posts.is-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1.5rem;
    grid-auto-flow: dense;
}

/* Annulation des styles WordPress par défaut */
.home-mosaic.wp-block-latest-posts[class*="columns-"] li,
.home-mosaic.wp-block-latest-posts.columns-3 li {
    width: auto !important;
    flex: initial !important;
    margin: 0 !important;
}

/* Style des cartes de la mosaïque */
.home-mosaic li {
    list-style: none;
    background: #fff;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 6px 20px rgba(0,0,0,.06);
    transition: transform .2s ease, box-shadow .2s ease;
    cursor: pointer;
}

.home-mosaic li:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 28px rgba(0,0,0,.1);
}

/* Images dans la mosaïque */
.home-mosaic .wp-block-latest-posts__featured-image {
    overflow: hidden;
}

.home-mosaic .wp-block-latest-posts__featured-image a {
    display: block;
    min-width: 100%;
    height: 100%;
}

.home-mosaic .wp-block-latest-posts__featured-image img {
    width: 100%;
    height: auto;
    display: block;
}

/* =====================================================================
 * 4. VARIANTES DE CARTES (WIDE & TALL)
 * ===================================================================== */

/* Carte large (2 colonnes) */
.home-mosaic li.wide {
    grid-column: span 2;
}

/* Carte haute (2 lignes) */
.home-mosaic li.tall {
    grid-row: span 2;
}

/* =====================================================================
 * 5. STYLE SPÉCIAL POUR LES CARTES WIDE (HERO-STYLE)
 * ===================================================================== */

.home-mosaic.wp-block-latest-posts.is-grid li.wide {
    grid-column: span 2;
    position: relative;
    min-height: 380px;
    padding: 0;
    background: #000;
    overflow: hidden;
}

/* Image en arrière-plan couvrant toute la carte */
.home-mosaic li.wide .wp-block-latest-posts__featured-image {
    position: absolute;
    inset: 0;
    z-index: 0;
}

.home-mosaic li.wide .wp-block-latest-posts__featured-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* Masquer l'extrait et "Lire la suite" sur les cartes wide */
.home-mosaic li.wide .wp-block-latest-posts__post-excerpt,
.home-mosaic li.wide .read-more {
    display: none !important;
}

/* Overlay cliquable */
.home-mosaic li.wide::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 10;
    cursor: pointer;
    background: transparent;
}

/* Gradient pour améliorer la lisibilité du titre */
.home-mosaic li.wide::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0,0,0,.55), rgba(0,0,0,0) 55%);
    z-index: 1;
    pointer-events: none;
}

/* Titre positionné en bas à gauche */
.home-mosaic li.wide .wp-block-latest-posts__post-title {
    position: absolute;
    left: 1rem;
    bottom: 1rem;
    margin: 0;
    padding: .5rem .75rem;
    color: #fff !important;
    background: rgba(0,0,0,.6);
    border-radius: .5rem;
    z-index: 11;
    text-decoration: none;
    pointer-events: auto;
}

.home-mosaic li.wide .wp-block-latest-posts__post-title:hover {
    text-decoration: underline;
}

.home-mosaic li.wide .wp-block-latest-posts__post-title::after {
    display: none;
}

/* =====================================================================
 * 6. NORMAL CARD (1 colonne)
 * ===================================================================== */

.home-mosaic.wp-block-latest-posts.is-grid li:not(.wide):not(.full-width) {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Conteneur image */
.home-mosaic li:not(.wide):not(.full-width) .wp-block-latest-posts__featured-image {
    width: 100%;
    height: 220px;
    overflow: hidden;
    position: relative;
}

/* Image cover */
.home-mosaic li:not(.wide):not(.full-width) .wp-block-latest-posts__featured-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
}

/* Contenu sous l'image */
.home-mosaic li:not(.wide):not(.full-width) .wp-block-latest-posts__post-title,
.home-mosaic li:not(.wide):not(.full-width) .wp-block-latest-posts__post-excerpt {
    padding: 1rem 1.2rem;
}

/* =====================================================================
 * 7. CARTES FULL-WIDTH (HERO HORIZONTAL - À LA UNE)
 * ===================================================================== */

.home-mosaic li.full-width {
    grid-column: span 3;
    display: flex !important;
    flex-direction: row !important;
    min-height: 320px;
    padding: 0;
    background: #fff;
    overflow: hidden;
    box-shadow: 0 6px 20px rgba(0,0,0,.06);
    margin-bottom: 2rem;
    align-items: stretch;
    border-radius: 16px;
}

/* Image à gauche (50%) */
.home-mosaic li.full-width .wp-block-latest-posts__featured-image {
    flex: 0 0 50% !important;
    width: 50% !important;
    max-width: 50%;
    height: auto !important;
    display: flex !important;
    align-items: center;
    overflow: hidden;
    position: relative;
}

.home-mosaic li.full-width .wp-block-latest-posts__featured-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Contenu à droite (50%) */
.home-mosaic li.full-width .full-width-content {
    flex: 1 1 50% !important;
    max-width: 50%;
    padding: 3rem !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    gap: 1rem;
    background: #fff;
}

/* Catégorie dans le contenu */
.home-mosaic li.full-width .full-width-content .post-category {
    display: inline-block;
    background: var(--forgr-primary, #2029d9);
    color: #fff;
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    text-decoration: none;
    align-self: flex-start;
    max-width: fit-content;
}

/* Titre dans le contenu */
.home-mosaic li.full-width .full-width-content .wp-block-latest-posts__post-title {
    font-size: 2rem;
    line-height: 1.2;
    color: var(--font-color, #000);
    margin: 0 0 1rem 0;
    text-align: left;
    font-weight: 700;
    text-decoration: none;
    display: block;
}

.home-mosaic li.full-width .full-width-content .wp-block-latest-posts__post-title:hover {
    color: var(--forgr-primary, #2029d9);
    text-decoration: underline;
}

/* Excerpt dans le contenu */
.home-mosaic li.full-width .full-width-content .wp-block-latest-posts__post-excerpt {
    font-size: 1rem;
    line-height: 1.6;
    color: #666;
    margin: 0;
    text-align: left;
}

/* Ordre correct des éléments */
.home-mosaic li.full-width .full-width-content .post-category {
    order: 1 !important;
}

.home-mosaic li.full-width .full-width-content .wp-block-latest-posts__post-title {
    order: 2 !important;
}

.home-mosaic li.full-width .full-width-content .wp-block-latest-posts__post-excerpt {
    order: 3 !important;
}

/* Avant que le JS crée le wrapper */
.home-mosaic li.full-width > .wp-block-latest-posts__post-title,
.home-mosaic li.full-width > .wp-block-latest-posts__post-excerpt {
    flex: 1 1 100%;
    max-width: 100%;
    padding: 2rem;
}

/* Après regroupement (wrapper présent) */
.home-mosaic li.full-width .full-width-content > .wp-block-latest-posts__post-title {
    padding: 0;
    font-size: 2rem;
    line-height: 1.2;
    margin: 0 0 .75rem 0;
}

.home-mosaic li.full-width .full-width-content > .wp-block-latest-posts__post-excerpt {
    padding: 0;
    margin: 0;
    line-height: 1.55;
    font-size: 1rem;
    color: #555;
}

/* Supprimer la duplication visuelle une fois le wrapper en place */
.home-mosaic li.full-width.fullwidth-wrapped > .wp-block-latest-posts__post-title,
.home-mosaic li.full-width.fullwidth-wrapped > .wp-block-latest-posts__post-excerpt {
    display: none !important;
}

/* =====================================================================
 * 8. GESTION DES EXTRAITS SELON LE CONTEXTE
 * ===================================================================== */

/* Masquer l'extrait sur les cartes normales seules */
.home-mosaic li.single-normal .wp-block-latest-posts__post-excerpt,
.home-mosaic li.single-normal .read-more {
    display: none !important;
}

/* Les cartes normales en groupe de 3 gardent leur extrait */
.home-mosaic li:not(.wide):not(.single-normal):not(.full-width) .wp-block-latest-posts__post-excerpt,
.home-mosaic li:not(.wide):not(.single-normal):not(.full-width) .read-more {
    display: block;
}

/* Ajustement du padding pour les cartes single-normal */
.home-mosaic li.single-normal {
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* =====================================================================
 * 9. OPTIMISATIONS POUR ÉVITER LE FLASH DE CONTENU NON STYLÉ (FOUC)
 * ===================================================================== */

.home-mosaic li.full-width.restructuring {
    opacity: 0;
    transition: opacity 0.1s ease;
}

.home-mosaic li.full-width.restructured {
    opacity: 1;
    transition: opacity 0.2s ease;
}

/* Accélération matérielle pour les transitions */
.home-mosaic li {
    will-change: transform, box-shadow;
    backface-visibility: hidden;
    transform: translateZ(0);
}

/* =====================================================================
 * 10. RESPONSIVE DESIGN
 * ===================================================================== */

/* TABLETTE (max 1024px) */
@media (max-width: 1024px) {
    .home-mosaic.wp-block-latest-posts.is-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .home-mosaic li.wide {
        grid-column: span 1;
        min-height: 320px;
    }

    .home-mosaic li:not(.wide):not(.full-width) .wp-block-latest-posts__featured-image {
        height: 180px;
    }

    .home-mosaic li.full-width {
        flex-direction: column !important;
        min-height: auto;
        grid-column: span 2;
    }

    .home-mosaic li.full-width .wp-block-latest-posts__featured-image {
        flex: 0 0 250px !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    .home-mosaic li.full-width .full-width-content {
        flex: 1 !important;
        width: 100% !important;
        max-width: 100% !important;
        padding: 1.5rem !important;
    }

    .home-mosaic li.full-width .full-width-content .wp-block-latest-posts__post-title {
        font-size: 1.8rem;
    }
}

/* MOBILE (max 767px) */
@media (max-width: 767px) {
    .home-mosaic.wp-block-latest-posts.is-grid {
        grid-template-columns: 1fr;
    }

    .home-mosaic li.wide {
        min-height: 240px;
    }

    .home-mosaic li:not(.wide):not(.full-width) .wp-block-latest-posts__featured-image {
        height: 160px;
    }

    .home-mosaic li.full-width {
        grid-column: span 1;
    }

    .home-mosaic li.full-width .wp-block-latest-posts__featured-image {
        flex: 0 0 200px !important;
        height: 200px !important;
    }

    .home-mosaic li.full-width .full-width-content {
        padding: 1rem !important;
    }

    .home-mosaic li.full-width .full-width-content .wp-block-latest-posts__post-title {
        font-size: 1.5rem;
    }

    .wp-block-latest-posts {
        margin-left: 0;
    }
}

/* =====================================================================
 * 11. LAYOUT MOSAIC POUR TEMPLATE CUSTOM (posts-grid)
 * Version alternative utilisant .posts-grid article
 * ===================================================================== */

.layout-mosaic .posts-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1.5rem;
    grid-auto-flow: dense;
}

.layout-mosaic .posts-grid article {
    list-style: none;
    background: #fff;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 6px 20px rgba(0,0,0,.06);
    transition: transform .2s ease, box-shadow .2s ease;
    position: relative;
}

.layout-mosaic .posts-grid article:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 28px rgba(0,0,0,.1);
}

/* Premier article en mode "À la une" */
.layout-mosaic .posts-grid article:first-child {
    grid-column: 1 / -1;
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    min-height: 400px;
    padding: 0 !important;
    align-items: stretch;
}

.layout-mosaic .posts-grid article:first-child .post-thumbnail-wrapper {
    grid-column: 1;
    grid-row: 1;
    height: 100%;
    min-height: 50vh;
    max-height: 500px;
    overflow: hidden;
    position: relative;
}

.layout-mosaic .posts-grid article:first-child .post-thumbnail {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
}

.layout-mosaic .posts-grid article:first-child .entry-content {
    grid-column: 2;
    grid-row: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 3rem;
    gap: 1rem;
    background: #fff;
}

.layout-mosaic .posts-grid article:first-child .entry-title {
    font-size: 2rem;
    line-height: 1.2;
    font-weight: 700;
    margin: 0 0 0.75rem 0;
}

.layout-mosaic .posts-grid article:first-child .entry-summary {
    font-size: 1.1rem;
    line-height: 1.6;
    -webkit-line-clamp: 5;
}

/* Badge "À la une" pour le premier article */
.layout-mosaic .posts-grid article:first-child::before {
    content: 'À la une';
    position: absolute;
    top: 1rem;
    left: 1rem;
    z-index: 2;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: white;
    background: var(--forgr-primary, #2029d9);
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    font-weight: 600;
}

/* Cartes normales */
.layout-mosaic .posts-grid article:not(:first-child) {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.layout-mosaic .posts-grid article:not(:first-child) .post-thumbnail-wrapper {
    width: 100%;
    height: 220px;
    overflow: hidden;
    position: relative;
}

.layout-mosaic .posts-grid article:not(:first-child) .post-thumbnail {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
    transition: transform 0.4s ease;
}

.layout-mosaic .posts-grid article:not(:first-child):hover .post-thumbnail {
    transform: scale(1.05);
}

.layout-mosaic .posts-grid article:not(:first-child) .entry-content {
    padding: 1.25rem;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.layout-mosaic .posts-grid article:not(:first-child) .entry-title {
    font-size: 1.1rem;
    line-height: 1.4;
    margin-bottom: 0.5rem;
}

/* Shared styles */
.layout-mosaic .posts-grid article .entry-category {
    display: inline-block;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: white;
    background: var(--forgr-primary, #2029d9);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-weight: 600;
    margin-bottom: 0.75rem;
    align-self: flex-start;
}

.layout-mosaic .posts-grid article .entry-title a {
    text-decoration: none;
    color: inherit;
}

.layout-mosaic .posts-grid article .entry-title a:hover {
    color: var(--forgr-primary, #2029d9);
}

.layout-mosaic .posts-grid article .entry-summary {
    font-size: 0.9rem;
    color: #666;
    line-height: 1.6;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.layout-mosaic .posts-grid article .entry-meta {
    font-size: 0.75rem;
    color: #999;
    margin-top: auto;
    padding-top: 0.75rem;
    border-top: 1px solid #f0f0f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Responsive pour .posts-grid */
@media (max-width: 1024px) {
    .layout-mosaic .posts-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .layout-mosaic .posts-grid article:first-child {
        grid-template-columns: 1fr !important;
    }

    .layout-mosaic .posts-grid article:first-child .post-thumbnail-wrapper {
        grid-column: 1;
        grid-row: 1;
        height: 300px;
        min-height: 300px;
    }

    .layout-mosaic .posts-grid article:first-child .entry-content {
        grid-column: 1;
        grid-row: 2;
        padding: 2rem;
    }

    .layout-mosaic .posts-grid article:first-child .entry-title {
        font-size: 1.75rem;
    }

    .layout-mosaic .posts-grid article:not(:first-child) .post-thumbnail-wrapper {
        height: 180px;
    }
}

@media (max-width: 767px) {
    .layout-mosaic .posts-grid {
        grid-template-columns: 1fr;
    }

    .layout-mosaic .posts-grid article:first-child .post-thumbnail-wrapper {
        height: 250px;
        min-height: 250px;
    }

    .layout-mosaic .posts-grid article:first-child .entry-content {
        padding: 1.5rem;
    }

    .layout-mosaic .posts-grid article:first-child .entry-title {
        font-size: 1.5rem;
    }

    .layout-mosaic .posts-grid article:first-child .entry-summary {
        font-size: 1rem;
        -webkit-line-clamp: 3;
    }

    .layout-mosaic .posts-grid article:not(:first-child) .post-thumbnail-wrapper {
        height: 160px;
    }
}
