<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Programări {{ $periodLabel }}</title>
<style>
  @page { margin: 18mm 14mm; }
  body { font-family: DejaVu Sans, sans-serif; font-size: 11px; color: #1a202c; }
  h1 { font-size: 18px; margin: 0 0 6px; color: #1a202c; }
  .sub { color: #718096; font-size: 11px; margin-bottom: 14px; }
  h2 { font-size: 14px; margin: 16px 0 8px; padding: 4px 8px; background: #ebf5ff; border-left: 3px solid #3b82f6; }
  table { width: 100%; border-collapse: collapse; }
  th { text-align: left; background: #f7fafc; font-size: 10px; padding: 6px 8px; border-bottom: 2px solid #e2e8f0; }
  td { padding: 6px 8px; border-bottom: 1px solid #edf2f7; vertical-align: top; }
  .time { font-weight: 700; color: #2563eb; white-space: nowrap; width: 60px; }
  .client-name { font-weight: 600; }
  .meta { color: #718096; font-size: 10px; }
  .footer { margin-top: 24px; padding-top: 8px; border-top: 1px solid #e2e8f0; font-size: 10px; color: #94a3b8; }
  .empty { padding: 20px; text-align: center; color: #94a3b8; font-style: italic; }
</style>
</head>
<body>
<h1>Programări — {{ $periodLabel }}</h1>
<div class="sub">Generat la {{ $generatedAt }} · {{ $appointments->flatten()->count() }} programări total</div>

@forelse ($appointments as $date => $dayAppts)
    @php $dateLabel = \Carbon\Carbon::parse($date)->locale('ro')->isoFormat('dddd, D MMMM YYYY'); @endphp
    <h2>{{ ucfirst($dateLabel) }} · {{ $dayAppts->count() }} programări</h2>
    <table>
        <thead>
            <tr>
                <th style="width:60px;">Ora</th>
                <th>Subiect</th>
                <th>Client / Auto</th>
                <th>Pod</th>
                <th>Maistru</th>
                <th style="width:60px;">Status</th>
            </tr>
        </thead>
        <tbody>
            @foreach ($dayAppts as $a)
                <tr>
                    <td class="time">{{ substr($a->time_start ?? '', 0, 5) }}–{{ substr($a->time_end ?? '', 0, 5) }}</td>
                    <td>{{ $a->title }}@if ($a->notes)<div class="meta">{{ $a->notes }}</div>@endif</td>
                    <td>
                        <div class="client-name">{{ $a->client?->name ?? '—' }}</div>
                        <div class="meta">
                            @if ($a->vehicle?->make){{ $a->vehicle?->make }} {{ $a->vehicle?->model }}@endif
                            @if ($a->vehicle?->plate) · {{ $a->vehicle->plate }}@endif
                        </div>
                    </td>
                    <td>{{ $a->post?->name ?? '—' }}</td>
                    <td>{{ $a->master?->name ?? '—' }}</td>
                    <td>{{ ucfirst($a->status) }}</td>
                </tr>
            @endforeach
        </tbody>
    </table>
@empty
    <div class="empty">Nicio programare în această perioadă.</div>
@endforelse

<div class="footer">AutoCRM PSauto · psauto.service.mir.md</div>
</body>
</html>
