<div class="user-management-container">
    <div class="card mb-6">
        <div class="card-header">
            <h3 class="card-title">نیا صارف شامل کریں (Add New User)</h3>
        </div>
        <div class="card-body">
            <form id="userForm">
                <div class="form-grid-3">
                    <div class="form-group">
                        <label class="form-label">یوزر نیم (Username)</label>
                        <input type="text" class="form-control" id="uUsername" required placeholder="مثلاً: mns102">
                    </div>
                    <div class="form-group">
                        <label class="form-label">پورا نام (Full Name)</label>
                        <input type="text" class="form-control" id="uFullName" required placeholder="مثلاً: محمد علی">
                    </div>
                    <div class="form-group">
                        <label class="form-label">پاس ورڈ (Password)</label>
                        <input type="password" class="form-control" id="uPassword" required>
                    </div>
                </div>
                
                <div class="form-grid-3">
                    <div class="form-group">
                        <label class="form-label">شعبہ (Department)</label>
                        <select id="uDepartment" class="form-control select2" required></select>
                    </div>
                    <div class="form-group">
                        <label class="form-label">عہدہ (Role)</label>
                        <select id="uRole" class="form-control" required></select>
                    </div>
                    <div class="form-group">
                        <label class="form-label">لیجر سیٹنگز (Settings)</label>
                        <label class="d-flex align-center gap-2" style="cursor: pointer; margin-top: 10px;">
                            <input type="checkbox" id="uHideReversals" checked style="width: 18px; height: 18px;">
                            <span class="fw-bold text-gray-700">منسوخ شدہ انٹریز چھپائیں</span>
                        </label>
                    </div>
                </div>

                <div class="form-section mt-6">
                    <h4 class="form-section-title">اختیارات کا تعین (Permissions Matrix)</h4>
                    <div class="table-responsive">
                        <table class="table table-bordered">
                            <thead class="bg-gray-50">
                                <tr>
                                    <th>ماڈیول (Module)</th>
                                    <th class="text-center">دیکھنا (View)</th>
                                    <th class="text-center">بنانا (Create)</th>
                                    <th class="text-center">تبدیلی (Edit)</th>
                                    <th class="text-center">ختم کرنا (Delete)</th>
                                    <th class="text-center">پرنٹ (Print)</th>
                                </tr>
                            </thead>
                            <tbody id="permissionsMatrixBody">
                                <!-- Dynamic Module Rows -->
                                <tr data-module-key="purchase">
                                    <td>کچی پرچی (Purchase)</td>
                                    <td class="text-center"><input type="checkbox" name="p_view" checked></td>
                                    <td class="text-center"><input type="checkbox" name="p_create"></td>
                                    <td class="text-center"><input type="checkbox" name="p_edit"></td>
                                    <td class="text-center"><input type="checkbox" name="p_delete"></td>
                                    <td class="text-center"><input type="checkbox" name="p_print"></td>
                                </tr>
                                <tr data-module-key="sale">
                                    <td>پکی پرچی (Sale)</td>
                                    <td class="text-center"><input type="checkbox" name="s_view" checked></td>
                                    <td class="text-center"><input type="checkbox" name="s_create"></td>
                                    <td class="text-center"><input type="checkbox" name="s_edit"></td>
                                    <td class="text-center"><input type="checkbox" name="s_delete"></td>
                                    <td class="text-center"><input type="checkbox" name="s_print"></td>
                                </tr>
                                <tr data-module-key="ledger">
                                    <td>لیجر / کھاتہ (Ledger)</td>
                                    <td class="text-center"><input type="checkbox" name="l_view" checked></td>
                                    <td class="text-center"><input type="checkbox" name="l_create"></td>
                                    <td class="text-center"><input type="checkbox" name="l_edit"></td>
                                    <td class="text-center"><input type="checkbox" name="l_delete"></td>
                                    <td class="text-center"><input type="checkbox" name="l_print"></td>
                                </tr>
                                <tr data-module-key="cashBank">
                                    <td>روزنامچہ (Cash/Bank)</td>
                                    <td class="text-center"><input type="checkbox" name="cb_view" checked></td>
                                    <td class="text-center"><input type="checkbox" name="cb_create"></td>
                                    <td class="text-center"><input type="checkbox" name="cb_edit"></td>
                                    <td class="text-center"><input type="checkbox" name="cb_delete"></td>
                                    <td class="text-center"><input type="checkbox" name="cb_print"></td>
                                </tr>
                                <tr data-module-key="expense">
                                    <td>اخراجات (Expense)</td>
                                    <td class="text-center"><input type="checkbox" name="e_view" checked></td>
                                    <td class="text-center"><input type="checkbox" name="e_create"></td>
                                    <td class="text-center"><input type="checkbox" name="e_edit"></td>
                                    <td class="text-center"><input type="checkbox" name="e_delete"></td>
                                    <td class="text-center"><input type="checkbox" name="e_print"></td>
                                </tr>
                                <tr data-module-key="setup">
                                    <td>سیٹ اپ / ماسٹرز (Setup)</td>
                                    <td class="text-center"><input type="checkbox" name="st_view"></td>
                                    <td class="text-center"><input type="checkbox" name="st_create"></td>
                                    <td class="text-center"><input type="checkbox" name="st_edit"></td>
                                    <td class="text-center"><input type="checkbox" name="st_delete"></td>
                                    <td class="text-center">---</td>
                                </tr>
                                <tr data-module-key="users">
                                    <td>صارفین (User Management)</td>
                                    <td class="text-center"><input type="checkbox" name="u_view"></td>
                                    <td class="text-center"><input type="checkbox" name="u_create"></td>
                                    <td class="text-center"><input type="checkbox" name="u_edit"></td>
                                    <td class="text-center"><input type="checkbox" name="u_delete"></td>
                                    <td class="text-center">---</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>

                <div class="form-actions mt-6">
                    <button type="submit" class="btn btn-primary btn-lg">
                        <i class="fas fa-save"></i> صارف محفوظ کریں
                    </button>
                    <button type="reset" class="btn btn-outline btn-lg">
                        ری سیٹ (Reset)
                    </button>
                </div>
            </form>
        </div>
    </div>

    <div class="card mt-10">
        <div class="card-header">
            <h3 class="card-title">رجسٹرڈ صارفین کی فہرست (Registered Users List)</h3>
        </div>
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-striped table-hover m-0">
                    <thead>
                        <tr>
                            <th>یوزر نیم</th>
                            <th>نام</th>
                            <th>شعبہ (Dept)</th>
                            <th>عہدہ (Role)</th>
                            <th>Status</th>
                            <th>عمل (Actions)</th>
                        </tr>
                    </thead>
                    <tbody id="userListBody">
                        <!-- Populated via initUsers -->
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
