๐Ÿ“‚ File Browser

AgentAI
๐ŸŒ™ Dark Mode
๐ŸŽฏ Quick Launch:

๐Ÿ“ Directories

๐Ÿ“ tmp/ ๐Ÿ”“ Open
๐Ÿ“ vendor/ ๐Ÿ”“ Open

๐Ÿ“„ Files

๐Ÿ˜ chat_handler.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ check_auth.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ“„ composer.json
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ database.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ debug_email.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ debug_email_parts.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ debug_emails.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ delete_chat.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ fetch_emails.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ find_models.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ gemini_direct.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ get_chats.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ get_email.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ index.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ logout.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ new_chat.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ oauth2callback.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ rename_chat.php
โ–ถ Open ๐Ÿ“„ View Source
๐ŸŽจ style.css
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ switch_chat.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ test_ajax.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ test_api.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ test_cmd.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ test_curl.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ test_db.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ test_db_ops.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ test_endpoint.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ test_ollama.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ test_ollama_direct.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ test_openrouter.php
โ–ถ Open ๐Ÿ“„ View Source
๐Ÿ˜ test_shell.php
โ–ถ Open ๐Ÿ“„ View Source

๐Ÿ“„ Source: index.php

<?php
session_start();
require_once 'vendor/autoload.php';

$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? "https" : "http";
$host = $_SERVER['HTTP_HOST'];
$baseUrl = "http://createcraftweb.playit.plus/AgentAI";

$client = new Google\Client();
$client->setClientId('1082083393389-c5uekspcp2boc1gd0n0gr3v1a5vbb3jg.apps.googleusercontent.com');
$client->setClientSecret('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');
$client->setRedirectUri("http://createcraftweb.playit.plus/AgentAI/oauth2callback.php");
$client->addScope('https://www.googleapis.com/auth/gmail.readonly');
$client->setAccessType('offline');
$client->setPrompt('consent');

$isMobile = preg_match('/(android|iphone|ipad|mobile)/i', $_SERVER['HTTP_USER_AGENT']);
$lang = $_COOKIE['inboxzero_lang'] ?? 'en';
?>
<!DOCTYPE html>
<html lang="<?php echo $lang; ?>">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
    <title>InboxZero AI - Email Assistant</title>
    <link rel="stylesheet" href="style.css">
</head>
<body data-theme="light">
<div class="container">
    <div class="header">
        <div class="header-top">
            <h1>๐Ÿ“ง InboxZero AI <span class="badge">v2.0</span></h1>
            <div class="controls">
                <button class="theme-toggle" onclick="toggleTheme()" id="themeBtn">๐ŸŒ™ Dark</button>
                <select class="lang-select" id="langSelect" onchange="changeLanguage()">
                    <option value="en" <?php echo $lang == 'en' ? 'selected' : ''; ?>>๐Ÿ‡ฌ๐Ÿ‡ง English</option>
                    <option value="ro" <?php echo $lang == 'ro' ? 'selected' : ''; ?>>๐Ÿ‡ท๐Ÿ‡ด Romรขnฤƒ</option>
                </select>
            </div>
        </div>
        <p id="headerDescription">Your intelligent email assistant - ask anything about your inbox</p>
        <div class="status">๐Ÿ”ง <?php echo date('Y-m-d H:i:s'); ?></div>
    </div>
    <div class="content">
        <div class="sidebar">
            <!-- Chat History Section -->
            <div class="chat-history-section">
                <h3>๐Ÿ’ฌ Recent Chats</h3>
                <div id="chatHistoryList" class="chat-history-list"></div>
                <button onclick="newChat()" class="new-chat-btn" id="newChatBtn">+ New Chat</button>
            </div>
            <hr>
            <h3 id="inboxTitle">๐Ÿ“ฌ Your Inbox</h3>
            <?php if (isset($_SESSION['access_token'])): ?>
                <button onclick="logout()" class="logout-btn" id="logoutBtn">๐Ÿšช Logout</button>
                <div id="emailList" style="margin-top: 15px;">
                    <div class="loading" id="loadingEmails">๐Ÿ“ฅ Loading your emails...</div>
                </div>
            <?php else: ?>
                <p id="loginPrompt">๐Ÿ” Login to access your Gmail inbox</p>
                <?php
                $authUrl = $client->createAuthUrl();
                if ($isMobile) {
                    $authUrl .= '&device_id=mobile_' . md5($_SERVER['REMOTE_ADDR']) . '&device_name=MobileBrowser';
                }
                ?>
                <a href="<?php echo $authUrl; ?>" class="login-btn" id="loginBtn">๐Ÿ”‘ Sign in with Google</a>
                <p style="font-size: 12px; margin-top: 15px;">
                    <small id="privacyNote">This app only reads your email metadata. No data is stored permanently.</small>
                </p>
            <?php endif; ?>
        </div>
        <div class="chat-area">
            <div class="messages" id="messages">
                <div class="message ai-message" id="welcomeMessage">
                    ๐Ÿค– <strong>Hello! I'm InboxZero AI.</strong><br><br>
                    I can help you:<br>
                    โ€ข ๐Ÿ“Š Summarize unread emails<br>
                    โ€ข ๐Ÿ” Find specific messages<br>
                    โ€ข ๐Ÿ“… Extract important dates<br>
                    โ€ข โšก Answer questions about your inbox<br><br>
                    <em>Try: "Show me emails from Steam" or "Do I have emails from ChatGPT?"</em>
                </div>
            </div>
            <?php if (isset($_SESSION['access_token'])): ?>
            <div class="input-area">
                <textarea id="userInput" placeholder="Ask about your emails..." rows="1" onkeypress="if(event.key==='Enter' && !event.shiftKey) { event.preventDefault(); sendMessage(); }" style="overflow-y: hidden; resize: none;"></textarea>
                <button onclick="sendMessage()" id="sendBtn">๐Ÿ“ค Send</button>
            </div>
            <?php endif; ?>
        </div>
    </div>
</div>

<script>
const translations = {
    en: {
        headerDesc: "Your intelligent email assistant - ask anything about your inbox",
        inboxTitle: "๐Ÿ“ฌ Your Inbox",
        logoutBtn: "๐Ÿšช Logout",
        loadingEmails: "๐Ÿ“ฅ Loading your emails...",
        loginPrompt: "๐Ÿ” Login to access your Gmail inbox",
        loginBtn: "๐Ÿ”‘ Sign in with Google",
        privacyNote: "This app only reads your email metadata. No data is stored permanently.",
        welcomeMsg: "๐Ÿค– <strong>Hello! I'm InboxZero AI.</strong><br><br>I can help you:<br>โ€ข ๐Ÿ“Š Summarize unread emails<br>โ€ข ๐Ÿ” Find specific messages<br>โ€ข ๐Ÿ“… Extract important dates<br>โ€ข โšก Answer questions about your emails<br><br><em>Try: \"Show me emails from Steam\" or \"Do I have emails from ChatGPT?\"</em>",
        inputPlaceholder: "Ask about your emails...",
        sendBtn: "๐Ÿ“ค Send",
        thinking: "๐Ÿค” Thinking...",
        error: "โŒ Error: ",
        noEmailsDetail: "๐Ÿ“ญ No emails found in your inbox",
        failedToLoad: "โŒ Failed to load emails",
        newChatBtn: "+ New Chat"
    },
    ro: {
        headerDesc: "Asistentul tฤƒu inteligent pentru emailuri - รฎntreabฤƒ orice despre inbox",
        inboxTitle: "๐Ÿ“ฌ Inbox-ul Tฤƒu",
        logoutBtn: "๐Ÿšช Deconectare",
        loadingEmails: "๐Ÿ“ฅ Se รฎncarcฤƒ emailurile...",
        loginPrompt: "๐Ÿ” Autentificฤƒ-te pentru a accesa Gmail",
        loginBtn: "๐Ÿ”‘ Conectare cu Google",
        privacyNote: "Aplicaศ›ia citeศ™te doar metadatele emailurilor. Nu stocheazฤƒ date permanent.",
        welcomeMsg: "๐Ÿค– <strong>Salut! Sunt InboxZero AI.</strong><br><br>Te pot ajuta:<br>โ€ข ๐Ÿ“Š Rezumatul emailurilor necitite<br>โ€ข ๐Ÿ” Gฤƒsirea mesajelor specifice<br>โ€ข ๐Ÿ“… Extragerea datelor importante<br>โ€ข โšก Rฤƒspuns la รฎntrebฤƒri despre emailurile tale<br><br><em>รŽncearcฤƒ: \"Aratฤƒ-mi emailurile de la Steam\" sau \"Am emailuri de la ChatGPT?\"</em>",
        inputPlaceholder: "รŽntreabฤƒ despre emailurile tale...",
        sendBtn: "๐Ÿ“ค Trimite",
        thinking: "๐Ÿค” Analizez inbox-ul...",
        error: "โŒ Eroare: ",
        noEmailsDetail: "๐Ÿ“ญ Nu s-au gฤƒsit emailuri รฎn inbox",
        failedToLoad: "โŒ Nu s-au putut รฎncฤƒrca emailurile",
        newChatBtn: "+ Chat Nou"
    }
};

let currentLang = '<?php echo $lang; ?>';
let currentEmails = [];
let currentConversationId = null;
let reminderTimeout = null;

function updateLanguage() {
    const t = translations[currentLang];
    const headerDesc = document.getElementById('headerDescription');
    if (headerDesc) headerDesc.innerText = t.headerDesc;
    const inboxTitle = document.getElementById('inboxTitle');
    if (inboxTitle) inboxTitle.innerText = t.inboxTitle;
    const logoutBtn = document.getElementById('logoutBtn');
    if (logoutBtn) logoutBtn.innerText = t.logoutBtn;
    const loginPrompt = document.getElementById('loginPrompt');
    if (loginPrompt) loginPrompt.innerText = t.loginPrompt;
    const loginBtn = document.getElementById('loginBtn');
    if (loginBtn) loginBtn.innerText = t.loginBtn;
    const privacyNote = document.getElementById('privacyNote');
    if (privacyNote) privacyNote.innerText = t.privacyNote;
    const welcomeMessage = document.getElementById('welcomeMessage');
    if (welcomeMessage) welcomeMessage.innerHTML = t.welcomeMsg;
    const userInput = document.getElementById('userInput');
    if (userInput) userInput.placeholder = t.inputPlaceholder;
    const sendBtn = document.getElementById('sendBtn');
    if (sendBtn) sendBtn.innerText = t.sendBtn;
    const newChatBtn = document.getElementById('newChatBtn');
    if (newChatBtn) newChatBtn.innerText = t.newChatBtn;
}

function changeLanguage() {
    const select = document.getElementById('langSelect');
    currentLang = select.value;
    document.documentElement.lang = currentLang;
    document.cookie = `inboxzero_lang=${currentLang}; path=/; max-age=${365 * 24 * 60 * 60}`;
    updateLanguage();
}

function toggleTheme() {
    const body = document.body;
    const currentTheme = body.getAttribute('data-theme');
    const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
    body.setAttribute('data-theme', newTheme);
    localStorage.setItem('inboxzero_theme', newTheme);
    const themeBtn = document.getElementById('themeBtn');
    themeBtn.innerHTML = newTheme === 'dark' ? 'โ˜€๏ธ Light' : '๐ŸŒ™ Dark';
}

const savedTheme = localStorage.getItem('inboxzero_theme') || 'light';
document.body.setAttribute('data-theme', savedTheme);
const themeBtn = document.getElementById('themeBtn');
if (themeBtn) themeBtn.innerHTML = savedTheme === 'dark' ? 'โ˜€๏ธ Light' : '๐ŸŒ™ Dark';

function setReminder(text, minutes) {
    if (reminderTimeout) clearTimeout(reminderTimeout);
    
    addMessage('ai', `โฐ Reminder set for ${minutes} minute(s): "${text}"`);
    
    reminderTimeout = setTimeout(() => {
        if (Notification.permission === 'granted') {
            new Notification('InboxZero Reminder', { body: text });
            addMessage('ai', `๐Ÿ”” REMINDER: ${text}`);
        } else if (Notification.permission !== 'denied') {
            Notification.requestPermission().then(permission => {
                if (permission === 'granted') {
                    new Notification('InboxZero Reminder', { body: text });
                    addMessage('ai', `๐Ÿ”” REMINDER: ${text}`);
                }
            });
        }
    }, minutes * 60 * 1000);
}

async function sendMessage() {
    const input = document.getElementById('userInput');
    const message = input.value.trim();
    if (!message) return;
    
    addMessage('user', message);
    input.value = '';
    input.disabled = true;
    
    const t = translations[currentLang];
    const thinkingMsg = addMessage('ai', t.thinking, true);
    
    try {
        const response = await fetch('chat_handler.php', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ 
                query: message, 
                lang: currentLang,
                conversation_id: currentConversationId
            })
        });
        
        if (!response.ok) {
            throw new Error(`HTTP ${response.status}`);
        }
        
        const data = await response.json();
        
        if (thinkingMsg) thinkingMsg.remove();
        
        let reply = data.reply;
        addMessage('ai', reply);
        
        if (data.reminder) {
            setReminder(data.reminder.text, data.reminder.minutes);
        }
        
        if (data.emails && data.emails.length > 0) {
            currentEmails = data.emails;
            displayEmails(currentEmails);
        }
        
        if (data.conversation_id && !currentConversationId) {
            currentConversationId = data.conversation_id;
            loadChatHistory();
        }
    } catch (error) {
        if (thinkingMsg) thinkingMsg.remove();
        console.error('Full error:', error);
        addMessage('ai', t.error + error.message);
    }
    
    input.disabled = false;
    input.focus();
}

function addMessage(role, text, returnElement = false, isHtml = false) {
    const messagesDiv = document.getElementById('messages');
    const messageDiv = document.createElement('div');
    messageDiv.className = `message ${role === 'user' ? 'user-message' : 'ai-message'}`;
    
    if (isHtml) {
        messageDiv.innerHTML = role === 'user' ? `๐Ÿ‘ค ${text}` : `๐Ÿค– ${text}`;
    } else {
        let formattedText = text.replace(/\n/g, '<br>');
        messageDiv.innerHTML = role === 'user' ? `๐Ÿ‘ค ${formattedText}` : `๐Ÿค– ${formattedText}`;
    }
    
    messagesDiv.appendChild(messageDiv);
    messagesDiv.scrollTop = messagesDiv.scrollHeight;
    
    if (returnElement) return messageDiv;
    return messageDiv;
}

async function loadEmails() {
    const t = translations[currentLang];
    try {
        const response = await fetch('fetch_emails.php');
        const emails = await response.json();
        if (emails.error) {
            document.getElementById('emailList').innerHTML = `<div class="loading">โŒ ${emails.error}</div>`;
        } else if (emails.length === 0) {
            document.getElementById('emailList').innerHTML = `<div class="loading">${t.noEmailsDetail}</div>`;
        } else {
            currentEmails = emails;
            displayEmails(emails);
        }
    } catch (error) {
        document.getElementById('emailList').innerHTML = `<div class="loading">${t.failedToLoad}</div>`;
    }
}

function displayEmails(emails) {
    if (!emails || emails.length === 0) {
        document.getElementById('emailList').innerHTML = '<div class="loading">๐Ÿ“ญ No emails found</div>';
        return;
    }
    let html = '<ul class="email-list">';
    for (let i = 0; i < Math.min(emails.length, 10); i++) {
        const email = emails[i];
        const fromShort = email.from.length > 35 ? email.from.substring(0, 32) + '...' : email.from;
        const subjectShort = email.subject.length > 45 ? email.subject.substring(0, 42) + '...' : email.subject;
        html += `<li class="email-item" onclick="viewEmail('${email.id}', '${email.threadId}')">
                    <div class="email-from">๐Ÿ“จ ${escapeHtml(fromShort)}</div>
                    <div class="email-subject">${escapeHtml(subjectShort)}</div>
                    <div class="email-date">๐Ÿ“… ${escapeHtml(email.date)}</div>
                </li>`;
    }
    html += '</ul>';
    document.getElementById('emailList').innerHTML = html;
}

async function getEmailLink(emailId, threadId) {
    // Gmail web client URL format
    const gmailUrl = `https://mail.google.com/mail/u/0/#inbox/${threadId}`;
    return gmailUrl;
}

async function viewEmail(emailId, threadId) {
    addMessage('ai', '๐Ÿ“– Opening email...');
    try {
        const response = await fetch('get_email.php', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ email_id: emailId })
        });
        const data = await response.json();
        if (data.content) {
            let content = data.content;
            if (content.includes('<a href')) {
                addMessage('ai', content, false, true);
            } else {
                addMessage('ai', content);
            }
            
            // Add a "Open in Gmail" link
            if (threadId) {
                const gmailLink = `https://mail.google.com/mail/u/0/#inbox/${threadId}`;
                addMessage('ai', `<a href="${gmailLink}" target="_blank" class="gmail-link">๐Ÿ“ง Open this email in Gmail โ†’</a>`, false, true);
            }
        } else {
            addMessage('ai', 'โŒ Could not load email content.');
        }
    } catch (error) {
        addMessage('ai', 'โŒ Failed to load email.');
    }
}

async function newChat() {
    try {
        const response = await fetch('new_chat.php', { 
            method: 'POST',
            headers: { 'Content-Type': 'application/json' }
        });
        const data = await response.json();
        
        if (data.success) {
            currentConversationId = data.chat_id;
            
            const messagesDiv = document.getElementById('messages');
            messagesDiv.innerHTML = '';
            
            const welcomeMsg = document.createElement('div');
            welcomeMsg.className = 'message ai-message';
            welcomeMsg.id = 'welcomeMessage';
            welcomeMsg.innerHTML = translations[currentLang].welcomeMsg;
            messagesDiv.appendChild(welcomeMsg);
            
            // Clear email list display (will reload)
            document.getElementById('emailList').innerHTML = '<div class="loading">๐Ÿ“ฅ Loading your emails...</div>';
            await loadEmails();
            await loadChatHistory();
            
            // Highlight the new chat in sidebar
            const chatItems = document.querySelectorAll('.chat-history-item');
            chatItems.forEach(item => item.classList.remove('active'));
        }
    } catch(e) {
        console.error('New chat error:', e);
        // Fallback: clear locally
        currentConversationId = 'local_' + Date.now();
        document.getElementById('messages').innerHTML = '';
        const welcomeMsg = document.createElement('div');
        welcomeMsg.className = 'message ai-message';
        welcomeMsg.id = 'welcomeMessage';
        welcomeMsg.innerHTML = translations[currentLang].welcomeMsg;
        document.getElementById('messages').appendChild(welcomeMsg);
        loadEmails();
    }
}

async function loadChatHistory() {
    try {
        const response = await fetch('get_chats.php');
        const chats = await response.json();
        const container = document.getElementById('chatHistoryList');
        if (container && !chats.error) {
            if (chats.length === 0) {
                container.innerHTML = '<div class="chat-history-item" style="opacity:0.6;">No previous chats</div>';
            } else {
                container.innerHTML = chats.map(chat => `
                    <div class="chat-history-item-wrapper">
                        <div class="chat-history-item ${currentConversationId == chat.id ? 'active' : ''}" onclick="switchChat(${chat.id})">
                            ${escapeHtml(chat.title)}
                        </div>
                        <div class="chat-history-actions">
                            <button onclick="event.stopPropagation(); renameChat(${chat.id})" title="Rename">โœ๏ธ</button>
                            <button onclick="event.stopPropagation(); deleteChat(${chat.id})" title="Delete">๐Ÿ—‘๏ธ</button>
                        </div>
                    </div>
                `).join('');
            }
        }
    } catch (e) {
        console.error('Load chat history error:', e);
    }
}

async function renameChat(chatId) {
    const newTitle = prompt('Enter new chat name:');
    if (newTitle && newTitle.trim()) {
        await fetch('rename_chat.php', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ chat_id: chatId, title: newTitle.trim() })
        });
        loadChatHistory();
    }
}

async function deleteChat(chatId) {
    if (confirm('Delete this chat?')) {
        await fetch('delete_chat.php', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ chat_id: chatId })
        });
        if (currentConversationId == chatId) {
            currentConversationId = null;
            document.getElementById('messages').innerHTML = '';
            const welcomeMsg = document.createElement('div');
            welcomeMsg.className = 'message ai-message';
            welcomeMsg.innerHTML = translations[currentLang].welcomeMsg;
            document.getElementById('messages').appendChild(welcomeMsg);
            // Create a new chat automatically
            const newChatResp = await fetch('new_chat.php', { method: 'POST' });
            const newChatData = await newChatResp.json();
            if (newChatData.success) {
                currentConversationId = newChatData.chat_id;
            }
        }
        loadChatHistory();
    }
}

async function switchChat(chatId) {
    currentConversationId = chatId;
    try {
        const response = await fetch('switch_chat.php', {
            method: 'POST',
            headers: { 'Content-Type': 'application/json' },
            body: JSON.stringify({ chat_id: chatId })
        });
        const data = await response.json();
        if (data.messages) {
            const messagesDiv = document.getElementById('messages');
            messagesDiv.innerHTML = '';
            // Display all messages from database
            for (const msg of data.messages) {
                addMessage(msg.role, msg.content);
            }
            // If no messages, show welcome
            if (data.messages.length === 0) {
                const welcomeMsg = document.createElement('div');
                welcomeMsg.className = 'message ai-message';
                welcomeMsg.id = 'welcomeMessage';
                welcomeMsg.innerHTML = translations[currentLang].welcomeMsg;
                messagesDiv.appendChild(welcomeMsg);
            }
        }
        await loadChatHistory();
    } catch (e) {
        console.error('Switch chat error:', e);
        window.location.reload();
    }
}

function logout() {
    fetch('logout.php').then(() => window.location.reload());
}

function escapeHtml(text) {
    if (!text) return '';
    const div = document.createElement('div');
    div.textContent = text;
    return div.innerHTML;
}

const textarea = document.getElementById('userInput');
if (textarea) {
    textarea.addEventListener('input', function() {
        this.style.height = 'auto';
        this.style.height = Math.min(this.scrollHeight, 100) + 'px';
    });
}

if ('Notification' in window && Notification.permission !== 'denied' && Notification.permission !== 'granted') {
    Notification.requestPermission();
}

updateLanguage();

<?php if (isset($_SESSION['access_token'])): ?>
window.onload = async function() {
    await loadEmails();
    await loadChatHistory();
    
    // If no conversation exists, create one
    if (!currentConversationId) {
        const response = await fetch('new_chat.php', { method: 'POST' });
        const data = await response.json();
        if (data.success) {
            currentConversationId = data.chat_id;
        }
    }
};
<?php endif; ?>
</script>
<style>
.chat-history-section {
    margin-bottom: 15px;
}
.chat-history-list {
    max-height: 150px;
    overflow-y: auto;
    margin-bottom: 8px;
}
.chat-history-item {
    padding: 6px 10px;
    margin-bottom: 4px;
    background: var(--bg-secondary);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-history-item:hover {
    background: var(--email-hover);
}
.chat-history-item.active {
    background: var(--user-message);
    color: white;
}
.new-chat-btn {
    width: 100%;
    padding: 6px;
    background: var(--user-message);
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.8rem;
}
.new-chat-btn:hover {
    opacity: 0.9;
}
hr {
    margin: 10px 0;
    border-color: var(--border);
}
</style>
</body>
</html>
โ† Back