<div class="flex items-center gap-3 mb-6"><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">Maintenance Report</h1></div>

<div class="grid grid-cols-2 md:grid-cols-4 gap-4 mb-6">
    <?php foreach (['new'=>['New','blue'],'assigned'=>['Assigned','yellow'],'in_progress'=>['In Progress','orange'],'completed'=>['Completed','green']] as $s=>[$label,$color]): ?>
    <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-4 text-center">
        <p class="text-xs text-gray-500 uppercase"><?= $label ?></p>
        <p class="text-2xl font-bold text-<?= $color ?>-600 mt-1"><?= $byStatus[$s] ?? 0 ?></p>
    </div>
    <?php endforeach; ?>
</div>

<div class="grid grid-cols-2 md:grid-cols-4 gap-4 mb-6">
    <?php foreach (['emergency'=>['Emergency','red'],'high'=>['High','orange'],'medium'=>['Medium','yellow'],'low'=>['Low','green']] as $pr=>[$label,$color]): ?>
    <div class="bg-<?= $color ?>-50 rounded-xl border border-<?= $color ?>-200 p-4 text-center">
        <p class="text-xs text-<?= $color ?>-700 uppercase">Priority: <?= $label ?></p>
        <p class="text-2xl font-bold text-<?= $color ?>-700 mt-1"><?= $byPriority[$pr] ?? 0 ?></p>
    </div>
    <?php endforeach; ?>
</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">Title</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">Tenant</th><th class="px-4 py-3 font-medium text-gray-600">Priority</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">Created</th></tr></thead>
        <tbody class="divide-y divide-gray-100">
            <?php foreach ($data as $r): ?>
            <tr class="hover:bg-gray-50">
                <td class="px-4 py-3 font-medium"><?= htmlspecialchars($r['title']) ?></td>
                <td class="px-4 py-3 text-gray-600"><?= htmlspecialchars(($r['property_name'] ?? '-').($r['unit_number'] ? ' / '.$r['unit_number'] : '')) ?></td>
                <td class="px-4 py-3 text-gray-600"><?= htmlspecialchars(($r['tenant_first'] ?? '').' '.($r['tenant_last'] ?? '')) ?></td>
                <td class="px-4 py-3"><?= priorityBadge($r['priority'] ?? 'medium') ?></td>
                <td class="px-4 py-3"><?= statusBadge($r['status'] ?? 'new') ?></td>
                <td class="px-4 py-3 text-gray-500"><?= formatDate($r['created_at']) ?></td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
</div>
