<!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; }
        .meta { color: #6b7280; font-size: 10px; margin: 0 0 12px 0; }
        .meta strong { color: #374151; }
        table { width: 100%; border-collapse: collapse; }
        thead th {
            background: #21409A; color: #fff; text-align: left;
            padding: 6px 8px; font-size: 9px; text-transform: uppercase; letter-spacing: .03em;
        }
        tbody td { padding: 5px 8px; border-bottom: 1px solid #e5e7eb; vertical-align: top; }
        tbody tr:nth-child(even) { background: #f3f4f6; }
        .mono { font-family: "DejaVu Sans Mono", monospace; }
        .muted { color: #9ca3af; }
        /* Surbrillance jaune des valeurs plaque/VIN en erreur (à corriger). */
        td.err { background: #fde047; }
        .footer { position: fixed; bottom: -10mm; left: 0; right: 0; color: #9ca3af; font-size: 8px; text-align: center; }
        .empty { padding: 24px; text-align: center; color: #9ca3af; }
    </style>
</head>
<body>
    <h1>{{ label }}</h1>
    <p class="meta">
        <strong>{{ total }}</strong> véhicule{{ total > 1 ? 's' }}
        {% if createdAt %} · {{ createdAt|date('d/m/Y à H:i') }}{% endif %}
        · Scanné par <strong>{{ scannedBy }}</strong>
        · Concession(s) : <strong>{{ concessionStr }}</strong>
        {% if locationStr != '-' %} · 📍 {{ locationStr }}{% endif %}
    </p>

    <table>
        <thead>
            <tr>
                <th style="width:5%">#</th>
                <th style="width:19%">VIN</th>
                <th style="width:12%">Plaque</th>
                <th style="width:13%">Marque</th>
                <th style="width:14%">Modèle</th>
                <th style="width:9%">Date VIN</th>
                <th style="width:9%">Date plaque</th>
                <th style="width:19%">Commentaire</th>
            </tr>
        </thead>
        <tbody>
            {% for r in rows %}
                <tr>
                    <td class="muted">{{ loop.index }}</td>
                    <td class="mono{{ r.vinError ? ' err' }}">{{ r.vin }}</td>
                    <td class="mono{{ r.plateError ? ' err' }}">{{ r.plate }}</td>
                    <td>{{ r.make }}</td>
                    <td>{{ r.model }}{% if r.modelConfidence %} <span class="muted">({{ r.modelConfidence }})</span>{% endif %}</td>
                    <td>{{ r.vinDate }}</td>
                    <td>{{ r.plateDate }}</td>
                    <td style="white-space: pre-wrap; word-break: break-word;">{{ r.comment }}</td>
                </tr>
            {% else %}
                <tr><td colspan="8" class="empty">Aucun véhicule dans cet inventaire.</td></tr>
            {% endfor %}
        </tbody>
    </table>

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