:root {
  --brand: #2387E3;
  --brand-ink: #ffffff;
  --navy: #334862;
  --bg: #f3f6fa;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1f2937;
  --muted: #64748b;
  --cite-bg: #e8f2fc;
  --cite-ink: #1C75BC;
  --warn-bg: #fff4e0;
  --warn-ink: #8a5a00;
  --danger-bg: #fdecea;
  --danger-ink: #b3261e;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { font-family: "Be Vietnam Pro", "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 15px; }
button { font-family: inherit; }
button:focus-visible, textarea:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

.app { height: 100%; display: flex; flex-direction: column; max-width: 860px; margin: 0 auto; background: var(--bg); }
@media (min-width: 900px) { body:not(.embed) .app { border-left: 1px solid var(--border); border-right: 1px solid var(--border); } }

.head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; padding-top: calc(12px + env(safe-area-inset-top, 0px)); background: var(--brand); color: var(--brand-ink); flex: none; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: rgba(255,255,255,.2); display: grid; place-items: center; font-weight: 700; font-size: .8rem; flex: none; overflow: hidden; position: relative; }
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #fff; }
.head-text { flex: 1; min-width: 0; line-height: 1.3; }
.head-text b { display: block; font-size: .98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-text small { opacity: .9; font-size: .74rem; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-btn { background: rgba(255,255,255,.16); color: var(--brand-ink); border: 1px solid rgba(255,255,255,.35); border-radius: 999px; padding: 5px 12px; font-size: .8rem; cursor: pointer; white-space: nowrap; }
.head-btn:hover { background: rgba(255,255,255,.28); }
.head-btn.icon { width: 32px; height: 32px; padding: 0; font-size: 1rem; display: grid; place-items: center; }
.head-btn.user { background: rgba(255,255,255,.95); color: var(--navy); border-color: transparent; }

.log { flex: 1; overflow-y: auto; padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 12px; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { .log { scroll-behavior: auto; } }

.msg { max-width: 88%; padding: 10px 13px; border-radius: 14px; line-height: 1.55; font-size: .92rem; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--brand); color: var(--brand-ink); border-top-right-radius: 4px; white-space: pre-wrap; }
.msg.bot { align-self: flex-start; background: var(--card); border: 1px solid var(--border); border-top-left-radius: 4px; }
.msg.bot p { margin: 0 0 8px; }
.msg.bot p:last-child, .msg.bot ul:last-child, .msg.bot ol:last-child { margin-bottom: 0; }
.msg.bot ul, .msg.bot ol { margin: 0 0 8px; padding-left: 20px; }
.msg.bot li { margin: 2px 0; }
.msg.bot a { color: var(--cite-ink); }
.msg.bot.notice { background: var(--warn-bg); border-color: #f3d9a4; }
.msg.bot.staff { background: #eef7ef; border-color: #b9dcbf; }
.foot-actions { display: flex; gap: 14px; }
button.handoff { border: 0; cursor: pointer; font-family: inherit; }
.msg.bot.alert { background: var(--danger-bg); border-color: #f5c2bd; }

.cite { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 4px; margin: 0 1px; border-radius: 5px; border: 0; background: var(--cite-bg); color: var(--cite-ink); font-size: .7rem; font-weight: 700; vertical-align: 2px; cursor: pointer; line-height: 1; }
.cite:hover { background: var(--cite-ink); color: #fff; }

.sources { margin-top: 10px; border-top: 1px dashed var(--border); padding-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.sources summary { cursor: pointer; font-size: .76rem; color: var(--muted); font-weight: 600; list-style: none; }
.sources summary::-webkit-details-marker { display: none; }
.sources summary::before { content: "▸ "; }
.sources[open] summary::before { content: "▾ "; }
.src { font-size: .78rem; color: var(--muted); padding: 6px 8px; border-radius: 8px; background: var(--bg); margin-top: 6px; }
.src b { color: var(--text); font-weight: 600; }
.src.flash { outline: 2px solid var(--cite-ink); }
.src .ex { margin-top: 3px; font-style: italic; }

.actions { display: flex; gap: 6px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.fb { border: 1px solid var(--border); background: var(--card); border-radius: 999px; padding: 2px 9px; font-size: .8rem; cursor: pointer; color: var(--muted); }
.fb[aria-pressed="true"] { border-color: var(--brand); background: var(--cite-bg); }
.fb:disabled { cursor: default; }
.handoff { display: inline-flex; align-items: center; gap: 6px; background: var(--brand); color: var(--brand-ink); border-radius: 999px; padding: 5px 12px; font-size: .82rem; text-decoration: none; font-weight: 600; }

.sugg { display: flex; flex-wrap: wrap; gap: 7px; align-self: flex-start; max-width: 100%; }
.sugg button { border: 1px solid var(--brand); color: var(--brand); background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: .84rem; cursor: pointer; text-align: left; }
.sugg button:hover { background: var(--cite-bg); }

.typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); opacity: .4; animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .typing i { animation: none; opacity: .7; } }

.composer { display: flex; gap: 8px; padding: 10px 12px; background: var(--card); border-top: 1px solid var(--border); flex: none; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--border); border-radius: 20px; padding: 9px 14px; font: inherit; font-size: .92rem; max-height: 140px; line-height: 1.45; background: var(--card); color: var(--text); }
.composer button { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--brand); color: var(--brand-ink); cursor: pointer; display: grid; place-items: center; flex: none; }
.composer button:disabled { opacity: .45; cursor: default; }
.foot { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: .7rem; color: var(--muted); padding: 0 14px 8px; padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); background: var(--card); flex: none; }
.link { background: none; border: 0; color: var(--cite-ink); text-decoration: underline; font-size: .74rem; cursor: pointer; padding: 0; font-weight: 600; }

.sheet { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet-box { background: var(--card); width: 100%; max-width: 520px; border-radius: 16px 16px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom, 0px)); max-height: 90%; overflow: auto; }
@media (min-width: 600px) { .sheet { align-items: center; } .sheet-box { border-radius: 16px; } }
.sheet-box h3 { margin: 0 0 6px; color: var(--navy); font-size: 1.05rem; }
.sheet-box p { margin: 0 0 10px; font-size: .84rem; color: var(--muted); }
.sheet-box label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin: 10px 0 4px; }
.sheet-box input, .sheet-box textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; font: inherit; font-size: .9rem; }
.sheet-box label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 500; color: var(--text); }
.sheet-box label.check input { width: auto; margin-top: 3px; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.btn { border: 1px solid var(--brand); background: var(--brand); color: var(--brand-ink); border-radius: 8px; padding: 8px 16px; cursor: pointer; font-size: .88rem; }
.btn.sec { background: var(--card); color: var(--brand); }
.err { color: var(--danger-ink); font-size: .8rem; margin-top: 8px; }

/* Chan trang don vi (trang chat day du, trang hoc tap) */
#org-footer { border-top: 1px solid var(--border); background: var(--card); color: var(--muted); font-size: .76rem; line-height: 1.55; padding: 12px 16px; flex: none; }
.org-foot-in { max-width: 980px; margin: 0 auto; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.org-foot-logo { height: 36px; width: auto; max-width: 120px; object-fit: contain; }
.org-foot-parent { font-size: .68rem; text-transform: uppercase; letter-spacing: .03em; color: #DA1919; font-weight: 700; }
.org-foot-name { font-weight: 700; color: var(--navy); }
.org-foot-note { font-style: italic; }
body.embed #org-footer { display: none; }
