/* ==========================================================================
   AI Chat Widget - UI/UX
   z-index luôn trên cùng; click icon chỉ mở; đóng bằng nút đóng; thu nhỏ bong bóng.
   ========================================================================== */

.ai-chat-widget {
  position: fixed;
  bottom: 180px;
  right: 30px;
  z-index: 2147483647;
  width: 100%;
  max-width: 380px;
  height: 520px;
  max-height: calc(100vh - 200px);
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px) scale(0.98);
  transition: opacity 0.25s ease, visibility 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}

.ai-chat-widget.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Bong bóng chat (thu nhỏ): luôn nằm dưới panel, chỉ hiện khi is-bubble */
.ai-chat-bubble {
  display: none;
  position: absolute;
  bottom: 0;
  right: 0;
  width: 56px;
  height: 56px;
  padding: 0;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e427c 0%, #17355f 100%);
  color: #fff;
  border: none;
  border-radius: 50%;
  box-shadow: 0 4px 16px rgba(30, 66, 124, 0.45);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  z-index: 1;
}

.ai-chat-bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(30, 66, 124, 0.5);
}

.ai-chat-bubble i {
  font-size: 1.5rem;
}

.ai-chat-bubble-label {
  position: absolute;
  left: 50%;
  bottom: 100%;
  transform: translateX(-50%) translateY(-8px);
  padding: 4px 10px;
  background: #333;
  color: #fff;
  font-size: 0.75rem;
  white-space: nowrap;
  border-radius: 6px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  pointer-events: none;
}

.ai-chat-bubble:hover .ai-chat-bubble-label {
  opacity: 1;
  visibility: visible;
}

/* Trạng thái thu nhỏ: ẩn panel, hiện bong bóng */
.ai-chat-widget.is-bubble {
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  bottom: 180px;
  right: 30px;
  opacity: 1;
  visibility: visible;
  transform: none;
  pointer-events: auto;
}

.ai-chat-widget.is-bubble .ai-chat-panel {
  display: none;
}

.ai-chat-widget.is-bubble .ai-chat-bubble {
  display: flex;
}

.ai-chat-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--white, #fff);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08);
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.06);
}

/* Header */
.ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(135deg, #1e427c 0%, #17355f 100%);
  color: #fff;
  flex-shrink: 0;
}

.ai-chat-header-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 1rem;
}

.ai-chat-header-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  font-size: 1rem;
}

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

.ai-chat-btn-icon,
.ai-chat-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.ai-chat-btn-icon:hover,
.ai-chat-close:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* Messages area */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f8f9fa;
  -webkit-overflow-scrolling: touch;
}

.ai-chat-msg {
  display: flex;
  gap: 10px;
  max-width: 90%;
  animation: ai-chat-msg-in 0.3s ease;
}

@keyframes ai-chat-msg-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.ai-chat-msg-user {
  flex-direction: row-reverse;
  margin-left: auto;
}

.ai-chat-msg-avatar {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e427c 0%, #17355f 100%);
  color: #fff;
  border-radius: 10px;
  font-size: 0.9rem;
}

.ai-chat-msg-user .ai-chat-msg-avatar {
  background: #495057;
}

.ai-chat-msg-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.ai-chat-msg-bot .ai-chat-msg-bubble {
  background: #fff;
  border-bottom-left-radius: 4px;
  border: 1px solid #e9ecef;
}

.ai-chat-msg-user .ai-chat-msg-bubble {
  background: linear-gradient(135deg, #1e427c 0%, #17355f 100%);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ai-chat-msg-text {
  margin: 0;
  font-size: 0.9375rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.ai-chat-msg-user .ai-chat-msg-text {
  color: #fff;
}

/* Phản hồi bot: link, danh sách */
.ai-chat-msg-text .ai-chat-link {
  color: #1e427c;
  text-decoration: underline;
  word-break: break-all;
}
.ai-chat-msg-bot .ai-chat-msg-text .ai-chat-link:hover {
  color: #17355f;
}
.ai-chat-msg-text .ai-chat-list-bullet {
  color: #1e427c;
  margin-right: 4px;
}

/* Typing indicator */
.ai-chat-typing {
  flex-shrink: 0;
  padding: 8px 16px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.ai-chat-typing-hidden {
  display: none !important;
}

.ai-chat-typing-dots {
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  background: #fff;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  border: 1px solid #e9ecef;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.ai-chat-typing-dots span {
  width: 8px;
  height: 8px;
  background: #adb5bd;
  border-radius: 50%;
  animation: ai-chat-dot 1.4s ease-in-out infinite both;
}

.ai-chat-typing-dots span:nth-child(1) {
  animation-delay: 0s;
}

.ai-chat-typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.ai-chat-typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes ai-chat-dot {

  0%,
  80%,
  100% {
    transform: scale(0.8);
    opacity: 0.5;
  }

  40% {
    transform: scale(1.2);
    opacity: 1;
  }
}

.ai-chat-typing-label {
  font-size: 0.8125rem;
  color: #6c757d;
}

/* Footer / Input */
.ai-chat-footer {
  flex-shrink: 0;
  padding: 12px 16px 16px;
  background: #fff;
  border-top: 1px solid #e9ecef;
}

.ai-chat-attach-preview {
  display: none;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px 0;
  min-height: 0;
}
.ai-chat-attach-preview:not(:empty) {
  display: flex;
}
.ai-chat-attach-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: #e9ecef;
  border-radius: 8px;
  font-size: 0.75rem;
  max-width: 160px;
}
.ai-chat-attach-item img {
  width: 32px;
  height: 32px;
  object-fit: cover;
  border-radius: 4px;
}
.ai-chat-attach-item-remove {
  margin-left: 4px;
  padding: 0 4px;
  background: transparent;
  border: none;
  color: #6c757d;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}
.ai-chat-attach-item-remove:hover {
  color: #dc3545;
}
.ai-chat-btn-attach {
  flex-shrink: 0;
  align-self: flex-end;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  background: transparent;
  color: #1e427c;
  cursor: pointer;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ai-chat-btn-attach:hover {
  background: rgba(30, 66, 124, 0.1);
}
.ai-chat-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 8px 12px;
  background: #f1f3f5;
  border-radius: 12px;
  border: 1px solid #e9ecef;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ai-chat-input-wrap:focus-within {
  border-color: #1e427c;
  box-shadow: 0 0 0 3px rgba(30, 66, 124, 0.15);
}

.ai-chat-input {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: 10px 0;
  border: none;
  background: transparent;
  font-size: 0.9375rem;
  line-height: 1.5;
  resize: none;
  outline: none;
}

.ai-chat-input::placeholder {
  color: #868e96;
}

.ai-chat-send {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: linear-gradient(135deg, #1e427c 0%, #17355f 100%);
  color: #fff;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.ai-chat-send:hover {
  transform: scale(1.05);
}

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

.ai-chat-hint {
  font-size: 0.75rem;
}

/* Mobile */
@media (max-width: 480px) {
  .ai-chat-widget {
    bottom: 0;
    right: 0;
    left: 0;
    max-width: none;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }

  .ai-chat-widget.is-bubble {
    bottom: 24px;
    right: 24px;
    left: auto;
  }

  .ai-chat-panel {
    border-radius: 0;
  }

  .ai-chat-messages {
    padding: 12px;
  }

  .ai-chat-msg {
    max-width: 95%;
  }
}
