<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    
    <!-- Google Analytics -->
    
        <script async src="https://www.googletagmanager.com/gtag/js?id=G-0G3QJ72DQL"></script>
        <script>
            window.dataLayer = window.dataLayer || [];
            function gtag(){dataLayer.push(arguments);}
            gtag('js', new Date());
            
            var gaId = "G-0G3QJ72DQL";
            gtag('config', gaId);
        </script>
    

    <title>Error - Chariot Of Colors</title>
    <link rel="icon" href="/images/favicon.png">
    <link rel="stylesheet" href="/css/style.css">
    <link rel="stylesheet" href="https://unpkg.com/aos@2.3.1/dist/aos.css" />
    <link rel="stylesheet" href="/css/animations.css">
    <link rel="stylesheet" href="/css/film-roll.css">
</head>

<body style="display: flex; flex-direction: column; min-height: 100vh;">

    <nav>
        <div class="logo">
            <a href="/" style="display: flex; align-items: center; gap: 15px;">
                <img src="/images/favicon.png" alt="Logo Icon" class="nav-logo-img">
                <img src="/images/logo-full.png" alt="Chariot Of Colors" class="logo-text-img">
            </a>
        </div>

        <button class="mobile-menu-toggle" aria-label="Toggle navigation">
            <span></span>
            <span></span>
            <span></span>
        </button>

        <ul class="nav-links">
            <li><a href="/#about">About</a></li>
            <li><a href="/#gallery">Gallery</a></li>
            <li><a href="/#categories">Services</a></li>
            <li><a href="/#reviews">Reviews</a></li>
            <li><a href="/#contact">Contact</a></li>
            <li><a href="/login">Admin</a></li>
            <!-- Mobile visible button only -->
            <li class="mobile-only-li"><a href="/order" class="btn" style="width: 100%; text-align: center;">Book
                    Order</a></li>
        </ul>
        <a href="/order" class="btn desktop-only-btn">Book an Order</a>

        <script>
            document.addEventListener('DOMContentLoaded', function () {
                const mobileMenuBtn = document.querySelector('.mobile-menu-toggle');
                const navLinks = document.querySelector('.nav-links');

                if (mobileMenuBtn) {
                    mobileMenuBtn.addEventListener('click', function () {
                        this.classList.toggle('active');
                        navLinks.classList.toggle('active');
                    });

                    // Close menu when a link is clicked
                    navLinks.querySelectorAll('a').forEach(link => {
                        link.addEventListener('click', () => {
                            mobileMenuBtn.classList.remove('active');
                            navLinks.classList.remove('active');
                        });
                    });
                }
            });
        </script>
    </nav>

    <div class="container" style="flex: 1; display: flex; align-items: center; justify-content: center; padding: 2rem;">
        <div class="glass-panel" style="text-align: center; max-width: 600px; width: 100%; padding: 3rem;">
            <div style="font-size: 5rem; margin-bottom: 1rem;">🎨</div>
            <h1 style="color: white; margin-bottom: 1rem; font-size: 2.5rem;">The colors got mixed up!</h1>
            <p style="font-size: 1.2rem; color: var(--text-secondary); margin-bottom: 2rem; line-height: 1.6;">
                Something went wrong while painting the digital canvas. <br>
                Please try again later or head back to our gallery.
            </p>
            <a href="/" class="btn">Back to Home</a>
        </div>
    </div>

    <div>
        <div class="chat-widget-btn" id="chatBtn">
            <div class="chat-bubble">Hi, I'm Violet! 👋</div>
            <img src="/images/violet.png" alt="Violet" class="chat-avatar">
        </div>

        <div class="chat-window" id="chatWindow">
            <div class="chat-header">
                <div style="display: flex; align-items: center; gap: 10px;">
                    <img src="/images/violet.png"
                        style="width: 30px; height: 30px; border-radius: 50%; border: 2px solid white;">
                    <h3>Violet</h3>
                </div>
                <div class="chat-controls">
                    <button class="maximize-chat" id="maximizeChat">
                        <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none"
                            stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                            <path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7" />
                        </svg>
                    </button>
                    <button class="close-chat" id="closeChat">&times;</button>
                </div>
            </div>
            <div class="chat-messages" id="chatMessages">
                <div class="message bot">
                    Hello! I'm Violet. How can I help you today?
                </div>
            </div>
            <div class="chat-input-area">
                <input type="text" id="chatInput" placeholder="Type a message...">
                <button id="sendBtn">Send</button>
            </div>
        </div>

        <script>
            // Ensure elements exist before adding listeners to prevent errors on pages where fragment might be misused
            document.addEventListener('DOMContentLoaded', () => {
                const chatBtn = document.getElementById('chatBtn');
                const chatWindow = document.getElementById('chatWindow');
                const closeChat = document.getElementById('closeChat');
                const maximizeChat = document.getElementById('maximizeChat');
                const sendBtn = document.getElementById('sendBtn');
                const chatInput = document.getElementById('chatInput');
                const chatMessages = document.getElementById('chatMessages');

                if (!chatBtn || !chatWindow) return;

                function toggleChat() {
                    chatWindow.classList.toggle('active');
                }

                function toggleMaximize() {
                    chatWindow.classList.toggle('maximized');
                    const isMax = chatWindow.classList.contains('maximized');
                    maximizeChat.innerHTML = isMax
                        ? '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 1 2-2h3M3 16h3a2 2 0 0 1 2 2v3"/></svg>'
                        : '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/></svg>';
                }

                chatBtn.addEventListener('click', toggleChat);
                closeChat.addEventListener('click', toggleChat);
                maximizeChat.addEventListener('click', toggleMaximize);

                function appendMessage(text, sender) {
                    const msgDiv = document.createElement('div');
                    msgDiv.classList.add('message', sender);
                    msgDiv.textContent = text;
                    chatMessages.appendChild(msgDiv);
                    chatMessages.scrollTop = chatMessages.scrollHeight;
                }

                async function sendMessage() {
                    const text = chatInput.value.trim();
                    if (!text) return;

                    appendMessage(text, 'user');
                    chatInput.value = '';

                    const loadingDiv = document.createElement('div');
                    loadingDiv.classList.add('message', 'bot');
                    loadingDiv.textContent = '...';
                    loadingDiv.id = 'loadingMsg';
                    chatMessages.appendChild(loadingDiv);
                    chatMessages.scrollTop = chatMessages.scrollHeight;

                    try {
                        const response = await fetch('/api/chat', {
                            method: 'POST',
                            headers: { 'Content-Type': 'application/json' },
                            body: JSON.stringify({ message: text })
                        });

                        const loadingMsg = document.getElementById('loadingMsg');
                        if (loadingMsg) loadingMsg.remove();

                        if (!response.ok) {
                            const errorText = await response.text();
                            appendMessage("I am not feeling well, please try again later.", 'bot');
                            return;
                        }

                        const data = await response.json();

                        if (data.reply) {
                            appendMessage(data.reply, 'bot');
                        } else {
                            appendMessage("Sorry, received empty response.", 'bot');
                        }
                    } catch (error) {
                        console.error(error);
                        const loadingMsg = document.getElementById('loadingMsg');
                        if (loadingMsg) loadingMsg.remove();
                        appendMessage("I am not feeling well, please try again later.", 'bot');
                    }
                }

                sendBtn.addEventListener('click', sendMessage);
                chatInput.addEventListener('keypress', (e) => {
                    if (e.key === 'Enter') sendMessage();
                });
            });
        </script>
    </div>

</body>

</html>