/* ============================================================
   ЧАТ — Telegram-like, взрослый дизайн
   ============================================================ */

.im-chat-layout {
    display: flex;
    height: min(780px, calc(100vh - 240px));
    min-height: 0;
    background: #fff;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(15, 23, 42, 0.08);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: #0f172a;
}

/* ============================================================
   ЛЕВАЯ КОЛОНКА
   ============================================================ */
.im-chat-sidebar {
    width: 340px;
    background: #fff;
    border-right: 1px solid #eef1f5;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.im-chat-sidebar-header {
    padding: 1.25rem 1.25rem 1rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.im-chat-sidebar-header h3 {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: #0f172a;
}

.im-chat-new-btn {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: #3b82f6;
    color: #fff;
    border: none;
    font-size: 1.4rem;
    font-weight: 300;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.1s;
    line-height: 1;
    padding: 0 0 2px 0;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.35);
}
.im-chat-new-btn:hover { background: #2563eb; }
.im-chat-new-btn:active { transform: scale(0.94); }

.im-chat-search {
    position: relative;
    padding: 0 1.25rem 0.75rem 1.25rem;
}
.im-chat-search input {
    width: 100%;
    padding: 0.7rem 1rem;
    border: none;
    border-radius: 12px;
    background: #f1f5f9;
    font-size: 0.9rem;
    outline: none;
    box-sizing: border-box;
    transition: background-color 0.15s;
}
.im-chat-search input:focus { background-color: #e2e8f0; }

.im-chat-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 0.25rem 0.5rem 1rem 0.5rem;
}

.im-chat-item {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.75rem 0.75rem;
    cursor: pointer;
    border-radius: 12px;
    transition: background 0.12s;
    margin-bottom: 2px;
}
.im-chat-item:hover { background: #f1f5f9; }
.im-chat-item.active { background: #3b82f6; color: #fff; }
.im-chat-item.active .im-chat-item-name { color: #fff; }
.im-chat-item.active .im-chat-item-time { color: rgba(255,255,255,0.75); }
.im-chat-item.active .im-chat-item-preview { color: rgba(255,255,255,0.8); }
.im-chat-item.active .im-chat-avatar { background: rgba(255,255,255,0.2); }

.im-chat-avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    color: #fff;
    font-size: 1.15rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    text-transform: uppercase;
    letter-spacing: -0.02em;
}
.im-chat-avatar img { width: 100%; height: 100%; object-fit: cover; }

.im-chat-item-body { flex: 1; min-width: 0; }

.im-chat-item-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.2rem;
}

.im-chat-item-name {
    font-weight: 700;
    font-size: 0.98rem;
    color: #0f172a;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    letter-spacing: -0.01em;
}

.im-chat-item-time {
    font-size: 0.75rem;
    color: #94a3b8;
    flex-shrink: 0;
    margin-left: 0.5rem;
    font-weight: 500;
}

.im-chat-item-preview {
    font-size: 0.87rem;
    color: #64748b;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.im-chat-unread {
    background: #3b82f6;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ============================================================
   ПРАВАЯ КОЛОНКА — ПЕРЕПИСКА
   ============================================================ */
.im-chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #f8fafc;
    min-width: 0;
    position: relative;
}

.im-chat-main-header {
    background: #fff;
    padding: 0.75rem 1.25rem;
    display: flex;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 10;
}
/* Скрываем подзаголовок — в шапке только иконка и имя */
.im-chat-main-subtitle { display: none; }
.im-chat-main-header .im-chat-avatar {
    width: 46px;
    height: 46px;
    font-size: 1.05rem;
    flex-shrink: 0;
}
.im-chat-main-title {
    font-weight: 700;
    font-size: 1.02rem;
    color: #0f172a;
    letter-spacing: -0.01em;
}

.im-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 1.75rem 1rem 1.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    background-image:
        radial-gradient(circle at 20% 30%, rgba(59,130,246,0.03) 0%, transparent 40%),
        radial-gradient(circle at 80% 70%, rgba(139,92,246,0.03) 0%, transparent 40%);
}

.im-chat-empty {
    text-align: center;
    color: #94a3b8;
    padding: 4rem 1rem;
    font-size: 0.95rem;
    font-weight: 500;
}

/* === Дата === */
.im-chat-date-sep {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 1.25rem 0 0.75rem 0;
}
.im-chat-date-sep span {
    background: rgba(15, 23, 42, 0.06);
    color: #475569;
    padding: 0.3rem 0.9rem;
    border-radius: 14px;
    font-size: 0.76rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

/* === Сообщение === */
.im-chat-msg {
    max-width: 60%;
    padding: 0.6rem 0.9rem 0.5rem 0.9rem;
    border-radius: 16px;
    word-wrap: break-word;
    position: relative;
    font-size: 0.95rem;
    line-height: 1.45;
    letter-spacing: -0.005em;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    animation: msgIn 0.18s ease-out;
}

@keyframes msgIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.im-chat-msg-in {
    align-self: flex-start;
    background: #fff;
    color: #0f172a;
    border-bottom-left-radius: 5px;
}
.im-chat-msg-out {
    align-self: flex-end;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: #fff;
    border-bottom-right-radius: 5px;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.25);
}

.im-chat-msg-sender {
    font-size: 0.78rem;
    font-weight: 700;
    color: #3b82f6;
    margin-bottom: 0.15rem;
}
.im-chat-msg-out .im-chat-msg-sender { color: rgba(255,255,255,0.95); }

.im-chat-msg-meta {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.7rem;
    margin-left: 0.6rem;
    opacity: 0.75;
    float: right;
    margin-top: 0.35rem;
    font-weight: 500;
}
.im-chat-msg-out .im-chat-msg-meta { color: rgba(255,255,255,0.9); }
.im-chat-msg-in .im-chat-msg-meta { color: #94a3b8; }

/* === Галочки === */
.im-chat-checks {
    display: inline-flex;
    align-items: center;
    margin-left: 0.15rem;
    position: relative;
    min-width: 16px;
    height: 12px;
    vertical-align: middle;
}
.im-chat-checks svg {
    width: 13px;
    height: 13px;
    position: absolute;
    top: -1px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}
.im-chat-checks .check-1 { left: 0; }
.im-chat-checks .check-2 { left: 5px; }
.im-chat-checks.unread .check-1 { color: rgba(255,255,255,0.7); }
.im-chat-checks.read .check-1,
.im-chat-checks.read .check-2 { color: #7dd3fc; }

/* === Reply === */
.im-chat-msg-reply {
    display: block;
    padding: 0.35rem 0.6rem;
    margin: -0.15rem -0.35rem 0.4rem -0.35rem;
    border-left: 3px solid #3b82f6;
    background: rgba(59, 130, 246, 0.08);
    border-radius: 6px;
    font-size: 0.82rem;
    cursor: pointer;
}
.im-chat-msg-out .im-chat-msg-reply {
    border-left-color: rgba(255,255,255,0.8);
    background: rgba(255,255,255,0.15);
}
.im-chat-msg-reply-author { font-weight: 700; display: block; font-size: 0.78rem; margin-bottom: 0.1rem; }
.im-chat-msg-reply-text { opacity: 0.85; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* === Вложения === */
.im-chat-msg img.im-chat-attach-img {
    max-width: 100%;
    max-height: 320px;
    border-radius: 12px;
    display: block;
    margin-top: 0.35rem;
    cursor: pointer;
}
.im-chat-msg video.im-chat-attach-video {
    max-width: 100%;
    max-height: 320px;
    border-radius: 12px;
    display: block;
    margin-top: 0.35rem;
}

.im-chat-attach-file {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.5rem 0.25rem 0.25rem 0.25rem;
    text-decoration: none;
    color: inherit;
}
.im-chat-attach-file-icon {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: rgba(59, 130, 246, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}
.im-chat-msg-out .im-chat-attach-file-icon { background: rgba(255,255,255,0.2); }
.im-chat-attach-file-info { min-width: 0; }
.im-chat-attach-file-name {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.im-chat-attach-file-size { font-size: 0.75rem; opacity: 0.7; }

/* === Голосовое === */
.im-chat-voice {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.3rem 0;
    min-width: 200px;
}
.im-chat-voice-play {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(59, 130, 246, 0.15);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    padding: 0;
    flex-shrink: 0;
    color: #3b82f6;
    transition: background 0.15s;
}
.im-chat-voice-play:hover { background: rgba(59, 130, 246, 0.25); }
.im-chat-msg-out .im-chat-voice-play { background: rgba(255,255,255,0.25); color: #fff; }
.im-chat-msg-out .im-chat-voice-play:hover { background: rgba(255,255,255,0.35); }

.im-chat-voice-wave {
    flex: 1;
    height: 28px;
    position: relative;
}
.im-chat-voice-wave::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 2px;
    background: rgba(59, 130, 246, 0.25);
    transform: translateY(-50%);
    border-radius: 1px;
}
.im-chat-msg-out .im-chat-voice-wave::before { background: rgba(255,255,255,0.4); }

.im-chat-voice-duration {
    font-size: 0.78rem;
    opacity: 0.85;
    flex-shrink: 0;
    font-weight: 600;
}

/* ============================================================
   ПОЛЕ ВВОДА
   ============================================================ */
.im-chat-input-area {
    background: #fff;
    border-top: 1px solid #eef1f5;
    padding: 0.9rem 1.25rem;
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
    position: relative;
}

.im-chat-input-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 1.2rem;
    color: #64748b;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s, transform 0.1s;
    flex-shrink: 0;
    padding: 0;
}
.im-chat-input-btn:hover { background: #f1f5f9; color: #3b82f6; }
.im-chat-input-btn:active { transform: scale(0.92); }

.im-chat-input-area textarea {
    flex: 1;
    resize: none;
    border: none;
    outline: none;
    font-size: 0.95rem;
    font-family: inherit;
    max-height: 120px;
    min-height: 40px;
    padding: 0.65rem 1rem;
    line-height: 1.4;
    box-sizing: border-box;
    background: #f1f5f9;
    border-radius: 20px;
    transition: background 0.15s;
    color: #0f172a;
}
.im-chat-input-area textarea:focus { background: #e2e8f0; }
.im-chat-input-area textarea::placeholder { color: #94a3b8; }

.im-chat-send-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 1.05rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s, box-shadow 0.15s;
    flex-shrink: 0;
    padding: 0;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.35);
}
.im-chat-send-btn:hover { box-shadow: 0 4px 12px rgba(59, 130, 246, 0.5); }
.im-chat-send-btn:active { transform: scale(0.94); }
.im-chat-send-btn:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }

.im-chat-send-btn.recording {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    animation: pulseRec 1.2s infinite;
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
}
.im-chat-send-btn.recording:hover { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }

@keyframes pulseRec {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
    50% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
}

/* ============================================================
   ЭМОДЗИ
   ============================================================ */
.im-chat-emoji-bar {
    position: absolute;
    bottom: 65px;
    left: 1.25rem;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.15), 0 0 0 1px rgba(15, 23, 42, 0.04);
    padding: 0.75rem;
    display: none;
    flex-wrap: wrap;
    gap: 0.15rem;
    max-width: 340px;
    z-index: 100;
}
.im-chat-emoji-bar.open { display: flex; }
.im-chat-emoji-bar button {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1.5rem;
    padding: 0.35rem 0.4rem;
    border-radius: 8px;
    line-height: 1;
    transition: background 0.12s, transform 0.1s;
}
.im-chat-emoji-bar button:hover {
    background: #f1f5f9;
    transform: scale(1.15);
}

/* ============================================================
   МЕНЮ ВЛОЖЕНИЙ
   ============================================================ */
.im-chat-attach-menu {
    position: absolute;
    bottom: 65px;
    left: 1.25rem;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.15), 0 0 0 1px rgba(15, 23, 42, 0.04);
    padding: 0.4rem;
    display: none;
    flex-direction: column;
    min-width: 200px;
    z-index: 100;
}
.im-chat-attach-menu.open { display: flex; }
.im-chat-attach-menu button {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.7rem 0.9rem;
    text-align: left;
    font-size: 0.92rem;
    font-weight: 500;
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: #0f172a;
    transition: background 0.12s;
}
.im-chat-attach-menu button:hover { background: #f1f5f9; }
.im-chat-attach-menu button .icon { font-size: 1.2rem; width: 24px; text-align: center; }

/* ============================================================
   ИНДИКАТОР ЗАПИСИ ГС
   ============================================================ */
.im-chat-recording-indicator {
    position: absolute;
    bottom: 65px;
    left: 1.25rem;
    right: 1.25rem;
    background: #fff;
    border: 1px solid #fecaca;
    border-radius: 14px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.15);
    padding: 0.8rem 1.1rem;
    display: none;
    align-items: center;
    gap: 0.85rem;
    z-index: 100;
}
.im-chat-recording-indicator.active { display: flex; }

.im-chat-rec-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: #ef4444;
    animation: recDot 1s infinite;
    flex-shrink: 0;
}
@keyframes recDot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.85); }
}

.im-chat-rec-text {
    flex: 1;
    font-size: 0.92rem;
    color: #dc2626;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.im-chat-rec-time {
    font-variant-numeric: tabular-nums;
    color: #0f172a;
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: 0.01em;
}

/* ============================================================
   МОДАЛКИ
   ============================================================ */
.im-chat-modal-bg {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    box-sizing: border-box;
    overflow: hidden;
    animation: fadeIn 0.15s;
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.im-chat-modal {
    background: #fff;
    border-radius: 18px;
    padding: 1.5rem;
    width: 100%;
    max-width: 460px;
    min-width: 0;
    box-sizing: border-box;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 64px rgba(15, 23, 42, 0.3);
    animation: modalIn 0.2s;
    overflow: hidden;
}
/* Все дети модалки не должны расширять её */
.im-chat-modal > * { max-width: 100%; box-sizing: border-box; }
@keyframes modalIn {
    from { opacity: 0; transform: scale(0.96) translateY(8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.im-chat-modal h3 {
    margin: 0 0 1.25rem 0;
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: #0f172a;
}

.im-chat-modal input[type="text"] {
    width: 100%;
    padding: 0.8rem 1rem;
    border: 1.5px solid #e2e8f0;
    border-radius: 12px;
    font-size: 0.95rem;
    box-sizing: border-box;
    margin-bottom: 1rem;
    outline: none;
    transition: border-color 0.15s;
    font-family: inherit;
}
.im-chat-modal input[type="text"]:focus { border-color: #3b82f6; }

.im-chat-user-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    max-height: 400px;
    margin: 0 0 1rem 0;
    padding: 0;
}

.im-chat-user-item {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.7rem 0.75rem;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.12s;
    box-sizing: border-box;
    width: 100%;
}
.im-chat-user-item:hover { background: #f1f5f9; }
/* Выбранный участник группы — подсветка держится до создания */
.im-chat-user-item.selected {
    background: #dbeafe;
    box-shadow: inset 0 0 0 2px #3b82f6;
}
.im-chat-user-item.selected:hover { background: #cfe0fd; }
.im-chat-user-item > div:last-child {
    min-width: 0;
    overflow: hidden;
}
.im-chat-user-item > div:last-child > div {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.im-chat-user-item .im-chat-avatar { width: 44px; height: 44px; font-size: 1rem; flex-shrink: 0; }

.im-chat-modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    flex-shrink: 0;
}
/* Панели внутри модалки — flex-колонки, чтобы список скроллился, а кнопки были видны */
.im-chat-modal h3 { flex-shrink: 0; }
#im-direct-panel,
#im-group-panel {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}
#im-group-panel[style*="display:none"],
#im-direct-panel[style*="display:none"] { display: none !important; }
#im-direct-panel > input,
#im-group-panel > input,
#im-group-selected { flex-shrink: 0; }
.im-chat-modal-actions button {
    padding: 0.7rem 1.4rem;
    border-radius: 10px;
    font-size: 0.92rem;
    font-weight: 700;
    cursor: pointer;
    border: none;
    transition: background 0.15s, transform 0.1s;
    letter-spacing: -0.005em;
}
.im-chat-modal-actions button:active { transform: scale(0.97); }
.im-chat-modal-cancel { background: #f1f5f9; color: #475569; }
.im-chat-modal-cancel:hover { background: #e2e8f0; }
.im-chat-modal-confirm { background: #3b82f6; color: #fff; }
.im-chat-modal-confirm:hover { background: #2563eb; }
.im-chat-modal-confirm:disabled { opacity: 0.4; cursor: not-allowed; }

/* ============================================================
   АДАПТИВ
   ============================================================ */
@media (max-width: 768px) {
    /* Только для десктоп-страниц (вне мобильного приложения).
       Правила мобильного приложения — в mobile.css, scoped на .im-mobile. */
    body:not(.im-mobile-body) .im-chat-layout { flex-direction: column; height: auto; }
    body:not(.im-mobile-body) .im-chat-sidebar { width: 100%; max-height: 300px; border-right: none; border-bottom: 1px solid #eef1f5; }
    body:not(.im-mobile-body) .im-chat-main { min-height: 400px; }
    .im-chat-msg { max-width: 85%; }
}

/* Кнопка «назад» к списку чатов (видна только на мобильных) */
.im-chat-back-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 38px; height: 38px;
    border: none; background: none;
    font-size: 1.8rem; line-height: 1;
    color: #334155; cursor: pointer;
    flex-shrink: 0; margin-right: 0.25rem;
    border-radius: 8px;
}
.im-chat-back-btn:hover { background: #f1f5f9; }
@media (max-width: 768px) {
    .im-chat-back-btn { display: inline-flex; }
}

/* === Кнопка скролла вниз === */
.im-chat-scroll-btn {
    position: absolute;
    right: 1.5rem;
    bottom: 5.5rem;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #fff;
    color: #3b82f6;
    border: none;
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(15,23,42,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s, background 0.15s;
    transform: translateY(8px);
    z-index: 50;
}
.im-chat-scroll-btn.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}
.im-chat-scroll-btn:hover {
    background: #3b82f6;
    color: #fff;
}
.im-chat-scroll-btn.pulse {
    animation: scrollPulse 0.6s ease;
}
@keyframes scrollPulse {
    0%   { transform: scale(1) translateY(0); }
    50%  { transform: scale(1.15) translateY(0); }
    100% { transform: scale(1) translateY(0); }
}

/* === Контекстное меню сообщения === */
.im-chat-ctx-menu {
    position: absolute;
    z-index: 9999;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(15,23,42,0.18), 0 0 0 1px rgba(15,23,42,0.05);
    padding: 0.35rem;
    min-width: 200px;
    animation: ctxIn 0.12s ease-out;
}

@keyframes ctxIn {
    from { opacity: 0; transform: scale(0.96); }
    to   { opacity: 1; transform: scale(1); }
}

.im-chat-ctx-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.6rem 0.9rem;
    background: transparent;
    border: none;
    border-radius: 8px;
    font-size: 0.92rem;
    font-weight: 500;
    color: #0f172a;
    cursor: pointer;
    text-align: left;
    transition: background 0.12s;
}
.im-chat-ctx-item:hover { background: #f1f5f9; }
.im-chat-ctx-item.danger { color: #ef4444; }
.im-chat-ctx-item.danger:hover { background: #fef2f2; }
.im-chat-ctx-icon {
    display: inline-flex;
    width: 20px;
    text-align: center;
    font-size: 1.05rem;
}

/* === Toast === */
.im-chat-toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translate(-50%, 20px);
    background: #0f172a;
    color: #fff;
    padding: 0.7rem 1.4rem;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    box-shadow: 0 8px 24px rgba(15,23,42,0.25);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s, transform 0.25s;
    z-index: 99999;
}
.im-chat-toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}
.im-chat-toast.error { background: #ef4444; }

/* === Блок reply над полем ввода === */
.im-chat-reply-box {
    display: flex;
    align-items: stretch;
    background: #f1f5f9;
    border-radius: 10px;
    margin: 0 0 0.5rem 0;
    padding: 0;
    overflow: hidden;
    position: absolute;
    bottom: 100%;
    left: 1rem;
    right: 1rem;
    box-shadow: 0 -2px 8px rgba(15,23,42,0.06);
    animation: replySlide 0.15s ease-out;
    z-index: 20;
}
@keyframes replySlide {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.im-chat-reply-bar {
    width: 3px;
    background: #3b82f6;
    flex-shrink: 0;
}
.im-chat-reply-body {
    flex: 1;
    padding: 0.5rem 0.75rem;
    min-width: 0;
}
.im-chat-reply-author {
    font-size: 0.8rem;
    font-weight: 700;
    color: #3b82f6;
    margin-bottom: 0.1rem;
}
.im-chat-reply-preview {
    font-size: 0.85rem;
    color: #64748b;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.im-chat-reply-close {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1.4rem;
    color: #94a3b8;
    padding: 0 0.75rem;
    line-height: 1;
    transition: color 0.15s;
    flex-shrink: 0;
}
.im-chat-reply-close:hover { color: #ef4444; }

/* === Закреплённое сообщение === */
.im-chat-pinned {
    display: flex;
    align-items: stretch;
    background: #fff;
    border-bottom: 1px solid #eef1f5;
    padding: 0.6rem 1rem;
    gap: 0.75rem;
    position: relative;
}
.im-chat-pinned-bar {
    width: 3px;
    background: #3b82f6;
    flex-shrink: 0;
    border-radius: 2px;
}
.im-chat-pinned-body {
    flex: 1;
    min-width: 0;
}
.im-chat-pinned-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: #3b82f6;
    margin-bottom: 0.15rem;
}
.im-chat-pinned-text {
    font-size: 0.88rem;
    color: #334155;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.im-chat-pinned-close {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1.4rem;
    color: #94a3b8;
    line-height: 1;
    padding: 0 0.4rem;
    align-self: center;
    transition: color 0.15s;
}
.im-chat-pinned-close:hover { color: #ef4444; }

/* === Inline-редактор === */
.im-chat-msg-editor {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 260px;
}
.im-chat-edit-input {
    width: 100%;
    min-height: 60px;
    padding: 0.5rem 0.7rem;
    border: 1px solid rgba(255,255,255,0.4);
    border-radius: 8px;
    background: rgba(255,255,255,0.15);
    color: inherit;
    font-family: inherit;
    font-size: 0.95rem;
    resize: vertical;
    box-sizing: border-box;
    outline: none;
}
.im-chat-msg-in .im-chat-edit-input {
    border-color: #cbd5e1;
    background: #f8fafc;
    color: #0f172a;
}
.im-chat-edit-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}
.im-chat-edit-actions button {
    padding: 0.4rem 0.9rem;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}
.im-chat-edit-cancel {
    background: rgba(255,255,255,0.25);
    color: inherit;
}
.im-chat-msg-in .im-chat-edit-cancel {
    background: #f1f5f9;
    color: #475569;
}
.im-chat-edit-save {
    background: #fff;
    color: #2563eb;
}
.im-chat-msg-in .im-chat-edit-save {
    background: #3b82f6;
    color: #fff;
}

/* === Подсветка сообщения при переходе === */
.im-chat-msg.im-chat-msg-highlight {
    animation: msgHighlight 1s ease-out;
}

@keyframes msgHighlight {
    0%   { box-shadow: 0 0 0 0 rgba(59,130,246,0.7); }
    30%  { box-shadow: 0 0 0 6px rgba(59,130,246,0.45); }
    100% { box-shadow: 0 0 0 0 rgba(59,130,246,0); }
}


/* ============================================================
   ЗАГОЛОВОК ЧАТА — КЛИКАБЕЛЬНЫЙ + МЕНЮ
   ============================================================ */
.im-chat-head-btn {
    display: flex !important;
    align-items: center !important;
    gap: 0.9rem !important;
    background: #eef2f7 !important;
    border: none !important;
    padding: 0.5rem 0.75rem 0.5rem 0.5rem !important;
    cursor: pointer !important;
    text-align: left !important;
    font-family: inherit !important;
    width: 100% !important;
    flex: 1 0 0% !important;
    min-width: 0 !important;
    height: 60px !important;
    max-height: 60px !important;
    box-sizing: border-box !important;
    border-radius: 30px !important;
    transition: background 0.15s !important;
}
.im-chat-head-btn:hover { background: #e4eaf2; }
.im-chat-head-btn .im-chat-main-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.im-chat-head-btn .im-chat-head-text { min-width: 0; flex: 1; }

.im-chat-head-menu {
    position: absolute;
    top: 100%;
    left: 1rem;
    margin-top: 0.4rem;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(15,23,42,0.18), 0 0 0 1px rgba(15,23,42,0.05);
    padding: 0.35rem;
    z-index: 200;
    animation: ctxIn 0.12s ease-out;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.15rem;
    flex-wrap: wrap;
    max-width: calc(100% - 2rem);
}
.im-chat-head-menu button {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.55rem 0.85rem;
    border: none;
    background: none;
    border-radius: 9px;
    font-size: 0.9rem;
    font-weight: 600;
    color: #334155;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    white-space: nowrap;
}
.im-chat-head-menu button:hover { background: #f1f5f9; }
.im-chat-head-menu button .icon { font-size: 1.05rem; line-height: 1; }
.im-chat-head-menu hr { border: none; border-left: 1px solid #eef1f5; margin: 0.15rem 0.25rem; align-self: stretch; }

/* ============================================================
   ПАНЕЛЬ ВЛОЖЕНИЙ (медиа / файлы / ссылки)
   ============================================================ */
.im-chat-attach-panel {
    position: absolute;
    top: 0; right: 0; bottom: 0;
    width: 360px;
    max-width: 100%;
    background: #fff;
    border-left: 1px solid #eef1f5;
    box-shadow: -8px 0 32px rgba(15,23,42,0.1);
    z-index: 150;
    display: flex;
    flex-direction: column;
    animation: panelIn 0.18s ease-out;
}
@keyframes panelIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

.im-chat-attach-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1rem 1.25rem; border-bottom: 1px solid #eef1f5;
}
.im-chat-attach-head h3 { margin: 0; font-size: 1.05rem; font-weight: 800; }
.im-chat-attach-close {
    background: none; border: none; font-size: 1.4rem; line-height: 1;
    color: #94a3b8; cursor: pointer; padding: 0;
}
.im-chat-attach-close:hover { color: #475569; }

.im-chat-attach-tabs {
    display: flex; gap: 0.25rem; padding: 0.75rem 1rem 0 1rem;
    border-bottom: 1px solid #eef1f5;
}
.im-chat-attach-tab {
    padding: 0.5rem 0.9rem; border: none; background: none; cursor: pointer;
    font-size: 0.9rem; font-weight: 700; color: #94a3b8; border-bottom: 2px solid transparent;
    font-family: inherit; margin-bottom: -1px;
}
.im-chat-attach-tab:hover { color: #475569; }
.im-chat-attach-tab.active { color: #3b82f6; border-bottom-color: #3b82f6; }

.im-chat-attach-body { flex: 1; overflow-y: auto; padding: 1rem; }

.im-chat-attach-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem;
}
.im-chat-attach-thumb {
    position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden;
    background: #f1f5f9; cursor: pointer; border: none; padding: 0;
}
.im-chat-attach-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.im-chat-attach-videobadge {
    position: absolute; bottom: 4px; right: 4px; background: rgba(15,23,42,0.7);
    color: #fff; font-size: 0.7rem; padding: 2px 6px; border-radius: 6px;
}

.im-chat-attach-file {
    display: flex; align-items: center; gap: 0.75rem; padding: 0.7rem 0.5rem;
    border-radius: 10px; text-decoration: none; color: inherit;
    border: 1px solid #eef1f5; margin-bottom: 0.5rem;
}
.im-chat-attach-file:hover { background: #f8fafc; }
.im-chat-attach-file .ic {
    width: 40px; height: 40px; border-radius: 10px; background: #eff6ff;
    display: flex; align-items: center; justify-content: center; font-size: 1.2rem; flex-shrink: 0;
}
.im-chat-attach-file .nm { font-weight: 600; font-size: 0.9rem; color: #1e293b; word-break: break-all; }
.im-chat-attach-file .sz { font-size: 0.78rem; color: #94a3b8; }

.im-chat-attach-link {
    display: block; padding: 0.7rem; border: 1px solid #eef1f5; border-radius: 10px;
    margin-bottom: 0.5rem; text-decoration: none; color: #2563eb; font-size: 0.88rem;
    word-break: break-all;
}
.im-chat-attach-link:hover { background: #f8fafc; }
.im-chat-attach-link .host { display: block; font-size: 0.75rem; color: #94a3b8; margin-top: 0.15rem; }

.im-chat-attach-empty {
    text-align: center; color: #94a3b8; padding: 2.5rem 1rem; font-size: 0.9rem;
}

/* ============================================================
   УЧАСТНИКИ / РЕДАКТИРОВАНИЕ ГРУППЫ
   ============================================================ */
.im-chat-member-row {
    display: flex; align-items: center; gap: 0.75rem; padding: 0.6rem 0.5rem;
    border-radius: 10px;
}
.im-chat-member-row:hover { background: #f8fafc; }
.im-chat-member-row .im-chat-avatar { width: 40px; height: 40px; font-size: 0.95rem; }
.im-chat-member-info { flex: 1; min-width: 0; }
.im-chat-member-name { font-weight: 600; font-size: 0.92rem; color: #1e293b; }
.im-chat-member-role { font-size: 0.76rem; color: #94a3b8; }
.im-chat-member-remove {
    background: #fef2f2; color: #dc2626; border: none; border-radius: 8px;
    padding: 0.35rem 0.7rem; font-size: 0.78rem; font-weight: 700; cursor: pointer;
}
.im-chat-member-remove:hover { background: #fee2e2; }

.im-chat-add-member-box { margin-top: 0.5rem; }
.im-chat-add-member-box input {
    width: 100%; padding: 0.7rem 0.9rem; border: 1.5px solid #e2e8f0;
    border-radius: 10px; font-size: 0.9rem; box-sizing: border-box; margin-bottom: 0.5rem;
    outline: none; font-family: inherit;
}
.im-chat-add-member-box input:focus { border-color: #3b82f6; }
.im-chat-add-member-results { max-height: 220px; overflow-y: auto; }

/* Просмотр медиа на весь экран */
.im-chat-lightbox {
    position: fixed; inset: 0; background: rgba(15,23,42,0.92); z-index: 100000;
    display: flex; align-items: center; justify-content: center; padding: 2rem;
}
.im-chat-lightbox img, .im-chat-lightbox video {
    max-width: 100%; max-height: 100%; border-radius: 8px;
}
.im-chat-lightbox-close {
    position: absolute; top: 1rem; right: 1.25rem; background: none; border: none;
    color: #fff; font-size: 2rem; cursor: pointer; line-height: 1;
}

@media (max-width: 768px) {
    .im-chat-attach-panel { width: 100%; }
}

/* === Миниатюры: обёртка + кнопка "открыть" === */
.im-chat-attach-thumb-wrap { position: relative; }
.im-chat-attach-zoomb {
    position: absolute; top: 4px; right: 4px; width: 22px; height: 22px;
    border-radius: 6px; border: none; background: rgba(15,23,42,0.65); color: #fff;
    font-size: 0.8rem; line-height: 1; cursor: pointer; opacity: 0; transition: opacity 0.15s;
    display: flex; align-items: center; justify-content: center; padding: 0;
}
.im-chat-attach-thumb-wrap:hover .im-chat-attach-zoomb { opacity: 1; }
.im-chat-attach-zoomb:hover { background: rgba(15,23,42,0.9); }

/* === Строка файла/ссылки с кнопкой "показать в чате" === */
.im-chat-attach-filerow { display: flex; align-items: stretch; gap: 0.4rem; }
.im-chat-attach-filerow .im-chat-attach-file,
.im-chat-attach-filerow .im-chat-attach-link { flex: 1; margin-bottom: 0.5rem; min-width: 0; }
.im-chat-attach-show {
    flex-shrink: 0; width: 40px; border: 1px solid #eef1f5; border-radius: 10px;
    background: #fff; color: #64748b; font-size: 1rem; cursor: pointer;
    margin-bottom: 0.5rem; transition: background 0.15s, color 0.15s;
}
.im-chat-attach-show:hover { background: #eff6ff; color: #3b82f6; border-color: #dbeafe; }

/* === Фото группы в модалке редактирования === */
.im-chat-edit-avatar-row {
    display: flex; align-items: center; gap: 1rem; margin-bottom: 1.25rem;
}
.im-chat-edit-avatar {
    width: 64px; height: 64px; font-size: 1.5rem; flex-shrink: 0;
}
.im-chat-edit-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* === Иконка закреплённого чата === */
.im-chat-pin-icon { font-size: 0.75rem; margin-right: 0.2rem; }
