/* MEGA Bot - mau chinh doi trong config.js; file nay de chinh bo cuc chi tiet */

:root,
:root[data-theme="light"] {
  --primary: #0b57d0;
  --primary-text: #ffffff;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #5f6873;
  --border: #dfe3e8;
  --hover: #eef1f4;
  --user-bubble: #e3ecfd;
  --price: #d0021b;
  --cheaper: #137333;
  --danger: #b3261e;
  --danger-bg: #fdecea;
  --code-bg: #f0f2f5;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px rgba(16, 24, 40, .06);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --content-width: 860px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --primary: #8ab4f8;
  --primary-text: #0b1b33;
  --bg: #141619;
  --surface: #1e2125;
  --text: #e6e8eb;
  --muted: #9aa3ad;
  --border: #30353b;
  --hover: #2a2e33;
  --user-bubble: #233452;
  --price: #ff6b6b;
  --cheaper: #6dd58c;
  --danger: #f2b8b5;
  --danger-bg: #3a1f1d;
  --code-bg: #2a2e33;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
svg { width: 20px; height: 20px; fill: currentColor; flex: none; }
.muted { color: var(--muted); }
.boot, .noscript { padding: 40px 16px; text-align: center; }
.offscreen { position: fixed; left: -9999px; top: 0; opacity: 0; }

/* ---------- Dang nhap ---------- */

.login-view { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  padding: 32px 28px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.login-brand { text-align: center; margin-bottom: 16px; }
.login-brand .logo { display: block; max-width: 180px; max-height: 56px; margin: 0 auto 12px; object-fit: contain; }
.login-brand h1 { margin: 0; font-size: 24px; line-height: 1.3; }
.login-brand p { margin: 4px 0 0; font-size: 14px; }
.login-card label { margin: 12px 0 6px; font-size: 14px; font-weight: 600; }
.login-card input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
}
.login-card input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 46px; }
.password-wrap .icon-btn { position: absolute; top: 4px; right: 4px; }
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
.icon-btn:hover, .icon-btn[aria-pressed="true"] { background: var(--hover); color: var(--text); }
.form-error { margin: 14px 0 0; padding: 8px 12px; font-size: 14px; color: var(--danger); background: var(--danger-bg); border-radius: 8px; }
.primary-btn {
  height: 44px;
  margin-top: 20px;
  font-weight: 600;
  color: var(--primary-text);
  background: var(--primary);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}
.primary-btn:hover { filter: brightness(1.06); }
.primary-btn:disabled { opacity: .65; cursor: progress; }
.hint { margin: 16px 0 0; font-size: 13px; text-align: center; }

/* ---------- Khung chat ---------- */

.chat-view { display: flex; flex-direction: column; height: 100%; height: 100dvh; }
.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 56px;
  padding: 0 12px 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-brand { display: flex; align-items: center; gap: 10px; min-width: 0; font-size: 17px; font-weight: 700; white-space: nowrap; }
.topbar-brand .logo { height: 28px; max-width: 120px; object-fit: contain; }
.topbar-actions { display: flex; align-items: center; gap: 4px; min-width: 0; }
.user-name { max-width: 220px; padding: 0 8px; overflow: hidden; font-size: 14px; color: var(--muted); white-space: nowrap; text-overflow: ellipsis; }
.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 10px;
  font-size: 14px;
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
.ghost-btn:hover { background: var(--hover); }

/* Thanh tab */
.tabs {
  flex: none;
  display: flex;
  gap: 6px;
  width: 100%;
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 8px 16px 0;
}
.tab {
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
}
.tab:hover { color: var(--text); background: var(--hover); }
.tab-active { color: var(--primary); background: var(--surface); border-color: var(--border); }

.messages { flex: 1; overflow-y: auto; padding: 24px 16px 8px; scroll-behavior: smooth; }
.list, .empty { max-width: var(--content-width); margin: 0 auto; }
.empty { padding: 8vh 0 24px; text-align: center; }
.empty h2 { margin: 0 0 6px; font-size: 22px; line-height: 1.35; }
.empty p { margin: 0; }
.suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 20px; }
.chip {
  padding: 8px 14px;
  font-size: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}
.chip:hover { color: var(--primary); border-color: var(--primary); }

.msg { display: flex; gap: 10px; margin: 0 0 18px; }
.msg-user { justify-content: flex-end; }
.msg-user .bubble {
  max-width: min(80%, 640px);
  padding: 10px 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--user-bubble);
  border-radius: 16px 16px 4px 16px;
}
.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin-top: 2px;
  font-size: 14px;
  font-weight: 700;
  color: var(--primary-text);
  background: var(--primary);
  border-radius: 50%;
}
.bot-wrap { flex: 1; min-width: 0; }
.msg-bot .bubble, .error-bubble {
  padding: 12px 16px;
  overflow-wrap: anywhere;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px 16px 16px 16px;
}
.msg-actions { margin: 2px 0 0 2px; }
.link-btn {
  padding: 2px 6px;
  font-size: 13px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}
.link-btn:hover { color: var(--primary); background: var(--hover); }
.msg-error .error-bubble { color: var(--danger); background: var(--danger-bg); border-color: transparent; }
.error-bubble p { margin: 0 0 2px; }
.error-bubble .link-btn { padding-left: 0; font-weight: 600; color: var(--danger); }
.error-bubble .link-btn:hover { background: transparent; text-decoration: underline; }

.msg-typing .bubble { display: inline-flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; background: currentColor; border-radius: 50%; animation: megabot-blink 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes megabot-blink {
  0%, 80%, 100% { opacity: .25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

/* Noi dung cau tra loi (markdown) */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 10px; }
.md ul, .md ol { margin: 4px 0 10px; padding-left: 22px; }
.md li { margin: 2px 0; }
.md a { color: var(--primary); text-decoration: none; }
.md a:hover { text-decoration: underline; }
.md code { padding: 1px 5px; font-size: .9em; background: var(--code-bg); border-radius: 4px; }
.md pre { padding: 10px 12px; overflow-x: auto; background: var(--code-bg); border-radius: 8px; }
.md pre code { padding: 0; background: none; }
.md h3, .md h4, .md h5, .md h6 { margin: 12px 0 6px; font-size: 16px; }
.md hr { margin: 12px 0; border: 0; border-top: 1px solid var(--border); }
.price { color: var(--price); font-weight: 700; }
.cheaper { color: var(--cheaper); font-weight: 700; }
.md .table-wrap { margin: 6px 0 12px; overflow-x: auto; }
.md table { width: 100%; font-size: 14px; border-collapse: collapse; }
.md th, .md td { padding: 7px 10px; border: 1px solid var(--border); text-align: left; vertical-align: top; }
.md th { font-weight: 600; white-space: nowrap; background: var(--hover); }
.md tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--hover) 45%, transparent); }

/* O nhap cau hoi */
.composer { flex: none; padding: 8px 16px calc(10px + env(safe-area-inset-bottom)); }
.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 6px 6px 6px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.composer-box:focus-within { border-color: var(--primary); }
.composer textarea {
  flex: 1;
  max-height: 160px;
  padding: 8px 0;
  line-height: 1.5;
  background: transparent;
  border: 0;
  outline: none;
  resize: none;
}
.send-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  color: var(--primary-text);
  background: var(--primary);
  border: 0;
  border-radius: 12px;
  cursor: pointer;
}
.send-btn:disabled { opacity: .35; cursor: default; }
.composer-note { max-width: var(--content-width); margin: 6px auto 0; font-size: 12px; text-align: center; }

@media (max-width: 640px) {
  .topbar { padding: 0 6px 0 14px; }
  .tabs { padding: 6px 10px 0; }
  .tab { padding: 7px 10px; font-size: 13px; }
  .md table { font-size: 13px; }
  .md th, .md td { padding: 6px 8px; }
  .btn-label { display: none; }
  .user-name { max-width: 120px; padding: 0 4px; }
  .messages { padding: 16px 10px 8px; }
  .msg { gap: 0; }
  .avatar { display: none; }
  .msg-user .bubble { max-width: 88%; }
  .msg-bot .bubble, .error-bubble { padding: 10px 12px; }
  .composer { padding-right: 8px; padding-left: 8px; }
  .composer textarea, .login-card input { font-size: 16px; }
  .composer-note { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .dots i { animation: none; opacity: .6; }
  .messages { scroll-behavior: auto; }
}
