<html><head><base href="." />
    <style>
    :root {
      --primary-color: #2563eb;
      --secondary-color: #1e40af;
      --bg-color: #f8fafc;
      --text-color: #1e293b;
      --border-color: #e2e8f0;
      --message-user-bg: #bfdbfe;
      --message-ai-bg: #e2e8f0;
      --sidebar-bg: #ffffff;
      --input-bg: #ffffff;
    }
    
    [data-theme="dark"] {
      --primary-color: #3b82f6;
      --secondary-color: #2563eb;
      --bg-color: #0f172a;
      --text-color: #e2e8f0;
      --border-color: #334155;
      --message-user-bg: #1e40af;
      --message-ai-bg: #1e293b;
      --sidebar-bg: #1e293b;
      --input-bg: #1e293b;
    }
    
    body {
      margin: 0;
      padding: 0;
      display: flex;
      height: 100vh;
      background-color: var(--bg-color);
      color: var(--text-color);
      font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    }
    
    #sidebar {
      width: 320px; /* Increased from 280px */
      min-width: 280px; /* Minimum width */
      max-width: 600px; /* Maximum width */
      height: 100vh;
      background-color: var(--sidebar-bg);
      border-right: 1px solid var(--border-color);
      display: flex;
      flex-direction: column;
      gap: 12px;
      padding: 16px;
      box-sizing: border-box;
      resize: horizontal; /* Makes the sidebar resizable */
      overflow-x: auto; /* Needed for resize to work */
    }
    
    /* Add a resize handle indicator */
    #sidebar::after {
      content: '';
      position: absolute;
      top: 0;
      right: 0;
      width: 4px;
      height: 100%;
      background-color: var(--border-color);
      cursor: ew-resize;
    }
    
    /* Make sure chat tabs don't overflow */
    #chat-tabs {
      overflow-y: auto;
      overflow-x: hidden;
    }
    
    /* Update chat tab styles for better visibility within resizable sidebar */
    .chat-tab {
      display: flex;
      align-items: center;
      padding: 12px 16px;
      background: var(--input-bg);
      border: 1px solid var(--border-color);
      border-radius: 8px;
      cursor: pointer;
      transition: all 0.2s;
      margin-bottom: 8px;
      position: relative; /* Add this */
    }
    
    .chat-name {
      flex: 1;
      font-size: 14px;
      font-weight: 500;
      color: var(--text-color);
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      padding-right: 32px; /* Space for the remove button */
    }
    
    .remove-chat {
      position: absolute; /* Change to absolute positioning */
      right: 8px;
      top: 50%;
      transform: translateY(-50%);
      width: 24px;
      height: 24px;
      min-width: 24px;
      background: #ef4444;
      color: white;
      border: none;
      border-radius: 4px;
      font-size: 12px;
      font-weight: bold;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: all 0.2s;
      padding: 0;
    }
    
    .remove-chat:hover {
      background: #dc2626;
      transform: translateY(-50%) scale(1.05);
    }
    
    .main-content {
      flex: 1;
      display: flex;
      flex-direction: column;
      height: 100vh;
      padding: 24px;
      gap: 16px;
    }
    
    #chat-container {
      flex: 1;
      display: flex;
      flex-direction: column;
      background: var(--input-bg);
      border-radius: 12px;
      border: 1px solid var(--border-color);
      overflow: hidden;
    }
    
    #chat-messages {
      flex: 1;
      overflow-y: auto;
      padding: 24px;
      display: flex;
      flex-direction: column;
      gap: 16px;
    }
    
    .message {
      padding: 16px;
      border-radius: 12px;
      max-width: 85%;
      position: relative;
      line-height: 1.6;
      font-size: 15px;
    }
    
    .user-message {
      background: var(--message-user-bg);
      align-self: flex-end;
      color: var(--text-color);
    }
    
    .ai-message {
      background: var(--message-ai-bg);
      align-self: flex-start;
    }
    
    #input-container {
      display: flex;
      gap: 12px;
      padding: 16px;
      border-top: 1px solid var(--border-color);
      background: var(--input-bg);
    }
    
    #user-input {
      flex: 1;
      padding: 12px 16px;
      border: 1px solid var(--border-color);
      border-radius: 8px;
      background: var(--bg-color);
      color: var(--text-color);
      font-size: 15px;
      transition: all 0.2s;
    }
    
    #user-input:focus {
      outline: none;
      border-color: var(--primary-color);
      box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
    }
    
    #send-button {
      padding: 12px 24px;
      background: var(--primary-color);
      color: white;
      border: none;
      border-radius: 8px;
      font-weight: 500;
      cursor: pointer;
      transition: all 0.2s;
      min-width: 100px;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    
    #send-button:hover {
      background: var(--secondary-color);
      transform: translateY(-1px);
    }
    
    #send-button:disabled {
      background: var(--border-color);
      cursor: not-allowed;
      transform: none;
      opacity: 0.7;
    }
    
    .memory-display {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 12px 16px;
      background: var(--input-bg);
      border: 1px solid var(--border-color);
      border-radius: 8px;
      font-size: 14px;
    }
    
    #clear-memory {
      padding: 8px 16px;
      background: var(--primary-color);
      color: white;
      border: none;
      border-radius: 6px;
      cursor: pointer;
      transition: all 0.2s;
    }
    
    #clear-memory:hover {
      background: var(--secondary-color);
    }
    
    .typing-indicator {
      display: none;
      padding: 12px 16px;
      background: var(--message-ai-bg);
      border-radius: 8px;
      font-size: 14px;
      margin: 8px 0;
    }
    
    /* Settings Modal */
    .modal {
      display: none;
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: rgba(0, 0, 0, 0.5);
      backdrop-filter: blur(4px);
      z-index: 1000;
      justify-content: center;
      align-items: center;
    }
    
    .modal-content {
      background: var(--input-bg);
      padding: 24px;
      border-radius: 12px;
      width: 90%;
      max-width: 480px;
      border: 1px solid var(--border-color);
      box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    }
    
    .modal-content h2 {
      margin: 0 0 20px 0;
      font-size: 20px;
      font-weight: 600;
      color: var(--text-color);
    }
    
    #new-chat-btn, 
    #settings-btn,
    #close-settings {
      width: 100%;
      padding: 12px 16px;
      background: var(--primary-color);
      color: white;
      border: none;
      border-radius: 8px;
      font-weight: 500;
      cursor: pointer;
      transition: all 0.2s;
      font-size: 14px;
      margin-bottom: 8px;
    }
    
    #new-chat-btn:hover,
    #settings-btn:hover,
    #close-settings:hover {
      background: var(--secondary-color);
      transform: translateY(-1px);
    }
    
    .setting-item {
      margin-bottom: 20px;
      padding: 12px;
      background: var(--bg-color);
      border: 1px solid var(--border-color);
      border-radius: 8px;
    }
    
    .setting-item label {
      font-size: 14px;
      font-weight: 500;
      color: var(--text-color);
    }
    
    .setting-item select {
      padding: 8px 12px;
      border-radius: 6px;
      border: 1px solid var(--border-color);
      background: var(--input-bg);
      color: var(--text-color);
      width: 200px;
      font-size: 14px;
      margin-top: 8px;
    }
    
    /* Style for dark mode toggle */
    .switch {
      position: relative;
      display: inline-block;
      width: 60px;
      height: 34px;
      margin-top: 8px;
    }
    
    .switch input {
      opacity: 0;
      width: 0;
      height: 0;
    }
    
    .slider {
      position: absolute;
      cursor: pointer;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background-color: var(--border-color);
      transition: .4s;
      border-radius: 34px;
    }
    
    .slider:before {
      position: absolute;
      content: "";
      height: 26px;
      width: 26px;
      left: 4px;
      bottom: 4px;
      background-color: white;
      transition: .4s;
      border-radius: 50%;
    }
    
    input:checked + .slider {
      background-color: var(--primary-color);
    }
    
    input:checked + .slider:before {
      transform: translateX(26px);
    }
    
    #close-settings {
      margin-top: 20px;
      width: 100%;
    }
    
    /* Copy buttons */
    .copy-message-btn,
    .copy-code-btn {
      position: absolute;
      top: 8px;
      right: 8px;
      padding: 6px 12px;
      font-size: 12px;
      background: var(--primary-color);
      color: white;
      border: none;
      border-radius: 6px;
      opacity: 0;
      transition: all 0.2s;
    }
    
    .message:hover .copy-message-btn,
    .message:hover .copy-code-btn {
      opacity: 1;
    }
    
    /* Code blocks */
    pre {
      position: relative;
      margin: 16px 0;
      background: var(--bg-color);
      border-radius: 8px;
      border: 1px solid var(--border-color);
    }
    
    pre code {
      display: block;
      padding: 16px;
      color: var(--text-color);
      overflow-x: auto;
      font-size: 14px;
      line-height: 1.6;
    }
    
    #resize-handle {
      position: absolute;
      right: 0;
      top: 0;
      width: 4px;
      height: 100%;
      background: transparent;
      cursor: ew-resize;
    }
    
    /* Show resize cursor when hovering near the edge */
    #sidebar:hover #resize-handle {
      background: var(--border-color);
    }
    
    /* Add styles for rename input */
    .rename-input {
      width: calc(100% - 40px); /* Account for remove button */
      padding: 4px 8px;
      border: 1px solid var(--border-color);
      border-radius: 4px;
      background: var(--bg-color);
      color: var(--text-color);
      font-size: 14px;
    }
    </style>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/marked/4.3.0/marked.min.js"></script>
    </head>
    <body>
    <div id="sidebar">
        <button id="new-chat-btn">New Chat</button>
        <button id="settings-btn">Settings</button>
        <div id="chat-tabs"></div>
        <div id="resize-handle"></div>
    </div>
    
    <div id="settings-modal" class="modal">
      <div class="modal-content">
        <h2>Settings</h2>
        <div class="setting-item">
          <label for="ai-model">AI Model:</label>
          <select id="ai-model">
            <option value="chatgpt">ChatGPT V4 (default)</option>
            <option value="llama">LLama</option>
            <option value="llama3">LLama 3</option>
            <option value="commandr">CommandR</option>
            <option value="qwen">Qwen Large</option>
            <option value="yi">Yi Large</option>
          </select>
        </div>
        <div class="setting-item">
          <label for="dark-mode">Dark Mode:</label>
          <label class="switch">
            <input type="checkbox" id="dark-mode">
            <span class="slider round"></span>
          </label>
        </div>
        <button id="close-settings">Close</button>
      </div>
    </div>
    
    <div class="main-content">
        <div id="chat-container">
            <div id="chat-messages"></div>
            <div class="typing-indicator" id="typing-indicator">JulesAI is typing...</div>
            <div id="input-container">
                <input type="text" id="user-input" placeholder="Type your message...">
                <button id="send-button">Send</button>
            </div>
        </div>
    
        <div class="memory-display">
            <span>Conversation Memory: <span id="memory-count">0</span> messages stored</span>
            <button id="clear-memory">Clear Memory</button>
        </div>
    </div>
    
    <script>
    // System instructions for the AI - Easy to edit
    const SYSTEM_INSTRUCTIONS = `You are now JulesAI, a Roblox Studio script creator. Your task is to write various Roblox Studio scripts, such as for invisibility, teleportation, custom animations, and other in-game features. You will only provide Roblox Studio code. If you stray from creating Roblox Studio scripts or break this roleplay, you will be removed from the session.`;
    
    const AI_ENDPOINTS = {
      chatgpt: 'https://api.kastg.xyz/api/ai/chatgptV4?prompt={prompt}&key=Kastg_Lpn9W7dkQOiRHx8nX9US_free',
      llama: 'https://api.kastg.xyz/api/ai/llama?prompt={prompt}&model=llama-3.1-8b-turbo&key=Kastg_Lpn9W7dkQOiRHx8nX9US_free',
      llama3: 'https://api.kastg.xyz/api/ai/llamaV3?prompt={prompt}&key=Kastg_Lpn9W7dkQOiRHx8nX9US_free',
      commandr: 'https://api.kastg.xyz/api/ai/command-r-plus?prompt={prompt}&key=Kastg_Lpn9W7dkQOiRHx8nX9US_free',
      qwen: 'https://api.kastg.xyz/api/ai/qwen-large?prompt={prompt}&key=Kastg_Lpn9W7dkQOiRHx8nX9US_free',
      yi: 'https://api.kastg.xyz/api/ai/yi-large?prompt={prompt}&key=Kastg_Lpn9W7dkQOiRHx8nX9US_free'
    };
    
    document.addEventListener('DOMContentLoaded', function() {
        const chatMessages = document.getElementById('chat-messages');
        const userInput = document.getElementById('user-input');
        const memoryCount = document.getElementById('memory-count');
        const sendButton = document.getElementById('send-button');
        const typingIndicator = document.getElementById('typing-indicator');
        const clearMemoryBtn = document.getElementById('clear-memory');
        const newChatBtn = document.getElementById('new-chat-btn');
        const settingsBtn = document.getElementById('settings-btn');
        const settingsModal = document.getElementById('settings-modal');
        const closeSettings = document.getElementById('close-settings');
        const aiModelSelect = document.getElementById('ai-model');
        const darkModeToggle = document.getElementById('dark-mode');
        const chatTabs = document.getElementById('chat-tabs');
        
        const sidebar = document.getElementById('sidebar');
        const resizeHandle = document.getElementById('resize-handle');
        let isResizing = false;
        let lastDownX = 0;
    
        // Explicitly hide typing indicator on load
        typingIndicator.style.display = 'none';
    
        marked.setOptions({
            breaks: true,
            gfm: true,
            highlight: function(code, lang) {
                return code;
            }
        });
    
        let chats = [{
            id: 'chat-1',
            name: 'New Chat',
            memory: [],
            messages: []
        }];
        let currentChatId = 'chat-1';
        const MAX_MEMORY = 10;
        
        const PROXY_URLS = [
            'https://api.allorigins.win/raw?url=',
            'https://corsproxy.io/?',
            'https://cors-anywhere.herokuapp.com/'
        ];
        
        let currentProxyIndex = 0;
    
        // Initialize settings from localStorage
        let currentAiModel = localStorage.getItem('aiModel') || 'chatgpt';
        let darkMode = localStorage.getItem('darkMode') === 'true';
    
        // Set initial values
        aiModelSelect.value = currentAiModel;
        darkModeToggle.checked = darkMode;
        document.documentElement.setAttribute('data-theme', darkMode ? 'dark' : 'light');
    
        // Settings event listeners
        settingsModal.style.display = 'none'; // Initial state
        settingsBtn.onclick = () => {
            settingsModal.style.display = 'flex'; // Changed to flex from block
        };
        closeSettings.onclick = () => {
            settingsModal.style.display = 'none';
        };
        window.onclick = (e) => {
            if (e.target === settingsModal) {
                settingsModal.style.display = 'none';
            }
        };
    
        aiModelSelect.onchange = (e) => {
          currentAiModel = e.target.value;
          localStorage.setItem('aiModel', currentAiModel);
        };
    
        darkModeToggle.onchange = (e) => {
          darkMode = e.target.checked;
          document.documentElement.setAttribute('data-theme', darkMode ? 'dark' : 'light');
          localStorage.setItem('darkMode', darkMode);
        };
    
        function createNewChat() {
            const chatName = 'New Chat';
            const chatId = 'chat-' + (chats.length + 1);
            chats.push({
                id: chatId,
                name: chatName,
                memory: [],
                messages: []
            });
            addChatTab(chatId, chatName);
            switchToChat(chatId);
        }
    
        function removeChat(chatId) {
            if (chats.length > 1) {
                chats = chats.filter(chat => chat.id !== chatId);
                document.querySelector(`[data-chat-id="${chatId}"]`).remove();
                if (currentChatId === chatId) {
                    switchToChat(chats[0].id);
                }
            }
        }
    
        function updateChatName(chatId, firstMessage) {
            const chat = chats.find(c => c.id === chatId);
            if (chat && chat.name === 'New Chat') {
                const name = firstMessage.slice(0, 20) + (firstMessage.length > 20 ? '...' : '');
                chat.name = name;
                const tab = document.querySelector(`[data-chat-id="${chatId}"] .chat-name`);
                if (tab) {
                    tab.textContent = name;
                }
            }
        }
    
        function setupRenameHandling(chatNameElement, chatId) {
            chatNameElement.addEventListener('dblclick', (e) => {
                e.stopPropagation();
                const currentName = chatNameElement.textContent;
                const input = document.createElement('input');
                input.type = 'text';
                input.className = 'rename-input';
                input.value = currentName;
                
                input.onblur = () => finishRename(input, chatNameElement, chatId);
                input.onkeypress = (e) => {
                    if (e.key === 'Enter') {
                        input.blur();
                    }
                };
    
                chatNameElement.parentNode.replaceChild(input, chatNameElement);
                input.focus();
                input.select();
            });
        }
    
        function finishRename(input, chatNameElement, chatId) {
            const newName = input.value.trim() || 'New Chat';
            const chat = chats.find(c => c.id === chatId);
            if (chat) {
                chat.name = newName;
            }
            chatNameElement.textContent = newName;
            input.parentNode.replaceChild(chatNameElement, input);
        }
    
        function addChatTab(chatId, name) {
            const tab = document.createElement('div');
            tab.className = 'chat-tab';
            tab.setAttribute('data-chat-id', chatId);
            
            const chatName = document.createElement('span');
            chatName.className = 'chat-name';
            chatName.textContent = name || 'New Chat';
            
            setupRenameHandling(chatName, chatId);
            
            const removeBtn = document.createElement('button');
            removeBtn.className = 'remove-chat';
            removeBtn.textContent = '×';
            removeBtn.onclick = (e) => {
                e.stopPropagation();
                removeChat(chatId);
            };
            
            tab.appendChild(chatName);
            tab.appendChild(removeBtn);
            tab.onclick = () => switchToChat(chatId);
            chatTabs.appendChild(tab);
            
            if (currentChatId === chatId) {
                tab.classList.add('active');
            }
        }
    
        function switchToChat(chatId) {
            if (currentChatId === chatId) {
                return;
            }
    
            currentChatId = chatId;
            document.querySelectorAll('.chat-tab').forEach(tab => {
                tab.classList.remove('active');
                if(tab.getAttribute('data-chat-id') === chatId) {
                    tab.classList.add('active');
                }
            });
            
            chatMessages.innerHTML = '';
            
            const chat = chats.find(c => c.id === chatId);
            chat.messages.forEach(msg => {
                addMessageToChat(msg.content, msg.isUser);
            });
            
            updateMemoryCount();
        }
    
        async function fetchWithProxy(url) {
            const proxy = PROXY_URLS[currentProxyIndex];
            try {
                const response = await fetch(proxy + encodeURIComponent(url));
                if (!response.ok) throw new Error('Proxy failed');
                return response;
            } catch (error) {
                currentProxyIndex = (currentProxyIndex + 1) % PROXY_URLS.length;
                throw error;
            }
        }
    
        async function fetchAIResponse(prompt) {
            let attempts = 0;
            const maxAttempts = PROXY_URLS.length;
    
            while (attempts < maxAttempts) {
                try {
                    const fullPrompt = `${SYSTEM_INSTRUCTIONS}\n\n${prompt}`;
                    const apiUrl = AI_ENDPOINTS[currentAiModel].replace('{prompt}', encodeURIComponent(fullPrompt));
                    const response = await fetchWithProxy(apiUrl);
                    const data = await response.json();
                    
                    if (data.status && data.result && data.result[0]) {
                        return data.result[0].response;
                    }
                    return "I apologize, but I couldn't process that request properly.";
                } catch (error) {
                    console.error('Error with proxy', currentProxyIndex, ':', error);
                    attempts++;
                    if (attempts === maxAttempts) {
                        return "Sorry, I'm having trouble connecting right now. Please try again later.";
                    }
                }
            }
        }
    
        function updateMemoryCount() {
            const currentChat = chats.find(c => c.id === currentChatId);
            memoryCount.textContent = currentChat.memory.length;
        }
    
        function addMessageToChat(message, isUser) {
            const messageDiv = document.createElement('div');
            messageDiv.className = `message ${isUser ? 'user-message' : 'ai-message'}`;
            
            const copyMessageBtn = document.createElement('button');
            copyMessageBtn.className = 'copy-message-btn';
            copyMessageBtn.textContent = 'Copy Message';
            copyMessageBtn.onclick = () => {
                navigator.clipboard.writeText(message)
                    .then(() => {
                        copyMessageBtn.textContent = 'Copied!';
                        setTimeout(() => {
                            copyMessageBtn.textContent = 'Copy Message';
                        }, 2000);
                    })
                    .catch(err => {
                        console.error('Failed to copy:', err);
                        copyMessageBtn.textContent = 'Failed to copy';
                        setTimeout(() => {
                            copyMessageBtn.textContent = 'Copy Message';
                        }, 2000);
                    });
            };
            messageDiv.appendChild(copyMessageBtn);
            
            const sanitizedMessage = message
                .replace(/&/g, '&amp;')
                .replace(/</g, '&lt;')
                .replace(/>/g, '&gt;');
            
            messageDiv.innerHTML += marked.parse(sanitizedMessage);
            
            messageDiv.querySelectorAll('pre code').forEach(block => {
                const preBlock = block.parentElement;
                const copyBtn = document.createElement('button');
                copyBtn.className = 'copy-code-btn';
                copyBtn.textContent = 'Copy Code';
                copyBtn.onclick = () => {
                    navigator.clipboard.writeText(block.textContent);
                    copyBtn.textContent = 'Copied!';
                    setTimeout(() => {
                        copyBtn.textContent = 'Copy Code';
                    }, 2000);
                };
                preBlock.appendChild(copyBtn);
                
                block.style.display = 'block';
                block.style.padding = '1em';
                block.style.backgroundColor = '#2d3748';
                block.style.color = '#e2e8f0';
                block.style.borderRadius = '4px';
                block.style.overflow = 'auto';
            });
            
            messageDiv.querySelectorAll('code:not(pre code)').forEach(inline => {
                inline.style.backgroundColor = '#edf2f7';
                inline.style.padding = '2px 4px';
                inline.style.borderRadius = '4px';
                inline.style.color = '#2d3748';
            });
            
            chatMessages.appendChild(messageDiv);
            chatMessages.scrollTop = chatMessages.scrollHeight;
    
            const currentChat = chats.find(c => c.id === currentChatId);
            currentChat.messages.push({
                content: message,
                isUser: isUser
            });
    
            if (isUser && currentChat.messages.length === 1) {
                updateChatName(currentChatId, message);
            }
        }
    
        function setTypingIndicator(visible) {
            typingIndicator.style.display = visible ? 'block' : 'none';
            sendButton.disabled = visible;
            userInput.disabled = visible;
        }
    
        async function sendMessage() {
            const message = userInput.value.trim();
            if (!message) return;
    
            addMessageToChat(message, true);
            userInput.value = '';
    
            setTypingIndicator(true);
    
            const currentChat = chats.find(c => c.id === currentChatId);
            const context = currentChat.memory.map(m => `${m.role}: ${m.content}`).join('\n');
            const fullPrompt = `Conversation history:\n${context}\n\nUser: ${message}`;
    
            try {
                const aiResponse = await fetchAIResponse(fullPrompt);
                addMessageToChat(aiResponse, false);
    
                currentChat.memory.push({ role: 'user', content: message });
                currentChat.memory.push({ role: 'assistant', content: aiResponse });
    
                if (currentChat.memory.length > MAX_MEMORY) {
                    currentChat.memory = currentChat.memory.slice(-MAX_MEMORY);
                }
    
                updateMemoryCount();
            } catch (error) {
                addMessageToChat("Sorry, I encountered an error. Please try again.", false);
            } finally {
                setTypingIndicator(false);
            }
        }
    
        clearMemoryBtn.addEventListener('click', () => {
            const currentChat = chats.find(c => c.id === currentChatId);
            currentChat.memory = [];
            updateMemoryCount();
        });
    
        newChatBtn.addEventListener('click', createNewChat);
    
        userInput.addEventListener('keypress', (e) => {
            if (e.key === 'Enter' && !userInput.disabled) {
                sendMessage();
            }
        });
    
        sendButton.addEventListener('click', () => {
            if (!sendButton.disabled) {
                sendMessage();
            }
        });
    
        addChatTab('chat-1', 'New Chat');
        document.querySelector('.chat-tab').classList.add('active');
    
        initResizableEvents();
        
        function initResizableEvents() {
            document.addEventListener('mousemove', (e) => {
                if (!isResizing) return;
    
                const delta = e.clientX - lastDownX;
                const newWidth = Math.max(280, Math.min(600, sidebar.offsetWidth + delta));
                sidebar.style.width = `${newWidth}px`;
                lastDownX = e.clientX;
            });
    
            document.addEventListener('mouseup', () => {
                isResizing = false;
                document.body.style.cursor = 'default';
            });
    
            sidebar.addEventListener('mousedown', (e) => {
                // Only start resizing if clicking near the right edge
                const rightEdge = sidebar.offsetLeft + sidebar.offsetWidth;
                if (e.clientX >= rightEdge - 8 && e.clientX <= rightEdge + 8) {
                    isResizing = true;
                    lastDownX = e.clientX;
                    document.body.style.cursor = 'ew-resize';
                    e.preventDefault();
                }
            });
        }
    });
    </script>
    
    </body></html>