<?php
@session_start();
include('./includes/config.php');

// Check registration status
checkRegisterStatus();

$R = '';
if (!empty($_GET['ref'])) {
    $R = base64_decode(mysqli_real_escape_string($tng_conn, $_GET['ref']));
}

$domain = $_SERVER['SERVER_NAME'];

function processRegistration($P, $tng_conn, $R, $domain) {
    $N   = mysqli_real_escape_string($tng_conn, $P['name']);
    $E   = mysqli_real_escape_string($tng_conn, $P['email']);
    $M   = mysqli_real_escape_string($tng_conn, $P['phone']);
    $T   = mysqli_real_escape_string($tng_conn, $P['usertype']);
    $PW  = $P['password'];
    $CPW = $P['cpassword'];

    // Phone number validation
    $normalizedPhone = preg_replace('/\D+/', '', $M);
    if (!preg_match('/^[6-9][0-9]{9}$/', $normalizedPhone)) {
        echo '<script>
            document.addEventListener("DOMContentLoaded", function(){
                Swal.fire("Invalid Mobile", "Please enter a valid 10-digit mobile number", "error");
            });
        </script>';
        return false;
    }
    $M = $normalizedPhone;

    // Prevent admin registration
    if (strtolower($T) == "admin") {
        echo '<script>
            document.addEventListener("DOMContentLoaded", function(){
                Swal.fire("Oops!", "You cannot register as ADMIN!", "error");
            });
        </script>';
        return false;
    }

    // Check if user already exists
    if (mysqli_num_rows(mysqli_query($tng_conn, "SELECT id FROM users WHERE phone='$M' OR email='$E'")) > 0) {
        echo '<script>
            document.addEventListener("DOMContentLoaded", function(){
                Swal.fire("Oops!", "Email or Phone already exists!", "error");
            });
        </script>';
        return false;
    }

    // Password match check
    if ($PW !== $CPW) {
        echo '<script>
            document.addEventListener("DOMContentLoaded", function(){
                Swal.fire("Oops!", "Password and Confirm Password do not match!", "error");
            });
        </script>';
        return false;
    }

    // Check OTP system setting from database
    $otp_system_setting = XyZ_val('otp_option');
    
    // If OTP system is enabled in admin panel
    if (strtolower($otp_system_setting) == "yes") {
        // Generate OTP
        $O = rand(100000, 999999);
        $_SESSION['s_otp']  = $O;
        $_SESSION['s_data'] = [
            'n' => $N, 
            'e' => $E, 
            'p' => $M, 
            't' => $T, 
            'r' => $R, 
            'pw' => $PW
        ];
        $_SESSION['otp_time'] = time();

        $msg = "🔑 Hello $N!\n\nYour OTP for registration is: $O\n\n⏱️ It is valid for 5 minutes only.\n\n🌐 Login at: $domain";
        $ftr = strtoupper($_SERVER['SERVER_NAME']);
        
        // Send WhatsApp message
        if(function_exists('sendWhatsAppMessage')) {
            sendWhatsAppMessage($M, $msg, $ftr);
        }
        
        // Send email
        if(function_exists('sendregisterOtpEmail')) {
            sendregisterOtpEmail($E, $N, $O, $domain);
        }

        echo '<script>
            document.addEventListener("DOMContentLoaded", function(){
                Swal.fire({
                    title: "OTP Sent!",
                    html: "Enter OTP sent to your phone and email:",
                    input: "text",
                    inputLabel: "6-digit OTP",
                    inputPlaceholder: "Enter OTP",
                    confirmButtonText: "Verify",
                    showCancelButton: true,
                    allowOutsideClick: false,
                    inputValidator: (value) => {
                        if (!value) {
                            return "Please enter OTP";
                        }
                        if (value.length !== 6) {
                            return "OTP must be 6 digits";
                        }
                    }
                }).then((result) => {
                    if (result.isConfirmed) {
                        const form = document.createElement("form");
                        form.method = "POST";
                        form.action = "";
                        
                        const otpInput = document.createElement("input");
                        otpInput.type = "hidden";
                        otpInput.name = "v_otp";
                        otpInput.value = result.value;
                        
                        form.appendChild(otpInput);
                        document.body.appendChild(form);
                        form.submit();
                    }
                });
            });
        </script>';
        return true;
        
    } else {
        // OTP system disabled - Direct registration
        return directRegistration($N, $E, $M, $T, $PW, $R, $domain, $tng_conn);
    }
}

function directRegistration($N, $E, $M, $T, $PW, $R, $domain, $tng_conn) {
    $VP = password_hash($PW, PASSWORD_DEFAULT);
    $oid = "TNG_" . rand(100000, 999999);
    $dt  = date("Y-m-d H:i:s");
    $payment_status = XyZ_val('payment_status');

    $q = "INSERT INTO `users` (`name`, `phone`, `email`, `password`, `type`, `status`, `referred_by`, `order_id`, `date`, `otp_system`) 
          VALUES ('$N', '$M', '$E', '$VP', '$T', '$payment_status', '$R', '$oid', '$dt', 'no')";
    $res = mysqli_query($tng_conn, $q);

    // Handle referral
    if ($R != '') {
        $ref_bal = "0";
        mysqli_query($tng_conn, "INSERT INTO referal (`phone`, `referred_by`, `txn_no`, `referral_balance`, `status`) 
            VALUES ('$M', '$R', 'REF" . rand(10000, 99999) . "', '$ref_bal', '1')");
    }

    if ($res) {
        $msg2 = "🎉 Welcome, $N! ✅ Your account has been successfully created.\n\n"
               . "👤 Name: $N\n"
               . "🆔 ID/Phone: $M\n"
               . "🔑 Password: $PW\n"
               . "🌐 Login here: $domain\n\n"
               . "🚀 Enjoy our services!";

        $ftr = strtoupper($_SERVER['SERVER_NAME']);
        
        if(function_exists('sendWhatsAppMessage')) {
            sendWhatsAppMessage($M, $msg2, $ftr);
        }
        
        if(function_exists('sendRegistrationEmail')) {
            sendRegistrationEmail($E, $N, $M, $PW, $domain);
        }

        echo '<script>
            document.addEventListener("DOMContentLoaded", function(){
                Swal.fire({
                    title: "Success!",
                    html: "Account created successfully!<br><br>Phone/ID: <b>' . $M . '</b><br>Password: <b>' . $PW . '</b>",
                    icon: "success",
                    confirmButtonText: "Login Now"
                }).then(() => {
                    window.location.href = "login.php";
                });
            });
        </script>';
        return true;
    } else {
        echo '<script>
            document.addEventListener("DOMContentLoaded", function(){
                Swal.fire("Error!", "Something went wrong! Please try again.", "error");
            });
        </script>';
        return false;
    }
}

// Handle form submission
if (!empty($_POST['phone']) && !isset($_POST['v_otp'])) {
    processRegistration($_POST, $tng_conn, $R, $domain);
}

// Handle OTP verification
if (!empty($_POST['v_otp'])) {
    $V = mysqli_real_escape_string($tng_conn, $_POST['v_otp']);
    
    // Check if OTP is valid and not expired (5 minutes)
    if (isset($_SESSION['s_otp']) && $V == $_SESSION['s_otp'] && (time() - $_SESSION['otp_time']) < 300) {
        $D = $_SESSION['s_data'];
        
        $VP = password_hash($D['pw'], PASSWORD_DEFAULT);
        $oid = "TNG_" . rand(100000, 999999);
        $dt = date("Y-m-d H:i:s");
        $payment_status = XyZ_val('payment_status');

        // Insert user with OTP system enabled
        $res = mysqli_query($tng_conn, "INSERT INTO `users` (`name`, `phone`, `email`, `password`, `type`, `status`, `referred_by`, `order_id`, `date`, `otp_system`) 
                 VALUES ('" . $D['n'] . "', '" . $D['p'] . "', '" . $D['e'] . "', '$VP', '" . $D['t'] . "', '$payment_status', '" . $D['r'] . "', '$oid', '$dt', 'yes')");

        // Handle referral
        if ($D['r'] != '') {
            $ref_bal = "0";
            mysqli_query($tng_conn, "INSERT INTO referal (`phone`, `referred_by`, `txn_no`, `referral_balance`, `status`) 
                VALUES ('" . $D['p'] . "', '" . $D['r'] . "', 'REF" . rand(10000, 99999) . "', '$ref_bal', '1')");
        }

        if ($res) {
            $msg2 = "🥳 Hey " . $D['n'] . "! Your account is ready to use.\n\n"
                   . "📲 ID: " . $D['p'] . "\n"
                   . "🔐 Password: " . $D['pw'] . "\n"
                   . "🌍 Login at: $domain\n\n"
                   . "💡 Keep your credentials safe!";
            
            $ftr = strtoupper($_SERVER['SERVER_NAME']);
            
            if(function_exists('sendWhatsAppMessage')) {
                sendWhatsAppMessage($D['p'], $msg2, $ftr);
            }
            
            if(function_exists('sendRegistrationEmail')) {
                sendRegistrationEmail($D['e'], $D['n'], $D['p'], $D['pw'], $domain);
            }

            echo '<script>
                document.addEventListener("DOMContentLoaded", function(){
                    Swal.fire({
                        title: "Success!",
                        text: "Account created successfully!",
                        icon: "success",
                        confirmButtonText: "Login Now"
                    }).then(() => {
                        window.location.href = "login.php";
                    });
                });
            </script>';
        } else {
            echo '<script>
                document.addEventListener("DOMContentLoaded", function(){
                    Swal.fire("Error!", "Something went wrong! Please try again.", "error");
                });
            </script>';
        }
        
        // Clear session data
        unset($_SESSION['s_otp'], $_SESSION['s_data'], $_SESSION['otp_time']);
    } else {
        echo '<script>
            document.addEventListener("DOMContentLoaded", function(){
                Swal.fire("Invalid OTP", "Entered OTP is incorrect or expired.", "error");
            });
        </script>';
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" href="./template/tngweb/assets/images/favicon-32x32.png" type="image/png" />
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <link href='https://unpkg.com/boxicons@2.1.4/css/boxicons.min.css' rel='stylesheet'>
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11.4.14/dist/sweetalert2.all.min.js"></script>
    <script disable-devtool-auto src='https://cdn.jsdelivr.net/npm/disable-devtool@latest'></script>
    <title><?php echo XyZ_val('brand'); ?> | <?php echo XyZ_val('title'); ?></title>
    
    <!-- ========== ENHANCED MODERN CSS (preserves all original classes) ========== -->
    <style>
        /* Reset & Base */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body {
            font-family: 'Poppins', sans-serif;
            background: linear-gradient(135deg, #0f0c29 0%, #302b63 50%, #24243e 100%);
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            position: relative;
            overflow-x: hidden;
        }
        /* Animated Background Shapes */
        .bg-shape {
            position: fixed;
            filter: blur(80px);
            opacity: 0.35;
            z-index: 0;
            border-radius: 50%;
            animation: floatBg 18s infinite ease-in-out;
            pointer-events: none;
        }
        .shape-1 { top: -150px; left: -150px; width: 400px; height: 400px; background: radial-gradient(circle, #00ffff, #0080ff); }
        .shape-2 { bottom: -120px; right: -120px; width: 500px; height: 500px; background: radial-gradient(circle, #ff00ff, #ff0080); animation-delay: -6s; }
        .shape-3 { top: 40%; left: -80px; width: 300px; height: 300px; background: radial-gradient(circle, #ffd700, #ff6600); animation-delay: -12s; }
        @keyframes floatBg {
            0% { transform: translate(0, 0) scale(1); }
            50% { transform: translate(40px, 30px) scale(1.1); }
            100% { transform: translate(0, 0) scale(1); }
        }
        
        /* Navbar - original classes, upgraded look */
        .navbar {
            position: relative;
            z-index: 100;
            background: rgba(15, 12, 41, 0.7);
            backdrop-filter: blur(12px);
            border-bottom: 1px solid rgba(255,255,255,0.1);
            padding: 1rem 2rem;
        }
        .nav-container {
            max-width: 1300px;
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
        }
        .logo {
            display: flex;
            align-items: center;
            gap: 12px;
            font-size: 1.5rem;
            font-weight: 700;
            color: white;
            text-decoration: none;
            letter-spacing: -0.5px;
        }
        .logo img {
            height: 40px;
            width: auto;
            filter: drop-shadow(0 2px 5px rgba(0,0,0,0.2));
        }
        .mobile-toggle {
            display: none;
            background: none;
            border: none;
            color: white;
            font-size: 1.8rem;
            cursor: pointer;
        }
        .nav-links {
            display: flex;
            gap: 2rem;
            list-style: none;
            align-items: center;
        }
        .nav-links li a {
            color: rgba(255,255,255,0.85);
            text-decoration: none;
            font-weight: 500;
            transition: 0.2s;
            font-size: 0.95rem;
            padding: 0.5rem 0;
        }
        .nav-links li a:hover {
            color: white;
            text-shadow: 0 0 6px rgba(255,255,255,0.5);
        }
        .nav-links li a.active {
            color: #c084fc;
            border-bottom: 2px solid #c084fc;
        }
        @media (max-width: 768px) {
            .navbar { padding: 0.8rem 1.2rem; }
            .mobile-toggle { display: block; }
            .nav-links {
                display: none;
                width: 100%;
                flex-direction: column;
                gap: 1rem;
                padding: 1.2rem 0 0.5rem;
            }
            .nav-links.active {
                display: flex;
            }
            .nav-links li a {
                display: block;
                padding: 0.5rem;
                text-align: center;
            }
        }
        
        /* Registration Container & Card - enhanced glassmorphism */
        .register-container {
            flex: 1;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 2rem 1.5rem;
            position: relative;
            z-index: 10;
        }
        .register-card {
            background: rgba(255, 255, 255, 0.07);
            backdrop-filter: blur(14px);
            border-radius: 2rem;
            border: 1px solid rgba(255, 255, 255, 0.2);
            box-shadow: 0 25px 45px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255,255,255,0.1);
            padding: 2rem;
            width: 100%;
            max-width: 600px;
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
        }
        .register-card:hover {
            transform: translateY(-4px);
            box-shadow: 0 30px 55px rgba(0, 0, 0, 0.4);
        }
        /* Shine effect on card */
        .register-card::before {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg, transparent, rgba(255,255,255,0.12), transparent);
            transition: left 0.5s;
            pointer-events: none;
        }
        .register-card:hover::before {
            left: 100%;
        }
        
        .register-header {
            text-align: center;
            margin-bottom: 1.8rem;
        }
        .register-header h1 {
            font-size: 2rem;
            font-weight: 700;
            background: linear-gradient(135deg, #fff, #c084fc);
            -webkit-background-clip: text;
            background-clip: text;
            color: transparent;
            margin-bottom: 0.3rem;
        }
        .register-header p {
            color: rgba(255,255,255,0.7);
            font-size: 0.85rem;
        }
        
        .form-row {
            display: flex;
            gap: 1rem;
            margin-bottom: 0;
        }
        .form-col {
            flex: 1;
        }
        .form-group {
            margin-bottom: 1.3rem;
        }
        .form-label {
            display: block;
            color: rgba(255,255,255,0.9);
            font-weight: 500;
            font-size: 0.8rem;
            margin-bottom: 0.5rem;
            letter-spacing: 0.5px;
        }
        .form-control, .form-select {
            width: 100%;
            background: rgba(255,255,255,0.1);
            border: 1px solid rgba(255,255,255,0.2);
            border-radius: 1.2rem;
            padding: 0.85rem 1rem;
            font-size: 0.9rem;
            color: white;
            font-weight: 500;
            transition: 0.2s;
            outline: none;
            font-family: 'Poppins', sans-serif;
        }
        .form-select option {
            background: #1e1b4b;
            color: white;
        }
        .form-control:focus, .form-select:focus {
            border-color: rgba(255,255,255,0.6);
            background: rgba(255,255,255,0.15);
            box-shadow: 0 0 10px rgba(255,255,255,0.15);
        }
        .form-control::placeholder {
            color: rgba(255,255,255,0.4);
        }
        /* Password input wrapper */
        .password-input {
            position: relative;
            display: flex;
            align-items: center;
        }
        .password-input .form-control {
            padding-right: 2.8rem;
        }
        .toggle-password {
            position: absolute;
            right: 1rem;
            background: none;
            border: none;
            color: rgba(255,255,255,0.6);
            cursor: pointer;
            font-size: 1.2rem;
            display: flex;
            align-items: center;
            transition: 0.2s;
        }
        .toggle-password:hover {
            color: white;
        }
        
        .register-btn {
            width: 100%;
            background: linear-gradient(95deg, #7c3aed, #a855f7);
            border: none;
            border-radius: 1.8rem;
            padding: 0.85rem;
            font-weight: 700;
            font-size: 0.95rem;
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 0.5rem;
            cursor: pointer;
            transition: 0.2s;
            position: relative;
            overflow: hidden;
            box-shadow: 0 6px 18px rgba(124,58,237,0.3);
        }
        .register-btn:hover {
            transform: scale(1.02);
            box-shadow: 0 8px 22px rgba(124,58,237,0.5);
        }
        .login-link {
            text-align: center;
            margin-top: 1.3rem;
            font-size: 0.8rem;
            color: rgba(255,255,255,0.7);
        }
        .login-link a {
            color: #c084fc;
            text-decoration: none;
            font-weight: 600;
        }
        .login-link a:hover {
            text-shadow: 0 0 5px #c084fc;
        }
        
        /* Footer */
        .footer {
            text-align: center;
            padding: 1.2rem;
            font-size: 0.7rem;
            color: rgba(255,255,255,0.4);
            z-index: 10;
            position: relative;
        }
        .container {
            max-width: 1200px;
            margin: 0 auto;
        }
        
        /* Alert container (if any) */
        .alert-container {
            position: fixed;
            top: 20px;
            right: 20px;
            z-index: 1000;
        }
        .alert {
            background: rgba(0,0,0,0.8);
            backdrop-filter: blur(8px);
            border-radius: 1rem;
            padding: 0.8rem 1.2rem;
            color: white;
            margin-bottom: 0.5rem;
            animation: slideIn 0.3s ease;
        }
        @keyframes slideIn {
            from { transform: translateX(100%); opacity: 0; }
            to { transform: translateX(0); opacity: 1; }
        }
        
        /* Responsive adjustments */
        @media (max-width: 600px) {
            .form-row {
                flex-direction: column;
                gap: 0;
            }
            .register-card {
                padding: 1.5rem;
            }
        }
    </style>
</head>

<body>
    <!-- Animated background shapes (added for glamour, does not affect functionality) -->
    <div class="bg-shape shape-1"></div>
    <div class="bg-shape shape-2"></div>
    <div class="bg-shape shape-3"></div>

    <!-- Alert Container for PHP messages -->
    <?php if (isset($show_alert) && $show_alert): ?>
    <div class="alert-container">
        <div class="alert alert-<?php echo $alert_type; ?>">
            <?php echo $alert_message; ?>
        </div>
    </div>
    <?php endif; ?>

    <!-- Navigation -->
    <nav class="navbar">
        <div class="nav-container">
            <a href="index.php" class="logo">
                <img src="<?php echo XyZ_val('logo'); ?>" alt="Logo">
                <?php echo XyZ_val('brand'); ?>
            </a>
            
            <button class="mobile-toggle" id="mobileToggle">
                <i class='bx bx-menu'></i>
            </button>
            
            <ul class="nav-links" id="navLinks">
                <li><a href="index.php">Home</a></li>
                <li><a href="register.php" class="active">Register</a></li>
                <li><a href="Forgot-password.php">Forgot Password</a></li>
                <li><a href="contact.php">Contact</a></li>
            </ul>
        </div>
    </nav>

    <!-- Registration Content -->
    <div class="register-container">
        <div class="register-card">
            <div class="register-header">
                <h1>Create Account</h1>
                <p>Join us and start your journey</p>
            </div>
            
            <div class="register-body">
                <form method="POST" action="" id="registerForm">
                    <div class="form-row">
                        <div class="form-col">
                            <div class="form-group">
                                <label for="inputFirstName" class="form-label">Full Name *</label>
                                <input required name="name" type="text" class="form-control" id="inputFirstName" placeholder="Enter Your Name" value="<?php echo isset($_POST['name']) ? htmlspecialchars($_POST['name']) : ''; ?>">
                            </div>
                        </div>
                        <div class="form-col">
                            <div class="form-group">
                                <label for="inputLastName" class="form-label">Phone *</label>
                                <input required maxlength="10" name="phone" type="text" class="form-control" id="inputLastName" placeholder="Phone Number" value="<?php echo isset($_POST['phone']) ? htmlspecialchars($_POST['phone']) : ''; ?>">
                            </div>
                        </div>
                    </div>
                    
                    <div class="form-group">
                        <label for="inputEmailAddress" class="form-label">Email Address *</label>
                        <input required name="email" type="email" class="form-control" id="inputEmailAddress" placeholder="example@user.com" value="<?php echo isset($_POST['email']) ? htmlspecialchars($_POST['email']) : ''; ?>">
                    </div>
                    
                    <div class="form-group">
                        <label for="inputSelectCountry" class="form-label">User Type *</label>
                        <select required name="usertype" class="form-select" id="inputSelectCountry">
                            <option value="">Please Select</option>
                            <option value="retailer" <?php echo (isset($_POST['usertype']) && $_POST['usertype'] == 'retailer') ? 'selected' : ''; ?>>Retailer</option>
                            <option value="distributor" <?php echo (isset($_POST['usertype']) && $_POST['usertype'] == 'distributor') ? 'selected' : ''; ?>>Distributor</option>
                        </select>
                    </div>
                    
                    <div class="form-row">
                        <div class="form-col">
                            <div class="form-group">
                                <label for="inputChoosePassword" class="form-label">Password *</label>
                                <div class="password-input">
                                    <input required name="password" type="password" class="form-control" id="inputChoosePassword" placeholder="Enter Password">
                                    <button type="button" class="toggle-password" data-target="inputChoosePassword">
                                        <i class='bx bx-hide'></i>
                                    </button>
                                </div>
                            </div>
                        </div>
                        <div class="form-col">
                            <div class="form-group">
                                <label for="inputConfirmPassword" class="form-label">Confirm Password *</label>
                                <div class="password-input">
                                    <input required name="cpassword" type="password" class="form-control" id="inputConfirmPassword" placeholder="Confirm Password">
                                    <button type="button" class="toggle-password" data-target="inputConfirmPassword">
                                        <i class='bx bx-hide'></i>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <button type="submit" class="register-btn" id="submitBtn">
                        <i class='bx bx-user'></i> Create Account
                    </button>
                    
                    <div class="login-link">
                        Already have an account? <a href="login.php">Login Here</a>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <!-- Footer -->
    <footer class="footer">
        <div class="container">
            <p>&copy; <?php echo date("Y"); ?> <?php echo strtoupper($_SERVER['SERVER_NAME']); ?>. All rights reserved.</p>
        </div>
    </footer>

    <script>
        // Mobile menu toggle
        document.getElementById('mobileToggle').addEventListener('click', function() {
            document.getElementById('navLinks').classList.toggle('active');
        });
        
        // Password visibility toggle
        document.querySelectorAll('.toggle-password').forEach(button => {
            button.addEventListener('click', function() {
                const targetId = this.getAttribute('data-target');
                const passwordInput = document.getElementById(targetId);
                const icon = this.querySelector('i');
                
                if (passwordInput.type === 'password') {
                    passwordInput.type = 'text';
                    icon.classList.remove('bx-hide');
                    icon.classList.add('bx-show');
                } else {
                    passwordInput.type = 'password';
                    icon.classList.remove('bx-show');
                    icon.classList.add('bx-hide');
                }
            });
        });
        
        // Close mobile menu when clicking outside
        document.addEventListener('click', function(event) {
            const navLinks = document.getElementById('navLinks');
            const mobileToggle = document.getElementById('mobileToggle');
            
            if (!mobileToggle.contains(event.target) && !navLinks.contains(event.target)) {
                navLinks.classList.remove('active');
            }
        });
        
        // Phone number validation (only numbers)
        document.getElementById('inputLastName').addEventListener('input', function(e) {
            this.value = this.value.replace(/[^0-9]/g, '');
        });
        
        // Form submission handling
        document.getElementById('registerForm').addEventListener('submit', function(e) {
            const submitBtn = document.getElementById('submitBtn');
            const originalText = submitBtn.innerHTML;
            
            // Show loading state
            submitBtn.innerHTML = '<i class="bx bx-loader-alt bx-spin"></i> Creating Account...';
            submitBtn.disabled = true;
            
            // Allow form to submit normally
        });
        
        // Auto-hide alerts after 5 seconds
        window.addEventListener('load', function() {
            const alerts = document.querySelectorAll('.alert');
            alerts.forEach(alert => {
                setTimeout(() => {
                    alert.style.animation = 'slideIn 0.3s ease reverse';
                    setTimeout(() => {
                        alert.style.display = 'none';
                    }, 300);
                }, 5000);
            });
        });
    </script>
</body>
</html>