{{-- PDF 2: Reporte de Tiempo Laborado Acumulado por Empleado --}}
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<style>
* { box-sizing:border-box; margin:0; padding:0; }
body { font-family: DejaVu Sans, Arial, sans-serif; font-size:8pt; color:#222; }
.header { display:flex; justify-content:space-between; align-items:center;
          border-bottom:2px solid #1a4f8a; padding-bottom:6px; margin-bottom:8px; }
.header-title { text-align:center; flex:1; }
.header-title h2 { font-size:12pt; color:#1a4f8a; }
.header-title p  { font-size:9pt; color:#1a4f8a; font-weight:bold; }
.header-periodo  { font-size:8pt; color:#555; text-align:right; }
table { width:100%; border-collapse:collapse; font-size:7.5pt; }
th { background:#1a4f8a; color:#fff; padding:4px 6px; text-align:center; border:1px solid #ccc; }
td { border:1px solid #ddd; padding:3px 6px; }
.td-left  { text-align:left; }
.td-right { text-align:right; }
.td-center{ text-align:center; }
.tr-emp   { background:#e8f0fd; font-weight:bold; }
.tr-cc    { background:#fff; }
.tr-total { background:#e8f5e9; font-weight:bold; }
</style>
</head>
<body>

<div class="header">
    <div style="width:100px"></div>
    <div class="header-title">
        <h2>REPORTE DE TIEMPO LABORADO ACUMULADO</h2>
        <p>POR EMPLEADO</p>
        <p>PERIODO {{ strtoupper($periodo->nombre_completo) }}</p>
    </div>
    <div class="header-periodo">
        {{ $periodo->fecha_inicio->format('d/m/Y') }}<br>
        al {{ $periodo->fecha_fin->format('d/m/Y') }}
    </div>
</div>

<table>
    <thead>
        <tr>
            <th style="width:30px">ITEM</th>
            <th style="text-align:left;width:130px">NOMBRE</th>
            <th style="text-align:left">CENTRO DE COSTO</th>
            <th style="width:55px">CÓDIGO</th>
            <th style="width:65px">LABORADAS</th>
            <th style="width:70px">EQUIVALENTES</th>
            <th style="width:40px">%</th>
        </tr>
    </thead>
    <tbody>
    @php $item = 1; @endphp
    @foreach($datos as $r)
    @php
        $emp = $r['empleado'];
        $dist = $r['distribucion'];
        $totalHoras = $r['horas_productivas'];
    @endphp
    <tr class="tr-emp">
        <td class="td-center" rowspan="{{ max(1,$dist->count()) + 1 }}">{{ $item++ }}</td>
        <td class="td-left"  rowspan="{{ max(1,$dist->count()) + 1 }}">{{ $emp->nombre }}</td>
        <td class="td-left"  colspan="4" style="font-size:7pt;color:#555">
            C.C. {{ $emp->cedula }} — {{ $emp->cargo }} — Estado: {{ strtoupper($r['hoja']->estado) }}
        </td>
        <td class="td-center">{{ number_format($totalHoras,2) }}</td>
    </tr>
    @foreach($dist as $d)
    <tr class="tr-cc">
        <td class="td-left">{{ $d['nombre'] }}</td>
        <td class="td-center">{{ $d['codigo'] ?? '—' }}</td>
        <td class="td-right">{{ number_format($d['horas'],2) }}</td>
        <td class="td-right">{{ number_format($d['equivalente_real'],0,'.',',') }}</td>
        <td class="td-center">{{ number_format($d['porcentaje'],2) }}%</td>
    </tr>
    @endforeach
    @endforeach
    </tbody>
</table>

<p style="margin-top:8px;font-size:6.5pt;color:#888;text-align:right">
    Generado: {{ now()->format('d/m/Y H:i') }}
</p>
</body>
</html>
