<?php
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}
// Robust path for DB config
$db_path = dirname(__DIR__) . '/config/db.php';
if (file_exists($db_path)) {
    require_once $db_path;
} else {
    // Fallback for different environments if needed
    require_once 'config/db.php';
}

// Fetch settings
$settings = [];
if (isset($conn)) {
    try {
        $stmt = $conn->prepare("SELECT * FROM settings LIMIT 1");
        if ($stmt) {
            $stmt->execute();
            $res = $stmt->get_result();
            if ($res) {
                $db_settings = $res->fetch_assoc();
                if ($db_settings) {
                    $settings = $db_settings;
                }
            }
        }
    } catch (Exception $e) {
        // Fallback
    }
}
if (isset($settings['whatsapp_number'])) {
    // Strip non-numeric characters (like spaces, +, -, and brackets) for WhatsApp API
    $settings['whatsapp_number'] = preg_replace('/[^0-9]/', '', (string)$settings['whatsapp_number']);
}
if (empty($settings['whatsapp_number'])) {
    $settings['whatsapp_number'] = '94771957420';
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= $settings['site_name'] ?? 'Methsisila' ?></title>
    <!-- Bootstrap & FontAwesome -->
    <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">
    <!-- Premium Fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&family=Poppins:wght@700;800&display=swap" rel="stylesheet">
    <!-- Animation Libs -->
    <link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/ScrollTrigger.min.js"></script>
    <!-- Custom Design System -->
    <link rel="stylesheet" href="assets/css/style.css">
    <link rel="stylesheet" href="assets/css/index-pro.css">
    <style>
        .reveal-up { opacity: 0; transform: translateY(50px); }
        .reveal-left { opacity: 0; transform: translateX(-50px); }
        .reveal-right { opacity: 0; transform: translateX(50px); }
        .reveal-zoom { opacity: 0; transform: scale(0.8); }
        .reveal-rotate-left { opacity: 0; }
    </style>
</head>
<body>
