<?php
/**
 * Sınav Koçu - Profesyonel Ana Satış Sayfası
 * Joker Kapak Zekası, Marka Logoları, Dinamik Ürün Kartları, Çoklu Kategori Desteği ve Özel Bannerlar Eklendi
 */
require_once 'includes/db.php';
require_once 'includes/functions.php';

// --- 1. VERİ ÇEKİMİ ---

$marquee_home = $db->query("SELECT content FROM marquees WHERE page_type = 'home' AND status = 1")->fetchColumn();
$musteri_yorumlari = $db->query("SELECT * FROM reviews WHERE product_id IS NULL AND status = 1 ORDER BY id DESC LIMIT 6")->fetchAll();
$sss_sorulari = $db->query("SELECT * FROM faqs WHERE page_type = 'home' AND status = 1 ORDER BY sort_order ASC, id DESC")->fetchAll();

$sliders = $db->query("SELECT * FROM sliders WHERE status = 1 ORDER BY sort_order ASC, id DESC")->fetchAll();
$hizli_kategoriler = $db->query("SELECT * FROM categories WHERE status = 1 AND parent_id IS NULL LIMIT 6")->fetchAll();

// --- ÜRÜN SORGULARI (KATEGORİ İSİMLERİ SORGULARA EKLENDİ) ---
$vitrin_urunleri = $db->query("
    SELECT p.id, p.name, p.slug, p.price, p.discount_price, p.type, p.exam_publication_date, p.is_free_shipping,
    b.logo as brand_logo, b.name as brand_name,
    (SELECT name FROM categories WHERE id = p.category_id) as cat_name,
    (SELECT GROUP_CONCAT(c3.name SEPARATOR ', ') FROM product_categories pc3 JOIN categories c3 ON pc3.category_id = c3.id WHERE pc3.product_id = p.id) as sub_categories,
    COALESCE(
        (SELECT image_path FROM product_images WHERE product_id = p.id AND is_main = 1 LIMIT 1),
        (SELECT default_cover FROM brands WHERE id = p.brand_id),
        'assets/img/no-image.jpg'
    ) as main_image
    FROM products p 
    LEFT JOIN brands b ON p.brand_id = b.id
    WHERE p.status = 1 AND p.is_featured = 1 
    ORDER BY p.id DESC LIMIT 8
")->fetchAll();

$kampanyali_urunler = $db->query("
    SELECT p.id, p.name, p.slug, p.price, p.discount_price, p.type, p.exam_publication_date, p.is_free_shipping,
    b.logo as brand_logo, b.name as brand_name,
    (SELECT name FROM categories WHERE id = p.category_id) as cat_name,
    (SELECT GROUP_CONCAT(c3.name SEPARATOR ', ') FROM product_categories pc3 JOIN categories c3 ON pc3.category_id = c3.id WHERE pc3.product_id = p.id) as sub_categories,
    COALESCE(
        (SELECT image_path FROM product_images WHERE product_id = p.id AND is_main = 1 LIMIT 1),
        (SELECT default_cover FROM brands WHERE id = p.brand_id),
        'assets/img/no-image.jpg'
    ) as main_image
    FROM products p 
    LEFT JOIN brands b ON p.brand_id = b.id
    WHERE p.status = 1 AND p.discount_price > 0
    ORDER BY (p.price - p.discount_price) DESC LIMIT 4
")->fetchAll();

// --- RASTGELE GELMESİ İSTENEN BLOKLAR ---

$deneme_paketleri = $db->query("
    SELECT p.id, p.name, p.slug, p.price, p.discount_price, p.type, p.exam_publication_date, p.is_free_shipping,
    b.logo as brand_logo, b.name as brand_name,
    (SELECT name FROM categories WHERE id = p.category_id) as cat_name,
    (SELECT GROUP_CONCAT(c3.name SEPARATOR ', ') FROM product_categories pc3 JOIN categories c3 ON pc3.category_id = c3.id WHERE pc3.product_id = p.id) as sub_categories,
    COALESCE(
        (SELECT image_path FROM product_images WHERE product_id = p.id AND is_main = 1 LIMIT 1),
        (SELECT default_cover FROM brands WHERE id = p.brand_id),
        'assets/img/no-image.jpg'
    ) as main_image
    FROM products p 
    LEFT JOIN brands b ON p.brand_id = b.id
    WHERE p.status = 1 AND p.type = 'exam_package' 
    ORDER BY RAND() LIMIT 8
")->fetchAll();

$abonelikler = $db->query("
    SELECT p.id, p.name, p.slug, p.price, p.discount_price, p.type, p.exam_publication_date, p.is_free_shipping,
    b.logo as brand_logo, b.name as brand_name,
    (SELECT name FROM categories WHERE id = p.category_id) as cat_name,
    (SELECT GROUP_CONCAT(c3.name SEPARATOR ', ') FROM product_categories pc3 JOIN categories c3 ON pc3.category_id = c3.id WHERE pc3.product_id = p.id) as sub_categories,
    COALESCE(
        (SELECT image_path FROM product_images WHERE product_id = p.id AND is_main = 1 LIMIT 1),
        (SELECT default_cover FROM brands WHERE id = p.brand_id),
        'assets/img/no-image.jpg'
    ) as main_image
    FROM products p 
    LEFT JOIN brands b ON p.brand_id = b.id
    WHERE p.status = 1 AND p.type = 'subscription' 
    ORDER BY p.id DESC LIMIT 4
")->fetchAll();

$yks_urunleri = $db->query("
    SELECT p.id, p.name, p.slug, p.price, p.discount_price, p.type, p.exam_publication_date, p.is_free_shipping,
    b.logo as brand_logo, b.name as brand_name, c.name as cat_name,
    (SELECT GROUP_CONCAT(c3.name SEPARATOR ', ') FROM product_categories pc3 JOIN categories c3 ON pc3.category_id = c3.id WHERE pc3.product_id = p.id) as sub_categories,
    COALESCE(
        (SELECT image_path FROM product_images WHERE product_id = p.id AND is_main = 1 LIMIT 1),
        (SELECT default_cover FROM brands WHERE id = p.brand_id),
        'assets/img/no-image.jpg'
    ) as main_image
    FROM products p 
    JOIN categories c ON p.category_id = c.id 
    LEFT JOIN brands b ON p.brand_id = b.id
    WHERE p.status = 1 AND (c.slug LIKE '%yks%' OR c.name LIKE '%YKS%') 
    ORDER BY p.id DESC LIMIT 4
")->fetchAll();

$lgs_urunleri = $db->query("
    SELECT p.id, p.name, p.slug, p.price, p.discount_price, p.type, p.exam_publication_date, p.is_free_shipping,
    b.logo as brand_logo, b.name as brand_name, c.name as cat_name,
    (SELECT GROUP_CONCAT(c3.name SEPARATOR ', ') FROM product_categories pc3 JOIN categories c3 ON pc3.category_id = c3.id WHERE pc3.product_id = p.id) as sub_categories,
    COALESCE(
        (SELECT image_path FROM product_images WHERE product_id = p.id AND is_main = 1 LIMIT 1),
        (SELECT default_cover FROM brands WHERE id = p.brand_id),
        'assets/img/no-image.jpg'
    ) as main_image
    FROM products p 
    JOIN categories c ON p.category_id = c.id 
    LEFT JOIN brands b ON p.brand_id = b.id
    WHERE p.status = 1 AND (c.slug LIKE '%lgs%' OR c.name LIKE '%LGS%') 
    ORDER BY RAND() LIMIT 4
")->fetchAll();

$favori_urunler = $db->query("
    SELECT p.id, p.name, p.slug, p.price, p.discount_price, p.type, p.exam_publication_date, p.is_free_shipping,
    b.logo as brand_logo, b.name as brand_name,
    (SELECT name FROM categories WHERE id = p.category_id) as cat_name,
    (SELECT GROUP_CONCAT(c3.name SEPARATOR ', ') FROM product_categories pc3 JOIN categories c3 ON pc3.category_id = c3.id WHERE pc3.product_id = p.id) as sub_categories,
    COALESCE(
        (SELECT image_path FROM product_images WHERE product_id = p.id AND is_main = 1 LIMIT 1),
        (SELECT default_cover FROM brands WHERE id = p.brand_id),
        'assets/img/no-image.jpg'
    ) as main_image
    FROM products p 
    LEFT JOIN brands b ON p.brand_id = b.id
    WHERE p.status = 1 
    ORDER BY RAND() LIMIT 4
")->fetchAll();

$yeni_urunler = $db->query("
    SELECT p.id, p.name, p.slug, p.price, p.discount_price, p.type, p.exam_publication_date, p.is_free_shipping,
    b.logo as brand_logo, b.name as brand_name,
    (SELECT name FROM categories WHERE id = p.category_id) as cat_name,
    (SELECT GROUP_CONCAT(c3.name SEPARATOR ', ') FROM product_categories pc3 JOIN categories c3 ON pc3.category_id = c3.id WHERE pc3.product_id = p.id) as sub_categories,
    COALESCE(
        (SELECT image_path FROM product_images WHERE product_id = p.id AND is_main = 1 LIMIT 1),
        (SELECT default_cover FROM brands WHERE id = p.brand_id),
        'assets/img/no-image.jpg'
    ) as main_image
    FROM products p 
    LEFT JOIN brands b ON p.brand_id = b.id
    WHERE p.status = 1 
    ORDER BY RAND() LIMIT 8
")->fetchAll();

// --- SON EKLENEN BLOG YAZILARI ---
$son_blog_yazilari = $db->query("
    SELECT b.title, b.slug, b.image, b.created_at, b.view_count, c.name as cat_name
    FROM blogs b
    LEFT JOIN blog_categories c ON b.category_id = c.id
    WHERE b.status = 1
    ORDER BY b.id DESC LIMIT 4
")->fetchAll();

$page_title = "SINAVKOCU Mağaza, Kitap, Deneme, Kırtasiye, Teknoloji";
require_once 'header.php';
?>

<main>
    <section class="mb-0">
        <div id="homeSlider" class="carousel slide" data-bs-ride="carousel">
            <div class="carousel-indicators">
                <?php foreach($sliders as $idx => $s): ?>
                    <button type="button" data-bs-target="#homeSlider" data-bs-slide-to="<?= $idx ?>" class="<?= $idx==0?'active':'' ?>"></button>
                <?php endforeach; ?>
            </div>
            
            <div class="carousel-inner">
                <?php if(count($sliders) > 0): ?>
                    <?php foreach($sliders as $index => $slide): ?>
                        <div class="carousel-item <?= $index === 0 ? 'active' : '' ?>">
                            <a href="<?= htmlspecialchars($slide['button_link']) ?>" class="d-block w-100">
                                <img src="<?= htmlspecialchars($slide['image_path']) ?>" class="d-block w-100 slider-img" alt="<?= htmlspecialchars($slide['title']) ?>" fetchpriority="high">
                            </a>
                        </div>
                    <?php endforeach; ?>
                <?php else: ?>
                    <div class="carousel-item active bg-primary text-white text-center py-5 slider-img">
                        <div class="d-flex flex-column justify-content-center h-100">
                            <h1 class="fw-bold">Sınav Koçu'na Hoş Geldiniz</h1>
                        </div>
                    </div>
                <?php endif; ?>
            </div>
            <button class="carousel-control-prev" type="button" data-bs-target="#homeSlider" data-bs-slide="prev">
                <span class="carousel-control-prev-icon" aria-hidden="true"></span>
                <span class="visually-hidden">Önceki</span>
            </button>
            <button class="carousel-control-next" type="button" data-bs-target="#homeSlider" data-bs-slide="next">
                <span class="carousel-control-next-icon" aria-hidden="true"></span>
                <span class="visually-hidden">Sonraki</span>
            </button>
        </div>
    </section>

    <?php if($marquee_home): ?>
    <section class="marquee-section bg-dark text-white shadow-sm border-bottom border-primary border-3">
        <div class="marquee-container">
            <div class="marquee-content fw-bold fs-6 tracking-wide">
                <?= $marquee_home ?> &nbsp;&nbsp;&nbsp; 
                <?= $marquee_home ?> &nbsp;&nbsp;&nbsp; 
                <?= $marquee_home ?> &nbsp;&nbsp;&nbsp; 
                <?= $marquee_home ?>
            </div>
        </div>
    </section>
    <?php endif; ?>

    <div class="container mt-5">
        
        <section class="row text-center mb-5 d-none d-md-flex">
            <div class="col-md-4">
                <div class="p-3 border rounded shadow-sm bg-white">
                    <i class="bi bi-truck fs-1 text-primary"></i>
                    <h5 class="mt-2 fw-bold">Ücretsiz Kargo Fırsatı</h5>
                    <p class="text-muted small mb-0">Açılışa Özel Ücretsiz Kargo Fırsatı.</p>
                </div>
            </div>
            <div class="col-md-4">
                <div class="p-3 border rounded shadow-sm bg-white">
                    <i class="bi bi-shield-check fs-1 text-success"></i>
                    <h5 class="mt-2 fw-bold">%100 Güvenli Ödeme</h5>
                    <p class="text-muted small mb-0">256-bit SSL sertifikası ile korunan altyapı.</p>
                </div>
            </div>
            <div class="col-md-4">
                <div class="p-3 border rounded shadow-sm bg-white">
                    <i class="bi bi-arrow-repeat fs-1 text-warning"></i>
                    <h5 class="mt-2 fw-bold">Kolay İade</h5>
                    <p class="text-muted small mb-0">14 gün içinde koşulsuz iade garantisi.</p>
                </div>
            </div>
        </section>

        <section class="mb-4">
            <div class="row g-3 text-center">
                <div class="col-6 col-md-3">
                    <a href="kategori/yks" class="p-3 border rounded shadow-sm bg-white d-block text-decoration-none">
                        <i class="bi bi-mortarboard fs-1 text-primary"></i>
                        <h5 class="mt-2 fw-bold text-dark mb-0 fs-6 fs-md-5">YKS Kaynakları</h5>
                    </a>
                </div>
                <div class="col-6 col-md-3">
                    <a href="kategori/lgs" class="p-3 border rounded shadow-sm bg-white d-block text-decoration-none">
                        <i class="bi bi-book fs-1 text-success"></i>
                        <h5 class="mt-2 fw-bold text-dark mb-0 fs-6 fs-md-5">LGS Kaynakları</h5>
                    </a>
                </div>
                <div class="col-6 col-md-3">
                    <a href="deneme-paketi-olustur.php" class="p-3 border rounded shadow-sm bg-red d-block text-decoration-none">
                        <i class="bi bi-journal-arrow-down fs-1 text-warning"></i>
                        <h5 class="mt-2 fw-bold text-dark mb-0 fs-6 fs-md-5">Deneme Paketini Oluştur</h5>
                    </a>
                </div>
                <div class="col-6 col-md-3">
                    <a href="kategori/teknoloji" class="p-3 border rounded shadow-sm bg-dark d-block text-decoration-none">
                        <i class="bi bi-laptop fs-1 text-white"></i>
                        <h5 class="mt-2 fw-bold text-white mb-0 fs-6 fs-md-5">Teknolojik Ürünler Burada</h5>
                    </a>
                </div>
            </div>
        </section>
        
        <section class="mb-4">
            <div class="row g-2 text-center">
                <div class="col-6 col-md-3">
                    <a href="kategori/tyt-deneme" class="py-2 px-1 border-0 rounded shadow-sm d-block text-decoration-none category-btn bg-blue-subtle">
                        <i class="bi bi-pencil-square fs-3 text-primary"></i>
                        <h6 class="mt-1 fw-bold text-primary-emphasis mb-0 small-title">TYT Deneme</h6>
                    </a>
                </div>

                <div class="col-6 col-md-3">
                    <a href="kategori/ayt-deneme" class="py-2 px-1 border-0 rounded shadow-sm d-block text-decoration-none category-btn bg-red-subtle">
                        <i class="bi bi-mortarboard fs-3 text-danger"></i>
                        <h6 class="mt-1 fw-bold text-danger-emphasis mb-0 small-title">AYT Deneme</h6>
                    </a>
                </div>

                <div class="col-6 col-md-3">
                    <a href="kategori/lgs-deneme" class="py-2 px-1 border-0 rounded shadow-sm d-block text-decoration-none category-btn bg-green-subtle">
                        <i class="bi bi-book fs-3 text-success"></i>
                        <h6 class="mt-1 fw-bold text-success-emphasis mb-0 small-title">LGS Deneme</h6>
                    </a>
                </div>

                <div class="col-6 col-md-3">
                    <a href="kategori/deneme-paketi" class="py-2 px-1 border-0 rounded shadow-sm d-block text-decoration-none category-btn bg-orange-subtle">
                        <i class="bi bi-boxes fs-3 text-warning"></i>
                        <h6 class="mt-1 fw-bold text-warning-emphasis mb-0 small-title">Deneme Paketleri</h6>
                    </a>
                </div>
            </div>
        </section>

        <section class="row g-3 mb-5">
            <div class="col-md-6">
                <a href="indirimli-urunler.php" class="text-decoration-none d-block">
                    <div class="p-4 rounded-4 shadow-sm bg-danger text-white position-relative overflow-hidden banner-card">
                        <div class="position-absolute top-0 start-0 w-100 h-100 opacity-25" style="background: repeating-linear-gradient(45deg, transparent, transparent 10px, rgba(0,0,0,0.1) 10px, rgba(0,0,0,0.1) 20px);"></div>
                        <div class="position-relative z-index-1 d-flex justify-content-between align-items-center">
                            <div>
                                <h4 class="fw-bold mb-1"><i class="bi bi-tags-fill text-warning me-2"></i>Süper İndirimler</h4>
                                <p class="mb-0 small text-white-50 fw-bold">Dev fırsatları kaçırmadan keşfedin</p>
                            </div>
                            <i class="bi bi-arrow-right-circle fs-1 opacity-75"></i>
                        </div>
                    </div>
                </a>
            </div>
            <div class="col-md-6">
                <a href="yeni-eklenen-urunler.php" class="text-decoration-none d-block">
                    <div class="p-4 rounded-4 shadow-sm bg-primary text-white position-relative overflow-hidden banner-card">
                        <div class="position-absolute top-0 start-0 w-100 h-100 opacity-25" style="background: repeating-linear-gradient(45deg, transparent, transparent 10px, rgba(0,0,0,0.1) 10px, rgba(0,0,0,0.1) 20px);"></div>
                        <div class="position-relative z-index-1 d-flex justify-content-between align-items-center">
                            <div>
                                <h4 class="fw-bold mb-1"><i class="bi bi-stars text-warning me-2"></i>Yeni Eklenenler</h4>
                                <p class="mb-0 small text-white-50 fw-bold">Güncel baskı ve yeni müfredat denemeler</p>
                            </div>
                            <i class="bi bi-arrow-right-circle fs-1 opacity-75"></i>
                        </div>
                    </div>
                </a>
            </div>
        </section>

        <?php 
        // ÜRÜN KARTI YAZDIRMA FONKSİYONU (KATEGORİ İSİMLERİ EKLENDİ)
        function urunKartiYazdir($urun) { 
        ?>
            <div class="col">
                <article class="card h-100 product-card shadow-sm border-0 position-relative transition rounded-4 overflow-hidden">
                    
                    <?php if(!empty($urun['brand_logo'])): ?>
                        <div class="position-absolute top-0 end-0 m-2 bg-white rounded shadow-sm d-flex align-items-center justify-content-center p-1" style="width: 40px; height: 25px; z-index: 5;">
                            <img src="<?= htmlspecialchars($urun['brand_logo']) ?>" class="img-fluid" style="max-height: 100%; max-width: 100%; object-fit: contain;">
                        </div>
                    <?php endif; ?>

                    <div class="position-relative overflow-hidden bg-light p-2 text-center">
                        <a href="urun/<?= $urun['slug'] ?>">
                            <img src="<?= htmlspecialchars($urun['main_image']) ?>" 
                                 class="card-img-top p-2" alt="<?= htmlspecialchars($urun['name']) ?>" 
                                 style="height: 200px; object-fit: contain;">
                        </a>
                        
                        <div class="position-absolute top-0 start-0 m-2 d-flex flex-column gap-1 align-items-start" style="z-index: 2;">
                            <?php if ($urun['discount_price'] > 0): ?>
                                <span class="badge bg-danger shadow-sm px-2 py-1" style="font-size:0.7rem;">
                                    -%<?= round((($urun['price'] - $urun['discount_price']) / $urun['price']) * 100) ?> İndirimli
                                </span>
                            <?php endif; ?>
                            
                            <?php if ($urun['is_free_shipping'] == 1): ?>
                                <span class="badge bg-success shadow-sm px-2 py-1" style="font-size:0.7rem;">
                                    <i class="bi bi-truck me-1"></i>Kargo Bedava
                                </span>
                            <?php endif; ?>
                        </div>

                        <?php if ($urun['type'] == 'subscription' || $urun['type'] == 'exam_package'): ?>
                            <span class="badge bg-dark position-absolute bottom-0 start-0 m-2 shadow-sm px-2 py-1" style="z-index: 2; font-size:0.7rem;">
                                <i class="bi bi-box-seam me-1"></i>Deneme Paketi
                            </span>
                        <?php endif; ?>
                    </div>

                    <div class="card-body text-center d-flex flex-column bg-white border-top p-2">
                        
                        <?php 
                            // KATEGORİ GÖSTERİMİ (Çoklu Kategori Destekli)
                            $kategori_isimleri = !empty($urun['sub_categories']) ? $urun['sub_categories'] : ($urun['cat_name'] ?? '');
                            if($kategori_isimleri): 
                        ?>
                            <small class="text-muted fw-bold text-uppercase text-truncate d-block mb-1" style="font-size: 0.60rem; letter-spacing: 0.5px;" title="<?= htmlspecialchars($kategori_isimleri) ?>">
                                <?= htmlspecialchars($kategori_isimleri) ?>
                            </small>
                        <?php endif; ?>

                        <h5 class="card-title fw-bold mb-1" style="height: 35px; overflow: hidden; font-size: 0.85rem; line-height: 1.2;">
                            <a href="urun/<?= $urun['slug'] ?>" class="text-dark text-decoration-none" title="<?= htmlspecialchars($urun['name']) ?>">
                                <?= htmlspecialchars($urun['name']) ?>
                            </a>
                        </h5>
                        
                        <?php if($urun['type'] == 'single_exam'): ?>
                            <div class="d-flex justify-content-center align-items-center mb-1 px-1 border-bottom pb-1">
                                <div class="small text-muted fw-bold" style="font-size: 0.65rem;">
                                    <i class="bi bi-calendar-event text-primary"></i> <?= htmlspecialchars($urun['exam_publication_date']) ?: 'Tarih Yok' ?>
                                </div>
                            </div>
                        <?php endif; ?>

                        <div class="mt-auto pt-1">
                            <?php if ($urun['discount_price'] > 0): ?>
                                <div class="d-flex justify-content-center align-items-baseline gap-1">
                                    <span class="text-muted small text-decoration-line-through" style="font-size:0.7rem;"><?= number_format($urun['price'], 2, ',', '.') ?> ₺</span>
                                    <span class="text-danger fw-bold fs-6"><?= number_format($urun['discount_price'], 2, ',', '.') ?> ₺</span>
                                </div>
                            <?php else: ?>
                                <div class="text-primary fw-bold fs-6"><?= number_format($urun['price'], 1, ',', '.') ?> ₺</div>
                            <?php endif; ?>
                            
                            <button class="btn btn-outline-primary w-100 btn-sm sepete-ekle-btn fw-bold mt-2" data-id="<?= $urun['id'] ?>">
                                <i class="bi bi-cart-plus"></i> Sepete Ekle
                            </button>
                        </div>
                    </div>
                </article>
            </div>
        <?php } ?>

        <?php if(count($kampanyali_urunler) > 0): ?>
        <section class="mb-5 bg-white p-4 rounded shadow-sm border border-danger border-opacity-25">
            <div class="d-flex justify-content-between align-items-center mb-3">
                <h2 class="h5 h4-md fw-bold border-start border-danger border-4 ps-2 text-danger">Süper Kampanyalar</h2>
                <a href="indirimli-urunler.php" class="text-decoration-none small text-danger fw-bold">Tüm İndirimler <i class="bi bi-chevron-right"></i></a>
            </div>
            <div class="row row-cols-2 row-cols-md-3 row-cols-lg-4 g-3">
                <?php foreach($kampanyali_urunler as $urun) { urunKartiYazdir($urun); } ?>
            </div>
        </section>
        <?php endif; ?>

        <?php if(count($deneme_paketleri) > 0): ?>
        <section class="mb-5 bg-white p-4 rounded shadow-sm border border-info border-opacity-25">
            <div class="d-flex justify-content-between align-items-center mb-3">
                <h2 class="h5 h4-md fw-bold border-start border-info border-4 ps-2 text-info">Deneme Paketleri</h2>
                <a href="kategori/deneme-paketi" class="text-decoration-none small text-info fw-bold">Tüm Paketler <i class="bi bi-chevron-right"></i></a>
            </div>
            <div class="row row-cols-2 row-cols-md-3 row-cols-lg-4 g-3">
                <?php foreach($deneme_paketleri as $urun) { urunKartiYazdir($urun); } ?>
            </div>
        </section>
        <?php endif; ?>

        <?php if(count($vitrin_urunleri) > 0): ?>
        <section class="mb-5">
            <div class="d-flex justify-content-between align-items-center mb-3">
                <h2 class="h5 h4-md fw-bold border-start border-primary border-4 ps-2">Öne Çıkan Ürünler</h2>
                <a href="urun-kategori.php?vitrin=1" class="text-decoration-none small text-muted">Tümünü Gör <i class="bi bi-chevron-right"></i></a>
            </div>
            <div class="row row-cols-2 row-cols-md-3 row-cols-lg-4 g-3">
                <?php foreach($vitrin_urunleri as $urun) { urunKartiYazdir($urun); } ?>
            </div>
        </section>
        <?php endif; ?>

        <?php if(count($yks_urunleri) > 0): ?>
        <section class="mb-5">
            <h2 class="h5 h4-md fw-bold border-start border-primary border-4 ps-2 mb-3 text-primary">YKS 2026 Hazırlık</h2>
            <div class="row row-cols-2 row-cols-md-3 row-cols-lg-4 g-3">
                <?php foreach($yks_urunleri as $urun) { urunKartiYazdir($urun); } ?>
            </div>
        </section>
        <?php endif; ?>

        <?php if(count($lgs_urunleri) > 0): ?>
        <section class="mb-5">
            <h2 class="h5 h4-md fw-bold border-start border-success border-4 ps-2 mb-3 text-success">LGS 2026 Hazırlık</h2>
            <div class="row row-cols-2 row-cols-md-3 row-cols-lg-4 g-3">
                <?php foreach($lgs_urunleri as $urun) { urunKartiYazdir($urun); } ?>
            </div>
        </section>
        <?php endif; ?>

        <section class="mb-5">
            <h2 class="h5 h4-md fw-bold border-start border-warning border-4 ps-2 mb-3">Öğrenci Favorileri</h2>
            <div class="row row-cols-2 row-cols-md-3 row-cols-lg-4 g-3">
                <?php foreach($favori_urunler as $urun) { urunKartiYazdir($urun); } ?>
            </div>
        </section>

        <section class="mb-5 bg-white p-4 rounded shadow-sm border border-light">
            <div class="d-flex justify-content-between align-items-center mb-4">
                <h2 class="h5 h4-md fw-bold border-start border-success border-4 ps-2 mb-0">Yeni Eklenen Ürünler</h2>
                <a href="yeni-eklenen-urunler.php" class="text-decoration-none small text-success fw-bold">Tümünü Gör <i class="bi bi-chevron-right"></i></a>
            </div>
            <div class="row row-cols-2 row-cols-md-4 g-3">
                <?php foreach($yeni_urunler as $urun) { urunKartiYazdir($urun); } ?>
            </div>
        </section>

    </div>

    <?php if(count($musteri_yorumlari) > 0): ?>
    <div class="container mb-5">
        <section class="bg-white p-4 p-md-5 rounded-4 shadow-sm border border-light">
            <div class="text-center mb-5">
                <h2 class="h3 fw-bold text-dark mb-1">Mutlu Müşteriler</h2>
                <p class="text-muted small">Öğrencilerimiz ve velilerimizin Sınav Koçu hakkındaki düşünceleri</p>
            </div>
            
            <div class="row g-4 justify-content-center">
                <?php foreach($musteri_yorumlari as $yorum): ?>
                    <?php
                        $isim_parcalari = explode(" ", trim($yorum['name']));
                        $gizli_isim = "";
                        foreach($isim_parcalari as $parca) {
                            if(mb_strlen($parca, 'UTF-8') > 1) {
                                $gizli_isim .= mb_substr($parca, 0, 1, 'UTF-8') . str_repeat("*", mb_strlen($parca, 'UTF-8')-1) . " ";
                            } else {
                                $gizli_isim .= $parca . " ";
                            }
                        }
                        $bas_harf = mb_substr(trim($yorum['name']), 0, 1, 'UTF-8');
                    ?>
                    <div class="col-md-6 col-lg-4">
                        <div class="card h-100 border-0 shadow-sm rounded-4" style="background-color: #f8f9fa;">
                            <div class="card-body p-4 d-flex flex-column">
                                <div class="d-flex align-items-center mb-3 pb-3 border-bottom border-light">
                                    <div class="bg-primary text-white rounded-circle d-flex align-items-center justify-content-center fw-bold fs-5 me-3 shadow-sm" style="width: 48px; height: 48px; flex-shrink: 0;">
                                        <?= htmlspecialchars($bas_harf) ?>
                                    </div>
                                    <div>
                                        <h6 class="mb-0 fw-bold text-dark" style="line-height: 1.2;"><?= htmlspecialchars(trim($gizli_isim)) ?></h6>
                                        <div class="text-warning small mt-1" style="font-size: 0.8rem;">
                                            <?= str_repeat('<i class="bi bi-star-fill"></i>', $yorum['rating']) ?>
                                            <?= str_repeat('<i class="bi bi-star text-muted"></i>', 5 - $yorum['rating']) ?>
                                        </div>
                                    </div>
                                </div>
                                <p class="card-text text-secondary fst-italic small mb-0 flex-grow-1">"<?= htmlspecialchars($yorum['comment']) ?>"</p>
                            </div>
                        </div>
                    </div>
                <?php endforeach; ?>
            </div>
        </section>
    </div>
    <?php endif; ?>

    <?php if(count($sss_sorulari) > 0): ?>
    <div class="container mb-5">
        <section class="bg-white p-4 p-md-5 rounded-4 shadow-sm border border-light">
            <div class="text-center mb-4">
                <h2 class="h3 fw-bold text-dark mb-1">Sıkça Sorulan Sorular</h2>
                <p class="text-muted small">Merak ettiğiniz tüm detaylar</p>
            </div>
            
            <div class="accordion accordion-flush" id="accordionSssHome">
                <?php foreach($sss_sorulari as $index => $soru): ?>
                    <div class="accordion-item border-bottom">
                        <h2 class="accordion-header" id="flush-heading-<?= $soru['id'] ?>">
                            <button class="accordion-button <?= $index !== 0 ? 'collapsed' : '' ?> fw-bold text-dark fs-6 bg-white" type="button" data-bs-toggle="collapse" data-bs-target="#flush-collapse-<?= $soru['id'] ?>">
                                <?= htmlspecialchars($soru['question']) ?>
                            </button>
                        </h2>
                        <div id="flush-collapse-<?= $soru['id'] ?>" class="accordion-collapse collapse <?= $index === 0 ? 'show' : '' ?>" data-bs-parent="#accordionSssHome">
                            <div class="accordion-body text-muted lh-lg">
                                <?= nl2br(htmlspecialchars($soru['answer'])) ?>
                            </div>
                        </div>
                    </div>
                <?php endforeach; ?>
            </div>
        </section>
    </div>
    <?php endif; ?>

<?php if(count($son_blog_yazilari) > 0): ?>
    <div class="container mb-5">
        <section class="bg-white p-4 p-md-5 rounded-4 shadow-sm border border-light">
            <div class="d-flex justify-content-between align-items-center border-bottom pb-3 mb-4">
                <div>
                    <h2 class="h3 fw-bold text-dark mb-1"><i class="bi bi-journal-text text-primary me-2"></i>Eğitim ve Sınav Rehberi</h2>
                    <p class="text-muted small mb-0">Sınav Koçu'ndan en güncel tavsiyeler, taktikler ve haberler</p>
                </div>
                <a href="blog.php" class="btn btn-outline-primary btn-sm fw-bold rounded-pill px-3 text-nowrap">Tüm Yazılar <i class="bi bi-arrow-right"></i></a>
            </div>

            <div class="row row-cols-1 row-cols-md-2 row-cols-lg-4 g-4">
                <?php foreach($son_blog_yazilari as $blog): 
                    $b_gorsel = !empty($blog['image']) ? $blog['image'] : 'assets/img/no-image.jpg';
                ?>
                <div class="col">
                    <div class="card h-100 border-0 shadow-sm product-card transition rounded-4 overflow-hidden bg-light">
                        <a href="blog/<?= $blog['slug'] ?>" class="text-decoration-none text-dark d-flex flex-column h-100">
                            <div class="position-relative overflow-hidden">
                                <img src="<?= htmlspecialchars($b_gorsel) ?>" class="card-img-top w-100" alt="<?= htmlspecialchars($blog['title']) ?>" style="aspect-ratio: 1200/630; object-fit: cover;">
                                <?php if($blog['cat_name']): ?>
                                    <span class="badge bg-primary position-absolute top-0 start-0 m-2 shadow-sm px-2 py-1" style="z-index: 2; font-size:0.7rem;">
                                        <?= htmlspecialchars($blog['cat_name']) ?>
                                    </span>
                                <?php endif; ?>
                            </div>
                            <div class="card-body bg-white p-3 d-flex flex-column flex-grow-1">
                                <h5 class="card-title fw-bold fs-6 mb-3" style="height: 40px; overflow: hidden; line-height: 1.4;">
                                    <?= htmlspecialchars($blog['title']) ?>
                                </h5>
                                <div class="text-muted small mt-auto d-flex justify-content-between border-top pt-2">
                                    <span><i class="bi bi-calendar3 me-1 text-primary"></i> <?= date('d.m.Y', strtotime($blog['created_at'])) ?></span>
                                    <span><i class="bi bi-eye text-primary me-1"></i> <?= $blog['view_count'] ?></span>
                                </div>
                            </div>
                        </a>
                    </div>
                </div>
                <?php endforeach; ?>
            </div>
        </section>
    </div>
    <?php endif; ?>
    ```


</main>

<style>
    /* SLİDER MOBİL EN-BOY KORUMA AYARI */
    .slider-img { width: 100%; height: auto !important; display: block; }
    @media (min-width: 992px) { .slider-img { max-height: 500px; object-fit: cover; } }

    .product-card { transition: all 0.3s ease; }
    .product-card:hover { transform: translateY(-5px); box-shadow: 0 10px 20px rgba(0,0,0,0.1) !important; }

    /* YENİ EKLENEN: BANNER KARTLARI HOVER EFEKTİ */
    .banner-card { transition: transform 0.3s ease, box-shadow 0.3s ease; }
    .banner-card:hover { transform: translateY(-5px); box-shadow: 0 10px 25px rgba(0,0,0,0.15) !important; }

    /* KAYAN YAZI (MARQUEE) ANİMASYONU */
    .marquee-section { padding: 12px 0; background-color: #212529; color: #fff; overflow: hidden; }
    .marquee-container { width: 100%; overflow: hidden; white-space: nowrap !important; box-sizing: border-box; }
    .marquee-content {
        display: inline-block;
        white-space: nowrap !important;
        padding-left: 100%;
        animation: marqueeScroll 25s linear infinite;
    }
    .marquee-content span { display: inline-block !important; }
    .marquee-content:hover { animation-play-state: paused; cursor: default; }
    
    @keyframes marqueeScroll {
        0% { transform: translateX(0); }
        100% { transform: translateX(-100%); }
    }
    
    /* Renkli Arka Plan Tanımlamaları */
    .bg-blue-subtle { background-color: #e7f1ff; border: 1px solid #cfe2ff !important; }
    .bg-red-subtle { background-color: #f8d7da; border: 1px solid #f5c2c7 !important; }
    .bg-green-subtle { background-color: #d1e7dd; border: 1px solid #badbcc !important; }
    .bg-orange-subtle { background-color: #fff3cd; border: 1px solid #ffecb5 !important; }

    .category-btn {
        transition: all 0.3s ease;
        min-height: 90px;
        display: flex !important;
        flex-direction: column;
        justify-content: center;
        align-items: center;
    }

    .category-btn:hover {
        transform: translateY(-3px);
        filter: brightness(0.95);
        box-shadow: 0 4px 8px rgba(0,0,0,0.1) !important;
    }

    .small-title {
        font-size: 0.85rem;
        letter-spacing: -0.2px;
    }

    /* Yazı renklerini biraz daha koyu yaparak okunabilirliği artırdık */
    .text-primary-emphasis { color: #052c65 !important; }
    .text-danger-emphasis { color: #58151c !important; }
    .text-success-emphasis { color: #0a3622 !important; }
    .text-warning-emphasis { color: #664d03 !important; }
</style>



<?php require_once 'footer.php'; ?>