/* INSPiRE Chatbot - giao diện v2 (màu & font theo lib.tdtu.edu.vn)
   Navy #051E5B · Cam #F68235 · Xám #404040 / #F0F3F6 · Barlow (tiêu đề) + Mulish (nội dung)
   Lưu ý: style.css cũ vẫn giữ nguyên vì trang /admin/logs còn dùng. */

:root {
  --navy: #051E5B;
  --orange: #F68235;
  --orange-ink: #B85410;      /* cam đậm cho chữ trên nền trắng (đủ tương phản) */
  --bg: #F0F3F6;
  --surface: #FFFFFF;
  --border: #DEE2E8;
  --border-strong: #D5DDE8;
  --text: #333333;
  --text-2: #404040;
  --muted: #5F6670;
  --tint: #FDEEE3;            /* nền nhạt cho avatar/icon */
  --chip-src: #FEF1E7;
  --user-bg: var(--navy);
  --user-fg: #FFFFFF;
  --hover: #F0F3F6;
  --faq-bg: #EAF6EF;
  --faq-fg: #17663E;
  --online: #1E9E5A;
  --error: #B4232A;
  --shadow: 0 1px 2px rgba(5, 30, 91, .06);
  --radius: 16px;
  --font-body: 'Mulish', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-head: 'Barlow', 'Mulish', system-ui, sans-serif;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #081530;
  --surface: #0E2147;
  --border: #1E3566;
  --border-strong: #2A4378;
  --text: #E6EBF3;
  --text-2: #D3DAE6;
  --muted: #A3AEC4;
  --tint: #16305E;
  --chip-src: #16305E;
  --user-bg: var(--orange);
  --user-fg: var(--navy);
  --hover: #13294F;
  --faq-bg: #173A2A;
  --faq-fg: #7FD9A8;
  --online: #34C27A;
  --orange-ink: #FFB37F;
  --error: #FF8A8A;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
a { color: var(--navy); }
:root[data-theme="dark"] a { color: var(--orange-ink); }
a:hover { color: var(--orange-ink); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { width: 20px; height: 20px; flex-shrink: 0; }
:focus-visible { outline: 3px solid rgba(246, 130, 53, .55); outline-offset: 2px; }

/* ---------- Bố cục ---------- */
.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

.sidebar {
  width: 272px; flex-shrink: 0;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 20px; padding: 20px 16px;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px; text-decoration: none; color: inherit; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 12px; background: var(--navy);
  display: flex; align-items: center; justify-content: center; color: #fff; flex-shrink: 0;
}
:root[data-theme="dark"] .brand-mark { background: var(--orange); color: var(--navy); }
.brand-name { font-family: var(--font-head); font-weight: 700; font-size: 20px; letter-spacing: .01em; color: var(--navy); line-height: 1.1; }
:root[data-theme="dark"] .brand-name { color: #fff; }
.brand-name span { color: var(--orange); }
.brand-sub { font-size: 12px; color: var(--muted); }

.btn-new {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; border: 0; border-radius: 12px; cursor: pointer;
  background: var(--orange); color: var(--navy); font-weight: 700; font-size: 14px;
}
.btn-new:hover { filter: brightness(1.05); }

.topics { display: flex; flex-direction: column; gap: 4px; }
.topics-title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; padding: 0 10px 6px; }
.topic {
  display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 10px;
  border: 0; border-radius: 10px; background: transparent; cursor: pointer;
  font-size: 14px; color: var(--text-2); text-align: left;
}
.topic:hover { background: var(--hover); }
.topic-ico {
  width: 30px; height: 30px; border-radius: 8px; background: var(--tint); color: var(--navy);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
:root[data-theme="dark"] .topic-ico { color: var(--orange); }
.topic-ico .icon { width: 16px; height: 16px; }

.help-card {
  margin-top: auto; display: flex; flex-direction: column; gap: 8px;
  padding: 16px; border-radius: 12px; background: var(--navy); color: #fff;
}
:root[data-theme="dark"] .help-card { background: #13294F; }
.help-card strong { font-size: 13px; }
.help-card span { font-size: 12px; color: #C9D1E3; line-height: 1.5; }
.help-card a { font-size: 13px; font-weight: 700; text-decoration: none; color: #FFB37F; }
.help-card a:hover { color: #FFD2B3; }

/* ---------- Khung chat ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 72px; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 28px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.bot-avatar {
  position: relative; width: 40px; height: 40px; border-radius: 50%; background: var(--tint); color: var(--navy);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
:root[data-theme="dark"] .bot-avatar { color: var(--orange); }
.bot-avatar .dot { position: absolute; right: 0; bottom: 0; width: 11px; height: 11px; border-radius: 50%; background: var(--online); border: 2px solid var(--surface); }
.bot-name { font-family: var(--font-head); font-weight: 600; font-size: 17px; color: var(--navy); }
:root[data-theme="dark"] .bot-name { color: #fff; }
.bot-status { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 10px; background: transparent; color: var(--muted);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.link-btn {
  height: 44px; display: flex; align-items: center; gap: 8px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--border-strong);
  font-size: 13px; font-weight: 700; color: var(--text-2); text-decoration: none;
}
:root[data-theme="dark"] .link-btn { color: var(--text-2); }
.link-btn:hover { border-color: var(--orange); color: var(--orange-ink); }
.menu-btn { display: none; }

.chat-scroll { flex: 1; min-height: 0; overflow-y: auto; scroll-behavior: smooth; }
.chat-inner { max-width: 820px; margin: 0 auto; padding: 28px 28px 12px; display: flex; flex-direction: column; gap: 22px; }

.welcome {
  display: flex; flex-direction: column; gap: 16px; padding: 24px;
  border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.welcome h1 { margin: 0; font-family: var(--font-head); font-size: 26px; font-weight: 700; color: var(--navy); }
:root[data-theme="dark"] .welcome h1 { color: #fff; }
.welcome p { margin: 0; font-size: 14px; color: var(--muted); line-height: 1.6; }
.chips { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.chip {
  display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 10px 14px;
  border-radius: 12px; border: 1px solid var(--border); background: var(--surface);
  font-size: 14px; color: var(--text-2); text-align: left; cursor: pointer;
}
.chip:hover { border-color: var(--orange); background: var(--hover); }
.chip .icon { width: 16px; height: 16px; color: var(--orange-ink); }

/* Tin nhắn */
.msg { display: flex; flex-direction: column; gap: 4px; animation: msg-in .2s ease-out; }
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg-user { align-items: flex-end; }
.msg-user .bubble {
  max-width: 72%; padding: 12px 16px; border-radius: 18px 18px 4px 18px;
  background: var(--user-bg); color: var(--user-fg); font-size: 15px; line-height: 1.55;
  white-space: pre-wrap; word-wrap: break-word;
}
.msg-time { font-size: 11px; color: var(--muted); }

.msg-bot { flex-direction: row; gap: 12px; align-items: flex-start; }
.msg-bot .bot-avatar { width: 34px; height: 34px; }
.msg-bot .stack { max-width: 82%; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.msg-bot .bubble {
  padding: 14px 18px; border-radius: 4px 18px 18px 18px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  font-size: 15px; line-height: 1.6; word-wrap: break-word;
}
.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }
.bubble p { margin: 0 0 8px; }
.bubble ul, .bubble ol { margin: 4px 0 8px; padding-left: 20px; }
.bubble li { margin: 3px 0; }
.bubble strong { color: var(--text-2); }
.bubble a { font-weight: 600; }
.bubble table { border-collapse: collapse; margin: 8px 0; font-size: 14px; display: block; overflow-x: auto; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }

.sources { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-top: 10px; margin-top: 10px; border-top: 1px solid var(--border); }
.sources-label { font-size: 12px; font-weight: 700; color: var(--muted); }
.source-chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  padding: 5px 10px; border-radius: 999px; background: var(--chip-src);
  font-size: 12px; font-weight: 600; text-decoration: none;
}
.source-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-chip .icon { width: 12px; height: 12px; }
.badge-faq { display: inline-block; margin-top: 10px; padding: 3px 9px; border-radius: 999px; background: var(--faq-bg); color: var(--faq-fg); font-size: 12px; font-weight: 700; }

.msg-actions { display: flex; align-items: center; gap: 2px; }
.msg-actions .msg-time { margin-right: 6px; }
.act {
  width: 32px; height: 32px; border: 0; border-radius: 8px; background: transparent; color: var(--muted);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.act:hover { background: var(--hover); color: var(--text); }
.act.on { background: var(--tint); color: var(--orange-ink); }
.act .icon { width: 15px; height: 15px; }

.typing { display: flex; gap: 12px; align-items: center; }
.typing .dots { display: flex; gap: 5px; padding: 14px 18px; border-radius: 4px 18px 18px 18px; background: var(--surface); border: 1px solid var(--border); }
.typing .dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--orange); animation: bounce 1.2s infinite ease-in-out; }
.typing .dots span:nth-child(2) { animation-delay: .15s; }
.typing .dots span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); opacity: .45; } 40% { transform: translateY(-4px); opacity: 1; } }

/* Ô nhập */
.composer { flex-shrink: 0; padding: 12px 28px 18px; }
.composer-inner { max-width: 764px; margin: 0 auto; display: flex; flex-direction: column; gap: 8px; }
.input-box {
  display: flex; align-items: flex-end; gap: 10px; padding: 8px 8px 8px 18px;
  border-radius: 16px; background: var(--surface); border: 1px solid var(--border-strong);
  transition: border-color .15s, box-shadow .15s;
}
.input-box:focus-within { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(246, 130, 53, .18); }
#user-input {
  flex: 1; min-width: 0; resize: none; border: 0; outline: none; background: transparent;
  font: inherit; font-size: 15px; line-height: 1.5; color: var(--text);
  padding: 10px 0; max-height: 160px;
}
#user-input::placeholder { color: var(--muted); }
.char-counter { font-size: 12px; color: var(--muted); padding-bottom: 13px; white-space: nowrap; }
.char-counter.warn { color: var(--error); font-weight: 700; }
.send-btn {
  width: 44px; height: 44px; flex-shrink: 0; border: 0; border-radius: 12px; cursor: pointer;
  background: var(--orange); color: var(--navy); display: flex; align-items: center; justify-content: center;
}
.send-btn:disabled { opacity: .45; cursor: not-allowed; }
.disclaimer { font-size: 12px; color: var(--muted); text-align: center; margin: 0; }
.error-message { font-size: 13px; color: var(--error); text-align: center; margin: 0; }
.hidden { display: none !important; }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translate(-50%, 12px);
  padding: 10px 16px; border-radius: 999px; background: var(--navy); color: #fff;
  font-size: 13px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.scrim { display: none; }

/* ---------- Điện thoại / máy tính bảng ---------- */
@media (max-width: 880px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40; width: 286px;
    transform: translateX(-100%); transition: transform .22s ease; box-shadow: 0 10px 40px rgba(5, 30, 91, .25);
  }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(5, 30, 91, .35); }
  .menu-btn { display: flex; }
  .topbar { padding: 0 8px 0 4px; height: 64px; border-bottom: 3px solid var(--orange); }
  .link-btn { display: none; }
  .chat-inner { padding: 18px 16px 8px; gap: 18px; }
  .welcome { padding: 18px; }
  .welcome h1 { font-size: 22px; }
  .chips { grid-template-columns: minmax(0, 1fr); }
  .msg-user .bubble { max-width: 85%; font-size: 14px; }
  .msg-bot .stack { max-width: calc(100% - 42px); }
  .msg-bot .bubble { font-size: 14px; padding: 13px 15px; }
  .msg-bot > .bot-avatar { width: 30px; height: 30px; }
  .composer { padding: 8px 12px 14px; }
  .input-box { padding: 6px 6px 6px 16px; }
  .bot-status { max-width: 170px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
