{% extends "base.html" %}

{% block title %}Logowanie - Norda Biznes Hub{% endblock %}

{% block container_class %}container-narrow{% endblock %}

{% block extra_css %}
<style>
    .auth-container {
        max-width: 480px;
        margin: 0 auto;
        padding: var(--spacing-2xl) 0;
    }

    .auth-card {
        background-color: var(--surface);
        padding: var(--spacing-2xl);
        border-radius: var(--radius-xl);
        box-shadow: var(--shadow-lg);
    }

    .auth-header {
        text-align: center;
        margin-bottom: var(--spacing-xl);
    }

    .auth-header h1 {
        font-size: var(--font-size-3xl);
        color: var(--text-primary);
        margin-bottom: var(--spacing-sm);
    }

    .auth-header p {
        color: var(--text-secondary);
    }

    .form-group {
        margin-bottom: var(--spacing-lg);
    }

    .form-label {
        display: block;
        font-weight: 500;
        margin-bottom: var(--spacing-sm);
        color: var(--text-primary);
    }

    .form-label .required {
        color: var(--error);
    }

    .form-input {
        width: 100%;
        padding: var(--spacing-md);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        font-size: var(--font-size-base);
        font-family: var(--font-family);
        transition: var(--transition);
    }

    .form-input:focus {
        outline: none;
        border-color: var(--primary);
        box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    }

    .form-input.error {
        border-color: var(--error);
    }

    .form-checkbox {
        display: flex;
        align-items: center;
        gap: var(--spacing-sm);
    }

    .form-checkbox input {
        width: 18px;
        height: 18px;
        cursor: pointer;
    }

    .form-actions {
        margin-top: var(--spacing-xl);
    }

    .btn-full {
        width: 100%;
    }

    .auth-footer {
        text-align: center;
        margin-top: var(--spacing-lg);
        padding-top: var(--spacing-lg);
        border-top: 1px solid var(--border);
        color: var(--text-secondary);
    }

    .auth-footer a {
        color: var(--primary);
        text-decoration: none;
        font-weight: 500;
    }

    .auth-footer a:hover {
        text-decoration: underline;
    }
</style>
{% endblock %}

{% block content %}
<div class="auth-container">
    <div class="auth-card">
        <div class="auth-header">
            <h1>Zaloguj się</h1>
            <p>Witaj ponownie! Zaloguj się do swojego konta.</p>
        </div>

        <form method="POST" action="{{ url_for('login') }}" novalidate>
            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">

            <div class="form-group">
                <label for="email" class="form-label">
                    Adres email <span class="required">*</span>
                </label>
                <input
                    type="email"
                    id="email"
                    name="email"
                    class="form-input"
                    placeholder="twoj@email.com"
                    required
                    autocomplete="email"
                    autofocus
                >
            </div>

            <div class="form-group">
                <label for="password" class="form-label">
                    Hasło <span class="required">*</span>
                </label>
                <input
                    type="password"
                    id="password"
                    name="password"
                    class="form-input"
                    placeholder="••••••••"
                    required
                    autocomplete="current-password"
                >
            </div>

            <div class="form-group">
                <label class="form-checkbox">
                    <input type="checkbox" name="remember" id="remember">
                    <span>Zapamiętaj mnie</span>
                </label>
            </div>

            <div class="form-actions">
                <button type="submit" class="btn btn-primary btn-lg btn-full">
                    Zaloguj się
                </button>
            </div>
        </form>

        <div class="auth-footer">
            <p><a href="{{ url_for('forgot_password') }}">Nie pamietasz hasla?</a></p>
            <p style="margin-top: var(--spacing-sm);"><a href="{{ url_for('resend_verification') }}">Nie otrzymales emaila weryfikacyjnego?</a></p>
            <p style="margin-top: var(--spacing-sm);">Nie masz konta? <a href="{{ url_for('register') }}">Zarejestruj sie</a></p>
        </div>
    </div>
</div>
{% endblock %}

{% block extra_js %}
    // Client-side validation
    document.querySelector('form').addEventListener('submit', function(e) {
        const email = document.getElementById('email');
        const password = document.getElementById('password');
        let valid = true;

        // Email validation
        if (!email.value || !email.value.includes('@')) {
            email.classList.add('error');
            valid = false;
        } else {
            email.classList.remove('error');
        }

        // Password validation
        if (!password.value || password.value.length < 1) {
            password.classList.add('error');
            valid = false;
        } else {
            password.classList.remove('error');
        }

        if (!valid) {
            e.preventDefault();
        }
    });
{% endblock %}
