<?php
session_start();
require_once '../config/db.php';

// Verifica se usuário está logado
if (!isset($_SESSION['user_id'])) {
    header("Location: login.php");
    exit;
}

$user_id = $_SESSION['user_id'];
$sucesso = false;
$erro_logo = "";

// Busca configurações do usuário (se não existir, cria em branco)
$stmt = $pdo->prepare("SELECT * FROM settings WHERE user_id = ?");
$stmt->execute([$user_id]);
$config = $stmt->fetch(PDO::FETCH_ASSOC);

if (!$config) {
    // Cria registro vazio para o usuário
    $pdo->prepare("INSERT INTO settings (user_id, nome_empresa, cnpj, endereco, telefone, email_contato, logo, pix_key) VALUES (?, '', '', '', '', '', '', '')")
        ->execute([$user_id]);
    $stmt = $pdo->prepare("SELECT * FROM settings WHERE user_id = ?");
    $stmt->execute([$user_id]);
    $config = $stmt->fetch(PDO::FETCH_ASSOC);
}

$logoPath = $config['logo'] ?? "";

// Upload de logo e atualização de dados
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Atualiza campos de texto
    $nome_empresa = trim($_POST['nome']);
    $cnpj         = trim($_POST['cnpj']);
    $endereco     = trim($_POST['endereco']);
    $contato      = trim($_POST['contato']);
    $pix_key      = trim($_POST['pix_key'] ?? '');

    // Upload da logo
    if (isset($_FILES['logo_upload']) && $_FILES['logo_upload']['error'] === UPLOAD_ERR_OK) {
        $fileTmp = $_FILES['logo_upload']['tmp_name'];
        $fileName = preg_replace('/[^a-z0-9\._-]/i', '_', $_FILES['logo_upload']['name']);
        $ext = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
        $allowed = ['jpg','jpeg','png','gif','webp'];

        if (in_array($ext, $allowed)) {
            $dest = '../public/uploads/'.$fileName;
            if (!is_dir('../public/uploads')) mkdir('../public/uploads', 0777, true);
            move_uploaded_file($fileTmp, $dest);
            $logoPath = 'uploads/'.$fileName; // Caminho relativo para public
        } else {
            $erro_logo = "Formato de imagem não permitido!";
        }
    } elseif (isset($_POST['logo_url']) && $_POST['logo_url']) {
        $logoPath = trim($_POST['logo_url']);
    }

    if (empty($erro_logo)) {
        $sql = "UPDATE settings SET nome_empresa = ?, cnpj = ?, endereco = ?, telefone = ?, logo = ?, pix_key = ?, updated_at = NOW() WHERE user_id = ?";
        $stmt = $pdo->prepare($sql);
        $stmt->execute([
            $nome_empresa,
            $cnpj,
            $endereco,
            $contato,
            $logoPath,
            $pix_key,
            $user_id
        ]);
        $sucesso = true;
        // Carrega os dados atualizados
        $stmt = $pdo->prepare("SELECT * FROM settings WHERE user_id = ?");
        $stmt->execute([$user_id]);
        $config = $stmt->fetch(PDO::FETCH_ASSOC);
    }
}
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="UTF-8">
    <title>Configuração do Estabelecimento - Fiado Fácil</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Google Fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
    <style>
        :root {
            --primary-color: #1876F2;
            --primary-dark: #1356b3;
            --primary-light: #eaf4ff;
            --secondary-color: #1bbf5c;
            --success-color: #10b981;
            --warning-color: #f59e0b;
            --danger-color: #ef4444;
            --background-color: #f8fafc;
            --surface-color: #ffffff;
            --text-primary: #1e293b;
            --text-secondary: #64748b;
            --border-color: #e2e8f0;
            --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
            --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
            --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
            --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
            --gradient-primary: linear-gradient(135deg, #1876F2 0%, #1356b3 100%);
            --gradient-success: linear-gradient(135deg, #10b981 0%, #059669 100%);
            --gradient-warning: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
            --gradient-danger: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
            --gradient-background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background: var(--gradient-background);
            color: var(--text-primary);
            line-height: 1.6;
            min-height: 100vh;
        }

        .sidebar {
            position: fixed;
            left: 0;
            top: 0;
            bottom: 0;
            width: 280px;
            background: var(--surface-color);
            backdrop-filter: blur(20px);
            border-right: 1px solid var(--border-color);
            display: flex;
            flex-direction: column;
            z-index: 100;
            box-shadow: var(--shadow-xl);
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        }

        .sidebar::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 120px;
            background: var(--gradient-primary);
            opacity: 0.05;
            border-radius: 0 0 24px 0;
        }

        .sidebar .logo {
            position: relative;
            padding: 32px 24px;
            font-size: 1.75rem;
            font-weight: 800;
            color: var(--primary-color);
            display: flex;
            align-items: center;
            gap: 12px;
            border-bottom: 1px solid var(--border-color);
        }

        .sidebar .logo i {
            font-size: 2rem;
            background: var(--gradient-primary);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }

        .sidebar nav {
            flex: 1;
            padding: 24px 16px;
        }

        .sidebar nav a {
            display: flex;
            align-items: center;
            gap: 16px;
            color: var(--text-secondary);
            text-decoration: none;
            font-size: 0.95rem;
            font-weight: 500;
            padding: 14px 20px;
            margin: 4px 0;
            border-radius: 12px;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            position: relative;
            overflow: hidden;
        }

        .sidebar nav a::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: var(--gradient-primary);
            opacity: 0;
            transition: opacity 0.3s ease;
            border-radius: 12px;
        }

        .sidebar nav a i {
            font-size: 1.1rem;
            width: 20px;
            text-align: center;
            position: relative;
            z-index: 1;
        }

        .sidebar nav a span {
            position: relative;
            z-index: 1;
        }

        .sidebar nav a.active,
        .sidebar nav a:hover {
            color: white;
            transform: translateX(4px);
            box-shadow: var(--shadow-md);
        }

        .sidebar nav a.active::before,
        .sidebar nav a:hover::before {
            opacity: 1;
        }

        .sidebar .bottom {
            padding: 24px;
            border-top: 1px solid var(--border-color);
        }

        .sidebar .logout-link {
            display: flex;
            align-items: center;
            gap: 12px;
            color: #ef4444;
            font-weight: 600;
            font-size: 0.95rem;
            text-decoration: none;
            padding: 12px 16px;
            border-radius: 12px;
            transition: all 0.3s ease;
        }

        .sidebar .logout-link:hover {
            background: #fef2f2;
            transform: translateX(4px);
        }

        .main-content {
            margin-left: 280px;
            padding: 32px;
            min-height: 100vh;
            animation: fadeIn 0.6s ease-out;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .page-header {
            display: flex;
            align-items: center;
            gap: 16px;
            margin-bottom: 32px;
            padding-bottom: 24px;
            border-bottom: 1px solid var(--border-color);
        }

        .page-header .icon-wrapper {
            width: 56px;
            height: 56px;
            border-radius: 16px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: var(--primary-light);
        }

        .page-header i {
            font-size: 1.75rem;
            color: var(--primary-color);
        }

        .page-header h2 {
            font-size: 2rem;
            font-weight: 700;
            color: var(--text-primary);
            margin: 0;
        }

        .config-card {
            background: var(--surface-color);
            border-radius: 20px;
            box-shadow: var(--shadow-md);
            border: 1px solid var(--border-color);
            overflow: hidden;
            animation: slideUp 0.6s ease-out;
            animation-delay: 0.1s;
            animation-fill-mode: both;
            position: relative;
            max-width: 1000px;
            margin: 0 auto;
        }

        .config-card::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 4px;
            background: var(--gradient-primary);
        }

        .card-header {
            padding: 24px 32px;
            border-bottom: 1px solid var(--border-color);
            background: var(--primary-light);
        }

        .card-header h3 {
            font-size: 1.25rem;
            font-weight: 700;
            color: var(--primary-color);
            margin: 0;
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .config-form {
            padding: 32px;
        }

        @keyframes slideUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .success-message {
            background: #f0fdf4;
            color: var(--success-color);
            padding: 16px 20px;
            border-radius: 12px;
            margin-bottom: 24px;
            text-align: center;
            font-weight: 600;
            border: 1px solid #bbf7d0;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            animation: slideDown 0.5s ease-out;
        }

        .error-message {
            background: #fef2f2;
            color: var(--danger-color);
            padding: 16px 20px;
            border-radius: 12px;
            margin-bottom: 24px;
            text-align: center;
            font-weight: 600;
            border: 1px solid #fecaca;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            animation: slideDown 0.5s ease-out;
        }

        @keyframes slideDown {
            from {
                opacity: 0;
                transform: translateY(-10px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .form-row {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
            gap: 24px;
            margin-bottom: 24px;
        }

        .form-group {
            display: flex;
            flex-direction: column;
            gap: 8px;
        }

        .form-label {
            font-size: 0.9rem;
            font-weight: 600;
            color: var(--text-secondary);
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .form-input {
            padding: 12px 16px;
            border: 2px solid var(--border-color);
            border-radius: 12px;
            background: var(--surface-color);
            font-size: 1rem;
            font-weight: 500;
            color: var(--text-primary);
            transition: all 0.3s ease;
            outline: none;
        }

        .form-input:focus {
            border-color: var(--primary-color);
            box-shadow: 0 0 0 3px rgba(24, 118, 242, 0.1);
        }

        .form-tip {
            font-size: 0.85rem;
            color: var(--text-secondary);
            margin-top: 4px;
            line-height: 1.4;
        }

        .logo-section {
            margin-bottom: 32px;
            padding: 24px;
            background: var(--background-color);
            border-radius: 16px;
            border: 1px solid var(--border-color);
        }

        .logo-section h4 {
            font-size: 1.1rem;
            font-weight: 700;
            color: var(--text-primary);
            margin-bottom: 16px;
            display: flex;
            align-items: center;
            gap: 8px;
        }

        .logo-upload-area {
            display: flex;
            flex-direction: column;
            gap: 16px;
        }

        .upload-options {
            display: flex;
            gap: 16px;
            align-items: center;
            flex-wrap: wrap;
        }

        .file-input-wrapper {
            position: relative;
            overflow: hidden;
            display: inline-block;
        }

        .file-input-wrapper input[type="file"] {
            position: absolute;
            left: -9999px;
        }

        .file-input-label {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 10px 16px;
            background: var(--primary-light);
            color: var(--primary-color);
            border: 2px solid var(--primary-color);
            border-radius: 12px;
            cursor: pointer;
            font-weight: 600;
            font-size: 0.9rem;
            transition: all 0.3s ease;
        }

        .file-input-label:hover {
            background: var(--primary-color);
            color: white;
        }

        .upload-separator {
            color: var(--text-secondary);
            font-weight: 600;
            font-size: 0.9rem;
        }

        .url-input {
            flex: 1;
            min-width: 200px;
        }

        .logo-preview {
            text-align: center;
            margin-top: 16px;
            padding: 20px;
            background: white;
            border-radius: 12px;
            border: 2px dashed var(--border-color);
        }

        .logo-preview img {
            max-width: 300px;
            max-height: 120px;
            border-radius: 8px;
            box-shadow: var(--shadow-md);
            background: white;
        }

        .no-logo {
            color: var(--text-secondary);
            font-style: italic;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            padding: 40px 20px;
        }

        .submit-btn {
            background: var(--gradient-primary);
            color: white;
            font-weight: 600;
            font-size: 1rem;
            border: none;
            border-radius: 12px;
            padding: 16px 32px;
            cursor: pointer;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            position: relative;
            overflow: hidden;
            width: 100%;
            margin-top: 24px;
        }

        .submit-btn::before {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
            transition: left 0.5s;
        }

        .submit-btn:hover {
            transform: translateY(-2px);
            box-shadow: var(--shadow-lg);
        }

        .submit-btn:hover::before {
            left: 100%;
        }

        /* Menu toggle para mobile */
        .menu-toggle {
            display: none;
            position: fixed;
            top: 20px;
            left: 20px;
            z-index: 1001;
            background: var(--surface-color);
            border: 2px solid var(--border-color);
            border-radius: 12px;
            padding: 12px;
            cursor: pointer;
            box-shadow: var(--shadow-md);
            color: var(--primary-color);
            font-size: 1.2rem;
        }

        /* Overlay para mobile */
        .overlay {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.5);
            z-index: 999;
        }

        /* Responsividade */
        @media (max-width: 768px) {
            .menu-toggle {
                display: block;
            }

            .overlay.active {
                display: block;
            }

            .sidebar {
                position: fixed;
                transform: translateX(-100%);
                width: 100%;
                max-width: 320px;
                z-index: 1000;
            }

            .sidebar.open {
                transform: translateX(0);
            }

            .main-content {
                margin-left: 0;
                padding: 20px 16px;
            }

            .page-header {
                flex-direction: column;
                align-items: flex-start;
                gap: 12px;
            }

            .page-header h2 {
                font-size: 1.5rem;
            }

            .config-card {
                margin: 0 -8px;
            }

            .card-header {
                padding: 20px 24px;
            }

            .config-form {
                padding: 24px;
            }

            .form-row {
                grid-template-columns: 1fr;
                gap: 20px;
            }

            .upload-options {
                flex-direction: column;
                align-items: stretch;
            }

            .upload-separator {
                text-align: center;
            }

            .logo-section {
                padding: 20px;
            }
        }
    </style>
</head>
<body>
    <button class="menu-toggle" id="menuToggle">
        <i class="fa-solid fa-bars"></i>
    </button>
    
    <div class="overlay" id="overlay"></div>
    
    <aside class="sidebar" id="sidebar">
        <div class="logo">
            <i class="fa-solid fa-wallet"></i>
            <span>Fiado Fácil</span>
        </div>
        <nav>
            <a href="dashboard.php">
                <i class="fa-solid fa-house"></i>
                <span>Painel</span>
            </a>
            <a href="clientes.php">
                <i class="fa-solid fa-users"></i>
                <span>Clientes</span>
            </a>
            <a href="fiados.php">
                <i class="fa-solid fa-file-invoice-dollar"></i>
                <span>Fiados</span>
            </a>
            <a href="carne.php">
                <i class="fa-solid fa-file-pdf"></i>
                <span>Carnê PDF</span>
            </a>
            <a href="relatorios.php">
                <i class="fa-solid fa-chart-line"></i>
                <span>Relatórios</span>
            </a>
            <a href="configuracao.php" class="active">
                <i class="fa-solid fa-cog"></i>
                <span>Configuração</span>
            </a>
        </nav>
        <div class="bottom">
            <a href="logout.php" class="logout-link">
                <i class="fa-solid fa-right-from-bracket"></i>
                <span>Sair</span>
            </a>
        </div>
    </aside>
    
    <div class="main-content">
        <div class="page-header">
            <div class="icon-wrapper">
                <i class="fa-solid fa-cog"></i>
            </div>
            <h2>Configuração do Estabelecimento</h2>
        </div>

        <div class="config-card">
            <div class="card-header">
                <h3>
                    <i class="fa-solid fa-store"></i>
                    Dados do Estabelecimento
                </h3>
            </div>
            
            <form method="post" enctype="multipart/form-data" autocomplete="off" class="config-form">
                <?php if ($sucesso): ?>
                    <div class="success-message">
                        <i class="fa-solid fa-check-circle"></i>
                        Configuração salva com sucesso!
                    </div>
                <?php endif; ?>
                
                <?php if ($erro_logo): ?>
                    <div class="error-message">
                        <i class="fa-solid fa-exclamation-triangle"></i>
                        <?= htmlspecialchars($erro_logo) ?>
                    </div>
                <?php endif; ?>

                <div class="form-row">
                    <div class="form-group">
                        <label for="nome" class="form-label">Nome do Estabelecimento</label>
                        <input type="text" name="nome" id="nome" required value="<?= htmlspecialchars($config['nome_empresa'] ?? '') ?>" class="form-input" placeholder="Digite o nome da sua empresa">
                    </div>
                    
                    <div class="form-group">
                        <label for="cnpj" class="form-label">CNPJ</label>
                        <input type="text" name="cnpj" id="cnpj" required value="<?= htmlspecialchars($config['cnpj'] ?? '') ?>" class="form-input" placeholder="00.000.000/0000-00">
                    </div>
                </div>

                <div class="form-row">
                    <div class="form-group">
                        <label for="endereco" class="form-label">Endereço</label>
                        <input type="text" name="endereco" id="endereco" required value="<?= htmlspecialchars($config['endereco'] ?? '') ?>" class="form-input" placeholder="Rua, número, bairro, cidade">
                    </div>
                    
                    <div class="form-group">
                        <label for="contato" class="form-label">Telefone de Contato</label>
                        <input type="text" name="contato" id="contato" required value="<?= htmlspecialchars($config['telefone'] ?? '') ?>" class="form-input" placeholder="(00) 00000-0000">
                    </div>
                </div>

                <div class="form-group">
                    <label for="pix_key" class="form-label">Chave PIX do Estabelecimento</label>
                    <input type="text" name="pix_key" id="pix_key" maxlength="120" placeholder="E-mail, CPF, CNPJ, chave aleatória ou telefone" value="<?= htmlspecialchars($config['pix_key'] ?? '') ?>" class="form-input">
                    <div class="form-tip">
                        <i class="fa-solid fa-info-circle"></i>
                        Preencha a chave PIX para gerar QR Codes nos carnês de pagamento.
                    </div>
                </div>

                <div class="logo-section">
                    <h4>
                        <i class="fa-solid fa-image"></i>
                        Logo do Estabelecimento
                    </h4>
                    
                    <div class="logo-upload-area">
                        <div class="upload-options">
                            <div class="file-input-wrapper">
                                <input type="file" name="logo_upload" id="logo_upload" accept="image/*">
                                <label for="logo_upload" class="file-input-label">
                                    <i class="fa-solid fa-upload"></i>
                                    Escolher Arquivo
                                </label>
                            </div>
                            
                            <span class="upload-separator">ou</span>
                            
                            <div class="form-group url-input">
                                <input type="text" name="logo_url" placeholder="Cole a URL da imagem aqui" value="<?= ($logoPath && !preg_match('#^uploads/#', $logoPath)) ? htmlspecialchars($logoPath) : "" ?>" class="form-input">
                            </div>
                        </div>
                        
                        <div class="form-tip">
                            <i class="fa-solid fa-info-circle"></i>
                            Formatos aceitos: JPG, PNG, GIF, WEBP. Tamanho recomendado: 300x120px
                        </div>
                        
                        <div class="logo-preview">
                            <?php if (!empty($logoPath)): ?>
                                <img src="<?= htmlspecialchars($logoPath) ?>" alt="Logo do Estabelecimento">
                            <?php else: ?>
                                <div class="no-logo">
                                    <i class="fa-solid fa-image"></i>
                                    Nenhuma logo carregada
                                </div>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>

                <button type="submit" class="submit-btn">
                    <i class="fa-solid fa-save"></i>
                    Salvar Configurações
                </button>
            </form>
        </div>
    </div>
    
    <script>
        // Menu mobile
        const menuToggle = document.getElementById('menuToggle');
        const sidebar = document.getElementById('sidebar');
        const overlay = document.getElementById('overlay');

        menuToggle.addEventListener('click', function() {
            sidebar.classList.toggle('open');
            overlay.classList.toggle('active');
        });

        overlay.addEventListener('click', function() {
            sidebar.classList.remove('open');
            overlay.classList.remove('active');
        });

        // Fechar menu ao clicar em um link (mobile)
        const sidebarLinks = sidebar.querySelectorAll('nav a, .logout-link');
        sidebarLinks.forEach(link => {
            link.addEventListener('click', function() {
                if (window.innerWidth <= 768) {
                    sidebar.classList.remove('open');
                    overlay.classList.remove('active');
                }
            });
        });

        // Animações de entrada
        window.addEventListener('load', function() {
            document.body.style.opacity = '1';
        });

        // Máscaras para campos
        function maskCNPJ(value) {
            return value
                .replace(/\D/g, '')
                .replace(/(\d{2})(\d)/, '$1.$2')
                .replace(/(\d{3})(\d)/, '$1.$2')
                .replace(/(\d{3})(\d)/, '$1/$2')
                .replace(/(\d{4})(\d)/, '$1-$2')
                .replace(/(-\d{2})\d+?$/, '$1');
        }

        function maskPhone(value) {
            return value
                .replace(/\D/g, '')
                .replace(/(\d{2})(\d)/, '($1) $2')
                .replace(/(\d{4})(\d)/, '$1-$2')
                .replace(/(\d{4})-(\d)(\d{4})/, '$1$2-$3')
                .replace(/(-\d{4})\d+?$/, '$1');
        }

        // Aplicar máscaras
        document.getElementById('cnpj').addEventListener('input', function(e) {
            e.target.value = maskCNPJ(e.target.value);
        });

        document.getElementById('contato').addEventListener('input', function(e) {
            e.target.value = maskPhone(e.target.value);
        });

        // Preview da logo ao selecionar arquivo
        document.getElementById('logo_upload').addEventListener('change', function(e) {
            const file = e.target.files[0];
            if (file) {
                const reader = new FileReader();
                reader.onload = function(e) {
                    const preview = document.querySelector('.logo-preview');
                    preview.innerHTML = `<img src="${e.target.result}" alt="Preview da Logo">`;
                };
                reader.readAsDataURL(file);
            }
        });

        // Feedback visual no formulário
        const form = document.querySelector('.config-form');
        const submitBtn = document.querySelector('.submit-btn');
        
        form.addEventListener('submit', function() {
            submitBtn.innerHTML = '<i class="fa-solid fa-spinner fa-spin"></i> Salvando...';
            submitBtn.disabled = true;
        });
    </script>
</body>
</html>