{{-- PDF 4: Reporte Mensual de Domingos y/o Festivos Laborados --}}
<!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:7pt; color:#222; }
.header { display:flex; justify-content:space-between; align-items:flex-start;
          border-bottom:2px solid #1a4f8a; padding-bottom:5px; margin-bottom:6px; }
.header-mid { text-align:center; flex:1; }
.header-mid h2 { font-size:11pt; color:#1a4f8a; }
.header-right { font-size:7pt; color:#555; text-align:right; min-width:120px; }
table { width:100%; border-collapse:collapse; font-size:6.5pt; }
th { background:#1a4f8a; color:#fff; padding:3px 2px; border:1px solid #888; text-align:center; }
td { border:1px solid #ddd; padding:2px 2px; text-align:center; }
.td-left { text-align:left; padding-left:4px; }
.th-nom  { text-align:left !important; min-width:100px; }
.td-dom  { background:#fce4ec; }
.td-sab  { background:#f1f8e9; }
.td-fest { background:#fff3e0; }
.td-total{ background:#fce4ec; font-weight:bold; color:#880e4f; }
.td-item { background:#f5f5f5; color:#888; font-size:6pt; }
</style>
</head>
<body>
@php use Carbon\Carbon; $diasSem = ['D','L','M','X','J','V','S']; @endphp

<div class="header">
    <div style="min-width:80px"></div>
    <div class="header-mid">
        <h2>Reporte Mensual de Domingos y/o Festivos Laborados</h2>
    </div>
    <div class="header-right">
        <strong>PERIODO</strong><br>
        {{ $periodo->fecha_inicio->format('d \d\e F \d\e Y') }}<br>
        {{ $periodo->fecha_fin->format('d \d\e F \d\e Y') }}
    </div>
</div>

<table>
    <thead>
        <tr>
            <th style="width:22px">ITEM</th>
            <th class="th-nom">NOMBRE</th>
            @foreach($fechas as $fecha)
            @php
                $cal = $calendario->get($fecha);
                $dow = $cal ? (int)$cal->dia_semana : Carbon::parse($fecha)->dayOfWeek;
                $fest= $cal ? (bool)$cal->es_festivo : false;
                // Solo resaltar DOM y festivos en el header
                $bg  = ($dow===0 || $fest) ? ($fest ? 'background:#fff3e0;color:#e65100' : 'background:#fce4ec;color:#880e4f') : '';
            @endphp
            <th style="width:18px;{{ $bg }}">
                {{ Carbon::parse($fecha)->day }}<br>{{ $diasSem[$dow] }}
            </th>
            @endforeach
            <th style="width:60px;background:#fce4ec;color:#880e4f">DOMINICAL o FESTIVO</th>
        </tr>
    </thead>
    <tbody>
    @foreach($filas as $i => $fila)
    <tr>
        <td class="td-item">{{ $i+1 }}</td>
        <td class="td-left">{{ $fila['empleado']->nombre }}</td>
        @foreach($fechas as $fecha)
        @php
            $cal2 = $calendario->get($fecha);
            $dow2 = $cal2 ? (int)$cal2->dia_semana : Carbon::parse($fecha)->dayOfWeek;
            $fest2= $cal2 ? (bool)$cal2->es_festivo : false;
            $h    = $fila['dias'][$fecha] ?? null;
            // Solo mostramos si es DOM o festivo
            $esDomFest = ($dow2===0 || $fest2);
            $cls  = $fest2 ? 'td-fest' : ($dow2===0 ? 'td-dom' : ($dow2===6 ? 'td-sab' : ''));
        @endphp
        <td class="{{ $cls }}">{{ ($esDomFest && $h > 0) ? number_format($h,1) : ($esDomFest ? '-' : '') }}</td>
        @endforeach
        <td class="td-total">{{ $fila['tiempo'] > 0 ? number_format($fila['tiempo'],1) : '-' }}</td>
    </tr>
    @endforeach
    </tbody>
</table>

<p style="margin-top:6px;font-size:5.5pt;color:#aaa;text-align:right">
    Código: 7_F15_v6 &nbsp;|&nbsp; Generado: {{ now()->format('d/m/Y H:i') }}
</p>
</body>
</html>
