::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d1d1; border-radius: 4px; }

body { background: #f4f7f6; }
body, .cw-bubble, .msg-body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol" !important;
}
.messenger-wrapper { padding: 10px 10px; max-width: 1300px; margin: 0 auto; }
.messenger-container { display: flex; height: 82vh; min-height: 500px; background: #fff; border-radius: 16px; overflow: hidden; border: 1px solid #eaeaea; position: relative; }

#left-column { width: 35%; min-width: 320px; border-right: 1px solid #eaeaea; display: flex; flex-direction: column; background: #fff; z-index: 2; transition: 0.3s; }
#right-column { flex: 1; display: flex; flex-direction: column; background: #f0f2f5; position: relative; z-index: 1; overflow: hidden; }

/* ТАБЫ */
.dialog-tabs { display: flex; border-bottom: 1px solid #eaeaea; background: #fcfcfc; overflow-x: auto; scrollbar-width: none; }
.dialog-tabs::-webkit-scrollbar { display: none; }
.d-tab { flex: 1; min-width: 75px; text-align: center; padding: 12px 5px; cursor: pointer; font-size: 13px; color: #888; transition: 0.2s; border-bottom: 2px solid transparent; font-weight: 500; }
.d-tab:hover { background: #f5f5f5; }
.d-tab.active { color: #4a90e2; border-bottom: 2px solid #4a90e2; background: #fff; }

#empty-chat-state { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: #888; }
.empty-chat-badge { background: rgba(0,0,0,0.05); padding: 8px 24px; border-radius: 20px; font-size: 15px; margin-top: 15px; color: #666; }
#active-chat-state { display: none; flex-direction: column; height: 100%; width: 100%; }

.dialog-item { display: flex; align-items: center; padding: 12px 15px; cursor: pointer; border-bottom: 1px solid #f6f6f6; transition: 0.2s; position: relative; }
.dialog-item:hover { background: #f9f9f9; }
.dialog-item.active-chat { background: #eef5fb; border-left: 4px solid #4a90e2; padding-left: 11px; }

.chat-header { display: flex; align-items: center; padding: 10px 20px; background: #fff; border-bottom: 1px solid #eaeaea; z-index: 10; justify-content: space-between; }
.mobile-back-btn { display: none; font-size: 20px; color: #4a90e2; margin-right: 15px; cursor: pointer; padding: 5px; font-weight: bold; }

.date-divider { display: flex; justify-content: center; margin: 15px 0; }
.date-divider span { background: rgba(0,0,0,0.1); color: #fff; font-size: 11px; font-weight: bold; padding: 4px 12px; border-radius: 12px; text-shadow: 0 1px 2px rgba(0,0,0,0.2); }

.msg-bubble { padding: 10px 15px; border-radius: 16px; max-width: 100%; box-shadow: 0 1px 2px rgba(0,0,0,0.05); font-size: 14px; line-height: 1.4; word-wrap: break-word; transition: 0.2s; position: relative; }
.msg-mine { background: #DCF8C6; border-bottom-right-radius: 4px; color: #111; }
.msg-theirs { background: #ffffff; border-bottom-left-radius: 4px; color: #111; border: 1px solid #f0f0f0; }
.msg-time { font-size: 11px; color: rgba(0,0,0,0.4); margin-top: 5px; text-align: right; display: flex; justify-content: flex-end; align-items: center; gap: 5px; }
.msg-edited-badge { font-size: 10px; font-style: italic; opacity: 0.6; }

.msg-wrapper { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; max-width: 85%; }
.msg-wrapper-mine { flex-direction: row-reverse; }
.msg-wrapper-theirs { flex-direction: row; }      

.msg-dots { width: 28px; height: 28px; display: flex; justify-content: center; align-items: center; border-radius: 50%; cursor: pointer; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.15); transition: 0.2s; color: #555; flex-shrink: 0; opacity: 1; }
.msg-dots:hover { background: #f0f0f0; }

.dialog-dots { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #999; transition: 0.2s; flex-shrink: 0; opacity: 0.5; }
.dialog-dots:hover { background: rgba(0,0,0,0.08); color: #333; opacity: 1; }
.dialog-item:hover .dialog-dots { opacity: 1; }

.header-btn { cursor: pointer; color: #777; width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; transition: 0.2s; }
.header-btn:hover { background: #f0f0f0; color: #333; }

.modern-input { width: 100%; padding: 10px 15px; border: 1px solid #e0e0e0; border-radius: 20px; outline: none; background: #f8f9fa; }
#pinned-msg-banner { display: none; background: #fff; border-bottom: 1px solid #eaeaea; padding: 8px 20px; cursor: pointer; border-left: 4px solid #f39c12; align-items: center; height: 50px; flex-shrink: 0; overflow: hidden; box-sizing: border-box; }

#custom-context-menu { position: fixed; background: #fff; border-radius: 12px; box-shadow: 0 4px 20px rgba(0,0,0,0.15); padding: 6px 0; z-index: 9999; min-width: 180px; display: none; border: 1px solid #eaeaea; }
.ctx-item { padding: 10px 16px; cursor: pointer; font-size: 14px; display: flex; align-items: center; gap: 12px; color: #333; transition: 0.1s; }
.ctx-item:hover { background: #f0f2f5; }
.ctx-item.danger { color: #e53935; }

.chat-toolbar { display: flex; gap: 8px; padding: 6px 15px; background: #f8f9fa; border-bottom: 1px solid #eaeaea; }
.toolbar-btn { cursor: pointer; color: #555; padding: 4px 8px; border-radius: 4px; font-size: 15px; }

/* НОВЫЙ ДИЗАЙН ОТВЕТОВ И УПОМИНАНИЙ */
.reply-badge { background: rgba(74, 144, 226, 0.1); border-left: 3px solid #4a90e2; padding: 6px 10px; margin-bottom: 6px; font-size: 13px; color: #4a90e2; cursor: pointer; border-radius: 4px; transition: 0.2s; }
.reply-badge:hover { background: rgba(74, 144, 226, 0.2); }
.old-quote { background: rgba(0,0,0,0.03); border-left: 3px solid #ccc; padding: 6px 10px; margin-bottom: 6px; font-size: 13px; color: #666; border-radius: 4px; }
.mention { color: #4a90e2; font-weight: 600; cursor: pointer; text-decoration: none; transition: 0.2s; }
.mention:hover { text-decoration: underline; }

@media (max-width: 768px) {
    /* mobile: messenger fullscreen over site header */
    .messenger-wrapper {
        padding: 0 !important;
        margin: 0 !important;
        max-width: 100% !important;
    }

    .messenger-container {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        height: calc(100% - 55px - env(safe-area-inset-bottom)) !important;
        height: calc(100dvh - 55px - env(safe-area-inset-bottom)) !important;
        width: 100% !important;
        max-width: 100vw !important;
        min-height: 0 !important;
        max-height: none !important;
        border-radius: 0 !important;
        border: none !important;
        z-index: 99999 !important;
        background: #fff;
        box-sizing: border-box !important;
        overflow-x: hidden !important;
    }

    #left-column {
        width: 100% !important;
        height: 100% !important;
        display: flex !important;
        flex-direction: column !important;
    }
    
    #left-column > div:first-child {
        flex-shrink: 0;
        background: #fff;
    }
    
    .dialog-tabs {
        flex-shrink: 0;
        position: sticky;
        top: 0;
        z-index: 5;
    }

    #dialogs-list {
        flex: 1 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    /* Управление отображением окон при активном чате */
    .messenger-container.chat-active #left-column { 
        display: none !important; 
    }
    
    .messenger-container.chat-active #right-column { 
        display: flex !important; 
        width: 100% !important; 
        height: 100% !important; 
        flex-direction: column !important;
    }

    /* Фиксируем верхнюю панель внутри открытого чата */
    .chat-header {
        flex-shrink: 0 !important;
        position: sticky !important;
        top: 0 !important;
        background: #fff !important;
        z-index: 10 !important;
    }

    /* История сообщений скроллится строго между хедером чата и полем ввода */
    #messages-history {
        flex: 1 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        display: flex !important;
        flex-direction: column !important;
    }

    /* ПОЛЕ ВВОДА: Жестко привязано к низу контейнера, не сжимается и не уходит */
    #chat-input-block { 
        flex-shrink: 0 !important;
        position: sticky !important;
        bottom: 0 !important;
        background: #fff !important;
        z-index: 11 !important;
    }

    .mobile-back-btn { 
        display: flex !important; 
    }
    
    .chat-search-input-wrap { 
        display: none !important; 
    } 
    
    .dialog-dots { 
        opacity: 1; 
    } 
	
	#msg-text, .modern-input {
        font-size: 16px !important; 
    }

    /* 2. Жесткая фиксация ширины блока ввода */
    #chat-input-block {
        width: 100% !important;
        max-width: 100vw !important;
        box-sizing: border-box !important;
        padding-left: env(safe-area-inset-left) !important;
        padding-right: env(safe-area-inset-right) !important;
    }
    
    /* Делаем панель с кнопками (B, I, U) тоже строго по ширине */
    .chat-toolbar {
        width: 100% !important;
        box-sizing: border-box !important;
        overflow-x: auto !important;
    }
}

.chat-header-tabs {
    display: flex;
    border-bottom: 1px solid #eaeaea;
    background: #fff;
    flex-shrink: 0;
}
.cht-btn {
    flex: 1;
    text-align: center;
    padding: 12px 0;
    cursor: pointer;
    color: #888;
    font-size: 14px;
    font-weight: 600;
    border-bottom: 3px solid transparent;
    transition: all 0.2s ease;
    user-select: none;
}
.cht-btn:hover { background: #fcfcfc; color: #555; }
.cht-btn.active { color: #11998e; border-bottom-color: #11998e; }

/* Карточка отдельного лога */
.log-card {
    background: #fff;
    border: 1px solid #eaeaea;
    border-left: 4px solid #11998e;
    border-radius: 8px;
    padding: 12px 15px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.02);
}
.log-card-header { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 6px; }
.log-card-admin { font-weight: bold; color: #222; }
.log-card-time { color: #888; }
.log-card-text { font-size: 13px; color: #444; }
/* ============================================================ */
/* РџРµСЂРµРЅРµСЃРµРЅРѕ РёР· РёРЅР»Р°Р№РЅ <style> РІ im.php (С‚РµРјР°, СЃРєРµР»РµС‚РѕРЅС‹, СЃС‚Р°С‚СѓСЃС‹) */
/* ============================================================ */
.d-tab.active { 
    color: #11998e !important; 
    border-bottom: 2px solid #11998e !important; 
}

/* 2. РђРєС‚РёРІРЅС‹Р№ РґРёР°Р»РѕРі РІ Р»РµРІРѕР№ РєРѕР»РѕРЅРєРµ */
.dialog-item.active-chat { 
    background: #f0fdf6 !important; /* РћС‡РµРЅСЊ Р»РµРіРєРёР№ Р·РµР»РµРЅС‹Р№ С„РѕРЅ */
    border-left: 4px solid #11998e !important; 
}

/* 3. РљРЅРѕРїРєР° РѕС‚РїСЂР°РІРєРё СЃРѕРѕР±С‰РµРЅРёСЏ (Р“СЂР°РґРёРµРЅС‚) */
#send-btn { 
    background: linear-gradient(135deg, #11998e, #38ef7d) !important; 
    box-shadow: 0 4px 10px rgba(17, 153, 142, 0.3) !important; 
    border: none !important; 
}

/* 4. Р’Р°С€Рё РѕС‚РїСЂР°РІР»РµРЅРЅС‹Рµ СЃРѕРѕР±С‰РµРЅРёСЏ */
.msg-mine { 
    background: #e6f9f0 !important; 
    border: 1px solid #cbf0df !important; 
    color: #111 !important; 
}

/* 5. Р‘Р»РѕРєРё "РћС‚РІРµС‚ РЅР° СЃРѕРѕР±С‰РµРЅРёРµ" Рё @СѓРїРѕРјРёРЅР°РЅРёСЏ */
.reply-badge { 
    background: rgba(17, 153, 142, 0.08) !important; 
    border-left: 3px solid #11998e !important; 
    color: #11998e !important; 
}
.reply-badge:hover { background: rgba(17, 153, 142, 0.15) !important; }
.mention { color: #11998e !important; }


/* 7. Р‘Р°РЅРЅРµСЂ Р·Р°РєСЂРµРїР»РµРЅРЅРѕРіРѕ СЃРѕРѕР±С‰РµРЅРёСЏ (рџ“Њ) вЂ” С„РёРєСЃ. РІС‹СЃРѕС‚Р°, РЅРµ РїРµСЂРµРєСЂС‹РІР°РµС‚ С‡Р°С‚ */
#pinned-msg-banner {
    display: none;               /* РїРѕРєР°Р·С‹РІР°РµС‚СЃСЏ РёР· JS С‡РµСЂРµР· flex */
    align-items: center;
    height: 48px;                /* С„РёРєСЃРёСЂРѕРІР°РЅРЅР°СЏ РІС‹СЃРѕС‚Р° */
    min-height: 48px;
    max-height: 48px;
    box-sizing: border-box;
    padding: 6px 14px;
    margin: 0;
    background: #f0f9f6;
    border-left: 4px solid #11998e !important;
    border-bottom: 1px solid #e3e8ee;
    cursor: pointer;
    overflow: hidden;
    flex-shrink: 0;              /* РЅРµ СЃР¶РёРјР°РµС‚СЃСЏ, С‡Р°С‚ РѕСЃС‚Р°С‘С‚СЃСЏ РЅРёР¶Рµ */
}
#pinned-msg-banner:hover { background: #e6f5f0; }
#pinned-msg-date { color: #11998e !important; }
#pinned-msg-text {
    font-size: 13px; color: #555;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* РљРЅРѕРїРєР° РѕС‚РєСЂРµРїРёС‚СЊ РІРЅСѓС‚СЂРё Р±Р°РЅРЅРµСЂР° */
#pinned-msg-unpin {
    margin-left: 10px; flex-shrink: 0;
    color: #999; font-size: 16px; line-height: 1;
    padding: 4px 6px; border-radius: 6px;
}
#pinned-msg-unpin:hover { background: rgba(0,0,0,0.06); color: #e53935; }

/* --- РџР РћР”Р’РРќРЈРўР«Р™ РЎРљР•Р›Р•РўРћРќ (SKELETON LOADER) --- */
.skeleton {
    background: linear-gradient(90deg, #f0f2f5 25%, #e6e8eb 50%, #f0f2f5 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite linear;
    border-radius: 8px;
}
@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* РЎС‚Р°С‚СѓСЃ РѕРЅР»Р°Р№РЅ */
.status-online { color: #11998e !important; font-weight: 500; }
.status-offline { color: #888 !important; }

#selection-popup-toolbar button:hover {
    background-color: #f0f2f5 !important;
    border-radius: 6px;
}
/* РќРµР±РѕР»СЊС€РѕР№ С‚СЂРµСѓРіРѕР»СЊРЅРёРє-СЃС‚СЂРµР»РѕС‡РєР° СЃРЅРёР·Сѓ РїР°РЅРµР»Рё */
#selection-popup-toolbar::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 6px 6px 0;
    border-style: solid;
    border-color: #ffffff transparent;
    display: block;
    width: 0;
}


/* ============================================================
   BOTTOM SHEET вЂ” РµРґРёРЅРѕРµ РєРѕРЅС‚РµРєСЃС‚РЅРѕРµ РјРµРЅСЋ РјРµСЃСЃРµРЅРґР¶РµСЂР°
   (Р·Р°РјРµРЅСЏРµС‚ РїРѕР·РёС†РёРѕРЅРёСЂРѕРІР°РЅРёРµ #custom-context-menu Сѓ РєСѓСЂСЃРѕСЂР°)
   ============================================================ */
.im-sheet-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 100000;
    opacity: 0; pointer-events: none;
    transition: opacity 0.25s ease;
}
.im-sheet-overlay.open { opacity: 1; pointer-events: auto; }

.im-sheet {
    position: fixed; left: 0; right: 0; bottom: 0;
    background: #fff;
    border-radius: 16px 16px 0 0;
    z-index: 100001;
    transform: translateY(100%);
    transition: transform 0.28s cubic-bezier(0.32,0.72,0,1);
    padding-bottom: env(safe-area-inset-bottom, 8px);
    max-width: 520px; margin: 0 auto;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
    max-height: 80vh; overflow-y: auto;
}
.im-sheet.open { transform: translateY(0); }

.im-sheet-handle {
    width: 40px; height: 4px; border-radius: 2px;
    background: #d0d0d0; margin: 10px auto 8px;
}

/* РџСѓРЅРєС‚С‹ РІРЅСѓС‚СЂРё Р»РёСЃС‚Р°: РїРµСЂРµРёСЃРїРѕР»СЊР·СѓРµРј .ctx-item РёР· РјРµРЅСЋ, РЅРѕ РєСЂСѓРїРЅРµРµ РЅР° С‚Р°С‡ */
.im-sheet .ctx-item {
    padding: 15px 22px; font-size: 16px;
}

/* Р‘Р»РѕРєРёСЂРѕРІРєР° РїСЂРѕРєСЂСѓС‚РєРё СЃС‚СЂР°РЅРёС†С‹ РїСЂРё РѕС‚РєСЂС‹С‚РѕРј Р»РёСЃС‚Рµ */
body.im-sheet-lock { overflow: hidden !important; touch-action: none; }

/* Р”РµСЃРєС‚РѕРї: Р»РёСЃС‚ РїРѕ С†РµРЅС‚СЂСѓ СЃ Р·СѓРјРѕРј (РµРґРёРЅС‹Р№ РІРёРґ СЃ РІРёРґР¶РµС‚РѕРј) */
@media (min-width: 769px) {
    .im-sheet {
        border-radius: 14px; bottom: auto; top: 50%; left: 50%; right: auto;
        transform: translate(-50%, -45%) scale(0.96); width: 300px;
        opacity: 0; transition: transform 0.2s, opacity 0.2s;
    }
    .im-sheet.open { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    .im-sheet-handle { display: none; }
}
