/* Brain Chat Widget Styles */
#brain-chat-widget {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 99999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Arial, sans-serif;
  color: #1f2937;
}

#brain-chat-button {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #2563eb;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
#brain-chat-button:hover {
  transform: translateY(-1px);
  background: #1d4ed8;
}
#brain-chat-button:active {
  transform: translateY(0);
}

#brain-chat-window {
  position: absolute;
  bottom: 70px;
  right: 0;
  width: 340px;
  max-height: 70vh;
  background: #ffffff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1), 0 8px 10px -6px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
}

/* Header */
#brain-chat-window .brain-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff;
  padding: 12px 12px;
}
#brain-chat-window .brain-chat-title {
  font-weight: 600;
}
#brain-chat-window .brain-chat-close {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
}
#brain-chat-window .brain-chat-close:hover {
  opacity: 0.85;
}

/* Body */
#brain-chat-window .brain-chat-body {
  padding: 12px;
  overflow-y: auto;
  background: #f9fafb;
  min-height: 140px;
}

/* Message bubbles */
.brain-chat-msg { display: flex; margin: 6px 0; position: relative; }
.brain-chat-msg .bubble {
  max-width: 75%;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.35;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.brain-chat-msg.user { justify-content: flex-end; }
.brain-chat-msg.user .bubble {
  background: #2563eb;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.brain-chat-msg.ai { justify-content: flex-start; }
.brain-chat-msg.ai .bubble {
  background: #ffffff;
  color: #111827;
  border-bottom-left-radius: 4px;
  border: 1px solid #e5e7eb;
}

/* Admin messages */
.brain-chat-msg.admin { justify-content: flex-start !important; }
.brain-chat-msg.admin .bubble {
  background: #10b981; /* emerald */
  color: #ffffff; /* white text */
  border-bottom-left-radius: 4px;
}
/* Ensure timestamp readable on admin bubbles */
.brain-chat-msg.admin .bubble .meta {
  color: #ffffff;
  opacity: 0.8;
}

/* Typing indicator */
.brain-chat-typing { display: flex; justify-content: flex-start; margin: 6px 0; }
.brain-chat-typing .bubble {
  background: #ffffff;
  color: #111827;
  border-bottom-left-radius: 4px;
  border: 1px solid #e5e7eb;
  max-width: 55%;
  padding: 6px 10px;
  border-radius: 10px;
}
.brain-chat-typing .typing-dots { display: inline-flex; gap: 4px; }
.brain-chat-typing .typing-dots span {
  display: inline-block;
  width: 6px; height: 6px;
  background: #9ca3af; /* gray-400 */
  border-radius: 50%;
  opacity: 0.5;
  animation: brain-chat-bounce 1s infinite ease-in-out;
}
.brain-chat-typing .typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.brain-chat-typing .typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes brain-chat-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
  40% { transform: translateY(-3px); opacity: 1; }
}
/* Ensure typing indicator appears at the end */
.brain-chat-typing { order: 99; }

/* Footer */
#brain-chat-window .brain-chat-footer {
  display: flex;
  gap: 8px;
  padding: 12px;
  background: #fff;
  border-top: 1px solid #e5e7eb;
}
#brain-chat-input {
  flex: 1 1 auto;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  outline: none;
  transition: border 0.15s ease, box-shadow 0.15s ease;
}
#brain-chat-input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
#brain-chat-send {
  flex: 0 0 auto;
  padding: 10px 14px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}
#brain-chat-send:hover {
  background: #1d4ed8;
}

/* Hidden state */
#brain-chat-window[hidden] {
  display: none !important;
}

/* Responsive tweak */
@media (max-width: 480px) {
  #brain-chat-window {
    width: calc(100vw - 40px);
    right: 0;
  }
}

/* Inline reply styles */
.reply-icon {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  color: rgba(0,0,0,0.45);
  cursor: pointer;
  display: none;
  user-select: none;
}
/* position icon based on alignment */
.brain-chat-msg.user .reply-icon { right: -22px; }
.brain-chat-msg.ai .reply-icon, .brain-chat-msg.admin .reply-icon { left: -22px; }
.brain-chat-msg:hover .reply-icon { display: inline-block; }
.reply-context {
  border-left: 3px solid rgba(37, 99, 235, 0.6);
  background: rgba(0,0,0,0.03);
  padding: 6px 8px;
  margin-bottom: 6px;
  border-radius: 6px;
}
.reply-context .reply-sender { font-weight: 600; font-size: 12px; margin-bottom: 2px; }
.reply-context .reply-snippet { font-size: 12px; color: #374151; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.reply-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: #f3f4f6;
  border-left: 4px solid #2563eb;
}
.reply-banner .reply-banner-text { font-size: 13px; color: #111827; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-banner .reply-cancel { background: transparent; border: none; color: #6b7280; cursor: pointer; }

/* Click-to-scroll highlight */
.message-highlighted { animation: bc-flash 1.5s ease; }
@keyframes bc-flash {
  0% { box-shadow: 0 0 0 0 rgba(37,99,235,0.0); }
  20% { box-shadow: 0 0 0 3px rgba(37,99,235,0.35); }
  100% { box-shadow: 0 0 0 0 rgba(37,99,235,0.0); }
}
