/* Chatbot Widget Styles */
.chatbot-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 48px);
  height: 520px;
  max-height: calc(100vh - 72px);
  background: #0f172a;
  color: #e5e7eb;
  border-radius: 18px;
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.7);
  display: none;
  flex-direction: column;
  z-index: 2100;
  overflow: hidden;
  /* Animation mở/đóng mượt mà */
  opacity: 0;
  transform: scale(0.9) translateY(20px);
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), 
              transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

.chatbot-widget.active {
  display: flex;
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}

.chatbot-header {
  padding: 14px 16px;
  background: radial-gradient(circle at top left, #22c55e, #0f172a);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(15, 23, 42, 0.6);
}

.chatbot-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chatbot-avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: radial-gradient(circle at 30% 0, #bbf7d0, #22c55e);
}

.chatbot-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.chatbot-header-title {
  display: flex;
  flex-direction: column;
}

.chatbot-header-title span:first-child {
  font-size: 14px;
  font-weight: 600;
}

.chatbot-header-title span:last-child {
  font-size: 11px;
  color: #d1d5db;
}

.chatbot-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chatbot-icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: none;
  background: rgba(15, 23, 42, 0.35);
  color: #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.chatbot-icon-btn:hover {
  background: rgba(15, 23, 42, 0.7);
  transform: translateY(-1px);
}

.chatbot-body {
  flex: 1;
  min-height: 0; /* Quan trọng: cho phép flex shrink */
  /* Nền sáng hơn, trung tính hơn */
  background: radial-gradient(circle at top, rgba(255, 255, 255, 0.18), transparent 55%), #1f2933;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch; /* Smooth scroll trên iOS */
}

.chatbot-message-container {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 8px;
  width: 100%;
}

.chatbot-message-container.bot {
  justify-content: flex-start;
}

.chatbot-message-container.user {
  justify-content: flex-end;
}

.chatbot-message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: radial-gradient(circle at 30% 0, #bbf7d0, #22c55e);
  flex-shrink: 0;
}

.chatbot-message-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.chatbot-message-avatar.user-avatar {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  order: 2;
}

.chatbot-message {
  max-width: calc(80% - 40px);
  padding: 9px 12px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.5;
  word-wrap: break-word;
}

.chatbot-message.user {
  background: #22c55e;
  color: #052e16;
  border-bottom-right-radius: 4px;
}

.chatbot-message.bot {
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(31, 41, 55, 0.9);
  border-bottom-left-radius: 4px;
}

.chatbot-message pre {
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 13px;
}

.chatbot-message-meta {
  margin-top: 4px;
  font-size: 10px;
  opacity: 0.75;
}

.chatbot-suggestions {
  display: none;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 8px 14px 6px 14px;
  /* Cùng tông với body nhưng hơi đậm hơn một chút để tách nhẹ */
  background: radial-gradient(circle at top, rgba(255, 255, 255, 0.14), transparent 55%), #1b2430;
}

.chatbot-suggestion {
  border: none;
  background: #ffffff;
  color: #111827;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12px;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.15);
  transition: background 0.12s ease, box-shadow 0.12s ease, transform 0.08s ease;
  width: auto;
  max-width: 100%;
  text-align: left;
  align-self: flex-start;
}

.chatbot-suggestion:hover {
  background: #f9fafb;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.3);
  transform: translateY(-1px);
}

/* Typing indicator */
.chatbot-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
}

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

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

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

@keyframes chatbot-typing-bounce {
  0%, 80%, 100% {
    transform: scale(0);
  }
  40% {
    transform: scale(1);
  }
}

.chatbot-input-wrapper {
  background: #020617;
  border-top: 1px solid rgba(15, 23, 42, 0.9);
}

.chatbot-input-area {
  padding: 10px 12px;
  background: #020617;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0; /* Input area không bị co lại */
}

.chatbot-textarea {
  flex: 1;
  border-radius: 999px;
  border: 1px solid rgba(31, 41, 55, 0.9);
  padding: 10px 14px;
  background: #020617;
  color: #e5e7eb;
  font-size: 13px;
  resize: none;
  min-height: 40px;
  max-height: 80px;
  outline: none;
}

.chatbot-textarea::placeholder {
  color: #6b7280;
}

.chatbot-send-btn {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: none;
  background: #22c55e;
  color: #052e16;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

.chatbot-send-btn:hover {
  background: #16a34a;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25);
  transform: translateY(-1px);
}

.chatbot-send-btn:disabled {
  background: #374151;
  color: #9ca3af;
  cursor: not-allowed;
  box-shadow: none;
}

.chatbot-powered {
  padding: 4px 12px 8px 12px;
  font-size: 12px;
  color: #6b7280;
  text-align: center;
  background: #020617;
}

.chatbot-empty-state {
  margin-top: 12px;
  margin-bottom: 6px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(31, 41, 55, 0.9);
  font-size: 12px;
  color: #9ca3af;
}

.chatbot-empty-state strong {
  color: #e5e7eb;
}

.chatbot-button {
  position: fixed;
  right: 24px;
  /* Đặt cao hơn nút share khoảng 72px */
  bottom: 96px;
  /* Kích thước ngang nút share */
  width: 56px;
  height: 56px;
  border: none;
  background: none; /* Không thêm nền phía sau avatar */
  display: flex;
  align-items: center;
  justify-content: center;
  position: fixed;
  cursor: pointer;
  z-index: 2050;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.chatbot-button:hover {
  transform: translateY(-2px);
}

.chatbot-button-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  /* Đổi glow sang bóng đổ trung tính, không ánh xanh lục */
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.35);
}

/* Tooltip bong bóng chat bên cạnh nút chatbot */
.chatbot-button-tooltip {
  position: absolute;
  right: calc(100% + 16px);
  top: 50%;
  transform: translateY(-50%);
  background: #ffffff;
  color: #1f2937;
  padding: 12px 16px;
  border-radius: 18px 18px 4px 18px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08);
  pointer-events: none;
  opacity: 0;
  animation: chatbot-tooltip-pop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
  animation-delay: 1s;
  border: 1px solid rgba(0, 0, 0, 0.06);
}

/* Mũi tên hướng về phía nút chatbot */
.chatbot-button-tooltip::after {
  content: '';
  position: absolute;
  right: -8px;
  bottom: 8px;
  width: 0;
  height: 0;
  border: 8px solid transparent;
  border-left-color: #ffffff;
  border-right: 0;
  filter: drop-shadow(2px 0 2px rgba(0,0,0,0.05));
}

@keyframes chatbot-tooltip-pop {
  0% {
    opacity: 0;
    transform: translateY(-50%) scale(0.8);
  }
  70% {
    opacity: 1;
    transform: translateY(-50%) scale(1.03);
  }
  100% {
    opacity: 1;
    transform: translateY(-50%) scale(1);
  }
}

/* Ẩn tooltip khi hover vào button hoặc khi chatbot đã mở */
.chatbot-button:hover .chatbot-button-tooltip,
.chatbot-button.tooltip-hidden .chatbot-button-tooltip {
  opacity: 0 !important;
  animation: none;
}

/* Backdrop overlay cho mobile */
.chatbot-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 2099;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chatbot-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

@media (min-width: 769px) {
  .chatbot-backdrop {
    display: none;
  }
}

@media (max-width: 768px) {
  .chatbot-widget {
    /* Full màn hình trên mobile */
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    max-width: 100vw !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    transform: scale(1) translateY(100%);
  }

  .chatbot-widget.active {
    transform: scale(1) translateY(0);
  }

  .chatbot-header {
    border-radius: 0;
    /* Đảm bảo header không bị tràn */
    padding-top: max(14px, env(safe-area-inset-top));
    flex-shrink: 0; /* Header không bị co lại */
  }

  .chatbot-body {
    /* Đảm bảo body có thể scroll và không bị che input */
    flex: 1;
    min-height: 0; /* Quan trọng: cho phép flex shrink */
    overflow-y: auto;
    padding-bottom: 8px;
    /* Đảm bảo scroll đến cuối không bị che */
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }

  .chatbot-input-area {
    /* Input area luôn ở bottom và visible */
    position: relative;
    flex-shrink: 0; /* Input area không bị co lại */
    padding: 10px 12px;
    padding-bottom: max(10px, calc(10px + env(safe-area-inset-bottom)));
    background: #020617;
    border-top: 1px solid rgba(15, 23, 42, 0.9);
    /* Đảm bảo input area luôn trên cùng */
    z-index: 1;
  }

  /* Đảm bảo textarea có thể click được */
  .chatbot-textarea {
    min-height: 44px; /* Touch target size */
    font-size: 16px; /* Tránh zoom trên iOS khi focus */
  }
}

