<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>{{ $definition->title }}</title>
    <style>
        {{--
            A plain <table> throughout — dompdf's CSS Grid and float support
            silently misplace content (see the QR label sheet in Phase 7).
            Landscape A4 because a report can carry six or more columns and a
            portrait page forces most of them into an unreadable wrap.
        --}}
        body {
            color: #111827;
            font-family: 'Helvetica', 'Arial', sans-serif;
            font-size: 9pt;
            margin: 0;
        }

        .header {
            border-bottom: 2pt solid #0d9488;
            margin-bottom: 12pt;
            padding-bottom: 8pt;
        }

        .header h1 {
            color: #111827;
            font-size: 16pt;
            margin: 0 0 3pt;
        }

        .header p {
            color: #6b7280;
            font-size: 8pt;
            margin: 0;
        }

        table.data {
            border-collapse: collapse;
            width: 100%;
        }

        table.data th {
            background-color: #f3f4f6;
            border-bottom: 1pt solid #d1d5db;
            color: #374151;
            font-size: 8pt;
            padding: 5pt 6pt;
            text-align: left;
        }

        table.data td {
            border-bottom: 0.5pt solid #e5e7eb;
            padding: 5pt 6pt;
        }

        table.data th.numeric,
        table.data td.numeric {
            text-align: right;
        }

        .footer {
            color: #9ca3af;
            font-size: 7pt;
            margin-top: 10pt;
        }

        .empty {
            color: #6b7280;
            padding: 20pt 0;
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="header">
        <h1>{{ $definition->title }}</h1>
        <p>{{ $definition->description }}</p>
        <p>Aumni AMS &middot; Generated {{ $generatedAt->format('d M Y, H:i') }} &middot; {{ $rows->count() }} {{ \Illuminate\Support\Str::plural('record', $rows->count()) }}</p>
    </div>

    @if ($rows->isEmpty())
        <p class="empty">No records match these filters.</p>
    @else
        <table class="data">
            <thead>
                <tr>
                    @foreach ($definition->columns as $column)
                        <th class="{{ $column->numeric ? 'numeric' : '' }}">{{ $column->label }}</th>
                    @endforeach
                </tr>
            </thead>
            <tbody>
                @foreach ($rows as $row)
                    <tr>
                        @foreach ($definition->columns as $column)
                            <td class="{{ $column->numeric ? 'numeric' : '' }}">{{ $row[$column->key] ?? '—' }}</td>
                        @endforeach
                    </tr>
                @endforeach
            </tbody>
        </table>
    @endif

    <div class="footer">
        Aumni Techworks LLP &middot; Internal use only
    </div>
</body>
</html>
