{% load static %}
<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=yes">
    <title>{% block title %}Billetterie Événementielle{% endblock %}</title>

    {# Google Fonts - Inter & Poppins pour un look moderne #}
    <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:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=Poppins:wght@400;500;600;700&display=swap" rel="stylesheet">

    <style>
        /* ============================================
           THÈME FESTIF & CHALEUREUX - BASE.HTML
           Palette : Orange Sunset, Ambre, Blanc cassé, Anthracite
           ============================================ */
        :root {
            --sunset-start: #FF8C42;    /* Orange Sunset */
            --sunset-end: #FF6B35;      /* Corail profond */
            --amber: #F2AF29;
            --warm-anthracite: #333533;
            --off-white: #FDFBF7;
            --success-emerald: #2E8B57;
            --danger-red: #D9534F;
            --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.06);
            --shadow-md: 0 8px 20px rgba(255, 140, 66, 0.12);
            --border-radius-btn: 50px;
            --border-radius-card: 20px;
            --font-main: 'Inter', sans-serif;
            --font-headings: 'Poppins', sans-serif;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: var(--font-main);
            background-color: var(--off-white);
            color: var(--warm-anthracite);
            line-height: 1.5;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        /* ===== NAVBAR (Mobile-First) ===== */
        .navbar {
            background: linear-gradient(135deg, var(--sunset-start) 0%, var(--sunset-end) 100%);
            padding: 0.8rem 1.2rem;
            box-shadow: var(--shadow-sm);
            position: sticky;
            top: 0;
            z-index: 1000;
            display: flex;
            align-items: center;
            justify-content: space-between;
            flex-wrap: wrap;
        }

        .navbar-brand {
            font-family: var(--font-headings);
            font-weight: 700;
            font-size: 1.5rem;
            color: white;
            text-decoration: none;
            display: flex;
            align-items: center;
            gap: 8px;
            text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
        }

        .navbar-brand i {
            font-size: 1.8rem;
        }

        /* Menu Desktop (caché sur mobile par défaut) */
        .navbar-menu {
            display: none;
            align-items: center;
            gap: 1.8rem;
        }

        .navbar-menu a {
            color: white;
            text-decoration: none;
            font-weight: 500;
            transition: opacity 0.2s;
            font-size: 1rem;
        }

        .navbar-menu a:hover {
            opacity: 0.8;
        }

        .navbar-end {
            display: flex;
            align-items: center;
            gap: 1rem;
        }

        .btn-nav {
            background: rgba(255,255,255,0.15);
            backdrop-filter: blur(4px);
            border: 1px solid rgba(255,255,255,0.3);
            color: white;
            padding: 0.5rem 1.2rem;
            border-radius: var(--border-radius-btn);
            font-weight: 500;
            text-decoration: none;
            transition: all 0.2s;
            font-size: 0.9rem;
        }

        .btn-nav:hover {
            background: white;
            color: var(--sunset-start);
            transform: translateY(-2px);
        }

        .btn-nav-primary {
            background: var(--amber);
            color: var(--warm-anthracite);
            border: none;
            font-weight: 600;
        }

        .btn-nav-primary:hover {
            background: #e09e1c;
            color: var(--warm-anthracite);
        }

        /* Menu Hamburger (mobile) */
        .hamburger {
            display: block;
            cursor: pointer;
            background: none;
            border: none;
            padding: 10px;
        }

        .hamburger span {
            display: block;
            width: 26px;
            height: 3px;
            background-color: white;
            margin: 5px 0;
            border-radius: 10px;
            transition: all 0.3s ease;
        }

        /* Menu Mobile (overlay) */
        .mobile-menu {
            position: fixed;
            top: 0;
            right: -100%;
            width: 80%;
            max-width: 320px;
            height: 100vh;
            background: white;
            box-shadow: -5px 0 20px rgba(0,0,0,0.1);
            transition: right 0.3s ease;
            z-index: 2000;
            padding: 2rem 1.5rem;
            display: flex;
            flex-direction: column;
        }

        .mobile-menu.active {
            right: 0;
        }

        .mobile-menu-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 2rem;
        }

        .mobile-menu-header h3 {
            color: var(--sunset-start);
            font-family: var(--font-headings);
        }

        .close-menu {
            background: none;
            border: none;
            font-size: 2rem;
            cursor: pointer;
            color: var(--warm-anthracite);
        }

        .mobile-menu a {
            display: block;
            padding: 1rem 0;
            color: var(--warm-anthracite);
            text-decoration: none;
            font-weight: 500;
            border-bottom: 1px solid #eee;
            transition: padding-left 0.2s;
        }

        .mobile-menu a:hover {
            padding-left: 10px;
            color: var(--sunset-start);
        }

        .mobile-menu .btn-nav {
            margin-top: 1rem;
            text-align: center;
            background: var(--sunset-start);
            color: white;
            display: inline-block;
            width: 100%;
        }

        .overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.4);
            z-index: 1500;
            opacity: 0;
            visibility: hidden;
            transition: opacity 0.3s;
        }

        .overlay.active {
            opacity: 1;
            visibility: visible;
        }

        /* ===== CONTENU PRINCIPAL ===== */
        .main-content {
            flex: 1;
            padding: 1.5rem 1rem;
            max-width: 1200px;
            margin: 0 auto;
            width: 100%;
        }

        /* ===== MESSAGES FLASH (TOASTS) ===== */
        .messages-container {
            position: fixed;
            top: 20px;
            right: 20px;
            z-index: 3000;
            display: flex;
            flex-direction: column;
            gap: 10px;
            max-width: 350px;
            width: calc(100% - 40px);
        }

        .toast {
            padding: 1rem 1.2rem;
            border-radius: 50px;
            color: white;
            font-weight: 500;
            box-shadow: var(--shadow-md);
            animation: slideIn 0.3s ease;
            display: flex;
            align-items: center;
            gap: 10px;
            backdrop-filter: blur(4px);
        }

        .toast.success {
            background: var(--success-emerald);
        }

        .toast.error {
            background: var(--danger-red);
        }

        .toast.warning {
            background: var(--amber);
            color: var(--warm-anthracite);
        }

        .toast.info {
            background: var(--sunset-start);
        }

        .toast .close-toast {
            margin-left: auto;
            background: none;
            border: none;
            color: inherit;
            font-size: 1.2rem;
            cursor: pointer;
            opacity: 0.8;
        }

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

        /* ===== FOOTER ===== */
        .footer {
            background: var(--warm-anthracite);
            color: rgba(255,255,255,0.8);
            padding: 2rem 1.5rem;
            margin-top: 2rem;
            text-align: center;
        }

        .footer-content {
            max-width: 1200px;
            margin: 0 auto;
            display: flex;
            flex-direction: column;
            gap: 1rem;
        }

        .footer-links {
            display: flex;
            justify-content: center;
            gap: 2rem;
            flex-wrap: wrap;
        }

        .footer-links a {
            color: var(--amber);
            text-decoration: none;
            transition: color 0.2s;
        }

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

        .footer-copyright {
            font-size: 0.9rem;
            opacity: 0.7;
        }

        /* ===== UTILITAIRES ===== */
        .container {
            width: 100%;
            padding-right: 15px;
            padding-left: 15px;
            margin-right: auto;
            margin-left: auto;
        }

        /* Adaptation tablette et desktop */
        @media (min-width: 768px) {
            .navbar-menu {
                display: flex;
            }
            .hamburger {
                display: none;
            }
            .navbar {
                padding: 0.8rem 2rem;
            }
            .main-content {
                padding: 2rem;
            }
        }

        /* Pour les très grands écrans */
        @media (min-width: 1200px) {
            .container {
                max-width: 1140px;
            }
        }

        /* Icônes de démonstration (simulées avec du CSS simple) */
        .icon-ticket::before {
            content: "🎫";
            margin-right: 4px;
        }
        .icon-scan::before {
            content: "📷";
            margin-right: 4px;
        }
        .icon-dashboard::before {
            content: "📊";
            margin-right: 4px;
        }
        .icon-logout::before {
            content: "🚪";
            margin-right: 4px;
        }
        .icon-login::before {
            content: "🔐";
            margin-right: 4px;
        }
    </style>
    {% block extrahead %}{% endblock %}
</head>
<body>
    {# Overlay pour mobile menu #}
    <div class="overlay" id="overlay"></div>

    {# Menu mobile (caché par défaut) #}
    <div class="mobile-menu" id="mobileMenu">
        <div class="mobile-menu-header">
            <h3>Menu</h3>
            <button class="close-menu" id="closeMenuBtn">&times;</button>
        </div>
        <nav>
            {% if user_context.is_authenticated %}
                {# Liens pour utilisateurs connectés #}
                <a href="{% url 'vitrine:home' %}">🏠 Accueil</a>
                
                {% if user_context.is_admin %}
                    <a href="{% url 'dashboard:home' %}">📊 Dashboard</a>
                    <a href="{% url 'scanner:welcome' %}">📷 Scanner</a>
                {% elif user_context.can_scan %}
                    <a href="{% url 'scanner:welcome' %}">📷 Scanner</a>
                {% endif %}
                
                <a href="{% url 'accounts:logout' %}">🚪 Déconnexion</a>
                <div style="margin-top: 20px; padding-top: 10px; border-top: 1px solid #eee; color: var(--sunset-start);">
                    Bonjour, {{ user_context.user_full_name }}
                </div>
            {% else %}
                {# Liens pour visiteurs non connectés #}
                <a href="{% url 'vitrine:home' %}">🏠 Accueil</a>
                <a href="{% url 'accounts:login' %}" class="btn-nav" style="margin-top: 10px;">🔐 Connexion Personnel</a>
            {% endif %}
        </nav>
    </div>

    {# Barre de navigation principale #}
    <nav class="navbar">
        <a href="{% url 'vitrine:home' %}" class="navbar-brand">
            <span>🎉</span> BilletFest
        </a>

        {# Menu Desktop (visible seulement sur tablette/desktop) #}
        <div class="navbar-menu">
            <a href="{% url 'vitrine:home' %}">Accueil</a>
            
            {% if user_context.is_authenticated %}
                {% if user_context.is_admin %}
                    <a href="{% url 'dashboard:home' %}">Dashboard</a>
                    <a href="{% url 'scanner:welcome' %}">Scanner</a>
                {% elif user_context.can_scan %}
                    <a href="{% url 'scanner:welcome' %}">Scanner</a>
                {% endif %}
            {% endif %}
        </div>

        <div class="navbar-end">
            {% if user_context.is_authenticated %}
                <span style="color: white; margin-right: 8px; font-weight: 500;">
                    👤 {{ user_context.user_full_name|truncatechars:15 }}
                </span>
                <a href="{% url 'accounts:logout' %}" class="btn-nav">
                    Déconnexion
                </a>
            {% else %}
                <a href="{% url 'accounts:login' %}" class="btn-nav btn-nav-primary">
                    Connexion Personnel
                </a>
            {% endif %}
            
            {# Bouton hamburger visible seulement sur mobile #}
            <button class="hamburger" id="hamburgerBtn" aria-label="Menu">
                <span></span>
                <span></span>
                <span></span>
            </button>
        </div>
    </nav>

    {# Zone de contenu principale #}
    <main class="main-content">
        {% block content %}
        {# Le contenu spécifique à chaque page viendra ici #}
        {% endblock %}
    </main>

    {# Pied de page #}
    <footer class="footer">
        <div class="footer-content">
            <div class="footer-links">
                <a href="https://imagink.agency/">À propos</a>
                <a href="https://imagink.agency/contact/">Contact</a>
                
            </div>
            <div class="footer-copyright">
                © {% now "Y" %} BilletFest - Tous droits réservés. Une billetterie chaleureuse et festive.
            </div>
        </div>
    </footer>

    {# Conteneur pour les messages flash (toasts) #}
    {% if messages %}
        <div class="messages-container" id="toastContainer">
            {% for message in messages %}
                <div class="toast {{ message.tags }}">
                    <span>
                        {% if message.tags == 'success' %}✅{% elif message.tags == 'error' %}❌{% elif message.tags == 'warning' %}⚠️{% else %}ℹ️{% endif %}
                    </span>
                    <span>{{ message }}</span>
                    <button class="close-toast" onclick="this.parentElement.remove()">&times;</button>
                </div>
            {% endfor %}
        </div>
    {% endif %}

    {# JavaScript pour le menu mobile et les toasts #}
    <script>
        (function() {
            // Gestion du menu mobile
            const hamburger = document.getElementById('hamburgerBtn');
            const mobileMenu = document.getElementById('mobileMenu');
            const overlay = document.getElementById('overlay');
            const closeBtn = document.getElementById('closeMenuBtn');

            function openMenu() {
                mobileMenu.classList.add('active');
                overlay.classList.add('active');
                document.body.style.overflow = 'hidden';
            }

            function closeMenu() {
                mobileMenu.classList.remove('active');
                overlay.classList.remove('active');
                document.body.style.overflow = '';
            }

            if (hamburger) {
                hamburger.addEventListener('click', openMenu);
            }
            if (closeBtn) {
                closeBtn.addEventListener('click', closeMenu);
            }
            if (overlay) {
                overlay.addEventListener('click', closeMenu);
            }

            // Fermer le menu si la fenêtre est redimensionnée au-dessus du breakpoint mobile
            window.addEventListener('resize', function() {
                if (window.innerWidth >= 768) {
                    closeMenu();
                }
            });

            // Auto-suppression des toasts après 5 secondes
            const toasts = document.querySelectorAll('.toast');
            toasts.forEach(toast => {
                setTimeout(() => {
                    toast.style.opacity = '0';
                    toast.style.transform = 'translateX(100%)';
                    setTimeout(() => toast.remove(), 300);
                }, 5000);
            });

            // Ajout d'une icône de fermeture fonctionnelle sur les toasts existants
            document.querySelectorAll('.close-toast').forEach(btn => {
                btn.addEventListener('click', function(e) {
                    const toast = this.closest('.toast');
                    if (toast) {
                        toast.style.opacity = '0';
                        toast.style.transform = 'translateX(100%)';
                        setTimeout(() => toast.remove(), 300);
                    }
                });
            });
        })();
    </script>

    {% block extrascripts %}{% endblock %}
</body>
</html>