<!-- ============================================================ -->
<!-- LETRAS - Editar letra individual -->
<!-- ============================================================ -->

<div class="mb-6">
    <a href="<?= BASE_URL ?>?c=letras" class="text-xs text-gray-400 hover:text-primary-400 transition-colors inline-flex items-center gap-1">
        <i class="fas fa-arrow-left"></i> Volver al listado
    </a>
</div>

<div class="glass-card rounded-2xl p-6 max-w-3xl">
    <h3 class="font-sora font-bold text-white text-lg mb-1">Editar Letra</h3>
    <p class="text-xs text-gray-500 mb-6">
        Empresa: <span class="text-white font-medium"><?= htmlspecialchars($letra['razon_social']) ?></span> | 
        Grupo: #<?= $letra['grupo_id'] ?>
    </p>

    <form method="POST" action="<?= BASE_URL ?>?c=letras&a=actualizar">
        <input type="hidden" name="id" value="<?= $letra['id'] ?>">

        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4 mb-6">
            
            <div>
                <label class="block text-xs text-gray-400 mb-1.5 font-medium">Nº Letra *</label>
                <input type="text" name="numero_letra" value="<?= htmlspecialchars($letra['numero_letra']) ?>" required class="input-glass w-full">
            </div>

            <div>
                <label class="block text-xs text-gray-400 mb-1.5 font-medium">Renovación</label>
                <input type="number" name="renovacion" value="<?= $letra['renovacion'] ?>" min="0" class="input-glass w-full">
            </div>

            <div>
                <label class="block text-xs text-gray-400 mb-1.5 font-medium">Tipo Letra</label>
                <select name="tipo_letra" class="input-glass w-full">
                    <option value="ORI" <?= $letra['tipo_letra'] === 'ORI' ? 'selected' : '' ?>>ORI - Original</option>
                    <option value="REN" <?= $letra['tipo_letra'] === 'REN' ? 'selected' : '' ?>>REN - Renovada</option>
                </select>
            </div>

            <div>
                <label class="block text-xs text-gray-400 mb-1.5 font-medium">Moneda</label>
                <select name="moneda" class="input-glass w-full">
                    <option value="USD" <?= $letra['moneda'] === 'USD' ? 'selected' : '' ?>>USD</option>
                    <option value="PEN" <?= $letra['moneda'] === 'PEN' ? 'selected' : '' ?>>PEN</option>
                </select>
            </div>

            <div>
                <label class="block text-xs text-gray-400 mb-1.5 font-medium">Fecha Emisión *</label>
                <input type="date" name="fecha_emision" value="<?= $letra['fecha_emision'] ?>" required class="input-glass w-full">
            </div>

            <div>
                <label class="block text-xs text-gray-400 mb-1.5 font-medium">Plazo (días)</label>
                <input type="number" name="plazo_dias" value="<?= $letra['plazo_dias'] ?>" min="1" class="input-glass w-full">
            </div>

            <div>
                <label class="block text-xs text-gray-400 mb-1.5 font-medium">Fecha Vencimiento *</label>
                <input type="date" name="fecha_vencimiento" value="<?= $letra['fecha_vencimiento'] ?>" required class="input-glass w-full">
            </div>

            <div>
                <label class="block text-xs text-gray-400 mb-1.5 font-medium">Fecha Pago (+8 días)</label>
                <input type="date" value="<?= $letra['fecha_pago'] ?>" disabled class="input-glass w-full opacity-60">
                <p class="text-[10px] text-gray-500 mt-1">Se calcula automáticamente</p>
            </div>

            <div>
                <label class="block text-xs text-gray-400 mb-1.5 font-medium">Importe *</label>
                <input type="number" step="0.01" name="importe" value="<?= $letra['importe'] ?>" required class="input-glass w-full">
            </div>

            <div>
                <label class="block text-xs text-gray-400 mb-1.5 font-medium">Banco</label>
                <input type="text" name="banco" value="<?= htmlspecialchars($letra['banco'] ?? '') ?>" class="input-glass w-full" placeholder="Ej: CONTINENTAL">
            </div>

            <div>
                <label class="block text-xs text-gray-400 mb-1.5 font-medium">Estado</label>
                <select name="estado" class="input-glass w-full">
                    <option value="pendiente" <?= $letra['estado'] === 'pendiente' ? 'selected' : '' ?>>Pendiente</option>
                    <option value="pagada" <?= $letra['estado'] === 'pagada' ? 'selected' : '' ?>>Pagada</option>
                    <option value="vencida" <?= $letra['estado'] === 'vencida' ? 'selected' : '' ?>>Vencida</option>
                    <?php if ($letra['estado'] === 'renovada'): ?>
                    <option value="renovada" selected>Renovada</option>
                    <?php endif; ?>
                    <option value="protestada" <?= $letra['estado'] === 'protestada' ? 'selected' : '' ?>>Protestada</option>
                </select>
                <?php if (in_array($letra['estado'], ['pendiente', 'vencida'])): ?>
                <a href="<?= BASE_URL ?>?c=letras&a=renovar&id=<?= $letra['id'] ?>" class="inline-flex items-center justify-center gap-2 w-full mt-3 px-3 py-2 bg-emerald-500/10 text-emerald-400 hover:bg-emerald-500/20 border border-emerald-500/20 rounded-xl text-xs font-semibold transition-all">
                    <i class="fas fa-sync-alt"></i> ¿Desea renovar esta letra?
                </a>
                <?php endif; ?>
            </div>

            <div>
                <label class="block text-xs text-gray-400 mb-1.5 font-medium">Referencia Única</label>
                <input type="text" name="referencia_unica" value="<?= htmlspecialchars($letra['referencia_unica'] ?? '') ?>" class="input-glass w-full">
            </div>
        </div>

        <div class="mb-6">
            <label class="block text-xs text-gray-400 mb-1.5 font-medium">Observaciones</label>
            <textarea name="observaciones" rows="2" class="input-glass w-full"><?= htmlspecialchars($letra['observaciones'] ?? '') ?></textarea>
        </div>

        <div class="flex items-center justify-end gap-3">
            <a href="<?= BASE_URL ?>?c=letras" class="px-6 py-2.5 rounded-xl text-sm font-medium text-gray-400 hover:text-white border border-white/10 hover:border-white/20 transition-colors">
                Cancelar
            </a>
            <button type="submit" class="btn-primary px-8 py-2.5 rounded-xl text-sm font-bold inline-flex items-center gap-2">
                <i class="fas fa-save"></i> Actualizar
            </button>
        </div>
    </form>
</div>
