/* =====================================================
   chatbot.css — AI Tutor Floating Chatbot
   Cambridge IT 9626 Learning Hub
   Dùng biến CSS của main.css — tự đổi theo theme dark/light
   ===================================================== */

/* ── Floating Button ─────────────────────────────── */
#ai-chat-btn {
  position: fixed;
  bottom: 28px; right: 28px;
  z-index: 9990;
  width: 60px; height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  border: none; cursor: pointer;
  box-shadow: 0 4px 24px rgba(78,127,255,.45);
  display: flex; align-items: center; justify-content: center;
  transition: transform .2s, box-shadow .2s;
  outline: none;
}
#ai-chat-btn:hover   { transform: scale(1.08) translateY(-2px); box-shadow: 0 8px 32px rgba(78,127,255,.6); }
#ai-chat-btn:active  { transform: scale(.95); }
#ai-chat-btn svg     { width: 28px; height: 28px; }
#ai-chat-btn .icon-chat  { display: block; }
#ai-chat-btn .icon-close { display: none; }
#ai-chat-btn.is-open .icon-chat  { display: none; }
#ai-chat-btn.is-open .icon-close { display: block; }

/* Badge */
#ai-chat-badge {
  position: absolute; top: 2px; right: 2px;
  width: 18px; height: 18px;
  background: var(--accent2); border-radius: 50%;
  font-size: .62rem; font-weight: 700; color: #fff;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--bg);
  opacity: 0; transform: scale(0);
  transition: opacity .2s, transform .25s cubic-bezier(.34,1.56,.64,1);
}
#ai-chat-badge.show { opacity: 1; transform: scale(1); }

/* ── Chat Window ─────────────────────────────────── */
#ai-chat-window {
  position: fixed;
  bottom: 100px; right: 28px;
  z-index: 9991;
  width: 400px;
  max-width: calc(100vw - 32px);
  height: 580px;
  max-height: calc(100vh - 120px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 16px 56px rgba(0,0,0,.65), 0 0 0 1px rgba(78,127,255,.08);
  display: flex; flex-direction: column; overflow: hidden;
  transform: scale(.93) translateY(18px); opacity: 0; pointer-events: none;
  transition: transform .24s cubic-bezier(.34,1.56,.64,1), opacity .18s ease;
}
#ai-chat-window.is-open { transform: scale(1) translateY(0); opacity: 1; pointer-events: all; }

/* ── Header ──────────────────────────────────────── */
.chat-header {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px;
  background: linear-gradient(135deg, rgba(78,127,255,.12), rgba(0,212,160,.06));
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-hdr-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg,var(--primary),var(--accent));
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.chat-hdr-avatar svg { width: 20px; height: 20px; }
.chat-hdr-info   { flex: 1; min-width: 0; }
.chat-hdr-name   { font-size: .88rem; font-weight: 700; color: var(--text); line-height: 1.2; }
.chat-hdr-status {
  font-size: .7rem; color: var(--accent); display: flex; align-items: center; gap: 4px; margin-top: 2px;
}
.chat-hdr-status::before {
  content:''; width:6px; height:6px; border-radius:50%; background:var(--accent); flex-shrink:0;
}
.chat-hdr-tag {
  font-size: .62rem; background: rgba(78,127,255,.15); border: 1px solid rgba(78,127,255,.25);
  color: var(--primary); border-radius: 4px; padding: 1px 6px; font-weight: 600;
}
.chat-hdr-actions { display: flex; gap: 4px; }
.chat-hdr-btn {
  width: 28px; height: 28px; background: transparent;
  border: 1px solid var(--border); border-radius: 8px;
  color: var(--text2); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s, border-color .15s;
}
.chat-hdr-btn:hover { background: var(--surface2); color: var(--text); border-color: var(--primary); }
.chat-hdr-btn svg { width: 13px; height: 13px; }

/* ── Context strip ───────────────────────────────── */
.chat-ctx-strip {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 12px;
  background: rgba(78,127,255,.06);
  border-bottom: 1px solid var(--surface2);
  font-size: .69rem; color: var(--text2);
  flex-shrink: 0;
}
.chat-ctx-strip.hidden { display: none; }
.chat-ctx-lbl { font-weight: 600; }

/* ── Suggestion chips ────────────────────────────── */
.chat-suggs {
  display: flex; gap: 5px; flex-wrap: wrap;
  padding: 7px 10px;
  border-bottom: 1px solid var(--surface2);
  background: var(--bg);
  flex-shrink: 0;
}
.chat-suggs.hidden { display: none; }
.chat-chip {
  font-size: .69rem; padding: 4px 10px;
  border-radius: 99px;
  background: var(--surface2); border: 1px solid var(--border2);
  color: var(--text2); cursor: pointer;
  transition: all .15s; white-space: nowrap;
  max-width: 200px; overflow: hidden; text-overflow: ellipsis;
}
.chat-chip:hover { background: rgba(78,127,255,.15); border-color: var(--primary); color: var(--primary); }

/* ── Messages area ───────────────────────────────── */
.chat-msgs {
  flex: 1; overflow-y: auto;
  padding: 12px 10px;
  display: flex; flex-direction: column; gap: 10px;
  scrollbar-width: thin; scrollbar-color: var(--border2) var(--surface);
}
.chat-msgs::-webkit-scrollbar { width: 4px; }
.chat-msgs::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }

/* ── Message bubbles ─────────────────────────────── */
.msg { display: flex; gap: 8px; align-items: flex-end; max-width: 100%; }
.msg.msg-user { flex-direction: row-reverse; }

.msg-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface2); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-bottom: 2px;
}
.msg-bot .msg-avatar { background: linear-gradient(135deg,rgba(78,127,255,.2),rgba(0,212,160,.12)); }
.msg-avatar svg { width: 14px; height: 14px; }

.msg-content { display: flex; flex-direction: column; gap: 2px; max-width: 86%; }
.msg-user .msg-content { align-items: flex-end; }

.msg-bubble {
  padding: 9px 13px; border-radius: 16px;
  font-size: .83rem; line-height: 1.6;
  word-break: break-word;
}
.msg-bot .msg-bubble {
  background: var(--surface2); border: 1px solid var(--border);
  border-bottom-left-radius: 4px; color: var(--text);
}
.msg-user .msg-bubble {
  background: linear-gradient(135deg,var(--primary),var(--primary-d));
  border-bottom-right-radius: 4px; color: #fff;
}
.msg-error .msg-bubble {
  background: rgba(255,107,107,.1); border-color: rgba(255,107,107,.3); color: var(--accent2);
}
.msg-time { font-size: .63rem; color: var(--text3); padding: 0 2px; }

/* Markdown styles inside bubbles */
.msg-bubble h2 { color: var(--primary); font-size: .9rem; margin: 10px 0 5px; }
.msg-bubble h3 { color: var(--primary); font-size: .82rem; margin: 8px 0 4px; border-bottom: 1px solid var(--border); padding-bottom: 3px; }
.msg-bubble strong { color: var(--text); font-weight: 700; }
.msg-bubble em    { color: var(--text2); font-style: italic; }
.msg-bubble code  {
  background: rgba(78,127,255,.12); border: 1px solid rgba(78,127,255,.2);
  border-radius: 4px; padding: 1px 5px;
  font-family: 'Fira Code', monospace; font-size: .78em; color: var(--accent);
}
.msg-bubble pre {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px; overflow-x: auto; margin: 6px 0; font-size: .77rem;
}
.msg-bubble pre code { background: transparent; border: none; padding: 0; color: var(--text); }
.msg-bubble ul, .msg-bubble ol { padding-left: 18px; margin: 4px 0; }
.msg-bubble li { margin-bottom: 3px; }
.msg-bubble blockquote {
  border-left: 3px solid var(--primary); padding-left: 10px; margin: 6px 0;
  color: var(--text2); font-style: italic;
}
.msg-bubble hr { border: none; border-top: 1px solid var(--border); margin: 8px 0; }
.msg-bubble a  { color: var(--primary); text-decoration: none; border-bottom: 1px dotted var(--primary); }
.msg-bubble a:hover { color: var(--accent); border-color: var(--accent); }

/* ── Typing dots ─────────────────────────────────── */
.typing-dots { display: flex; gap: 4px; align-items: center; height: 16px; }
.typing-dots span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--primary);
  animation: tdot 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .2s; background: var(--primary); }
.typing-dots span:nth-child(3) { animation-delay: .4s; background: var(--accent); }
@keyframes tdot {
  0%,80%,100% { transform: translateY(0); opacity:.45; }
  40%          { transform: translateY(-5px); opacity:1; }
}

/* ── Input area ──────────────────────────────────── */
.chat-input-area {
  padding: 9px 10px 11px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}
.chat-input-row { display: flex; gap: 7px; align-items: flex-end; }

#ai-chat-input {
  flex: 1;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 12px;
  padding: 8px 12px; color: var(--text);
  font-family: 'Be Vietnam Pro', sans-serif; font-size: .83rem; line-height: 1.45;
  resize: none; outline: none;
  min-height: 36px; max-height: 120px; overflow-y: auto;
  transition: border-color .15s, box-shadow .15s;
  scrollbar-width: thin; scrollbar-color: var(--border2) var(--surface2);
}
#ai-chat-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(78,127,255,.1);
}
#ai-chat-input::placeholder { color: var(--text3); }

#ai-chat-send {
  width: 36px; height: 36px; flex-shrink: 0;
  border-radius: 12px;
  background: linear-gradient(135deg,var(--primary),var(--primary-d));
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: opacity .15s, transform .15s;
}
#ai-chat-send:hover    { opacity: .9; transform: scale(1.06); }
#ai-chat-send:disabled { opacity: .35; cursor: not-allowed; transform: none; }
#ai-chat-send svg { width: 17px; height: 17px; }

.chat-input-hint {
  font-size: .64rem; color: var(--text3); text-align: center; margin-top: 5px;
}

/* ── Empty state ─────────────────────────────────── */
.chat-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  flex: 1; padding: 28px 20px; text-align: center; gap: 10px;
}
.chat-empty-icon {
  width: 60px; height: 60px; border-radius: 50%;
  background: rgba(78,127,255,.08); border: 1px solid rgba(78,127,255,.15);
  display: flex; align-items: center; justify-content: center;
}
.chat-empty-icon svg { width: 36px; height: 36px; }
.chat-empty-title { font-size: .9rem; font-weight: 700; color: var(--text); }
.chat-empty-sub   { font-size: .76rem; color: var(--text3); line-height: 1.6; }

/* ── Mobile ──────────────────────────────────────── */
@media (max-width: 480px) {
  #ai-chat-window {
    bottom: 0; right: 0;
    width: 100%; max-width: 100%;
    height: 76vh;
    border-radius: 20px 20px 0 0;
    border-bottom: none;
  }
  #ai-chat-btn { bottom: 18px; right: 18px; width: 54px; height: 54px; }
}
