const chatForm = document.getElementById("chatForm"); const userInput = document.getElementById("userInput"); const chatWindow = document.getElementById("chatWindow"); const WORKER_URL = "https://YOUR-WORKER-URL.workers.dev"; const messages = [ { role: "system", content: "You are a helpful L'Oréal beauty advisor. Only answer questions about L'Oréal products, skincare, makeup, haircare, fragrance, routines, ingredients, and product recommendations. If the user asks about anything unrelated, politely refuse and redirect them to L'Oréal beauty topics. Keep responses friendly, concise, and useful.", }, ]; function scrollToBottom() { chatWindow.scrollTop = chatWindow.scrollHeight; } function addMessage(role, text) { const bubble = document.createElement("div"); bubble.className = `msg ${role}`; const label = document.createElement("div"); label.className = "msg-label"; label.textContent = role === "user" ? "You" : "L'Oréal Advisor"; const content = document.createElement("div"); content.className = "msg-text"; content.textContent = text; bubble.appendChild(label); bubble.appendChild(content); chatWindow.appendChild(bubble); scrollToBottom(); return bubble; } function showTyping() { const bubble = document.createElement("div"); bubble.className = "msg ai typing"; bubble.innerHTML = `