:root {
    --primary: #7c5cfc;
    --primary-hover: #6a48e0;
    --primary-light: #f3f0ff;
    --primary-alpha: rgba(124, 92, 252, 0.08);
    --bg: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --bg-hover: #f1f5f9;
    --bg-active: #ede9fe;
    --text: #0f172a;
    --text-secondary: #64748b;
    --text-tertiary: #94a3b8;
    --border: #e2e8f0;
    --bubble-sent: #7c5cfc;
    --bubble-received: #f1f5f9;
    --danger: #ef4444;
    --success: #22c55e;
    --shadow-xl: 0 25px 35px -5px rgba(0, 0, 0, 0.15);
    --radius-xs: 6px;
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 18px;
    --radius-2xl: 28px;
    --radius-full: 9999px;
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --sidebar-width: 400px;
    --right-panel-width: 380px;
    --header-height: 64px;
    --backdrop-color: rgba(15, 23, 42, 0.45);
    --modal-bg: #ffffff;
    --input-bg: #f8fafc;
    --avatar-gradient: linear-gradient(135deg, #ddd6fe, #c4b5fd);
    --avatar-color: #5b21b6;
}

body.dark {
    --primary: #8b74f7;
    --primary-hover: #9d88fa;
    --primary-light: #2d2440;
    --primary-alpha: rgba(139, 116, 247, 0.15);
    --bg: #1a1b2e;
    --bg-secondary: #212337;
    --bg-tertiary: #282b40;
    --bg-hover: #282b40;
    --bg-active: #2d2440;
    --text: #e8e9f0;
    --text-secondary: #a0a3b8;
    --text-tertiary: #6b6f85;
    --border: #2e3148;
    --bubble-sent: #8b74f7;
    --bubble-received: #282b40;
    --backdrop-color: rgba(0, 0, 0, 0.6);
    --modal-bg: #212337;
    --input-bg: #282b40;
    --avatar-gradient: linear-gradient(135deg, #3d3058, #4a3870);
    --avatar-color: #b9a0f0;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; background: #e8ecf1; }
body.dark { background: #0f1119; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', system-ui, sans-serif;
    color: var(--text); -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent; user-select: none;
    display: flex; justify-content: center; align-items: center; transition: background 0.3s;
}
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
body.dark ::-webkit-scrollbar-thumb { background: #3d4055; }

/* Уведомления */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 14px 20px; border-radius: var(--radius-md); color: #fff; font-size: 14px; font-weight: 500; box-shadow: 0 10px 30px rgba(0,0,0,0.2); animation: toastIn 0.3s ease; max-width: 360px; cursor: pointer; transition: 0.2s; }
.toast.error { background: #ef4444; } .toast.success { background: #22c55e; } .toast.info { background: #3b82f6; }
@keyframes toastIn { from { opacity: 0; transform: translateX(50px); } to { opacity: 1; transform: translateX(0); } }

/* Авторизация */
.auth-screen { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: var(--bg); z-index: 100; display: flex; align-items: center; justify-content: center; transition: opacity 0.3s, background 0.3s; }
.auth-card { background: var(--modal-bg); border-radius: var(--radius-2xl); padding: 36px 28px; width: 90%; max-width: 400px; box-shadow: var(--shadow-xl); text-align: center; transition: background 0.3s; }
.auth-card h2 { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.auth-card p { color: var(--text-secondary); font-size: 14px; margin-bottom: 24px; }
.auth-tabs { display: flex; margin-bottom: 20px; border-radius: var(--radius-md); overflow: hidden; border: 1px solid var(--border); }
.auth-tab { flex: 1; padding: 10px; cursor: pointer; font-weight: 600; font-size: 14px; border: none; background: transparent; color: var(--text-secondary); font-family: inherit; transition: 0.2s; }
.auth-tab.active { background: var(--primary); color: #fff; }
.auth-input { width: 100%; padding: 12px 16px; border-radius: var(--radius-md); border: 1px solid var(--border); font-size: 15px; outline: none; margin-bottom: 10px; font-family: inherit; color: var(--text); background: var(--input-bg); transition: 0.2s; }
.auth-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-alpha); }
.auth-submit { width: 100%; padding: 13px; border-radius: var(--radius-md); background: var(--primary); color: #fff; font-weight: 600; font-size: 16px; border: none; cursor: pointer; margin-top: 12px; font-family: inherit; transition: 0.2s; }
.auth-submit:hover { background: var(--primary-hover); } .auth-submit:disabled { opacity: 0.5; cursor: not-allowed; }
.auth-error { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 20px; }
.auth-info { font-size: 12px; color: var(--text-tertiary); margin-top: 16px; line-height: 1.5; }

/* Мессенджер */
.messenger { width: 100vw; height: 100vh; display: flex; background: var(--bg); overflow: hidden; position: relative; transition: background 0.3s; }

/* Сайдбар */
.sidebar { width: 100%; height: 100%; flex-shrink: 0; display: flex; flex-direction: column; background: var(--bg); border-right: 1px solid var(--border); z-index: 5; transition: transform 0.25s, background 0.3s; }
@media (min-width: 768px) { .sidebar { width: var(--sidebar-width); min-width: var(--sidebar-width); } }
@media (max-width: 767px) { .sidebar.hidden-mobile { transform: translateX(-100%); } }
.sidebar-header { height: var(--header-height); padding: 0 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.sidebar-title { font-size: 23px; font-weight: 750; letter-spacing: -0.4px; }
.sidebar-actions { display: flex; gap: 6px; }

/* Кнопки с иконками */
.icon-btn { width: 38px; height: 38px; border-radius: var(--radius-full); border: none; background: transparent; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: 0.15s; color: var(--text-secondary); }
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn:active { transform: scale(0.93); }

/* Поиск */
.search-wrapper { padding: 12px 16px; position: relative; flex-shrink: 0; }
.search-input { width: 100%; padding: 11px 14px 11px 42px; border-radius: var(--radius-full); border: 1px solid var(--border); background: var(--bg-secondary); font-size: 14px; outline: none; color: var(--text); font-family: inherit; transition: 0.2s; }
.search-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-alpha); }
.search-icon { position: absolute; left: 28px; top: 50%; transform: translateY(-50%); color: var(--text-tertiary); pointer-events: none; z-index: 1; }

/* Список диалогов */
.dialog-list { flex: 1; overflow-y: auto; }
.dialog-item { display: flex; align-items: center; gap: 12px; padding: 11px 16px; cursor: pointer; transition: 0.15s; margin: 2px 10px; border-radius: var(--radius-lg); }
.dialog-item:hover { background: var(--bg-hover); }
.dialog-item.active { background: var(--bg-active); }
.dialog-avatar { width: 50px; height: 50px; border-radius: var(--radius-full); flex-shrink: 0; background: var(--avatar-gradient); display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--avatar-color); font-size: 16px; position: relative; overflow: hidden; }
.dialog-avatar img { width: 100%; height: 100%; object-fit: cover; }
.online-dot { position: absolute; bottom: 2px; right: 2px; width: 12px; height: 12px; background: var(--success); border-radius: 50%; border: 2.5px solid var(--bg); }
.dialog-item.active .online-dot { border-color: var(--bg-active); }
.dialog-content { flex: 1; min-width: 0; }
.dialog-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 3px; }
.dialog-name { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dialog-time { font-size: 11px; color: var(--text-tertiary); flex-shrink: 0; margin-left: 8px; }
.dialog-bottom { display: flex; justify-content: space-between; align-items: center; }
.dialog-preview { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dialog-badge { background: var(--primary); color: #fff; font-size: 10px; font-weight: 700; min-width: 20px; height: 20px; border-radius: var(--radius-full); display: inline-flex; align-items: center; justify-content: center; padding: 0 5px; flex-shrink: 0; margin-left: 8px; }

/* Область чата */
.chat-area { flex: 1; display: flex; flex-direction: column; background: var(--bg); min-width: 0; height: 100%; transition: background 0.3s; }
@media (max-width: 767px) { .chat-area { position: fixed; top: 0; left: 0; right: 0; bottom: 0; transform: translateX(100%); z-index: 10; transition: transform 0.25s; } .chat-area.active { transform: translateX(0); } }
.chat-header { height: var(--header-height); display: flex; align-items: center; padding: 0 18px; border-bottom: 1px solid var(--border); gap: 12px; flex-shrink: 0; background: var(--bg); }
.back-btn-mobile { display: none; } @media (max-width: 767px) { .back-btn-mobile { display: flex; } }
.chat-avatar { width: 42px; height: 42px; border-radius: var(--radius-full); flex-shrink: 0; background: var(--avatar-gradient); display: flex; align-items: center; justify-content: center; font-weight: 600; color: var(--avatar-color); font-size: 15px; cursor: pointer; overflow: hidden; position: relative; }
.chat-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-avatar .avatar-upload-overlay { position: absolute; bottom: -2px; right: -2px; width: 22px; height: 22px; background: var(--primary); border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 10px; cursor: pointer; opacity: 0; transition: 0.2s; }
.chat-avatar:hover .avatar-upload-overlay { opacity: 1; }
.chat-header-info { flex: 1; min-width: 0; cursor: pointer; }
.chat-header-name { font-weight: 650; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-header-status { font-size: 12px; color: var(--text-secondary); }

/* Сообщения */
.messages-viewport { flex: 1; overflow-y: auto; position: relative; background: var(--bg); }
.messages-list { min-height: 100%; padding: 20px 18px; display: flex; flex-direction: column; justify-content: flex-end; gap: 5px; }
.message-row { display: flex; max-width: 72%; animation: msgIn 0.25s ease-out; }
.message-row.sent { align-self: flex-end; }
.message-row.received { align-self: flex-start; align-items: flex-end; gap: 8px; }
@keyframes msgIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.msg-avatar-small { width: 28px; height: 28px; border-radius: var(--radius-full); flex-shrink: 0; background: var(--avatar-gradient); display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--avatar-color); font-size: 10px; overflow: hidden; }
.msg-avatar-small img { width: 100%; height: 100%; object-fit: cover; }
.bubble { padding: 10px 15px; border-radius: var(--radius-lg); font-size: 14.5px; line-height: 1.55; word-break: break-word; }
.bubble span { white-space: pre-wrap; word-wrap: break-word; }
.message-row.sent .bubble { background: var(--bubble-sent); color: #fff; border-bottom-right-radius: var(--radius-xs); }
.message-row.received .bubble { background: var(--bubble-received); color: var(--text); border-bottom-left-radius: var(--radius-xs); }
.bubble-sender { font-size: 11px; font-weight: 700; color: var(--primary); margin-bottom: 3px; }
.bubble-meta { font-size: 10.5px; margin-top: 5px; text-align: right; opacity: 0.75; display: flex; align-items: center; justify-content: flex-end; gap: 3px; }
.message-row.sent .bubble-meta { color: rgba(255,255,255,0.7); }
.message-row.received .bubble-meta { color: var(--text-tertiary); }

/* Медиа в сообщениях */
.file-message { max-width: 250px; cursor: pointer; border-radius: var(--radius-md); overflow: hidden; padding: 0 !important; background: transparent !important; position: relative; }
.file-message img { width: 100%; height: auto; display: block; border-radius: var(--radius-md); }
.file-message .file-time { position: absolute; bottom: 4px; right: 6px; color: #fff; font-size: 10px; text-shadow: 0 0 3px rgba(0,0,0,0.5); background: rgba(0,0,0,0.4); padding: 2px 6px; border-radius: 10px; }
.audio-message { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--bubble-received); border-radius: var(--radius-lg); min-width: 200px; }
.audio-play-btn { width: 36px; height: 36px; border-radius: 50%; border: none; background: var(--primary); color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0; }
.audio-waveform { flex: 1; height: 36px; background: var(--bg-tertiary); border-radius: 4px; position: relative; overflow: hidden; }
.audio-progress { height: 100%; background: var(--primary); width: 0%; transition: width 0.1s linear; }
.audio-duration { font-size: 11px; color: var(--text-secondary); flex-shrink: 0; }

/* Пустой чат */
.empty-chat { height: 100%; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 10px; color: var(--text-tertiary); }

/* Поле ввода */
.input-bar { display: flex; align-items: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); background: var(--bg); flex-shrink: 0; }
.msg-input { flex: 1; border: 1px solid var(--border); border-radius: var(--radius-full); padding: 11px 18px; font-size: 14px; outline: none; resize: none; max-height: 110px; background: var(--bg-secondary); font-family: inherit; color: var(--text); line-height: 1.5; min-height: 44px; transition: 0.2s; }
.msg-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-alpha); }
.send-btn { width: 44px; height: 44px; border-radius: var(--radius-full); border: none; background: var(--primary); cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: 0.15s; color: #fff; }
.send-btn:hover { background: var(--primary-hover); transform: scale(1.04); }
.send-btn:disabled { opacity: 0.35; pointer-events: none; background: #cbd5e1; }

/* Меню вложений */
.attach-menu { position: absolute; bottom: 70px; left: 16px; background: var(--modal-bg); border-radius: var(--radius-lg); box-shadow: var(--shadow-xl); z-index: 20; display: none; flex-direction: column; padding: 8px; min-width: 200px; border: 1px solid var(--border); }
.attach-menu.active { display: flex; }
.attach-menu-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; cursor: pointer; border-radius: var(--radius-md); font-size: 14px; font-weight: 500; color: var(--text); transition: 0.15s; border: none; background: transparent; font-family: inherit; width: 100%; text-align: left; }
.attach-menu-item:hover { background: var(--bg-hover); }

/* Правые панели */
.right-panel { position: fixed; top: 0; right: 0; width: 100%; max-width: var(--right-panel-width); height: 100vh; background: var(--bg); z-index: 40; transform: translateX(100%); transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), background 0.3s; box-shadow: var(--shadow-xl); display: flex; flex-direction: column; border-left: 1px solid var(--border); }
.right-panel.active { transform: translateX(0); }
.right-panel-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.right-panel-title { font-weight: 700; font-size: 17px; }
.right-panel-body { flex: 1; overflow-y: auto; padding: 24px 20px; display: flex; flex-direction: column; gap: 16px; }
.backdrop { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: var(--backdrop-color); z-index: 35; opacity: 0; visibility: hidden; transition: opacity 0.3s, visibility 0.3s; backdrop-filter: blur(2px); }
.backdrop.active { opacity: 1; visibility: visible; }

/* Профиль */
.profile-avatar-lg { width: 100px; height: 100px; border-radius: var(--radius-full); background: var(--avatar-gradient); display: flex; align-items: center; justify-content: center; font-size: 38px; font-weight: 700; color: var(--avatar-color); margin: 0 auto; overflow: hidden; position: relative; cursor: pointer; }
.profile-avatar-lg img { width: 100%; height: 100%; object-fit: cover; }
.profile-avatar-lg:hover::after { content: 'Сменить'; position: absolute; bottom: 0; left: 0; right: 0; background: rgba(0,0,0,0.5); color: #fff; font-size: 11px; padding: 4px; text-align: center; }
.profile-name-lg { font-size: 22px; font-weight: 700; text-align: center; }
.profile-phone { color: var(--text-secondary); font-size: 14px; text-align: center; }

/* Участники */
.member-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-md); transition: 0.15s; }
.member-item:hover { background: var(--bg-hover); }
.member-avatar { width: 36px; height: 36px; border-radius: var(--radius-full); background: var(--avatar-gradient); display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--avatar-color); font-size: 13px; overflow: hidden; }
.member-avatar img { width: 100%; height: 100%; object-fit: cover; }
.member-name { flex: 1; font-weight: 500; font-size: 14px; }
.member-remove { color: var(--danger); cursor: pointer; padding: 4px 8px; border-radius: var(--radius-xs); font-size: 12px; font-weight: 600; border: none; background: transparent; font-family: inherit; }
.member-remove:hover { background: rgba(239,68,68,0.1); }
.member-add-row { display: flex; gap: 8px; }
.member-add-input { flex: 1; padding: 8px 12px; border-radius: var(--radius-md); border: 1px solid var(--border); font-size: 13px; outline: none; background: var(--input-bg); color: var(--text); font-family: inherit; }
.member-add-btn { padding: 8px 14px; border-radius: var(--radius-md); border: none; background: var(--primary); color: #fff; cursor: pointer; font-weight: 600; font-size: 13px; font-family: inherit; }
.group-edit-input { padding: 10px 14px; border-radius: var(--radius-md); border: 1px solid var(--border); font-size: 14px; outline: none; background: var(--input-bg); color: var(--text); font-family: inherit; flex: 1; }

/* Кнопки */
.btn { padding: 11px 22px; border-radius: var(--radius-md); font-size: 14px; font-weight: 600; cursor: pointer; border: none; font-family: inherit; transition: 0.15s; }
.btn-primary { background: var(--primary); color: #fff; } .btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--bg-secondary); color: var(--text); border: 1px solid var(--border); } .btn-secondary:hover { background: var(--bg-tertiary); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid rgba(239,68,68,0.3); } .btn-danger:hover { background: rgba(239,68,68,0.08); }
.btn-full { width: 100%; text-align: center; }

/* Модальные окна */
.modal-backdrop { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: var(--backdrop-color); z-index: 50; display: flex; align-items: center; justify-content: center; opacity: 0; visibility: hidden; transition: opacity 0.25s, visibility 0.25s; backdrop-filter: blur(3px); padding: 20px; }
.modal-backdrop.active { opacity: 1; visibility: visible; }
.modal { background: var(--modal-bg); border-radius: var(--radius-2xl); padding: 28px 24px 24px; width: 100%; max-width: 440px; box-shadow: var(--shadow-xl); transform: translateY(20px) scale(0.96); transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.3s; max-height: 80vh; overflow-y: auto; }
.modal-backdrop.active .modal { transform: translateY(0) scale(1); }
.modal-title { font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.modal-subtitle { font-size: 13px; color: var(--text-secondary); margin-bottom: 20px; }
.modal-input { width: 100%; padding: 12px 16px; border-radius: var(--radius-md); border: 1px solid var(--border); font-size: 14px; outline: none; margin-bottom: 12px; font-family: inherit; color: var(--text); background: var(--input-bg); transition: 0.2s; }
.modal-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-alpha); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }

/* Поиск пользователей */
.user-search-results { max-height: 250px; overflow-y: auto; margin-bottom: 10px; border: 1px solid var(--border); border-radius: var(--radius-md); }
.user-search-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; cursor: pointer; transition: 0.15s; border-bottom: 1px solid var(--border); }
.user-search-item:last-child { border-bottom: none; }
.user-search-item:hover { background: var(--bg-hover); }
.user-search-item.selected { background: var(--bg-active); }
.user-search-avatar { width: 40px; height: 40px; border-radius: var(--radius-full); flex-shrink: 0; background: var(--avatar-gradient); display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--avatar-color); font-size: 14px; overflow: hidden; }
.user-search-avatar img { width: 100%; height: 100%; object-fit: cover; }
.selected-users { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.selected-user-tag { display: flex; align-items: center; gap: 6px; padding: 6px 10px; background: var(--primary-light); border-radius: var(--radius-full); font-size: 13px; font-weight: 500; color: var(--text); }

/* Ссылка-приглашение */
.invite-link-row { display: flex; gap: 8px; align-items: center; padding: 10px 12px; background: var(--bg-secondary); border-radius: var(--radius-md); margin-top: 8px; }
.invite-link-input { flex: 1; border: none; background: transparent; font-size: 13px; color: var(--text); font-family: monospace; outline: none; }
.copy-btn { padding: 6px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg); cursor: pointer; font-size: 12px; font-weight: 600; color: var(--text); font-family: inherit; transition: 0.15s; }
.copy-btn:hover { background: var(--bg-hover); }

.bot-buttons { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 16px; border-top: 1px solid var(--border); }
.bot-btn { padding: 8px 16px; border-radius: 20px; border: 1px solid var(--primary); background: transparent; color: var(--primary); cursor: pointer; font-size: 13px; font-weight: 500; font-family: inherit; transition: 0.15s; }
.bot-btn:hover { background: var(--primary); color: #fff; }
.bot-btn:active { transform: scale(0.95); }

.bot-badge { display: none; }
.bot-badge-text { font-size: 10px; background: var(--primary); color: #fff; padding: 2px 6px; border-radius: 4px; font-weight: 600; margin-left: 4px; }

/* Загрузка изображений */
.image-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100px;
    background: var(--bg-secondary);
    border-radius: 12px;
    animation: pulse 1.5s ease-in-out infinite;
}
.image-loading::after {
    content: '';
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 0.6; } 50% { opacity: 1; } }

/* Просмотрщик изображений */
.image-viewer-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    animation: fadeIn 0.2s ease;
}
.image-viewer-overlay img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.image-viewer-close {
    position: absolute;
    top: 20px; right: 20px;
    width: 40px; height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.image-viewer-close:hover { background: rgba(255, 255, 255, 0.2); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Сообщения с файлами */
.file-message { cursor: pointer; position: relative; }
.file-message img { max-width: 250px; max-height: 250px; border-radius: 12px; display: block; opacity: 0; transition: opacity 0.3s ease; }
.file-message img.loaded { opacity: 1; }

/* Аватарки с лоадером */
.avatar-loading { position: relative; overflow: hidden; }
.avatar-loading::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--avatar-gradient);
    z-index: 1;
}
.avatar-loading::after {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    width: 20px; height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid var(--bg-tertiary);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: avatar-spin 0.6s linear infinite;
    z-index: 2;
}
.avatar-loading img { opacity: 0; transition: opacity 0.3s; position: relative; z-index: 3; }
.avatar-loading img.loaded { opacity: 1; }
@keyframes avatar-spin { to { transform: rotate(360deg); } }

/* Ответ на сообщение */
.reply-preview {
    background: var(--bg-tertiary);
    border-left: 3px solid var(--primary);
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 6px;
    cursor: pointer;
    transition: background 0.15s;
}
.reply-preview:hover { background: var(--bg-hover); }
.reply-preview-header {
    font-size: 11px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 2px;
}
.reply-preview-text {
    font-size: 12px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 250px;
}

/* Метка пересылки */
.forward-label {
    font-size: 11px;
    color: var(--primary);
    margin-bottom: 2px;
    font-weight: 500;
    padding-left: 4px;
    opacity: 0.8;
}

/* Выделенные сообщения */
.message-row.message-selected .bubble {
    box-shadow: 0 0 0 2px var(--primary);
}
.message-row.message-selected { opacity: 0.95; }

/* Панель режима выделения */
#selectModeBar {
    animation: slideDown 0.2s ease;
}
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Упоминания */
.user-mention {
    color: #7c5cfc !important;
    cursor: pointer;
    font-weight: 600;
    background: rgba(124, 92, 252, 0.1);
    padding: 1px 4px;
    border-radius: 4px;
    transition: background 0.15s;
    opacity: 1 !important;
    display: inline-block;
}
.user-mention:hover { background: #7c5cfc; color: #ffffff !important; }

/* Команды */
.chat-command {
    color: #6366f1 !important;
    cursor: pointer;
    font-weight: 500;
    border-bottom: 1.5px dashed #6366f1;
    transition: all 0.15s;
    opacity: 1 !important;
    display: inline-block;
}
.chat-command:hover {
    color: #4f46e5 !important;
    border-bottom-style: solid;
    background: rgba(99, 102, 241, 0.08);
    border-radius: 3px;
    padding: 0 2px;
}

/* Тёмная тема для упоминаний и команд */
body.dark .user-mention { color: #8b74f7 !important; background: rgba(139, 116, 247, 0.15); }
body.dark .user-mention:hover { background: #8b74f7; color: #ffffff !important; }
body.dark .chat-command { color: #818cf8 !important; border-bottom-color: #818cf8; }
body.dark .chat-command:hover { color: #a5b4fc !important; background: rgba(129, 140, 248, 0.15); }

/* Отправленные сообщения с упоминаниями */
.message-row.sent .bubble .user-mention {
    color: #ffffff !important;
    background: rgba(255, 255, 255, 0.2);
}
.message-row.sent .bubble .user-mention:hover { background: #ffffff; color: #7c5cfc !important; }
.message-row.sent .bubble .chat-command { color: #ffffff !important; border-bottom-color: rgba(255, 255, 255, 0.6); }
.message-row.sent .bubble .chat-command:hover { color: #ffffff !important; background: rgba(255, 255, 255, 0.15); }



.message-selected .bubble {
    outline: 2px solid var(--primary) !important;
    outline-offset: 2px !important;
}
body.dark .message-row.sent.message-selected .bubble {
    outline-color: #fff !important;
}