/* === AI BUDDY CHAT WIDGET === */

/* Floating button */
.ai-buddy-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: white;
  box-shadow: 0 4px 20px rgba(16, 185, 129, 0.4), 0 2px 8px rgba(0,0,0,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  animation: ai-buddy-entrance 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.5s both;
}

.ai-buddy-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(16, 185, 129, 0.5), 0 4px 12px rgba(0,0,0,0.15);
}

.ai-buddy-fab:active {
  transform: scale(0.95);
}

.ai-buddy-fab svg {
  width: 28px;
  height: 28px;
  transition: transform 0.3s ease;
}

.ai-buddy-fab.open svg.icon-chat { display: none; }
.ai-buddy-fab:not(.open) svg.icon-close { display: none; }
.ai-buddy-fab.open { background: linear-gradient(135deg, #0c1222 0%, #1e293b 100%); box-shadow: 0 4px 20px rgba(0,0,0,0.3); }

/* Pulse ring on fab */
.ai-buddy-fab::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid rgba(16, 185, 129, 0.4);
  animation: ai-buddy-ping 2s cubic-bezier(0, 0, 0.2, 1) infinite;
}

.ai-buddy-fab.open::after { display: none; }

@keyframes ai-buddy-ping {
  0% { transform: scale(1); opacity: 0.8; }
  75%, 100% { transform: scale(1.5); opacity: 0; }
}

@keyframes ai-buddy-entrance {
  from { opacity: 0; transform: scale(0) translateY(20px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

/* Chat window */
.ai-buddy-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  z-index: 9998;
  width: 400px;
  max-height: 580px;
  background: #ffffff;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15), 0 4px 20px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.95);
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.ai-buddy-window.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Header */
.ai-buddy-header {
  background: linear-gradient(135deg, #0c1222 0%, #1a2332 100%);
  padding: 20px 20px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.ai-buddy-avatar {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #10b981, #059669);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  flex-shrink: 0;
}

.ai-buddy-header-text h3 {
  color: #ffffff;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 0.95rem;
  margin: 0;
  line-height: 1.3;
}

.ai-buddy-header-text p {
  color: #94a3b8;
  font-size: 0.75rem;
  margin: 2px 0 0;
  line-height: 1.3;
}

.ai-buddy-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.ai-buddy-status .status-dot {
  width: 6px;
  height: 6px;
  background: #10b981;
  border-radius: 50%;
  animation: ai-buddy-status-pulse 2s ease-in-out infinite;
}

@keyframes ai-buddy-status-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Context banner */
.ai-buddy-context {
  background: #f0fdf4;
  border-bottom: 1px solid #dcfce7;
  padding: 8px 20px;
  font-size: 0.75rem;
  color: #166534;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.ai-buddy-context svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.ai-buddy-context:empty {
  display: none;
}

/* Messages area */
.ai-buddy-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 280px;
  max-height: 340px;
  scroll-behavior: smooth;
}

.ai-buddy-messages::-webkit-scrollbar {
  width: 4px;
}

.ai-buddy-messages::-webkit-scrollbar-track {
  background: transparent;
}

.ai-buddy-messages::-webkit-scrollbar-thumb {
  background: #e2e8f0;
  border-radius: 4px;
}

/* Message bubbles */
.ai-buddy-msg {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 0.88rem;
  line-height: 1.6;
  word-wrap: break-word;
  animation: ai-buddy-msg-in 0.25s ease-out;
}

@keyframes ai-buddy-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.ai-buddy-msg.bot {
  align-self: flex-start;
  background: #f1f5f9;
  color: #0f172a;
  border-bottom-left-radius: 4px;
}

.ai-buddy-msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  border-bottom-right-radius: 4px;
}

.ai-buddy-msg.bot a {
  color: #10b981;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ai-buddy-msg.bot strong {
  font-weight: 600;
  color: #0f172a;
}

/* RUO disclaimer on bot messages */
.ai-buddy-msg.bot .ruo-tag {
  display: inline-block;
  margin-top: 8px;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #94a3b8;
  padding: 2px 6px;
  background: #e2e8f0;
  border-radius: 3px;
}

/* Typing indicator */
.ai-buddy-typing {
  align-self: flex-start;
  padding: 12px 16px;
  background: #f1f5f9;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 5px;
  align-items: center;
}

.ai-buddy-typing span {
  width: 7px;
  height: 7px;
  background: #94a3b8;
  border-radius: 50%;
  animation: ai-buddy-bounce 1.4s ease-in-out infinite;
}

.ai-buddy-typing span:nth-child(2) { animation-delay: 0.16s; }
.ai-buddy-typing span:nth-child(3) { animation-delay: 0.32s; }

@keyframes ai-buddy-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Quick action chips */
.ai-buddy-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 8px;
  flex-shrink: 0;
}

.ai-buddy-chip {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.78rem;
  font-weight: 500;
  color: #475569;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  font-family: 'Inter', sans-serif;
}

.ai-buddy-chip:hover {
  background: #f0fdf4;
  border-color: #10b981;
  color: #059669;
}

/* Input area */
.ai-buddy-input-area {
  padding: 12px 16px 16px;
  border-top: 1px solid #f1f5f9;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
  background: #ffffff;
}

.ai-buddy-input {
  flex: 1;
  border: 1.5px solid #e2e8f0;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.88rem;
  font-family: 'Inter', sans-serif;
  color: #0f172a;
  background: #f8fafc;
  resize: none;
  min-height: 42px;
  max-height: 100px;
  outline: none;
  transition: border-color 0.2s ease, background 0.2s ease;
  line-height: 1.4;
}

.ai-buddy-input:focus {
  border-color: #10b981;
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.ai-buddy-input::placeholder {
  color: #94a3b8;
}

.ai-buddy-send {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.ai-buddy-send:hover {
  transform: scale(1.05);
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.4);
}

.ai-buddy-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.ai-buddy-send svg {
  width: 18px;
  height: 18px;
}

/* Footer disclaimer */
.ai-buddy-footer {
  padding: 8px 16px 12px;
  text-align: center;
  font-size: 0.65rem;
  color: #94a3b8;
  background: #fafafa;
  border-top: 1px solid #f1f5f9;
  flex-shrink: 0;
}

/* Mobile responsive */
@media (max-width: 480px) {
  .ai-buddy-window {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-height: 100vh;
    border-radius: 20px 20px 0 0;
  }

  .ai-buddy-fab {
    bottom: 16px;
    right: 16px;
    width: 56px;
    height: 56px;
  }

  .ai-buddy-fab svg {
    width: 24px;
    height: 24px;
  }

  .ai-buddy-messages {
    max-height: calc(100vh - 260px);
  }
}

@media (max-width: 768px) {
  .ai-buddy-window {
    width: min(400px, calc(100vw - 16px));
    right: 8px;
    bottom: 84px;
    max-height: calc(100vh - 100px);
  }
}
