<div class="d-flex justify-content-between align-items-center mb-4">
    <div>
        <h1 class="darlink-title mb-1">Détail inventaire</h1>
        <p class="text-muted mb-0"><?= htmlspecialchars($inventory['date_inventaire']) ?> — <?= htmlspecialchars($inventory['commentaire'] ?? '-') ?></p>
    </div>
    <a href="index.php?page=stock_inventory" class="btn btn-outline-secondary">Retour inventaire</a>
</div>

<div class="row g-3 mb-4">
    <div class="col-md-3"><div class="darlink-card p-3"><div class="text-muted">Articles contrôlés</div><div class="h4 mb-0"><?= (int)$inventory['nb_articles'] ?></div></div></div>
    <div class="col-md-3"><div class="darlink-card p-3"><div class="text-muted">Écarts</div><div class="h4 mb-0"><?= (int)$inventory['nb_ecarts'] ?></div></div></div>
    <div class="col-md-3"><div class="darlink-card p-3"><div class="text-muted">Écart quantité</div><div class="h4 mb-0"><?= number_format((float)$inventory['total_ecart_quantite'], 0, ',', ' ') ?></div></div></div>
    <div class="col-md-3"><div class="darlink-card p-3"><div class="text-muted">Valeur écart HT</div><div class="h4 mb-0 <?= (float)$inventory['valeur_ecart_ht'] < 0 ? 'text-danger' : 'text-success' ?>"><?= number_format((float)$inventory['valeur_ecart_ht'], 2, ',', ' ') ?></div></div></div>
</div>

<div class="darlink-card p-4">
    <div class="table-responsive">
        <table class="table table-hover align-middle darlink-table">
            <thead>
                <tr>
                    <th>Référence</th>
                    <th>Désignation</th>
                    <th class="text-end">Théorique</th>
                    <th class="text-end">Réel</th>
                    <th class="text-end">Écart</th>
                    <th class="text-end">Valeur écart HT</th>
                </tr>
            </thead>
            <tbody>
            <?php foreach ($lines as $line): ?>
                <tr>
                    <td><strong><?= htmlspecialchars($line['reference']) ?></strong></td>
                    <td><?= htmlspecialchars($line['designation']) ?></td>
                    <td class="text-end"><?= number_format((float)$line['stock_theorique'], 0, ',', ' ') ?></td>
                    <td class="text-end fw-bold"><?= number_format((float)$line['stock_reel'], 0, ',', ' ') ?></td>
                    <td class="text-end <?= (float)$line['ecart'] < 0 ? 'text-danger' : ((float)$line['ecart'] > 0 ? 'text-success' : '') ?>"><?= number_format((float)$line['ecart'], 0, ',', ' ') ?></td>
                    <td class="text-end <?= (float)$line['valeur_ecart_ht'] < 0 ? 'text-danger' : ((float)$line['valeur_ecart_ht'] > 0 ? 'text-success' : '') ?>"><?= number_format((float)$line['valeur_ecart_ht'], 2, ',', ' ') ?></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>
