{% extends "base.html" %}

{% block title %}Bezpieczeństwo - Moje konto - Norda Biznes Partner{% endblock %}

{% block extra_css %}
<style>
    .konto-layout {
        display: grid;
        grid-template-columns: 240px 1fr;
        gap: var(--spacing-xl);
        max-width: 1000px;
        margin: 0 auto;
    }

    .konto-sidebar {
        background: var(--surface);
        border-radius: var(--radius-lg);
        padding: var(--spacing-lg);
        box-shadow: var(--shadow);
        height: fit-content;
        position: sticky;
        top: 100px;
    }

    .konto-sidebar-header {
        display: flex;
        align-items: center;
        gap: var(--spacing-md);
        padding-bottom: var(--spacing-md);
        margin-bottom: var(--spacing-md);
        border-bottom: 1px solid var(--border);
    }

    .konto-avatar {
        width: 48px;
        height: 48px;
        border-radius: 50%;
        background: linear-gradient(135deg, var(--primary), #1e40af);
        color: white;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 20px;
        font-weight: 600;
    }

    .konto-sidebar-name {
        font-weight: 600;
        color: var(--text-primary);
        font-size: var(--font-size-sm);
    }

    .konto-sidebar-email {
        font-size: 11px;
        color: var(--text-secondary);
        word-break: break-all;
    }

    .konto-nav {
        display: flex;
        flex-direction: column;
        gap: var(--spacing-xs);
    }

    .konto-nav a {
        display: flex;
        align-items: center;
        gap: var(--spacing-sm);
        padding: var(--spacing-sm) var(--spacing-md);
        border-radius: var(--radius);
        text-decoration: none;
        color: var(--text-secondary);
        font-size: var(--font-size-sm);
        transition: all 0.2s;
    }

    .konto-nav a:hover {
        background: var(--background);
        color: var(--text-primary);
    }

    .konto-nav a.active {
        background: var(--primary);
        color: white;
    }

    .konto-nav a svg {
        width: 18px;
        height: 18px;
        flex-shrink: 0;
    }

    .konto-content {
        background: var(--surface);
        border-radius: var(--radius-lg);
        padding: var(--spacing-xl);
        box-shadow: var(--shadow);
    }

    .konto-header {
        margin-bottom: var(--spacing-xl);
        padding-bottom: var(--spacing-lg);
        border-bottom: 1px solid var(--border);
    }

    .konto-header h1 {
        font-size: var(--font-size-2xl);
        color: var(--text-primary);
        margin-bottom: var(--spacing-xs);
    }

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

    .security-card {
        background: var(--background);
        border-radius: var(--radius);
        padding: var(--spacing-lg);
        margin-bottom: var(--spacing-lg);
    }

    .security-card h2 {
        font-size: var(--font-size-lg);
        color: var(--text-primary);
        margin-bottom: var(--spacing-md);
        display: flex;
        align-items: center;
        gap: var(--spacing-sm);
    }

    .security-card p {
        color: var(--text-secondary);
        font-size: var(--font-size-sm);
        margin-bottom: var(--spacing-md);
    }

    .status-badge {
        display: inline-flex;
        align-items: center;
        gap: var(--spacing-xs);
        padding: 4px 12px;
        border-radius: var(--radius-full);
        font-size: var(--font-size-sm);
        font-weight: 500;
    }

    .status-enabled {
        background: #dcfce7;
        color: #166534;
    }

    .status-disabled {
        background: #fee2e2;
        color: #991b1b;
    }

    .security-actions {
        display: flex;
        gap: var(--spacing-md);
        margin-top: var(--spacing-md);
    }

    @media (max-width: 768px) {
        .konto-layout {
            grid-template-columns: 1fr;
        }

        .konto-sidebar {
            position: static;
        }

        .konto-nav {
            flex-direction: row;
            flex-wrap: wrap;
        }

        .security-actions {
            flex-direction: column;
        }
    }
</style>
{% endblock %}

{% block content %}
<div class="konto-layout">
    <aside class="konto-sidebar">
        <div class="konto-sidebar-header">
            <div class="konto-avatar">
                {{ (current_user.name or current_user.email)[0].upper() }}
            </div>
            <div>
                <div class="konto-sidebar-name">{{ current_user.name or 'Użytkownik' }}</div>
                <div class="konto-sidebar-email">{{ current_user.email }}</div>
            </div>
        </div>
        <nav class="konto-nav">
            <a href="{{ url_for('konto_dane') }}">
                <svg fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
                    <path d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"/>
                </svg>
                Twoje dane
            </a>
            <a href="{{ url_for('konto_prywatnosc') }}">
                <svg fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
                    <path d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"/>
                </svg>
                Prywatność
            </a>
            <a href="{{ url_for('konto_bezpieczenstwo') }}" class="active">
                <svg fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
                    <path d="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"/>
                </svg>
                Bezpieczeństwo
            </a>
            <a href="{{ url_for('konto_blokady') }}">
                <svg fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
                    <path d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636"/>
                </svg>
                Blokady
            </a>
        </nav>
    </aside>

    <main class="konto-content">
        <div class="konto-header">
            <h1>Bezpieczeństwo</h1>
            <p>Zarządzaj ustawieniami bezpieczeństwa Twojego konta</p>
        </div>

        <div class="security-card">
            <h2>
                <svg width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
                    <path d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"/>
                </svg>
                Weryfikacja dwuetapowa (2FA)
            </h2>
            <p>Dodatkowa warstwa zabezpieczeń. Po włączeniu, przy logowaniu będziesz musiał podać kod z aplikacji uwierzytelniającej.</p>

            {% if current_user.totp_enabled %}
            <span class="status-badge status-enabled">
                <svg width="14" height="14" fill="currentColor" viewBox="0 0 20 20">
                    <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd"/>
                </svg>
                Włączona
            </span>
            <div class="security-actions">
                <a href="{{ url_for('settings_2fa') }}" class="btn btn-outline">Zarządzaj 2FA</a>
            </div>
            {% else %}
            <span class="status-badge status-disabled">
                <svg width="14" height="14" fill="currentColor" viewBox="0 0 20 20">
                    <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z" clip-rule="evenodd"/>
                </svg>
                Wyłączona
            </span>
            <div class="security-actions">
                <a href="{{ url_for('settings_2fa') }}" class="btn btn-primary">Włącz 2FA</a>
            </div>
            {% endif %}
        </div>

        <div class="security-card">
            <h2>
                <svg width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
                    <path d="M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"/>
                </svg>
                Zmiana hasła
            </h2>
            <p>Regularnie zmieniaj hasło, aby zwiększyć bezpieczeństwo konta.</p>
            <div class="security-actions">
                <a href="{{ url_for('forgot_password') }}" class="btn btn-outline">Zmień hasło</a>
            </div>
        </div>

        <div class="security-card">
            <h2>
                <svg width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
                    <path d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/>
                </svg>
                Historia logowań
            </h2>
            <p>Ostatnie logowanie: {% if current_user.last_login %}{{ current_user.last_login.strftime('%d.%m.%Y %H:%M') }}{% else %}Brak danych{% endif %}</p>
            <p>Konto utworzone: {{ current_user.created_at.strftime('%d.%m.%Y') }}</p>
        </div>
    </main>
</div>
{% endblock %}
