UNPKG

bettercx-widget

Version:

Professional AI-powered chat widget for BetterCX platform. Seamlessly integrate intelligent customer support into any website.

1 lines 55.4 kB
var __assign=this&&this.__assign||function(){__assign=Object.assign||function(t){for(var r,e=1,a=arguments.length;e<a;e++){r=arguments[e];for(var i in r)if(Object.prototype.hasOwnProperty.call(r,i))t[i]=r[i]}return t};return __assign.apply(this,arguments)};var __awaiter=this&&this.__awaiter||function(t,r,e,a){function i(t){return t instanceof e?t:new e((function(r){r(t)}))}return new(e||(e=Promise))((function(e,n){function o(t){try{c(a.next(t))}catch(t){n(t)}}function s(t){try{c(a["throw"](t))}catch(t){n(t)}}function c(t){t.done?e(t.value):i(t.value).then(o,s)}c((a=a.apply(t,r||[])).next())}))};var __generator=this&&this.__generator||function(t,r){var e={label:0,sent:function(){if(n[0]&1)throw n[1];return n[1]},trys:[],ops:[]},a,i,n,o;return o={next:s(0),throw:s(1),return:s(2)},typeof Symbol==="function"&&(o[Symbol.iterator]=function(){return this}),o;function s(t){return function(r){return c([t,r])}}function c(s){if(a)throw new TypeError("Generator is already executing.");while(o&&(o=0,s[0]&&(e=0)),e)try{if(a=1,i&&(n=s[0]&2?i["return"]:s[0]?i["throw"]||((n=i["return"])&&n.call(i),0):i.next)&&!(n=n.call(i,s[1])).done)return n;if(i=0,n)s=[s[0]&2,n.value];switch(s[0]){case 0:case 1:n=s;break;case 4:e.label++;return{value:s[1],done:false};case 5:e.label++;i=s[1];s=[0];continue;case 7:s=e.ops.pop();e.trys.pop();continue;default:if(!(n=e.trys,n=n.length>0&&n[n.length-1])&&(s[0]===6||s[0]===2)){e=0;continue}if(s[0]===3&&(!n||s[1]>n[0]&&s[1]<n[3])){e.label=s[1];break}if(s[0]===6&&e.label<n[1]){e.label=n[1];n=s;break}if(n&&e.label<n[2]){e.label=n[2];e.ops.push(s);break}if(n[2])e.ops.pop();e.trys.pop();continue}s=r.call(t,e)}catch(t){s=[6,t];i=0}finally{a=n=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:true}}};var __await=this&&this.__await||function(t){return this instanceof __await?(this.v=t,this):new __await(t)};var __asyncGenerator=this&&this.__asyncGenerator||function(t,r,e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var a=e.apply(t,r||[]),i,n=[];return i={},s("next"),s("throw"),s("return",o),i[Symbol.asyncIterator]=function(){return this},i;function o(t){return function(r){return Promise.resolve(r).then(t,d)}}function s(t,r){if(a[t]){i[t]=function(r){return new Promise((function(e,a){n.push([t,r,e,a])>1||c(t,r)}))};if(r)i[t]=r(i[t])}}function c(t,r){try{b(a[t](r))}catch(t){l(n[0][3],t)}}function b(t){t.value instanceof __await?Promise.resolve(t.value.v).then(x,d):l(n[0][2],t)}function x(t){c("next",t)}function d(t){c("throw",t)}function l(t,r){if(t(r),n.shift(),n.length)c(n[0][0],n[0][1])}};var __asyncValues=this&&this.__asyncValues||function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=t[Symbol.asyncIterator],e;return r?r.call(t):(t=typeof __values==="function"?__values(t):t[Symbol.iterator](),e={},a("next"),a("throw"),a("return"),e[Symbol.asyncIterator]=function(){return this},e);function a(r){e[r]=t[r]&&function(e){return new Promise((function(a,n){e=t[r](e),i(a,n,e.done,e.value)}))}}function i(t,r,e,a){Promise.resolve(a).then((function(r){t({value:r,done:e})}),r)}};var __spreadArray=this&&this.__spreadArray||function(t,r,e){if(e||arguments.length===2)for(var a=0,i=r.length,n;a<i;a++){if(n||!(a in r)){if(!n)n=Array.prototype.slice.call(r,0,a);n[a]=r[a]}}return t.concat(n||Array.prototype.slice.call(r))};import{r as registerInstance,c as createEvent,a as getElement,h,H as Host}from"./index-KfgIcFMr.js";var AuthService=function(){function t(t){if(t===void 0){t="http://localhost:8000"}this.baseUrl=t}t.prototype.createSession=function(t,r){return __awaiter(this,void 0,void 0,(function(){var e,a,i,n;return __generator(this,(function(o){switch(o.label){case 0:e={widget_key:t,origin:r};return[4,fetch("".concat(this.baseUrl,"/api/widgets/session/create/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})];case 1:a=o.sent();if(!!a.ok)return[3,3];return[4,a.json()];case 2:i=o.sent();throw new Error(i.error||"HTTP ".concat(a.status,": ").concat(a.statusText));case 3:return[4,a.json()];case 4:n=o.sent();this.sessionToken=n.data.token;this.sessionExpiresAt=new Date(n.data.expires_at);return[2,n.data]}}))}))};t.prototype.getToken=function(){if(this.isTokenValid()){return this.sessionToken}return undefined};t.prototype.isTokenValid=function(){if(!this.sessionToken||!this.sessionExpiresAt){return false}return new Date<this.sessionExpiresAt};t.prototype.clearSession=function(){this.sessionToken=undefined;this.sessionExpiresAt=undefined};t.prototype.getAuthHeader=function(){var t=this.getToken();return t?{Authorization:"Bearer ".concat(t)}:{}};t.prototype.refreshSessionIfNeeded=function(t,r){return __awaiter(this,void 0,void 0,(function(){var e;return __generator(this,(function(a){switch(a.label){case 0:if(this.isTokenValid()){return[2,true]}a.label=1;case 1:a.trys.push([1,3,,4]);return[4,this.createSession(t,r)];case 2:a.sent();return[2,true];case 3:e=a.sent();return[2,false];case 4:return[2]}}))}))};return t}();var ApiService=function(){function t(t,r,e){if(t===void 0){t="http://localhost:8000"}if(r===void 0){r="http://localhost:8081"}this.dbServiceUrl=t;this.aiServiceUrl=r;this.authService=e||new AuthService(t)}t.prototype.getWidgetConfig=function(t){return __awaiter(this,void 0,void 0,(function(){var r,e,a,i;return __generator(this,(function(n){switch(n.label){case 0:r=this.authService.getToken();if(!r){throw new Error("No valid session token available")}n.label=1;case 1:n.trys.push([1,6,,7]);return[4,fetch("".concat(this.dbServiceUrl,"/api/widgets/org/").concat(t,"/widget-config/"),{method:"GET",headers:__assign({"Content-Type":"application/json"},this.authService.getAuthHeader())})];case 2:e=n.sent();if(!!e.ok)return[3,4];return[4,e.json()];case 3:a=n.sent();throw new Error(a.error||"HTTP ".concat(e.status,": ").concat(e.statusText));case 4:return[4,e.json()];case 5:return[2,n.sent()];case 6:i=n.sent();throw i;case 7:return[2]}}))}))};t.prototype.sendMessage=function(t){return __awaiter(this,void 0,void 0,(function(){var r,e,a,i,n;return __generator(this,(function(o){switch(o.label){case 0:r=this.authService.getToken();if(!r){throw new Error("No valid session token available")}e={content:t};o.label=1;case 1:o.trys.push([1,5,,6]);return[4,fetch("".concat(this.aiServiceUrl,"/widget/ai/respond/"),{method:"POST",headers:__assign({"Content-Type":"application/json"},this.authService.getAuthHeader()),body:JSON.stringify(e)})];case 2:a=o.sent();if(!!a.ok)return[3,4];return[4,a.json()];case 3:i=o.sent();throw new Error(i.error||"HTTP ".concat(a.status,": ").concat(a.statusText));case 4:return[2,a.body];case 5:n=o.sent();throw n;case 6:return[2]}}))}))};t.prototype.parseStreamResponse=function(t){return __asyncGenerator(this,arguments,(function r(){var e,a,i,n,o,s,c,b,x,d,l,u,g,p;return __generator(this,(function(r){switch(r.label){case 0:e=t.getReader();a=new TextDecoder;i="streaming_output";r.label=1;case 1:r.trys.push([1,,14,15]);r.label=2;case 2:if(!true)return[3,13];return[4,__await(e.read())];case 3:n=r.sent(),o=n.done,s=n.value;if(o)return[3,13];c=a.decode(s,{stream:true});b=c.split("\n");x=0,d=b;r.label=4;case 4:if(!(x<d.length))return[3,12];l=d[x];if(l.startsWith("event: ")){i=l.slice(7).trim();return[3,11]}if(!l.startsWith("data: "))return[3,11];u=l.slice(6);if(!(u==="[DONE]"))return[3,6];return[4,__await(void 0)];case 5:return[2,r.sent()];case 6:r.trys.push([6,10,,11]);g=JSON.parse(u);if(!g.content)return[3,9];return[4,__await({type:i,content:g.content})];case 7:return[4,r.sent()];case 8:r.sent();r.label=9;case 9:return[3,11];case 10:p=r.sent();return[3,11];case 11:x++;return[3,4];case 12:return[3,2];case 13:return[3,15];case 14:e.releaseLock();return[7];case 15:return[2]}}))}))};t.prototype.getAuthService=function(){return this.authService};return t}();var ThemeService=function(){function t(t){this.currentTheme="auto";this.hostElement=t}t.prototype.detectWebsiteLanguage=function(){return __awaiter(this,void 0,void 0,(function(){var t,r,e,r,a,i,n,o,s,c,b,x,d,l,u,g,p;var m,f,h;return __generator(this,(function(v){switch(v.label){case 0:v.trys.push([0,5,,6]);t=document.querySelector('meta[http-equiv="content-language"]');if(t){r=(m=t.getAttribute("content"))===null||m===void 0?void 0:m.toLowerCase();if(r===null||r===void 0?void 0:r.includes("pl"))return[2,"pl"];if(r===null||r===void 0?void 0:r.includes("en"))return[2,"en"]}e=document.querySelector('meta[name="language"]');if(e){r=(f=e.getAttribute("content"))===null||f===void 0?void 0:f.toLowerCase();if(r===null||r===void 0?void 0:r.includes("pl"))return[2,"pl"];if(r===null||r===void 0?void 0:r.includes("en"))return[2,"en"]}a=((h=document.body.textContent)===null||h===void 0?void 0:h.toLowerCase())||"";i=["i","w","na","z","do","od","po","przy","dla","przez","bez","pod","nad","między","przed","za","jest","są","ma","mają","być","może","można","możemy","można","możemy","jest","są","ma","mają","być","może","można","możemy","można","możemy","strona","stronie","strony","stron","stroną","stronę","stronie","strony","stron","stroną","stronę","informacje","informacji","informacjami","informacjami","informacjami","informacjami","informacjami","kontakt","kontakcie","kontaktu","kontaktem","kontaktem","kontaktem","kontaktem","kontaktem","nowy","nowa","nowe","nowego","nowej","nowego","nowym","nową","nowym","nowym","dobry","dobra","dobre","dobrego","dobrej","dobrego","dobrym","dobrą","dobrym","dobrym","oraz","lub","ale","jednak","więc","dlatego","ponieważ","gdy","gdyż","jeśli","jeżeli","w","na","z","do","od","po","przy","dla","przez","bez","pod","nad","między","przed","za","nie","już","jeszcze","tylko","także","również","też","tak","nie","już","jeszcze","tylko","także","również","też","tak"];n=i.filter((function(t){var r=new RegExp("\\b".concat(t,"\\b"),"gi");return r.test(a)})).length;if(n>=2){return[2,"pl"]}o=/[ąćęłńóśźż]/gi;s=(a.match(o)||[]).length;if(s>=5){return[2,"pl"]}c=navigator.language.toLowerCase().split("-")[0];if(c==="pl")return[2,"pl"];b=["www.",".pl","strona główna","o nas","kontakt","oferta","usługi","produkty","cennik","galeria","aktualności","news","blog","pomoc","faq","regulamin","polityka prywatności","cookies"];x=b.filter((function(t){return a.includes(t.toLowerCase())})).length;if(x>=2){return[2,"pl"]}v.label=1;case 1:v.trys.push([1,3,,4]);return[4,this.detectLanguageWithGoogleTranslate(a.substring(0,1e3))];case 2:d=v.sent();if(d){if(d==="pl")return[2,"pl"];if(d==="en")return[2,"en"]}return[3,4];case 3:l=v.sent();console.error("Error detecting language with online translation:",l);return[3,4];case 4:u=document.documentElement.lang;if(u){g=u.toLowerCase().split("-")[0];if(g==="pl")return[2,"pl"];if(g==="en")return[2,"en"]}return[2,"en"];case 5:p=v.sent();return[2,"en"];case 6:return[2]}}))}))};t.prototype.detectLanguageWithGoogleTranslate=function(t){return __awaiter(this,void 0,void 0,(function(){var r,e,a,i;return __generator(this,(function(n){switch(n.label){case 0:n.trys.push([0,3,,4]);return[4,fetch("https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=en&dt=t&q=".concat(encodeURIComponent(t)))];case 1:r=n.sent();if(!r.ok){throw new Error("Google Translate API request failed")}return[4,r.json()];case 2:e=n.sent();a=e[2];return[2,a];case 3:i=n.sent();return[2,null];case 4:return[2]}}))}))};t.prototype.applyConfig=function(t,r){if(r===void 0){r="auto"}this.currentTheme=r;var e=this.resolveTheme(r);var a=e==="dark"?t.dark_mode:t.light_mode;if(a){this.applyColorConfig(a)}};t.prototype.applyColorConfig=function(t){var r=this;var e={"--bcx-primary":t.primary_color,"--bcx-secondary":t.secondary_color,"--bcx-background":t.background_color,"--bcx-text":t.text_color};Object.entries(e).forEach((function(t){var e=t[0],a=t[1];if(a){r.hostElement.style.setProperty(e,a)}}))};t.prototype.resolveTheme=function(t){if(t==="auto"){return this.detectWebsiteColorScheme()}return t};t.prototype.detectWebsiteColorScheme=function(){try{var t=this.detectCSSTheme();if(t)return t;var r=this.detectDataTheme();if(r)return r;var e=this.detectClassTheme();if(e)return e;var a=this.detectMetaTheme();if(a)return a;var i=this.detectComputedTheme();if(i)return i;return"light"}catch(t){return"light"}};t.prototype.detectCSSTheme=function(){var t=document.documentElement;var r=window.getComputedStyle(t);var e=["--color-scheme","--theme","--mode","--color-mode","--dark-mode","--light-mode","--app-theme","--ui-theme"];for(var a=0,i=e;a<i.length;a++){var n=i[a];var o=r.getPropertyValue(n).trim();if(o){if(o.includes("dark")||o==="dark")return"dark";if(o.includes("light")||o==="light")return"light"}}var s=["--bg-color","--background-color","--primary-bg","--surface-color"];for(var c=0,b=s;c<b.length;c++){var n=b[c];var o=r.getPropertyValue(n).trim();if(o){if(this.isDarkColor(o))return"dark";if(this.isLightColor(o))return"light"}}return null};t.prototype.detectDataTheme=function(){var t=[document.documentElement,document.body];var r=["data-theme","data-mode","data-color-scheme","data-color-mode"];for(var e=0,a=t;e<a.length;e++){var i=a[e];if(!i)continue;for(var n=0,o=r;n<o.length;n++){var s=o[n];var c=i.getAttribute(s);if(c){if(c.includes("dark")||c==="dark")return"dark";if(c.includes("light")||c==="light")return"light"}}}return null};t.prototype.detectClassTheme=function(){var t=[document.documentElement,document.body];var r=["dark","dark-mode","theme-dark","dark-theme","is-dark","dark-theme","night-mode"];for(var e=0,a=t;e<a.length;e++){var i=a[e];if(!i)continue;var n=i.classList;for(var o=0,s=r;o<s.length;o++){var c=s[o];if(n.contains(c))return"dark"}}return null};t.prototype.detectMetaTheme=function(){var t=document.querySelector('meta[name="theme-color"]');if(t){var r=t.getAttribute("content");if(r&&this.isDarkColor(r))return"dark";if(r&&this.isLightColor(r))return"light"}return null};t.prototype.detectComputedTheme=function(){try{var t=document.body;if(!t)return null;var r=window.getComputedStyle(t);var e=r.backgroundColor;var a=r.color;if(!e||e==="rgba(0, 0, 0, 0)"||!a)return null;var i=this.isDarkColor(e);var n=this.isDarkColor(a);if(i&&!n)return"dark";if(!i&&n)return"light";return null}catch(t){return null}};t.prototype.isDarkColor=function(t){try{var r=this.parseColor(t);if(!r)return false;var e=(.299*r.r+.587*r.g+.114*r.b)/255;return e<.5}catch(t){return false}};t.prototype.isLightColor=function(t){try{var r=this.parseColor(t);if(!r)return false;var e=(.299*r.r+.587*r.g+.114*r.b)/255;return e>.7}catch(t){return false}};t.prototype.parseColor=function(t){t=t.trim();if(t.startsWith("#")){var r=t.slice(1);if(r.length===3){return{r:parseInt(r[0]+r[0],16),g:parseInt(r[1]+r[1],16),b:parseInt(r[2]+r[2],16)}}else if(r.length===6){return{r:parseInt(r.slice(0,2),16),g:parseInt(r.slice(2,4),16),b:parseInt(r.slice(4,6),16)}}}var e=t.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);if(e){return{r:parseInt(e[1]),g:parseInt(e[2]),b:parseInt(e[3])}}var a=t.match(/hsla?\((\d+),\s*(\d+)%,\s*(\d+)%/);if(a){var i=parseInt(a[1])/360;var n=parseInt(a[2])/100;var o=parseInt(a[3])/100;var s=function(t,r,e){if(e<0)e+=1;if(e>1)e-=1;if(e<1/6)return t+(r-t)*6*e;if(e<1/2)return r;if(e<2/3)return t+(r-t)*(2/3-e)*6;return t};var c=o<.5?o*(1+n):o+n-o*n;var b=2*o-c;return{r:Math.round(s(b,c,i+1/3)*255),g:Math.round(s(b,c,i)*255),b:Math.round(s(b,c,i-1/3)*255)}}return null};t.prototype.setDefaultTheme=function(){var t=this;var r={"--bcx-primary":"#007bff","--bcx-secondary":"#6c757d","--bcx-background":"#ffffff","--bcx-text":"#212529","--bcx-border":"#dee2e6","--bcx-shadow":"rgba(0, 0, 0, 0.1)","--bcx-success":"#28a745","--bcx-warning":"#ffc107","--bcx-error":"#dc3545","--bcx-info":"#17a2b8"};Object.entries(r).forEach((function(r){var e=r[0],a=r[1];t.hostElement.style.setProperty(e,a)}));Object.entries(r).forEach((function(t){var r=t[0],e=t[1];document.documentElement.style.setProperty(r,e)}))};t.prototype.applyCustomProperties=function(t){var r=this;Object.entries(t).forEach((function(t){var e=t[0],a=t[1];r.hostElement.style.setProperty(e,a)}))};t.prototype.watchSystemTheme=function(t){var r=window.matchMedia("(prefers-color-scheme: dark)");var e=function(r){t(r.matches?"dark":"light")};r.addEventListener("change",e);return function(){r.removeEventListener("change",e)}};t.prototype.watchWebsiteTheme=function(t){var r=this;if(typeof MutationObserver==="undefined"){return function(){}}var e=[];var a=function(){var a=[document.documentElement,document.body];var i=new MutationObserver((function(e){e.forEach((function(e){if(e.type==="attributes"&&e.attributeName==="class"){var a=r.detectWebsiteColorScheme();t(a)}}))}));a.forEach((function(t){if(t){i.observe(t,{attributes:true,attributeFilter:["class"]})}}));e.push((function(){return i.disconnect()}))};var i=function(){var a=[document.documentElement,document.body];var i=new MutationObserver((function(e){e.forEach((function(e){if(e.type==="attributes"&&["data-theme","data-mode","data-color-scheme"].includes(e.attributeName)){var a=r.detectWebsiteColorScheme();t(a)}}))}));a.forEach((function(t){if(t){i.observe(t,{attributes:true,attributeFilter:["data-theme","data-mode","data-color-scheme"]})}}));e.push((function(){return i.disconnect()}))};var n=function(){var a=document.documentElement;var i=new MutationObserver((function(e){e.forEach((function(e){if(e.type==="attributes"&&e.attributeName==="style"){var a=r.detectWebsiteColorScheme();t(a)}}))}));if(a){i.observe(a,{attributes:true,attributeFilter:["style"]})}e.push((function(){return i.disconnect()}))};a();i();n();return function(){e.forEach((function(t){return t()}))}};t.prototype.getCurrentDetectedTheme=function(){return this.detectWebsiteColorScheme()};t.prototype.getCurrentTheme=function(){return this.currentTheme==="auto"?this.detectWebsiteColorScheme():this.currentTheme};return t}();var bettercxWidgetCss=':host{--bcx-widget-size:60px;--bcx-widget-chat-width:400px;--bcx-widget-chat-height:640px;--bcx-widget-border-radius:20px;--bcx-widget-shadow:0 20px 60px rgba(0, 0, 0, 0.08), 0 8px 25px rgba(0, 0, 0, 0.04);--bcx-widget-shadow-hover:0 25px 80px rgba(0, 0, 0, 0.12), 0 12px 35px rgba(0, 0, 0, 0.06);--bcx-widget-shadow-active:0 15px 40px rgba(0, 0, 0, 0.1), 0 6px 20px rgba(0, 0, 0, 0.05);--bcx-primary:#007bff;--bcx-background:#ffffff;--bcx-text:#212529;--bcx-primary-50:color-mix(in srgb, var(--bcx-primary) 5%, var(--bcx-background));--bcx-primary-100:color-mix(in srgb, var(--bcx-primary) 10%, var(--bcx-background));--bcx-primary-200:color-mix(in srgb, var(--bcx-primary) 20%, var(--bcx-background));--bcx-primary-300:color-mix(in srgb, var(--bcx-primary) 30%, var(--bcx-background));--bcx-primary-400:color-mix(in srgb, var(--bcx-primary) 40%, var(--bcx-background));--bcx-primary-500:var(--bcx-primary);--bcx-primary-600:color-mix(in srgb, var(--bcx-primary) 80%, #000000);--bcx-primary-700:color-mix(in srgb, var(--bcx-primary) 70%, #000000);--bcx-primary-800:color-mix(in srgb, var(--bcx-primary) 60%, #000000);--bcx-primary-900:color-mix(in srgb, var(--bcx-primary) 50%, #000000);--bcx-text-primary:var(--bcx-text);--bcx-text-secondary:color-mix(in srgb, var(--bcx-text) 70%, var(--bcx-background));--bcx-text-tertiary:color-mix(in srgb, var(--bcx-text) 50%, var(--bcx-background));--bcx-text-quaternary:color-mix(in srgb, var(--bcx-text) 30%, var(--bcx-background));--bcx-bg-primary:var(--bcx-background);--bcx-bg-secondary:color-mix(in srgb, var(--bcx-text) 2%, var(--bcx-background));--bcx-bg-tertiary:color-mix(in srgb, var(--bcx-text) 4%, var(--bcx-background));--bcx-bg-elevated:color-mix(in srgb, var(--bcx-background) 95%, #ffffff);--bcx-border-subtle:color-mix(in srgb, var(--bcx-text) 8%, var(--bcx-background));--bcx-border-soft:color-mix(in srgb, var(--bcx-text) 12%, var(--bcx-background));--bcx-border-medium:color-mix(in srgb, var(--bcx-text) 16%, var(--bcx-background));--bcx-space-1:4px;--bcx-space-2:8px;--bcx-space-3:12px;--bcx-space-4:16px;--bcx-space-5:20px;--bcx-space-6:24px;--bcx-space-8:32px;--bcx-space-10:40px;--bcx-space-12:48px;--bcx-space-16:64px;--bcx-text-xs:11px;--bcx-text-sm:12px;--bcx-text-base:14px;--bcx-text-lg:16px;--bcx-text-xl:18px;--bcx-text-2xl:20px;--bcx-radius-sm:6px;--bcx-radius-md:8px;--bcx-radius-lg:12px;--bcx-radius-xl:16px;--bcx-radius-2xl:20px;--bcx-radius-full:9999px;--bcx-transition-fast:150ms cubic-bezier(0.4, 0, 0.2, 1);--bcx-transition-normal:250ms cubic-bezier(0.4, 0, 0.2, 1);--bcx-transition-slow:350ms cubic-bezier(0.4, 0, 0.2, 1);position:fixed;bottom:var(--bcx-space-6);right:var(--bcx-space-6);z-index:9999}:host--left{right:auto !important;left:var(--bcx-space-6) !important}:host{font-family:-apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Helvetica Neue", Arial, sans-serif;font-size:var(--bcx-text-base);line-height:1.5;color:var(--bcx-text-primary);font-weight:400;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}:host(.bcx-widget--left){right:auto !important;left:var(--bcx-space-6) !important}:host(.bcx-widget--left) .bcx-widget__toggle{position:relative;z-index:10}:host(.bcx-widget--left) .bcx-widget__chat{left:0;right:auto}.bcx-widget--loading .bcx-widget__toggle,.bcx-widget--error .bcx-widget__toggle{display:none}.bcx-widget--open .bcx-widget__toggle{-webkit-transform:rotate(180deg);transform:rotate(180deg)}.bcx-widget__toggle{width:var(--bcx-widget-size);height:var(--bcx-widget-size);border:2px solid var(--bcx-bg-elevated);border-radius:var(--bcx-radius-full);background:var(--bcx-primary-500);color:var(--bcx-bg-primary);cursor:pointer;display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;font-size:24px;font-weight:500;-webkit-box-shadow:var(--bcx-widget-shadow);box-shadow:var(--bcx-widget-shadow);-webkit-transition:all var(--bcx-transition-normal);transition:all var(--bcx-transition-normal);position:relative;z-index:1;backdrop-filter:blur(20px);-webkit-backdrop-filter:blur(20px)}.bcx-widget__toggle::before{content:"";position:absolute;inset:0;border-radius:inherit;background:linear-gradient(135deg, color-mix(in srgb, var(--bcx-primary-500) 20%, transparent) 0%, transparent 50%, color-mix(in srgb, var(--bcx-primary-500) 10%, transparent) 100%);opacity:0;-webkit-transition:opacity var(--bcx-transition-fast);transition:opacity var(--bcx-transition-fast)}.bcx-widget__toggle:hover{-webkit-transform:translateY(-2px) scale(1.04);transform:translateY(-2px) scale(1.04);-webkit-box-shadow:var(--bcx-widget-shadow-hover);box-shadow:var(--bcx-widget-shadow-hover);background:var(--bcx-primary-600);border-color:var(--bcx-bg-elevated)}.bcx-widget__toggle:hover::before{opacity:1}.bcx-widget__toggle:focus{outline:none;-webkit-box-shadow:var(--bcx-widget-shadow-hover);box-shadow:var(--bcx-widget-shadow-hover)}.bcx-widget__toggle:active{-webkit-transform:translateY(-1px) scale(1.02);transform:translateY(-1px) scale(1.02);-webkit-box-shadow:var(--bcx-widget-shadow-active);box-shadow:var(--bcx-widget-shadow-active);background:var(--bcx-primary-700)}.bcx-widget__toggle:active::after{content:"";position:absolute;inset:-8px;border-radius:inherit;background:var(--bcx-primary-200);opacity:0.3;-webkit-animation:bcx-ripple 300ms ease-out;animation:bcx-ripple 300ms ease-out}.bcx-widget__toggle-icon{-webkit-transition:-webkit-transform var(--bcx-transition-normal);transition:-webkit-transform var(--bcx-transition-normal);transition:transform var(--bcx-transition-normal);transition:transform var(--bcx-transition-normal), -webkit-transform var(--bcx-transition-normal);-webkit-filter:drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));filter:drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center}.bcx-widget__toggle-icon svg{width:20px;height:20px;stroke-width:2;-webkit-transition:all var(--bcx-transition-fast);transition:all var(--bcx-transition-fast);display:block;-ms-flex-negative:0;flex-shrink:0}.bcx-widget__toggle:hover .bcx-widget__toggle-icon{-webkit-transform:scale(1.1);transform:scale(1.1)}.bcx-widget__toggle:hover .bcx-widget__toggle-icon svg{stroke-width:2.2}.bcx-widget__toggle:active .bcx-widget__toggle-icon{-webkit-transform:scale(0.96);transform:scale(0.96)}.bcx-widget__toggle:active .bcx-widget__toggle-icon svg{stroke-width:1.8}.bcx-widget__chat{position:absolute;bottom:calc(var(--bcx-widget-size) + var(--bcx-space-3));right:0;width:var(--bcx-widget-chat-width);height:var(--bcx-widget-chat-height);background:var(--bcx-bg-elevated);border:1px solid var(--bcx-border-subtle);border-radius:var(--bcx-widget-border-radius);-webkit-box-shadow:var(--bcx-widget-shadow);box-shadow:var(--bcx-widget-shadow);display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;overflow:hidden;-webkit-animation:bcx-slide-up 0.4s cubic-bezier(0.16, 1, 0.3, 1);animation:bcx-slide-up 0.4s cubic-bezier(0.16, 1, 0.3, 1);backdrop-filter:blur(24px);-webkit-backdrop-filter:blur(24px)}.bcx-widget--left .bcx-widget__chat{right:auto !important;left:0 !important}.bcx-widget__chat::before{content:"";position:absolute;inset:0;border-radius:inherit;background:linear-gradient(135deg, color-mix(in srgb, var(--bcx-bg-primary) 50%, transparent) 0%, transparent 50%, color-mix(in srgb, var(--bcx-bg-primary) 30%, transparent) 100%);pointer-events:none}.bcx-widget__header{background:var(--bcx-primary-500);color:var(--bcx-bg-primary);padding:var(--bcx-space-4);display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:justify;justify-content:space-between;-ms-flex-negative:0;flex-shrink:0;border-radius:var(--bcx-widget-border-radius) var(--bcx-widget-border-radius) 0 0;position:relative;z-index:1}.bcx-widget__header::before{content:"";position:absolute;inset:0;background:linear-gradient(135deg, color-mix(in srgb, var(--bcx-primary-500) 80%, transparent) 0%, transparent 50%, color-mix(in srgb, var(--bcx-primary-500) 90%, transparent) 100%);border-radius:inherit;pointer-events:none}.bcx-widget__header h3{margin:0;font-size:var(--bcx-text-lg);font-weight:600;letter-spacing:-0.02em;position:relative;z-index:1;text-shadow:0 1px 2px rgba(0, 0, 0, 0.1)}.bcx-widget__close{background:none;border:none;color:color-mix(in srgb, var(--bcx-bg-primary) 80%, transparent);cursor:pointer;font-size:18px;padding:var(--bcx-space-2);border-radius:var(--bcx-radius-md);-webkit-transition:all var(--bcx-transition-fast);transition:all var(--bcx-transition-fast);display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;width:36px;height:36px;position:relative;z-index:1}.bcx-widget__close svg{width:18px;height:18px;stroke-width:2;-webkit-transition:all var(--bcx-transition-fast);transition:all var(--bcx-transition-fast);display:block;-ms-flex-negative:0;flex-shrink:0}.bcx-widget__close:hover{background:color-mix(in srgb, var(--bcx-bg-primary) 15%, transparent);color:var(--bcx-bg-primary);-webkit-transform:scale(1.1);transform:scale(1.1)}.bcx-widget__close:hover svg{stroke-width:2.2}.bcx-widget__close:focus{outline:none;background:color-mix(in srgb, var(--bcx-bg-primary) 20%, transparent);color:var(--bcx-bg-primary);-webkit-box-shadow:0 0 0 2px color-mix(in srgb, var(--bcx-bg-primary) 30%, transparent);box-shadow:0 0 0 2px color-mix(in srgb, var(--bcx-bg-primary) 30%, transparent)}.bcx-widget__close:focus svg{stroke-width:2.2}.bcx-widget__close:active{-webkit-transform:scale(0.95);transform:scale(0.95)}.bcx-widget__close:active svg{stroke-width:1.8}.bcx-widget__messages{-ms-flex:1;flex:1;overflow-y:auto;padding:var(--bcx-space-4);display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;gap:var(--bcx-space-4);background:var(--bcx-bg-primary);color:var(--bcx-text-primary);scroll-behavior:smooth;scrollbar-width:thin;scrollbar-color:var(--bcx-border-soft) transparent;position:relative}.bcx-widget__messages::-webkit-scrollbar{width:4px}.bcx-widget__messages::-webkit-scrollbar-track{background:transparent}.bcx-widget__messages::-webkit-scrollbar-thumb{background:var(--bcx-border-soft);border-radius:var(--bcx-radius-sm);-webkit-transition:background var(--bcx-transition-fast);transition:background var(--bcx-transition-fast)}.bcx-widget__messages::-webkit-scrollbar-thumb:hover{background:var(--bcx-border-medium)}.bcx-widget__messages::before,.bcx-widget__messages::after{content:"";position:-webkit-sticky;position:sticky;left:0;right:0;height:var(--bcx-space-4);background:-webkit-gradient(linear, left top, left bottom, from(var(--bcx-bg-primary)), to(transparent));background:linear-gradient(to bottom, var(--bcx-bg-primary), transparent);pointer-events:none;z-index:1}.bcx-widget__messages::before{top:0;margin-bottom:calc(-1 * var(--bcx-space-4))}.bcx-widget__messages::after{bottom:0;background:-webkit-gradient(linear, left bottom, left top, from(var(--bcx-bg-primary)), to(transparent));background:linear-gradient(to top, var(--bcx-bg-primary), transparent);margin-top:calc(-1 * var(--bcx-space-4))}.bcx-widget__message{display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;max-width:85%;-webkit-animation:bcx-message-appear 0.3s cubic-bezier(0.16, 1, 0.3, 1);animation:bcx-message-appear 0.3s cubic-bezier(0.16, 1, 0.3, 1)}.bcx-widget__message--user{-ms-flex-item-align:end;align-self:flex-end}.bcx-widget__message--user .bcx-widget__message-content{background:var(--bcx-primary-500);color:var(--bcx-bg-primary);border-radius:var(--bcx-radius-2xl) var(--bcx-radius-2xl) var(--bcx-radius-sm) var(--bcx-radius-2xl);-webkit-box-shadow:0 4px 12px color-mix(in srgb, var(--bcx-primary-500) 25%, transparent), 0 1px 3px color-mix(in srgb, var(--bcx-primary-500) 15%, transparent);box-shadow:0 4px 12px color-mix(in srgb, var(--bcx-primary-500) 25%, transparent), 0 1px 3px color-mix(in srgb, var(--bcx-primary-500) 15%, transparent);text-align:start;position:relative}.bcx-widget__message--user .bcx-widget__message-content::before{content:"";position:absolute;inset:0;border-radius:inherit;background:linear-gradient(135deg, color-mix(in srgb, var(--bcx-primary-500) 20%, transparent) 0%, transparent 50%, color-mix(in srgb, var(--bcx-primary-500) 10%, transparent) 100%);pointer-events:none}.bcx-widget__message--user .bcx-widget__message-time{text-align:right;color:var(--bcx-text-tertiary)}.bcx-widget__message--assistant{-ms-flex-item-align:start;align-self:flex-start}.bcx-widget__message--assistant .bcx-widget__message-content{background:var(--bcx-bg-elevated);color:var(--bcx-text-primary);border-radius:var(--bcx-radius-2xl) var(--bcx-radius-2xl) var(--bcx-radius-2xl) var(--bcx-radius-sm);-webkit-box-shadow:0 2px 8px color-mix(in srgb, var(--bcx-text-primary) 8%, transparent), 0 1px 3px color-mix(in srgb, var(--bcx-text-primary) 4%, transparent);box-shadow:0 2px 8px color-mix(in srgb, var(--bcx-text-primary) 8%, transparent), 0 1px 3px color-mix(in srgb, var(--bcx-text-primary) 4%, transparent);border:1px solid var(--bcx-border-subtle);text-align:left;position:relative}.bcx-widget__message--assistant .bcx-widget__message-time{text-align:left;color:var(--bcx-text-tertiary)}.bcx-widget__message-content{padding:var(--bcx-space-3) var(--bcx-space-4);word-wrap:break-word;white-space:pre-wrap;font-size:var(--bcx-text-base);line-height:1.5;font-weight:400;position:relative;z-index:1}.bcx-widget__message--user .bcx-widget__message-content{color:var(--bcx-bg-primary);text-shadow:0 1px 2px rgba(0, 0, 0, 0.1)}.bcx-widget__message--assistant .bcx-widget__message-content{color:var(--bcx-text-primary)}.bcx-widget__message-time{font-size:var(--bcx-text-xs);margin-top:var(--bcx-space-1);font-weight:500;letter-spacing:0.025em}.bcx-widget__example-questions{padding:var(--bcx-space-4) 0;display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;gap:var(--bcx-space-2);margin-top:var(--bcx-space-2);border-top:1px solid var(--bcx-border-subtle);position:relative}.bcx-widget__example-questions::before{content:"";position:absolute;top:0;left:0;right:0;height:1px;background:-webkit-gradient(linear, left top, right top, from(transparent), color-stop(20%, var(--bcx-border-soft)), color-stop(80%, var(--bcx-border-soft)), to(transparent));background:linear-gradient(90deg, transparent 0%, var(--bcx-border-soft) 20%, var(--bcx-border-soft) 80%, transparent 100%)}.bcx-widget__example-questions-title{font-size:var(--bcx-text-xs);color:var(--bcx-text-tertiary);font-weight:600;margin-bottom:var(--bcx-space-3);text-transform:uppercase;letter-spacing:0.05em;text-align:center;position:relative}.bcx-widget__example-questions-title::after{content:"";position:absolute;bottom:-6px;left:50%;-webkit-transform:translateX(-50%);transform:translateX(-50%);width:24px;height:1px;background:var(--bcx-primary-300)}.bcx-widget__example-question{background:var(--bcx-bg-secondary);border:1px solid var(--bcx-border-subtle);border-radius:var(--bcx-radius-lg);padding:var(--bcx-space-3) var(--bcx-space-4);text-align:left;font-size:var(--bcx-text-sm);color:var(--bcx-text-secondary);cursor:pointer;-webkit-transition:all var(--bcx-transition-normal);transition:all var(--bcx-transition-normal);-webkit-box-shadow:0 1px 3px color-mix(in srgb, var(--bcx-text-primary) 4%, transparent);box-shadow:0 1px 3px color-mix(in srgb, var(--bcx-text-primary) 4%, transparent);word-wrap:break-word;white-space:pre-wrap;position:relative;font-weight:500;line-height:1.4}.bcx-widget__example-question::before{content:"";position:absolute;inset:0;border-radius:inherit;background:linear-gradient(135deg, color-mix(in srgb, var(--bcx-primary-500) 5%, transparent) 0%, transparent 50%, color-mix(in srgb, var(--bcx-primary-500) 3%, transparent) 100%);opacity:0;-webkit-transition:opacity var(--bcx-transition-fast);transition:opacity var(--bcx-transition-fast);pointer-events:none}.bcx-widget__example-question:hover{background:var(--bcx-bg-tertiary);border-color:var(--bcx-primary-200);-webkit-transform:translateY(-2px);transform:translateY(-2px);-webkit-box-shadow:0 4px 12px color-mix(in srgb, var(--bcx-text-primary) 8%, transparent), 0 1px 3px color-mix(in srgb, var(--bcx-text-primary) 4%, transparent);box-shadow:0 4px 12px color-mix(in srgb, var(--bcx-text-primary) 8%, transparent), 0 1px 3px color-mix(in srgb, var(--bcx-text-primary) 4%, transparent);color:var(--bcx-text-primary)}.bcx-widget__example-question:hover::before{opacity:1}.bcx-widget__example-question:active{-webkit-transform:translateY(-1px);transform:translateY(-1px);background:var(--bcx-bg-tertiary);-webkit-box-shadow:0 2px 6px color-mix(in srgb, var(--bcx-text-primary) 6%, transparent);box-shadow:0 2px 6px color-mix(in srgb, var(--bcx-text-primary) 6%, transparent)}.bcx-widget__example-question:focus{outline:none;border-color:var(--bcx-primary-300);-webkit-box-shadow:0 0 0 3px var(--bcx-primary-100);box-shadow:0 0 0 3px var(--bcx-primary-100);color:var(--bcx-text-primary)}.bcx-widget__typing{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;padding:var(--bcx-space-2) 0;-webkit-animation:bcx-typing-appear 0.3s cubic-bezier(0.16, 1, 0.3, 1);animation:bcx-typing-appear 0.3s cubic-bezier(0.16, 1, 0.3, 1)}.bcx-widget__typing-indicator{display:-ms-flexbox;display:flex;gap:var(--bcx-space-1);padding:var(--bcx-space-3) var(--bcx-space-4);background:var(--bcx-bg-elevated);border-radius:var(--bcx-radius-2xl) var(--bcx-radius-2xl) var(--bcx-radius-2xl) var(--bcx-radius-sm);-ms-flex-item-align:start;align-self:flex-start;-webkit-box-shadow:0 2px 8px color-mix(in srgb, var(--bcx-text-primary) 8%, transparent), 0 1px 3px color-mix(in srgb, var(--bcx-text-primary) 4%, transparent);box-shadow:0 2px 8px color-mix(in srgb, var(--bcx-text-primary) 8%, transparent), 0 1px 3px color-mix(in srgb, var(--bcx-text-primary) 4%, transparent);border:1px solid var(--bcx-border-subtle);position:relative}.bcx-widget__typing-indicator span{width:8px;height:8px;border-radius:var(--bcx-radius-full);background:var(--bcx-primary-400);-webkit-animation:bcx-pulse 1.6s ease-in-out infinite both;animation:bcx-pulse 1.6s ease-in-out infinite both;-webkit-box-shadow:0 1px 2px color-mix(in srgb, var(--bcx-primary-500) 20%, transparent);box-shadow:0 1px 2px color-mix(in srgb, var(--bcx-primary-500) 20%, transparent)}.bcx-widget__typing-indicator span:nth-child(1){-webkit-animation-delay:-0.4s;animation-delay:-0.4s}.bcx-widget__typing-indicator span:nth-child(2){-webkit-animation-delay:-0.2s;animation-delay:-0.2s}.bcx-widget__typing-indicator span:nth-child(3){-webkit-animation-delay:0s;animation-delay:0s}.bcx-widget__composer{border-top:1px solid var(--bcx-border-subtle);padding:var(--bcx-space-4);-ms-flex-negative:0;flex-shrink:0;background:var(--bcx-bg-elevated);width:100%;-webkit-box-sizing:border-box;box-sizing:border-box;position:relative}.bcx-widget__composer::before{content:"";position:absolute;top:0;left:0;right:0;height:1px;background:-webkit-gradient(linear, left top, right top, from(transparent), color-stop(20%, var(--bcx-border-soft)), color-stop(80%, var(--bcx-border-soft)), to(transparent));background:linear-gradient(90deg, transparent 0%, var(--bcx-border-soft) 20%, var(--bcx-border-soft) 80%, transparent 100%)}.bcx-widget__composer bcx-message-composer{display:block;width:100%}.bcx-widget__loading{display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;padding:var(--bcx-spacing-xl);color:var(--bcx-text)}.bcx-widget__spinner{width:32px;height:32px;border:3px solid var(--bcx-border);border-top:3px solid var(--bcx-primary);border-radius:50%;-webkit-animation:bcx-spin 1s linear infinite;animation:bcx-spin 1s linear infinite;margin-bottom:var(--bcx-spacing-md)}.bcx-widget__error{display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;padding:var(--bcx-spacing-xl);text-align:center;color:var(--bcx-text);background:var(--bcx-background);border:1px solid var(--bcx-border);border-radius:var(--bcx-widget-border-radius);-webkit-box-shadow:var(--bcx-widget-shadow);box-shadow:var(--bcx-widget-shadow);width:var(--bcx-widget-chat-width);height:var(--bcx-widget-chat-height)}.bcx-widget__error-icon{font-size:48px;margin-bottom:var(--bcx-spacing-md)}.bcx-widget__retry-btn{background:var(--bcx-primary);color:white;border:none;padding:var(--bcx-spacing-sm) var(--bcx-spacing-md);border-radius:var(--bcx-radius-md);cursor:pointer;font-size:var(--bcx-font-size-sm);margin-top:var(--bcx-spacing-md);-webkit-transition:background-color var(--bcx-transition-fast);transition:background-color var(--bcx-transition-fast)}.bcx-widget__retry-btn:hover{background:color-mix(in srgb, var(--bcx-primary) 85%, black)}.bcx-widget__retry-btn:focus{outline:none;-webkit-box-shadow:0 0 0 3px rgba(var(--bcx-primary), 0.3);box-shadow:0 0 0 3px rgba(var(--bcx-primary), 0.3)}@-webkit-keyframes bcx-slide-up{from{opacity:0;-webkit-transform:translateY(24px) scale(0.96);transform:translateY(24px) scale(0.96)}to{opacity:1;-webkit-transform:translateY(0) scale(1);transform:translateY(0) scale(1)}}@keyframes bcx-slide-up{from{opacity:0;-webkit-transform:translateY(24px) scale(0.96);transform:translateY(24px) scale(0.96)}to{opacity:1;-webkit-transform:translateY(0) scale(1);transform:translateY(0) scale(1)}}@-webkit-keyframes bcx-message-appear{from{opacity:0;-webkit-transform:translateY(12px) scale(0.98);transform:translateY(12px) scale(0.98)}to{opacity:1;-webkit-transform:translateY(0) scale(1);transform:translateY(0) scale(1)}}@keyframes bcx-message-appear{from{opacity:0;-webkit-transform:translateY(12px) scale(0.98);transform:translateY(12px) scale(0.98)}to{opacity:1;-webkit-transform:translateY(0) scale(1);transform:translateY(0) scale(1)}}@-webkit-keyframes bcx-typing-appear{from{opacity:0;-webkit-transform:translateY(8px);transform:translateY(8px)}to{opacity:1;-webkit-transform:translateY(0);transform:translateY(0)}}@keyframes bcx-typing-appear{from{opacity:0;-webkit-transform:translateY(8px);transform:translateY(8px)}to{opacity:1;-webkit-transform:translateY(0);transform:translateY(0)}}@-webkit-keyframes bcx-pulse{0%,80%,100%{-webkit-transform:scale(0.8);transform:scale(0.8);opacity:0.4}40%{-webkit-transform:scale(1.1);transform:scale(1.1);opacity:1}}@keyframes bcx-pulse{0%,80%,100%{-webkit-transform:scale(0.8);transform:scale(0.8);opacity:0.4}40%{-webkit-transform:scale(1.1);transform:scale(1.1);opacity:1}}@-webkit-keyframes bcx-ripple{0%{-webkit-transform:scale(0.8);transform:scale(0.8);opacity:0.3}100%{-webkit-transform:scale(1.2);transform:scale(1.2);opacity:0}}@keyframes bcx-ripple{0%{-webkit-transform:scale(0.8);transform:scale(0.8);opacity:0.3}100%{-webkit-transform:scale(1.2);transform:scale(1.2);opacity:0}}@-webkit-keyframes bcx-spin{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@keyframes bcx-spin{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@media (max-width: 768px){:host{--bcx-widget-chat-width:calc(100vw - 32px);--bcx-widget-chat-height:calc(100vh - 120px);bottom:var(--bcx-space-4);right:var(--bcx-space-4);left:var(--bcx-space-4)}.bcx-widget__chat{width:var(--bcx-widget-chat-width) !important;height:var(--bcx-widget-chat-height) !important;left:0 !important;right:0 !important;bottom:calc(var(--bcx-widget-size) + var(--bcx-space-3)) !important;top:auto !important;position:absolute !important;border-radius:var(--bcx-widget-border-radius) !important;margin:0 !important;-webkit-box-shadow:var(--bcx-widget-shadow) !important;box-shadow:var(--bcx-widget-shadow) !important}.bcx-widget__toggle{position:absolute !important;bottom:0 !important;z-index:10 !important}:host(.bcx-widget--left){right:auto !important;left:var(--bcx-space-4) !important}:host(.bcx-widget--left) .bcx-widget__toggle{right:auto !important;left:0 !important}:host(.bcx-widget--left) .bcx-widget__chat{right:auto !important;left:0 !important}:host(.bcx-widget--right){right:var(--bcx-space-4) !important;left:auto !important}:host(.bcx-widget--right) .bcx-widget__toggle{right:0 !important;left:auto !important}:host(.bcx-widget--right) .bcx-widget__chat{right:0 !important;left:auto !important}}@media (max-width: 480px){:host{--bcx-widget-chat-width:calc(100vw - 24px);--bcx-widget-chat-height:calc(100vh - 100px);bottom:var(--bcx-space-3);right:var(--bcx-space-3);left:var(--bcx-space-3)}.bcx-widget__chat{width:var(--bcx-widget-chat-width) !important;height:var(--bcx-widget-chat-height) !important;left:0 !important;right:0 !important;bottom:calc(var(--bcx-widget-size) + var(--bcx-space-2)) !important;top:auto !important;position:absolute !important;border-radius:var(--bcx-widget-border-radius) !important;margin:0 !important;-webkit-box-shadow:var(--bcx-widget-shadow) !important;box-shadow:var(--bcx-widget-shadow) !important}.bcx-widget__toggle{position:absolute !important;bottom:0 !important;z-index:10 !important}:host(.bcx-widget--left){right:auto !important;left:var(--bcx-space-3) !important}:host(.bcx-widget--left) .bcx-widget__toggle{right:auto !important;left:0 !important}:host(.bcx-widget--left) .bcx-widget__chat{right:auto !important;left:0 !important}:host(.bcx-widget--right){right:var(--bcx-space-3) !important;left:auto !important}:host(.bcx-widget--right) .bcx-widget__toggle{right:0 !important;left:auto !important}:host(.bcx-widget--right) .bcx-widget__chat{right:0 !important;left:auto !important}}@media (prefers-contrast: high){:host{--bcx-border:#000000;--bcx-shadow:rgba(0, 0, 0, 0.5)}}@media (prefers-reduced-motion: reduce){.bcx-widget__toggle,.bcx-widget__toggle-icon,.bcx-widget__close,.bcx-widget__retry-btn{-webkit-transition:none;transition:none}.bcx-widget__chat{-webkit-animation:none;animation:none}.bcx-widget__spinner,.bcx-widget__typing-indicator span{-webkit-animation:none;animation:none}}';var BetterCXWidget=function(){function t(t){var r=this;this.theme="auto";this.debug=false;this.baseUrl="https://dev-api.bettercx.ai";this.aiServiceUrl="https://dev-ai.bettercx.ai";this.autoInit=true;this.position="right";this.state={isOpen:false,isAuthenticated:false,isLoading:true,messages:[],isTyping:false};this.language="en";this.handleToggleClick=function(){if(r.state.isOpen){r.close()}else{r.open()}};this.handleMessageSubmit=function(t){r.sendMessage(t.detail)};this.handleExampleQuestionClick=function(t){var e={content:t.question_text,author:"user",timestamp:(new Date).toISOString(),id:r.generateId()};r.setState({messages:__spreadArray(__spreadArray([],r.state.messages,true),[e],false)});r.simulateTypingResponse(t.answer_text)};registerInstance(this,t);this.widgetEvent=createEvent(this,"widgetEvent")}Object.defineProperty(t.prototype,"el",{get:function(){return getElement(this)},enumerable:false,configurable:true});t.prototype.onPublicKeyChange=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){switch(t.label){case 0:if(!this.publicKey)return[3,2];return[4,this.initialize()];case 1:t.sent();t.label=2;case 2:return[2]}}))}))};t.prototype.componentWillLoad=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){switch(t.label){case 0:if(!(this.publicKey&&this.autoInit))return[3,2];return[4,this.initialize()];case 1:t.sent();t.label=2;case 2:return[2]}}))}))};t.prototype.componentDidLoad=function(){return __awaiter(this,void 0,void 0,(function(){var t=this;return __generator(this,(function(r){if(this.themeService){this.themeService.watchWebsiteTheme((function(){t.themeService.setDefaultTheme()}))}return[2]}))}))};t.prototype.initialize=function(){return __awaiter(this,void 0,void 0,(function(){var t,r,e,a;return __generator(this,(function(i){switch(i.label){case 0:if(!this.publicKey){this.setState({isLoading:false,isAuthenticated:false});return[2]}i.label=1;case 1:i.trys.push([1,4,,5]);this.setState({isLoading:true,error:undefined});this.authService=new AuthService(this.baseUrl);t=window.location.origin;return[4,this.authService.createSession(this.publicKey,t)];case 2:r=i.sent();this.apiService=new ApiService(this.baseUrl,this.aiServiceUrl,this.authService);this.themeService=new ThemeService(this.el);e=this;return[4,this.themeService.detectWebsiteLanguage()];case 3:e.language=i.sent();this.themeService.setDefaultTheme();if("attrs"in r&&r.attrs){this.applyCustomColors(r.attrs);this.applyColorsToMessageComposer()}this.setState({isAuthenticated:true,exampleQuestions:"example_questions"in r?r.example_questions:[]});this.emitEvent("session-created",{origin:t});this.setState({isLoading:false});this.setState({isOpen:false});return[3,5];case 4:a=i.sent();this.setState({isLoading:false,isAuthenticated:false});this.emitEvent("error",{error:a.message});return[3,5];case 5:return[2]}}))}))};t.prototype.open=function(){return __awaiter(this,void 0,void 0,(function(){var t=this;return __generator(this,(function(r){if(this.state.isAuthenticated){this.setState({isOpen:true});this.emitEvent("opened");this.applyColorsToMessageComposer();setTimeout((function(){t.scrollToBottom(false)}),100)}return[2]}))}))};t.prototype.close=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){this.setState({isOpen:false});this.emitEvent("closed");return[2]}))}))};t.prototype.toggle=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){switch(t.label){case 0:if(!this.state.isOpen)return[3,2];return[4,this.close()];case 1:t.sent();return[3,4];case 2:return[4,this.open()];case 3:t.sent();t.label=4;case 4:return[2]}}))}))};t.prototype.sendMessage=function(t){return __awaiter(this,void 0,void 0,(function(){var r,e,a,i,n,o,s,c,b,x,d;var l=this;var u,g,p,m;return __generator(this,(function(f){switch(f.label){case 0:if(!this.state.isAuthenticated||!t.trim()){return[2]}r={content:t.trim(),author:"user",timestamp:(new Date).toISOString(),id:this.generateId()};this.setState({messages:__spreadArray(__spreadArray([],this.state.messages,true),[r],false),isTyping:true});setTimeout((function(){l.scrollToBottom(true)}),50);this.emitEvent("message-sent",r);f.label=1;case 1:f.trys.push([1,17,18,19]);return[4,this.apiService.sendMessage(t)];case 2:e=f.sent();if(!e)return[3,16];a=null;i=false;return[4,this.apiService.parseStreamResponse(e)];case 3:n=f.sent();f.label=4;case 4:f.trys.push([4,9,10,15]);o=true,s=__asyncValues(n);f.label=5;case 5:return[4,s.next()];case 6:if(!(c=f.sent(),u=c.done,!u))return[3,8];m=c.value;o=false;b=m;if(b.type==="streaming_output"){if(!i){a={content:"",author:"assistant",timestamp:(new Date).toISOString(),id:this.generateId()};this.setState({messages:__spreadArray(__spreadArray([],this.state.messages,true),[a],false),isTyping:false});i=true}if(a){a.content+=b.content;this.setState({messages:__spreadArray(__spreadArray([],this.state.messages.slice(0,-1),true),[__assign({},a)],false)})}}else{if(!i){this.setState({isTyping:true})}}f.label=7;case 7:o=true;return[3,5];case 8:return[3,15];case 9:x=f.sent();g={error:x};return[3,15];case 10:f.trys.push([10,,13,14]);if(!(!o&&!u&&(p=s.return)))return[3,12];return[4,p.call(s)];case 11:f.sent();f.label=12;case 12:return[3,14];case 13:if(g)throw g.error;return[7];case 14:return[7];case 15:if(a){this.emitEvent("message-received",a)}f.label=16;case 16:return[3,19];case 17:d=f.sent();this.setState({error:"Failed to send message"});this.emitEvent("error",{error:d.message});return[3,19];case 18:this.setState({isTyping:false});return[7];case 19:return[2]}}))}))};t.prototype.setState=function(t){var r=this;var e=this.state.messages;this.state=__assign(__assign({},this.state),t);if(t.messages&&t.messages!==e){setTimeout((function(){r.scrollToBottom(true)}),0)}};t.prototype.emitEvent=function(t,r){var e={type:t,data:r,timestamp:(new Date).toISOString()};this.widgetEvent.emit(e)};t.prototype.generateId=function(){return Math.random().toString(36).substr(2,9)};t.prototype.getTranslation=function(t){var r,e;