/*
Theme Name: JNews
Version: 7.2.0
Theme URI: http://themeforest.net
Description: JNews
Author: Jegtheme
Author URI: http://jegtheme.com/
License: GNU General Public License v2.0
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags:  custom-background,custom-colors, custom-menu, editor-style, featured-images, full-width-template, sticky-post, theme-options, threaded-comments, translation-ready
Text Domain: jnews
*/
function jep_display_recent_posts() {
    ob_start();
    ?>
    <style>
        /* Le CSS reste identique pour garantir le look clean */
        .jep-blog-section { max-width: 1200px; margin: 40px auto; padding: 0 20px; font-family: 'Montserrat', sans-serif; }
        .jep-section-header { text-align: left; margin-bottom: 40px; border-bottom: 2px solid #eee; padding-bottom: 15px; }
        .jep-section-header h2 { font-family: 'Playfair Display', serif; font-size: 32px; color: #051221; margin: 0; }
        .jep-articles-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 30px; }
        .jep-post-card { display: flex; flex-direction: column; transition: 0.3s; text-decoration: none; color: inherit; background: #fff; }
        .jep-post-card:hover { transform: translateY(-5px); }
        .jep-post-image { width: 100%; height: 200px; background-size: cover; background-position: center; border-radius: 8px; margin-bottom: 15px; }
        .jep-post-meta { font-size: 11px; text-transform: uppercase; color: #c49a6c; font-weight: 700; letter-spacing: 1.2px; margin-bottom: 8px; display: block; }
        .jep-post-card h3 { font-family: 'Playfair Display', serif; font-size: 20px; color: #051221; margin: 0 0 10px 0; line-height: 1.4; }
        .jep-post-excerpt { font-size: 14px; color: #666; line-height: 1.6; margin-bottom: 15px; }
        .jep-read-more { font-size: 12px; font-weight: 700; color: #051221; text-transform: uppercase; display: flex; align-items: center; gap: 5px; }
        @media (max-width: 768px) { .jep-articles-grid { grid-template-columns: 1fr; } }
    </style>

    <section class="jep-blog-section">
        <div class="jep-section-header">
            <h2>Dernières Publications</h2>
        </div>
        <div class="jep-articles-grid">
            <?php
            $query = new WP_Query(array('posts_per_page' => 3, 'post_status' => 'publish'));
            if ($query->have_posts()) :
                while ($query->have_posts()) : $query->the_post(); 
                    $thumb = get_the_post_thumbnail_url(get_the_ID(), 'medium_large') ?: 'https://via.placeholder.com/600x400';
                    $cats = get_the_category();
                    $cat_name = !empty($cats) ? $cats[0]->name : 'Article';
            ?>
            <a href="<?php the_permalink(); ?>" class="jep-post-card">
                <div class="jep-post-image" style="background-image: url('<?php echo esc_url($thumb); ?>');"></div>
                <span class="jep-post-meta"><?php echo esc_html($cat_name); ?></span>
                <h3><?php the_title(); ?></h3>
                <p class="jep-post-excerpt"><?php echo wp_trim_words(get_the_excerpt(), 15, '...'); ?></p>
                <span class="jep-read-more">Lire la suite</span>
            </a>
            <?php endwhile; wp_reset_postdata(); endif; ?>
        </div>
    </section>
    <?php
    return ob_get_clean();
}
add_shortcode('jep_articles', 'jep_display_recent_posts');