/* chat.css — khung chat nổi (trợ lý ảo DeepSeek) cho toàn bộ ERP.
   Bám theo biến màu của site.css; tự ẩn nếu trợ lý chưa được bật. */

:root {
  --chat-accent: #0b6bcb;
  --chat-accent-dark: #08529b;
  --chat-bg: #ffffff;
  --chat-line: #d8dee8;
  --chat-text: #1c2530;
  --chat-muted: #64748b;
}

/* ---------- Nút bong bóng ---------- */
#chat-fab {
  position: fixed;
  right: 22px;
  bottom: 22px;
  width: 58px;
  height: 58px;
  border: none;
  border-radius: 50%;
  background: var(--chat-accent);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(11, 107, 203, .38);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s ease, background .15s ease;
}
#chat-fab:hover { background: var(--chat-accent-dark); transform: scale(1.06); }
#chat-fab:active { transform: scale(.96); }
#chat-fab[hidden] { display: none; }

/* Chấm báo câu trả lời mới khi khung đang đóng */
#chat-fab .chat-fab__dot {
  position: absolute;
  top: 2px; right: 2px;
  width: 13px; height: 13px;
  background: #e5484d;
  border: 2px solid #fff;
  border-radius: 50%;
  display: none;
}
#chat-fab.co-tin-moi .chat-fab__dot { display: block; }

/* ---------- Khung chat ---------- */
#chat-panel {
  position: fixed;
  right: 22px;
  bottom: 92px;
  width: min(430px, calc(100vw - 32px));
  height: min(620px, calc(100vh - 130px));
  background: var(--chat-bg);
  border: 1px solid var(--chat-line);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(15, 30, 50, .22);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9001;
  color: var(--chat-text);
}
#chat-panel[hidden] { display: none; }

.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  background: var(--chat-accent);
  color: #fff;
  flex: 0 0 auto;
}
.chat-head__title { font-weight: 600; font-size: 14.5px; }
.chat-head__sub { font-size: 11.5px; opacity: .85; margin-top: 1px; }
.chat-head__spacer { flex: 1; }
.chat-head button {
  background: rgba(255, 255, 255, .16);
  border: none;
  color: #fff;
  width: 27px; height: 27px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}
.chat-head button:hover { background: rgba(255, 255, 255, .3); }

/* ---------- Vùng tin nhắn ---------- */
.chat-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px;
  background: #f7f9fc;
  display: flex;
  flex-direction: column;
  gap: 11px;
}
.chat-msg {
  max-width: 88%;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-msg--user {
  align-self: flex-end;
  background: var(--chat-accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg--bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--chat-line);
  border-bottom-left-radius: 4px;
}
.chat-msg--bot code {
  background: #eef2f7;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12.5px;
}
.chat-msg--loi {
  align-self: flex-start;
  background: #fff1f1;
  border: 1px solid #f5c2c2;
  color: #8b1a1a;
}
.chat-msg__meta {
  display: block;
  margin-top: 6px;
  font-size: 11px;
  color: var(--chat-muted);
}
.chat-msg--user .chat-msg__meta { color: rgba(255, 255, 255, .8); }

/* Dấu "đang trả lời" */
.chat-typing { display: flex; gap: 4px; align-items: center; }
.chat-typing span {
  width: 6px; height: 6px;
  background: var(--chat-muted);
  border-radius: 50%;
  animation: chat-blink 1.3s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: .18s; }
.chat-typing span:nth-child(3) { animation-delay: .36s; }
@keyframes chat-blink {
  0%, 80%, 100% { opacity: .28; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* ---------- Câu hỏi gợi ý ---------- */
.chat-goi-y {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 14px 10px;
  background: #f7f9fc;
  flex: 0 0 auto;
}
.chat-goi-y button {
  background: #fff;
  border: 1px solid var(--chat-line);
  border-radius: 14px;
  padding: 5px 11px;
  font-size: 12px;
  color: var(--chat-accent);
  cursor: pointer;
}
.chat-goi-y button:hover { background: #eaf3fd; border-color: #b9d5f1; }

/* ---------- Ô nhập ---------- */
.chat-foot {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--chat-line);
  background: #fff;
  align-items: flex-end;
}
#chat-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--chat-line);
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 13.5px;
  font-family: inherit;
  line-height: 1.45;
  max-height: 116px;
  outline: none;
  color: var(--chat-text);
}
#chat-input:focus { border-color: var(--chat-accent); }
#chat-send {
  background: var(--chat-accent);
  color: #fff;
  border: none;
  border-radius: 9px;
  padding: 9px 15px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
#chat-send:hover { background: var(--chat-accent-dark); }
#chat-send:disabled { background: #a9bdd4; cursor: not-allowed; }

/* Màn hình hẹp: khung chat chiếm gần trọn */
@media (max-width: 560px) {
  #chat-panel {
    right: 8px;
    left: 8px;
    bottom: 84px;
    width: auto;
    height: min(74vh, 560px);
  }
  #chat-fab { right: 14px; bottom: 14px; }
}
