<div class="flex items-center justify-between mb-6">
    <div class="flex items-center gap-3"><a href="?page=reports" class="text-gray-400 hover:text-gray-600"><svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/></svg></a>
        <div><h1 class="text-2xl font-bold text-gray-900">Delinquency Report</h1><p class="text-sm text-gray-500 mt-1"><?= count($data) ?> tenants with outstanding balances</p></div></div>
    <div class="bg-red-50 rounded-xl border border-red-200 px-4 py-2 text-center"><p class="text-xs text-red-600">Total Outstanding</p><p class="text-xl font-bold text-red-700"><?= formatMoney($totalDelinquent) ?></p></div>
</div>
<div class="bg-white rounded-xl shadow-sm border border-gray-200 overflow-x-auto">
    <table class="w-full text-sm">
        <thead class="bg-gray-50 text-left"><tr><th class="px-4 py-3 font-medium text-gray-600">Tenant</th><th class="px-4 py-3 font-medium text-gray-600">Property / Unit</th><th class="px-4 py-3 font-medium text-gray-600">Contact</th><th class="px-4 py-3 font-medium text-gray-600 text-right">Rent</th><th class="px-4 py-3 font-medium text-gray-600 text-right">Balance Due</th></tr></thead>
        <tbody class="divide-y divide-gray-100">
            <?php if (empty($data)): ?><tr><td colspan="5" class="px-4 py-12 text-center text-green-600 font-medium">No delinquent accounts!</td></tr>
            <?php else: foreach ($data as $d): ?>
            <tr class="hover:bg-gray-50">
                <td class="px-4 py-3 font-medium"><a href="?page=tenants&action=show&id=<?= $d['id'] ?>" class="text-indigo-600 hover:underline"><?= htmlspecialchars($d['first_name'].' '.$d['last_name']) ?></a></td>
                <td class="px-4 py-3 text-gray-600"><?= htmlspecialchars(($d['property_name'] ?? '-').($d['unit_number'] ? ' / '.$d['unit_number'] : '')) ?></td>
                <td class="px-4 py-3 text-xs text-gray-500"><?= htmlspecialchars($d['email'] ?? '') ?><br><?= htmlspecialchars($d['phone'] ?? '') ?></td>
                <td class="px-4 py-3 text-right"><?= formatMoney($d['rent_amount'] ?? 0) ?></td>
                <td class="px-4 py-3 text-right font-bold text-red-600"><?= formatMoney($d['balance']) ?></td>
            </tr>
            <?php endforeach; endif; ?>
        </tbody>
    </table>
</div>
