<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><h1 class="text-2xl font-bold text-gray-900">Payment Report</h1></div>
    <div class="bg-white rounded-xl shadow-sm border border-gray-200 px-4 py-2 text-center"><p class="text-xs text-gray-500">Period Total</p><p class="text-xl font-bold text-green-700"><?= formatMoney($totalAmount) ?></p></div>
</div>
<div class="bg-white rounded-xl shadow-sm border border-gray-200 mb-4 p-4">
    <form method="GET" class="flex flex-wrap items-end gap-3"><input type="hidden" name="page" value="reports"><input type="hidden" name="action" value="payments">
        <div><label class="block text-xs font-medium text-gray-600 mb-1">From</label><input type="date" name="from" value="<?= htmlspecialchars($from) ?>" class="px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-indigo-500"></div>
        <div><label class="block text-xs font-medium text-gray-600 mb-1">To</label><input type="date" name="to" value="<?= htmlspecialchars($to) ?>" class="px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-indigo-500"></div>
        <button type="submit" class="px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 text-sm font-medium">Run Report</button>
    </form>
</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">Date</th><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">Method</th><th class="px-4 py-3 font-medium text-gray-600">Status</th><th class="px-4 py-3 font-medium text-gray-600 text-right">Amount</th></tr></thead>
        <tbody class="divide-y divide-gray-100">
            <?php if (empty($data)): ?><tr><td colspan="6" class="px-4 py-12 text-center text-gray-400">No payments in this period.</td></tr>
            <?php else: foreach ($data as $py): ?>
            <tr class="hover:bg-gray-50">
                <td class="px-4 py-3 text-gray-600"><?= formatDate($py['payment_date']) ?></td>
                <td class="px-4 py-3 font-medium"><?= htmlspecialchars(($py['first_name'] ?? '').' '.($py['last_name'] ?? '')) ?></td>
                <td class="px-4 py-3 text-gray-600"><?= htmlspecialchars(($py['property_name'] ?? '-').($py['unit_number'] ? ' / '.$py['unit_number'] : '')) ?></td>
                <td class="px-4 py-3"><?= ucfirst(str_replace('_',' ',$py['payment_method'] ?? '-')) ?></td>
                <td class="px-4 py-3"><?= statusBadge($py['status'] ?? 'pending') ?></td>
                <td class="px-4 py-3 text-right font-semibold"><?= formatMoney($py['amount']) ?></td>
            </tr>
            <?php endforeach; endif; ?>
        </tbody>
    </table>
</div>
