.elementor-1714 .elementor-element.elementor-element-c35fc43{--display:flex;}.elementor-1714 .elementor-element.elementor-element-d566604{--display:flex;}/* Start custom CSS for html, class: .elementor-element-199865e */function sgl_latest_contract_articles() {

    $category = get_category_by_slug('قراردادها-و-تعهدات');

    if (!$category) {
        $categories = get_categories(array(
            'hide_empty' => false
        ));

        foreach ($categories as $cat) {
            if (trim($cat->name) === 'قراردادها و تعهدات') {
                $category = $cat;
                break;
            }
        }
    }

    if (!$category) {
        return '<div class="sgl-no-articles">دسته «قراردادها و تعهدات» پیدا نشد.</div>';
    }

    $articles = new WP_Query(array(
        'post_type'      => 'post',
        'posts_per_page' => 3,
        'post_status'    => 'publish',
        'cat'            => $category->term_id,
        'orderby'        => 'date',
        'order'          => 'DESC',
        'ignore_sticky_posts' => true
    ));

    if (!$articles->have_posts()) {
        return '<div class="sgl-no-articles">هنوز مقاله‌ای در این دسته ثبت نشده است.</div>';
    }

    ob_start();
    ?>

    <div class="sgl-contract-section">

        <div class="sgl-contract-grid">

            <?php while ($articles->have_posts()) : $articles->the_post(); ?>

                <article class="sgl-contract-card">

                    <!-- تصویر مقاله -->
                    <a class="sgl-card-image" href="<?php the_permalink(); ?>">

                        <?php if (has_post_thumbnail()) : ?>

                            <?php
                            the_post_thumbnail(
                                'large',
                                array(
                                    'class'   => 'sgl-featured-image',
                                    'loading' => 'lazy',
                                    'alt'     => esc_attr(get_the_title())
                                )
                            );
                            ?>

                        <?php else : ?>

                            <div class="sgl-no-image">
                                تصویر مقاله
                            </div>

                        <?php endif; ?>

                    </a>

                    <!-- محتوای کارت -->
                    <div class="sgl-card-content">

                        <!-- تاریخ -->
                        <div class="sgl-card-date">
                            <?php echo esc_html(get_the_date('Y/m/d')); ?>
                        </div>

                        <!-- عنوان -->
                        <h3 class="sgl-card-title">

                            <a href="<?php the_permalink(); ?>">
                                <?php the_title(); ?>
                            </a>

                        </h3>

                        <!-- خلاصه -->
                        <div class="sgl-card-excerpt">

                            <?php
                            $excerpt = get_the_excerpt();

                            if (!$excerpt) {
                                $excerpt = wp_trim_words(
                                    wp_strip_all_tags(get_the_content()),
                                    24,
                                    '...'
                                );
                            }

                            echo esc_html($excerpt);
                            ?>

                        </div>

                        <!-- پایین کارت -->
                        <div class="sgl-card-bottom">

                            <span class="sgl-card-category">
                                <?php echo esc_html($category->name); ?>
                            </span>

                            <a
                                class="sgl-read-more"
                                href="<?php the_permalink(); ?>"
                            >
                                مطالعه مقاله ←
                            </a>

                        </div>

                    </div>

                </article>

            <?php endwhile; ?>

        </div>

    </div>

    <?php

    wp_reset_postdata();

    return ob_get_clean();
}

add_shortcode(
    'sgl_contract_articles',
    'sgl_latest_contract_articles'
);


/* =========================
   استایل مقالات
========================= */

function sgl_contract_articles_styles() {
    ?>

    <style>

        .sgl-contract-section {
            width: 100%;
            direction: rtl;
        }

        .sgl-contract-grid {
            width: 100%;
            max-width: 1200px;
            margin: 0 auto;

            display: grid;
            grid-template-columns: repeat(3, minmax(0, 1fr));

            gap: 24px;
            align-items: stretch;
        }

        .sgl-contract-card {
            background: #ffffff;

            border: 1px solid #C9921E;
            border-radius: 14px;

            overflow: hidden;

            display: flex;
            flex-direction: column;

            min-width: 0;

            box-shadow:
                0 6px 18px rgba(0, 0, 0, 0.06);

            transition:
                transform 0.25s ease,
                box-shadow 0.25s ease;
        }

        .sgl-contract-card:hover {
            transform: translateY(-4px);

            box-shadow:
                0 12px 28px rgba(0, 0, 0, 0.10);
        }

        /* تصویر */

        .sgl-card-image {
            display: block;

            width: 100%;
            height: 230px;

            overflow: hidden;

            background: #f1f1f1;

            text-decoration: none;
        }

        .sgl-card-image img.sgl-featured-image {
            display: block;

            width: 100%;
            height: 100%;

            object-fit: cover;

            margin: 0;
            padding: 0;

            transition: transform 0.35s ease;
        }

        .sgl-contract-card:hover
        .sgl-card-image img.sgl-featured-image {
            transform: scale(1.04);
        }

        .sgl-no-image {
            width: 100%;
            height: 100%;

            display: flex;
            align-items: center;
            justify-content: center;

            background: #f3f3f3;

            color: #06264A;

            font-size: 16px;
        }

        /* محتوای کارت */

        .sgl-card-content {
            padding: 22px 24px 20px;

            display: flex;
            flex-direction: column;

            flex: 1;

            text-align: right;
        }

        /* تاریخ */

        .sgl-card-date {
            color: #8a8a8a;

            font-size: 13px;

            line-height: 1.7;

            margin-bottom: 12px;
        }

        /* عنوان */

        .sgl-card-title {
            margin: 0 0 16px;

            padding-right: 12px;

            border-right: 3px solid #06264A;

            font-size: 20px;

            line-height: 2;

            font-weight: 700;
        }

        .sgl-card-title a {
            color: #06264A;

            text-decoration: none;
        }

        .sgl-card-title a:hover {
            color: #C9921E;
        }

        /* خلاصه */

        .sgl-card-excerpt {
            color: #333333;

            font-size: 15px;

            line-height: 2;

            margin-bottom: 24px;

            display: -webkit-box;

            -webkit-line-clamp: 3;
            -webkit-box-orient: vertical;

            overflow: hidden;
        }

        /* پایین کارت */

        .sgl-card-bottom {
            margin-top: auto;

            display: flex;

            align-items: center;
            justify-content: space-between;

            gap: 12px;
        }

        .sgl-card-category {
            color: #06264A;

            font-size: 13px;
        }

        .sgl-read-more {
            color: #C9921E;

            font-size: 14px;

            font-weight: 700;

            text-decoration: none;

            white-space: nowrap;
        }

        .sgl-read-more:hover {
            color: #06264A;
        }

        .sgl-no-articles {
            text-align: center;

            color: #06264A;

            font-size: 16px;

            padding: 30px;
        }


        /* =========================
           تبلت
        ========================= */

        @media (max-width: 1024px) {

            .sgl-contract-grid {
                grid-template-columns: repeat(2, minmax(0, 1fr));

                gap: 20px;
            }

            .sgl-card-image {
                height: 210px;
            }

        }


        /* =========================
           موبایل
        ========================= */

        @media (max-width: 767px) {

            .sgl-contract-grid {
                grid-template-columns: 1fr;

                gap: 18px;
            }

            .sgl-card-image {
                height: 220px;
            }

            .sgl-card-content {
                padding: 20px;
            }

            .sgl-card-title {
                font-size: 18px;

                line-height: 1.9;
            }

            .sgl-card-excerpt {
                font-size: 14px;
            }

        }

    </style>

    <?php
}

add_action(
    'wp_head',
    'sgl_contract_articles_styles'
);/* End custom CSS */