<!DOCTYPE html>
<html lang="it">
<head>
    <meta charset="UTF-8">
    <title>Log Import XML</title>
    <style>
        body { font-family: DejaVu Sans, sans-serif; font-size: 12px; color: #111; margin: 20px; }
        h1 { font-size: 17px; margin-bottom: 4px; }
        .meta { font-size: 11px; color: #555; margin-bottom: 16px; }
        .stats-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
        .stat { background: #f3f4f6; border: 1px solid #e5e7eb; border-radius: 6px; padding: 8px 12px; min-width: 180px; }
        .stat-label { font-size: 11px; color: #6b7280; }
        .stat-value { font-size: 14px; font-weight: bold; color: #1f2937; }
        h2 { font-size: 14px; margin-top: 20px; margin-bottom: 8px; border-bottom: 1px solid #e5e7eb; padding-bottom: 4px; }
        table { width: 100%; border-collapse: collapse; font-size: 11px; }
        thead tr { background: #f9fafb; }
        th { text-align: left; padding: 7px 8px; border-bottom: 1px solid #d1d5db; font-size: 11px; color: #374151; }
        td { padding: 6px 8px; border-bottom: 1px solid #f3f4f6; vertical-align: top; }
        tr:nth-child(even) td { background: #f9fafb; }
        .badge-err { color: #b91c1c; font-weight: bold; }
        .footer { margin-top: 30px; font-size: 10px; color: #9ca3af; text-align: right; }
    </style>
</head>
<body>
    <h1>Log Import XML — TerManager2</h1>
    <div class="meta">Generato il {{ $generatedAt }}</div>

    <div class="stats-grid">
        <div class="stat"><div class="stat-label">Zone importate</div><div class="stat-value">{{ $stats['zone_importate'] ?? 0 }}</div></div>
        <div class="stat"><div class="stat-label">Tipologie importate</div><div class="stat-value">{{ $stats['tipologie_importate'] ?? 0 }}</div></div>
        <div class="stat"><div class="stat-label">Proclamatori importati</div><div class="stat-value">{{ $stats['proclamatori_importati'] ?? 0 }}</div></div>
        <div class="stat"><div class="stat-label">Territori importati</div><div class="stat-value">{{ $stats['territori_importati'] ?? 0 }}</div></div>
        <div class="stat"><div class="stat-label">Anni teocratici</div><div class="stat-value">{{ $stats['anni_importati'] ?? 0 }}</div></div>
        <div class="stat"><div class="stat-label">Campagne importate</div><div class="stat-value">{{ $stats['campagne_importate'] ?? 0 }}</div></div>
        <div class="stat"><div class="stat-label">Assegnazioni importate</div><div class="stat-value">{{ $stats['assegnazioni_importate'] ?? 0 }}</div></div>
        <div class="stat"><div class="stat-label">Territori duplicati saltati</div><div class="stat-value badge-err">{{ $stats['duplicate_territori'] ?? 0 }}</div></div>
        <div class="stat"><div class="stat-label">Assegnazioni saltate</div><div class="stat-value badge-err">{{ $stats['assegnazioni_saltate'] ?? 0 }}</div></div>
    </div>

    @if(!empty($issues))
        <h2>Dettaglio righe non importate</h2>
        <table>
            <thead>
                <tr>
                    <th style="width:18%">Entità</th>
                    <th style="width:14%">Legacy ID</th>
                    <th>Motivo</th>
                </tr>
            </thead>
            <tbody>
                @foreach($issues as $issue)
                    <tr>
                        <td>{{ $issue['entity'] }}</td>
                        <td>{{ $issue['legacy_id'] }}</td>
                        <td>{{ $issue['reason'] }}</td>
                    </tr>
                @endforeach
            </tbody>
        </table>
    @else
        <p style="color:#16a34a;margin-top:12px;">✓ Nessun elemento saltato durante l'importazione.</p>
    @endif

    <div class="footer">TerManager2 — Export generato automaticamente</div>
</body>
</html>
