<?php
// index.php - Complete Landing Page for হোমিওপ্যাথি স্বাস্থ্য কানন
require_once 'includes/config.php';
require_once 'includes/site-data.php';

// Dynamic settings
$st = $S['site_title'] ?? 'হোমিওপ্যাথি স্বাস্থ্য কানন';
$lt = $S['logo_text'] ?? 'স্বাস্থ্য কানন';
$li = $S['logo_icon'] ?? 'fa-heartbeat';
$pc = $S['primary_color'] ?? '#2d6a4f';
$ui = $S['use_image_logo'] ?? '0';
$lim = $S['logo_image'] ?? '';
$ft = $S['footer_text'] ?? 'হোমিওপ্যাথি স্বাস্থ্য কানন | সর্বস্বত্ব সংরক্ষিত';
$ph = $S['phone1'] ?? '';
$em = $S['email1'] ?? '';
$fb = $S['facebook_url'] ?? '#';
$yt = $S['youtube_url'] ?? '#';
$ig = $S['instagram_url'] ?? '#';
$wa = $S['whatsapp_number'] ?? '';
$desc = $S['site_description'] ?? 'অভিজ্ঞ হোমিওপ্যাথিক ডাক্তার দ্বারা পরিচালিত সম্পূর্ণ প্রাকৃতিক চিকিৎসা কেন্দ্র';
$hero_title = $S['hero_title'] ?? 'সুস্থ জীবন,<br>প্রাকৃতিক চিকিৎসা';
$hero_sub = $S['hero_subtitle'] ?? 'অভিজ্ঞ হোমিওপ্যাথিক ডাক্তারের পরামর্শ নিন এবং প্রাকৃতিক উপায়ে সুস্থ থাকুন';
$hero_btn = $S['hero_button_text'] ?? 'কোর্স দেখুন';
$hero_btn2 = $S['hero_second_button_text'] ?? 'অ্যাপয়েন্টমেন্ট নিন';

// Get data safely
$categories = []; try { $categories = $pdo->query("SELECT * FROM categories ORDER BY name_bn")->fetchAll(); } catch(Exception $e) {}

$featured = [];
try { $featured = $pdo->query("SELECT c.*, cat.name_bn as category_name, (SELECT COUNT(*) FROM lessons WHERE course_id=c.id) as lesson_count, (SELECT COUNT(*) FROM enrollments WHERE course_id=c.id AND payment_status='completed') as student_count FROM featured_courses fc JOIN courses c ON fc.course_id=c.id JOIN categories cat ON c.category_id=cat.id WHERE fc.is_active=1 AND c.status='published' ORDER BY fc.order_number LIMIT 8")->fetchAll(); } catch(Exception $e) {}
if(empty($featured)) { try { $featured = $pdo->query("SELECT c.*, cat.name_bn as category_name, (SELECT COUNT(*) FROM lessons WHERE course_id=c.id) as lesson_count, (SELECT COUNT(*) FROM enrollments WHERE course_id=c.id AND payment_status='completed') as student_count FROM courses c JOIN categories cat ON c.category_id=cat.id WHERE c.status='published' ORDER BY student_count DESC LIMIT 8")->fetchAll(); } catch(Exception $e) {} }

$instructors = []; try { $instructors = $pdo->query("SELECT u.*, COUNT(DISTINCT c.id) as course_count, COUNT(DISTINCT e.user_id) as student_count FROM users u LEFT JOIN courses c ON u.id=c.instructor_id LEFT JOIN enrollments e ON c.id=e.course_id WHERE u.role='instructor' AND u.show_on_website=1 GROUP BY u.id ORDER BY student_count DESC LIMIT 4")->fetchAll(); } catch(Exception $e) {}

$slogans = []; try { $slogans = $pdo->query("SELECT * FROM slogans WHERE is_active=1 ORDER BY order_number")->fetchAll(); } catch(Exception $e) {}
if(empty($slogans)) $slogans = [['text_bn'=>'৫,০০০+ রোগী','icon'=>'fa-users'],['text_bn'=>'১৫+ বছরের অভিজ্ঞতা','icon'=>'fa-calendar-check'],['text_bn'=>'১০০% প্রাকৃতিক','icon'=>'fa-leaf'],['text_bn'=>'২৪/৭ সাপোর্ট','icon'=>'fa-headset']];

$reviews = []; try { $reviews = $pdo->query("SELECT * FROM landing_reviews WHERE is_active=1 ORDER BY order_number LIMIT 10")->fetchAll(); } catch(Exception $e) {}
$concerns = []; try { $concerns = $pdo->query("SELECT * FROM brother_concerns WHERE is_active=1 ORDER BY order_number")->fetchAll(); } catch(Exception $e) {}
$banners = []; try { $banners = $pdo->query("SELECT * FROM dashboard_banners WHERE is_active=1 AND position='middle' AND (start_date IS NULL OR start_date<=CURDATE()) AND (end_date IS NULL OR end_date>=CURDATE()) ORDER BY order_number LIMIT 3")->fetchAll(); } catch(Exception $e) {}
?>
<!DOCTYPE html>
<html lang="bn">
<head>
    <meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1.0">
    <meta name="description" content="<?=htmlspecialchars($desc)?>">
    <title><?=htmlspecialchars($st)?> - হোমিওপ্যাথিক চিকিৎসা</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">
    <style>
        :root{--primary:<?=$pc?>;--g1:linear-gradient(135deg,<?=$pc?>,#52b788)}
        *{margin:0;padding:0;box-sizing:border-box}
        body{background:#f5faf7;font-family:'Segoe UI','Hind Siliguri','Noto Sans Bengali',Arial,sans-serif;overflow-x:hidden}
        .container{max-width:1200px;margin:0 auto;padding:0 20px}
        
        .top-bar{background:#1a3d2a;color:white;padding:6px 0;font-size:.78rem}
        .top-bar a{color:rgba(255,255,255,.8);text-decoration:none;margin:0 6px;transition:.3s}
        .top-bar a:hover{color:white}
        
        .navbar{background:rgba(255,255,255,.97);backdrop-filter:blur(15px);box-shadow:0 2px 20px rgba(0,0,0,.06);padding:12px 0;position:sticky;top:0;z-index:1000}
        .navbar-brand{font-weight:800;font-size:1.2rem;color:var(--primary)!important;text-decoration:none;display:flex;align-items:center;gap:8px}
        .navbar-brand img{height:34px}
        .nav-link{color:#555;text-decoration:none;font-weight:500;margin:0 8px;font-size:.9rem;transition:.3s}
        .nav-link:hover,.nav-link.active{color:var(--primary)}
        .btn-nav{background:var(--g1);color:white!important;border-radius:50px;padding:8px 22px;font-weight:600;text-decoration:none;font-size:.85rem;display:inline-flex;align-items:center;gap:6px;transition:.3s}
        .btn-nav:hover{transform:translateY(-2px);box-shadow:0 8px 20px rgba(45,106,79,.35)}
        
        .hero-section{background:linear-gradient(135deg,#1b4332,#2d6a4f,#40916c);color:white;padding:100px 0 150px;position:relative;overflow:hidden}
        .hero-section::before{content:'';position:absolute;top:-100px;right:-100px;width:500px;height:500px;border-radius:50%;background:rgba(255,255,255,.04);animation:float 8s infinite}
        .hero-section::after{content:'';position:absolute;bottom:-50px;left:-50px;width:300px;height:300px;border-radius:50%;background:rgba(255,255,255,.03);animation:float 6s infinite reverse}
        @keyframes float{0%,100%{transform:translate(0,0)}50%{transform:translate(30px,-30px)}}
        .hero-content{position:relative;z-index:2}
        .hero-content h1{font-size:3rem;font-weight:800;line-height:1.3;margin-bottom:15px}
        .hero-content p{font-size:1.15rem;opacity:.9;margin-bottom:25px}
        .hero-badge{display:inline-block;padding:6px 18px;border-radius:50px;font-weight:700;font-size:.85rem;margin-bottom:15px;background:rgba(255,255,255,.2)}
        
        .btn-hero{padding:14px 32px;border-radius:50px;font-weight:700;text-decoration:none;display:inline-flex;align-items:center;gap:8px;font-size:1rem;transition:all .3s}
        .btn-hero:hover{transform:translateY(-3px)}
        .btn-hero-primary{background:white;color:var(--primary)!important}
        .btn-hero-primary:hover{box-shadow:0 10px 35px rgba(0,0,0,.3)}
        .btn-hero-outline{border:2px solid rgba(255,255,255,.5);color:white!important}
        .btn-hero-outline:hover{background:white;color:var(--primary)!important}
        
        .search-wrapper{margin-top:-45px;position:relative;z-index:10}
        .search-box{background:white;border-radius:20px;padding:6px;box-shadow:0 20px 60px rgba(0,0,0,.12);display:flex;gap:6px}
        .search-box select{border:2px solid #e8eaef;border-radius:14px;padding:14px 16px;font-size:.9rem;background:#fafbfd;min-width:160px}
        .search-box input{border:none;padding:14px 18px;font-size:1rem;flex:1;border-radius:14px;outline:none}
        .search-box button{background:var(--g1);color:white;border:none;border-radius:14px;padding:14px 28px;font-weight:700;cursor:pointer}
        
        .section-padding{padding:80px 0}
        .section-header{text-align:center;margin-bottom:50px}
        .section-header h2{font-weight:800;font-size:2.2rem;color:#1a1a2e;margin-bottom:10px;position:relative;display:inline-block}
        .section-header h2::after{content:'';position:absolute;bottom:-5px;left:50%;transform:translateX(-50%);width:70px;height:4px;background:var(--g1);border-radius:2px}
        .section-header p{color:#888;font-size:1.05rem;max-width:600px;margin:15px auto 0}
        .section-badge{padding:6px 18px;border-radius:50px;font-weight:600;font-size:.8rem;display:inline-block;margin-bottom:12px}
        
        .stats-bar{background:#1a3d2a;color:white;padding:40px 0}
        .stat-item{text-align:center;padding:20px}
        .stat-item i{font-size:2rem;margin-bottom:10px;opacity:.8}
        .stat-item h3{font-weight:800;font-size:2rem;margin:0}
        
        .cat-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:18px}
        .cat-card{background:white;border-radius:16px;padding:22px 20px;box-shadow:0 2px 10px rgba(0,0,0,.04);transition:all .4s cubic-bezier(.175,.885,.32,1.275);text-decoration:none;color:#1a1a2e;display:flex;align-items:center;gap:16px;border:1px solid #f0f0f0}
        .cat-card:hover{transform:translateY(-8px);box-shadow:0 20px 60px rgba(0,0,0,.12);border-color:transparent}
        .cat-icon{width:58px;height:58px;min-width:58px;border-radius:16px;display:flex;align-items:center;justify-content:center;font-size:1.4rem;color:white;transition:.3s}
        .cat-card:hover .cat-icon{transform:rotate(8deg)scale(1.1)}
        .cat-info h6{font-weight:700;margin:0 0 3px;font-size:.92rem}.cat-info small{color:#888;font-size:.78rem}
        
        .course-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(280px,1fr));gap:25px}
        .course-card{background:white;border-radius:20px;overflow:hidden;box-shadow:0 2px 10px rgba(0,0,0,.04);transition:all .4s;position:relative}
        .course-card:hover{transform:translateY(-15px);box-shadow:0 25px 60px rgba(0,0,0,.12)}
        .course-thumb{height:200px;object-fit:cover;width:100%;transition:.5s}.course-card:hover .course-thumb{transform:scale(1.1)}
        .course-thumb-placeholder{height:200px;display:flex;align-items:center;justify-content:center;font-size:3rem;color:white}
        .course-body{padding:20px}.course-footer{display:flex;justify-content:space-between;align-items:center;padding-top:15px;border-top:1px solid #f0f0f0;font-size:.85rem}
        .course-price{font-weight:800;font-size:1.2rem}.course-price.free{color:#2d6a4f}.course-price.paid{color:var(--primary)}
        
        .inst-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(220px,1fr));gap:20px}
        .inst-card{background:white;border-radius:20px;padding:35px 25px;text-align:center;box-shadow:0 2px 10px rgba(0,0,0,.04);transition:.3s}
        .inst-card:hover{transform:translateY(-10px);box-shadow:0 20px 60px rgba(0,0,0,.12)}
        .inst-card img{width:95px;height:95px;border-radius:50%;object-fit:cover;border:5px solid var(--primary);margin-bottom:15px}
        
        .review-card{background:white;border-radius:20px;padding:30px 24px;box-shadow:0 2px 10px rgba(0,0,0,.04);transition:.3s;text-align:center;position:relative}
        .review-card:hover{transform:translateY(-8px);box-shadow:0 15px 45px rgba(0,0,0,.12)}
        .review-card::before{content:'"';position:absolute;top:10px;left:20px;font-size:5rem;color:var(--primary);opacity:.06;font-family:Georgia,serif;line-height:1}
        .review-card img{width:70px;height:70px;border-radius:50%;object-fit:cover;border:4px solid var(--primary);margin-bottom:12px}
        .stars{color:#ffc107;font-size:1.1rem;margin-bottom:8px}
        
        .concern-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(350px,1fr));gap:20px}
        .concern-card{background:white;border-radius:20px;padding:30px 25px;box-shadow:0 2px 10px rgba(0,0,0,.04);transition:.3s;border-left:6px solid transparent}
        .concern-card:hover{transform:translateY(-8px);box-shadow:0 20px 60px rgba(0,0,0,.12);border-left-color:var(--primary)}
        
        .wa-float{position:fixed;bottom:30px;right:30px;z-index:999;width:65px;height:65px;background:#25d366;border-radius:50%;display:flex;align-items:center;justify-content:center;font-size:2rem;color:white;box-shadow:0 5px 25px rgba(37,211,102,.4);animation:waPulse 2s infinite;text-decoration:none}
        @keyframes waPulse{0%,100%{box-shadow:0 0 0 0 rgba(37,211,102,.4)}50%{box-shadow:0 0 0 20px rgba(37,211,102,.3)}}
        
        footer{background:#1a1a2e;color:white;padding:60px 0 25px;position:relative}
        footer::before{content:'';position:absolute;top:0;left:0;width:100%;height:3px;background:var(--g1)}
        footer h5{font-weight:700}footer a{color:rgba(255,255,255,.7);text-decoration:none;display:block;margin-bottom:8px;transition:.3s}
        footer a:hover{color:white;padding-left:8px}
        .social-icon{width:45px;height:45px;border-radius:50%;background:rgba(255,255,255,.1);display:inline-flex;align-items:center;justify-content:center;color:white;margin:0 6px;transition:.3s;text-decoration:none;font-size:1.2rem}
        .social-icon:hover{background:var(--primary);transform:translateY(-5px)}
        
        @media(max-width:992px){.cat-grid{grid-template-columns:repeat(2,1fr)}}
        @media(max-width:768px){.hero-content h1{font-size:2rem}.cat-grid{grid-template-columns:1fr}.course-grid{grid-template-columns:1fr}.concern-grid{grid-template-columns:1fr}}
        /* All Courses Cards */
.card-img-top {
    transition: .5s ease;
}
.card:hover .card-img-top {
    transform: scale(1.05);
}
.card {
    transition: all .4s cubic-bezier(.175,.885,.32,1.275);
}
.card:hover {
    transform: translateY(-10px);
    box-shadow: 0 20px 60px rgba(0,0,0,.15) !important;
}
.card .badge {
    z-index: 2;
}
    </style>
</head>
<body>

<!-- Top Bar -->
<div class="top-bar"><div class="container" style="display:flex;justify-content:space-between;flex-wrap:wrap">
    <span>📞 <?=htmlspecialchars($ph)?: '01712-345678'?> | ✉️ <?=htmlspecialchars($em)?: 'info@shasthokanon.com'?></span>
    <span><?php if($fb):?><a href="<?=$fb?>"><i class="fab fa-facebook"></i></a><?php endif;?><?php if($yt):?><a href="<?=$yt?>"><i class="fab fa-youtube"></i></a><?php endif;?></span>
</div></div>

<!-- Navbar -->
<nav class="navbar"><div class="container" style="display:flex;justify-content:space-between;align-items:center">
    <a href="index.php" class="navbar-brand"><?php if($ui=='1'&&!empty($lim)&&file_exists('uploads/logo/'.$lim)):?><img src="uploads/logo/<?=$lim?>" alt=""><?php else:?><i class="fas <?=$li?> me-2"></i><?=htmlspecialchars($lt)?><?php endif;?></a>
    <div style="display:flex;gap:10px;align-items:center;flex-wrap:wrap">
        <a href="index.php" class="nav-link active">হোম</a><a href="courses.php" class="nav-link">কোর্স</a>
        <a href="about.php" class="nav-link">আমাদের সম্পর্কে</a><a href="contact.php" class="nav-link">যোগাযোগ</a>
        <?php if(isset($_SESSION['user_id'])):?><a href="dashboard.php" class="btn-nav"><i class="fas fa-user"></i> ড্যাশবোর্ড</a><?php else:?><a href="auth.php" class="btn-nav"><i class="fas fa-sign-in-alt"></i> লগইন</a><?php endif;?>
    </div>
</div></nav>

<!-- Hero -->
<section class="hero-section"><div class="container"><div class="row align-items-center">
    <div class="col-lg-7 hero-content" data-aos="fade-right">
        <span class="hero-badge">🏥 হোমিওপ্যাথিক চিকিৎসা</span>
        <h1><?=nl2br(htmlspecialchars($hero_title))?></h1>
        <p><?=htmlspecialchars($hero_sub)?></p>
        <div class="d-flex gap-3 flex-wrap">
            <a href="courses.php" class="btn-hero btn-hero-primary"><i class="fas fa-book-medical"></i> <?=htmlspecialchars($hero_btn)?></a>
            <a href="contact.php" class="btn-hero btn-hero-outline"><i class="fas fa-calendar-check"></i> <?=htmlspecialchars($hero_btn2)?></a>
        </div>
    </div>
    <div class="col-lg-5 text-center d-none d-lg-block" data-aos="fade-left"><i class="fas fa-heartbeat" style="font-size:15rem;opacity:.15"></i></div>
</div></div></section>

<!-- Search -->
<div class="container"><div class="search-wrapper" data-aos="zoom-in"><div class="search-box">
    <select onchange="if(this.value)window.location='courses.php?category='+this.value"><option value="">📂 সকল বিষয়</option><?php foreach($categories as $cat):?><option value="<?=$cat['slug']?>"><?=htmlspecialchars($cat['name_bn'])?></option><?php endforeach;?></select>
    <input type="text" id="courseSearch" placeholder="🔍 আপনার পছন্দের কোর্স খুঁজুন..." onkeypress="if(event.key==='Enter')window.location='courses.php?search='+encodeURIComponent(this.value)">
    <button onclick="window.location='courses.php?search='+encodeURIComponent(document.getElementById('courseSearch').value)"><i class="fas fa-search"></i> খুঁজুন</button>
</div></div></div>

<!-- Stats -->
<div class="stats-bar"><div class="container"><div class="row"><?php foreach($slogans as $sl):?><div class="col-6 col-md-3 stat-item" data-aos="fade-up"><i class="fas <?=$sl['icon']?>"></i><h3><?=htmlspecialchars($sl['text_bn'])?></h3><p><?=htmlspecialchars($st)?></p></div><?php endforeach;?></div></div></div>

<!-- Categories -->
<?php if(count($categories) > 0): ?>
<div class="section-padding bg-white"><div class="container"><div class="section-header" data-aos="fade-up"><span class="section-badge" style="background:#e8f5e9;color:#2d6a4f">📂 বিষয়সমূহ</span><h2>আমাদের কোর্স বিষয়</h2><p class="text-muted">আপনার পছন্দের বিষয় অনুযায়ী হোমিওপ্যাথিক কোর্স খুঁজুন</p></div>
<div class="cat-grid"><?php $catColors=['#2d6a4f','#40916c','#52b788','#74c69d','#95d5b2','#b7e4c7','#1b4332','#081c15','#3a5a40','#588157'];foreach($categories as $ci=>$cat):$cc=0;try{$cst=$pdo->prepare("SELECT COUNT(*) FROM courses WHERE category_id=? AND status='published'");$cst->execute([$cat['id']]);$cc=$cst->fetchColumn();}catch(Exception $e){}?>
    <a href="courses.php?category=<?=$cat['slug']?>" class="cat-card" data-aos="fade-up" data-aos-delay="<?=$ci*80?>"><div class="cat-icon" style="background:<?=$catColors[$ci%10]?>"><i class="fas <?=$cat['icon']?:'fa-book-medical'?>"></i></div><div class="cat-info"><h6><?=htmlspecialchars($cat['name_bn'])?></h6><small><?=$cc?> টি কোর্স</small></div></a>
<?php endforeach;?></div></div></div>
<?php endif; ?>

<!-- Banners -->
<?php if(count($banners)>0):?><div class="container py-3"><?php foreach($banners as $b):?>
    <div class="ad-banner text-white p-4 p-md-5 mb-3 rounded-4" data-aos="fade-up" style="background:var(--g1)"><div class="row align-items-center"><div class="col-md-8"><?php if($b['badge_text']):?><span class="badge mb-2" style="background:<?=$b['badge_color']?>"><?=htmlspecialchars($b['badge_text'])?></span><?php endif;?><h4 class="fw-bold"><?=htmlspecialchars($b['title'])?></h4><p class="mb-0" style="opacity:.9"><?=htmlspecialchars($b['subtitle']??'')?></p></div><div class="col-md-4 text-md-end mt-3 mt-md-0"><?php if($b['button_text']):?><a href="<?=$b['button_url']?>" class="btn btn-light rounded-pill fw-bold me-2"><?=htmlspecialchars($b['button_text'])?></a><?php endif;?></div></div></div>
<?php endforeach;?></div><?php endif;?>

<!-- Featured Courses -->
<div class="section-padding"><div class="container"><div class="section-header" data-aos="fade-up"><span class="section-badge" style="background:#fff8e1;color:#f57f17">⭐ জনপ্রিয়</span><h2>জনপ্রিয় কোর্সসমূহ</h2><p class="text-muted">আমাদের সেরা হোমিওপ্যাথিক কোর্সগুলো দেখুন</p></div>
<div class="course-grid"><?php foreach($featured as $c):$yt=null;$ls=$pdo->prepare("SELECT youtube_url FROM lessons WHERE course_id=? LIMIT 1");$ls->execute([$c['id']]);$l=$ls->fetch();if($l){preg_match('/(?:youtube\.com\/watch\?v=|youtu\.be\/)([a-zA-Z0-9_-]{11})/',$l['youtube_url'],$m);$yt=$m[1]??null;}?>
    <div class="course-card" data-aos="fade-up"><?php if($yt):?><img src="https://img.youtube.com/vi/<?=$yt?>/maxresdefault.jpg" class="course-thumb" alt=""><?php else:?><div class="course-thumb-placeholder" style="background:var(--g1)"><i class="fas fa-book-medical"></i></div><?php endif;?><span class="badge bg-<?=$c['price']==0?'success':'warning'?> position-absolute top-0 end-0 m-2" style="z-index:2"><?=$c['price']==0?'ফ্রি':'৳'.number_format($c['price'])?></span>
    <div class="course-body"><span class="badge bg-secondary mb-2" style="font-size:.7rem"><?=htmlspecialchars($c['category_name'])?></span><h6 class="fw-bold"><a href="course-details.php?id=<?=$c['id']?>" class="text-decoration-none text-dark"><?=htmlspecialchars(mb_substr($c['title_bn'],0,35))?></a></h6>
    <div class="course-footer"><small class="text-muted"><?=$c['lesson_count']?> লেসন | <?=$c['student_count']?> শিক্ষার্থী</small><span class="course-price fw-bold <?=$c['price']==0?'free':'paid'?>"><?=$c['price']==0?'ফ্রি':'৳'.number_format($c['price'])?></span></div></div></div>
<?php endforeach;?></div><div class="text-center mt-5"><a href="courses.php" class="btn btn-lg rounded-pill fw-bold text-white" style="background:var(--g1)">সকল কোর্স দেখুন <i class="fas fa-arrow-right ms-2"></i></a></div></div></div>

<!-- Instructors -->
<?php if(count($instructors)>0):?><div class="section-padding bg-white"><div class="container"><div class="section-header" data-aos="fade-up"><span class="section-badge" style="background:#fff3e0;color:#e67e22">👨‍⚕️ বিশেষজ্ঞ</span><h2>অভিজ্ঞ হোমিওপ্যাথিক ডাক্তার</h2><p class="text-muted">দক্ষ ও অভিজ্ঞ ডাক্তারদের কাছ থেকে শিখুন</p></div>
<div class="inst-grid"><?php foreach($instructors as $ins):?><div class="inst-card" data-aos="fade-up"><img src="uploads/avatars/<?=$ins['avatar']?:'default-avatar.png'?>" onerror="this.src='https://ui-avatars.com/api/?name=<?=urlencode($ins['full_name'])?>&background=2d6a4f&color=fff&size=95'"><h6 class="fw-bold mt-2"><?=htmlspecialchars($ins['full_name'])?></h6><small class="text-muted"><?=$ins['course_count']?> কোর্স | <?=$ins['student_count']?> শিক্ষার্থী</small></div><?php endforeach;?></div></div></div><?php endif;?>

<!-- Services -->
<?php if(count($concerns)>0):?><div class="section-padding"><div class="container"><div class="section-header" data-aos="fade-up"><span class="section-badge" style="background:#d4f5e9;color:#2d6a4f">🌟 সেবা</span><h2>আমাদের সেবাসমূহ</h2></div>
<div class="concern-grid"><?php foreach($concerns as $cn):?><div class="concern-card" data-aos="fade-up"><div class="d-flex gap-3"><div class="rounded-3 d-flex align-items-center justify-content-center text-white flex-shrink-0" style="width:55px;height:55px;background:<?=$cn['gradient_color']?>;font-size:1.4rem"><i class="fas <?=$cn['icon']?>"></i></div><div><h6 class="fw-bold"><?=htmlspecialchars($cn['title'])?></h6><p class="text-muted small"><?=htmlspecialchars(mb_substr($cn['description']??'',0,80))?></p><?php if($cn['main_button_text']):?><a href="<?=$cn['main_button_url']?>" class="btn btn-sm rounded-pill fw-bold text-white" style="background:<?=$cn['main_button_color']?>"><?=htmlspecialchars($cn['main_button_text'])?></a><?php endif;?></div></div></div><?php endforeach;?></div></div></div><?php endif;?>

<!-- Reviews -->
<?php if(count($reviews)>0):?><div class="section-padding bg-white"><div class="container"><div class="section-header" data-aos="fade-up"><span class="section-badge" style="background:#fff8e1;color:#f57f17">⭐ রোগীদের মতামত</span><h2>রোগীরা যা বলছেন</h2></div>
<div class="row g-4"><?php foreach($reviews as $lr):?><div class="col-md-4" data-aos="fade-up"><div class="review-card"><img src="<?=$lr['student_avatar']?:'https://ui-avatars.com/api/?name='.urlencode($lr['student_name']).'&background=2d6a4f&color=fff&size=70'?>" alt=""><div class="stars"><?=str_repeat('★',$lr['rating']).str_repeat('☆',5-$lr['rating'])?></div><p class="small text-muted">"<?=htmlspecialchars(mb_substr($lr['comment'],0,120))?>"</p><strong><?=htmlspecialchars($lr['student_name'])?></strong><br><small class="text-muted"><?=htmlspecialchars($lr['student_designation'])?></small></div></div><?php endforeach;?></div></div></div><?php endif;?>
<!-- All Courses Section -->
<div class="section-padding">
    <div class="container">
        <div class="section-header text-center mb-5" data-aos="fade-up">
            <span class="section-badge d-inline-block mb-2" style="background:#e8f5e9;color:#2d6a4f">📚 সকল কোর্স</span>
            <h2>আমাদের সকল কোর্স</h2>
            <p class="text-muted">হোমিওপ্যাথির উপর আমাদের সম্পূর্ণ কোর্স তালিকা</p>
        </div>
        
        <?php
        // Get all published courses
        $allCourses = [];
        try {
            $allCourses = $pdo->query("
                SELECT c.*, cat.name_bn as category_name, u.full_name as instructor_name,
                       (SELECT COUNT(*) FROM lessons WHERE course_id=c.id) as lesson_count,
                       (SELECT COUNT(*) FROM enrollments WHERE course_id=c.id AND payment_status='completed') as student_count,
                       COALESCE((SELECT AVG(rating) FROM reviews WHERE course_id=c.id), 0) as avg_rating
                FROM courses c
                JOIN categories cat ON c.category_id = cat.id
                JOIN users u ON c.instructor_id = u.id
                WHERE c.status = 'published'
                ORDER BY c.created_at DESC
            ")->fetchAll();
        } catch(Exception $e) { $allCourses = []; }
        ?>
        
        <?php if(count($allCourses) > 0): ?>
        <div class="row g-4">
            <?php foreach($allCourses as $c): 
                $yt = null;
                try {
                    $ls = $pdo->prepare("SELECT youtube_url FROM lessons WHERE course_id=? LIMIT 1");
                    $ls->execute([$c['id']]);
                    $l = $ls->fetch();
                    if($l && !empty($l['youtube_url'])) {
                        preg_match('/(?:youtube\.com\/watch\?v=|youtu\.be\/)([a-zA-Z0-9_-]{11})/', $l['youtube_url'], $m);
                        $yt = $m[1] ?? null;
                    }
                } catch(Exception $e) {}
            ?>
            <div class="col-md-6 col-lg-4" data-aos="fade-up">
                <div class="card h-100 border-0 shadow-sm rounded-4 overflow-hidden">
                    <?php if($yt): ?>
                        <img src="https://img.youtube.com/vi/<?=$yt?>/maxresdefault.jpg" class="card-img-top" style="height:200px;object-fit:cover" alt="<?=htmlspecialchars($c['title_bn'])?>">
                    <?php else: ?>
                        <div class="d-flex align-items-center justify-content-center" style="height:200px;background:linear-gradient(135deg,#2d6a4f,#52b788);color:white;font-size:3rem">
                            <i class="fas fa-book-medical"></i>
                        </div>
                    <?php endif; ?>
                    
                    <span class="badge bg-<?=$c['price']==0?'success':'warning'?> position-absolute" style="top:12px;right:12px;font-size:.8rem;padding:6px 14px;border-radius:20px">
                        <?=$c['price']==0 ? '🆓 ফ্রি' : '💰 ৳'.number_format($c['price'])?>
                    </span>
                    
                    <div class="card-body d-flex flex-column">
                        <span class="badge bg-light text-dark mb-2 align-self-start" style="font-size:.7rem">
                            <?=htmlspecialchars($c['category_name'] ?? 'কোর্স')?>
                        </span>
                        <h6 class="fw-bold mb-2">
                            <a href="course-details.php?id=<?=$c['id']?>" class="text-decoration-none text-dark">
                                <?=htmlspecialchars(mb_substr($c['title_bn'], 0, 50))?>
                                <?=mb_strlen($c['title_bn'])>50 ? '...' : ''?>
                            </a>
                        </h6>
                        
                        <div class="mt-auto">
                            <div class="d-flex justify-content-between align-items-center text-muted small mb-2">
                                <span><i class="fas fa-video me-1"></i> <?=$c['lesson_count']?> লেসন</span>
                                <span><i class="fas fa-user-graduate me-1"></i> <?=$c['student_count']?> শিক্ষার্থী</span>
                                <?php if($c['avg_rating'] > 0): ?>
                                <span><i class="fas fa-star text-warning me-1"></i> <?=round($c['avg_rating'],1)?></span>
                                <?php endif; ?>
                            </div>
                            <div class="d-flex gap-2">
                                <a href="course-details.php?id=<?=$c['id']?>" class="btn btn-sm flex-fill rounded-pill text-white" style="background:var(--g1)">
                                    <i class="fas fa-info-circle me-1"></i> বিস্তারিত
                                </a>
                                <a href="enroll.php?course=<?=$c['id']?>" class="btn btn-sm flex-fill rounded-pill btn-outline-success">
                                    <i class="fas fa-sign-in-alt me-1"></i> এনরোল
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <?php endforeach; ?>
        </div>
        
        <div class="text-center mt-5">
            <a href="courses.php" class="btn btn-lg rounded-pill fw-bold text-white px-5 py-3" style="background:var(--g1)">
                <i class="fas fa-th-large me-2"></i> সকল কোর্স দেখুন
            </a>
        </div>
        <?php else: ?>
        <div class="text-center py-5 text-muted">
            <i class="fas fa-book-open fa-3x mb-3" style="opacity:.3"></i>
            <h5>কোন কোর্স পাওয়া যায়নি</h5>
        </div>
        <?php endif; ?>
    </div>
</div>
<!-- WhatsApp -->
<?php if($wa):?><a href="https://wa.me/<?=$wa?>?text=<?=urlencode('আমি স্বাস্থ্য কানন সম্পর্কে জানতে চাই')?>" target="_blank" class="wa-float"><i class="fab fa-whatsapp"></i></a><?php endif;?>

<!-- Footer -->
<footer><div class="container"><div class="row">
    <div class="col-md-4 mb-4"><h5><i class="fas <?=$li?> me-2"></i><?=htmlspecialchars($st)?></h5><p style="opacity:.7"><?=htmlspecialchars($desc)?></p><div class="mt-3"><?php if($fb):?><a href="<?=$fb?>" class="social-icon"><i class="fab fa-facebook-f"></i></a><?php endif;?><?php if($yt):?><a href="<?=$yt?>" class="social-icon"><i class="fab fa-youtube"></i></a><?php endif;?></div></div>
    <div class="col-md-3 mb-4"><h6 class="fw-bold">দ্রুত লিংক</h6><a href="courses.php">📚 কোর্স</a><a href="about.php">ℹ️ আমাদের সম্পর্কে</a><a href="contact.php">📞 যোগাযোগ</a></div>
    <div class="col-md-3 mb-4"><h6 class="fw-bold">সাপোর্ট</h6><a href="dashboard.php">📊 ড্যাশবোর্ড</a><a href="my-courses.php">🎓 আমার কোর্স</a><a href="my-certificates.php">🏆 সার্টিফিকেট</a></div>
    <div class="col-md-2 mb-4"><h6 class="fw-bold">যোগাযোগ</h6><p style="opacity:.7;font-size:.85rem"><?=htmlspecialchars($ph)?><br><?=htmlspecialchars($em)?></p></div>
</div><hr style="border-color:rgba(255,255,255,.1)"><p class="text-center mb-0">&copy; <?=date('Y')?> <?=htmlspecialchars($ft)?></p></div></footer>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>
<script>AOS.init({duration:800,once:true});</script>
</body>
</html>