<?php
/**
 * MEC Command Center — Tela de Login
 * Layout split-screen: vídeo à esquerda, formulário à direita
 * Autenticação por senha fixa do coordenador (1010)
 */
session_start();

// Se já está logado, redireciona para o app
if (isset($_SESSION['mec_authenticated']) && $_SESSION['mec_authenticated'] === true) {
    header("Location: index.php");
    exit;
}

$error = '';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $password = $_POST['password'] ?? '';
    
    if ($password === '1010') {
        $_SESSION['mec_authenticated'] = true;
        $_SESSION['user_id'] = 1; // ID padrão para o coordenador
        $_SESSION['user_nome'] = 'Alex Sandro';
        $_SESSION['user_role'] = 'admin'; // Alterado para admin para compatibilidade com o painel
        header("Location: index.php");
        exit;
    } else {
        $error = 'Senha incorreta. Verifique a senha do coordenador.';
    }
}
?>
<!DOCTYPE html>
<html lang="pt-BR">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MEC Command Center - CEUNSP</title>
    <meta name="description" content="Sistema de Gestão de Excelência Universitária - CEUNSP">
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <script src="https://unpkg.com/lucide@latest"></script>
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    fontFamily: { sans: ['Inter', 'sans-serif'] },
                    colors: {
                        brand: { 50: '#f0fdf4', 100: '#dcfce7', 400: '#4ade80', 500: '#22c55e', 600: '#16a34a', 700: '#15803d', 800: '#166534', 900: '#14532d' }
                    }
                }
            }
        }
    </script>
    <style>
        body { font-family: 'Inter', sans-serif; }
        .fade-in { animation: fadeIn 0.4s ease-out forwards; }
        @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
    </style>
</head>
<body class="h-screen overflow-hidden bg-slate-100">

    <!-- LOGIN LAYOUT -->
    <div class="flex h-screen w-full">
        <!-- Lado Esquerdo: Vídeo -->
        <div class="w-full md:w-[65%] lg:w-[70%] bg-slate-900 hidden md:block relative overflow-hidden group">
            <video id="login-video" src="https://asbd.com.br/mec10/video.mp4" autoplay loop muted playsinline class="w-full h-full object-cover absolute inset-0 opacity-90"></video>
            
            <!-- Overlay com título sobre o vídeo -->
            <div class="absolute inset-0 flex flex-col items-center justify-start pt-24 bg-gradient-to-b from-slate-900/90 via-slate-900/30 to-transparent pointer-events-none">
                <i data-lucide="shield-check" class="text-brand-400 w-16 h-16 mb-4 drop-shadow-lg"></i>
                <h1 class="text-5xl font-bold text-white z-10 px-12 text-center drop-shadow-lg tracking-tight">MEC Command Center<br><span class="text-brand-400 text-3xl font-medium mt-2 block">Gestão de Excelência Universitária</span></h1>
            </div>

            <!-- Botão de mute/unmute do vídeo -->
            <button id="mute-btn" onclick="toggleMute()" class="absolute bottom-8 left-8 z-20 p-3 bg-black/40 hover:bg-black/60 text-white rounded-full backdrop-blur-md transition-colors border border-white/20 opacity-70 hover:opacity-100 cursor-pointer shadow-lg" title="Ligar/Desligar Som">
                <i data-lucide="volume-x" class="w-6 h-6"></i>
            </button>
        </div>

        <!-- Lado Direito: Formulário de Login -->
        <div class="w-full md:w-[35%] lg:w-[30%] bg-white flex flex-col items-center justify-center p-6 sm:p-8 shadow-2xl z-10">
            <div class="max-w-sm w-full space-y-8 fade-in">
                <div class="text-center">
                    <div class="mx-auto w-16 h-16 bg-brand-50 text-brand-600 rounded-full flex items-center justify-center mb-4 border border-brand-100">
                        <i data-lucide="lock" class="w-8 h-8"></i>
                    </div>
                    <h2 class="text-2xl font-bold text-slate-800">Acesso Restrito</h2>
                    <p class="text-slate-500 text-sm mt-2">Insira sua senha de coordenador para acessar o painel de instrumentos.</p>
                </div>

                <?php if ($error): ?>
                <div class="bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded-xl text-sm flex items-center">
                    <i data-lucide="alert-circle" class="w-4 h-4 mr-2 shrink-0"></i>
                    <?php echo htmlspecialchars($error); ?>
                </div>
                <?php endif; ?>

                <form method="POST" class="mt-8 space-y-6">
                    <div>
                        <label for="password" class="sr-only">Senha de Acesso</label>
                        <div class="relative">
                            <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                                <i data-lucide="key" class="h-5 w-5 text-slate-400"></i>
                            </div>
                            <input id="password" name="password" type="password" required 
                                class="appearance-none rounded-xl relative block w-full px-3 py-4 pl-10 border border-slate-300 placeholder-slate-400 text-slate-900 focus:outline-none focus:ring-brand-500 focus:border-brand-500 focus:z-10 sm:text-sm bg-slate-50 transition-colors" 
                                placeholder="Senha de Acesso (Ex: 1010)"
                                autofocus>
                        </div>
                    </div>
                    <div>
                        <button type="submit" class="group relative w-full flex justify-center py-3.5 px-4 border border-transparent text-sm font-bold rounded-xl text-white bg-brand-600 hover:bg-brand-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-brand-500 transition-colors shadow-md hover:shadow-lg">
                            Entrar no Sistema
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <script>
        lucide.createIcons();

        // Controle de mute/unmute do vídeo
        function toggleMute() {
            const video = document.getElementById('login-video');
            const btn = document.getElementById('mute-btn');
            video.muted = !video.muted;
            btn.innerHTML = video.muted 
                ? '<i data-lucide="volume-x" class="w-6 h-6"></i>' 
                : '<i data-lucide="volume-2" class="w-6 h-6"></i>';
            lucide.createIcons();
        }
    </script>
</body>
</html>
