/* ==========================================================================
   CHATBOX UI - DỊCH VỤ THUẾ KẾ TOÁN TADA
   Theme: Burgundy (#800020) & Gold (#D4AF37)
   ========================================================================== */

/* Cot phai trong hero: chatbox truc tiep la cot 2 cua grid-2 */
.chatbox-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  flex: 1;              /* chiếm phần còn lại sau audit — chatbox + audit = cao bằng cột trái */
  min-height: 0;
  background: var(--glass-bg-light);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-light);
  border-radius: var(--border-radius-lg);
  box-shadow: 0 24px 60px -20px rgba(128, 0, 32, 0.25);
  overflow: hidden;
  position: relative;
  transition: box-shadow 0.25s ease;
}

/* Mobile (grid 1 cột): chatbox không có cột trái để dựa vào,
   giữ chiều cao hợp lý + scroll nội bộ thay vì giãn vô hạn */
@media (max-width: 1024px) {
  .chatbox-wrap {
    flex: none;
    height: clamp(360px, 60vh, 560px);
    min-height: 360px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }
}

/* Mở rộng khi đang chat: chatbox giãn chiều cao trong luồng,
   hero-content bên trái vẫn hiển thị, audit vẫn ở dưới */
.chatbox-wrap.is-expanded {
  flex: 1 1 auto;
  min-height: 380px;
  max-height: 520px;
  box-shadow: 0 24px 60px -20px rgba(128, 0, 32, 0.35);
  border-radius: var(--border-radius-lg);
}

/* Header */
.chatbox-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 22px;
  background: linear-gradient(135deg, var(--primary-burgundy) 0%, var(--primary-burgundy-dark) 100%);
  color: var(--text-light);
}

.chatbox-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent-gold);
  display: grid;
  place-items: center;
  font-size: 20px;
  flex-shrink: 0;
}

.chatbox-heading {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
}

.chatbox-title {
  font-weight: 700;
  font-size: 16px;
  color: var(--text-light);
}

.chatbox-status {
  font-size: 12px;
  color: var(--accent-gold-light);
  display: flex;
  align-items: center;
  gap: 6px;
}

.chatbox-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4caf50;
  box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.25);
}

.chatbox-reset {
  margin-left: auto;
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: var(--text-light);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: var(--transition-fast);
}
.chatbox-reset:hover { background: rgba(255, 255, 255, 0.22); }

/* Messages */
.chatbox-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}

.chat-msg {
  max-width: 92%;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-msg.bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--border-light);
  border-bottom-left-radius: 4px;
  color: var(--text-dark);
}

.chat-msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--primary-burgundy) 0%, var(--primary-burgundy-light) 100%);
  color: var(--text-light);
  border-bottom-right-radius: 4px;
}

.chat-msg.typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}
.chat-msg.typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-muted-dark);
  animation: chat-bounce 1.2s infinite ease-in-out;
}
.chat-msg.typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-msg.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* Quick suggestions */
.chatbox-suggest {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 8px;
  padding: 0 22px 12px;
  overflow-x: auto;
  align-items: center;
}
.chatbox-suggest button {
  flex: 0 0 auto;
  background: rgba(212, 175, 55, 0.12);
  border: 1px solid var(--border-dark);
  color: var(--primary-burgundy);
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: var(--transition-fast);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
}
.chatbox-suggest button:hover {
  background: var(--accent-gold);
  color: #fff;
}

/* Input */
.chatbox-input-area {
  display: flex;
  gap: 10px;
  padding: 16px 22px;
  border-top: 1px solid var(--border-light);
  background: #fff;
}

.chatbox-input {
  flex: 1;
  border: 1px solid var(--border-light);
  border-radius: var(--border-radius-md);
  padding: 12px 16px;
  font-family: var(--font-sans);
  font-size: 15px;
  resize: none;
  outline: none;
  transition: var(--transition-fast);
}
.chatbox-input:focus {
  border-color: var(--accent-gold);
  box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.18);
}

.chatbox-send {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border: none;
  border-radius: var(--border-radius-md);
  background: linear-gradient(135deg, var(--primary-burgundy) 0%, var(--primary-burgundy-light) 100%);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  transition: var(--transition-fast);
}
.chatbox-send:hover { transform: scale(1.05); }
.chatbox-send:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ---- Nguồn tham khảo (từ RAG) ---- */
.chat-sources {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 6px;
  margin-bottom: 4px;
}
.chat-source {
  font-size: 12px;
  color: var(--text-muted-dark);
  background: var(--bg-light-alt);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 6px 10px;
  line-height: 1.4;
}
.chat-source b {
  color: var(--primary-burgundy);
  font-weight: 600;
}

/* ---- Auth overlay (hết 3 câu free) ---- */
.chatbox-auth-overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 5, 7, 0.7);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.chatbox-auth-overlay.active {
  opacity: 1;
  pointer-events: auto;
}
.chatbox-auth-box {
  background: #fff;
  border-radius: var(--border-radius-md);
  padding: 40px 32px 32px;
  max-width: 360px;
  width: 90%;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0,0,0,0.3);
}
.chatbox-auth-icon {
  font-size: 48px;
  margin-bottom: 12px;
}
.chatbox-auth-box h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary-burgundy);
  margin: 0 0 8px;
}
.chatbox-auth-box p {
  font-size: 14px;
  color: var(--text-muted-dark);
  margin: 0 0 20px;
  line-height: 1.5;
}
.btn-auth-google {
  display: inline-flex !important;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: var(--border-radius-sm);
  border: 2px solid var(--border-light);
  background: #fff;
  color: var(--text-dark);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-fast);
}
.btn-auth-google:hover {
  border-color: var(--accent-gold);
  background: var(--bg-light-alt);
}
.btn-auth-google .btn-icon {
  width: 20px;
  height: 20px;
}
.chatbox-auth-note {
  font-size: 12px !important;
  color: var(--text-muted-light) !important;
  margin-top: 12px !important;
  margin-bottom: 0 !important;
}

/* Chatbox: relative container cho overlay */
.chatbox-wrap {
  position: relative;
}

/* ---- Google Login Button (header) ---- */
.btn-google {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--border-radius-sm);
  border: none;
  background: #fff;
  color: var(--text-dark);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-fast);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.btn-google:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  background: #f8f8f8;
}
.btn-google .btn-icon {
  width: 18px;
  height: 18px;
}

/* ---- User Avatar & Dropdown ---- */
.user-avatar {
  position: relative;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
.user-avatar img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--accent-gold);
  object-fit: cover;
}
/* Cầu nối hover từ avatar xuống dropdown — tránh mất focus */
.user-avatar::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  height: 8px;
}
.user-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: #fff;
  border-radius: var(--border-radius-sm);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  padding: 12px 16px;
  min-width: 200px;
  flex-direction: column;
  gap: 6px;
  z-index: 200;
}
.user-avatar.active .user-dropdown {
  display: flex;
}
.btn-logout {
  margin-top: 6px;
  padding: 6px 12px;
  border: none;
  border-radius: var(--border-radius-sm);
  background: var(--bg-light-alt);
  color: var(--primary-burgundy);
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition-fast);
}
.btn-logout:hover {
  background: var(--primary-burgundy);
  color: #fff;
}

/* Nút Viết bài trong dropdown */
.dropdown-write-btn {
  display: block;
  margin-top: 6px;
  padding: 8px 12px;
  border: none;
  border-radius: var(--border-radius-sm);
  background: var(--primary-burgundy);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  transition: var(--transition-fast);
}
.dropdown-write-btn:hover {
  background: var(--accent-gold-dark);
  color: #fff;
}
