:root,
[data-theme='dark-purple'] {
  color-scheme: dark;
  --bg: #0a0a0f;
  --surface: #12121a;
  --surface-2: #1a1a26;
  --border: #2a2a3a;
  --text: #e8e8f0;
  --text-muted: #8888a0;
  --text-on-accent: #ffffff;
  --accent: #6c5ce7;
  --accent-hover: #7d6ff0;
  --logo-from: #6c5ce7;
  --logo-to: #a29bfe;
  --online: #00d68f;
  --sleeping: #ffaa00;
  --offline: #555570;
  --danger: #ff6b6b;
  --radius: 12px;
}

[data-theme='dark-emerald'] {
  color-scheme: dark;
  --bg: #071210;
  --surface: #0f1f1a;
  --surface-2: #152a22;
  --border: #1f3d32;
  --text: #e0f5ee;
  --text-muted: #7a9e92;
  --text-on-accent: #ffffff;
  --accent: #00b894;
  --accent-hover: #00d1a7;
  --logo-from: #00b894;
  --logo-to: #55efc4;
  --online: #00cec9;
  --sleeping: #fdcb6e;
  --offline: #4a6b60;
  --danger: #e17055;
}

[data-theme='dark-ocean'] {
  color-scheme: dark;
  --bg: #060d14;
  --surface: #0c1824;
  --surface-2: #122233;
  --border: #1e3a5f;
  --text: #e3f0ff;
  --text-muted: #7a9bb8;
  --text-on-accent: #ffffff;
  --accent: #0984e3;
  --accent-hover: #1e9bff;
  --logo-from: #0984e3;
  --logo-to: #74b9ff;
  --online: #00b894;
  --sleeping: #fdcb6e;
  --offline: #4a6278;
  --danger: #d63031;
}

[data-theme='dark-rose'] {
  color-scheme: dark;
  --bg: #10080d;
  --surface: #1a1018;
  --surface-2: #261a24;
  --border: #3d2a38;
  --text: #f5e8f0;
  --text-muted: #a08098;
  --text-on-accent: #ffffff;
  --accent: #e84393;
  --accent-hover: #f368b5;
  --logo-from: #e84393;
  --logo-to: #fd79a8;
  --online: #00b894;
  --sleeping: #fdcb6e;
  --offline: #6b4f62;
  --danger: #d63031;
}

[data-theme='midnight-gold'] {
  color-scheme: dark;
  --bg: #0c0a08;
  --surface: #16120e;
  --surface-2: #221c16;
  --border: #3d3428;
  --text: #f5efe6;
  --text-muted: #a89880;
  --text-on-accent: #1a1208;
  --accent: #fdcb6e;
  --accent-hover: #ffe08a;
  --logo-from: #fdcb6e;
  --logo-to: #f39c12;
  --online: #00b894;
  --sleeping: #e17055;
  --offline: #6b5f50;
  --danger: #e74c3c;
}

[data-theme='neon-cyber'] {
  color-scheme: dark;
  --bg: #050508;
  --surface: #0d0d14;
  --surface-2: #141420;
  --border: #2a2a40;
  --text: #e8fff8;
  --text-muted: #8a9aa8;
  --text-on-accent: #031a16;
  --accent: #00f5d4;
  --accent-hover: #33f9de;
  --logo-from: #00f5d4;
  --logo-to: #7b2ff7;
  --online: #00f5d4;
  --sleeping: #fee440;
  --offline: #4a4a60;
  --danger: #ff006e;
}

[data-theme='synthwave'] {
  color-scheme: dark;
  --bg: #0f0820;
  --surface: #180f30;
  --surface-2: #221540;
  --border: #3d2a60;
  --text: #f0e6ff;
  --text-muted: #9a80c0;
  --text-on-accent: #ffffff;
  --accent: #ff6bcb;
  --accent-hover: #ff8ad8;
  --logo-from: #ff6bcb;
  --logo-to: #7b2ff7;
  --online: #00f5d4;
  --sleeping: #fee440;
  --offline: #5a4a78;
  --danger: #ff006e;
}

[data-theme='classic-irc'] {
  color-scheme: dark;
  --bg: #000000;
  --surface: #0a0a0a;
  --surface-2: #111111;
  --border: #333333;
  --text: #00ff00;
  --text-muted: #00aa00;
  --text-on-accent: #000000;
  --accent: #00cc00;
  --accent-hover: #00ff00;
  --logo-from: #00ff00;
  --logo-to: #00aa00;
  --online: #00ff00;
  --sleeping: #ffff00;
  --offline: #006600;
  --danger: #ff0000;
  --radius: 4px;
}

[data-theme='light-clean'] {
  color-scheme: light;
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #eef0f5;
  --border: #d8dce6;
  --text: #1a1d26;
  --text-muted: #5c6370;
  --text-on-accent: #ffffff;
  --accent: #5c6bc0;
  --accent-hover: #4a5ab5;
  --logo-from: #5c6bc0;
  --logo-to: #7986cb;
  --online: #059669;
  --sleeping: #d97706;
  --offline: #9ca3af;
  --danger: #dc2626;
}

[data-theme='light-warm'] {
  color-scheme: light;
  --bg: #faf6f2;
  --surface: #ffffff;
  --surface-2: #f5efe8;
  --border: #e8ddd2;
  --text: #2d2418;
  --text-muted: #6b5c4a;
  --text-on-accent: #ffffff;
  --accent: #c45a3a;
  --accent-hover: #a8482e;
  --logo-from: #c45a3a;
  --logo-to: #e17055;
  --online: #0d9488;
  --sleeping: #ca8a04;
  --offline: #a89888;
  --danger: #b91c1c;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/*
 * Mobile layout — mọi khung smartphone thế giới (DOCS/32 + DOCS/00).
 * Không CSS từng model: cover bằng token + breakpoint dải width.
 * QA bắt buộc: 280–320, 360, 390, 393, 412, 430–440, landscape, tablet, desktop.
 */
:root {
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --touch-min: 44px;
  --phone-gutter: clamp(0.5rem, 2.8vw, 1rem);
  --phone-header-pad-y: 0.65rem;
  --phone-header-pad-x: var(--phone-gutter);
  --app-height: 100dvh;
  --app-top: 0px;
}

html {
  height: 100%;
  width: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html,
body {
  height: 100%;
  max-width: 100%;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  min-height: var(--app-height);
  overflow-x: hidden;
}

html.chat-mode {
  overflow: hidden;
  height: 100%;
  overscroll-behavior: none;
}

body:has(.chat-layout),
body.chat-mode {
  overflow: hidden;
  /* Full layout viewport backdrop — #app tracks visualViewport separately */
  height: 100%;
  max-height: none;
  /* Khóa rubber-band / kéo cả trang — layout không “chạy” theo ngón tay */
  position: fixed;
  inset: 0;
  width: 100%;
  overscroll-behavior: none;
  touch-action: manipulation;
}

#app.chat-mode {
  position: fixed;
  left: 0;
  right: 0;
  /* Follow visualViewport — fixes iOS “composer pushed to top + black gap” */
  top: var(--app-top, 0px);
  width: 100%;
  height: var(--app-height);
  max-height: var(--app-height);
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-width: 100%;
  padding-left: var(--sal);
  padding-right: var(--sar);
  box-sizing: border-box;
  overscroll-behavior: none;
}

#app {
  width: 100%;
  max-width: 100%;
  min-height: var(--app-height);
}

#app.chat-mode .chat-layout {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  width: 100%;
  overflow: hidden;
}

/* Login */
.login-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  min-height: var(--app-height);
  padding:
    max(1rem, var(--sat))
    max(1.25rem, var(--sar))
    max(1.5rem, var(--sab))
    max(1.25rem, var(--sal));
  gap: 1.5rem;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

.login-topbar {
  width: 100%;
  max-width: 960px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.65rem;
  min-height: 2.5rem;
  z-index: 20;
}

.btn-pwa-topbar {
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 500;
  background: var(--surface-2);
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.btn-pwa-topbar:hover {
  background: var(--accent);
  color: var(--text-on-accent);
}

.login-footer-install {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
  text-decoration: none;
}

.login-footer-install:hover {
  color: var(--accent);
  text-decoration: underline;
}

.login-topbar .lang-picker {
  margin: 0;
}

.login-topbar .lang-menu {
  right: 0;
  left: auto;
}

.login-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.75rem;
  width: 100%;
}

.login-footer {
  width: 100%;
  max-width: 960px;
  text-align: center;
  padding-top: 0.5rem;
}

.login-footer-links {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem 0.65rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.login-footer-links a {
  color: var(--text-muted);
  text-decoration: none;
}

.login-footer-links a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.login-footer-copy {
  margin: 0.55rem 0 0;
  font-size: 0.72rem;
  color: var(--text-muted);
  opacity: 0.75;
}

.logo {
  text-align: center;
}

.logo-mark {
  display: block;
  margin: 0 auto 1rem;
  width: 88px;
  height: 88px;
  object-fit: contain;
  border-radius: 20px;
  box-shadow: 0 0 32px rgba(0, 230, 118, 0.25);
}

.logo h1 {
  font-size: 3rem;
  font-weight: 700;
  background: linear-gradient(135deg, #00e676, #22d3ee);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo p {
  color: var(--text-muted);
  margin-top: 0.5rem;
  font-size: 0.95rem;
}

.logo-domain {
  margin-top: 0.35rem !important;
  font-size: 0.8rem !important;
  letter-spacing: 0.06em;
  color: #22d3ee !important;
  font-weight: 600;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 400px;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.tab {
  flex: 1;
  padding: 0.55rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: clamp(0.72rem, 2.6vw, 0.88rem);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all 0.2s;
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--text-on-accent);
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.form-group input, .form-group select {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-group textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.8rem;
  font-family: var(--font-mono, 'JetBrains Mono', ui-monospace, monospace);
  outline: none;
  resize: vertical;
  min-height: 5.5rem;
  line-height: 1.35;
  transition: border-color 0.2s;
}

.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--accent);
}

.login-hint {
  margin: 0.4rem 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.55;
}

.login-key-box {
  position: relative;
  margin-top: 0;
}

.login-key-box textarea {
  display: block;
  width: 100%;
  min-height: 5.1rem; /* ~1cm shorter than 7.5rem */
  resize: vertical;
  text-align: left;
}

.login-key-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0.85rem 1rem;
  box-sizing: border-box;
  text-align: center;
  white-space: pre-line;
  font-size: 0.8rem;
  line-height: 1.55;
  color: var(--text-muted);
  pointer-events: auto;
  cursor: text;
  user-select: none;
}

.login-key-box.has-value .login-key-placeholder,
.login-key-box:focus-within .login-key-placeholder {
  display: none;
}

.login-hint-save {
  margin: 0.2rem 0 0;
}

.login-key-tips {
  margin: 0.45rem 0 0.35rem;
}

.login-hint-create {
  margin: 0 0 0.25rem;
}

.login-nick-title {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  text-align: center;
}

.login-nick-lead {
  margin: 0 0 1rem;
  text-align: center;
}

.login-nick-back {
  margin-top: 0.5rem;
  width: 100%;
}

.login-key-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.6rem;
}

.login-key-actions .btn {
  width: auto;
  flex: 1;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
}

.legal-page {
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 3rem;
  padding-bottom: calc(3rem + env(safe-area-inset-bottom, 0px));
  color: var(--text);
  box-sizing: border-box;
}

/* Article + page must be able to grow so parent #app can scroll */
.legal-article {
  padding-bottom: 1rem;
}

.legal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.legal-brand {
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  font-size: 1.1rem;
}

.legal-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.legal-lang select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.5rem;
  font-size: 0.85rem;
}

.legal-nav {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.75rem;
}

.legal-nav a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 0.25rem 0;
}

.legal-nav a.active {
  color: var(--accent);
  font-weight: 600;
  border-bottom: 2px solid var(--accent);
}

.legal-article h1 {
  font-size: 1.6rem;
  margin: 0 0 0.5rem;
}

.legal-updated {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 0 0 1rem;
}

.legal-intro {
  line-height: 1.55;
  margin-bottom: 1.5rem;
}

.legal-section {
  margin-bottom: 1.5rem;
}

.legal-section h2 {
  font-size: 1.1rem;
  margin: 0 0 0.5rem;
}

.legal-section p {
  line-height: 1.55;
  color: var(--text);
  margin: 0 0 0.75rem;
  opacity: 0.92;
}

.legal-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.legal-footer a {
  color: var(--accent);
  text-decoration: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.btn {
  width: 100%;
  padding: 0.85rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--accent);
  color: var(--text-on-accent);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 0.75rem;
  text-align: center;
  white-space: pre-line;
  line-height: 1.45;
}

/* Chat layout — full viewport, resizable sidebar + header pinned (see DOCS/07 §9) */
.chat-layout {
  --sidebar-width: 280px;
  display: grid;
  grid-template-columns: var(--sidebar-width) 5px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

/* Desktop: backdrop must not occupy a grid track (only used on mobile drawer) */
.sidebar-backdrop {
  display: none;
}

.chat-layout > .sidebar {
  grid-column: 1;
  grid-row: 1;
}

.chat-layout > .layout-splitter {
  grid-column: 2;
  grid-row: 1;
}

.chat-layout > .chat-area {
  grid-column: 3;
  grid-row: 1;
}

.layout-splitter {
  cursor: col-resize;
  touch-action: none;
  user-select: none;
  background: var(--border);
  position: relative;
  z-index: 3;
  transition: background 0.15s;
}

.layout-splitter::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: -4px;
  right: -4px;
}

.layout-splitter:hover,
.layout-splitter.dragging {
  background: color-mix(in srgb, var(--accent) 55%, var(--border));
}

body.layout-resizing {
  cursor: col-resize !important;
  user-select: none;
}

body.layout-resizing * {
  cursor: col-resize !important;
}

.sidebar {
  background: var(--surface);
  border-right: none;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.sidebar-header {
  padding: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-self-profile {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
  min-width: 0;
}

.sidebar-self-avatar-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
  flex-shrink: 0;
}

.sidebar-self-avatar-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sidebar-self-avatar-hint {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.55rem;
  line-height: 1.1rem;
  text-align: center;
  color: var(--text-muted);
  pointer-events: none;
}

.sidebar-self-meta {
  min-width: 0;
  flex: 1;
}

.sidebar-self-name {
  display: block;
  flex: 1;
  min-width: 0;
  max-width: 100%;
  padding: 0.15rem 0;
  margin: 0;
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 1.1rem;
  font-weight: 700;
  text-align: start;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-height: 44px;
  line-height: 1.2;
}

.sidebar-self-name-row {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  min-width: 0;
  width: 100%;
}

.sidebar-self-edit-nick {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.95rem;
  cursor: pointer;
}

.sidebar-self-edit-nick:focus-visible,
.sidebar-self-name:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sidebar-self-profile .user-info {
  margin-top: 0;
}

.avatar-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
  z-index: 1;
}

.avatar-initials {
  position: relative;
  z-index: 0;
  letter-spacing: 0.02em;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.avatar-crop-overlay,
.avatar-preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 12000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(0.75rem, env(safe-area-inset-top))
    max(0.75rem, env(safe-area-inset-right))
    max(0.75rem, env(safe-area-inset-bottom))
    max(0.75rem, env(safe-area-inset-left));
  background: rgba(0, 0, 0, 0.55);
  box-sizing: border-box;
}

.avatar-crop-card,
.avatar-preview-card {
  width: min(100%, 22rem);
  max-height: min(90dvh, 36rem);
  overflow: auto;
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 1rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.avatar-crop-title {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.avatar-crop-stage {
  display: flex;
  justify-content: center;
  touch-action: none;
}

.avatar-crop-canvas {
  width: min(280px, 72vw);
  height: auto;
  aspect-ratio: 1;
  max-width: 100%;
  border-radius: 8px;
  cursor: grab;
  touch-action: none;
}

.avatar-crop-zoom {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0.85rem 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.avatar-crop-zoom input[type='range'] {
  width: 100%;
  min-height: 44px;
}

.avatar-crop-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

.avatar-crop-actions .btn,
.avatar-preview-card .btn {
  min-height: 44px;
  min-width: 44px;
}

.avatar-preview-body {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 0.75rem;
  /* Preview = ảnh vuông nguyên (không mask tròn) */
}

.avatar-preview-body .avatar {
  width: min(72vw, 12rem);
  height: min(72vw, 12rem);
  font-size: 3rem;
  border-radius: 12px;
}

.avatar-preview-img {
  width: min(88vw, 22rem);
  height: auto;
  max-height: min(70dvh, 22rem);
  aspect-ratio: 1;
  object-fit: contain;
  border-radius: 8px;
  display: block;
  background: var(--surface-2);
}

.avatar-preview-card .btn {
  width: 100%;
}

.nickname-edit-overlay {
  position: fixed;
  inset: 0;
  z-index: 12000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(0.75rem, env(safe-area-inset-top))
    max(0.75rem, env(safe-area-inset-right))
    max(0.75rem, env(safe-area-inset-bottom))
    max(0.75rem, env(safe-area-inset-left));
  background: rgba(0, 0, 0, 0.55);
  box-sizing: border-box;
}

.nickname-edit-card {
  width: min(100%, 22rem);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 1rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.nickname-edit-title {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.nickname-edit-input {
  width: 100%;
  min-height: 44px;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  box-sizing: border-box;
}

.nickname-edit-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 0.85rem;
}

.nickname-edit-actions .btn {
  min-height: 44px;
  min-width: 44px;
}

.sidebar-header h2 {
  font-size: 1.1rem;
  color: var(--accent);
}

.user-info {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.search-box {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.search-box input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
}

.user-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.user-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.user-item:hover, .user-item.active {
  background: var(--surface-2);
}

.user-item-avatar-btn,
.chat-peer-avatar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 50%;
  min-width: 44px;
  min-height: 44px;
  flex-shrink: 0;
}

.user-item-avatar-btn:focus-visible,
.chat-peer-avatar-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Avatar chữ cái */
.avatar {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--avatar-bg, var(--accent));
  color: #0a0f1a;
  font-weight: 700;
  line-height: 1;
  user-select: none;
  overflow: hidden;
}

.avatar-sm {
  width: 1.75rem;
  height: 1.75rem;
  font-size: 0.65rem;
}

.avatar-md {
  width: 2.25rem;
  height: 2.25rem;
  font-size: 0.75rem;
}

.avatar-lg {
  width: 3rem;
  height: 3rem;
  font-size: 0.95rem;
}

.avatar-initials {
  letter-spacing: 0.02em;
}

.avatar-status {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 0.55rem;
  height: 0.55rem;
  border: 2px solid var(--surface);
  border-radius: 50%;
}

.avatar-lg .avatar-status {
  width: 0.7rem;
  height: 0.7rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.online { background: var(--online); }
.status-dot.sleeping { background: var(--sleeping); }
.status-dot.offline { background: var(--offline); }

.user-item .name {
  font-size: 0.9rem;
  font-weight: 500;
}

.user-item-body {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.user-item-body .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unread-badge {
  background: var(--accent);
  color: var(--text-on-accent);
  font-size: 0.7rem;
  font-weight: 700;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.35rem;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.user-list-label {
  padding: 0.5rem 1rem 0.25rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.user-list-empty,
.messages-empty {
  padding: 1.5rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.5;
}

.btn-logout {
  padding: 0.4rem 0.75rem;
  font-size: 0.75rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.sidebar-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.btn-logout:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.chat-toolbar {
  display: none;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-shrink: 0;
}

.chat-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-left: auto;
}

.btn-toolbar-pwa {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  cursor: pointer;
}

.btn-toolbar-pwa:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-pwa-sidebar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.55rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
}

.btn-pwa-sidebar:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.pwa-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(0, 0, 0, 0.55);
}

.pwa-modal {
  width: min(100%, 360px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.35rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.pwa-modal-title {
  margin: 0 0 0.65rem;
  font-size: 1.05rem;
}

.pwa-modal-body {
  margin: 0 0 1.1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.45;
  white-space: pre-line;
}

.pwa-modal-ok {
  width: 100%;
}

.pwa-modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.pwa-modal-actions .btn {
  flex: 1;
}

.pwa-modal-ios {
  width: min(100%, 380px);
}

.pwa-steps {
  list-style: none;
  margin: 0 0 1.1rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.pwa-step {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  padding: 0.65rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface) 88%, var(--text-muted) 12%);
}

.pwa-step-share {
  border-color: color-mix(in srgb, #00e676 45%, var(--border));
  box-shadow: 0 0 0 1px color-mix(in srgb, #00e676 22%, transparent);
}

.pwa-step-num {
  flex: 0 0 auto;
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: #0a0f1a;
  background: #00e676;
  margin-top: 0.05rem;
}

.pwa-share-icon {
  flex: 0 0 auto;
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #00e676;
  background: color-mix(in srgb, #00e676 16%, transparent);
  margin-top: 0.05rem;
}

.pwa-step-text {
  flex: 1;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.pwa-ios-coachmark {
  position: fixed;
  left: 50%;
  bottom: max(0.85rem, env(safe-area-inset-bottom));
  z-index: 10001;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  pointer-events: none;
  animation: pwa-coach-bounce 1.4s ease-in-out infinite;
}

.pwa-ios-coachmark .pwa-share-icon {
  width: 2.1rem;
  height: 2.1rem;
  margin: 0;
  background: rgba(10, 15, 26, 0.88);
  border: 1px solid color-mix(in srgb, #00e676 50%, transparent);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

.pwa-ios-coachmark-arrow {
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 9px solid #00e676;
}

@keyframes pwa-coach-bounce {
  0%,
  100% {
    transform: translateX(-50%) translateY(0);
  }
  50% {
    transform: translateX(-50%) translateY(-6px);
  }
}

@media (min-width: 900px) {
  .pwa-ios-coachmark {
    display: none;
  }
}

.save-key-overlay {
  position: fixed;
  inset: 0;
  z-index: 10050;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(0, 0, 0, 0.65);
}

.save-key-modal {
  width: min(100%, 420px);
  max-height: min(92dvh, 640px);
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.35rem 1.4rem 1.25rem;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

.save-key-title {
  margin: 0 0 0.75rem;
  font-size: 1.15rem;
  font-weight: 650;
  text-align: center;
}

.save-key-nick {
  margin: 0 0 0.85rem;
  text-align: center;
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
}

.save-key-line {
  margin: 0 0 0.55rem;
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--text-muted);
}

.save-key-warn {
  margin: 0 0 0.9rem;
  font-size: 0.86rem;
  line-height: 1.45;
  color: var(--text-muted);
}

.save-key-box textarea {
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
  min-height: 6.5rem;
  padding: 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.72rem;
  line-height: 1.4;
}

.save-key-actions {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-top: 0.95rem;
}

.save-key-actions .btn {
  width: 100%;
}

.btn-toolbar-settings {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 0.35rem 0.65rem;
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1.2;
}

.btn-toolbar-settings:hover {
  color: var(--text);
  border-color: var(--accent);
}

.btn-menu {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.4rem 0.65rem;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-menu-bars {
  display: block;
  width: 1.15rem;
  height: 0.85rem;
  background:
    linear-gradient(currentColor, currentColor) center top / 100% 2.5px no-repeat,
    linear-gradient(currentColor, currentColor) center / 100% 2.5px no-repeat,
    linear-gradient(currentColor, currentColor) center bottom / 100% 2.5px no-repeat;
}

/* Desktop: ẩn midrail — sidebar luôn hiện */
.chat-area > .btn-menu--midrail {
  display: none;
}

.chat-top--bare {
  border-bottom: none !important;
  min-height: 0 !important;
  padding: 0 !important;
  height: 0;
  overflow: hidden;
}

/* Tab mép ☰ đã bỏ — dùng .btn-menu--midrail trên mobile */
.btn-sidebar-edge {
  display: none !important;
}

.status-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.chat-appearance {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.chat-appearance-item {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 140px;
  flex: 1;
}

.chat-appearance-item label {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
}

.chat-appearance-select {
  width: 100%;
  padding: 0.45rem 0.6rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}

.chat-appearance-select:focus {
  outline: none;
  border-color: var(--accent);
}

.user-item .badge {
  font-size: 0.65rem;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  background: var(--accent);
  color: var(--text-on-accent);
  margin-left: auto;
}

.chat-layout > .sidebar,
.chat-layout > .layout-splitter,
.chat-layout > .chat-area {
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
}

/* Chat area — Zalo-style: header + input fixed, only middle row scrolls.
 * Named areas: mọi child lạc (progress, midrail) không được tạo hàng 4 → nhảy input. */
.chat-area {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    'top'
    'main'
    'bottom';
  background: var(--bg);
  min-width: 0;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
  position: relative;
}

.chat-top {
  grid-area: top;
  z-index: 2;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}

.chat-messages-pane,
.empty-chat {
  grid-area: main;
  z-index: 0;
  isolation: isolate;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  background: var(--bg);
  /* Neo tin xuống đáy khi ít tin — tránh «dồn 1 cục» trên đầu (PC/web). */
  display: flex;
  flex-direction: column;
}

.chat-bottom {
  grid-area: bottom;
  /* Phải trên messages — tránh emoji/tools bị lớp trắng khung chat đè (mobile Safari/Chrome). */
  z-index: 6;
  background: var(--bg);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 100%;
  /* Chỉ chặn tràn ngang — overflow:hidden từng cắt nửa hàng emoji/tools */
  overflow-x: hidden;
  overflow-y: visible;
  padding-bottom: var(--composer-safe-bottom, env(safe-area-inset-bottom, 0px));
}

@media (display-mode: browser) {
  .chat-bottom {
    padding-bottom: 0;
  }
}

.chat-header {
  padding: 0.75rem 1rem;
  border-bottom: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.chat-header-main {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.chat-header-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.chat-header-main h3 {
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
}

.chat-header-text .status-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.btn-voice-call {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  white-space: nowrap;
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 8px;
  min-height: var(--touch-min);
  border: 1px solid transparent;
  cursor: pointer;
}

.btn-video-call {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  white-space: nowrap;
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 8px;
  min-height: var(--touch-min);
  min-width: var(--touch-min);
  border: 1px solid transparent;
  cursor: pointer;
}

.btn-voice-call-icon {
  flex-shrink: 0;
  display: block;
}

.btn-voice-call--online {
  background: color-mix(in srgb, #22c55e 22%, var(--surface-2));
  border-color: color-mix(in srgb, #22c55e 55%, var(--border));
  color: #4ade80;
}

.btn-video-call.btn-voice-call--online {
  background: color-mix(in srgb, #38bdf8 22%, var(--surface-2));
  border-color: color-mix(in srgb, #38bdf8 55%, var(--border));
  color: #7dd3fc;
}

.btn-voice-call--online:hover {
  background: color-mix(in srgb, #22c55e 32%, var(--surface-2));
  color: #86efac;
}

.btn-voice-call--offline {
  background: color-mix(in srgb, #ef4444 18%, var(--surface-2));
  border-color: color-mix(in srgb, #ef4444 50%, var(--border));
  color: #f87171;
}

.btn-voice-call--offline:hover {
  background: color-mix(in srgb, #ef4444 28%, var(--surface-2));
  color: #fca5a5;
}

.voice-call-overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, #0b0f1a 72%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding:
    max(1rem, var(--sat))
    max(1rem, var(--sar))
    max(1rem, var(--sab))
    max(1rem, var(--sal));
  box-sizing: border-box;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.voice-call-card {
  width: min(360px, 100%);
  max-width: 100%;
  background: linear-gradient(
    165deg,
    color-mix(in srgb, var(--bg-elevated, #1a1f2e) 92%, #2a3550) 0%,
    var(--bg-elevated, #141824) 100%
  );
  border: 1px solid color-mix(in srgb, #fff 8%, transparent);
  border-radius: 1.35rem;
  padding: 1.6rem 1.2rem 1.35rem;
  text-align: center;
  box-shadow: 0 18px 50px color-mix(in srgb, #000 45%, transparent);
  box-sizing: border-box;
  overflow: hidden;
}

.voice-call-card[data-mode='direct'] {
  box-shadow:
    0 0 0 1px color-mix(in srgb, #22c55e 35%, transparent),
    0 18px 50px color-mix(in srgb, #000 45%, transparent);
}

.voice-call-card[data-mode='relay'] {
  box-shadow:
    0 0 0 1px color-mix(in srgb, #f59e0b 40%, transparent),
    0 18px 50px color-mix(in srgb, #000 45%, transparent);
}

.voice-call-avatar {
  width: 4.75rem;
  height: 4.75rem;
  margin: 0 auto 0.85rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  background: linear-gradient(145deg, #6366f1, #8b5cf6 55%, #a855f7);
  box-shadow: 0 8px 24px color-mix(in srgb, #6366f1 35%, transparent);
}

.voice-call-nick {
  margin: 0 0 0.35rem;
  font-size: clamp(1.15rem, 4.2vw, 1.4rem);
  font-weight: 650;
  color: var(--text, #f4f4f8);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.voice-call-status {
  margin: 0 0 0.55rem;
  font-size: 0.95rem;
  line-height: 1.35;
  color: var(--text-muted, #a8b0c0);
  min-height: 1.35em;
}

/* Live call: chỉ timer — to + xanh lá (emoji 🟢) */
.voice-call-status--timer {
  margin: 0.15rem 0 0.65rem;
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.15;
  color: #22c55e;
  font-variant-numeric: tabular-nums;
  min-height: 1.15em;
}

.voice-call-link {
  margin: 0 0 1.25rem;
  font-size: 0.78rem;
  line-height: 1.35;
  color: var(--text-muted);
  opacity: 0.9;
}

.voice-call-mode {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0 0 1.35rem;
  padding: 0.28rem 0.7rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: color-mix(in srgb, #94a3b8 18%, transparent);
  color: var(--text, #eee);
}

.voice-call-mode[data-mode='direct'] {
  background: color-mix(in srgb, #22c55e 28%, transparent);
  color: #bbf7d0;
}

.voice-call-mode[data-mode='relay'] {
  background: color-mix(in srgb, #f59e0b 30%, transparent);
  color: #fde68a;
}

.voice-call-actions {
  display: flex;
  gap: 0.85rem;
  justify-content: center;
  align-items: flex-start;
  flex-wrap: wrap;
}

.voice-call-actions--triple {
  gap: 1rem;
}

.voice-call-circle {
  appearance: none;
  border: none;
  cursor: pointer;
  width: 4.25rem;
  min-width: 4.25rem;
  height: 4.25rem;
  min-height: max(4.25rem, var(--touch-min));
  border-radius: 50%;
  padding: 0.35rem;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1.15;
  color: #e8eaf2;
  background: color-mix(in srgb, #fff 10%, #1e2433);
  box-shadow: 0 4px 14px color-mix(in srgb, #000 28%, transparent);
  transition: transform 0.12s ease, background 0.15s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.voice-call-circle:active {
  transform: scale(0.94);
}

.voice-call-circle-label {
  max-width: 3.6rem;
  text-align: center;
  word-break: break-word;
}

.voice-call-circle--danger {
  width: 4.6rem;
  min-width: 4.6rem;
  height: 4.6rem;
  min-height: max(4.6rem, var(--touch-min));
  background: #e11d48;
  color: #fff;
  box-shadow: 0 6px 18px color-mix(in srgb, #e11d48 45%, transparent);
}

.voice-call-circle--primary {
  background: #16a34a;
  color: #fff;
  box-shadow: 0 6px 18px color-mix(in srgb, #16a34a 40%, transparent);
}

.voice-call-circle--active {
  background: color-mix(in srgb, #6366f1 55%, #1e2433);
  box-shadow: 0 0 0 2px color-mix(in srgb, #a5b4fc 55%, transparent);
}

.voice-call-debug-link {
  display: inline-block;
  margin-top: 0.85rem;
  background: none;
  border: none;
  color: var(--text-muted, #889);
  font-size: 0.72rem;
  text-decoration: underline;
  cursor: pointer;
}

.voice-call-route-hint {
  margin: 0.65rem 0 0;
  width: 100%;
  font-size: 0.75rem;
  color: var(--text-muted, #9aa3b5);
}

.voice-call-privacy-hint {
  margin: 0.55rem 0 0;
  width: 100%;
  max-width: 22rem;
  font-size: 0.68rem;
  line-height: 1.4;
  color: var(--text-muted, #8b93a7);
  text-align: center;
  white-space: pre-line;
}

.voice-call-mic-icon {
  display: inline-block;
  width: 16px;
  height: 16px;
  vertical-align: -3px;
  margin-right: 0.2rem;
  object-fit: contain;
  border-radius: 3px;
}

.voice-call-card[data-speaker='external'] .voice-call-route-hint {
  color: #86efac;
}

.voice-call-card[data-speaker='earpiece'] .voice-call-route-hint {
  color: #93c5fd;
}

.voice-call-card[data-speaker='speaker'] .voice-call-route-hint {
  color: #86efac;
}

.voice-call-card[data-speaker='headphone'] .voice-call-route-hint {
  color: #93c5fd;
}

.voice-call-circle-icon {
  display: block;
  font-size: 1.05rem;
  line-height: 1;
  margin-bottom: 0.1rem;
}

/* Desktop Portable — wider card, clearer PC controls (Speaker / Headphones) */
.voice-call-overlay--desktop {
  background: color-mix(in srgb, #070b14 78%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.voice-call-card--desktop {
  width: min(420px, calc(100vw - 3rem));
  padding: 2rem 1.75rem 1.65rem;
  border-radius: 1.5rem;
  border: 1px solid color-mix(in srgb, #fff 10%, transparent);
  background: linear-gradient(
    160deg,
    color-mix(in srgb, #1c2438 96%, #3b82f6) 0%,
    #121826 48%,
    #0e1320 100%
  );
  box-shadow:
    0 24px 64px color-mix(in srgb, #000 55%, transparent),
    inset 0 1px 0 color-mix(in srgb, #fff 8%, transparent);
}

.voice-call-card--desktop .voice-call-avatar {
  width: 5.5rem;
  height: 5.5rem;
  font-size: 1.65rem;
  margin-bottom: 1rem;
  box-shadow: 0 10px 28px color-mix(in srgb, #6366f1 40%, transparent);
}

.voice-call-card--desktop .voice-call-nick {
  font-size: 1.45rem;
  letter-spacing: 0.01em;
}

.voice-call-card--desktop .voice-call-status--timer {
  font-size: 2.1rem;
  margin: 0.35rem 0 0.85rem;
}

.voice-call-card--desktop .voice-call-actions--triple {
  gap: 1.25rem;
  margin-top: 0.25rem;
}

.voice-call-card--desktop .voice-call-circle {
  width: 4.6rem;
  min-width: 4.6rem;
  height: 4.6rem;
  font-size: 0.72rem;
}

.voice-call-card--desktop .voice-call-circle--danger {
  width: 5.1rem;
  min-width: 5.1rem;
  height: 5.1rem;
}

.voice-call-card--desktop .voice-call-circle-label {
  max-width: 4.2rem;
}

.voice-call-card--desktop .voice-call-privacy-hint {
  margin-top: 0.85rem;
  font-size: 0.74rem;
  max-width: 24rem;
  color: color-mix(in srgb, #a8b0c0 88%, transparent);
}

.voice-call-card--desktop .voice-call-route-hint {
  margin-top: 0.75rem;
  font-size: 0.8rem;
}

.voice-call-btn {
  min-width: min(7rem, 100%);
  min-height: var(--touch-min);
  flex: 1 1 auto;
}

.btn-danger {
  background: #c0392b;
  color: #fff;
  border: none;
}

.btn-danger:hover {
  background: #a93226;
}

.chat-header-appearance {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.chat-appearance-compact {
  max-width: 9.5rem;
  padding: 0.35rem 0.45rem;
  font-size: 0.78rem;
}

.messages {
  padding: 0.75rem 1rem;
  margin-top: auto;
  width: 100%;
  box-sizing: border-box;
}

.message-day-sep {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0.85rem 0 0.65rem;
  width: 100%;
}

.message-day-sep span {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.75rem;
  line-height: 1.3;
  max-width: min(90%, 22rem);
  text-align: center;
}

.message {
  display: block;
  width: fit-content;
  max-width: min(85%, 20rem);
  margin: 0 0 0.55rem;
  padding: 0.4rem 0.65rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  line-height: 1.35;
  color: var(--text);
  word-break: break-word;
  overflow-wrap: anywhere;
  font-family: var(--chat-font-family, 'Courier New', 'Fixedsys', 'Terminal', monospace);
}

.message-text {
  display: block;
  white-space: pre-wrap;
}

.message.sent {
  margin-left: auto;
  margin-right: 0;
  background: var(--accent);
  color: var(--text-on-accent);
  border-bottom-right-radius: 4px;
}

.message.received {
  margin-right: auto;
  background: var(--surface-2);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.message.mentioned {
  outline: 1px solid var(--accent);
}

.message.thread-reply .bubble {
  border-left: 2px solid var(--accent);
  padding-left: 0.4rem;
}

.msg-actions {
  display: flex;
  gap: 0.25rem;
  opacity: 0.7;
  font-size: 0.75rem;
}

.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.msg-react {
  font-size: 0.75rem;
  padding: 0.1rem 0.35rem;
}

.chat-pins,
.reply-bar {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--surface-2);
}

.cm-matrix table {
  border-collapse: collapse;
  font-size: 0.75rem;
}

.cm-matrix th,
.cm-matrix td {
  border: 1px solid var(--border);
  padding: 0.2rem 0.35rem;
  text-align: center;
}

.message.system {
  margin-left: auto;
  margin-right: auto;
  width: auto;
  max-width: 90%;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-style: italic;
  padding: 0.35rem 0.75rem;
  text-align: center;
}

.message.file-offer {
  margin-right: auto;
  max-width: 85%;
  padding: 0;
  background: transparent;
}

.file-offer-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
  padding: 0.85rem 1rem;
}

.file-offer-card-title {
  margin: 0 0 0.35rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.file-offer-card-name {
  margin: 0 0 0.25rem;
  font-weight: 600;
  font-size: 0.9rem;
  word-break: break-all;
}

.file-offer-card-meta {
  margin: 0 0 0.65rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.file-offer-card-status {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
}

.file-offer-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

.file-offer-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  flex-wrap: wrap;
  padding: 0.6rem max(0.75rem, env(safe-area-inset-right))
    0.6rem max(0.75rem, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
  flex-shrink: 0;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
}

.chat-top .file-offer-banner {
  border-top: 1px solid var(--border);
}

.file-offer-banner-text {
  flex: 1 1 12rem;
  min-width: 0;
  color: var(--text);
  line-height: 1.35;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.file-offer-banner-actions {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.file-offer-banner-actions .btn {
  min-height: 36px;
  min-width: 44px;
}

@media (max-width: 430px) {
  .file-offer-banner {
    font-size: 0.78rem;
    padding: 0.55rem 0.65rem;
  }
}

.btn-sm {
  padding: 0.3rem 0.65rem;
  font-size: 0.78rem;
}

.file-transfer-progress {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.55rem max(0.75rem, env(safe-area-inset-right))
    0.45rem max(0.75rem, env(safe-area-inset-left));
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--surface);
  flex-shrink: 0;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
}

.file-transfer-progress-body {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.file-transfer-label {
  display: block;
  line-height: 1.35;
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: normal;
  min-width: 0;
}

/* Bar full width — không xếp ngang cùng Hủy (tránh tràn trên phone hẹp) */
.file-transfer-bar {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 6px;
  background: var(--surface-2);
  border-radius: 3px;
  overflow: hidden;
  box-sizing: border-box;
}

.file-transfer-fill {
  height: 100%;
  background: var(--accent);
  transition: width 120ms linear;
}

.file-transfer-bar--finalizing .file-transfer-fill {
  animation: file-transfer-pulse 1.1s ease-in-out infinite;
}

@keyframes file-transfer-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.55;
  }
}

.file-transfer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.file-transfer-pct {
  flex: 1 1 auto;
  min-width: 0;
  text-align: start;
  font-variant-numeric: tabular-nums;
}

.file-transfer-pct--phase {
  min-height: 1em;
}

.file-transfer-cancel {
  flex: 0 0 auto;
  max-width: 100%;
  white-space: nowrap;
  min-height: 44px;
  min-width: 44px;
  padding: 0.25rem 0.75rem;
  font-size: 0.78rem;
  box-sizing: border-box;
}

.file-transfer-progress .btn {
  flex-shrink: 0;
}

/* Legacy row class — phòng HTML cũ / cache */
.file-transfer-progress-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
  width: 100%;
}

@media (max-width: 430px) {
  .file-transfer-progress {
    font-size: 0.75rem;
    padding: 0.5rem max(0.5rem, env(safe-area-inset-right))
      max(0.5rem, env(safe-area-inset-bottom))
      max(0.5rem, env(safe-area-inset-left));
  }
}

@media (max-width: 359px) {
  .file-transfer-cancel {
    font-size: 0.72rem;
    padding: 0.25rem 0.55rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .file-transfer-bar--finalizing .file-transfer-fill {
    animation: none;
  }
}

.file-save-sheet {
  position: fixed;
  left: max(0.75rem, env(safe-area-inset-left, 0px));
  right: max(0.75rem, env(safe-area-inset-right, 0px));
  bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
  z-index: 1200;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: var(--surface, #1a1f2e);
  border: 1px solid var(--border, rgba(255, 255, 255, 0.12));
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  max-width: min(28rem, 100%);
  margin-inline: auto;
  box-sizing: border-box;
}

.file-save-sheet-text {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text, #e8eaed);
  line-height: 1.35;
}

.file-save-sheet-meta {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-muted, rgba(232, 234, 237, 0.72));
  line-height: 1.3;
  word-break: break-word;
}

.file-save-sheet-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted, rgba(232, 234, 237, 0.78));
  line-height: 1.4;
}

.file-save-sheet-btn {
  width: 100%;
  min-height: 44px;
}

.file-save-chip {
  position: fixed;
  left: max(0.75rem, env(safe-area-inset-left, 0px));
  right: max(0.75rem, env(safe-area-inset-right, 0px));
  bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
  z-index: 1190;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  background: var(--surface, #1a1f2e);
  border: 1px solid var(--border, rgba(255, 255, 255, 0.12));
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  max-width: min(28rem, 100%);
  margin-inline: auto;
  box-sizing: border-box;
}

.file-save-chip-text {
  flex: 1 1 10rem;
  font-size: 0.8rem;
  color: var(--text, #e8eaed);
  line-height: 1.3;
  word-break: break-word;
}

.file-save-chip-btn {
  flex: 0 0 auto;
  min-height: 44px;
  min-width: 7rem;
}

/* Phone hẹp 280–360 */
@media (max-width: 359px) {
  .file-save-sheet,
  .file-save-chip {
    left: max(0.5rem, env(safe-area-inset-left, 0px));
    right: max(0.5rem, env(safe-area-inset-right, 0px));
    padding: 0.75rem 0.85rem;
  }

  .file-save-sheet-text {
    font-size: 0.88rem;
  }
}

.message .meta {
  font-size: 0.7rem;
  opacity: 0.65;
  margin-top: 0.2rem;
  line-height: 1.2;
}

.message .message-receipt {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.68rem;
  opacity: 0.85;
  font-style: normal;
}

.file-transfer-progress-stack {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  width: 100%;
}

.file-transfer-progress-stack .file-transfer-progress {
  margin: 0;
}

.typing-indicator {
  padding: 0 1.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
  min-height: 1.2rem;
  flex-shrink: 0;
}

.chat-input {
  padding: 0.65rem 1.5rem;
  border-top: none;
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
  flex-shrink: 0;
  background: var(--bg);
}

.chat-input-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

.chat-input-compose {
  display: flex;
  align-items: flex-end;
  gap: 0.4rem;
  min-width: 0;
  width: 100%;
  --compose-control-h: 44px;
}

.chat-input--v2 {
  flex-direction: column;
  gap: 0.35rem;
  padding-top: 0.4rem;
  padding-bottom: 0.45rem;
}

.chat-input--v2 .chat-input-main {
  gap: 0;
}

.composer-surface {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-end;
  gap: 0.15rem;
  padding: 0.15rem 0.2rem 0.15rem 0.65rem;
  border: 1px solid var(--border, #303044);
  border-radius: 22px;
  background: var(--surface-2, var(--bg-elevated, rgba(255,255,255,0.04)));
  min-height: var(--compose-control-h);
  box-sizing: border-box;
}

.composer-surface:focus-within {
  border-color: color-mix(in srgb, var(--accent, #7357FF) 55%, var(--border, #303044));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent, #7357FF) 22%, transparent);
}

.composer-surface .msg-input-rich,
.composer-surface #msg-input {
  flex: 1;
  min-width: 0;
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
  outline: none !important;
  min-height: calc(var(--compose-control-h) - 6px);
  max-height: 132px;
  padding: 0.45rem 0.25rem;
  line-height: 1.35;
  font-size: 16px;
}

/* Inside composer surface: override global .btn-icon border/fill (cấm viền chip). */
.chat-input--v2 .composer-emoji-toggle.btn-icon,
.composer-emoji-toggle {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  margin: 0;
  padding: 0;
  border: none !important;
  border-radius: 0;
  box-shadow: none !important;
  outline: none !important;
  color: var(--text-muted, #A5A5B5);
  background: transparent !important;
  font-size: 1.35rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.chat-input--v2 .composer-emoji-toggle.btn-icon:hover,
.composer-emoji-toggle:hover,
.composer-emoji-toggle:focus-visible {
  background: transparent !important;
  border: none !important;
  color: var(--text, #eee);
}

/* Active = keyboard glyph only — cấm chip nền / viền (parity Android flat + user chốt). */
.chat-input--v2 .composer-emoji-toggle.btn-icon.is-active,
.chat-input--v2 .composer-emoji-toggle.btn-icon[aria-pressed='true'],
.composer-emoji-toggle.is-active,
.composer-emoji-toggle[aria-pressed='true'] {
  color: var(--text-muted, #A5A5B5);
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
}

.composer-emoji-toggle .composer-keyboard-icon {
  display: block;
}

.btn-composer-send {
  flex-shrink: 0;
  width: var(--compose-control-h);
  height: var(--compose-control-h);
  min-width: var(--compose-control-h);
  min-height: var(--compose-control-h);
  border: none;
  border-radius: 50%;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent, #7357FF);
  color: #fff;
  cursor: pointer;
  transition: transform 0.14s ease, opacity 0.14s ease;
}

.btn-composer-send:hover {
  filter: brightness(1.06);
}

.btn-composer-send:active {
  transform: scale(0.96);
}

.btn-composer-more {
  flex-shrink: 0;
  width: var(--compose-control-h);
  height: var(--compose-control-h);
  min-width: var(--compose-control-h);
  min-height: var(--compose-control-h);
  color: var(--text-muted, #A5A5B5);
}

.chat-input-compose .btn-attach-compose {
  flex-shrink: 0;
  box-sizing: border-box;
  width: var(--compose-control-h);
  height: var(--compose-control-h);
  min-width: var(--compose-control-h);
  min-height: var(--compose-control-h);
  max-width: var(--compose-control-h);
  max-height: var(--compose-control-h);
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  margin: 0;
  align-self: flex-end;
  color: var(--accent, #7357FF);
  background: transparent;
}

.chat-input-compose .btn-attach-compose.is-selected {
  background: color-mix(in srgb, var(--accent, #7357FF) 18%, transparent);
}

.chat-input-compose .btn-attach-compose:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.composer-attach-tray {
  width: 100%;
  padding: 0.55rem 0.35rem 0.35rem;
  border-radius: 16px 16px 12px 12px;
  background: var(--surface, rgba(21, 21, 31, 0.96));
  border: 1px solid var(--border, #303044);
  box-sizing: border-box;
}

.composer-attach-tray-handle {
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: var(--border, #303044);
  margin: 0 auto 0.55rem;
}

.composer-attach-tray-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.35rem;
}

.composer-attach-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  min-height: 72px;
  padding: 0.45rem 0.25rem;
  border: none;
  border-radius: 14px;
  background: transparent;
  color: var(--text, #F7F7FB);
  cursor: pointer;
}

.composer-attach-chip:hover,
.composer-attach-chip:focus-visible {
  background: color-mix(in srgb, var(--accent, #7357FF) 12%, transparent);
  outline: none;
}

.composer-attach-chip-icon {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--accent, #7357FF) 16%, transparent);
  color: var(--accent, #7357FF);
}

.composer-attach-chip-label {
  font-size: 0.7rem;
  color: var(--text-muted, #A5A5B5);
  text-align: center;
  line-height: 1.2;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.composer-appearance-popover {
  width: 100%;
  padding: 0.45rem 0.5rem;
  border-radius: 14px;
  border: 1px solid var(--border, #303044);
  background: var(--surface, rgba(21, 21, 31, 0.96));
  box-sizing: border-box;
}

.composer-appearance-popover-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.chat-input-compose .msg-input-rich,
.chat-input-compose #msg-input {
  flex: 1;
  min-width: 0;
}

/* Legacy tools row kept for non-v2 surfaces */
.chat-input-tools {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  position: relative;
}

.chat-input-tools-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
  /* Đủ chỗ trên — không bị mép messages che nửa icon */
  padding-top: 0.15rem;
  min-height: 44px;
}

.chat-tools-divider {
  width: 1px;
  height: 1.35rem;
  background: var(--border);
  flex-shrink: 0;
  margin: 0 0.1rem;
}

.chat-input-appearance {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
}

.chat-input-appearance-select {
  max-width: 7.5rem;
  padding: 0.28rem 0.4rem;
  font-size: 0.72rem;
}

.chat-format-bar {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  flex-wrap: wrap;
  padding: 0.2rem 0.15rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.chat-format-bar[hidden] {
  display: none;
}

.btn-format {
  min-width: 1.75rem;
  height: 1.75rem;
  padding: 0 0.35rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 0.82rem;
  line-height: 1;
}

.btn-format:hover {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}

.format-fontsize-wrap {
  display: inline-flex;
  align-items: center;
  margin-left: 0.15rem;
}

.format-fontsize-select {
  min-width: 3rem;
  height: 1.75rem;
  padding: 0 0.2rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  line-height: 1;
}

.format-fontsize-select:focus {
  outline: none;
  border-color: var(--accent);
}

.msg-fs-sm {
  font-size: 14px;
}

.msg-fs-md {
  font-size: 16px;
}

.msg-fs-lg {
  font-size: 18px;
}

.msg-fs-12 { font-size: 12px; }
.msg-fs-14 { font-size: 14px; }
.msg-fs-16 { font-size: 16px; }
.msg-fs-18 { font-size: 18px; }
.msg-fs-20 { font-size: 20px; }
.msg-fs-24 { font-size: 24px; }

#msg-input.msg-fs-12 { font-size: 12px; }
#msg-input.msg-fs-14 { font-size: 14px; }
#msg-input.msg-fs-16,
#msg-input.msg-fs-md { font-size: 16px; }
#msg-input.msg-fs-18,
#msg-input.msg-fs-lg { font-size: 18px; }
#msg-input.msg-fs-20 { font-size: 20px; }
#msg-input.msg-fs-24 { font-size: 24px; }
#msg-input.msg-fs-sm { font-size: 14px; }

.btn-format-toggle {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.btn-format-toggle.active {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: var(--accent);
}

.chat-input-tools .btn-icon {
  width: 2rem;
  height: 2rem;
  font-size: 1rem;
}

.message-text strong,
.message-text b {
  font-weight: 800;
  /* Monospace IRC thường thiếu face bold — đậm giả để thấy rõ */
  -webkit-text-stroke: 0.35px currentColor;
  text-shadow: 0.3px 0 0 currentColor;
}

.message-text em,
.message-text i {
  font-style: italic;
  font-synthesis: style;
}

.message-text u {
  text-decoration: underline;
  text-underline-offset: 2px;
}

.message-text s {
  text-decoration: line-through;
}

.emoji-picker-root {
  display: none;
  position: absolute;
  bottom: calc(100% + 0.35rem);
  left: 0;
  z-index: 50;
}

.emoji-picker-root.open {
  display: block;
}

.emoji-picker {
  width: min(360px, calc(100vw - 2rem));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.emoji-picker-loading {
  padding: 2rem 1rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.emoji-picker-panels {
  display: flex;
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  overscroll-behavior-x: contain;
  touch-action: pan-x;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
  cursor: grab;
}

.emoji-picker-panels:active {
  cursor: grabbing;
}

.emoji-picker-panels::-webkit-scrollbar {
  display: none;
}

.emoji-picker-panel {
  flex: 0 0 100%;
  width: 100%;
  min-width: 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  max-height: 17.5rem;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.35rem 0.45rem;
  touch-action: pan-y;
}

.emoji-picker-empty {
  margin: 2rem 0.5rem;
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.emoji-picker-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 1px;
}

.emoji-cell {
  aspect-ratio: 1;
  min-width: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 8px;
  font-size: 1.45rem;
  line-height: 1;
  padding: 0.15rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.emoji-cell:hover {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}

.emoji-picker-tabs {
  display: flex;
  overflow-x: auto;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  padding: 0.2rem 0.35rem;
  gap: 0.05rem;
  scrollbar-width: none;
}

.emoji-picker-tabs::-webkit-scrollbar {
  display: none;
}

.emoji-picker-tab {
  flex: 0 0 auto;
  width: 2.15rem;
  height: 2.15rem;
  border: none;
  background: transparent;
  font-size: 1.05rem;
  border-radius: 7px;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.15s, background 0.15s;
}

.emoji-picker-tab:hover {
  opacity: 0.85;
}

.emoji-picker-tab.active {
  opacity: 1;
  background: color-mix(in srgb, var(--accent) 20%, transparent);
}

.sticker-picker-root {
  display: none;
  position: absolute;
  bottom: calc(100% + 0.35rem);
  left: 0;
  z-index: 51;
}

.sticker-picker-root.open {
  display: block;
}

.sticker-picker {
  width: min(360px, calc(100vw - 2rem));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.sticker-picker-loading {
  padding: 2rem 1rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.sticker-picker-panels {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
}

.sticker-picker-panels::-webkit-scrollbar {
  display: none;
}

.sticker-picker-panel {
  flex: 0 0 100%;
  scroll-snap-align: start;
  max-height: 17.5rem;
  overflow-y: auto;
  padding: 0.35rem 0.45rem;
}

.sticker-picker-empty {
  margin: 1.5rem 0.5rem;
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.sticker-custom-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.35rem;
}

.sticker-picker-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.35rem;
}

.sticker-cell-wrap {
  position: relative;
}

.sticker-cell {
  width: 100%;
  aspect-ratio: 1;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 10px;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sticker-cell:hover {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.sticker-cell img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.sticker-cell-remove {
  position: absolute;
  top: 0;
  right: 0;
  width: 1.1rem;
  height: 1.1rem;
  border: none;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}

.sticker-cell-wrap:hover .sticker-cell-remove {
  opacity: 1;
}

.sticker-picker-tabs {
  display: flex;
  overflow-x: auto;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  padding: 0.2rem 0.35rem;
  gap: 0.05rem;
  scrollbar-width: none;
}

.sticker-picker-tabs::-webkit-scrollbar {
  display: none;
}

.sticker-picker-tab {
  flex: 0 0 auto;
  width: 2.15rem;
  height: 2.15rem;
  border: none;
  background: transparent;
  font-size: 1.05rem;
  border-radius: 7px;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.15s, background 0.15s;
}

.sticker-picker-tab:hover {
  opacity: 0.85;
}

.sticker-picker-tab.active {
  opacity: 1;
  background: color-mix(in srgb, var(--accent) 20%, transparent);
}

.message.sticker {
  white-space: normal;
  padding: 0.35rem;
  background: transparent;
}

.message.sticker.sent {
  margin-left: auto;
  margin-right: 0;
  background: transparent;
}

.message.sticker.received {
  margin-right: auto;
  background: transparent;
}

.message-sticker {
  width: 6rem;
  height: 6rem;
  object-fit: contain;
  display: block;
}

.chat-input textarea,
.chat-input .msg-input-rich {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
  padding: 0 0.85rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 0.9rem;
  /* Box 40px − border ≈ 38px → placeholder/caret giữa khung */
  line-height: 38px;
  resize: none;
  outline: none;
  font-family: inherit;
  min-height: 40px;
  max-height: 120px;
  height: 40px;
  box-sizing: border-box;
  field-sizing: content;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: block;
}

.chat-input .msg-input-rich.msg-input-rich--multiline {
  line-height: 1.35;
  padding-top: 0.45rem;
  padding-bottom: 0.45rem;
}

.chat-input .msg-input-rich {
  white-space: pre-wrap;
  word-break: break-word;
  caret-color: var(--accent, #5c6bc0);
}

.chat-input .msg-input-rich:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  pointer-events: none;
  line-height: inherit;
}

.chat-input .msg-input-rich:focus {
  border-color: var(--accent);
}

.chat-input .msg-input-rich strong,
.chat-input .msg-input-rich b {
  font-weight: 700;
}

.chat-input .msg-input-rich em,
.chat-input .msg-input-rich i {
  font-style: italic;
}

.chat-input .msg-input-rich u {
  text-decoration: underline;
}

.chat-input .ttl-select {
  padding: 0.28rem 0.4rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.72rem;
  max-width: 5.5rem;
  min-height: 36px;
  flex-shrink: 0;
}

.chat-input .btn-send {
  width: auto;
  flex: 0 0 auto;
  padding: 0 0.9rem;
  min-height: var(--compose-control-h, 40px);
  height: var(--compose-control-h, 40px);
  align-self: center;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.empty-chat {
  grid-row: 2;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.95rem;
  overflow-y: auto;
}

.empty-chat p {
  display: block;
  margin: 0;
  max-width: 22rem;
  line-height: 1.45;
  color: var(--text);
}

.empty-chat .hint {
  display: block;
  margin: 0;
  max-width: 22rem;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--text-muted);
  opacity: 0.85;
}

.btn-open-list {
  margin-top: 0.85rem;
  padding: 0.7rem 1.15rem !important;
  font-size: 0.9rem !important;
  background: var(--accent) !important;
  color: var(--text-on-accent) !important;
  border-color: var(--accent) !important;
}

.connection-status {
  padding: 0.4rem 0.75rem;
  border-radius: 20px;
  font-size: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  white-space: nowrap;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.connection-status.connected { border-color: var(--online); color: var(--online); }
.connection-status.disconnected { border-color: var(--danger); color: var(--danger); }

.sidebar-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.btn-icon {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 8px;
  width: 2rem;
  height: 2rem;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.btn-icon:hover {
  color: var(--text);
  border-color: var(--accent);
}

.btn-settings-open {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  margin-top: 0.75rem;
  padding: 0.55rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--accent);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
}

.btn-settings-open:hover {
  background: var(--accent);
  color: var(--text-on-accent);
}

.settings-btn-icon {
  font-size: 1.1rem;
}

.prefs-summary {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

.prefs-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 0.55rem;
  cursor: pointer;
  font-family: inherit;
  line-height: 1.2;
}

.prefs-chip:hover {
  border-color: var(--accent);
  color: var(--text);
}

.lang-picker {
  position: relative;
  z-index: 20;
}

.lang-picker-btn .lang-flag {
  font-size: 0.95rem;
  line-height: 1;
}

.lang-picker-btn .lang-caret {
  font-size: 0.65rem;
  opacity: 0.7;
}

.lang-flag-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12);
  line-height: 0;
  perspective: 40px;
}

.lang-flag-sm {
  width: 1.35rem;
  height: 0.95rem;
}

.lang-flag-md {
  width: 1.75rem;
  height: 1.2rem;
}

.lang-flag-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transform-origin: left center;
}

/* Cờ bay bay */
.lang-flag-wave {
  animation: flag-wave 1.1s ease-in-out infinite;
}

.lang-option:hover .lang-flag-wave,
.lang-picker.open .lang-picker-btn .lang-flag-wave {
  animation-duration: 0.75s;
}

@keyframes flag-wave {
  0% {
    transform: rotateY(0deg) skewY(0deg) scaleX(1);
  }
  25% {
    transform: rotateY(8deg) skewY(1.5deg) scaleX(0.97);
  }
  50% {
    transform: rotateY(0deg) skewY(0deg) scaleX(1);
  }
  75% {
    transform: rotateY(-8deg) skewY(-1.5deg) scaleX(0.97);
  }
  100% {
    transform: rotateY(0deg) skewY(0deg) scaleX(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .lang-flag-wave {
    animation: none;
  }
}

.lang-menu {
  position: absolute;
  top: calc(100% + 0.35rem);
  left: 0;
  min-width: 11.5rem;
  max-height: min(320px, 50vh);
  overflow-y: auto;
  padding: 0.35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.lang-menu[hidden] {
  display: none !important;
}

.lang-option {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  text-align: left;
  padding: 0.45rem 0.55rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 0.82rem;
  cursor: pointer;
  font-family: inherit;
}

.lang-option:hover {
  background: var(--surface-2);
}

.lang-option.active {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  color: var(--text);
}

.lang-option .lang-flag {
  font-size: 1.1rem;
  width: 1.4rem;
  text-align: center;
  flex-shrink: 0;
}

.lang-option .lang-name {
  flex: 1;
  min-width: 0;
}

.prefs-swatch {
  display: inline-block;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  border: 1px solid var(--border);
}

.prefs-font-chip {
  font-family: var(--chat-font-family, monospace);
  font-weight: 600;
}

#irchat-settings-root {
  position: relative;
  z-index: 9999;
}

body.irchat-settings-open {
  overflow: hidden;
}

.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 1rem;
}

.settings-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
}

.settings-modal-compact {
  max-width: 400px;
}

.settings-section {
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.settings-section:last-of-type {
  border-bottom: none;
}

.settings-section-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.65rem;
}

.settings-section-hint {
  margin: 0 0 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}


.settings-toggle-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-height: 44px;
  margin: 0 0 0.35rem;
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
}
.settings-toggle-row input {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.settings-hint-inline {
  margin: 0 0 0.65rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.settings-field-label {
  display: block;
  margin: 0.55rem 0 0.3rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.settings-select {
  width: 100%;
  min-height: 44px;
  margin: 0 0 0.55rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.9rem;
}

.settings-audio-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) auto;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
  margin: 0.35rem 0 0.55rem;
  font-size: 0.88rem;
}

.settings-subsection-title {
  margin: 1rem 0 0.35rem;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
}

.settings-audio-row input[type='range'] {
  width: 100%;
  min-height: 32px;
}

.settings-audio-val {
  min-width: 3.2rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  font-size: 0.82rem;
}

@media (max-width: 360px) {
  .settings-audio-row {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
  }
  .settings-audio-row label {
    grid-column: 1 / -1;
  }
}

.settings-devices {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.65rem;
  max-height: 10rem;
  overflow-y: auto;
}

.settings-device-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}

.settings-device-meta {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
  font-size: 0.8rem;
}

.settings-device-meta span {
  color: var(--text-muted);
  font-size: 0.72rem;
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.theme-card {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  background: var(--surface-2);
  border: 2px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  color: var(--text);
  text-align: left;
}

.theme-card:hover {
  border-color: var(--accent-hover);
}

.theme-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.theme-swatch {
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.theme-name {
  font-size: 0.78rem;
  line-height: 1.2;
}

.font-preview {
  margin-top: 0.65rem;
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  line-height: 1.4;
}

.settings-actions {
  margin-top: 1rem;
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.55rem 1rem;
  border-radius: 8px;
  cursor: pointer;
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.settings-header h3 {
  font-size: 1.1rem;
}

.settings-hint {
  font-size: 0.8rem;
  color: var(--online);
  min-height: 1.2rem;
  margin-top: 0.5rem;
}

html[dir="rtl"] .sidebar-header-row,
html[dir="rtl"] .chat-header,
html[dir="rtl"] .user-item {
  flex-direction: row-reverse;
}

html[dir="rtl"] .message.sent {
  margin-left: 0;
  margin-right: auto;
  border-bottom-right-radius: var(--radius);
  border-bottom-left-radius: 4px;
}

html[dir="rtl"] .message.received {
  margin-left: auto;
  margin-right: 0;
  border-bottom-left-radius: var(--radius);
  border-bottom-right-radius: 4px;
}

/* ========== Phone / tablet shell (mọi khung smartphone thế giới — DOCS/32) ========== */
@media (max-width: 1023px) {
  html,
  body,
  #app,
  #app.chat-mode {
    overflow-x: hidden;
    max-width: 100%;
  }

  .chat-layout {
    grid-template-columns: minmax(0, 1fr);
    height: 100%;
    width: 100%;
    max-width: 100%;
  }

  .chat-layout > .sidebar,
  .chat-layout > .chat-area {
    grid-column: 1;
    grid-row: 1;
  }

  .layout-splitter {
    display: none !important;
  }

  .chat-toolbar {
    display: flex;
    flex-shrink: 0;
    gap: 0.5rem;
    min-width: 0;
    justify-content: flex-start;
    padding: 0.45rem var(--phone-gutter);
  }

  /* Không còn nút ⚙ trên thanh chat — Cài đặt nằm trong sidebar */
  .btn-toolbar-settings {
    display: none !important;
  }

  .chat-header-main {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
  }

  .btn-menu--in-header {
    display: none !important;
  }

  /* absolute only — CẤM grid-area span full: từng làm hàng emoji bị khung main đè */
  .chat-area > .btn-menu--midrail {
    display: inline-flex;
    position: absolute;
    left: max(0.2rem, env(safe-area-inset-left, 0px));
    top: 50%;
    right: auto;
    bottom: auto;
    transform: translateY(-50%);
    z-index: 8;
    width: 52px;
    height: 52px;
    min-width: 52px;
    min-height: 52px;
    padding: 0;
    margin: 0;
    border-radius: 14px;
    border: 1.5px solid color-mix(in srgb, var(--accent) 55%, var(--border));
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 18%, var(--surface));
    box-shadow:
      0 2px 10px color-mix(in srgb, var(--accent) 22%, transparent),
      0 0 0 1px color-mix(in srgb, var(--accent) 12%, transparent);
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    cursor: grab;
    user-select: none;
  }

  .chat-area > .btn-menu--midrail.is-dragging {
    cursor: grabbing;
    opacity: 0.92;
  }

  .chat-area > .btn-menu--midrail .btn-menu-bars {
    width: 1.45rem;
    height: 1.1rem;
    pointer-events: none;
    background:
      linear-gradient(currentColor, currentColor) center top / 100% 3.5px no-repeat,
      linear-gradient(currentColor, currentColor) center / 100% 3.5px no-repeat,
      linear-gradient(currentColor, currentColor) center bottom / 100% 3.5px no-repeat;
  }

  .chat-area > .btn-menu--midrail:active:not(.is-dragging) {
    background: color-mix(in srgb, var(--accent) 28%, var(--surface));
  }

  /* Bỏ tab mép cố định cũ */
  .btn-sidebar-edge {
    display: none !important;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: var(--app-top, 0px);
    height: var(--app-height, 100dvh);
    bottom: auto;
    /* Chừa mép phải ≥ ~52px để tap đóng */
    width: min(300px, calc(100vw - 3.25rem));
    max-width: calc(100% - 3.25rem);
    z-index: 200;
    transform: translateX(-105%);
    transition: transform 0.25s ease;
    box-shadow: none;
    border-right: 1px solid var(--border);
    padding-top: var(--sat);
    padding-bottom: var(--sab);
    padding-left: var(--sal);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.55);
  }

  /*
   * Backdrop phải nằm GIỮA chat-area và sidebar.
   * Trước đây z-index 150 + chat-area cùng lưới → mép phải nhận click của chat, không đóng được.
   */
  .sidebar-backdrop {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    top: var(--app-top, 0px);
    height: var(--app-height, 100dvh);
    z-index: 190;
    background: rgba(0, 0, 0, 0.5);
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }

  .sidebar-backdrop.visible {
    display: block;
  }

  /* Khi drawer mở: chat không chặn tap/swipe vùng phải */
  .chat-layout.sidebar-open > .chat-area {
    pointer-events: none;
  }

  .chat-area {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    position: relative;
    z-index: 1;
  }

  .chat-top {
    padding-top: var(--sat);
  }

  .chat-header {
    padding: var(--phone-header-pad-y) var(--phone-header-pad-x);
    gap: 0.45rem;
    flex-wrap: nowrap;
  }

  .chat-header-actions .btn,
  .chat-header-actions button {
    min-height: var(--touch-min);
  }

  /* Mobile: hiện theme + font trên trình duyệt phone */
  .chat-input-appearance {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    max-width: 100%;
  }

  .chat-input-appearance-select {
    max-width: min(42vw, 8.5rem);
    min-height: 36px;
    font-size: 0.7rem;
  }

  .message {
    max-width: min(88%, calc(100% - 2.5rem));
  }

  .messages {
    padding: 0.75rem var(--phone-gutter);
    max-width: 100%;
  }

  /* Bớt dư khoảng trống dưới ô nhập (Safari / safe-area) */
  .chat-bottom {
    padding-bottom: 0 !important;
    padding-top: 0;
  }

  .chat-input {
    flex-wrap: nowrap;
    gap: 0.35rem;
    padding: 0.35rem var(--phone-gutter) 0.35rem;
    align-items: stretch;
  }

  .chat-input-main {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
  }

  .chat-input-compose {
    gap: 0.35rem;
    --compose-control-h: 44px;
    align-items: flex-end;
  }

  .chat-input--v2 {
    padding: 0.3rem 0 0.35rem;
  }

  .composer-attach-tray-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  @media (max-width: 320px) {
    .composer-attach-chip-label {
      font-size: 0.62rem;
    }
    .composer-attach-chip-icon {
      width: 44px;
      height: 44px;
    }
  }

  .chat-input-compose .btn-attach-compose {
    width: var(--compose-control-h);
    height: var(--compose-control-h);
    min-width: var(--compose-control-h);
    min-height: var(--compose-control-h);
    max-width: var(--compose-control-h);
    max-height: var(--compose-control-h);
  }

  .chat-input .ttl-select {
    margin: 0;
    max-width: 4.75rem;
    min-height: 36px;
    font-size: 0.7rem;
  }

  .chat-input .btn-send,
  .chat-input .btn-composer-send {
    margin: 0;
    min-height: var(--compose-control-h);
    height: var(--compose-control-h);
    min-width: var(--compose-control-h);
  }

  .composer-surface .msg-input-rich,
  .composer-surface #msg-input,
  .chat-input textarea,
  .chat-input .msg-input-rich {
    min-width: 0;
    flex: 1 1 auto;
    min-height: calc(var(--compose-control-h) - 6px);
    height: auto;
    max-height: 132px;
    padding: 0.45rem 0.25rem;
    box-sizing: border-box;
    line-height: 1.35;
    font-size: 16px;
  }

  .chat-input .msg-input-rich.msg-input-rich--multiline {
    line-height: 1.35;
    padding-top: 0.4rem;
    padding-bottom: 0.4rem;
    max-height: 132px;
    height: auto;
  }

  /* Tools row: touch 44px — không áp dụng cho nút 📎 cạnh ô gửi */
  .chat-input-tools .btn-icon {
    min-height: var(--touch-min);
    min-width: var(--touch-min);
  }

  .typing-indicator {
    min-height: 0;
    padding: 0.15rem var(--phone-gutter) 0;
  }

  #app.chat-mode {
    padding-bottom: 0;
  }

  .channel-host,
  .group-host {
    max-height: none;
  }

  .user-list {
    flex: 1 1 auto;
    min-height: 8rem;
  }

  .toast-host {
    top: calc(env(safe-area-inset-top, 0px) + var(--app-top, 0px) + 0.5rem);
    right: max(0.65rem, env(safe-area-inset-right, 0px));
    left: max(0.65rem, env(safe-area-inset-left, 0px));
    max-width: none;
    width: auto;
  }

  .toast {
    padding: 0.75rem 0.9rem;
    border-radius: 14px;
  }

  .toast-body {
    -webkit-line-clamp: 6;
    line-clamp: 6;
  }
}

/* Touch phones (kể cả landscape rộng tới ~1100) */
@media (hover: none) and (pointer: coarse) and (max-width: 1100px) {
  .chat-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .layout-splitter {
    display: none !important;
  }
  .chat-toolbar {
    display: flex;
  }

  .btn-toolbar-settings {
    display: none !important;
  }

  .chat-area > .btn-menu--midrail {
    display: inline-flex;
    position: absolute;
    left: max(0.2rem, env(safe-area-inset-left, 0px));
    top: 50%;
    right: auto;
    bottom: auto;
    transform: translateY(-50%);
    z-index: 8;
    width: 52px;
    height: 52px;
    min-width: 52px;
    min-height: 52px;
    padding: 0;
    margin: 0;
    border-radius: 14px;
    border: 1.5px solid color-mix(in srgb, var(--accent) 55%, var(--border));
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 18%, var(--surface));
    box-shadow:
      0 2px 10px color-mix(in srgb, var(--accent) 22%, transparent),
      0 0 0 1px color-mix(in srgb, var(--accent) 12%, transparent);
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
    cursor: grab;
    user-select: none;
  }

  .chat-area > .btn-menu--midrail.is-dragging {
    cursor: grabbing;
  }

  .chat-area > .btn-menu--midrail .btn-menu-bars {
    width: 1.45rem;
    height: 1.1rem;
    pointer-events: none;
    background:
      linear-gradient(currentColor, currentColor) center top / 100% 3.5px no-repeat,
      linear-gradient(currentColor, currentColor) center / 100% 3.5px no-repeat,
      linear-gradient(currentColor, currentColor) center bottom / 100% 3.5px no-repeat;
  }

  .btn-sidebar-edge {
    display: none !important;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: var(--app-top, 0px);
    height: var(--app-height, 100dvh);
    bottom: auto;
    width: min(300px, calc(100vw - 3.25rem));
    max-width: calc(100% - 3.25rem);
    z-index: 200;
    transform: translateX(-105%);
    transition: transform 0.25s ease;
    padding-top: var(--sat);
    padding-bottom: var(--sab);
    padding-left: var(--sal);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.55);
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    top: var(--app-top, 0px);
    height: var(--app-height, 100dvh);
    z-index: 190;
    background: rgba(0, 0, 0, 0.5);
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
  .sidebar-backdrop.visible {
    display: block;
  }
  .chat-layout.sidebar-open > .chat-area {
    pointer-events: none;
  }

  .btn,
  button.btn,
  .voice-call-btn,
  .btn-voice-call,
  .btn-video-call {
    min-height: var(--touch-min);
  }
}

/* xs — fold cover / SE cũ / máy rất hẹp (≤359) */
@media (max-width: 359px) {
  :root {
    --phone-gutter: 0.45rem;
    --phone-header-pad-y: 0.45rem;
  }

  .sidebar {
    width: min(280px, 92vw);
  }

  .chat-header-text h3,
  .chat-header-text .peer-nick {
    font-size: 0.92rem;
  }

  .btn-voice-call {
    padding: 0.4rem 0.45rem;
    font-size: 0.75rem;
  }

  /* xs: icon-only — Voice + Video không tràn header */
  .btn-voice-call .btn-voice-call-label,
  .btn-video-call .btn-voice-call-label {
    display: none;
  }

  .btn-voice-call,
  .btn-video-call {
    min-width: var(--touch-min);
    padding: 0.4rem;
  }

  .chat-appearance-compact {
    max-width: 6.5rem;
    font-size: 0.72rem;
  }

  .voice-call-card {
    padding: 1.1rem 0.85rem;
  }

  .voice-call-btn {
    min-width: 0;
    flex: 1 1 calc(50% - 0.4rem);
  }

  .message {
    max-width: min(92%, calc(100% - 1.25rem));
    font-size: 0.85rem;
  }
}

/* sm — Android baseline (≥360) */
@media (min-width: 360px) and (max-width: 1023px) {
  :root {
    --phone-gutter: 0.65rem;
  }
}

/* md — iPhone chuẩn (≥390) */
@media (min-width: 390px) and (max-width: 1023px) {
  :root {
    --phone-gutter: 0.75rem;
  }

  .sidebar {
    width: min(340px, 86vw);
  }
}

/* lg-phone — Pro / Plus / flagship (≥393 đã gộp trong 390; tinh chỉnh ≥412) */
@media (min-width: 412px) and (max-width: 1023px) {
  .sidebar {
    width: min(360px, 84vw);
  }

  .message {
    max-width: min(85%, 22rem);
  }
}

/* xl-phone — Pro Max / Ultra (≥430) */
@media (min-width: 430px) and (max-width: 1023px) {
  :root {
    --phone-gutter: 0.85rem;
  }

  .voice-call-card {
    width: min(380px, 100%);
  }
}

/* Header hẹp (≤520) — giữ nút Gọi / appearance không vỡ */
@media (max-width: 520px) {
  .chat-header {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
  }

  .chat-header-main {
    flex: 1;
    min-width: 0;
  }

  .chat-header-appearance {
    width: auto;
  }

  .chat-appearance-compact {
    flex: 0 1 auto;
    max-width: 9.5rem;
  }

  .btn-voice-call {
    padding: 0.45rem 0.55rem;
    font-size: 0.8rem;
  }
}

/* Landscape phone — chiều cao ngắn */
@media (max-width: 1023px) and (orientation: landscape) and (max-height: 500px) {
  .chat-header {
    padding-top: 0.35rem;
    padding-bottom: 0.35rem;
  }

  .voice-call-overlay {
    align-items: flex-start;
    padding-top: max(0.5rem, var(--sat));
  }

  .voice-call-card {
    padding: 0.85rem 1rem;
  }

  .voice-call-status {
    margin-bottom: 0.75rem;
  }

  .login-screen {
    justify-content: flex-start;
    gap: 0.75rem;
    padding-top: max(0.5rem, var(--sat));
  }
}

/* Tablet (≥768) — sidebar drawer rộng hơn, vẫn 1 cột tới desktop */
@media (min-width: 768px) and (max-width: 1023px) {
  .sidebar {
    width: min(380px, 42vw);
  }

  .message {
    max-width: min(75%, 26rem);
  }
}

/* Toast tin mới — luôn dưới status bar / notch (viewport-fit=cover) */
.toast-host {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + var(--app-top, 0px) + 0.65rem);
  right: max(1rem, env(safe-area-inset-right, 0px));
  left: auto;
  z-index: 10040;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(360px, calc(100vw - 2rem));
  pointer-events: none;
  box-sizing: border-box;
}

.toast {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
  width: 100%;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  text-align: left;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  min-height: var(--touch-min, 44px);
}

.toast-in {
  opacity: 1;
  transform: translateY(0);
}

.toast-out {
  opacity: 0;
  transform: translateY(-8px);
}

.toast-message {
  border-left: 3px solid var(--accent, #00e676);
}

.toast-title {
  font-weight: 700;
  font-size: 0.9rem;
  line-height: 1.25;
  max-width: 100%;
  word-break: break-word;
}

.toast-body {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.35;
  max-width: 100%;
  /* Tràn xuống nhiều dòng — không cắt 1 dòng dưới status bar */
  white-space: normal;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 5;
  line-clamp: 5;
  word-break: break-word;
}

html[dir="rtl"] .toast-host {
  right: auto;
  left: max(1rem, env(safe-area-inset-left, 0px));
}

/* Module panels — Channel / Group tách riêng */
.channel-host,
.group-host {
  border-top: 1px solid var(--border, rgba(255, 255, 255, 0.08));
  margin-top: 0.35rem;
  padding-top: 0.35rem;
  max-height: 28vh;
  overflow: auto;
}

.module-panel {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0 0.5rem 0.5rem;
}

.module-panel-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.module-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.module-actions .btn-secondary {
  font-size: 0.72rem;
  padding: 0.3rem 0.45rem;
}

.module-list .meta {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.chat-header .meta {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 400;
}

/* Part 21/22 — channel manage sheet */
.channel-manage-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.channel-manage-sheet {
  width: min(520px, 100%);
  max-height: min(88dvh, 720px);
  overflow: auto;
  background: var(--bg-elevated, var(--bg, #1a1a1e));
  color: var(--text, #eee);
  border-radius: 12px 12px 0 0;
  padding: 0.75rem 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.channel-manage-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.channel-manage-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.channel-manage-tabs button.active {
  outline: 2px solid var(--accent, #3b82f6);
}

.channel-manage-body {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.channel-manage-body label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.8rem;
}

.channel-manage-body input:not([type='checkbox']),
.channel-manage-body textarea {
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border, #333);
  background: var(--bg, #111);
  color: inherit;
  font: inherit;
  resize: vertical;
}

.channel-manage-body .cm-check {
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
}

.cm-member,
.cm-audit {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border, #2a2a2e);
  font-size: 0.82rem;
}

.cm-member-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  align-items: center;
}

.cm-member-actions button,
.cm-member-actions select {
  font-size: 0.7rem;
  padding: 0.2rem 0.35rem;
}

@media (min-width: 720px) {
  .channel-manage-overlay {
    align-items: center;
  }
  .channel-manage-sheet {
    border-radius: 12px;
  }
}

.cd-filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
}

.cd-filters input,
.cd-filters select {
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border, #333);
  background: var(--bg, #111);
  color: inherit;
  font-size: 0.8rem;
}

.cd-card {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border, #2a2a2e);
}

.cd-card-media {
  flex: 1;
  min-width: 0;
}

.cd-card-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.cd-card .room-banner {
  margin-bottom: 0.35rem;
  max-height: 72px;
}

.cd-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.room-avatar {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
  background: color-mix(in srgb, var(--accent, #3d8bfd) 25%, transparent);
}

.room-avatar-sm {
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

.room-avatar-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text);
}

.room-banner {
  width: 100%;
  max-height: 96px;
  overflow: hidden;
  border-radius: 0;
  flex-shrink: 0;
}

.room-banner img {
  width: 100%;
  height: 96px;
  object-fit: cover;
  display: block;
}

.cd-cat-btn {
  margin: 0.15rem;
}

.stage-honest {
  font-size: 0.72rem;
  margin: 0;
  line-height: 1.35;
}

.stage-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

@media (max-width: 640px) {
  .stage-cols {
    grid-template-columns: 1fr;
  }
}

.im-token {
  display: block;
  font-size: 0.65rem;
  word-break: break-all;
  margin-top: 0.2rem;
  opacity: 0.85;
}

/* =============================================================================
   IRChat desktop app (Electron) — Zalo-style shell
   - No PWA install chrome (user already has native app)
   - Full content below OS title bar; settings via sidebar ⚙ + tray
   - CẤM position:fixed + height:% chain (Electron Windows → #app = 0 → màn đen)
   - Dùng absolute + inset:0 bám cửa sổ BrowserWindow
   ============================================================================= */
html.irchat-desktop {
  font-family: system-ui, 'Segoe UI', sans-serif !important;
}

html.irchat-desktop,
html.irchat-desktop body {
  height: 100vh !important;
  height: 100dvh !important;
  width: 100% !important;
  margin: 0 !important;
  overflow: hidden !important;
}

html.irchat-desktop.chat-mode,
html.irchat-desktop.chat-mode body,
html.irchat-desktop body.chat-mode,
html.irchat-desktop body:has(.chat-layout) {
  position: relative !important;
  inset: auto !important;
  top: auto !important;
  left: auto !important;
  right: auto !important;
  bottom: auto !important;
  overflow: hidden !important;
  height: 100vh !important;
  height: 100dvh !important;
  width: 100% !important;
  max-height: none !important;
}

html.irchat-desktop #app {
  position: relative !important;
  width: 100% !important;
  height: 100vh !important;
  height: 100dvh !important;
  min-height: 100vh !important;
  min-height: 100dvh !important;
  max-height: none !important;
  display: flex !important;
  flex-direction: column !important;
}

html.irchat-desktop #app.chat-mode {
  position: absolute !important;
  inset: 0 !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: auto !important;
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  z-index: 1;
}

html.irchat-desktop #app.chat-mode .chat-layout {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  height: 100% !important;
  width: 100% !important;
}

html.irchat-desktop .desktop-fatal-overlay {
  position: absolute !important;
  inset: 0 !important;
  z-index: 2147483646;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: #0a0f1a;
  color: #e8e8f0;
  text-align: center;
  box-sizing: border-box;
}

html.irchat-desktop .btn-pwa-topbar,
html.irchat-desktop .login-footer-install,
html.irchat-desktop .login-footer-desktop-dl,
html.irchat-desktop .pwa-install-chip,
html.irchat-desktop #pwa-install-banner {
  display: none !important;
}

/* Legal long docs: desktop shell locks body overflow — scroll inside #app */
html.irchat-desktop:has(.legal-page),
html.irchat-desktop:has(.legal-page) body {
  overflow: hidden !important;
}

html.irchat-desktop #app:has(.legal-page) {
  overflow-x: hidden !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  align-items: stretch;
}

html.irchat-desktop #app:has(.legal-page) > .legal-page {
  flex: 0 0 auto;
  width: 100%;
  max-width: 720px;
  margin-left: auto;
  margin-right: auto;
}

html.irchat-desktop .legal-page {
  min-height: auto;
  height: auto;
  max-height: none;
  padding-bottom: calc(4rem + env(safe-area-inset-bottom, 0px));
}

html.irchat-desktop .login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
}

html.irchat-desktop .login-main {
  flex: 1;
  justify-content: center;
}

html.irchat-desktop .login-card {
  width: min(100%, 420px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

html.irchat-desktop.chat-mode .chat-layout {
  border-radius: 0;
}

/* Desktop app ≥1024: sidebar always visible — Zalo 3-pane feel */
@media (min-width: 1024px) {
  html.irchat-desktop.chat-mode .chat-layout {
    grid-template-columns: minmax(260px, var(--sidebar-width)) 5px minmax(0, 1fr);
  }

  html.irchat-desktop.chat-mode .sidebar {
    border-right: 1px solid var(--border);
  }

  html.irchat-desktop.chat-mode .btn-menu--midrail {
    display: none !important;
  }

  html.irchat-desktop.chat-mode .sidebar-backdrop {
    display: none !important;
  }
}

html.irchat-desktop.chat-mode .desktop-lite-shell {
  min-height: 0;
  height: 100%;
}

html.irchat-desktop .desktop-lite-shell .sidebar-self-name {
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 0.25rem;
}

html.irchat-desktop .desktop-lite-input .chat-input-compose {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px;
  min-height: 48px;
}

html.irchat-desktop .desktop-lite-input .msg-input-plain {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  max-height: 120px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elevated, #121820);
  color: inherit;
  padding: 8px 10px;
  font: inherit;
  line-height: 1.4;
}

html.irchat-desktop .msg-input-plain-desktop {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  max-height: 120px;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elevated, #121820);
  color: inherit;
  padding: 8px 10px;
  font: inherit;
  line-height: 1.4;
  overflow-y: auto;
}

html.irchat-desktop .desktop-lite-input .chat-input-tools-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 6px 8px 0;
}

html.irchat-desktop .emoji-quick-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px 8px 8px;
}

html.irchat-desktop .desktop-lite-p2p {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0;
}

html.irchat-desktop .desktop-lite-p2p-btn {
  flex: 1 1 auto;
  min-height: 44px;
  min-width: 44px;
}

html.irchat-desktop .desktop-lite-p2p-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Software raster path on Windows portable — blur/filters/shadows can kill renderer (-36861). */
html.irchat-desktop *,
html.irchat-desktop *::before,
html.irchat-desktop *::after {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  filter: none !important;
}

html.irchat-desktop.chat-mode *,
html.irchat-desktop.chat-mode *::before,
html.irchat-desktop.chat-mode *::after {
  box-shadow: none !important;
  background-image: none !important;
}

/* DOC 18: freeze #chat-area at the 0.1.26 grid. P2P controls are shell siblings. */
html.irchat-desktop .chat-layout > .desktop-chat-stack {
  grid-column: 3;
  grid-row: 1;
  position: relative;
  min-width: 0;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
}

html.irchat-desktop .desktop-chat-stack > .chat-area {
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: 100%;
}

html.irchat-desktop .desktop-p2p-header,
html.irchat-desktop .desktop-p2p-composer {
  position: absolute;
  z-index: 6;
  display: flex;
  align-items: center;
  pointer-events: none;
}

html.irchat-desktop .desktop-p2p-header {
  top: 0.45rem;
  right: 1rem;
  gap: 0.4rem;
}

html.irchat-desktop .desktop-p2p-composer {
  /* Attach moved into chat-input--v2 (+); host stays empty. */
  display: none !important;
}

html.irchat-desktop .desktop-p2p-header > *,
html.irchat-desktop .desktop-p2p-composer > * {
  pointer-events: auto;
}

html.irchat-desktop .desktop-chat-stack .chat-header {
  /* Room for Voice + Video official chrome on the right */
  padding-right: 15.5rem;
}

html.irchat-desktop .desktop-chat-stack .chat-input--v2 .chat-input-compose {
  padding-left: 0;
}

html.irchat-desktop .desktop-chat-stack .desktop-lite-input .chat-input-compose {
  padding-left: 0;
}

html.irchat-desktop[dir='rtl'] .desktop-p2p-header {
  right: auto;
  left: 1rem;
}

html.irchat-desktop[dir='rtl'] .desktop-p2p-composer {
  right: calc(1.5rem + 10px);
  left: auto;
}

html.irchat-desktop[dir='rtl'] .desktop-chat-stack .chat-header {
  padding-right: 1rem;
  padding-left: 15.5rem;
}

html.irchat-desktop[dir='rtl']
  .desktop-chat-stack
  .desktop-lite-input
  .chat-input-compose {
  padding-right: 62px;
  padding-left: 10px;
}

/* Official Call/File chrome — plain controls (không .btn-voice-call color-mix). */
html.irchat-desktop .desktop-lite-call-btn,
html.irchat-desktop .desktop-lite-attach-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elevated, #121820);
  color: inherit;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

html.irchat-desktop .desktop-lite-video-btn {
  background: color-mix(in srgb, #38bdf8 18%, var(--bg-elevated, #121820));
  border-color: color-mix(in srgb, #38bdf8 45%, var(--border));
  color: #7dd3fc;
}

html.irchat-desktop .desktop-lite-attach-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

@media (max-width: 1023px) {
  html.irchat-desktop .chat-layout > .desktop-chat-stack {
    grid-column: 1;
    grid-row: 1;
  }

  html.irchat-desktop .chat-layout.sidebar-open > .desktop-chat-stack {
    pointer-events: none;
  }
}


/* —— Media editor (pre-send) —— */
.media-editor-overlay {
  position: fixed;
  inset: 0;
  z-index: 12000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: max(0.5rem, env(safe-area-inset-top)) max(0.5rem, env(safe-area-inset-right))
    max(0.5rem, env(safe-area-inset-bottom)) max(0.5rem, env(safe-area-inset-left));
  background: rgba(0, 0, 0, 0.55);
  box-sizing: border-box;
}
@media (min-width: 768px) {
  .media-editor-overlay { align-items: center; }
}
.media-editor-card {
  width: min(520px, 100%);
  max-height: min(92dvh, 900px);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.85rem;
  border-radius: 16px;
  background: var(--surface, #15151f);
  border: 1px solid var(--border, #303044);
  color: var(--text, #e8eef7);
  box-sizing: border-box;
  overflow: auto;
}
.media-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.media-editor-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}
.media-editor-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  max-height: min(48dvh, 420px);
  background: #0a0f1a;
  border-radius: 12px;
  overflow: hidden;
}
.media-editor-stage-wrap {
  position: relative;
  display: inline-flex;
  max-width: 100%;
  max-height: min(48dvh, 420px);
}
.media-editor-bake-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  visibility: hidden;
}
.media-editor-draw-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}
.media-editor-draw-layer.is-crop {
  cursor: nwse-resize;
}
.media-editor-draw-layer.is-text {
  cursor: grab;
}
.media-editor-preview {
  max-width: 100%;
  max-height: min(48dvh, 420px);
  object-fit: contain;
  transition: filter 0.15s ease, opacity 0.12s ease;
}
.media-editor-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
.media-editor-tool-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  width: 100%;
}
.media-editor-btn.is-active {
  outline: 2px solid var(--accent, #00e676);
}
.media-editor-hint {
  width: 100%;
  font-size: 0.75rem;
  color: var(--text-muted, #a9b6c9);
  margin: 0;
}
.media-editor-timeline {
  position: relative;
  width: 100%;
  height: 36px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  overflow: visible;
  touch-action: none;
  min-height: 44px;
}
.media-editor-timeline-bar {
  position: absolute;
  inset: 8px 0;
  border-radius: 4px;
  background: linear-gradient(90deg, rgba(0, 230, 118, 0.15), rgba(0, 230, 118, 0.05));
}
.media-editor-timeline-sel {
  position: absolute;
  top: 8px;
  bottom: 8px;
  background: rgba(0, 230, 118, 0.35);
  border-left: 2px solid var(--accent, #00e676);
  border-right: 2px solid var(--accent, #00e676);
  min-width: 4px;
}
.media-editor-timeline-handle {
  position: absolute;
  top: 50%;
  width: 14px;
  height: 28px;
  margin-top: -14px;
  border-radius: 4px;
  background: #00e676;
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35);
  touch-action: none;
}
.media-editor-timeline-handle--start {
  left: -7px;
}
.media-editor-timeline-handle--end {
  right: -7px;
}
.media-editor-album-item.is-dragging {
  opacity: 0.55;
}
.media-editor-album-drag {
  cursor: grab;
  color: var(--text-muted, #a9b6c9);
  min-width: 28px;
  text-align: center;
  user-select: none;
}
.media-editor-album-list {
  list-style: none;
  margin: 0;
  padding: 0.5rem 1rem;
  max-height: min(40dvh, 320px);
  overflow: auto;
  width: 100%;
}
.media-editor-album-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  min-height: 44px;
  font-size: 0.85rem;
}
.media-editor-album-ops {
  display: flex;
  gap: 0.25rem;
}
.media-editor-filter {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1 1 140px;
  font-size: 0.8rem;
  color: var(--text-muted, #a9b6c9);
}
.media-editor-filter input[type='range'] {
  width: 100%;
  min-height: 44px;
}
.media-editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.media-editor-btn {
  min-height: 44px;
  flex: 1 1 auto;
  padding: 0.55rem 0.75rem;
}
.media-editor-btn--primary {
  background: var(--accent, #00e676);
  color: #04140a;
  font-weight: 700;
}
.file-export-progress {
  border-top-color: color-mix(in srgb, var(--accent, #00e676) 45%, var(--border));
}

.voice-call-beauty-bar {
  display: none !important; /* legacy center dump — replaced by .voice-call-fx */
}

/* Video call effects: right rail + one tray (TikTok-style, không che giữa màn). */
.voice-call-fx {
  position: absolute;
  right: max(0.5rem, env(safe-area-inset-right, 0px));
  top: 50%;
  transform: translateY(-50%);
  z-index: 6;
  display: flex;
  flex-direction: row-reverse;
  align-items: center;
  gap: 0.4rem;
  max-width: min(46vw, 11.5rem);
  pointer-events: none;
}
.voice-call-fx > * {
  pointer-events: auto;
}
html[dir='rtl'] .voice-call-fx {
  right: auto;
  left: max(0.5rem, env(safe-area-inset-left, 0px));
  flex-direction: row;
}
.voice-call-fx-rail {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.voice-call-fx-cat {
  min-height: 44px;
  min-width: 44px;
  padding: 0.35rem 0.55rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(10, 15, 26, 0.82);
  color: #e8eef7;
  font-size: 0.72rem;
  font-weight: 700;
  writing-mode: horizontal-tb;
  text-align: center;
  line-height: 1.15;
}
.voice-call-fx-cat.is-active {
  background: #00e676;
  color: #04140a;
  border-color: transparent;
}
.voice-call-fx-tray {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  max-height: min(52dvh, 20rem);
  overflow-y: auto;
  padding: 0.3rem;
  border-radius: 14px;
  background: rgba(10, 15, 26, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.12);
  -webkit-overflow-scrolling: touch;
}
.voice-call-fx-tray[hidden] {
  display: none !important;
}
.voice-call-beauty-chip {
  min-height: 44px;
  min-width: 44px;
  padding: 0.4rem 0.65rem;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.2);
  background: rgba(10,15,26,.75);
  color: #e8eef7;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}
.voice-call-beauty-chip.is-active {
  background: #00e676;
  color: #04140a;
  border-color: transparent;
}

/* Video stage — full bleed under card/controls */
.voice-call-overlay--video .voice-call-video-stage {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: #000;
}
.voice-call-overlay--video .voice-call-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
}
.voice-call-overlay--video .voice-call-video--local {
  inset: auto;
  right: max(0.75rem, env(safe-area-inset-right, 0px));
  bottom: calc(5.75rem + env(safe-area-inset-bottom, 0px));
  width: min(28vw, 7.5rem);
  height: min(38vw, 10rem);
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  z-index: 2;
  object-fit: cover;
}
.voice-call-overlay--video .voice-call-card {
  position: relative;
  z-index: 3;
  background: transparent;
  box-shadow: none;
  pointer-events: none;
}
.voice-call-overlay--video .voice-call-card .voice-call-actions,
.voice-call-overlay--video .voice-call-card button {
  pointer-events: auto;
}

@media (max-width: 430px) {
  .voice-call-fx {
    top: auto;
    bottom: calc(5.25rem + env(safe-area-inset-bottom, 0px));
    transform: none;
    right: 50%;
    translate: 50% 0;
    max-width: min(96vw, 22rem);
    flex-direction: column;
    align-items: stretch;
  }
  html[dir='rtl'] .voice-call-fx {
    left: 50%;
    right: auto;
    translate: -50% 0;
  }
  .voice-call-fx-rail {
    flex-direction: row;
    justify-content: center;
    flex-wrap: wrap;
  }
  .voice-call-fx-tray {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    max-height: 22dvh;
  }
}
