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

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $email = trim($_POST['email']);
    $pass  = $_POST['password'];

    $sql = "SELECT * FROM users WHERE email = ?";
    $stmt = $pdo->prepare($sql);
    $stmt->execute([$email]);
    $user = $stmt->fetch();

    if ($user && password_verify($pass, $user['password'])) {
        if ($user['active'] == 1) {
            $_SESSION['user_id'] = $user['id'];
            header('Location: dashboard.php');
            exit;
        } else {
            $error = "Seu acesso está bloqueado.<br>Entre em contato pelo <b>WhatsApp (83) 99853-3151</b> para liberação.";
        }
    } else {
        $error = "Seu acesso está bloqueado.<br>Entre em contato pelo <b>WhatsApp (83) 99853-3151</b> para liberação.";
    }
}
?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="UTF-8">
    <title>Login - 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.4;
            min-height: 100vh;
            overflow-x: hidden;
        }

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

        .info-section {
            flex: 1;
            max-width: 550px;
            padding: 20px;
            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: 12px;
            margin-bottom: 20px;
        }

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

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

        .info-section h1 {
            font-size: 2.2rem;
            color: var(--text-primary);
            font-weight: 800;
            margin-bottom: 15px;
            line-height: 1.1;
            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: 1rem;
            color: var(--text-secondary);
            margin-bottom: 25px;
            line-height: 1.5;
        }

        .price {
            color: var(--primary-color);
            font-weight: 700;
            font-size: 1.2rem;
            text-decoration: none;
            background: var(--primary-light);
            padding: 3px 10px;
            border-radius: 6px;
            display: inline-block;
        }

        .features {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 12px;
            margin-bottom: 25px;
        }

        .feature-card {
            background: var(--surface-color);
            border-radius: 12px;
            padding: 16px;
            box-shadow: var(--shadow-md);
            border: 1px solid var(--border-color);
            display: flex;
            align-items: flex-start;
            gap: 12px;
            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(-2px);
            box-shadow: var(--shadow-lg);
        }

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

        .feature-content {
            flex: 1;
        }

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

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

        .cta {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            padding: 12px 24px;
            background: var(--gradient-primary);
            color: white;
            border-radius: 10px;
            text-decoration: none;
            font-size: 0.95rem;
            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%;
        }

        .login-section {
            flex: 0 0 380px;
            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);
            }
        }

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

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

        .login-header {
            text-align: center;
            margin-bottom: 25px;
        }

        .login-header h2 {
            font-size: 1.5rem;
            font-weight: 700;
            color: var(--text-primary);
            margin-bottom: 6px;
        }

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

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

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

        .form-group {
            margin-bottom: 18px;
        }

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

        .form-input {
            width: 100%;
            padding: 12px 14px;
            border: 2px solid var(--border-color);
            border-radius: 10px;
            background: var(--surface-color);
            font-size: 0.95rem;
            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;
        }

        .forgot-link {
            display: block;
            text-align: right;
            margin-bottom: 20px;
            font-size: 0.85rem;
            color: var(--primary-color);
            text-decoration: none;
            font-weight: 500;
            transition: color 0.3s ease;
        }

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

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

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

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

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

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

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

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

            .login-section {
                flex: none;
                width: 100%;
                max-width: 380px;
            }

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

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

            .info-section {
                padding: 15px;
            }

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

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

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

            .feature-card {
                padding: 14px;
            }

            .login-box {
                padding: 25px;
            }
        }

        @media (max-width: 480px) {
            .container {
                padding: 15px 12px;
            }

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

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

            .brand-icon {
                width: 40px;
                height: 40px;
                font-size: 1.3rem;
            }

            .login-box {
                padding: 20px;
            }

            .login-header h2 {
                font-size: 1.3rem;
            }
        }

        /* Otimizações para altura da viewport */
        @media (max-height: 700px) {
            .container {
                padding: 10px;
                gap: 20px;
            }

            .info-section {
                padding: 15px;
            }

            .info-section h1 {
                font-size: 1.8rem;
                margin-bottom: 10px;
            }

            .info-section p {
                margin-bottom: 20px;
                font-size: 0.9rem;
            }

            .brand-header {
                margin-bottom: 15px;
            }

            .features {
                margin-bottom: 20px;
                gap: 8px;
            }

            .feature-card {
                padding: 12px;
            }

            .login-box {
                padding: 25px;
            }

            .login-header {
                margin-bottom: 20px;
            }

            .form-group {
                margin-bottom: 15px;
            }
        }

        @media (max-height: 600px) {
            .container {
                min-height: auto;
                padding: 8px;
            }

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

            .features {
                grid-template-columns: repeat(2, 1fr);
                gap: 6px;
            }

            .feature-card {
                padding: 10px;
            }

            .feature-title {
                font-size: 0.85rem;
            }

            .feature-desc {
                font-size: 0.75rem;
            }

            .login-box {
                padding: 20px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="info-section">
            <div class="brand-header">
                <div class="brand-icon">
                    <i class="fas fa-handshake"></i>
                </div>
                <div class="brand-text">Fiado Fácil</div>
            </div>
            
            <h1>Controle de Fiado Inteligente</h1>
            <p>Gerencie seus clientes fiados de forma simples e eficiente. Tenha controle total sobre vendas a prazo com <span class="price">apenas R$ 19,90/mês</span>.</p>
            
            <div class="features">
                <div class="feature-card">
                    <div class="feature-icon">
                        <i class="fas fa-users"></i>
                    </div>
                    <div class="feature-content">
                        <div class="feature-title">Gestão de Clientes</div>
                        <div class="feature-desc">Cadastre e organize todos os seus clientes fiados</div>
                    </div>
                </div>
                
                <div class="feature-card">
                    <div class="feature-icon">
                        <i class="fas fa-chart-line"></i>
                    </div>
                    <div class="feature-content">
                        <div class="feature-title">Relatórios Detalhados</div>
                        <div class="feature-desc">Acompanhe vendas e recebimentos em tempo real</div>
                    </div>
                </div>
                
                <div class="feature-card">
                    <div class="feature-icon">
                        <i class="fas fa-bell"></i>
                    </div>
                    <div class="feature-content">
                        <div class="feature-title">Lembretes Automáticos</div>
                        <div class="feature-desc">Notificações de vencimento via WhatsApp</div>
                    </div>
                </div>
                
                <div class="feature-card">
                    <div class="feature-icon">
                        <i class="fas fa-mobile-alt"></i>
                    </div>
                    <div class="feature-content">
                        <div class="feature-title">Acesso Mobile</div>
                        <div class="feature-desc">Use em qualquer dispositivo, a qualquer hora</div>
                    </div>
                </div>
            </div>
            
            <a href="#" class="cta">
                <i class="fas fa-rocket"></i>
                Começar Agora
            </a>
        </div>
        
        <div class="login-section">
            <div class="login-box">
                <div class="login-header">
                    <h2>Fazer Login</h2>
                    <p>Acesse sua conta</p>
                </div>
                
                <?php if (isset($error)): ?>
                    <div class="error-message">
                        <i class="fas fa-exclamation-triangle"></i>
                        <?= $error ?>
                    </div>
                <?php endif; ?>
                
                <form method="POST">
                    <div class="form-group">
                        <label class="form-label">E-mail</label>
                        <input type="email" name="email" class="form-input" placeholder="seu@email.com" required>
                    </div>
                    
                    <div class="form-group">
                        <label class="form-label">Senha</label>
                        <input type="password" name="password" class="form-input" placeholder="••••••••" required>
                    </div>
                    
                    <a href="#" class="forgot-link">Esqueceu a senha?</a>
                    
                    <button type="submit" class="submit-btn">
                        <i class="fas fa-sign-in-alt"></i>
                        Entrar
                    </button>
                </form>
                
                <div class="register-link">
                    Não tem conta? <a href="#">Cadastre-se</a>
                </div>
            </div>
        </div>
    </div>
</body>
</html>