<div class="row justify-content-center">
    <div class="col-md-6 col-lg-5">
        <div class="card shadow-sm">
            <div class="card-header bg-white d-flex justify-content-between align-items-center">
                <h5 class="mb-0"><i class="bi bi-pencil-square"></i> Ajuster le solde</h5>
                <a href="<?= site_url('cashboxes'); ?>" class="btn btn-sm btn-outline-secondary">
                    <i class="bi bi-arrow-left"></i> Retour
                </a>
            </div>
            <div class="card-body">
                <div class="alert alert-warning py-2">
                    <i class="bi bi-exclamation-triangle"></i>
                    <strong>Attention :</strong> Cette opération modifie directement le solde de la caisse.
                    Utilisez-la uniquement pour l'initialisation ou pour corriger un écart justifié.
                </div>

                <div class="card bg-light mb-3">
                    <div class="card-body py-2">
                        <div class="d-flex justify-content-between">
                            <div>
                                <strong><?= htmlspecialchars($cashbox->name); ?></strong>
                                <code class="small ms-1"><?= $cashbox->code; ?></code>
                            </div>
                            <div>
                                <?php if ($cashbox->location_name): ?>
                                <span class="badge bg-light text-dark"><i class="bi bi-geo-alt"></i> <?= $cashbox->location_name; ?></span>
                                <?php endif; ?>
                            </div>
                        </div>
                        <div class="h4 mb-0 mt-1">
                            Solde actuel : <strong><?= number_format($cashbox->current_balance, 0, ',', ' '); ?> KMF</strong>
                        </div>
                    </div>
                </div>

                <?= form_open('cashboxes/adjust_balance/' . $cashbox->id); ?>

                    <div class="mb-3">
                        <label class="form-label">Nouveau solde <span class="text-danger">*</span></label>
                        <div class="input-group">
                            <input type="number" name="new_balance" class="form-control" 
                                   step="1" required
                                   value="<?= set_value('new_balance', $cashbox->current_balance); ?>"
                                   placeholder="0">
                            <span class="input-group-text">KMF</span>
                        </div>
                    </div>

                    <div class="mb-3">
                        <label class="form-label">Motif de l'ajustement <span class="text-danger">*</span></label>
                        <textarea name="reason" class="form-control" rows="3" required
                                  placeholder="Ex: Initialisation du solde bancaire suite au cash advance de 49 000 000 KMF du 01/03/2026"><?= set_value('reason'); ?></textarea>
                        <div class="form-text">Obligatoire. Ce motif sera enregistré dans le journal d'audit.</div>
                    </div>

                    <hr>
                    <div class="d-flex gap-2">
                        <button type="submit" class="btn btn-warning" 
                                onclick="return confirm('Confirmer l\'ajustement du solde ?');">
                            <i class="bi bi-check-lg"></i> Appliquer l'ajustement
                        </button>
                        <a href="<?= site_url('cashboxes'); ?>" class="btn btn-outline-secondary">Annuler</a>
                    </div>

                <?= form_close(); ?>
            </div>
        </div>
    </div>
</div>
