<?php
// login.php
ini_set('session.cookie_path', '/');
session_start();

// Si las variables de sesión de administrador o padre ya están inicializadas, omitimos el login de forma directa
if (isset($_SESSION['usu_id']) || isset($_SESSION['padre_id'])) {
    header("Location: index.php");
    exit;
}
?>
<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Stage Dance Class | Iniciar Sesión</title>
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        body {
            font-family: 'Poppins', sans-serif;
            background: linear-gradient(135deg, #f26a8d 0%, #111b24 100%);
            height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 0;
        }
        .login-card {
            background: rgba(255, 255, 255, 0.96);
            padding: 40px;
            border-radius: 20px;
            box-shadow: 0 15px 35px rgba(0,0,0,0.25);
            width: 100%;
            max-width: 410px;
        }
        .btn-stage {
            background-color: #f26a8d;
            color: white;
            border: none;
            font-weight: 600;
            transition: all 0.3s ease;
        }
        .btn-stage:hover {
            background-color: #db5375;
            color: white;
            transform: translateY(-2px);
        }
        .text-stage {
            color: #111b24;
        }
        .text-pink {
            color: #f26a8d !important;
            transition: color 0.2s ease-in-out;
        }
        .text-pink:hover {
            color: #db5375 !important;
        }
    </style>
</head>
<body>

    <div class="login-card">
        <div class="text-center mb-4">
            <img src="assets/img/stage.png" alt="Stage Dance Class" style="max-width: 150px; height: auto;" class="mb-2">
            <h5 class="fw-bold text-stage">Sistema de Gestión</h5>
            <p class="text-muted small">Panel de Control Operativo y Financiero</p>
        </div>

        <?php if (isset($_GET['error'])): ?>
            <div class="alert alert-danger d-flex align-items-center small py-2 mb-3" role="alert">
                <i class="fas fa-exclamation-circle me-2"></i>
                <div>
                    <?php 
                        if ($_GET['error'] == 'vacio') echo "Por favor, complete todos los campos obligatorios.";
                        else echo "Las credenciales ingresadas son incorrectas.";
                    ?>
                </div>
            </div>
        <?php endif; ?>

        <form action="modelo/validar_login.php" method="POST">
            <div class="mb-3">
                <label class="form-label text-muted small fw-bold">Usuario</label>
                <div class="input-group">
                    <span class="input-group-text bg-light border-end-0"><i class="fas fa-user text-muted"></i></span>
                    <input type="text" name="usu_usuario" class="form-control bg-light border-start-0" placeholder="Su nombre de usuario o Cédula de Alumna" required autofocus>
                </div>
            </div>
            <div class="mb-4">
                <label class="form-label text-muted small fw-bold">Contraseña</label>
                <div class="input-group">
                    <span class="input-group-text bg-light border-end-0"><i class="fas fa-lock text-muted"></i></span>
                    <input type="password" name="usu_clave" class="form-control bg-light border-start-0" placeholder="••••••••" required>
                </div>
            </div>
            
            <button type="submit" class="btn btn-stage w-100 rounded-pill shadow-sm py-2 text-uppercase mb-3" style="font-size: 0.85rem; letter-spacing: 0.5px;">
                Ingresar al Sistema <i class="fas fa-arrow-right ms-2"></i>
            </button>
        </form>

        <div class="text-center mt-3">
            <span class="text-muted small">¿Nueva Alumna / Bastonera?</span>
            <a href="registro_bastonera.php" class="text-decoration-none fw-bold small text-pink ms-1">Regístrate aquí</a>
        </div>

        <div class="text-center mt-4">
            <hr class="text-muted opacity-25">
            <small class="text-muted">Stage Dance Class &copy; <?php echo date('Y'); ?></small>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>