<?php
require_once __DIR__.'/includes/functions.php';
verify_csrf();
if($_SERVER['REQUEST_METHOD']==='POST'){
    $u=one('SELECT * FROM mj_users WHERE email=? AND is_active=1', [trim($_POST['email']??'')]);
    if($u && password_verify((string)($_POST['password']??''),$u['password_hash'])){
        $_SESSION['user_id']=$u['id']; q('UPDATE mj_users SET last_login_at=NOW() WHERE id=?',[$u['id']]); redirect('my-account.php');
    }
    flash('error','Invalid login. Please check your email and password.');
}
$pageTitle='User Login'; include __DIR__.'/includes/header.php';
?>
<section class="mj-auth-shell"><div class="container"><div class="row justify-content-center"><div class="col-xl-10"><div class="card mj-auth-card"><div class="row g-0"><div class="col-lg-6"><div class="mj-auth-visual h-100"><span class="badge text-bg-light text-primary rounded-pill mb-3"><i class="bi bi-shield-check me-1"></i>Secure member access</span><h1 class="fw-bold display-5">Welcome back to MJ Marketplace.</h1><p class="text-white-50">Continue chats, offers, company enquiries and listing management from one account.</p><img src="<?=asset('images/marketplace-hero.svg')?>" alt="Login illustration"></div></div><div class="col-lg-6"><div class="p-4 p-lg-5"><h2 class="fw-bold mb-1">Login</h2><p class="text-muted mb-4">Sign in to manage your marketplace account.</p><form method="post"><?=csrf_input()?><div class="mb-3"><label class="form-label fw-semibold">Email address</label><div class="input-group"><span class="input-group-text bg-white border-end-0 rounded-start-4"><i class="bi bi-envelope"></i></span><input class="form-control border-start-0 rounded-end-4" type="email" name="email" placeholder="you@example.com" required></div></div><div class="mb-3"><label class="form-label fw-semibold">Password</label><div class="input-group"><span class="input-group-text bg-white border-end-0 rounded-start-4"><i class="bi bi-lock"></i></span><input class="form-control border-start-0 rounded-end-4" type="password" name="password" placeholder="••••••••" required></div></div><div class="d-flex justify-content-between align-items-center mb-4"><label class="small text-muted"><input type="checkbox" class="form-check-input me-1"> Remember me</label><a href="help.php" class="small text-decoration-none">Need help?</a></div><button class="btn btn-primary w-100 btn-lg"><i class="bi bi-box-arrow-in-right me-1"></i>Login</button></form><div class="text-center mt-4 text-muted">No account? <a href="register.php" class="fw-bold text-decoration-none">Create one now</a></div></div></div></div></div></div></div></div></section>
<?php include __DIR__.'/includes/footer.php'; ?>
