:root {
  /* Dark is the committed default for this app (a messaging product reads
     better dark-first, independent of OS setting) — see the
     prefers-color-scheme:light override below for users whose OS prefers
     light, rather than the more common light-default-with-dark-override
     pattern. */
  --bg: #0d0f13;
  --bg-sidebar: #121419;
  --surface: #181b21;
  --surface-raised: #20242c;
  --text: #eceef1;
  --text-soft: #8b92a0;
  --text-faint: #5b6270;
  --accent: #6670f6;
  --accent-contrast: #ffffff;
  --bubble-own: #5a63ee;
  --bubble-own-text: #ffffff;
  --bubble-theirs: #20242c;
  --bubble-theirs-text: #eceef1;
  --line: #262a33;
  --danger: #ef4444;
  --online: #2fd16b;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 10px 32px rgba(0, 0, 0, 0.4);
  --name-sat: 70%;
  --name-light: 68%;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f4f7;
    --bg-sidebar: #ffffff;
    --surface: #ffffff;
    --surface-raised: #f0f1f4;
    --text: #15171c;
    --text-soft: #686f7a;
    --text-faint: #9aa0aa;
    --accent: #4a4ddb;
    --bubble-own: #4a4ddb;
    --bubble-theirs: #ffffff;
    --bubble-theirs-text: #15171c;
    --line: #e4e6eb;
    --shadow-sm: 0 1px 2px rgba(20, 20, 30, 0.08);
    --shadow-md: 0 8px 24px rgba(20, 20, 30, 0.12);
    --shadow-lg: 0 10px 32px rgba(20, 20, 30, 0.16);
    --name-sat: 60%;
    --name-light: 38%;
    color-scheme: light;
  }
}

/* An explicit choice from the theme-toggle button (stored in localStorage,
   applied as data-theme on <html>) overrides prefers-color-scheme in
   either direction — every token must already be set on the bare :root
   above, these blocks only ever redefine, never introduce a token. */
:root[data-theme='light'] {
  --bg: #f3f4f7;
  --bg-sidebar: #ffffff;
  --surface: #ffffff;
  --surface-raised: #f0f1f4;
  --text: #15171c;
  --text-soft: #686f7a;
  --text-faint: #9aa0aa;
  --accent: #4a4ddb;
  --bubble-own: #4a4ddb;
  --bubble-theirs: #ffffff;
  --bubble-theirs-text: #15171c;
  --line: #e4e6eb;
  --shadow-sm: 0 1px 2px rgba(20, 20, 30, 0.08);
  --shadow-md: 0 8px 24px rgba(20, 20, 30, 0.12);
  --shadow-lg: 0 10px 32px rgba(20, 20, 30, 0.16);
  --name-sat: 60%;
  --name-light: 38%;
  color-scheme: light;
}
:root[data-theme='dark'] {
  --bg: #0d0f13;
  --bg-sidebar: #121419;
  --surface: #181b21;
  --surface-raised: #20242c;
  --text: #eceef1;
  --text-soft: #8b92a0;
  --text-faint: #5b6270;
  --accent: #6670f6;
  --bubble-own: #5a63ee;
  --bubble-own-text: #ffffff;
  --bubble-theirs: #20242c;
  --bubble-theirs-text: #eceef1;
  --line: #262a33;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 10px 32px rgba(0, 0, 0, 0.4);
  --name-sat: 70%;
  --name-light: 68%;
  color-scheme: dark;
}
/* True-black AMOLED variant (design idea #1) — same structure as dark,
   just every surface pushed to pure/near-pure black so OLED screens can
   switch those pixels off entirely. A 3rd position in the theme-toggle
   cycle (light -> dark -> amoled -> light), not a separate toggle. */
:root[data-theme='amoled'] {
  --bg: #000000;
  --bg-sidebar: #000000;
  --surface: #0a0a0a;
  --surface-raised: #141414;
  --text: #eceef1;
  --text-soft: #8b92a0;
  --text-faint: #5b6270;
  --accent: #6670f6;
  --bubble-own: #5a63ee;
  --bubble-own-text: #ffffff;
  --bubble-theirs: #141414;
  --bubble-theirs-text: #eceef1;
  --line: #1c1c1c;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.6);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 10px 32px rgba(0, 0, 0, 0.65);
  --name-sat: 70%;
  --name-light: 68%;
  color-scheme: dark;
}

/* Accent color picker (design idea #3) — layered on top of whichever
   theme is active (light/dark/amoled all define --accent above; these
   just override it again, same two tokens only, so every other theme
   token stays exactly as that theme set it). */
:root[data-accent='blue'] { --accent: #2f80ed; --accent-contrast: #ffffff; --bubble-own: #2f80ed; }
:root[data-accent='green'] { --accent: #1db954; --accent-contrast: #ffffff; --bubble-own: #1aa34a; }
:root[data-accent='red'] { --accent: #e5484d; --accent-contrast: #ffffff; --bubble-own: #e5484d; }
:root[data-accent='purple'] { --accent: #9b5de5; --accent-contrast: #ffffff; --bubble-own: #8a3fd1; }

/* Smooth light/dark transition (idea #7): a toggle swaps every surface/
   text/accent token at once — without this, that's an instant, jarring
   flash. prefers-reduced-motion gets no transition, same as everywhere
   else in this file. */
@media (prefers-reduced-motion: no-preference) {
  html, body, .bubble, .chat-header, .settings-panel, .people-row,
  .thread-item, .composer-icon-btn, .chat-composer {
    transition: background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease;
  }
}

/* A `display` rule on the same element (e.g. .login-screen{display:flex})
   otherwise beats the browser's native [hidden] hiding, since both are
   normal-weight author/UA rules at equal specificity — so every screen
   toggled via `el.hidden = true/false` in this app needs this to actually
   disappear instead of just losing its flex layout. */
[hidden] { display: none !important; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; }

/* ---------- Twemoji (design request): every emoji character on the page
   becomes one of these <img class="emoji">, via js/emojiRender.js — sized
   to sit on the text baseline the way a native emoji glyph would,
   regardless of what size font-size it's dropped into (a message bubble,
   a 1.3rem picker button, a tiny badge). */
img.emoji {
  height: 1.2em;
  width: 1.2em;
  margin: 0 0.03em 0 0.08em;
  vertical-align: -0.2em;
  display: inline-block;
}

/* ---------- avatars ---------- */
.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
  /* Telegram-style two-tone gradient (design request) — avatarHtml()/
     renderAvatarInto() in chat-ui.js set --avatar-gradient per person; a
     handful of hardcoded non-person icons (🛟 admin, 🔖 saved messages,
     etc.) never set it and fall back to the old solid --avatar-hue circle. */
  background: var(--avatar-gradient, hsl(var(--avatar-hue, 220), 58%, 45%));
  letter-spacing: 0.02em;
}
.avatar.sm { width: 38px; height: 38px; font-size: 0.82rem; }
.avatar.xs { width: 30px; height: 30px; font-size: 0.7rem; }
.avatar.lg { width: 96px; height: 96px; font-size: 2rem; }

/* ---------- in-app browser warning ---------- */
.in-app-warning {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  padding: 24px 20px;
  background: var(--bg);
  color: var(--text);
  overflow-y: auto;
}
/* [hidden] and .in-app-warning both have specificity (0,0,1,0), so without
   this the class's own `display: flex` wins the tie and the full-screen
   overlay shows on EVERY page load, in every browser, blacking out the
   entire visitor site regardless of whether it was actually hidden. */
.in-app-warning[hidden] { display: none; }
.in-app-warning p { margin: 0; line-height: 1.5; max-width: 480px; }
.in-app-warning-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 6px;
}

/* ---------- login / onboarding ---------- */
.login-screen {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-inline: 16px;
  background:
    radial-gradient(900px 500px at 12% -8%, rgba(91, 140, 255, 0.16), transparent 58%),
    radial-gradient(700px 420px at 92% 108%, rgba(91, 140, 255, 0.10), transparent 55%),
    var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 40px 32px;
  text-align: center;
  max-width: 360px;
  width: 100%;
  box-shadow: var(--shadow-md), 0 0 0 1px rgba(255, 255, 255, 0.02) inset;
}
.login-card .brand-mark {
  width: 52px;
  height: 52px;
  margin: 0 auto 18px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(155deg, var(--accent), var(--bubble-own));
  box-shadow: var(--shadow-sm);
}
.login-card .brand-mark svg { width: 28px; height: 28px; }
.login-card h1 { margin: 0 0 8px; font-size: 1.6rem; letter-spacing: -0.01em; }
.login-card p { color: var(--text-soft); margin: 0 0 24px; line-height: 1.5; }
.btn-google {
  background: linear-gradient(155deg, var(--accent), var(--bubble-own));
  color: var(--accent-contrast);
  border: none;
  border-radius: 12px;
  padding: 13px 20px;
  font-size: 0.98rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: filter 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
  box-shadow: 0 4px 14px rgba(91, 140, 255, 0.28);
}
.btn-google:hover { filter: brightness(1.08); box-shadow: 0 6px 18px rgba(91, 140, 255, 0.36); }
.btn-google:active { transform: scale(0.98); }

.login-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0 14px;
  color: var(--text-faint);
  font-size: 0.8rem;
}
.login-divider::before, .login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}

#emailAuthForm {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#emailAuthForm input {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  /* 16px, not smaller — iOS Safari auto-zooms the whole page in on focus
     for any text input under 16px, which read as "noqulay" (uncomfortable)
     on phones. Same reasoning applies to every other input/textarea
     font-size fixed alongside this one. */
  font-size: 1rem;
  background: var(--surface-raised);
  color: var(--text);
  width: 100%;
}
#emailAuthForm input:focus { outline: none; border-color: var(--accent); }

.btn-ghost-full {
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}
.btn-ghost-full:hover { background: var(--line); }
.btn-ghost-full:disabled { opacity: 0.6; cursor: default; }

.login-error {
  color: var(--danger);
  font-size: 0.82rem;
  margin: 0;
  text-align: left;
}

.login-toggle-mode {
  margin: 14px 0 0 !important;
  font-size: 0.85rem;
  color: var(--text-soft);
}
.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0 0 0 4px;
}

#profileSetupForm {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#profileSetupForm input {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px 14px;
  font-size: 1rem;
  background: var(--surface-raised);
  color: var(--text);
  width: 100%;
}
#profileSetupForm input:focus {
  outline: none;
  border-color: var(--accent);
}
#profileSetupForm input::placeholder { color: var(--text-faint); }

/* ---------- shared chat chrome ---------- */
.chat-screen, .admin-screen {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.admin-screen { flex-direction: row; }

.chat-header {
  position: relative;
  /* Without an explicit z-index here, .chat-header and .chat-container
     (the message feed right below it) both sit at the default stacking
     level, so DOM order alone decided who painted on top — the feed,
     being later in markup, silently ate clicks meant for
     .header-more-menu (an absolutely-positioned child of THIS element)
     whenever the popover's box extended past the header's own bottom
     edge into the feed's area. */
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  flex-shrink: 0;
  transition: box-shadow 0.15s ease;
}
/* A touch of the app's accent color on the navbar itself (design
   request), echoing the same thin gradient bar already used on the auth
   screen's card — subtle, not a full color wash, so it stays readable in
   every theme/accent combination. */
.chat-header::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 35%, transparent), transparent 70%);
}
/* ---------- "⋯" header menu (design request): consolidates search/media/
   settings into one popover instead of 3 permanent icons ---------- */
.header-more-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 10px;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
  z-index: 20;
  min-width: 170px;
}
.header-more-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  color: var(--text);
  padding: 11px 14px;
  font-size: 0.88rem;
  cursor: pointer;
}
.header-more-item:hover { background: var(--surface); }
/* Scroll shadow (design request) — toggled via JS (.chat-feed scroll
   listener) instead of always-on, so it only appears once there's
   something to actually indicate ("content continues above"). */
.chat-header.scrolled { box-shadow: 0 2px 10px -4px rgba(0, 0, 0, 0.25); }
#chatHeaderAvatar { flex-shrink: 0; cursor: default; }
.chat-header-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.chat-title { font-weight: 650; font-size: 1rem; line-height: 1.25; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-subtitle { font-size: 0.78rem; color: var(--text-soft); display: inline-flex; align-items: center; gap: 5px; }
.subtitle-online-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--online); flex-shrink: 0; position: relative; }
.subtitle-online-dot::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--online);
  animation: online-pulse-kf 1.8s ease-out infinite;
}
@keyframes online-pulse-kf {
  0% { opacity: 0.55; transform: scale(1); }
  100% { opacity: 0; transform: scale(2.6); }
}
@media (prefers-reduced-motion: reduce) {
  .subtitle-online-dot::after { animation: none; display: none; }
}

/* ---------- ripple feedback on tappable buttons (design idea #14) ----------
   One shared utility class (applyRipple() in index.html/admin.html adds it
   on pointerdown to whatever was pressed) rather than per-button markup —
   a span absolutely positioned at the press point, scaling out and fading. */
.ripple-span {
  position: absolute;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.25;
  transform: scale(0);
  animation: ripple-kf 0.5s ease-out;
  pointer-events: none;
}
@keyframes ripple-kf {
  to { transform: scale(2.6); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .ripple-span { display: none; }
}

/* ---------- avatar ring: online/offline at a glance (design idea #22) ---------- */
.avatar-ring-wrap { position: relative; display: inline-flex; }
.avatar-ring-wrap::after {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  border: 2px solid var(--text-faint);
  opacity: 0.4;
}
.avatar-ring-wrap.online::after { border-color: var(--online); opacity: 1; }

/* ---------- search-result matched-text highlight (design idea #17) ---------- */
.search-match-highlight { background: color-mix(in srgb, var(--accent) 35%, transparent); color: inherit; border-radius: 3px; padding: 0 1px; }

/* ---------- floating "new message" action button (design idea #18) ---------- */
#peoplePanel .settings-panel { position: relative; }
.people-fab {
  position: absolute;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-contrast, #fff);
  font-size: 1.4rem;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}
.people-fab:active { transform: scale(0.94); }

/* ---------- tick: single -> double transition (design idea #30) ---------- */
.bubble-tick-2 {
  display: inline-block;
  max-width: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-width 0.2s ease, opacity 0.2s ease;
  vertical-align: top;
}
.bubble-tick.read .bubble-tick-2 { max-width: 10px; opacity: 1; }

/* ---------- composer "/" quick-reply shortcuts (design idea #29) ---------- */
.quick-reply-menu {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: calc(100% + 6px);
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
  z-index: 4;
}
.quick-reply-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  color: var(--text);
  padding: 10px 14px;
  font-size: 0.86rem;
  cursor: pointer;
}
.quick-reply-item:hover, .quick-reply-item.active { background: var(--surface); }
.quick-reply-item b { color: var(--accent); }

.sticker-suggest-strip {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: calc(100% + 6px);
  display: flex;
  gap: 6px;
  overflow-x: auto;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  padding: 8px;
  z-index: 4;
}
.sticker-suggest-btn {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  background: none;
  border: none;
  border-radius: 10px;
  padding: 4px;
  cursor: pointer;
}
.sticker-suggest-btn:hover { background: var(--surface); }
.sticker-suggest-btn img { width: 100%; height: 100%; object-fit: contain; }
.attach-menu { left: 8px; right: auto; width: max-content; }
.chat-header-spacer { flex: 1; }

.btn-ghost {
  background: none;
  border: 1px solid var(--line);
  color: var(--text-soft);
  border-radius: 10px;
  padding: 7px 13px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}
.btn-ghost:hover { background: var(--surface-raised); color: var(--text); }

.header-icon-btn {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-soft);
  flex-shrink: 0;
  transition: background 0.15s ease;
}
.header-icon-btn:hover { background: var(--surface-raised); }

.mobile-back-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px 4px 0;
}

.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--bg);
}

.chat-feed {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

/* ---------- pinned message bar ---------- */
.pinned-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  background: var(--surface-raised);
  border-bottom: 1px solid var(--line);
  font-size: 0.85rem;
  flex-shrink: 0;
}
.pinned-icon { flex-shrink: 0; }
.pinned-text {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-soft);
}
/* ---------- translate bar + per-message translation block ---------- */
.translate-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  background: var(--surface-raised);
  border-bottom: 1px solid var(--line);
  font-size: 0.85rem;
  flex-shrink: 0;
}
.translate-bar-icon { flex-shrink: 0; font-weight: 700; color: var(--accent); }
.translate-bar-label { flex: 1; min-width: 0; color: var(--text-soft); }
.translate-bar-close {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 0.9rem;
  flex-shrink: 0;
}

/* ---------- multi-select (design request: bulk delete, Telegram-style) ---------- */
.selection-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  background: var(--surface-raised);
  border-bottom: 1px solid var(--line);
  font-size: 0.88rem;
  font-weight: 600;
  flex-shrink: 0;
}
.selection-bar-count { flex: 1; min-width: 0; }
.selection-bar-close, .selection-bar-delete {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  flex-shrink: 0;
}
.selection-bar-close { color: var(--text-faint); font-size: 0.95rem; }
.selection-bar-delete { color: var(--danger); font-weight: 650; }
/* Checkbox overlay — present but invisible (width:0) until .selecting is
   on the row, so it slides in from the gutter rather than just popping
   into place; an own-message row's checkbox sits on the right (same side
   as the bubble), a theirs-row's on the left. */
.msg-select-check {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--text-faint);
  background: var(--surface);
  transition: width 0.15s ease, opacity 0.15s ease;
  opacity: 0;
  overflow: hidden;
}
/* Placed in whichever side is actually EMPTY for that row — "own" bubbles
   are right-aligned (empty space on the left), "theirs" are left-aligned
   (empty space on the right) — not the side the bubble itself hugs,
   which has no room since the bubble already reaches that edge. */
.msg-row.own .msg-select-check { left: -28px; }
.msg-row.theirs .msg-select-check { right: -28px; }
.msg-row.selecting .msg-select-check { width: 22px; opacity: 1; }
.msg-row.selecting.own .msg-select-check { left: 2px; }
.msg-row.selecting.theirs .msg-select-check { right: 2px; }
.msg-row.selected .msg-select-check {
  background: var(--accent);
  border-color: var(--accent);
}
.msg-row.selected .msg-select-check::after {
  content: '✓';
  display: block;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}
.msg-row.selecting .bubble { opacity: 0.94; }
.msg-row.selected .bubble { opacity: 1; box-shadow: 0 0 0 2px var(--accent), var(--shadow-sm); }
.bubble-translation {
  margin-top: 6px;
  padding-top: 6px;
  padding-left: 9px;
  border-top: 1px solid rgba(127, 127, 127, 0.25);
  border-left: 2px solid var(--accent);
  font-style: italic;
  font-size: 0.88em;
  opacity: 0.88;
}
.pinned-unpin {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 0.9rem;
  flex-shrink: 0;
}
.pinned-unpin:hover { color: var(--text); }

/* ---------- jump-to-latest pill ---------- */
.jump-latest-pill {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  z-index: 5;
}
.jump-latest-pill:hover { filter: brightness(1.08); }

/* ---------- load older messages (pagination) ---------- */
.load-older-btn {
  display: block;
  margin: 2px auto 10px;
  background: var(--surface-raised);
  color: var(--text-soft);
  border: none;
  border-radius: 999px;
  padding: 7px 16px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}
.load-older-btn:hover { color: var(--text); }
.load-older-btn:disabled { opacity: 0.6; cursor: default; }

/* ---------- composer context bar (reply preview / edit mode) ---------- */
.composer-context-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--surface-raised);
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}
.composer-context-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  font-size: 0.82rem;
}
.composer-context-text b { color: var(--accent); font-size: 0.75rem; font-weight: 650; }
.composer-context-text span {
  color: var(--text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.composer-context-cancel {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 0.95rem;
  flex-shrink: 0;
}
.composer-context-cancel:hover { color: var(--text); }

.chat-feed-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 0.9rem;
  text-align: center;
  padding: 24px;
}

/* ---------- skeleton loaders (message feed + thread list) ---------- */
.feed-skeleton { display: flex; flex-direction: column; gap: 10px; padding: 4px 0; }
.skeleton-row { display: flex; }
.skeleton-row.own { justify-content: flex-end; }
.skeleton-row.theirs { justify-content: flex-start; }
.skeleton-bubble {
  width: 180px;
  height: 36px;
  border-radius: 18px;
  background: var(--surface-raised);
}
.skeleton-bubble.short { width: 110px; }
.skeleton-thread-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; }
.skeleton-avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--surface-raised); flex-shrink: 0; }
.skeleton-lines { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.skeleton-line { height: 10px; border-radius: 5px; background: var(--surface-raised); }
.skeleton-line.w60 { width: 60%; }
.skeleton-line.w40 { width: 40%; }
@media (prefers-reduced-motion: no-preference) {
  .skeleton-bubble, .skeleton-avatar, .skeleton-line {
    background-image: linear-gradient(90deg, transparent, rgba(255,255,255,0.06), transparent);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.4s ease-in-out infinite;
  }
}
@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.msg-row { display: flex; margin: 3px 0; position: relative; }
.msg-row.own { justify-content: flex-end; }
.msg-row.theirs { justify-content: flex-start; }

/* ---------- swipe-to-reply hint icon ---------- */
.bubble-swipe-reply-hint {
  position: absolute;
  left: 4px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.1rem;
  color: var(--accent);
  opacity: 0;
  pointer-events: none;
}

.bubble {
  max-width: 74%;
  padding: 9px 13px 8px;
  border-radius: 18px;
  position: relative;
  font-size: 0.93rem;
  line-height: 1.42;
  word-break: break-word;
  box-shadow: var(--shadow-sm), 0 1px 0 rgba(255, 255, 255, 0.04) inset;
}
.msg-row.own .bubble {
  background: var(--bubble-own);
  color: var(--bubble-own-text);
  border-bottom-right-radius: 5px;
}
.msg-row.theirs .bubble {
  background: var(--bubble-theirs);
  color: var(--bubble-theirs-text);
  border-bottom-left-radius: 5px;
}

/* ---------- bubble tail ----------
   A small triangular notch pointing at the sender's side, Telegram-style
   — only on the LAST bubble of a consecutive-same-sender group (grouped
   messages share one tail at the bottom, same logic as the existing
   border-radius-on-.grouped rule below). Previously shown only on
   hover-capable devices (desktop) — on touch/phones, where most of this
   app's actual traffic is, there was NO tail at all, a real gap against
   "Telegram'dek" (bubbles are one of Telegram's most recognizable visual
   details) — now shown everywhere, plus a touch of shadow for depth. */
.msg-row.own .bubble::after,
.msg-row.theirs .bubble::after {
  content: '';
  position: absolute;
  bottom: 0;
  width: 9px;
  height: 11px;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.1));
}
.msg-row.own .bubble::after {
  right: -7px;
  background: var(--bubble-own);
  clip-path: polygon(0 0, 0% 100%, 100% 100%);
}
.msg-row.theirs .bubble::after {
  left: -7px;
  background: var(--bubble-theirs);
  clip-path: polygon(100% 0, 0% 100%, 100% 100%);
}
.msg-row.own.grouped .bubble::after,
.msg-row.theirs.grouped .bubble::after {
  display: none;
}

.bubble-time {
  display: block;
  font-size: 0.68rem;
  opacity: 0.65;
  margin-top: 4px;
  text-align: right;
}
.bubble-tick { margin-left: 4px; }
.bubble-tick.read { color: #8fd1ff; opacity: 1; }
/* The tick element is rebuilt from scratch on every re-render (the whole
   bubble is), so a CSS `transition` has no "before" state to animate
   from on the same node — this uses `animation` instead, which plays
   once whenever a freshly-inserted .read tick appears, giving the same
   "just turned blue" feel without needing persistent DOM nodes. */
@keyframes tick-read-flash {
  from { color: var(--text-faint); transform: scale(0.85); }
  to { color: #8fd1ff; transform: scale(1); }
}
@media (prefers-reduced-motion: no-preference) {
  .bubble-tick.read { animation: tick-read-flash 0.4s ease; display: inline-block; }
}

/* ---------- animated typing-indicator dots (replaces a static "…") ---------- */
.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-right: 5px;
  vertical-align: middle;
}
.typing-dots span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.4;
}
@media (prefers-reduced-motion: no-preference) {
  .typing-dots span { animation: typing-bounce 1.1s ease-in-out infinite; }
  .typing-dots span:nth-child(2) { animation-delay: 0.15s; }
  .typing-dots span:nth-child(3) { animation-delay: 0.3s; }
}
@keyframes typing-bounce {
  0%, 60%, 100% { opacity: 0.4; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}

/* ---------- first-run onboarding overlay (shown once per device) ---------- */
.onboarding-overlay {
  position: fixed;
  inset: 0;
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 6, 9, 0.6);
  padding: 20px;
  padding-top: calc(20px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
}
.onboarding-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 22px 20px;
  animation: onboarding-card-in-kf 0.35s cubic-bezier(0.2, 0.8, 0.3, 1);
}
@keyframes onboarding-card-in-kf {
  from { opacity: 0; transform: translateY(18px) scale(0.96); }
  to { opacity: 1; transform: none; }
}
.onboarding-card h2 { margin: 0 0 18px; font-size: 1.25rem; text-align: center; }
/* Staggered entrance (design request) — each item fades/slides in a beat
   after the last, nth-child driving the delay so no JS timers are needed. */
.onboarding-item {
  opacity: 0;
  animation: onboarding-item-in-kf 0.35s ease forwards;
  animation-delay: calc(0.15s + var(--item-i, 0) * 0.08s);
}
.onboarding-item:nth-child(2) { --item-i: 1; }
.onboarding-item:nth-child(3) { --item-i: 2; }
.onboarding-item:nth-child(4) { --item-i: 3; }
@keyframes onboarding-item-in-kf {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .onboarding-card, .onboarding-item { animation: none; opacity: 1; }
}
.onboarding-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 16px;
}
.onboarding-icon { font-size: 1.5rem; flex-shrink: 0; line-height: 1.3; }
.onboarding-item strong { display: block; font-size: 0.92rem; margin-bottom: 2px; }
.onboarding-item p { margin: 0; font-size: 0.82rem; color: var(--text-soft); line-height: 1.4; }
.onboarding-card .btn-google { width: 100%; margin-top: 6px; }

/* ---------- double-tap heart-react burst particles ---------- */
.heart-burst-particle {
  position: fixed;
  z-index: 9000;
  font-size: 1.1rem;
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: heart-burst-kf 0.7s ease-out forwards;
  animation-delay: var(--delay, 0ms);
}
@keyframes heart-burst-kf {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(0.8);
  }
}

.bubble-reply {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 5px 9px;
  margin-bottom: 6px;
  border-left: 2px solid currentColor;
  opacity: 0.85;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.12);
  font-size: 0.82rem;
}
.bubble-reply-sender { font-weight: 650; font-size: 0.74rem; }
.bubble-reply-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.bubble-forwarded-label {
  font-size: 0.72rem;
  font-weight: 650;
  opacity: 0.75;
  font-style: italic;
  margin-bottom: 3px;
}

.file-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.14);
  text-decoration: none;
  color: inherit;
  min-width: 180px;
  max-width: 260px;
}
.file-card-icon { font-size: 1.6rem; flex-shrink: 0; }
.file-card-info { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.file-card-name {
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-card-size { font-size: 0.72rem; opacity: 0.75; }

.link-preview-card {
  display: flex;
  flex-direction: column;
  margin-top: 8px;
  border-radius: 10px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.14);
  text-decoration: none;
  color: inherit;
  max-width: 280px;
}
.link-preview-img { width: 100%; max-height: 140px; object-fit: cover; display: block; }
.link-preview-text { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; }
.link-preview-title { font-size: 0.82rem; font-weight: 650; }
.link-preview-desc { font-size: 0.76rem; opacity: 0.8; line-height: 1.3; }

.bubble-deleted {
  font-style: italic;
  color: var(--text-faint);
  background: var(--surface-raised);
  box-shadow: none;
  animation: bubble-deleted-fade-kf 0.25s ease;
}
@keyframes bubble-deleted-fade-kf {
  from { opacity: 0.3; }
  to { opacity: 1; }
}

/* ---------- reactions (Telegram-style pill, overlaps the bubble corner) ---------- */
.msg-row.has-reaction { margin-bottom: 11px; }
.bubble-reactions {
  position: absolute;
  bottom: -10px;
  display: flex;
  gap: 3px;
  z-index: 2;
}
.msg-row.own .bubble-reactions { right: 10px; }
.msg-row.theirs .bubble-reactions { left: 10px; }
.reaction-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 23px;
  height: 23px;
  padding: 0 6px;
  border: 2px solid var(--bg);
  border-radius: 12px;
  background: var(--surface-raised);
  box-shadow: var(--shadow-sm);
  font-size: 0.82rem;
  line-height: 1;
  cursor: default;
}
.reaction-chip.mine { cursor: pointer; background: var(--accent-soft, var(--surface-raised)); }
.reaction-chip.mine:active { transform: scale(0.92); }

/* ---------- Telegram-style press/right-click context menu ---------- */
.msg-context-menu {
  position: fixed;
  z-index: 1000;
  min-width: 200px;
  max-width: 260px;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-lg, 0 8px 28px rgba(0, 0, 0, 0.28));
  padding: 8px;
  opacity: 0;
  transform: scale(0.94);
  transform-origin: top left;
  transition: opacity 0.1s ease, transform 0.1s ease;
}
.msg-context-menu.ctx-menu-open { opacity: 1; transform: scale(1); }
.ctx-react-row {
  display: flex;
  justify-content: space-between;
  gap: 2px;
  padding: 2px 2px 8px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--line);
}
.ctx-react-btn {
  background: none;
  border: none;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  padding: 3px;
  border-radius: 8px;
}
.ctx-react-btn:hover, .ctx-react-btn:active { background: var(--surface); }
.ctx-react-more { color: var(--text-faint); font-weight: 700; font-size: 1.1rem; }
.ctx-react-row-expanded { display: block; border-bottom: none; padding: 0; margin-bottom: 4px; }
.ctx-react-grid {
  max-height: 180px;
  grid-template-columns: repeat(auto-fill, minmax(30px, 1fr));
  padding: 4px;
}
.ctx-menu-list { display: flex; flex-direction: column; }
.ctx-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  border: none;
  text-align: left;
  font-size: 0.86rem;
  color: var(--text);
  padding: 8px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.ctx-menu-item:hover { background: var(--surface); }
.ctx-menu-item.danger { color: var(--danger, #e5484d); }
.ctx-menu-icon { width: 18px; text-align: center; font-size: 0.9rem; flex-shrink: 0; }

.bubble-media { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.bubble-media-img, .bubble-media-video {
  max-width: min(280px, 60vw);
  border-radius: 14px;
  display: block;
}
.bubble-media-videonote {
  width: 170px;
  height: 170px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  border: 2px solid rgba(255, 255, 255, 0.15);
}

.voice-note { display: flex; align-items: center; gap: 8px; min-width: 150px; }
.voice-play {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.16);
  color: inherit;
  cursor: pointer;
  font-size: 0.9rem;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.msg-row.theirs .voice-play { background: rgba(255, 255, 255, 0.08); }
.voice-wave {
  width: 120px;
  height: 24px;
  cursor: pointer;
  /* Own (sent) bubbles sit on --bubble-own; theirs on --bubble-theirs —
     each side needs its own played/unplayed contrast since the two
     backgrounds aren't the same lightness. */
  --wave-played: #fff;
  --wave-unplayed: rgba(255, 255, 255, 0.38);
}
.msg-row.theirs .voice-wave {
  --wave-played: var(--accent);
  --wave-unplayed: var(--text-faint);
}
.voice-duration { font-size: 0.82rem; opacity: 0.85; }
.voice-speed-btn {
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.14);
  border: none;
  border-radius: 8px;
  color: inherit;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 6px;
  cursor: pointer;
}
.msg-row.theirs .voice-speed-btn { background: var(--surface-raised); }
.voice-speed-btn:hover { filter: brightness(1.15); }

/* ---------- composer ----------
   Reverted back to a plain, full-width bar (design feedback: the floating
   "pill" version — margin from the edges, rounded all around, blurred
   background — didn't read right on a real phone; the actual Telegram
   reference the user compared against uses a flat full-width composer,
   not a floating pill, so this matches that instead now. */
.chat-composer {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  box-shadow: 0 -1px 0 var(--line), 0 -6px 16px -8px rgba(0, 0, 0, 0.18);
  flex-shrink: 0;
  z-index: 5;
}
.chat-composer input[type='text'] {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 11px 17px;
  font-size: 0.93rem;
  background: var(--surface-raised);
  color: var(--text);
  min-width: 0;
}
.chat-composer input[type='text']:focus { outline: none; border-color: var(--accent); }
.chat-composer input[type='text']::placeholder { color: var(--text-faint); }

.composer-icon-btn {
  background: none;
  border: none;
  font-size: 1.15rem;
  cursor: pointer;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-soft);
  transition: background 0.15s ease, color 0.15s ease;
}
.composer-icon-btn:hover { background: var(--surface-raised); color: var(--text); }
.composer-icon-btn.recording {
  background: var(--danger);
  color: #fff;
  animation: composer-recording-pulse-kf 1.1s ease-in-out infinite;
}
/* Same merged mic button, just a distinct color while it's the VIDEO
   gesture (quick tap) rather than the voice one (hold) — so a glance at
   the button alone says which kind of message is being recorded. */
.composer-icon-btn.recording.recording-video {
  background: var(--accent);
  animation-name: composer-recording-pulse-kf;
}
@keyframes composer-recording-pulse-kf {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 35%, transparent); }
  50% { box-shadow: 0 0 0 7px transparent; }
}
@media (prefers-reduced-motion: reduce) {
  .composer-icon-btn.recording { animation: none; }
}
/* Icon-only (not a "Yuborish" text pill) and shown only while the
   composer has text — see updateComposerMode() in chat-ui.js. Together
   with hiding the voice/video-note buttons in that same state, this is
   the fix for the textarea repeatedly getting squeezed down to ~1
   character wide on phones: at most 3 icon-slots ever compete with the
   textarea at once now, never all 5 (attach+emoji+video+voice+send). */
.composer-send {
  width: 40px;
  height: 40px;
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  font-size: 1.05rem;
  font-weight: 600;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px -2px color-mix(in srgb, var(--accent) 55%, transparent);
  transition: filter 0.15s ease, transform 0.1s ease;
}
.composer-send:hover { filter: brightness(1.08); }
.composer-send:active { transform: scale(0.96); }

/* ---------- admin: sidebar ---------- */
.thread-list {
  width: 340px;
  flex-shrink: 0;
  border-right: 1px solid var(--line);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
}
.thread-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--line);
  font-weight: 650;
  font-size: 1.05rem;
  gap: 10px;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.thread-list-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.thread-list-header-actions .btn-ghost {
  font-size: 0.76rem;
}
.thread-list-items {
  flex: 1;
  overflow-y: auto;
}
.thread-list-empty {
  padding: 32px 20px;
  color: var(--text-faint);
  font-size: 0.88rem;
  text-align: center;
}

.thread-item {
  display: flex;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-left: 3px solid transparent;
  padding: 11px 14px;
  cursor: pointer;
  color: var(--text);
  gap: 11px;
  align-items: center;
  transition: background 0.12s ease;
}
.thread-item:hover { background: var(--surface); }
.thread-item.active { background: var(--surface); border-left-color: var(--accent); }

.thread-item-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.thread-item-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.thread-item-name {
  font-weight: 600;
  font-size: 0.93rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.thread-item-time {
  font-size: 0.72rem;
  color: var(--text-faint);
  flex-shrink: 0;
}
.thread-item-username {
  color: var(--text-soft);
  font-size: 0.78rem;
}
.thread-item-preview {
  color: var(--text-soft);
  font-size: 0.83rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- admin: responsive collapse ---------- */
.mobile-back-btn { display: none; }

@media (max-width: 760px) {
  .admin-screen { position: relative; overflow: hidden; }
  .thread-list { width: 100%; border-right: none; }
  .admin-screen .chat-container { display: none; }
  .admin-screen.chat-open .thread-list { display: none; }
  .admin-screen.chat-open .chat-container { display: flex; width: 100%; }
  .mobile-back-btn { display: inline-flex; align-items: center; justify-content: center; }
}

@media (min-width: 761px) {
  .admin-screen .chat-container { display: flex; }
}

/* ======================================================================
   Design pass 2 — animation, lightbox, grouping, backgrounds, presence,
   a11y, fonts, logo, stat cards. Appended by the fork that finished what
   an earlier stalled fork left half-done (chat-ui.js was already fully
   rewritten to expect these classes; this section is what makes them
   actually render instead of showing up unstyled).
   ====================================================================== */

/* ---------- fonts ---------- */
.chat-title, .login-card h1, .brand-title {
  font-family: 'Sora', -apple-system, 'Segoe UI', Roboto, sans-serif;
}

/* ---------- app logo mark (original abstract monogram, not any real
   messaging app's actual logo) ---------- */
.brand-mark {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.brand-mark svg { width: 100%; height: 100%; display: block; }
/* Back arrow (design request) — shown instead of the brand mark while a
   peer conversation is open, giving a way "back" to the conversation
   list that doesn't depend on remembering the 👥 icon means that. */
.chat-back-btn { font-size: 1.6rem; font-weight: 600; line-height: 1; flex-shrink: 0; }
/* Same "‹" glyph as the chat's own back button — these panels became
   full-screen pages on phone (design request to match Telegram, which
   never shows a centered modal card for Chats/Settings/Profile), so a
   back arrow reads right where "✕" used to. */
#peopleCloseBtn, #settingsCloseBtn, #profileViewCloseBtn { font-size: 1.6rem; font-weight: 600; }

/* ---------- entrance animation ----------
   Split in two (idea #2 send / #3 receive) so each direction reads
   differently: a sent bubble pops up from where the composer sits
   (bigger rise, slight overshoot settle); an incoming one gets a
   small attention bounce since it wasn't triggered by the viewer's own
   action and needs to draw the eye. Both replace the single shared
   msg-enter-kf this app used before. */
@keyframes msg-enter-own-kf {
  0% { opacity: 0; transform: translateY(16px) scale(0.9); }
  70% { opacity: 1; transform: translateY(-2px) scale(1.015); }
  100% { opacity: 1; transform: none; }
}
@keyframes msg-enter-theirs-kf {
  0% { opacity: 0; transform: translateY(6px) scale(0.96); }
  55% { opacity: 1; transform: translateY(-3px) scale(1.02); }
  80% { transform: translateY(1px) scale(0.995); }
  100% { transform: none; }
}
.msg-row.own.msg-enter { animation: msg-enter-own-kf 0.26s cubic-bezier(0.2, 0.8, 0.3, 1.1); }
.msg-row.theirs.msg-enter { animation: msg-enter-theirs-kf 0.32s ease-out; }
@media (prefers-reduced-motion: reduce) {
  .msg-row.msg-enter { animation: none; }
}

/* ---------- consecutive-message grouping ---------- */
.msg-row { margin: 10px 0 2px; transition: margin 0.1s ease; }
.msg-row.grouped { margin-top: 2px; }
.msg-row.grouped .bubble-time { display: none; }
.msg-row.own.grouped .bubble { border-bottom-right-radius: 18px; }
.msg-row.theirs.grouped .bubble { border-bottom-left-radius: 18px; }

/* ---------- date separator pill ---------- */
.date-sep { display: flex; justify-content: center; margin: 14px 0 6px; }
.date-sep span {
  background: var(--surface-raised);
  color: var(--text-soft);
  font-size: 0.74rem;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 999px;
}

/* ---------- empty state icon ---------- */
.chat-feed-empty-icon { font-size: 2.2rem; margin-bottom: 10px; opacity: 0.8; }

/* ---------- sending-state pending dot (replaces the timestamp briefly) ---------- */
.bubble-pending-dot {
  display: inline-block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.6;
  animation: pending-pulse 1s ease-in-out infinite;
}
@keyframes pending-pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.9; }
}

/* ---------- lightbox (full-screen photo viewer) ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 9, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 200;
  padding: 24px;
}
.lightbox.open { opacity: 1; pointer-events: auto; }
.lightbox img {
  max-width: min(92vw, 900px);
  max-height: 90vh;
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  cursor: zoom-out;
  touch-action: none;
  transition: transform 0.15s ease-out;
}
.lightbox video {
  max-width: min(92vw, 900px);
  max-height: 90vh;
  border-radius: 10px;
  box-shadow: var(--shadow-md);
}

/* ---------- media gallery (grid of a thread's photos/videos) ---------- */
.media-gallery {
  position: fixed;
  inset: 0;
  z-index: 180;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 6, 9, 0.6);
  padding: 16px;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}
.media-gallery.open { opacity: 1; pointer-events: auto; }
.media-gallery-panel {
  width: 100%;
  max-width: 480px;
  max-height: 100%;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow-md);
}
.media-gallery-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  font-weight: 650;
  position: sticky;
  top: 0;
  background: var(--surface);
}
.media-gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  padding: 3px;
}
.media-gallery-tile {
  aspect-ratio: 1;
  background: var(--surface-raised);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  color: var(--text-soft);
}
.media-gallery-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.media-gallery-tile-video {
  background: linear-gradient(155deg, var(--surface-raised), var(--bg));
}
.media-gallery-play {
  font-size: 1.3rem;
  color: var(--accent-contrast, #fff);
  opacity: 0.85;
}
.media-gallery-empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--text-soft);
  font-size: 0.9rem;
  grid-column: 1 / -1;
}
/* Friendlier empty states (design request) — a big icon above the text,
   shared by .people-empty and .media-gallery-empty; each call site picks
   its own emoji via this span, so "no conversations" and "no search
   results" don't look identical. */
.empty-state-icon { display: block; font-size: 2.2rem; margin-bottom: 8px; line-height: 1; }

/* Search panel reuses .media-gallery/.media-gallery-panel/.media-gallery-header/
   .media-gallery-empty above for the overlay shell + close button. */
.search-panel-panel {
  max-width: 420px;
  display: flex;
  flex-direction: column;
}
.search-panel-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: var(--surface-raised);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 1rem;
  color: var(--text);
  margin-right: 8px;
}
.search-panel-input:focus { outline: 2px solid var(--accent); }
.search-panel-tabs {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
}
.search-panel-tab {
  flex: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-soft);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
}
.search-panel-tab.active {
  background: var(--accent);
  color: var(--accent-contrast, #fff);
  border-color: var(--accent);
}
.search-panel-results {
  overflow-y: auto;
  max-height: 60vh;
  display: flex;
  flex-direction: column;
}
.search-panel-result {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
  color: var(--text);
}
.search-panel-result:hover { background: var(--surface-raised); }
.search-panel-result-icon { font-size: 1.1rem; flex: none; }
.search-panel-result-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.search-panel-result-snippet {
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}
.search-panel-result-meta {
  font-size: 0.76rem;
  color: var(--text-soft);
}
.search-jump-highlight { animation: search-jump-flash-kf 1.5s ease; }
@keyframes search-jump-flash-kf {
  0%, 100% { background: transparent; }
  15% { background: color-mix(in srgb, var(--accent) 25%, transparent); }
}

/* ---------- drag-and-drop overlay ---------- */
.drop-zone {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(91, 140, 255, 0.12);
  border: 2px dashed var(--accent);
  border-radius: 14px;
  margin: 8px;
  color: var(--accent);
  font-weight: 650;
  font-size: 1rem;
  pointer-events: none;
  z-index: 20;
}
.chat-container { position: relative; }

/* ---------- online-status dot on an avatar ---------- */
.avatar-wrap { position: relative; display: inline-flex; flex-shrink: 0; }
.presence-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--online);
  border: 2px solid var(--bg-sidebar);
  display: none;
}
.presence-dot.online { display: block; }

/* ---------- chat-feed backgrounds: subtle gradient wash + faint pattern ---------- */
.chat-container {
  background:
    radial-gradient(900px 500px at 85% -8%, rgba(91, 140, 255, 0.07), transparent 55%),
    var(--bg);
}
.chat-feed {
  background-image: radial-gradient(var(--line) 1px, transparent 1px);
  background-size: 22px 22px;
  background-position: -2px -2px;
  background-attachment: local;
}

/* ---------- wallpaper presets: a per-device chat-feed background choice,
   stored in localStorage like theme/a11y, applied via [data-wallpaper] on
   <html>. "default" is intentionally the existing look above (no override
   needed), the rest replace both the .chat-container wash and the
   .chat-feed pattern together so they stay visually coherent. ---------- */
:root[data-wallpaper='sunset'] .chat-container {
  background: linear-gradient(165deg, rgba(255, 150, 90, 0.10), rgba(255, 90, 140, 0.06) 45%, transparent 75%), var(--bg);
}
:root[data-wallpaper='sunset'] .chat-feed {
  background-image: radial-gradient(rgba(255, 150, 90, 0.16) 1px, transparent 1px);
  background-size: 24px 24px;
}
:root[data-wallpaper='ocean'] .chat-container {
  background: linear-gradient(165deg, rgba(60, 190, 200, 0.10), rgba(60, 120, 220, 0.07) 45%, transparent 75%), var(--bg);
}
:root[data-wallpaper='ocean'] .chat-feed {
  background-image: radial-gradient(rgba(60, 190, 200, 0.16) 1px, transparent 1px);
  background-size: 24px 24px;
}
:root[data-wallpaper='lines'] .chat-container { background: var(--bg); }
:root[data-wallpaper='lines'] .chat-feed {
  background-image: repeating-linear-gradient(135deg, var(--line) 0 1px, transparent 1px 26px);
  background-size: auto;
}
:root[data-wallpaper='mono'] .chat-container { background: var(--bg); }
:root[data-wallpaper='mono'] .chat-feed { background-image: none; }
:root[data-wallpaper='custom'] .chat-container { background: var(--bg); }
:root[data-wallpaper='custom'] .chat-feed {
  background-image: var(--custom-wallpaper-url, none);
  background-size: cover;
  background-position: center;
  background-attachment: local;
}
/* Animated gradient wallpaper (design idea #5) — a slow drifting hue wash
   behind the feed instead of a static image; paused automatically under
   reduced-motion since it's pure decoration, never load-bearing. */
:root[data-wallpaper='gradient-animated'] .chat-container { background: var(--bg); }
:root[data-wallpaper='gradient-animated'] .chat-feed {
  background-image: linear-gradient(120deg,
    color-mix(in srgb, var(--accent) 16%, transparent),
    transparent 35%,
    color-mix(in srgb, var(--accent) 10%, transparent) 65%,
    transparent 85%);
  background-size: 220% 220%;
  animation: wallpaper-drift-kf 18s ease-in-out infinite;
}
@keyframes wallpaper-drift-kf {
  0% { background-position: 0% 30%; }
  50% { background-position: 100% 70%; }
  100% { background-position: 0% 30%; }
}
@media (prefers-reduced-motion: reduce) {
  :root[data-wallpaper='gradient-animated'] .chat-feed { animation: none; background-position: 30% 40%; }
}

/* ---------- per-conversation wallpaper override (design request) ----------
   Same presets as above, but keyed on [data-wallpaper] set directly on
   .chat-container itself (one specific peer chat) instead of inherited
   from :root (the global default) — index.html sets/clears this
   attribute on open() based on that conversation's own
   conversations/{id}.wallpaper_by.<uid> field. No "custom image" option
   here (scoped to the preset patterns only, to avoid needing a whole
   second per-chat image-upload flow). */
.chat-container[data-wallpaper='default'] { background: var(--bg) !important; }
.chat-container[data-wallpaper='default'] .chat-feed { background-image: none !important; }
.chat-container[data-wallpaper='sunset'] {
  background: linear-gradient(165deg, rgba(255, 150, 90, 0.10), rgba(255, 90, 140, 0.06) 45%, transparent 75%), var(--bg) !important;
}
.chat-container[data-wallpaper='sunset'] .chat-feed {
  background-image: radial-gradient(rgba(255, 150, 90, 0.16) 1px, transparent 1px) !important;
  background-size: 24px 24px !important;
}
.chat-container[data-wallpaper='ocean'] {
  background: linear-gradient(165deg, rgba(60, 190, 200, 0.10), rgba(60, 120, 220, 0.07) 45%, transparent 75%), var(--bg) !important;
}
.chat-container[data-wallpaper='ocean'] .chat-feed {
  background-image: radial-gradient(rgba(60, 190, 200, 0.16) 1px, transparent 1px) !important;
  background-size: 24px 24px !important;
}
.chat-container[data-wallpaper='lines'] { background: var(--bg) !important; }
.chat-container[data-wallpaper='lines'] .chat-feed {
  background-image: repeating-linear-gradient(135deg, var(--line) 0 1px, transparent 1px 26px) !important;
  background-size: auto !important;
}
.chat-container[data-wallpaper='mono'] { background: var(--bg) !important; }
.chat-container[data-wallpaper='mono'] .chat-feed { background-image: none !important; }
.chat-container[data-wallpaper='gradient-animated'] { background: var(--bg) !important; }
.chat-container[data-wallpaper='gradient-animated'] .chat-feed {
  background-image: linear-gradient(120deg,
    color-mix(in srgb, var(--accent) 16%, transparent),
    transparent 35%,
    color-mix(in srgb, var(--accent) 10%, transparent) 65%,
    transparent 85%) !important;
  background-size: 220% 220% !important;
  animation: wallpaper-drift-kf 18s ease-in-out infinite;
}

.settings-row-icon-label-only { display: flex; align-items: center; gap: 12px; padding: 11px 10px 2px; font-size: 0.92rem; }
.wallpaper-swatches { display: flex; gap: 10px; padding: 6px 10px 12px; flex-wrap: wrap; }
.wallpaper-swatch {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 2px solid var(--line);
  cursor: pointer;
  padding: 0;
  background: var(--bg);
}
.wallpaper-swatch.active { border-color: var(--accent); }
.wallpaper-swatch[data-wallpaper-option='default'] { background-image: radial-gradient(var(--line) 1px, transparent 1px); background-size: 8px 8px; }
.wallpaper-swatch[data-wallpaper-option='sunset'] { background: linear-gradient(165deg, #ff965a, #ff5a8c); }
.wallpaper-swatch[data-wallpaper-option='ocean'] { background: linear-gradient(165deg, #3cbec8, #3c78dc); }
.wallpaper-swatch[data-wallpaper-option='lines'] { background-image: repeating-linear-gradient(135deg, var(--line) 0 1px, transparent 1px 8px); }
.wallpaper-swatch[data-wallpaper-option='mono'] { background: var(--surface-raised); }
.wallpaper-swatch[data-wallpaper-option='gradient-animated'] {
  background: linear-gradient(120deg, var(--accent), transparent 60%, var(--accent));
  background-size: 220% 220%;
}
.accent-swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--line);
  cursor: pointer;
  padding: 0;
}
.accent-swatch.active { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.wallpaper-swatch-custom {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: var(--text-faint);
  background: var(--surface-raised);
  background-image: var(--custom-wallpaper-url, none);
  background-size: cover;
  background-position: center;
}
.wallpaper-swatch-custom.active { color: var(--accent); }
/* ---------- glassmorphism on headers, with a solid fallback ---------- */
.chat-header, .thread-list-header {
  background: color-mix(in srgb, var(--surface) 88%, transparent);
}
@supports (backdrop-filter: blur(10px)) or (-webkit-backdrop-filter: blur(10px)) {
  .chat-header, .thread-list-header {
    backdrop-filter: blur(14px) saturate(1.1);
    -webkit-backdrop-filter: blur(14px) saturate(1.1);
  }
}

/* ---------- thin custom scrollbar ---------- */
.chat-feed, .thread-list-items {
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.chat-feed::-webkit-scrollbar, .thread-list-items::-webkit-scrollbar { width: 8px; }
.chat-feed::-webkit-scrollbar-track, .thread-list-items::-webkit-scrollbar-track { background: transparent; }
.chat-feed::-webkit-scrollbar-thumb, .thread-list-items::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.chat-feed::-webkit-scrollbar-thumb:hover, .thread-list-items::-webkit-scrollbar-thumb:hover {
  background: var(--text-faint);
  background-clip: padding-box;
}

/* ---------- button micro-interactions ---------- */
.composer-icon-btn, .header-icon-btn, .ctx-react-btn, .ctx-menu-item, .composer-send {
  transition: transform 0.1s ease, background 0.15s ease, filter 0.15s ease, color 0.15s ease;
}
.composer-icon-btn:active, .header-icon-btn:active,
.ctx-react-btn:active, .composer-send:active, .btn-google:active, .btn-ghost:active {
  transform: scale(0.92);
}

/* ---------- composer: textarea (was a single-line input) + keyboard hint ---------- */
.chat-composer textarea[data-chat-text] {
  flex: 1;
  border: 1.5px solid transparent;
  border-radius: 22px;
  padding: 11px 17px;
  font-size: 1rem;
  font-family: inherit;
  background: var(--surface-raised);
  color: var(--text);
  min-width: 0;
  resize: none;
  max-height: 120px;
  line-height: 1.4;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.chat-composer textarea[data-chat-text]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
.chat-composer textarea[data-chat-text]::placeholder { color: var(--text-faint); }

.composer-hint {
  display: none;
  text-align: center;
  font-size: 0.68rem;
  color: var(--text-faint);
  padding: 2px 0 6px;
}
@media (min-width: 761px) {
  /* Shift+Enter only means anything with a physical keyboard — dead text
     on a phone, where there's no such key. Desktop keeps the hint, but even
     there it's plain text now, not a bar with its own background. */
  .composer-hint { display: block; }
}

/* ---------- admin stat cards ---------- */
.stat-cards {
  display: flex;
  gap: 8px;
  padding: 10px 14px 4px;
}
.stat-card {
  flex: 1;
  background: var(--surface-raised);
  border-radius: 10px;
  padding: 8px 10px;
  text-align: center;
}
.stat-card .stat-num { font-size: 1.15rem; font-weight: 700; line-height: 1.2; }
.stat-card .stat-label { font-size: 0.68rem; color: var(--text-soft); margin-top: 1px; }

/* ---------- accessibility mode: high contrast + large text ---------- */
:root[data-a11y~='contrast'] {
  --line: #6b7280;
  --text-soft: #c3c8d1;
  --bubble-theirs: #2b313c;
}
:root[data-theme='light'][data-a11y~='contrast'],
:root[data-a11y~='contrast'] {
  --shadow-sm: 0 0 0 1px var(--line);
}
:root[data-a11y~='large'] { font-size: 112.5%; }
:root[data-a11y~='large'] .bubble { font-size: 1rem; }
:root[data-a11y~='large'] .chat-composer textarea[data-chat-text] { font-size: 1rem; }

/* ---------- settings panel ---------- */
.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 6, 9, 0.55);
  padding: 16px;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}
.settings-panel {
  width: 100%;
  max-width: 400px;
  max-height: 100%;
  overflow-y: auto;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow-md);
  animation: panel-slide-in-kf 0.22s ease;
}
@keyframes panel-slide-in-kf {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .settings-panel { animation: none; }
}

/* ---------- phone-width full-screen pages (design request: these read as
   small centered dialog CARDS — dimmed backdrop, rounded corners, shadow
   — when Telegram's own Chats/Settings/Profile are each the WHOLE
   screen, no card chrome at all) ----------
   Scoped the same way as the desktop sidebar block below (signed-in only,
   via body:has(#chatScreen:not([hidden]))) so a logged-out visitor's
   login screen never gets this treatment. Modals that stay small
   deliberately (create-folder, report, wallpaper picker) are NOT in this
   selector list — only the three "whole section" screens are. */
@media (max-width: 999px) {
  body:has(#chatScreen:not([hidden])) #peoplePanel,
  body:has(#chatScreen:not([hidden])) #settingsPanel,
  body:has(#chatScreen:not([hidden])) #privacyPanel,
  body:has(#chatScreen:not([hidden])) #profileViewPanel {
    background: var(--bg);
    padding: 0;
  }
  body:has(#chatScreen:not([hidden])) #peoplePanel .settings-panel,
  body:has(#chatScreen:not([hidden])) #settingsPanel .settings-panel,
  body:has(#chatScreen:not([hidden])) #privacyPanel .settings-panel,
  body:has(#chatScreen:not([hidden])) #profileViewPanel .settings-panel {
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: var(--bg);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  /* The overlay's own padding-top (which used to clear the status bar for
     the centered card) is gone now that the card fills the screen — the
     sticky header needs to reserve that space itself instead. */
  body:has(#chatScreen:not([hidden])) #peoplePanel .settings-panel-header,
  body:has(#chatScreen:not([hidden])) #settingsPanel .settings-panel-header,
  body:has(#chatScreen:not([hidden])) #privacyPanel .settings-panel-header,
  body:has(#chatScreen:not([hidden])) #profileViewPanel .settings-panel-header {
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
  }
}

/* ---------- wide-screen permanent "Suhbatlar" sidebar (idea #1) ----------
   On a wide viewport, #peoplePanel docks as a permanent left column next
   to the chat instead of a full-screen overlay — scoped strictly to
   #peoplePanel BY ID (never the shared .settings-overlay/.settings-panel
   classes, which #settingsPanel and #profileViewPanel also use — those
   must keep their normal overlay behavior at every width). Only active
   while signed in and past onboarding (body:has(#chatScreen:not([hidden]))
   — chatScreen is the one screen shown only after a successful sign-in),
   so a logged-out visitor's login/register screen is never covered by a
   sidebar nobody asked for. `[hidden]` is `!important` globally (see the
   comment near that rule) — overriding it here needs the same
   specificity weapon, which an ID selector legitimately wins on. */
@media (min-width: 1000px) {
  body:has(#chatScreen:not([hidden])) #peoplePanel {
    position: fixed;
    inset: 0 auto 0 var(--rail-width, 72px);
    z-index: 15;
    width: 360px;
    padding: 0;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--line);
    align-items: stretch;
    justify-content: flex-start;
  }
  body:has(#chatScreen:not([hidden])) #peoplePanel[hidden] { display: flex !important; }
  body:has(#chatScreen:not([hidden])) #peoplePanel .settings-panel {
    width: 100%;
    max-width: none;
    height: 100%;
    border: none;
    border-radius: 0;
    box-shadow: none;
  }
  body:has(#chatScreen:not([hidden])) #peoplePanel #peopleCloseBtn { display: none; }
  body:has(#chatScreen:not([hidden])) #peopleOpenBtn { display: none; }
  body:has(#chatScreen:not([hidden])) #chatScreen { padding-left: calc(var(--rail-width, 72px) + 360px); }
  body:has(#chatScreen:not([hidden])) #folderRail { display: flex; }
}
:root { --rail-width: 72px; }
.folder-rail {
  display: none;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--rail-width, 72px);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--line);
  z-index: 16;
  transition: width 0.15s ease;
}
.folder-rail-top {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 0;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
}
.folder-rail-bottom {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 6px 0;
  padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
}
.folder-rail-btn {
  position: relative;
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border: none;
  background: none;
  border-radius: 12px;
  font-size: 1.2rem;
  color: var(--text-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.folder-rail-btn:hover { background: var(--surface); }
.folder-rail-btn.active { background: var(--surface-raised); color: var(--accent); }
.folder-rail-icon { filter: grayscale(1); opacity: 0.6; transition: filter 0.15s ease, opacity 0.15s ease; flex-shrink: 0; }
.folder-rail-btn.active .folder-rail-icon { filter: none; opacity: 1; }
.folder-rail-label { display: none; font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.folder-rail-custom { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.folder-rail-add-btn { color: var(--text-faint); font-weight: 700; }
.folder-rail-profile-btn { margin-bottom: 2px; }
.folder-rail-profile-btn .avatar { width: 40px; height: 40px; font-size: 1rem; }
.folder-rail-divider { width: 32px; height: 1px; background: var(--line); margin: 2px 0 8px; flex-shrink: 0; }

/* Expanded rail mode (design idea #4) — icon-only by default, toggled to
   icon+label via railExpandBtn; actual width comes from --rail-width
   (set in JS), shared with #peoplePanel's left offset and #chatScreen's
   padding below, so every width-dependent rule stays in sync off one var. */
.folder-rail.expanded .folder-rail-btn { width: 100%; justify-content: flex-start; padding: 0 16px; }
.folder-rail.expanded .folder-rail-label { display: inline; }
.folder-rail.expanded .folder-rail-divider { width: calc(100% - 32px); }

.rail-context-menu {
  position: fixed;
  z-index: 90;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 4px;
  min-width: 220px;
}
.rail-context-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  border: none;
  background: none;
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
}
.rail-context-menu-item:hover { background: var(--surface); }

/* ---------- phone-width bottom tab bar (design request — real Telegram
   mobile reference, not the earlier floating-pill AO Watches look) ----------
   Mirrors the desktop folder rail's four main destinations, just docked
   at the bottom instead of the left edge. Flush, full-width, opaque —
   like Telegram's own Chats/Contacts/Settings/Profile bar, not a
   floating rounded pill. Hidden by default; shown only at phone widths
   AND only while on a "top-level" section (the conversation list or
   settings) — see the max-width:999px block below for why it has to
   disappear once an actual chat (with its own composer) is open. */
.mobile-nav-bar {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 65;
  background: var(--bg-sidebar);
  border-top: 1px solid var(--line);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom, 0px));
}
.mobile-nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: none;
  background: none;
  color: var(--text-faint);
  padding: 4px 4px;
  cursor: pointer;
}
.mobile-nav-icon { font-size: 1.3rem; filter: grayscale(1); opacity: 0.65; transition: filter 0.15s ease, opacity 0.15s ease; }
.mobile-nav-label { font-size: 0.64rem; font-weight: 600; white-space: nowrap; }
.mobile-nav-btn.active { color: var(--accent); }
.mobile-nav-btn.active .mobile-nav-icon { filter: none; opacity: 1; }
@media (min-width: 1000px) {
  .mobile-nav-bar { display: none !important; }
}
@media (max-width: 999px) {
  body:has(#chatScreen:not([hidden])) #mobileNavBar { display: flex; }
  body:has(#chatScreen:not([hidden])):has(#peoplePanel[hidden]):has(#settingsPanel[hidden]) #mobileNavBar { display: none; }
  /* The bar is a solid full-width strip now (not a small floating pill
     with gaps around it) — without this, its last ~60px permanently
     covers the bottom of whatever list is behind it. */
  body:has(#chatScreen:not([hidden])):has(#peoplePanel:not([hidden])) #peoplePanel .settings-body,
  body:has(#chatScreen:not([hidden])):has(#settingsPanel:not([hidden])) #settingsPanel .settings-body {
    padding-bottom: calc(66px + env(safe-area-inset-bottom, 0px));
  }
}
.folder-rail-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 15px;
  padding: 0 3px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-contrast, #fff);
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 15px;
  text-align: center;
}
.settings-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  font-weight: 650;
  position: sticky;
  top: 0;
  background: var(--surface);
}
.settings-body { padding: 12px 10px 18px; }

.settings-profile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 8px 16px;
}
.settings-profile-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.settings-profile-name { font-weight: 650; font-size: 0.98rem; }
.settings-profile-username { font-size: 0.82rem; color: var(--text-soft); }

.settings-edit-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 8px 16px;
}
.settings-edit-form input {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 1rem;
  background: var(--surface-raised);
  color: var(--text);
  width: 100%;
}
.settings-edit-actions { display: flex; gap: 8px; }
.settings-edit-actions .btn-ghost, .settings-edit-actions .btn-google { flex: 1; width: auto; }

.settings-section-label {
  font-size: 0.72rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  padding: 14px 10px 6px;
}
.settings-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 10px;
  border: none;
  border-radius: 12px;
  background: none;
  color: var(--text);
  font-size: 0.92rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease;
}
.settings-row:hover { background: var(--surface-raised); }
.settings-row.danger { color: var(--danger); }
.settings-row-icon { font-size: 1.05rem; width: 22px; text-align: center; flex-shrink: 0; }
.settings-row-label { flex: 1; }
.settings-row-value { color: var(--text-soft); font-size: 0.85rem; }

/* ---------- people panel: search + my conversations (user-to-user chat) ---------- */
.people-search-wrap { padding: 4px 8px 10px; display: flex; align-items: center; gap: 6px; }
.people-search-wrap .people-search-input { flex: 1; }
.people-search-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 13px;
  font-size: 1rem;
  background: var(--surface-raised);
  color: var(--text);
}
.people-list { display: flex; flex-direction: column; gap: 2px; }
/* .people-row is now just the outer clip/position container for the
   swipe-to-reveal backdrop (design request) — the flex layout, padding
   and hover background that used to live directly on it now belong to
   .people-row-content, the part that actually slides. */
.people-row {
  position: relative;
  width: 100%;
  padding: 0;
  border: none;
  border-radius: 12px;
  background: none;
  color: var(--text);
  font-size: 0.92rem;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
}
.people-row-content {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 9px 8px;
  background: var(--surface);
  border-radius: 12px;
  transition: background 0.15s ease;
}
.people-row:hover .people-row-content { background: var(--surface-raised); }
.people-row-swipe-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  display: flex;
  align-items: center;
  font-size: 0.82rem;
  font-weight: 650;
  color: #fff;
  padding: 0 16px;
}
.people-row-swipe-bg-pin { justify-content: flex-start; background: var(--accent); }
.people-row-swipe-bg-archive { justify-content: flex-end; background: var(--danger); }
.people-row.swipe-reveal-pin .people-row-swipe-bg-archive,
.people-row.swipe-reveal-archive .people-row-swipe-bg-pin { display: none; }
.people-row-admin { margin: 4px 0 0; border-top: 1px solid var(--line); border-radius: 0; }
.people-row-admin .people-row-content { padding: 12px 8px; }
#openSavedMessagesBtn.people-row-admin { margin-bottom: 8px; border-bottom: 1px solid var(--line); }
.people-row-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.people-row-name { font-weight: 600; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.premium-badge {
  display: inline-block;
  margin-left: 3px;
  font-size: 0.85em;
  background: linear-gradient(135deg, #ffd66b, #ff9d4d);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  vertical-align: middle;
}
.people-row-sub { font-size: 0.78rem; color: var(--text-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Per-chat draft preview (design gap vs. Telegram) — red, same convention
   Telegram itself uses, so an unsent draft reads as distinct from a real
   received/sent message at a glance. */
.people-row-sub-draft { color: var(--danger); }
.people-row-time { font-size: 0.72rem; color: var(--text-faint); flex-shrink: 0; align-self: flex-start; margin-top: 2px; }
.people-row-avatar { flex-shrink: 0; }

/* ---------- per-conversation pin/archive action icons ---------- */
.people-row-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  align-self: center;
}
.people-row-pin-btn, .people-row-archive-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  font-size: 0.82rem;
  opacity: 0.35;
  cursor: pointer;
}
.people-row:hover .people-row-pin-btn,
.people-row:hover .people-row-archive-btn,
.people-row-pin-btn:focus-visible,
.people-row-archive-btn:focus-visible { opacity: 0.8; }
.people-row-pin-btn:hover, .people-row-archive-btn:hover { background: var(--surface); opacity: 1; }
.people-row-pin-btn.active { opacity: 1; filter: drop-shadow(0 0 0 var(--accent)); }
.people-row.is-pinned .people-row-content { background: var(--surface-raised); }

/* ---------- read-only profile view (another person's profile) ---------- */
.profile-view-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px 16px;
  gap: 4px;
}
.profile-view-avatar-wrap { margin-bottom: 12px; }
.profile-view-name { margin: 0; font-size: 1.15rem; }
.profile-view-username { margin: 0 0 10px; color: var(--text-soft); font-size: 0.88rem; }
.profile-view-bio { margin: 0 0 16px; font-size: 0.86rem; color: var(--text); max-width: 280px; line-height: 1.4; }
.profile-view-actions { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; max-width: 240px; }
.profile-view-body .btn-google { width: 100%; max-width: 240px; }
.profile-view-actions .btn-ghost { width: 100%; text-align: center; }
.people-empty { padding: 14px 8px; color: var(--text-faint); font-size: 0.85rem; text-align: center; }

/* ---------- chat folders (Telegram-style tabs above the conversation list) ---------- */
/* Telegram-style tab bar (design request): a thin indicator sliding
   under the active tab, not a filled pill — the wrap hosts the two
   edge-fade overlays (a ::before/::after each, toggled by scroll
   position via JS) OUTSIDE the scrolling element itself so they stay
   fixed at the viewport edges instead of scrolling away with the tabs. */
.chat-folders-wrap { position: relative; }
.chat-folders-wrap::before, .chat-folders-wrap::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 18px;
  z-index: 1;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.chat-folders-wrap::before { left: 0; background: linear-gradient(90deg, var(--surface), transparent); }
.chat-folders-wrap::after { right: 0; background: linear-gradient(270deg, var(--surface), transparent); }
.chat-folders-wrap.can-scroll-left::before { opacity: 1; }
.chat-folders-wrap.can-scroll-right::after { opacity: 1; }
.chat-folders {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 8px 10px;
  border-top: 1px solid var(--line);
  margin-top: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.chat-folders::-webkit-scrollbar { display: none; }
.chat-folder-indicator {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 2.5px;
  width: 0;
  border-radius: 2px;
  background: var(--accent);
  transform: translateX(0);
  transition: transform 0.25s cubic-bezier(0.3, 0.7, 0.4, 1), width 0.25s cubic-bezier(0.3, 0.7, 0.4, 1);
  pointer-events: none;
}
.chat-folder-btn {
  position: relative;
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-soft);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
}
.chat-folder-btn:hover { background: var(--surface); }
.chat-folder-btn.active { color: var(--accent); }
.chat-folder-btn.muted, .folder-rail-btn.muted { opacity: 0.5; }
.chat-folder-icon { filter: grayscale(1); opacity: 0.55; transition: filter 0.15s ease, opacity 0.15s ease; }
.chat-folder-btn.active .chat-folder-icon { filter: none; opacity: 1; }
.custom-folder-tabs { display: flex; gap: 6px; flex: none; }
@keyframes folder-slide-from-right-kf { from { transform: translateX(18px); opacity: 0.4; } to { transform: none; opacity: 1; } }
@keyframes folder-slide-from-left-kf { from { transform: translateX(-18px); opacity: 0.4; } to { transform: none; opacity: 1; } }
.folder-slide-from-right { animation: folder-slide-from-right-kf 0.22s ease-out; }
.folder-slide-from-left { animation: folder-slide-from-left-kf 0.22s ease-out; }
@media (prefers-reduced-motion: reduce) {
  .folder-slide-from-right, .folder-slide-from-left { animation: none; }
}
.chat-folder-add-btn {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-faint);
  padding: 6px 11px;
}
.chat-folder-badge {
  display: inline-block;
  margin-left: 5px;
  min-width: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-contrast, #fff);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

/* ---------- custom folder create/edit modal ---------- */
.folder-preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.folder-preset-btn {
  flex: none;
  border: 1px solid var(--line);
  background: var(--surface-raised);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.82rem;
  cursor: pointer;
}
.folder-preset-btn:hover { background: var(--surface); }
.folder-name-input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface-raised);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 1rem;
  color: var(--text);
  margin-bottom: 12px;
}
.folder-name-input:focus { outline: 2px solid var(--accent); }
.folder-icon-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}
.folder-icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-raised);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.folder-icon-btn.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, transparent); }
.folder-auto-rule-row { display: flex; flex-direction: column; gap: 2px; margin-bottom: 4px; }
.folder-radio-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 2px;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
}
.folder-radio-row input { accent-color: var(--accent); flex-shrink: 0; }
#folderMembersSection { margin: 8px 0 12px; }
.folder-visibility-hint { font-size: 0.78rem; color: var(--text-faint); padding: 6px 2px 0; }
#folderMembersList { max-height: 180px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; }
.folder-modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.folder-delete-btn {
  background: none;
  border: none;
  color: var(--danger, #e5484d);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 8px 4px;
}

/* ---------- per-conversation "which folders is this chat in" list ---------- */
.folder-assign-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: none;
  background: none;
  padding: 10px 8px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--text);
  font-size: 0.9rem;
  text-align: left;
}
.folder-assign-row:hover { background: var(--surface-raised); }
.folder-assign-row.checked { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.folder-assign-icon { font-size: 1.05rem; flex: none; }
.folder-assign-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.folder-assign-check { flex: none; color: var(--accent); font-weight: 700; width: 16px; text-align: center; }

/* ---------- row "⋯" (add-to-folder) action, alongside pin/archive ---------- */
.people-row-more-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  font-size: 0.95rem;
  opacity: 0.35;
  cursor: pointer;
}
.people-row:hover .people-row-more-btn, .people-row-more-btn:focus-visible { opacity: 0.8; }
.people-row-more-btn:hover { background: var(--surface); opacity: 1; }

/* Unread row: a small dot where the timestamp column sits, and a bolder
   name — mirrors Telegram's unread-row treatment without needing a
   separate numeric badge (a single peer chat has at most one "unread"
   state here, not a count, since read_by is per-message not per-count). */
.people-row.people-row-unread .people-row-name { font-weight: 750; }
.people-row.people-row-unread .people-row-sub { color: var(--text); }
.people-row.people-row-unread .people-row-content::after {
  content: '';
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  margin-left: 4px;
}

/* ---------- colored names (idea #4): deterministic per-person hue,
   shared with that person's avatar color (see colorNameEl in chat-ui.js).
   Lightness/saturation are theme tokens (defined alongside the other
   theme tokens above) rather than a separate per-theme override block
   here, so this follows the same token pattern as everything else. */
.colored-name { color: hsl(var(--name-hue) var(--name-sat) var(--name-light)); font-weight: 650; }

/* ---------- auto-linked URLs inside text bubbles ---------- */
.bubble-link { text-decoration: underline; word-break: break-all; }
.msg-row.theirs .bubble-link { color: var(--accent); }
.msg-row.own .bubble-link { color: inherit; text-decoration-color: rgba(255, 255, 255, 0.6); }
.bubble-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86em;
  background: rgba(127, 127, 127, 0.18);
  border-radius: 4px;
  padding: 1px 5px;
}
.bubble-readmore-btn {
  display: block;
  border: none;
  background: none;
  color: inherit;
  text-decoration: underline;
  opacity: 0.75;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 4px 0 0;
  cursor: pointer;
}

/* ---------- blur-up photo loading ---------- */
.media-blur-wrap {
  position: relative;
  display: inline-block;
  min-width: 120px;
  min-height: 120px;
  border-radius: 14px;
  overflow: hidden;
  background: var(--surface-raised);
}
.media-blur-wrap::before {
  content: '';
  position: absolute;
  inset: 0;
  filter: blur(14px);
  background: var(--surface-raised);
  opacity: 1;
  transition: opacity 0.35s ease;
}
.media-blur-wrap.loaded::before { opacity: 0; }
.media-blur-wrap img {
  position: relative;
  display: block;
  opacity: 0;
  transition: opacity 0.35s ease;
}
.media-blur-wrap.loaded img { opacity: 1; }

/* ---------- unread-messages divider (computed once per thread open) ---------- */
.unread-sep {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 10px 0;
}
.unread-sep::before, .unread-sep::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--danger);
  opacity: 0.35;
}
.unread-sep span {
  font-size: 0.68rem;
  font-weight: 650;
  color: var(--danger);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* ---------- admin thread-list filter chips ---------- */
.thread-filters {
  display: flex;
  gap: 6px;
  padding: 8px 14px 2px;
  flex-wrap: wrap;
}
.filter-chip {
  border: 1px solid var(--line);
  background: none;
  color: var(--text-soft);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.filter-chip:hover { background: var(--surface-raised); }
.filter-chip.active { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }

/* ---------- visitor-facing "band" (busy) banner ---------- */
.busy-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 16px;
  background: rgba(245, 165, 36, 0.14);
  border-bottom: 1px solid rgba(245, 165, 36, 0.35);
  color: var(--text);
  font-size: 0.85rem;
  flex-shrink: 0;
}
.busy-banner button {
  background: none;
  border: none;
  color: var(--text-soft);
  cursor: pointer;
  font-size: 0.95rem;
  flex-shrink: 0;
}
.busy-banner button:hover { color: var(--text); }
#blockedBannerUnblockBtn { font-size: 0.8rem; font-weight: 650; color: var(--accent); text-decoration: underline; }

/* ---------- upload progress bar ---------- */
.upload-progress-bar {
  position: relative;
  height: 26px;
  margin: 0 14px;
  background: var(--surface-raised);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.upload-progress-fill {
  position: absolute;
  inset: 0;
  width: 0%;
  background: var(--accent);
  opacity: 0.35;
  transition: width 0.15s ease;
}
.upload-progress-pct {
  position: relative;
  margin: 0 auto;
  font-size: 0.74rem;
  font-weight: 650;
  color: var(--text);
}

/* ---------- send-failed retry bar (reuses these classes' styling) ---------- */
.bubble-undo-bar {
  display: flex;
  justify-content: flex-end;
  margin-top: 5px;
}
.bubble-undo-btn {
  background: rgba(255, 255, 255, 0.18);
  border: none;
  color: inherit;
  font-size: 0.74rem;
  font-weight: 650;
  padding: 3px 9px;
  border-radius: 999px;
  cursor: pointer;
}
.bubble-undo-btn:hover { background: rgba(255, 255, 255, 0.28); }

/* ---------- failed send: kept bubble + retry ---------- */
.bubble-send-failed { opacity: 0.85; border: 1px solid rgba(220, 80, 80, 0.55); }
.bubble-send-error-label {
  font-size: 0.74rem;
  color: #ffb3b3;
  margin-right: auto;
  align-self: center;
}
.bubble-undo-bar:has(.bubble-send-error-label) { justify-content: space-between; }

.send-error-banner {
  font-size: 0.8rem;
  color: #ffb3b3;
  padding: 6px 4px;
  text-align: center;
}

/* ---------- admin: thread search + archive action ---------- */
.thread-search-input {
  margin: 8px 14px 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 1rem;
  background: var(--surface-raised);
  color: var(--text);
  width: calc(100% - 28px);
}
.thread-search-input::placeholder { color: var(--text-faint); }
.thread-search-input:focus { outline: none; border-color: var(--accent); }

.thread-item-archive-btn {
  flex-shrink: 0;
  font-size: 0.95rem;
  opacity: 0;
  padding: 4px;
  border-radius: 6px;
  cursor: pointer;
}
.thread-item:hover .thread-item-archive-btn,
.thread-item-archive-btn:focus-visible { opacity: 0.8; }
.thread-item-archive-btn:hover { opacity: 1; background: var(--surface-raised); }

/* ---------- avatar: real uploaded photo (swapped in over the initials circle) ---------- */
.avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

/* ---------- settings: avatar upload row inside the edit form ---------- */
.settings-edit-avatar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 2px 0 6px;
}
.settings-edit-banner { padding: 2px 0 10px; }

/* ---------- settings: profile banner / cover photo ---------- */
.settings-banner {
  height: 100px;
  border-radius: 12px;
  /* Default look when no banner photo is set — a flat var(--surface-raised)
     box here used to just read as an empty, unfinished placeholder. */
  background-image: linear-gradient(135deg, color-mix(in srgb, var(--accent) 55%, transparent), color-mix(in srgb, var(--accent) 15%, transparent));
  background-color: var(--surface-raised);
  background-size: cover;
  background-position: center;
  margin-bottom: 10px;
}

/* ---------- settings: bio line under the name ---------- */
.settings-profile-bio {
  font-size: 0.82rem;
  color: var(--text-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- settings: account info (created/last-sign-in) ---------- */
.settings-account-info { padding: 2px 10px 6px; display: flex; flex-direction: column; gap: 4px; }
.settings-info-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.85rem;
}
.settings-info-row span:first-child { color: var(--text-soft); }

/* ---------- admin: verified-customer badge ---------- */
.verified-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.6rem;
  margin-left: 4px;
  vertical-align: middle;
}
.header-icon-btn.active { color: var(--accent); background: var(--surface-raised); }

/* ---------- admin: thread meta line (phone / last-active) ---------- */
.chat-subtitle-meta { font-size: 0.74rem; color: var(--text-faint); }

/* ---------- combined emoji + sticker picker ----------
   One floating panel (.expression-picker) behind a single composer
   button, with a two-tab mode switch at the top — .emoji-picker and
   .sticker-picker are just its two content panes now, not independently
   positioned/floating (that's what made this two separate buttons
   before; merged into one to free up composer-row width — see the JS
   comment at this panel's construction for why that mattered). */
.expression-picker {
  position: absolute;
  bottom: 100%;
  left: 12px;
  right: 12px;
  margin-bottom: 8px;
  max-height: 340px;
  display: flex;
  flex-direction: column;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  z-index: 30;
  overflow: hidden;
}
.expression-mode-row {
  display: flex;
  flex-shrink: 0;
  border-bottom: 1px solid var(--line);
}
.expression-mode-btn {
  flex: 1;
  background: none;
  border: none;
  padding: 10px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-soft);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.expression-mode-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* .emoji-picker is the outer pane (category tabs on top, reusing the
   sticker picker's .sticker-tabs-row/.sticker-tab-btn styling, + a
   scrollable grid below) — the grid itself, not this wrapper, scrolls. */
.emoji-picker { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.emoji-picker-grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
  gap: 2px;
  padding: 8px;
}
.emoji-pick-btn {
  background: none;
  border: none;
  font-size: 1.3rem;
  line-height: 1;
  padding: 6px;
  border-radius: 8px;
  cursor: pointer;
}
.emoji-pick-btn:hover { background: var(--surface); }
.skin-tone-popup {
  position: fixed;
  z-index: 1200;
  display: flex;
  gap: 2px;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-lg, 0 8px 28px rgba(0, 0, 0, 0.28));
  padding: 6px;
}
.skin-tone-btn {
  background: none;
  border: none;
  font-size: 1.3rem;
  line-height: 1;
  padding: 4px;
  border-radius: 8px;
  cursor: pointer;
}
.skin-tone-btn:hover { background: var(--surface); }

/* ---------- sticker picker pane (Telegram-style: search + pack tabs + grid) ---------- */
.sticker-picker {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}
.sticker-search-row { padding: 8px 8px 0; flex-shrink: 0; }
.sticker-search-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 11px;
  font-size: 1rem;
  background: var(--surface);
  color: var(--text);
}
.sticker-tabs-row, .emoji-tabs-row {
  display: flex;
  gap: 2px;
  padding: 8px;
  overflow-x: auto;
  flex-shrink: 0;
  border-bottom: 1px solid var(--line);
}
.sticker-tab-btn, .emoji-tab-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  font-size: 1.1rem;
  line-height: 1;
  padding: 6px 9px;
  border-radius: 8px;
  cursor: pointer;
  opacity: 0.55;
}
.sticker-tab-btn:hover, .emoji-tab-btn:hover { background: var(--surface); opacity: 0.85; }
.sticker-tab-btn.active, .emoji-tab-btn.active { background: var(--surface); opacity: 1; }
.sticker-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 6px;
  padding: 10px;
}
.sticker-pick-btn {
  position: relative;
  background: none;
  border: none;
  border-radius: 10px;
  padding: 4px;
  cursor: pointer;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sticker-pick-btn:hover { background: var(--surface); }
.sticker-pick-btn img { width: 100%; height: 100%; object-fit: contain; }
.sticker-fav-star {
  position: absolute;
  top: 2px;
  right: 2px;
  font-size: 0.8rem;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.1s ease;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}
.sticker-pick-btn:hover .sticker-fav-star, .sticker-fav-star.active { opacity: 1; }

/* Stickers render "bare" — no bubble background/padding/shadow/tail,
   just the animation itself, Telegram-style (distinct from photo/video
   bubbles, which keep the normal bubble chrome). */
.bubble.bubble-sticker {
  background: none;
  box-shadow: none;
  padding: 0;
  max-width: 148px;
}
.bubble.bubble-sticker::after { display: none; }
.bubble-sticker-video {
  width: 148px;
  height: 148px;
  object-fit: contain;
  display: block;
  pointer-events: none;
}
.bubble.bubble-sticker .bubble-time {
  position: absolute;
  bottom: 2px;
  right: 6px;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  border-radius: 8px;
  padding: 1px 6px;
  margin-top: 0;
}

/* ---------- premium auth (login/register) screen ---------- */
.auth-screen {
  background:
    radial-gradient(900px 520px at 12% -10%, rgba(91, 140, 255, 0.18), transparent 55%),
    radial-gradient(760px 520px at 92% 112%, rgba(63, 109, 240, 0.14), transparent 55%),
    var(--bg);
}
.auth-card { position: relative; overflow: hidden; animation: auth-card-in-kf 0.4s cubic-bezier(0.2, 0.8, 0.3, 1); }
@keyframes auth-card-in-kf {
  from { opacity: 0; transform: translateY(14px) scale(0.97); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) { .auth-card { animation: none; } }
.auth-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 55%, white));
}
#authForm {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 6px;
}
#authForm input {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px 14px;
  font-size: 1rem;
  background: var(--surface-raised);
  color: var(--text);
  width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
#authForm input::placeholder { color: var(--text-faint); }
#authForm input:focus,
.settings-edit-form input:focus,
#profileSetupForm input:focus,
#pinUnlockForm input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

/* ---------- premium primary-action buttons (gradient, used sitewide) ---------- */
.btn-google, .composer-send {
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 72%, white));
}

/* ---------- PIN lock screen (transparent device lock — always clearly
   labeled "Suhbat", never disguised as a different app) ---------- */
#pinUnlockForm {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#pinUnlockForm input {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px 14px;
  font-size: 1.3rem;
  letter-spacing: 0.3em;
  text-align: center;
  background: var(--surface-raised);
  color: var(--text);
  width: 100%;
}

/* ---------- toast (copy-link confirmation, register welcome message) ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(10px) scale(0.96);
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-raised);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 18px 10px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  z-index: 80;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  max-width: calc(100vw - 32px);
  text-align: left;
}
.toast:not([hidden]) { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
.toast-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  background: var(--online);
  color: #fff;
}
.toast.toast-error .toast-icon { background: var(--danger); }
.toast-text { min-width: 0; }

/* ---------- in-app new-message banner (design request) ----------
   Shown when a message arrives in a DIFFERENT conversation than the one
   currently open — push notifications already cover the "app not
   focused" case, this covers "app open, but looking at a different
   chat", which otherwise gave no in-app signal at all. */
.in-app-banner {
  position: fixed;
  top: env(safe-area-inset-top, 0px);
  left: 10px;
  right: 10px;
  z-index: 85;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px 14px 10px 10px;
  box-shadow: var(--shadow-lg);
  text-align: left;
  cursor: pointer;
  transform: translateY(calc(-100% - 20px));
  transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.3, 1);
}
.in-app-banner:not([hidden]) { transform: translateY(10px); }
.in-app-banner-body { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.in-app-banner-name { font-weight: 650; font-size: 0.88rem; }
.in-app-banner-text { font-size: 0.82rem; color: var(--text-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- auth form: password toggle, inline field hints, mode-switch
   transition, submit spinner ---------- */
.auth-password-wrap { position: relative; }
.auth-password-wrap input { padding-right: 44px; }
.auth-password-toggle {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 1.05rem;
  line-height: 1;
  padding: 8px;
  cursor: pointer;
  border-radius: 8px;
}
.auth-password-toggle:hover { color: var(--text-soft); background: var(--line); }

.field-hint {
  display: block;
  color: var(--danger);
  font-size: 0.76rem;
  margin: -4px 2px 0;
  text-align: left;
}
.field-hint.field-hint-ok { color: var(--online); }

#authNameInput {
  transition: max-height 0.2s ease, opacity 0.15s ease, margin 0.2s ease, padding 0.2s ease, border-width 0.2s ease;
  max-height: 54px;
  overflow: hidden;
}
#authNameInput.auth-field-collapsed {
  max-height: 0;
  opacity: 0;
  margin: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
  border-width: 0 !important;
  pointer-events: none;
}
#authSubtitle, #authSubmitBtn, #authToggleText, #authToggleBtn {
  transition: opacity 0.12s ease;
}

.auth-spinner {
  display: inline-block;
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: auth-spin 0.7s linear infinite;
  vertical-align: -3px;
  margin-right: 7px;
}
@keyframes auth-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  #authNameInput, #authSubtitle, #authSubmitBtn, #authToggleText, #authToggleBtn, .toast {
    transition: none !important;
  }
  .auth-spinner { animation-duration: 1.4s; }
}

/* ---------- Nuriyat Ilmi Lyceum orqali kirish ---------- */
.btn-lyceum {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 13px 18px; border-radius: 12px; border: none; cursor: pointer;
  font-size: 0.98rem; font-weight: 600; color: #fff;
  background: linear-gradient(155deg, #1e3a8a, #2563eb);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.32);
  transition: filter 0.15s ease, transform 0.1s ease;
}
.btn-lyceum:hover { filter: brightness(1.08); }
.btn-lyceum:active { transform: scale(0.98); }
.btn-lyceum:disabled { opacity: 0.75; cursor: default; }
.btn-lyceum-icon { font-size: 1.15rem; line-height: 1; }
.btn-lyceum.is-loading .btn-lyceum-icon { animation: lyceum-spin 0.9s linear infinite; display: inline-block; }
@keyframes lyceum-spin { to { transform: rotate(360deg); } }
#lyceumLoginError { margin-top: 10px; }
.login-card p.login-lyceum-note { margin: 16px 0 0; font-size: 0.78rem; color: var(--text-faint); }
#ssoUsernameForm { display: flex; flex-direction: column; gap: 12px; margin-top: 6px; }
.sso-username-wrap {
  display: flex; align-items: center; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface-raised); padding: 0 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.sso-username-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.sso-at { color: var(--text-faint); font-size: 1rem; margin-right: 2px; }
#ssoUsernameInput { flex: 1; border: none; background: transparent; color: var(--text); font-size: 1rem; padding: 13px 0; outline: none; min-width: 0; }

/* ---------- Maxfiylik va xavfsizlik (Telegram uslubidagi guruhlangan kartalar) ---------- */
#privacyPanel { z-index: 61; }
.privacy-panel { max-width: 520px; }
.privacy-panel .settings-panel-header { gap: 8px; }
.privacy-panel .settings-panel-header #privacyTitle { flex: 1; text-align: center; font-weight: 650; }
.privacy-header-spacer { width: 36px; flex-shrink: 0; }
.pv-card {
  background: var(--surface-raised);
  border-radius: 14px;
  overflow: hidden;
  margin: 0 2px;
}
.pv-row {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 50px; padding: 9px 14px;
  border: none; background: none; color: var(--text);
  font-size: 0.95rem; text-align: left; cursor: pointer;
  position: relative;
}
.pv-row + .pv-row::before {
  content: ''; position: absolute; top: 0; right: 0; left: 56px;
  height: 1px; background: var(--line);
}
.pv-radio + .pv-radio::before, .pv-blocked-row + .pv-blocked-row::before { left: 48px; }
.pv-row:hover { background: color-mix(in srgb, var(--text) 5%, transparent); }
.pv-icon {
  width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--pv-c); font-size: 0.95rem; line-height: 1;
}
.pv-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pv-value { color: var(--text-soft); font-size: 0.9rem; white-space: nowrap; }
.pv-chev { color: var(--text-faint); font-size: 1.2rem; line-height: 1; margin-left: 2px; }
.pv-caption { margin: 8px 16px 18px; font-size: 0.78rem; line-height: 1.45; color: var(--text-faint); }
.pv-section {
  font-size: 0.74rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-faint); padding: 4px 16px 8px;
}
.pv-radio-dot {
  width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--text-faint); position: relative; box-sizing: border-box;
  transition: border-color 0.15s ease;
}
.pv-radio.checked .pv-radio-dot { border-color: var(--accent); }
.pv-radio.checked .pv-radio-dot::after {
  content: ''; position: absolute; inset: 3px; border-radius: 50%; background: var(--accent);
}
.pv-blocked-row { cursor: default; }
.pv-blocked-row .avatar { flex-shrink: 0; width: 34px; height: 34px; }
.pv-unblock {
  border: none; background: none; color: var(--accent); font-weight: 600;
  font-size: 0.85rem; cursor: pointer; padding: 6px 4px; white-space: nowrap;
}
.pv-empty { padding: 18px 16px; text-align: center; color: var(--text-soft); font-size: 0.9rem; }
.profile-view-phone {
  display: inline-block; margin: -6px 0 16px; font-size: 0.9rem;
  color: var(--accent); text-decoration: none; font-weight: 500;
}
@media (max-width: 999px) {
  .privacy-panel .settings-body { padding-left: 12px; padding-right: 12px; }
}
