<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Reporte de Ventas</title>

<style>
body{
    font-family: DejaVu Sans, sans-serif;
    font-size: 12px;
    color: #1f2937;
}

h1{
    font-size: 18px;
    margin-bottom: 5px;
}

.header{
    margin-bottom: 15px;
}

.info{
    margin-bottom: 10px;
}

.table{
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

.table th{
    background: #22c55e;
    color: #ffffff;
    padding: 8px;
    text-align: left;
    font-weight: bold;
}

.table td{
    padding: 8px;
    border-bottom: 1px solid #e5e7eb;
}

.resumen{
    margin-top: 20px;
    width: 40%;
    float: right;
}

.resumen td{
    padding: 6px;
}

.total-final{
    font-size: 14px;
    font-weight: bold;
    border-top: 2px solid #000;
}
</style>
</head>
<body>

<div class="header">
    <h1>REPORTE DE VENTAS</h1>
</div>

<div class="info">
    <strong>Periodo:</strong> {{ \Carbon\Carbon::parse($from)->format('d/m/Y') }}
    al
    {{ \Carbon\Carbon::parse($to)->format('d/m/Y') }}
</div>

<table class="table">
    <thead>
        <tr>
            <th>No.</th>
            <th>Fecha</th>
            <th>Cliente</th>
            <th>Total</th>
            <th>Estado</th>
        </tr>
    </thead>
    <tbody>
        @foreach($cotizaciones as $c)
        <tr>
            <td>#{{ $c->id }}</td>
            <td>{{ $c->created_at->format('d/m/Y') }}</td>
            <td>{{ $c->cliente->nombre ?? '' }}</td>
            <td>${{ number_format($c->total,2) }}</td>
            <td>
                @if($c->estado=='aprobada')
                    Pagada
                @else
                    Pendiente
                @endif
            </td>
        </tr>
        @endforeach
    </tbody>
</table>

@php
$totalCount = $cotizaciones->count();
@endphp

<table class="resumen">
    <tr>
        <td>Total de cotizaciones:</td>
        <td>{{ $totalCount }}</td>
    </tr>
    <tr class="total-final">
        <td>Total vendido:</td>
        <td>${{ number_format($totalSales,2) }}</td>
    </tr>
</table>

</body>
</html>