<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Request Access · {{ hotelName() }}</title>
    <!-- Bootstrap 5 & Font Awesome -->
    <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">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        :root {
            --primary-green: #1a936f;
            --secondary-green: #88d498;
            --light-green: #e3f0e3;
            --dark-green: #114b5f;
            --accent-gold: #d4a373;
            --deep-charcoal: #2d3e3f;
            --soft-white: #faf9f7;
            --warm-gray: #f0efed;
            --slate: #5e7a7a;
            --border-light: #e8e6e1;
        }

        body {
            font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background: #f3f5f2;
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 20px;
            margin: 0;
        }

        .main-container {
            width: 100%;
            max-width: 1300px;
            background: white;
            border-radius: 40px;
            box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.15);
            overflow: hidden;
            display: flex;
            min-height: 800px;
        }

        /* Left Panel - Minimalist Info */
        .info-panel {
            width: 35%;
            background: white;
            padding: 3rem 2rem;
            border-right: 1px solid var(--border-light);
            display: flex;
            flex-direction: column;
        }

        .brand {
            display: flex;
            align-items: center;
            gap: 10px;
            color: var(--dark-green);
            font-weight: 600;
            font-size: 1rem;
            letter-spacing: 0.5px;
            margin-bottom: 3rem;
        }

        .brand-icon {
            width: 36px;
            height: 36px;
            background: var(--primary-green);
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 1.2rem;
        }

        .info-content {
            flex: 1;
        }

        .info-title {
            font-size: 2.2rem;
            font-weight: 600;
            color: var(--dark-green);
            line-height: 1.2;
            margin-bottom: 1rem;
        }

        .info-subtitle {
            color: var(--slate);
            font-size: 0.95rem;
            line-height: 1.6;
            margin-bottom: 2.5rem;
        }

        .process-steps {
            display: flex;
            flex-direction: column;
            gap: 1.5rem;
        }

        .step-item {
            display: flex;
            align-items: flex-start;
            gap: 15px;
        }

        .step-number {
            width: 32px;
            height: 32px;
            background: var(--light-green);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: var(--primary-green);
            font-weight: 600;
            font-size: 0.9rem;
            flex-shrink: 0;
        }

        .step-content h4 {
            font-size: 1rem;
            font-weight: 600;
            color: var(--deep-charcoal);
            margin-bottom: 4px;
        }

        .step-content p {
            font-size: 0.85rem;
            color: var(--slate);
            margin: 0;
        }

        .director-note {
            margin-top: 2.5rem;
            padding: 1.25rem;
            background: var(--warm-gray);
            border-radius: 20px;
            display: flex;
            align-items: center;
            gap: 15px;
        }

        .director-icon {
            width: 48px;
            height: 48px;
            background: white;
            border-radius: 16px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: var(--accent-gold);
            font-size: 1.4rem;
        }

        .director-text h5 {
            font-size: 0.95rem;
            font-weight: 600;
            color: var(--deep-charcoal);
            margin-bottom: 4px;
        }

        .director-text p {
            font-size: 0.8rem;
            color: var(--slate);
            margin: 0;
        }

        .stats-mini {
            margin-top: 2rem;
            display: flex;
            gap: 1.5rem;
            padding-top: 1.5rem;
            border-top: 1px solid var(--border-light);
        }

        .stats-mini span {
            display: flex;
            align-items: center;
            gap: 8px;
            color: var(--slate);
            font-size: 0.85rem;
        }

        .stats-mini i {
            color: var(--primary-green);
        }

        /* Right Panel - Form */
        .form-panel {
            width: 65%;
            background: white;
            padding: 3rem 3rem;
            overflow-y: auto;
        }

        .form-header {
            margin-bottom: 2rem;
        }

        .form-header h2 {
            font-size: 1.8rem;
            font-weight: 600;
            color: var(--deep-charcoal);
            margin-bottom: 0.25rem;
        }

        .form-header p {
            color: var(--slate);
            font-size: 0.9rem;
        }

        .form-section {
            margin-bottom: 2rem;
            padding-bottom: 2rem;
            border-bottom: 1px solid var(--border-light);
        }

        .form-section:last-of-type {
            border-bottom: none;
            padding-bottom: 0;
        }

        .section-title {
            display: flex;
            align-items: center;
            gap: 8px;
            color: var(--dark-green);
            font-weight: 600;
            font-size: 0.95rem;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            margin-bottom: 1.5rem;
        }

        .section-title i {
            color: var(--primary-green);
            font-size: 1rem;
        }

        .form-row {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 1rem;
            margin-bottom: 1rem;
        }

        .input-wrapper {
            margin-bottom: 1rem;
        }

        .input-label {
            display: block;
            font-size: 0.85rem;
            font-weight: 500;
            color: var(--deep-charcoal);
            margin-bottom: 0.5rem;
        }

        .input-field {
            width: 100%;
            padding: 0.75rem 1rem;
            border: 1px solid var(--border-light);
            border-radius: 12px;
            font-size: 0.95rem;
            transition: all 0.2s;
            background: white;
        }

        .input-field:focus {
            outline: none;
            border-color: var(--primary-green);
            box-shadow: 0 0 0 3px rgba(26, 147, 111, 0.1);
        }

        .input-field::placeholder {
            color: #b8b8b8;
            font-size: 0.9rem;
        }

        /* Role Grid */
        .role-grid {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 0.75rem;
            margin-bottom: 1rem;
        }

        .role-option {
            background: white;
            border: 1px solid var(--border-light);
            border-radius: 16px;
            padding: 1rem 0.5rem;
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 8px;
            cursor: pointer;
            transition: all 0.2s;
        }

        .role-option i {
            font-size: 1.4rem;
            color: var(--primary-green);
            transition: all 0.2s;
        }

        .role-option span {
            font-size: 0.85rem;
            font-weight: 500;
            color: var(--deep-charcoal);
            text-align: center;
        }

        .role-option .role-desc {
            font-size: 0.7rem;
            color: var(--slate);
            margin: 0;
        }

        .role-option:hover {
            border-color: var(--primary-green);
            background: #f9fdf9;
            transform: translateY(-1px);
        }

        .role-option.selected {
            background: var(--primary-green);
            border-color: var(--primary-green);
        }

        .role-option.selected i,
        .role-option.selected span,
        .role-option.selected .role-desc {
            color: white;
        }

        .role-note {
            font-size: 0.8rem;
            color: var(--slate);
            display: flex;
            align-items: center;
            gap: 8px;
            background: var(--warm-gray);
            padding: 0.75rem 1rem;
            border-radius: 30px;
            margin-top: 1rem;
        }

        .role-note i {
            color: var(--accent-gold);
        }

        /* Password Requirements */
        .password-reqs {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 0.5rem;
            margin-top: 0.75rem;
            font-size: 0.8rem;
        }

        .req-item {
            display: flex;
            align-items: center;
            gap: 6px;
            color: var(--slate);
        }

        .req-item i {
            width: 14px;
            font-size: 0.7rem;
        }

        .req-item.met {
            color: var(--primary-green);
        }

        .req-item.met i {
            color: var(--primary-green);
        }

        .password-strength {
            height: 4px;
            border-radius: 2px;
            margin: 0.75rem 0;
            background: #eee;
            overflow: hidden;
        }

        .strength-bar {
            height: 100%;
            width: 0%;
            transition: all 0.3s;
        }

        .strength-0 { width: 0%; background: #dc3545; }
        .strength-1 { width: 25%; background: #dc3545; }
        .strength-2 { width: 50%; background: #ffc107; }
        .strength-3 { width: 75%; background: #17a2b8; }
        .strength-4 { width: 100%; background: var(--primary-green); }

        /* Checkbox */
        .terms-check {
            display: flex;
            align-items: flex-start;
            gap: 10px;
            margin: 1.5rem 0;
        }

        .terms-check input {
            width: 18px;
            height: 18px;
            margin-top: 2px;
            accent-color: var(--primary-green);
        }

        .terms-check label {
            font-size: 0.9rem;
            color: var(--slate);
            line-height: 1.5;
        }

        /* Submit Button */
        .btn-submit {
            width: 100%;
            padding: 1rem;
            background: var(--dark-green);
            color: white;
            border: none;
            border-radius: 16px;
            font-weight: 600;
            font-size: 1rem;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
            cursor: pointer;
            transition: all 0.2s;
            margin-bottom: 1.5rem;
        }

        .btn-submit:hover {
            background: #0e3f4f;
            transform: translateY(-1px);
            box-shadow: 0 8px 20px -8px rgba(17, 75, 95, 0.3);
        }

        .btn-submit:disabled {
            opacity: 0.5;
            cursor: not-allowed;
            transform: none;
        }

        .login-link {
            text-align: center;
            font-size: 0.9rem;
            color: var(--slate);
        }

        .login-link a {
            color: var(--primary-green);
            text-decoration: none;
            font-weight: 500;
        }

        .login-link a:hover {
            text-decoration: underline;
        }

        /* Status Check Card */
        .status-card {
            margin-top: 2rem;
            padding-top: 1.5rem;
            border-top: 1px solid var(--border-light);
        }

        .status-title {
            display: flex;
            align-items: center;
            gap: 8px;
            color: var(--deep-charcoal);
            font-weight: 600;
            font-size: 0.9rem;
            margin-bottom: 1rem;
        }

        .status-input {
            display: flex;
            gap: 0.5rem;
        }

        .status-input input {
            flex: 1;
            padding: 0.75rem 1rem;
            border: 1px solid var(--border-light);
            border-radius: 12px;
            font-size: 0.9rem;
        }

        .status-input button {
            padding: 0.75rem 1.5rem;
            background: white;
            border: 1px solid var(--primary-green);
            border-radius: 12px;
            color: var(--primary-green);
            font-weight: 500;
            cursor: pointer;
            transition: all 0.2s;
        }

        .status-input button:hover {
            background: var(--primary-green);
            color: white;
        }

        .status-result {
            margin-top: 1rem;
            padding: 1rem;
            border-radius: 12px;
            display: none;
            font-size: 0.9rem;
        }

        .status-pending {
            background: #fff9e6;
            border-left: 3px solid #ffc107;
        }

        .status-approved {
            background: #e6f7e6;
            border-left: 3px solid var(--primary-green);
        }

        .status-rejected {
            background: #fee9e7;
            border-left: 3px solid #dc3545;
        }

        /* Alerts */
        .alert {
            padding: 1rem;
            border-radius: 12px;
            margin-bottom: 1.5rem;
            font-size: 0.9rem;
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .alert-success {
            background: #e6f7e6;
            color: var(--dark-green);
        }

        .alert-danger {
            background: #fee9e7;
            color: #721c24;
        }

        .loading-spinner {
            display: inline-block;
            width: 16px;
            height: 16px;
            border: 2px solid rgba(255,255,255,0.3);
            border-radius: 50%;
            border-top-color: white;
            animation: spin 1s linear infinite;
        }

        @keyframes spin {
            to { transform: rotate(360deg); }
        }

        @media (max-width: 968px) {
            .main-container {
                flex-direction: column;
                border-radius: 30px;
            }
            .info-panel, .form-panel {
                width: 100%;
            }
            .info-panel {
                border-right: none;
                border-bottom: 1px solid var(--border-light);
                padding: 2rem;
            }
            .form-panel {
                padding: 2rem;
            }
            .role-grid {
                grid-template-columns: repeat(2, 1fr);
            }
        }

        @media (max-width: 480px) {
            .form-row {
                grid-template-columns: 1fr;
            }
            .role-grid {
                grid-template-columns: 1fr;
            }
        }
    </style>
</head>
<body>
    <div class="main-container">
        <!-- Left Panel - Minimalist Info -->
        <div class="info-panel">
            <div class="brand">
                <div class="brand-icon">
                    <i class="fa-regular fa-leaf"></i>
                </div>
                <h4>{{ hotelName() }}</h4>
            </div>

            <div class="info-content">
                <h1 class="info-title">Request<br>access</h1>
                <p class="info-subtitle">Join the team. Submit your details for director approval.</p>

                <div class="process-steps">
                    <div class="step-item">
                        <div class="step-number">1</div>
                        <div class="step-content">
                            <h4>Complete form</h4>
                            <p>Fill in your personal and role information</p>
                        </div>
                    </div>
                    <div class="step-item">
                        <div class="step-number">2</div>
                        <div class="step-content">
                            <h4>Director review</h4>
                            <p>Your request is sent to the director's desk</p>
                        </div>
                    </div>
                    <div class="step-item">
                        <div class="step-number">3</div>
                        <div class="step-content">
                            <h4>Access granted</h4>
                            <p>Receive credentials upon approval</p>
                        </div>
                    </div>
                </div>

                <div class="director-note">
                    <div class="director-icon">
                        <i class="fa-regular fa-crown"></i>
                    </div>
                    <div class="director-text">
                        <h5>Director review required</h5>
                        <p>All requests are personally reviewed by the Director of Operations</p>
                    </div>
                </div>

                <div class="stats-mini">
                    <span><i class="fa-regular fa-users"></i> 47 active</span>
                    <span><i class="fa-regular fa-clock"></i> <span id="pendingCount">12</span> pending</span>
                    <span><i class="fa-regular fa-check-circle"></i> 24-48h</span>
                </div>
            </div>
        </div>

        <!-- Right Panel - Form -->
        <div class="form-panel">
            <div class="form-header">
                <h2>Staff access request</h2>
                <p>Please fill in your details accurately</p>
            </div>

            <!-- Session Status -->
            @if (session('success'))
                <div class="alert alert-success">
                    <i class="fa-regular fa-circle-check"></i>
                    {{ session('success') }}
                </div>
            @endif

            @if (session('error'))
                <div class="alert alert-danger">
                    <i class="fa-regular fa-circle-exclamation"></i>
                    {{ session('error') }}
                </div>
            @endif

            @if ($errors->any())
                <div class="alert alert-danger">
                    <i class="fa-regular fa-circle-exclamation"></i>
                    <ul class="mb-0 ps-3">
                        @foreach ($errors->all() as $error)
                            <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                </div>
            @endif

            <div id="customAlert" class="alert" style="display: none;"></div>

            <!-- Request Form -->
            <form method="POST" action="{{ route('register') }}" id="requestForm">
                @csrf

                <!-- Personal Information -->
                <div class="form-section">
                    <div class="section-title">
                        <i class="fa-regular fa-user"></i>
                        <span>Personal</span>
                    </div>

                    <div class="form-row">
                        <div class="input-wrapper">
                            <label class="input-label">First name</label>
                            <input type="text" class="input-field @error('first_name') is-invalid @enderror" 
                                   name="first_name" value="{{ old('first_name') }}" placeholder="John" required>
                            @error('first_name')
                                <small class="text-danger">{{ $message }}</small>
                            @enderror
                        </div>
                        <div class="input-wrapper">
                            <label class="input-label">Last name</label>
                            <input type="text" class="input-field @error('last_name') is-invalid @enderror" 
                                   name="last_name" value="{{ old('last_name') }}" placeholder="Doe" required>
                            @error('last_name')
                                <small class="text-danger">{{ $message }}</small>
                            @enderror
                        </div>
                    </div>
                </div>

                <!-- Contact -->
                <div class="form-section">
                    <div class="section-title">
                        <i class="fa-regular fa-address-book"></i>
                        <span>Contact</span>
                    </div>

                    <div class="input-wrapper">
                        <label class="input-label">Email address</label>
                        <input type="email" class="input-field @error('email') is-invalid @enderror" 
                               name="email" value="{{ old('email') }}" placeholder="john.doe@example.com" required>
                        @error('email')
                            <small class="text-danger">{{ $message }}</small>
                        @enderror
                    </div>

                    <div class="input-wrapper">
                        <label class="input-label">Phone number</label>
                        <input type="tel" class="input-field @error('phone') is-invalid @enderror" 
                               name="phone" value="{{ old('phone') }}" placeholder="+1 234 567 8900" required>
                        @error('phone')
                            <small class="text-danger">{{ $message }}</small>
                        @enderror
                    </div>
                </div>

                <!-- Role Selection -->
                <div class="form-section">
                    <div class="section-title">
                        <i class="fa-regular fa-id-card"></i>
                        <span>Requested role</span>
                    </div>

                    <div class="role-grid">
                        <div class="role-option" data-role="manager" onclick="selectRole('manager')">
                            <i class="fas fa-user-tie"></i>
                            <span>Manager</span>
                            <small class="role-desc">Department lead</small>
                        </div>
                        <div class="role-option" data-role="front_desk" onclick="selectRole('front_desk')">
                            <i class="fas fa-concierge-bell"></i>
                            <span>Front Desk</span>
                            <small class="role-desc">Reception</small>
                        </div>
                        <div class="role-option" data-role="housekeeping" onclick="selectRole('housekeeping')">
                            <i class="fas fa-broom"></i>
                            <span>Housekeeping</span>
                            <small class="role-desc">Cleaning</small>
                        </div>
                        <div class="role-option" data-role="food_beverage" onclick="selectRole('food_beverage')">
                            <i class="fas fa-utensils"></i>
                            <span>F&B</span>
                            <small class="role-desc">Restaurant</small>
                        </div>
                        <div class="role-option" data-role="maintenance" onclick="selectRole('maintenance')">
                            <i class="fas fa-tools"></i>
                            <span>Maintenance</span>
                            <small class="role-desc">Facilities</small>
                        </div>
                        <!-- CHANGED: from accounting to accountant -->
                        <div class="role-option" data-role="accountant" onclick="selectRole('accountant')">
                            <i class="fas fa-calculator"></i>
                            <span>Accountant</span>
                            <small class="role-desc">Finance</small>
                        </div>
                    </div>
                    <input type="hidden" name="role" id="selected_role" value="{{ old('role') }}">

                    <div class="role-note">
                        <i class="fa-regular fa-circle-info"></i>
                        <span>Director role cannot be requested. Admin creates director accounts.</span>
                    </div>
                    @error('role')
                        <small class="text-danger">{{ $message }}</small>
                    @enderror
                </div>

                <!-- Security -->
                <div class="form-section">
                    <div class="section-title">
                        <i class="fa-regular fa-lock"></i>
                        <span>Security</span>
                    </div>

                    <div class="input-wrapper">
                        <label class="input-label">Password</label>
                        <input type="password" class="input-field @error('password') is-invalid @enderror" 
                               id="password" name="password" placeholder="Create a password" required>
                        @error('password')
                            <small class="text-danger">{{ $message }}</small>
                        @enderror
                    </div>

                    <!-- Password Strength -->
                    <div class="password-strength">
                        <div id="strengthBar" class="strength-bar strength-0"></div>
                    </div>

                    <div class="password-reqs">
                        <div class="req-item" id="req-length">
                            <i class="fa-regular fa-circle"></i> 8+ characters
                        </div>
                        <div class="req-item" id="req-lower">
                            <i class="fa-regular fa-circle"></i> Lowercase
                        </div>
                        <div class="req-item" id="req-upper">
                            <i class="fa-regular fa-circle"></i> Uppercase
                        </div>
                        <div class="req-item" id="req-number">
                            <i class="fa-regular fa-circle"></i> Number
                        </div>
                        <div class="req-item" id="req-special">
                            <i class="fa-regular fa-circle"></i> Special character
                        </div>
                    </div>

                    <div class="input-wrapper" style="margin-top: 1rem;">
                        <label class="input-label">Confirm password</label>
                        <input type="password" class="input-field" 
                               id="password_confirmation" name="password_confirmation" 
                               placeholder="Re-enter password" required>
                        <div id="passwordMatch" class="small mt-1 text-danger" style="display: none;"></div>
                    </div>
                </div>

                <!-- Additional Notes -->
                <div class="form-section">
                    <div class="section-title">
                        <i class="fa-regular fa-note-sticky"></i>
                        <span>Notes (optional)</span>
                    </div>

                    <textarea class="input-field" name="notes" rows="3" 
                              placeholder="Add any relevant information for the director...">{{ old('notes') }}</textarea>
                </div>

                <!-- Terms -->
                <div class="terms-check">
                    <input type="checkbox" id="terms" name="terms" required {{ old('terms') ? 'checked' : '' }}>
                    <label for="terms">I confirm that the information provided is accurate and understand that account approval is at the director's discretion.</label>
                </div>

                <!-- Submit -->
                <button type="submit" class="btn-submit" id="submitButton">
                    <span>Submit request for approval</span>
                    <span class="loading-spinner" id="submitSpinner" style="display: none;"></span>
                </button>

                <div class="login-link">
                    Already have an account? <a href="{{ route('login') }}">Log in</a>
                </div>
            </form>

            <!-- Status Check -->
            <div class="status-card">
                <div class="status-title">
                    <i class="fa-regular fa-magnifying-glass"></i>
                    <span>Check request status</span>
                </div>
                <div class="status-input">
                    <input type="email" id="checkEmail" placeholder="Enter your email" value="{{ session('request_email') ?? '' }}">
                    <button onclick="checkManualStatus()">Check</button>
                </div>
                <div id="manualStatusResult" class="status-result"></div>
            </div>
        </div>
    </div>

    <script>
        // Role selection
        function selectRole(role) {
            document.querySelectorAll('.role-option').forEach(opt => opt.classList.remove('selected'));
            document.querySelector(`[data-role="${role}"]`).classList.add('selected');
            document.getElementById('selected_role').value = role;
        }

        // Load saved role
        document.addEventListener('DOMContentLoaded', function() {
            const oldRole = '{{ old('role') }}';
            if (oldRole) selectRole(oldRole);
        });

        // Password strength checker
        const password = document.getElementById('password');
        const confirm = document.getElementById('password_confirmation');
        const strengthBar = document.getElementById('strengthBar');
        const matchDiv = document.getElementById('passwordMatch');

        function checkPasswordStrength() {
            const pwd = password.value;
            const reqs = {
                length: pwd.length >= 8,
                lower: /[a-z]/.test(pwd),
                upper: /[A-Z]/.test(pwd),
                number: /[0-9]/.test(pwd),
                special: /[^a-zA-Z0-9]/.test(pwd)
            };

            // Update requirement icons
            ['length', 'lower', 'upper', 'number', 'special'].forEach(req => {
                const el = document.getElementById(`req-${req}`);
                const icon = el.querySelector('i');
                if (reqs[req]) {
                    icon.className = 'fa-regular fa-circle-check';
                    el.classList.add('met');
                } else {
                    icon.className = 'fa-regular fa-circle';
                    el.classList.remove('met');
                }
            });

            // Update strength bar
            const strength = Object.values(reqs).filter(Boolean).length;
            strengthBar.className = 'strength-bar';
            strengthBar.classList.add(`strength-${strength}`);
        }

        password.addEventListener('input', checkPasswordStrength);

        // Password match checker
        function checkPasswordMatch() {
            if (confirm.value.length > 0) {
                matchDiv.style.display = 'block';
                if (password.value === confirm.value) {
                    matchDiv.innerHTML = '<i class="fa-regular fa-circle-check me-1"></i> Passwords match';
                    matchDiv.classList.remove('text-danger');
                    matchDiv.classList.add('text-success');
                } else {
                    matchDiv.innerHTML = '<i class="fa-regular fa-circle-xmark me-1"></i> Passwords do not match';
                    matchDiv.classList.remove('text-success');
                    matchDiv.classList.add('text-danger');
                }
            } else {
                matchDiv.style.display = 'none';
            }
        }

        confirm.addEventListener('input', checkPasswordMatch);

        // Form validation
        document.getElementById('requestForm').addEventListener('submit', function(e) {
            const role = document.getElementById('selected_role').value;
            if (!role) {
                e.preventDefault();
                showAlert('Please select your requested role.', 'danger');
                return;
            }

            if (password.value !== confirm.value) {
                e.preventDefault();
                showAlert('Passwords do not match.', 'danger');
                return;
            }

            if (!document.getElementById('terms').checked) {
                e.preventDefault();
                showAlert('You must agree to the terms.', 'danger');
                return;
            }

            // Show loading
            document.getElementById('submitButton').disabled = true;
            document.getElementById('submitSpinner').style.display = 'inline-block';
        });

        function showAlert(message, type) {
            const alert = document.getElementById('customAlert');
            alert.className = `alert alert-${type}`;
            alert.innerHTML = `<i class="fa-regular fa-circle-${type === 'danger' ? 'exclamation' : 'info'}"></i>${message}`;
            alert.style.display = 'flex';
            setTimeout(() => alert.style.display = 'none', 5000);
        }

        // Status check
        function checkManualStatus() {
            const email = document.getElementById('checkEmail').value.trim();
            const resultDiv = document.getElementById('manualStatusResult');
            
            if (!email || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
                resultDiv.style.display = 'block';
                resultDiv.className = 'status-result status-rejected';
                resultDiv.innerHTML = 'Please enter a valid email address.';
                return;
            }

            resultDiv.style.display = 'block';
            resultDiv.innerHTML = 'Checking...';
            resultDiv.className = 'status-result';

            // Simulate API call - replace with actual fetch
            setTimeout(() => {
                resultDiv.className = 'status-result status-pending';
                resultDiv.innerHTML = 'Request pending. Please wait for director review.';
            }, 1000);
        }

        // Phone formatting
        document.querySelector('input[name="phone"]').addEventListener('input', function() {
            let phone = this.value.replace(/\D/g, '');
            if (phone.length > 10) phone = phone.substr(0, 10);
            if (phone.length > 6) {
                phone = phone.replace(/(\d{3})(\d{3})(\d{4})/, '($1) $2-$3');
            } else if (phone.length > 3) {
                phone = phone.replace(/(\d{3})(\d+)/, '($1) $2');
            }
            this.value = phone;
        });
    </script>
</body>
</html>
