<?php
require_once __DIR__ . '/includes/bootstrap.php';
if (current_user()) { redirect('dashboard.php'); }
$error = null;
if (is_post()) {
    $email = trim($_POST['email'] ?? '');
    $password = $_POST['password'] ?? '';
    $stmt = db()->prepare("SELECT * FROM users WHERE email = ? AND status = 'active' LIMIT 1");
    $stmt->execute([$email]);
    $user = $stmt->fetch();
    if ($user && password_verify($password, $user['password'])) { login_user($user); audit_log('login', 'users', $user['id'], 'Inicio de sesión'); redirect('dashboard.php'); } else { $error = 'Correo o contraseña incorrectos.'; }
}
?>
<!doctype html><html lang="es"><head><meta charset="utf-8"><title>Login - <?= e(APP_NAME) ?></title><meta name="viewport" content="width=device-width, initial-scale=1"><link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"><link href="<?= e(base_url('assets/css/app.css')) ?>" rel="stylesheet"></head><body>
<div class="container-fluid login-shell"><div class="row justify-content-center align-items-center" style="min-height:100vh;"><div class="col-xl-10 col-lg-10"><div class="card login-card"><div class="row g-0">
<div class="col-md-5 login-brand d-flex flex-column justify-content-center p-5"><img src="<?= e(base_url('assets/img/logo.png')) ?>" alt="HM Servicios Informáticos" class="mb-4"><h2 class="fw-bold mb-3">ERP RRHH v5 v3 Comercial</h2><p class="mb-3">Base lista para demo, venta e implementación inicial en cPanel.</p><ul class="list-clean small opacity-75"><li>Instalador web incluido</li><li>Empresa editable desde panel</li><li>Recibo imprimible de nómina</li><li>Vacaciones con saldo automático</li></ul></div>
<div class="col-md-7 bg-white p-4 p-md-5"><div class="mb-4"><span class="badge-soft">Acceso al sistema</span><h3 class="mt-3 mb-1">Bienvenido</h3><p class="text-muted mb-0">Ingresá con tus credenciales para administrar RRHH.</p></div><?php if ($error): ?><div class="alert alert-danger rounded-4 border-0"><?= e($error) ?></div><?php endif; ?>
<form method="post"><div class="mb-3"><label class="form-label fw-semibold">Correo</label><input type="email" name="email" class="form-control form-control-lg" required value="admin@local.test"></div><div class="mb-3"><label class="form-label fw-semibold">Contraseña</label><input type="password" name="password" class="form-control form-control-lg" required value="admin123"></div><button class="btn btn-primary btn-lg w-100 rounded-4">Ingresar</button></form>
<div class="mt-4 text-muted small">Usuario inicial: <strong>admin@local.test</strong> · Clave: <strong>admin123</strong></div></div>
</div></div></div></div></div></body></html>
