/* FlexFly Chat Widget */

#ff-chat-widget {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Toggle Button */
#ff-chat-toggle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background-color: #6c5ce7;
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(108, 92, 231, 0.4);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#ff-chat-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 16px rgba(108, 92, 231, 0.5);
}

/* Chat Panel */
#ff-chat-panel {
  position: absolute;
  bottom: 70px;
  right: 0;
  width: 380px;
  max-height: 520px;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(10px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#ff-chat-panel.ff-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Header */
#ff-chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: #6c5ce7;
  color: white;
}

#ff-chat-header-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#ff-chat-header-info strong {
  font-size: 0.95rem;
}

#ff-chat-status {
  font-size: 0.75rem;
  opacity: 0.8;
}

#ff-chat-close {
  background: none;
  border: none;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0 4px;
  opacity: 0.8;
  transition: opacity 0.15s;
}

#ff-chat-close:hover {
  opacity: 1;
}

/* Messages Area */
#ff-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 300px;
  max-height: 360px;
}

.ff-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.ff-msg-user {
  align-self: flex-end;
  background-color: #6c5ce7;
  color: white;
  border-bottom-right-radius: 4px;
}

.ff-msg-assistant {
  align-self: flex-start;
  background-color: #f1f3f5;
  color: #212529;
  border-bottom-left-radius: 4px;
}

.ff-msg-system {
  align-self: center;
  background: none;
  color: #6c757d;
  font-size: 0.8rem;
  text-align: center;
  padding: 4px 8px;
}

/* Input Area */
#ff-chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid #e9ecef;
}

#ff-chat-input {
  flex: 1;
  border: 1px solid #e9ecef;
  border-radius: 12px;
  padding: 10px 14px;
  font-family: inherit;
  font-size: 0.9rem;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.4;
  transition: border-color 0.15s;
}

#ff-chat-input:focus {
  border-color: #6c5ce7;
}

#ff-chat-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background-color: #6c5ce7;
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background-color 0.15s;
}

#ff-chat-send:hover {
  background-color: #5a4bd4;
}

/* Scrollbar */
#ff-chat-messages::-webkit-scrollbar {
  width: 5px;
}

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

#ff-chat-messages::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 3px;
}

/* Links in messages */
.ff-msg-assistant a {
  color: #6c5ce7;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.ff-msg-assistant a:hover {
  color: #5a4bd4;
}

/* Markdown lists in messages */
.ff-msg-assistant ul,
.ff-msg-assistant ol {
  margin: 4px 0;
  padding-left: 20px;
  white-space: normal;
}

.ff-msg-assistant li {
  margin: 2px 0;
}

/* Typing Indicator */
.ff-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
}

.ff-dot {
  width: 7px;
  height: 7px;
  background-color: #adb5bd;
  border-radius: 50%;
  animation: ff-bounce 1.4s infinite ease-in-out both;
}

.ff-dot:nth-child(1) { animation-delay: 0s; }
.ff-dot:nth-child(2) { animation-delay: 0.16s; }
.ff-dot:nth-child(3) { animation-delay: 0.32s; }

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

/* Unread Badge */
#ff-unread-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  background: #ef4444;
  color: white;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  border: 2px solid white;
}

/* Mobile Responsive */
@media (max-width: 480px) {
  #ff-chat-panel {
    width: calc(100vw - 24px);
    right: -8px;
    bottom: 65px;
    max-height: 70vh;
    border-radius: 12px;
  }

  #ff-chat-messages {
    max-height: calc(70vh - 130px);
  }
}
