<div class="modal fade" id="ajouterArticleModal" tabindex="-1" aria-hidden="true">
  <div class="modal-dialog">
    <form method="POST" action="/eagle_client_istanbulcups/api/production/ajouter_matiere.php">
      <div class="modal-content">

        <div class="modal-header bg-primary text-white">
          <h5 class="modal-title">Ajouter une matière première</h5>
          <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
        </div>

        <div class="modal-body">

          <!-- Code article -->
          <div class="mb-3">
            <label class="form-label">Code (optionnel)</label>
            <input type="text" name="code" class="form-control" placeholder="MP-001">
          </div>

          <!-- Nom -->
          <div class="mb-3">
            <label class="form-label">Nom *</label>
            <input type="text" name="nom" class="form-control" required>
          </div>

          <!-- Unité -->
          <div class="mb-3">
            <label class="form-label">Unité *</label>
            <select name="unite_id" class="form-select" required>
              <option value="">— Sélectionner —</option>
              <?php
              $unites = $conn->query("SELECT id, nom FROM unites ORDER BY nom")->fetchAll(PDO::FETCH_ASSOC);
              foreach ($unites as $u) {
                  echo "<option value='{$u['id']}'>" . htmlspecialchars($u['nom']) . "</option>";
              }
              ?>
            </select>
          </div>

          <!-- Coût achat -->
          <div class="mb-3">
            <label class="form-label">Coût d’achat unitaire</label>
            <input type="number" step="0.01" name="cout_achat" class="form-control" placeholder="0.00">
          </div>

          <div class="mb-3">
            <label class="form-label">Quantité initiale (optionnelle)</label>
            <input type="number" step="0.01" name="quantite" class="form-control" placeholder="0">
            <small class="text-muted">
              Utilisé seulement si vous avez déjà du stock.
            </small>
          </div>

          <!-- Seuil -->
          <div class="mb-3">
            <label class="form-label">Seuil d’alerte</label>
            <input type="number" step="0.01" name="seuil_alerte" class="form-control" placeholder="0">
          </div>

          <!-- Fournisseur (désactivé volontairement) -->
          <div class="mb-3">
            <label class="form-label">Fournisseur</label>
            <select class="form-select" disabled>
              <option>— géré lors de l’achat —</option>
            </select>
            <small class="text-muted">
              Le fournisseur sera enregistré lors de l’achat (module caisse).
            </small>
          </div>

        </div>

        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Fermer</button>
          <button type="submit" class="btn btn-primary">Enregistrer</button>
        </div>

      </div>
    </form>
  </div>
</div>
