<!-- Payment Registration Modal -->
<div class="modal fade" id="paymentRegistrationModal" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-xl" role="document">
        <div class="modal-content">
            <div class="modal-header text-white">
                <h6 class="modal-title mb-0">
                    <i class="fas fa-money-bill-wave"></i> Register Payment
                </h6>
                <button type="button" class="close text-white" data-dismiss="modal">
                    <span>&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <!-- Supplier Selection - Compact -->
                <div class="row mb-2">
                    <div class="col-md-9">
                        <label class="font-weight-bold mb-1">
                            <i class="fas fa-truck"></i> Supplier <span class="text-danger">*</span>
                        </label>
                        <select id="paymentSupplierSelect" class="form-control">
                            <option value="">-- Select Supplier --</option>
                        </select>
                    </div>
                    <div class="col-md-3">
                        <label class="mb-1 d-block">&nbsp;</label>
                        <button type="button" class="btn btn-block" id="btnLoadOutstanding">
                            <i class="fas fa-sync-alt"></i> Load Bills
                        </button>
                    </div>
                </div>

                <!-- Supplier Info Display - Compact -->
                <div id="paymentSupplierInfo" style="display:none;">
                    <div class="row align-items-center">
                        <div class="col-md-4">
                            <strong>Supplier:</strong><br>
                            <span id="paymentSupplierName" class="text-primary font-weight-bold">-</span>
                        </div>
                        <div class="col-md-4">
                            <strong>Code:</strong><br>
                            <span id="paymentSupplierCode">-</span>
                        </div>
                        <div class="col-md-4 text-right">
                            <strong>Total Outstanding:</strong><br>
                            <h5 class="mb-0 text-danger" id="paymentTotalOutstanding">₹0.00</h5>
                        </div>
                    </div>
                </div>

                <!-- Outstanding Invoices Table -->
                <div id="outstandingInvoicesSection" style="display:none;">
                    <h6 class="mt-3">
                        <i class="fas fa-file-invoice-dollar"></i> Outstanding Invoices
                    </h6>
                    <div class="table-responsive" style="max-height: 350px; overflow-y: auto;">
                        <table class="table table-sm table-hover">
                            <thead>
                                <tr>
                                    <th width="4%">
                                        <input type="checkbox" id="selectAllInvoices">
                                    </th>
                                    <th width="16%">Invoice No</th>
                                    <th width="12%">Date</th>
                                    <th width="12%" class="text-right">Amount</th>
                                    <th width="12%" class="text-right">Paid</th>
                                    <th width="12%" class="text-right">Outstanding</th>
                                    <th width="16%" class="text-right">Payment</th>
                                    <th width="16%">Mode</th>
                                </tr>
                            </thead>
                            <tbody id="outstandingInvoicesList">
                                <tr>
                                    <td colspan="8" class="text-center text-muted">
                                        <i class="fas fa-info-circle"></i> Select supplier and load bills
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>

                    <!-- Payment Summary - Compact -->
                    <div class="card bg-light mt-2">
                        <div class="card-body">
                            <div class="row">
                                <div class="col-3">
                                    <label>Selected:</label>
                                    <h5 class="text-primary" id="selectedInvoicesCount">0</h5>
                                </div>
                                <div class="col-3">
                                    <label>Outstanding:</label>
                                    <h5 class="text-danger" id="selectedOutstandingAmount">₹0.00</h5>
                                </div>
                                <div class="col-3">
                                    <label>Payment:</label>
                                    <h5 class="text-success" id="totalPaymentAmount">₹0.00</h5>
                                </div>
                                <div class="col-3">
                                    <label>Remaining:</label>
                                    <h5 class="text-warning" id="remainingOutstanding">₹0.00</h5>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- Payment Details - Compact -->
                    <div class="row mt-2">
                        <div class="col-md-3">
                            <label class="mb-1">
                                <i class="fas fa-calendar"></i> Date <span class="text-danger">*</span>
                            </label>
                            <input type="date" id="paymentDate" class="form-control" value="<?php echo date('Y-m-d'); ?>">
                        </div>
                        <div class="col-md-3">
                            <label class="mb-1">
                                <i class="fas fa-credit-card"></i> Mode
                            </label>
                            <select id="paymentMode" class="form-control">
                                <option value="Cash">Cash</option>
                                <option value="UPI">UPI</option>
                                <option value="Card">Card</option>
                                <option value="Cheque">Cheque</option>
                                <option value="Bank Transfer">Bank Transfer</option>
                            </select>
                        </div>
                        <div class="col-md-3">
                            <label class="mb-1">
                                <i class="fas fa-hashtag"></i> Reference
                            </label>
                            <input type="text" id="paymentReference" class="form-control" placeholder="Txn/Cheque No">
                        </div>
                        <div class="col-md-3">
                            <label class="mb-1">
                                <i class="fas fa-sticky-note"></i> Notes
                            </label>
                            <input type="text" id="paymentNotes" class="form-control" placeholder="Optional notes">
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">
                    <i class="fas fa-times"></i> Cancel
                </button>
                <button type="button" class="btn btn-success" id="btnSavePayment" disabled>
                    <i class="fas fa-check"></i> Register Payment
                </button>
            </div>
        </div>
    </div>
</div>
