<?php
session_start();

// Handle referral code from URL or cookie
$refCode = $_GET['ref'] ?? $_COOKIE['referral_code'] ?? null;
if ($refCode) {
    $_SESSION['pending_referral'] = $refCode;
    setcookie('referral_code', $refCode, time() + (86400 * 30), '/');
}

// Generate a simple 6-character text captcha
if (!isset($_SESSION['captcha_code'])) {
    $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
    $_SESSION['captcha_code'] = substr(str_shuffle($chars), 0, 6);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>Register - Theinteractivebrokers</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    
    <style>
        :root {
            --primary-color: #4f46e5;
            --success-color: #10b981;
            --bg-body: #0b111a;
            --bg-card: #121a24;
            --bg-step: #1a2235;
            --text-main: #ffffff;
            --text-muted: #8b9bb4;
            --input-bg: #1c2635;
            --border-color: #2a3749;
            --referral-glow: rgba(79, 70, 229, 0.3);
        }

        body.light-mode {
            --bg-body: #f3f4f6;
            --bg-card: #ffffff;
            --bg-step: #e5e7eb;
            --text-main: #111827;
            --text-muted: #6b7280;
            --input-bg: #f9fafb;
            --border-color: #d1d5db;
            --referral-glow: rgba(79, 70, 229, 0.15);
        }

        * { 
            box-sizing: border-box; 
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
            -webkit-tap-highlight-color: transparent;
        }
        
        body {
            background-color: var(--bg-body);
            color: var(--text-main);
            display: flex;
            justify-content: center;
            align-items: flex-start;
            min-height: 100vh;
            margin: 0;
            padding: 15px;
            transition: all 0.3s ease;
        }

        .theme-toggle { 
            position: fixed; 
            top: 15px; 
            right: 15px; 
            cursor: pointer; 
            font-size: 1.2rem; 
            color: var(--text-muted); 
            z-index: 100;
            background: var(--bg-card);
            width: 40px;
            height: 40px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            border: 1px solid var(--border-color);
        }
        
        .translator-container { 
            position: fixed; 
            bottom: 15px; 
            left: 15px; 
            background: var(--bg-card); 
            padding: 5px; 
            border-radius: 5px; 
            border: 1px solid var(--border-color); 
            z-index: 100;
        }

        .register-card {
            background-color: var(--bg-card);
            padding: 25px;
            border-radius: 16px;
            width: 100%;
            max-width: 600px;
            border: 1px solid var(--border-color);
            box-shadow: 0 10px 40px rgba(0,0,0,0.3);
            margin-top: 10px;
            margin-bottom: 20px;
        }

        .header-text { text-align: center; margin-bottom: 25px; }
        .header-text img { height: 35px; margin-bottom: 12px; }
        .header-text h1 { font-size: 1.4rem; margin: 0 0 6px; }
        .header-text h1 span { color: var(--primary-color); }
        .header-text p { color: var(--text-muted); font-size: 0.9rem; margin: 0; }

        /* Referral Badge */
        .referral-badge {
            background: linear-gradient(135deg, rgba(79, 70, 229, 0.15), rgba(139, 92, 246, 0.1));
            border: 1px solid rgba(79, 70, 229, 0.3);
            border-radius: 12px;
            padding: 12px 14px;
            margin-bottom: 20px;
            display: flex;
            align-items: center;
            gap: 10px;
            animation: referralPulse 2s ease-in-out infinite;
            flex-wrap: wrap;
        }
        
        @keyframes referralPulse {
            0%, 100% { box-shadow: 0 0 0 0 var(--referral-glow); }
            50% { box-shadow: 0 0 20px 5px var(--referral-glow); }
        }
        
        .referral-badge i {
            font-size: 1.3rem;
            color: #818cf8;
        }
        
        .referral-badge .ref-info h4 {
            margin: 0;
            font-size: 0.8rem;
            color: #818cf8;
        }
        
        .referral-badge .ref-info p {
            margin: 2px 0 0;
            font-size: 0.7rem;
            color: var(--text-muted);
        }
        
        .referral-badge .ref-code {
            margin-left: auto;
            background: rgba(79, 70, 229, 0.2);
            padding: 4px 10px;
            border-radius: 6px;
            font-family: monospace;
            font-size: 0.8rem;
            font-weight: bold;
            color: #a5b4fc;
            border: 1px dashed rgba(129, 140, 248, 0.4);
        }

        /* Step Indicators */
        .stepper { 
            display: flex; 
            justify-content: space-between; 
            position: relative; 
            margin-bottom: 25px; 
        }
        .stepper::before {
            content: ''; 
            position: absolute; 
            top: 15px; 
            left: 0; 
            width: 100%; 
            height: 2px;
            background: var(--border-color); 
            z-index: 1;
        }
        .step { 
            position: relative; 
            z-index: 2; 
            text-align: center; 
            width: 33%; 
        }
        .step .circle {
            width: 32px; 
            height: 32px; 
            background: var(--bg-card); 
            border: 2px solid var(--border-color);
            border-radius: 50%; 
            display: flex; 
            align-items: center; 
            justify-content: center;
            margin: 0 auto 5px; 
            font-weight: bold; 
            font-size: 0.85rem;
            color: var(--text-muted); 
            transition: all 0.3s;
        }
        .step.active .circle { 
            background: var(--primary-color); 
            border-color: var(--primary-color); 
            color: #fff; 
        }
        .step.completed .circle { 
            background: var(--success-color); 
            border-color: var(--success-color); 
            color: #fff; 
        }
        .step p { 
            margin: 0; 
            font-size: 0.75rem; 
            font-weight: bold; 
        }
        .step span { 
            display: none; 
        }

        /* Form Steps */
        .form-step { 
            display: none; 
            animation: fadeIn 0.4s ease; 
        }
        .form-step.active { 
            display: block; 
        }
        @keyframes fadeIn { 
            from { opacity: 0; transform: translateY(10px); } 
            to { opacity: 1; transform: translateY(0); } 
        }

        .step-title-box { 
            background: var(--bg-step); 
            padding: 14px; 
            border-radius: 12px; 
            margin-bottom: 20px; 
            display: flex; 
            align-items: center; 
            gap: 12px; 
            border: 1px solid var(--border-color); 
        }
        .step-title-box i { 
            font-size: 1.3rem; 
            color: var(--primary-color); 
            flex-shrink: 0;
        }
        .step-title-box h3 { 
            margin: 0 0 3px; 
            font-size: 1rem; 
        }
        .step-title-box p { 
            margin: 0; 
            font-size: 0.8rem; 
            color: var(--text-muted); 
        }

        /* ===== FIXED INPUT STYLES FOR MOBILE ===== */
        .input-grid { 
            display: grid; 
            grid-template-columns: 1fr; 
            gap: 16px; 
            margin-bottom: 20px; 
        }
        
        .form-group {
            width: 100%;
        }
        
        .form-group label { 
            display: block; 
            font-size: 0.9rem; 
            margin-bottom: 8px; 
            color: var(--text-main); 
            font-weight: 500;
        }
        .form-group label span { 
            color: #ef4444; 
        }
        
        .input-wrapper { 
            display: flex; 
            align-items: center; 
            background: var(--input-bg); 
            border: 2px solid var(--border-color); 
            border-radius: 12px; 
            overflow: hidden;
            width: 100%;
            min-height: 52px;
            transition: border-color 0.3s, box-shadow 0.3s;
        }
        
        .input-wrapper:focus-within {
            border-color: var(--primary-color);
            box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1);
        }
        
        .input-wrapper i { 
            padding: 0 14px; 
            color: var(--text-muted); 
            font-size: 1rem;
            flex-shrink: 0;
        }
        
        .input-wrapper input, 
        .input-wrapper select { 
            flex: 1; 
            background: transparent; 
            border: none; 
            padding: 14px 12px; 
            color: var(--text-main); 
            outline: none; 
            width: 100%; 
            font-size: 1rem;
            min-height: 48px;
            -webkit-appearance: none;
            appearance: none;
        }
        
        .input-wrapper select {
            cursor: pointer;
            background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%238b9bb4' viewBox='0 0 16 16'%3E%3Cpath d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E");
            background-repeat: no-repeat;
            background-position: right 14px center;
            padding-right: 40px;
        }

        /* Specific UI Elements */
        .info-box { 
            background: rgba(14, 165, 233, 0.1); 
            border: 1px solid #0ea5e9; 
            padding: 14px; 
            border-radius: 12px; 
            font-size: 0.85rem; 
            color: var(--text-muted); 
            margin-bottom: 20px; 
            line-height: 1.5; 
        }
        .info-box i { 
            color: #0ea5e9; 
            margin-right: 5px; 
        }

        .captcha-box { 
            background: #1a1a2e; 
            text-align: center; 
            padding: 18px; 
            border-radius: 12px; 
            letter-spacing: 8px; 
            font-size: 1.5rem; 
            font-weight: bold; 
            color: #facc15; 
            margin-bottom: 12px; 
            border: 2px dashed var(--border-color); 
            user-select: none;
        }
        
        .password-req { 
            background: var(--bg-step); 
            padding: 16px; 
            border-radius: 12px; 
            font-size: 0.85rem; 
            color: var(--text-muted); 
            margin-bottom: 20px; 
            border: 1px solid var(--border-color); 
        }
        .password-req p { 
            margin: 0 0 10px; 
            font-weight: bold; 
            color: var(--text-main); 
            font-size: 0.9rem;
        }
        .password-req ul { 
            margin: 0; 
            padding-left: 20px; 
        }
        .password-req ul li { 
            margin-bottom: 6px; 
            line-height: 1.4;
        }

        .terms-box { 
            background: var(--bg-step); 
            padding: 16px; 
            border-radius: 12px; 
            font-size: 0.85rem; 
            color: var(--text-muted); 
            margin-bottom: 20px; 
            display: flex; 
            gap: 12px; 
            align-items: flex-start; 
            border: 1px solid var(--border-color); 
            line-height: 1.5;
        }
        .terms-box input[type="checkbox"] {
            width: 20px;
            height: 20px;
            min-width: 20px;
            margin-top: 2px;
            cursor: pointer;
            accent-color: var(--primary-color);
        }
        .terms-box a { 
            color: var(--primary-color); 
            text-decoration: none; 
            font-weight: 600;
        }
        
        /* Buttons */
        .btn-controls { 
            display: flex; 
            justify-content: space-between; 
            align-items: center; 
            margin-top: 20px; 
            padding-top: 20px; 
            border-top: 1px solid var(--border-color); 
            gap: 10px;
            flex-wrap: wrap;
        }
        .step-counter { 
            font-size: 0.85rem; 
            color: var(--text-muted); 
            width: 100%;
            text-align: center;
            order: 3;
            margin-top: 8px;
        }
        
        .btn { 
            padding: 14px 24px; 
            border-radius: 12px; 
            font-weight: 600; 
            cursor: pointer; 
            border: none; 
            font-size: 1rem; 
            transition: all 0.3s; 
            min-height: 52px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
        }
        .btn-primary { 
            background: var(--primary-color); 
            color: #fff; 
            flex: 1;
        }
        .btn-primary:hover {
            filter: brightness(1.1);
            transform: translateY(-1px);
        }
        .btn-primary:active {
            transform: translateY(0);
        }
        .btn-success { 
            background: var(--success-color); 
            color: #fff; 
            width: 100%; 
            display: flex; 
            justify-content: center; 
            align-items: center; 
            gap: 10px; 
            padding: 16px;
            font-size: 1.05rem;
            margin-top: 15px;
        }
        .btn-success:hover {
            filter: brightness(1.1);
        }
        .btn-back { 
            background: transparent; 
            color: var(--text-muted); 
            border: 2px solid var(--border-color);
            flex: 1;
        }
        .btn-back:hover { 
            color: var(--text-main); 
            border-color: var(--text-muted);
        }

        .footer-links { 
            text-align: center; 
            margin-top: 25px; 
            font-size: 0.9rem; 
        }
        .footer-links a { 
            color: var(--primary-color); 
            text-decoration: none; 
            font-weight: 600;
        }
        .security-footer { 
            display: flex; 
            justify-content: center; 
            gap: 15px; 
            margin-top: 15px; 
            font-size: 0.75rem; 
            color: var(--text-muted); 
            flex-wrap: wrap;
        }
        
        /* SweetAlert2 Dark Mode Override */
        .swal2-popup {
            background: var(--bg-card) !important;
            color: var(--text-main) !important;
            border: 1px solid var(--border-color) !important;
        }
        .swal2-title, .swal2-html-container {
            color: var(--text-main) !important;
        }

        /* ===== DESKTOP BREAKPOINTS ===== */
        @media (min-width: 640px) {
            body {
                align-items: center;
                padding: 20px;
            }
            
            .register-card {
                padding: 40px;
                border-radius: 16px;
            }
            
            .header-text h1 {
                font-size: 1.6rem;
            }
            
            .input-grid {
                grid-template-columns: 1fr 1fr;
                gap: 20px;
            }
            
            .step span {
                display: block;
                font-size: 0.7rem;
                color: var(--text-muted);
            }
            
            .step p {
                font-size: 0.8rem;
            }
            
            .referral-badge {
                padding: 14px 18px;
            }
            
            .referral-badge .ref-info h4 {
                font-size: 0.9rem;
            }
            
            .referral-badge .ref-info p {
                font-size: 0.8rem;
            }
            
            .referral-badge .ref-code {
                font-size: 0.9rem;
                padding: 6px 14px;
            }
            
            .step-counter {
                width: auto;
                order: 0;
                margin-top: 0;
            }
            
            .btn {
                padding: 12px 24px;
                min-height: 48px;
            }
            
            .btn-primary, .btn-back {
                flex: 0 0 auto;
            }
        }
        
        @media (min-width: 768px) {
            .register-card {
                max-width: 650px;
            }
        }
    </style>
</head>
<body>

    <div class="theme-toggle" onclick="toggleTheme()">
        <i class="fa-solid fa-moon" id="theme-icon"></i>
    </div>
    
    <div class="translator-container">
        <div id="google_translate_element"></div>
    </div>

    <div class="register-card">
        
        <div class="header-text">
            <img src="account/logo.png" alt="Logo">
            <h1>Join <span>Theinteractivebrokers</span></h1>
            <p>Start your professional trading journey</p>
        </div>

        <?php if (isset($_SESSION['pending_referral']) || isset($_GET['ref'])): 
            $displayRef = $_GET['ref'] ?? $_SESSION['pending_referral'] ?? '';
        ?>
        <div class="referral-badge">
            <i class="fa-solid fa-gift"></i>
            <div class="ref-info">
                <h4>You've been invited!</h4>
                <p>Sign up with this referral to earn bonuses</p>
            </div>
            <div class="ref-code"><?= htmlspecialchars($displayRef) ?></div>
        </div>
        <?php endif; ?>

        <div class="stepper">
            <div class="step active" id="indicator-1">
                <div class="circle">1</div>
                <p>Personal Info</p>
                <span>Basic details</span>
            </div>
            <div class="step" id="indicator-2">
                <div class="circle">2</div>
                <p>Location</p>
                <span>Regional settings</span>
            </div>
            <div class="step" id="indicator-3">
                <div class="circle">3</div>
                <p>Security</p>
                <span>Account protection</span>
            </div>
        </div>

        <form action="register_code.php" method="POST" id="registerForm">
            
            <input type="hidden" name="referral_code" value="<?= htmlspecialchars($_GET['ref'] ?? $_SESSION['pending_referral'] ?? '') ?>">
            
            <!-- STEP 1: Personal Info -->
            <div class="form-step active" id="step-1">
                <div class="step-title-box">
                    <i class="fa-solid fa-id-card-clip"></i>
                    <div>
                        <h3>Personal Information</h3>
                        <p>Create your trading profile</p>
                    </div>
                </div>

                <div class="input-grid">
                    <div class="form-group">
                        <label>Trading Username <span>*</span></label>
                        <div class="input-wrapper">
                            <i class="fa-regular fa-user"></i>
                            <input type="text" name="username" placeholder="user123" required autocomplete="username">
                        </div>
                    </div>
                    <div class="form-group">
                        <label>Full Name <span>*</span></label>
                        <div class="input-wrapper">
                            <i class="fa-solid fa-user-plus"></i>
                            <input type="text" name="full_name" placeholder="Enter full name" required autocomplete="name">
                        </div>
                    </div>
                    <div class="form-group">
                        <label>Email Address <span>*</span></label>
                        <div class="input-wrapper">
                            <i class="fa-regular fa-envelope"></i>
                            <input type="email" name="email" placeholder="your.email@example.com" required autocomplete="email">
                        </div>
                    </div>
                    <div class="form-group">
                        <label>Phone Number <span>*</span></label>
                        <div class="input-wrapper">
                            <i class="fa-solid fa-phone"></i>
                            <input type="tel" name="phone" placeholder="+1 (555) 123-4567" required autocomplete="tel">
                        </div>
                    </div>
                </div>

                <div class="btn-controls" style="justify-content: flex-end;">
                    <span class="step-counter">Step 1 of 3</span>
                    <button type="button" class="btn btn-primary" onclick="nextStep(2)">
                        Continue <i class="fa-solid fa-arrow-right"></i>
                    </button>
                </div>
            </div>

            <!-- STEP 2: Location -->
            <div class="form-step" id="step-2">
                <div class="step-title-box">
                    <i class="fa-solid fa-earth-americas"></i>
                    <div>
                        <h3>Location</h3>
                        <p>Set your regional trading preferences</p>
                    </div>
                </div>

                <div class="form-group">
                    <label>Country <span>*</span></label>
                    <div class="input-wrapper">
                        <i class="fa-regular fa-flag"></i>
                        <select name="country" required>
                            <option value="">Select your country</option>
                            <option value="United States">United States</option>
                            <option value="United Kingdom">United Kingdom</option>
                            <option value="Canada">Canada</option>
                            <option value="Nigeria">Nigeria</option>
                            <option value="Australia">Australia</option>
                            <option value="Germany">Germany</option>
                            <option value="France">France</option>
                            <option value="India">India</option>
                            <option value="Brazil">Brazil</option>
                            <option value="South Africa">South Africa</option>
                            <option value="Japan">Japan</option>
                            <option value="Singapore">Singapore</option>
                            <option value="UAE">UAE</option>
                            <option value="Other">Other</option>
                        </select>
                    </div>
                </div>

                <div class="info-box">
                    <i class="fa-solid fa-circle-info"></i> <strong>Regional Trading Information</strong><br>
                    Your location helps us provide region-specific features, compliance, and optimal server connections for faster trading execution.
                </div>

                <div class="btn-controls">
                    <button type="button" class="btn btn-back" onclick="prevStep(1)">
                        <i class="fa-solid fa-arrow-left"></i> Previous
                    </button>
                    <span class="step-counter">Step 2 of 3</span>
                    <button type="button" class="btn btn-primary" onclick="nextStep(3)">
                        Continue <i class="fa-solid fa-arrow-right"></i>
                    </button>
                </div>
            </div>

            <!-- STEP 3: Security -->
            <div class="form-step" id="step-3">
                <div class="step-title-box" style="border-color: var(--success-color);">
                    <i class="fa-solid fa-shield-halved" style="color: var(--success-color);"></i>
                    <div>
                        <h3 style="color: var(--success-color);">Account Security</h3>
                        <p>Secure your trading account</p>
                    </div>
                </div>

                <div class="input-grid">
                    <div class="form-group">
                        <label>Password <span>*</span></label>
                        <div class="input-wrapper">
                            <i class="fa-solid fa-lock"></i>
                            <input type="password" name="password" id="pwd" placeholder="••••••••" required autocomplete="new-password">
                        </div>
                    </div>
                    <div class="form-group">
                        <label>Confirm Password <span>*</span></label>
                        <div class="input-wrapper">
                            <i class="fa-solid fa-key"></i>
                            <input type="password" name="cpassword" id="cpwd" placeholder="Confirm your password" required autocomplete="new-password">
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <label>Security Verification <span>*</span></label>
                    <div class="captcha-box"><?php echo $_SESSION['captcha_code']; ?></div>
                    <div class="input-wrapper">
                        <i class="fa-solid fa-shield"></i>
                        <input type="text" name="captcha" placeholder="ENTER THE CODE ABOVE" required style="text-transform: uppercase; letter-spacing: 2px;">
                    </div>
                </div>

                <div class="password-req">
                    <p>Password Requirements:</p>
                    <ul>
                        <li>At least 8 characters long</li>
                        <li>Contains uppercase and lowercase letters</li>
                        <li>Includes at least one number or special character</li>
                    </ul>
                </div>

                <div class="terms-box">
                    <input type="checkbox" required id="terms">
                    <label for="terms">I agree to Theinteractivebrokers's <a href="#">Terms and Conditions</a> and acknowledge that I have read and understood the <a href="#">Privacy Policy</a>. By creating an account, you confirm you are at least 18 years old.</label>
                </div>

                <div class="btn-controls">
                    <button type="button" class="btn btn-back" onclick="prevStep(2)">
                        <i class="fa-solid fa-arrow-left"></i> Previous
                    </button>
                    <span class="step-counter">Step 3 of 3</span>
                </div>
                
                <button type="submit" name="register" class="btn btn-success">
                    <i class="fa-solid fa-user-plus"></i> Create Trading Account
                </button>
            </div>
        </form>

        <div class="footer-links">
            Already have an account? <a href="login.php">Sign in here</a>
        </div>
        <div class="security-footer">
            <span><i class="fa-solid fa-shield-check"></i> SSL Secured</span>
            <span><i class="fa-solid fa-lock"></i> 256-bit Encryption</span>
            <span><i class="fa-solid fa-building-columns"></i> Regulated</span>
        </div>
    </div>

    <script>
        // Google Translate
        function googleTranslateElementInit() {
            new google.translate.TranslateElement({pageLanguage: 'en', layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, 'google_translate_element');
        }

        // Theme Toggle
        function toggleTheme() {
            const body = document.body;
            const icon = document.getElementById('theme-icon');
            body.classList.toggle('light-mode');
            if (body.classList.contains('light-mode')) {
                icon.classList.replace('fa-moon', 'fa-sun');
            } else {
                icon.classList.replace('fa-sun', 'fa-moon');
            }
        }

        // Form Multi-step Navigation
        function nextStep(step) {
            const currentStepDiv = document.getElementById('step-' + (step - 1));
            const inputs = currentStepDiv.querySelectorAll('input[required], select[required]');
            let isValid = true;
            let firstEmpty = null;
            
            inputs.forEach(input => { 
                if (!input.value.trim()) {
                    isValid = false;
                    if (!firstEmpty) firstEmpty = input;
                    input.closest('.input-wrapper').style.borderColor = '#ef4444';
                } else {
                    input.closest('.input-wrapper').style.borderColor = '';
                }
            });
            
            if (!isValid) {
                Swal.fire({
                    icon: 'warning',
                    title: 'Required Fields',
                    text: 'Please fill in all required fields before continuing.',
                    confirmButtonColor: '#f59e0b',
                    confirmButtonText: 'OK, Got it'
                });
                if (firstEmpty) firstEmpty.focus();
                return;
            }

            document.querySelectorAll('.form-step').forEach(el => el.classList.remove('active'));
            document.getElementById('step-' + step).classList.add('active');
            
            document.getElementById('indicator-' + (step-1)).classList.add('completed');
            document.getElementById('indicator-' + (step)).classList.add('active');
            
            window.scrollTo({ top: 0, behavior: 'smooth' });
        }

        function prevStep(step) {
            document.querySelectorAll('.form-step').forEach(el => el.classList.remove('active'));
            document.getElementById('step-' + step).classList.add('active');
            
            document.getElementById('indicator-' + (step+1)).classList.remove('active');
            document.getElementById('indicator-' + step).classList.remove('completed');
            
            window.scrollTo({ top: 0, behavior: 'smooth' });
        }

        // Final Password Validation before submit
        document.getElementById('registerForm').addEventListener('submit', function(e) {
            const pwd = document.getElementById('pwd').value;
            const cpwd = document.getElementById('cpwd').value;
            
            if (pwd !== cpwd) {
                e.preventDefault();
                Swal.fire({
                    icon: 'error',
                    title: 'Password Mismatch',
                    text: 'The passwords you entered do not match. Please try again.',
                    confirmButtonColor: '#ef4444'
                });
                document.getElementById('cpwd').focus();
                return;
            }
            
            if (pwd.length < 8) {
                e.preventDefault();
                Swal.fire({
                    icon: 'warning',
                    title: 'Weak Password',
                    text: 'Password must be at least 8 characters long.',
                    confirmButtonColor: '#f59e0b'
                });
                document.getElementById('pwd').focus();
                return;
            }
        });

        // Remove red border on input
        document.querySelectorAll('input, select').forEach(input => {
            input.addEventListener('input', function() {
                if (this.value.trim()) {
                    this.closest('.input-wrapper').style.borderColor = '';
                }
            });
        });
    </script>
    <script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
</body>
</html>