/* ai.mora.vn — bộ nhận diện MORA (brand.mora.vn; cùng token với account.mora.vn):
   xanh MORA #0077B2 · hover #00669A · nền nhạt #E6F2F8 · navy #0B1220 · chữ #1F2328; MORA AI: dải #38BDF8 → #0077B2 → #1E3A8A.
   Chữ Plus Jakarta Sans (tự phục vụ). Không style nội tuyến (CSP). Đo 320/375/768/1280/1440/2000px trước khi phát hành. */

@font-face { font-family: "Plus Jakarta Sans"; font-style: normal; font-weight: 400 800; font-display: swap;
  src: url("fonts/pjs-vietnamese.woff2") format("woff2");
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB; }
@font-face { font-family: "Plus Jakarta Sans"; font-style: normal; font-weight: 400 800; font-display: swap;
  src: url("fonts/pjs-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

:root {
  --blue: #0077B2; --blue-hover: #00669A; --blue-active: #005681; --blue-soft: #E6F2F8; --blue-line: #B9DCEE;
  --sky: #38BDF8; --deep: #1E3A8A;
  --navy: #0B1220; --ink: #1F2328; --ink-2: #3B4252; --mute: #5B6478; --line: #E3E8EF; --line-2: #D5DCE6;
  --bg: #F6F8FC; --surface: #FFFFFF; --surface-2: #F1F4F9; --hover: #EEF3F9;
  --ok: #047857; --ok-soft: #E3F4EC; --warn: #B45309; --warn-soft: #FDF1E1; --err: #C8102E; --err-soft: #FCE8EC;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.06);
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 28px rgba(16,24,40,.08);
  --radius: 14px; --radius-sm: 10px;
  --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
  --gutter: 16px; --side: 288px; --read: 800px;
  color-scheme: light;
}
@media (min-width: 720px) { :root { --gutter: 24px; } }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.6 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
img, svg { display: block; max-width: 100%; }
a { color: var(--blue); text-decoration: none; }
a:hover { color: var(--blue-hover); text-decoration: underline; text-underline-offset: 3px; }
h1, h2, h3 { line-height: 1.25; letter-spacing: -.015em; margin: 0; text-wrap: balance; }
p { margin: 0; }
button { font: inherit; color: inherit; }
.muted { color: var(--mute); }
.small { font-size: 14px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid rgba(0,119,178,.45); outline-offset: 2px; border-radius: 8px; }
.skip { position: absolute; left: -9999px; top: 8px; z-index: 60; background: var(--surface); padding: 8px 14px; border-radius: 8px; box-shadow: var(--shadow); }
.skip:focus { left: 8px; }
.ic { width: 20px; height: 20px; flex: none; }

/* ---------- nút ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 0 16px;
  font: 600 15px/1.2 var(--font); border-radius: var(--radius-sm); border: 1px solid var(--line-2); background: var(--surface);
  color: var(--ink); cursor: pointer; text-decoration: none; transition: background-color .15s, border-color .15s, color .15s; }
.btn:hover { background: var(--hover); color: var(--ink); text-decoration: none; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; box-shadow: 0 1px 2px rgba(0,86,129,.25); }
.btn.primary:hover { background: var(--blue-hover); border-color: var(--blue-hover); color: #fff; }
.btn.primary:active { background: var(--blue-active); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--hover); }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.lg { min-height: 50px; padding: 0 24px; font-size: 16px; }
.btn.danger { color: var(--err); }
.btn[disabled] { opacity: .55; cursor: default; }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 10px; background: transparent;
  color: var(--ink-2); cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--hover); }

.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--navy); text-decoration: none; }
.brand:hover { text-decoration: none; color: var(--navy); }
.brand img { border-radius: 8px; }
.brand-word { font-weight: 700; font-size: 18px; letter-spacing: .02em; }
.brand-word b { font-weight: 800; background: linear-gradient(90deg, var(--blue), var(--deep)); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---------- trang thường (giới thiệu, điều khoản, thông báo) ---------- */
body.page { min-height: 100vh; display: flex; flex-direction: column;
  background: var(--bg) radial-gradient(1200px 560px at 85% -10%, var(--blue-soft) 0%, rgba(230,242,248,0) 62%) no-repeat; }
.wrap { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 var(--gutter); }
.wrap.narrow { max-width: 720px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.site-head { padding: 14px 0; }
.site-foot { margin-top: auto; padding: 28px 0; color: var(--mute); font-size: 14px; border-top: 1px solid var(--line); }
.landing { flex: 1 0 auto; }
.hero { text-align: center; padding-top: 40px; padding-bottom: 32px; }
.hero-ic { margin: 0 auto 20px; border-radius: 22px; box-shadow: 0 12px 40px rgba(0,119,178,.25); }
.hero h1 { font-size: clamp(32px, 6vw, 54px); font-weight: 800; }
.hero .accent { background: linear-gradient(90deg, var(--sky), var(--blue) 45%, var(--deep)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.lead { max-width: 640px; margin: 18px auto 0; font-size: 18px; color: var(--ink-2); }
.cta { margin: 28px 0 12px; display: flex; justify-content: center; }
.features { display: grid; grid-template-columns: 1fr; gap: 14px; padding-bottom: 56px; }
@media (min-width: 720px) { .features { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1100px) { .features { grid-template-columns: repeat(4, 1fr); } }
.feat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm); }
.feat h2 { font-size: 17px; margin-bottom: 6px; }
.feat p { color: var(--ink-2); font-size: 15px; }
.doc { padding-top: 16px; padding-bottom: 56px; }
.doc h1 { font-size: 28px; }
.doc h2 { font-size: 18px; margin: 26px 0 8px; }
.doc ul { padding-left: 20px; margin: 0; }
.doc li { margin: 6px 0; color: var(--ink-2); }
.consent-form { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 28px; }
.msg { padding-top: 32px; padding-bottom: 56px; }
.msg-card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 28px; box-shadow: var(--shadow); text-align: center; }
.msg-card img { margin: 0 auto 14px; border-radius: 12px; }
.msg-card h1 { font-size: 22px; margin-bottom: 10px; }
.msg-card p { color: var(--ink-2); overflow-wrap: anywhere; }
.msg-card p + p { margin-top: 10px; }
.msg-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 20px; }
@media (max-width: 560px) {
  .btn { white-space: normal; text-align: center; }
  .consent-form .btn, .msg-actions .btn, .msg-actions form { width: 100%; }
}

/* ---------- khung trò chuyện ---------- */
body.chat { height: 100vh; height: 100dvh; overflow: hidden; }
.shell { display: flex; height: 100%; }
.side { width: var(--side); flex: none; display: flex; flex-direction: column; gap: 10px; padding: 14px 12px;
  background: var(--surface); border-right: 1px solid var(--line); min-height: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 6px; }
.new-chat { width: 100%; justify-content: flex-start; }
.side-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--mute); padding: 8px 8px 0; }
.conv-list { flex: 1 1 auto; overflow-y: auto; min-height: 0; display: flex; flex-direction: column; gap: 2px; margin: 0 -4px; padding: 0 4px; }
.side-empty { color: var(--mute); font-size: 14px; padding: 6px 8px; }
.conv { display: flex; align-items: center; gap: 4px; border-radius: 10px; }
.conv a { flex: 1 1 auto; min-width: 0; display: block; padding: 9px 10px; color: var(--ink-2); font-size: 14.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-radius: 10px; }
.conv a:hover { background: var(--hover); text-decoration: none; color: var(--ink); }
.conv.active a { background: var(--blue-soft); color: var(--blue-active); font-weight: 600; }
.conv .del { opacity: 0; width: 32px; height: 32px; }
.conv:hover .del, .conv.active .del, .conv .del:focus-visible { opacity: 1; }
@media (hover: none) { .conv .del { opacity: 1; } }
.side-foot { border-top: 1px solid var(--line); padding-top: 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.me { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none; color: #fff; font-weight: 700;
  background: linear-gradient(135deg, var(--sky), var(--blue) 55%, var(--deep)); }
.me-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.me-text b, .me-text small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-text b { font-size: 14px; }
.me-text small { color: var(--mute); font-size: 12.5px; }

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; min-height: 0;
  background: var(--bg) radial-gradient(1000px 420px at 100% -8%, var(--blue-soft) 0%, rgba(230,242,248,0) 60%) no-repeat; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 10px var(--gutter); min-height: 58px; border-bottom: 1px solid transparent; }
.conv-title { flex: 1 1 auto; min-width: 0; font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.only-narrow { display: none; }

.thread { flex: 1 1 auto; overflow-y: auto; min-height: 0; padding: 8px var(--gutter) 24px; scroll-behavior: smooth; }
.thread > * { max-width: var(--read); margin-left: auto; margin-right: auto; }
.welcome { text-align: center; padding: min(10vh, 80px) 0 24px; }
.welcome-ic { margin: 0 auto 16px; border-radius: 18px; box-shadow: 0 10px 30px rgba(0,119,178,.22); }
.welcome h2 { font-size: clamp(22px, 4vw, 30px); font-weight: 800; }
.welcome > p { max-width: 600px; margin: 10px auto 0; }
.suggest { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 22px; }
.chip { border: 1px solid var(--line-2); background: var(--surface); border-radius: 999px; padding: 8px 14px; font-size: 14px; font-weight: 600;
  color: var(--ink-2); cursor: pointer; box-shadow: var(--shadow-sm); }
.chip:hover { border-color: var(--blue-line); background: var(--blue-soft); color: var(--blue-active); }
.perm { margin: 18px auto 0; max-width: 600px; font-size: 14px; color: var(--warn); background: var(--warn-soft); border-radius: 10px; padding: 10px 14px; }

.msg-user { display: flex; justify-content: flex-end; margin: 18px auto 6px; }
.bubble { max-width: min(640px, 88%); background: var(--blue); color: #fff; padding: 10px 16px; border-radius: 18px 18px 4px 18px;
  white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: 0 1px 2px rgba(0,86,129,.2); }
.msg-ai { display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 12px; margin: 14px auto; }
.msg-ai > img { width: 32px; height: 32px; border-radius: 9px; margin-top: 2px; }
.ai-body { min-width: 0; display: flex; flex-direction: column; gap: 8px; }

/* nội dung Markdown của trợ lý */
.md { overflow-wrap: anywhere; color: var(--ink); }
.md > * + * { margin-top: .7em; }
.md h1, .md h2, .md h3, .md h4 { font-size: 1.08em; font-weight: 700; margin-top: 1em; }
.md h1 { font-size: 1.22em; }
.md ul, .md ol { padding-left: 1.4em; margin-bottom: 0; }
.md li + li { margin-top: .25em; }
.md blockquote { margin: 0; padding: 4px 14px; border-left: 3px solid var(--blue-line); color: var(--ink-2); }
.md code { font-family: var(--mono); font-size: .88em; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 5px; }
.md pre { background: var(--navy); color: #E6EBF3; padding: 12px 14px; border-radius: 10px; overflow-x: auto; font-size: 13.5px; line-height: 1.5; }
.md pre code { background: none; border: 0; padding: 0; color: inherit; overflow-wrap: normal; white-space: pre; }
.md hr { border: 0; border-top: 1px solid var(--line); }
.md a { overflow-wrap: anywhere; }
.tbl { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.md table { border-collapse: collapse; width: 100%; font-size: 14.5px; }
.md th, .md td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; min-width: 90px; }
.md th { background: var(--surface-2); font-weight: 700; }
.md tr:last-child td { border-bottom: 0; }
.caret::after { content: ""; display: inline-block; width: 8px; height: 1.1em; vertical-align: -3px; margin-left: 2px; background: var(--blue); border-radius: 2px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.note { color: var(--ink-2); font-style: italic; }

/* hoạt động công cụ */
.act { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--ink-2); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 12px; flex-wrap: wrap; }
.act .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.act.run .dot { background: var(--blue); animation: pulse 1s ease-in-out infinite; }
.act.bad .dot { background: var(--warn); }
.act .lbl { flex: 1 1 200px; min-width: 0; overflow-wrap: anywhere; }
.act a { font-weight: 600; white-space: nowrap; }
@keyframes pulse { 50% { transform: scale(.6); opacity: .5; } }
.thinking { display: inline-flex; gap: 5px; padding: 6px 0; }
.thinking i { width: 7px; height: 7px; border-radius: 50%; background: var(--blue-line); animation: bounce 1.2s infinite; }
.thinking i:nth-child(2) { animation-delay: .15s; } .thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); opacity: .5; } 40% { transform: translateY(-5px); opacity: 1; } }

/* thẻ xác nhận */
.card { border: 1px solid var(--blue-line); background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px; background: var(--blue-soft);
  font-weight: 700; color: var(--blue-active); flex-wrap: wrap; }
.card-state { font-size: 13px; font-weight: 700; padding: 2px 10px; border-radius: 999px; background: var(--surface); color: var(--ink-2); }
.card-state.ok { color: var(--ok); background: var(--ok-soft); }
.card-state.no { color: var(--mute); }
.card-body { padding: 12px 14px; display: grid; gap: 6px; font-size: 14.5px; }
.card-row { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 8px; }
.card-row > span:first-child { color: var(--mute); }
.card-row > span:last-child { overflow-wrap: anywhere; }
.card-text { margin-top: 6px; padding: 10px 12px; background: var(--surface-2); border-radius: 10px; white-space: pre-wrap; overflow-wrap: anywhere;
  max-height: 280px; overflow-y: auto; font-size: 14px; }
.card-note { color: var(--mute); font-size: 13px; }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 14px 14px; }
.card.done .card-actions { display: none; }

.err { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: var(--err-soft); color: var(--err); border-radius: 10px; padding: 10px 14px; font-size: 14.5px; }
.err span { flex: 1 1 220px; }
.notice { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 10px 14px; font-size: 14.5px; }

/* ô nhập */
.composer-wrap { padding: 8px var(--gutter) max(12px, env(safe-area-inset-bottom)); }
.composer { max-width: var(--read); margin: 0 auto; display: flex; align-items: flex-end; gap: 8px; background: var(--surface);
  border: 1px solid var(--line-2); border-radius: 20px; padding: 8px 8px 8px 16px; box-shadow: var(--shadow); }
.composer:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0,119,178,.15), var(--shadow); }
.composer textarea { flex: 1 1 auto; min-width: 0; border: 0; outline: 0; resize: none; background: transparent; font: 16px/1.5 var(--font);
  color: var(--ink); max-height: 40vh; padding: 7px 0; }
.send, .stop { width: 40px; height: 40px; border-radius: 12px; border: 0; display: grid; place-items: center; cursor: pointer; flex: none; color: #fff; background: var(--blue); }
.send:hover { background: var(--blue-hover); }
.send[disabled] { background: var(--line-2); cursor: default; }
.stop { background: var(--navy); }
.fine { max-width: var(--read); margin: 6px auto 0; text-align: center; font-size: 12.5px; color: var(--mute); }
.quota { margin-left: 8px; }

/* màn hẹp: danh sách hội thoại trượt ra */
@media (max-width: 959px) {
  .only-narrow { display: inline-grid; }
  .side { position: fixed; z-index: 40; top: 0; bottom: 0; left: 0; width: min(86vw, var(--side)); transform: translateX(-102%);
    transition: transform .2s ease; box-shadow: var(--shadow); }
  .side.open { transform: none; }
  .scrim { position: fixed; inset: 0; z-index: 30; background: rgba(11,18,32,.35); }
  .topbar { border-bottom-color: var(--line); background: rgba(255,255,255,.85); }
}
@media (max-width: 560px) {
  .msg-ai { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .msg-ai > img { width: 26px; height: 26px; }
  .card-row { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .card-actions .btn { flex: 1 1 140px; }
  .bubble { max-width: 92%; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
