<?php
if (session_status() === PHP_SESSION_NONE) { session_start(); }
date_default_timezone_set('Asia/Dhaka');

require_once 'db_connect.php';

// ==========================================
// ⚙️ FETCH CMS SETTINGS FROM DATABASE
// ==========================================
$settings = [];
if (isset($pdo)) {
    try {
        $stmt = $pdo->query("SELECT setting_key, setting_value FROM settings");
        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
            $settings[$row['setting_key']] = $row['setting_value'];
        }
    } catch (PDOException $e) {}
}

// 🟢 GLOBAL SETTINGS
$site_title = $settings['site_title'] ?? 'Ahmad Academy';
$site_tagline = $settings['site_tagline'] ?? 'Online Quranic Institute';
$contact_phone = $settings['contact_phone'] ?? '+8801815244716';
$contact_whatsapp = $settings['contact_whatsapp'] ?? '8801815244716';

// 🟢 SMART LOGO PATH FIXER
$raw_logo = $settings['site_logo'] ?? '';
$site_logo = 'https://ahmadonlineacademy.com/assets/images/logo.png'; 
if (!empty($raw_logo)) {
    if (strpos($raw_logo, 'http') === 0) {
        $site_logo = $raw_logo;
    } else {
        $clean_path = ltrim(str_replace('../', '', $raw_logo), '/');
        $site_logo = 'https://ahmadonlineacademy.com/' . $clean_path;
    }
}

// 🟢 DYNAMIC HERO SLIDERS
$hero1_title = $settings['hero1_title'] ?? 'Online Quranic Institute';
$hero1_desc  = $settings['hero1_desc']  ?? 'Spreading authentic Islamic knowledge worldwide with certified international tutors.';
$hero1_image = !empty($settings['hero1_image']) ? str_replace('../', '', $settings['hero1_image']) : 'https://ahmadonlineacademy.com/assets/images/hero1.jpg';

$hero2_title = $settings['hero2_title'] ?? 'Master the Tajweed';
$hero2_desc  = $settings['hero2_desc']  ?? 'Learn to recite beautifully with proper rules from the comfort of your home.';
$hero2_image = !empty($settings['hero2_image']) ? str_replace('../', '', $settings['hero2_image']) : 'https://ahmadonlineacademy.com/assets/images/hero2.jpg';

$hero3_title = $settings['hero3_title'] ?? 'Authentic Islamic Studies';
$hero3_desc  = $settings['hero3_desc']  ?? 'Build a strong foundation in Islamic Fiqh, Aqeedah, and Arabic language.';
$hero3_image = !empty($settings['hero3_image']) ? str_replace('../', '', $settings['hero3_image']) : 'https://ahmadonlineacademy.com/assets/images/hero3.jpg';

// 🟢 DYNAMIC CATEGORIES
$categories = [
    ['title' => $settings['cat1_title'] ?? 'Qur’an Studies', 'icon' => 'fa-quran'],
    ['title' => $settings['cat2_title'] ?? 'Hifz Program', 'icon' => 'fa-book-reader'],
    ['title' => $settings['cat3_title'] ?? 'Arabic Learning', 'icon' => 'fa-language'],
    ['title' => $settings['cat4_title'] ?? 'Islamic Knowledge', 'icon' => 'fa-mosque'],
    ['title' => $settings['cat5_title'] ?? 'Fiqh & Shariah', 'icon' => 'fa-scale-balanced'],
    ['title' => $settings['cat6_title'] ?? 'Special Programs', 'icon' => 'fa-star-and-crescent']
];

// 🟢 DYNAMIC FEATURES (Why Choose Us)
$features = [
    ['icon' => 'fa-chalkboard-teacher', 'title' => $settings['feat1_title'] ?? 'Experienced Teachers', 'desc' => $settings['feat1_desc'] ?? 'Our dedicated teachers give individual attention to every student.'],
    ['icon' => 'fa-tasks', 'title' => $settings['feat2_title'] ?? 'Quiz in Every Class', 'desc' => $settings['feat2_desc'] ?? 'A short quiz is conducted in every class to track understanding.'],
    ['icon' => 'fa-calendar-check', 'title' => $settings['feat3_title'] ?? 'Regular Updates', 'desc' => $settings['feat3_desc'] ?? 'Class schedules are regularly shared through WhatsApp groups.'],
    ['icon' => 'fa-chart-line', 'title' => $settings['feat4_title'] ?? 'Monthly Reports', 'desc' => $settings['feat4_desc'] ?? 'Detailed academic progress reports are provided monthly.'],
    ['icon' => 'fa-users', 'title' => $settings['feat5_title'] ?? 'Parent Communication', 'desc' => $settings['feat5_desc'] ?? 'We maintain regular communication with parents.'],
    ['icon' => 'fa-bullseye', 'title' => $settings['feat6_title'] ?? 'Personalized Attention', 'desc' => $settings['feat6_desc'] ?? 'Each student receives guidance based on their strengths.'],
    ['icon' => 'fa-file-signature', 'title' => $settings['feat7_title'] ?? 'Regular Exams', 'desc' => $settings['feat7_desc'] ?? 'Frequent tests help students stay well-prepared.'],
    ['icon' => 'fa-trophy', 'title' => $settings['feat8_title'] ?? 'Focus on Improvement', 'desc' => $settings['feat8_desc'] ?? 'We focus on achieving strong results and moral improvement.']
];

// 🟢 DYNAMIC FAQs
$faqs = [
    ['q' => $settings['faq1_q'] ?? 'How to learn the Quran online?', 'a' => $settings['faq1_a'] ?? 'Learning the Quran online is simple. All you need is a laptop or smartphone and a stable internet connection.'],
    ['q' => $settings['faq2_q'] ?? 'How can I start lessons with Ahmad Academy?', 'a' => $settings['faq2_a'] ?? 'Simply browse our courses, select one, and click "View Details" to enroll. After payment, our team will contact you.'],
    ['q' => $settings['faq3_q'] ?? 'Are there female Quran teachers available?', 'a' => $settings['faq3_a'] ?? 'Yes, we have dedicated and qualified female teachers for our female students and children.'],
    ['q' => $settings['faq4_q'] ?? 'How flexible are the class timings?', 'a' => $settings['faq4_a'] ?? 'Our timings are highly flexible. We operate across different time zones to accommodate students worldwide.'],
    ['q' => $settings['faq5_q'] ?? 'Do you provide certificates after course completion?', 'a' => $settings['faq5_a'] ?? 'Yes, Alhamdulillah! Upon successful completion of a course, we provide a digital certificate of achievement.']
];

// ==========================================
// ⚙️ FULLY DYNAMIC COURSES
// ==========================================
$courses = [];
try {
    $stmt = $pdo->query("
        SELECT c.*, t.name as teacher_name, 
               (SELECT COUNT(*) FROM enrollments e WHERE e.course_id = c.id AND e.status='active') as total_students 
        FROM courses c 
        LEFT JOIN teachers t ON c.teacher_id = t.id 
        WHERE c.status = 'active' 
        ORDER BY c.id ASC LIMIT 6
    ");
    $courses = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {}

include 'header.php'; 
?>

<style>
    /* =========================================
       🔥 1. PREMIUM DYNAMIC SLIDER STYLES
       ========================================= */
    .slider-wrap { border-bottom: 5px solid var(--accent); position: relative; overflow: hidden; }
    .carousel-item { height: 85vh; min-height: 600px; position: relative; overflow: hidden; }
    .carousel-item::after { content: ""; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: linear-gradient(to bottom, rgba(2, 44, 34, 0.6) 0%, rgba(2, 44, 34, 0.9) 100%); z-index: 1; }
    
    .slider-bg-img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; z-index: 0; transform: scale(1.1); transition: transform 6s ease-in-out; }
    .carousel-item.active .slider-bg-img { transform: scale(1); }

    .slider-caption-custom { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); text-align: center; color: white; width: 90%; max-width: 800px; z-index: 10; }
    .slider-caption-custom > * { opacity: 0; transform: translateY(30px); transition: all 0.8s cubic-bezier(0.25, 0.8, 0.25, 1); }
    .carousel-item.active .slider-caption-custom > * { opacity: 1; transform: translateY(0); }
    
    .carousel-item.active .slider-caption-custom span.arabic-text { transition-delay: 0.2s; }
    .carousel-item.active .slider-caption-custom h1 { transition-delay: 0.4s; }
    .carousel-item.active .slider-caption-custom p { transition-delay: 0.6s; }
    .carousel-item.active .slider-caption-custom a.btn { transition-delay: 0.8s; }

    .slider-title { font-size: 4rem; font-weight: 800; margin-bottom: 20px; text-shadow: 0 4px 15px rgba(0,0,0,0.4); line-height: 1.2; }
    .slider-desc { font-size: 1.25rem; margin-bottom: 40px; color: rgba(255,255,255,0.85); font-weight: 400; }

    .custom-carousel-control { width: 60px; height: 60px; background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.3); border-radius: 50%; top: 50%; transform: translateY(-50%); opacity: 0; transition: 0.3s; display: flex; align-items: center; justify-content: center; }
    .slider-wrap:hover .custom-carousel-control { opacity: 1; }
    .custom-carousel-control:hover { background: var(--accent); border-color: var(--accent); }
    .custom-carousel-control:hover i { color: var(--primary-dark) !important; }
    .carousel-control-prev.custom-carousel-control { left: 30px; }
    .carousel-control-next.custom-carousel-control { right: 30px; }

    /* =========================================
       2. OTHER SECTION STYLES
       ========================================= */
    .section-padding { padding: 80px 0; }
    .section-title { font-weight: 800; color: var(--primary-dark); font-size: 34px; margin-bottom: 40px; text-align: center; }
    .section-subtitle { color: #64748b; font-size: 16px; max-width: 600px; margin: 0 auto 40px; text-align: center; }

    .adv-card { background: #fff; padding: 30px 20px; border-radius: 20px; text-align: center; border: 1px solid #f1f5f9; transition: all 0.3s ease; height: 100%; }
    .adv-card:hover { transform: translateY(-8px); border-color: var(--accent); box-shadow: 0 15px 35px rgba(212, 175, 55, 0.1) !important; }
    .adv-icon-wrap { width: 60px; height: 60px; background: rgba(6, 78, 59, 0.05); color: var(--primary); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 24px; margin: 0 auto 20px; transition: 0.3s; }
    .adv-card:hover .adv-icon-wrap { background: var(--primary); color: var(--accent); }
    .adv-card h5 { font-size: 17px; color: var(--primary-dark); margin-bottom: 12px; line-height: 1.4; }

    .course-card { background: var(--white); border-radius: 15px; overflow: hidden; border: 1px solid #e2e8f0; transition: 0.3s; height: 100%; display: flex; flex-direction: column; }
    .course-card:hover { transform: translateY(-8px); box-shadow: 0 15px 30px rgba(0,0,0,0.08); border-color: var(--primary); }
    .course-thumb-custom { height: 180px; background: linear-gradient(135deg, var(--primary-dark), var(--primary)); border-bottom: 3px solid var(--accent); display: flex; align-items: center; justify-content: center; transition: 0.4s ease; overflow: hidden; }
    .course-thumb-custom img { max-height: 90px; filter: drop-shadow(0 4px 6px rgba(0,0,0,0.3)); transition: transform 0.4s ease; }
    .course-card:hover .course-thumb-custom img { transform: scale(1.08); }
    .course-head { background: var(--bg-soft); padding: 25px; border-bottom: 1px solid #e2e8f0; text-align: center; position: relative; }
    .course-head h3 { font-weight: 800; color: var(--primary); font-size: 22px; margin-top: 10px; line-height: 1.4; transition: 0.3s; }
    .course-head h3:hover { color: var(--accent); }
    .course-body { padding: 25px; display: flex; flex-direction: column; flex-grow: 1; }

    .cat-card { background: var(--white); border: 1px solid #e2e8f0; border-radius: 15px; padding: 25px; text-align: center; transition: 0.3s; box-shadow: 0 5px 15px rgba(0,0,0,0.02); height: 100%; }
    .cat-card:hover { transform: translateY(-5px); border-color: var(--accent); box-shadow: 0 10px 20px rgba(212, 175, 55, 0.15); }

    /* Testimonials Styles */
    .premium-testimonial-grid { background-color: #022c22; background-image: url('https://www.transparenttextures.com/patterns/arabesque.png'); padding: 100px 0; position: relative; }
    .modern-divider { width: 80px; height: 4px; background: var(--accent); border-radius: 10px; margin-top: 15px; }
    .modern-static-card { background: #ffffff; border-radius: 24px; padding: 45px 35px; height: 100%; position: relative; overflow: hidden; transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1); border: 1px solid rgba(212, 175, 55, 0.1); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2); }
    .modern-static-card:hover { transform: translateY(-12px); border-color: var(--accent); box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3); }
    .card-glow { position: absolute; top: 0; left: 0; width: 100%; height: 6px; background: linear-gradient(90deg, transparent, var(--accent), transparent); opacity: 0; transition: 0.3s; }
    .modern-static-card:hover .card-glow { opacity: 1; }
    .quote-mark { position: absolute; top: 20px; right: 25px; font-size: 40px; color: rgba(212, 175, 55, 0.1); transition: 0.3s; }
    .modern-static-card:hover .quote-mark { color: rgba(212, 175, 55, 0.2); }
    .star-rating { color: var(--accent); font-size: 13px; }
    .testimonial-desc { color: #475569; font-size: 16px; line-height: 1.8; margin-bottom: 30px; font-style: italic; min-height: 100px; }
    .user-info-box { border-top: 1px solid #f1f5f9; padding-top: 20px; }
    .calligraphy-avatar { width: 50px; height: 50px; background: #064e3b; color: var(--accent); border-radius: 12px; display: flex; align-items: center; justify-content: center; font-family: 'Amiri', serif; font-size: 20px; border: 2px solid var(--accent); transition: 0.3s; }
    .modern-static-card:hover .calligraphy-avatar { background: var(--accent); color: #064e3b; transform: rotate(-5deg); }

    .contact-card-modern { margin-bottom: 40px; }
    .btn-whatsapp-submit { background: #021a14; color: white; font-weight: 800; border: none; border-radius: 12px; transition: 0.3s ease; }
    .btn-whatsapp-submit:hover { background: #1ebe57; transform: translateY(-2px); color: white; }
    
    .custom-faq-accordion .accordion-button { background-color: #fff; color: var(--primary-dark); border: 1px solid #f1f5f9; box-shadow: none; border-radius: 12px !important; }
    .custom-faq-accordion .accordion-button:not(.collapsed) { background-color: rgba(6, 78, 59, 0.05); color: var(--primary); }
    .custom-faq-accordion .accordion-item { border: 1px solid #f1f5f9 !important; border-radius: 12px !important; margin-bottom: 15px; overflow: hidden; }

    @media (max-width: 991px) {
        .carousel-item { height: 60vh; min-height: 450px; }
        .slider-title { font-size: 2.2rem; margin-bottom: 10px; }
        .slider-desc { font-size: 1rem; margin-bottom: 30px; }
        .slider-caption-custom span.arabic-text { font-size: 20px !important; }
        .custom-carousel-control { display: none !important; }
        .section-title { font-size: 26px !important; text-align: center !important; }
        h4.text-uppercase { text-align: center !important; }
        .section-padding { padding: 50px 0; }
        .premium-testimonial-grid { padding: 60px 0; }
        .modern-static-card { padding: 30px 20px; }
    }
</style>

<section class="slider-wrap">
    <div id="ahmadHero" class="carousel slide carousel-fade" data-bs-ride="carousel" data-bs-interval="4000">
        <div class="carousel-inner">
            
            <div class="carousel-item active">
                <img src="<?= htmlspecialchars($hero1_image); ?>" class="slider-bg-img" alt="Background">
                <div class="slider-caption-custom">
                    <span class="arabic-text text-warning fs-2 mb-3 d-block">اَلسَّلَامُ عَلَيْكُمْ وَرَحْمَةُ اللّٰهِ وَبَرَكَاتُهُ</span>
                    <h1 class="slider-title"><?= htmlspecialchars($hero1_title); ?></h1>
                    <p class="slider-desc"><?= htmlspecialchars($hero1_desc); ?></p>
                    <a href="free_trial" class="btn btn-lg px-5 py-3 rounded-pill fw-bold shadow-lg" style="background:var(--accent); color:var(--primary-dark); border:none;">Apply Free Class</a>
                </div>
            </div>

            <div class="carousel-item">
                <img src="<?= htmlspecialchars($hero2_image); ?>" class="slider-bg-img" alt="Background">
                <div class="slider-caption-custom">
                    <span class="arabic-text text-warning fs-2 mb-3 d-block">بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم</span>
                    <h1 class="slider-title"><?= htmlspecialchars($hero2_title); ?></h1>
                    <p class="slider-desc"><?= htmlspecialchars($hero2_desc); ?></p>
                    <a href="#courses" class="btn btn-lg px-5 py-3 rounded-pill fw-bold shadow-lg" style="background:var(--accent); color:var(--primary-dark); border:none;">Explore Courses</a>
                </div>
            </div>

            <div class="carousel-item">
                <img src="<?= htmlspecialchars($hero3_image); ?>" class="slider-bg-img" alt="Background">
                <div class="slider-caption-custom">
                    <span class="arabic-text text-warning fs-2 mb-3 d-block">طَلَبُ الْعِلْمِ فَرِيضَةٌ عَلَى كُلِّ مُسْلِمٍ</span>
                    <h1 class="slider-title"><?= htmlspecialchars($hero3_title); ?></h1>
                    <p class="slider-desc"><?= htmlspecialchars($hero3_desc); ?></p>
                    <a href="about-us" class="btn btn-lg px-5 py-3 rounded-pill fw-bold shadow-lg" style="background:var(--accent); color:var(--primary-dark); border:none;">Learn More</a>
                </div>
            </div>

        </div>
        <button class="carousel-control-prev custom-carousel-control position-absolute" type="button" data-bs-target="#ahmadHero" data-bs-slide="prev">
            <i class="fas fa-chevron-left fs-4 text-white"></i>
        </button>
        <button class="carousel-control-next custom-carousel-control position-absolute" type="button" data-bs-target="#ahmadHero" data-bs-slide="next">
            <i class="fas fa-chevron-right fs-4 text-white"></i>
        </button>
    </div>
</section>

<section class="section-padding" style="background-color: var(--bg-soft);" id="why-choose">
    <div class="container py-md-5 py-4">
        <div class="text-center mb-5">
            <h4 class="text-uppercase fw-bold mb-2" style="color: var(--accent); font-size: 14px; letter-spacing: 2px;">
                <?= htmlspecialchars($settings['why_choose_subtitle'] ?? 'Why Choose Ahmad Academy?'); ?>
            </h4>
            <h2 class="section-title">
                <?= htmlspecialchars($settings['why_choose_title'] ?? 'The Best Path for Your Islamic Journey'); ?>
            </h2>
            <p class="section-subtitle">We are committed to excellence in Islamic education with a modern and caring approach.</p>
        </div>

        <div class="row g-4">
            <?php foreach($features as $feat): 
                if(empty($feat['title'])) continue; // Skip if title is empty from CMS
            ?>
            <div class="col-lg-3 col-md-6">
                <div class="adv-card shadow-sm">
                    <div class="adv-icon-wrap"><i class="fas <?= htmlspecialchars($feat['icon']) ?>"></i></div>
                    <h5 class="fw-bold"><?= htmlspecialchars($feat['title']) ?></h5>
                    <p class="text-muted small"><?= htmlspecialchars($feat['desc']) ?></p>
                </div>
            </div>
            <?php endforeach; ?>
        </div>
    </div>
</section>

<section class="py-5 bg-white" id="courses">
    <div class="container py-5">
        <div class="text-center mb-5">
            <h2 class="section-title"><?= htmlspecialchars($settings['courses_title'] ?? 'Our Featured Courses'); ?></h2>
            <p class="section-subtitle"><?= htmlspecialchars($settings['courses_subtitle'] ?? 'Start your journey of seeking knowledge with our expert-led programs.'); ?></p>
        </div>

        <div class="row g-4">
            <?php if(!empty($courses)): foreach($courses as $c): 
                $img_url = !empty($c['image_url']) ? $c['image_url'] : 'assets/images/logo.png';
            ?>
            <div class="col-lg-4 col-md-6">
                <div class="course-card h-100 d-flex flex-column">
                    <a href="course_details.php?id=<?= $c['id']; ?>" class="text-decoration-none">
                        <div class="course-thumb-custom">
                            <img src="<?= htmlspecialchars($img_url); ?>" alt="<?= htmlspecialchars($c['title']); ?>">
                        </div>
                    </a>
                    <div class="course-head">
                        <span class="badge mb-2 px-3 py-2 rounded-pill" style="background: rgba(212, 175, 55, 0.15); color: var(--primary-dark); border: 1px solid var(--accent);">
                            <i class="far fa-clock me-1"></i> Duration: <?= htmlspecialchars($c['duration'] ?? 'Flexible'); ?>
                        </span>
                        <a href="course_details.php?id=<?= $c['id']; ?>" class="text-decoration-none"><h3><?= htmlspecialchars($c['title']); ?></h3></a>
                        
                        <div class="mt-2 text-muted small fw-bold">
                            <i class="fas fa-chalkboard-teacher text-warning me-1"></i> 
                            <?= htmlspecialchars($c['teacher_name'] ?? 'TBA') ?>
                        </div>
                    </div>
                    <div class="course-body d-flex flex-column flex-grow-1">
                        <div class="text-center mb-3 pb-3 border-bottom">
                            <span class="text-muted d-block fw-bold text-uppercase mb-1" style="font-size: 13px; letter-spacing: 1px;">Course Fee</span>
                            <h2 class="fw-black m-0" style="color: var(--primary); font-weight: 900;">$<?= number_format($c['fee'], 2); ?></h2>
                        </div>
                        
                        <div class="d-flex justify-content-center gap-3 mb-3 fw-bold small text-muted">
                            <div><i class="fas fa-users text-warning me-1"></i> <?= $c['total_students']; ?> Enrolled</div>
                            <div><i class="fas fa-certificate text-warning me-1"></i> Certificate</div>
                        </div>

                        <p class="text-muted small mb-4 flex-grow-1" style="text-align: center; line-height: 1.6;">
                            <?php 
                                $desc = strip_tags($c['description']);
                                echo mb_strlen($desc) > 100 ? mb_substr($desc, 0, 100) . '...' : ($desc ?: 'Join this course to enhance your authentic Islamic knowledge.');
                            ?>
                        </p>
                        <a href="course_details.php?id=<?= $c['id']; ?>" class="btn w-100 fw-bold mt-auto text-decoration-none" style="background: var(--primary-dark); color: var(--accent); padding: 12px; border-radius: 8px; transition: 0.3s;" onmouseover="this.style.backgroundColor='var(--accent)'; this.style.color='var(--primary-dark)';" onmouseout="this.style.backgroundColor='var(--primary-dark)'; this.style.color='var(--accent)';">
                            View Details <i class="fas fa-arrow-right ms-2"></i>
                        </a>
                    </div>
                </div>
            </div>
            <?php endforeach; else: ?>
                <div class="col-12 text-center py-5"><h5 class="text-muted">Courses are currently being updated. Check back soon.</h5></div>
            <?php endif; ?>
        </div>
    </div>
</section>

<section class="section-padding bg-white pt-0">
    <div class="container">
        <h2 class="section-title"><?= htmlspecialchars($settings['categories_title'] ?? 'Top Categories'); ?></h2>
        <div class="row g-4 justify-content-center">
            <?php foreach($categories as $cat): 
                if(empty($cat['title'])) continue;
            ?>
            <div class="col-lg-2 col-md-4 col-6">
                <div class="cat-card">
                    <i class="fas <?= $cat['icon']; ?> fa-2x mb-3 text-warning"></i>
                    <h6 class="fw-bold m-0"><?= htmlspecialchars($cat['title']); ?></h6>
                </div>
            </div>
            <?php endforeach; ?>
        </div>
    </div>
</section>

<section class="premium-testimonial-grid" id="testimonials">
    <div class="container py-5">
        <div class="text-center mb-5 pb-3">
            <h4 class="text-uppercase fw-bold mb-2" style="color: var(--accent); font-size: 14px; letter-spacing: 3px;">
                <?= htmlspecialchars($settings['testimonials_subtitle'] ?? 'Testimonials'); ?>
            </h4>
            <h2 class="section-title text-white fw-bold display-5">
                <?= htmlspecialchars($settings['testimonials_title'] ?? 'Success Stories from Our Global Community'); ?>
            </h2>
            <div class="modern-divider mx-auto"></div>
        </div>

        <div class="row g-4 justify-content-center">
            <?php 
            // ৬টি ডিফল্ট রিভিউ (যদি অ্যাডমিন প্যানেলে কিছু না থাকে)
            $default_testimonials = [
                1 => ['name' => 'Sarah Jameel', 'role' => 'Student, Australia', 'text' => 'The female tutors are amazing. My Tajweed has improved significantly in just 3 months of dedicated learning.'],
                2 => ['name' => 'Yusuf Ahmed', 'role' => 'Parent, Dubai', 'text' => 'Monthly progress reports help me track my son\'s Hifz journey effectively. The transparency is commendable.'],
                3 => ['name' => 'Ayesha Siddiqua', 'role' => 'Student, UK', 'text' => 'The interactive quizzes in every class make learning fun and very easy to remember. Alhamdulillah!'],
                4 => ['name' => 'Abdullah Ibn Musa', 'role' => 'Student, USA', 'text' => 'The teachers are highly qualified and patient. Their methodology is perfectly suited for working professionals.'],
                5 => ['name' => 'Fatima Rahman', 'role' => 'Parent, Canada', 'text' => 'Ahmad Academy transformed how my children learn the Quran. A truly professional and reliable foundation.'],
                6 => ['name' => 'Omar Al-Farsi', 'role' => 'Student, UK', 'text' => 'Highly flexible timing. I can manage my work and Quran classes easily without any pressure or stress.']
            ];

            // লুপ করে ৬টি রিভিউ নিয়ে আসা হচ্ছে
            for($i=1; $i<=6; $i++): 
                // যদি CMS এ ডেটা থাকে তাহলে সেটা নিবে, না থাকলে ডিফল্টটা নিবে
                $t_name = !empty($settings["testi_{$i}_name"]) ? $settings["testi_{$i}_name"] : $default_testimonials[$i]['name'];
                $t_role = !empty($settings["testi_{$i}_role"]) ? $settings["testi_{$i}_role"] : $default_testimonials[$i]['role'];
                $t_text = !empty($settings["testi_{$i}_text"]) ? $settings["testi_{$i}_text"] : $default_testimonials[$i]['text'];
                $t_rating = !empty($settings["testi_{$i}_rating"]) ? $settings["testi_{$i}_rating"] : 5;
                $t_initial = strtoupper(substr($t_name, 0, 1));
            ?>
            <div class="col-lg-4 col-md-6">
                <div class="modern-static-card">
                    <div class="card-glow"></div>
                    <div class="quote-mark"><i class="fas fa-quote-right"></i></div>
                    <div class="star-rating mb-3">
                        <?php for($s=0; $s<$t_rating; $s++) echo '<i class="fas fa-star"></i>'; ?>
                    </div>
                    <p class="testimonial-desc">"<?= htmlspecialchars($t_text); ?>"</p>
                    <div class="user-info-box d-flex align-items-center gap-3">
                        <div class="calligraphy-avatar"><?= $t_initial; ?></div>
                        <div>
                            <h6 class="m-0 fw-bold" style="color: var(--primary-dark);"><?= htmlspecialchars($t_name); ?></h6>
                            <small class="text-muted"><?= htmlspecialchars($t_role); ?></small>
                        </div>
                    </div>
                </div>
            </div>
            <?php endfor; ?>
        </div>
    </div>
</section>

<section class="section-padding bg-white border-top" id="help">
    <div class="container py-md-5 py-4">
        <div class="row g-5 align-items-start">
            
            <div class="col-lg-5">
                <div class="contact-card-modern">
                    <h4 class="text-uppercase fw-bold mb-2" style="color: #25D366; font-size: 14px; letter-spacing: 1px;">
                        <?= htmlspecialchars($settings['contact_subtitle'] ?? 'Direct Assistance'); ?>
                    </h4>
                    <h2 class="section-title text-start mb-4" style="font-size: 30px;">
                        <?= htmlspecialchars($settings['contact_title'] ?? 'Chat With Us on WhatsApp'); ?>
                    </h2>
                    <div class="form-wrapper p-4 rounded-4 shadow-sm border-top border-5" style="border-color: #25D366 !important; background: #f8fafc;">
                        <form id="whatsappForm" onsubmit="sendToWhatsApp(event)">
                            <div class="mb-3"><label class="form-label fw-bold small">Full Name <span class="text-danger">*</span></label><input type="text" id="wa_name" class="form-control border-0 shadow-sm py-2" placeholder="Enter your name" required></div>
                            <div class="mb-3"><label class="form-label fw-bold small">Phone Number <span class="text-danger">*</span></label><input type="tel" id="wa_phone" class="form-control border-0 shadow-sm py-2" placeholder="+880 XXXXX" required></div>
                            <div class="mb-4"><label class="form-label fw-bold small">Your Message <span class="text-danger">*</span></label><textarea id="wa_message" class="form-control border-0 shadow-sm" rows="3" placeholder="How can we help you?" required></textarea></div>
                            <button type="submit" class="btn btn-whatsapp-submit w-100 py-3 shadow">SEND MESSAGE <i class="fab fa-whatsapp ms-2 fs-5"></i></button>
                        </form>
                    </div>
                </div>
            </div>

            <div class="col-lg-7">
                <h4 class="text-uppercase fw-bold mb-2" style="color: var(--accent); font-size: 14px; letter-spacing: 1px;">
                    <?= htmlspecialchars($settings['faq_subtitle'] ?? 'Common Questions'); ?>
                </h4>
                <h2 class="section-title text-start mb-4" style="font-size: 30px;">
                    <?= htmlspecialchars($settings['faq_title'] ?? 'Frequently Asked Questions'); ?>
                </h2>
                <div class="accordion custom-faq-accordion" id="ahmadAcademyFaq">
                    <?php foreach($faqs as $index => $faq): 
                        if(empty($faq['q'])) continue;
                    ?>
                    <div class="accordion-item shadow-sm">
                        <h2 class="accordion-header">
                            <button class="accordion-button <?= $index !== 0 ? 'collapsed' : '' ?> fw-bold py-3" type="button" data-bs-toggle="collapse" data-bs-target="#faq<?= $index ?>">
                                <?= htmlspecialchars($faq['q']) ?>
                            </button>
                        </h2>
                        <div id="faq<?= $index ?>" class="accordion-collapse collapse <?= $index === 0 ? 'show' : '' ?>" data-bs-parent="#ahmadAcademyFaq">
                            <div class="accordion-body text-muted"><?= htmlspecialchars($faq['a']) ?></div>
                        </div>
                    </div>
                    <?php endforeach; ?>
                </div>
            </div>

        </div>
    </div>
</section>

<div class="container my-5">
    <div class="newsletter-section shadow-lg position-relative" style="background: var(--primary); padding: 60px 20px; border-radius: 20px; color: white; text-align: center; overflow: hidden;">
        <div class="position-absolute top-0 start-0 w-100 h-100 opacity-10" style="background-image: url('https://www.transparenttextures.com/patterns/arabesque.png'); pointer-events: none;"></div>
        <div class="position-relative z-10">
            <i class="fas fa-envelope-open-text fa-3x mb-3 text-warning"></i>
            <h2 class="fw-bold mb-3"><?= htmlspecialchars($settings['newsletter_title'] ?? 'Subscribe to Our Newsletter'); ?></h2>
            <p class="mb-4 text-white-50 fs-5"><?= htmlspecialchars($settings['newsletter_desc'] ?? 'Get the latest updates on new courses, Islamic articles, and academy news.'); ?></p>
            <form class="d-flex justify-content-center max-w-lg mx-auto" style="max-width: 550px; margin: 0 auto;">
                <div class="input-group input-group-lg shadow-sm">
                    <input type="email" class="form-control border-0" placeholder="Enter your email address" required style="border-radius: 8px 0 0 8px;">
                    <button class="btn" style="background: var(--accent); color: var(--primary-dark); font-weight: bold; border-radius: 0 8px 8px 0; padding: 0 25px;" type="submit">Subscribe</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    function sendToWhatsApp(event) {
        event.preventDefault();
        const name = document.getElementById('wa_name').value;
        const phone = document.getElementById('wa_phone').value;
        const message = document.getElementById('wa_message').value;
        let whatsappText = `*New Inquiry from Website*\n\n*Name:* ${name}\n*Phone:* ${phone}\n\n*Message:*\n${message}`;
        
        const adminWhatsapp = "<?= htmlspecialchars($contact_whatsapp); ?>";
        const whatsappURL = `https://wa.me/${adminWhatsapp}?text=${encodeURIComponent(whatsappText)}`;
        window.open(whatsappURL, '_blank');
        document.getElementById('whatsappForm').reset();
    }
</script>

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