:root {
  --bg: #fff7f9; --panel: #ffffff; --side: #fdeef2; --text: #2b2226; --muted: #8a7a80; --line: #f0d9e0;
  --brand: #e9638c; --brand-2: #d94f7b; --me: #e9638c; --me-text: #fff; --bot: #ffffff; --code: #f6eef1; --err: #c62828;
  --shadow: 0 1px 3px rgba(80, 20, 40, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1719; --panel: #262022; --side: #211b1d; --text: #f3e9ec; --muted: #a8979d; --line: #3a2f33;
    --brand: #ee7aa0; --brand-2: #f08cad; --me: #b9466c; --me-text: #fff; --bot: #2b2427; --code: #332a2d; --err: #ff7b7b;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%; overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--err); min-height: 1.4em; font-size: 14px; }

/* ---- dang nhap */
.login { height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-box { width: 100%; max-width: 340px; background: var(--panel); border-radius: 20px; padding: 28px 22px; text-align: center; box-shadow: var(--shadow); }
.login-logo { width: 72px; height: 72px; border-radius: 18px; }
.login-box h1 { margin: 12px 0 2px; font-size: 22px; }
.login-box input { width: 100%; margin: 16px 0 12px; padding: 12px 14px; font-size: 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--text); }
.btn-primary { background: var(--brand); color: #fff; border: 0; border-radius: 12px; padding: 11px 18px; font-weight: 600; }
.login-box .btn-primary { width: 100%; }
.btn-primary:disabled { opacity: .6; }

/* ---- bo cuc */
.app { display: flex; height: 100%; height: 100dvh; }
.side { width: 280px; background: var(--side); display: flex; flex-direction: column; border-right: 1px solid var(--line); }
.side-head { display: flex; gap: 8px; padding: 12px; padding-top: max(12px, env(safe-area-inset-top)); }
.btn-new { flex: 1; text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-weight: 600; }
.conv-list { list-style: none; margin: 0; padding: 4px 8px; overflow-y: auto; flex: 1; }
.conv-list li { display: flex; align-items: center; border-radius: 10px; }
.conv-list li.on { background: var(--panel); }
.conv-list .c-name { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-list .c-act { background: none; border: 0; padding: 8px 6px; color: var(--muted); font-size: 15px; }
.side-foot { padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.link-btn { background: none; border: 0; color: var(--muted); padding: 8px; }
.icon-btn { background: none; border: 0; width: 40px; height: 40px; border-radius: 10px; font-size: 20px; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.icon-btn:active { background: var(--line); }
.scrim { display: none; }
.only-mobile { display: none; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.top { display: flex; align-items: center; gap: 4px; padding: 6px 8px; padding-top: max(6px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); background: var(--bg); }
.top .title { flex: 1; text-align: center; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#menuBtn { visibility: hidden; }

.msgs { flex: 1; overflow-y: auto; padding: 16px 12px 8px; -webkit-overflow-scrolling: touch; }
.empty { text-align: center; padding: 24px 8px; color: var(--muted); }
.empty h2 { color: var(--text); margin: 10px 0 4px; font-size: 21px; }
.empty-logo { width: 64px; height: 64px; border-radius: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 18px; }
.chip { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; font-size: 14px; }

.msg { display: flex; margin: 0 auto 14px; max-width: 760px; }
.msg.user { justify-content: flex-end; }
.bubble { max-width: 86%; padding: 10px 14px; border-radius: 18px; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--me); color: var(--me-text); border-bottom-right-radius: 6px; white-space: pre-wrap; }
.msg.bot .bubble { background: var(--bot); border: 1px solid var(--line); border-bottom-left-radius: 6px; max-width: 100%; box-shadow: var(--shadow); }
.msg .imgs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; justify-content: flex-end; }
.msg .imgs img { width: 120px; height: 120px; object-fit: cover; border-radius: 12px; }
.meta { display: flex; align-items: center; gap: 10px; margin-top: 6px; font-size: 13px; color: var(--muted); }
.copy { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 3px 10px; font-size: 13px; color: var(--muted); }
.status { font-size: 14px; color: var(--muted); font-style: italic; }
.status::after { content: "…"; animation: dots 1.2s steps(3, end) infinite; display: inline-block; width: 1em; overflow: hidden; vertical-align: bottom; }
@keyframes dots { from { width: 0; } to { width: 1em; } }
.msg.err .bubble { border-color: var(--err); color: var(--err); }

/* markdown */
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .7em; }
.md h1, .md h2, .md h3, .md h4 { margin: .8em 0 .4em; line-height: 1.3; }
.md h1 { font-size: 1.25em; } .md h2 { font-size: 1.15em; } .md h3, .md h4 { font-size: 1.05em; }
.md ul, .md ol { margin: 0 0 .7em; padding-left: 1.4em; }
.md li { margin: .15em 0; }
.md code { background: var(--code); padding: 1px 5px; border-radius: 5px; font-size: .92em; }
.md pre { background: var(--code); padding: 10px 12px; border-radius: 10px; overflow-x: auto; white-space: pre-wrap; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 0 0 .7em; padding: 4px 12px; border-left: 3px solid var(--brand); color: var(--text); background: var(--code); border-radius: 0 8px 8px 0; }
.md a { color: var(--brand-2); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.md .tbl { overflow-x: auto; margin: 0 0 .7em; }
.md table { border-collapse: collapse; font-size: 14px; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: top; }

/* soan tin */
.composer { border-top: 1px solid var(--line); background: var(--bg); padding: 8px 8px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.bar { display: flex; align-items: flex-end; gap: 4px; max-width: 760px; margin: 0 auto; background: var(--panel); border: 1px solid var(--line); border-radius: 22px; padding: 4px; }
.bar textarea { flex: 1; min-width: 0; border: 0; outline: 0; resize: none; background: transparent; color: var(--text); font: inherit; font-size: 16px; padding: 8px 4px; max-height: 160px; }
.send { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--brand); color: #fff; font-size: 17px; flex: none; }
.send:disabled { opacity: .45; }
.attach { cursor: pointer; }
#micBtn.on { background: var(--brand); color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .65; } }
.preview { display: flex; gap: 8px; max-width: 760px; margin: 0 auto 8px; overflow-x: auto; }
.preview .pv { position: relative; flex: none; }
.preview img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; }
.preview .pv.up img { opacity: .5; }
.preview .x { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: #0009; color: #fff; font-size: 12px; line-height: 22px; padding: 0; }
.stt-hint { text-align: center; font-size: 13px; color: var(--brand-2); margin-bottom: 6px; }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: #333; color: #fff; padding: 8px 14px; border-radius: 10px; font-size: 14px; z-index: 50; max-width: 90%; text-align: center; }
.dlg { border: 0; border-radius: 16px; padding: 18px; width: min(340px, 90vw); background: var(--panel); color: var(--text); }
.dlg::backdrop { background: #0006; }
.dlg input { width: 100%; padding: 10px 12px; font-size: 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); margin-bottom: 12px; }
.dlg-btns { display: flex; justify-content: flex-end; gap: 8px; }

/* ---- dien thoai */
@media (max-width: 800px) {
  .side { position: fixed; z-index: 30; top: 0; bottom: 0; left: 0; width: 84%; max-width: 320px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; background: #0005; z-index: 20; }
  #menuBtn { visibility: visible; }
  .only-mobile { display: inline-flex; }
  .msg.bot .bubble { max-width: 100%; }
}
@media (min-width: 801px) { #newBtn2 { visibility: hidden; } }

/* ---- trang Tri nho */
.mem { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: flex; flex-direction: column; }
.mem-body { flex: 1; overflow-y: auto; padding: 14px 14px max(14px, env(safe-area-inset-bottom)); max-width: 760px; width: 100%; margin: 0 auto; }
.mem-switch { display: flex; gap: 12px; align-items: center; justify-content: space-between; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.mem-switch input { width: 46px; height: 26px; flex: none; accent-color: var(--brand); }
.mem-add { display: flex; gap: 8px; margin: 14px 0 6px; }
.mem-add input { flex: 1; min-width: 0; padding: 10px 12px; font-size: 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); }
.mem-count { font-size: 13px; margin: 8px 2px; }
.mem-list { list-style: none; margin: 0; padding: 0; }
.mem-list li { display: flex; gap: 6px; align-items: flex-start; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 6px 10px 12px; margin-bottom: 8px; }
.mem-list .m-txt { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.mem-list .c-act { background: none; border: 0; padding: 4px 6px; font-size: 15px; }
.mem-list.off { opacity: .55; }
.mem-clear { margin-top: 14px; width: 100%; background: none; border: 1px solid var(--err); color: var(--err); border-radius: 12px; padding: 10px; }
.side-mem { width: 100%; text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 6px; font-weight: 600; }
.nho { color: var(--brand-2); }
