<?php
if (session_status() !== PHP_SESSION_ACTIVE) {
    session_start();
}

function rp_h($v) {
    return htmlspecialchars((string)$v, ENT_QUOTES, 'UTF-8');
}

$error = $_SESSION['error'] ?? '';
unset($_SESSION['error']);

$email = $_GET['email'] ?? $_POST['email'] ?? '';
$token = $_GET['token'] ?? $_POST['token'] ?? '';
?>
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8">
<title>Set New Password</title>
<link href="https://fonts.googleapis.com/css2?family=Cairo:wght@400;700;900&display=swap" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.rtl.min.css" rel="stylesheet">
<style>
body{font-family:Cairo,sans-serif;min-height:100vh;background:linear-gradient(135deg,#0f172a,#1d4ed8);display:flex;align-items:center;justify-content:center;padding:20px}
.cardx{max-width:540px;width:100%;background:#fff;border-radius:28px;box-shadow:0 25px 70px rgba(0,0,0,.25);overflow:hidden}
.head{background:linear-gradient(135deg,#0f172a,#2563eb);color:#fff;padding:28px}
.form-control{border-radius:16px;padding:13px}
.btn-main{border:0;border-radius:18px;padding:13px;font-weight:900;background:linear-gradient(135deg,#16a34a,#22c55e);color:#fff}
</style>
</head>
<body>
<div class="cardx">
    <div class="head">
        <h3 class="fw-bold mb-1">تعيين كلمة مرور جديدة</h3>
        <div class="opacity-75">Choose a new password for your account.</div>
    </div>

    <div class="p-4">
        <?php if ($error): ?><div class="alert alert-danger"><?= rp_h($error) ?></div><?php endif; ?>

        <form method="post" action="/easychair/reset-password">
            <input type="hidden" name="email" value="<?= rp_h($email) ?>">
            <input type="hidden" name="token" value="<?= rp_h($token) ?>">

            <label class="form-label fw-bold">New Password</label>
            <input type="password" name="password" class="form-control mb-3" minlength="8" required>

            <label class="form-label fw-bold">Confirm Password</label>
            <input type="password" name="password_confirm" class="form-control mb-3" minlength="8" required>

            <button class="btn-main w-100">Save New Password</button>
        </form>
    </div>
</div>
</body>
</html>
