<div class="max-w-2xl mx-auto bg-white rounded-xl shadow-sm border border-gray-100 p-6">
    <h3 class="text-lg font-semibold text-gray-800 mb-6"><?= isset($client) ? 'Editar Cliente' : 'Novo Cliente' ?></h3>

    <form action="<?= isset($client) ? '/admin/clients/update/' . $client['id'] : '/admin/clients/store' ?>"
        method="POST">
        <div class="space-y-4">
            <div>
                <label class="block text-sm font-medium text-gray-700 mb-1">Razão Social / Nome</label>
                <input type="text" name="name" value="<?= $client['name'] ?? '' ?>"
                    class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent"
                    required>
            </div>

            <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">ASN (ex: AS12345)</label>
                    <input type="text" name="asn" value="<?= $client['asn'] ?? '' ?>"
                        class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent"
                        required>
                </div>
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">Telegram ID (Opcional)</label>
                    <input type="text" name="telegram_id" value="<?= $client['telegram_id'] ?? '' ?>"
                        class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent">
                </div>
            </div>

            <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">Email Principal (Login)</label>
                    <input type="email" name="email" value="<?= $client['email'] ?? '' ?>"
                        class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent"
                        required>
                </div>
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">Email Financeiro</label>
                    <input type="email" name="financial_email" value="<?= $client['financial_email'] ?? '' ?>"
                        class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent"
                        required>
                </div>
            </div>

            <div>
                <label class="block text-sm font-medium text-gray-700 mb-1">Senha de Acesso
                    <?= isset($client) ? '<span class="text-gray-400 font-normal">(Deixe em branco para manter)</span>' : '' ?></label>
                <input type="password" name="password"
                    class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent"
                    <?= isset($client) ? '' : 'required' ?>>
            </div>

            <?php if (isset($client)): ?>
                <div>
                    <label class="block text-sm font-medium text-gray-700 mb-1">Status</label>
                    <select name="status"
                        class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary-500 focus:border-transparent">
                        <option value="active" <?= $client['status'] == 'active' ? 'selected' : '' ?>>Ativo</option>
                        <option value="inactive" <?= $client['status'] == 'inactive' ? 'selected' : '' ?>>Inativo</option>
                    </select>
                </div>
            <?php else: ?>
                <input type="hidden" name="status" value="active">
            <?php endif; ?>
        </div>

        <div class="mt-6 flex justify-end space-x-3">
            <a href="/admin/clients"
                class="px-4 py-2 text-gray-700 hover:bg-gray-100 rounded-lg transition-colors">Cancelar</a>
            <button type="submit"
                class="px-4 py-2 bg-primary-600 text-white rounded-lg hover:bg-primary-700 transition-colors">
                <?= isset($client) ? 'Salvar Alterações' : 'Criar Cliente' ?>
            </button>
        </div>
    </form>
</div>