<!DOCTYPE html>
<html lang="pl">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Norda Biznes Hub - katalog firm członkowskich stowarzyszenia Norda Biznes">
    <meta name="author" content="Norda Biznes">
    <meta name="robots" content="index, follow">

    <title>{% block title %}Norda Biznes Hub{% endblock %}</title>

    <!-- Favicon -->
    <link rel="icon" type="image/x-icon" href="{{ url_for('static', filename='img/favicon.ico') }}">

    <!-- Fonts -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">

    <!-- Styles -->
    <style>
        /* ============================================================
         * RESET & BASE STYLES
         * ============================================================ */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        :root {
            /* Colors - Professional blue palette */
            --primary: #2563eb;
            --primary-dark: #1e40af;
            --primary-light: #3b82f6;
            --secondary: #64748b;
            --success: #10b981;
            --warning: #f59e0b;
            --error: #ef4444;
            --background: #f8fafc;
            --surface: #ffffff;
            --text-primary: #1e293b;
            --text-secondary: #64748b;
            --border: #e2e8f0;

            /* Spacing */
            --spacing-xs: 0.25rem;
            --spacing-sm: 0.5rem;
            --spacing-md: 1rem;
            --spacing-lg: 1.5rem;
            --spacing-xl: 2rem;
            --spacing-2xl: 3rem;

            /* Typography */
            --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
            --font-size-sm: 0.875rem;
            --font-size-base: 1rem;
            --font-size-lg: 1.125rem;
            --font-size-xl: 1.25rem;
            --font-size-2xl: 1.5rem;
            --font-size-3xl: 1.875rem;

            /* Shadows */
            --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
            --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
            --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
            --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

            /* Border radius */
            --radius-sm: 0.25rem;
            --radius: 0.5rem;
            --radius-lg: 0.75rem;
            --radius-xl: 1rem;

            /* Transitions */
            --transition: all 0.2s ease-in-out;
        }

        body {
            font-family: var(--font-family);
            font-size: var(--font-size-base);
            line-height: 1.6;
            color: var(--text-primary);
            background-color: var(--background);
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        /* ============================================================
         * LAYOUT
         * ============================================================ */
        .container {
            width: 100%;
            max-width: 1280px;
            margin: 0 auto;
            padding: 0 var(--spacing-md);
        }

        .container-narrow {
            max-width: 768px;
        }

        main {
            flex: 1;
            padding: var(--spacing-xl) 0;
        }

        /* ============================================================
         * HEADER & NAVIGATION
         * ============================================================ */
        header {
            background-color: var(--surface);
            border-bottom: 1px solid var(--border);
            box-shadow: var(--shadow-sm);
            position: sticky;
            top: 0;
            z-index: 100;
        }

        nav {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: var(--spacing-md) 0;
        }

        .nav-brand {
            font-size: var(--font-size-xl);
            font-weight: 700;
            color: var(--primary);
            text-decoration: none;
            display: flex;
            align-items: center;
            gap: var(--spacing-sm);
        }

        .nav-brand:hover {
            color: var(--primary-dark);
        }

        .nav-menu {
            display: flex;
            gap: var(--spacing-lg);
            align-items: center;
            list-style: none;
        }

        .nav-link {
            color: var(--text-secondary);
            text-decoration: none;
            font-weight: 500;
            transition: var(--transition);
            padding: var(--spacing-sm) var(--spacing-md);
            border-radius: var(--radius);
        }

        .nav-link:hover {
            color: var(--primary);
            background-color: var(--background);
        }

        .nav-link.active {
            color: var(--primary);
        }

        /* Navigation badge (unread messages) */
        .nav-link-with-badge {
            position: relative;
        }

        .nav-badge {
            position: absolute;
            top: -4px;
            right: -8px;
            background: var(--error);
            color: white;
            font-size: 11px;
            font-weight: 600;
            min-width: 18px;
            height: 18px;
            border-radius: 9px;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 0 5px;
        }

        /* Admin dropdown menu */
        .nav-dropdown {
            position: relative;
        }

        .nav-dropdown-menu {
            display: none;
            position: absolute;
            top: 100%;
            right: 0;
            background: var(--surface);
            border: 1px solid var(--border);
            border-radius: var(--radius);
            box-shadow: var(--shadow-lg);
            min-width: 180px;
            padding: var(--spacing-xs) 0;
            z-index: 200;
            list-style: none;
        }

        .nav-dropdown:hover .nav-dropdown-menu {
            display: block;
        }

        .nav-dropdown-menu li a {
            display: block;
            padding: var(--spacing-sm) var(--spacing-md);
            color: var(--text-primary);
            text-decoration: none;
            transition: var(--transition);
        }

        .nav-dropdown-menu li a:hover {
            background: var(--background);
            color: var(--primary);
        }

        /* Mobile menu toggle */
        .nav-toggle {
            display: none;
            background: none;
            border: none;
            cursor: pointer;
            padding: var(--spacing-sm);
        }

        @media (max-width: 768px) {
            .nav-toggle {
                display: block;
            }

            .nav-menu {
                display: none;
                position: absolute;
                top: 100%;
                left: 0;
                right: 0;
                background-color: var(--surface);
                flex-direction: column;
                padding: var(--spacing-md);
                border-top: 1px solid var(--border);
                box-shadow: var(--shadow-md);
            }

            .nav-menu.active {
                display: flex;
            }
        }

        /* ============================================================
         * BUTTONS
         * ============================================================ */
        .btn {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: var(--spacing-sm);
            padding: var(--spacing-sm) var(--spacing-lg);
            font-size: var(--font-size-base);
            font-weight: 500;
            text-decoration: none;
            border-radius: var(--radius);
            border: none;
            cursor: pointer;
            transition: var(--transition);
            white-space: nowrap;
        }

        .btn-primary {
            background-color: var(--primary);
            color: white;
        }

        .btn-primary:hover {
            background-color: var(--primary-dark);
        }

        .btn-secondary {
            background-color: var(--secondary);
            color: white;
        }

        .btn-secondary:hover {
            background-color: #475569;
        }

        .btn-outline {
            background-color: transparent;
            color: var(--primary);
            border: 2px solid var(--primary);
        }

        .btn-outline:hover {
            background-color: var(--primary);
            color: white;
        }

        .btn-sm {
            padding: var(--spacing-xs) var(--spacing-md);
            font-size: var(--font-size-sm);
        }

        .btn-lg {
            padding: var(--spacing-md) var(--spacing-xl);
            font-size: var(--font-size-lg);
        }

        /* ============================================================
         * FLASH MESSAGES
         * ============================================================ */
        .flash-messages {
            position: fixed;
            top: var(--spacing-xl);
            right: var(--spacing-xl);
            z-index: 1000;
            max-width: 400px;
        }

        .flash {
            padding: var(--spacing-md);
            margin-bottom: var(--spacing-md);
            border-radius: var(--radius);
            box-shadow: var(--shadow-lg);
            display: flex;
            align-items: start;
            gap: var(--spacing-md);
            animation: slideIn 0.3s ease-out;
        }

        @keyframes slideIn {
            from {
                transform: translateX(100%);
                opacity: 0;
            }
            to {
                transform: translateX(0);
                opacity: 1;
            }
        }

        .flash-success {
            background-color: var(--success);
            color: white;
        }

        .flash-error {
            background-color: var(--error);
            color: white;
        }

        .flash-warning {
            background-color: var(--warning);
            color: white;
        }

        .flash-info {
            background-color: var(--primary);
            color: white;
        }

        .flash-close {
            background: none;
            border: none;
            color: inherit;
            font-size: var(--font-size-xl);
            cursor: pointer;
            margin-left: auto;
            opacity: 0.8;
        }

        .flash-close:hover {
            opacity: 1;
        }

        /* ============================================================
         * DEVELOPMENT NOTICE BANNER
         * ============================================================ */
        .dev-notice {
            background: linear-gradient(135deg, #fef3c7, #fde68a);
            border-bottom: 2px solid #f59e0b;
            padding: var(--spacing-sm) var(--spacing-md);
            text-align: center;
            font-size: var(--font-size-sm);
            color: #92400e;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: var(--spacing-sm);
        }

        .dev-notice-icon {
            font-size: 1.2em;
        }

        .dev-notice-text {
            font-weight: 500;
        }

        .dev-notice-close {
            background: none;
            border: none;
            color: #92400e;
            font-size: 1.2em;
            cursor: pointer;
            padding: 0 var(--spacing-sm);
            opacity: 0.6;
            transition: var(--transition);
            margin-left: var(--spacing-md);
        }

        .dev-notice-close:hover {
            opacity: 1;
        }

        /* ============================================================
         * FOOTER
         * ============================================================ */
        footer {
            background-color: var(--text-primary);
            color: white;
            padding: var(--spacing-xl) 0;
            margin-top: auto;
        }

        .footer-content {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: var(--spacing-xl);
        }

        .footer-section h3 {
            margin-bottom: var(--spacing-md);
            font-size: var(--font-size-lg);
        }

        .footer-section p,
        .footer-section a {
            color: #94a3b8;
            text-decoration: none;
            display: block;
            margin-bottom: var(--spacing-sm);
        }

        .footer-section a:hover {
            color: white;
        }

        .footer-bottom {
            border-top: 1px solid #334155;
            margin-top: var(--spacing-xl);
            padding-top: var(--spacing-md);
            text-align: center;
            color: #94a3b8;
            font-size: var(--font-size-sm);
        }

        /* ============================================================
         * UTILITIES
         * ============================================================ */
        .text-center { text-align: center; }
        .text-muted { color: var(--text-secondary); }
        .mt-1 { margin-top: var(--spacing-md); }
        .mt-2 { margin-top: var(--spacing-lg); }
        .mt-3 { margin-top: var(--spacing-xl); }
        .mb-1 { margin-bottom: var(--spacing-md); }
        .mb-2 { margin-bottom: var(--spacing-lg); }
        .mb-3 { margin-bottom: var(--spacing-xl); }

        {% block extra_css %}{% endblock %}
    </style>
</head>
<body>
    <!-- Header -->
    <header>
        <div class="container">
            <nav role="navigation" aria-label="Main navigation">
                <a href="{{ url_for('index') }}" class="nav-brand" aria-label="Norda Biznes Home">
                    <svg width="32" height="32" viewBox="0 0 32 32" fill="currentColor">
                        <path d="M16 2L2 9v14l14 7 14-7V9L16 2zm0 3.5L25.5 10 16 14.5 6.5 10 16 5.5zm-11 6.8l10 5v9.4l-10-5v-9.4zm12 14.4v-9.4l10-5v9.4l-10 5z"/>
                    </svg>
                    <span>Norda Biznes Hub</span>
                </a>

                <button class="nav-toggle" aria-label="Toggle navigation" onclick="toggleMobileMenu()">
                    <svg width="24" height="24" fill="none" stroke="currentColor" stroke-width="2">
                        <path d="M3 12h18M3 6h18M3 18h18"/>
                    </svg>
                </button>

                <ul class="nav-menu" id="navMenu">
                    <li><a href="{{ url_for('index') }}" class="nav-link {% if request.endpoint == 'index' %}active{% endif %}">Firmy</a></li>
                    <li><a href="{{ url_for('search') }}" class="nav-link {% if request.endpoint == 'search' %}active{% endif %}">Szukaj</a></li>
                    {% if current_user.is_authenticated %}
                        <li><a href="{{ url_for('events') }}" class="nav-link {% if request.endpoint == 'events' %}active{% endif %}">Aktualnosci</a></li>
                        <li><a href="{{ url_for('calendar_index') }}" class="nav-link {% if request.endpoint and 'calendar' in request.endpoint %}active{% endif %}">Kalendarz</a></li>
                        <li><a href="{{ url_for('forum_index') }}" class="nav-link {% if request.endpoint and 'forum' in request.endpoint %}active{% endif %}">Forum</a></li>
                        <li><a href="{{ url_for('classifieds_index') }}" class="nav-link {% if request.endpoint and 'classifieds' in request.endpoint %}active{% endif %}">Tablica B2B</a></li>
                        <li>
                            <a href="{{ url_for('messages_inbox') }}" class="nav-link nav-link-with-badge {% if request.endpoint and 'messages' in request.endpoint %}active{% endif %}">
                                Wiadomosci
                                <span class="nav-badge" id="unreadBadge" style="display: none;">0</span>
                            </a>
                        </li>
                        <li><a href="{{ url_for('chat') }}" class="nav-link {% if request.endpoint == 'chat' %}active{% endif %}">Chat AI</a></li>
                        <li><a href="{{ url_for('dashboard') }}" class="nav-link {% if request.endpoint == 'dashboard' %}active{% endif %}">Panel</a></li>
                        {% if current_user.is_admin %}
                        <li class="nav-dropdown">
                            <a href="#" class="nav-link {% if request.endpoint and 'admin' in request.endpoint %}active{% endif %}">Admin ▾</a>
                            <ul class="nav-dropdown-menu">
                                <li><a href="{{ url_for('admin_calendar') }}">Kalendarz</a></li>
                                <li><a href="{{ url_for('admin_social_media') }}">Social Media</a></li>
                                <li><a href="{{ url_for('chat_analytics') }}">Analityka Chatu</a></li>
                                <li><a href="{{ url_for('debug_panel') }}">Debug Panel</a></li>
                            </ul>
                        </li>
                        {% endif %}
                        <li><a href="{{ url_for('logout') }}" class="nav-link">Wyloguj</a></li>
                    {% else %}
                        <li><a href="{{ url_for('login') }}" class="btn btn-outline btn-sm">Zaloguj</a></li>
                        <li><a href="{{ url_for('register') }}" class="btn btn-primary btn-sm">Rejestracja</a></li>
                    {% endif %}
                </ul>
            </nav>
        </div>
    </header>

    <!-- Development Notice Banner -->
    <div class="dev-notice" id="devNotice">
        <span class="dev-notice-icon">🚧</span>
        <span class="dev-notice-text">
            Serwis w fazie rozwoju. Oficjalne uruchomienie po akceptacji Zarządu Norda Biznes.
        </span>
        <button class="dev-notice-close" onclick="dismissDevNotice()" aria-label="Zamknij">&times;</button>
    </div>

    <!-- Flash Messages -->
    {% with messages = get_flashed_messages(with_categories=true) %}
        {% if messages %}
            <div class="flash-messages" role="alert" aria-live="polite">
                {% for category, message in messages %}
                    <div class="flash flash-{{ category }}">
                        <span>{{ message }}</span>
                        <button class="flash-close" onclick="this.parentElement.remove()" aria-label="Close">&times;</button>
                    </div>
                {% endfor %}
            </div>
        {% endif %}
    {% endwith %}

    <!-- Main Content -->
    <main role="main">
        <div class="container {% block container_class %}{% endblock %}">
            {% block content %}{% endblock %}
        </div>
    </main>

    <!-- Footer -->
    <footer>
        <div class="container">
            <div class="footer-content">
                <div class="footer-section">
                    <h3>Norda Biznes Hub</h3>
                    <p>Katalog firm członkowskich stowarzyszenia Norda Biznes - networking i współpraca biznesowa.</p>
                </div>
                <div class="footer-section">
                    <h3>Linki</h3>
                    <a href="{{ url_for('index') }}">Katalog firm</a>
                    <a href="{{ url_for('search') }}">Wyszukiwarka</a>
                    {% if current_user.is_authenticated %}
                        <a href="{{ url_for('calendar_index') }}">Kalendarz</a>
                        <a href="{{ url_for('classifieds_index') }}">Tablica B2B</a>
                        <a href="{{ url_for('new_members') }}">Nowi czlonkowie</a>
                        <a href="{{ url_for('chat') }}">Chat AI</a>
                    {% endif %}
                </div>
                <div class="footer-section">
                    <h3>Kontakt</h3>
                    <p>Email: biuro@inpi.pl</p>
                    <p>Telefon: +48 785 337 754</p>
                    <p>Adres: ul. Tomasza Rogali 11, 84-200 Wejherowo</p>
                </div>
            </div>
            <div class="footer-bottom">
                <p>&copy; {{ current_year }} Norda Biznes. Wszelkie prawa zastrzeżone.</p>
            </div>
        </div>
    </footer>

    <!-- Scripts -->
    <script>
        // Mobile menu toggle
        function toggleMobileMenu() {
            document.getElementById('navMenu').classList.toggle('active');
        }

        // Auto-dismiss flash messages after 5 seconds
        document.addEventListener('DOMContentLoaded', function() {
            const flashes = document.querySelectorAll('.flash');
            flashes.forEach(flash => {
                setTimeout(() => {
                    flash.style.animation = 'slideOut 0.3s ease-out';
                    setTimeout(() => flash.remove(), 300);
                }, 5000);
            });
        });

        // Close mobile menu when clicking outside
        document.addEventListener('click', function(event) {
            const navMenu = document.getElementById('navMenu');
            const navToggle = document.querySelector('.nav-toggle');

            if (!navMenu.contains(event.target) && !navToggle.contains(event.target)) {
                navMenu.classList.remove('active');
            }
        });

        // Development notice banner
        function dismissDevNotice() {
            const notice = document.getElementById('devNotice');
            if (notice) {
                notice.style.display = 'none';
                // Remember dismissal for this session
                sessionStorage.setItem('devNoticeDismissed', 'true');
            }
        }

        // Check if notice was dismissed in this session
        document.addEventListener('DOMContentLoaded', function() {
            if (sessionStorage.getItem('devNoticeDismissed') === 'true') {
                const notice = document.getElementById('devNotice');
                if (notice) notice.style.display = 'none';
            }
        });

        // Fetch unread message count (for authenticated users)
        {% if current_user.is_authenticated %}
        async function updateUnreadBadge() {
            try {
                const response = await fetch('{{ url_for("api_unread_count") }}');
                const data = await response.json();
                const badge = document.getElementById('unreadBadge');
                if (badge && data.count > 0) {
                    badge.textContent = data.count > 99 ? '99+' : data.count;
                    badge.style.display = 'flex';
                } else if (badge) {
                    badge.style.display = 'none';
                }
            } catch (error) {
                console.log('Could not fetch unread count');
            }
        }
        // Check unread on page load and every 60 seconds
        document.addEventListener('DOMContentLoaded', updateUnreadBadge);
        setInterval(updateUnreadBadge, 60000);
        {% endif %}

        {% block extra_js %}{% endblock %}
    </script>
</body>
</html>
