/* === ГЛОБАЛЬНЫЙ ФИКС РАЗМЕРОВ === */
*, *::before, *::after {
    box-sizing: border-box;
}

/* public/css/chat.css — ЧИСТАЯ ВЕРСИЯ */

/* =========================================
   1. ЦВЕТОВЫЕ СХЕМЫ (ПЕРЕМЕННЫЕ)
   ========================================= */
:root {
    --bg-body: #f4f6f8;
    --bg-header: #3498db;
    --text-header: #ffffff;
    
    --bg-sidebar: #ffffff;
    --bg-sidebar-header: #f7f7f7;
    --text-main: #2c3e50;
    --text-secondary: #7f8c8d;
    
    --msg-mine: #bbdefb;
    --msg-other: #ffffff;
    --msg-text: #2c3e50;
    
    --bg-input: #ffffff;      
    --border-color: #dfe6e9;
    --send-btn: #3498db;
    --send-btn-text: #ffffff;

    --menu-btn-bg: #f8f9fa;
    --menu-btn-text: #2c3e50;
    --menu-btn-border: #e1e4e8;
}

[data-theme="dark"] {
    --bg-body: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
    --bg-header: #0f2027;     
    --text-header: #ffffff;
    
    --bg-sidebar: rgba(15, 32, 39, 0.95);
    --bg-sidebar-header: rgba(255, 255, 255, 0.05);
    --text-main: #ffffff;
    --text-secondary: #bdc3c7;
    
    --msg-mine: #2980b9;
    --msg-other: #2c3e50;
    --msg-text: #ffffff;
    
    --bg-input: #2c3e50;
    --border-color: #34495e;
    --send-btn: #00f2fe;
    --send-btn-text: #000000;

    --menu-btn-bg: #2c3e50;
    --menu-btn-text: #ecf0f1;
    --menu-btn-border: #34495e;
}



/* =========================================
   2. ОСНОВНАЯ РАЗМЕТКА (FIXED LAYOUT)
   ========================================= */
html, body {
    height: 100%; width: 100%; overflow: hidden; overscroll-behavior: none; 
    position: fixed; top: 0; left: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg-body); background-size: cover;
    margin: 0; padding: 0;
}

.chat-container { height: 100%; display: flex; flex-direction: column; overflow: hidden; }
#app-viewport { display: flex; flex-direction: column; width: 100%; height: 100%; }

/* =========================================
   3. ШАПКА (HEADER)
   ========================================= */
.chat-header {
    height: 60px; min-height: 60px; 
    background: var(--bg-header); 
    color: var(--text-header);
    padding: 0 10px; 
    display: flex; align-items: center; justify-content: space-between; 
    z-index: 30;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: relative; 
}

.menu-btn { 
    background: none; border: none; color: var(--text-header); 
    font-size: 26px; cursor: pointer; padding: 0; 
    width: 40px; text-align: left; z-index: 31; 
}

.chat-branding {
    position: absolute; left: 50%; transform: translateX(-50%);
    display: flex; align-items: center; justify-content: center;
    height: 100%; width: 60%; pointer-events: none; 
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.header-logo {
    height: 48px; width: auto; display: block;
    filter: brightness(0) invert(1); opacity: 0.95; pointer-events: auto;
}

.header-spacer { width: 40px; }

/* =========================================
   4. БОКОВАЯ ПАНЕЛЬ (SIDEBAR) — ФИНАЛЬНАЯ ВЕРСИЯ (NO JUMP)
   ========================================= */
.chat-body { flex: 1; display: flex; overflow: hidden; position: relative; width: 100%; }

.users-sidebar {
    width: 280px; 
    background: var(--bg-sidebar); 
    border-right: 1px solid var(--border-color);
    color: var(--text-main);
    display: flex; 
    flex-direction: column; 
    z-index: 40;
    height: 100%;
    
    /* Стабилизация скролла: */
    overflow-y: auto;        
    overflow-x: hidden;      
    overflow-anchor: none;   /* Запрещаем браузеру двигать скролл */
    justify-content: flex-start;
}

@media (max-width: 768px) {
    .users-sidebar {
        position: absolute; top: 0; bottom: 0; left: 0;
        width: 85%; max-width: 300px;
        transform: translateX(-100%); 
        box-shadow: 2px 0 15px rgba(0,0,0,0.5);
    }
    .users-sidebar.active { transform: translateX(0); }
}

.sidebar-header {
    padding: 15px; font-weight: bold; 
    border-bottom: 1px solid var(--border-color); 
    background: var(--bg-sidebar-header); color: var(--text-main);
}

/* === ЗАГОЛОВКИ (КНОПКИ) === */
.clickable-header {
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-sidebar-header);
    user-select: none;
    min-height: 50px; 
    flex-shrink: 0;
    padding: 0 15px; 
    border-bottom: 1px solid var(--border-color);
    margin: 0; /* Важно: никаких маржинов */
}

.clickable-header:active { opacity: 0.7; }

/* Стрелка */
#settingsArrow, #groupsArrow {
    display: inline-block;
    transition: transform 0.3s ease;
    transform: rotate(0deg); 
}

/* Класс переворота */
.rotate-arrow {
    transform: rotate(180deg) !important; 
}

/* === АНИМАЦИЯ ПАНЕЛИ (ВАЖНОЕ ИСПРАВЛЕНИЕ) === */
.collapsed-panel {
    max-height: 1200px; /* Запас высоты */
    opacity: 1;
    overflow: hidden; 
    
    /* 🔥 УБРАЛИ padding из анимации. Теперь он не будет "ездить". 
       Анимируем только высоту и прозрачность */
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
    
    background: var(--bg-sidebar);
}

/* === ПАНЕЛЬ НАСТРОЕК (GRID) === */
.sidebar-controls {
    display: grid;
    grid-template-columns: repeat(4, 1fr); 
    gap: 6px; 
    
    /* Твои настройки высоты и паддинга (подушка 70px) */
    height: auto !important; 
    padding: 10px 10px 10px 10px !important;
    
    background: var(--bg-sidebar); 
    border-bottom: 1px solid var(--border-color);
}

/* === СОСТОЯНИЕ "ЗАКРЫТО" === */
.collapsed-panel.closed {
    /* Схлопываем высоту в ноль */
    max-height: 0 !important;
    opacity: 0;
    
    /* Убираем паддинги мгновенно (без transition), чтобы не было "подушки" */
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    margin: 0 !important;
    border: none !important;
    min-height: 0 !important; /* На всякий случай */
}

/* === КНОПКИ === */
.control-btn {
    width: 100%; 
    min-height: 70px; 
    background: var(--menu-btn-bg); 
    border: 1px solid var(--menu-btn-border);
    border-radius: 10px; 
    color: var(--menu-btn-text); 
    padding: 5px 2px;
    cursor: pointer; 
    display: flex; 
    flex-direction: column; 
    align-items: center;
    justify-content: center; 
    gap: 6px; 
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.control-btn:active { transform: scale(0.96); }
.control-btn .icon { font-size: 20px !important; line-height: 1; display: block; margin: 0; }
.control-btn .label { 
    font-size: 9px; font-weight: bold; 
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}

/* ЗАПРЕТ СЖАТИЯ: Блоки не поедут вверх, даже если места мало */
.clickable-header,
.collapsed-panel,
#groupsWrapper,
.sidebar-controls {
    flex-shrink: 0 !important;
}

/* === ГРУППЫ === */
/* Обертка групп тоже не должна иметь лишних отступов */
#groupsWrapper { margin: 0; padding: 0; }

/* Список юзеров/групп */
.user-item { padding: 12px 15px; display: flex; align-items: center; border-bottom: 1px solid var(--border-color); cursor: pointer; }
.user-name { font-size: 15px; color: var(--text-main); font-weight: bold; }
.user-status-text { font-size: 12px; color: var(--text-secondary); }
.overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 35; }
.overlay.active { display: block; }
/* === СПИСОК ЮЗЕРОВ === */
.user-item { padding: 12px 15px; display: flex; align-items: center; border-bottom: 1px solid var(--border-color); cursor: pointer; }
.user-name { font-size: 15px; color: var(--text-main); font-weight: bold; }
.user-status-text { font-size: 12px; color: var(--text-secondary); }
.overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 35; }
.overlay.active { display: block; }

/* =========================================
   5. ОБЛАСТЬ СООБЩЕНИЙ
   ========================================= */
.messages-area {
    flex: 1; display: flex; flex-direction: column;
    background: transparent; position: relative; width: 100%;
}

.messages-list {
    flex: 1; overflow-y: auto; padding: 15px; 
    display: flex; flex-direction: column; gap: 8px;
    overscroll-behavior-y: contain; -webkit-overflow-scrolling: touch; 
}

/* === СООБЩЕНИЯ (ПУЗЫРИ) === */
.message { margin-bottom: 15px; display: flex; width: 100%; align-items: flex-end; z-index: 2; }
.my-message { flex-direction: row-reverse; }
.other-message { flex-direction: row; }

.bubble { 
    padding: 8px 12px; max-width: 70%; position: relative; 
    word-wrap: break-word; overflow-wrap: break-word; 
    box-shadow: 0 1px 2px rgba(0,0,0,0.1); 
}
.bubble img { max-width: 100%; height: auto; border-radius: 8px; }

.my-message .bubble { 
    background: var(--msg-mine); color: var(--msg-text);
    border-radius: 12px 12px 0 12px; margin-right: 10px; 
}
/* === ЧУЖИЕ СООБЩЕНИЯ (ЛЕВАЯ СТОРОНА) === */
.other-message .bubble { 
    background: var(--msg-other); 
    color: var(--msg-text);
    /* Закругляем всё, кроме левого нижнего угла */
    border-radius: 12px 12px 12px 0; 
    /* 🔥 Прижимаем ближе к аватарке (было больше) */
    margin-left: 5px; 
    border: 1px solid var(--border-color); 
    position: relative;
}

/* === ХВОСТИК (СТРЕЛКА) ВЛЕВО === */
.other-message .bubble::before {
    content: "";
    position: absolute;
    /* Сдвигаем влево, чтобы указывало на аватарку */
    left: -8px;    
    /* Прижимаем к низу */
    bottom: 0;  
    width: 0; 
    height: 0;
    /* Рисуем треугольник, смотрящий ВЛЕВО */
    border-style: solid;
    /* Верх, Право, Низ, Лево */
    border-width: 0 10px 10px 0; 
    /* Цвет должен совпадать с фоном пузыря */
    border-color: transparent var(--msg-other) transparent transparent; 
}

/* Выравниваем аватарку и сообщение по низу */
.message {
    align-items: flex-end; 
}

.sender-name { font-size: 0.75rem; color: var(--text-secondary); margin-bottom: 2px; font-weight: bold; }
.msg-time { font-size: 0.65rem; color: var(--text-secondary); text-align: right; margin-top: 2px; display: block; opacity: 0.8; }
.my-message .sender-name { display: none; }

/* Дата */
.date-divider {
    position: relative; width: 100%; text-align: center;
    margin: 25px 0 15px 0; display: flex; justify-content: center; pointer-events: none; z-index: 1;
}
.date-badge {
    display: inline-block; padding: 6px 14px; border-radius: 15px;
    background-color: rgba(0, 0, 0, 0.15); color: #fff;
    font-size: 12px; font-weight: 600; backdrop-filter: blur(2px);
}
[data-theme="light"] .date-badge { background-color: #e1f5fe; color: #444; }

/* =========================================
   6. ПАНЕЛЬ ВВОДА (INPUT)
   ========================================= */
#chatForm { background: transparent !important; }

.input-area {
    width: 100%; min-height: 60px; padding: 8px 10px; 
    display: flex; align-items: flex-end; gap: 8px; 
    z-index: 20; box-sizing: border-box; background: transparent !important;
}

.input-wrapper {
    display: flex; /* Выстраиваем в ряд */
    align-items: center; /* Центрируем по высоте */
    background: #fff; /* Белый фон */
    border-radius: 25px; /* Округлость */
    padding: 2px 10px; /* Отступы внутри */
    flex: 1; /* 🔥 ВАЖНО: Занимай всё свободное место, но не больше */
    margin-right: 8px; /* Отступ до микрофона */
    min-width: 0; /* 🔥 Секрет CSS: разрешает блоку сжиматься, если места мало */
    border: 1px solid #ccc; /* Граница, если была */
}

.chat-input {
    flex: 1; /* 🔥 ВАЖНО: Растягивайся внутри обертки */
    width: auto !important; /* Отменяем жесткие 100% */
    min-width: 0; /* Разрешаем сжиматься */
    border: none; /* Убираем рамку самого поля */
    outline: none;
    background: transparent;
    max-height: 100px;
    padding: 8px 5px; /* Чуть уменьшим боковые отступы, т.к. рядом кнопки */
    font-family: inherit; /* Как мы договаривались */
    font-size: 16px;
    /* Твой фикс для центрирования */
    display: flex;
    align-items: center;
}


.attach-btn {
    flex-shrink: 0; /* 🔥 Запрещаем кнопкам сплющиваться */
    width: 30px; /* Фиксируем размер */
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin: 0 2px; /* Чуть раздвинем */
}

/* Темная тема (проверка) */
[data-theme="dark"] .input-wrapper {
    background: #333;
    border-color: #444;
    /* color: whitesmoke; */
}

[data-theme="dark"] .chat-input{
    color: white;
}

.mic-btn {
    width: 48px; height: 48px; border-radius: 50%; 
    background: #25d366; color: #ffffff;
    border: none; font-size: 20px; cursor: pointer; 
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; box-shadow: 0 2px 5px rgba(0,0,0,0.15);
    transition: transform 0.1s, background 0.3s;
}
.mic-btn:active { transform: scale(0.95); }
.mic-btn[data-mode="send"] { background: var(--send-btn); }

/* =========================================
   7. ДОПОЛНИТЕЛЬНЫЕ ЭЛЕМЕНТЫ (MODALS, GEO, ETC)
   ========================================= */
.mute-modal { 
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; 
    background: rgba(0,0,0,0.6); z-index: 100; 
    align-items: center; justify-content: center; display: none; 
}
.mute-content {
    background: var(--bg-input); color: var(--text-main);
    width: 300px; padding: 20px; border-radius: 15px; 
    display: flex; flex-direction: column; gap: 10px; 
    box-shadow: 0 10px 30px rgba(0,0,0,0.5); border: 1px solid var(--border-color);
}
.mute-content button {
    padding: 12px; border: none; background: var(--bg-input); 
    color: var(--text-main); border-radius: 8px; font-size: 16px; 
    cursor: pointer; text-align: left; border: 1px solid var(--border-color);
}
.mute-content .close-mute { text-align: center; color: var(--text-secondary); border: none; }

/* Геолокация в чате */
.geo-card {
    background: rgba(255,255,255,0.9); border-radius: 10px; padding: 10px;
    min-width: 200px; max-width: 100%; box-shadow: 0 2px 5px rgba(0,0,0,0.1); margin-top: 5px;
}
.geo-header { font-weight: bold; font-size: 14px; margin-bottom: 8px; color: #333; display: flex; align-items: center; gap: 5px; }
.geo-actions { display: flex; flex-direction: column; gap: 5px; }
.geo-btn {
    display: block; text-align: center; padding: 8px; border-radius: 6px;
    text-decoration: none; font-size: 13px; font-weight: bold; color: white !important;
}
.geo-btn.google { background-color: #4285F4; }
.geo-btn.waze { background-color: #33ccff; }

/* =========================================
   8. УСКОРЕНИЕ (SPEED PACK)
   ========================================= */

/* 1. Анимация появления страницы (выезд справа) */
.chat-container, #app-viewport {
    animation: slideInRight 0.3s cubic-bezier(0.25, 1, 0.5, 1);
    will-change: transform, opacity;
}

@keyframes slideInRight {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

/* 2. Скелетон (Заглушки вместо белого экрана) */
.skeleton-loader {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
}

.sk-msg {
    height: 45px;
    border-radius: 12px;
    background: linear-gradient(90deg, rgba(0,0,0,0.05) 25%, rgba(0,0,0,0.1) 50%, rgba(0,0,0,0.05) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
}

.sk-mine { align-self: flex-end; width: 40%; border-bottom-right-radius: 0; background-color: #e3f2fd; }
.sk-other { align-self: flex-start; width: 60%; border-bottom-left-radius: 0; }

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* 3. Улучшение для картинок (чтобы не прыгали) */
.bubble img {
    background: #f0f0f0; /* Серый фон, пока картинка грузится */
    min-height: 150px;   /* Резервируем место */
    transition: opacity 0.3s ease;
}

/* Заставляем ВСЕ поля ввода и кнопки использовать наш красивый шрифт */
input, textarea, button, select {
    font-family: inherit; /* Наследовать шрифт от body */
}

/* На всякий случай, уточним специально для твоего поля ввода */
.chat-input {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
}

/* И даже для подсказки (placeholder), которая пишет "Сообщение" */
::placeholder {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Единая панель */
.unified-panel {
    position: absolute;
    bottom: 70px;
    left: 0;
    right: 0;
    z-index: 1000;
    background: #fff;
    border-radius: 15px 15px 0 0; /* Закругляем только верх */
    box-shadow: 0 -5px 20px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 320px; /* Фиксированная высота */
}

/* Контент (где живут смайлы и стикеры) */
.panel-content {
    flex: 1;
    overflow: hidden;
    position: relative;
}

emoji-picker {
    width: 100%;
    height: 100%;
    border: none;
    --background: transparent;
}

/* Сетка для стикеров */
.sticker-grid {
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    height: 100%;
    overflow-y: auto;
    box-sizing: border-box;
}

/* Табы внизу */
.panel-tabs {
    display: flex;
    background: #f0f0f0;
    height: 40px;
    border-top: 1px solid #ddd;
}

.tab-btn {
    flex: 1;
    border: none;
    background: none;
    font-size: 14px;
    font-weight: bold;
    color: #666;
    cursor: pointer;
    transition: background 0.2s;
}

.tab-btn.active {
    background: #fff;
    color: #27ae60; /* Твой зеленый цвет */
    border-top: 3px solid #27ae60;
}

/* Темная тема */
[data-theme="dark"] .unified-panel { background: #2c2c2c; }
[data-theme="dark"] .panel-tabs { background: #1e1e1e; border-top: 1px solid #333; }
[data-theme="dark"] .tab-btn { color: #aaa; }
[data-theme="dark"] .tab-btn.active { background: #2c2c2c; color: #fff; }
[data-theme="dark"] emoji-picker { --background: #2c2c2c; }