/* ============================================================
   KHUNG CHAT TRỢ LÝ AI - góc phải màn hình
   Dùng lại biến màu trong style.css (--accent, --card…)
   ============================================================ */

.cb { position: fixed; right: 20px; bottom: 20px; z-index: 150; font-size: 14.5px; }

/* ---- Nút tròn mở chat ---- */
.cb-fab {
  position: relative; width: 58px; height: 58px; border-radius: 999px; border: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-size: 24px; cursor: pointer;
  box-shadow: 0 10px 30px rgba(139, 92, 246, .45);
  display: grid; place-items: center; transition: transform .18s;
}
.cb-fab:hover { transform: translateY(-2px) scale(1.04); }
.cb-fab::after {                           /* vòng sáng nhấp nháy mời bấm */
  content: ''; position: absolute; inset: -4px; border-radius: inherit;
  border: 2px solid rgba(139, 92, 246, .55); animation: cb-pulse 2.2s ease-out infinite;
}
.cb.open .cb-fab::after, .cb.seen .cb-fab::after { display: none; }
@keyframes cb-pulse { 0% { transform: scale(.95); opacity: 1; } 100% { transform: scale(1.35); opacity: 0; } }

.cb-ic-close { display: none; }
.cb.open .cb-ic-open { display: none; }
.cb.open .cb-ic-close { display: inline; }

.cb-fab-tip {
  position: absolute; right: 68px; top: 50%; transform: translateY(-50%);
  white-space: nowrap; background: var(--card); color: var(--text);
  border: 1px solid var(--border-2); padding: 7px 12px; border-radius: 999px;
  font-size: 13px; font-weight: 600; box-shadow: var(--shadow); pointer-events: none;
}
.cb.open .cb-fab-tip, .cb.seen .cb-fab-tip { display: none; }

/* ---- Khung chat ---- */
.cb-panel {
  position: absolute; right: 0; bottom: 72px;
  width: 380px; height: min(600px, calc(100vh - 110px));
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg-2); border: 1px solid var(--border-2); border-radius: var(--r);
  box-shadow: var(--shadow); animation: cb-in .2s ease;
}
.cb-panel[hidden] { display: none; }
@keyframes cb-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.cb-head {
  display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 14px;
  background: linear-gradient(135deg, rgba(139, 92, 246, .22), rgba(99, 102, 241, .12));
  border-bottom: 1px solid var(--border);
}
.cb-ava {
  width: 38px; height: 38px; border-radius: 999px; flex: none; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; font-size: 17px;
}
.cb-title { flex: 1; min-width: 0; }
.cb-title .n { font-weight: 700; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cb-title .s { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.cb-title .dot { width: 7px; height: 7px; border-radius: 99px; background: var(--green); }
.cb-hbtn {
  width: 32px; height: 32px; border-radius: 9px; border: 0; background: transparent;
  color: var(--muted); cursor: pointer; font-size: 14px;
}
.cb-hbtn:hover { background: rgba(255, 255, 255, .08); color: #fff; }

/* ---- Tin nhắn ---- */
.cb-body { flex: 1; overflow-y: auto; padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 10px; }
.cb-msg {
  max-width: 86%; padding: 10px 13px; border-radius: 14px; line-height: 1.55;
  word-wrap: break-word; overflow-wrap: anywhere;
}
.cb-msg.bot  { align-self: flex-start; background: var(--card-2); color: var(--text); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.cb-msg.user { align-self: flex-end; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-bottom-right-radius: 4px; }
.cb-msg.err  { align-self: flex-start; background: var(--red-soft); color: #fecaca; border: 1px solid rgba(239, 68, 68, .3); }
.cb-msg p + p, .cb-msg p + ul, .cb-msg ul + p, .cb-msg p + ol, .cb-msg ol + p { margin-top: 7px; }
.cb-msg ul, .cb-msg ol { padding-left: 20px; }
.cb-msg li + li { margin-top: 3px; }
.cb-msg strong { color: #fff; }
.cb-msg a { color: #c4b5fd; text-decoration: underline; font-weight: 600; }
.cb-msg.user a { color: #fff; }

.cb-typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.cb-typing i { width: 7px; height: 7px; border-radius: 99px; background: var(--muted); animation: cb-dot 1.2s infinite; }
.cb-typing i:nth-child(2) { animation-delay: .15s; }
.cb-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes cb-dot { 0%, 60%, 100% { opacity: .3; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }

/* ---- Gợi ý nhanh ---- */
.cb-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 14px 10px; }
.cb-chips[hidden] { display: none; }
.cb-chips button {
  border: 1px solid var(--border-2); background: var(--card); color: var(--text);
  border-radius: 999px; padding: 6px 11px; font: inherit; font-size: 12.5px; cursor: pointer;
}
.cb-chips button:hover { border-color: var(--accent); background: var(--accent-soft); }

/* ---- Ô nhập ---- */
.cb-form { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); }
.cb-form textarea {
  flex: 1; resize: none; max-height: 110px; min-height: 42px;
  background: var(--card); color: var(--text); border: 1px solid var(--border-2);
  border-radius: 12px; padding: 10px 12px; font: inherit; line-height: 1.4; outline: none;
}
.cb-form textarea:focus { border-color: var(--accent); }
.cb-form button {
  width: 42px; height: 42px; flex: none; border-radius: 12px; border: 0; cursor: pointer;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; font-size: 15px;
}
.cb-form button:disabled { opacity: .5; cursor: default; }
.cb-foot { text-align: center; font-size: 11.5px; color: var(--muted-2); padding: 0 12px 10px; }
.cb-foot a { color: var(--muted); text-decoration: underline; }

/* ---- Điện thoại: khung chat gần full màn hình ---- */
@media (max-width: 520px) {
  .cb { right: 14px; bottom: 14px; }
  .cb-fab { width: 54px; height: 54px; font-size: 22px; }
  .cb-fab-tip { display: none; }
  .cb-panel {
    position: fixed; inset: auto 0 0 0; width: 100%;
    height: calc(100dvh - 60px); border-radius: var(--r) var(--r) 0 0;
  }
  .cb.open .cb-fab { display: none; }
  .cb-form textarea { font-size: 16px; }   /* iPhone không tự phóng to khi gõ */
}

/* ============================================================
   TAB "TRỢ LÝ AI" TRONG TRANG ADMIN (admin.php)
   ============================================================ */
.chat-h3 { font-size: 15px; font-weight: 700; margin-bottom: 10px; }
.chat-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.chat-stat { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.chat-stat .k { font-size: 12.5px; color: var(--muted-2); }
.chat-stat .v { font-size: 24px; font-weight: 800; margin-top: 2px; }
.chat-stat .s { font-size: 11.5px; color: var(--muted-2); margin-top: 2px; }

.chat-grid { display: grid; grid-template-columns: minmax(260px, 360px) 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .chat-grid { grid-template-columns: 1fr; } }

.chat-bar { height: 5px; background: var(--border); border-radius: 99px; margin-top: 6px; overflow: hidden; }
.chat-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: inherit; }
.chat-zero td { background: var(--amber-soft); }
.chat-paid { font-size: 11px; color: #fcd34d; border: 1px solid rgba(245, 158, 11, .4); border-radius: 99px; padding: 0 7px; margin-left: 4px; }

.chat-row { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.chat-row.err { border-color: rgba(239, 68, 68, .4); }
.chat-meta { font-size: 12px; color: var(--muted-2); margin-bottom: 6px; }
.chat-meta a { color: #a78bfa; }
.chat-q { font-weight: 600; font-size: 14px; }
.chat-q i { color: var(--muted-2); margin-right: 4px; }
.chat-tools { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chat-tools span {
  font-size: 12px; background: var(--accent-soft); color: #c4b5fd;
  border: 1px solid rgba(139, 92, 246, .35); border-radius: 99px; padding: 2px 9px;
}
.chat-a { margin-top: 8px; font-size: 13px; }
.chat-a summary { cursor: pointer; color: var(--muted); }
.chat-a div { white-space: pre-wrap; margin-top: 8px; padding: 10px 12px; background: var(--card-2); border-radius: 9px; line-height: 1.55; }
.chat-test { margin-bottom: 22px; }

/* ---- Bảng chọn tool theo từ khoá (trình sửa trong tab Trợ lý AI) ---- */
.tm-box { background: var(--card); border: 1px solid var(--border); border-radius: var(--r); padding: 16px; margin-bottom: 22px; }
.tm-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.tm-head p { font-size: 13px; color: var(--muted-2); margin-top: 4px; max-width: 720px; }
.tm-row {
  display: grid; grid-template-columns: 28px minmax(220px, 1fr) minmax(260px, 1.4fr) 36px; gap: 12px; align-items: start;
  padding: 12px 0; border-top: 1px solid var(--border);
}
.tm-num { width: 26px; height: 26px; border-radius: 99px; background: var(--card-2); color: var(--muted); display: grid; place-items: center; font-size: 12px; font-weight: 700; margin-top: 20px; }
.tm-lbl { font-size: 11.5px; color: var(--muted-2); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .03em; }
.tm-chips {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-height: 40px;
  background: var(--bg-2); border: 1px solid var(--border-2); border-radius: 10px; padding: 6px 8px; cursor: text;
}
.tm-chips:focus-within { border-color: var(--accent); }
.tm-chips input { flex: 1; min-width: 110px; background: transparent; border: 0; outline: 0; color: var(--text); font: inherit; font-size: 13px; padding: 3px 2px; }
.tm-chips select {
  background: var(--card); color: var(--muted); border: 1px dashed var(--border-2); border-radius: 99px;
  padding: 3px 8px; font: inherit; font-size: 12.5px; max-width: 230px; cursor: pointer;
}
.tm-key, .tm-tool {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; border-radius: 99px; padding: 3px 4px 3px 10px;
}
.tm-key  { background: rgba(59, 130, 246, .14); color: #93c5fd; border: 1px solid rgba(59, 130, 246, .3); }
.tm-tool { background: var(--accent-soft); color: #c4b5fd; border: 1px solid rgba(139, 92, 246, .35); }
.tm-tool em { font-style: normal; font-size: 10.5px; color: #fcd34d; }
.tm-tool.off { opacity: .5; text-decoration: line-through; }
.tm-key button, .tm-tool button {
  border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 15px; line-height: 1;
  width: 18px; height: 18px; border-radius: 99px; opacity: .7;
}
.tm-key button:hover, .tm-tool button:hover { opacity: 1; background: rgba(255, 255, 255, .12); }
.tm-tool button.mv { font-size: 14px; margin-left: -4px; }
.tm-note {
  width: 100%; margin-top: 6px; background: transparent; border: 1px solid transparent; border-radius: 8px;
  color: var(--muted); font: inherit; font-size: 12.5px; padding: 5px 8px;
}
.tm-note:hover, .tm-note:focus { border-color: var(--border-2); outline: 0; color: var(--text); }
.tm-del { margin-top: 20px; width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--border); background: transparent; color: var(--muted-2); cursor: pointer; }
.tm-del:hover { color: var(--red); border-color: rgba(239, 68, 68, .4); }
.tm-foot { font-size: 12.5px; color: var(--muted-2); padding-top: 12px; border-top: 1px solid var(--border); line-height: 1.9; }
.tm-miss { display: inline-block; background: var(--amber-soft); color: #fcd34d; border-radius: 99px; padding: 0 8px; margin: 0 2px; }
@media (max-width: 860px) {
  .tm-row { grid-template-columns: 1fr; }
  .tm-num { display: none; }
  .tm-del { margin-top: 0; justify-self: end; }
}
/* Bảng trong admin mặc định có min-width để cuộn ngang; bảng tool gọn nên bỏ đi */
.chat-grid > div { min-width: 0; }
#chatTools table { min-width: 0; width: 100%; }
