<?php
/**
 * Reset Password View — Helmyx Auth Page
 */
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Reset Password — Helmyx</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@600;700&family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
    <link rel="icon" type="image/png" sizes="32x32" href="<?= defined('APP_URL') ? APP_URL : '' ?>/assets/brand/favicon/helmyx-icon-32.png">
    <link rel="stylesheet" href="<?= defined('APP_URL') ? APP_URL : '' ?>/assets/css/hx-tokens.css">
    <link rel="stylesheet" href="<?= defined('APP_URL') ? APP_URL : '' ?>/assets/css/style.css">
    <link rel="stylesheet" href="<?= defined('APP_URL') ? APP_URL : '' ?>/assets/css/auth.css">
    <style>
        .password-wrapper { position: relative; }
        .password-toggle { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 0; }
    </style>
</head>
<body class="auth-body">

<div class="auth-wrapper">
    <div class="auth-shapes">
        <div class="shape shape-1"></div>
        <div class="shape shape-2"></div>
        <div class="shape shape-3"></div>
        <div class="shape shape-4"></div>
    </div>

    <div class="auth-card">
        <div class="auth-logo">
            <img src="<?= APP_URL ?>/assets/brand/logo/helmyx-horizontal.svg" alt="Helmyx — Steer. Plan. Deliver." style="height:46px;">
        </div>

        <h1 class="auth-title">Set a new password</h1>
        <p class="auth-subtitle">Choose a strong password for your account.</p>

        <?php if (!empty($_SESSION['flash'])): ?>
            <?php foreach ($_SESSION['flash'] as $type => $message): ?>
                <div class="alert alert-<?= htmlspecialchars($type) ?>" style="margin-bottom:16px;">
                    <span><?= htmlspecialchars($message) ?></span>
                    <button class="alert-dismiss" onclick="this.parentElement.remove()">&times;</button>
                </div>
            <?php endforeach; unset($_SESSION['flash']); ?>
        <?php endif; ?>

        <form method="POST" action="<?= APP_URL ?>/reset-password" novalidate>
            <input type="hidden" name="csrf_token" value="<?= htmlspecialchars($_SESSION[CSRF_TOKEN_NAME] ?? '') ?>">
            <input type="hidden" name="token" value="<?= htmlspecialchars($token ?? '') ?>">

            <div class="form-group">
                <label class="form-label" for="password">New Password</label>
                <div class="password-wrapper input-group">
                    <input type="password" id="password" name="password" class="form-control" placeholder="At least 8 characters" autocomplete="new-password" required style="padding-right:44px;">
                    <button type="button" class="password-toggle" onclick="togglePassword('password')">Show</button>
                </div>
                <p style="font-size:0.75rem;color:var(--text-muted);margin-top:6px;">Must include an uppercase letter, a lowercase letter, a number, and a special character.</p>
            </div>

            <div class="form-group">
                <label class="form-label" for="password_confirm">Confirm New Password</label>
                <input type="password" id="password_confirm" name="password_confirm" class="form-control" placeholder="Re-enter your password" autocomplete="new-password" required>
            </div>

            <button type="submit" class="btn btn-primary w-full btn-lg" style="justify-content:center;">Reset Password</button>
        </form>

        <p style="text-align:center;margin-top:24px;font-size:0.85rem;">
            <a href="<?= APP_URL ?>/login" style="color:var(--primary);text-decoration:none;">&larr; Back to Sign In</a>
        </p>
    </div>
</div>

<script>
function togglePassword(inputId) {
    const input = document.getElementById(inputId);
    input.type = input.type === 'password' ? 'text' : 'password';
}
</script>
</body>
</html>
