// cognito-widget.js (function () { if (window.CognitoWidgetInitialized) return; window.CognitoWidgetInitialized = true; const CONFIG = { apiBase: window.COGNITO_API_BASE || "https://your-cognito-server.example.com", apiKey: window.COGNITO_API_KEY || null, // optional if you protect endpoint with a key placeholder: "Ask Cognito...", title: "Cognito", welcome: "Hi — I'm Cognito. How can I help?", }; // minimal CSS const css = ` .cognito-chat-btn { position: fixed; right: 20px; bottom: 20px; z-index: 100000; background: #0b5fff; color: #fff; border-radius: 28px; padding: 12px 16px; cursor: pointer; box-shadow: 0 6px 18px rgba(11,95,255,0.2); font-family: Arial, sans-serif; } .cognito-panel { position: fixed; right: 20px; bottom: 80px; width: 360px; max-width: 90vw; z-index: 100000; border-radius: 12px; box-shadow: 0 10px 40px rgba(0,0,0,0.2); overflow: hidden; font-family: Arial, sans-serif; background: #fff; display: none; flex-direction: column; } .cognito-header { padding: 12px; background: #0b5fff; color: #fff; font-weight: bold; display:flex; align-items:center; justify-content:space-between } .cognito-body { padding: 12px; height: 320px; overflow:auto; background:#f7f7fb } .cognito-input-row { display:flex; padding: 8px; border-top:1px solid #eee; background:#fff } .cognito-input { flex:1; padding:8px 10px; border-radius:8px; border:1px solid #ddd; outline:none } .cognito-send { margin-left:8px; padding:8px 12px; border-radius:8px; border:none; background:#0b5fff; color:#fff; cursor:pointer } .cognito-msg { margin-bottom:8px; padding:8px 10px; border-radius:8px; max-width:85% } .cognito-msg.user { background:#0b5fff; color:#fff; margin-left:auto } .cognito-msg.bot { background:#fff; color:#111; border:1px solid #eee } `; const styleEl = document.createElement("style"); styleEl.innerHTML = css; document.head.appendChild(styleEl); const btn = document.createElement("button"); btn.className = "cognito-chat-btn"; btn.innerText = CONFIG.title; document.body.appendChild(btn); const panel = document.createElement("div"); panel.className = "cognito-panel"; panel.innerHTML = `