<div class="max-w-4xl mx-auto">
    <div class="flex items-center justify-between mb-6">
        <div class="flex items-center gap-3">
            <a href="?page=vendors" 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"><?= htmlspecialchars($vendor['company_name']) ?></h1>
                <p class="text-sm text-gray-500"><?= htmlspecialchars($vendor['contact_name'] ?? '') ?> · <?= ucwords(str_replace('_',' ',$vendor['service_category'] ?? 'General')) ?></p>
            </div>
        </div>
        <div class="flex gap-2">
            <a href="?page=vendors&action=edit&id=<?= $vendor['id'] ?>" class="px-4 py-2 border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-50 text-sm font-medium">Edit</a>
            <form method="POST" action="?page=vendors&action=delete&id=<?= $vendor['id'] ?>" onsubmit="return confirm('Delete this vendor?')"><?= CSRF::field() ?><button class="px-4 py-2 border border-red-300 text-red-600 rounded-lg hover:bg-red-50 text-sm font-medium">Delete</button></form>
        </div>
    </div>

    <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6">
        <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-5">
            <p class="text-xs font-medium text-gray-500 uppercase">W-9 Status</p>
            <div class="mt-2"><?= statusBadge($vendor['w9_status'] ?? 'pending') ?></div>
        </div>
        <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-5">
            <p class="text-xs font-medium text-gray-500 uppercase">Insurance Expiry</p>
            <p class="text-lg font-bold text-gray-900 mt-1"><?= $vendor['insurance_expiry'] ? formatDate($vendor['insurance_expiry']) : 'Not set' ?></p>
            <?php if ($vendor['insurance_expiry'] && strtotime($vendor['insurance_expiry']) < time()): ?><p class="text-xs text-red-600 mt-1">Expired</p><?php endif; ?>
        </div>
        <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-5">
            <p class="text-xs font-medium text-gray-500 uppercase">Rating</p>
            <p class="text-lg font-bold text-gray-900 mt-1"><?php if ($vendor['rating']): for ($i=1;$i<=5;$i++) echo $i<=$vendor['rating'] ? '⭐' : '☆'; else: echo '-'; endif; ?></p>
        </div>
    </div>

    <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
        <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-6">
            <h3 class="text-sm font-semibold text-gray-500 uppercase tracking-wider mb-4">Contact Info</h3>
            <dl class="space-y-3 text-sm">
                <div class="flex justify-between"><dt class="text-gray-500">Email</dt><dd class="font-medium"><a href="mailto:<?= htmlspecialchars($vendor['email']) ?>" class="text-indigo-600 hover:underline"><?= htmlspecialchars($vendor['email']) ?></a></dd></div>
                <div class="flex justify-between"><dt class="text-gray-500">Phone</dt><dd class="font-medium"><?= htmlspecialchars($vendor['phone'] ?? '-') ?></dd></div>
                <div class="flex justify-between"><dt class="text-gray-500">Address</dt><dd class="font-medium text-right"><?= htmlspecialchars(implode(', ', array_filter([$vendor['address'],$vendor['city'],$vendor['state'],$vendor['zip']])) ?: '-') ?></dd></div>
            </dl>
        </div>
        <?php if ($vendor['notes']): ?>
        <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-6">
            <h3 class="text-sm font-semibold text-gray-500 uppercase tracking-wider mb-4">Notes</h3>
            <p class="text-sm text-gray-700 whitespace-pre-line"><?= htmlspecialchars($vendor['notes']) ?></p>
        </div>
        <?php endif; ?>
    </div>

    <div class="bg-white rounded-xl shadow-sm border border-gray-200 p-6">
        <h3 class="text-sm font-semibold text-gray-500 uppercase tracking-wider mb-4">Recent Work Orders</h3>
        <?php if (!empty($workOrders)): ?>
            <table class="w-full text-sm">
                <thead class="text-left"><tr><th class="pb-2 font-medium text-gray-600">Title</th><th class="pb-2 font-medium text-gray-600">Property</th><th class="pb-2 font-medium text-gray-600">Status</th><th class="pb-2 font-medium text-gray-600">Cost</th></tr></thead>
                <tbody class="divide-y divide-gray-50">
                    <?php foreach ($workOrders as $wo): ?>
                        <tr><td class="py-2 font-medium"><?= htmlspecialchars($wo['title'] ?? 'WO #'.$wo['id']) ?></td><td class="py-2 text-gray-600"><?= htmlspecialchars($wo['property_name'] ?? '-') ?></td><td class="py-2"><?= statusBadge($wo['status']) ?></td><td class="py-2 font-medium"><?= $wo['cost'] ? formatMoney($wo['cost']) : '-' ?></td></tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        <?php else: ?><p class="text-gray-400 text-sm">No work orders assigned</p><?php endif; ?>
    </div>
</div>
