/* Tổ — Telegram-inspired look. Light theme by default, dark via system or setting. */
:root {
  --accent: #3390EC;
  --accent-hover: #2A7FD4;
  --accent-soft: rgba(51, 144, 236, .12);
  --on-accent: #FFFFFF;
  --side: #FFFFFF;
  --surface: #FFFFFF;
  --hover: #F4F4F5;
  --text: #0F1419;
  --text-2: #707579;
  --text-3: #A2ACB0;
  --line: #E4E6E8;
  --input: #F1F3F4;
  --out: #E2FFC9;
  --out-meta: #4FAE4E;
  --in: #FFFFFF;
  --in-meta: #8D969C;
  --check: #4FAE4E;
  --link: #3390EC;
  --danger: #E53935;
  --online: #4FC75B;
  --service-bg: rgba(42, 61, 39, .32);
  --service-solid: rgba(42, 61, 39, .55);
  --chat-bg:
    radial-gradient(circle at 12% 18%, #D9E8B3 0, transparent 48%),
    radial-gradient(circle at 88% 22%, #AAD5BE 0, transparent 46%),
    radial-gradient(circle at 25% 88%, #EEE5A8 0, transparent 52%),
    radial-gradient(circle at 85% 85%, #9DCCB0 0, transparent 48%),
    #C9DFB4;
  --pattern-opacity: .11;
  --pattern-filter: none;
  --shadow-pop: 0 6px 24px rgba(0, 0, 0, .16), 0 1px 3px rgba(0, 0, 0, .08);
  --bubble-shadow: 0 1px 1.5px rgba(16, 35, 47, .14);
  --font: "Roboto", system-ui, -apple-system, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #6AB2F2; --accent-hover: #82BFF5; --accent-soft: rgba(106, 178, 242, .14); --on-accent: #0E1621;
    --side: #17212B; --surface: #17212B; --hover: #202B36; --text: #F2F4F5; --text-2: #8196A8; --text-3: #5D7080;
    --line: #0E1621; --input: #242F3D; --out: #2B5278; --out-meta: #8DB8E0; --in: #182533; --in-meta: #6D8193;
    --check: #6AB2F2; --link: #6AB2F2; --danger: #EF5350; --service-bg: rgba(0, 0, 0, .35); --service-solid: rgba(0, 0, 0, .5);
    --chat-bg: radial-gradient(circle at 20% 20%, #15283A 0, transparent 50%), radial-gradient(circle at 80% 80%, #142433 0, transparent 50%), #0E1621;
    --pattern-opacity: .06; --pattern-filter: invert(1);
    --bubble-shadow: 0 1px 1.5px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --accent: #6AB2F2; --accent-hover: #82BFF5; --accent-soft: rgba(106, 178, 242, .14); --on-accent: #0E1621;
  --side: #17212B; --surface: #17212B; --hover: #202B36; --text: #F2F4F5; --text-2: #8196A8; --text-3: #5D7080;
  --line: #0E1621; --input: #242F3D; --out: #2B5278; --out-meta: #8DB8E0; --in: #182533; --in-meta: #6D8193;
  --check: #6AB2F2; --link: #6AB2F2; --danger: #EF5350; --service-bg: rgba(0, 0, 0, .35); --service-solid: rgba(0, 0, 0, .5);
  --chat-bg: radial-gradient(circle at 20% 20%, #15283A 0, transparent 50%), radial-gradient(circle at 80% 80%, #142433 0, transparent 50%), #0E1621;
  --pattern-opacity: .06; --pattern-filter: invert(1);
  --bubble-shadow: 0 1px 1.5px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body { font-family: var(--font); font-size: 15px; line-height: 1.38; color: var(--text); background: var(--side); -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
svg { display: block; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }

/* ---------- primitives */
.btn { border: 0; border-radius: 10px; padding: 10px 18px; font-weight: 500; background: var(--input); transition: background .15s; }
@media (hover: hover) { .btn:hover { filter: brightness(.97); } }
.btn-primary { background: var(--accent); color: var(--on-accent); }
@media (hover: hover) { .btn-primary:hover { background: var(--accent-hover); filter: none; } }
.btn-danger { background: transparent; color: var(--danger); box-shadow: inset 0 0 0 1.5px var(--danger); }
@media (hover: hover) { .btn-danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); filter: none; } }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.link-btn { border: 0; background: none; color: var(--accent); padding: 8px; font-weight: 500; }
.icon-btn { border: 0; background: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--text-2); flex: none; transition: background .15s, color .15s; }
@media (hover: hover) { .icon-btn:hover { background: var(--hover); } }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.small { width: 30px; height: 30px; }
.icon-btn.small svg { width: 18px; height: 18px; }

.avatar { position: relative; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 500; flex: none; user-select: none;
  width: var(--s, 40px); height: var(--s, 40px); font-size: calc(var(--s, 40px) * .4); }
.avatar > .face { position: absolute; inset: 0; border-radius: 50%; display: grid; place-items: center; overflow: hidden;
  background: linear-gradient(160deg, color-mix(in srgb, var(--c) 70%, #fff), var(--c)); }
.avatar > .face img { width: 100%; height: 100%; object-fit: cover; }
.avatar .dot { position: absolute; right: 0; bottom: 0; width: 28%; height: 28%; min-width: 11px; min-height: 11px; border-radius: 50%; background: var(--online); box-shadow: 0 0 0 2px var(--side); }

/* ---------- auth */
.auth { height: 100%; overflow-y: auto; display: grid; place-items: center; padding: 24px 16px; background: var(--chat-bg); position: relative; }
.auth::before { content: ""; position: fixed; inset: 0; background: url(/pattern.svg); opacity: var(--pattern-opacity); filter: var(--pattern-filter); pointer-events: none; }
.auth-card { position: relative; width: 100%; max-width: 380px; background: var(--surface); border-radius: 20px; padding: 26px 24px 16px; text-align: center; box-shadow: var(--shadow-pop); margin-top: 60px; }
.auth-mascot { margin: -92px auto 0; }
.auth h1 { font-size: 30px; font-weight: 500; }
.auth-sub { color: var(--text-2); margin: 4px 0 20px; }
.auth form { display: grid; gap: 14px; text-align: left; }
.auth label, .field { display: grid; gap: 6px; font-size: 13px; font-weight: 500; color: var(--text-2); }
.auth input, .field input, .field select, .modal input[type=search], .modal .pick-list + input {
  border: 1.5px solid var(--line); border-radius: 10px; padding: 11px 13px; background: var(--surface); font-size: 16px; font-weight: 400; color: var(--text); width: 100%;
}
.auth input:focus, .field input:focus, .modal input[type=search]:focus, .modal .pick-list + input:focus { outline: none; border-color: var(--accent); }
.form-error { color: var(--danger); font-size: 14px; }
.form-error:empty { display: none; }

/* ---------- shell */
.shell { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; height: 100dvh; }
.side { background: var(--side); display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); position: relative; }
.side-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px 8px 10px; }
.search { flex: 1; display: flex; align-items: center; gap: 8px; background: var(--input); border-radius: 22px; padding: 0 14px; height: 42px; border: 2px solid transparent; }
.search:focus-within { border-color: var(--accent); background: var(--surface); }
.search svg { width: 20px; height: 20px; fill: none; stroke: var(--text-3); stroke-width: 2; stroke-linecap: round; flex: none; }
.search input { border: 0; background: none; outline: none; flex: 1; min-width: 0; font-size: 16px; }
.side-scroll { flex: 1; overflow-y: auto; padding: 0 8px 84px; overscroll-behavior: contain; }

.chat-list { list-style: none; margin: 0; padding: 0; }
.chat-item { width: 100%; display: flex; align-items: center; gap: 12px; border: 0; background: none; padding: 8px 10px; border-radius: 12px; text-align: left; color: var(--text); }
@media (hover: hover) { .chat-item:hover { background: var(--hover); } }
.chat-item[aria-current="true"] { background: var(--accent); color: #fff; }
.chat-item .body { flex: 1; min-width: 0; display: grid; gap: 3px; }
.chat-item .row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.chat-item .name { flex: 1; min-width: 0; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .time { font-size: 12px; color: var(--text-3); flex: none; display: flex; align-items: center; gap: 3px; }
.chat-item .preview { flex: 1; min-width: 0; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .preview .who { color: var(--text); }
.chat-item .preview.typing { color: var(--accent); }
.chat-item[aria-current="true"] .time, .chat-item[aria-current="true"] .preview, .chat-item[aria-current="true"] .preview .who,
.chat-item[aria-current="true"] .preview.typing, .chat-item[aria-current="true"] .ticks { color: rgba(255,255,255,.9); }
.chat-item[aria-current="true"] .avatar .dot { box-shadow: 0 0 0 2px var(--accent); }
.badge { background: var(--accent); color: #fff; font-size: 12.5px; font-weight: 500; border-radius: 999px; min-width: 22px; height: 22px; padding: 0 7px; display: grid; place-items: center; flex: none; }
.chat-item[aria-current="true"] .badge { background: #fff; color: var(--accent); }
.in-call { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 500; color: var(--online); flex: none; }
.in-call::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--online); animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.ticks { display: inline-block; width: 18px; height: 14px; color: var(--check); flex: none; }
.ticks svg { width: 18px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.search-results h3 { font-size: 14px; font-weight: 500; color: var(--text-2); padding: 14px 10px 6px; }
.search-results mark { background: none; color: var(--accent); font-weight: 500; }
.chat-item[aria-current="true"] mark { color: #fff; }
.search-empty { color: var(--text-2); padding: 24px 10px; text-align: center; font-size: 14px; }

.fab { position: absolute; right: 18px; bottom: 18px; width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; box-shadow: 0 2px 8px rgba(0,0,0,.25); transition: transform .15s; }
@media (hover: hover) { .fab:hover { transform: scale(1.05); } }
.fab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- main / chat area */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; background: var(--chat-bg); }
.main::before { content: ""; position: absolute; inset: 0; background: url(/pattern.svg); background-size: 420px; opacity: var(--pattern-opacity); filter: var(--pattern-filter); pointer-events: none; }
.main > * { position: relative; }
.empty-main { margin: auto; }
.service-pill { background: var(--service-bg); color: #fff; font-size: 14px; font-weight: 500; padding: 5px 12px; border-radius: 16px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }

.conv-view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.conv-head { display: flex; align-items: center; gap: 12px; padding: 6px 8px 6px 16px; background: var(--surface); min-height: 56px; box-shadow: 0 1px 0 var(--line); z-index: 3; }
.back-btn { display: none; margin-left: -8px; }
.conv-title { flex: 1; min-width: 0; }
.conv-title h1 { font-size: 16px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-title p { font-size: 14px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-title p.online, .conv-title p.typing { color: var(--accent); }
.typing-dots { display: inline-flex; gap: 2px; margin-right: 5px; vertical-align: middle; }
.typing-dots i { width: 4px; height: 4px; border-radius: 50%; background: currentColor; animation: tdot 1.2s infinite; }
.typing-dots i:nth-child(2) { animation-delay: .15s; }
.typing-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes tdot { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-2px); } }
.conv-actions { display: flex; gap: 2px; }

.pinned-bar { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; text-align: left; background: var(--surface); padding: 6px 8px 6px 16px; box-shadow: 0 1px 0 var(--line); z-index: 2; }
.pinned-bar .line { width: 2px; align-self: stretch; background: var(--accent); border-radius: 2px; flex: none; }
.pinned-bar .txt { flex: 1; min-width: 0; font-size: 14px; }
.pinned-bar .txt b { display: block; color: var(--accent); font-weight: 500; }
.pinned-bar .txt span { display: block; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ttl-note { font-size: 13px; color: var(--text-2); background: var(--surface); padding: 6px 16px; display: flex; gap: 8px; align-items: center; box-shadow: 0 1px 0 var(--line); z-index: 1; }
.ttl-note svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; flex: none; }
.call-banner { display: flex; align-items: center; gap: 10px; padding: 8px 12px 8px 16px; background: var(--online); color: #fff; font-weight: 500; font-size: 14px; z-index: 2; }
.call-banner span { flex: 1; }
.call-banner .btn { padding: 6px 14px; background: #fff; color: #1B7A2A; }

.chat-area { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.messages { flex: 1; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; padding: 8px 0 4px; }
.msg-list { max-width: 760px; margin: 0 auto; padding: 0 14px; display: flex; flex-direction: column; }
.top-sentinel { height: 1px; flex: none; }
.day-sep { align-self: center; position: sticky; top: 6px; z-index: 2; margin: 10px 0 6px; }
.unread-sep { align-self: stretch; text-align: center; background: color-mix(in srgb, var(--surface) 85%, transparent); color: var(--text-2); font-size: 14px; font-weight: 500; padding: 4px 0; margin: 8px -14px; }
.conv-intro { align-self: center; margin: 24px 0 12px; background: var(--service-bg); color: #fff; border-radius: 18px; padding: 16px 20px; text-align: center; max-width: 300px; display: grid; justify-items: center; gap: 4px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.conv-intro img { width: 110px; height: 110px; }
.conv-intro b { font-weight: 500; font-size: 16px; }
.conv-intro span { font-size: 14px; opacity: .92; }

/* ---------- messages */
.msg { display: flex; align-items: flex-end; gap: 6px; margin-top: 2px; position: relative; }
.msg.new { animation: msg-in .18s ease-out; }
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } }
.msg.first { margin-top: 8px; }
.msg.mine { flex-direction: row-reverse; }
.msg .avatar-slot { width: 34px; flex: none; align-self: flex-end; }
.msg.mine .avatar-slot, .msg.no-avatar .avatar-slot { display: none; }
.msg .col { min-width: 0; max-width: min(480px, 78%); display: flex; flex-direction: column; align-items: flex-start; }
.msg.mine .col { align-items: flex-end; }

.bubble { position: relative; background: var(--in); color: var(--text); padding: 6px 9px 7px 10px; border-radius: 6px 15px 15px 6px; box-shadow: var(--bubble-shadow); overflow-wrap: anywhere; min-width: 64px; max-width: 100%; }
.msg.first .bubble { border-top-left-radius: 15px; }
.msg.last .bubble { border-bottom-left-radius: 0; }
.msg.mine .bubble { background: var(--out); border-radius: 15px 6px 6px 15px; }
.msg.mine.first .bubble { border-top-right-radius: 15px; }
.msg.mine.last .bubble { border-bottom-right-radius: 0; }
.msg.last .bubble.tail::after { content: ""; position: absolute; bottom: 0; left: -8px; width: 9px; height: 17px; background: inherit; clip-path: path("M9 0 V17 H1.5 C0 17 -.5 15.6 .6 14.8 C4 12.4 8 8 9 0 Z"); }
.msg.mine.last .bubble.tail::after { left: auto; right: -8px; clip-path: path("M0 0 V17 H7.5 C9 17 9.5 15.6 8.4 14.8 C5 12.4 1 8 0 0 Z"); }
.bubble .text { white-space: pre-wrap; }
.bubble a { color: var(--link); text-decoration: none; }
@media (hover: hover) { .bubble a:hover { text-decoration: underline; } }
.sender { font-size: 14px; font-weight: 500; margin-bottom: 1px; display: block; }
.meta { float: right; display: inline-flex; align-items: center; gap: 3px; font-size: 12px; color: var(--in-meta); margin: 8px -3px -4px 12px; line-height: 1; user-select: none; white-space: nowrap; position: relative; top: 1px; }
.msg.mine .meta { color: var(--out-meta); }
.meta .ticks { width: 16px; height: 12px; color: inherit; }
.meta .ticks svg { width: 16px; height: 12px; }
.meta .clock { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2; }
.meta .edited { font-style: italic; }
.meta.overlay { float: none; position: absolute; right: 6px; bottom: 6px; margin: 0; top: auto; background: rgba(0,0,0,.42); color: #fff !important; padding: 3px 6px; border-radius: 10px; }
.timer-ico { width: 11px; height: 11px; fill: none; stroke: currentColor; stroke-width: 2.4; }

.bubble.big-emoji { background: none !important; box-shadow: none; padding: 0 2px; }
.bubble.big-emoji .text { font-size: 48px; line-height: 1.15; }
.bubble.big-emoji::after { display: none; }
.bubble.big-emoji .meta { float: none; display: flex; width: fit-content; margin: 2px 0 0 auto; background: var(--service-bg); color: #fff !important; padding: 3px 6px; border-radius: 10px; top: 0; }

.sticker-wrap { position: relative; }
.sticker-msg { width: 168px; height: 168px; display: grid; place-items: center; }
.sticker-msg > * { width: 100%; height: 100%; object-fit: contain; }
.sticker-wrap .meta { float: none; position: absolute; right: 0; bottom: 4px; margin: 0; background: var(--service-bg); color: #fff !important; padding: 3px 6px; border-radius: 10px; top: auto; }
.sticker-wrap .reactions { position: static; }
.sticker-gone { font-size: 12px; color: var(--text-3); text-align: center; }

.bubble.media { padding: 0; }
.bubble.media .img-msg { display: block; border: 0; padding: 0; background: var(--hover); cursor: zoom-in; border-radius: inherit; overflow: hidden; position: relative; width: 100%; }
.bubble.media .img-msg img { display: block; max-width: min(380px, 100%); max-height: 420px; width: auto; height: auto; min-width: 140px; }
.bubble.media.has-head .img-msg { border-top-left-radius: 0; border-top-right-radius: 0; }
.bubble.media.has-caption .img-msg { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.bubble.media.has-caption:not(.video) { max-width: min(380px, 100%); }
.bubble.media.has-caption .img-msg img { width: 100%; max-width: none; object-fit: cover; }
.bubble.media .caption { padding: 6px 9px 7px 10px; }
.bubble.media .head { padding: 6px 10px 4px; }
.bubble.media > .reactions { padding: 0 8px 6px; }
.file-msg { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--text); padding: 2px 0; }
.file-msg .file-ico { width: 46px; height: 46px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; }
.msg.mine .file-msg .file-ico { background: var(--out-meta); }
.file-msg .file-ico svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; }
.file-msg b { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 240px; }
.file-msg small { color: var(--text-2); font-size: 13px; }

.reply-quote { display: block; width: 100%; text-align: left; border: 0; font-size: 14px; padding: 3px 8px 3px 10px; margin: 2px 0 5px; border-radius: 6px; background: color-mix(in srgb, var(--accent) 10%, transparent); box-shadow: inset 3px 0 0 var(--accent); overflow: hidden; }
.msg.mine .reply-quote { background: color-mix(in srgb, var(--out-meta) 14%, transparent); box-shadow: inset 3px 0 0 var(--out-meta); }
.reply-quote b { display: block; color: var(--accent); font-weight: 500; }
.msg.mine .reply-quote b { color: var(--out-meta); }
.reply-quote span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }

.reactions { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0 2px; clear: both; }
.reactions:empty { display: none; }
.rx { display: inline-flex; align-items: center; gap: 4px; height: 28px; padding: 0 9px 0 6px; border-radius: 14px; border: 0; background: color-mix(in srgb, var(--accent) 13%, transparent); color: var(--accent); font-size: 14px; font-weight: 500; transition: transform .12s; }
.msg.mine .rx { background: color-mix(in srgb, var(--out-meta) 20%, transparent); color: var(--out-meta); }
.rx .e { font-size: 17px; line-height: 1; }
.rx.me { background: var(--accent); color: #fff; }
.msg.mine .rx.me { background: var(--out-meta); color: var(--out); }
.rx:active { transform: scale(.92); }
.rx .faces { display: flex; }
.rx .faces .avatar { --s: 20px; margin-left: -5px; }
.rx .faces .avatar:first-child { margin-left: 0; }
.sticker-wrap .rx, .emoji-wrap .rx { background: var(--service-bg) !important; color: #fff !important; }
.rx-pop { animation: rxpop .35s ease-out; }
@keyframes rxpop { 40% { transform: scale(1.25); } }

.msg.pending .meta { opacity: .85; }
.msg.failed .bubble { box-shadow: 0 0 0 1.5px var(--danger); }
.msg.highlight .bubble, .msg.highlight .sticker-msg { animation: hl 1.4s ease-out; }
@keyframes hl { 0%, 40% { filter: brightness(.8); } }
.msg.ctx-target .bubble, .msg.ctx-target .sticker-msg { filter: brightness(.93); }

/* the deletion moment — message dissolves rather than leaving a "deleted" placeholder */
.msg.dissolving { animation: dissolve .42s ease-in forwards; pointer-events: none; }
@keyframes dissolve {
  0% { opacity: 1; filter: blur(0); transform: scale(1); max-height: 500px; }
  60% { opacity: 0; filter: blur(6px); transform: scale(.94) translateY(-4px); max-height: 500px; }
  100% { opacity: 0; filter: blur(8px); transform: scale(.9); max-height: 0; margin: 0; }
}

/* ---------- context menu */
.ctx-layer { position: fixed; inset: 0; z-index: 70; }
.ctx { position: fixed; display: grid; gap: 6px; z-index: 71; animation: ctx-in .14s ease-out; max-width: calc(100vw - 16px); }
.ctx, .ctx-layer { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
/* Điện thoại: giữ để mở menu, không để iOS bật chế độ chọn chữ / kính lúp (đã có nút Sao chép). */
/* Tin của mình: canh phải như bong bóng. Hàng emoji cuộn ngang nếu màn hình quá hẹp. */
.ctx.mine { justify-items: end; }
.ctx-react { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.ctx-react::-webkit-scrollbar { display: none; }
.ctx-react button { flex: none; }
@media (hover: none) { .msg { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; } }
@keyframes ctx-in { from { opacity: 0; transform: scale(.94); } }
.ctx-react { display: flex; gap: 2px; background: var(--surface); border-radius: 24px; padding: 5px 6px; box-shadow: var(--shadow-pop); width: fit-content; }
.ctx-react button { border: 0; background: none; width: 38px; height: 38px; border-radius: 50%; font-size: 24px; line-height: 1; display: grid; place-items: center; transition: transform .12s, background .12s; }
@media (hover: hover) { .ctx-react button:hover { transform: scale(1.18); background: var(--hover); } }
.ctx-react button.on { background: var(--accent-soft); }
.ctx-menu { background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-radius: 12px; padding: 5px; box-shadow: var(--shadow-pop); min-width: 210px; width: fit-content; }
.ctx-menu button { display: flex; align-items: center; gap: 14px; width: 100%; border: 0; background: none; padding: 9px 12px; border-radius: 8px; font-size: 14.5px; font-weight: 500; text-align: left; }
@media (hover: hover) { .ctx-menu button:hover { background: var(--hover); } }
.ctx-menu button svg { width: 20px; height: 20px; fill: none; stroke: var(--text-2); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ctx-menu button.danger { color: var(--danger); }
.ctx-menu button.danger svg { stroke: var(--danger); }
.ctx-menu .confirm { padding: 8px 10px 6px; font-size: 14px; max-width: 250px; }
.ctx-menu .confirm .row { display: flex; gap: 6px; justify-content: flex-end; margin-top: 10px; }
.ctx-menu .confirm .row button { width: auto; padding: 7px 12px; justify-content: center; }
.ctx-menu .confirm .row .yes { background: var(--danger); color: #fff; }

/* ---------- composer */
.composer-wrap { position: relative; padding: 4px 12px calc(10px + env(safe-area-inset-bottom)); }
.composer { max-width: 760px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px; }
.input-box { flex: 1; min-width: 0; display: flex; align-items: flex-end; background: var(--surface); border-radius: 18px; padding: 3px 4px; box-shadow: var(--bubble-shadow); }
.compose-bar:not([hidden]) + .composer .input-box { border-top-left-radius: 0; border-top-right-radius: 0; }
.input-box textarea { flex: 1; min-width: 0; border: 0; resize: none; background: none; padding: 10px 4px; max-height: 180px; outline: none; line-height: 1.35; font-size: 16px; }
.input-box .icon-btn { width: 42px; height: 42px; }
.input-box .icon-btn svg { width: 25px; height: 25px; }
.sticker-btn[aria-expanded="true"] { color: var(--accent); }
.send-btn { width: 50px; height: 50px; border-radius: 50%; border: 0; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; flex: none; box-shadow: var(--bubble-shadow); transition: transform .12s, background .15s; }
@media (hover: hover) { .send-btn:hover { background: var(--accent-hover); } }
.send-btn:active { transform: scale(.92); }
.send-btn svg { width: 24px; height: 24px; fill: currentColor; stroke: none; margin-left: 3px; }
.send-btn svg.check { fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; margin-left: 0; }
.compose-bar { max-width: 702px; display: flex; align-items: center; gap: 10px; background: var(--surface); padding: 6px 4px 4px 12px; border-radius: 18px 18px 0 0; margin: 0 auto; width: calc(100% - 58px); transform: translateX(-29px); box-shadow: 0 -1px 1.5px rgba(16, 35, 47, .08); }
.compose-bar > svg { width: 22px; height: 22px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.compose-bar .txt { flex: 1; min-width: 0; font-size: 14px; border-left: 2px solid var(--accent); padding-left: 8px; }
.compose-bar .txt b { display: block; color: var(--accent); font-weight: 500; }
.compose-bar .txt span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.scroll-down { position: absolute; right: 18px; bottom: 82px; width: 48px; height: 48px; border-radius: 50%; border: 0; background: var(--surface); color: var(--text-2); display: grid; place-items: center; box-shadow: var(--shadow-pop); z-index: 4; animation: ctx-in .14s ease-out; }
.scroll-down svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.scroll-down .count { position: absolute; top: -7px; right: -2px; background: var(--accent); color: var(--on-accent); font-size: 12px; font-weight: 500; border-radius: 10px; min-width: 20px; height: 20px; padding: 0 6px; display: grid; place-items: center; }
.drop-hint { position: absolute; inset: 0; background: color-mix(in srgb, var(--accent) 82%, transparent); color: #fff; display: grid; place-items: center; font-size: 20px; font-weight: 500; z-index: 20; pointer-events: none; }

/* ---------- sticker panel */
.sticker-panel { position: absolute; bottom: calc(100% - 4px); left: max(12px, calc((100% - 760px) / 2)); width: min(380px, calc(100% - 24px)); height: 380px; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-pop); display: flex; flex-direction: column; z-index: 10; overflow: hidden; animation: ctx-in .14s ease-out; transform-origin: bottom left; }
.sp-tabs { display: flex; gap: 2px; padding: 6px; overflow-x: auto; flex: none; box-shadow: 0 1px 0 var(--line); }
.sp-tab { border: 0; background: none; padding: 4px; border-radius: 10px; width: 44px; height: 44px; flex: none; display: grid; place-items: center; }
.sp-tab > img, .sp-tab > video, .sp-tab > .lottie { width: 34px; height: 34px; object-fit: contain; }
.sp-tab[aria-selected="true"] { background: var(--accent-soft); }
.sp-tab.text { width: auto; padding: 0 12px; font-size: 14px; font-weight: 500; color: var(--text-2); }
.sp-tab.text[aria-selected="true"] { color: var(--accent); }
.sp-tab .sticker-gone { font-size: 0; }
.sp-tab .sticker-gone::after { content: "★"; font-size: 20px; color: var(--text-3); }
.sp-body { flex: 1; overflow-y: auto; padding: 6px 8px 10px; }
.sp-body h3 { font-size: 14px; font-weight: 500; color: var(--text-2); margin: 6px 4px; }
.sp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 2px; }
.sp-cell { position: relative; }
.sp-item { width: 100%; border: 0; background: none; border-radius: 12px; padding: 4px; aspect-ratio: 1; display: grid; place-items: center; transition: background .12s, transform .12s; }
@media (hover: hover) { .sp-item:hover { background: var(--hover); transform: scale(1.05); } }
.sp-item > img, .sp-item > video, .sp-item > .lottie { width: 100%; height: 100%; object-fit: contain; }
.sp-cell .rm { position: absolute; top: 0; right: 0; width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--danger); color: #fff; font-size: 14px; line-height: 1; display: none; }
.sp-cell:focus-within .rm { display: block; }
@media (hover: hover) { .sp-cell:hover .rm { display: block; } }
.sp-empty { color: var(--text-2); font-size: 14px; padding: 24px 12px; text-align: center; }
.sp-add { display: grid; gap: 10px; padding: 8px 6px; font-size: 14px; color: var(--text-2); }
.sp-add h3 { color: var(--accent) !important; }
.hint { font-size: 13px; color: var(--text-2); margin-top: 4px; }

/* ---------- calls (used only when calls are enabled) */
.call-stage { background: #0E1715; color: #E4EEEA; display: flex; flex-direction: column; flex: none; height: min(52vh, 460px); z-index: 5; }
.call-stage.full { position: fixed; inset: 0; height: auto; z-index: 50; }
.tiles { flex: 1; display: grid; gap: 6px; padding: 6px; min-height: 0; grid-auto-rows: 1fr; }
.tile { position: relative; background: #1B2826; border-radius: 12px; overflow: hidden; display: grid; place-items: center; min-height: 0; }
.tile video { width: 100%; height: 100%; object-fit: cover; }
.tile video.contain { object-fit: contain; background: #000; }
.tile.speaking { box-shadow: inset 0 0 0 3px var(--online); }
.tile .label { position: absolute; left: 8px; bottom: 8px; background: rgba(0,0,0,.55); padding: 2px 8px; border-radius: 6px; font-size: 13px; display: flex; gap: 6px; align-items: center; }
.tile .label svg { width: 14px; height: 14px; fill: none; stroke: #F28C7A; stroke-width: 2.2; }
.tile .avatar.xl { width: 72px; height: 72px; font-size: 28px; background: #557; }
.call-controls { display: flex; justify-content: center; gap: 10px; padding: 10px; flex: none; align-items: center; }
.call-controls .ctl { width: 48px; height: 48px; border-radius: 50%; border: 0; background: #2A3B38; color: #E4EEEA; display: grid; place-items: center; }
.call-controls .ctl svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.call-controls .ctl.off { background: #E4EEEA; color: #0E1715; }
.call-controls .ctl.hang { background: var(--danger); color: #fff; width: 60px; }
.call-controls .timer { font-variant-numeric: tabular-nums; font-size: 14px; color: #9FB8B1; min-width: 48px; }

/* ---------- toasts / ring */
.toasts { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; width: min(420px, calc(100% - 24px)); pointer-events: none; }
.toasts > * { pointer-events: auto; }
.toast { background: rgba(30, 36, 40, .92); color: #fff; border-radius: 12px; padding: 11px 15px; font-size: 14px; box-shadow: var(--shadow-pop); animation: ctx-in .16s ease-out; }
.toast.error { background: var(--danger); }
.ring { background: var(--surface); border-radius: 18px; padding: 14px; display: flex; align-items: center; gap: 12px; box-shadow: var(--shadow-pop); }
.ring img { width: 56px; height: 56px; }
.ring .txt { flex: 1; min-width: 0; }
.ring .txt b { display: block; font-weight: 500; }
.ring .txt span { font-size: 13px; color: var(--text-2); }
.ring .btn { padding: 8px 14px; }
.ring .btn-call { background: var(--online); color: #fff; }

/* ---------- modals */
.modal-back:has(.media-composer) { inset: auto 0; top: var(--app-top, 0px); height: var(--app-h, 100dvh); }
.modal:has(.media-composer) { width: min(460px, 100%); padding: 18px 18px 16px; display: flex; flex-direction: column; overflow: hidden; max-height: calc(var(--app-h, 100dvh) - 24px); }
.media-composer { display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; }
.mc-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; flex: none; }
.media-composer h2 { margin: 0; }
.mc-close { display: none; border: 0; background: none; color: var(--text-2); font-size: 18px; width: 36px; height: 36px; border-radius: 50%; padding: 0; }
.mc-send { display: none; flex: none; width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--accent); color: var(--on-accent); font-size: 18px; padding: 0 0 0 3px; }
.mc-grid { flex: 0 1 auto; min-height: 70px; display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px; overflow-y: auto; border-radius: 12px; overscroll-behavior: contain; }
.mc-item { position: relative; border-radius: 10px; overflow: hidden; background: var(--input); aspect-ratio: 1; }
.mc-item.single { grid-column: 1 / -1; aspect-ratio: auto; display: grid; place-items: center; }
.mc-item img, .mc-item video { width: 100%; height: 100%; object-fit: cover; display: block; }
/* ảnh đơn: luôn chừa chỗ cho ô chú thích và nút Gửi, kể cả khi bàn phím đang mở */
.mc-item.single img, .mc-item.single video { width: auto; max-width: 100%; height: auto; max-height: min(52dvh, calc(var(--app-h, 100dvh) - 230px)); object-fit: contain; }
.mc-item.file { aspect-ratio: auto; }
.mc-file { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 18px 10px; text-align: center; min-height: 100px; }
.mc-file .mc-ico { font-size: 30px; }
.mc-file b { font-weight: 500; font-size: 13.5px; word-break: break-all; }
.mc-file small { color: var(--text-2); font-size: 12.5px; }
.mc-rm { position: absolute; top: 6px; right: 6px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, .55); color: #fff; font-size: 13px; line-height: 28px; padding: 0; }
.mc-bottom { display: flex; align-items: flex-end; gap: 8px; margin-top: 12px; flex: none; }
.mc-add { flex: none; width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--input); color: var(--accent); font-size: 24px; line-height: 40px; padding: 0; }
.mc-caption { flex: 1; min-width: 0; resize: none; border: 1.5px solid transparent; background: var(--input); color: var(--text); border-radius: 20px; padding: 9px 14px; font: inherit; font-size: 16px; line-height: 1.4; max-height: 120px; }
.mc-caption:focus { outline: none; border-color: var(--accent); }
.media-composer .actions { margin-top: 12px; flex: none; }
/* điện thoại: khung trượt lên từ dưới, nằm ngay trên bàn phím */
@media (max-width: 600px) {
  .modal-back:has(.media-composer) { place-items: end stretch; padding: 0; }
  .modal:has(.media-composer) { width: 100%; border-radius: 18px 18px 0 0; padding: 16px 14px calc(12px + env(safe-area-inset-bottom)); max-height: calc(var(--app-h, 100dvh) - 12px); animation: mc-up .22s ease-out; }
  html.kb-open .modal:has(.media-composer) { padding-bottom: 10px; }
  .media-composer h2 { font-size: 18px; }
  .mc-head { margin-bottom: 10px; }
  .mc-close, .mc-send { display: block; }
  .modal .media-composer .actions { display: none; }
  .mc-grid { grid-template-columns: repeat(3, 1fr); }
}
@keyframes mc-up { from { transform: translateY(40px); opacity: .4; } }

.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); display: grid; place-items: center; z-index: 80; padding: 16px; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--surface); border-radius: 16px; width: min(420px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto; padding: 20px 22px; box-shadow: var(--shadow-pop); animation: ctx-in .16s ease-out; }
.modal h2 { font-size: 20px; font-weight: 500; margin-bottom: 16px; }
.modal h3 { font-size: 14px; font-weight: 500; color: var(--accent); margin: 22px 0 10px; }
.modal .field { margin-bottom: 12px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { border: 0; background: var(--input); border-radius: 16px; padding: 7px 13px; font-size: 14px; font-weight: 500; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }
.profile-head { display: flex; align-items: center; gap: 16px; }
.profile-head .avatar { --s: 84px; }
.profile-head .who { flex: 1; min-width: 0; }
.profile-head .who b { display: block; font-size: 18px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.profile-head .who span { color: var(--text-2); font-size: 14px; }
.profile-head .acts { display: flex; flex-wrap: wrap; gap: 0 4px; margin: 4px 0 0 -8px; }
.user-row { display: flex; align-items: center; gap: 12px; padding: 7px 0; }
.user-row .n { flex: 1; min-width: 0; }
.user-row .n small { display: block; color: var(--text-2); }
.user-row .btn { padding: 6px 11px; font-size: 13px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; font-size: 15px; }
.switch-row label { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.switch-row input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.switch-row .link-btn { padding: 4px; font-size: 13px; flex: none; }
.danger-zone { border-top: 1px solid var(--line); margin-top: 20px; padding-top: 4px; display: grid; gap: 8px; }
.danger-zone h3 { color: var(--danger); }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 90; animation: fade .15s; overflow: hidden; }
.lb-stage { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; touch-action: none; cursor: zoom-in; }
.lb-stage img { max-width: calc(100vw - 32px); max-height: calc(100dvh - 32px); width: auto; height: auto; object-fit: contain; transform-origin: center center; will-change: transform; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.lb-bar { position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 10px; display: flex; gap: 8px; z-index: 2; }
.lb-btn { width: 42px; height: 42px; border-radius: 50%; border: 0; background: rgba(0,0,0,.5); box-shadow: 0 0 0 1px rgba(255,255,255,.2); color: #fff; display: grid; place-items: center; cursor: pointer; }
.lb-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- mobile: stack navigation */
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .shell .main { display: none; }
  .shell.conv-open .side { display: none; }
  .shell.conv-open .main { display: flex; }
  /* trong lúc trượt: danh sách và màn chat chồng lên nhau, màn chat ở trên */
  .shell.nav-anim .side, .shell.nav-anim .main { grid-area: 1 / 1; display: flex; }
  .shell.nav-anim .main { z-index: 2; box-shadow: -8px 0 24px rgba(0, 0, 0, .12); will-change: transform; }
  .shell.nav-anim .side { z-index: 0; position: relative; }
  /* luôn giữ 2 cột trên lớp GPU riêng: bỏ/tạo lại lớp đúng lúc hết hiệu ứng là thứ gây khựng ở cuối */
  .shell .side, .shell .main { will-change: transform; backface-visibility: hidden; }
  .nav-dim { position: fixed; inset: 0; z-index: 1; background: #000; opacity: 0; pointer-events: none; will-change: opacity; }
  .shell .main.nav-ghost { position: fixed; z-index: 3; display: flex; flex-direction: column; overflow: hidden; box-shadow: -8px 0 24px rgba(0, 0, 0, .12); will-change: transform; pointer-events: none; }
  .nav-ghost > .conv-view { flex: 1; min-height: 0; }
  .side { border-right: 0; }
  .back-btn { display: grid; }
  .conv-head { padding-left: 12px; gap: 10px; }
  .msg .col { max-width: 84%; }
  .msg-list { padding: 0 8px; }
  .unread-sep { margin: 8px -8px; }
  .sticker-panel { left: 8px; width: calc(100% - 16px); height: 330px; }
  .composer-wrap { padding: 4px 8px calc(8px + env(safe-area-inset-bottom)); }
  .sticker-msg { width: 150px; height: 150px; }
  .conv-actions [data-conv-search] { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}

/* ---------- additions: video, ttl chip, members, 2FA */
.bubble.video { overflow: hidden; }
.bubble.video.tail { overflow: visible; }
.vid-msg { position: relative; border-radius: inherit; overflow: hidden; background: #000; }
.vid-msg video { display: block; width: min(380px, 100%); max-height: 460px; background: #000; }
.bubble.media.has-head .vid-msg { border-top-left-radius: 0; border-top-right-radius: 0; }
.bubble.media.has-caption .vid-msg { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.meta.overlay.top { bottom: auto; top: 6px; }
.ttl-chip { border: 0; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 700; border-radius: 8px; padding: 3px 6px; margin: 0 2px 11px; flex: none; line-height: 1.2; }
.conv-title, .head-avatar { cursor: pointer; }
.chat-item.member { padding: 6px 4px; }
.preview.online { color: var(--accent) !important; }
.twofa .qr { display: grid; place-items: center; margin: 10px 0; }
.twofa .qr svg { border-radius: 8px; max-width: 100%; height: auto; }
.twofa .secret { display: block; text-align: center; font-size: 15px; letter-spacing: 1px; background: var(--input); padding: 8px; border-radius: 8px; user-select: all; word-break: break-all; }
.twofa .codes { background: var(--input); padding: 12px 16px; border-radius: 10px; font-size: 16px; line-height: 1.7; columns: 2; text-align: center; user-select: all; }
/* group consecutive messages: name on the first bubble, avatar beside the last */
.msg:not(.last) .avatar-slot > * { visibility: hidden; }
.msg:not(.first) .sender { display: none; }
.msg:not(.first) .head:not(:has(.reply-quote)) { display: none; }
.msg:not(.first) .bubble.media.has-head:not(:has(.reply-quote)) .img-msg,
.msg:not(.first) .bubble.media.has-head:not(:has(.reply-quote)) .vid-msg { border-top-left-radius: inherit; border-top-right-radius: inherit; }

.vid-processing { display: flex; align-items: center; gap: 12px; padding: 4px 0; max-width: 300px; }
.vid-processing b { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 230px; }
.vid-processing small { color: var(--text-2); font-size: 13px; }
.spinner { width: 40px; height: 40px; border-radius: 50%; border: 3px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .9s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.sound-row { display: grid; gap: 6px; padding: 6px 0; }
.sound-row .lbl { font-size: 14px; color: var(--text); }
.sound-row .ctl { display: flex; align-items: center; gap: 6px; }
.sound-row select { flex: 1; min-width: 0; border: 1.5px solid var(--line); border-radius: 10px; padding: 9px 12px; background: var(--surface); color: var(--text); font-size: 15px; }
.sound-row select:focus { outline: none; border-color: var(--accent); }
.sound-row .icon-btn { color: var(--accent); background: var(--accent-soft); width: 38px; height: 38px; }

/* ---------- voice messages */
.voice { display: flex; align-items: center; gap: 10px; min-width: 210px; padding: 2px 0; }
.vplay { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; }
.msg.mine .vplay { background: var(--out-meta); color: var(--out); }
.vplay svg { width: 22px; height: 22px; }
.vbody { flex: 1; min-width: 0; display: grid; gap: 3px; }
.vwave { display: flex; align-items: center; gap: 2px; height: 24px; cursor: pointer; }
.vwave i { flex: 1; max-width: 3px; min-width: 2px; border-radius: 2px; background: color-mix(in srgb, var(--accent) 35%, transparent); }
.vwave i.on { background: var(--accent); }
.msg.mine .vwave i { background: color-mix(in srgb, var(--out-meta) 40%, transparent); }
.msg.mine .vwave i.on { background: var(--out-meta); }
.vinfo { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--in-meta); }
.msg.mine .vinfo { color: var(--out-meta); }
.vspeed { border: 0; background: color-mix(in srgb, currentColor 14%, transparent); color: inherit; font-size: 11.5px; font-weight: 700; border-radius: 8px; padding: 1px 6px; }
.vinfo .meta.inline { float: none; position: static; margin: 0 0 0 auto; top: auto; }
.voice { width: 100%; }
.input-box { position: relative; }
.rec-bar { position: absolute; inset: 0; background: var(--surface); border-radius: inherit; display: flex; align-items: center; gap: 10px; padding: 0 12px 0 4px; z-index: 2; }
.rec-bar .icon-btn { color: var(--danger); }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; flex: none; }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 500; min-width: 40px; }
.rec-level { flex: 1; height: 4px; border-radius: 2px; background: var(--accent); transform-origin: left; transform: scaleX(.08); transition: transform .08s linear; max-width: 160px; }
.rec-hint { color: var(--text-2); font-size: 14px; margin-left: auto; }
.send-btn svg.mic { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; margin-left: 0; }
@media (max-width: 760px) { .rec-hint { display: none; } }

/* ---------- wallpaper picker */
.wp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 8px; }
.wp-tile { border: 0; background: none; padding: 0; display: grid; gap: 4px; justify-items: center; font-size: 12.5px; color: var(--text-2); }
.wp-prev { position: relative; width: 100%; aspect-ratio: 3 / 4; border-radius: 12px; overflow: hidden; display: grid; place-items: center; background: var(--input); box-shadow: inset 0 0 0 1px rgba(0,0,0,.06); }
.wp-prev.pat::before { content: ""; position: absolute; inset: 0; background: url(/pattern.svg); background-size: 210px; opacity: .14; filter: var(--pattern-filter); }
.wp-prev svg { width: 26px; height: 26px; fill: none; stroke: var(--text-2); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.wp-tile[aria-pressed="true"] .wp-prev { box-shadow: 0 0 0 3px var(--accent); }
.wp-tile[aria-pressed="true"] .wp-label { color: var(--accent); font-weight: 500; }

/* keep the bubble tail clear of the screen edge on phones */
@media (max-width: 760px) {
  .msg-list { padding: 0 12px 0 10px; }
  .msg.mine .col { max-width: 82%; }
}
/* always contain the floating timestamp inside its bubble (Safari) */
.bubble .text { display: flow-root; }

/* ---------- auth note, credentials, swatches */
.auth-note { color: var(--text-2) !important; font-weight: 400 !important; cursor: default; font-size: 14px; }
.cred { background: var(--input); padding: 12px 14px; border-radius: 10px; font-size: 14px; line-height: 1.6; white-space: pre-wrap; user-select: all; overflow-wrap: anywhere; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 36px; height: 36px; border-radius: 50%; border: 0; box-shadow: inset 0 0 0 1px rgba(0,0,0,.15); display: grid; place-items: center; font-size: 13px; font-weight: 700; color: var(--text-2); background: var(--input); position: relative; overflow: hidden; padding: 0; }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.swatch.picker { background: conic-gradient(#f44, #fb3, #4c4, #3bf, #94f, #f4a, #f44); cursor: pointer; }
.swatch.picker input { opacity: 0; position: absolute; inset: 0; width: 100%; height: 100%; cursor: pointer; border: 0; padding: 0; }
.modal select { border: 1.5px solid var(--line); border-radius: 10px; padding: 9px 12px; background: var(--surface); color: var(--text); font-size: 15px; }

/* ---------- app lock */
.privacy-blur .shell, .privacy-blur .toasts { filter: blur(22px); }
.lock-screen { position: fixed; inset: 0; z-index: 200; background: var(--surface); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); animation: fade .15s; }
.lk-logo { width: 72px; height: 72px; border-radius: 18px; }
.lk-box { display: grid; justify-items: center; gap: 10px; }
.lk-box h2 { font-size: 20px; font-weight: 500; }
.lk-sub { color: var(--text-2); font-size: 14px; min-height: 1.2em; text-align: center; }
.lk-dots { display: flex; gap: 14px; margin: 6px 0 14px; height: 14px; }
.lk-dots i { width: 14px; height: 14px; border-radius: 50%; box-shadow: inset 0 0 0 2px var(--text-3); transition: background .1s; }
.lk-dots i.on { background: var(--accent); box-shadow: none; }
.lk-dots.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }
.lk-pad { display: grid; grid-template-columns: repeat(3, 72px); gap: 14px 22px; }
.lk-key { width: 72px; height: 72px; border-radius: 50%; border: 0; background: var(--input); font-size: 28px; font-weight: 400; color: var(--text); display: grid; place-items: center; transition: background .1s, transform .08s; }
.lk-key:active { transform: scale(.94); background: var(--accent-soft); }
.lk-fn { background: none; }
.lk-fn svg { width: 30px; height: 30px; fill: none; stroke: var(--text-2); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.lk-forgot { margin-top: 4px; }
.lk-actions { display: flex; gap: 10px; }
.lk-confirm { text-align: center; max-width: 300px; font-size: 14px; }
.lk-confirm .row { display: flex; gap: 8px; justify-content: center; margin-top: 10px; }
@media (max-height: 640px) { .lk-key { width: 60px; height: 60px; font-size: 24px; } .lk-pad { grid-template-columns: repeat(3, 60px); gap: 10px 18px; } .lk-logo { width: 52px; height: 52px; } }

.members-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 22px 0 6px; }
.members-head h3 { margin: 0 !important; }
.btn-sm { padding: 6px 12px; font-size: 14px; border-radius: 8px; }

/* follow the visible viewport (keyboard-aware on iOS): header pinned on top, composer above the keyboard */
.shell { position: fixed; left: 0; right: 0; top: var(--app-top, 0px); height: var(--app-h, 100dvh); }
.lock-screen { top: var(--app-top, 0px); bottom: auto; height: var(--app-h, 100dvh); }
.conv-head, .pinned-bar { flex: none; }

/* ---------- floating header + pinned message (Telegram-style pills over the chat) */
.conv-view { position: relative; --sat: env(safe-area-inset-top, 0px); --head-space: calc(72px + var(--sat)); }
.conv-view.has-pinned { --head-space: calc(128px + var(--sat)); }
.conv-view > .conv-head {
  position: absolute; top: calc(8px + var(--sat)); left: 12px; right: 12px; z-index: 6;
  min-height: 56px; border-radius: 28px; padding: 6px 8px 6px 8px;
  box-shadow: 0 1px 4px rgba(16, 35, 47, .16), 0 1px 1px rgba(16, 35, 47, .06);
}
.conv-view > .pinned-bar {
  position: absolute; top: calc(72px + var(--sat)); left: 12px; right: 12px; z-index: 5; width: auto;
  border-radius: 24px; padding: 7px 8px 7px 18px; min-height: 48px;
  box-shadow: 0 1px 4px rgba(16, 35, 47, .14), 0 1px 1px rgba(16, 35, 47, .05);
}
.conv-view > .call-banner { position: absolute; top: calc(var(--head-space) + 2px); left: 12px; right: 12px; z-index: 5; border-radius: 18px; }
.conv-view > .chat-area { flex: 1; }
.conv-view .messages { padding-top: calc(var(--head-space) + 4px); }
.conv-view .day-sep { top: calc(4px + var(--sat)); }
.head-avatar .avatar { --s: 42px !important; }
@media (max-width: 760px) {
  .conv-view > .conv-head { left: 8px; right: 8px; padding-left: 4px; }
  .conv-view > .pinned-bar { left: 8px; right: 8px; }
  .back-btn { margin-left: 0; }
}

.lottie { position: relative; }
.lottie > .st-thumb { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }

.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 46px; }
.pw-eye { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 38px; height: 38px; border: 0; background: none; border-radius: 50%; display: grid; place-items: center; color: var(--text-3); }
.pw-eye svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.pw-eye.on { color: var(--accent); }

/* keyboard open on phones: sit the composer right on top of the keyboard */
.kb-open .composer-wrap { padding-bottom: 6px !important; }

.bot-tag { display: inline-block; margin-left: 6px; margin-right: 2px; padding: 0 5px; border-radius: 4px; font-size: 10px; font-weight: 700; line-height: 16px; letter-spacing: .3px; vertical-align: 1px; background: var(--accent); color: #fff; }

.pick-list { max-height: 46vh; overflow-y: auto; margin: 4px -6px 6px; }
.pick-row { display: flex; align-items: center; gap: 10px; padding: 6px; border-radius: 10px; cursor: pointer; }
@media (hover: hover) { .pick-row:hover { background: var(--hover, rgba(0,0,0,.05)); } }
.pick-row input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.pick-row .n { display: flex; flex-direction: column; min-width: 0; font-weight: 500; }
.pick-row .n small { font-weight: 400; opacity: .65; }
.chat-item.member { position: relative; }
.member-rm { position: absolute; right: 4px; bottom: 6px; opacity: .55; }
.member-rm.armed { opacity: 1; color: #E53935; }
@media (hover: hover) { .member-rm:hover { opacity: 1; color: #E53935; } }

/* No double-tap zoom anywhere in the app (it is a chat, not a document) */
*, *::before, *::after { touch-action: manipulation; }
.lock-screen, .lock-screen * { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.lk-key { -webkit-tap-highlight-color: transparent; }

/* ---------- performance on phones */
/* The background pattern is drawn once into its own layer instead of on every scroll frame. */
.main::before { transform: translateZ(0); will-change: transform; }
/* Live blur behind the floating date pills is expensive while scrolling on phones: use a solid tint. */
@media (hover: none), (max-width: 760px) {
  .service-pill, .conv-intro { backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--service-solid); }
  .ctx-menu { backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--surface); }
}

/* ---------- chat list: menu, pin / mute / archive */
.chat-ctx .ctx-menu { min-width: 230px; }
.chat-item .name { display: inline-flex; align-items: center; gap: 4px; min-width: 0; }
.muted-ico svg { width: 14px; height: 14px; opacity: .55; flex: none; }
.pin-ico { margin-left: auto; color: var(--text-3); display: grid; place-items: center; }
.pin-ico svg { width: 16px; height: 16px; transform: rotate(45deg); }
.badge.muted { background: var(--text-3); }
.badge.dot { min-width: 12px; width: 12px; height: 12px; padding: 0; }
.arch-ico { display: grid; place-items: center; background: var(--text-3); color: #fff; border-radius: 50%; width: var(--s); height: var(--s); flex: none; }
.arch-ico svg { width: 26px; height: 26px; }
.chat-item { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.auth { min-height: 100dvh; }

/* a bigger, easy-to-hit back button on phones */
.back-btn { width: 44px; height: 44px; margin-left: -4px; }

/* ---------- @mentions */
.mention { color: var(--link); font-weight: 500; cursor: pointer; }
.mention.me { background: color-mix(in srgb, var(--accent) 16%, transparent); border-radius: 4px; padding: 0 2px; cursor: default; }
.msg.mine .mention { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.composer-wrap { position: relative; }
.mention-box { position: absolute; bottom: calc(100% + 4px); left: max(12px, calc((100% - 760px) / 2)); width: min(340px, calc(100% - 24px)); max-height: 260px; overflow-y: auto; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-pop); padding: 4px; z-index: 11; }
.mention-item { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 10px; cursor: pointer; }
.mention-item.on { background: var(--hover); }
@media (hover: hover) { .mention-item:hover { background: var(--hover); } }
.mention-item .n { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.mention-item small { color: var(--text-2); }
.avatar.all { display: grid; place-items: center; background: var(--accent); color: #fff; font-weight: 700; width: var(--s); height: var(--s); border-radius: 50%; flex: none; }

/* ---------- hidden content (card numbers, ||spoilers||) */
.spoiler {
  color: transparent; border-radius: 5px; padding: 0 2px; cursor: pointer;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  background-color: color-mix(in srgb, var(--text) 14%, transparent);
  background-image: radial-gradient(color-mix(in srgb, var(--text) 55%, transparent) .9px, transparent 1.3px),
                    radial-gradient(color-mix(in srgb, var(--text) 35%, transparent) .7px, transparent 1.1px);
  background-size: 5px 5px, 7px 7px; background-position: 0 0, 3px 2px;
  box-decoration-break: clone; -webkit-box-decoration-break: clone;
}
.spoiler a { color: transparent; }
.spoiler.open { color: inherit; background-image: none; background-color: color-mix(in srgb, var(--text) 8%, transparent); cursor: text; -webkit-user-select: text; user-select: text; }

.share-row { width: 100%; border: 0; background: none; text-align: left; font: inherit; color: inherit; }

/* ---------- videos: tap to open full screen, keep playing in the chat after closing */
.vid-msg { cursor: pointer; }
.vid-play, .vid-mini { position: absolute; display: grid; place-items: center; color: #fff; background: rgba(0,0,0,.5); border-radius: 50%; border: 0; pointer-events: none; }
.vid-play { left: 50%; top: 50%; width: 56px; height: 56px; transform: translate(-50%, -50%); }
.vid-play svg { width: 26px; height: 26px; margin-left: 3px; }
.vid-mini { left: 8px; top: 8px; width: 34px; height: 34px; display: none; pointer-events: auto; cursor: pointer; }
.vid-mini svg { width: 16px; height: 16px; }
.vid-msg.playing .vid-play { display: none; }
.vid-msg.playing .vid-mini { display: grid; }
.vid-dur { position: absolute; left: 8px; bottom: 8px; background: rgba(0,0,0,.5); color: #fff; font-size: 12px; padding: 2px 7px; border-radius: 10px; }
.vid-msg.playing .vid-dur { display: none; }
.vlb-stage { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: calc(56px + env(safe-area-inset-top)) 0 calc(16px + env(safe-area-inset-bottom)); }
.vlb-stage video { max-width: 100vw; max-height: 100%; width: auto; height: auto; background: #000; transition: transform .15s; }

/* Phones: the sign-in card sits near the top and the page has room to scroll it above the keyboard.
   The layout never changes while typing, so the button stays exactly where the finger lands. */
@media (hover: none), (max-width: 760px) { .auth { align-items: start; padding-bottom: 50vh; } }

/* tin chuyển tiếp */
.fwd { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--accent); margin: 0 0 3px; line-height: 1.3; min-width: 0; }
.fwd svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.fwd span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fwd b { font-weight: 600; }
.bubble.media .head .fwd { margin: 0; }
.sticker-wrap > .fwd { background: var(--service-bg); color: #fff; padding: 3px 8px; border-radius: 10px; width: fit-content; }
.modal .pick-list + input { margin-top: 6px; }
.modal input[type=search] { margin-bottom: 4px; }

/* thư mục chat (tab như Telegram) */
.folder-tabs { display: flex; gap: 4px; padding: 0 10px 8px; overflow-x: auto; scrollbar-width: none; flex: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.folder-tabs::-webkit-scrollbar { display: none; }
.folder-tabs[hidden] { display: none; }
.ftab { flex: none; display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; color: var(--text-2); font-size: 15px; font-weight: 500; padding: 7px 14px; border-radius: 18px; white-space: nowrap; }
.ftab[aria-pressed="true"] { background: var(--accent-soft, var(--hover)); color: var(--accent); }
@media (hover: hover) { .ftab:hover { background: var(--hover); } }
.ftab .fcount { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--text-3); color: #fff; font-size: 11.5px; font-weight: 600; display: inline-grid; place-items: center; }
.ftab[aria-pressed="true"] .fcount { background: var(--accent); }
.folder-settings { display: grid; gap: 4px; justify-items: start; }
.folder-settings .pick-row { width: 100%; border: 0; background: none; text-align: left; color: inherit; }
.folder-settings .pick-row svg { width: 22px; height: 22px; fill: none; stroke: var(--text-2); stroke-width: 1.8; stroke-linejoin: round; flex: none; }
.search-empty .btn { margin-top: 8px; }

.chat-item .preview .draft { color: var(--danger); }
.chat-item[aria-current="true"] .preview .draft { color: #fff; }

/* vuốt trái để trả lời */
.swipe-reply { position: absolute; right: 6px; top: 50%; width: 32px; height: 32px; border-radius: 50%; background: var(--service-bg); display: grid; place-items: center; pointer-events: none; transition: background .15s; }
.swipe-reply svg { width: 18px; height: 18px; fill: none; stroke: #fff; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.swipe-reply.armed { background: var(--accent); }
.msg .col { will-change: auto; }

/* menu giữ tin nhắn trên điện thoại: làm mờ nền, tin nhắn nổi lên */
.ctx-layer.focus { background: rgba(0, 0, 0, .18); backdrop-filter: blur(10px) saturate(1.1); -webkit-backdrop-filter: blur(10px) saturate(1.1); animation: fade .16s ease-out; }
.ctx-ghost { position: fixed; margin: 0 !important; pointer-events: none; animation: ghost-in .2s ease-out; transform-origin: center; }
.ctx-ghost .bubble, .ctx-ghost .sticker-msg { filter: none !important; }
@keyframes ghost-in { 50% { transform: scale(1.02); } }
@media (prefers-reduced-motion: reduce) { .ctx-layer.focus, .ctx-ghost { animation: none; } }

/* phản hồi khi nhấn trên điện thoại (thay cho hover) */
@media (hover: none) {
  .chat-item:active:not([aria-current="true"]) { background: var(--hover); transition: background 0s; }
  .chat-item { transition: background .25s; }
  .icon-btn:active, .ftab:active { background: var(--hover); }
  .fab:active, .send-btn:active { transform: scale(.92); }
  .fab, .send-btn { transition: transform .12s; }
  .ctx-menu button:active, .pick-row:active { background: var(--hover); }
}

/* hộp mời bật thông báo khi mở app đã cài */
.notif-ask { display: grid; justify-items: center; text-align: center; gap: 8px; padding: 6px 0 0; }
.notif-ask h2 { margin: 4px 0 0; }
.notif-ask p { margin: 0 0 8px; color: var(--text-2); }
.notif-ask-ico { width: 64px; height: 64px; border-radius: 50%; background: var(--accent-soft); display: grid; place-items: center; }
.notif-ask-ico svg { width: 32px; height: 32px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* họa tiết nền cột danh sách */
.side[data-pattern]::before { content: ""; position: absolute; inset: 0; background-image: var(--side-pat); background-size: var(--side-pat-size); opacity: var(--side-pat-op); filter: var(--side-pat-filter); pointer-events: none; z-index: 0; }
.side[data-pattern] > :not(.fab) { position: relative; z-index: 1; }
.side[data-pattern] .chat-item[aria-current="false"], .side[data-pattern] .chat-item:not([aria-current]) { background-color: transparent; }
.pat-picks { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px; }
.pat-pick { position: relative; height: 64px; border-radius: 12px; border: 2px solid var(--line); overflow: hidden; display: flex; align-items: flex-end; justify-content: center; padding: 0 0 4px; color: var(--text); }
.pat-pick[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.pat-pick small { position: relative; font-size: 11.5px; background: var(--surface); padding: 1px 6px; border-radius: 8px; }
.pat-swatch { position: absolute; inset: 0; background-image: var(--p); background-size: var(--ps); opacity: .25; }

/* màn đăng nhập: dùng margin auto thay cho căn giữa bằng grid, để khi màn hình thấp
   linh vật phía trên thẻ không bị cắt mất (grid căn giữa tràn ra cả 2 phía, phần trên không cuộn tới được) */
.auth { display: flex; flex-direction: column; padding: calc(100px + env(safe-area-inset-top)) 16px 24px; }
.auth > .auth-card { margin: auto; }
.auth-mascot { filter: drop-shadow(0 10px 18px rgba(16, 60, 180, .35)); }

/* Vùng tai thỏ / thanh trạng thái: Safari và bản "Thêm vào MH chính" để giá trị này = 0,
   còn app iOS (Chat.ipa) cho trang tràn lên dưới thanh trạng thái nên phải chừa chỗ. */
.side { padding-top: env(safe-area-inset-top, 0px); }
.toasts { top: calc(12px + env(safe-area-inset-top, 0px)); }

/* Như Telegram: tin nhắn cuộn lên dưới thanh trạng thái / đầu màn chat thì mờ dần đi,
   không hiện rõ chữ chồng lên giờ, sóng, pin. */
.conv-view::before {
  content: ""; position: absolute; left: 0; right: 0; top: 0; z-index: 4; pointer-events: none;
  height: calc(var(--sat) + 100px);
  background: linear-gradient(to bottom, color-mix(in srgb, var(--surface) 55%, transparent), color-mix(in srgb, var(--surface) 0%, transparent));
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  -webkit-mask-image: linear-gradient(to bottom, #000 0, #000 calc(var(--sat) + 40px), transparent 100%);
  mask-image: linear-gradient(to bottom, #000 0, #000 calc(var(--sat) + 40px), transparent 100%);
}
.conv-view.has-pinned::before { height: calc(var(--sat) + 156px); }

/* App iOS: bàn phím iOS mới có viền bo tròn và lớp kính mờ nhô lên phía trên khung báo về,
   nên chừa thêm khoảng để ô soạn tin không bị mép bàn phím che. */
.in-app.kb-open .composer-wrap { padding-bottom: 16px !important; }

/* Đang gọi (khung gọi nằm trên, màn chat ở dưới): khung gọi mới là thứ chạm thanh trạng thái,
   nên khung gọi chừa chỗ tai thỏ, còn màn chat bên dưới không cần chừa nữa (trước bị hở một khoảng trống). */
.call-stage:not([hidden]) { padding-top: env(safe-area-inset-top, 0px); height: calc(min(52vh, 460px) + env(safe-area-inset-top, 0px)); }
.call-stage.full:not([hidden]) { height: auto; padding-bottom: env(safe-area-inset-bottom, 0px); }
.call-stage:not([hidden]) ~ .conv-view { --sat: 0px; }

/* ---------- chọn nhiều tin nhắn */
.conv-head { position: relative; }
.select-bar { position: absolute; inset: 0; display: flex; align-items: center; gap: 4px; padding: 0 8px; background: var(--surface); border-radius: inherit; z-index: 2; animation: fade .15s; }
.select-bar .sel-count { flex: 1; font-weight: 600; font-size: 17px; margin-left: 6px; }
.select-bar .icon-btn { width: 42px; height: 42px; border: 0; background: none; border-radius: 50%; display: grid; place-items: center; color: var(--text); }
.select-bar .icon-btn:hover { background: var(--hover); }
.select-bar .icon-btn[disabled] { opacity: .3; }
.select-bar .icon-btn.danger { color: var(--danger); }
.select-bar .icon-btn svg { width: 22px; height: 22px; }
.conv-view.selecting .msg[data-id] { cursor: pointer; padding-left: 38px; }
.conv-view.selecting .msg[data-id]::before { content: ""; position: absolute; left: 8px; top: 50%; width: 22px; height: 22px; margin-top: -11px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .9); box-shadow: 0 0 0 1px rgba(0, 0, 0, .2); background: rgba(0, 0, 0, .12); box-sizing: border-box; }
.conv-view.selecting .msg.selected::before { background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E") center / 14px no-repeat; border-color: var(--accent); }
.conv-view.selecting .msg.selected { background: color-mix(in srgb, var(--accent) 14%, transparent); border-radius: 10px; }
.conv-view.selecting .msg[data-id] * { pointer-events: none; }

/* chọn nhiều trên điện thoại: không bôi chữ / bật menu hệ thống khi chạm giữ, chạm là ăn ngay */
.conv-view.selecting .msg[data-id] { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
@media (max-width: 560px) {
  .select-bar { gap: 0; padding: 0 4px; }
  .select-bar .sel-count { font-size: 16px; margin-left: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .select-bar .icon-btn { width: 40px; height: 40px; }
  .conv-view.selecting .msg[data-id] { padding-left: 34px; }
  .conv-view.selecting .msg[data-id]::before { left: 6px; }
}

/* ---------- xem tài liệu (PDF, Word, Excel, file chữ) ngay trong chat */
.docview { display: flex; flex-direction: column; background: #2b2e33; }
.dv-head { display: flex; align-items: center; gap: 8px; padding: calc(8px + env(safe-area-inset-top)) 10px 8px 16px; background: rgba(0,0,0,.35); color: #fff; flex: none; }
.dv-head .lb-btn { font-size: 24px; line-height: 1; flex: none; }
.dv-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.dv-title b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dv-info { font-size: 12.5px; opacity: .7; }
.dv-body { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.dv-pages { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 12px 12px calc(24px + env(safe-area-inset-bottom)); min-width: min-content; }
.dv-page { background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.4); max-width: none; }
.dv-page canvas { width: 100%; height: 100%; display: block; }
.dv-status { color: #e8e8e8; text-align: center; padding: 48px 20px; line-height: 1.7; }
.dv-status .btn { display: inline-block; margin-top: 14px; color: #fff; }
.dv-text { margin: 0; padding: 16px 18px calc(24px + env(safe-area-inset-bottom)); color: #e9edf1; font: 13.5px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-word; -webkit-user-select: text; user-select: text; }
@media (max-width: 760px) { .dv-head .lb-btn { width: 38px; height: 38px; } }

/* ---------- thẻ "đang gửi" trong khung chat */
.up-list { padding-top: 0; }
.msg.uploading { margin-top: 4px; }
.msg.uploading .bubble { padding: 4px; }
.up-card.media { position: relative; width: min(280px, 62vw); border-radius: 12px; overflow: hidden; background: #000; }
.up-card.media img, .up-card.media video { display: block; width: 100%; max-height: 320px; object-fit: cover; filter: brightness(.72); }
.up-over { position: absolute; inset: 0; display: grid; place-items: center; }
.up-foot { position: absolute; left: 6px; bottom: 6px; padding: 2px 8px; border-radius: 10px; background: rgba(0,0,0,.55); color: #fff; font-size: 12px; font-variant-numeric: tabular-nums; }
.up-card.doc { display: flex; align-items: center; gap: 12px; padding: 4px 10px 4px 4px; max-width: 300px; }
.up-ico { position: relative; width: 52px; height: 52px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--accent); }
.up-txt { min-width: 0; }
.up-txt b { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-txt .up-status { color: var(--text-2); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.up-ring { position: relative; width: 52px; height: 52px; display: grid; place-items: center; color: #fff; }
.up-ring svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.up-ring circle { fill: none; stroke-width: 3; }
.up-ring .bg { stroke: rgba(255,255,255,.28); }
.up-ring .fg { stroke: #fff; stroke-linecap: round; transition: stroke-dashoffset .3s; }
.up-ring.spin svg { animation: upspin 1.1s linear infinite; }
.up-ring span { font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; transition: opacity .15s; }
.up-card.media .up-ring { width: 58px; height: 58px; background: rgba(0,0,0,.35); border-radius: 50%; }
.up-cancel { position: absolute; width: 26px; height: 26px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; cursor: pointer; display: grid; place-items: center; opacity: 0; transition: opacity .15s; }
.up-card.media .up-cancel { top: 8px; right: 8px; opacity: 1; }
.up-ico .up-cancel { inset: 0; width: 100%; height: 100%; background: rgba(0,0,0,.45); font-size: 16px; }
.up-ico:hover .up-cancel, .up-ico:focus-within .up-cancel { opacity: 1; }
@media (hover: none) { .up-ico .up-cancel { opacity: 0; } .up-ico .up-cancel:active { opacity: 1; } }
.msg.uploading.failed .up-ring .fg { stroke: var(--danger, #e5484d); }
.msg.uploading.failed .up-status { color: var(--danger, #e5484d); }
@keyframes upspin { to { transform: rotate(270deg); } }
/* video trong khung gửi: có nút ▶ để biết là video kể cả khi iPhone chưa vẽ xong khung hình đầu */
.mc-item.video { min-height: 160px; background: #1f2328; }
.mc-item.video::after { content: ''; position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%; background: rgba(0,0,0,.5) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='white' d='M8 5v14l11-7z'/%3E%3C/svg%3E") center / 26px no-repeat; pointer-events: none; }
.up-card.media video { min-height: 160px; background: #1f2328; }

/* ---------- video TikTok / Facebook dán vào chat */
.vembed { width: auto; min-width: min(280px, 68vw); max-width: 100%; margin: 2px 0 6px; border-radius: 12px; overflow: hidden; background: #111; }
.vembed-poster { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; width: 100%; aspect-ratio: 16 / 10; border: 0; padding: 0; cursor: pointer; color: #fff; font: inherit;
  background: radial-gradient(circle at 30% 20%, #3a3f47, #121417 70%); }
.vembed.tiktok .vembed-poster { background: radial-gradient(circle at 25% 15%, rgba(37,244,238,.35), transparent 45%), radial-gradient(circle at 80% 85%, rgba(254,44,85,.35), transparent 45%), #111; }
.vembed.facebook .vembed-poster { background: radial-gradient(circle at 30% 20%, #2d6ff0, #0b2f73 75%); }
.vembed-logo { position: absolute; top: 10px; left: 10px; width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; font-weight: 800; font-size: 18px; background: rgba(255,255,255,.14); }
.vembed-logo.facebook { font-family: Arial, sans-serif; }
.vembed-play { width: 54px; height: 54px; border-radius: 50%; background: rgba(255,255,255,.18) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='white' d='M8 5v14l11-7z'/%3E%3C/svg%3E") 55% center / 30px no-repeat; transition: transform .15s; }
.vembed-poster:hover .vembed-play { transform: scale(1.08); }
.vembed-poster:disabled { cursor: progress; }
.vembed-label { font-size: 14px; font-weight: 600; padding: 0 12px; text-align: center; }
.vembed.playing iframe { display: block; width: 100%; aspect-ratio: 9 / 16; border: 0; background: #000; }
.vembed-bar { display: flex; justify-content: space-between; background: #1b1d21; }
.vembed-bar button { background: none; border: 0; color: #cfd6de; font: inherit; font-size: 13px; padding: 8px 12px; cursor: pointer; }
.vembed-bar button:hover { color: #fff; }
.conv-view.selecting .vembed { pointer-events: none; }
.vembed.playing video { display: block; width: 100%; max-height: 70vh; aspect-ratio: 9 / 16; background: #000; object-fit: contain; }
/* YouTube: video ngang 16:9, Shorts dọc */
.vembed.youtube .vembed-poster { background: #200 center / cover no-repeat; }
.vembed.youtube .vembed-logo { background: #f00; font-size: 13px; }
.vembed.wide { min-width: min(360px, 68vw); } /* thẻ giãn theo bề ngang bong bóng, không chừa khoảng trống */
.vembed.wide .vembed-poster, .vembed.wide.playing iframe { aspect-ratio: 16 / 9; }
.vembed.tiktok .vembed-poster { background-color: #111; background-size: cover; background-position: center; }

/* màn hình chờ lúc mở app (thay cho trang trắng); quá 8 giây chưa mở xong thì hiện nút tải lại */
.boot { position: fixed; inset: 0; display: grid; place-items: center; align-content: center; gap: 18px; background: var(--bg, #fff); }
.boot-spin { width: 34px; height: 34px; border-radius: 50%; border: 3px solid color-mix(in srgb, var(--accent, #3390ec) 25%, transparent); border-top-color: var(--accent, #3390ec); animation: bootspin .8s linear infinite; }
.boot-retry { color: var(--accent, #3390ec); font-size: 15px; text-decoration: none; padding: 8px 14px; opacity: 0; pointer-events: none; animation: bootshow 0s 8s forwards; }
@keyframes bootspin { to { transform: rotate(360deg); } }
@keyframes bootshow { to { opacity: 1; pointer-events: auto; } }
