/* Chatbot positioning and slide-out functionality */
#chatbot {
  position: fixed;
  top: 50%;
  right: -450px; /* Hidden by default */
  transform: translateY(-50%);
  width: 450px;
  height: 600px;
  background: #ffffff;
  border-radius: 12px 0 0 12px;
  box-shadow: -5px 0 20px rgba(0, 0, 0, 0.15);
  transition: right 0.3s ease-in-out;
  z-index: 1000;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  border: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Fullscreen mode */
#chatbot.fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100vh;
  transform: none;
  border-radius: 0;
  z-index: 10000;
  background: #ffffff;
}

#chatbot.fullscreen #chat-messages {
  height: 100% !important;
}

/* When chatbot is open */
#chatbot.open {
  right: 0;
}

/* Toggle Button */
#chat-toggle {
  position: fixed;
  top: 20%;
  right: 20px;
  transform: translateY(-50%);
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 999;
}

#chat-toggle:hover {
  background: linear-gradient(135deg, #1d4ed8 0%, #2563eb 100%);
  transform: translateY(-50%) scale(1.05);
}

#chat-toggle svg {
  width: 28px;
  height: 28px;
  fill: white;
}

/* Hide toggle when chatbot is open */
#chatbot.open ~ #chat-toggle {
  opacity: 0;
  pointer-events: none;
}

/* Chat header */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 20px;
  border-bottom: 1px solid #e5e7eb;
  background: #f9fafb;
  flex-shrink: 0;
}

.chat-header-title {
  font-size: 18px;
  font-weight: 600;
  color: #1f2937;
}

.chat-header-buttons {
  display: flex;
  gap: 10px;
}

/* Expand button for fullscreen */
#chat-expand {
  background: #f3f4f6;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6b7280;
  font-size: 16px;
  transition: all 0.2s ease;
}

#chat-expand:hover {
  background: #e5e7eb;
  color: #374151;
}

/* Close button */
#chat-close {
  background: #f3f4f6;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6b7280;
  font-size: 20px;
  transition: all 0.2s ease;
}

#chat-close:hover {
  background: #fee2e2;
  color: #dc2626;
}

/* Chat messages container */
.chat-messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: #f9fafb;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Enhanced chat messages styling */
#chat-messages {
  display: flex;
  flex-direction: column;
  gap: 16px;
  font-size: 14px;
  line-height: 1.6;
  user-select: text !important;
  -webkit-user-select: text !important;
  -moz-user-select: text !important;
  -ms-user-select: text !important;
  width: 100%;
}

/* Prevent scroll propagation */
.chat-messages-container {
  overscroll-behavior: contain;
}

/* Message styling */
.message {
  display: flex;
  flex-direction: column;
  animation: messageSlideIn 0.3s ease-out;
  width: 100%;
}

.message.user {
  align-items: flex-end;
}

.message.bot {
  align-items: flex-start;
}

.message-bubble {
  max-width: 70%;
  padding: 12px 16px;
  border-radius: 18px;
  word-wrap: break-word;
  position: relative;
  user-select: text !important;
  -webkit-user-select: text !important;
}

.message.user .message-bubble {
  background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
  color: white;
  border-bottom-right-radius: 6px;
  box-shadow: 0 2px 8px rgba(30, 64, 175, 0.3);
}

.message.bot .message-bubble {
  background: white;
  color: #374151;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 6px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.message-sender {
  font-size: 11px;
  color: #6b7280;
  margin-bottom: 6px;
  font-weight: 500;
  padding: 0 4px;
}

.message.user .message-sender {
  text-align: right;
}

.message.bot .message-sender {
  text-align: left;
}

/* Message with image */
.message-image {
  max-width: 100%;
  border-radius: 8px;
  margin-top: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.message.user .message-image {
  border: 2px solid rgba(255, 255, 255, 0.3);
}

.message.bot .message-image {
  border: 1px solid #e5e7eb;
}

/* Typing indicator styling */
.message.typing .message-bubble {
  background: white !important;
  border: 1px solid #e5e7eb !important;
  padding: 12px 16px !important;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 20px;
}

.typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: #9ca3af;
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
  animation-delay: 0s;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

.typing-text {
  font-size: 12px;
  color: #6b7280;
  font-style: italic;
}

@keyframes typingBounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-8px);
    opacity: 1;
  }
}

/* Legacy message support (for existing messages) */
#chat-messages > div:not(.message) {
  margin-bottom: 12px;
  padding: 10px 14px;
  border-radius: 16px;
  max-width: 85%;
  word-wrap: break-word;
  user-select: text !important;
  -webkit-user-select: text !important;
}

#chat-messages > div:not(.message):has(strong:contains("You")) {
  background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
  color: white;
  margin-left: auto;
  text-align: right;
  border-bottom-right-radius: 6px;
  box-shadow: 0 2px 8px rgba(30, 64, 175, 0.3);
}

#chat-messages > div:not(.message):has(strong:contains("Sail Talks")) {
  background: white;
  color: #374151;
  border: 1px solid #e5e7eb;
  margin-right: auto;
  border-bottom-left-radius: 6px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

#chat-messages strong {
  font-weight: 600;
  margin-right: 8px;
}

/* Chat input container */
.chat-input-container {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 15px 20px;
  border-top: 1px solid #e5e7eb;
  background: white;
  flex-shrink: 0;
}

/* Attach whiteboard button */
#attach-whiteboard-btn {
  background: #f3f4f6;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6b7280;
  font-size: 20px;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

#attach-whiteboard-btn:hover {
  background: #e5e7eb;
  color: #374151;
}

#attach-whiteboard-btn.active {
  background: #dbeafe;
  color: #1e40af;
}

/* Image preview container */
.image-preview-container {
  position: relative;
  display: none;
  margin-right: 10px;
}

.image-preview-container.visible {
  display: block;
}

.image-preview {
  width: 60px;
  height: 60px;
  border-radius: 8px;
  object-fit: cover;
  border: 2px solid #e5e7eb;
}

.remove-image-btn {
  position: absolute;
  top: -8px;
  right: -8px;
  background: #ef4444;
  color: white;
  border: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
  font-weight: bold;
}

.remove-image-btn:hover {
  background: #dc2626;
}

/* Input styling */
#chat-input {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid #d1d5db;
  border-radius: 20px;
  outline: none;
  font-size: 14px;
  transition: all 0.2s ease;
  font-family: inherit;
  resize: none;
  min-height: 40px;
  max-height: 120px;
}

#chat-input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

#chat-input::placeholder {
  color: #9ca3af;
}

/* Send button */
#chat-send {
  /* background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%); */
  background: white;
  color: white;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  font-size: 25px;
  flex-shrink: 0;
}

#chat-send:hover {
  /* background: linear-gradient(135deg, #1d4ed8 0%, #2563eb 100%); */
  transform: scale(1.05);
  /* box-shadow: 0 4px 12px rgba(30, 64, 175, 0.3); */
}

#chat-send:active {
  transform: scale(0.95);
}

/* Scrollbar styling */
.chat-messages-container::-webkit-scrollbar {
  width: 8px;
}

.chat-messages-container::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 4px;
}

.chat-messages-container::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
  border: 2px solid #f1f5f9;
}

.chat-messages-container::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Animations */
@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Mobile responsiveness */
@media (max-width: 768px) {
  #chatbot {
    width: 100%;
    height: 100%;
    right: -100%;
    top: 0;
    transform: none;
    border-radius: 0;
  }
  
  #chat-toggle {
    right: 15px;
    width: 50px;
    height: 50px;
  }
  
  .message-bubble {
    max-width: 85%;
  }
}

/* Fullscreen overlay */
.chat-fullscreen-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.chat-fullscreen-overlay.active {
  opacity: 1;
  pointer-events: all;
}