@php use App\Models\Dsar\DsarEvidenceItem; @endphp
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <style>
        @page { margin: 18mm 16mm 18mm 16mm; }
        * { box-sizing: border-box; margin: 0; padding: 0; }
        body {
            font-family: 'DejaVu Sans', Arial, sans-serif;
            font-size: 10pt;
            color: #1a1a1a;
            line-height: 1.5;
        }
        h1 { font-size: 18pt; margin-bottom: 2px; }
        .subtitle { color: #666; font-size: 9pt; margin-bottom: 4px; }
        .meta { color: #888; font-size: 8.5pt; margin-bottom: 18px; }
        .rule { border-bottom: 2px solid #1a1a1a; margin-bottom: 18px; }

        .group { margin-bottom: 22px; page-break-inside: avoid; }
        .group-title {
            font-size: 12pt;
            font-weight: bold;
            border-bottom: 1px solid #ccc;
            padding-bottom: 4px;
            margin-bottom: 8px;
        }
        .group-title.untagged { color: #666; }
        .count-badge { font-size: 8.5pt; font-weight: normal; color: #888; }

        .item { padding: 6px 0; border-bottom: 1px solid #eee; page-break-inside: avoid; }
        .item:last-child { border-bottom: none; }
        .chips { margin-bottom: 3px; }
        .chip {
            display: inline-block;
            font-size: 7.5pt;
            padding: 1px 6px;
            border-radius: 8px;
            margin-right: 4px;
            border: 1px solid #ccc;
        }
        .sev-high { color: #b91c1c; border-color: #f0a0a0; }
        .sev-medium { color: #b45309; border-color: #f5cf8a; }
        .sev-low { color: #555; }
        blockquote {
            font-style: italic;
            color: #333;
            border-left: 3px solid #ddd;
            padding-left: 8px;
            margin: 2px 0 3px 0;
            font-size: 9.5pt;
        }
        .comment { font-size: 9pt; color: #444; }
        .provenance { font-size: 8pt; color: #999; margin-top: 2px; }
        .empty { color: #888; font-style: italic; }
    </style>
</head>
<body>
    <h1>Evidence Review Summary</h1>
    <div class="subtitle">{{ $client->fullName ?? $client->display_name ?? 'Client' }}</div>
    <div class="meta">
        {{ $totalItems }} confirmed item{{ $totalItems === 1 ? '' : 's' }}
        · Generated {{ $generatedAt->format('d M Y, H:i') }}
    </div>
    <div class="rule"></div>

    @forelse($groups as $group)
        <div class="group">
            <div class="group-title {{ $group['is_untagged'] ? 'untagged' : '' }}">
                {{ $group['label'] }}
                <span class="count-badge">— {{ $group['entries']->count() }} item{{ $group['entries']->count() === 1 ? '' : 's' }}</span>
            </div>

            @foreach($group['entries'] as $entry)
                @php $item = $entry['item']; $row = $entry['row']; @endphp
                <div class="item">
                    <div class="chips">
                        <span class="chip">{{ DsarEvidenceItem::categoryLabel($item->category) }}</span>
                        <span class="chip sev-{{ $item->severity }}">{{ ucfirst($item->severity) }}</span>
                    </div>
                    @if($item->quote)
                        <blockquote>"{{ $item->quote }}"</blockquote>
                    @endif
                    @if($item->comment)
                        <div class="comment">{{ $item->comment }}</div>
                    @endif
                    <div class="provenance">
                        Source: {{ $row['name'] }} ({{ $row['origin'] }})@if($item->page) · page {{ $item->page }}@endif
                        @if($row['institution']) · {{ $row['institution']->display_name }} @endif
                    </div>
                </div>
            @endforeach
        </div>
    @empty
        <p class="empty">No confirmed evidence to report yet. Confirm items in the evidence viewer to include them here.</p>
    @endforelse
</body>
</html>
