<?php
// admin/landing-manager.php - Complete Dynamic Landing Page Manager
session_start();
require_once '../includes/config.php';

if(!isset($_SESSION['user_id']) || $_SESSION['user_role'] != 'admin') {
    header('Location: ../auth.php');
    exit;
}

$tab = $_GET['tab'] ?? 'overview';
$msg = $_GET['msg'] ?? '';
$msg_type = $_GET['type'] ?? 'success';

// ==================== SAVE COLORS ====================
if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['save_colors'])) {
    $color_keys = ['primary_color','hero_bg_color','hero_bg_color2','hero_title_color','hero_subtitle_color',
        'navbar_bg_color','navbar_text_color','footer_bg_color','footer_text_color','body_bg_color',
        'heading_color','text_color','muted_text_color','card_bg_color','card_text_color',
        'link_color','link_hover_color','badge_bg_color','badge_text_color','button_color','button_text_color',
        'stats_bg_color','stats_text_color','section_bg_alt'];
    $stmt = $pdo->prepare("INSERT INTO site_settings (setting_key, setting_value) VALUES (?, ?) ON DUPLICATE KEY UPDATE setting_value = VALUES(setting_value)");
    foreach($color_keys as $k) { $stmt->execute([$k, $_POST[$k] ?? '']); }
    $msg = '✅ কালার সেটিংস সফলভাবে সংরক্ষিত হয়েছে!';
}

// ==================== SAVE HERO ====================
if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['save_hero'])) {
    $hero_keys = ['hero_title','hero_subtitle','hero_button_text','hero_button_url','hero_second_button_text','hero_second_button_url','site_subtitle'];
    $stmt = $pdo->prepare("INSERT INTO site_settings (setting_key, setting_value) VALUES (?, ?) ON DUPLICATE KEY UPDATE setting_value = VALUES(setting_value)");
    foreach($hero_keys as $k) { $stmt->execute([$k, $_POST[$k] ?? '']); }
    $msg = '✅ হিরো সেকশন আপডেট হয়েছে!';
}

// ==================== SAVE BRANDING ====================
if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['save_branding'])) {
    $brand_keys = ['site_title','logo_text','logo_icon','footer_text','phone1','email1','facebook_url','youtube_url','instagram_url','linkedin_url','whatsapp_number','site_description'];
    $stmt = $pdo->prepare("INSERT INTO site_settings (setting_key, setting_value) VALUES (?, ?) ON DUPLICATE KEY UPDATE setting_value = VALUES(setting_value)");
    foreach($brand_keys as $k) { $stmt->execute([$k, $_POST[$k] ?? '']); }
    
    if(isset($_FILES['logo_image']) && $_FILES['logo_image']['error'] == 0) {
        $ext = strtolower(pathinfo($_FILES['logo_image']['name'], PATHINFO_EXTENSION));
        if(in_array($ext, ['jpg','jpeg','png','gif','webp','svg'])) {
            $dir = '../uploads/logo/'; if(!is_dir($dir)) mkdir($dir, 0777, true);
            $old = $pdo->query("SELECT setting_value FROM site_settings WHERE setting_key='logo_image'")->fetchColumn();
            if($old && file_exists($dir.$old)) unlink($dir.$old);
            $name = 'logo_'.time().'.'.$ext;
            move_uploaded_file($_FILES['logo_image']['tmp_name'], $dir.$name);
            $stmt->execute(['logo_image', $name]);
        }
    }
    $use_img = isset($_POST['use_image_logo']) ? '1' : '0';
    $stmt->execute(['use_image_logo', $use_img]);
    $msg = '✅ ব্র্যান্ডিং আপডেট হয়েছে!';
}

// ==================== ADD SLOGAN ====================
if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['add_slogan'])) {
    $pdo->prepare("INSERT INTO slogans (text_bn, icon, order_number, is_active) VALUES (?, ?, ?, 1)")->execute([$_POST['text_bn'], $_POST['icon'] ?? 'fa-star', $_POST['order_number'] ?? 1]);
    header('Location: landing-manager.php?tab=slogans&msg=স্লোগান+যোগ+হয়েছে'); exit;
}
if(isset($_GET['delete_slogan'])) { $pdo->prepare("DELETE FROM slogans WHERE id=?")->execute([$_GET['delete_slogan']]); header('Location: landing-manager.php?tab=slogans&msg=ডিলিট+হয়েছে'); exit; }
if(isset($_GET['toggle_slogan'])) { $pdo->prepare("UPDATE slogans SET is_active = NOT is_active WHERE id=?")->execute([$_GET['toggle_slogan']]); header('Location: landing-manager.php?tab=slogans'); exit; }

// ==================== ADD REVIEW ====================
if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['add_review'])) {
    $pdo->prepare("INSERT INTO landing_reviews (student_name, student_designation, rating, comment, course_name, student_avatar, is_active) VALUES (?,?,?,?,?,?,1)")->execute([$_POST['student_name'], $_POST['student_designation'] ?? '', $_POST['rating'] ?? 5, $_POST['comment'] ?? '', $_POST['course_name'] ?? '', $_POST['student_avatar'] ?? '']);
    header('Location: landing-manager.php?tab=reviews&msg=রিভিউ+যোগ+হয়েছে'); exit;
}
if(isset($_GET['delete_review'])) { $pdo->prepare("DELETE FROM landing_reviews WHERE id=?")->execute([$_GET['delete_review']]); header('Location: landing-manager.php?tab=reviews&msg=ডিলিট+হয়েছে'); exit; }
if(isset($_GET['toggle_review'])) { $pdo->prepare("UPDATE landing_reviews SET is_active = NOT is_active WHERE id=?")->execute([$_GET['toggle_review']]); header('Location: landing-manager.php?tab=reviews'); exit; }

// ==================== SAVE FEATURED ====================
if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['save_featured'])) {
    $pdo->query("DELETE FROM featured_courses");
    if(isset($_POST['course_ids']) && is_array($_POST['course_ids'])) {
        $st = $pdo->prepare("INSERT INTO featured_courses (course_id, order_number, is_active) VALUES (?, ?, 1)");
        foreach($_POST['course_ids'] as $i => $cid) { $st->execute([$cid, $i+1]); }
    }
    header('Location: landing-manager.php?tab=featured&msg=ফিচার্ড+কোর্স+আপডেট+হয়েছে'); exit;
}

// ==================== GET DATA ====================
$S = []; $res = $pdo->query("SELECT setting_key, setting_value FROM site_settings"); while($r = $res->fetch()) { $S[$r['setting_key']] = $r['setting_value']; }
$slogans = $pdo->query("SELECT * FROM slogans ORDER BY order_number")->fetchAll();
$reviews = $pdo->query("SELECT * FROM landing_reviews ORDER BY order_number")->fetchAll();
$all_courses = $pdo->query("SELECT id, title_bn, price FROM courses WHERE status='published' ORDER BY title_bn")->fetchAll();
$featured_ids = $pdo->query("SELECT course_id FROM featured_courses WHERE is_active=1")->fetchAll(PDO::FETCH_COLUMN);
$categories = $pdo->query("SELECT * FROM categories ORDER BY name_bn")->fetchAll();

// Defaults
$pc = $S['primary_color'] ?? '#6C5CE7';
?>
<!DOCTYPE html>
<html lang="bn"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>ল্যান্ডিং পেজ ম্যানেজার - অ্যাডমিন</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?>,<?=$pc?>dd);--shadow:0 4px 20px rgba(0,0,0,.06)}
body{background:#f0f2f8;font-family:'Segoe UI','Hind Siliguri',Arial,sans-serif}
.navbar{background:white;box-shadow:0 2px 10px rgba(0,0,0,.06);padding:12px 0;position:sticky;top:0;z-index:100}
.container{max-width:1200px;margin:0 auto;padding:20px}
.page-header{background:var(--g1);color:white;border-radius:20px;padding:25px 30px;margin-bottom:25px;display:flex;justify-content:space-between;align-items:center;flex-wrap:wrap;gap:15px}
.page-header h4{font-weight:700;margin:0}.page-header p{opacity:.85;margin:5px 0 0;font-size:.9rem}
.nav-pills{gap:5px;margin-bottom:25px;flex-wrap:wrap}
.nav-pills .nav-link{border-radius:50px;padding:9px 20px;font-weight:600;font-size:.83rem;border:2px solid #e0e0e0;color:#555;transition:all .3s;background:white}
.nav-pills .nav-link:hover{border-color:var(--primary);color:var(--primary)}
.nav-pills .nav-link.active{background:var(--g1);color:white;border-color:transparent;box-shadow:0 4px 15px rgba(108,92,231,.25)}
.nav-pills .nav-link i{margin-right:5px}
.card{background:white;border-radius:18px;padding:28px;box-shadow:var(--shadow);margin-bottom:22px;transition:.3s}
.card:hover{box-shadow:0 8px 30px rgba(0,0,0,.08)}
.section-title{font-weight:700;font-size:1.1rem;color:var(--primary);margin-bottom:20px;display:flex;align-items:center;gap:8px;padding-bottom:10px;border-bottom:2px solid #f0f0f0}
label{font-weight:600;font-size:.83rem;display:block;margin-bottom:5px;color:#444}
input,textarea,select{width:100%;padding:10px 14px;border:2px solid #e8eaef;border-radius:10px;margin-bottom:10px;font-size:.9rem;background:#fafbfd;transition:all .3s;font-family:inherit}
input:focus,textarea:focus,select:focus{outline:none;border-color:var(--primary);box-shadow:0 0 0 3px rgba(108,92,231,.06);background:white}
.btn{border-radius:50px;padding:10px 24px;font-weight:600;cursor:pointer;border:none;transition:all .3s;font-size:.88rem;display:inline-flex;align-items:center;gap:6px}
.btn-primary{background:var(--g1);color:white}.btn-primary:hover{transform:translateY(-2px);box-shadow:0 8px 20px rgba(108,92,231,.3)}
.btn-success{background:#28a745;color:white}.btn-danger{background:#ff4757;color:white}.btn-warning{background:#ffc107;color:#333}.btn-info{background:#17a2b8;color:white}
.btn-sm{padding:6px 14px;font-size:.78rem}.btn-xs{padding:4px 10px;font-size:.7rem}.btn-outline{border:2px solid var(--primary);color:var(--primary);background:white}
.alert{border-radius:12px;padding:14px 18px;margin-bottom:18px;font-weight:500}
.alert-success{background:#eaffea;color:#2d7d46;border:1px solid #b7ebc5}
.color-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(260px,1fr));gap:12px}
.color-item{background:#f8f9fa;border-radius:12px;padding:16px;border:1px solid #e0e0e0;transition:.3s}
.color-item:hover{border-color:var(--primary)}
.color-preview{width:100%;height:35px;border-radius:8px;margin-bottom:8px;border:2px solid #ddd}
.color-input-row{display:flex;align-items:center;gap:8px}
.color-input-row input[type="color"]{width:45px;height:35px;padding:2px;border-radius:8px;cursor:pointer;margin-bottom:0}
.color-input-row input[type="text"]{flex:1;margin-bottom:0;font-size:.8rem}
.live-preview{border:2px solid #e0e0e0;border-radius:16px;overflow:hidden;margin-top:20px}
.preview-navbar{padding:14px 20px;display:flex;justify-content:space-between;align-items:center;font-size:.9rem}
.preview-hero{padding:50px 20px;text-align:center}
.preview-body{padding:30px 20px;text-align:center}
.preview-footer{padding:25px 20px;text-align:center;font-size:.85rem}
.item-row{display:flex;justify-content:space-between;align-items:center;padding:12px 16px;border:1px solid #e8eaef;border-radius:10px;margin-bottom:6px;transition:.3s}
.item-row:hover{background:#f8f9ff;border-color:var(--primary)}
.item-row.inactive{opacity:.5}
.badge-status{padding:4px 10px;border-radius:20px;font-size:.7rem;font-weight:600}
.stats-mini{display:grid;grid-template-columns:repeat(auto-fit,minmax(120px,1fr));gap:10px;margin-bottom:20px}
.stat-mini{background:white;border-radius:14px;padding:18px;text-align:center;box-shadow:0 2px 8px rgba(0,0,0,.03)}
.stat-mini h4{font-weight:800;font-size:1.4rem;margin:0}
.stat-mini small{color:#888;font-size:.75rem}
@media(max-width:768px){.page-header{text-align:center;justify-content:center}.color-grid{grid-template-columns:1fr}}
</style>
</head>
<body>

<nav class="navbar"><div class="container" style="display:flex;justify-content:space-between;align-items:center">
    <a href="dashboard.php" style="font-weight:700;color:var(--primary);text-decoration:none;font-size:1.1rem"><i class="fas fa-graduation-cap me-2"></i>অ্যাডমিন প্যানেল</a>
    <div class="d-flex gap-2">
        <a href="../index.php" target="_blank" class="btn btn-outline btn-sm">👁️ সাইট দেখুন</a>
        <a href="../logout.php" class="btn btn-sm" style="background:#ff4757;color:white">লগআউট</a>
    </div>
</div></nav>

<div class="container">
    
    <div class="page-header"><div><h4><i class="fas fa-paint-brush me-2"></i>ল্যান্ডিং পেজ ম্যানেজার</h4><p>হোমপেজের সকল সেকশন, কালার ও কন্টেন্ট এখান থেকে নিয়ন্ত্রণ করুন</p></div></div>
    
    <?php if($msg):?><div class="alert alert-<?=$msg_type?>"><i class="fas fa-check-circle me-2"></i><?=htmlspecialchars($msg)?></div><?php endif;?>
    
    <!-- Stats -->
    <div class="stats-mini">
        <div class="stat-mini"><h4 style="color:<?=$pc?>"><?=count($slogans)?></h4><small>স্লোগান</small></div>
        <div class="stat-mini"><h4 style="color:#f5576c"><?=count($reviews)?></h4><small>রিভিউ</small></div>
        <div class="stat-mini"><h4 style="color:#ffc107"><?=count($featured_ids)?></h4><small>ফিচার্ড</small></div>
        <div class="stat-mini"><h4 style="color:#4facfe"><?=count($categories)?></h4><small>ক্যাটাগরি</small></div>
    </div>
    
    <!-- Tabs -->
    <ul class="nav nav-pills">
        <li><a class="nav-link <?=$tab=='overview'?'active':''?>" href="?tab=overview"><i class="fas fa-home"></i> ওভারভিউ</a></li>
        <li><a class="nav-link <?=$tab=='colors'?'active':''?>" href="?tab=colors"><i class="fas fa-palette"></i> কালার</a></li>
        <li><a class="nav-link <?=$tab=='hero'?'active':''?>" href="?tab=hero"><i class="fas fa-image"></i> হিরো</a></li>
        <li><a class="nav-link <?=$tab=='branding'?'active':''?>" href="?tab=branding"><i class="fas fa-building"></i> ব্র্যান্ডিং</a></li>
        <li><a class="nav-link <?=$tab=='slogans'?'active':''?>" href="?tab=slogans"><i class="fas fa-chart-bar"></i> স্লোগান</a></li>
        <li><a class="nav-link <?=$tab=='reviews'?'active':''?>" href="?tab=reviews"><i class="fas fa-star"></i> রিভিউ</a></li>
        <li><a class="nav-link <?=$tab=='featured'?'active':''?>" href="?tab=featured"><i class="fas fa-star text-warning"></i> ফিচার্ড</a></li>
    </ul>
    
    <!-- OVERVIEW TAB -->
    <?php if($tab == 'overview'):?>
    <div class="row g-3">
        <div class="col-md-4"><div class="card text-center"><i class="fas fa-palette fa-3x mb-3" style="color:<?=$pc?>"></i><h5>কালার সেটিংস</h5><p class="text-muted small">সাইটের সকল রং পরিবর্তন করুন</p><a href="?tab=colors" class="btn btn-primary btn-sm">ম্যানেজ করুন</a></div></div>
        <div class="col-md-4"><div class="card text-center"><i class="fas fa-image fa-3x mb-3" style="color:#f5576c"></i><h5>হিরো সেকশন</h5><p class="text-muted small">হোমপেজের উপরের অংশ</p><a href="?tab=hero" class="btn btn-primary btn-sm">ম্যানেজ করুন</a></div></div>
        <div class="col-md-4"><div class="card text-center"><i class="fas fa-building fa-3x mb-3" style="color:#4facfe"></i><h5>ব্র্যান্ডিং</h5><p class="text-muted small">লোগো, নাম, সোশ্যাল লিংক</p><a href="?tab=branding" class="btn btn-primary btn-sm">ম্যানেজ করুন</a></div></div>
        <div class="col-md-4"><div class="card text-center"><i class="fas fa-chart-bar fa-3x mb-3" style="color:#43e97b"></i><h5>স্লোগান</h5><p class="text-muted small"><?=count($slogans)?> টি স্লোগান</p><a href="?tab=slogans" class="btn btn-primary btn-sm">ম্যানেজ করুন</a></div></div>
        <div class="col-md-4"><div class="card text-center"><i class="fas fa-star fa-3x mb-3" style="color:#ffc107"></i><h5>রিভিউ</h5><p class="text-muted small"><?=count($reviews)?> টি রিভিউ</p><a href="?tab=reviews" class="btn btn-primary btn-sm">ম্যানেজ করুন</a></div></div>
        <div class="col-md-4"><div class="card text-center"><i class="fas fa-star fa-3x mb-3" style="color:#ffc107"></i><h5>ফিচার্ড কোর্স</h5><p class="text-muted small"><?=count($featured_ids)?> টি কোর্স</p><a href="?tab=featured" class="btn btn-primary btn-sm">ম্যানেজ করুন</a></div></div>
    </div>
    <?php endif;?>
    
    <!-- COLORS TAB -->
    <?php if($tab == 'colors'):?>
    <div class="card"><div class="section-title"><i class="fas fa-palette"></i> সাইটের সকল কালার কাস্টমাইজ করুন</div>
    <p class="text-muted mb-3">প্রতিটি সেকশনের জন্য আলাদা কালার সেট করুন। নিচের প্রিভিউতে তাৎক্ষণিক পরিবর্তন দেখতে পাবেন।</p>
    <form method="POST"><input type="hidden" name="save_colors" value="1">
        <div class="color-grid">
            <?php
            $colorFields = [
                ['primary_color','🎨 প্রাইমারি কালার','বাটন, লিংক, হাইলাইট'],
                ['hero_bg_color','🦸 হিরো BG (প্রথম)','হিরো সেকশন ব্যাকগ্রাউন্ড ১'],
                ['hero_bg_color2','🦸 হিরো BG (দ্বিতীয়)','হিরো গ্রেডিয়েন্ট ২'],
                ['hero_title_color','🦸 হিরো টাইটেল','হিরো হেডিং টেক্সট'],
                ['hero_subtitle_color','🦸 হিরো সাবটাইটেল','হিরো প্যারাগ্রাফ টেক্সট'],
                ['navbar_bg_color','📱 ন্যাভবার BG','ন্যাভবার ব্যাকগ্রাউন্ড'],
                ['navbar_text_color','📱 ন্যাভবার টেক্সট','ন্যাভবার লিংক কালার'],
                ['body_bg_color','📄 বডি BG','পেজ ব্যাকগ্রাউন্ড'],
                ['heading_color','📝 হেডিং টেক্সট','সকল সেকশন টাইটেল'],
                ['text_color','📝 সাধারণ টেক্সট','বডি টেক্সট কালার'],
                ['muted_text_color','📝 মিউটেড টেক্সট','ছোট/হালকা টেক্সট'],
                ['card_bg_color','🗂️ কার্ড BG','কার্ড ব্যাকগ্রাউন্ড'],
                ['card_text_color','🗂️ কার্ড টেক্সট','কার্ডের ভিতরের টেক্সট'],
                ['link_color','🔗 লিংক','সকল লিংক'],
                ['link_hover_color','🔗 লিংক হোভার','লিংকে মাউস নিলে'],
                ['badge_bg_color','🏷️ ব্যাজ BG','ব্যাজ ব্যাকগ্রাউন্ড'],
                ['badge_text_color','🏷️ ব্যাজ টেক্সট','ব্যাজ টেক্সট'],
                ['button_color','🔘 বাটন BG','হিরো বাটন ব্যাকগ্রাউন্ড'],
                ['button_text_color','🔘 বাটন টেক্সট','হিরো বাটন টেক্সট'],
                ['footer_bg_color','📄 ফুটার BG','ফুটার ব্যাকগ্রাউন্ড'],
                ['footer_text_color','📄 ফুটার টেক্সট','ফুটার টেক্সট'],
                ['stats_bg_color','📊 স্ট্যাটস BG','স্ট্যাটস বার ব্যাকগ্রাউন্ড'],
                ['stats_text_color','📊 স্ট্যাটস টেক্সট','স্ট্যাটস বার টেক্সট'],
            ];
            foreach($colorFields as $cf):
                $val = $S[$cf[0]] ?? '#888888';
            ?>
            <div class="color-item">
                <label><?=$cf[1]?></label>
                <small class="text-muted d-block mb-1"><?=$cf[2]?></small>
                <div class="color-preview" style="background:<?=$val?>"></div>
                <div class="color-input-row">
                    <input type="color" name="<?=$cf[0]?>" value="<?=$val?>" onchange="this.parentElement.parentElement.querySelector('.color-preview').style.background=this.value">
                    <input type="text" value="<?=$val?>" readonly>
                </div>
            </div>
            <?php endforeach;?>
        </div>
        <button type="submit" class="btn btn-primary btn-lg w-100 mt-3"><i class="fas fa-save me-2"></i>সকল কালার সংরক্ষণ করুন</button>
    </form>
    </div>
    <?php endif;?>
    
    <!-- HERO TAB -->
    <?php if($tab == 'hero'):?>
    <div class="card"><div class="section-title"><i class="fas fa-image"></i> হিরো সেকশন সেটিংস</div>
    <form method="POST"><input type="hidden" name="save_hero" value="1">
        <div class="row"><div class="col-md-12"><label>হিরো টাইটেল (br দিলে লাইন ব্রেক হবে)</label><textarea name="hero_title" rows="2"><?=htmlspecialchars($S['hero_title']??'')?></textarea></div></div>
        <div class="row"><div class="col-md-12"><label>হিরো সাব-টাইটেল</label><textarea name="hero_subtitle" rows="2"><?=htmlspecialchars($S['hero_subtitle']??'')?></textarea></div></div>
        <label>সাইট সাব-টাইটেল (হিরোতে ব্যাজ আকারে দেখায়)</label><input type="text" name="site_subtitle" value="<?=htmlspecialchars($S['site_subtitle']??'')?>">
        <div class="row"><div class="col-md-6"><label>প্রথম বাটন টেক্সট</label><input type="text" name="hero_button_text" value="<?=htmlspecialchars($S['hero_button_text']??'')?>"></div><div class="col-md-6"><label>প্রথম বাটন URL</label><input type="text" name="hero_button_url" value="<?=htmlspecialchars($S['hero_button_url']??'')?>"></div></div>
        <div class="row"><div class="col-md-6"><label>দ্বিতীয় বাটন টেক্সট (খালি রাখলে দেখাবে না)</label><input type="text" name="hero_second_button_text" value="<?=htmlspecialchars($S['hero_second_button_text']??'')?>"></div><div class="col-md-6"><label>দ্বিতীয় বাটন URL</label><input type="text" name="hero_second_button_url" value="<?=htmlspecialchars($S['hero_second_button_url']??'')?>"></div></div>
        <button type="submit" class="btn btn-primary mt-3"><i class="fas fa-save me-1"></i> হিরো সংরক্ষণ</button>
    </form></div>
    <?php endif;?>
    
    <!-- BRANDING TAB -->
    <?php if($tab == 'branding'):?>
    <div class="card"><div class="section-title"><i class="fas fa-building"></i> ব্র্যান্ডিং ও কন্টাক্ট তথ্য</div>
    <form method="POST" enctype="multipart/form-data"><input type="hidden" name="save_branding" value="1">
        <div class="row"><div class="col-md-6"><label>সাইট টাইটেল (Browser Tab)</label><input type="text" name="site_title" value="<?=htmlspecialchars($S['site_title']??'')?>"></div><div class="col-md-6"><label>লোগো টেক্সট</label><input type="text" name="logo_text" value="<?=htmlspecialchars($S['logo_text']??'')?>"></div></div>
        <div class="row"><div class="col-md-6"><label>লোগো আইকন (Font Awesome)</label><input type="text" name="logo_icon" value="<?=$S['logo_icon']??'fa-graduation-cap'?>"></div><div class="col-md-6"><label><input type="checkbox" name="use_image_logo" <?=($S['use_image_logo']??'0')=='1'?'checked':''?>> ছবি লোগো ব্যবহার করুন</label></div></div>
        <label>লোগো ছবি আপলোড</label><input type="file" name="logo_image" accept="image/*">
        <?php if(!empty($S['logo_image'])):?><small>বর্তমান: <?=$S['logo_image']?></small><?php endif;?>
        <label>ফুটার টেক্সট</label><input type="text" name="footer_text" value="<?=htmlspecialchars($S['footer_text']??'')?>">
        <hr><h6 class="fw-bold mb-2">📞 যোগাযোগ</h6>
        <div class="row"><div class="col-md-6"><label>ফোন</label><input type="text" name="phone1" value="<?=htmlspecialchars($S['phone1']??'')?>"></div><div class="col-md-6"><label>ইমেইল</label><input type="text" name="email1" value="<?=htmlspecialchars($S['email1']??'')?>"></div></div>
        <h6 class="fw-bold mb-2 mt-2">🔗 সোশ্যাল মিডিয়া</h6>
        <div class="row"><div class="col-md-6"><label>Facebook URL</label><input type="text" name="facebook_url" value="<?=htmlspecialchars($S['facebook_url']??'')?>"></div><div class="col-md-6"><label>YouTube URL</label><input type="text" name="youtube_url" value="<?=htmlspecialchars($S['youtube_url']??'')?>"></div></div>
        <div class="row"><div class="col-md-6"><label>Instagram URL</label><input type="text" name="instagram_url" value="<?=htmlspecialchars($S['instagram_url']??'')?>"></div><div class="col-md-6"><label>LinkedIn URL</label><input type="text" name="linkedin_url" value="<?=htmlspecialchars($S['linkedin_url']??'')?>"></div></div>
        <div class="row"><div class="col-md-6"><label>WhatsApp Number</label><input type="text" name="whatsapp_number" value="<?=htmlspecialchars($S['whatsapp_number']??'')?>" placeholder="8801700000000"></div><div class="col-md-6"><label>সাইট ডেসক্রিপশন</label><input type="text" name="site_description" value="<?=htmlspecialchars($S['site_description']??'')?>"></div></div>
        <button type="submit" class="btn btn-primary mt-3"><i class="fas fa-save me-1"></i> ব্র্যান্ডিং সংরক্ষণ</button>
    </form></div>
    <?php endif;?>
    
    <!-- SLOGANS TAB -->
    <?php if($tab == 'slogans'):?>
    <div class="row"><div class="col-md-5"><div class="card"><div class="section-title"><i class="fas fa-plus-circle"></i> নতুন স্লোগান</div>
    <form method="POST"><input type="hidden" name="add_slogan" value="1"><label>স্লোগান টেক্সট</label><input type="text" name="text_bn" required placeholder="যেমন: ১০,০০০+ শিক্ষার্থী"><label>আইকন (Font Awesome)</label><input type="text" name="icon" value="fa-star"><label>ক্রমিক নম্বর</label><input type="number" name="order_number" value="1"><button type="submit" class="btn btn-primary w-100 mt-2"><i class="fas fa-plus me-1"></i> স্লোগান যোগ করুন</button></form></div></div>
    <div class="col-md-7"><div class="card"><div class="section-title"><i class="fas fa-list"></i> স্লোগান তালিকা (<?=count($slogans)?>)</div>
    <?php foreach($slogans as $sl):?>
    <div class="item-row <?=!$sl['is_active']?'inactive':''?>"><div><i class="fas <?=$sl['icon']?> me-2" style="color:<?=$pc?>"></i><strong><?=htmlspecialchars($sl['text_bn'])?></strong></div><div class="d-flex gap-1"><span class="badge-status bg-<?=$sl['is_active']?'success':'secondary'?>"><?=$sl['is_active']?'সক্রিয়':'নিষ্ক্রিয়'?></span><a href="?toggle_slogan=<?=$sl['id']?>&tab=slogans" class="btn btn-info btn-xs"><i class="fas fa-sync-alt"></i></a><a href="?delete_slogan=<?=$sl['id']?>&tab=slogans" class="btn btn-danger btn-xs" onclick="return confirm('ডিলিট করবেন?')"><i class="fas fa-trash"></i></a></div></div>
    <?php endforeach;?></div></div></div>
    <?php endif;?>
    
    <!-- REVIEWS TAB -->
    <?php if($tab == 'reviews'):?>
    <div class="row"><div class="col-md-5"><div class="card"><div class="section-title"><i class="fas fa-plus-circle"></i> নতুন রিভিউ</div>
    <form method="POST"><input type="hidden" name="add_review" value="1"><label>নাম *</label><input type="text" name="student_name" required><label>পদবি</label><input type="text" name="student_designation" placeholder="যেমন: ওয়েব ডেভেলপার"><label>রেটিং (১-৫)</label><input type="number" name="rating" value="5" min="1" max="5"><label>মতামত</label><textarea name="comment" rows="2" placeholder="শিক্ষার্থীর মতামত লিখুন..."></textarea><label>কোর্সের নাম</label><input type="text" name="course_name"><label>অ্যাভাটার URL (ঐচ্ছিক)</label><input type="text" name="student_avatar" placeholder="https://..."><button type="submit" class="btn btn-primary w-100 mt-2"><i class="fas fa-plus me-1"></i> রিভিউ যোগ করুন</button></form></div></div>
    <div class="col-md-7"><div class="card"><div class="section-title"><i class="fas fa-list"></i> রিভিউ তালিকা (<?=count($reviews)?>)</div>
    <?php foreach($reviews as $rv):?>
    <div class="item-row <?=!$rv['is_active']?'inactive':''?>"><div><strong><?=htmlspecialchars($rv['student_name'])?></strong> <span style="color:#ffc107"><?=str_repeat('★',$rv['rating'])?></span><br><small class="text-muted"><?=htmlspecialchars(mb_substr($rv['comment'],0,50))?>...</small></div><div class="d-flex gap-1"><span class="badge-status bg-<?=$rv['is_active']?'success':'secondary'?>"><?=$rv['is_active']?'সক্রিয়':'নিষ্ক্রিয়'?></span><a href="?toggle_review=<?=$rv['id']?>&tab=reviews" class="btn btn-info btn-xs"><i class="fas fa-sync-alt"></i></a><a href="?delete_review=<?=$rv['id']?>&tab=reviews" class="btn btn-danger btn-xs" onclick="return confirm('ডিলিট করবেন?')"><i class="fas fa-trash"></i></a></div></div>
    <?php endforeach;?></div></div></div>
    <?php endif;?>
    
    <!-- FEATURED TAB -->
    <?php if($tab == 'featured'):?>
    <div class="card"><div class="section-title"><i class="fas fa-star text-warning"></i> ফিচার্ড কোর্স সিলেক্ট করুন (হোমপেজের "সেরা কোর্স" সেকশন)</div>
    <p class="text-muted mb-3">যে কোর্সগুলো হোমপেজে দেখাতে চান সেগুলো সিলেক্ট করুন। সিলেক্টেড: <strong><?=count($featured_ids)?></strong> টি</p>
    <form method="POST"><input type="hidden" name="save_featured" value="1">
        <div class="row g-2"><?php foreach($all_courses as $c): $checked=in_array($c['id'],$featured_ids);?>
            <div class="col-md-6 col-lg-4"><div class="p-3 rounded-3" style="background:<?=$checked?'#fffef5':'white'?>;border:2px solid <?=$checked?'#ffc107':'#e0e0e0'?>;cursor:pointer;transition:.3s" onclick="var cb=this.querySelector('input');cb.checked=!cb.checked;this.style.background=cb.checked?'#fffef5':'white';this.style.borderColor=cb.checked?'#ffc107':'#e0e0e0'">
                <div class="form-check"><input class="form-check-input" type="checkbox" name="course_ids[]" value="<?=$c['id']?>" <?=$checked?'checked':''?> style="pointer-events:none"><label class="form-check-label fw-bold" style="pointer-events:none"><?=htmlspecialchars(mb_substr($c['title_bn'],0,40))?></label></div>
                <small class="text-muted ms-4">৳<?=number_format($c['price'])?></small>
                <?php if($checked):?><i class="fas fa-star text-warning position-absolute" style="top:10px;right:15px"></i><?php endif;?>
            </div></div>
        <?php endforeach;?></div>
        <button type="submit" class="btn btn-primary btn-lg w-100 mt-3"><i class="fas fa-save me-2"></i>ফিচার্ড কোর্স সেভ করুন</button>
    </form></div>
    <?php endif;?>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>