<?php
require_once '../config/db.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $name  = trim($_POST['name']);
    $email = trim($_POST['email']);
    $phone = trim($_POST['phone']);
    $pass  = password_hash($_POST['password'], PASSWORD_BCRYPT);

    $sql = "INSERT INTO users (name, email, phone, password) VALUES (?, ?, ?, ?)";
    $stmt = $pdo->prepare($sql);
    try {
        $stmt->execute([$name, $email, $phone, $pass]);
        header('Location: login.php?success=1');
        exit;
    } catch (PDOException $e) {
        $error = "Erro ao cadastrar: " . $e->getMessage();
    }
}
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="UTF-8">
    <title>Cadastro - 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;
        }

        .container {
            display: flex;
            min-height: 100vh;
            align-items: center;
            justify-content: center;
            padding: 20px;
            gap: 40px;
        }

        .info-section {
            flex: 1;
            max-width: 600px;
            padding: 40px;
            animation: slideInLeft 0.8s ease-out;
        }

        @keyframes slideInLeft {
            from {
                opacity: 0;
                transform: translateX(-30px);
            }
            to {
                opacity: 1;
                transform: translateX(0);
            }
        }

        .brand-header {
            display: flex;
            align-items: center;
            gap: 16px;
            margin-bottom: 32px;
        }

        .brand-icon {
            width: 64px;
            height: 64px;
            border-radius: 20px;
            background: var(--gradient-primary);
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 2rem;
            box-shadow: var(--shadow-lg);
        }

        .brand-text {
            font-size: 2rem;
            font-weight: 800;
            color: var(--primary-color);
        }

        .info-section h1 {
            font-size: 3rem;
            color: var(--text-primary);
            font-weight: 800;
            margin-bottom: 24px;
            line-height: 1.2;
            background: linear-gradient(135deg, var(--text-primary) 0%, var(--primary-color) 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }

        .info-section p {
            font-size: 1.25rem;
            color: var(--text-secondary);
            margin-bottom: 40px;
            line-height: 1.6;
        }

        .price {
            color: var(--primary-color);
            font-weight: 700;
            font-size: 1.5rem;
            text-decoration: none;
            background: var(--primary-light);
            padding: 4px 12px;
            border-radius: 8px;
            display: inline-block;
        }

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

        .feature-card {
            background: var(--surface-color);
            border-radius: 16px;
            padding: 24px;
            box-shadow: var(--shadow-md);
            border: 1px solid var(--border-color);
            display: flex;
            align-items: flex-start;
            gap: 16px;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            animation: slideUp 0.6s ease-out;
            animation-fill-mode: both;
        }

        .feature-card:nth-child(1) { animation-delay: 0.1s; }
        .feature-card:nth-child(2) { animation-delay: 0.2s; }
        .feature-card:nth-child(3) { animation-delay: 0.3s; }
        .feature-card:nth-child(4) { animation-delay: 0.4s; }

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

        .feature-card:hover {
            transform: translateY(-4px);
            box-shadow: var(--shadow-lg);
        }

        .feature-icon {
            width: 48px;
            height: 48px;
            border-radius: 12px;
            background: var(--primary-light);
            display: flex;
            align-items: center;
            justify-content: center;
            color: var(--primary-color);
            font-size: 1.25rem;
            flex-shrink: 0;
        }

        .feature-content {
            flex: 1;
        }

        .feature-title {
            font-weight: 700;
            font-size: 1.1rem;
            color: var(--text-primary);
            margin-bottom: 4px;
        }

        .feature-desc {
            color: var(--text-secondary);
            font-size: 0.95rem;
            line-height: 1.5;
        }

        .cta {
            display: inline-flex;
            align-items: center;
            gap: 8px;
            padding: 16px 32px;
            background: var(--gradient-primary);
            color: white;
            border-radius: 12px;
            text-decoration: none;
            font-size: 1.1rem;
            font-weight: 600;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            box-shadow: var(--shadow-md);
            position: relative;
            overflow: hidden;
        }

        .cta::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;
        }

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

        .cta:hover::before {
            left: 100%;
        }

        .register-section {
            flex: 0 0 420px;
            display: flex;
            align-items: center;
            justify-content: center;
            animation: slideInRight 0.8s ease-out;
        }

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

        .register-box {
            background: var(--surface-color);
            backdrop-filter: blur(20px);
            border-radius: 24px;
            padding: 40px;
            box-shadow: var(--shadow-xl);
            border: 1px solid var(--border-color);
            width: 100%;
            max-width: 400px;
            position: relative;
        }

        .register-box::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 4px;
            background: var(--gradient-primary);
            border-radius: 24px 24px 0 0;
        }

        .register-header {
            text-align: center;
            margin-bottom: 32px;
        }

        .register-header h2 {
            font-size: 1.75rem;
            font-weight: 700;
            color: var(--text-primary);
            margin-bottom: 8px;
        }

        .register-header p {
            color: var(--text-secondary);
            font-size: 1rem;
        }

        .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-group {
            margin-bottom: 20px;
        }

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

        .form-input {
            width: 100%;
            padding: 14px 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-input::placeholder {
            color: var(--text-secondary);
            opacity: 0.7;
        }

        .submit-btn {
            width: 100%;
            background: var(--gradient-primary);
            color: white;
            font-weight: 600;
            font-size: 1rem;
            border: none;
            border-radius: 12px;
            padding: 16px;
            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;
            margin-bottom: 24px;
            margin-top: 8px;
        }

        .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%;
        }

        .login-link {
            text-align: center;
            font-size: 1rem;
            color: var(--text-secondary);
        }

        .login-link a {
            color: var(--primary-color);
            text-decoration: none;
            font-weight: 600;
            transition: color 0.3s ease;
        }

        .login-link a:hover {
            color: var(--primary-dark);
            text-decoration: underline;
        }

        /* Responsividade */
        @media (max-width: 1024px) {
            .container {
                flex-direction: column;
                gap: 40px;
                padding: 40px 20px;
            }

            .info-section {
                max-width: 100%;
                text-align: center;
            }

            .register-section {
                flex: none;
                width: 100%;
                max-width: 400px;
            }

            .features {
                grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            }
        }

        @media (max-width: 768px) {
            .container {
                padding: 20px 16px;
            }

            .info-section {
                padding: 20px;
            }

            .info-section h1 {
                font-size: 2.5rem;
            }

            .info-section p {
                font-size: 1.1rem;
            }

            .features {
                grid-template-columns: 1fr;
                gap: 16px;
            }

            .register-box {
                padding: 32px 24px;
            }

            .brand-header {
                justify-content: center;
            }

            .brand-icon {
                width: 56px;
                height: 56px;
                font-size: 1.75rem;
            }

            .brand-text {
                font-size: 1.75rem;
            }
        }

        @media (max-width: 480px) {
            .info-section h1 {
                font-size: 2rem;
            }

            .feature-card {
                padding: 20px;
            }

            .register-box {
                padding: 24px 20px;
            }

            .form-group {
                margin-bottom: 16px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="info-section">
            <div class="brand-header">
                <div class="brand-icon">
                    <i class="fa-solid fa-wallet"></i>
                </div>
                <div class="brand-text">Fiado Fácil</div>
            </div>
            
            <h1>Comece agora a controlar Vendas Fiadas!</h1>
            <p>
                Tenha controle total dos clientes, parcelas e cobranças de forma simples e eficiente.<br>
                Apenas <span class="price">R$ 10,99/mês</span> com 30 dias grátis para testar.
            </p>
            
            <div class="features">
                <div class="feature-card">
                    <div class="feature-icon">
                        <i class="fa-solid fa-building"></i>
                    </div>
                    <div class="feature-content">
                        <div class="feature-title">Multiempresa</div>
                        <div class="feature-desc">Ambiente isolado e seguro para cada negócio</div>
                    </div>
                </div>
                
                <div class="feature-card">
                    <div class="feature-icon">
                        <i class="fa-solid fa-file-pdf"></i>
                    </div>
                    <div class="feature-content">
                        <div class="feature-title">Carnês em PDF</div>
                        <div class="feature-desc">Gere carnês personalizados com QR Code</div>
                    </div>
                </div>
                
                <div class="feature-card">
                    <div class="feature-icon">
                        <i class="fa-brands fa-whatsapp"></i>
                    </div>
                    <div class="feature-content">
                        <div class="feature-title">Envio por WhatsApp</div>
                        <div class="feature-desc">Cobranças e carnês direto pelo WhatsApp</div>
                    </div>
                </div>
                
                <div class="feature-card">
                    <div class="feature-icon">
                        <i class="fa-solid fa-chart-line"></i>
                    </div>
                    <div class="feature-content">
                        <div class="feature-title">Relatórios Completos</div>
                        <div class="feature-desc">Acompanhe o desempenho do seu negócio</div>
                    </div>
                </div>
            </div>
            
            <a class="cta" href="login.php">
                <i class="fa-solid fa-sign-in-alt"></i>
                Já tem conta? Acesse aqui!
            </a>
        </div>
        
        <div class="register-section">
            <div class="register-box">
                <div class="register-header">
                    <h2>Crie sua conta</h2>
                    <p>Preencha os dados para começar seu teste gratuito</p>
                </div>
                
                <?php if (isset($error)): ?>
                    <div class="error-message">
                        <i class="fa-solid fa-exclamation-triangle"></i>
                        <?= htmlspecialchars($error) ?>
                    </div>
                <?php endif; ?>
                
                <form method="post" autocomplete="off">
                    <div class="form-group">
                        <label for="name" class="form-label">Nome Completo</label>
                        <input type="text" name="name" id="name" class="form-input" placeholder="Digite seu nome completo" required>
                    </div>
                    
                    <div class="form-group">
                        <label for="email" class="form-label">E-mail</label>
                        <input type="email" name="email" id="email" class="form-input" placeholder="Digite seu e-mail" required>
                    </div>
                    
                    <div class="form-group">
                        <label for="phone" class="form-label">Telefone</label>
                        <input type="tel" name="phone" id="phone" class="form-input" placeholder="(99) 99999-9999" required>
                    </div>
                    
                    <div class="form-group">
                        <label for="password" class="form-label">Senha</label>
                        <input type="password" name="password" id="password" class="form-input" placeholder="Crie uma senha segura" required>
                    </div>
                    
                    <button type="submit" class="submit-btn">
                        <i class="fa-solid fa-user-plus"></i>
                        Criar Conta Gratuita
                    </button>
                </form>
                
                <div class="login-link">
                    Já tem uma conta? <a href="login.php">Faça login aqui</a>
                </div>
            </div>
        </div>
    </div>
    
    <script>
        // Animações de entrada
        window.addEventListener('load', function() {
            document.body.style.opacity = '1';
        });

        // Máscara para telefone
        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áscara no telefone
        document.getElementById('phone').addEventListener('input', function(e) {
            e.target.value = maskPhone(e.target.value);
        });

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

        // Efeitos de hover nos cards
        const featureCards = document.querySelectorAll('.feature-card');
        featureCards.forEach(card => {
            card.addEventListener('mouseenter', function() {
                this.style.transform = 'translateY(-8px)';
            });
            
            card.addEventListener('mouseleave', function() {
                this.style.transform = 'translateY(0)';
            });
        });

        // Validação em tempo real
        const inputs = document.querySelectorAll('.form-input');
        inputs.forEach(input => {
            input.addEventListener('blur', function() {
                if (this.value.trim() === '') {
                    this.style.borderColor = 'var(--danger-color)';
                } else {
                    this.style.borderColor = 'var(--success-color)';
                }
            });
            
            input.addEventListener('focus', function() {
                this.style.borderColor = 'var(--primary-color)';
            });
        });
    </script>
</body>
</html>