/* --- CSS ПЕРЕМЕННЫЕ (ТЕМЫ И СТИЛЬ) --- */
:root {
    /* Светлая тема */
    --bg-main: #f0f2f5; 
    
    --bg-sidebar: linear-gradient(180deg, #ffffff 0%, #f2f4f8 100%);
    --bg-chat: linear-gradient(135deg, #99a7ff 0%, #faefff 100%); 
    
    /* Новый градиент для выезжающего меню (Drawer) */
    --drawer-bg: linear-gradient(160deg, #ffffff 0%, #edf0f5 100%);
    
    --bg-header: #ffffff;
    --text-main: #000000;
    --text-muted: #707579;
    --border-color: #e6e6e6;
    
    --gradient-primary: linear-gradient(135deg, #0078ff 0%, #00c6ff 100%);
    --gradient-my-msg: linear-gradient(135deg, #0078ff 0%, #00c6ff 100%);
    
    --primary-color: #0078ff; 
    --msg-my-text: #ffffff;
    --msg-other-bg: #ffffff;
    --msg-other-text: #000000;
    
    --msg-meta-my: rgba(255, 255, 255, 0.85); 
    --msg-meta-other: #a0aab5;
    
    --input-bg: #ffffff;
    --search-bg: #eef0f4;

    --main-radius: 16px;
    --msg-radius: 18px; 
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.12);
}

body.dark-theme {
    /* Тёмная тема */
    --bg-main: #0a0a0a;
    
    --bg-sidebar: linear-gradient(180deg, #18181b 0%, #201e28 100%);
    --bg-chat: linear-gradient(135deg, #27173f 0%, #3c1c74 100%);
    
    /* Тёмный неоновый градиент для выезжающего меню (Drawer) */
    --drawer-bg: linear-gradient(160deg, #18181b 0%, #1e182d 100%);
    
    --bg-header: #18181b;
    --text-main: #ffffff;
    --text-muted: #aaaaaa;
    --border-color: #2b2b2c;
    
    --gradient-primary: linear-gradient(135deg, #7b6ac4 0%, #a484ec 100%);
    --gradient-my-msg: linear-gradient(135deg, #7b6ac4 0%, #a484ec 100%);
    
    --primary-color: #a484ec; 
    --msg-my-text: #ffffff;
    --msg-other-bg: #212121;
    --msg-other-text: #ffffff;
    --msg-meta-my: rgba(255, 255, 255, 0.85);
    --msg-meta-other: #808080;
    
    --input-bg: #212121;
    --search-bg: #121212;
    
    --shadow-sm: 0 2px 10px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 20px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0; padding: 0; display: flex;
    height: 100vh; height: 100dvh; 
    background-color: var(--bg-main); color: var(--text-main);
    overflow: hidden; transition: background-color 0.3s ease, color 0.3s ease;
}

/* --- ВЫЕЗЖАЮЩЕЕ МЕНЮ (DRAWER) --- */
.backdrop {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.4); z-index: 998;
    opacity: 0; visibility: hidden; transition: opacity 0.3s ease, visibility 0.3s ease;
}
.backdrop.show { opacity: 1; visibility: visible; }

.drawer {
    position: fixed; top: 0; left: 0; width: 290px; height: 100%;
    background: var(--drawer-bg); /* Градиент применяется здесь */
    z-index: 999;
    transform: translateX(-100%); 
    /* Обновили transition для поддержки градиентов */
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1), background 0.3s;
    box-shadow: 2px 0 20px rgba(0,0,0,0.15); display: flex; flex-direction: column;
    border-top-right-radius: var(--main-radius); border-bottom-right-radius: var(--main-radius);
}
.drawer.open { transform: translateX(0); }

.drawer-header {
    background: var(--gradient-primary); 
    color: white; padding: 25px 20px;
    display: flex; flex-direction: column; gap: 15px; transition: background 0.3s;
    border-top-right-radius: var(--main-radius);
}
.drawer-avatar {
    width: 60px; height: 60px; border-radius: 50%; background: white;
    color: var(--primary-color); display: flex; align-items: center; justify-content: center;
    font-size: 24px; font-weight: bold; box-shadow: var(--shadow-sm);
}
.drawer-user-info .name { font-weight: 600; font-size: 17px; margin-bottom: 4px; }
.drawer-user-info .phone { font-size: 14px; opacity: 0.8; }

.drawer-menu { list-style: none; padding: 0; margin: 15px 0; }
.drawer-menu li {
    padding: 15px 20px; display: flex; align-items: center; gap: 15px;
    cursor: pointer; font-size: 15px; font-weight: 500; color: var(--text-main); transition: background 0.2s;
}
/* При наведении делаем легкое затемнение поверх градиента */
.drawer-menu li:hover { background: rgba(128,128,128,0.1); border-radius: 10px; margin: 0 10px; }
.drawer-menu li .icon { font-size: 20px; color: var(--text-muted); width: 24px; text-align: center; }

/* --- ЛЕВАЯ ПАНЕЛЬ ЧАТОВ --- */
.sidebar {
    width: 320px; 
    background: var(--bg-sidebar); 
    border-right: 1px solid var(--border-color);
    display: flex; flex-direction: column; z-index: 10; transition: border-color 0.3s;
    margin: 10px; border-radius: var(--main-radius); box-shadow: var(--shadow-sm);
}
.sidebar-header {
    padding: 10px 15px; display: flex; align-items: center; gap: 12px;
    border-bottom: 1px solid var(--border-color); height: 50px;
}

.menu-btn {
    background: none; border: none; font-size: 22px; color: var(--text-muted);
    cursor: pointer; padding: 0; display: flex; align-items: center; justify-content: center; transition: color 0.2s;
}
.menu-btn:hover { color: var(--primary-color); }

.search-bar {
    flex: 1; padding: 10px 15px; background: var(--search-bg); border: none;
    border-radius: 20px; color: var(--text-main); outline: none; font-size: 14px; transition: background 0.3s, color 0.3s;
}
.search-bar::placeholder { color: var(--text-muted); }

.chat-mock {
    padding: 12px 15px; display: flex; align-items: center; gap: 15px;
    background: var(--gradient-primary); 
    color: white; cursor: pointer; transition: transform 0.2s;
    margin: 10px 10px 0 10px; border-radius: 12px; box-shadow: var(--shadow-sm);
}
.chat-mock:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.chat-mock .avatar {
    width: 48px; height: 48px; border-radius: 50%; background: #fff;
    display: flex; align-items: center; justify-content: center; color: var(--primary-color); font-weight: bold; font-size: 19px;
}

/* --- ПРАВАЯ ЗОНА ЧАТА --- */
.chat-area {
    flex: 1; display: flex; flex-direction: column;
    background: var(--bg-chat); 
    position: relative; 
    margin: 10px 10px 10px 0; border-radius: var(--main-radius); box-shadow: var(--shadow-sm); overflow: hidden;
}
.chat-header {
    height: 50px; background: var(--bg-header); display: flex; align-items: center;
    padding: 0 15px; z-index: 5;
    border-bottom: 1px solid var(--border-color); transition: background 0.3s, border-color 0.3s;
}

.back-btn {
    display: none; background: none; border: none; font-size: 24px;
    color: var(--text-muted); cursor: pointer; padding: 0 15px 0 0;
    align-items: center; justify-content: center; transition: color 0.2s;
}
.back-btn:hover { color: var(--primary-color); }

.chat-header-info { display: flex; flex-direction: column; }
.chat-name { font-weight: 600; font-size: 16px; color: var(--text-main); }
.chat-status { font-size: 13px; color: var(--primary-color); margin-top: 2px; }

.messages {
    flex: 1; padding: 25px 8%; overflow-y: auto; display: flex; flex-direction: column; gap: 12px;
}

.message {
    position: relative; max-width: 60%; padding: 10px 16px; border-radius: var(--msg-radius);
    font-size: 15px; line-height: 1.45; box-shadow: var(--shadow-sm);
    word-wrap: break-word; transition: background 0.3s, color 0.3s, border-radius 0.2s;
}

.my-message { 
    background: var(--gradient-my-msg); 
    color: var(--msg-my-text); 
    align-self: flex-end; 
    border-bottom-right-radius: 6px; 
}

.other-message { 
    background: var(--msg-other-bg); color: var(--msg-other-text); 
    align-self: flex-start; 
    border-bottom-left-radius: 6px; 
}

.meta { float: right; font-size: 11px; margin: 8px 0 -4px 12px; opacity: 0.9; }
.my-message .meta { color: var(--msg-meta-my); }
.other-message .meta { color: var(--msg-meta-other); }

/* --- ГАЛОЧКИ ПРОЧИТАНО/ОТПРАВЛЕНО --- */
.msg-status {
    font-size: 11px;
    margin-left: 6px;
    font-weight: bold;
    display: inline-block;
}
.status-sent {
    color: rgba(255, 255, 255, 0.7); /* Одна полупрозрачная галочка */
}
.status-read {
    color: #4ade80; /* Две ярко-зеленые галочки (можно поменять на синие #3b82f6) */
}
.other-message .msg-status {
    display: none; /* У входящих сообщений галочки не рисуем */
}

/* ПАНЕЛЬ ВВОДА */
.input-area-wrapper { padding: 0px 15px 15px 8%; background: transparent; opacity: 1;}
.input-area {
    display: flex; background: var(--input-bg); border-radius: 24px;
    padding: 8px 15px; box-shadow: var(--shadow-md); align-items: center; gap: 10px; transition: background 0.3s;
}
#message-input { flex: 1; border: none; outline: none; font-size: 15px; background: transparent; color: var(--text-main); padding: 8px 0; }
#message-input::placeholder { color: var(--text-muted); }

#send-btn {
    background: var(--gradient-primary); 
    border: none; color: white; font-size: 18px;
    cursor: pointer; width: 36px; height: 36px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; transition: opacity 0.2s, transform 0.1s;
    box-shadow: var(--shadow-sm);
}
#send-btn:hover { opacity: 0.9; transform: scale(1.05); }
#send-btn:active { transform: scale(0.95); }

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 10px; }
body.dark-theme ::webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); }

/* --- АНИМАЦИЯ ДЛЯ ЗАПИСИ ГОЛОСА --- */
@keyframes pulse-mic {
    0% { transform: scale(1); color: #ff4d4d; }
    50% { transform: scale(1.2); color: #ff0000; }
    100% { transform: scale(1); color: #ff4d4d; }
}
#mic-btn.recording {
    animation: pulse-mic 1.5s infinite;
}

/* --- АДАПТИВНОСТЬ --- */
@media (max-width: 768px) {
    .sidebar, .chat-area { margin: 0; border-radius: 0; box-shadow: none; width: 100%; border: none; }
    .sidebar { display: flex; }
    .chat-area { display: none; }
    body.mobile-chat-active .sidebar { display: none; }
    body.mobile-chat-active .chat-area { display: flex; }
    .back-btn { display: flex; }
    .messages { padding: 15px 4%; gap: 8px; }
    .input-area-wrapper { padding: 10px 4%; }
    .message { max-width: 85%; padding: 8px 14px; border-radius: 16px; }
    .my-message { border-bottom-right-radius: 4px; }
    .other-message { border-bottom-left-radius: 4px; }
    .drawer { border-radius: 0; width: 270px; }
    .drawer-header { border-radius: 0; }
}

/* --- TELEGRAM-STYLE IMAGE VIEWER (ПОВЕРХ ВСЕГО) --- */
#image-viewer {
    display: none; 
    position: fixed; /* Фиксируем относительно экрана, а не чата */
    top: 0; 
    left: 0; 
    width: 100vw; 
    height: 100vh;
    background: rgba(0, 0, 0, 0.7); 
    
    /* Устанавливаем самый высокий приоритет */
    z-index: 20000; 
    
    justify-content: center; 
    align-items: center;
    opacity: 0; 
    transition: opacity 0.3s ease;
    cursor: zoom-out;
    overflow: hidden;

    /* Эффект размытия заднего фона */
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
}

#image-viewer.show { 
    display: flex; 
    opacity: 1; 
}

.viewer-img-container {
    display: flex; 
    justify-content: center; 
    align-items: center;
    max-width: 90%; 
    max-height: 90%;
    transition: transform 0.1s ease-out; 
    transform-origin: center center;
    border-radius: 12px;
    box-shadow: 0 10px 50px rgba(0,0,0,0.8);
}

#image-viewer img {
    max-width: 100%; 
    max-height: 100%; 
    border-radius: 12px; 
    display: block;
    user-select: none;
}

/* ВАЖНО: Удали все лишние скобки "}" после этого места! */

/* --- СТИЛИ ДЛЯ ЗАПИСИ "КРУЖОЧКОВ" (ВИДЕО) --- */
#video-record-overlay {
    /* ЗАМЕНИТЕ display: none; на эти три строчки: */
    display: flex;
    visibility: hidden;
    pointer-events: none; 
    
    position: fixed; 
    top: 0; 
    left: 0; 
    width: 100vw; 
    height: 100vh;
    background: rgba(0, 0, 0, 0.7); 
    z-index: 20001;
    justify-content: center; 
    align-items: center;
    opacity: 0; 
    transition: opacity 0.3s ease, visibility 0.3s; /* Обновили transition */
    cursor: auto;
    overflow: hidden;
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
}

#video-record-overlay.show { 
    /* ЗАМЕНИТЕ display: flex; на эти две строчки: */
    visibility: visible;
    pointer-events: auto;
    opacity: 1; 
}

/* Контейнер в виде идеального круга */
.record-circle-container {
    width: 250px; 
    height: 250px;
    border-radius: 50%; /* Делаем круг */
    overflow: hidden; /* Скрываем края видео */
    position: relative;
    border: 4px solid #fff; /* Белая обводка */
    box-shadow: 0 10px 50px rgba(0,0,0,0.8);
    transition: transform 0.1s ease-out;
    background: #000; /* Фон, пока камера загружается */
}

/* Видео предпросмотра внутри круга */
#record-preview {
    width: 100%;
    height: 100%;
    object-fit: cover; 
}

#record-preview.mirrored {
    transform: scaleX(-1);
}

/* Кнопка смены камеры */
.control-btn.switch {
    font-size: 20px;
}

/* Индикатор активной записи (красная пульсирующая точка) */
#record-timer {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: #fff;
    background: rgba(0,0,0,0.5);
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}


#record-timer .dot {
    width: 10px; height: 10px;
    background: #ff4d4d;
    border-radius: 50%;
    animation: pulse-red 1.5s infinite;
}

@keyframes pulse-red {
    0% { box-shadow: 0 0 0 0 rgba(255, 77, 77, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(255, 77, 77, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 77, 77, 0); }
}

/* Адаптация для мобильных */
@media (max-width: 480px) {
    .record-circle-container {
        width: 180px; 
        height: 180px;
    }
}

/* --- СТИЛИ ДЛЯ КНОПОК УПРАВЛЕНИЯ ЗАПИСЬЮ В КРУЖКЕ --- */
/* Обновленные стили контейнера кнопок */
.record-controls {
    display: flex;
    gap: 20px; /* Расстояние между кнопками */
    justify-content: center;
    align-items: center;
    /* Убрали position: absolute, bottom и right */
}

/* Общие стили для кнопок управления */
.control-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%; /* Скругляем */
    background: rgba(0, 0, 0, 0.6); /* Полупрозрачный черный фон */
    color: #fff;
    border: 2px solid #fff; /* Белая обводка */
    font-size: 18px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s ease-in-out;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
}

/* Стили при наведении */
.control-btn:hover {
    background: rgba(0, 0, 0, 0.8);
    transform: scale(1.05); /* Легкое увеличение */
}

/* Стили для кнопки паузы */
.control-btn.pause {
    /* Стили для иконки паузы (||) уже есть */
}

/* Стили для кнопки остановки */
.control-btn.stop {
    color: #ff4d4d; /* Красный цвет иконки "Stop" (■) */
}

/* Стили для состояния паузы (если нужно) */
.control-btn.paused {
    background: rgba(255, 77, 77, 0.5); /* Полупрозрачный красный фон */
    color: #fff;
    border-color: #ff4d4d;
}

/* --- СТИЛИ ДЛЯ СООБЩЕНИЙ-КРУЖОЧКОВ (ПРОЗРАЧНЫЙ ФОН) --- */
.message.circle-message {
    background: transparent !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin-bottom: 15px; /* Немного отступа снизу */
}

/* Красивая полупрозрачная плашка для времени и галочек поверх кружка */
.message.circle-message .meta {
    position: absolute;
    bottom: 5px;
    right: 5px;
    background: rgba(0, 0, 0, 0.4); /* Темная подложка */
    color: white !important;
    padding: 3px 8px;
    border-radius: 12px;
    margin: 0;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 2;
}

/* Убеждаемся, что статус доставки хорошо видно на темном фоне */
.message.circle-message .status-sent {
    color: rgba(255, 255, 255, 0.8) !important;
}

/* --- СТИЛИ ДЛЯ СООБЩЕНИЙ-КРУЖОЧКОВ (ПРОЗРАЧНЫЙ ФОН) --- */
.message.circle-message {
    background: transparent !important; /* Убираем синий/белый фон */
    box-shadow: none !important; /* Убираем тень от квадрата */
    padding: 0 !important; /* Убираем внутренние отступы */
    position: relative;
    width: 180px; 
    height: 180px;
    margin-bottom: 15px;
}

/* Красивая полупрозрачная плашка для времени и галочек поверх кружка */
.message.circle-message .meta {
    position: absolute;
    bottom: 10px;
    right: 50%;
    transform: translateX(50%); /* Центрируем внизу кружка */
    background: rgba(0, 0, 0, 0.4); /* Темная подложка */
    color: white !important;
    padding: 4px 10px;
    border-radius: 12px;
    margin: 0;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Белые галочки на темном фоне для кружков */
.message.circle-message .status-sent,
.message.circle-message .status-read {
    color: white !important;
    margin-left: 2px;
}

/* === АНИМАЦИИ ДЛЯ КРУЖОЧКОВ (TELEGRAM STYLE) === */

/* 1. Пружинистое появление самого окна записи */
.record-circle-container {
    transform: scale(0.4);
    opacity: 0;
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.25), opacity 0.3s ease;
}

#video-record-overlay.show .record-circle-container {
    transform: scale(1);
    opacity: 1;
}

/* Кнопки управления под кружком тоже красиво выезжают снизу */
.record-controls {
    transform: translateY(30px);
    opacity: 0;
    transition: transform 0.4s ease 0.1s, opacity 0.3s ease 0.1s;
}

#video-record-overlay.show .record-controls {
    transform: translateY(0);
    opacity: 1;
}

/* 2. Анимация увеличения кружка при воспроизведении в чате */
.circle-video-player {
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.2) !important;
    position: relative;
    z-index: 1;
}

/* Класс, который JS будет добавлять во время Play */
.circle-video-player.is-playing {
    transform: scale(1.08) !important; /* Увеличиваем на 8% */
    z-index: 10 !important; /* Выводим поверх остальных сообщений */
    box-shadow: 0 10px 25px rgba(0,0,0,0.5) !important; /* Делаем тень глубже */
}

/* --- ПЛАВАЮЩАЯ КНОПКА В САЙДБАРЕ --- */
.sidebar {
    position: relative; /* Чтобы кнопка позиционировалась относительно сайдбара */
}

#sidebar-group-btn {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--gradient-primary);
    color: white;
    border: none;
    font-size: 28px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    z-index: 100; /* Чтобы была выше списка чатов */
    transition: transform 0.2s, box-shadow 0.2s;
}

#sidebar-group-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0,0,0,0.3);
}

#sidebar-group-btn:active {
    transform: scale(0.95);
}
/* --- ПЛАВАЮЩАЯ КНОПКА СОЗДАНИЯ ГРУППЫ В САЙДБАРЕ --- */

/* Делаем сайдбар относительным, чтобы кнопка не улетала за его пределы */
.sidebar {
    position: relative; 
}

#sidebar-group-btn {
    position: absolute; /* Вырываем кнопку из общего списка чатов */
    bottom: 20px;       /* Прижимаем к низу */
    right: 20px;        /* Прижимаем к правому краю */
    
    width: 56px;
    height: 56px;
    border-radius: 50%; /* Делаем идеальный круг */
    
    background: var(--gradient-primary);
    color: white;
    border: none;
    font-size: 28px;
    cursor: pointer;
    
    display: flex;
    align-items: center;
    justify-content: center;
    
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 100; /* Поднимаем над списком чатов */
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    
    /* Сбрасываем возможные стандартные отступы браузера */
    padding: 0;
    margin: 0;
}

/* Эффект при наведении */
#sidebar-group-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}

/* Эффект при клике */
#sidebar-group-btn:active {
    transform: scale(0.95);
}

.sidebar {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden; /* Запрещаем общий скролл сайдбара */
}

.sidebar-header {
    flex-shrink: 0; /* Шапка поиска не сжимается */
}

/* Контейнер для списка чатов */
#chats-container {
    flex: 1;
    overflow-y: auto; /* Разрешаем скролл только списку */
    padding-bottom: 80px; /* Место под кнопку + */
}

/* Стилизация скроллбара (опционально, для красоты) */
#chats-container::-webkit-scrollbar {
    width: 4px;
}
#chats-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}