<?php if (isset($component)) { $__componentOriginale0f1cdd055772eb1d4a99981c240763e = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginale0f1cdd055772eb1d4a99981c240763e = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.admin-layout','data' => ['title' => 'Dashboard']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('admin-layout'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['title' => 'Dashboard']); ?>
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.4/dist/chart.umd.min.js"></script>

<?php
    $statusColors = [
        'Novo'        => ['bg'=>'#dbeafe','color'=>'#1d4ed8'],
        'Em contato'  => ['bg'=>'#fef3c7','color'=>'#92400e'],
        'Qualificado' => ['bg'=>'#ede9fe','color'=>'#6d28d9'],
        'Convertido'  => ['bg'=>'#dcfce7','color'=>'#15803d'],
        'Perdido'     => ['bg'=>'#fee2e2','color'=>'#dc2626'],
    ];
    $prioColors = [
        'Crítica' => '#ef4444',
        'Alta'    => '#f59e0b',
        'Média'   => '#2563eb',
        'Baixa'   => '#94a3b8',
    ];
?>


<div style="margin-bottom:1.5rem;">
    <h1 style="font-size:1.25rem; font-weight:700; color:#1e3a5f; margin:0 0 2px;">Dashboard</h1>
    <p style="font-size:0.8125rem; color:#94a3b8; margin:0;">Visão geral atualizada em tempo real</p>
</div>


<div style="display:grid; grid-template-columns:repeat(auto-fit, minmax(180px,1fr)); gap:1rem; margin-bottom:1.5rem;">

    
    <div style="background:#fff; border:1px solid #e2e8f0; border-radius:14px; padding:1.25rem; display:flex; flex-direction:column; gap:0.5rem;">
        <div style="display:flex; align-items:center; justify-content:space-between;">
            <span style="font-size:0.75rem; font-weight:600; color:#64748b; text-transform:uppercase; letter-spacing:0.05em;">Leads / mês</span>
            <div style="width:34px;height:34px;border-radius:9px;background:#eff6ff;display:flex;align-items:center;justify-content:center;">
                <svg width="16" height="16" fill="none" stroke="#2563eb" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.75" 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 0z"/></svg>
            </div>
        </div>
        <p style="font-size:2rem; font-weight:800; color:#1e3a5f; margin:0; line-height:1;"><?php echo e($leadsNovosMes); ?></p>
        <p style="font-size:0.75rem; color:#94a3b8; margin:0;">em <?php echo e(now()->translatedFormat('F')); ?></p>
    </div>

    
    <div style="background:#fff; border:1px solid #e2e8f0; border-radius:14px; padding:1.25rem; display:flex; flex-direction:column; gap:0.5rem;">
        <div style="display:flex; align-items:center; justify-content:space-between;">
            <span style="font-size:0.75rem; font-weight:600; color:#64748b; text-transform:uppercase; letter-spacing:0.05em;">Demandas abertas</span>
            <div style="width:34px;height:34px;border-radius:9px;background:#f0fdf4;display:flex;align-items:center;justify-content:center;">
                <svg width="16" height="16" fill="none" stroke="#25b87e" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.75" d="M9 17V7m0 10a2 2 0 01-2 2H5a2 2 0 01-2-2V7a2 2 0 012-2h2a2 2 0 012 2m0 10a2 2 0 002 2h2a2 2 0 002-2M9 7a2 2 0 012-2h2a2 2 0 012 2m0 10V7"/></svg>
            </div>
        </div>
        <p style="font-size:2rem; font-weight:800; color:#1e3a5f; margin:0; line-height:1;"><?php echo e($demandasAbertas); ?></p>
        <p style="font-size:0.75rem; color:#94a3b8; margin:0;">em andamento</p>
    </div>

    
    <div style="background:#fff; border:1px solid <?php echo e($demandasVencidas > 0 ? '#fecaca' : '#e2e8f0'); ?>; border-radius:14px; padding:1.25rem; display:flex; flex-direction:column; gap:0.5rem; <?php echo e($demandasVencidas > 0 ? 'background:#fff5f5;' : ''); ?>">
        <div style="display:flex; align-items:center; justify-content:space-between;">
            <span style="font-size:0.75rem; font-weight:600; color:<?php echo e($demandasVencidas > 0 ? '#dc2626' : '#64748b'); ?>; text-transform:uppercase; letter-spacing:0.05em;">SLA vencido</span>
            <div style="width:34px;height:34px;border-radius:9px;background:#fee2e2;display:flex;align-items:center;justify-content:center;">
                <svg width="16" height="16" fill="none" stroke="#dc2626" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.75" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
            </div>
        </div>
        <p style="font-size:2rem; font-weight:800; color:<?php echo e($demandasVencidas > 0 ? '#dc2626' : '#1e3a5f'); ?>; margin:0; line-height:1;"><?php echo e($demandasVencidas); ?></p>
        <p style="font-size:0.75rem; color:#94a3b8; margin:0;"><?php echo e($demandasHoje); ?> vencem hoje</p>
    </div>

    
    <div style="background:#fff; border:1px solid #e2e8f0; border-radius:14px; padding:1.25rem; display:flex; flex-direction:column; gap:0.5rem;">
        <div style="display:flex; align-items:center; justify-content:space-between;">
            <span style="font-size:0.75rem; font-weight:600; color:#64748b; text-transform:uppercase; letter-spacing:0.05em;">Contratos ativos</span>
            <div style="width:34px;height:34px;border-radius:9px;background:#fef3c7;display:flex;align-items:center;justify-content:center;">
                <svg width="16" height="16" fill="none" stroke="#d97706" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.75" 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 style="font-size:2rem; font-weight:800; color:#1e3a5f; margin:0; line-height:1;"><?php echo e($contratosAtivos); ?></p>
        <p style="font-size:0.75rem; color:#94a3b8; margin:0;">em vigor</p>
    </div>

    
    <div style="background:#fff; border:1px solid #e2e8f0; border-radius:14px; padding:1.25rem; display:flex; flex-direction:column; gap:0.5rem;">
        <div style="display:flex; align-items:center; justify-content:space-between;">
            <span style="font-size:0.75rem; font-weight:600; color:#64748b; text-transform:uppercase; letter-spacing:0.05em;">Faturado / mês</span>
            <div style="width:34px;height:34px;border-radius:9px;background:#f0fdf4;display:flex;align-items:center;justify-content:center;">
                <svg width="16" height="16" fill="none" stroke="#25b87e" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.75" d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
            </div>
        </div>
        <p style="font-size:1.5rem; font-weight:800; color:#1e3a5f; margin:0; line-height:1;">R$ <?php echo e(number_format($receitaMes, 2, ',', '.')); ?></p>
        <p style="font-size:0.75rem; color:#94a3b8; margin:0;">A receber: R$ <?php echo e(number_format($receitaAReceber, 2, ',', '.')); ?></p>
    </div>
</div>


<div style="display:grid; grid-template-columns:repeat(auto-fit,minmax(280px,1fr)); gap:1rem; margin-bottom:1.5rem;">

    
    <div style="background:#fff; border:1px solid #e2e8f0; border-radius:14px; padding:1.25rem;">
        <div style="display:flex; align-items:center; justify-content:space-between; margin-bottom:1rem;">
            <h2 style="font-size:0.8125rem; font-weight:700; color:#1e3a5f; margin:0;">Leads por status</h2>
            <a href="<?php echo e(route('leads.index')); ?>" style="font-size:0.75rem; color:#25b87e; text-decoration:none;">Ver todos →</a>
        </div>
        <?php $totalLeads = $leadsPorStatus->sum(); ?>
        <div style="display:flex; flex-direction:column; gap:0.625rem;">
            <?php $__currentLoopData = \App\Models\Lead::statuses(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $status): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <?php
                $count = $leadsPorStatus[$status] ?? 0;
                $pct   = $totalLeads > 0 ? round($count / $totalLeads * 100) : 0;
                $sc    = $statusColors[$status] ?? ['bg'=>'#f1f5f9','color'=>'#64748b'];
            ?>
            <div>
                <div style="display:flex; justify-content:space-between; margin-bottom:3px;">
                    <span style="font-size:0.75rem; font-weight:500; color:#1e3a5f;"><?php echo e($status); ?></span>
                    <span style="font-size:0.75rem; font-weight:700; color:<?php echo e($sc['color']); ?>;"><?php echo e($count); ?></span>
                </div>
                <div style="height:6px; background:#f1f5f9; border-radius:100px; overflow:hidden;">
                    <div style="height:100%; width:<?php echo e($pct); ?>%; background:<?php echo e($sc['color']); ?>; border-radius:100px; transition:width 0.6s;"></div>
                </div>
            </div>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </div>
    </div>

    
    <div style="background:#fff; border:1px solid #e2e8f0; border-radius:14px; padding:1.25rem;">
        <div style="display:flex; align-items:center; justify-content:space-between; margin-bottom:1rem;">
            <h2 style="font-size:0.8125rem; font-weight:700; color:#1e3a5f; margin:0;">Contratos por status</h2>
            <a href="<?php echo e(route('contratos.index')); ?>" style="font-size:0.75rem; color:#25b87e; text-decoration:none;">Ver todos →</a>
        </div>
        <?php
            $steps = \App\Models\Contrato::workflowSteps();
            $totalContratos = $contratosPorStatus->sum();
        ?>
        <div style="display:flex; flex-direction:column; gap:0.5rem;">
            <?php $__currentLoopData = $steps; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $step): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <?php $count = $contratosPorStatus[$key] ?? 0; if(!$count) continue; ?>
            <div style="display:flex; align-items:center; justify-content:space-between; padding:0.375rem 0.5rem; border-radius:8px; background:#f8fafc;">
                <div style="display:flex; align-items:center; gap:0.5rem;">
                    <span style="width:8px; height:8px; border-radius:50%; background:<?php echo e($step['color']); ?>; flex-shrink:0;"></span>
                    <span style="font-size:0.75rem; color:#374151;"><?php echo e($step['label']); ?></span>
                </div>
                <span style="font-size:0.75rem; font-weight:700; color:<?php echo e($step['color']); ?>;"><?php echo e($count); ?></span>
            </div>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            <?php if($totalContratos === 0): ?>
                <p style="font-size:0.8125rem; color:#94a3b8; text-align:center; padding:1rem 0;">Nenhum contrato ainda</p>
            <?php endif; ?>
        </div>
    </div>
</div>


<div style="display:grid; grid-template-columns:repeat(auto-fit,minmax(280px,1fr)); gap:1rem; margin-bottom:1.5rem;">

    
    <div style="background:#fff; border:1px solid #e2e8f0; border-radius:14px; padding:1.25rem;">
        <div style="display:flex; align-items:center; justify-content:space-between; margin-bottom:1rem;">
            <h2 style="font-size:0.8125rem; font-weight:700; color:#1e3a5f; margin:0;">Leads — últimos 6 meses</h2>
        </div>
        <canvas id="leadsChart" height="110"></canvas>
    </div>

    
    <div style="background:#fff; border:1px solid #e2e8f0; border-radius:14px; padding:1.25rem;">
        <div style="display:flex; align-items:center; justify-content:space-between; margin-bottom:1rem;">
            <h2 style="font-size:0.8125rem; font-weight:700; color:#1e3a5f; margin:0;">Demandas por setor</h2>
        </div>
        <canvas id="setorChart" height="130"></canvas>
    </div>
</div>


<div style="background:#fff; border:1px solid #e2e8f0; border-radius:14px; padding:1.25rem; margin-bottom:1.5rem;">
    <div style="display:flex; align-items:center; justify-content:space-between; margin-bottom:1rem;">
        <h2 style="font-size:0.8125rem; font-weight:700; color:#1e3a5f; margin:0;">Receita recebida — últimos 6 meses</h2>
        <a href="<?php echo e(route('admin.financeiro.index')); ?>" style="font-size:0.75rem; color:#25b87e; text-decoration:none;">Ver financeiro →</a>
    </div>
    <canvas id="receitaChart" height="80"></canvas>
</div>


<div style="display:grid; grid-template-columns:repeat(auto-fit,minmax(280px,1fr)); gap:1rem;">

    
    <div style="background:#fff; border:1px solid #e2e8f0; border-radius:14px; overflow:hidden;">
        <div style="padding:1rem 1.25rem; border-bottom:1px solid #f1f5f9; display:flex; align-items:center; justify-content:space-between;">
            <h2 style="font-size:0.8125rem; font-weight:700; color:#1e3a5f; margin:0;">Últimos leads</h2>
            <a href="<?php echo e(route('leads.index')); ?>" style="font-size:0.75rem; color:#25b87e; text-decoration:none;">Ver CRM →</a>
        </div>
        <div>
            <?php $__empty_1 = true; $__currentLoopData = $leadsRecentes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $lead): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
            <?php $sc = $statusColors[$lead->status] ?? ['bg'=>'#f1f5f9','color'=>'#64748b']; ?>
            <div style="padding:0.75rem 1.25rem; border-bottom:1px solid #f8fafc; display:flex; align-items:center; gap:0.75rem;">
                <div style="width:32px;height:32px;border-radius:9px;background:#e8f8f1;display:flex;align-items:center;justify-content:center;font-size:0.75rem;font-weight:700;color:#25b87e;flex-shrink:0;">
                    <?php echo e(strtoupper(substr($lead->name, 0, 2))); ?>

                </div>
                <div style="flex:1; min-width:0;">
                    <p style="font-size:0.8125rem; font-weight:600; color:#1e3a5f; margin:0; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;"><?php echo e($lead->name); ?></p>
                    <p style="font-size:0.6875rem; color:#94a3b8; margin:0;"><?php echo e($lead->company ?? $lead->email); ?></p>
                </div>
                <span style="padding:0.2rem 0.5rem; border-radius:100px; font-size:0.6875rem; font-weight:600; background:<?php echo e($sc['bg']); ?>; color:<?php echo e($sc['color']); ?>; white-space:nowrap; flex-shrink:0;">
                    <?php echo e($lead->status); ?>

                </span>
            </div>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
            <p style="padding:1.5rem; text-align:center; color:#94a3b8; font-size:0.8125rem;">Nenhum lead ainda</p>
            <?php endif; ?>
        </div>
    </div>

    
    <div style="background:#fff; border:1px solid #e2e8f0; border-radius:14px; overflow:hidden;">
        <div style="padding:1rem 1.25rem; border-bottom:1px solid #f1f5f9; display:flex; align-items:center; justify-content:space-between;">
            <h2 style="font-size:0.8125rem; font-weight:700; color:#1e3a5f; margin:0;">Demandas prioritárias</h2>
            <a href="<?php echo e(route('kanban.index')); ?>" style="font-size:0.75rem; color:#25b87e; text-decoration:none;">Ver Kanban →</a>
        </div>
        <div>
            <?php $__empty_1 = true; $__currentLoopData = $demandasUrgentes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $dem): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
            <?php $vencida = $dem->isVencida(); $hoje = $dem->isVenceHoje(); ?>
            <div style="padding:0.75rem 1.25rem; border-bottom:1px solid #f8fafc; display:flex; align-items:center; gap:0.75rem;">
                <span style="width:8px;height:8px;border-radius:50%;flex-shrink:0;background:<?php echo e($prioColors[$dem->prioridade] ?? '#94a3b8'); ?>;"></span>
                <div style="flex:1; min-width:0;">
                    <p style="font-size:0.8125rem; font-weight:600; color:#1e3a5f; margin:0; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;"><?php echo e($dem->titulo); ?></p>
                    <p style="font-size:0.6875rem; color:#94a3b8; margin:0;"><?php echo e($dem->cliente); ?> · <?php echo e($dem->setor); ?></p>
                </div>
                <?php if($vencida): ?>
                    <span style="padding:0.2rem 0.5rem; border-radius:100px; font-size:0.6875rem; font-weight:700; background:#fee2e2; color:#dc2626; white-space:nowrap; flex-shrink:0;">Vencida</span>
                <?php elseif($hoje): ?>
                    <span style="padding:0.2rem 0.5rem; border-radius:100px; font-size:0.6875rem; font-weight:700; background:#fef3c7; color:#92400e; white-space:nowrap; flex-shrink:0;">Hoje</span>
                <?php elseif($dem->sla_vencimento): ?>
                    <span style="padding:0.2rem 0.5rem; border-radius:100px; font-size:0.6875rem; color:#64748b; background:#f1f5f9; white-space:nowrap; flex-shrink:0;"><?php echo e($dem->sla_vencimento->format('d/m')); ?></span>
                <?php endif; ?>
            </div>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
            <p style="padding:1.5rem; text-align:center; color:#94a3b8; font-size:0.8125rem;">Nenhuma demanda aberta</p>
            <?php endif; ?>
        </div>
    </div>
</div>

<script>
document.addEventListener('DOMContentLoaded', function () {
    const font = { family: 'Poppins, sans-serif', size: 11 };
    const gridColor = '#f1f5f9';
    const navy = '#1e3a5f';
    const green = '#25b87e';

    // Leads chart
    new Chart(document.getElementById('leadsChart'), {
        type: 'bar',
        data: {
            labels: <?php echo json_encode($leadsChartLabels, 15, 512) ?>,
            datasets: [{
                label: 'Leads',
                data: <?php echo json_encode($leadsChartData, 15, 512) ?>,
                backgroundColor: 'rgba(37,184,126,0.18)',
                borderColor: green,
                borderWidth: 2,
                borderRadius: 6,
            }]
        },
        options: {
            responsive: true, maintainAspectRatio: true,
            plugins: { legend: { display: false } },
            scales: {
                x: { grid: { display: false }, ticks: { font, color: '#94a3b8' } },
                y: { grid: { color: gridColor }, ticks: { font, color: '#94a3b8', stepSize: 1 }, beginAtZero: true },
            }
        }
    });

    // Setor doughnut
    const setorLabels = <?php echo json_encode($demandaPorSetor->keys(), 15, 512) ?>;
    const setorData   = <?php echo json_encode($demandaPorSetor->values(), 15, 512) ?>;
    const palette = ['#1e3a5f','#25b87e','#2563eb','#d97706','#7c3aed','#0369a1','#dc2626','#475569'];
    new Chart(document.getElementById('setorChart'), {
        type: 'doughnut',
        data: {
            labels: setorLabels,
            datasets: [{ data: setorData, backgroundColor: palette, borderWidth: 0, hoverOffset: 4 }]
        },
        options: {
            responsive: true, maintainAspectRatio: true, cutout: '65%',
            plugins: {
                legend: { position: 'bottom', labels: { font, color: navy, boxWidth: 10, padding: 12 } }
            }
        }
    });

    // Receita chart
    new Chart(document.getElementById('receitaChart'), {
        type: 'line',
        data: {
            labels: <?php echo json_encode($receitaChartLabels, 15, 512) ?>,
            datasets: [{
                label: 'Receita (R$)',
                data: <?php echo json_encode($receitaChartData, 15, 512) ?>,
                borderColor: navy,
                backgroundColor: 'rgba(30,58,95,0.07)',
                borderWidth: 2,
                pointBackgroundColor: navy,
                pointRadius: 4,
                fill: true,
                tension: 0.35,
            }]
        },
        options: {
            responsive: true, maintainAspectRatio: true,
            plugins: { legend: { display: false } },
            scales: {
                x: { grid: { display: false }, ticks: { font, color: '#94a3b8' } },
                y: {
                    grid: { color: gridColor }, beginAtZero: true,
                    ticks: { font, color: '#94a3b8', callback: v => 'R$ ' + v.toLocaleString('pt-BR') }
                },
            }
        }
    });
});
</script>

 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginale0f1cdd055772eb1d4a99981c240763e)): ?>
<?php $attributes = $__attributesOriginale0f1cdd055772eb1d4a99981c240763e; ?>
<?php unset($__attributesOriginale0f1cdd055772eb1d4a99981c240763e); ?>
<?php endif; ?>
<?php if (isset($__componentOriginale0f1cdd055772eb1d4a99981c240763e)): ?>
<?php $component = $__componentOriginale0f1cdd055772eb1d4a99981c240763e; ?>
<?php unset($__componentOriginale0f1cdd055772eb1d4a99981c240763e); ?>
<?php endif; ?>
<?php /**PATH C:\ProjetosWeb\OPCON\resources\views\pages\admin\dashboard.blade.php ENDPATH**/ ?>