/* ──────────────────────────────────────────────────────────────────────────
   Мессенджер: тёмная/светлая тема, адаптив, доступность.
   ────────────────────────────────────────────────────────────────────────── */

:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --bg-2: #f3f6fa;
  --bg-3: #e9eff6;
  --panel: #ffffff;
  --text: #16202b;
  --muted: #64748b;
  --border: #dfe6ef;
  --accent: #2a8bf2;
  --accent-2: #1f6fd0;
  --accent-soft: #e4f1ff;
  --brand-2: #12b5a6;
  --brand-3: #f4b740;
  --bubble-in: #f1f5f9;
  --bubble-in-text: #16202b;
  --bubble-out: #2a8bf2;
  --bubble-out-text: #ffffff;
  --danger: #e5484d;
  --success: #2fa46c;
  --warning: #e09a05;
  --shadow: 0 18px 50px rgba(15, 28, 45, 0.14);
  --shadow-soft: 0 2px 10px rgba(15, 28, 45, 0.08);
  --radius: 14px;
  --radius-sm: 10px;
  --head-h: 60px;
  --composer-h: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1720;
    --bg-2: #131e29;
    --bg-3: #1b2733;
    --panel: #17212b;
    --text: #e9f0f7;
    --muted: #93a4b5;
    --border: #25323f;
    --accent: #4aa3ff;
    --accent-2: #2a8bf2;
    --accent-soft: #1c334c;
    --brand-2: #3dd6c8;
    --brand-3: #ffcb6b;
    --bubble-in: #1c2733;
    --bubble-in-text: #e9f0f7;
    --bubble-out: #2b5278;
    --bubble-out-text: #ffffff;
    --danger: #ff6b6b;
    --success: #4ade80;
    --warning: #fbbf24;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
    --shadow-soft: 0 2px 10px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg-2);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── Кнопки и поля ────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 10px 16px; background: var(--bg-3); color: var(--text);
  font-weight: 600; transition: background 0.15s, transform 0.1s, border-color 0.15s;
}
.btn:hover { background: var(--border); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(0.92); }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.ghost:hover { background: var(--bg-3); }
.btn.block { width: 100%; }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; flex: none;
  border: 0; border-radius: 50%; background: transparent;
  font-size: 19px; line-height: 1; color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
[data-icon] { display: inline-flex; align-items: center; justify-content: center; line-height: 0; }
.icon { display: inline-block; vertical-align: middle; flex: none; }
.icon-btn:hover { background: var(--bg-3); color: var(--text); }
.icon-btn.tiny { width: 26px; height: 26px; font-size: 13px; }
.icon-btn.text-btn { width: auto; padding: 0 4px; font-size: 12px; font-weight: 800; letter-spacing: 0.5px; }
.icon-btn.is-active { background: var(--accent-soft); color: var(--accent); }

.linklike {
  border: 0; background: none; color: var(--accent); font-weight: 600;
  padding: 0; text-decoration: underline;
}

input[type="text"], input[type="password"], input[type="search"], textarea, select {
  width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-2); color: var(--text); padding: 10px 12px;
  transition: border-color 0.15s, background 0.15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); outline: none; background: var(--bg); }
textarea { resize: none; }

.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: #fff; font-weight: 700; flex: none;
  overflow: hidden; user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.sm { width: 30px; height: 30px; font-size: 13px; }
.avatar.lg { width: 46px; height: 46px; font-size: 17px; }
.avatar.xl { width: 76px; height: 76px; font-size: 28px; }

fieldset.color-field { border: 0; padding: 0; margin: 12px 0 0; }
fieldset.color-field legend { font-size: 13px; color: var(--muted); padding: 0; margin-bottom: 6px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 30px; height: 30px; border-radius: 50%; border: 3px solid transparent;
  padding: 0; background-clip: content-box;
}
.swatch.is-active { border-color: var(--text); }
.swatch:focus-visible { outline-offset: 3px; }

/* ── Экран входа ─────────────────────────────────────────────────────────── */

.auth-screen {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
  position: relative; overflow: hidden;
}
.auth-screen::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: url('/brand-pattern.svg') 0 0 / 280px 280px repeat;
  opacity: 0.34;
  mask-image: radial-gradient(circle at 50% 44%, #000 0, transparent 72%);
  -webkit-mask-image: radial-gradient(circle at 50% 44%, #000 0, transparent 72%);
}
.auth-glow {
  position: absolute; inset: -20%;
  background:
    radial-gradient(circle at 18% 18%, color-mix(in srgb, var(--accent) 26%, transparent), transparent 42%),
    radial-gradient(circle at 82% 78%, color-mix(in srgb, var(--success) 18%, transparent), transparent 40%);
  filter: blur(8px);
  pointer-events: none;
}
.auth-card {
  position: relative; width: min(420px, 100%);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--border); border-radius: 24px;
  padding: clamp(20px, 4vw, 32px); box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.brand-mark {
  width: 52px; height: 52px; border-radius: 16px; flex: none;
  object-fit: contain;
  filter: drop-shadow(0 8px 18px color-mix(in srgb, var(--brand-2) 28%, transparent));
}
.brand h1 { margin: 0; font-size: 27px; letter-spacing: 0.04em; font-weight: 800; }
.brand p { margin: 2px 0 0; }
.auth-signature {
  margin: 14px 0 0; text-align: center; color: var(--muted);
  font-size: 10.5px; letter-spacing: 0.22em; text-transform: uppercase;
}

.tabs { display: flex; gap: 6px; background: var(--bg-2); border-radius: 12px; padding: 5px; margin-bottom: 18px; }
.tab {
  flex: 1; border: 0; border-radius: 9px; padding: 9px; background: transparent;
  color: var(--muted); font-weight: 600;
}
.tab.is-active { background: var(--panel); color: var(--text); box-shadow: var(--shadow-soft); }

.auth-form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; color: var(--muted); }
.field-hint { margin: 0; font-size: 12.5px; color: var(--muted); }
.form-error { min-height: 18px; margin: 0; color: var(--danger); font-size: 13px; }
.auth-foot { display: flex; align-items: center; justify-content: center; gap: 6px; margin: 16px 0 0; }

/* ── Каркас ──────────────────────────────────────────────────────────────── */

.app { height: 100dvh; }
.layout { display: flex; height: 100%; min-height: 0; }

.sidebar {
  width: clamp(280px, 30vw, 380px); flex: none;
  display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border-right: 1px solid var(--border);
}
.sidebar-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 14px; padding-top: max(14px, env(safe-area-inset-top));
  min-height: var(--head-h);
}
.avatar-button { border: 0; background: none; padding: 0; border-radius: 50%; }
.me-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.me-text strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-text span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.search-wrap {
  position: relative; display: flex; align-items: center; gap: 6px;
  padding: 0 12px 10px;
}
.search-icon {
  position: absolute; left: 24px; top: 50%; transform: translateY(-62%);
  color: var(--muted); pointer-events: none; line-height: 0;
}
.search-icon .icon { width: 18px; height: 18px; }
.search-wrap input { padding-left: 38px; padding-right: 34px; border-radius: 12px; height: 40px; }
.search-wrap .icon-btn { position: absolute; right: 18px; }

.search-panel {
  max-height: 46%; overflow-y: auto; padding: 0 10px 8px;
  border-bottom: 1px solid var(--border);
}

.chat-list { flex: 1; overflow-y: auto; padding: 4px 8px 10px; min-height: 0; }
.chat-item {
  width: 100%; display: flex; align-items: center; gap: 11px;
  padding: 10px 10px; border: 0; border-radius: 12px; background: none; text-align: left;
  color: var(--text); transition: background 0.12s;
}
.chat-item:hover { background: var(--bg-2); }
.chat-item.is-active { background: var(--accent-soft); }
.chat-item-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.chat-item-line { display: flex; align-items: center; gap: 8px; }
.chat-item-line strong { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14.5px; }
.chat-item-line time { color: var(--muted); font-size: 11.5px; flex: none; }
.chat-item-preview {
  color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-item-preview.own { color: var(--muted); }
.chat-item-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
.unread {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 11.5px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.presence-dot {
  position: absolute; right: 0; bottom: 0; width: 11px; height: 11px;
  border-radius: 50%; background: var(--success); border: 2px solid var(--panel);
}
.avatar-wrap { position: relative; flex: none; display: inline-flex; }

.sidebar-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}
.brand-signature {
  color: var(--muted); font-size: 9.5px; letter-spacing: 0.22em;
  opacity: 0.75; user-select: none;
}
.connection-state { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.connection-state .dot, .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none;
}
.connection-state[data-state="online"] .dot { background: var(--success); }
.connection-state[data-state="polling"] .dot { background: var(--warning); }
.connection-state[data-state="reconnecting"] .dot, .connection-state[data-state="connecting"] .dot { background: var(--warning); }
.connection-state[data-state="offline"] .dot { background: var(--danger); }

/* ── Чат ─────────────────────────────────────────────────────────────────── */

.chat-pane {
  flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column;
  background: var(--bg-2); position: relative;
}
.chat-head {
  display: flex; align-items: center; gap: 10px; flex: none;
  padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
  min-height: var(--head-h); background: var(--panel); border-bottom: 1px solid var(--border);
  z-index: 2;
}
.chat-head-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-head-text strong { font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head-text span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head-actions { display: flex; align-items: center; gap: 2px; }

.banner {
  margin: 6px 12px 0; padding: 8px 12px; border-radius: 10px;
  background: var(--accent-soft); color: var(--text); font-size: 13px;
  display: flex; align-items: center; gap: 8px;
}
.banner.warn { background: color-mix(in srgb, var(--warning) 22%, var(--bg)); }

.typing {
  padding: 2px 18px 4px; font-size: 12.5px; color: var(--muted); min-height: 20px;
}

.messages {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden;
  padding: 12px clamp(10px, 3vw, 30px) 8px;
  display: flex; flex-direction: column; gap: 3px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
.messages .empty-state, .messages .date-sep { width: 100%; }
.empty-state {
  margin: auto; text-align: center; color: var(--muted); padding: 30px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.empty-state .big { font-size: 44px; }
.brand-empty { width: 48px; height: 48px; object-fit: contain; opacity: 0.9; }

.date-sep { display: flex; justify-content: center; margin: 12px 0 8px; }
.date-sep span {
  background: color-mix(in srgb, var(--panel) 75%, transparent);
  border: 1px solid var(--border); border-radius: 20px;
  padding: 3px 12px; font-size: 11.5px; color: var(--muted);
}

.msg-row { display: flex; align-items: flex-end; gap: 7px; max-width: 100%; }
.msg-row.mine { flex-direction: row-reverse; }
.msg-row.system { justify-content: center; }
.msg-stack { display: flex; flex-direction: column; min-width: 0; max-width: min(680px, 78%); }
.msg-row.mine .msg-stack { align-items: flex-end; }

.msg {
  position: relative; padding: 7px 11px 6px;
  border-radius: 15px; border-bottom-left-radius: 5px;
  background: var(--bubble-in); color: var(--bubble-in-text);
  overflow-wrap: anywhere; word-break: break-word;
  box-shadow: var(--shadow-soft);
}
.msg.mine {
  background: var(--bubble-out); color: var(--bubble-out-text);
  border-bottom-left-radius: 15px; border-bottom-right-radius: 5px;
}
.msg.system {
  background: transparent; box-shadow: none; color: var(--muted);
  font-size: 12.5px; padding: 6px 12px; border-radius: 16px;
  border: 1px solid var(--border); text-align: center;
}
.msg-sender { font-size: 12.5px; font-weight: 700; color: var(--accent); margin-bottom: 2px; }
.msg.mine .msg-sender { display: none; }
.msg-text { white-space: pre-wrap; font-size: 15px; line-height: 1.4; }
.msg-text.jumbo { font-size: clamp(34px, 9vw, 52px); line-height: 1.15; padding: 2px 0; }
.msg-meta {
  display: flex; align-items: center; justify-content: flex-end; gap: 5px;
  margin-top: 2px; font-size: 10.5px; opacity: 0.72;
}
.msg-meta .edited { font-style: italic; }
.msg-meta .checks { letter-spacing: -2px; }
.msg-row.mine .msg-meta { color: color-mix(in srgb, var(--bubble-out-text) 80%, transparent); }

.msg-actions {
  display: flex; gap: 2px; opacity: 0; transition: opacity 0.12s;
  align-self: flex-end; margin-bottom: 2px;
}
.msg-row:hover .msg-actions, .msg-row:focus-within .msg-actions { opacity: 1; }
.msg-actions .icon-btn { width: 26px; height: 26px; font-size: 13px; background: var(--panel); border: 1px solid var(--border); }

.quote {
  border-left: 3px solid var(--accent); padding: 3px 8px; margin-bottom: 5px;
  background: color-mix(in srgb, var(--accent) 10%, transparent); border-radius: 4px 8px 8px 4px;
  font-size: 12.5px; max-height: 60px; overflow: hidden;
}
.quote.mine { border-left-color: #fff9; background: #ffffff1f; }
.quote-author { font-weight: 700; color: inherit; opacity: 0.9; display: block; }
.quote-text { opacity: 0.85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.msg-sticker {
  width: 132px; height: 132px; border-radius: 18px;
  display: flex; align-items: center; justify-content: center;
  font-size: 76px; line-height: 1;
  box-shadow: var(--shadow-soft);
}
.msg-sticker .sticker-label { position: absolute; bottom: 7px; font-size: 10px; opacity: 0.8; letter-spacing: 0.04em; }
.msg-sticker { font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "DejaVu Sans", system-ui, sans-serif; }
.msg-media { margin: 0; border-radius: 12px; overflow: hidden; display: block; max-width: 100%; }
.msg-media img, .msg-media video { display: block; max-width: 100%; max-height: 360px; border-radius: 12px; }
.msg-media.gif { width: 280px; max-width: 100%; }
.msg-media.gif img { width: 100%; }

.voice-player {
  display: flex; align-items: center; gap: 10px; min-width: 180px;
  padding: 4px 2px;
}
.voice-play {
  width: 38px; height: 38px; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; font-size: 16px;
  display: flex; align-items: center; justify-content: center; flex: none;
  line-height: 0;
}
.voice-wave { flex: 1; display: flex; align-items: center; gap: 2px; height: 26px; }
.voice-bar { flex: 1; min-width: 2px; max-width: 4px; border-radius: 2px; background: currentColor; opacity: 0.5; height: 30%; }
.voice-time { font-size: 11.5px; opacity: 0.8; }

.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.reaction {
  display: inline-flex; align-items: center; gap: 4px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--panel); color: var(--text);
  font-size: 12.5px; padding: 2px 7px; line-height: 1.4;
}
.reaction.is-mine { border-color: var(--accent); background: var(--accent-soft); }
.reaction:hover { filter: brightness(1.08); }
.reaction .count { font-weight: 600; }

.msg-failed { color: var(--danger); font-size: 11.5px; margin-top: 3px; }
.msg-pending { opacity: 0.7; }

.scroll-anchor { height: 1px; }

.jump-bottom {
  position: absolute; right: 18px; bottom: calc(var(--composer-h) + 18px);
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--panel); color: var(--text); font-size: 18px; box-shadow: var(--shadow-soft);
  z-index: 5;
}

.reply-bar {
  display: flex; align-items: center; gap: 10px;
  margin: 0 12px 6px; padding: 8px 10px;
  border-left: 3px solid var(--accent); border-radius: 8px;
  background: var(--panel); font-size: 13px;
}
.reply-bar .reply-content { flex: 1; min-width: 0; }
.reply-bar .reply-content strong { display: block; font-size: 12px; color: var(--accent); }
.reply-bar .reply-content span { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }

.recording {
  display: flex; align-items: center; gap: 10px;
  margin: 0 12px 6px; padding: 8px 12px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--border);
}
.recording-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }

.composer {
  display: flex; align-items: flex-end; gap: 2px; flex: none;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--border);
  min-height: var(--composer-h);
}
.composer textarea {
  flex: 1; min-width: 0; max-height: 132px; border-radius: 20px;
  padding: 9px 12px; line-height: 1.35; background: var(--bg-2);
  overflow-y: auto;
}
.send-button {
  width: 42px; height: 42px; flex: none; border-radius: 50%; border: 0;
  background: var(--accent); color: #fff; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.12s, background 0.15s;
}
.send-button:hover { background: var(--accent-2); }
.send-button:active { transform: scale(0.95); }
.send-button:disabled { opacity: 0.5; }

/* ── Пикер (эмодзи, стикеры, GIF) ───────────────────────────────────────── */

.picker {
  position: absolute; right: 12px; bottom: calc(var(--composer-h) + 8px);
  width: min(380px, calc(100vw - 24px)); max-height: min(480px, 60vh);
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow); z-index: 12;
  overflow: hidden;
}
.picker-head { display: flex; align-items: center; gap: 4px; padding: 8px; border-bottom: 1px solid var(--border); }
.picker-tab {
  border: 0; background: none; padding: 6px 10px; border-radius: 8px;
  color: var(--muted); font-size: 13px; font-weight: 600;
}
.picker-tab.is-active { background: var(--accent-soft); color: var(--accent); }
.picker-close { margin-left: auto; }
.picker-body { flex: 1; overflow-y: auto; padding: 8px; min-height: 120px; }
.picker-status { padding: 18px; text-align: center; color: var(--muted); font-size: 13px; }
.panel-section-title { font-size: 11.5px; color: var(--muted); margin: 8px 4px 4px; text-transform: uppercase; letter-spacing: 0.04em; }
.symbol-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 2px; }
.symbol-btn {
  border: 0; background: transparent; border-radius: 8px; padding: 4px;
  font-size: 23px; line-height: 1.2;
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "DejaVu Sans", system-ui, sans-serif;
}
.symbol-btn:hover { background: var(--bg-3); }
.symbol-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }
.sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.sticker-btn {
  border: 1px solid var(--border); background: var(--bg-2); border-radius: 14px;
  padding: 8px; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.sticker-btn:hover { background: var(--bg-3); }
.sticker-symbol {
  font-size: 46px; line-height: 1.1;
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", "DejaVu Sans", system-ui, sans-serif;
}
.sticker-label { font-size: 10.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.gif-search { padding: 8px 8px 0; }
.gif-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; padding: 8px; }
.gif-btn { border: 0; background: var(--bg-2); padding: 0; border-radius: 8px; overflow: hidden; }
.gif-btn img { width: 100%; height: 108px; object-fit: cover; display: block; }
.gif-btn:hover { outline: 2px solid var(--accent); }

/* ── Модальные окна ─────────────────────────────────────────────────────── */

.modal-root { position: fixed; inset: 0; z-index: 120; }
.modal-overlay {
  position: absolute; inset: 0; background: rgba(8, 14, 22, 0.55);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  backdrop-filter: blur(2px);
  animation: fade-in 0.14s ease-out;
}
.modal-card {
  width: min(440px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 18px; box-shadow: var(--shadow); padding: 20px;
  animation: slide-up 0.16s ease-out;
}
.modal-card.wide { width: min(640px, 100%); }
.modal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.modal-head h2 { margin: 0; font-size: 18px; flex: 1; }
.modal-body { display: flex; flex-direction: column; gap: 12px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 18px; }
.modal-body .field { display: flex; flex-direction: column; gap: 6px; }
.modal-body .field > span { font-size: 13px; color: var(--muted); }

.image-viewer {
  max-width: 100%; max-height: 100%; display: flex; align-items: center; justify-content: center;
  background: transparent; padding: 0;
}
.image-viewer img { max-width: calc(100vw - 32px); max-height: calc(100dvh - 32px); border-radius: 8px; }

/* ── Тосты ───────────────────────────────────────────────────────────────── */

.toasts {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 130;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none; width: min(420px, calc(100vw - 24px));
}
.toast {
  background: #111c28; color: #f2f7fc; border: 1px solid #ffffff22;
  padding: 10px 14px; border-radius: 10px; font-size: 13.5px;
  box-shadow: var(--shadow); pointer-events: auto; max-width: 100%;
  animation: slide-up 0.18s ease-out;
}
.toast.error { background: #5c1f24; }
.toast.success { background: #15392b; }

/* ── Звонки ──────────────────────────────────────────────────────────────── */

.call-screen {
  position: fixed; inset: 0; z-index: 100;
  background: #0b1219; color: #f2f7fc;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.call-backdrop {
  position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(circle at 50% 0%, #2a8bf222, transparent 55%),
    radial-gradient(circle at 10% 100%, #8e4ec622, transparent 55%);
}
.call-head {
  position: relative; display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; gap: 12px;
}
.call-head strong { display: block; font-size: 16px; }
.call-head span { display: block; }
.badge {
  border: 1px solid #ffffff33; border-radius: 20px; padding: 4px 10px;
  font-size: 11.5px; color: #cfe1f3; background: #ffffff10;
}
.call-grid {
  position: relative; flex: 1; min-height: 0;
  display: grid; gap: 10px; padding: 0 14px 10px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  align-content: center;
}
.call-tile {
  position: relative; min-height: 150px; border-radius: 16px; overflow: hidden;
  background: #15202b; border: 1px solid #ffffff14;
  display: flex; align-items: center; justify-content: center;
}
.call-tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.call-tile.audio video { display: none; }
.call-tile .tile-avatar { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: #15202b; }
.call-tile .tile-avatar .avatar { width: 84px; height: 84px; font-size: 30px; }
.call-tile .tile-label {
  position: absolute; left: 8px; bottom: 8px; max-width: calc(100% - 16px);
  background: #0b1219cc; border-radius: 8px; padding: 3px 8px;
  font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.call-tile .tile-flags { position: absolute; right: 8px; top: 8px; display: flex; gap: 5px; font-size: 12px; }
.tile-flag {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 7px;
  background: #0b1219cc; color: #dbeafe; line-height: 0;
}
.call-tile.local video { transform: scaleX(-1); }
.call-tile.is-screen video { object-fit: contain; background: #000; transform: none; }
.call-tile.local .tile-label::after { content: " · вы"; opacity: 0.7; }

.call-bottom { position: relative; padding: 6px 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.call-quality { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 12.5px; color: #bcd0e2; }
.call-controls { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }
.round {
  width: 54px; height: 54px; border-radius: 50%; border: 1px solid #ffffff22;
  background: #ffffff14; color: #fff; font-size: 22px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, transform 0.1s;
}
.round:hover { background: #ffffff26; }
.round:active { transform: scale(0.96); }
.round.is-off { background: #ffffff33; color: #ffd7d7; }
.round.is-on { background: #4aa3ff; border-color: #4aa3ff; }
.round.danger { background: #e5484d; border-color: #e5484d; }
.round.danger:hover { background: #ff6b6b; }
.call-hint { text-align: center; min-height: 16px; font-size: 12px; color: #9fb3c8; margin: 0; }

.incoming {
  position: fixed; inset: 0; z-index: 110; background: rgba(4, 9, 14, 0.75);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  backdrop-filter: blur(4px);
}
.incoming-card {
  width: min(360px, 100%); background: #15202b; color: #f2f7fc;
  border: 1px solid #ffffff22; border-radius: 22px; padding: 26px 22px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  box-shadow: var(--shadow);
}
.incoming-card .avatar { box-shadow: 0 0 0 0 #4aa3ff88; animation: ring 1.8s infinite; }
.incoming-card strong { font-size: 19px; }
.incoming-actions { display: flex; gap: 12px; width: 100%; margin-top: 14px; }
.incoming-actions .btn { flex: 1; }
.incoming-kind { font-size: 13px; color: #9fb3c8; }

/* ── Адаптив ─────────────────────────────────────────────────────────────── */

.only-mobile { display: none; }

@media (max-width: 860px) {
  .only-mobile { display: inline-flex; }
  .sidebar { width: 100%; max-width: none; border-right: 0; }
  .chat-pane {
    position: fixed; inset: 0; z-index: 20; display: none;
    padding: 0;
  }
  .app.chat-open .chat-pane { display: flex; }
  .app.chat-open .sidebar { display: none; }
  .chat-head { padding-left: 8px; }
  .messages { padding: 8px 8px 4px; }
  .msg-stack { max-width: 84%; }
  .msg-actions { opacity: 0.7; }
  .msg-actions .icon-btn { background: var(--panel); }
  .composer { gap: 0; padding-left: 4px; padding-right: 4px; }
  .composer .icon-btn { width: 34px; height: 38px; font-size: 17px; }
  .composer .icon-btn .icon { width: 17px; height: 17px; }
  .composer .icon-btn.text-btn { width: 34px; }
  .composer textarea { padding: 8px 10px; }
  .send-button { width: 40px; height: 40px; }
  .picker { left: 6px; right: 6px; width: auto; bottom: calc(var(--composer-h) + 4px); max-height: 55vh; }
  .call-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); padding: 0 8px; }
  .round { width: 48px; height: 48px; font-size: 20px; }
  .call-controls { gap: 9px; }
  .modal-card { border-radius: 16px; padding: 16px; }
  .toasts { bottom: calc(12px + env(safe-area-inset-bottom)); }
}

@media (max-width: 380px) {
  .composer .icon-btn.text-btn { display: none; }
  .msg-stack { max-width: 88%; }
}

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

/* ── Анимации ────────────────────────────────────────────────────────────── */

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }
@keyframes ring {
  0% { box-shadow: 0 0 0 0 #4aa3ff88; }
  70% { box-shadow: 0 0 0 18px #4aa3ff00; }
  100% { box-shadow: 0 0 0 0 #4aa3ff00; }
}

/* Скроллбары */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ── Дополнительные элементы ─────────────────────────────────────────────── */

.avatar-placeholder { visibility: hidden; }

.search-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 6px; border: 0; border-radius: 10px; background: none;
  text-align: left; color: var(--text);
}
.search-item:hover { background: var(--bg-2); }
.search-item-text {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px;
}
.search-item-text strong,
.search-item-text span {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.search-message { border-left: 2px solid var(--border); border-radius: 4px 10px 10px 4px; }

.badge-online {
  flex: none; font-size: 11px; color: var(--success);
  border: 1px solid color-mix(in srgb, var(--success) 35%, transparent);
  background: color-mix(in srgb, var(--success) 10%, transparent);
  border-radius: 10px; padding: 2px 8px;
}

.msg-row.is-highlight .msg {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.settings-block {
  border-top: 1px solid var(--border);
  padding-top: 12px; display: flex; flex-direction: column; gap: 10px;
}
.settings-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
}
.settings-row > div { min-width: 0; }
.settings-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.switch-wrap { display: inline-flex; align-items: center; cursor: pointer; flex: none; }
.switch {
  position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none;
}
.switch-track {
  width: 44px; height: 26px; border-radius: 14px; background: var(--border);
  position: relative; transition: background 0.15s;
}
.switch-track::after {
  content: ""; position: absolute; width: 20px; height: 20px; border-radius: 50%;
  background: var(--panel); top: 3px; left: 3px; transition: left 0.15s;
  box-shadow: var(--shadow-soft);
}
.switch:checked + .switch-track { background: var(--accent); }
.switch:checked + .switch-track::after { left: 21px; }
.switch:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

.profile-top { display: flex; align-items: center; gap: 14px; }
.profile-top-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.profile-top-text strong { color: var(--accent); }
.profile-top input[type="file"] { font-size: 12px; max-width: 100%; color: var(--muted); }

.group-results {
  max-height: 230px; overflow-y: auto; display: flex; flex-direction: column;
  gap: 2px; border: 1px solid var(--border); border-radius: 10px; padding: 4px;
  background: var(--bg-2);
}
.group-row {
  display: flex; align-items: center; gap: 10px; padding: 6px;
  border-radius: 8px; cursor: pointer;
}
.group-row:hover { background: var(--bg-3); }
.group-row div { min-width: 0; }

.call-tile video {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  background: #000;
}
.call-tile.has-video .tile-avatar { display: none; }
.call-tile:not(.has-video) video { opacity: 0; width: 1px; height: 1px; }
.call-tile .tile-avatar, .call-tile .tile-label, .call-tile .tile-flags { z-index: 1; }

#call-quality-dot[data-level="good"] { background: var(--success); }
#call-quality-dot[data-level="medium"] { background: var(--warning); }
#call-quality-dot[data-level="poor"] { background: var(--danger); }

.badge.is-survival {
  border-color: color-mix(in srgb, #4aa3ff 60%, transparent);
  background: #4aa3ff22; color: #cfe9ff;
}

/* Прижимаем сообщения к низу, когда их мало; при переполнении прокрутка работает как обычно. */
.messages::before { content: ""; margin-top: auto; }

/* Скрытый input внутри стилизованной кнопки загрузки аватара. */
.file-input-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.file-button { align-self: flex-start; cursor: pointer; }

@media (max-width: 860px) {
  .msg-actions { display: none; }
  .msg-row.is-actions-open .msg-actions {
    display: flex; opacity: 1; background: var(--bg-2);
    border-radius: 10px; padding: 2px; align-self: center;
  }
}

/* Фирменные штрихи: акцентные действия в шапке чата читаются лучше. */
.chat-head-actions .icon-btn { color: var(--text); }
.chat-head-actions .icon-btn:hover { background: var(--bg-3); color: var(--accent); }
#new-group { color: var(--text); }
#new-group:hover { background: var(--accent-soft); color: var(--accent); }
