<div class="space-y-6">
    <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-5">
        <div class="glass rounded-2xl p-5 shadow-sm border border-slate-200/60">
            <div class="flex items-center justify-between mb-4">
                <div class="w-11 h-11 rounded-xl bg-blue-100 flex items-center justify-center">
                    <svg xmlns="http://www.w3.org/2000/svg" class="w-5.5 h-5.5 text-blue-600" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.8">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z" />
                    </svg>
                </div>
            </div>
            <p class="text-xs font-semibold text-slate-400 uppercase tracking-wider mb-1">Total Leads</p>
            <p class="text-3xl font-bold text-slate-800"><?= $totalLeads ?? 0 ?></p>
        </div>

        <div class="glass rounded-2xl p-5 shadow-sm border border-slate-200/60">
            <div class="flex items-center justify-between mb-4">
                <div class="w-11 h-11 rounded-xl bg-emerald-100 flex items-center justify-center">
                    <svg xmlns="http://www.w3.org/2000/svg" class="w-5.5 h-5.5 text-emerald-600" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.8">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
                    </svg>
                </div>
            </div>
            <p class="text-xs font-semibold text-slate-400 uppercase tracking-wider mb-1">Documents</p>
            <p class="text-3xl font-bold text-slate-800"><?= $totalDocuments ?? 0 ?></p>
        </div>

        <div class="glass rounded-2xl p-5 shadow-sm border border-slate-200/60">
            <div class="flex items-center justify-between mb-4">
                <div class="w-11 h-11 rounded-xl bg-amber-100 flex items-center justify-center">
                    <svg xmlns="http://www.w3.org/2000/svg" class="w-5.5 h-5.5 text-amber-600" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.8">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z" />
                    </svg>
                </div>
            </div>
            <p class="text-xs font-semibold text-slate-400 uppercase tracking-wider mb-1">Agents</p>
            <p class="text-3xl font-bold text-slate-800"><?= $totalAgents ?? 0 ?></p>
        </div>

        <div class="glass rounded-2xl p-5 shadow-sm border border-slate-200/60">
            <div class="flex items-center justify-between mb-4">
                <div class="w-11 h-11 rounded-xl bg-purple-100 flex items-center justify-center">
                    <svg xmlns="http://www.w3.org/2000/svg" class="w-5.5 h-5.5 text-purple-600" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.8">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4" />
                    </svg>
                </div>
            </div>
            <p class="text-xs font-semibold text-slate-400 uppercase tracking-wider mb-1">Statuses</p>
            <p class="text-3xl font-bold text-slate-800"><?= $totalStatuses ?? 0 ?></p>
        </div>
    </div>

    <div class="glass rounded-2xl p-6 shadow-sm border border-slate-200/60">
        <div class="flex items-center justify-between mb-5">
            <div class="flex items-center gap-3">
                <div class="w-9 h-9 rounded-xl bg-blue-100 flex items-center justify-center">
                    <svg xmlns="http://www.w3.org/2000/svg" class="w-4.5 h-4.5 text-blue-600" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.8">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
                    </svg>
                </div>
                <div>
                    <h4 class="text-sm font-bold text-slate-800">Recent Leads</h4>
                    <p class="text-xs text-slate-500">Latest leads added to the system</p>
                </div>
            </div>
            <a href="<?= site_url('/admin/leads') ?>" class="text-xs font-semibold text-blue-600 hover:text-blue-700 transition">View All &rarr;</a>
        </div>

        <?php if (empty($recentLeads)): ?>
            <div class="py-12 text-center">
                <div class="w-14 h-14 rounded-2xl bg-slate-100 flex items-center justify-center mx-auto mb-3">
                    <svg xmlns="http://www.w3.org/2000/svg" class="w-7 h-7 text-slate-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.8">
                        <path stroke-linecap="round" stroke-linejoin="round" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z" />
                    </svg>
                </div>
                <p class="text-sm font-medium text-slate-600">No leads yet</p>
                <p class="text-xs text-slate-400 mt-0.5">Get started by creating your first lead</p>
            </div>
        <?php else: ?>
            <div class="space-y-2">
                <?php foreach ($recentLeads as $lead): ?>
                    <a href="<?= site_url('/admin/leads/view/' . $lead['id']) ?>" class="flex items-center justify-between p-3 rounded-xl hover:bg-slate-50 transition group">
                        <div class="flex items-center gap-3">
                            <div class="w-10 h-10 rounded-xl bg-gradient-to-br from-blue-500 to-indigo-600 flex items-center justify-center text-white font-semibold text-sm shadow-sm">
                                <?= strtoupper(substr(esc($lead['name']), 0, 1)) ?>
                            </div>
                            <div>
                                <p class="text-sm font-semibold text-slate-700 group-hover:text-blue-600 transition"><?= esc($lead['name']) ?></p>
                                <p class="text-xs text-slate-400 font-mono"><?= esc($lead['lead_number']) ?></p>
                            </div>
                        </div>
                        <div class="flex items-center gap-4">
                            <?php if (!empty($lead['status_name'])): ?>
                                <span class="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-[11px] font-semibold" style="background: <?= esc($lead['status_color'] ?? '#3b82f6') ?>18; color: <?= esc($lead['status_color'] ?? '#3b82f6') ?>;">
                                    <span class="w-1.5 h-1.5 rounded-full" style="background: <?= esc($lead['status_color'] ?? '#3b82f6') ?>;"></span>
                                    <?= esc($lead['status_name']) ?>
                                </span>
                            <?php endif; ?>
                            <span class="text-xs text-slate-400"><?= !empty($lead['created_at']) ? date('M j', strtotime($lead['created_at'])) : '' ?></span>
                        </div>
                    </a>
                <?php endforeach; ?>
            </div>
        <?php endif; ?>
    </div>
</div>
