<?php
// ============================================
// OPD (Appointment Booking) INDEX - DEBUG VERSION
// Path: /public_html/Appointment/opd/index.php
// ============================================

// --- Enable Error Display for Debugging ---
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

// --- Find config.php ---
$config_paths = [
    '../../config.php',
    '../../../config.php',
    '../config.php',
    'config.php',
    '../../opd/config.php',
];

$config_found = false;
foreach ($config_paths as $path) {
    if (file_exists($path)) {
        require_once $path;
        $config_found = true;
        break;
    }
}

if (!$config_found) {
    die("Error: config.php not found. Checked paths: " . implode(', ', $config_paths));
}

// --- Test Database Connection ---
if (!isset($conn) || !$conn) {
    die("Error: Database connection failed. Please check config.php");
}

// --- Start Session ---
if (session_status() === PHP_SESSION_NONE) session_start();

// ============================================
// DEFINE $brand FIRST - BEFORE ANY HTML
// ============================================

// Default values
$brand = array(
    'name' => 'ওয়ান হোমিওপ্যাথি',
    'slogan' => 'প্রাকৃতিক চিকিৎসায় সুস্থ জীবন',
    'phone' => '017XXXXXXXX',
    'whatsapp' => '017XXXXXXXX',
    'email' => 'info@example.com',
    'address' => 'ঢাকা, বাংলাদেশ',
    'logo' => '',
    'facebook' => '',
    'youtube' => '',
    'hero_image' => 'assets/images/hero-bg.jpg'
);

// Try to fetch from database
try {
    $brand_result = mysqli_query($conn, "SELECT * FROM brand LIMIT 1");
    if ($brand_result && mysqli_num_rows($brand_result) > 0) {
        $brand_data = mysqli_fetch_assoc($brand_result);
        foreach ($brand_data as $key => $value) {
            if (!empty($value)) {
                $brand[$key] = $value;
            }
        }
    }
} catch (Exception $e) {
    // Table might not exist, use defaults
}

// ============================================
// FETCH OTHER DATA
// ============================================

$hero_slides = array();
try {
    $hero_result = mysqli_query($conn, "SELECT * FROM hero_slides WHERE is_active = 1 ORDER BY id LIMIT 1");
    if ($hero_result && mysqli_num_rows($hero_result) > 0) {
        while ($row = mysqli_fetch_assoc($hero_result)) {
            $hero_slides[] = $row;
        }
    }
} catch (Exception $e) {
    // Table might not exist
}

if (empty($hero_slides)) {
    $hero_slides[] = array(
        'id' => 1,
        'title' => $brand['name'],
        'subtitle' => $brand['slogan'],
        'image' => $brand['hero_image'],
        'button_text' => 'যোগাযোগ করুন',
        'button_link' => '#contact',
        'button_secondary_text' => 'অ্যাপয়েন্টমেন্ট করুন',
        'button_secondary_link' => 'book.php'
    );
}

// Doctors
$doctors = array();
try {
    $doctors_result = mysqli_query($conn, "SELECT * FROM doctors WHERE is_active = 1 ORDER BY id");
    if ($doctors_result) {
        while ($row = mysqli_fetch_assoc($doctors_result)) {
            $doctors[] = $row;
        }
    }
} catch (Exception $e) {
    // Table might not exist
}

// Services
$services = array();
try {
    $services_result = mysqli_query($conn, "SELECT * FROM services WHERE is_active = 1 ORDER BY id");
    if ($services_result) {
        while ($row = mysqli_fetch_assoc($services_result)) {
            $services[] = $row;
        }
    }
} catch (Exception $e) {
    // Table might not exist
}

// Products
$products = array();
try {
    $products_result = mysqli_query($conn, "SELECT * FROM products WHERE is_active = 1 ORDER BY id LIMIT 8");
    if ($products_result) {
        while ($row = mysqli_fetch_assoc($products_result)) {
            $products[] = $row;
        }
    }
} catch (Exception $e) {
    // Table might not exist
}

// Chambers
$chambers = array();
try {
    $chambers_result = mysqli_query($conn, "SELECT * FROM chambers WHERE status = 'active' ORDER BY id");
    if ($chambers_result) {
        while ($row = mysqli_fetch_assoc($chambers_result)) {
            $chambers[] = $row;
        }
    }
} catch (Exception $e) {
    // Table might not exist
}

// User Session
$is_logged_in = isset($_SESSION['patient_id']);
$patient_name = $_SESSION['patient_name'] ?? '';
$patient_id = $_SESSION['patient_id'] ?? 0;

// Free Camp
$has_free_camp = false;
$free_camp_details = null;
$today_day = date('w');

try {
    $free_camp_query = "SELECT cs.*, c.name as chamber_name, c.address 
                        FROM chamber_schedules cs 
                        JOIN chambers c ON cs.chamber_id = c.id 
                        WHERE cs.day_of_week = $today_day 
                        AND cs.is_free_camp = 1 
                        AND cs.status = 'active' 
                        LIMIT 1";
    $free_camp_result = mysqli_query($conn, $free_camp_query);
    if ($free_camp_result && mysqli_num_rows($free_camp_result) > 0) {
        $has_free_camp = true;
        $free_camp_details = mysqli_fetch_assoc($free_camp_result);
    }
} catch (Exception $e) {
    // Query might fail
}

// ============================================
// NOW START HTML - $brand IS DEFINED!
// ============================================
?>
<!DOCTYPE html>
<html lang="bn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo htmlspecialchars($brand['name']); ?> | অ্যাপয়েন্টমেন্ট</title>
    <meta name="description" content="<?php echo htmlspecialchars($brand['slogan']); ?>">
    
    <!-- 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">
    <link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">
    
    <style>
        :root {
            --primary: #2d6a4f;
            --primary-dark: #1b4332;
            --primary-light: #52b788;
            --secondary: #25D366;
            --accent: #f39c12;
            --bg-light: #f8f9fa;
            --text-dark: #1a1a2e;
            --text-light: #6c757d;
            --shadow: 0 10px 40px rgba(0,0,0,0.08);
            --radius: 20px;
            --navbar-height: 70px;
        }

        * { margin: 0; padding: 0; box-sizing: border-box; }
        body {
            font-family: 'Hind Siliguri', 'SolaimanLipi', Arial, sans-serif;
            background: #ffffff;
            color: var(--text-dark);
            padding-top: var(--navbar-height);
            line-height: 1.7;
        }
        
        .container-custom {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 20px;
        }

        .navbar {
            background: rgba(255,255,255,0.95);
            backdrop-filter: blur(10px);
            box-shadow: 0 2px 20px rgba(0,0,0,0.06);
            padding: 8px 0;
            transition: all 0.3s ease;
            height: var(--navbar-height);
            min-height: var(--navbar-height);
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            z-index: 1000;
        }
        .navbar.scrolled {
            background: rgba(255,255,255,0.98);
            box-shadow: 0 4px 30px rgba(0,0,0,0.1);
        }
        .navbar-brand {
            font-weight: 700;
            color: var(--primary) !important;
            font-size: 1.3rem;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        .navbar-brand img {
            height: 40px;
            width: auto;
            object-fit: contain;
        }
        .navbar .nav-link {
            color: #2c3e50;
            font-weight: 500;
            padding: 8px 16px;
            border-radius: 8px;
            transition: all 0.3s ease;
            font-size: 0.95rem;
        }
        .navbar .nav-link:hover,
        .navbar .nav-link.active {
            color: var(--primary);
            background: rgba(45, 106, 79, 0.08);
        }

        .btn-nav {
            padding: 6px 16px;
            border-radius: 50px;
            font-weight: 600;
            font-size: 0.9rem;
            transition: all 0.3s ease;
            display: inline-flex;
            align-items: center;
            gap: 6px;
        }
        .btn-appointment {
            background: var(--primary);
            color: white !important;
        }
        .btn-appointment:hover {
            background: var(--primary-dark);
            color: white !important;
            transform: translateY(-2px);
        }

        .hero-section {
            position: relative;
            min-height: 80vh;
            display: flex;
            align-items: center;
            overflow: hidden;
            padding: 60px 0;
            background: linear-gradient(135deg, #1a5276, #2e86c1);
        }
        .hero-section .hero-overlay {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.3);
            z-index: 1;
        }
        .hero-section .hero-content {
            position: relative;
            z-index: 2;
            color: white;
            text-align: center;
            max-width: 900px;
            margin: 0 auto;
            padding: 0 20px;
        }
        .hero-section .hero-content h1 {
            font-size: 3.5rem;
            font-weight: 800;
            margin-bottom: 20px;
            text-shadow: 0 4px 30px rgba(0,0,0,0.3);
        }
        .hero-section .hero-content .hero-subtitle {
            font-size: 1.3rem;
            font-weight: 400;
            margin-bottom: 30px;
            opacity: 0.9;
            text-shadow: 0 2px 15px rgba(0,0,0,0.2);
        }
        .hero-section .hero-content .hero-buttons {
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
            gap: 15px;
        }
        .hero-section .hero-content .btn {
            padding: 12px 30px;
            border-radius: 50px;
            font-weight: 600;
            transition: all 0.3s ease;
            font-size: 1rem;
            min-width: 160px;
        }
        .hero-section .hero-content .btn-light {
            background: white;
            color: #1a5276;
            border: none;
        }
        .hero-section .hero-content .btn-light:hover {
            transform: translateY(-3px);
            box-shadow: 0 15px 40px rgba(255,255,255,0.3);
        }
        .hero-section .hero-content .btn-success {
            background: var(--secondary);
            color: white;
            border: none;
        }
        .hero-section .hero-content .btn-success:hover {
            transform: translateY(-3px);
            box-shadow: 0 15px 40px rgba(37, 211, 102, 0.4);
        }

        .free-camp-banner {
            background: linear-gradient(135deg, #f39c12, #e67e22);
            padding: 12px 20px;
            border-radius: 15px;
            display: inline-flex;
            align-items: center;
            gap: 15px;
            animation: pulse 2s infinite;
            box-shadow: 0 5px 20px rgba(243, 156, 18, 0.3);
            margin-top: 20px;
        }
        @keyframes pulse {
            0%, 100% { transform: scale(1); }
            50% { transform: scale(1.02); }
        }

        section {
            padding: 70px 0;
        }
        section:nth-child(even) { background: var(--bg-light); }

        .section-header {
            text-align: center;
            margin-bottom: 50px;
        }
        .section-header h2 {
            font-size: 2.5rem;
            font-weight: 800;
            margin-bottom: 10px;
            color: var(--text-dark);
        }
        .section-header h2 span { color: var(--primary); }
        .section-header p {
            color: var(--text-light);
            max-width: 700px;
            margin: 0 auto;
            font-size: 1.1rem;
        }
        .section-header .subtitle-line {
            width: 60px;
            height: 4px;
            background: var(--primary);
            margin: 15px auto 0;
            border-radius: 10px;
        }

        .card-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
            gap: 25px;
        }
        .card-grid-3 { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
        .card-grid-4 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

        .doctor-card, .service-card, .product-card, .chamber-card {
            background: white;
            border-radius: var(--radius);
            padding: 25px;
            box-shadow: var(--shadow);
            transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
            height: 100%;
            display: flex;
            flex-direction: column;
            align-items: center;
            text-align: center;
            border: 1px solid rgba(0,0,0,0.03);
        }
        .doctor-card:hover, .service-card:hover, .product-card:hover, .chamber-card:hover {
            transform: translateY(-8px);
            box-shadow: 0 20px 60px rgba(0,0,0,0.12);
        }

        .doctor-card img {
            width: 120px;
            height: 120px;
            border-radius: 50%;
            object-fit: cover;
            border: 4px solid var(--primary);
            margin-bottom: 15px;
        }
        .doctor-card h5 { font-size: 1.1rem; font-weight: 700; }

        .service-icon {
            font-size: 3rem;
            color: var(--primary);
            margin-bottom: 15px;
        }
        .service-card h5 { font-size: 1.1rem; font-weight: 700; }
        .service-card p {
            color: var(--text-light);
            font-size: 0.95rem;
            flex-grow: 1;
        }

        .chamber-card {
            align-items: flex-start;
            text-align: left;
        }
        .chamber-card h5 { color: var(--primary); }
        .chamber-card p {
            margin-bottom: 5px;
            font-size: 0.95rem;
            display: flex;
            align-items: center;
            gap: 8px;
        }
        .chamber-card p i {
            width: 20px;
            color: var(--primary);
        }

        .contact-info p {
            margin-bottom: 12px;
            font-size: 1.05rem;
            display: flex;
            align-items: center;
            gap: 12px;
        }
        .contact-info p i {
            width: 25px;
            color: var(--primary);
        }

        .social-links {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
            margin-top: 15px;
        }
        .social-links .btn {
            border-radius: 50%;
            width: 45px;
            height: 45px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            transition: all 0.3s;
            font-size: 1.1rem;
        }
        .social-links .btn:hover { transform: translateY(-3px) scale(1.05); }

        footer {
            background: #1a1a2e;
            color: rgba(255,255,255,0.7);
            padding: 40px 0;
            text-align: center;
        }
        footer .footer-links {
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
            gap: 20px;
            margin-top: 15px;
        }
        footer .footer-links a {
            color: rgba(255,255,255,0.6);
            transition: all 0.3s;
        }
        footer .footer-links a:hover { color: white; }

        @media (max-width: 991px) {
            :root { --navbar-height: 60px; }
            .navbar-collapse {
                background: white;
                padding: 20px;
                border-radius: 16px;
                box-shadow: 0 20px 60px rgba(0,0,0,0.15);
                margin-top: 10px;
                max-height: 80vh;
                overflow-y: auto;
            }
            .navbar .nav-link { padding: 10px 16px; }
        }

        @media (max-width: 767px) {
            .hero-section .hero-content h1 { font-size: 2.2rem; }
            .hero-section .hero-content .hero-subtitle { font-size: 1rem; }
            .card-grid, .card-grid-3, .card-grid-4 { grid-template-columns: 1fr 1fr; }
        }

        @media (max-width: 575px) {
            :root { --navbar-height: 52px; }
            .hero-section .hero-content h1 { font-size: 1.8rem; }
            .card-grid, .card-grid-3, .card-grid-4 { grid-template-columns: 1fr; }
            .doctor-card img { width: 100px; height: 100px; }
            section { padding: 50px 0; }
            .section-header h2 { font-size: 1.8rem; }
        }
    </style>
</head>
<body>

<!-- ============================================
     NAVIGATION
     ============================================ -->
<nav class="navbar navbar-expand-lg fixed-top" id="navbar">
    <div class="container-custom">
        <a class="navbar-brand" href="index.php">
            <?php if (!empty($brand['logo'])): ?>
                <img src="<?php echo htmlspecialchars($brand['logo']); ?>" alt="Logo">
            <?php else: ?>
                <i class="fas fa-clinic-medical"></i>
            <?php endif; ?>
            <span><?php echo htmlspecialchars($brand['name']); ?></span>
        </a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav ms-auto">
                <li class="nav-item"><a class="nav-link" href="#home">হোম</a></li>
                <li class="nav-item"><a class="nav-link" href="#doctors">ডাক্তার</a></li>
                <li class="nav-item"><a class="nav-link" href="#services">সেবা</a></li>
                <li class="nav-item"><a class="nav-link" href="#products">পণ্য</a></li>
                <li class="nav-item"><a class="nav-link" href="#chambers">চেম্বার</a></li>
                <li class="nav-item"><a class="nav-link" href="#contact">যোগাযোগ</a></li>
                <?php if ($is_logged_in): ?>
                    <li class="nav-item"><a class="nav-link" href="../../dashboard.php"><i class="fas fa-user-md"></i> ড্যাশবোর্ড</a></li>
                    <li class="nav-item"><a class="btn-nav btn-appointment" href="../../logout.php"><i class="fas fa-sign-out-alt"></i> লগআউট</a></li>
                <?php else: ?>
                    <li class="nav-item"><a class="btn-nav btn-appointment" href="../../login.php"><i class="fas fa-sign-in-alt"></i> লগইন</a></li>
                <?php endif; ?>
                <li class="nav-item"><a class="btn-nav btn-appointment" href="book.php"><i class="fas fa-calendar-check"></i> অ্যাপয়েন্টমেন্ট</a></li>
            </ul>
        </div>
    </div>
</nav>

<!-- ============================================
     HERO SECTION
     ============================================ -->
<section id="home" class="hero-section">
    <div class="hero-overlay"></div>
    <div class="hero-content">
        <?php if (!empty($hero_slides)): ?>
            <?php $slide = $hero_slides[0]; ?>
            <h1><?php echo htmlspecialchars($slide['title'] ?? $brand['name']); ?></h1>
            <p class="hero-subtitle"><?php echo htmlspecialchars($slide['subtitle'] ?? $brand['slogan']); ?></p>
        <?php else: ?>
            <h1><?php echo htmlspecialchars($brand['name']); ?></h1>
            <p class="hero-subtitle"><?php echo htmlspecialchars($brand['slogan']); ?></p>
        <?php endif; ?>
        
        <?php if ($has_free_camp && $free_camp_details): ?>
        <div class="free-camp-banner">
            <i class="fas fa-gift"></i>
            <div>
                <strong>ফ্রি মেডিসিন ক্যাম্প আজ!</strong>
                <span style="font-size:13px;">
                    <?php echo htmlspecialchars($free_camp_details['chamber_name'] ?? ''); ?> 
                    (<?php echo date('h:i A', strtotime($free_camp_details['start_time'] ?? '00:00')); ?> - 
                    <?php echo date('h:i A', strtotime($free_camp_details['end_time'] ?? '00:00')); ?>)
                </span>
            </div>
        </div>
        <?php endif; ?>
        
        <div class="hero-buttons">
            <a href="#contact" class="btn btn-light">
                <i class="fas fa-phone"></i> যোগাযোগ করুন
            </a>
            <a href="book.php" class="btn btn-success">
                <i class="fas fa-calendar-plus"></i> অ্যাপয়েন্টমেন্ট করুন
            </a>
        </div>
    </div>
</section>

<!-- ============================================
     DOCTORS SECTION
     ============================================ -->
<section id="doctors">
    <div class="container-custom">
        <div class="section-header">
            <h2>আমাদের <span>দক্ষ ডাক্তারবৃন্দ</span></h2>
            <p>আপনার স্বাস্থ্য সেবার জন্য আমাদের অভিজ্ঞ ডাক্তাররা সর্বদা প্রস্তুত</p>
            <div class="subtitle-line"></div>
        </div>
        <div class="card-grid">
            <?php if (!empty($doctors)): ?>
                <?php foreach ($doctors as $doctor): ?>
                <div class="doctor-card" data-aos="fade-up">
                    <?php if (!empty($doctor['photo']) && file_exists($doctor['photo'])): ?>
                        <img src="<?php echo htmlspecialchars($doctor['photo']); ?>" alt="<?php echo htmlspecialchars($doctor['name']); ?>" loading="lazy">
                    <?php else: ?>
                        <div style="width:120px;height:120px;border-radius:50%;background:#e9ecef;display:flex;align-items:center;justify-content:center;color:#6c757d;font-size:50px;margin:0 auto 15px;border:4px solid var(--primary);">
                            <i class="fas fa-user-md"></i>
                        </div>
                    <?php endif; ?>
                    <h5><?php echo htmlspecialchars($doctor['name'] ?? 'ডাক্তার'); ?></h5>
                    <p class="text-muted"><?php echo htmlspecialchars($doctor['degree'] ?? ''); ?></p>
                </div>
                <?php endforeach; ?>
            <?php else: ?>
                <div class="text-center text-muted" style="grid-column:1/-1;padding:40px;">
                    <i class="fas fa-user-md fa-3x mb-3 d-block"></i>
                    <p>কোনও ডাক্তার পাওয়া যায়নি।</p>
                </div>
            <?php endif; ?>
        </div>
    </div>
</section>

<!-- ============================================
     SERVICES SECTION
     ============================================ -->
<section id="services" class="bg-light">
    <div class="container-custom">
        <div class="section-header">
            <h2>আমাদের <span>সেবাসমূহ</span></h2>
            <p>আপনার জন্য আমাদের বিশেষ সেবা প্যাকেজ</p>
            <div class="subtitle-line"></div>
        </div>
        <div class="card-grid card-grid-3">
            <?php if (!empty($services)): ?>
                <?php foreach ($services as $service): ?>
                <div class="service-card" data-aos="fade-up">
                    <div class="service-icon">
                        <i class="<?php echo htmlspecialchars($service['icon'] ?? 'fas fa-heartbeat'); ?>"></i>
                    </div>
                    <h5><?php echo htmlspecialchars($service['title'] ?? 'সেবা'); ?></h5>
                    <p><?php echo htmlspecialchars(substr($service['description'] ?? '', 0, 100)); ?>...</p>
                </div>
                <?php endforeach; ?>
            <?php else: ?>
                <div class="text-center text-muted" style="grid-column:1/-1;padding:40px;">
                    <i class="fas fa-heartbeat fa-3x mb-3 d-block"></i>
                    <p>কোনও সেবা পাওয়া যায়নি।</p>
                </div>
            <?php endif; ?>
        </div>
    </div>
</section>

<!-- ============================================
     PRODUCTS SECTION
     ============================================ -->
<section id="products">
    <div class="container-custom">
        <div class="section-header">
            <h2>আমাদের <span>পণ্যসমূহ</span></h2>
            <p>গুণগত মান সম্পন্ন হোমিওপ্যাথি পণ্য</p>
            <div class="subtitle-line"></div>
        </div>
        <div class="card-grid card-grid-4">
            <?php if (!empty($products)): ?>
                <?php foreach ($products as $product): ?>
                <div class="product-card" data-aos="fade-up">
                    <div style="font-size:3rem;color:var(--primary);margin-bottom:15px;">
                        <i class="fas fa-capsules"></i>
                    </div>
                    <h6><?php echo htmlspecialchars($product['name'] ?? 'পণ্য'); ?></h6>
                    <p class="price" style="font-size:1.2rem;font-weight:700;color:var(--primary);">
                        ৳<?php echo number_format($product['price'] ?? 0, 2); ?>
                    </p>
                </div>
                <?php endforeach; ?>
            <?php else: ?>
                <div class="text-center text-muted" style="grid-column:1/-1;padding:40px;">
                    <i class="fas fa-capsules fa-3x mb-3 d-block"></i>
                    <p>কোনও পণ্য পাওয়া যায়নি।</p>
                </div>
            <?php endif; ?>
        </div>
    </div>
</section>

<!-- ============================================
     CHAMBERS SECTION
     ============================================ -->
<section id="chambers" class="bg-light">
    <div class="container-custom">
        <div class="section-header">
            <h2>আমাদের <span>চেম্বারসমূহ</span></h2>
            <p>আপনার নিকটবর্তী চেম্বারে আসুন</p>
            <div class="subtitle-line"></div>
        </div>
        <div class="card-grid card-grid-3">
            <?php if (!empty($chambers)): ?>
                <?php foreach ($chambers as $chamber): ?>
                <div class="chamber-card" data-aos="fade-up">
                    <h5><?php echo htmlspecialchars($chamber['name'] ?? 'চেম্বার'); ?></h5>
                    <p><i class="fas fa-map-marker-alt"></i> <?php echo htmlspecialchars($chamber['address'] ?? ''); ?></p>
                    <?php if (!empty($chamber['phone'])): ?>
                        <p><i class="fas fa-phone"></i> <?php echo htmlspecialchars($chamber['phone']); ?></p>
                    <?php endif; ?>
                    <?php if (!empty($chamber['schedule'])): ?>
                        <p><i class="fas fa-clock"></i> <?php echo nl2br(htmlspecialchars($chamber['schedule'])); ?></p>
                    <?php endif; ?>
                </div>
                <?php endforeach; ?>
            <?php else: ?>
                <div class="text-center text-muted" style="grid-column:1/-1;padding:40px;">
                    <i class="fas fa-hospital fa-3x mb-3 d-block"></i>
                    <p>কোনও চেম্বার পাওয়া যায়নি।</p>
                </div>
            <?php endif; ?>
        </div>
    </div>
</section>

<!-- ============================================
     CONTACT SECTION
     ============================================ -->
<section id="contact">
    <div class="container-custom">
        <div class="section-header">
            <h2><span>যোগাযোগ</span> করুন</h2>
            <p>আমাদের সাথে যোগাযোগ করতে নিচের ফর্মটি পূরণ করুন</p>
            <div class="subtitle-line"></div>
        </div>
        <div class="row g-4">
            <div class="col-lg-5" data-aos="fade-right">
                <div class="contact-info">
                    <h4 class="mb-4"><i class="fas fa-address-card text-primary"></i> যোগাযোগের তথ্য</h4>
                    <p><i class="fas fa-phone text-success"></i> <?php echo htmlspecialchars($brand['phone']); ?></p>
                    <p><i class="fab fa-whatsapp text-success"></i> <?php echo htmlspecialchars($brand['whatsapp']); ?></p>
                    <p><i class="fas fa-envelope text-primary"></i> <?php echo htmlspecialchars($brand['email']); ?></p>
                    <p><i class="fas fa-map-marker-alt text-danger"></i> <?php echo nl2br(htmlspecialchars($brand['address'])); ?></p>
                    <div class="social-links">
                        <?php if (!empty($brand['facebook'])): ?>
                            <a href="<?php echo htmlspecialchars($brand['facebook']); ?>" class="btn btn-primary" target="_blank"><i class="fab fa-facebook"></i></a>
                        <?php endif; ?>
                        <?php if (!empty($brand['youtube'])): ?>
                            <a href="<?php echo htmlspecialchars($brand['youtube']); ?>" class="btn btn-danger" target="_blank"><i class="fab fa-youtube"></i></a>
                        <?php endif; ?>
                        <?php if (!empty($brand['whatsapp'])): ?>
                            <a href="https://wa.me/<?php echo htmlspecialchars($brand['whatsapp']); ?>" class="btn btn-success" target="_blank"><i class="fab fa-whatsapp"></i></a>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
            <div class="col-lg-7" data-aos="fade-left">
                <form class="contact-form" id="leadForm" method="post" action="process_lead.php">
                    <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="tel" name="phone" class="form-control" placeholder="মোবাইল নম্বর *" required>
                        </div>
                        <div class="col-12">
                            <input type="email" name="email" class="form-control" placeholder="ইমেইল (ঐচ্ছিক)">
                        </div>
                        <div class="col-12">
                            <textarea name="message" class="form-control" rows="4" placeholder="আপনার বার্তা"></textarea>
                        </div>
                        <div class="col-12">
                            <button type="submit" class="btn btn-primary w-100">
                                <i class="fas fa-paper-plane"></i> বার্তা পাঠান
                            </button>
                        </div>
                    </div>
                </form>
                <div id="leadResult" class="mt-3"></div>
            </div>
        </div>
    </div>
</section>

<!-- ============================================
     FOOTER
     ============================================ -->
<footer>
    <div class="container-custom">
        <p>&copy; <?php echo date('Y'); ?> <?php echo htmlspecialchars($brand['name']); ?> - সর্বস্বত্ব সংরক্ষিত</p>
        <small><?php echo htmlspecialchars($brand['slogan']); ?></small>
        <div class="footer-links">
            <a href="#home">হোম</a>
            <a href="#doctors">ডাক্তার</a>
            <a href="#services">সেবা</a>
            <a href="#products">পণ্য</a>
            <a href="#chambers">চেম্বার</a>
            <a href="#contact">যোগাযোগ</a>
        </div>
    </div>
</footer>

<!-- ============================================
     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 src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>

<script>
AOS.init({
    duration: 800,
    once: true,
    offset: 100,
    easing: 'ease-out-cubic'
});

$(window).scroll(function() {
    if ($(window).scrollTop() > 50) {
        $('#navbar').addClass('scrolled');
    } else {
        $('#navbar').removeClass('scrolled');
    }
});

$('a[href^="#"]').on('click', function(e) {
    e.preventDefault();
    var target = $(this).attr('href');
    if (target !== '#') {
        $('html, body').animate({
            scrollTop: $(target).offset().top - 70
        }, 800);
    }
});

$('#leadForm').on('submit', function(e) {
    e.preventDefault();
    
    var form = $(this);
    var btn = form.find('button[type="submit"]');
    var originalText = btn.html();
    
    btn.html('<i class="fas fa-spinner fa-spin"></i> পাঠানো হচ্ছে...').prop('disabled', true);
    
    $.ajax({
        url: form.attr('action'),
        type: 'POST',
        data: form.serialize(),
        success: function(response) {
            $('#leadResult').html('<div class="alert alert-success">✅ আপনার বার্তা পাঠানো হয়েছে। আমরা শীঘ্রই যোগাযোগ করব।</div>');
            form[0].reset();
            btn.html(originalText).prop('disabled', false);
            setTimeout(function() {
                $('#leadResult').html('');
            }, 5000);
        },
        error: function() {
            $('#leadResult').html('<div class="alert alert-danger">❌ বার্তা পাঠাতে সমস্যা হয়েছে। আবার চেষ্টা করুন।</div>');
            btn.html(originalText).prop('disabled', false);
        }
    });
});
</script>

</body>
</html>