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

body { background: #f4f7f6; }
.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) {
    .messenger-container { 
       position: fixed !important;
        top: 0 !important; /* Прибиваем к самому верху, перекрывая шапку */
        bottom: calc(55px + env(safe-area-inset-bottom)) !important;        
        left: 0 !important; 
        width: 100% !important;
        height: auto !important; 
        max-height: none !important;       
        border-radius: 0 !important; 
        border: none !important; 
        z-index: 1029 !important; /* Увеличиваем z-index, чтобы быть выше всех */
        background: #fff;
        max-width: 100vw !important;
        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;
    }
}