/* ===== Phông chữ Be Vietnam Pro (tự lưu trong app, không cần mạng ngoài) ===== */
@font-face { font-family: 'Be Vietnam Pro'; font-style: normal; font-weight: 400; font-display: swap;
  src: url(/fonts/be-vietnam-pro-vietnamese-400-normal.woff2) format('woff2');
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB; }
@font-face { font-family: 'Be Vietnam Pro'; font-style: normal; font-weight: 400; font-display: swap;
  src: url(/fonts/be-vietnam-pro-latin-400-normal.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Be Vietnam Pro'; font-style: normal; font-weight: 600; font-display: swap;
  src: url(/fonts/be-vietnam-pro-vietnamese-600-normal.woff2) format('woff2');
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB; }
@font-face { font-family: 'Be Vietnam Pro'; font-style: normal; font-weight: 600; font-display: swap;
  src: url(/fonts/be-vietnam-pro-latin-600-normal.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Be Vietnam Pro'; font-style: normal; font-weight: 800; font-display: swap;
  src: url(/fonts/be-vietnam-pro-vietnamese-800-normal.woff2) format('woff2');
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB; }
@font-face { font-family: 'Be Vietnam Pro'; font-style: normal; font-weight: 800; font-display: swap;
  src: url(/fonts/be-vietnam-pro-latin-800-normal.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

/* ===== Màu sắc: ngọc bích (jade) + nghệ (turmeric) ===== */
:root {
  --jade: #0E7C66;
  --jade-deep: #0A5E4E;
  --jade-ink: #0E7C66;
  --jade-wash: #DCEFE9;
  --turmeric: #F2B01E;
  --turmeric-wash: #FCEFCC;
  --turmeric-ink: #7A5600;
  --presence: #2DBE7E;
  --ink: #14201C;
  --ink-2: #3E4C47;
  --muted: #62716B;
  --bg: #EEF2EF;
  --surface: #FFFFFF;
  --field: #F1F4F2;
  --line: #DDE4E0;
  --theirs: #FFFFFF;
  --theirs-line: #DDE4E0;
  --danger: #B3372A;
  --danger-wash: #F8E3DF;
  --overlay: rgba(12, 22, 18, 0.46);
  --toast: #14201C;
  --toast-ink: #F2F6F4;
  --meter-good: #008A6A;
  --meter-good-track: #D5EEE6;
  --meter-warn: #E29C00;
  --meter-warn-track: #FBEBC4;
  --meter-crit: #C23B2C;
  --meter-crit-track: #F6DAD6;
  --font: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji';
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --jade-ink: #4CC9AA;
    --jade-wash: #16342C;
    --turmeric-wash: #3A2F12;
    --turmeric-ink: #F2C04E;
    --ink: #E3EBE7;
    --ink-2: #BFCBC6;
    --muted: #93A39C;
    --bg: #0F1714;
    --surface: #16211D;
    --field: #1E2B26;
    --line: #26352F;
    --theirs: #1F2C27;
    --theirs-line: #1F2C27;
    --danger: #F0826F;
    --danger-wash: #3A1F1A;
    --overlay: rgba(0, 0, 0, 0.6);
    --toast: #E3EBE7;
    --toast-ink: #14201C;
    --meter-good: #1E9E7C;
    --meter-good-track: #173B31;
    --meter-warn: #BD8B11;
    --meter-warn-track: #3A2F12;
    --meter-crit: #C2443A;
    --meter-crit-track: #3D1F1B;
    color-scheme: dark;
  }
}

/* ===== Nền tảng ===== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; min-height: 100%; background: var(--bg); }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
img { display: block; }
a { color: var(--jade-ink); }
:focus-visible { outline: 2px solid var(--jade-ink); outline-offset: 2px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ic { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ===== Nút & ô nhập ===== */
.btn {
  --spin: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 12px;
  background: var(--field); color: var(--ink);
  font-weight: 600; font-size: 15px; line-height: 1.2; text-align: center;
  transition: background-color .15s, opacity .15s;
}
.btn:hover { background: color-mix(in srgb, var(--field), var(--ink) 6%); }
.btn-primary { --spin: #fff; background: var(--jade); color: #fff; }
.btn-primary:hover { background: var(--jade-deep); }
.btn-quiet { background: transparent; color: var(--ink-2); }
.btn-quiet:hover { background: var(--field); }
.btn-danger { background: transparent; color: var(--danger); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--danger), transparent 55%); }
.btn-danger:hover { background: var(--danger-wash); }
.btn-danger-quiet { color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { cursor: default; }
.btn.busy { position: relative; color: transparent !important; }
.btn.busy::after {
  content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--spin); border-right-color: transparent; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn { display: inline-grid; place-items: center; width: 42px; height: 42px; flex: none; border-radius: 12px; color: var(--ink-2); }
.icon-btn:hover { background: var(--field); }
.link-btn { color: var(--danger); font-size: 14px; font-weight: 600; padding: 6px 8px; border-radius: 8px; }

.stack { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field > span:first-child { font-size: 13.5px; font-weight: 600; color: var(--ink-2); }
.field input, .inline input, .search input, .search-input {
  width: 100%; min-height: 46px; padding: 0 14px;
  font-size: 16px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .inline input:focus, .search input:focus, .search-input:focus {
  border-color: var(--jade-ink);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--jade-ink), transparent 80%);
}
.field input::placeholder, .search input::placeholder, .search-input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
.pw { position: relative; display: block; }
.pw input { padding-right: 50px; }
.pw-toggle { position: absolute; top: 50%; right: 2px; transform: translateY(-50%); width: 44px; height: 44px; display: grid; place-items: center; color: var(--muted); border-radius: 10px; }
.pw-toggle.on { color: var(--jade-ink); }
.form-error { color: var(--danger); font-size: 14px; }
.hint { color: var(--muted); font-size: 13.5px; }

/* ===== Màn chờ & đăng nhập ===== */
.screen.boot { min-height: 100vh; min-height: 100dvh; display: grid; place-content: center; justify-items: center; gap: 18px; padding: 24px; }
.boot-hint { max-width: 260px; color: var(--muted); font-size: 14px; text-align: center; }
.screen.boot img { border-radius: 16px; }

/* Nền đen chữ trắng kiểu X (luôn đen, không theo chế độ sáng/tối của máy) */
html.auth-mode, html.auth-mode body { background: #000000; }
.screen.auth {
  --x-bg: #000000;
  --x-text: #E7E9EA;
  --x-muted: #71767B;
  --x-line: #333639;
  --x-btn: #EFF3F4;
  --x-btn-ink: #0F1419;
  --x-error: #F4212E;
  min-height: 100vh; min-height: 100dvh;
  display: grid; align-content: start;
  padding: calc(32px + var(--safe-top)) 24px calc(32px + var(--safe-bottom));
  background: var(--x-bg); color: var(--x-text); color-scheme: dark;
}
.auth-brand, .auth-main { width: 100%; max-width: 400px; margin: 0 auto; }
.wordmark { font-weight: 800; font-size: 34px; line-height: 1; letter-spacing: -0.045em; overflow-wrap: anywhere; }
.auth-main { margin-top: 56px; }
.auth-headline { font-weight: 800; font-size: clamp(36px, 10.5vw, 44px); line-height: 1.08; letter-spacing: -0.03em; }
.auth-headline-sm { font-size: 31px; line-height: 1.15; }
.auth-lead { margin-top: 12px; color: var(--x-muted); font-size: 16px; }
.auth-form { display: grid; gap: 16px; margin-top: 36px; }
.auth-note { margin-top: 28px; color: var(--x-muted); font-size: 15px; }
.auth .hint { color: var(--x-muted); }
.auth .form-error { color: var(--x-error); font-size: 15px; }
.auth :focus-visible { outline-color: var(--x-text); }

/* Ô nhập có nhãn nổi, viền mảnh */
.float { position: relative; }
.float input {
  width: 100%; height: 58px; padding: 24px 12px 6px;
  border: 1px solid var(--x-line); border-radius: 6px; outline: none;
  background: transparent; color: var(--x-text); font-size: 17px;
  transition: border-color .15s, box-shadow .15s;
}
.float.has-toggle input { padding-right: 52px; }
.float-label {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  color: var(--x-muted); font-size: 17px; pointer-events: none;
  transition: top .15s, font-size .15s, transform .15s, color .15s;
}
.float input:focus { border-color: var(--x-text); box-shadow: 0 0 0 1px var(--x-text); }
.float input:focus + .float-label,
.float input:not(:placeholder-shown) + .float-label,
.float input:-webkit-autofill + .float-label { top: 9px; transform: none; font-size: 13px; }
.float input:focus + .float-label { color: var(--x-text); }
.float input:-webkit-autofill {
  -webkit-text-fill-color: var(--x-text); caret-color: var(--x-text);
  -webkit-box-shadow: 0 0 0 1000px var(--x-bg) inset; transition: background-color 9999s ease-out;
}
.float .pw-toggle { right: 4px; color: var(--x-muted); }
.float .pw-toggle.on { color: var(--x-text); }

/* Nút viên thuốc trắng chữ đen */
.btn-pill { --spin: var(--x-btn-ink); min-height: 52px; border-radius: 999px; background: var(--x-btn); color: var(--x-btn-ink); font-size: 17px; font-weight: 800; }
.btn-pill:hover { background: #D7DBDC; }
.btn-pill-outline { min-height: 52px; margin-top: 12px; border-radius: 999px; background: transparent; color: var(--x-text); box-shadow: inset 0 0 0 1px #536471; font-size: 17px; font-weight: 800; }
.btn-pill-outline:hover { background: rgba(239, 243, 244, .1); }

/* Màn đăng nhập: chỉ có chữ Think và form, căn giữa theo chiều dọc */
.screen.auth-login { align-content: center; }
@media (max-width: 899.98px) { .screen.auth-login { padding-bottom: calc(12vh + var(--safe-bottom)); } }
.auth-login .wordmark { font-size: clamp(64px, 21vw, 96px); letter-spacing: -0.055em; }
.auth-login .auth-main { margin-top: 32px; }
.auth-login .auth-form { margin-top: 0; }

/* Máy tính: chữ Think thật to bên trái, form bên phải */
@media (min-width: 900px) {
  .screen.auth { grid-template-columns: 1fr 1fr; align-content: center; align-items: center; column-gap: 56px; padding: 48px 72px; }
  .auth-brand { max-width: none; margin: 0; display: grid; place-items: center; }
  .auth-brand .wordmark { font-size: clamp(120px, 13vw, 230px); letter-spacing: -0.06em; }
  .auth-main, .auth-login .auth-main { max-width: 420px; margin: 0; }
  .auth-headline { font-size: clamp(48px, 4.6vw, 64px); }
  .auth-headline-sm { font-size: 36px; }
}

/* ===== Bố cục chính ===== */
.screen.main {
  position: fixed; left: 0; right: 0;
  top: var(--vv-top, 0px);
  height: var(--app-h, 100dvh);
  display: grid; grid-template-columns: 1fr;
  background: var(--bg); overflow: hidden;
}
@media (min-width: 860px) {
  .screen.main { grid-template-columns: minmax(320px, 390px) 1fr; }
}
@media (max-width: 859.98px) {
  body.in-chat .sidebar { display: none; }
  body:not(.in-chat) .chat { display: none; }
}

/* Cột trái */
.sidebar { display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-right: 1px solid var(--line); padding-left: var(--safe-left); }
.side-head { display: flex; align-items: center; gap: 6px; padding: calc(10px + var(--safe-top)) 10px 8px 16px; }
.side-title { flex: 1; min-width: 0; font-weight: 800; font-size: 24px; letter-spacing: -0.03em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search { padding: 4px 16px 10px; }
.search input { min-height: 42px; background: var(--field); border-color: transparent; }

#banner:empty { display: none; }
.banner { margin: 0 12px 10px; padding: 14px; border-radius: 16px; background: var(--jade-wash); display: grid; gap: 10px; font-size: 14px; }
.banner-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.conv-list { list-style: none; margin: 0; padding: 2px 8px 12px; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.conv-link { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 14px; color: inherit; text-decoration: none; }
.conv-link:hover { background: var(--field); }
.conv.is-active .conv-link { background: var(--jade-wash); }
.conv-main { flex: 1; min-width: 0; display: grid; gap: 1px; }
.conv-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.conv-name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { flex: none; font-size: 12px; color: var(--muted); }
.conv-preview { flex: 1; min-width: 0; font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-preview.is-typing { color: var(--jade-ink); }
.conv.has-unread .conv-preview, .conv.has-unread .conv-time { color: var(--ink); font-weight: 600; }
.conv-empty { color: var(--muted); padding: 20px 12px; font-size: 14px; }
.badge {
  flex: none; display: inline-grid; place-items: center;
  min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px;
  background: var(--turmeric); color: #14201C;
  font-size: 12px; font-weight: 800; line-height: 1;
}
.conn-status { margin: 0 12px 10px; padding: 8px 12px; border-radius: 10px; background: var(--turmeric-wash); color: var(--turmeric-ink); font-size: 13px; text-align: center; }

/* Ảnh đại diện */
.avatar {
  --size: 48px;
  position: relative; flex: none;
  width: var(--size); height: var(--size); border-radius: 50%;
  display: inline-grid; place-items: center;
  background: var(--av, #5E6B66); color: #fff;
  font-weight: 600; font-size: calc(var(--size) * .42); line-height: 1;
  user-select: none; -webkit-user-select: none;
}
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatar.is-group { background: var(--jade); }
.avatar.is-group .ic { width: 56%; height: 56%; stroke-width: 1.7; }
.avatar.is-online::after {
  content: ''; position: absolute; right: -1px; bottom: -1px;
  width: max(11px, calc(var(--size) * .27)); height: max(11px, calc(var(--size) * .27));
  border-radius: 50%; background: var(--presence); border: 2.5px solid var(--surface);
}
.avatar-xs { --size: 16px; font-size: 9px; }
.avatar-sm { --size: 28px; }
.avatar-xl { --size: 88px; }
#tab-avatar { --size: 26px; font-size: 12px; }
#chat-avatar { --size: 40px; }

/* Khung chat */
.chat { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); padding-right: var(--safe-right); }
.chat-empty { flex: 1; display: grid; place-items: center; padding: 40px; text-align: center; color: var(--muted); }
.chat-empty p { max-width: 300px; }
.chat-pane { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: calc(8px + var(--safe-top)) 14px 8px 8px; background: var(--surface); border-bottom: 1px solid var(--line); }
.chat-title { flex: 1; min-width: 0; }
.chat-title h2 { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-title p { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-title p.is-online { color: var(--jade-ink); }
@media (min-width: 860px) {
  .back-btn { display: none; }
  .chat-head { padding-left: 16px; }
}

.messages { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 8px 12px 10px; display: flex; flex-direction: column; }
@media (min-width: 860px) { .messages { padding: 8px 24px 12px; } }
.msg-state { text-align: center; color: var(--muted); font-size: 13px; padding: 14px 0; min-height: 46px; }
.intro { display: grid; justify-items: center; gap: 6px; padding: 28px 16px 18px; text-align: center; }
.intro .avatar { margin-bottom: 6px; }
.intro-name { font-weight: 800; font-size: 20px; letter-spacing: -0.015em; }
.intro-text { color: var(--muted); font-size: 14px; max-width: 300px; }
.day-sep { display: flex; justify-content: center; margin: 16px 0 6px; }
.day-sep span { font-size: 12px; font-weight: 600; color: var(--muted); padding: 3px 10px; border-radius: 999px; background: color-mix(in srgb, var(--bg), var(--ink) 6%); }

.msg { display: flex; align-items: flex-end; gap: 8px; margin-top: 2px; }
.msg.first { margin-top: 10px; }
.msg.mine { justify-content: flex-end; }
.msg-avatar { width: 28px; flex: none; }
.msg-col { display: flex; flex-direction: column; min-width: 0; max-width: min(78%, 560px); }
.msg.mine .msg-col { align-items: flex-end; }
.msg.theirs .msg-col { align-items: flex-start; }
.msg-sender { font-size: 12px; color: var(--muted); margin: 0 12px 3px; }
.bubble {
  position: relative; padding: 8px 13px; border-radius: 20px;
  font-size: 15.5px; line-height: 1.4;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.mine .bubble { background: var(--jade); color: #fff; }
.msg.theirs .bubble { background: var(--theirs); color: var(--ink); box-shadow: inset 0 0 0 1px var(--theirs-line); }
.msg.mine:not(.last) .bubble { border-bottom-right-radius: 6px; }
.msg.mine:not(.first) .bubble { border-top-right-radius: 6px; }
.msg.theirs:not(.last) .bubble { border-bottom-left-radius: 6px; }
.msg.theirs:not(.first) .bubble { border-top-left-radius: 6px; }
.msg.mine .bubble a { color: #fff; }
.bubble.is-image { padding: 0; background: none !important; box-shadow: none !important; }
.bubble.has-image { padding: 4px 4px 8px; }
.bubble.has-image .bubble-text { display: block; padding: 6px 9px 0; }
.msg-img {
  max-width: 100%; height: auto; border-radius: 16px;
  background: color-mix(in srgb, var(--bg), var(--ink) 8%);
  cursor: zoom-in; -webkit-touch-callout: none; user-select: none; -webkit-user-select: none;
}
.bubble.is-emoji { padding: 0 2px; background: none !important; box-shadow: none !important; font-size: 42px; line-height: 1.15; }
.bubble.is-deleted { background: transparent !important; color: var(--muted) !important; box-shadow: inset 0 0 0 1px var(--line) !important; font-size: 14px; }
.msg-meta { font-size: 11.5px; color: var(--muted); margin: 3px 6px 0; }
.msg.pending .bubble { opacity: .65; }
.msg.failed .bubble { box-shadow: 0 0 0 2px var(--danger); }
.msg.failed .msg-meta { color: var(--danger); font-weight: 600; cursor: pointer; }
.msg.is-selected .bubble { outline: 2px solid var(--turmeric); outline-offset: 2px; }
.msg.enter .bubble { animation: pop .2s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.97); } to { opacity: 1; transform: none; } }
.seen { display: flex; justify-content: flex-end; align-items: center; gap: 5px; margin: 4px 4px 0; font-size: 11.5px; color: var(--muted); }

.chat-foot { position: relative; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: var(--safe-bottom); }
.jump-btn {
  position: absolute; left: 50%; bottom: calc(100% + 10px); transform: translateX(-50%);
  padding: 8px 14px; border-radius: 999px; background: var(--jade); color: #fff;
  font-size: 13.5px; font-weight: 600; white-space: nowrap;
  box-shadow: 0 6px 18px rgba(10, 40, 30, .25);
}
.typing { display: flex; align-items: center; gap: 8px; padding: 7px 16px 0; font-size: 13px; color: var(--muted); }
.dots { display: inline-flex; gap: 3px; }
.dots i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; animation: blink 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; transform: none; } 30% { opacity: 1; transform: translateY(-2px); } }
.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px; }
.composer textarea {
  flex: 1; min-width: 0; min-height: 42px; max-height: 140px; resize: none;
  padding: 10px 15px; border-radius: 21px; border: 1px solid transparent;
  background: var(--field); font-size: 16px; line-height: 1.35; outline: none;
}
.composer textarea:focus { border-color: color-mix(in srgb, var(--jade-ink), transparent 50%); }
.send-btn { display: grid; place-items: center; width: 42px; height: 42px; flex: none; border-radius: 50%; background: var(--field); color: var(--muted); transition: background-color .15s, color .15s; }
.send-btn .ic { stroke-width: 2.4; }
.send-btn.is-ready { background: var(--jade); color: #fff; }

/* ===== Trả lời, cảm xúc, tin hệ thống ===== */
.sys-msg { display: flex; justify-content: center; margin: 12px 0 6px; padding: 0 24px; text-align: center; }
.sys-msg span { font-size: 12.5px; line-height: 1.4; color: var(--muted); }

.msg { touch-action: pan-y pinch-zoom; }
.msg.swipe-ready .bubble { box-shadow: 0 0 0 2px var(--turmeric); }
.msg.is-flash .bubble { animation: flash 1.5s ease-out; }
@keyframes flash { 0%, 35% { box-shadow: 0 0 0 3px var(--turmeric); } 100% { box-shadow: 0 0 0 3px transparent; } }

.quote {
  display: block; width: 100%; min-width: 140px; margin: 0 0 6px; padding: 6px 10px;
  border-radius: 12px; border-left: 3px solid var(--jade-ink);
  background: color-mix(in srgb, var(--theirs), var(--ink) 7%); color: var(--ink);
  text-align: left; font-size: 13.5px; line-height: 1.35; white-space: normal;
}
.msg.mine .quote { background: rgba(255, 255, 255, .16); border-left-color: rgba(255, 255, 255, .8); color: #fff; }
.bubble.has-image .quote { margin: 0 0 4px; }
.quote-name { display: block; font-size: 12.5px; font-weight: 600; }
.quote-text { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; opacity: .85; }
.quote.is-gone .quote-text { opacity: .6; }

.reacts {
  position: relative; z-index: 1; display: inline-flex; align-items: center; gap: 3px;
  margin-top: -8px; padding: 2px 7px; border-radius: 999px;
  background: var(--surface); box-shadow: 0 0 0 1px var(--line), 0 1px 3px rgba(0, 0, 0, .08);
  font-size: 13px; line-height: 1.3;
}
.msg.mine .reacts { margin-right: 10px; }
.msg.theirs .reacts { margin-left: 10px; }
.reacts.is-mine { box-shadow: 0 0 0 1.5px var(--jade-ink), 0 1px 3px rgba(0, 0, 0, .08); }
.reacts-count { font-size: 12px; font-weight: 600; color: var(--muted); }

.react-bar { display: flex; gap: 2px; padding: 2px 2px 6px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
.react-btn { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; font-size: 24px; line-height: 1; transition: transform .12s, background-color .12s; }
.react-btn:hover, .react-btn:focus-visible { transform: scale(1.15); background: var(--field); }
.react-btn.is-on { background: var(--jade-wash); }
.menu-title { padding: 6px 10px 8px; font-size: 14px; font-weight: 600; }
.reactor { display: flex; align-items: center; gap: 10px; min-width: 220px; padding: 6px 10px; }
.reactor-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reactor-emoji { font-size: 20px; }

.reply-bar { display: flex; align-items: center; gap: 6px; padding: 8px 6px 0 16px; }
.reply-bar-main { flex: 1; min-width: 0; display: grid; padding-left: 10px; border-left: 3px solid var(--jade-ink); }
.reply-bar-title { font-size: 12.5px; color: var(--muted); }
.reply-bar-title strong { font-weight: 600; color: var(--ink); }
.reply-bar-text { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-bar .icon-btn { width: 36px; height: 36px; }

.seen.readers { gap: 0; }
.seen.readers .avatar { box-shadow: 0 0 0 1.5px var(--bg); }
.seen.readers .avatar + .avatar { margin-left: -3px; }
.seen.readers > span:not(.avatar) { margin-left: 5px; }

/* ===== Nhóm chat riêng ===== */
.avatar.is-team { border-radius: 30%; }
.chat-title.is-link { cursor: pointer; }
.chat-title.is-link:hover h2 { text-decoration: underline; text-underline-offset: 3px; }
.new-group-row { margin-bottom: -8px; }
.person.pick .person-main, .member-row .person-main { flex: 1; }
.person.pick .check {
  flex: none; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  box-shadow: inset 0 0 0 2px var(--line); color: transparent; transition: background-color .12s, box-shadow .12s;
}
.person.pick .check .ic { width: 16px; height: 16px; stroke-width: 3; }
.person.pick[aria-pressed="true"] .check { background: var(--jade); box-shadow: none; color: #fff; }
.sheet-foot { padding: 12px 20px calc(12px + var(--safe-bottom)); border-top: 1px solid var(--line); }
.panel-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.group-add { display: grid; gap: 10px; padding: 12px; border-radius: 16px; background: var(--field); }
.group-add .search-input { background: var(--surface); }
.member-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.member-name { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-weight: 600; }
.tag-me { background: var(--field); color: var(--muted); }
.profile-title { margin-top: 10px; font-size: 20px; font-weight: 800; letter-spacing: -0.015em; text-align: center; }

/* ===== Bảng trượt (cài đặt, admin, tin nhắn mới) ===== */
.sheet-layer { position: fixed; inset: 0; z-index: 30; display: grid; }
.sheet-backdrop { position: absolute; inset: 0; background: var(--overlay); opacity: 0; transition: opacity .2s; }
.sheet {
  position: relative; align-self: end; justify-self: center;
  width: 100%; max-height: calc(var(--app-h, 100dvh) - var(--safe-top) - 16px);
  display: flex; flex-direction: column;
  background: var(--surface); border-radius: 20px 20px 0 0; outline: none;
  transform: translateY(28px); opacity: 0; transition: transform .22s ease, opacity .22s ease;
}
.sheet-layer.open .sheet-backdrop { opacity: 1; }
.sheet-layer.open .sheet { transform: none; opacity: 1; }
@media (min-width: 860px) {
  .sheet { align-self: center; width: min(520px, calc(100vw - 48px)); max-height: min(780px, calc(100vh - 64px)); border-radius: 20px; }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 10px 12px 20px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { font-size: 20px; font-weight: 800; letter-spacing: -0.015em; }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; padding: 18px 20px calc(28px + var(--safe-bottom)); display: grid; gap: 22px; align-content: start; }
.page-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 6px 20px 32px; display: grid; gap: 22px; align-content: start; }
.panel { display: grid; gap: 12px; }
.sheet-body > .panel + .panel, .sheet-body > .profile + .panel,
.page-body > .panel + .panel, .page-body > .profile + .panel, .page-body > .credential + .panel { border-top: 1px solid var(--line); padding-top: 20px; }
.panel h3 { font-size: 16px; font-weight: 600; }

.profile { display: grid; justify-items: center; gap: 4px; }
.avatar-edit { position: relative; border-radius: 50%; }
.avatar-edit-tag {
  position: absolute; left: 50%; bottom: -8px; transform: translateX(-50%);
  padding: 3px 10px; border-radius: 999px; background: var(--ink); color: var(--surface);
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.avatar-edit.busy .avatar { opacity: .45; }
.profile-username { margin-top: 14px; color: var(--muted); font-size: 14px; }
.inline { display: flex; gap: 8px; }
.inline input { flex: 1; min-width: 0; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 15px; cursor: pointer; }
.switch {
  appearance: none; -webkit-appearance: none; position: relative; flex: none; margin: 0;
  width: 46px; height: 28px; border-radius: 14px; background: var(--line); cursor: pointer; transition: background-color .15s;
}
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .18s; }
.switch:checked { background: var(--jade); }
.switch:checked::after { transform: translateX(18px); }
.check-row { display: flex; align-items: center; gap: 10px; font-size: 15px; cursor: pointer; }
.check-row input { width: 20px; height: 20px; margin: 0; accent-color: var(--jade); }

.people-list, .admin-list { list-style: none; margin: 0; padding: 0; display: grid; }
.person { width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-radius: 14px; text-align: left; }
.person:hover { background: var(--field); }
.person-main { display: grid; min-width: 0; }
.person-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-sub { font-size: 13px; color: var(--muted); }
.person-sub.is-online { color: var(--jade-ink); }
.people-empty { color: var(--muted); padding: 16px 8px; font-size: 14px; }

.admin-row { display: flex; gap: 12px; padding: 14px 0; border-top: 1px solid var(--line); }
.admin-row:first-child { border-top: 0; padding-top: 4px; }
.admin-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.admin-name { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-weight: 600; }
.admin-sub { font-size: 13px; color: var(--muted); }
.admin-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag { font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.tag-admin { background: var(--jade-wash); color: var(--jade-ink); }
.tag-locked { background: var(--danger-wash); color: var(--danger); }
.tag-pending { background: var(--turmeric-wash); color: var(--turmeric-ink); }

.credential { padding: 16px; border-radius: 16px; background: var(--turmeric-wash); display: grid; gap: 10px; }
.credential-title { font-weight: 600; }
.credential-text { margin: 0; padding: 12px 14px; border-radius: 12px; background: var(--surface); font: inherit; font-size: 14.5px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; user-select: all; -webkit-user-select: all; }

/* ===== Xem ảnh, menu tin nhắn, thông báo nhỏ ===== */
.lightbox { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom)); background: rgba(5, 10, 8, .92); }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; }
.lightbox-actions { position: absolute; top: calc(10px + var(--safe-top)); right: 10px; display: flex; gap: 8px; }
.lightbox .icon-btn { color: #fff; background: rgba(255, 255, 255, .14); }
.lightbox .icon-btn:hover { background: rgba(255, 255, 255, .24); }

.menu-layer { position: fixed; inset: 0; z-index: 40; }
.menu { position: fixed; min-width: 180px; padding: 6px; border-radius: 14px; background: var(--surface); display: grid; box-shadow: 0 12px 36px rgba(10, 25, 20, .22), 0 0 0 1px var(--line); }
.menu-item { padding: 11px 12px; border-radius: 10px; text-align: left; font-weight: 600; font-size: 15px; }
.menu-item:hover, .menu-item:focus-visible { background: var(--field); }
.menu-item.is-danger { color: var(--danger); }

.toasts { position: fixed; z-index: 60; left: 50%; top: calc(10px + var(--safe-top)); transform: translateX(-50%); width: min(420px, calc(100vw - 24px)); display: grid; gap: 8px; pointer-events: none; }
@media (min-width: 860px) { .toasts { left: auto; right: 20px; top: 20px; transform: none; width: 360px; } }
.toast {
  pointer-events: auto; padding: 12px 16px; border-radius: 14px;
  background: var(--toast); color: var(--toast-ink);
  font-size: 14.5px; text-align: left;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .2); animation: toast-in .2s ease-out;
}
.toast.is-leaving { opacity: 0; transform: translateY(-6px); transition: opacity .2s, transform .2s; }
.toast-msg { display: flex; align-items: center; gap: 10px; width: 100%; }
.toast-text { display: grid; min-width: 0; }
.toast-text strong { font-weight: 600; }
.toast-text span { opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

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

/* ===== Trang trong cột trái + thanh điều hướng dưới ===== */
.tab-page { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.tab-page[hidden] { display: none !important; }
.tabbar {
  flex: none; display: flex; align-items: stretch;
  border-top: 1px solid var(--line); background: var(--surface);
  padding: 0 4px var(--safe-bottom);
}
.tab {
  flex: 1; min-width: 0; min-height: 58px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: 11.5px; font-weight: 600;
  border-radius: 12px; transition: color .15s;
}
.tab:hover { color: var(--ink-2); }
.tab[aria-current="page"] { color: var(--jade-ink); }
.tab-icon { position: relative; display: grid; place-items: center; width: 30px; height: 28px; }
.tab-icon .ic { width: 25px; height: 25px; }
.tab[aria-current="page"] .tab-icon .ic { stroke-width: 2.3; }
.tab[aria-current="page"] #tab-avatar { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--jade-ink); }
.tab-label { line-height: 1.1; }
.tab-badge {
  position: absolute; top: -3px; left: 17px;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  display: grid; place-items: center;
  background: var(--turmeric); color: #14201C; box-shadow: 0 0 0 2px var(--surface);
  font-size: 11px; font-weight: 800; line-height: 1;
}
/* Điện thoại: đang gõ phím thì ẩn thanh dưới cho rộng chỗ */
body.typing .tabbar { display: none; }

/* Chuyển mục trong trang Quản trị */
.seg { display: flex; gap: 4px; margin: 2px 16px 10px; padding: 4px; border-radius: 14px; background: var(--field); }
.seg-btn { flex: 1; min-height: 38px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg-btn[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }

.field select {
  width: 100%; min-height: 46px; padding: 0 12px; font: inherit; font-size: 16px; color: var(--ink);
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface); outline: none;
}
.field select:focus { border-color: var(--jade-ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--jade-ink), transparent 80%); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn .ic { width: 18px; height: 18px; }

/* ===== Lưu trên máy ===== */
.local-stats { font-size: 14px; color: var(--ink-2); }
.local-stats:empty { display: none; }
.switch-row input:disabled { opacity: .45; cursor: default; }

/* Ảnh đã bị dọn khỏi máy chủ hoặc không tải được */
.img-gone {
  display: flex; align-items: center; gap: 8px; width: 220px; max-width: 100%;
  padding: 14px 12px; border-radius: 16px; font-size: 13.5px; line-height: 1.35; text-align: left;
  background: color-mix(in srgb, var(--bg), var(--ink) 6%); color: var(--muted);
}
.msg.mine .bubble.has-image .img-gone { background: rgba(255, 255, 255, .16); color: rgba(255, 255, 255, .85); }
.img-gone .ic { width: 20px; height: 20px; flex: none; }
button.img-gone { cursor: pointer; }

/* ===== Bộ nhớ máy chủ (Quản trị) ===== */
.storage-figure { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; }
.storage-percent { font-size: 48px; font-weight: 800; line-height: 1; letter-spacing: -0.03em; }
.storage-amount { color: var(--ink-2); font-size: 14.5px; }
.meter {
  --fill: var(--meter-good); --track: var(--meter-good-track);
  position: relative; height: 14px; margin: 14px 0 4px; border-radius: 7px; background: var(--track);
}
.meter.is-warn { --fill: var(--meter-warn); --track: var(--meter-warn-track); }
.meter.is-crit { --fill: var(--meter-crit); --track: var(--meter-crit-track); }
.meter-fill { position: absolute; inset: 0 auto 0 0; min-width: 4px; border-radius: 7px; background: var(--fill); transition: width .4s ease; }
.meter-tick { position: absolute; top: -4px; bottom: -4px; width: 2px; margin-left: -1px; border-radius: 1px; background: var(--ink-2); }
.meter-scale { position: relative; height: 18px; font-size: 12px; color: var(--muted); }
.meter-scale span { position: absolute; top: 2px; transform: translateX(-50%); white-space: nowrap; }
.meter-scale span:first-child { transform: none; }
.storage-state { display: flex; align-items: flex-start; gap: 8px; font-size: 14.5px; font-weight: 600; color: var(--ink); }
.storage-state .ic { width: 20px; height: 20px; flex: none; margin-top: 1px; }
.storage-state.is-good .ic { color: var(--meter-good); }
.storage-state.is-warn .ic { color: var(--meter-warn); }
.storage-state.is-crit .ic { color: var(--meter-crit); }
.storage-table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.storage-table th { text-align: left; font-weight: 400; color: var(--ink-2); padding: 9px 0; }
.storage-table td { text-align: right; padding: 9px 0 9px 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.storage-table td.num-muted { color: var(--muted); }
.storage-table tr + tr > * { border-top: 1px solid var(--line); }
.storage-table tfoot th, .storage-table tfoot td { font-weight: 600; color: var(--ink); }
.storage-note { font-size: 13.5px; color: var(--muted); }
.clean-preview { padding: 12px 14px; border-radius: 12px; background: var(--field); font-size: 14.5px; }
.clean-preview strong { font-weight: 600; }
.storage-alert { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 14px; font-size: 14px; background: var(--meter-warn-track); color: var(--ink); }
.storage-alert.is-crit { background: var(--meter-crit-track); }
.storage-alert .ic { width: 20px; height: 20px; flex: none; color: var(--meter-warn); }
.storage-alert.is-crit .ic { color: var(--meter-crit); }
.storage-alert button { margin-left: auto; font-weight: 600; color: var(--jade-ink); white-space: nowrap; }
#me-name { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
#me-name + .profile-username { margin-top: 2px; }
.chat-empty.is-quiet p { visibility: hidden; }
