<?php
$email = strtolower(trim((string) ($_GET['email'] ?? '')));
?>
<!DOCTYPE html>
<html lang="ms">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Reset Kata Laluan | MAINPP WORKSPACE</title>
    <style>
        html {
            min-height: 100%;
            margin: 0;
            padding: 0;
            background: #f5f8f7;
        }

        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
            font-family: 'Segoe UI', 'Inter', Tahoma, Geneva, Verdana, sans-serif;
        }

        :root {
            --main-blue: #0077b6;
            --deep-blue: #023e5f;
            --soft-blue: #00b4d8;
            --text-dark: #17232b;
            --text-muted: #2d5367;
        }

        body {
            min-height: 100vh;
            color: var(--text-dark);
            background: #f5f8f7;
            overflow: hidden;
        }

        body::before,
        body::after {
            content: "";
            position: fixed;
            pointer-events: none;
            z-index: 0;
        }

        body::before {
            width: 54vw;
            height: 54vw;
            left: -18vw;
            bottom: -25vw;
            background:
                linear-gradient(155deg, rgba(255, 255, 255, 0.11), rgba(255, 255, 255, 0.01)),
                repeating-linear-gradient(0deg, transparent 0 32px, rgba(255, 255, 255, 0.08) 33px 34px);
            border: 1px solid rgba(255, 255, 255, 0.12);
            border-radius: 38px;
            transform: rotate(-10deg);
            box-shadow: 0 30px 120px rgba(0, 0, 0, 0.16);
        }

        body::after {
            width: 34vw;
            height: 34vw;
            left: 12vw;
            top: 10vw;
            background:
                radial-gradient(circle, rgba(0, 180, 216, 0.28), transparent 58%),
                radial-gradient(circle, rgba(0, 119, 182, 0.16), transparent 44%);
            filter: blur(8px);
            opacity: 0.95;
        }

        .reset-shell {
            position: relative;
            z-index: 1;
            min-height: 100vh;
            height: 100vh;
            display: grid;
            grid-template-columns: minmax(340px, 1fr) minmax(340px, 1fr);
            align-items: stretch;
            width: 100%;
        }

        .brand-panel {
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            padding: clamp(36px, 7vw, 92px);
            text-align: center;
            background:
                linear-gradient(135deg, rgba(2, 62, 95, 0.82), rgba(0, 119, 182, 0.58)),
                radial-gradient(circle at 22% 24%, rgba(0, 180, 216, 0.38), transparent 28%),
                radial-gradient(circle at 56% 74%, rgba(0, 180, 216, 0.24), transparent 24%);
            overflow: hidden;
        }

        .brand-mark {
            position: relative;
            display: flex;
            align-items: center;
            justify-content: center;
            width: min(340px, 54vw);
            aspect-ratio: 1;
            border-radius: 50%;
            background:
                radial-gradient(circle, rgba(255, 255, 255, 0.18), rgba(255, 255, 255, 0.03) 58%, transparent 62%),
                conic-gradient(from 0deg, rgba(255, 255, 255, 0.02), rgba(0, 180, 216, 0.3), rgba(255, 255, 255, 0.02), rgba(0, 119, 182, 0.28), rgba(255, 255, 255, 0.02));
            box-shadow: 0 34px 95px rgba(0, 0, 0, 0.32);
        }

        .brand-mark::before {
            content: "";
            position: absolute;
            inset: 11%;
            border: 1px solid rgba(255, 255, 255, 0.16);
            border-radius: 50%;
        }

        .brand-mark::after {
            content: "";
            position: absolute;
            width: 118%;
            height: 118%;
            border-radius: 50%;
            border: 1px dashed rgba(255, 255, 255, 0.2);
            animation: orbitSpin 12s linear infinite;
        }

        .brand-mark img {
            position: relative;
            z-index: 1;
            width: clamp(155px, 19vw, 245px);
            height: auto;
            filter: drop-shadow(0 18px 28px rgba(0, 0, 0, 0.34));
            animation: logoRotate 9s linear infinite;
            transform-origin: center;
        }
        .brand-name {
            max-width: 360px;
            margin-top: 34px;
            color: #fff;
            font-size: clamp(1.05rem, 2vw, 1.45rem);
            line-height: 1.35;
            font-weight: 800;
            text-align: center;
            text-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
        }

        @keyframes logoRotate {
            from { transform: rotateY(0deg); }
            to { transform: rotateY(360deg); }
        }

        @keyframes orbitSpin {
            from { transform: rotate(0deg); }
            to { transform: rotate(360deg); }
        }

        .reset-panel {
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: clamp(28px, 6vw, 74px);
            background:
                linear-gradient(135deg, rgba(255, 255, 255, 0.48), rgba(0, 180, 216, 0.12)),
                url('assets/auth-bg.png') center/cover no-repeat;
        }

        .reset-card {
            width: 100%;
            max-width: 430px;
            border-radius: 22px;
            padding: 34px 38px;
            background: rgba(255, 255, 255, 0.30);
            border: 1px solid rgba(255, 255, 255, 0.42);
            box-shadow: 0 30px 90px rgba(2, 38, 60, 0.26);
            backdrop-filter: blur(24px) saturate(1.25);
            -webkit-backdrop-filter: blur(24px) saturate(1.25);
        }

        .form-heading {
            text-align: center;
            margin-bottom: 24px;
        }

        .form-heading h1 {
            color: #005f99;
            font-size: clamp(1.78rem, 3vw, 2.25rem);
            line-height: 1.12;
            font-weight: 800;
            margin-bottom: 10px;
        }

        .form-heading p {
            color: #355f73;
            font-size: 0.94rem;
            font-weight: 600;
            line-height: 1.5;
        }

        .form-group {
            margin-bottom: 16px;
        }

        label {
            display: block;
            margin-bottom: 8px;
            color: var(--text-dark);
            font-weight: 700;
            font-size: 0.9rem;
        }

        input {
            width: 100%;
            height: 46px;
            padding: 11px 15px;
            border: 1px solid #dce5e4;
            border-radius: 7px;
            font-size: 0.95rem;
            color: #12313e;
            transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
            background: #fff;
            box-shadow: 0 1px 0 rgba(16, 50, 47, 0.03);
        }

        input[readonly] {
            color: #69767c;
            background: #f4f8f9;
        }

        input::placeholder {
            color: #526b79;
        }

        input:focus {
            border-color: rgba(0, 180, 216, 0.95);
            outline: none;
            box-shadow: 0 0 0 4px rgba(0, 180, 216, 0.15);
            background: #fff;
        }

        .btn-submit {
            width: 100%;
            height: 50px;
            margin-top: 4px;
            padding: 0 18px;
            background: linear-gradient(90deg, #0077b6, #00b4d8);
            color: #fff;
            border: 1px solid rgba(0, 119, 182, 0.28);
            border-radius: 999px;
            font-size: 0.95rem;
            font-weight: 850;
            letter-spacing: 0.04em;
            cursor: pointer;
            box-shadow: 0 14px 28px rgba(0, 119, 182, 0.26);
            transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
        }

        .btn-submit:hover {
            transform: translateY(-1px);
            filter: brightness(1.03);
            box-shadow: 0 18px 34px rgba(0, 119, 182, 0.34);
        }

        .error {
            color: #dc3545;
            font-size: 0.85rem;
            margin-top: 6px;
            display: none;
        }

        .helper-text {
            text-align: center;
            margin-top: 16px;
            color: var(--text-muted);
            font-size: 0.88rem;
            line-height: 1.5;
        }

        .back-link {
            text-align: center;
            margin-top: 18px;
            font-size: 0.9rem;
        }

        .back-link a {
            color: var(--main-blue);
            font-weight: 700;
            text-decoration: none;
        }

        .back-link a:hover,
        .back-link a:focus {
            text-decoration: none;
        }

        @media (max-width: 860px) {
            body {
                overflow-y: auto;
                overflow-x: hidden;
            }

            .reset-shell {
                grid-template-columns: 1fr;
                min-height: 100vh;
                height: auto;
            }

            .brand-panel {
                min-height: 36vh;
                padding: 36px 24px;
            }

            .brand-mark {
                width: min(260px, 70vw);
            }
            .brand-name {
                margin-top: 24px;
                font-size: 1.05rem;
            }

            .reset-panel {
                min-height: auto;
                padding: 34px 18px 44px;
            }
        }

        @media (max-width: 460px) {
            .reset-card {
                padding: 26px 20px;
                border-radius: 22px;
            }
        }
    </style>
</head>
<body>
    <main class="reset-shell">
        <section class="brand-panel" aria-label="Logo MAINPP">
            <div class="brand-mark">
                <img src="mainpp.png" alt="Logo MAINPP">
            </div>
            <p class="brand-name">Majlis Agama Islam Negeri Pulau Pinang</p>
        </section>

        <section class="reset-panel" aria-label="Reset kata laluan">
            <div class="reset-card">
                <div class="form-heading">
                    <h1>Reset Kata Laluan</h1>
                    <p>MAINPP WORKSPACE</p>
                </div>

                <form action="process_reset.php" method="POST" id="resetForm">
                    <input type="hidden" name="email" value="<?php echo htmlspecialchars($email, ENT_QUOTES, 'UTF-8'); ?>">

                    <div class="form-group">
                        <label for="resetEmail">Emel Berdaftar</label>
                        <input type="email" id="resetEmail" value="<?php echo htmlspecialchars($email, ENT_QUOTES, 'UTF-8'); ?>" readonly>
                    </div>

                    <div class="form-group">
                        <label for="token">Token Pengesahan</label>
                        <input type="text" name="token" id="token" placeholder="6 digit angka" inputmode="numeric" pattern="[0-9]{6}" maxlength="6" required>
                    </div>

                    <div class="form-group">
                        <label for="newPass">Kata Laluan Baru</label>
                        <input type="password" name="new_pass" id="newPass" autocomplete="new-password" required>
                    </div>

                    <div class="form-group">
                        <label for="confirmPass">Sahkan Kata Laluan</label>
                        <input type="password" name="confirm_pass" id="confirmPass" autocomplete="new-password" required>
                        <div class="error" id="passError">Kata laluan tidak sepadan.</div>
                    </div>

                    <button type="submit" class="btn-submit">TETAPKAN KATA LALUAN</button>
                </form>

                <div class="helper-text">
                    Masukkan token 6 digit yang dihantar ke emel anda.
                </div>

                <div class="back-link">
                    <a href="forgot_password.php">&larr; Kembali</a>
                </div>
            </div>
        </section>
    </main>

    <script>
        document.getElementById('resetForm').addEventListener('submit', function(e) {
            const p1 = document.querySelector('input[name="new_pass"]').value;
            const p2 = document.querySelector('input[name="confirm_pass"]').value;
            const err = document.getElementById('passError');
            if (p1 !== p2) {
                e.preventDefault();
                err.style.display = 'block';
            } else {
                err.style.display = 'none';
            }
        });
    </script>
</body>
</html>
