/* ─── AI Chat Widget ────────────────────────────────────────────────────── */

#ai-chat-widget {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 9999;
  font-family: 'Open Sans', sans-serif;
}

/* Toggle button */
#ai-chat-toggle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4A00E0, #8E2DE2);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(74, 0, 224, 0.5);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  margin-left: auto;
}

#ai-chat-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 26px rgba(74, 0, 224, 0.7);
}

#ai-chat-toggle i {
  color: #fff;
  font-size: 22px;
}

#ai-chat-toggle .ai-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 14px;
  height: 14px;
  background: #00e676;
  border-radius: 50%;
  border: 2px solid #171C32;
}

/* Chat panel */
#ai-chat-panel {
  display: none;
  width: 340px;
  border-radius: 16px;
  overflow: hidden;
  background: #1a2040;
  border: 1px solid rgba(142, 45, 226, 0.3);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  margin-bottom: 12px;
}

/* Header */
#ai-chat-header {
  background: linear-gradient(135deg, #4A00E0, #8E2DE2);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#ai-chat-header .ai-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

#ai-chat-header .ai-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
}

#ai-chat-header .ai-avatar i {
  color: #fff;
  font-size: 16px;
}

#ai-chat-header .ai-title {
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  margin: 0;
  text-transform: none;
  letter-spacing: 0;
}

#ai-chat-header .ai-subtitle {
  color: rgba(255, 255, 255, 0.7);
  font-size: 11px;
  margin: 0;
}

#ai-chat-close {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  padding: 4px;
  font-size: 16px;
  line-height: 1;
  transition: color 0.2s;
}

#ai-chat-close:hover {
  color: #fff;
}

/* Messages area */
#ai-chat-messages {
  height: 320px;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(142, 45, 226, 0.4) transparent;
}

#ai-chat-messages::-webkit-scrollbar {
  width: 4px;
}

#ai-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

#ai-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(142, 45, 226, 0.4);
  border-radius: 4px;
}

/* Bubbles */
.ai-bubble {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.55;
  word-break: break-word;
}

.ai-bubble.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #4A00E0, #8E2DE2);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ai-bubble.assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.07);
  color: #e0e0e0;
  border-bottom-left-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

/* Typing indicator */
.ai-typing {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  padding: 10px 16px;
  display: flex;
  gap: 5px;
  align-items: center;
}

.ai-typing span {
  width: 7px;
  height: 7px;
  background: #8E2DE2;
  border-radius: 50%;
  display: inline-block;
  animation: aiTypingBounce 1.2s infinite ease-in-out;
}

.ai-typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes aiTypingBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40%           { transform: translateY(-5px); opacity: 1; }
}

/* Input area */
#ai-chat-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  background: #151a35;
}

#ai-chat-input {
  flex: 1;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 24px;
  padding: 9px 16px;
  color: #fff;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
  resize: none;
  font-family: 'Open Sans', sans-serif;
}

#ai-chat-input::placeholder {
  color: rgba(255, 255, 255, 0.35);
}

#ai-chat-input:focus {
  border-color: rgba(142, 45, 226, 0.6);
}

#ai-chat-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4A00E0, #8E2DE2);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s, transform 0.2s;
}

#ai-chat-send:hover {
  opacity: 0.9;
  transform: scale(1.05);
}

#ai-chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

#ai-chat-send i {
  color: #fff;
  font-size: 14px;
}

/* Error state */
.ai-bubble.error {
  align-self: flex-start;
  background: rgba(220, 53, 69, 0.15);
  color: #ff6b6b;
  border: 1px solid rgba(220, 53, 69, 0.3);
  font-size: 12.5px;
}

/* Rate limit warning */
#ai-chat-ratelimit {
  display: none;
  text-align: center;
  color: rgba(255, 200, 100, 0.8);
  font-size: 11.5px;
  padding: 4px 14px 10px;
  background: #151a35;
}

/* Responsive — shift up on mobile to avoid overlap with mobile nav */
@media (max-width: 576px) {
  #ai-chat-widget {
    bottom: 20px;
    right: 16px;
  }

  #ai-chat-panel {
    width: calc(100vw - 32px);
  }
}
