/* ============================================================
   RentTrek — AI Chatbot Widget (TrekBot)
   Đồng bộ 100% với hệ thống Design Tokens và Typography của RentTrek
   ============================================================ */

/* Nút kích hoạt mở Chatbot (Floating Action Button) */
.rt-chat-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 120;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--moss);
  color: var(--paper);
  border: 1px solid rgba(247, 242, 232, 0.2);
  border-radius: 99px;
  padding: 13px 20px;
  font-family: var(--sans);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  box-shadow: 0 12px 32px -4px rgba(29, 32, 22, 0.35);
  transition: transform 0.35s var(--ease), background 0.3s var(--ease), box-shadow 0.3s var(--ease);
  user-select: none;
}
.rt-chat-fab:hover {
  background: var(--moss-2);
  transform: translateY(-2px);
  box-shadow: 0 16px 36px -4px rgba(29, 32, 22, 0.45);
}
.rt-chat-fab:active {
  transform: translateY(0);
}
.rt-chat-fab .rt-fab-icon {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}
.rt-chat-fab .rt-fab-badge {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: #4ade80;
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--moss);
  animation: rt-pulse 2s infinite;
}

@keyframes rt-pulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(74, 222, 128, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); }
}

/* Cửa sổ Chatbot chính */
.rt-chat-panel {
  position: fixed;
  right: 24px;
  bottom: 86px;
  z-index: 125;
  width: 395px;
  max-width: calc(100vw - 32px);
  height: 580px;
  max-height: calc(100vh - 110px);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 24px 60px -12px rgba(29, 32, 22, 0.3), 0 4px 16px rgba(29, 32, 22, 0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  pointer-events: none;
  visibility: hidden;
  transition: opacity 0.35s var(--ease), transform 0.35s var(--ease), visibility 0.35s;
}
.rt-chat-panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
  visibility: visible;
}

/* Header khung chat */
.rt-chat-header {
  background: var(--moss);
  color: var(--paper);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(247, 242, 232, 0.12);
  flex-shrink: 0;
}
.rt-chat-profile {
  display: flex;
  align-items: center;
  gap: 12px;
}
.rt-chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--paper);
  color: var(--moss);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.rt-chat-title h3 {
  font-family: var(--sans);
  font-size: 16px;
  font-weight: 700;
  margin: 0;
  line-height: 1.2;
  color: var(--paper);
}
.rt-chat-title span {
  display: block;
  font-family: var(--mono);
  font-size: 11px;
  color: rgba(247, 242, 232, 0.72);
  margin-top: 2px;
}
.rt-chat-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.rt-chat-btn-icon {
  background: transparent;
  border: none;
  color: var(--paper);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  opacity: 0.8;
  transition: opacity 0.2s, background 0.2s;
}
.rt-chat-btn-icon:hover {
  opacity: 1;
  background: rgba(247, 242, 232, 0.15);
}

/* Khung tin nhắn cuộn */
.rt-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: #FAF7F0;
  scroll-behavior: smooth;
}
.rt-chat-body::-webkit-scrollbar {
  width: 5px;
}
.rt-chat-body::-webkit-scrollbar-track {
  background: transparent;
}
.rt-chat-body::-webkit-scrollbar-thumb {
  background: rgba(29, 32, 22, 0.15);
  border-radius: 99px;
}

/* Tin nhắn */
.rt-msg {
  display: flex;
  flex-direction: column;
  max-width: 90%;
  animation: rt-fade-in 0.25s var(--ease);
}
@keyframes rt-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.rt-msg.bot {
  align-self: flex-start;
}
.rt-msg.user {
  align-self: flex-end;
}

.rt-msg-bubble {
  padding: 12px 15px;
  border-radius: 18px;
  font-size: 14.5px;
  line-height: 1.55;
  letter-spacing: -0.01em;
  word-break: break-word;
}
.rt-msg.bot .rt-msg-bubble {
  background: #FFFFFF;
  color: var(--ink);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 6px rgba(29, 32, 22, 0.04);
}
.rt-msg.user .rt-msg-bubble {
  background: var(--moss);
  color: var(--paper);
  border-bottom-right-radius: 4px;
}

/* Định dạng văn bản trong tin nhắn Bot */
.rt-msg.bot .rt-msg-bubble p {
  margin: 0 0 8px;
}
.rt-msg.bot .rt-msg-bubble p:last-child {
  margin-bottom: 0;
}
.rt-msg.bot .rt-msg-bubble ul,
.rt-msg.bot .rt-msg-bubble ol {
  margin: 6px 0 8px;
  padding-left: 20px;
}
.rt-msg.bot .rt-msg-bubble li {
  margin-bottom: 4px;
}
.rt-msg.bot .rt-msg-bubble strong {
  font-weight: 700;
  color: var(--ink);
}

.rt-msg-time {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-3);
  margin-top: 4px;
  padding: 0 4px;
}
.rt-msg.user .rt-msg-time {
  text-align: right;
}

/* Thẻ sản phẩm mini trong chat */
.rt-prod-card {
  display: flex;
  gap: 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  margin: 8px 0;
  align-items: center;
  box-shadow: 0 2px 8px rgba(29, 32, 22, 0.05);
}
.rt-prod-thumb {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  object-fit: cover;
  background: var(--bg-2);
  flex-shrink: 0;
}
.rt-prod-meta {
  flex: 1;
  min-width: 0;
}
.rt-prod-meta h4 {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rt-prod-price {
  font-size: 13px;
  font-weight: 700;
  color: var(--moss);
  margin-bottom: 6px;
}
.rt-prod-btns {
  display: flex;
  gap: 6px;
}
.rt-prod-btn {
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 99px;
  border: 1px solid var(--ink);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.rt-prod-btn:hover {
  background: var(--ink);
  color: var(--paper);
}
.rt-prod-btn.primary {
  background: var(--moss);
  color: var(--paper);
  border-color: var(--moss);
}
.rt-prod-btn.primary:hover {
  background: var(--moss-2);
  border-color: var(--moss-2);
}

/* Danh sách câu hỏi gợi ý nhanh (Chips) */
.rt-quick-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.rt-chip {
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: -0.01em;
  background: #FFFFFF;
  border: 1px solid var(--line);
  color: var(--ink-2);
  border-radius: 99px;
  padding: 6px 12px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
  white-space: nowrap;
}
.rt-chip:hover {
  background: var(--moss);
  color: var(--paper);
  border-color: var(--moss);
}

/* Đang nhập (Typing Indicator) */
.rt-typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: #FFFFFF;
  border: 1px solid var(--line);
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}
.rt-typing span {
  width: 6px;
  height: 6px;
  background: var(--moss);
  border-radius: 50%;
  animation: rt-bounce 1.4s infinite ease-in-out both;
}
.rt-typing span:nth-child(1) { animation-delay: -0.32s; }
.rt-typing span:nth-child(2) { animation-delay: -0.16s; }
@keyframes rt-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Khung soạn thảo tin nhắn */
.rt-chat-footer {
  background: var(--paper);
  border-top: 1px solid var(--line);
  padding: 12px 16px 10px;
  flex-shrink: 0;
}
.rt-chat-form {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #FFFFFF;
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 4px 6px 4px 14px;
  transition: border-color 0.25s, box-shadow 0.25s;
}
.rt-chat-form:focus-within {
  border-color: var(--moss);
  box-shadow: 0 0 0 2px rgba(61, 74, 42, 0.15);
}
.rt-chat-input {
  flex: 1;
  border: none;
  outline: none;
  font-family: var(--sans);
  font-size: 14px;
  color: var(--ink);
  background: transparent;
  padding: 6px 0;
}
.rt-chat-input::placeholder {
  color: var(--ink-3);
  font-size: 13.5px;
}
.rt-chat-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--moss);
  color: var(--paper);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
  flex-shrink: 0;
}
.rt-chat-send:hover:not(:disabled) {
  background: var(--moss-2);
}
.rt-chat-send:active:not(:disabled) {
  transform: scale(0.95);
}
.rt-chat-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.rt-chat-note {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-3);
  text-align: center;
  margin-top: 6px;
  letter-spacing: -0.01em;
}

/* Cảnh báo lỗi / Trạng thái cấu hình */
.rt-chat-notice {
  background: #FEF3C7;
  border: 1px solid #F59E0B;
  color: #92400E;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.45;
  margin-top: 6px;
}
.rt-chat-notice-btns {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.rt-chat-notice-btn {
  font-family: var(--mono);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 6px;
  background: #92400E;
  color: #FFF;
  text-decoration: none;
  display: inline-block;
}

/* ============================================================
   RESPONSIVE: Tối ưu cho Điện thoại & Máy tính bảng
   ============================================================ */
/* Khi Modal xem chi tiết sản phẩm hoặc Túi thuê mở ra, tự động ẩn nút Chatbot để không che các nút thao tác */
body.has-modal-open .rt-chat-fab,
body.has-bag-open .rt-chat-fab,
body:has(.modal.open) .rt-chat-fab,
body:has(.drawer.open) .rt-chat-fab {
  opacity: 0 !important;
  pointer-events: none !important;
  transform: scale(0.8) translateY(14px) !important;
  visibility: hidden !important;
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease), visibility 0.25s;
}

@media (max-width: 860px) {
  /* Vì nút "Túi thuê" (.fab) ở bottom: 16px, nút Chatbot được xếp ngay phía trên, không che lẫn nhau */
  .rt-chat-fab {
    right: 16px;
    bottom: 76px;
    padding: 11px 16px;
    font-size: 14px;
    z-index: 100;
  }
}

@media (max-width: 600px) {
  .rt-chat-panel {
    right: 0;
    bottom: 0;
    width: 100vw;
    max-width: 100vw;
    height: 88vh;
    max-height: 88vh;
    border-radius: 20px 20px 0 0;
    border-bottom: none;
  }
}
