/* Chat widget — scoped to #duerp-ai-root so we don't leak into host page */
#duerp-ai-root, #duerp-ai-root * { box-sizing: border-box; }
#duerp-ai-root {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0;
  pointer-events: none; z-index: 2147483000;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

#duerp-ai-root .ai-bubble {
  position: fixed; bottom: 24px; right: 24px;
  width: 60px; height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1e88e5 0%, #1565c0 100%);
  color: white; border: none; cursor: pointer; font-size: 26px;
  box-shadow: 0 8px 24px rgba(21, 101, 192, 0.35);
  pointer-events: auto;
  transition: transform 0.15s;
  z-index: 2;
}
#duerp-ai-root .ai-bubble:hover { transform: scale(1.08); }

#duerp-ai-root .ai-panel {
  position: fixed; top: 0; right: 0;
  width: 420px; height: 100vh;
  background: #f8fafc;
  box-shadow: -6px 0 30px rgba(15, 23, 42, 0.18);
  transform: translateX(100%);
  transition: transform 0.25s;
  display: flex; flex-direction: column;
  pointer-events: auto;
  color: #1f2937;
  font-size: 14px; line-height: 1.45;
}
#duerp-ai-root .ai-panel.open { transform: translateX(0); }

#duerp-ai-root .ai-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(135deg, #1e88e5 0%, #1565c0 100%);
  color: white;
}
#duerp-ai-root .ai-header-left { display: flex; align-items: center; gap: 12px; }
#duerp-ai-root .ai-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: rgba(255,255,255,0.22);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px;
}
#duerp-ai-root .ai-name { font-weight: 600; font-size: 15px; }
#duerp-ai-root .ai-sub { font-size: 11px; opacity: 0.88; margin-top: 1px; }
#duerp-ai-root .ai-icon-btn {
  background: transparent; border: none; color: white; cursor: pointer;
  padding: 6px 10px; border-radius: 6px; font-size: 16px; line-height: 1;
}
#duerp-ai-root .ai-icon-btn:hover { background: rgba(255,255,255,0.15); }

#duerp-ai-root .ai-msgs {
  flex: 1; overflow-y: auto; padding: 16px 14px;
  display: flex; flex-direction: column; gap: 10px;
}

#duerp-ai-root .ai-msg {
  max-width: 88%; padding: 10px 12px;
  border-radius: 12px; word-wrap: break-word; white-space: pre-wrap;
  box-shadow: 0 2px 6px rgba(15,23,42,0.05);
  animation: ai-slide-up 0.18s ease;
}
#duerp-ai-root .ai-msg.assistant {
  align-self: flex-start; background: white; border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
}
#duerp-ai-root .ai-msg.user {
  align-self: flex-end; background: #1565c0; color: white;
  border-bottom-right-radius: 4px;
}
#duerp-ai-root .ai-msg.system {
  align-self: center; background: #e2e8f0; color: #475569;
  font-size: 12px; font-style: italic; padding: 6px 10px;
}
#duerp-ai-root .ai-msg.error {
  align-self: center; background: #fee2e2; color: #991b1b;
  border: 1px solid #fecaca; font-size: 12px;
}
#duerp-ai-root .ai-msg strong { font-weight: 700; }
#duerp-ai-root .ai-msg em { font-style: italic; opacity: 0.85; }
#duerp-ai-root .ai-msg code {
  background: rgba(0,0,0,0.08); padding: 1px 4px; border-radius: 4px;
  font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
#duerp-ai-root .ai-msg ul { margin: 6px 0 0 16px; padding: 0; }
#duerp-ai-root .ai-msg li { margin: 2px 0; }
#duerp-ai-root .ai-typing { display: inline-flex; gap: 4px; align-items: center; }
#duerp-ai-root .ai-typing span {
  width: 6px; height: 6px; border-radius: 50%; background: #94a3b8;
  animation: ai-blink 1.2s infinite ease-in-out both;
}
#duerp-ai-root .ai-typing span:nth-child(2) { animation-delay: 0.2s; }
#duerp-ai-root .ai-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ai-blink { 0%,80%,100% { opacity: 0.25; } 40% { opacity: 1; } }
@keyframes ai-slide-up { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

#duerp-ai-root .ai-chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 0 14px 10px;
}
#duerp-ai-root .ai-chips button {
  background: #e3f2fd; color: #1565c0; border: 1px solid #bbdefb;
  border-radius: 999px; padding: 6px 10px; font-size: 12px; cursor: pointer;
}
#duerp-ai-root .ai-chips button:hover { background: #d1e9fb; }

#duerp-ai-root .ai-composer {
  display: flex; gap: 6px; align-items: flex-end;
  padding: 10px 12px; border-top: 1px solid #e2e8f0; background: white;
}
#duerp-ai-root .ai-composer textarea {
  flex: 1; resize: none; border: 1px solid #e2e8f0; border-radius: 8px;
  padding: 8px 10px; font: inherit; line-height: 1.4; max-height: 140px;
  outline: none; color: #1f2937; background: white;
}
#duerp-ai-root .ai-composer textarea:focus {
  border-color: #1565c0; box-shadow: 0 0 0 3px #e3f2fd;
}
#duerp-ai-root .ai-composer button {
  width: 40px; height: 40px; border: none; background: #1565c0;
  color: white; border-radius: 8px; cursor: pointer; font-size: 14px;
  flex-shrink: 0;
}
#duerp-ai-root .ai-composer button:disabled { opacity: 0.4; cursor: not-allowed; }

#duerp-ai-root .ai-footer {
  display: flex; justify-content: space-between;
  font-size: 10px; color: #94a3b8; padding: 6px 14px;
  background: white; border-top: 1px solid #e2e8f0;
}
