<?php
// =========================================================
// SINGLE BLOG POST - MODERN VERSION
// =========================================================
if (session_status() === PHP_SESSION_NONE) session_start();
require_once 'config.php';

// =========================================================
// GET POST ID
// =========================================================
$post_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
if (!$post_id) {
    header('Location: blog.php');
    exit;
}

// =========================================================
// FETCH POST DATA
// =========================================================
$post = $conn->query("SELECT p.*, c.name as category_name, c.slug as category_slug
                      FROM blog_posts p
                      LEFT JOIN blog_categories c ON p.category_id = c.id
                      WHERE p.id = $post_id AND p.status = 'published'")->fetch_assoc();

if (!$post) {
    header('Location: blog.php');
    exit;
}

// =========================================================
// UPDATE VIEWS
// =========================================================
$conn->query("UPDATE blog_posts SET views = views + 1 WHERE id = $post_id");

// =========================================================
// FETCH COMMENTS (if table exists)
// =========================================================
$comments = [];
$comment_count = 0;
$table_check = $conn->query("SHOW TABLES LIKE 'blog_comments'");
if ($table_check && $table_check->num_rows > 0) {
    $comments = $conn->query("SELECT * FROM blog_comments WHERE post_id = $post_id AND status = 'approved' ORDER BY created_at DESC");
    $comment_count = $comments ? $comments->num_rows : 0;
}

// =========================================================
// FETCH RELATED POSTS
// =========================================================
$related = $conn->query("SELECT id, title, slug, image, created_at 
                         FROM blog_posts 
                         WHERE status = 'published' 
                         AND category_id = {$post['category_id']} 
                         AND id != $post_id 
                         ORDER BY RAND() LIMIT 3");

// =========================================================
// GET BRAND INFO
// =========================================================
$brand = getBrand();
$whatsapp_number = $brand['whatsapp'] ?? '01775121112';
$cartCount = function_exists('getCartCount') ? getCartCount(session_id()) : 0;

// =========================================================
// SEO META TAGS
// =========================================================
$meta_title = $post['meta_title'] ?: $post['title'];
$meta_description = $post['meta_description'] ?: substr(strip_tags($post['excerpt'] ?: $post['content']), 0, 160);
$meta_keywords = $post['meta_keywords'] ?: 'homeopathy, health, blog';
$og_image = $post['image'] ?: ($brand['logo'] ?: 'https://drmdferdous.com/assets/default-blog.jpg');
$og_url = 'https://drmdferdous.com/single_post.php?id=' . $post_id;

// =========================================================
// EXTRA DATA FOR SHARING
// =========================================================
$share_text = urlencode($post['title']);
$share_url = urlencode($og_url);
?>
<!DOCTYPE html>
<html lang="bn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
    <title><?= htmlspecialchars($meta_title) ?> | <?= htmlspecialchars($brand['name'] ?? 'ওয়ান হোমিওপ্যাথি') ?></title>
    <meta name="description" content="<?= htmlspecialchars($meta_description) ?>">
    <meta name="keywords" content="<?= htmlspecialchars($meta_keywords) ?>">
    <meta name="theme-color" content="#2d6a4f">
    <link rel="icon" href="<?= !empty($brand['logo']) ? $brand['logo'] : 'data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🏥</text></svg>' ?>">
    
    <!-- Open Graph -->
    <meta property="og:title" content="<?= htmlspecialchars($meta_title) ?>" />
    <meta property="og:description" content="<?= htmlspecialchars($meta_description) ?>" />
    <meta property="og:image" content="<?= htmlspecialchars($og_image) ?>" />
    <meta property="og:url" content="<?= htmlspecialchars($og_url) ?>" />
    <meta property="og:type" content="article" />
    <meta name="twitter:card" content="summary_large_image" />
    
    <!-- CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    
    <style>
        :root{--p:#2d6a4f;--pd:#1b4332}
        *{margin:0;padding:0;box-sizing:border-box}
        body{font-family:'Segoe UI','Hind Siliguri',sans-serif;background:#f0f2f5;color:#1a1a2e;overflow-x:hidden}
        
        /* NAVBAR - Same as index */
        #navbar{background:var(--p)!important;padding:12px 0;transition:.3s;z-index:1000;box-shadow:0 2px 15px rgba(0,0,0,.1);position:fixed;top:0;left:0;right:0}
        #navbar.scrolled{background:var(--pd)!important;padding:8px 0}
        .navbar-brand{color:#fff!important;font-weight:700;font-size:clamp(1rem,4vw,1.2rem);display:flex;align-items:center;gap:8px}
        .nav-logo{height:clamp(30px,5vw,38px);border-radius:50%;border:2px solid rgba(255,255,255,.3);object-fit:cover}
        .nav-link{color:rgba(255,255,255,.9)!important;font-weight:500;padding:8px 12px!important;transition:.2s}
        .nav-link:hover{color:#fff!important;transform:translateY(-2px)}
        
        .login-nav{background:#fff;padding:8px 0;position:fixed;top:60px;left:0;right:0;z-index:999;border-bottom:2px solid #eee;display:flex;justify-content:center;gap:clamp(5px,2vw,15px);flex-wrap:wrap;box-shadow:0 2px 5px rgba(0,0,0,.05)}
        .login-nav a{padding:clamp(5px,2vw,10px) clamp(10px,3vw,20px);border-radius:30px;font-size:clamp(.7rem,2.5vw,.85rem);font-weight:600;text-decoration:none;transition:.2s}
        .login-nav a:hover{transform:translateY(-2px)}
        .btn-login-admin{background:#dc3545;color:#fff}
        .btn-login-patient{background:#007bff;color:#fff}
        .btn-login-student{background:#17a2b8;color:#fff}
        .btn-login-doctor{background:#28a745;color:#fff}
        
        /* HERO */
        .post-hero{background:linear-gradient(135deg,var(--p),var(--pd));color:#fff;padding:160px 0 60px;margin-top:70px;position:relative;overflow:hidden}
        .post-hero::before{content:'';position:absolute;top:0;left:0;right:0;bottom:0;background:url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1440 320"><path fill="rgba(255,255,255,0.05)" d="M0,96L48,112C96,128,192,160,288,160C384,160,480,128,576,122.7C672,117,768,139,864,154.7C960,171,1056,181,1152,165.3C1248,149,1344,107,1392,85.3L1440,64L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z"></path></svg>') no-repeat bottom;background-size:cover}
        .post-hero h1{font-size:clamp(1.8rem,5vw,2.8rem);font-weight:800;position:relative;z-index:1}
        .post-meta{display:flex;flex-wrap:wrap;gap:15px;position:relative;z-index:1;margin-top:20px}
        .post-meta span{opacity:.8;font-size:.9rem}
        .post-meta i{margin-right:5px}
        
        /* CONTENT */
        .post-content{background:#fff;border-radius:20px;padding:40px;box-shadow:0 5px 20px rgba(0,0,0,.08);margin-top:-30px;position:relative;z-index:2}
        .post-content img{max-width:100%;height:auto;border-radius:12px;margin:25px 0}
        .post-content h2,.post-content h3{margin-top:30px;color:var(--p)}
        .post-content p{line-height:1.8;font-size:1.05rem}
        .post-content ul,.post-content ol{margin:15px 0;padding-left:25px}
        .post-content blockquote{background:#f8faf9;border-left:4px solid var(--p);padding:15px 20px;margin:20px 0;border-radius:0 10px 10px 0}
        
        /* FEATURED IMAGE */
        .featured-image{width:100%;border-radius:15px;margin-bottom:30px;max-height:500px;object-fit:cover}
        
        /* SHARE BUTTONS */
        .share-section{background:#f8faf9;border-radius:15px;padding:20px;margin:30px 0;display:flex;flex-wrap:wrap;gap:12px;align-items:center}
        .share-section .share-label{font-weight:700;color:#2c3e50}
        .share-btn{display:inline-flex;align-items:center;gap:8px;padding:8px 18px;border-radius:25px;color:#fff;text-decoration:none;transition:all .3s;font-size:.9rem}
        .share-btn:hover{transform:translateY(-3px);color:#fff}
        .share-fb{background:#1877f2}.share-fb:hover{background:#1664d9}
        .share-wa{background:#25D366}.share-wa:hover{background:#20b85b}
        .share-tw{background:#000}.share-tw:hover{background:#222}
        .share-li{background:#0077b5}.share-li:hover{background:#006396}
        .share-copy{background:#6c757d}.share-copy:hover{background:#5a6268}
        
        /* TAGS */
        .tags-section{display:flex;flex-wrap:wrap;gap:8px;margin:20px 0}
        .tag{background:#e8f5e9;color:#2d6a4f;padding:5px 15px;border-radius:20px;font-size:.8rem;text-decoration:none;transition:.3s}
        .tag:hover{background:#2d6a4f;color:#fff}
        
        /* AUTHOR BIO */
        .author-bio{background:#f8faf9;border-radius:15px;padding:25px;margin:30px 0;display:flex;align-items:center;gap:20px;flex-wrap:wrap}
        .author-avatar{width:70px;height:70px;border-radius:50%;background:var(--p);color:#fff;display:flex;align-items:center;justify-content:center;font-size:2rem;font-weight:700}
        .author-info h5{margin-bottom:5px}
        .author-info p{font-size:.9rem;color:#6c757d;margin-bottom:0}
        
        /* COMMENTS */
        .comments-section{background:#fff;border-radius:20px;padding:30px;box-shadow:0 5px 20px rgba(0,0,0,.08);margin-top:30px}
        .comment-item{display:flex;gap:15px;padding:15px 0;border-bottom:1px solid #eee}
        .comment-avatar{width:45px;height:45px;border-radius:50%;background:var(--p);color:#fff;display:flex;align-items:center;justify-content:center;font-weight:700;flex-shrink:0}
        .comment-body h6{margin-bottom:2px}
        .comment-body .comment-date{font-size:.75rem;color:#6c757d}
        .comment-body p{margin-top:5px;font-size:.95rem}
        
        /* COMMENT FORM */
        .comment-form textarea{resize:vertical;min-height:100px}
        .comment-form .btn-submit{background:var(--p);color:#fff;border:none;border-radius:30px;padding:10px 30px;font-weight:600;transition:.3s}
        .comment-form .btn-submit:hover{background:var(--pd);transform:translateY(-2px)}
        
        /* RELATED POSTS */
        .related-card{border:none;border-radius:15px;overflow:hidden;box-shadow:0 3px 15px rgba(0,0,0,.08);transition:.3s;height:100%}
        .related-card:hover{transform:translateY(-8px);box-shadow:0 15px 30px rgba(0,0,0,.15)}
        .related-card img{height:180px;object-fit:cover;width:100%}
        .related-card .card-body{padding:18px}
        .related-card .card-title{font-size:1rem;font-weight:600}
        .related-card .card-title a{color:#1a1a2e;text-decoration:none}
        .related-card .card-title a:hover{color:var(--p)}
        
        /* WHATSAPP FLOAT */
        .wa-float{position:fixed;bottom:30px;right:30px;width:60px;height:60px;background:#25D366;border-radius:50%;display:flex;align-items:center;justify-content:center;font-size:32px;color:#fff;z-index:999;box-shadow:0 4px 15px rgba(37,211,102,.3);transition:.3s;animation:waPulse 2s infinite;text-decoration:none}
        .wa-float:hover{transform:scale(1.1);animation:none;box-shadow:0 8px 25px rgba(37,211,102,.5)}
        @keyframes waPulse{0%{transform:scale(1);box-shadow:0 4px 15px rgba(37,211,102,.3)}50%{transform:scale(1.08);box-shadow:0 8px 30px rgba(37,211,102,.5)}100%{transform:scale(1);box-shadow:0 4px 15px rgba(37,211,102,.3)}}
        
        /* BACK TO TOP */
        .back-to-top{position:fixed;bottom:20px;right:100px;width:45px;height:45px;background:var(--p);color:#fff;border-radius:50%;display:flex;align-items:center;justify-content:center;cursor:pointer;z-index:999;transition:.3s;opacity:0;visibility:hidden;text-decoration:none}
        .back-to-top.show{opacity:1;visibility:visible}
        .back-to-top:hover{transform:translateY(-5px)}
        
        footer{background:#0a0a0a;color:#aaa;padding:40px 0 20px;margin-top:50px}
        .dev-credit{display:inline-block;padding:6px 15px;border-radius:25px;background:rgba(82,183,136,.12);color:#52b788;font-weight:600;font-size:.8rem;text-decoration:none}
        
        @media(max-width:768px){.login-nav{top:55px}.post-hero{margin-top:55px;padding:130px 0 40px}.post-content{padding:20px}.post-hero h1{font-size:1.5rem}}
        @media(max-width:576px){.login-nav{top:50px}.post-hero{margin-top:50px}.share-section{flex-direction:column;align-items:stretch}.share-btn{justify-content:center}}
    </style>
</head>
<body>

<!-- NAVBAR -->
<nav class="navbar navbar-expand-lg fixed-top" id="navbar">
    <div class="container">
        <a class="navbar-brand" href="../index.php">
            <?php if(!empty($brand['logo'])): ?>
                <img src="<?= htmlspecialchars($brand['logo']) ?>" alt="Logo" class="nav-logo" loading="lazy">
            <?php else: ?>
                <span style="font-size:1.5rem;">🏥</span>
            <?php endif; ?>
            <?= htmlspecialchars($brand['name'] ?? 'ওয়ান হোমিওপ্যাথি') ?>
        </a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navMenu"><span class="navbar-toggler-icon"></span></button>
        <div class="collapse navbar-collapse" id="navMenu">
            <ul class="navbar-nav ms-auto align-items-lg-center">
                <li class="nav-item"><a class="nav-link" href="../index.php#home">হোম</a></li>
                <li class="nav-item"><a class="nav-link" href="../index.php#doctors">ডাক্তার</a></li>
                <li class="nav-item"><a class="nav-link" href="../index.php#services">সেবা</a></li>
                <li class="nav-item"><a class="nav-link" href="../index.php#products">পণ্য</a></li>
                <li class="nav-item"><a class="nav-link" href="blog.php">ব্লগ</a></li>
                <li class="nav-item"><a class="nav-link" href="../index.php#contact">যোগাযোগ</a></li>
                <li class="nav-item ms-lg-1 mt-2 mt-lg-0">
                    <a href="../cart.php" class="btn btn-warning" style="color:#fff!important; position:relative;">
                        <i class="fas fa-shopping-cart"></i> কার্ট
                        <span id="cartCountBadge" style="position:absolute; top:-8px; right:-8px; background:#dc3545; color:#fff; font-size:0.7rem; width:20px; height:20px; border-radius:50%; display:inline-flex; align-items:center; justify-content:center;"><?= $cartCount ?></span>
                    </a>
                </li>
            </ul>
        </div>
    </div>
</nav>

<!-- LOGIN NAV -->
<div class="login-nav">
    <a href="../admin.php" class="btn-login-admin"><i class="fas fa-user-shield"></i> অ্যাডমিন</a>
    <a href="../opd/" class="btn-login-patient"><i class="fas fa-user-injured"></i> রোগী</a>
    <a href="../lms/" class="btn-login-student"><i class="fas fa-user-graduate"></i> শিক্ষার্থী</a>
    <a href="../doctor.php" class="btn-login-doctor"><i class="fas fa-user-md"></i> ডাক্তার</a>
</div>

<!-- POST HERO -->
<div class="post-hero">
    <div class="container text-center">
        <h1><?= htmlspecialchars($post['title']) ?></h1>
        <div class="post-meta justify-content-center">
            <span><i class="far fa-user"></i> <?= htmlspecialchars($post['author'] ?? 'Admin') ?></span>
            <span><i class="far fa-calendar"></i> <?= date('d M Y', strtotime($post['published_at'])) ?></span>
            <span><i class="far fa-eye"></i> <?= number_format($post['views'] ?? 0) ?> বার দেখা</span>
            <?php if($post['category_name']): ?>
                <span><i class="far fa-folder"></i> <?= htmlspecialchars($post['category_name']) ?></span>
            <?php endif; ?>
        </div>
    </div>
</div>

<!-- MAIN CONTENT -->
<section class="py-4">
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-lg-8">
                <div class="post-content">
                    <!-- Featured Image -->
                    <?php if($post['image']): ?>
                        <img src="<?= htmlspecialchars($post['image']) ?>" class="featured-image" alt="<?= htmlspecialchars($post['title']) ?>">
                    <?php endif; ?>
                    
                    <!-- Post Body -->
                    <div class="post-body">
                        <?= htmlspecialchars_decode($post['content']) ?>
                    </div>
                    
                    <!-- Tags -->
                    <?php if($post['tags']): ?>
                        <div class="tags-section">
                            <?php foreach(explode(',', $post['tags']) as $tag): ?>
                                <a href="blog.php?tag=<?= urlencode(trim($tag)) ?>" class="tag">#<?= htmlspecialchars(trim($tag)) ?></a>
                            <?php endforeach; ?>
                        </div>
                    <?php endif; ?>
                    
                    <!-- Share Section -->
                    <div class="share-section">
                        <span class="share-label"><i class="fas fa-share-alt"></i> শেয়ার করুন:</span>
                        <a href="https://www.facebook.com/sharer/sharer.php?u=<?= $share_url ?>" target="_blank" class="share-btn share-fb"><i class="fab fa-facebook-f"></i> Facebook</a>
                        <a href="https://wa.me/?text=<?= $share_text ?>%20<?= $share_url ?>" target="_blank" class="share-btn share-wa"><i class="fab fa-whatsapp"></i> WhatsApp</a>
                        <a href="https://twitter.com/intent/tweet?text=<?= $share_text ?>&url=<?= $share_url ?>" target="_blank" class="share-btn share-tw"><i class="fab fa-x-twitter"></i> Twitter</a>
                        <a href="https://www.linkedin.com/sharing/share-offsite/?url=<?= $share_url ?>" target="_blank" class="share-btn share-li"><i class="fab fa-linkedin-in"></i> LinkedIn</a>
                        <button class="share-btn share-copy" onclick="copyLink()"><i class="fas fa-link"></i> কপি লিংক</button>
                    </div>
                    
                    <!-- Author Bio -->
                    <div class="author-bio">
                        <div class="author-avatar"><?= strtoupper(substr($post['author'] ?? 'Admin', 0, 1)) ?></div>
                        <div class="author-info">
                            <h5><?= htmlspecialchars($post['author'] ?? 'ডা. মোঃ ফেরদৌস') ?></h5>
                            <p>হোমিওপ্যাথি বিশেষজ্ঞ। স্বাস্থ্য সচেতনতা ও প্রাকৃতিক চিকিৎসা নিয়ে লেখালেখি করেন।</p>
                        </div>
                    </div>
                </div>
                
                <!-- Comments Section -->
                <div class="comments-section">
                    <h5><i class="fas fa-comments"></i> মন্তব্য (<?= $comment_count ?>)</h5>
                    
                    <?php if($comment_count > 0): ?>
                        <div class="comment-list">
                            <?php while($cmt = $comments->fetch_assoc()): ?>
                                <div class="comment-item">
                                    <div class="comment-avatar"><?= strtoupper(substr($cmt['name'], 0, 1)) ?></div>
                                    <div class="comment-body">
                                        <h6><?= htmlspecialchars($cmt['name']) ?></h6>
                                        <span class="comment-date"><?= date('d M Y, h:i A', strtotime($cmt['created_at'])) ?></span>
                                        <p><?= nl2br(htmlspecialchars($cmt['comment'])) ?></p>
                                    </div>
                                </div>
                            <?php endwhile; ?>
                        </div>
                    <?php else: ?>
                        <p class="text-muted">কোনো মন্তব্য নেই। প্রথম মন্তব্য করুন!</p>
                    <?php endif; ?>
                    
                    <!-- Comment Form -->
                    <div class="comment-form mt-4">
                        <h6>মন্তব্য করুন</h6>
                        <form id="commentForm">
                            <input type="hidden" name="post_id" value="<?= $post_id ?>">
                            <div class="row g-3">
                                <div class="col-md-6">
                                    <input type="text" name="name" class="form-control" placeholder="আপনার নাম *" required>
                                </div>
                                <div class="col-md-6">
                                    <input type="email" name="email" class="form-control" placeholder="ইমেইল (প্রকাশিত হবে না)">
                                </div>
                                <div class="col-12">
                                    <textarea name="comment" class="form-control" rows="4" placeholder="আপনার মন্তব্য *" required></textarea>
                                </div>
                                <div class="col-12">
                                    <button type="submit" class="btn-submit"><i class="fas fa-paper-plane"></i> মন্তব্য পোস্ট করুন</button>
                                </div>
                            </div>
                        </form>
                        <div id="commentResult" class="mt-3"></div>
                    </div>
                </div>
            </div>
            
            <!-- SIDEBAR -->
            <div class="col-lg-4">
                <!-- Related Posts -->
                <?php if($related && $related->num_rows > 0): ?>
                    <div class="card border-0 shadow-sm rounded-4 p-3 mb-4">
                        <h5 class="mb-3"><i class="fas fa-link"></i> সম্পর্কিত পোস্ট</h5>
                        <?php while($r = $related->fetch_assoc()): ?>
                            <div class="d-flex gap-3 mb-3 pb-3 border-bottom">
                                <?php if($r['image']): ?>
                                    <img src="<?= htmlspecialchars($r['image']) ?>" width="70" height="70" style="object-fit:cover;border-radius:12px;" alt="">
                                <?php else: ?>
                                    <div style="width:70px;height:70px;background:#e9ecef;border-radius:12px;display:flex;align-items:center;justify-content:center;"><i class="fas fa-newspaper text-muted"></i></div>
                                <?php endif; ?>
                                <div>
                                    <a href="single_post.php?id=<?= $r['id'] ?>" class="text-dark text-decoration-none fw-semibold"><?= htmlspecialchars($r['title']) ?></a>
                                    <div class="text-muted small"><?= date('d M Y', strtotime($r['created_at'])) ?></div>
                                </div>
                            </div>
                        <?php endwhile; ?>
                    </div>
                <?php endif; ?>
                
                <!-- Back to Blog -->
                <div class="card border-0 shadow-sm rounded-4 p-3">
                    <a href="blog.php" class="btn btn-primary rounded-pill"><i class="fas fa-arrow-left"></i> সব পোস্ট দেখুন</a>
                </div>
            </div>
        </div>
    </div>
</section>

<!-- FOOTER -->
<footer>
    <div class="container">
        <div class="row">
            <div class="col-md-6">
                <h5 style="color:#fff;"><?= htmlspecialchars($brand['name'] ?? 'ওয়ান হোমিওপ্যাথি') ?></h5>
                <p><?= htmlspecialchars($brand['about'] ?? '') ?></p>
            </div>
            <div class="col-md-6 text-md-end">
                <p><i class="fas fa-phone"></i> <?= htmlspecialchars($brand['phone'] ?? '') ?></p>
                <p><i class="fas fa-envelope"></i> <?= htmlspecialchars($brand['email'] ?? '') ?></p>
                <div>
                    <?php if($brand['facebook']): ?>
                        <a href="<?= htmlspecialchars($brand['facebook']) ?>" class="text-white me-2" target="_blank"><i class="fab fa-facebook fa-lg"></i></a>
                    <?php endif; ?>
                    <?php if($brand['youtube']): ?>
                        <a href="<?= htmlspecialchars($brand['youtube']) ?>" class="text-white me-2" target="_blank"><i class="fab fa-youtube fa-lg"></i></a>
                    <?php endif; ?>
                    <a href="https://wa.me/88<?= htmlspecialchars($whatsapp_number) ?>" style="color:#25D366" target="_blank"><i class="fab fa-whatsapp fa-lg"></i></a>
                </div>
            </div>
        </div>
        <hr>
        <div class="row align-items-center">
            <div class="col-md-6 text-center text-md-start">
                <p class="mb-0 small">© <?= date('Y') ?> <?= htmlspecialchars($brand['name'] ?? 'ওয়ান হোমিওপ্যাথি') ?>. সর্বস্বত্ব সংরক্ষিত।</p>
            </div>
            <div class="col-md-6 text-center text-md-end">
                <a href="https://www.onesbd.com/host" target="_blank" class="dev-credit"><i class="fas fa-globe"></i> Developed by <strong>OneSBD</strong></a>
            </div>
        </div>
    </div>
</footer>

<!-- WHATSAPP FLOAT -->
<a href="https://wa.me/88<?= htmlspecialchars($whatsapp_number) ?>?text=আমি%20Dr.%20Ferdous%20এর%20সেবা%20নিয়ে%20জানতে%20চাই" target="_blank" class="wa-float"><i class="fab fa-whatsapp"></i></a>

<!-- BACK TO TOP -->
<a href="#" class="back-to-top" id="backToTop"><i class="fas fa-arrow-up"></i></a>

<!-- SCRIPTS -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>

<script>
// =========================================================
// NAVBAR SCROLL
// =========================================================
$(window).scroll(function() {
    $('#navbar').toggleClass('scrolled', $(this).scrollTop() > 50);
    const backToTop = document.getElementById('backToTop');
    if ($(this).scrollTop() > 300) {
        backToTop.classList.add('show');
    } else {
        backToTop.classList.remove('show');
    }
});

// =========================================================
// BACK TO TOP
// =========================================================
document.getElementById('backToTop').addEventListener('click', function(e) {
    e.preventDefault();
    window.scrollTo({ top: 0, behavior: 'smooth' });
});

// =========================================================
// COPY LINK
// =========================================================
function copyLink() {
    const url = window.location.href;
    if (navigator.clipboard) {
        navigator.clipboard.writeText(url).then(() => {
            showToast('✅ লিংক কপি করা হয়েছে!', 'success');
        }).catch(() => {
            fallbackCopy(url);
        });
    } else {
        fallbackCopy(url);
    }
}

function fallbackCopy(text) {
    const textarea = document.createElement('textarea');
    textarea.value = text;
    textarea.style.position = 'fixed';
    textarea.style.opacity = '0';
    document.body.appendChild(textarea);
    textarea.select();
    try {
        document.execCommand('copy');
        showToast('✅ লিংক কপি করা হয়েছে!', 'success');
    } catch (err) {
        showToast('❌ লিংক কপি করতে ব্যর্থ', 'danger');
    }
    document.body.removeChild(textarea);
}

// =========================================================
// TOAST
// =========================================================
function showToast(message, type) {
    const container = document.createElement('div');
    container.style.cssText = 'position:fixed;bottom:80px;left:50%;transform:translateX(-50%);z-index:9999;background:#fff;padding:12px 24px;border-radius:12px;box-shadow:0 10px 30px rgba(0,0,0,0.15);border-left:4px solid #28a745;animation:slideUp 0.3s ease;font-family:Segoe UI,sans-serif';
    if (type === 'danger') container.style.borderLeftColor = '#dc3545';
    container.textContent = message;
    document.body.appendChild(container);
    setTimeout(() => {
        container.style.opacity = '0';
        container.style.transition = 'opacity 0.3s';
        setTimeout(() => container.remove(), 300);
    }, 3000);
}

// Add slideUp keyframe
const style = document.createElement('style');
style.textContent = '@keyframes slideUp{from{opacity:0;transform:translateX(-50%) translateY(20px)}to{opacity:1;transform:translateX(-50%) translateY(0)}}';
document.head.appendChild(style);

// =========================================================
// COMMENT FORM (AJAX)
// =========================================================
$('#commentForm').submit(function(e) {
    e.preventDefault();
    const formData = $(this).serialize();
    const $btn = $(this).find('.btn-submit');
    const originalText = $btn.html();
    $btn.html('<i class="fas fa-spinner fa-spin"></i> পাঠানো হচ্ছে...').prop('disabled', true);
    
    $.post('submit_comment.php', formData, function(res) {
        if (res.success) {
            $('#commentResult').html('<div class="alert alert-success">✅ মন্তব্যটি অনুমোদনের জন্য জমা দেওয়া হয়েছে।</div>');
            $('#commentForm')[0].reset();
            setTimeout(() => location.reload(), 2000);
        } else {
            $('#commentResult').html('<div class="alert alert-danger">❌ ' + (res.message || 'ত্রুটি! আবার চেষ্টা করুন।') + '</div>');
        }
        $btn.html(originalText).prop('disabled', false);
    }).fail(function() {
        $('#commentResult').html('<div class="alert alert-danger">❌ সার্ভার ত্রুটি। পরে চেষ্টা করুন।</div>');
        $btn.html(originalText).prop('disabled', false);
    });
});
</script>

</body>
</html>