<div class="flex items-center justify-between mb-6">
    <div><h1 class="text-2xl font-bold text-gray-900">Vendors</h1><p class="text-sm text-gray-500 mt-1"><?= $total ?? 0 ?> vendors</p></div>
    <a href="?page=vendors&action=create" class="inline-flex items-center gap-2 px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition text-sm font-medium"><svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/></svg>Add Vendor</a>
</div>
<div class="bg-white rounded-xl shadow-sm border border-gray-200">
    <div class="p-4 border-b border-gray-100">
        <form method="GET" class="flex flex-wrap gap-3"><input type="hidden" name="page" value="vendors">
            <input type="text" name="search" value="<?= htmlspecialchars($_GET['search'] ?? '') ?>" placeholder="Search vendors..." class="flex-1 min-w-[200px] px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-indigo-500">
            <select name="category" class="px-3 py-2 border border-gray-300 rounded-lg text-sm focus:ring-2 focus:ring-indigo-500"><option value="">All Categories</option>
                <?php foreach (['plumbing','electrical','hvac','appliance','pest_control','general','painting','flooring','cleaning','landscaping','roofing','other'] as $c): ?><option value="<?= $c ?>" <?= ($_GET['category'] ?? '') === $c ? 'selected' : '' ?>><?= ucwords(str_replace('_',' ',$c)) ?></option><?php endforeach; ?>
            </select>
            <button type="submit" class="px-4 py-2 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 text-sm font-medium">Filter</button>
        </form>
    </div>
    <div class="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">Company</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">Category</th><th class="px-4 py-3 font-medium text-gray-600">W-9</th><th class="px-4 py-3 font-medium text-gray-600">Work Orders</th><th class="px-4 py-3 font-medium text-gray-600 text-right">Actions</th></tr></thead>
            <tbody class="divide-y divide-gray-100">
                <?php if (empty($vendors)): ?><tr><td colspan="6" class="px-4 py-12 text-center text-gray-400">No vendors found.</td></tr>
                <?php else: foreach ($vendors as $vn): ?>
                    <tr class="hover:bg-gray-50"><td class="px-4 py-3 font-medium text-gray-900"><a href="?page=vendors&action=show&id=<?= $vn['id'] ?>" class="hover:text-indigo-600"><?= htmlspecialchars($vn['company_name']) ?></a></td>
                    <td class="px-4 py-3 text-gray-600"><div><?= htmlspecialchars($vn['contact_name'] ?? '') ?></div><div class="text-xs text-gray-400"><?= htmlspecialchars($vn['email'] ?? '') ?></div></td>
                    <td class="px-4 py-3 text-gray-600"><?= ucwords(str_replace('_',' ',$vn['service_category'] ?? '-')) ?></td>
                    <td class="px-4 py-3"><?= statusBadge($vn['w9_status'] ?? 'pending') ?></td>
                    <td class="px-4 py-3"><span class="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-gray-100 text-gray-700"><?= $vn['wo_count'] ?></span></td>
                    <td class="px-4 py-3 text-right"><a href="?page=vendors&action=edit&id=<?= $vn['id'] ?>" class="text-indigo-600 hover:text-indigo-800 text-xs font-medium mr-3">Edit</a><a href="?page=vendors&action=show&id=<?= $vn['id'] ?>" class="text-gray-500 hover:text-gray-700 text-xs font-medium">View</a></td></tr>
                <?php endforeach; endif; ?>
            </tbody>
        </table>
    </div>
    <?php if (!empty($pagination)): ?><div class="px-4 py-3 border-t border-gray-100"><?= $pagination ?></div><?php endif; ?>
</div>
