<div class="row g-4">
    <div class="col-lg-5">
        <div class="card">
            <div class="card-header d-flex justify-content-between align-items-center">
                <h6 class="mb-0"><i class="fas fa-university me-2"></i>
                    <?= e($dep['deposit_number']) ?>
                </h6>
                <?= status_badge($dep['status']) ?>
            </div>
            <div class="card-body">
                <table class="table table-sm mb-0">
                    <tr>
                        <th width="40%">
                            <?= lang('adv_finance.bank_name') ?>
                        </th>
                        <td>
                            <?= e($dep['bank_name_en']) ?>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <?= lang('adv_finance.deposit_date') ?>
                        </th>
                        <td>
                            <?= format_date($dep['deposit_date']) ?>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <?= lang('adv_finance.total_amount') ?>
                        </th>
                        <td class="fw-bold fs-5">
                            <?= format_money($dep['total_amount']) ?>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <?= lang('adv_finance.cash_amount') ?>
                        </th>
                        <td>
                            <?= format_money($dep['cash_amount']) ?>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <?= lang('adv_finance.check_amount') ?>
                        </th>
                        <td>
                            <?= format_money($dep['check_amount']) ?> <span class="text-muted">(
                                <?= (int) $dep['check_count'] ?> checks)
                            </span>
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <?= lang('common.status') ?>
                        </th>
                        <td>
                            <?= status_badge($dep['status']) ?>
                        </td>
                    </tr>
                    <?php if ($dep['bank_reference']): ?>
                        <tr>
                            <th>
                                <?= lang('adv_finance.bank_reference') ?>
                            </th>
                            <td><code><?= e($dep['bank_reference']) ?></code></td>
                        </tr>
                    <?php endif; ?>
                    <?php if ($dep['notes']): ?>
                        <tr>
                            <th>Notes</th>
                            <td>
                                <?= e($dep['notes']) ?>
                            </td>
                        </tr>
                    <?php endif; ?>
                    <?php if ($dep['confirmed_at']): ?>
                        <tr>
                            <th>Confirmed</th>
                            <td>
                                <?= format_datetime($dep['confirmed_at']) ?>
                            </td>
                        </tr>
                    <?php endif; ?>
                </table>
            </div>
        </div>

        <?php if (in_array($dep['status'], ['prepared', 'deposited']) && auth_can('gl.manage')): ?>
            <div class="card mt-3">
                <div class="card-header">
                    <h6 class="mb-0"><i class="fas fa-check-circle me-2"></i>
                        <?= lang('adv_finance.confirm_deposit') ?>
                    </h6>
                </div>
                <div class="card-body">
                    <form method="POST" action="/advanced-finance/deposits/<?= $dep['id'] ?>/confirm" data-ajax="true">
                        <?= csrf_field() ?>
                        <div class="mb-3">
                            <label class="form-label">
                                <?= lang('adv_finance.bank_reference') ?>
                            </label>
                            <input type="text" name="bank_reference" class="form-control"
                                placeholder="Bank transaction reference...">
                        </div>
                        <button type="submit" class="btn btn-success"
                            onclick="return confirm('<?= lang('common.are_you_sure') ?>')">
                            <i class="fas fa-check me-1"></i>
                            <?= lang('adv_finance.confirm_deposit') ?>
                        </button>
                    </form>
                </div>
            </div>
        <?php endif; ?>
    </div>

    <div class="col-lg-7">
        <div class="card">
            <div class="card-header">
                <h6 class="mb-0"><i class="fas fa-list me-2"></i>Deposit Items</h6>
            </div>
            <div class="card-body p-0">
                <table class="table table-sm table-striped mb-0">
                    <thead>
                        <tr>
                            <th width="5%">#</th>
                            <th width="15%">Type</th>
                            <th width="25%">
                                <?= lang('adv_finance.amount') ?>
                            </th>
                            <th>Details</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $lineNo = 1;
                        foreach ($items as $it): ?>
                            <tr>
                                <td>
                                    <?= $lineNo++ ?>
                                </td>
                                <td>
                                    <?php if ($it['item_type'] === 'cash'): ?>
                                        <span class="badge bg-success"><i class="fas fa-money-bill-wave me-1"></i>Cash</span>
                                    <?php else: ?>
                                        <span class="badge bg-info"><i class="fas fa-money-check me-1"></i>Check</span>
                                    <?php endif; ?>
                                </td>
                                <td class="fw-bold">
                                    <?= format_money($it['amount']) ?>
                                </td>
                                <td>
                                    <?php if ($it['item_type'] === 'check' && $it['check_number']): ?>
                                        <div>
                                            <strong>
                                                <?= lang('adv_finance.check_number') ?>:
                                            </strong>
                                            <?= e($it['check_number']) ?><br>
                                            <strong>
                                                <?= lang('adv_finance.drawer_name') ?>:
                                            </strong>
                                            <?= e($it['drawer_name'] ?? '—') ?><br>
                                            <strong>
                                                <?= lang('adv_finance.bank_name') ?>:
                                            </strong>
                                            <?= e($it['check_bank'] ?? '—') ?>
                                        </div>
                                    <?php else: ?>
                                        <span class="text-muted">—</span>
                                    <?php endif; ?>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                        <?php if (empty($items)): ?>
                            <tr>
                                <td colspan="4" class="text-center text-muted py-4">No items in this deposit</td>
                            </tr>
                        <?php endif; ?>
                    </tbody>
                    <tfoot class="table-light">
                        <tr>
                            <td colspan="2" class="text-end fw-bold">Total:</td>
                            <td class="fw-bold">
                                <?= format_money($dep['total_amount']) ?>
                            </td>
                            <td></td>
                        </tr>
                    </tfoot>
                </table>
            </div>
        </div>
    </div>
</div>