/* Wi MSG — Apple-like design language: system type, frosted surfaces,
   hairline separators, restrained color. Theme via [data-theme] or system. */

:root {
  --bg: #f2f2f7; --panel: #ffffff; --glass: rgb(255 255 255 / 78%);
  --border: rgb(60 60 67 / 13%); --hairline: rgb(60 60 67 / 22%);
  --text: #000000; --muted: #8e8e93;
  --accent: #0a84ff; --accent-2: #4aa3ff; --accent-soft: rgb(10 132 255 / 10%);
  --hover: rgb(120 120 128 / 10%); --active: #0a84ff;
  --chat-bg: #eef0f4;
  --bubble: #e9e9eb; --bubble-text: #000000;
  --mine: linear-gradient(180deg, #3d9bff, #0a84ff); --mine-flat: #0a84ff;
  --mine-text: #ffffff; --mine-meta: rgb(255 255 255 / 75%);
  --danger: #ff3b30; --online: #30d158;
  --shadow: 0 1px 2px rgb(0 0 0 / 7%);
  --shadow-lg: 0 12px 48px rgb(0 0 0 / 18%);
  --tile-filter: none; --tile-opacity: .05;
}
:root[data-theme='dark'] {
  --bg: #000000; --panel: #1c1c1e; --glass: rgb(28 28 30 / 78%);
  --border: rgb(84 84 88 / 34%); --hairline: rgb(84 84 88 / 55%);
  --text: #ffffff; --muted: #98989f;
  --accent: #0a84ff; --accent-2: #4aa3ff; --accent-soft: rgb(10 132 255 / 18%);
  --hover: rgb(120 120 128 / 18%); --active: #0a84ff;
  --chat-bg: #0b0b0d;
  --bubble: #26252a; --bubble-text: #ffffff;
  --mine: linear-gradient(180deg, #2b8fff, #0a6de0); --mine-flat: #0a84ff;
  --mine-text: #ffffff; --mine-meta: rgb(255 255 255 / 70%);
  --shadow: 0 1px 3px rgb(0 0 0 / 50%);
  --shadow-lg: 0 12px 48px rgb(0 0 0 / 60%);
  --tile-filter: invert(1); --tile-opacity: .06;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #000000; --panel: #1c1c1e; --glass: rgb(28 28 30 / 78%);
    --border: rgb(84 84 88 / 34%); --hairline: rgb(84 84 88 / 55%);
    --text: #ffffff; --muted: #98989f;
    --accent: #0a84ff; --accent-2: #4aa3ff; --accent-soft: rgb(10 132 255 / 18%);
    --hover: rgb(120 120 128 / 18%); --active: #0a84ff;
    --chat-bg: #0b0b0d;
    --bubble: #26252a; --bubble-text: #ffffff;
    --mine: linear-gradient(180deg, #2b8fff, #0a6de0); --mine-flat: #0a84ff;
    --mine-text: #ffffff; --mine-meta: rgb(255 255 255 / 70%);
    --shadow: 0 1px 3px rgb(0 0 0 / 50%);
    --shadow-lg: 0 12px 48px rgb(0 0 0 / 60%);
    --tile-filter: invert(1); --tile-opacity: .06;
  }
}

* { box-sizing: border-box; scrollbar-width: thin; scrollbar-color: rgb(128 128 128 / 30%) transparent; }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-thumb { background: rgb(128 128 128 / 30%); border-radius: 3px; }
::-webkit-scrollbar-track { background: transparent; }

html, body { height: 100%; }
html { overflow: hidden; }

/* No text selection anywhere in the UI — accidental long-press selections
   on touch break the layout. Editable fields keep selection so typing works. */
* { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
input, textarea, [contenteditable] {
  user-select: text; -webkit-user-select: text; -webkit-touch-callout: default;
}
body {
  margin: 0; color: var(--text); background: var(--bg); overflow: hidden;
  font: 15px/1.42 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; letter-spacing: -.01em;
  overscroll-behavior: none; touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
.error { color: var(--danger); font-size: 14px; }
.busy { color: var(--muted); font-size: 14px; }
button { font-family: inherit; color: inherit; transition: filter .12s, background .15s, transform .1s, opacity .15s; }
button:active { transform: scale(.96); }

/* keyboard focus ring (only for keyboard users, not mouse/touch) */
:focus { outline: none; }
button:focus-visible, .chat-item:focus-visible, .pick-row:focus-visible,
a:focus-visible, [role="button"]:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px;
}
/* round controls: the focus ring should be round, not a rounded rectangle */
#send-btn:focus-visible, .fab:focus-visible, .call-btn:focus-visible,
.avatar:focus-visible, .accent-swatch:focus-visible, .icon-btn:focus-visible {
  border-radius: 50%;
}
.ic { display: block; flex: none; }

@keyframes popIn { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }

/* toasts — replace native alert() */
.toasts {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center;
  width: max-content; max-width: min(92vw, 420px); pointer-events: none;
}
.toast {
  pointer-events: auto; background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-left: 3px solid var(--muted); border-radius: 12px; padding: 11px 15px; font-size: 14px; line-height: 1.35;
  box-shadow: var(--shadow-lg); opacity: 0; transform: translateY(12px); transition: opacity .26s ease, transform .26s ease;
  max-width: 100%;
}
.toast.show { opacity: 1; transform: none; }
.toast-error { border-left-color: var(--danger); }
.toast-success { border-left-color: var(--online); }
.toast-info { border-left-color: var(--accent); }

/* styled confirm() */
.confirm-back {
  position: fixed; inset: 0; z-index: 210; display: flex; align-items: center; justify-content: center;
  background: rgb(0 0 0 / 45%); padding: 20px; opacity: 0; transition: opacity .2s ease;
}
.confirm-back.show { opacity: 1; }
.confirm-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 18px; padding: 20px;
  width: 100%; max-width: 340px; box-shadow: var(--shadow-lg); transform: scale(.94); transition: transform .2s ease;
}
.confirm-back.show .confirm-card { transform: none; }
.confirm-msg { font-size: 15px; line-height: 1.45; margin-bottom: 16px; }
.confirm-actions { display: flex; gap: 8px; }
.confirm-actions .btn { flex: 1; padding: 10px; }
@keyframes slideDown { from { opacity: 0; transform: translate(-50%, -16px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes msgIn { from { opacity: 0; transform: translateY(10px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { filter: brightness(1.25); } }
@keyframes tdot { 0%, 60%, 100% { opacity: .35; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ================= auth ================= */
.auth-wrap {
  /* body itself is locked (mobile keyboard fixes) — this screen scrolls */
  height: var(--vvh, 100dvh); overflow-y: auto;
  display: flex; justify-content: center;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  background:
    radial-gradient(1100px 520px at 85% -10%, rgb(10 132 255 / 10%), transparent 70%),
    radial-gradient(900px 520px at -10% 110%, rgb(94 92 230 / 9%), transparent 70%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 384px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 22px; padding: 30px 28px; box-shadow: var(--shadow-lg);
  animation: popIn .25s ease-out;
  margin: auto; /* centers when it fits, scrolls when taller than the screen */
  flex: none;
}
.auth-logo {
  width: 76px; height: 76px; margin: 0 auto; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: #fff; border: 1px solid var(--border);
  border-radius: 22px; box-shadow: var(--shadow);
}
.auth-logo img { width: 100%; height: 100%; object-fit: cover; }
.auth-card h1 { margin: 14px 0 2px; text-align: center; letter-spacing: -.03em; font-size: 26px; }
.auth-sub { margin: 0 0 20px; text-align: center; color: var(--muted); font-size: 13px; }
.tabs, .segmented { display: flex; gap: 2px; background: var(--hover); padding: 2px; border-radius: 10px; }
.tabs { margin-bottom: 18px; }
.tab, .segmented button {
  flex: 1; padding: 7px 8px; border: none; background: transparent; color: var(--text);
  border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 500;
}
.tab.active, .segmented button.active { background: var(--panel); box-shadow: var(--shadow); }
form label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
form input {
  width: 100%; margin-top: 4px; padding: 11px 13px; border: 1px solid var(--border);
  border-radius: 12px; background: var(--bg); color: var(--text); font-size: 15px;
  transition: border-color .15s, box-shadow .15s;
}
form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3.5px var(--accent-soft); }
.hint { font-size: 11px; }
.warn-note { font-size: 12px; color: var(--muted); background: var(--accent-soft); padding: 9px 11px; border-radius: 12px; }
.btn {
  padding: 9px 16px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--panel); color: var(--text); cursor: pointer; font-size: 14px; font-weight: 500;
}
.btn.primary { background: var(--accent); border: none; color: #fff; }
form .btn.primary { width: 100%; padding: 12px; font-size: 15px; }
.btn:hover { filter: brightness(1.05); }

/* ================= layout ================= */
/* --vvh tracks the visual viewport: with the mobile keyboard open the app
   shrinks and the chat header stays pinned to the top of the screen */
.app { display: flex; height: var(--vvh, 100dvh); }
@media (max-width: 720px) {
  body { position: fixed; inset: 0; }
}

/* ---- sidebar ---- */
.sidebar {
  width: 372px; min-width: 264px; max-width: 40vw; background: var(--panel);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
}
.side-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; position: relative; }
.search-wrap { flex: 1; }
.search-wrap input {
  width: 100%; padding: 8px 14px; border: none; border-radius: 10px;
  background: var(--hover); color: var(--text); font-size: 15px;
}
.search-wrap input::placeholder { color: var(--muted); }
.search-wrap input:focus { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.icon-btn {
  background: none; border: none; color: var(--muted); cursor: pointer;
  padding: 8px; border-radius: 10px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--hover); color: var(--accent); }
.dropdown {
  position: absolute; top: 50px; right: 8px; z-index: 30; min-width: 230px;
  background: var(--glass); backdrop-filter: blur(24px) saturate(1.8);
  border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow-lg); padding: 5px; display: flex; flex-direction: column;
  animation: popIn .14s ease-out;
}
.dropdown button {
  display: flex; align-items: center; gap: 10px;
  background: none; border: none; color: var(--text); text-align: left; font-size: 14px;
  padding: 9px 11px; border-radius: 9px; cursor: pointer; white-space: nowrap;
}
.dropdown button .ic { color: var(--muted); }
.dropdown button:hover { background: var(--hover); }
.dropdown.ctx { position: fixed; top: 0; left: 0; right: auto; }

/* chat list loading skeleton */
.skel-chat { pointer-events: none; }
.skel-chat .avatar.skel { background: none; }
.skel-line { height: 12px; border-radius: 6px; margin: 4px 0; }
.chat-item .avatar.skel { border-radius: 50%; }

.chat-filters { display: flex; gap: 6px; padding: 4px 12px 8px; }
.chat-filter {
  border: none; cursor: pointer; font-size: 13px; font-weight: 500;
  padding: 6px 13px; border-radius: 16px; background: var(--hover); color: var(--muted);
}
.chat-filter.active { background: var(--accent); color: #fff; }
.chat-list { overflow-y: auto; scrollbar-gutter: stable; padding: 2px 0; }
.side-section { border-top: 1px solid var(--border); overflow-y: auto; }
.side-title {
  font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); padding: 10px 16px 4px; display: flex; align-items: center; gap: 8px;
}
.conn { width: 7px; height: 7px; border-radius: 50%; display: inline-block; transition: background .3s; }
.conn.online { background: var(--online); }
.conn.offline { background: var(--danger); }

.chat-item {
  display: flex; align-items: center; gap: 12px; padding: 8px 12px; cursor: pointer;
  border-radius: 12px; margin: 1px 6px; transition: background .12s;
}
.chat-item:hover { background: var(--hover); }
@keyframes archiveOut { to { opacity: 0; transform: translateX(-40px) scale(.96); } }
.chat-item.archiving { animation: archiveOut .24s ease forwards; pointer-events: none; }
.chat-item.archive-row { color: var(--muted); font-weight: 500; }
.chat-item.archive-row .ci-name { font-size: 14.5px; }
.ci-badge.archive-count { background: var(--muted); margin-left: auto; }
.chat-item.active { background: var(--active); color: #fff; }
.chat-item.active .ci-preview, .chat-item.active .ci-time, .chat-item.active .ci-name { color: #fff; }
.ci-body { flex: 1; min-width: 0; }
.ci-top { display: flex; align-items: baseline; gap: 8px; }
.ci-name { font-weight: 590; font-size: 15px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-time { font-size: 12px; color: var(--muted); flex: none; font-variant-numeric: tabular-nums; }
.ci-bottom { display: flex; align-items: center; gap: 8px; }
.cl-section { padding: 10px 14px 4px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.ci-preview { flex: 1; font-size: 13.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-preview.online-text, .typing-preview { color: var(--accent); }
.ci-tick { color: var(--muted); font-weight: 700; letter-spacing: -1px; }
.ci-tick.read { color: var(--accent); }
.chat-item.active .ci-tick { color: rgb(255 255 255 / 80%); }
.typing-preview { font-style: italic; }
.ci-pin { flex: none; color: var(--muted); display: inline-flex; }
.chat-item.active .ci-pin { color: #fff; }
.ci-badge.muted-badge { background: var(--muted); }
.chat-item.active .ci-badge.muted-badge { background: rgb(255 255 255 / 55%); color: var(--accent); }
.ci-badge {
  flex: none; min-width: 21px; height: 21px; border-radius: 11px; background: var(--accent);
  color: #fff; font-size: 12px; font-weight: 600; display: flex; align-items: center; justify-content: center; padding: 0 6px;
}
.chat-item.active .ci-badge { background: #fff; color: var(--accent); }

.avatar {
  width: 44px; height: 44px; border-radius: 50%; flex: none; position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 15px; font-weight: 600; user-select: none;
  background: linear-gradient(135deg, #7fa7e8, #4a76c9);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatar.uploading::after {
  content: ''; position: absolute; inset: 0; border-radius: 50%; background: rgb(0 0 0 / 45%);
  border: 2.5px solid rgb(255 255 255 / 35%); border-top-color: #fff; box-sizing: border-box;
  animation: spin .8s linear infinite;
}
.saved-avatar { background: linear-gradient(135deg, var(--accent-2), var(--accent)); }
.saved-avatar .ic { color: #fff; }
.avatar.online::after {
  content: ''; position: absolute; right: 0; bottom: 0; width: 11px; height: 11px;
  border-radius: 50%; background: var(--online); border: 2px solid var(--panel);
}
#me-avatar { width: 36px; height: 36px; font-size: 13px; }

.job-tag {
  flex: none; font-size: 11px; font-weight: 590; line-height: 1;
  color: var(--accent); background: var(--accent-soft);
  border-radius: 7px; padding: 3px 7px; max-width: 130px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-item.active .job-tag { color: #fff; background: rgb(255 255 255 / 24%); }
.edit-job { opacity: 0; transition: opacity .12s; }
.chat-item:hover .edit-job { opacity: .9; }

/* ---- chat area & wallpapers ---- */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; background: var(--chat-bg); }
.chat::before { content: ''; position: absolute; inset: 0; pointer-events: none; }
.chat.wp-logo::before {
  background-image: url('/icons/wito-tile.png');
  background-size: 150px; opacity: var(--tile-opacity); filter: var(--tile-filter);
}
/* Chat wallpapers — soft mesh gradients (Telegram/WhatsApp style). Each class
   only declares its light (--wl) and dark (--wd) gradient; two global rules
   apply the right one per theme, so adding a wallpaper is a single line. */
.chat[class*="wp-"] { background: var(--wl, var(--chat-bg)); }
:root[data-theme='dark'] .chat[class*="wp-"] { background: var(--wd, var(--chat-bg)); }
@media (prefers-color-scheme: dark) { :root:not([data-theme='light']) .chat[class*="wp-"] { background: var(--wd, var(--chat-bg)); } }

.chat.wp-plain { --wl: var(--chat-bg); --wd: var(--chat-bg); }
.chat.wp-blue {
  --wl: radial-gradient(at 18% 18%,#d6ecff 0,transparent 55%),radial-gradient(at 82% 12%,#bcd6f2 0,transparent 50%),radial-gradient(at 55% 92%,#e2f0ff 0,transparent 55%),#c6dcf4;
  --wd: radial-gradient(at 18% 18%,#14293f 0,transparent 55%),radial-gradient(at 82% 12%,#0d1c30 0,transparent 50%),#0a1522; }
.chat.wp-mint {
  --wl: radial-gradient(at 20% 15%,#dcf7e8 0,transparent 55%),radial-gradient(at 80% 20%,#bff0d4 0,transparent 50%),#c6e8d4;
  --wd: radial-gradient(at 20% 15%,#10281c 0,transparent 55%),radial-gradient(at 80% 20%,#0c2016 0,transparent 50%),#091810; }
.chat.wp-gradient {
  --wl: radial-gradient(at 20% 20%,#c7d8ec 0,transparent 55%),radial-gradient(at 80% 15%,#aec6e0 0,transparent 50%),#9fb8d2;
  --wd: radial-gradient(at 20% 20%,#1d1b29 0,transparent 55%),radial-gradient(at 80% 15%,#17151f 0,transparent 50%),#100f16; }
.chat.wp-lavender {
  --wl: radial-gradient(at 18% 20%,#ece4ff 0,transparent 55%),radial-gradient(at 82% 12%,#dcc9ff 0,transparent 50%),#d2c2ef;
  --wd: radial-gradient(at 18% 20%,#1e1830 0,transparent 55%),radial-gradient(at 82% 12%,#171226 0,transparent 50%),#120f1e; }
.chat.wp-sunset {
  --wl: radial-gradient(at 15% 20%,#ffe6c9 0,transparent 55%),radial-gradient(at 85% 15%,#ffcbd6 0,transparent 50%),radial-gradient(at 60% 92%,#ffdcc0 0,transparent 55%),#ffd0bd;
  --wd: radial-gradient(at 15% 20%,#2e1b16 0,transparent 55%),radial-gradient(at 85% 15%,#2a1520 0,transparent 50%),#1a0f12; }
.chat.wp-rose {
  --wl: radial-gradient(at 20% 20%,#ffe4ef 0,transparent 55%),radial-gradient(at 80% 12%,#ffd0e0 0,transparent 50%),#f7cbdc;
  --wd: radial-gradient(at 20% 20%,#2c1520 0,transparent 55%),radial-gradient(at 80% 12%,#230f19 0,transparent 50%),#1a0d14; }
.chat.wp-sand {
  --wl: radial-gradient(at 25% 15%,#f5ecd9 0,transparent 55%),radial-gradient(at 80% 20%,#ecdcc0 0,transparent 50%),#e9ddc6;
  --wd: radial-gradient(at 25% 15%,#241f16 0,transparent 55%),radial-gradient(at 80% 20%,#1b170f 0,transparent 50%),#16130d; }
.chat.wp-forest {
  --wl: radial-gradient(at 20% 20%,#d4ecd6 0,transparent 55%),radial-gradient(at 80% 12%,#b6ddc2 0,transparent 50%),#aad2b6;
  --wd: radial-gradient(at 20% 20%,#0f2318 0,transparent 55%),radial-gradient(at 80% 12%,#0b1c12 0,transparent 50%),#08150e; }
.chat.wp-aurora {
  --wl: radial-gradient(at 12% 18%,#c2f0e0 0,transparent 50%),radial-gradient(at 85% 12%,#dcc9ff 0,transparent 50%),radial-gradient(at 60% 92%,#ffd9c2 0,transparent 55%),#d6e4ff;
  --wd: radial-gradient(at 12% 18%,#0d2620 0,transparent 50%),radial-gradient(at 85% 12%,#1c1630 0,transparent 50%),radial-gradient(at 60% 92%,#2a1a12 0,transparent 55%),#0c1018; }
.chat.wp-graphite {
  --wl: radial-gradient(at 20% 20%,#e2e7ee 0,transparent 55%),radial-gradient(at 80% 18%,#cdd4dd 0,transparent 50%),#c4ccd6;
  --wd: radial-gradient(at 20% 20%,#1b1f26 0,transparent 55%),radial-gradient(at 80% 18%,#14171d 0,transparent 50%),#0e1014; }
.chat > * { position: relative; }

.chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; }
.empty-pill {
  background: var(--glass); backdrop-filter: blur(12px); color: var(--muted);
  border: 1px solid var(--border); padding: 7px 16px; border-radius: 16px; font-size: 14px;
}
.chat-pane { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }

.chat-head {
  display: flex; align-items: center; gap: 12px; padding: 7px 14px;
  background: var(--glass); backdrop-filter: blur(24px) saturate(1.8);
  border-bottom: 1px solid var(--border); z-index: 5;
}
.chat-head .avatar { width: 38px; height: 38px; }
.chat-head-info { flex: 1; min-width: 0; }
.chat-head-info strong { display: block; font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-sub { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-sub.online-text { color: var(--accent); }
.icon-btn.back { display: none; }

/* in-chat search */
.chat-search {
  position: relative; display: flex; align-items: center; gap: 8px;
  background: var(--glass); backdrop-filter: blur(24px) saturate(1.8);
  border-bottom: 1px solid var(--border); padding: 6px 14px; z-index: 6;
  animation: popIn .12s ease-out;
}
.chat-search input {
  flex: 1; border: none; border-radius: 10px; padding: 8px 12px;
  background: var(--hover); color: var(--text); font-size: 15px;
}
.chat-search input:focus { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.cs-count { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.cs-results {
  position: absolute; top: 100%; left: 8px; right: 8px; max-height: 46dvh; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 0 0 14px 14px;
  box-shadow: var(--shadow-lg); z-index: 7;
}
.cs-row { padding: 8px 14px; cursor: pointer; border-bottom: 1px solid var(--border); }
.cs-row:last-child { border-bottom: none; }
.cs-row:hover { background: var(--hover); }
.cs-top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.cs-date { color: var(--muted); flex: none; }
.cs-snippet { font-size: 13.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cs-hl { background: var(--accent-soft); color: var(--accent); border-radius: 3px; padding: 0 1px; font-weight: 600; }

.messages { flex: 1; overflow-y: auto; scrollbar-gutter: stable; padding: 12px 7% 8px; display: flex; flex-direction: column; }
.day-sep {
  align-self: center; font-size: 12px; font-weight: 590; color: var(--muted);
  background: var(--glass); border: 1px solid var(--border); backdrop-filter: blur(10px);
  border-radius: 12px; padding: 3px 11px; margin: 10px 0 6px;
  position: sticky; top: 4px; z-index: 3;
}

.heart-pop {
  position: absolute; left: 50%; top: 40%; font-size: 30px; pointer-events: none; z-index: 6;
  animation: heartPop .7s ease-out forwards;
}
@keyframes heartPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.4); }
  25% { opacity: 1; transform: translate(-50%, -90%) scale(1.25); }
  100% { opacity: 0; transform: translate(-50%, -170%) scale(1); }
}
.unread-sep {
  align-self: stretch; text-align: center; font-size: 12px; font-weight: 600; color: var(--accent);
  background: var(--accent-soft); border-radius: 8px; padding: 4px 0; margin: 12px 0 8px;
}
.msg-row { position: relative; display: flex; gap: 8px; align-items: flex-end; max-width: min(480px, 86%); margin-bottom: 2.5px; }
.msg-row.anim { animation: msgIn .18s ease-out; }
.msg-row.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg-row .avatar { width: 32px; height: 32px; font-size: 12px; margin-bottom: 3px; }
.msg-row.chain .avatar { visibility: hidden; }

.bubble {
  position: relative; background: var(--bubble); color: var(--bubble-text);
  border-radius: 17px; padding: 7px 11px 6px; box-shadow: var(--shadow);
  min-width: 68px; max-width: 100%;
}
.msg-row:not(.mine):not(.chain) .bubble { border-bottom-left-radius: 5px; }
.msg-row.mine:not(.chain) .bubble { border-bottom-right-radius: 5px; }
.msg-row:not(.mine):not(.chain) .bubble::after {
  content: ''; position: absolute; left: -6.5px; bottom: 0; width: 9px; height: 13px;
  background: var(--bubble); clip-path: path('M9 0 C8 6.5 5 10 0 13 L9 13 Z');
}
.msg-row.mine:not(.chain) .bubble::after {
  content: ''; position: absolute; right: -6.5px; bottom: 0; width: 9px; height: 13px;
  background: var(--mine-flat); clip-path: path('M0 0 C1 6.5 4 10 9 13 L0 13 Z');
}
.mine .bubble { background: var(--mine); color: var(--mine-text); }
.msg-sender { font-size: 12.5px; font-weight: 600; margin-bottom: 1px; }
.msg-text { white-space: pre-wrap; word-break: break-word; font-size: 15px; }
.emoji {
  font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
  font-size: 1.35em; line-height: 1; vertical-align: -0.14em;
}
/* 1–3 emojis without text: no bubble, just big emoji */
.bubble.emoji-only { background: transparent; box-shadow: none; padding: 0 2px; min-width: 0; }
.bubble.emoji-only::after { display: none; }
.bubble.emoji-only .msg-text { line-height: 1.1; }
.bubble.emoji-only .emoji { font-size: 46px; }
.bubble.emoji-only .msg-meta { color: var(--muted); margin-top: 12px; }
.mine .bubble.emoji-only { color: var(--text); }
.mine .bubble.emoji-only .msg-meta, .mine .bubble.emoji-only .msg-meta .tick.read { color: var(--muted); }

/* photo/video without caption: bare rounded media, time pill overlaid */
.bubble.media-only { background: transparent; box-shadow: none; padding: 0; min-width: 0; }
.bubble.media-only::after { display: none; }
.media-wrap { position: relative; }
.bubble.media-only .media-img, .bubble.media-only .media-video,
.bubble.media-only .media-placeholder { margin: 0; border-radius: 14px; display: block; }
.bubble.media-only .msg-meta {
  position: absolute; right: 8px; bottom: 8px; float: none; margin: 0;
  background: rgb(0 0 0 / 45%); color: #fff; padding: 2px 8px; border-radius: 10px;
  backdrop-filter: blur(4px);
}
.bubble.media-only .msg-meta .tick, .mine .bubble.media-only .msg-meta { color: #fff; }
.bubble.media-only .msg-sender {
  position: absolute; top: 8px; left: 10px; z-index: 2;
  background: rgb(0 0 0 / 45%); color: #fff !important; padding: 2px 8px; border-radius: 10px;
  backdrop-filter: blur(4px); font-size: 12px;
}
.msg-text a { color: var(--accent); text-decoration-thickness: 1px; }
.msg-text code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .92em;
  background: rgb(128 128 128 / 18%); padding: 1px 5px; border-radius: 5px;
}
.mine .msg-text code { background: rgb(255 255 255 / 22%); }
.msg-text strong { font-weight: 700; }
.msg-text em { font-style: italic; }
.mention { color: var(--accent); font-weight: 600; cursor: pointer; }
.mine .mention { color: #fff; text-decoration: underline; text-underline-offset: 2px; }
.mention-me { background: color-mix(in srgb, var(--accent) 22%, transparent); border-radius: 5px; padding: 0 3px; }
.mine .mention-me { background: rgb(255 255 255 / 26%); }

/* @mention autocomplete popup */
.mention-pop {
  position: absolute; bottom: 72px; left: 7%; z-index: 11; width: 300px; max-width: 86%;
  max-height: 240px; overflow-y: auto;
  background: var(--glass); backdrop-filter: blur(24px) saturate(1.8);
  border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg);
  animation: popIn .12s ease-out;
}
.mention-row { display: flex; align-items: center; gap: 10px; padding: 7px 12px; cursor: pointer; }
.mention-row .avatar { width: 32px; height: 32px; font-size: 12px; }
.mention-row.active, .mention-row:hover { background: var(--hover); }
@media (max-width: 720px) { .mention-pop { left: 8px; width: auto; right: 8px; } }
.mine .msg-text a { color: inherit; font-weight: 500; }
.msg-meta {
  float: right; margin: 7px -4px 0 8px; font-size: 10.5px; color: var(--muted);
  display: flex; gap: 3px; align-items: center; font-variant-numeric: tabular-nums;
}
.mine .msg-meta { color: var(--mine-meta); }
.msg-meta .ic { width: 12px; height: 12px; opacity: .8; }
.msg-meta .send-failed {
  display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px; border-radius: 50%; background: #fff; color: var(--danger);
  font-weight: 700; font-size: 11px;
}
.msg-row.failed .bubble { opacity: .85; cursor: pointer; }
.msg-row.failed .bubble::after { background: var(--danger) !important; }
.msg-meta .tick { font-size: 11px; letter-spacing: -3px; padding-right: 3px; }
.msg-meta .tick.read { color: var(--accent); }
.mine .msg-meta .tick.read { color: #fff; }

.quick-reply {
  position: absolute; top: 50%; transform: translateY(-50%); border: none; cursor: pointer;
  width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: var(--glass); backdrop-filter: blur(8px); border: 1px solid var(--border);
  color: var(--muted); opacity: 0; transition: opacity .12s;
}
.msg-row:not(.mine) .quick-reply { right: -40px; }
.msg-row.mine .quick-reply { left: -40px; }
.msg-row:hover .quick-reply { opacity: 1; }
.quick-reply:hover { color: var(--accent); }

.fwd-label {
  display: flex; align-items: center; gap: 5px;
  font-size: 12.5px; font-weight: 590; color: var(--accent); margin: 1px 0 3px;
}
.mine .fwd-label { color: var(--mine-meta); }

.reply-quote {
  border-left: 3px solid var(--accent); background: var(--accent-soft);
  border-radius: 7px; padding: 3px 8px; margin-bottom: 4px; cursor: pointer; overflow: hidden;
}
.reply-quote.has-media { display: flex; align-items: center; gap: 8px; }
.reply-quote .rq-body { min-width: 0; flex: 1; }
.rq-thumb { width: 34px; height: 34px; border-radius: 6px; object-fit: cover; flex: none; background: rgb(0 0 0 / 8%); }
.rq-thumb-ico { display: flex; align-items: center; justify-content: center; color: var(--accent); }
.mine .rq-thumb-ico { color: #fff; }
.mine .reply-quote { border-left-color: rgb(255 255 255 / 80%); background: rgb(255 255 255 / 16%); }
.rq-name { font-size: 12.5px; font-weight: 600; color: var(--accent); }
.mine .rq-name { color: #fff; }
.rq-text { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .8; }

.msg-row.flash .bubble { outline: 2px solid var(--accent); }

.sys-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.sys-actions .btn.small { padding: 6px 12px; font-size: 13px; }

/* group read-by avatars under a message */
.read-avatars { display: flex; align-items: center; gap: 0; margin-top: 4px; cursor: pointer; }
.read-avatars.hidden { display: none; }
.read-avatars .avatar.ra-mini {
  width: 18px; height: 18px; font-size: 8px; margin-left: -5px; border: 1.5px solid var(--bubble);
}
.mine .read-avatars .avatar.ra-mini { border-color: var(--mine-flat); }
.read-avatars .avatar.ra-mini:first-child { margin-left: 0; }
.ra-more { font-size: 11px; color: var(--muted); margin-left: 4px; }
.mine .ra-more { color: var(--mine-meta); }

.delivery-status {
  align-self: flex-end; font-size: 11px; font-weight: 500; color: var(--muted);
  margin: 0 8px 4px 0; animation: fadeIn .2s;
}

/* reactions */
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reactions.hidden { display: none; }
.reaction-chip {
  display: inline-flex; align-items: center; gap: 4px; border: none; cursor: pointer;
  background: var(--hover); border-radius: 12px; padding: 2px 8px; font-size: 14px; line-height: 1.4;
  animation: popIn .15s ease-out;
}
.mine .reaction-chip { background: rgb(255 255 255 / 22%); color: #fff; }
.reaction-chip.mine-r { background: var(--accent-soft); box-shadow: inset 0 0 0 1.5px var(--accent); }
.mine .reaction-chip.mine-r { background: rgb(255 255 255 / 32%); box-shadow: inset 0 0 0 1.5px #fff; }
.rc-count { font-size: 12px; font-weight: 600; color: var(--muted); }
.mine .rc-count { color: #fff; }
.reaction-chip.mine-r .rc-count { color: var(--accent); }

/* message action sheet: blurred backdrop, reactions above, menu below */
.action-backdrop {
  position: fixed; inset: 0; z-index: 45; background: rgb(0 0 0 / 28%);
  backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px); animation: fadeIn .18s;
}
/* fixed-layer clone of the pressed message: escapes the scroll container,
   slides with a spring и не может быть обрезан списком */
.msg-row.msg-clone {
  position: fixed; z-index: 46; margin: 0; pointer-events: none;
  transition: top .3s cubic-bezier(.34, 1.3, .64, 1);
}
.msg-row.msg-clone .quick-reply { display: none; }
@keyframes sheetIn { from { opacity: 0; transform: scale(.72); } }
@keyframes rPop { from { opacity: 0; transform: scale(.2) translateY(12px); } }
.as-reactions {
  position: fixed; z-index: 47; display: flex; align-items: center;
  background: var(--glass); backdrop-filter: blur(24px) saturate(1.8);
  border: 1px solid var(--border); border-radius: 26px; padding: 5px 7px;
  box-shadow: var(--shadow-lg); animation: sheetIn .2s cubic-bezier(.34, 1.56, .64, 1);
  transform-origin: bottom center;
}
.as-reactions button {
  border: none; background: none; cursor: pointer; font-size: 28px; line-height: 1;
  padding: 3px 5px; border-radius: 50%; transition: transform .12s;
  animation: rPop .3s cubic-bezier(.34, 1.56, .64, 1) backwards;
  font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
}
.as-reactions button:hover { transform: scale(1.3) translateY(-3px); }
.as-reactions .as-plus {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%; color: var(--muted);
  background: var(--hover); margin-left: 2px;
}
.as-reactions .as-plus:hover { color: var(--accent); transform: scale(1.15); }
.as-menu {
  position: fixed; z-index: 47; min-width: 232px; overflow: hidden;
  background: var(--glass); backdrop-filter: blur(24px) saturate(1.8);
  border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  animation: sheetIn .2s cubic-bezier(.34, 1.56, .64, 1); transform-origin: top center;
}
.as-menu button {
  display: flex; align-items: center; gap: 12px; padding: 11px 15px; font-size: 15px;
  background: none; border: none; border-bottom: 1px solid var(--border);
  cursor: pointer; color: var(--text); text-align: left;
}
.as-menu button:last-child { border-bottom: none; }
.as-menu button:hover { background: var(--hover); }
.as-menu button .ic { color: var(--muted); }
.as-menu button.danger, .as-menu button.danger .ic { color: var(--danger); }
.as-menu .as-readinfo { font-size: 13.5px; color: var(--muted); gap: 8px; }
.as-menu .as-readinfo .ic { color: var(--accent); }
.as-readavs { display: inline-flex; }
.as-readavs .avatar.mini {
  width: 22px; height: 22px; font-size: 9px; margin-left: -6px; border: 1.5px solid var(--panel);
}
.as-readavs .avatar.mini:first-child { margin-left: 0; }

/* media */
.media-img, .media-video {
  display: block; max-width: 320px; max-height: 340px; width: 100%;
  border-radius: 12px; margin: 2px 0 4px; cursor: pointer; object-fit: cover; background: rgb(0 0 0 / 8%);
}
/* photo album grid */
.album { display: grid; gap: 3px; border-radius: 12px; overflow: hidden; margin: 2px 0 4px; max-width: 320px; }
.album .media-img, .album .media-placeholder { margin: 0; border-radius: 0; width: 100%; height: 100%; max-width: none; max-height: none; aspect-ratio: 1 / 1; }
.album-1 { grid-template-columns: 1fr; }
.album-2 { grid-template-columns: 1fr 1fr; }
.album-3 { grid-template-columns: 1fr 1fr; }
.album-3 > :first-child { grid-column: span 2; aspect-ratio: 2 / 1; }
.album-4 { grid-template-columns: 1fr 1fr; }

.media-img { transition: filter .15s; animation: fadeIn .25s ease; }
.media-img:hover { filter: brightness(.93); }
.media-video { cursor: default; }
.media-placeholder {
  width: 260px; height: 180px; border-radius: 12px; margin: 2px 0 4px;
  background: rgb(0 0 0 / 7%); display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 14px;
}
.spinner { width: 24px; height: 24px; border: 2.5px solid rgb(128 128 128 / 25%); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }

.file-card { display: flex; align-items: center; gap: 10px; padding: 4px 2px; cursor: pointer; min-width: 200px; }
.file-icon {
  width: 42px; height: 42px; border-radius: 50%; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; flex: none;
}
.mine .file-icon { background: rgb(255 255 255 / 22%); }
.file-info { min-width: 0; }
.file-name { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 240px; }
.file-size { font-size: 12.5px; color: var(--muted); }
.mine .file-size { color: var(--mine-meta); }

/* round video note (circle) */
.bubble.circle-only { background: transparent; box-shadow: none; padding: 0; min-width: 0; }
.bubble.circle-only::after { display: none; }
.circle-msg { position: relative; width: 200px; height: 200px; }
.circle-video, .circle-ph {
  width: 200px; height: 200px; border-radius: 50%; object-fit: cover;
  background: rgb(0 0 0 / 10%); display: block; cursor: pointer;
}
.circle-ph { display: flex; align-items: center; justify-content: center; color: var(--muted); }
.circle-dur {
  position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 2px;
  background: rgb(0 0 0 / 55%); color: #fff; font-size: 12px; padding: 2px 9px; border-radius: 11px;
  backdrop-filter: blur(4px); font-variant-numeric: tabular-nums;
}
.circle-dur.hidden { display: none; }
.circle-dur.sound { background: var(--accent); }

/* drag & drop overlay */
.drop-overlay {
  position: absolute; inset: 0; z-index: 12; display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--accent) 18%, rgb(0 0 0 / 30%));
  backdrop-filter: blur(3px); animation: fadeIn .12s;
}
.drop-inner {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 30px 44px; border: 2.5px dashed rgb(255 255 255 / 80%); border-radius: 20px;
  color: #fff; font-size: 16px; font-weight: 600; text-shadow: 0 1px 3px rgb(0 0 0 / 40%);
  pointer-events: none;
}
.drop-inner .ic { color: #fff; }

/* multi-select */
.select-bar {
  display: flex; align-items: center; gap: 8px; padding: 8px 14px;
  background: var(--glass); backdrop-filter: blur(24px) saturate(1.8);
  border-bottom: 1px solid var(--border); z-index: 6; animation: popIn .12s ease-out;
}
.select-count { flex: 1; font-weight: 600; font-size: 15px; }
.select-bar .icon-btn { color: var(--accent); }
.select-bar #select-delete { color: var(--danger); }
.app.selecting .msg-row { cursor: pointer; }
.app.selecting .bubble { transition: transform .1s; }
.msg-row.selected .bubble { outline: 2px solid var(--accent); }
.msg-row.selected::before {
  content: '✓'; position: absolute; top: 50%; transform: translateY(-50%);
  width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #fff;
  font-size: 13px; display: flex; align-items: center; justify-content: center; z-index: 2;
}
.msg-row.selected:not(.mine)::before { right: -30px; }
.msg-row.selected.mine::before { left: -30px; }
@media (max-width: 720px) {
  .msg-row.selected::before { right: auto; left: -4px; }
  .msg-row.selected.mine::before { left: auto; right: -4px; }
}

/* pinned message bar */
.pinned-bar {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  padding: 6px 14px; background: var(--glass); backdrop-filter: blur(24px) saturate(1.8);
  border-bottom: 1px solid var(--border); z-index: 5; animation: popIn .12s ease-out;
}
.pinned-ico { color: var(--accent); display: inline-flex; flex: none; }
.pinned-body { flex: 1; min-width: 0; border-left: 2px solid var(--accent); padding-left: 10px; }
.pinned-title { font-size: 12.5px; font-weight: 600; color: var(--accent); }
.pinned-text { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* circle recorder overlay */
.circle-overlay {
  position: fixed; inset: 0; z-index: 62; background: rgb(0 0 0 / 92%);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px;
  animation: fadeIn .15s; padding: 20px;
}
.circle-stage { position: relative; width: min(300px, 78vw); height: min(300px, 78vw); }
#circle-preview {
  width: 100%; height: 100%; border-radius: 50%; object-fit: cover;
  transform: scaleX(-1); background: #000; box-shadow: 0 8px 40px rgb(0 0 0 / 50%);
}
.circle-ring { position: absolute; inset: -6px; width: calc(100% + 12px); height: calc(100% + 12px); transform: rotate(-90deg); pointer-events: none; }
.circle-ring circle { fill: none; stroke: var(--danger); stroke-width: 3; stroke-linecap: round; transition: stroke-dashoffset .1s linear; }
.circle-timer { color: #fff; font-size: 17px; font-variant-numeric: tabular-nums; }
.circle-controls { display: flex; gap: 24px; }
.circle-controls .call-btn.recording { background: #fff; }
.circle-controls .call-btn.recording .ic { color: var(--danger); fill: var(--danger); }
.circle-hint { color: rgb(255 255 255 / 65%); font-size: 13px; margin: 0; text-align: center; }

.voice-player { display: flex; align-items: center; gap: 10px; padding: 4px 2px; min-width: 230px; }
.vp-btn {
  width: 40px; height: 40px; border-radius: 50%; border: none; cursor: pointer; flex: none;
  background: var(--accent); color: #fff; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.mine .vp-btn { background: rgb(255 255 255 / 22%); }
.vp-bars { display: flex; align-items: center; gap: 2px; height: 30px; cursor: pointer; flex: 1; }
.vp-bars i { width: 3px; border-radius: 2px; background: rgb(128 128 128 / 35%); transition: background .15s, height .25s ease-out; }
.vp-bars i.on { background: var(--accent); }
.mine .vp-bars i { background: rgb(255 255 255 / 35%); }
.mine .vp-bars i.on { background: #fff; }
.vp-time { font-size: 12px; color: var(--muted); flex: none; min-width: 34px; text-align: right; font-variant-numeric: tabular-nums; }
.mine .vp-time { color: var(--mine-meta); }
.vp-speed {
  flex: none; border: none; cursor: pointer; font-size: 11px; font-weight: 700;
  padding: 2px 6px; border-radius: 9px; background: rgb(128 128 128 / 20%); color: var(--muted);
}
.mine .vp-speed { background: rgb(255 255 255 / 22%); color: #fff; }
.vp-speed.hidden { display: none; }

/* skeletons / empty */
.skel {
  background: linear-gradient(100deg, rgb(128 128 128 / 12%) 40%, rgb(128 128 128 / 22%) 50%, rgb(128 128 128 / 12%) 60%);
  background-size: 200% 100%; animation: shimmer 1.2s linear infinite;
}
.skel-row .bubble.skel { box-shadow: none; }
.chat-welcome {
  align-self: center; margin: auto; text-align: center; color: var(--muted);
  background: var(--glass); backdrop-filter: blur(12px); border: 1px solid var(--border);
  border-radius: 20px; padding: 22px 26px; max-width: 300px; animation: popIn .25s ease-out;
}
.cw-emoji { font-size: 38px; margin-bottom: 8px; }
.cw-title { font-weight: 600; font-size: 16px; margin-bottom: 4px; color: var(--text); }
.cw-text { font-size: 13px; }

.typing { min-height: 20px; padding: 0 7% 2px; font-size: 12.5px; color: var(--muted); }
.typing-dots { display: inline-flex; gap: 3px; margin-right: 6px; vertical-align: middle; }
.typing-dots i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; animation: tdot 1.2s infinite; }
.typing-dots i:nth-child(2) { animation-delay: .2s; }
.typing-dots i:nth-child(3) { animation-delay: .4s; }

.scroll-down {
  position: absolute; right: 18px; bottom: 92px; min-width: 42px; height: 42px; border-radius: 21px;
  background: var(--glass); backdrop-filter: blur(16px); color: var(--muted);
  border: 1px solid var(--border); cursor: pointer; box-shadow: var(--shadow-lg); z-index: 6;
  display: flex; align-items: center; justify-content: center; gap: 7px; padding: 0 11px;
  font-size: 13px; font-weight: 500; animation: popIn .15s ease-out;
}
.scroll-down:hover { color: var(--accent); }
.scroll-down .sd-label { display: none; }
.scroll-down.has-new { color: #fff; background: var(--accent); border-color: transparent; }
.scroll-down.has-new .sd-label { display: inline; }

/* context bars */
.context-bar {
  display: flex; align-items: center; gap: 10px;
  background: var(--glass); backdrop-filter: blur(24px) saturate(1.8);
  border-top: 1px solid var(--border); padding: 6px 14px; animation: popIn .12s ease-out;
}
.context-bar-body { flex: 1; min-width: 0; border-left: 3px solid var(--accent); padding-left: 10px; }
.cb-title { font-size: 12.5px; font-weight: 600; color: var(--accent); }
.cb-text { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-preview { width: 40px; height: 40px; border-radius: 10px; background: var(--hover); display: flex; align-items: center; justify-content: center; overflow: hidden; color: var(--muted); }
.attach-preview img { width: 100%; height: 100%; object-fit: cover; }

/* composer */
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 8px 7% 14px; background: transparent; }
.composer-box {
  flex: 1; min-width: 0; display: flex; align-items: flex-end;
  background: var(--glass); backdrop-filter: blur(24px) saturate(1.8);
  border: 1px solid var(--border); border-radius: 22px; box-shadow: var(--shadow);
}
.composer textarea {
  flex: 1; resize: none; border: none; background: transparent; padding: 11px 6px; font: inherit; font-size: 15px;
  color: var(--text); max-height: 160px;
}
.composer textarea::placeholder { color: var(--muted); }
.composer textarea:focus { outline: none; }
.icon-btn.tool { border-radius: 50%; padding: 10px; color: var(--muted); background: transparent; }
.icon-btn.tool:hover { color: var(--accent); background: transparent; }
#emoji-btn { margin-left: 4px; }
#mic-btn { margin-right: 4px; }
#mic-btn.recording { color: #fff; background: var(--danger); animation: pulse 1.2s infinite; }
.send-btn {
  width: 44px; height: 44px; border-radius: 50%; border: none;
  background: var(--accent); color: #fff; cursor: pointer; flex: none;
  display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow);
}
/* D7: swap mic/circle ↔ send depending on whether there's something to send */
.composer:not(.has-content) #send-btn { display: none; }
.composer.has-content #mic-btn, .composer.has-content #circle-btn { display: none; }
.composer.has-content #send-btn { animation: popScale .18s ease; }
.composer:not(.has-content) #mic-btn, .composer:not(.has-content) #circle-btn { animation: popScale .18s ease; }
@keyframes popScale { from { transform: scale(.55); opacity: .2; } to { transform: scale(1); opacity: 1; } }
.send-btn { transition: opacity .18s ease, transform .12s ease, filter .15s ease; }
.send-btn:hover:not(:disabled) { filter: brightness(1.08); }
.send-btn:active:not(:disabled) { transform: scale(.92); }
.send-btn:disabled { opacity: .4; cursor: default; box-shadow: none; }
.send-btn.sending { opacity: .6; }

/* emoji panel */
.emoji-panel {
  position: absolute; bottom: 76px; left: 7%; z-index: 10; width: 344px; max-width: 90%;
  background: var(--glass); backdrop-filter: blur(24px) saturate(1.8);
  border: 1px solid var(--border); border-radius: 18px;
  box-shadow: var(--shadow-lg); overflow: hidden; animation: popIn .15s ease-out;
}
.emoji-tabs { display: flex; border-bottom: 1px solid var(--border); }
.emoji-tabs button { flex: 1; background: none; border: none; font-size: 17px; padding: 8px 0; cursor: pointer; opacity: .45; }
.emoji-tabs button.active { opacity: 1; border-bottom: 2px solid var(--accent); }
.emoji-grid { height: 244px; overflow-y: auto; display: grid; grid-template-columns: repeat(8, 1fr); padding: 6px; }
.emoji-grid button {
  background: none; border: none; font-size: 24px; padding: 5px 0; cursor: pointer; border-radius: 8px;
  font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
}
.emoji-grid button:hover { background: var(--hover); }

/* lightbox */
.lightbox { position: fixed; inset: 0; z-index: 50; background: rgb(0 0 0 / 90%); display: flex; align-items: center; justify-content: center; animation: fadeIn .15s; overflow: hidden; touch-action: none; }
.lightbox img { max-width: 94vw; max-height: 88vh; border-radius: 6px; transform-origin: center center; cursor: zoom-in; will-change: transform; }
.lightbox img.zoomed { cursor: grab; border-radius: 0; }
.lb-top {
  position: absolute; top: 0; left: 0; right: 0; z-index: 2;
  display: flex; align-items: center; justify-content: flex-end; gap: 6px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: linear-gradient(rgb(0 0 0 / 45%), transparent);
}
.lb-counter { margin-right: auto; color: #fff; font-size: 14px; font-variant-numeric: tabular-nums; }
.lb-btn {
  border: none; cursor: pointer; color: #fff; background: rgb(255 255 255 / 14%);
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; backdrop-filter: blur(6px);
}
.lb-btn:hover { background: rgb(255 255 255 / 28%); }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); z-index: 2; width: 46px; height: 46px; }
.lb-prev { left: 14px; }
.lb-next { right: 14px; }
@media (max-width: 720px) { .lb-nav { display: none; } } /* свайп вместо стрелок */

/* modal */
.modal-backdrop {
  /* height follows the VISIBLE viewport (--vvh), so an open keyboard shrinks
     the box and the modal recenters above the keyboard instead of behind it */
  position: fixed; top: 0; left: 0; right: 0; height: var(--vvh, 100dvh);
  background: rgb(0 0 0 / 40%); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; z-index: 40; padding: 16px; animation: fadeIn .15s;
}
.modal {
  width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 18px; padding: 20px; max-height: calc(var(--vvh, 100dvh) - 24px);
  display: flex; flex-direction: column; min-height: 0;
  box-shadow: var(--shadow-lg); animation: popIn .18s ease-out;
}
.modal h3 { margin: 0 0 12px; letter-spacing: -.02em; }

/* shared content viewer (media / files / links / audio) */
.modal.chatmedia { max-width: 480px; }
.cm-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 0 -4px 10px; }
.cm-tab {
  flex: 1; padding: 9px 4px 10px; background: none; border: none; cursor: pointer; position: relative;
  color: var(--muted); font-size: 13.5px; font-weight: 600; border-radius: 8px 8px 0 0;
}
.cm-tab:hover { background: var(--hover); }
.cm-tab.active { color: var(--accent); }
.cm-tab.active::after { content: ''; position: absolute; left: 8px; right: 8px; bottom: -1px; height: 2px; background: var(--accent); border-radius: 2px; }
.cm-tab[data-count]:not([data-count=""])::before { content: attr(data-count); margin-right: 5px; font-variant-numeric: tabular-nums; opacity: .7; }
.cm-content { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.cm-loading { text-align: center; color: var(--muted); font-size: 13px; padding: 16px; }
.cm-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.cm-tile {
  position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--hover);
  display: grid; place-items: center; cursor: pointer; color: var(--muted);
}
.cm-tile .media-img { width: 100%; height: 100%; object-fit: cover; border-radius: 0; cursor: pointer; }
.cm-tile.cm-vid { background: #000; color: #fff; }
.cm-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.cm-row .file-card, .cm-row .voice-player { flex: 1; min-width: 0; }
.cm-row .cm-date, .cm-link .cm-date { font-size: 11px; color: var(--muted); white-space: nowrap; flex: none; }
.cm-link { display: flex; flex-direction: column; gap: 2px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.cm-link-url { color: var(--accent); font-size: 14px; word-break: break-all; text-decoration: none; }
.cm-link-url:hover { text-decoration: underline; }
.cm-link-text { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cm-entry .cm-entry-ico { width: 40px; height: 40px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.member-picker { flex: 1; min-height: 0; overflow-y: auto; margin: 8px 0; display: flex; flex-direction: column; gap: 2px; }
.pick-row { display: flex; align-items: center; gap: 10px; padding: 6px; cursor: pointer; font-size: 14px; color: var(--text); border-radius: 10px; }
.pick-row:hover { background: var(--hover); }
.pick-row .avatar { width: 34px; height: 34px; font-size: 12px; }
.member-remove { color: var(--danger); flex: none; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }

/* compose FAB + empty states */
.fab {
  position: absolute; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%; border: none; cursor: pointer; z-index: 8;
  background: linear-gradient(135deg, var(--accent-2), var(--accent)); color: #fff;
  font-size: 28px; line-height: 1; box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 45%, transparent);
  display: flex; align-items: center; justify-content: center;
}
.fab:hover { filter: brightness(1.08); }
.sidebar { position: relative; }
.list-empty { padding: 28px 24px; text-align: center; color: var(--muted); font-size: 14px; }
.empty-state {
  padding: 48px 28px; display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center;
}
.empty-state .es-badge {
  width: 76px; height: 76px; border-radius: 24px; display: grid; place-items: center; margin-bottom: 6px;
  color: var(--accent); background: var(--accent-soft);
}
.empty-state .es-title { font-size: 17px; font-weight: 600; }
.empty-state .es-text { font-size: 14px; color: var(--muted); line-height: 1.45; max-width: 260px; }
.empty-state .btn.primary { margin-top: 12px; padding: 11px 22px; width: auto; border-radius: 12px; }

/* new chat */
.newchat-action {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 10px;
  background: none; border: none; border-radius: 12px; cursor: pointer; color: var(--text);
  font-size: 15px; font-weight: 500;
}
.newchat-action:hover { background: var(--hover); }
.nc-ico {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  background: linear-gradient(135deg, var(--accent-2), var(--accent)); color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.newchat-search {
  width: 100%; margin: 10px 0 4px; padding: 10px 14px; border: 1px solid var(--border);
  border-radius: 12px; background: var(--bg); color: var(--text); font-size: 15px;
}
.newchat-search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.nc-hint { font-size: 12.5px; color: var(--muted); padding: 2px 4px 8px; }

/* connection banner */
.conn-banner {
  text-align: center; font-size: 12.5px; font-weight: 500; color: var(--muted);
  background: var(--hover); padding: 5px 0; animation: fadeIn .3s;
}

/* draft preview */
.draft-label { color: var(--danger); font-weight: 590; }

/* danger button */
.btn.danger-btn { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); width: 100%; }
.btn.danger-btn:hover { background: color-mix(in srgb, var(--danger) 8%, transparent); }

/* iOS-style switch */
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 15px; cursor: pointer; min-height: 44px; }
.switch-row + .switch-row { border-top: 1px solid var(--border); }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 2; }
.switch .knob {
  position: absolute; inset: 0; border-radius: 15px; background: var(--hover); transition: background .2s;
}
.switch .knob::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 26px; height: 26px;
  border-radius: 50%; background: #fff; box-shadow: 0 2px 5px rgb(0 0 0 / 25%); transition: transform .2s;
}
.switch input:checked + .knob { background: var(--online); }
.switch input:checked + .knob::after { transform: translateX(20px); }

/* settings */
.settings-card { max-width: 380px; gap: 4px; }
.profile-group { display: flex; align-items: center; gap: 14px; }
.profile-group .avatar.xl { width: 68px; height: 68px; font-size: 26px; cursor: pointer; flex: none; }
.settings-profile-fields { flex: 1; min-width: 0; }
.name-edit-row { display: flex; gap: 8px; align-items: center; }
.name-edit-row input {
  flex: 1; min-width: 0; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--bg); color: var(--text); font-size: 15px;
}
.name-edit-row input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn.small.primary { padding: 7px 12px; font-size: 13px; }
.settings-profile-fields .profile-line { margin-top: 6px; }
.settings-link {
  background: none; border: none; color: var(--accent); font-size: 15px; cursor: pointer;
  padding: 4px 0; text-align: left;
}
.change-pw { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.sessions-box { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.sessions-loading { color: var(--muted); font-size: 13px; padding: 6px 2px; }
.session-row { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border: 1px solid var(--border); border-radius: 12px; }
.session-row.current { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); background: var(--accent-soft); }
.session-info { flex: 1; min-width: 0; }
.session-device { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 7px; }
.session-current { font-size: 11px; font-weight: 600; color: var(--accent); background: var(--panel); border-radius: 6px; padding: 1px 6px; }
.session-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.session-del { border: none; background: none; color: var(--muted); cursor: pointer; padding: 4px; border-radius: 8px; flex: none; }
.session-del:hover { color: var(--danger); background: var(--hover); }
.change-pw input {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--text); font-size: 15px;
}
.change-pw input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.change-pw-msg { font-size: 13px; color: var(--danger); margin: 0; }
.change-pw-msg.ok { color: var(--online); }
.settings-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.settings-head h3 { margin: 0; }
.settings-group { padding: 12px 0; border-top: 1px solid var(--border); }
.settings-label { font-size: 13px; font-weight: 590; color: var(--muted); margin-bottom: 10px; }
.accent-grid { display: flex; gap: 12px; flex-wrap: wrap; }
.accent-swatch {
  width: 34px; height: 34px; border-radius: 50%; border: 2px solid transparent; cursor: pointer;
  background: var(--sw); box-shadow: 0 1px 3px rgb(0 0 0 / 20%); position: relative;
}
.accent-swatch.active { box-shadow: 0 0 0 3px var(--panel), 0 0 0 5px var(--sw); }
.list-error { padding: 32px 22px; text-align: center; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.list-error .le-title { font-weight: 600; font-size: 16px; }
.list-error .le-text { color: var(--muted); font-size: 13px; line-height: 1.45; max-width: 260px; }
.list-error .le-actions { display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 240px; margin-top: 10px; }
.list-error .le-actions .btn { width: 100%; padding: 11px; }
.wallpaper-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.wp-swatch {
  width: 56px; height: 76px; border-radius: 12px; border: 2px solid var(--border);
  cursor: pointer; background: var(--chat-bg); position: relative; overflow: hidden;
}
.wp-swatch.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.wps-logo { background: var(--chat-bg) url('/icons/wito-tile.png') center/44px repeat; }
.wps-plain { background: var(--chat-bg); }
.wps-blue { background: radial-gradient(at 25% 20%,#d6ecff 0,transparent 60%),radial-gradient(at 80% 15%,#bcd6f2 0,transparent 60%),#c6dcf4; }
.wps-mint { background: radial-gradient(at 25% 18%,#dcf7e8 0,transparent 60%),radial-gradient(at 80% 20%,#bff0d4 0,transparent 60%),#c6e8d4; }
.wps-gradient { background: radial-gradient(at 25% 20%,#c7d8ec 0,transparent 60%),radial-gradient(at 80% 15%,#aec6e0 0,transparent 60%),#9fb8d2; }
.wps-lavender { background: radial-gradient(at 25% 20%,#ece4ff 0,transparent 60%),radial-gradient(at 80% 15%,#dcc9ff 0,transparent 60%),#d2c2ef; }
.wps-sunset { background: radial-gradient(at 20% 20%,#ffe6c9 0,transparent 60%),radial-gradient(at 85% 15%,#ffcbd6 0,transparent 60%),#ffd0bd; }
.wps-rose { background: radial-gradient(at 25% 20%,#ffe4ef 0,transparent 60%),radial-gradient(at 80% 15%,#ffd0e0 0,transparent 60%),#f7cbdc; }
.wps-sand { background: radial-gradient(at 25% 18%,#f5ecd9 0,transparent 60%),radial-gradient(at 80% 20%,#ecdcc0 0,transparent 60%),#e9ddc6; }
.wps-forest { background: radial-gradient(at 25% 20%,#d4ecd6 0,transparent 60%),radial-gradient(at 80% 15%,#b6ddc2 0,transparent 60%),#aad2b6; }
.wps-aurora { background: radial-gradient(at 15% 20%,#c2f0e0 0,transparent 55%),radial-gradient(at 85% 15%,#dcc9ff 0,transparent 55%),radial-gradient(at 60% 92%,#ffd9c2 0,transparent 60%),#d6e4ff; }
.wps-graphite { background: radial-gradient(at 25% 20%,#e2e7ee 0,transparent 60%),radial-gradient(at 80% 18%,#cdd4dd 0,transparent 60%),#c4ccd6; }

/* profile card */
.profile-card {
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  width: 100%; max-width: 300px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 22px; padding: 26px 22px 22px; box-shadow: var(--shadow-lg); animation: popIn .18s ease-out;
}
.avatar.xl { width: 96px; height: 96px; font-size: 34px; margin-bottom: 6px; }
.profile-card strong { font-size: 18px; letter-spacing: -.02em; }
.profile-line { font-size: 13px; color: var(--muted); }
.profile-actions { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.safety-box { margin-top: 12px; width: 100%; background: var(--hover); border-radius: 12px; padding: 12px 14px; }
.safety-hint { font-size: 12px; color: var(--muted); line-height: 1.4; margin-bottom: 8px; }
.safety-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.safety-group {
  font-family: var(--mono, ui-monospace, "SF Mono", Menlo, monospace); font-size: 15px; font-weight: 600;
  letter-spacing: .06em; text-align: center; color: var(--text); font-variant-numeric: tabular-nums;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 5px 0;
}

/* QR login */
.qr-toggle { width: 100%; margin-top: 12px; }
.qr-login { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 6px; }
.qr-box { width: 240px; height: 240px; background: #fff; border-radius: 16px; padding: 8px; display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow); }
.qr-box svg { width: 100%; height: 100%; }
.qr-hint { font-size: 13px; color: var(--muted); text-align: center; margin: 0; }

/* calls */
.call-overlay {
  position: fixed; inset: 0; z-index: 60; background: radial-gradient(900px 600px at 50% 30%, #1d2733, #0d1117);
  display: flex; align-items: center; justify-content: center; animation: fadeIn .2s;
}
#remote-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.call-peer { position: relative; z-index: 2; display: flex; flex-direction: column; align-items: center; gap: 10px; color: #fff; text-align: center; }
.call-overlay.has-video .call-peer { position: absolute; top: 24px; left: 0; right: 0; }
.call-overlay.has-video .call-peer .avatar { display: none; }
.avatar.big { width: 110px; height: 110px; font-size: 38px; box-shadow: 0 0 0 10px rgb(255 255 255 / 6%), 0 0 0 22px rgb(255 255 255 / 3%); }
.call-overlay.ringing .avatar.big { animation: ringGlow 1.6s ease-in-out infinite; }
@keyframes ringGlow {
  0%, 100% { box-shadow: 0 0 0 10px rgb(255 255 255 / 6%), 0 0 0 22px rgb(255 255 255 / 3%); }
  50% { box-shadow: 0 0 0 16px rgb(255 255 255 / 10%), 0 0 0 34px rgb(255 255 255 / 4%); }
}

/* group photo row in members sheet */
.group-photo-row {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 6px 0 14px; cursor: pointer; border-bottom: 1px solid var(--border); margin-bottom: 6px;
}
.group-photo-row .avatar.xl { cursor: pointer; }
.group-name-edit { display: flex; align-items: center; gap: 6px; }
.group-name-edit input {
  border: none; background: transparent; text-align: center; color: var(--text);
  font-size: 17px; font-weight: 600; max-width: 220px; padding: 4px 6px; border-radius: 8px;
}
.group-name-edit input:focus { outline: none; background: var(--hover); }
.group-name-edit .ic { color: var(--muted); }
.call-name { font-size: 22px; font-weight: 600; text-shadow: 0 1px 3px rgb(0 0 0 / 50%); }
.call-status { font-size: 14px; opacity: .8; }
.local-video {
  position: absolute; right: 16px; bottom: 110px; width: 200px; max-width: 34vw;
  border-radius: 14px; z-index: 3; box-shadow: 0 4px 20px rgb(0 0 0 / 50%); background: #000;
}
.call-controls { position: absolute; bottom: 28px; left: 0; right: 0; display: flex; justify-content: center; gap: 18px; z-index: 4; }
.call-btn {
  width: 56px; height: 56px; border-radius: 50%; border: none; cursor: pointer;
  background: rgb(255 255 255 / 16%); color: #fff; backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
}
.call-btn:hover { background: rgb(255 255 255 / 28%); }
.call-btn.danger { background: var(--danger); }
.call-btn.danger .ic { transform: rotate(135deg); }
.call-btn.accept { background: var(--online); }
.call-btn.off { background: #fff; color: #10151c; }

.incoming-call {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%); z-index: 70;
  display: flex; align-items: center; gap: 14px;
  background: var(--glass); backdrop-filter: blur(24px) saturate(1.8);
  border: 1px solid var(--border); border-radius: 20px; padding: 12px 16px;
  box-shadow: var(--shadow-lg); min-width: 320px; animation: slideDown .25s ease-out;
}
.incoming-call .call-btn { width: 44px; height: 44px; }
.inc-info { flex: 1; min-width: 0; }
.inc-info strong { display: block; }
.inc-type { font-size: 13px; color: var(--muted); }

/* QR scanner */
.scanner-overlay {
  position: fixed; inset: 0; z-index: 65; background: rgb(0 0 0 / 92%);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 16px;
  animation: fadeIn .15s;
}
#scanner-video { width: min(420px, 92vw); border-radius: 16px; background: #000; }
.scanner-hint { color: #fff; font-size: 14px; margin: 0; }
.scanner-manual { display: flex; gap: 8px; }
.scanner-manual input { padding: 9px 12px; border-radius: 10px; border: none; font-size: 14px; width: 240px; }

/* mobile */
@media (max-width: 720px) {
  .sidebar { width: 100%; max-width: none; border-right: none; }
  .app.in-chat .sidebar { display: none; }
  .app:not(.in-chat) .chat { display: none; }
  .icon-btn.back { display: inline-flex; }
  .messages, .typing { padding-left: 8px; padding-right: 8px; }
  .composer {
    gap: 6px;
    padding: 8px calc(8px + env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) calc(8px + env(safe-area-inset-left));
  }
  .composer.kb { padding-bottom: 8px; }
  .side-head { padding-top: calc(10px + env(safe-area-inset-top)); }
  .chat-head { padding-top: calc(7px + env(safe-area-inset-top)); }
  .quick-reply { display: none; }
  .msg-row { max-width: 88%; }
  .media-img, .media-video { max-width: min(280px, 74vw); }
  .voice-player { min-width: min(230px, 62vw); }

  /* iOS Safari auto-zooms focused inputs below 16px — keep them at 16px */
  form input, .composer textarea, .search-wrap input, .scanner-manual input, .chat-search input { font-size: 16px; }


  /* emoji picker sits BELOW the composer (in-flow), so the text field stays
     visible above it — like a keyboard replacement */
  .emoji-panel {
    position: static; width: 100%; max-width: 100%; left: auto; right: auto; bottom: auto;
    border-radius: 0; border-left: none; border-right: none;
    box-shadow: none; animation: none;
    padding-bottom: env(safe-area-inset-bottom);
    flex: none;
  }
  .emoji-grid { height: 210px; }

  /* larger touch targets */
  .chat-item { padding: 10px 12px; }
  .icon-btn.tool { padding: 12px 10px; }
  .send-btn { width: 46px; height: 46px; }
  .reaction-chip { padding: 4px 10px; }
  .scroll-down { bottom: calc(96px + env(safe-area-inset-bottom)); }
  .incoming-call { min-width: 0; width: calc(100vw - 24px); top: calc(12px + env(safe-area-inset-top)); }
  .local-video { width: 120px; bottom: calc(110px + env(safe-area-inset-bottom)); }
  .dropdown { min-width: 210px; }
  .profile-card, .settings-card { max-width: 100%; }
  .wallpaper-grid { flex-wrap: wrap; }
}
