/* ==========================================================================
   Chat Widget - Huyền công / Tu tịnh
   Style độc lập, không phụ thuộc theme. Có thể chỉnh màu ở phần biến CSS
   ngay bên dưới (--hc-primary) cho khớp màu chủ đạo của site.
   ========================================================================== */

.hc-chat-widget {
  --hc-primary: #7a3b12;      /* màu chủ đạo - đổi cho khớp theme */
  --hc-primary-dark: #5c2c0d;
  --hc-bg: #fffaf3;
  --hc-bubble-bot: #f3ece0;
  --hc-bubble-user: #7a3b12;
  --hc-text: #2c2013;
  --hc-border: #e6d9c3;
  --hc-radius: 14px;
  --hc-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 999999;
  font-family: var(--hc-font);
}

.hc-chat-widget * {
  box-sizing: border-box;
}

/* Nút nổi */
.hc-chat-toggle {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--hc-primary);
  border: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: transform 0.15s ease, background 0.15s ease;
}

.hc-chat-toggle:hover {
  background: var(--hc-primary-dark);
  transform: scale(1.05);
}

.hc-chat-toggle svg {
  width: 26px;
  height: 26px;
}

/* Cửa sổ chat */
.hc-chat-panel {
  position: fixed;
  right: 20px;
  bottom: 90px;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100vh - 120px);
  background: var(--hc-bg);
  border-radius: var(--hc-radius);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  display: none;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--hc-border);
}

.hc-chat-widget.hc-open .hc-chat-panel {
  display: flex;
}

.hc-chat-header {
  background: var(--hc-primary);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.hc-chat-header-title {
  font-size: 15px;
  font-weight: 600;
}

.hc-chat-header-sub {
  font-size: 11px;
  opacity: 0.85;
  margin-top: 2px;
  font-weight: 400;
}

.hc-chat-close {
  background: transparent;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 4px;
  opacity: 0.85;
  display: flex;
}

.hc-chat-close:hover {
  opacity: 1;
}

.hc-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hc-msg {
  max-width: 86%;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.hc-msg-user {
  align-self: flex-end;
  background: var(--hc-bubble-user);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.hc-msg-bot {
  align-self: flex-start;
  background: var(--hc-bubble-bot);
  color: var(--hc-text);
  border-bottom-left-radius: 4px;
}

.hc-msg-bot .hc-msg-body {
  white-space: pre-wrap;
  word-wrap: break-word;
}

.hc-msg-error {
  align-self: flex-start;
  background: #f6dede;
  color: #7a1f1f;
  border-bottom-left-radius: 4px;
}

/* Nút "Sao chép" dưới mỗi câu trả lời của bot */
.hc-copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  padding: 3px 8px;
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: rgba(255, 255, 255, 0.6);
  color: var(--hc-primary-dark);
  font-size: 11px;
  font-family: var(--hc-font);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.hc-copy-btn:hover {
  background: #fff;
}

.hc-copy-btn.hc-copied {
  color: #2c7a3f;
  border-color: rgba(44, 122, 63, 0.35);
}

.hc-copy-btn svg {
  flex-shrink: 0;
}

.hc-sources {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  font-size: 11.5px;
}

.hc-sources-label {
  opacity: 0.65;
  margin-bottom: 4px;
}

.hc-source-link {
  display: block;
  color: var(--hc-primary-dark);
  text-decoration: none;
  margin-bottom: 3px;
}

.hc-source-link:hover {
  text-decoration: underline;
}

/* Các câu hỏi gợi ý cho câu hỏi tiếp theo */
.hc-suggested {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}

.hc-suggested-label {
  font-size: 11px;
  opacity: 0.65;
  margin-bottom: 6px;
}

.hc-suggested-chips {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hc-suggested-chip {
  align-self: flex-start;
  max-width: 100%;
  text-align: left;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--hc-primary);
  background: #fff;
  color: var(--hc-primary-dark);
  font-size: 12.5px;
  font-family: var(--hc-font);
  line-height: 1.4;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.hc-suggested-chip:hover {
  background: var(--hc-primary);
  color: #fff;
}

.hc-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 10px 12px;
  background: var(--hc-bubble-bot);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
}

.hc-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #a08a6a;
  animation: hc-blink 1.2s infinite ease-in-out;
}

.hc-typing span:nth-child(2) { animation-delay: 0.2s; }
.hc-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes hc-blink {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 1; }
}

.hc-chat-inputbar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--hc-border);
  background: var(--hc-bg);
  flex-shrink: 0;
}

.hc-chat-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--hc-border);
  border-radius: 10px;
  padding: 8px 10px;
  font-family: var(--hc-font);
  font-size: 13.5px;
  max-height: 90px;
  color: var(--hc-text);
  background: #fff;
}

.hc-chat-input:focus {
  outline: none;
  border-color: var(--hc-primary);
}

.hc-chat-send {
  background: var(--hc-primary);
  border: none;
  color: #fff;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.hc-chat-send:hover {
  background: var(--hc-primary-dark);
}

.hc-chat-send:disabled {
  opacity: 0.5;
  cursor: default;
}

@media (max-width: 480px) {
  .hc-chat-panel {
    right: 12px;
    left: 12px;
    width: auto;
    bottom: 84px;
  }
  .hc-chat-widget {
    right: 12px;
    bottom: 12px;
  }
}
