<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="utf-8">
    <style>
        * { font-family: "DejaVu Sans", sans-serif; }
        @page { margin: 18mm 12mm 16mm 12mm; }
        body { color: #1f2937; font-size: 10px; }
        h1 { color: #21409A; font-size: 18px; margin: 0 0 2px 0; }
        h2 { font-size: 12px; margin: 16px 0 4px 0; }
        .meta { color: #6b7280; font-size: 10px; margin: 0 0 4px 0; }
        .badges span { display: inline-block; padding: 3px 8px; border-radius: 4px; font-size: 10px; margin-right: 6px; }
        .b-missing { background: #fee2e2; color: #991b1b; }
        .b-extra { background: #fef3c7; color: #92400e; }
        .b-matched { background: #dcfce7; color: #166534; }
        table { width: 100%; border-collapse: collapse; margin-top: 2px; }
        thead th { background: #374151; color: #fff; text-align: left; padding: 5px 8px; font-size: 9px; text-transform: uppercase; }
        tbody td { padding: 4px 8px; border-bottom: 1px solid #e5e7eb; }
        tbody tr:nth-child(even) { background: #f3f4f6; }
        .mono { font-family: "DejaVu Sans Mono", monospace; }
        .empty { padding: 10px 8px; color: #9ca3af; }
        .footer { position: fixed; bottom: -10mm; left: 0; right: 0; color: #9ca3af; font-size: 8px; text-align: center; }
    </style>
</head>
<body>
    <h1>Comparaison inventaire / stock</h1>
    <p class="meta">Inventaire : <strong>{{ label }}</strong> — {{ createdAt|date('d/m/Y à H:i') }}</p>
    <p class="meta">Concession : <strong>{{ concessions }}</strong> · VN/VO : <strong>{{ vnVo|default('Tous') }}</strong> · Date du stock : <strong>{{ stockDate|default('-') }}</strong></p>
    <p class="badges">
        <span class="b-missing">{{ missing|length }} manquant(s) au scan</span>
        <span class="b-extra">{{ extra|length }} en trop (non attendu)</span>
        <span class="b-matched">{{ matched|length }} concordant(s)</span>
    </p>

    {% macro section(title, rows, cls) %}
        <h2>{{ title }} ({{ rows|length }})</h2>
        <table>
            <thead>
                <tr>
                    <th style="width:16%">Plaque</th>
                    <th style="width:24%">VIN</th>
                    <th style="width:18%">Marque</th>
                    <th style="width:14%">Type</th>
                    <th style="width:28%">Localisation</th>
                </tr>
            </thead>
            <tbody>
                {% for r in rows %}
                    <tr>
                        <td class="mono">{{ r.plate }}</td>
                        <td class="mono">{{ r.vin }}</td>
                        <td>{{ r.make }}</td>
                        <td>{{ r.type }}</td>
                        <td>{{ r.localisation }}</td>
                    </tr>
                {% else %}
                    <tr><td colspan="5" class="empty">Aucun</td></tr>
                {% endfor %}
            </tbody>
        </table>
    {% endmacro %}

    {{ _self.section('Manquants au scan (attendus, non trouvés)', missing, 'missing') }}
    {{ _self.section('En trop (scannés, absents du stock)', extra, 'extra') }}
    {{ _self.section('Concordants', matched, 'matched') }}

    <div class="footer">Scan Inventaire — Emil Frey · document généré le {{ "now"|date('d/m/Y H:i') }}</div>
</body>
</html>
