:root{
  --keai-bg:#0a0c10;
  --keai-card:#12151c;
  --keai-text:#f0f4f8;
  --keai-muted:#8b96a5;
  --keai-line:rgba(255,255,255,.08);
  --keai-accent:#f28c1b;
  --keai-accent-light:#ffa940;
  --keai-primary-dark:#d97706;
  --keai-shadow:0 20px 60px rgba(0,0,0,.5), 0 0 100px rgba(242,140,27,.08);
  --keai-radius:16px;
  --keai-glow:0 0 20px rgba(242,140,27,.3);
}

/* Root mount (scoped) */
.keai-root{
  position:fixed;
  right:20px;
  bottom:20px;
  z-index:9999;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color:var(--keai-text);
  display:flex;
  flex-direction:column;
  align-items:flex-end;
  gap:16px;
}

.keai-stack{
  position:relative;
  display:flex;
  flex-direction:column;
  align-items:flex-end;
  gap:0;
  width:68px;
}

.keai-toggle{
  width:68px;
  height:68px;
  border-radius:50%;
  border:none;
  background:linear-gradient(135deg, var(--keai-accent) 0%, var(--keai-accent-light) 100%);
  box-shadow:0 8px 24px rgba(242,140,27,.35), 0 0 40px rgba(242,140,27,.15);
  cursor:pointer;
  position:relative;
  overflow:visible;
  flex-shrink:0;
  padding:0;
  outline:none;
  margin-bottom:-8px;
  user-select:none;
  transition:transform .25s cubic-bezier(0.34,1.56,0.64,1), box-shadow .25s;
}
.keai-toggle:hover{
  transform:scale(1.08) translateY(-2px);
  box-shadow:0 12px 32px rgba(242,140,27,.45), 0 0 50px rgba(242,140,27,.25);
}
.keai-toggle:active{
  transform:scale(0.95);
}
.keai-toggle:focus{outline:none;}
.keai-toggle-chat,
.keai-toggle-close{
  width:68px;
  height:68px;
  display:block;
  object-fit:contain;
  pointer-events:none;
  transform:scale(1.6);
  filter:drop-shadow(0 2px 4px rgba(0,0,0,.2));
}
.keai-toggle-close{
  display:none;
}
.keai-toggle[data-open="true"]{
  background:linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  box-shadow:0 8px 24px rgba(0,0,0,.4);
}
.keai-toggle[data-open="true"]:hover{
  transform:scale(1.08) translateY(-2px);
}
.keai-toggle[data-open="true"] .keai-toggle-chat{
  display:none;
}
.keai-toggle[data-open="true"] .keai-toggle-close{
  display:block;
}

.keai-panel{
  position:absolute;
  right:0;
  bottom:90px;
  width:440px;
  max-width:calc(100vw - 40px);
  height:640px;
  max-height:calc(100vh - 140px);
  border-radius:var(--keai-radius);
  border:1px solid rgba(242,140,27,.15);
  background:linear-gradient(165deg, rgba(18,21,28,.98) 0%, rgba(10,12,16,.98) 100%);
  backdrop-filter:blur(24px) saturate(180%);
  box-shadow:var(--keai-shadow);
  overflow:hidden;
  display:none;
  opacity:0;
  transform:translateY(20px) scale(0.95);
  transition:opacity .3s cubic-bezier(0.34,1.56,0.64,1), transform .3s cubic-bezier(0.34,1.56,0.64,1);
}
.keai-panel[data-open="true"]{
  display:flex;
  flex-direction:column;
  opacity:1;
  transform:translateY(0) scale(1);
}
.keai-panel::before{
  content:"";
  position:absolute;
  top:0;
  left:0;
  right:0;
  height:1px;
  background:linear-gradient(90deg, transparent, var(--keai-accent), transparent);
  opacity:0.5;
}

.keai-head{
  padding:20px 20px;
  display:flex;
  align-items:center;
  justify-content:center;
  border-bottom:1px solid rgba(242,140,27,.12);
  background:linear-gradient(180deg, rgba(242,140,27,.04) 0%, transparent 100%);
  position:relative;
}
.keai-head::after{
  content:"";
  position:absolute;
  bottom:-1px;
  left:50%;
  transform:translateX(-50%);
  width:120px;
  height:1px;
  background:linear-gradient(90deg, transparent, var(--keai-accent), transparent);
  opacity:0.6;
}
.keai-title{
  display:flex;
  align-items:center;
  justify-content:center;
  gap:10px;
}
.keai-title strong{
  font-family:"Montserrat","Inter",system-ui,-apple-system,sans-serif;
  font-size:18px;
  font-weight:800;
  letter-spacing:0.5px;
  background:linear-gradient(135deg, var(--keai-text) 0%, var(--keai-accent-light) 100%);
  -webkit-background-clip:text;
  -webkit-text-fill-color:transparent;
  background-clip:text;
  text-shadow:0 0 20px rgba(242,140,27,.2);
}
.keai-actions{display:flex;gap:8px;align-items:center;}
.keai-btn{
  border:1px solid rgba(242,140,27,.25);
  background:rgba(242,140,27,.08);
  color:var(--keai-text);
  border-radius:12px;
  font-size:13px;
  padding:10px 14px;
  cursor:pointer;
  transition:all .2s;
  font-weight:500;
}
.keai-btn:hover{
  background:rgba(242,140,27,.15);
  border-color:rgba(242,140,27,.4);
  transform:translateY(-1px);
}
.keai-btn:focus{outline:2px solid rgba(242,140,27,.5);outline-offset:2px;}

.keai-chat{
  flex:1;
  overflow:auto;
  padding:16px;
  display:flex;
  flex-direction:column;
  gap:14px;
  background:linear-gradient(180deg, rgba(242,140,27,.01) 0%, transparent 15%);
}
.keai-chat::-webkit-scrollbar{
  width:8px;
}
.keai-chat::-webkit-scrollbar-track{
  background:rgba(255,255,255,.02);
  border-radius:10px;
}
.keai-chat::-webkit-scrollbar-thumb{
  background:rgba(242,140,27,.3);
  border-radius:10px;
  border:2px solid transparent;
  background-clip:padding-box;
}
.keai-chat::-webkit-scrollbar-thumb:hover{
  background:rgba(242,140,27,.5);
  background-clip:padding-box;
}

.keai-msg{
  display:flex;
  flex-direction:column;
  gap:6px;
  max-width:90%;
  animation:keai-msg-in .3s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes keai-msg-in{
  from{opacity:0;transform:translateY(10px) scale(0.95);}
  to{opacity:1;transform:translateY(0) scale(1);}
}
.keai-msg.keai-user{
  align-self:flex-end;
  max-width:80%;
}
.keai-bubble{
  border:1px solid var(--keai-line);
  border-radius:16px;
  padding:14px 16px;
  font-size:14.5px;
  line-height:1.6;
  white-space:normal;
  word-break:break-word;
  position:relative;
  transition:transform .2s, box-shadow .2s;
}
.keai-bubble:hover{
  transform:translateY(-1px);
}
.keai-user .keai-bubble{
  background:linear-gradient(135deg, rgba(242,140,27,.2) 0%, rgba(242,140,27,.12) 100%);
  border-color:rgba(242,140,27,.3);
  box-shadow:0 4px 16px rgba(242,140,27,.08), inset 0 1px 0 rgba(255,255,255,.1);
}
.keai-assistant .keai-bubble{
  background:linear-gradient(135deg, rgba(30,41,59,.65) 0%, rgba(15,23,42,.65) 100%);
  border-color:rgba(100,116,139,.2);
  box-shadow:0 4px 16px rgba(0,0,0,.15), inset 0 1px 0 rgba(255,255,255,.03);
}
.keai-meta{
  font-size:11px;
  color:var(--keai-muted);
  padding-left:4px;
}

.keai-input{
  border-top:1px solid rgba(242,140,27,.12);
  padding:14px;
  display:flex;
  gap:10px;
  align-items:flex-end;
  background:linear-gradient(180deg, transparent 0%, rgba(242,140,27,.02) 100%);
  position:relative;
}
.keai-input::before{
  content:"";
  position:absolute;
  top:-1px;
  left:50%;
  transform:translateX(-50%);
  width:120px;
  height:1px;
  background:linear-gradient(90deg, transparent, var(--keai-accent), transparent);
  opacity:0.4;
}
.keai-textarea{
  flex:1;
  min-height:46px;
  max-height:120px;
  resize:none;
  border-radius:12px;
  border:1px solid rgba(242,140,27,.2);
  background:rgba(10,12,16,.8);
  color:var(--keai-text);
  padding:12px 14px;
  font-size:14px;
  line-height:1.5;
  font-family:"Inter",system-ui,-apple-system,sans-serif;
  transition:border-color .2s, box-shadow .2s;
  overflow-y:auto;
  scrollbar-width:thin;
  scrollbar-color:rgba(242,140,27,.4) transparent;
}
.keai-textarea::-webkit-scrollbar{
  width:6px;
}
.keai-textarea::-webkit-scrollbar-track{
  background:transparent;
}
.keai-textarea::-webkit-scrollbar-thumb{
  background:rgba(242,140,27,.3);
  border-radius:10px;
  border:1px solid transparent;
  background-clip:padding-box;
}
.keai-textarea::-webkit-scrollbar-thumb:hover{
  background:rgba(242,140,27,.5);
  background-clip:padding-box;
}
.keai-textarea::placeholder{
  color:var(--keai-muted);
  opacity:0.6;
}
.keai-textarea:focus{
  outline:none;
  border-color:var(--keai-accent);
  box-shadow:0 0 0 3px rgba(242,140,27,.15), inset 0 1px 3px rgba(0,0,0,.3);
}
.keai-send{
  border:0;
  background:linear-gradient(135deg, var(--keai-accent) 0%, var(--keai-accent-light) 100%);
  color:#0a0c10;
  font-weight:900;
  border-radius:12px;
  padding:12px;
  cursor:pointer;
  min-width:48px;
  width:48px;
  height:48px;
  display:flex;
  align-items:center;
  justify-content:center;
  transition:transform .2s, box-shadow .2s;
  box-shadow:0 4px 12px rgba(242,140,27,.3), inset 0 1px 0 rgba(255,255,255,.2);
}
.keai-send:hover{
  transform:translateY(-2px);
  box-shadow:0 6px 20px rgba(242,140,27,.45), inset 0 1px 0 rgba(255,255,255,.3);
}
.keai-send:active{
  transform:translateY(0);
}
.keai-send:disabled{
  opacity:.6;
  cursor:not-allowed;
  transform:none;
}
.keai-send-icon{
  width:22px;
  height:22px;
  stroke:currentColor;
  fill:none;
  filter:drop-shadow(0 1px 2px rgba(0,0,0,.2));
}

/* Markdown content styles (scoped) */
.keai-bubble .keai-md{
  color:var(--keai-text);
  line-height:1.6;
  font-size:14.5px;
}
.keai-bubble .keai-md p{margin:0 0 12px;}
.keai-bubble .keai-md p:last-child{margin-bottom:0;}
.keai-bubble .keai-md h1,.keai-bubble .keai-md h2,.keai-bubble .keai-md h3{
  margin:16px 0 10px;
  font-weight:700;
  line-height:1.3;
  color:var(--keai-text);
  letter-spacing:-0.01em;
}
.keai-bubble .keai-md h1{font-size:1.3em;}
.keai-bubble .keai-md h2{
  font-size:1.18em;
  border-bottom:1px solid rgba(242,140,27,.2);
  padding-bottom:6px;
  background:linear-gradient(90deg, var(--keai-accent) 0%, transparent 100%);
  -webkit-background-clip:text;
  -webkit-text-fill-color:transparent;
  background-clip:text;
}
.keai-bubble .keai-md h3{font-size:1.08em;}
.keai-bubble .keai-md strong{
  font-weight:700;
  color:var(--keai-accent-light);
}
.keai-bubble .keai-md a{
  display:inline-block;
  color:#0a0c10;
  background:linear-gradient(135deg, #ffd19c 0%, #f28c1b 100%);
  padding:10px 18px;
  border-radius:12px;
  text-decoration:none;
  font-weight:600;
  font-size:14px;
  margin:6px 8px 6px 0;
  border:1px solid rgba(255,255,255,.25);
  box-shadow:0 4px 12px rgba(242,140,27,.3), inset 0 1px 0 rgba(255,255,255,.3);
  transition:transform .2s, box-shadow .2s;
  position:relative;
}
.keai-bubble .keai-md a::before{
  content:"→";
  position:absolute;
  right:18px;
  opacity:0;
  transition:opacity .2s, right .2s;
}
.keai-bubble .keai-md a:hover{
  transform:translateY(-2px) scale(1.02);
  box-shadow:0 6px 20px rgba(242,140,27,.45), inset 0 1px 0 rgba(255,255,255,.4);
  padding-right:32px;
}
.keai-bubble .keai-md a:hover::before{
  opacity:1;
  right:12px;
}
.keai-bubble .keai-md a:active{
  transform:translateY(0) scale(0.98);
}
.keai-bubble .keai-md ul,.keai-bubble .keai-md ol{
  margin:10px 0 10px 22px;
  padding:0;
}
.keai-bubble .keai-md li{
  margin:6px 0;
  padding-left:4px;
}
.keai-bubble .keai-md li::marker{
  color:var(--keai-accent);
}
.keai-bubble .keai-md code{
  background:rgba(242,140,27,.08);
  border:1px solid rgba(242,140,27,.2);
  padding:3px 8px;
  border-radius:6px;
  font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;
  font-size:13px;
  color:var(--keai-accent-light);
}
.keai-bubble .keai-md pre{
  background:rgba(0,0,0,.4);
  border:1px solid rgba(242,140,27,.15);
  padding:14px 16px;
  border-radius:12px;
  overflow:auto;
  margin:10px 0;
  box-shadow:inset 0 2px 8px rgba(0,0,0,.3);
}
.keai-bubble .keai-md pre code{
  border:none;
  background:transparent;
  padding:0;
  color:var(--keai-text);
}
.keai-bubble .keai-md blockquote{
  margin:10px 0;
  padding:12px 14px;
  border-left:3px solid var(--keai-accent);
  background:rgba(242,140,27,.08);
  border-radius:0 12px 12px 0;
  font-style:italic;
}
.keai-bubble .keai-md hr{
  border:none;
  border-top:1px solid rgba(242,140,27,.2);
  margin:14px 0;
}

/* Typing animation */
.keai-thinking-bubble{
  background:rgba(30,41,59,.15) !important;
  border-color:rgba(242,140,27,.2) !important;
  box-shadow:0 4px 16px rgba(242,140,27,.08), inset 0 1px 0 rgba(255,255,255,.02) !important;
  backdrop-filter:blur(8px);
}
.keai-typing{
  display:inline-flex;
  gap:5px;
  align-items:center;
  padding:4px 0;
}
.keai-typing-dot{
  width:7px;
  height:7px;
  border-radius:50%;
  background:var(--keai-accent);
  box-shadow:0 0 8px rgba(242,140,27,.4);
  animation:keai-typing-bounce 1.4s infinite ease-in-out;
}
.keai-typing-dot:nth-child(2){animation-delay:.2s;}
.keai-typing-dot:nth-child(3){animation-delay:.4s;}
@keyframes keai-typing-bounce{
  0%,80%,100%{transform:scale(0.7);opacity:.4;}
  40%{transform:scale(1.3);opacity:1;box-shadow:0 0 12px rgba(242,140,27,.6);}
}

.keai-whatsapp{
  width:68px;
  height:68px;
  border-radius:50%;
  border:1px solid rgba(255,255,255,.1);
  background:linear-gradient(135deg, #57d163 0%, #23b33a 100%);
  color:#fff;
  box-shadow:0 8px 24px rgba(35,179,58,.35), 0 0 40px rgba(35,179,58,.15);
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  transition:transform .25s cubic-bezier(0.34,1.56,0.64,1), box-shadow .25s;
}
.keai-whatsapp:hover{
  transform:scale(1.08) translateY(-2px);
  box-shadow:0 12px 32px rgba(35,179,58,.5), 0 0 50px rgba(35,179,58,.25);
}
.keai-whatsapp:active{
  transform:scale(0.95);
}
.keai-whatsapp:focus{outline:2px solid rgba(35,179,58,.6);outline-offset:3px;}
.keai-whatsapp svg{
  width:32px;
  height:32px;
  display:block;
  filter:drop-shadow(0 2px 4px rgba(0,0,0,.2));
}

@media (max-width:520px){
  .keai-panel{
    width:calc(100vw - 32px);
    right:-8px;
    height:72vh;
    bottom:85px;
  }
  .keai-root{right:16px;bottom:16px;}
  .keai-toggle{width:60px;height:60px;}
  .keai-toggle-chat,.keai-toggle-close{width:60px;height:60px;}
}
