﻿:root {
    --bg-gradient: linear-gradient(135deg, #0f0c29 0%, #302b63 50%, #24243e 100%);
    --glass-bg: rgba(255, 255, 255, 0.06);
    --glass-border: rgba(255, 255, 255, 0.12);
    --accent-gradient: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
    --accent-hover: linear-gradient(135deg, #7b2cbf 0%, #3a86ff 100%);
    --text-main: #ffffff;
    --text-muted: #a5a6c4;
    --msg-in: rgba(255, 255, 255, 0.1);
    --transition: all 0.35s cubic-bezier(0.25, 0.8, 0.25, 1);
    --online: #00f5d4;
    --title-gradient: linear-gradient(90deg, #a18cd1, #66a6ff);
    --accent-soft: #66a6ff;
    --select-accent: #3a86ff;
    --select-accent-bg: rgba(58, 134, 255, 0.2);
    --focus-ring: #6a11cb;
    --focus-glow: rgba(106, 17, 203, 0.4);
    --accent-shadow: rgba(37, 117, 252, 0.3);
    --overlay-bg: rgba(10, 8, 28, 0.88);
    --panel-bg: rgba(15, 12, 41, 0.4);
    --panel-solid: rgba(15, 12, 41, 0.94);
    --header-bg: rgba(15, 12, 41, 0.25);
    --inputbar-bg: rgba(15, 12, 41, 0.3);
    --active-bg: linear-gradient(90deg, rgba(106, 17, 203, 0.4), rgba(37, 117, 252, 0.25));
    --active-border: rgba(106, 17, 203, 0.5);
    --video-bg: #08061a;
    --video-border: #6a11cb;
    --avatar-ring: #1a163f;
    --online-bg: rgba(0, 245, 212, 0.1);
    --online-border: rgba(0, 245, 212, 0.35);
    --accent-rgb: 106, 17, 203;
    /* Одна высота у шапки списка (.my-profile) и шапки чата (.chat-header):
       при переходе список ↔ чат шапка не «прыгает». */
    --header-h: 72px;
}
/* --- тема «Багровая» (чёрно-красная) ---
   Варианты селектора: html.theme-crimson-html — ранняя тема из index.html
   (до загрузки app.js, переключение на body.theme-crimson не требуется),
   body.theme-crimson — переключение из настроек без перезагрузки. */
html.theme-crimson-html,
body.theme-crimson {
    --bg-gradient: linear-gradient(135deg, #0a0406 0%, #1a0508 50%, #12060a 100%);
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --accent-gradient: linear-gradient(135deg, #8b0d1e 0%, #c0122f 100%);
    --accent-hover: linear-gradient(135deg, #a51025 0%, #d91e3d 100%);
    --online: #ff5a6e;
    --title-gradient: linear-gradient(90deg, #ff8ba0, #e02440);
    --accent-soft: #ff5a6e;
    --select-accent: #e02440;
    --select-accent-bg: rgba(224, 36, 64, 0.2);
    --focus-ring: #c0122f;
    --focus-glow: rgba(192, 18, 47, 0.4);
    --accent-shadow: rgba(192, 18, 47, 0.35);
    --overlay-bg: rgba(10, 4, 6, 0.88);
    --panel-bg: rgba(20, 6, 9, 0.5);
    --panel-solid: rgba(20, 6, 9, 0.94);
    --header-bg: rgba(20, 6, 9, 0.3);
    --inputbar-bg: rgba(20, 6, 9, 0.35);
    --active-bg: linear-gradient(90deg, rgba(192, 18, 47, 0.45), rgba(224, 36, 64, 0.22));
    --active-border: rgba(224, 36, 64, 0.55);
    --video-bg: #0a0406;
    --video-border: #c0122f;
    --avatar-ring: #1a0508;
    --online-bg: rgba(255, 90, 110, 0.1);
    --online-border: rgba(255, 90, 110, 0.35);
    --accent-rgb: 192, 18, 47;
}
* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Segoe UI', Roboto, sans-serif; }
html {
    /* Страница никогда не скроллится вбок: причина «уехавшего вправо» экрана. */
    overflow-x: hidden;
    max-width: 100%;
    /* Меньше случайных pull-to-refresh на мобиле (сессия всё равно переживает reload). */
    overscroll-behavior-y: none;
}
body {
    background: var(--bg-gradient);
    color: var(--text-main);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    max-width: 100%;
    overscroll-behavior-y: none;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(15px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes pulseGlow {
    0% { box-shadow: 0 0 0 0 var(--focus-glow); }
    70% { box-shadow: 0 0 0 22px transparent; }
    100% { box-shadow: 0 0 0 0 transparent; }
}
.auth-overlay {
    position: fixed; inset: 0; background: var(--overlay-bg);
    backdrop-filter: blur(18px); display: flex; justify-content: center;
    align-items: flex-start; z-index: 100; transition: var(--transition);
    /* Карточка выше экрана — скролл оверлея (body overflow:hidden). */
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding:
      max(12px, env(safe-area-inset-top, 0px))
      12px
      max(12px, env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
}
.auth-overlay.hidden { opacity: 0; pointer-events: none; transform: scale(1.05); }
.auth-card {
    background: var(--glass-bg); border: 1px solid var(--glass-border);
    padding: 2.5rem; border-radius: 24px; width: 90%; max-width: 400px;
    text-align: center; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.5s ease forwards;
    position: relative;
    flex-shrink: 0;
    margin-top: auto;
    margin-bottom: auto;
    max-height: none;
}
.auth-card h2 {
    font-size: 1.9rem; margin-bottom: 0.4rem;
    background: var(--title-gradient);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.auth-card p { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1.25rem; }
.auth-mode-switch {
    display: flex; gap: 0; margin-bottom: 1.25rem;
    border: 1px solid var(--glass-border); border-radius: 14px; overflow: hidden;
}
.auth-mode-btn {
    flex: 1; padding: 10px 8px; border: none; background: transparent;
    color: var(--text-muted); font-size: 0.85rem; cursor: pointer;
    transition: var(--transition);
}
.auth-mode-btn.active {
    background: var(--select-accent-bg); color: #fff; font-weight: 600;
}
.auth-warn {
    color: #ff2a5f; font-size: 0.85rem; margin-bottom: 1rem;
    font-weight: 600; animation: fadeIn 0.3s ease forwards;
}
.auth-ok {
    color: #3dd68c; font-size: 0.85rem; margin-bottom: 1rem;
    font-weight: 600; animation: fadeIn 0.3s ease forwards;
}
.auth-legal {
    margin: 0.85rem 0 0;
    font-size: 0.72rem;
    line-height: 1.4;
    color: var(--text-muted);
}
.auth-legal a { color: var(--text-muted); text-decoration: underline; }
.auth-legal a:hover { color: #fff; }
.auth-legal.auth-legal-warn { color: #ff2a5f; }
.auth-legal.auth-legal-warn a { color: #ff7a9a; }
.auth-subtitle { font-size: 0.82rem !important; line-height: 1.35; }
.load-more-btn {
    display: block; width: 100%; margin: 0 0 10px;
    padding: 8px 12px; border-radius: 12px; border: 1px solid var(--glass-border);
    background: rgba(255,255,255,0.06); color: var(--text-muted);
    font-size: 0.8rem; cursor: pointer;
}
.load-more-btn:hover { color: #fff; border-color: var(--focus-ring); }
.recovery-group { text-align: left; }
.recovery-hint {
    color: var(--text-muted); font-size: 0.75rem; margin-top: 0.4rem; line-height: 1.35;
}
.recovery-modal {
    position: fixed; inset: 0; z-index: 450;
    background: var(--overlay-bg); backdrop-filter: blur(18px);
    display: flex; justify-content: center; align-items: flex-start;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding:
      max(12px, env(safe-area-inset-top, 0px))
      12px
      max(12px, env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
}
.recovery-modal[hidden] { display: none !important; }
.recovery-card {
    background: var(--glass-bg); border: 1px solid var(--glass-border);
    padding: 1.75rem; border-radius: 20px; width: 90%; max-width: 380px;
    text-align: center; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    flex-shrink: 0;
    margin-top: auto;
    margin-bottom: auto;
}
.recovery-card h3 { font-size: 1.25rem; margin-bottom: 0.5rem; }
.recovery-card p { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 1rem; line-height: 1.4; }
.recovery-code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: clamp(0.78rem, 3.4vw, 1.05rem);
    letter-spacing: 0.04em;
    padding: 0.85rem 1rem; border-radius: 12px;
    background: rgba(0, 0, 0, 0.35); border: 1px solid var(--glass-border);
    margin-bottom: 1rem; user-select: all;
    white-space: nowrap; overflow-x: auto;
}
.recovery-actions { display: flex; flex-direction: column; gap: 0.6rem; }
.recovery-ok { background: transparent; border: 1px solid var(--glass-border); box-shadow: none; }
.recovery-ok:disabled {
    opacity: 0.45; cursor: not-allowed; pointer-events: none;
}
.avatar-picker { display: flex; justify-content: center; gap: 12px; margin-bottom: 1.5rem; }
.avatar-option {
    width: 48px; height: 48px; border-radius: 50%; display: flex;
    justify-content: center; align-items: center; font-size: 1.5rem;
    cursor: pointer; background: rgba(255, 255, 255, 0.08);
    border: 2px solid transparent; transition: var(--transition);
}
.avatar-option:hover, .avatar-option.selected {
    border-color: var(--select-accent); transform: scale(1.15); background: var(--select-accent-bg);
}
.input-group { margin-bottom: 1rem; }
.input-group input {
    width: 100%; padding: 12px 16px; border-radius: 14px;
    border: 1px solid var(--glass-border); background: rgba(0, 0, 0, 0.25);
    color: #fff; font-size: 1rem; outline: none; transition: var(--transition);
}
.input-group input:focus { border-color: var(--focus-ring); box-shadow: 0 0 15px var(--focus-glow); }
.btn-primary {
    width: 100%; padding: 13px; border: none; border-radius: 14px;
    background: var(--accent-gradient); color: #fff; font-size: 1rem;
    font-weight: 600; cursor: pointer; transition: var(--transition);
    box-shadow: 0 8px 20px var(--accent-shadow);
}
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-2px); }
.btn-primary:disabled {
    opacity: 0.65;
    cursor: wait;
    transform: none;
    filter: grayscale(0.15);
}
.app-container {
    width: 95vw; max-width: 1200px; height: 90vh;
    background: var(--glass-bg); backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border); border-radius: 28px;
    display: flex; overflow: hidden; box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6);
    animation: fadeIn 0.6s ease;
}
.sidebar {
    width: 320px; border-right: 1px solid var(--glass-border);
    display: flex; flex-direction: column; background: var(--panel-bg);
}
.my-profile {
    height: var(--header-h); padding: 0 20px; display: flex; align-items: center;
    justify-content: space-between; border-bottom: 1px solid var(--glass-border);
    flex-shrink: 0;
}
.profile-info { display: flex; align-items: center; gap: 12px; }
.peer-wrap { flex: 1; min-width: 0; }
.my-profile .profile-info { flex: 1; min-width: 0; }
.chat-header .profile-info { min-width: 0; }
.profile-info .contact-name {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.avatar {
    width: 46px; height: 46px; border-radius: 50%;
    background: var(--accent-gradient); display: flex;
    justify-content: center; align-items: center; font-size: 1.4rem;
    position: relative; flex-shrink: 0;
    /* без overflow:hidden — иначе ::after (онлайн) режется в «полоску» поверх фото */
}
.avatar-photo {
    position: absolute;
    inset: 0;
    width: 100%; height: 100%;
    object-fit: cover; display: block;
    border-radius: 50%;
    z-index: 0;
}
.avatar::after {
    content: ""; width: 11px; height: 11px; background: var(--online); border-radius: 50%;
    position: absolute; bottom: 0; right: 0; border: 2px solid var(--avatar-ring);
    z-index: 1;
    box-sizing: border-box;
}
.avatar.offline::after { background: #ff2a5f; }
.profile-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.icon-btn {
    background: rgba(255, 255, 255, 0.08); border: none; color: #fff;
    width: 38px; height: 38px; border-radius: 12px; cursor: pointer;
    display: flex; justify-content: center; align-items: center;
    font-size: 1.1rem; transition: var(--transition);
}
.icon-btn:hover { background: var(--accent-gradient); transform: scale(1.08); }
.icon-btn svg, .call-btn svg, .msg-del-btn svg {
    width: 20px; height: 20px; display: block; pointer-events: none;
}
.icon-btn.back-btn svg { width: 22px; height: 22px; }
.icon-btn.back-btn { transform: scaleX(-1); }
.icon-btn.back-btn:hover { transform: scaleX(-1) scale(1.08); }
.pwa-install-btn {
    width: 38px; height: 38px; padding: 0; border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px; cursor: pointer; overflow: hidden;
    background: linear-gradient(135deg, #0f0c29 0%, #302b63 50%, #24243e 100%);
    display: flex; justify-content: center; align-items: center;
    transition: var(--transition); flex-shrink: 0;
}
.pwa-install-btn:hover {
    border-color: rgba(var(--accent-rgb), 0.55);
    box-shadow: 0 0 14px rgba(var(--accent-rgb), 0.35);
}
.pwa-install-btn img {
    width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none;
}
.call-btn svg { width: 24px; height: 24px; display: block; margin: auto; }
.call-btn.off { opacity: 0.45; }
.contacts-title {
    padding: 14px 20px 6px; font-size: 0.75rem; text-transform: uppercase;
    letter-spacing: 1px; color: var(--text-muted);
}
.contacts-search { padding: 10px 16px 8px; }
.contacts-tabs {
    display: flex;
    gap: 0;
    margin: 0 16px 10px;
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    overflow: hidden;
    flex-shrink: 0;
}
.contacts-tab {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    padding: 9px 8px;
    cursor: pointer;
    transition: var(--transition);
}
.contacts-tab.active {
    background: var(--select-accent-bg);
    color: #fff;
}
.contacts-tab:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: -2px;
}
.search-field { position: relative; display: flex; align-items: center; }
.search-field > svg {
    position: absolute; left: 12px; width: 16px; height: 16px;
    color: var(--text-muted); pointer-events: none;
}
.search-field input {
    width: 100%; padding: 9px 36px; border-radius: 999px;
    border: 1px solid var(--glass-border); background: rgba(255, 255, 255, 0.06);
    color: var(--text-main); font: inherit; font-size: 0.88rem; outline: none;
    transition: var(--transition);
}
.search-field input:focus {
    border-color: var(--select-accent); background: rgba(255, 255, 255, 0.1);
}
.search-field input::-webkit-search-cancel-button { display: none; }
.search-clear {
    position: absolute; right: 6px; width: 26px; height: 26px; padding: 0;
    display: flex; align-items: center; justify-content: center;
    background: none; border: none; border-radius: 50%;
    color: var(--text-muted); cursor: pointer; transition: var(--transition);
}
.search-clear:hover { color: var(--text-main); background: rgba(255, 255, 255, 0.1); }
.search-clear svg { width: 14px; height: 14px; }
.search-clear[hidden] { display: none; }
.unread-badge {
    flex-shrink: 0; min-width: 20px; height: 20px; padding: 0 6px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 999px; background: var(--accent-gradient);
    color: #fff; font-size: 0.7rem; font-weight: 700; line-height: 1;
    box-shadow: 0 2px 8px var(--accent-shadow);
}
.contacts-list {
    flex: 1; min-height: 0; overflow-y: auto; padding: 8px 12px;
    overscroll-behavior-y: contain;
    scrollbar-width: none; /* Firefox */
}
.contacts-list::-webkit-scrollbar { display: none; width: 0; height: 0; }
.contact-item {
    display: flex; align-items: center; gap: 12px; padding: 12px 14px;
    border-radius: 16px; cursor: pointer; transition: var(--transition); margin-bottom: 6px;
}
.contact-item:hover { background: rgba(255, 255, 255, 0.07); transform: translateX(4px); }
.contact-item .avatar.offline { opacity: 0.55; }
.contact-item.active {
    background: var(--active-bg);
    border: 1px solid var(--active-border);
}
.contact-details { flex: 1; min-width: 0; overflow: hidden; }
.contact-name {
    font-weight: 600; font-size: 0.95rem; margin-bottom: 2px;
    overflow-wrap: anywhere; word-break: break-word;
}
.contact-last-msg { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-area { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.active-chat {
    display: none;
    flex: 1; min-height: 0; overflow: hidden;
    flex-direction: column;
}
.app-container.chat-open .active-chat,
.active-chat.is-open {
    display: flex;
}
.empty-state {
    flex: 1; display: flex; flex-direction: column; justify-content: center;
    align-items: center; color: var(--text-muted); text-align: center; padding: 20px;
}
.chat-header {
    height: var(--header-h); padding: 0 25px; border-bottom: 1px solid var(--glass-border);
    display: flex; justify-content: space-between; align-items: center;
    background: var(--header-bg); flex-shrink: 0;
}
.chat-actions { display: flex; gap: 10px; }
.messages-box {
    flex: 1; min-height: 0; padding: 25px; overflow-y: auto; overflow-x: hidden;
    display: flex;
    flex-direction: column; gap: 14px; scroll-behavior: smooth;
    overscroll-behavior-y: contain;
}
.message {
    max-width: 68%; padding: 12px 18px; border-radius: 20px;
    font-size: 0.95rem; line-height: 1.45; animation: fadeIn 0.3s ease forwards;
    overflow-wrap: anywhere; word-break: break-word; white-space: pre-wrap;
    display: flex; flex-direction: column; gap: 8px;
    position: relative;
}
.message.in {
    align-self: flex-start; background: var(--msg-in);
    border-bottom-left-radius: 4px; border: 1px solid var(--glass-border);
}
.message.out {
    align-self: flex-end; background: var(--accent-gradient);
    border-bottom-right-radius: 4px; box-shadow: 0 5px 15px var(--accent-shadow);
}
.msg-link {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
    word-break: break-all;
}
.message.in .msg-link { color: var(--accent-soft, #8ab4ff); }
.message.out .msg-link { color: #fff; text-decoration-color: rgba(255, 255, 255, 0.7); }
.msg-link:hover { opacity: 0.9; }
/* --- вложения в сообщениях --- */
.msg-image {
    max-width: 100%; max-height: 320px; border-radius: 14px;
    cursor: zoom-in; display: block; object-fit: cover; align-self: flex-start;
}
.msg-file {
    display: flex; align-items: center; gap: 10px; padding: 10px 14px;
    border-radius: 14px; cursor: pointer; min-width: 180px;
    background: rgba(0, 0, 0, 0.18); transition: var(--transition);
}
.msg-file:hover { background: rgba(0, 0, 0, 0.3); }
.msg-file.out { background: rgba(255, 255, 255, 0.15); }
.msg-file.out:hover { background: rgba(255, 255, 255, 0.25); }
.msg-file-icon {
    width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    background: rgba(255, 255, 255, 0.15);
}
.msg-file-icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.msg-file-info { display: flex; flex-direction: column; min-width: 0; }
.msg-file-name {
    font-size: 0.85rem; font-weight: 600;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    max-width: 220px; color: inherit;
}
.msg-file-size { font-size: 0.7rem; opacity: 0.7; }
.msg-file.md .msg-file-icon { background: rgba(100, 180, 255, 0.2); }
.msg-file-actions {
    display: flex; align-items: center; gap: 4px; flex-shrink: 0; margin-left: auto;
}
.msg-file-dl {
    width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0;
    border: none; cursor: pointer; padding: 0;
    background: rgba(255, 255, 255, 0.12); color: inherit;
    display: flex; align-items: center; justify-content: center;
    transition: var(--transition);
}
.msg-file-dl:hover { background: rgba(255, 255, 255, 0.22); }
.msg-file-dl svg {
    width: 16px; height: 16px; fill: none; stroke: currentColor;
    stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.msg-file-open-hint {
    font-size: 0.65rem; opacity: 0.65; margin-top: 1px;
}
.msg-time { display: block; font-size: 0.7rem; opacity: 0.7; margin-top: 5px; text-align: right; }
.typing-indicator {
    font-size: 0.8rem; color: var(--accent-soft); padding: 0 25px 8px;
    height: 24px; flex-shrink: 0; opacity: 0; transition: opacity 0.3s ease;
}
.typing-indicator.visible { opacity: 1; }
.chat-input-area {
    padding: 18px 25px; border-top: 1px solid var(--glass-border);
    display: flex; flex-wrap: wrap; gap: 12px; background: var(--inputbar-bg); flex-shrink: 0;
    align-items: flex-end; min-width: 0;
}
/* Панель редактирования — отдельная строка; скрепка/инпут/отправка всегда в одном ряду. */
.chat-input-area .edit-bar { order: -1; flex: 1 0 100%; }
.attach-btn {
    width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0;
    border: 1px solid var(--glass-border); cursor: pointer;
    background: rgba(255, 255, 255, 0.05); color: var(--text-muted);
    display: flex; align-items: center; justify-content: center;
    transition: var(--transition); padding: 0;
}
.attach-btn:hover { border-color: var(--select-accent); color: var(--text-main); }
.attach-btn:disabled { opacity: 0.5; cursor: wait; }
.attach-btn svg { width: 18px; height: 18px; display: block; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.attach-preview {
    display: flex; align-items: center; gap: 8px; max-width: min(240px, 28vw);
    padding: 7px 10px; border-radius: 12px; font-size: 0.8rem;
    flex: 0 1 auto; min-width: 0;
    background: rgba(255, 255, 255, 0.06); border: 1px dashed var(--glass-border);
}
.attach-preview-name {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    color: var(--text-muted); min-width: 0;
}
.attach-preview-remove {
    border: none; background: none; color: var(--text-muted); cursor: pointer;
    font-size: 0.9rem; padding: 0 2px; flex-shrink: 0;
}
.attach-preview-remove:hover { color: #ff8ba0; }
.chat-input-area input,
.chat-input-area textarea.message-input {
    /* без width:100% — иначе при flex-wrap инпут уезжает на свою строку */
    flex: 1 1 0; min-width: 0; width: auto; padding: 14px 20px; border-radius: 18px;
    border: 1px solid var(--glass-border); background: rgba(255, 255, 255, 0.07);
    color: #fff; font-size: 0.95rem; outline: none; transition: var(--transition);
    box-sizing: border-box;
}
.chat-input-area input:focus,
.chat-input-area textarea.message-input:focus { border-color: var(--select-accent); background: rgba(255, 255, 255, 0.12); }
.send-btn {
    height: 50px; padding: 0 28px; border: none; border-radius: 18px;
    background: var(--accent-gradient); color: #fff; font-weight: 600;
    font-size: 0.95rem; white-space: nowrap; flex-shrink: 0;
    cursor: pointer; transition: var(--transition);
}
.send-btn:hover { transform: scale(1.05); }
.call-modal {
    position: fixed; inset: 0; background: var(--overlay-bg);
    backdrop-filter: blur(25px); display: flex; flex-direction: column;
    justify-content: center; align-items: center; z-index: 120;
    opacity: 0; pointer-events: none; transform: scale(0.95); transition: var(--transition);
}
.call-modal.active { opacity: 1; pointer-events: all; transform: scale(1); }
.videos-grid { display: flex; gap: 20px; margin-bottom: 20px; flex-wrap: wrap; justify-content: center; }
video {
    width: 300px; height: 220px; border-radius: 20px; background: var(--video-bg);
    object-fit: cover; border: 2px solid var(--video-border); display: none;
}
.call-avatar {
    width: 110px; height: 110px; border-radius: 50%;
    background: var(--accent-gradient); display: flex;
    justify-content: center; align-items: center; font-size: 3.5rem;
    margin-bottom: 20px; animation: pulseGlow 2s infinite;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}
.call-avatar .avatar-photo {
    position: absolute;
    inset: 0;
    width: 100%; height: 100%;
    object-fit: cover; display: block;
    border-radius: 50%;
}
.call-controls { display: flex; gap: 20px; margin-top: 25px; }
.call-btn {
    width: 58px; height: 58px; border-radius: 50%; border: none;
    font-size: 1.4rem; cursor: pointer; color: #fff;
    background: rgba(255, 255, 255, 0.15); transition: var(--transition);
    display: flex; justify-content: center; align-items: center;
    padding: 0; flex-shrink: 0;
}
.call-btn:hover { transform: scale(1.1); }
.call-btn.accept { background: #00b894; box-shadow: 0 8px 25px rgba(0, 184, 148, 0.4); }
.call-btn.end { background: #ff2a5f; box-shadow: 0 8px 25px rgba(255, 42, 95, 0.4); }
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); border-radius: 10px; }
.version-badge {
    flex-shrink: 0; padding: 10px 14px; text-align: center;
    font-size: 0.72rem; color: var(--text-muted); opacity: 0.7;
    border-top: 1px solid var(--glass-border);
    pointer-events: auto; transition: var(--transition);
}
.version-badge.stale {
    cursor: pointer; color: #ffd166; opacity: 1;
    background: rgba(255, 209, 102, 0.12);
}
.version-badge.stale:hover { background: rgba(255, 209, 102, 0.2); }
.pwa-hint {
    position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
    z-index: 220; max-width: min(92vw, 360px);
    padding: 12px 16px; border-radius: 14px;
    background: var(--panel-solid); border: 1px solid var(--glass-border);
    color: var(--text-main); font-size: 0.9rem; text-align: center;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    animation: fadeIn 0.3s ease forwards;
}
.pwa-hint[hidden] { display: none; }

/* --- стартовая заставка: лого + название --- */
#apex-splash {
    position: fixed; inset: 0; z-index: 400;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 14px; background: var(--bg-gradient);
    transition: opacity 0.45s ease, visibility 0.45s ease;
}
#apex-splash img {
    width: 96px; height: 96px; border-radius: 22px;
    animation: pulseGlow 2s infinite;
}
.splash-title {
    font-size: 1.7rem; font-weight: 700; letter-spacing: 2px;
    background: var(--title-gradient);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.splash-sub { font-size: 0.82rem; color: var(--text-muted); }
#apex-splash.done { opacity: 0; visibility: hidden; pointer-events: none; }

/* --- кликабельные аватары/имена --- */
.clickable { cursor: pointer; transition: var(--transition); }
.clickable:hover { transform: scale(1.06); }

/* --- модалка профиля --- */
.profile-modal {
    position: fixed; inset: 0; z-index: 150;
    background: var(--overlay-bg); backdrop-filter: blur(14px);
    display: flex; justify-content: center; align-items: center;
    opacity: 0; pointer-events: none; transition: var(--transition);
}
.profile-modal.open { opacity: 1; pointer-events: all; }
.profile-card {
    position: relative;
    background: var(--panel-solid); border: 1px solid var(--glass-border);
    padding: 1.6rem 1.35rem 1.15rem; border-radius: 24px; width: 92%; max-width: 380px;
    max-height: min(88vh, 720px); overflow-y: auto;
    text-align: center; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.4s ease forwards;
    -webkit-overflow-scrolling: touch;
}
.profile-section {
    text-align: left;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--glass-border);
}
.profile-section[hidden] { display: none !important; }
.profile-section-title {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 10px;
}
.profile-legal-foot {
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--glass-border);
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.45;
}
.profile-legal-foot[hidden] { display: none !important; }
.profile-legal-foot a {
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  transition: var(--transition);
}
.profile-legal-foot a:hover {
  color: var(--text-main);
  border-bottom-color: rgba(255, 255, 255, 0.4);
}
.profile-legal-sep {
  margin: 0 0.5em;
  opacity: 0.45;
  user-select: none;
}
.profile-section-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.4;
    margin-bottom: 10px;
}
.profile-invite-row {
    display: flex;
    gap: 8px;
    align-items: stretch;
}
.profile-invite-input {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    background: rgba(0, 0, 0, 0.28);
    color: var(--text-main);
    font: inherit;
    font-size: 0.78rem;
}
.profile-invite-copy {
    width: auto;
    margin: 0;
    padding: 0 14px;
    font-size: 0.82rem;
    flex-shrink: 0;
}
.profile-invite-copy:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
.profile-invite-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
}
.profile-invite-actions .photo-pick-btn {
    flex: 1;
    min-width: 120px;
}
.profile-sec-btn {
    width: 100%;
    margin-bottom: 8px;
    text-align: center;
}
.profile-section > .profile-sec-btn:last-child,
.profile-section > .profile-delete-btn:last-child {
    margin-bottom: 0;
}
.profile-section .profile-pass-form {
    margin-bottom: 8px;
}
.profile-section .profile-photo-row {
    margin-bottom: 0;
}
.profile-section .profile-delete-btn {
    margin-top: 0;
    width: 100%;
}
.profile-close { position: absolute; top: 14px; right: 14px; }
.profile-avatar {
    width: 96px; height: 96px; border-radius: 50%;
    background: var(--accent-gradient); display: flex;
    justify-content: center; align-items: center; font-size: 3rem;
    margin: 0 auto 16px; box-shadow: 0 10px 30px var(--focus-glow);
    position: relative;
    overflow: hidden; /* только фото/эмодзи, без онлайн-точки */
}
.profile-avatar .avatar-photo {
    position: absolute;
    inset: 0;
    border-radius: 50%;
}
.profile-photo-row {
    display: flex; gap: 8px; justify-content: center; margin-bottom: 14px;
}
.photo-pick-btn {
    padding: 8px 14px; border-radius: 12px; cursor: pointer;
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.05); color: var(--text-main);
    font: inherit; font-size: 0.85rem; transition: var(--transition);
}
.photo-pick-btn:hover {
    border-color: var(--select-accent);
    background: var(--select-accent-bg);
}
.photo-pick-btn.photo-pending { opacity: 0.6; }
.photo-delete-btn { color: #ff8ba0; }
.profile-name {
    font-size: 1.4rem; font-weight: 700; margin-bottom: 6px;
    background: var(--title-gradient);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    word-break: break-word;
}
.profile-status {
    color: var(--text-muted); font-size: 0.95rem; margin-bottom: 14px;
    word-break: break-word;
}
.profile-badge {
    display: inline-block; padding: 5px 14px; border-radius: 999px;
    font-size: 0.78rem; color: var(--online);
    background: var(--online-bg); border: 1px solid var(--online-border);
}
.profile-badge.offline {
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.06); border-color: var(--glass-border);
}

/* --- избранные контакты (только у себя) --- */
.profile-chips {
    display: flex; justify-content: center; align-items: center;
    gap: 10px; flex-wrap: wrap; margin-bottom: 4px;
}
.profile-chips .profile-badge,
.profile-chips .profile-fav-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    height: 34px; padding: 0 16px; margin: 0; border-radius: 999px;
    font: inherit; font-size: 0.8rem; line-height: 1; white-space: nowrap;
}
.profile-chips .profile-fav-btn svg { width: 15px; height: 15px; opacity: 0.85; }
.profile-fav-btn {
    padding: 9px 18px; border-radius: 999px;
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.05); color: var(--text-muted);
    font: inherit; font-size: 0.88rem; cursor: pointer;
    transition: var(--transition);
}
.profile-fav-btn svg { width: 16px; height: 16px; opacity: 0.8; }
.profile-fav-btn:hover { border-color: rgba(255, 209, 102, 0.5); color: #ffd166; }
.profile-fav-btn.active {
    color: #ffd166; border-color: rgba(255, 209, 102, 0.55);
    background: rgba(255, 209, 102, 0.1);
}
.profile-fav-note {
    margin-top: 10px; font-size: 0.74rem; color: var(--text-muted); opacity: 0.7;
}
.profile-fav-note.is-error {
    color: #ff2a5f; opacity: 1; font-weight: 600;
}
.profile-fav-note.is-ok {
    color: #3dd68c; opacity: 1; font-weight: 600;
}
.app-toast {
    position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
    transform: translateX(-50%) translateY(12px);
    z-index: 500; max-width: min(92vw, 360px);
    padding: 10px 16px; border-radius: 12px;
    background: rgba(20, 16, 40, 0.94); border: 1px solid var(--glass-border);
    color: #fff; font-size: 0.85rem; font-weight: 600; text-align: center;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    opacity: 0; pointer-events: none; transition: opacity 0.2s ease, transform 0.2s ease;
}
.app-toast.show {
    opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto;
}
.app-toast.is-error { border-color: rgba(255, 42, 95, 0.45); color: #ff8ba0; }
.profile-delete-btn {
    color: #ff8ba0 !important;
    border-color: rgba(255, 42, 95, 0.35) !important;
    margin-top: 8px;
}
.account-guard {
    margin: 8px 12px 4px; padding: 10px 12px; border-radius: 12px;
    background: rgba(255, 180, 60, 0.12); border: 1px solid rgba(255, 180, 60, 0.35);
    color: var(--text-main); font-size: 0.78rem; line-height: 1.35;
}
.account-guard-text { margin-bottom: 8px; opacity: 0.95; }
.account-guard-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn-secondary {
    display: inline-flex; align-items: center; justify-content: center;
    width: 100%; margin-top: 0.5rem; padding: 12px 18px;
    border-radius: 14px; border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.06); color: var(--text-main);
    font: inherit; font-weight: 600; cursor: pointer;
    transition: var(--transition);
}
.btn-secondary:hover { border-color: var(--accent-soft); background: rgba(255, 255, 255, 0.1); }
.auth-close-btn {
    position: absolute; top: 12px; right: 12px; z-index: 2;
}
.icon-btn[hidden],
.auth-close-btn[hidden],
.pwa-install-btn[hidden] {
    display: none !important;
}

.chat-blocked-banner {
    grid-column: 1 / -1;
    width: 100%;
    padding: 8px 12px;
    border-radius: 10px;
    background: rgba(255, 42, 95, 0.12);
    border: 1px solid rgba(255, 42, 95, 0.35);
    color: #ff8ba0;
    font-size: 0.78rem;
    line-height: 1.35;
    margin-bottom: 6px;
}
.profile-block-btn.is-blocked {
    color: #ffd166 !important;
    border-color: rgba(255, 209, 102, 0.4) !important;
}
.account-guard-actions .btn-primary,
.account-guard-actions .btn-secondary {
    width: auto; margin: 0; padding: 6px 12px; font-size: 0.78rem;
}
.profile-nick-wrap {
    display: flex; gap: 8px; margin-top: 14px; width: 100%;
}
.profile-nick-input {
    flex: 1; min-width: 0; padding: 10px 14px; border-radius: 12px;
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.05); color: var(--text-main);
    font: inherit; font-size: 0.9rem; outline: none;
}
.profile-nick-input:focus { border-color: var(--accent-soft); }
.profile-nick-save { width: auto; padding: 10px 16px; font-size: 0.85rem; flex-shrink: 0; margin-top: 0; }
.fav-star {
    display: inline-flex; align-items: center; flex-shrink: 0;
    color: #ffd166; margin-left: auto;
}
.fav-star svg { width: 14px; height: 14px; }
/* Если звезды нет — бейдж сам прижимается вправо; если есть — рядом со звездой. */
.contact-item > .unread-badge { margin-left: auto; }
.contact-item > .fav-star + .unread-badge { margin-left: 0; }

/* --- системные строки: удалено / звонки (максимально компактно) --- */
.message.sys-msg,
.message.call-msg,
.message.deleted-msg {
    align-self: center;
    max-width: 94%;
    width: auto;
    margin: 0;
    padding: 1px 6px;
    gap: 6px;
    border: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    animation: none;
    font-size: 0.68rem;
    font-weight: 500;
    line-height: 1.25;
    opacity: 0.55;
    display: flex;
    align-items: baseline;
    justify-content: center;
    flex-wrap: wrap;
}
.sys-msg-text,
.call-msg-text {
    color: var(--text-muted);
    font-style: normal;
}
.sys-msg-time {
    font-size: 0.62rem;
    color: var(--text-muted);
    opacity: 0.75;
    flex-shrink: 0;
}
.message.deleted {
    font-style: italic; opacity: 0.55; color: var(--text-muted);
    background: transparent; box-shadow: none; border: none;
}
.msg-meta {
    display: flex; align-items: center; justify-content: flex-end;
    gap: 8px; margin-top: 5px;
}
.msg-time { display: block; font-size: 0.7rem; opacity: 0.7; }
.msg-del-btn {
    background: rgba(255, 255, 255, 0.12); border: none; cursor: pointer;
    color: #fff; border-radius: 8px;
    width: 22px; height: 22px; padding: 0;
    display: flex; justify-content: center; align-items: center;
    opacity: 0; transition: var(--transition);
}
.msg-del-btn svg { width: 13px; height: 13px; }
.message:hover .msg-del-btn { opacity: 0.85; }
.msg-del-btn:hover { background: #ff2a5f; opacity: 1; transform: scale(1.1); }

/* --- реакции на сообщения --- */
.msg-more-btn {
    background: rgba(255, 255, 255, 0.12); border: none; cursor: pointer;
    color: #fff; border-radius: 8px;
    width: 22px; height: 22px; padding: 0; line-height: 1;
    font-size: 1rem; opacity: 0; transition: var(--transition);
}
.message:hover .msg-more-btn { opacity: 0.85; }
.msg-more-btn:hover { background: var(--select-accent); opacity: 1; transform: scale(1.1); }
.msg-edited {
    font-size: 0.65rem; opacity: 0.65; margin-right: 4px; font-style: italic;
}
.msg-action-menu {
    position: fixed; z-index: 120;
    min-width: 200px; max-width: min(320px, calc(100vw - 16px));
    padding: 8px; border-radius: 16px;
    background: var(--panel-solid);
    border: 1px solid var(--glass-border);
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.5);
}
.msg-action-reacts {
    display: flex; flex-wrap: wrap; gap: 2px; padding: 2px 2px 8px;
    border-bottom: 1px solid var(--glass-border); margin-bottom: 4px;
}
.msg-action-item {
    display: block; width: 100%; text-align: left;
    border: none; background: transparent; color: var(--text-main);
    padding: 10px 12px; border-radius: 10px; cursor: pointer;
    font-size: 0.92rem;
}
.msg-action-item:hover { background: rgba(255, 255, 255, 0.08); }
.chat-search-bar {
    display: flex; gap: 8px; align-items: center;
    padding: 8px 12px; border-bottom: 1px solid var(--glass-border);
    background: rgba(0, 0, 0, 0.18);
}
.chat-search-bar[hidden] { display: none !important; }
.chat-search-bar input {
    flex: 1; min-width: 0; padding: 8px 12px; border-radius: 10px;
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.06); color: var(--text-main);
    font: inherit; font-size: 0.88rem; outline: none;
}
.chat-search-close {
    border: none; background: transparent; color: var(--text-muted);
    font-size: 1rem; cursor: pointer; padding: 6px 8px;
}
.chat-search-hits {
    max-height: 160px; overflow: auto;
    border-bottom: 1px solid var(--glass-border);
    background: rgba(0, 0, 0, 0.22);
}
.chat-search-hits[hidden] { display: none !important; }
.chat-search-hit {
    display: flex; gap: 10px; width: 100%;
    padding: 8px 14px; border: none; background: transparent;
    color: var(--text-main); text-align: left; cursor: pointer;
    font: inherit; font-size: 0.82rem;
}
.chat-search-hit:hover { background: rgba(255, 255, 255, 0.06); }
.chat-search-hit-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-search-hit-time { flex-shrink: 0; color: var(--text-muted); font-size: 0.72rem; }
.chat-search-empty { padding: 10px 14px; color: var(--text-muted); font-size: 0.8rem; }
.msg-reply-quote {
    display: flex; flex-direction: column; gap: 2px; width: 100%;
    margin: 0 0 6px; padding: 6px 8px; border: none; border-radius: 8px;
    border-left: 3px solid var(--accent-soft, #7aa2ff);
    background: rgba(0, 0, 0, 0.18); color: inherit;
    text-align: left; cursor: pointer; font: inherit;
}
.message.out .msg-reply-quote { background: rgba(255, 255, 255, 0.12); }
.msg-reply-who { font-size: 0.72rem; font-weight: 700; opacity: 0.9; }
.msg-reply-text { font-size: 0.78rem; opacity: 0.85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message.msg-flash {
    outline: 2px solid var(--accent-soft, #7aa2ff);
    animation: msgFlash 1.1s ease;
}
@keyframes msgFlash {
    0% { outline-color: var(--accent-soft, #7aa2ff); }
    100% { outline-color: transparent; }
}
.reply-bar .edit-bar-label { color: var(--accent-soft, #7aa2ff); }
.edit-bar {
    display: flex; align-items: center; gap: 8px;
    width: 100%; padding: 8px 10px; margin-bottom: 6px;
    border-radius: 12px; background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--glass-border); box-sizing: border-box;
}
.edit-bar[hidden] { display: none !important; }
.edit-bar-label {
    font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--accent-soft); flex-shrink: 0;
}
.edit-bar-text {
    flex: 1; min-width: 0; font-size: 0.82rem; color: var(--text-muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.edit-bar-close {
    border: none; background: none; color: var(--text-muted);
    cursor: pointer; font-size: 0.95rem; padding: 0 4px;
}
.reaction-picker {
    display: flex; gap: 2px; padding: 5px 7px;
    background: var(--panel-solid);
    border: 1px solid var(--glass-border);
    border-radius: 14px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
    z-index: 30;
    animation: reactionPickerIn 0.15s ease forwards;
}
.reaction-option {
    border: none; cursor: pointer; background: transparent;
    font-size: 1.15rem; line-height: 1; padding: 5px 6px;
    border-radius: 9px; transition: var(--transition);
}
.reaction-option:hover { background: var(--select-accent-bg); transform: scale(1.25); }
/* opacity-only: fadeIn заканчивается transform'ом, который перебивал позицию пикера */
@keyframes reactionPickerIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
.msg-reactions {
    display: flex; flex-wrap: wrap; gap: 5px; margin-top: 4px;
    max-width: 100%;
}
.reaction-chip {
    display: inline-flex; align-items: center; gap: 4px;
    border: 1px solid var(--glass-border); cursor: pointer;
    background: rgba(255, 255, 255, 0.06); color: var(--text-main);
    border-radius: 12px; padding: 3px 9px;
    font-size: 0.82rem; line-height: 1.3;
    transition: var(--transition);
}
.reaction-chip:hover {
    background: rgba(255, 255, 255, 0.12);
    transform: translateY(-1px);
}
.reaction-chip.mine {
    background: var(--select-accent-bg);
    border-color: var(--select-accent);
}

/* --- пароль аккаунта --- */
.profile-pass-row { flex-direction: column; gap: 6px; }
.profile-pass-form {
    display: flex; flex-direction: column; gap: 8px; width: 100%;
}
.profile-pass-form .profile-nick-input { width: 100%; box-sizing: border-box; }

/* --- лайтбокс изображений --- */
.apex-lightbox {
    position: fixed; inset: 0; z-index: 400;
    background: rgba(5, 4, 18, 0.92);
    backdrop-filter: blur(8px);
    display: flex; align-items: center; justify-content: center;
    opacity: 0; transition: opacity 0.18s ease;
    touch-action: none;
}
/* hidden + display:flex: display перебивает hidden — гасим указателями и видимостью */
.apex-lightbox[hidden] { display: none; }
.apex-lightbox.open { opacity: 1; }
.apex-lightbox-img {
    max-width: 92vw; max-height: 88vh;
    border-radius: 12px; box-shadow: 0 18px 60px rgba(0, 0, 0, 0.6);
    transition: transform 0.16s ease;
    will-change: transform;
    user-select: none; -webkit-user-drag: none;
    touch-action: none;
}
.apex-lightbox-btn {
    position: absolute;
    background: var(--panel-solid); color: var(--text-main);
    border: 1px solid var(--glass-border); border-radius: 50%;
    width: 42px; height: 42px; font-size: 1.1rem; line-height: 1;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: var(--transition);
}
.apex-lightbox-btn:hover { background: var(--select-accent); }
.apex-lightbox-close { top: calc(16px + env(safe-area-inset-top)); right: 16px; }
.apex-lightbox-download {
    bottom: calc(56px + env(safe-area-inset-bottom)); right: 16px;
}
.apex-lightbox-zoom-in {
    bottom: calc(56px + env(safe-area-inset-bottom)); left: 16px;
}
.apex-lightbox-zoom-out {
    bottom: calc(56px + env(safe-area-inset-bottom)); left: 68px;
}
.apex-lightbox-caption {
    position: absolute;
    left: 0; right: 0;
    bottom: calc(16px + env(safe-area-inset-bottom));
    text-align: center; color: var(--text-muted);
    font-size: 0.82rem; padding: 0 60px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* --- просмотр Markdown-вложений --- */
.apex-md-viewer {
    position: fixed; inset: 0; z-index: 410;
    height: var(--app-height, 100dvh);
    max-height: var(--app-height, 100dvh);
    background: rgba(5, 4, 18, 0.72);
    backdrop-filter: blur(6px);
    display: flex; align-items: stretch; justify-content: center;
    opacity: 0; transition: opacity 0.18s ease;
}
.apex-md-viewer[hidden] { display: none; }
.apex-md-viewer.open { opacity: 1; }
body.md-viewer-open { overflow: hidden; }
.apex-md-panel {
    display: flex; flex-direction: column;
    width: 100%; height: 100%;
    background: var(--bg, #0f0c29);
    color: var(--text-main);
    min-width: 0; min-height: 0;
}
.apex-md-header {
    flex-shrink: 0;
    display: flex; align-items: center; gap: 10px;
    min-height: 52px;
    padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
    border-bottom: 1px solid var(--glass-border);
    background: var(--panel-solid, rgba(20, 18, 40, 0.96));
}
.apex-md-back {
    flex-shrink: 0;
    min-height: 42px; min-width: 72px;
    padding: 8px 12px; border-radius: 12px;
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-main); font: inherit; font-size: 0.9rem; font-weight: 600;
    cursor: pointer; transition: var(--transition);
}
.apex-md-back:hover { border-color: var(--select-accent); background: var(--select-accent-bg); }
.apex-md-title {
    flex: 1; min-width: 0;
    font-size: 0.95rem; font-weight: 600;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.apex-md-download {
    flex-shrink: 0;
    width: 42px; height: 42px; border-radius: 50%;
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-main); font-size: 1.05rem; line-height: 1;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: var(--transition);
}
.apex-md-download:hover { background: var(--select-accent); }
.apex-md-scroll {
    flex: 1; min-height: 0; overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
}
@media (min-width: 720px) {
    .apex-md-viewer { padding: 24px 16px; align-items: center; }
    .apex-md-panel {
        width: min(800px, 100%);
        height: min(92%, var(--app-height, 100dvh));
        max-height: min(92%, var(--app-height, 100dvh));
        border-radius: 16px;
        border: 1px solid var(--glass-border);
        box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
        overflow: hidden;
    }
    .apex-md-header { padding-top: 12px; }
    .apex-md-scroll { padding: 20px 28px 28px; }
}
.apex-md-body {
    font-size: 0.95rem; line-height: 1.55;
    color: var(--text-main); word-wrap: break-word; overflow-wrap: anywhere;
}
.apex-md-body .md-h { margin: 1.1em 0 0.45em; font-weight: 700; line-height: 1.25; }
.apex-md-body .md-h1 { font-size: 1.55rem; }
.apex-md-body .md-h2 { font-size: 1.3rem; }
.apex-md-body .md-h3 { font-size: 1.12rem; }
.apex-md-body .md-h4, .apex-md-body .md-h5, .apex-md-body .md-h6 { font-size: 1rem; }
.apex-md-body .md-p { margin: 0 0 0.85em; white-space: pre-wrap; }
.apex-md-body .md-ul, .apex-md-body .md-ol { margin: 0 0 0.85em; padding-left: 1.4em; }
.apex-md-body .md-ul li, .apex-md-body .md-ol li { margin: 0.25em 0; }
.apex-md-body .md-quote {
    margin: 0 0 0.85em; padding: 0.4em 0.9em;
    border-left: 3px solid var(--select-accent, #6c8cff);
    background: rgba(255, 255, 255, 0.04); color: var(--text-muted);
}
.apex-md-body hr {
    border: none; border-top: 1px solid var(--glass-border);
    margin: 1.1em 0;
}
.apex-md-body a { color: var(--accent-soft, #9eb6ff); text-decoration: underline; }
.apex-md-body .md-inline-code,
.apex-md-body .md-pre code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.86em;
}
.apex-md-body .md-inline-code {
    padding: 0.12em 0.4em; border-radius: 6px;
    background: rgba(255, 255, 255, 0.08);
}
.apex-md-body .md-pre {
    margin: 0 0 0.95em; padding: 12px 14px; border-radius: 12px;
    background: rgba(0, 0, 0, 0.35); border: 1px solid var(--glass-border);
    overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.apex-md-body .md-pre code { white-space: pre; }
.apex-md-body .md-table-wrap {
    margin: 0 0 0.95em; overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.apex-md-body .md-table {
    border-collapse: collapse; width: max-content; min-width: 100%;
    font-size: 0.88rem;
}
.apex-md-body .md-table th,
.apex-md-body .md-table td {
    border: 1px solid var(--glass-border); padding: 8px 10px; text-align: left;
}
.apex-md-body .md-table th { background: rgba(255, 255, 255, 0.06); font-weight: 600; }
.apex-md-body .md-img-alt { color: var(--text-muted); font-style: italic; }

/* --- пикер оформления (логин + профиль) --- */
.theme-picker { display: flex; justify-content: center; gap: 10px; margin-top: 1.25rem; }
.profile-section .theme-picker { margin-top: 0.35rem; justify-content: stretch; }
.profile-section .theme-option { max-width: none; }
.theme-option {
    flex: 1 1 0; min-width: 0; max-width: 132px;
    padding: 10px 8px 8px; border-radius: 14px; cursor: pointer;
    background: rgba(255, 255, 255, 0.05); border: 2px solid var(--glass-border);
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    transition: var(--transition); font: inherit;
}
.theme-option:hover { transform: scale(1.05); }
.theme-option.selected { border-color: var(--select-accent); background: var(--select-accent-bg); }
.theme-swatch {
    width: 40px; height: 26px; border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.25);
}
.theme-swatch.default { background: linear-gradient(135deg, #0f0c29 0%, #302b63 60%, #6a11cb 130%); }
.theme-swatch.crimson { background: linear-gradient(135deg, #0a0406 0%, #1a0508 55%, #c0122f 140%); }
.theme-label {
    font-size: 0.72rem; line-height: 1.25; text-align: center;
    color: var(--text-muted); pointer-events: none;
    white-space: normal; overflow-wrap: anywhere;
}
.theme-option.selected .theme-label { color: var(--text-main); }
@media (max-width: 380px) {
    .theme-option { flex-basis: 0; max-width: none; }
    .theme-label { font-size: 0.68rem; }
}

/* --- папки избранных --- */
.folder-header {
    display: flex; align-items: center; gap: 6px;
    padding: 10px 14px 6px; margin-bottom: 2px;
    border-radius: 10px; cursor: pointer; user-select: none;
    transition: var(--transition);
}
.folder-header:hover { background: rgba(255, 255, 255, 0.05); }
.folder-chevron {
    flex-shrink: 0; width: 12px; font-size: 0.7rem; line-height: 1;
    color: var(--text-muted); text-align: center;
}
.folder-title {
    flex: 1; min-width: 0; font-size: 0.72rem; font-weight: 700;
    letter-spacing: 1px; text-transform: uppercase;
    color: var(--accent-soft); white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
}
.folder-header.collapsed .folder-title { opacity: 0.75; }
.folder-body { padding-bottom: 2px; }
.folder-edit-btn {
    background: none; border: none; cursor: pointer;
    color: var(--text-muted); font-size: 0.8rem; line-height: 1;
    padding: 2px 4px; border-radius: 6px; transition: var(--transition);
}
.folder-edit-btn:hover { color: var(--text-main); background: rgba(255, 255, 255, 0.1); }
/* Полоса между папками/избранными и остальными пользователями. */
.contacts-separator {
    height: 1px; margin: 10px 14px 8px;
    background: var(--glass-border);
    opacity: 0.9;
}
.profile-folder-select {
    appearance: none; -webkit-appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
        linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
    background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%;
    background-size: 5px 5px;
    background-repeat: no-repeat;
    padding-right: 30px;
}
.profile-folder-select option { background: #1a163f; color: #fff; }

/* --- галочки прочтения --- */
.msg-read { display: inline-flex; align-items: center; opacity: 0.75; }
.msg-read-svg {
    width: 15px; height: 15px; display: block;
    fill: none; stroke: currentColor; stroke-width: 2.5;
    stroke-linecap: round; stroke-linejoin: round;
}
.message.out .msg-read { color: rgba(255, 255, 255, 0.85); }
.msg-read.read { color: #7bffb2; opacity: 1; }
.message.out .msg-read.read { color: #aef7cc; }

/* --- радар: кнопка на мобиле и десктопе --- */
.radar-btn { display: flex; }
.radar-overlay {
    position: fixed; inset: 0; z-index: 90;
    display: flex; flex-direction: column;
    background: var(--bg, #0f0c29);
    background: linear-gradient(160deg, rgba(15, 12, 41, 0.98), rgba(36, 36, 62, 0.98));
    color: #fff;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}
.radar-overlay[hidden] { display: none !important; }
.radar-overlay .back-btn { display: flex !important; }
body.radar-open { overflow: hidden; }
.radar-header {
    height: var(--header-h, 60px); padding: 0 14px;
    display: flex; align-items: center; gap: 10px; flex-shrink: 0;
    border-bottom: 1px solid var(--glass-border, rgba(255, 255, 255, 0.08));
}
.radar-title {
    font-size: 1.05rem; font-weight: 600; letter-spacing: 0.02em;
}
.radar-loc-open {
    margin-left: auto; border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(255, 255, 255, 0.08); color: #fff;
    border-radius: 10px; padding: 8px 12px; cursor: pointer;
    font-size: 0.8rem; font-weight: 600; white-space: nowrap;
}
.radar-loc-open:hover { background: rgba(var(--accent-rgb, 123, 97, 255), 0.28); }
/* Оверлей формы поверх радара */
.radar-loc-sheet {
    position: absolute; inset: 0; z-index: 20;
    display: flex; align-items: flex-end; justify-content: center;
    padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom));
    box-sizing: border-box;
}
.radar-loc-sheet[hidden] { display: none !important; }
.radar-loc-backdrop {
    position: absolute; inset: 0; border: none; padding: 0;
    background: rgba(0, 0, 0, 0.55); cursor: pointer;
}
.radar-loc-panel {
    position: relative; z-index: 1; width: min(100%, 420px);
    max-height: min(78%, 520px); overflow-y: auto;
    padding: 14px 14px 16px;
    display: flex; flex-direction: column; gap: 10px;
    background: var(--panel-solid, rgba(15, 12, 41, 0.96));
    border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.12));
    border-radius: 18px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
}
.radar-loc-top {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.radar-loc-title {
    font-size: 0.95rem; font-weight: 600; letter-spacing: 0.02em; color: #fff;
}
.radar-loc-btn {
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(255, 255, 255, 0.08); color: #fff;
    border-radius: 10px; padding: 8px 12px; cursor: pointer;
    font-size: 0.8rem; font-weight: 600; white-space: nowrap;
}
.radar-loc-btn-block { width: 100%; text-align: center; }
.radar-loc-btn:hover { background: rgba(var(--accent-rgb, 123, 97, 255), 0.28); }
.radar-cloak {
    display: flex; align-items: center; gap: 8px;
    font-size: 0.85rem; color: #fff; cursor: pointer; user-select: none;
}
.radar-cloak input { width: 16px; height: 16px; accent-color: var(--online, #2dff9a); }
.radar-addr-wrap { position: relative; }
.radar-loc-input {
    width: 100%; box-sizing: border-box;
    padding: 10px 12px; border-radius: 12px;
    border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.12));
    background: rgba(0, 0, 0, 0.28); color: #fff; font-size: 0.85rem;
}
.radar-loc-input::placeholder { color: var(--text-muted, #9aa0b5); }
.radar-addr-suggest {
    position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 5;
    max-height: 180px; overflow-y: auto;
    background: var(--panel-solid, rgba(15, 12, 41, 0.96));
    border: 1px solid var(--glass-border); border-radius: 12px;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
}
.radar-addr-suggest[hidden] { display: none; }
.radar-addr-item {
    display: block; width: 100%; text-align: left;
    border: none; background: transparent; color: #fff;
    padding: 10px 12px; font-size: 0.78rem; line-height: 1.3; cursor: pointer;
}
.radar-addr-item:hover,
.radar-addr-item:focus { background: rgba(255, 255, 255, 0.08); }
.radar-coords-row {
    display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: center;
}
.radar-panel-status {
    font-size: 0.75rem; color: var(--text-muted, #9aa0b5);
}
.radar-panel-status[hidden] { display: none; }
.radar-pills {
    display: flex; gap: 8px; padding: 12px 14px 8px;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    flex-shrink: 0; scrollbar-width: none;
}
.radar-pills::-webkit-scrollbar { display: none; }
.radar-pill {
    flex: 0 0 auto; border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.06); color: #fff;
    border-radius: 14px; padding: 8px 12px; cursor: pointer;
    display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
    transition: var(--transition, 0.2s ease);
}
.radar-pill-label { font-size: 0.82rem; font-weight: 600; white-space: nowrap; }
.radar-pill-km { font-size: 0.68rem; color: var(--text-muted, #9aa0b5); white-space: nowrap; }
.radar-pill.active {
    border-color: rgba(var(--accent-rgb, 123, 97, 255), 0.7);
    background: rgba(var(--accent-rgb, 123, 97, 255), 0.22);
    box-shadow: 0 0 12px rgba(var(--accent-rgb, 123, 97, 255), 0.25);
}
.radar-status {
    padding: 4px 16px 8px; font-size: 0.82rem;
    color: var(--text-muted, #9aa0b5); text-align: center; flex-shrink: 0;
}
.radar-status[hidden] { display: none; }
.radar-stage {
    flex: 1 1 auto; min-height: 180px; display: flex; align-items: center; justify-content: center;
    padding: 8px 16px 12px;
}
.radar-disc {
    position: relative; width: min(86vw, 420px); aspect-ratio: 1;
    border-radius: 50%;
    background:
        radial-gradient(circle at center, rgba(var(--accent-rgb, 123, 97, 255), 0.18), transparent 55%),
        rgba(0, 0, 0, 0.28);
    border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.35);
    transition: transform 0.12s linear;
    will-change: transform;
}
.radar-ring {
    position: absolute; inset: 0; margin: auto; border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.1); pointer-events: none;
}
.radar-ring-1 { width: 33%; height: 33%; }
.radar-ring-2 { width: 66%; height: 66%; }
.radar-ring-3 { width: 96%; height: 96%; }
.radar-cross {
    position: absolute; background: rgba(255, 255, 255, 0.08); pointer-events: none;
}
.radar-cross-h { left: 8%; right: 8%; top: 50%; height: 1px; }
.radar-cross-v { top: 8%; bottom: 8%; left: 50%; width: 1px; }
.radar-north {
    position: absolute; top: 6px; left: 50%; transform: translateX(-50%);
    font-size: 0.75rem; font-weight: 700; color: #ff6b6b; letter-spacing: 0.05em;
    pointer-events: none;
}
.radar-self {
    position: absolute; left: 50%; top: 50%; width: 14px; height: 14px;
    margin: -7px 0 0 -7px; border-radius: 50%;
    background: var(--online, #2dff9a);
    box-shadow: 0 0 0 4px rgba(45, 255, 154, 0.25);
    z-index: 2;
}
.radar-peers { position: absolute; inset: 0; }
.radar-peer {
    position: absolute; transform: translate(-50%, -50%);
    border: none; background: transparent; padding: 0; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    z-index: 3; max-width: 88px; color: #fff;
}
.radar-peer-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--accent-gradient, linear-gradient(135deg, #667eea, #764ba2));
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem;
    border: 2px solid rgba(255, 255, 255, 0.35);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
.radar-peer-label {
    transform: rotate(var(--radar-counter, 0deg));
    text-align: center; line-height: 1.15;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
}
.radar-peer-name {
    font-size: 0.68rem; font-weight: 600; color: #fff;
    max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.radar-peer-dist {
    font-size: 0.62rem; color: var(--text-muted, #c5c9d8);
}
.radar-peer-avatar.offline,
.radar-list-avatar.offline { opacity: 0.55; }
.radar-list {
    flex-shrink: 0; max-height: 32vh; overflow-y: auto;
    padding: 0 14px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--glass-border, rgba(255, 255, 255, 0.08));
}
.radar-list:empty { display: none; }
.radar-list-title {
    padding: 10px 4px 6px; font-size: 0.72rem; text-transform: uppercase;
    letter-spacing: 1px; color: var(--text-muted, #9aa0b5);
}
.radar-list-item {
    width: 100%; display: flex; align-items: center; gap: 12px;
    padding: 10px 8px; border: none; border-radius: 12px;
    background: transparent; color: #fff; cursor: pointer; text-align: left;
}
.radar-list-item:hover,
.radar-list-item:active { background: rgba(255, 255, 255, 0.06); }
.radar-list-avatar {
    width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
    background: var(--accent-gradient, linear-gradient(135deg, #667eea, #764ba2));
    display: flex; align-items: center; justify-content: center; font-size: 1.2rem;
}
.radar-list-meta { min-width: 0; flex: 1; }
.radar-list-name {
    font-size: 0.92rem; font-weight: 600;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.radar-list-sub { font-size: 0.75rem; color: var(--text-muted, #9aa0b5); }

/* --- мобильная версия --- */
@media (max-width: 768px) {
    :root { --header-h: 60px; }
    /* Не центрировать shell: при клавиатуре vv сжимает --app-height и flex
       иначе «подпрыгивает» UI вверх/вниз. Pin к visualViewport (--vv-top). */
    body {
        overflow: hidden;
        align-items: stretch;
        justify-content: flex-start;
    }
    .app-container {
        position: fixed;
        left: 0;
        right: 0;
        top: var(--vv-top, 0px);
        width: 100%;
        height: 100vh;
        height: var(--app-height, 100dvh);
        max-width: 100%;
        border-radius: 0; border: none;
    }
    .sidebar { width: 100%; height: 100%; min-height: 0; border-right: none; }
    .chat-area { height: 100%; min-height: 0; }
    .my-profile { padding: 0 16px; }
    .chat-area { display: none; }
    .app-container.chat-open .sidebar { display: none; }
    .app-container.chat-open .chat-area { display: flex; }
    .back-btn { display: flex; }
    .chat-header { padding: 0 14px; gap: 8px; }
    .chat-header .profile-info { flex: 1; min-width: 0; }
    .peer-wrap { min-width: 0; }
    .messages-box { padding: 16px 12px; gap: 10px; }
    .message { max-width: 85%; padding: 10px 14px; }
    .msg-del-btn, .msg-more-btn { opacity: 0.85; }
    .msg-action-reacts { justify-content: center; }
    .chat-input-area {
        padding: 12px 14px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
        min-width: 0; max-width: 100%;
        flex-wrap: wrap;
        gap: 8px;
    }
    .chat-input-area input,
    .chat-input-area textarea.message-input { padding: 12px 14px; min-width: 0; flex: 1 1 0; }
    .send-btn { height: 46px; padding: 0 14px; font-size: 0.9rem; }
    .attach-btn { width: 38px; height: 38px; flex-shrink: 0; }
    .attach-preview { max-width: min(120px, 26vw); }
    .msg-file { min-width: 150px; }
    .msg-file-name { max-width: 140px; }
    .msg-image { max-height: 240px; }
    .typing-indicator { padding: 0 14px 6px; }
    .call-modal {
        overflow-y: auto;
        padding: 16px 12px calc(16px + env(safe-area-inset-bottom));
    }
    .call-controls { flex-shrink: 0; }
    .videos-grid { gap: 10px; padding: 0 10px; }
    video { width: min(92vw, 340px); height: 30vh; }
    .call-avatar { width: 84px; height: 84px; font-size: 2.6rem; }
    .profile-card { width: 94vw; max-width: 360px; padding: 1.6rem 1.35rem 1.15rem; }
    .profile-avatar { width: 110px; height: 110px; font-size: 3.4rem; }
    .auth-card {
        width: min(94vw, 400px);
        padding: 1.5rem 1.25rem 1.25rem;
    }
    .auth-card h2 { font-size: 1.55rem; }
}
@media (min-width: 769px) {
    .back-btn { display: none; }
    .radar-overlay .back-btn { display: flex !important; }
    /* Радар в том же «окне», что и чат — не на весь монитор. */
    .radar-overlay {
        inset: auto;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 95vw;
        max-width: 1200px;
        height: 90vh;
        border-radius: 28px;
        border: 1px solid var(--glass-border);
        box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6);
        padding-top: 0;
        padding-bottom: 0;
        overflow: hidden;
    }
}

/* Катана-wipe: переход мессенджер ↔ /admin (см. katana-nav.js) */
.apex-katana {
  position: fixed;
  inset: 0;
  z-index: 100000;
  pointer-events: none;
  opacity: 0;
}
.apex-katana.is-on {
  pointer-events: all;
  opacity: 1;
}
.apex-katana-blade {
  position: absolute;
  inset: -20%;
  background:
    linear-gradient(
      118deg,
      transparent 42%,
      rgba(255, 255, 255, 0.55) 49.5%,
      rgba(180, 210, 255, 0.35) 50.5%,
      transparent 58%
    ),
    linear-gradient(135deg, #0a0618 0%, #1a1240 45%, #2a1f5c 100%);
  clip-path: polygon(0 0, 0 0, 0 100%, 0 100%);
  transform: skewX(-8deg);
}
.apex-katana.is-on .apex-katana-blade {
  animation: apex-katana-slash 0.52s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}
@keyframes apex-katana-slash {
  0% { clip-path: polygon(0 0, 0 0, 0 100%, 0 100%); }
  35% { clip-path: polygon(0 0, 18% 0, 0 100%, 0 100%); }
  100% { clip-path: polygon(0 0, 110% 0, 110% 100%, 0 100%); }
}
@media (prefers-reduced-motion: reduce) {
  .apex-katana.is-on .apex-katana-blade {
    animation: none;
    clip-path: none;
  }
}

/* --- установленное PWA (standalone) --- */
@media (display-mode: standalone) {
    body {
        height: 100dvh;
        align-items: stretch;
        justify-content: flex-start;
        padding:
            env(safe-area-inset-top)
            env(safe-area-inset-right)
            env(safe-area-inset-bottom)
            env(safe-area-inset-left);
    }
    .app-container {
        position: fixed;
        left: 0;
        right: 0;
        top: var(--vv-top, 0px);
        width: 100%;
        max-width: none;
        height: var(--app-height, 100%);
        max-height: var(--app-height, 100%);
        border-radius: 0;
        border: none;
        box-shadow: none;
    }
    /* body уже даёт safe-area — не дублируем у инпута/списка радара */
    .chat-input-area { padding-bottom: 12px; }
    .radar-list { padding-bottom: 12px; }
    .pwa-hint {
        bottom: calc(28px + env(safe-area-inset-bottom));
    }
}

.auth-forgot-btn {
    display: block; width: 100%; margin: -4px 0 10px;
    border: none; background: transparent; color: var(--accent-soft);
    font: inherit; font-size: 0.82rem; cursor: pointer; text-align: center;
}
.auth-forgot-btn:hover { text-decoration: underline; }
.auth-forgot-btn[hidden] { display: none !important; }

.message-input {
    flex: 1; min-width: 0; resize: none; max-height: 140px;
    padding: 10px 14px; border-radius: 12px;
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.06); color: var(--text-main);
    font: inherit; font-size: 0.95rem; line-height: 1.35;
    outline: none; overflow-y: auto;
}


.msg-more-btn { opacity: 0.35; }
.message:hover .msg-more-btn { opacity: 0.85; }

.msg-forwarded {
    font-size: 0.72rem; color: var(--accent-soft);
    margin-bottom: 4px; opacity: 0.9;
}

.forward-overlay {
    position: fixed; inset: 0; z-index: 160;
    background: var(--overlay-bg); backdrop-filter: blur(10px);
    display: flex; align-items: center; justify-content: center;
}
.forward-overlay[hidden] { display: none !important; }
.forward-card {
    position: relative; width: min(92vw, 380px); max-height: min(70vh, 520px);
    background: var(--panel-solid); border: 1px solid var(--glass-border);
    border-radius: 20px; padding: 1.25rem 1rem 1rem; overflow: hidden;
    display: flex; flex-direction: column; gap: 10px;
}
.forward-close { position: absolute; top: 10px; right: 10px; }
.forward-title { font-weight: 700; font-size: 1.05rem; padding-right: 36px; }
.forward-list { overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.forward-peer {
    text-align: left; border: 1px solid var(--glass-border); border-radius: 12px;
    background: rgba(255,255,255,0.04); color: var(--text-main);
    padding: 10px 12px; font: inherit; cursor: pointer;
}
.forward-peer:hover { background: var(--select-accent-bg); border-color: var(--select-accent); }
.forward-empty { color: var(--text-muted); font-size: 0.85rem; padding: 12px; }

.profile-blocked-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.profile-blocked-row {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.profile-blocked-name { font-size: 0.9rem; text-align: left; min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat-search-filters {
    display: flex; gap: 6px; flex-wrap: wrap;
    padding: 8px 12px; border-bottom: 1px solid var(--glass-border);
}
.chat-search-filters[hidden] { display: none !important; }
.chat-search-filter {
    border: 1px solid var(--glass-border); background: rgba(255,255,255,0.04);
    color: var(--text-muted); border-radius: 999px; padding: 5px 12px;
    font: inherit; font-size: 0.78rem; cursor: pointer;
}
.chat-search-filter.active {
    color: var(--text-main); border-color: var(--accent-soft);
    background: color-mix(in srgb, var(--accent-soft) 18%, transparent);
}
.chat-search-hits.is-gallery {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 3px; padding: 6px; max-height: 42vh; overflow-y: auto;
}
.chat-media-thumb {
    position: relative; border: none; padding: 0; aspect-ratio: 1;
    overflow: hidden; cursor: pointer; background: rgba(0,0,0,0.25);
}
.chat-media-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.chat-media-date {
    position: absolute; left: 4px; bottom: 4px; font-size: 0.62rem;
    color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}
.chat-search-more {
    grid-column: 1 / -1; margin: 6px; border: 1px solid var(--glass-border);
    background: transparent; color: var(--accent-soft); border-radius: 10px;
    padding: 8px; font: inherit; cursor: pointer;
}
.apex-lightbox-chat {
    bottom: calc(56px + env(safe-area-inset-bottom)); right: 68px;
}
