/* ============ LTK Chat — giao diện nền ============ */

/* Bộ màu sáng (mặc định) */
:root {
  --bg: #f2f4f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --surface-3: #e5e8ed;
  --hover: #f3f5f8;
  --active: #e7efff;
  --border: #e2e5ea;
  --text: #111418;
  --text-2: #5c6470;
  --text-3: #6b7380;
  --accent: #2563eb;
  --accent-hover: #1d4fd8;
  --accent-text: #1d4fd8;
  --accent-soft: #e6eeff;
  --on-accent: #ffffff;
  --danger: #d42a2a;
  --danger-soft: #fdecec;
  --success: #15803d;
  --call-green: #16a34a;
  --badge: #d92b2b;
  --online: #22a559;
  --chat-bg: #e8ecf2;
  --bubble-me: #2563eb;
  --bubble-me-text: #ffffff;
  --bubble-me-sub: #eef3ff;
  --bubble-other: #ffffff;
  --bubble-other-text: #111418;
  --shadow: 0 6px 24px rgba(17, 20, 24, .12);
  --shadow-sm: 0 1px 3px rgba(17, 20, 24, .1);
  --scrim: rgba(10, 12, 16, .45);
  --skeleton: #e6e9ee;
  --radius: 14px;
  --nav-h: 58px;
  --top-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

/* Bộ màu tối */
[data-theme="dark"] {
  --bg: #1a1a1a;
  --surface: #242424;
  --surface-2: #2e2e2e;
  --surface-3: #383838;
  --hover: #2b2b2b;
  --active: #233251;
  --border: #333333;
  --text: #e8e8e8;
  --text-2: #9a9a9a;
  --text-3: #9a9a9a;
  --accent: #2f66e0;
  --accent-hover: #3d74f0;
  --accent-text: #7fa8ff;
  --accent-soft: #22304d;
  --on-accent: #ffffff;
  --danger: #ff6b6b;
  --danger-soft: #3a2224;
  --success: #4ade80;
  --call-green: #16a34a;
  --badge: #d92b2b;
  --online: #34c46b;
  --chat-bg: #1a1a1a;
  --bubble-me: #2b5fd4;
  --bubble-me-text: #ffffff;
  --bubble-me-sub: #eef3ff;
  --bubble-other: #2c2c2c;
  --bubble-other-text: #e8e8e8;
  --shadow: 0 8px 28px rgba(0, 0, 0, .5);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .5);
  --scrim: rgba(0, 0, 0, .6);
  --skeleton: #2e2e2e;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body, #app { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  overscroll-behavior: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: default; opacity: .55; }
a { color: var(--accent-text); }
img { display: block; max-width: 100%; }
h1, h2, h3, p { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ic { flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hidden { display: none !important; }
.muted { color: var(--text-2); }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* ---------- Nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 18px; border-radius: 10px; font-weight: 600;
  transition: background .15s, transform .05s;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-ghost { background: var(--surface-2); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); }
.btn-soft { background: var(--accent-soft); color: var(--accent-text); }
.btn-danger { background: var(--danger); color: #fff; }
[data-theme="dark"] .btn-danger { background: #c62828; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13.5px; border-radius: 8px; }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%;
  color: var(--text-2); transition: background .15s, color .15s; position: relative; flex: none;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.accent { color: var(--accent-text); }

/* ---------- Form ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13.5px; font-weight: 600; color: var(--text-2); }
.input, .textarea {
  width: 100%; height: 44px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.textarea { height: auto; padding: 10px 14px; resize: vertical; min-height: 80px; }
.input:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.form-error { color: var(--danger); font-size: 14px; min-height: 1.2em; }
.searchbox {
  flex: 1; display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px;
  background: var(--surface-2); border-radius: 10px; color: var(--text-2); min-width: 0;
}
.searchbox input { flex: 1; border: 0; outline: 0; background: none; min-width: 0; height: 100%; }
.searchbox:focus-within { box-shadow: 0 0 0 2px var(--accent-soft); }

/* ---------- Avatar ---------- */
.avatar { position: relative; width: var(--s); height: var(--s); flex: none; border-radius: 50%; }
.avatar > img, .avatar > span {
  width: 100%; height: 100%; border-radius: 50%; object-fit: cover; background: var(--surface-3);
}
.avatar > span {
  display: grid; place-items: center; color: #fff; font-weight: 600;
  font-size: calc(var(--s) * .38); letter-spacing: .02em; user-select: none;
}
.dot-online {
  position: absolute; right: 1px; bottom: 1px; width: 26%; height: 26%; min-width: 10px; min-height: 10px;
  max-width: 14px; max-height: 14px; border-radius: 50%; background: var(--online); border: 2px solid var(--surface);
}
.avatar-group { display: grid; gap: 2px; border-radius: 50%; overflow: hidden; background: var(--surface-3); }
.avatar-group.n2 { grid-template-columns: 1fr 1fr; align-items: center; }
.avatar-group.n3, .avatar-group.n4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.avatar-group .avatar { width: 100%; height: 100%; border-radius: 0; }
.avatar-group .avatar > img, .avatar-group .avatar > span { border-radius: 0; font-size: calc(var(--s) * .38); }
.avatar-group.n3 .avatar:first-child { grid-row: span 2; }

/* ---------- Splash ---------- */
.splash { height: 100%; display: grid; place-items: center; }
.splash img { width: 84px; height: 84px; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(.92); opacity: .75; } }

/* ---------- Đăng nhập / đăng ký ---------- */
.auth {
  height: 100%; overflow-y: auto; display: flex; align-items: center; justify-content: center;
  padding: 24px 16px calc(24px + var(--safe-b));
  background: radial-gradient(1200px 500px at 50% -10%, var(--accent-soft), transparent 70%), var(--bg);
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface); border-radius: 20px;
  padding: 28px 24px; box-shadow: var(--shadow);
}
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 22px; text-align: center; }
.auth-brand img { width: 64px; height: 64px; }
.auth-brand h1 { font-size: 24px; }
.auth-brand p { color: var(--text-2); font-size: 14px; }
.auth-note { margin: 16px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); color: var(--text-2); font-size: 13px; text-align: center; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 10px; padding: 4px; margin-bottom: 18px; }
.auth-tabs button { height: 36px; border-radius: 8px; font-weight: 600; color: var(--text-2); }
.auth-tabs button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 70px; }
.pw-toggle { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font-size: 13px; color: var(--accent-text); font-weight: 600; padding: 6px; }

/* ---------- Khung ứng dụng ---------- */
.shell { height: 100%; display: flex; }
.nav {
  display: flex; background: var(--surface); border-color: var(--border); z-index: 20;
}
.nav-btn {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--text-2); font-size: 11.5px; font-weight: 500;
}
.nav-btn.on { color: var(--accent-text); }
.nav-btn .badge { position: absolute; top: 4px; left: calc(50% + 6px); }
.nav-me { display: none; }
.badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--badge);
  color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}
.sidebar {
  display: flex; flex-direction: column; background: var(--surface); min-width: 0; position: relative;
}
.topbar {
  flex: none; height: var(--top-h); display: flex; align-items: center; gap: 4px; padding: 0 8px 0 12px;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.topbar-title { flex: 1; font-size: 18px; font-weight: 700; padding-left: 4px; }
.pane { flex: 1; overflow-y: auto; overscroll-behavior: contain; min-height: 0; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--chat-bg); position: relative; }
.welcome { margin: auto; text-align: center; padding: 24px; color: var(--text-2); max-width: 420px; }
.welcome img { width: 96px; height: 96px; margin: 0 auto 16px; opacity: .95; }
.welcome h2 { color: var(--text); font-size: 22px; margin-bottom: 8px; }

/* Di động: thanh điều hướng dưới, chat phủ toàn màn hình */
@media (max-width: 899px) {
  .shell { flex-direction: column; }
  .nav {
    order: 2; height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
    border-top: 1px solid var(--border);
  }
  .nav-btn { flex: 1; }
  .nav-logo { display: none; }
  .sidebar { flex: 1; min-height: 0; padding-top: var(--safe-t); }
  .main {
    position: fixed; inset: 0; z-index: 30; transform: translateX(100%);
    transition: transform .22s ease; visibility: hidden; padding-top: var(--safe-t);
  }
  .shell.chat-open .main { transform: none; visibility: visible; }
  .main .welcome { display: none; }
}

/* Máy tính: rail trái + 2 cột */
@media (min-width: 900px) {
  .nav { flex-direction: column; width: 68px; border-right: 1px solid var(--border); padding: 12px 0; gap: 6px; align-items: center; }
  .nav-logo { width: 40px; height: 40px; margin-bottom: 12px; }
  .nav-btn { width: 54px; height: 54px; border-radius: 12px; font-size: 10.5px; }
  .nav-btn:hover { background: var(--hover); }
  .nav-btn.on { background: var(--accent-soft); }
  .nav-btn .badge { top: 3px; left: auto; right: 3px; }
  .nav-spacer { flex: 1; }
  .sidebar { width: 360px; flex: none; border-right: 1px solid var(--border); }
}
@media (min-width: 1400px) { .sidebar { width: 400px; } }

/* ---------- Danh sách (list item) ---------- */
.list { list-style: none; margin: 0; padding: 4px 0; }
.item {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; cursor: pointer;
  position: relative; user-select: none; transition: background .12s;
}
.item:hover { background: var(--hover); }
.item.on { background: var(--active); }
.item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.item-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.item-title { font-weight: 600; flex: 1; }
.item-sub { color: var(--text-2); font-size: 14px; flex: 1; }
.item-meta { color: var(--text-2); font-size: 12.5px; flex: none; }
.item-actions { display: flex; gap: 6px; flex: none; }
.section-title {
  padding: 14px 16px 6px; font-size: 13px; font-weight: 700; color: var(--text-2);
  text-transform: uppercase; letter-spacing: .03em;
}
.empty { padding: 40px 24px; text-align: center; color: var(--text-2); }
.empty .ic { margin: 0 auto 10px; opacity: .6; }
.divider { height: 8px; background: var(--bg); }
.game-thumb { width: 64px; height: 64px; flex: none; border-radius: 12px; object-fit: cover; background: var(--surface-3); }
.game-desc { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- Trò chơi (tab Khám phá) ---------- */
.game-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; padding: 4px 16px 12px; }
.game-card {
  display: flex; flex-direction: row; align-items: center; gap: 12px; text-align: left; padding: 12px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); cursor: pointer; min-width: 0;
}
.game-card:hover { background: var(--hover); }
.game-card:active { transform: scale(.98); }
.game-card-ic {
  flex: none; width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-text); font-size: 28px; line-height: 1;
  box-shadow: inset 0 0 0 1px rgba(40, 70, 130, .06);
}
.game-card-ic-co { background: linear-gradient(145deg, #edf3ff, #e2ebff); color: #3764d8; }
.game-card-ic-bai { background: linear-gradient(145deg, #fff1ee, #ffe7e3); color: #d94f55; }
.game-card-ic-tritue { background: linear-gradient(145deg, #f2edff, #e8e1ff); color: #6849c8; }
.game-logo { width: 36px; height: 36px; display: block; overflow: visible; fill: none; stroke: currentColor; stroke-width: 1.25; stroke-linecap: round; stroke-linejoin: round; }
.game-logo .mark-board, .game-logo .mark-card { fill: #fff; stroke: #6680b3; stroke-width: 1.1; }
.game-logo .mark-card-back { fill: #d9e4ff; stroke: #6680b3; stroke-width: 1.1; }
.game-logo .mark-grid { stroke: #8293b5; stroke-width: .9; }
.game-logo .mark-primary { fill: #3764df; stroke: #244fca; }
.game-logo .mark-secondary, .game-logo .mark-blue { fill: #5d91f5; stroke: #3b70d8; }
.game-logo .mark-disc { fill: #fff7ee; stroke: #bd8c53; stroke-width: 1.3; }
.game-logo .mark-ring { stroke: #d05a4f; stroke-width: 1.1; }
.game-logo .mark-chinese { fill: #d34d4d; stroke: none; font: 700 9px/1 sans-serif; }
.game-logo .mark-red { fill: #ef7274; stroke: #d6535e; }
.game-logo .mark-yellow, .game-logo .mark-gold { fill: #f5c554; stroke: #d99c2c; }
.game-logo .mark-green { fill: #59c4a0; stroke: #339b7b; }
.game-logo .mark-light { fill: #fff; stroke: #d5deef; }
.game-logo .mark-wood { fill: #f3dfbd; stroke: #b88b4c; stroke-width: 1.2; }
.game-logo .mark-wood-line { stroke: #d0a66b; stroke-width: .8; }
.game-logo .mark-stone { fill: #435d91; stroke: #fff; stroke-width: .5; }
.game-logo .mark-card { stroke: #7586a5; }
.game-logo .mark-stroke { stroke: #42577d; stroke-width: 1.35; }
.game-logo .mark-light-stroke { stroke: #fff; stroke-width: 1.5; }
.game-logo .mark-black { fill: #303c55; stroke: #202b42; }
.game-logo .mark-sky { fill: #79b8ed; stroke: #4a91c9; }
.game-logo .mark-purple { fill: #9376e8; stroke: #765ac9; }
.game-logo .mark-wolf { fill: #66738d; stroke: #46536d; stroke-width: 1.15; }
.game-logo .mark-muzzle { fill: #f7f8fb; stroke: #46536d; }
.game-logo .mark-gold-stroke { stroke: #f1c24c; stroke-width: 1.6; }
/* Chữ trên lá bài (số, huy hiệu B/N), phỉnh Poker, các chi Mậu Binh */
.game-logo .mark-txt { stroke: none; font-family: system-ui, -apple-system, "Segoe UI", sans-serif; font-weight: 800; }
.game-logo .mark-txt-red { fill: #d6404a; }
.game-logo .mark-txt-black { fill: #26314a; }
.game-logo .mark-txt-blue { fill: #2f62d0; }
.game-logo .mark-txt-white { fill: #fff; }
.game-logo .mark-badge-red { fill: #e0464f; stroke: #fff; stroke-width: 1.2; }
.game-logo .mark-badge-blue { fill: #2f6fdc; stroke: #fff; stroke-width: 1.2; }
.game-logo .mark-chip { fill: #e2535b; stroke: #b5343e; }
.game-logo .mark-chip-notch { stroke: #fff; stroke-width: 2.6; stroke-linecap: butt; stroke-dasharray: 3.1416 3.1416; }
.game-logo .mark-row-gold { fill: #f5c554; stroke: #fff; stroke-width: .7; }
.game-logo .mark-row-blue { fill: #5d91f5; stroke: #fff; stroke-width: .7; }
.game-logo .mark-row-red { fill: #ef7274; stroke: #fff; stroke-width: .7; }
/* Mỗi game bài một màu nền riêng để dễ phân biệt */
.game-card-ic-g-baimau { background: linear-gradient(145deg, #fff6e0, #ffecc2); }
.game-card-ic-g-tala { background: linear-gradient(145deg, #e8f7ef, #d5f0e2); }
.game-card-ic-g-tienlen { background: linear-gradient(145deg, #fff0ef, #ffdedd); }
.game-card-ic-g-tienlen_mn { background: linear-gradient(145deg, #ebf2ff, #dae6ff); }
.game-card-ic-g-maubinh { background: linear-gradient(145deg, #f4efff, #e6dcff); }
.game-card-ic-g-poker { background: linear-gradient(145deg, #2f3a52, #1f2739); }
.game-card-ic-g-solitaire { background: linear-gradient(145deg, #e3f5f2, #cdebe6); }
.game-card-text { display: flex; flex: 1; flex-direction: column; gap: 3px; min-width: 0; }
.game-card-name { font-weight: 700; font-size: 15.5px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 64px; }
.game-card:not(:has(.game-card-live)) .game-card-name { padding-right: 0; }
.game-card-desc { font-size: 13px; color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.game-card { position: relative; }
.game-card-live {
  position: absolute; top: 10px; right: 10px; padding: 2px 8px; border-radius: 99px;
  background: var(--online); color: #fff; font-size: 11px; font-weight: 700;
}
/* Game phủ toàn bộ vùng nội dung; thanh điều hướng của chat (dưới / rail trái) vẫn hiện và là menu duy nhất */
.game-overlay {
  position: fixed; top: 0; left: 0; right: 0; z-index: 90; height: calc(100dvh - var(--nav-h) - var(--safe-b));
  display: flex; flex-direction: column; background: var(--bg); overflow: hidden;
}
@media (min-width: 900px) {
  .game-overlay { left: 68px; height: 100dvh; }
}
.game-overlay-bar {
  flex: none; display: flex; align-items: center; gap: 4px; height: calc(48px + var(--safe-t));
  padding: var(--safe-t) 8px 0 4px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.game-overlay-title { flex: 1; font-size: 16px; font-weight: 700; }
.game-frame { flex: 1; width: 100%; min-height: 0; border: 0; display: block; background: var(--bg); }
.game-frame.hidden { display: none; }
html.game-open, html.game-open body { overflow: hidden; }
html.game-open .nav-btn[data-tab="explore"] { color: var(--accent-text); }

/* ---------- Hộp thoại ---------- */
.modal-wrap {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  background: var(--scrim); opacity: 0; transition: opacity .18s; padding: 16px;
}
.modal-wrap.show { opacity: 1; }
.modal {
  width: 100%; max-width: 440px; max-height: min(86vh, 760px); display: flex; flex-direction: column;
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow);
  transform: translateY(12px) scale(.98); transition: transform .18s;
}
.modal-wrap.show .modal { transform: none; }
.modal-wide { max-width: 560px; }
.modal-sm .modal { max-width: 380px; }
.modal-head { display: flex; align-items: center; gap: 8px; padding: 12px 8px 12px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { flex: 1; font-size: 17px; }
.modal-body { padding: 16px 20px 20px; overflow-y: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.confirm-text { color: var(--text); line-height: 1.55; }
@media (max-width: 899px) {
  .modal-wrap:not(.modal-sm) { align-items: flex-end; padding: 0; }
  .modal-wrap:not(.modal-sm) .modal { max-width: none; border-radius: 18px 18px 0 0; max-height: 92vh; padding-bottom: var(--safe-b); transform: translateY(40px); }
  .modal-wrap.show:not(.modal-sm) .modal { transform: none; }
}

/* ---------- Menu ---------- */
.menu-wrap { position: fixed; inset: 0; z-index: 110; opacity: 0; transition: opacity .15s; }
.menu-wrap.show { opacity: 1; }
.menu { background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.menu-pop { position: fixed; min-width: 210px; border-radius: 12px; padding: 6px; border: 1px solid var(--border); }
.menu-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; border-radius: 18px 18px 0 0; padding: 8px 8px calc(8px + var(--safe-b));
  transform: translateY(30px); transition: transform .18s;
}
.menu-wrap:has(.menu-sheet) { background: var(--scrim); }
.menu-wrap.show .menu-sheet { transform: none; }
.menu-item {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 12px; border-radius: 8px;
  text-align: left; color: var(--text);
}
.menu-item:hover { background: var(--hover); }
.menu-item.danger { color: var(--danger); }
.menu-item .ic { color: var(--text-2); }
.menu-item.danger .ic { color: var(--danger); }

/* ---------- Toast ---------- */
#toast-root {
  position: fixed; left: 50%; top: calc(16px + var(--safe-t)); transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none;
  width: max-content; max-width: calc(100vw - 32px);
}
.toast {
  padding: 10px 16px; border-radius: 10px; background: #1f2937; color: #fff; font-size: 14px;
  box-shadow: var(--shadow); opacity: 0; transform: translateY(-8px); transition: all .2s;
}
[data-theme="dark"] .toast { background: #3a3a3a; }
.toast.show { opacity: 1; transform: none; }
.toast-error { background: #b42318; }
[data-theme="dark"] .toast-error { background: #b42318; }
.toast-success { background: #15703a; }
[data-theme="dark"] .toast-success { background: #15703a; }

/* ---------- Spinner ---------- */
.spinner {
  display: inline-block; width: var(--s); height: var(--s); border-radius: 50%;
  border: 3px solid var(--surface-3); border-top-color: var(--accent); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.center-pad { display: grid; place-items: center; padding: 32px; }

/* ---------- Trang cá nhân ---------- */
.profile-head { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 28px 16px 20px; text-align: center; }
.profile-head h2 { font-size: 20px; }
.profile-head .bio { color: var(--text-2); font-size: 14px; max-width: 320px; white-space: pre-wrap; word-break: break-word; }
.avatar-edit { position: relative; }
.avatar-edit .cam {
  position: absolute; right: 0; bottom: 0; width: 34px; height: 34px; border-radius: 50%;
  background: var(--surface-2); border: 2px solid var(--surface); display: grid; place-items: center; color: var(--text);
}
.setting {
  display: flex; align-items: center; gap: 14px; padding: 13px 16px; width: 100%; text-align: left;
  cursor: pointer; color: var(--text);
}
.setting:hover { background: var(--hover); }
.setting .ic { color: var(--text-2); }
.setting > span { flex: 1; }
.setting small { color: var(--text-2); font-size: 13px; }
.setting.danger, .setting.danger .ic { color: var(--danger); }
/* Công tắc bật / tắt (Chế độ tối) */
.switch {
  position: relative; flex: none; width: 46px; height: 28px; border-radius: 999px;
  background: var(--border); transition: background 0.2s;
}
.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, 0.3); transition: transform 0.2s;
}
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(18px); }

/* Skeleton */
.sk { background: var(--skeleton); border-radius: 6px; animation: skp 1.2s ease-in-out infinite; }
@keyframes skp { 50% { opacity: .55; } }

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

/* ---------- Danh bạ & hộp thoại ---------- */
.subtabs { display: flex; gap: 4px; padding: 8px 12px 4px; position: sticky; top: 0; background: var(--surface); z-index: 2; }
.subtabs button { flex: 1; height: 36px; border-radius: 8px; font-weight: 600; color: var(--text-2); }
.subtabs button.on { background: var(--accent-soft); color: var(--accent-text); }
.round-ic {
  width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--accent-soft); color: var(--accent-text); overflow: hidden;
}
.round-ic.big { width: 56px; height: 56px; cursor: pointer; }
.round-ic img { width: 100%; height: 100%; object-fit: cover; }
.letter { padding: 10px 16px 2px; font-weight: 700; color: var(--text-2); font-size: 13px; list-style: none; }
.tag { font-size: 13px; padding: 4px 10px; border-radius: 99px; background: var(--surface-2); color: var(--text-2); font-weight: 600; }
.user-card { display: flex; align-items: center; gap: 12px; padding: 14px 0 4px; flex-wrap: wrap; }
.user-card .item-main b { font-size: 16px; }
.user-card-actions { display: flex; gap: 8px; width: 100%; padding-left: 68px; }
.row-input { display: flex; gap: 8px; }
.row-input .input { flex: 1; }
.picker { display: flex; flex-direction: column; gap: 8px; }
.picker .searchbox { flex: none; }
.picker-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.picker-chips:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 8px 3px 3px; border-radius: 99px;
  background: var(--accent-soft); color: var(--accent-text); font-size: 13.5px; font-weight: 600;
}
.picker-list { max-height: 46vh; overflow-y: auto; margin: 0 -20px; }
.picker-list .item { padding: 8px 20px; }
.check {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--border); display: grid; place-items: center; color: transparent; flex: none;
}
.check.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.group-name-row { display: flex; align-items: center; gap: 12px; }
.group-name-row .input { flex: 1; }
.quick-row { display: flex; justify-content: center; gap: 6px; padding: 4px 8px 16px; flex-wrap: wrap; }
.quick-row button {
  display: flex; flex-direction: column; align-items: center; gap: 6px; width: 92px; font-size: 12.5px; color: var(--text-2); text-align: center;
}
.quick-row button .ic { width: 42px; height: 42px; padding: 10px; border-radius: 50%; background: var(--surface-2); color: var(--text); }
.profile-actions { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.profile-head h2 { display: flex; align-items: center; gap: 4px; }
.menu-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.role-owner { color: #b45309; display: inline-flex; align-items: center; gap: 3px; font-size: 12.5px; }
.role-deputy { color: var(--accent-text); display: inline-flex; align-items: center; gap: 3px; font-size: 12.5px; }
[data-theme="dark"] .role-owner { color: #f5b544; }

/* Danh sách hội thoại */
.conv .item-title { font-weight: 500; }
.conv.unread .item-title { font-weight: 700; }
.conv.unread .item-sub { color: var(--text); font-weight: 600; }
.conv .item-row + .item-row { margin-top: 2px; }
.flag { color: var(--text-3); display: inline-flex; }
.badge-muted { background: var(--text-3); }
.live-call { color: var(--call-green); display: inline-flex; animation: pulse 1.6s infinite; }

/* Gợi ý bật thông báo */
.push-banner {
  display: flex; align-items: center; gap: 10px; margin: 8px 10px 4px; padding: 10px 6px 10px 12px;
  border-radius: 12px; background: var(--accent-soft); color: var(--text); font-size: 13.5px;
}
.push-banner > .ic { color: var(--accent-text); }
.push-banner span { flex: 1; }

/* Mã QR */
.qr-card { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.qr-box { padding: 10px; background: #fff; border-radius: 14px; box-shadow: var(--shadow-sm); margin: 6px 0; }
.qr-box svg { display: block; width: 220px; height: 220px; }
.af-qr { display: flex; gap: 8px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.scan-box { position: relative; border-radius: 14px; overflow: hidden; background: #000; aspect-ratio: 1; }
.scan-box video { width: 100%; height: 100%; object-fit: cover; }
.scan-frame { position: absolute; inset: 18%; border: 3px solid rgba(255, 255, 255, .9); border-radius: 18px; box-shadow: 0 0 0 999px rgba(0, 0, 0, .35); }
