/* --- ЦВЕТОВЫЕ ТЕМЫ (Telegram Dark & Light) --- */
:root {
    /* DARK THEME (DEFAULT) */
    --bg-app: #17212b;
    --bg-header: #17212b;
    --bg-chat-list: #17212b;
    --bg-chat-area: #0e1621;
    --bg-msg-in: #182533;
    --bg-msg-out: #2b5278;
    --text-main: #ffffff;
    --text-sec: #7c8b9d;
    --text-accent: #64b5ef;
    --border: #111921;
    --hover: #202b36;
    --input-bg: #17212b;
    --search-bg: #242f3d;
    --modal-bg: #17212b;
    --scroll-thumb: rgba(255,255,255,0.15);
    --menu-bg: #232e3c;
    --green-call: #00c73e;
    --red-call: #ff5c5c;
    --badge-bg: #64b5ef; 
    --read-color: #4facfe;
    --profile-bg: #0f161e;
    --bg-image: url('https://web.telegram.org/img/bg_0.png');
}

/* LIGHT THEME (СВЕТЛАЯ ТЕМА) */
body.light-mode {
    --bg-app: #ffffff;
    --bg-header: #ffffff;
    --bg-chat-list: #ffffff;
    --bg-chat-area: #86a688; /* Классический зеленый фон ТГ */
    --bg-msg-in: #ffffff;
    --bg-msg-out: #effdde;
    --text-main: #000000;
    --text-sec: #707579;
    --text-accent: #3390ec;
    --border: #dfe1e5;
    --hover: #f4f4f5;
    --input-bg: #ffffff;
    --search-bg: #f1f1f1;
    --modal-bg: #ffffff;
    --scroll-thumb: rgba(0,0,0,0.2);
    --menu-bg: #ffffff;
    --profile-bg: #f1f1f1;
    --bg-image: url('https://web.telegram.org/img/bg_1.png');
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body { 
    font-family: 'Roboto', sans-serif; 
    background-color: var(--bg-app); 
    height: 100dvh; 
    width: 100%; 
    overflow: hidden; 
    color: var(--text-main); 
    position: fixed; 
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* Скроллбар */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 3px; }

/* LAYOUT */
.app-container { display: flex; height: 100%; width: 100%; max-width: 1600px; margin: 0 auto; }
.sidebar { width: 350px; border-right: 1px solid var(--border); display: flex; flex-direction: column; background: var(--bg-chat-list); z-index: 10; position: relative; transition: background 0.2s; }
.chat-area { flex: 1; position: relative; display: flex; flex-direction: column; background: var(--bg-chat-area); background-image: var(--bg-image); background-size: 400px; transition: background 0.2s; }

/* HEADER */
.main-header, .chat-header { 
    height: 56px; padding: 0 10px; 
    background: var(--bg-header); 
    display: flex; align-items: center; gap: 10px; 
    flex-shrink: 0; position: relative; 
    box-shadow: 0 1px 2px rgba(0,0,0,0.1); 
    z-index: 20;
    transition: background 0.2s;
}
.main-header { justify-content: space-between; }
/* touch-action убирает двойной тап (зум) на мобилках */
.header-icons i, .icon-btn { font-size: 20px; color: var(--text-sec); cursor: pointer; padding: 8px; flex-shrink: 0; transition: color 0.2s; touch-action: manipulation; }
.icon-btn:hover { color: var(--text-main); }
.back-btn { display: none; }

/* ПОИСК В БОКОВОЙ ПАНЕЛИ */
.search-bar-box { 
    padding: 10px 12px; 
    flex-shrink: 0; 
    background: var(--bg-chat-list); 
    transition: background 0.2s;
}
.search-wrapper {
    background-color: var(--search-bg);
    border-radius: 20px; 
    display: flex; align-items: center;
    padding: 0 12px; height: 36px;
    transition: 0.2s; border: 1px solid transparent;
}
.search-wrapper:focus-within {
    border-color: var(--text-accent);
    background-color: var(--input-bg);
}
.search-icon { color: var(--text-sec); font-size: 14px; margin-right: 10px; }
.search-input { width: 100%; background: transparent; border: none; outline: none; font-size: 15px; color: var(--text-main); padding: 0; margin: 0; height: 100%; }
.search-input::placeholder { color: var(--text-sec); opacity: 0.7; }

/* ПОИСК В ЧАТЕ */
.chat-search-bar { 
    display: none; position: absolute; top: 0; left: 0; width: 100%; height: 56px; 
    background: var(--bg-header); align-items: center; padding: 0 10px; z-index: 30;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.chat-search-bar.active { display: flex; animation: fadeIn 0.2s ease-out; }
.chat-search-bar input { 
    flex: 1; background: var(--search-bg); border: none; outline: none; 
    color: var(--text-main); font-size: 16px; padding: 8px 15px; border-radius: 20px; margin: 0 10px;
}

/* СПИСКИ ЧАТОВ */
.list-container { flex: 1; overflow-y: auto; padding-bottom: 60px; scrollbar-width: none; }
.list-container::-webkit-scrollbar { display: none; }
.chat-item, .call-item { display: flex; align-items: center; padding: 10px 15px; cursor: pointer; transition: 0.2s; position: relative; }
.chat-item:hover, .call-item:hover { background-color: var(--hover); }
.chat-item.active-chat { background-color: var(--hover); }

.avatar { width: 50px; height: 50px; border-radius: 50%; object-fit: cover; background: #888; margin-right: 12px; flex-shrink: 0; }
.chat-info, .call-info { flex: 1; overflow: hidden; border-bottom: 1px solid var(--border); padding-bottom: 12px; display: flex; flex-direction: column; justify-content: center; }
.chat-name, .call-name { font-weight: 500; font-size: 16px; color: var(--text-main); margin-bottom: 4px; }
.chat-last-msg { font-size: 14px; color: var(--text-sec); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; max-width: 200px; }

/* BADGES (Кружочки непрочитанных) */
.unread-badge {
    background-color: var(--badge-bg); color: #fff; border-radius: 12px; padding: 0 6px;
    font-size: 12px; font-weight: bold; min-width: 20px; height: 20px;
    display: flex; align-items: center; justify-content: center; margin-left: 10px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.3); flex-shrink: 0;
}

/* STORIES */
.stories-container { padding: 10px; display: flex; gap: 15px; overflow-x: auto; scrollbar-width: none; flex-shrink: 0; border-bottom: 1px solid var(--border); }
.stories-container::-webkit-scrollbar { display: none; }
.story-item { display: flex; flex-direction: column; align-items: center; cursor: pointer; min-width: 60px; }
.story-ring { width: 60px; height: 60px; border-radius: 50%; padding: 2px; border: 2px solid var(--text-accent); position: relative; }
.story-ring img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; background: #333; }
.story-add-btn { position: absolute; bottom: 0; right: 0; background: var(--text-accent); color: #fff; width: 20px; height: 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 12px; border: 2px solid var(--bg-chat-list); }
.story-name { font-size: 11px; margin-top: 5px; color: var(--text-main); max-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* СООБЩЕНИЯ */
.messages-box { flex: 1; padding: 10px 15px; overflow-y: auto; display: flex; flex-direction: column; gap: 5px; scroll-behavior: smooth; }
.message { max-width: 80%; padding: 8px 12px; border-radius: 12px; font-size: 15px; position: relative; word-wrap: break-word; color: var(--text-main); box-shadow: 0 1px 1px rgba(0,0,0,0.1); }
.message.in { align-self: flex-start; background: var(--bg-msg-in); border-bottom-left-radius: 0; }
.message.out { align-self: flex-end; background: var(--bg-msg-out); border-bottom-right-radius: 0; }

body.light-mode .message.in { color: #000; }
body.light-mode .message.out { color: #000; }

.message img, .message video:not(.video-circle) { max-width: 100%; border-radius: 8px; margin-top: 5px; }

/* ВРЕМЯ И ГАЛОЧКИ */
.msg-time-block { float: right; display: flex; align-items: center; gap: 4px; margin-top: 6px; margin-left: 8px; height: 14px; }
.msg-time { font-size: 11px; color: rgba(255,255,255,0.5); }
body.light-mode .msg-time { color: #a2a5a9; } 

.msg-check { font-size: 10px; color: rgba(255,255,255,0.5); transition: color 0.2s; }
body.light-mode .msg-check { color: #a2a5a9; }
.msg-check.read { color: var(--read-color) !important; }

/* --- МЕДИА-ЭЛЕМЕНТЫ (Видеокружочки и Голосовые) --- */

/* Нативное голосовое сообщение (адаптация для всех устройств) */
audio {
    max-width: 100%; /* Защита от вылезания за края */
    height: 40px;
    border-radius: 30px;
    outline: none;
    border: none;
    background-color: transparent;
}
/* Легкая стилизация контролов на WebKit (Chrome, Safari) */
audio::-webkit-media-controls-panel {
    background-color: #f0f0f0;
}
body:not(.light-mode) audio::-webkit-media-controls-panel {
    background-color: #d1d5da; /* Чуть темнее для контраста в темной теме */
}

/* Видеокружочки (идеальный круг без артефактов на iOS) */
.video-wrapper { 
    position: relative; 
    width: 220px; 
    height: 220px; 
    margin-top: 5px; 
    border-radius: 50%;
    /* ВАЖНО: Фикс для Safari/iOS чтобы видео не выходило за радиус */
    overflow: hidden; 
    -webkit-mask-image: -webkit-radial-gradient(white, black);
    -webkit-backface-visibility: hidden;
    -moz-backface-visibility: hidden;
}

.video-circle { 
    width: 100%; 
    height: 100%; 
    border-radius: 50%; 
    object-fit: cover; 
    background: #000; 
    cursor: pointer; 
    display: block; 
    border: none;
    outline: none;
}

.video-mute-icon { position: absolute; bottom: 10px; right: 30px; background: rgba(0,0,0,0.6); color: #fff; border-radius: 50%; width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; font-size: 14px; pointer-events: none; }

/* Старые стили (оставлены для совместимости, если есть старые сообщения) */
.audio-msg { display: flex; align-items: center; gap: 10px; min-width: 200px; padding: 5px 0; }
.play-btn { width: 36px; height: 36px; background: var(--text-accent); border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; color: #fff; }

/* ПОЛЕ ВВОДА */
.input-area { background: var(--bg-header); padding: 6px 8px; display: flex; align-items: center; gap: 8px; flex-shrink: 0; transition: background 0.2s; }
.msg-input { flex: 1; min-width: 0; padding: 10px 15px; border: none; outline: none; font-size: 16px; background: var(--bg-app); border-radius: 20px; color: var(--text-main); transition: background 0.2s, color 0.2s; }
.send-btn { color: var(--text-accent); }

/* МЕНЮ ЧАТА */
.header-menu-container { position: relative; }
.chat-dropdown { display: none; position: absolute; top: 45px; right: 0; background: var(--menu-bg); width: 230px; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.2); z-index: 100; padding: 8px 0; overflow: hidden; }
.chat-dropdown.active { display: block; animation: slideDown 0.2s ease; }
.dropdown-item { padding: 12px 20px; display: flex; align-items: center; gap: 15px; cursor: pointer; font-size: 15px; color: var(--text-main); }
.dropdown-item:hover { background: var(--hover); }
.dropdown-item i { width: 20px; text-align: center; color: var(--text-sec); }

/* НИЖНЕЕ МЕНЮ */
.bottom-nav { position: absolute; bottom: 0; left: 0; width: 100%; height: 55px; background: var(--bg-header); display: flex; align-items: center; justify-content: space-around; border-top: 1px solid var(--border); z-index: 20; transition: background 0.2s; }
.nav-item { display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-sec); font-size: 10px; cursor: pointer; flex: 1; height: 100%; }
.nav-item i { font-size: 22px; margin-bottom: 4px; }
.nav-item.active { color: var(--text-accent); }

/* МОДАЛЬНЫЕ ОКНА */
.modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 1000; align-items: center; justify-content: center; backdrop-filter: blur(5px); }
.modal.active { display: flex; animation: fadeIn 0.3s ease; }
.modal-content { background: var(--modal-bg); padding: 25px; border-radius: 12px; width: 350px; max-width: 90%; text-align: center; color: var(--text-main); position:relative; box-shadow: 0 5px 15px rgba(0,0,0,0.3); }
.close-modal-btn { position: absolute; top:10px; right:15px; font-size:24px; cursor:pointer; color: var(--text-sec); }
.btn { width: 100%; padding: 12px; border: none; border-radius: 8px; font-size: 16px; cursor: pointer; margin-top: 10px; font-weight: 500; transition: background 0.2s; }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--text-accent); color: #fff; }
.btn-danger { background: var(--red-call); color: #fff; }
.simple-input { width: 100%; padding: 12px; margin-bottom: 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--input-bg); color: var(--text-main); outline: none; }

/* ЗВОНКИ */
.call-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: #0f1820; z-index: 3000; flex-direction: column; align-items: center; padding-top: 60px; color: #fff; }
.call-overlay.active { display: flex; animation: fadeIn 0.3s ease; }
.call-avatar { width: 120px; height: 120px; border-radius: 50%; object-fit: cover; margin-bottom: 20px; box-shadow: 0 0 20px rgba(0,0,0,0.5); z-index: 2; transition: all 0.3s; }
#remoteVideo { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; z-index: 1; display: none; background: #000; }
#localVideo { position: absolute; top: 20px; right: 20px; width: 100px; height: 140px; background: #333; border-radius: 10px; object-fit: cover; z-index: 3; border: 2px solid rgba(255,255,255,0.2); display: none; transform: scaleX(-1); }
.call-status { color: var(--text-sec); font-size: 14px; margin-top: 10px; z-index: 2; text-shadow: 0 1px 2px #000; }
.call-name-large { font-size: 24px; font-weight: 500; z-index: 2; text-shadow: 0 1px 2px #000; }
.call-buttons { position: absolute; bottom: 50px; width: 100%; display: flex; justify-content: center; gap: 30px; z-index: 10; }
.call-btn-round { width: 60px; height: 60px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 24px; cursor: pointer; color: #fff; background: rgba(255,255,255,0.1); }
.btn-end-call { background: var(--red-call); transform: rotate(135deg); }

/* ВХОДЯЩИЙ ЗВОНОК */
.incoming-call-modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.85); z-index: 4000; align-items: center; justify-content: center; flex-direction: column; }
.incoming-call-modal.active { display: flex; }
.incoming-card { text-align: center; width: 100%; padding: 20px; animation: slideUp 0.3s ease-out; }
.incoming-avatar { width: 120px; height: 120px; border-radius: 50%; object-fit: cover; margin-bottom: 15px; border: 3px solid var(--bg-app); box-shadow: 0 0 20px rgba(0,0,0,0.5); }
.incoming-name { font-size: 26px; font-weight: bold; color: var(--text-main); margin-bottom: 5px; }
.incoming-text { color: var(--text-sec); margin-bottom: 60px; font-size: 16px; }
.incoming-actions { display: flex; justify-content: space-around; width: 80%; margin: 0 auto; }
.btn-answer { background: var(--green-call); color: #fff; border-radius: 50%; width: 70px; height: 70px; display: flex; align-items: center; justify-content: center; font-size: 30px; cursor: pointer; animation: pulseCall 1.5s infinite; }
.btn-decline { background: var(--red-call); color: #fff; border-radius: 50%; width: 70px; height: 70px; display: flex; align-items: center; justify-content: center; font-size: 30px; cursor: pointer; transform: rotate(135deg); }

@keyframes pulseCall { 0% { box-shadow: 0 0 0 0 rgba(0, 199, 62, 0.7); } 70% { box-shadow: 0 0 0 20px rgba(0, 199, 62, 0); } 100% { box-shadow: 0 0 0 0 rgba(0, 199, 62, 0); } }
@keyframes slideUp { from { transform: translateY(50px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes slideDown { from { transform: translateY(-10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.call-icon-type { font-size: 14px; margin-right: 5px; }
.call-incoming { color: var(--text-main); transform: rotate(135deg); }
.call-outgoing { color: var(--green-call); transform: rotate(45deg); }
.call-missed { color: var(--red-call); transform: rotate(135deg); }
.call-btn-list { padding: 10px; color: var(--green-call); font-size: 22px; }

/* STICKERS */
.sticker-btn { font-size: 20px; color: var(--text-sec); padding: 10px; cursor: pointer; transition: color 0.2s; touch-action: manipulation;}
.sticker-btn:hover, .sticker-btn.active { color: var(--text-accent); }
.sticker-picker {
    display: none; position: absolute; bottom: 60px; left: 10px; width: 320px; max-width: 95%; height: 250px;
    background: var(--bg-header); backdrop-filter: blur(10px); border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.5); z-index: 50; overflow-y: auto; padding: 10px;
    grid-template-columns: repeat(4, 1fr); gap: 8px; border: 1px solid var(--border);
}
.sticker-picker.active { display: grid; animation: slideUp 0.2s ease-out; }
.sticker-option { width: 100%; height: auto; cursor: pointer; transition: transform 0.1s; }
.sticker-option:active { transform: scale(0.9); }
.message.sticker-msg { background: transparent !important; box-shadow: none !important; padding: 0 !important; }
.sticker-img-chat { width: 160px; height: auto; display: block; margin-bottom: 5px; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.3)); }

/* АДАПТАЦИЯ (МОБИЛЬНЫЕ УСТРОЙСТВА) */
@media (max-width: 768px) {
    .sidebar { width: 100%; height: 100%; position: absolute; }
    .chat-area { width: 100%; height: 100%; position: absolute; transform: translateX(100%); transition: transform 0.25s ease-out; z-index: 20; }
    .app-container.chat-open .chat-area { transform: translateX(0); }
    .back-btn { display: block; margin-right: 5px; }
    .input-area { padding: 6px 8px; gap: 6px; }
    .msg-input { font-size: 16px; padding: 8px 12px; }
    .icon-btn { padding: 8px; font-size: 22px; }
    .sticker-picker { width: 95%; left: 2.5%; bottom: 65px; }
}

@media (max-width: 400px) {
    /* На очень маленьких экранах видео чуть меньше */
    .video-wrapper { width: 200px; height: 200px; }
}

/* LOGIN */
.login-body { display: flex; align-items: center; justify-content: center; height: 100%; width: 100%; background-color: var(--bg-chat-area); background-image: var(--bg-image); background-size: 400px; }
.login-card { background: var(--bg-header); padding: 40px; border-radius: 15px; width: 350px; max-width: 90%; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,0.5); animation: slideUp 0.3s ease-out; }

/* PROFILE (NEW STYLE) */
.profile-body { display: flex; align-items: center; justify-content: center; height: 100%; width: 100%; background-color: var(--profile-bg); transition: background 0.2s; }
.profile-card { width: 100%; max-width: 600px; height: 100%; background: var(--bg-app); display: flex; flex-direction: column; overflow-y: auto; padding: 0; border-radius: 0; box-shadow: none; transition: background 0.2s; }
@media (min-width: 600px) { .profile-card { border-right: 1px solid var(--border); border-left: 1px solid var(--border); } }
.profile-header { display: flex; align-items: center; padding: 15px; background: var(--bg-header); flex-shrink: 0; z-index: 10; transition: background 0.2s; }
.profile-hero { display: flex; flex-direction: column; align-items: center; padding: 30px 0; background: var(--bg-header); transition: background 0.2s; }
.profile-avatar-container { position: relative; width: 120px; height: 120px; margin-bottom: 20px; cursor: pointer; }
.profile-avatar-img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.avatar-overlay { position: absolute; top:0; left:0; width:100%; height:100%; background:rgba(0,0,0,0.5); border-radius:50%; display:flex; align-items:center; justify-content:center; opacity:0; transition:0.2s; color:#fff; font-size:24px; }
.profile-avatar-container:hover .avatar-overlay { opacity: 1; }
.profile-name { font-size: 24px; font-weight: 500; color: var(--text-main); margin-bottom: 5px; }
.profile-status { font-size: 16px; color: var(--text-sec); }
.profile-actions { display: flex; justify-content: center; gap: 40px; padding: 20px 0; background: var(--bg-header); margin-bottom: 10px; transition: background 0.2s; }
.action-btn-col { display: flex; flex-direction: column; align-items: center; cursor: pointer; }
.action-icon { width: 50px; height: 50px; border-radius: 50%; background: var(--hover); display: flex; align-items: center; justify-content: center; font-size: 22px; color: var(--text-accent); margin-bottom: 8px; transition: 0.2s; }
.action-icon:hover { background: var(--input-bg); }
.action-label { font-size: 12px; color: var(--text-accent); }
.profile-info-list { background: var(--bg-header); padding: 5px 0; transition: background 0.2s; }
.info-item { display: flex; align-items: center; padding: 12px 20px; cursor: pointer; border-bottom: 1px solid var(--border); }
.info-item:last-child { border-bottom: none; }
.info-icon { width: 40px; font-size: 22px; color: var(--text-sec); text-align: left; }
.info-content { flex: 1; display: flex; flex-direction: column; }
.info-value { font-size: 16px; color: var(--text-main); background: transparent; border: none; outline: none; width: 100%; }
.info-label { font-size: 13px; color: var(--text-sec); margin-top: 2px; }
.save-btn-float { position: fixed; bottom: 20px; right: 20px; width: 60px; height: 60px; border-radius: 50%; background: var(--text-accent); color: #fff; font-size: 24px; display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 10px rgba(0,0,0,0.3); cursor: pointer; display: none; z-index: 100; }
.save-btn-float.visible { display: flex; animation: slideUp 0.3s; }

/* --- ПРИКРЕПЛЕННЫЕ ФАЙЛЫ (Документы, Архивы, Текст) --- */
.file-msg {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 10px;
    min-width: 220px;
    max-width: 300px;
    margin-top: 5px;
}

body.light-mode .file-msg {
    background: rgba(0, 0, 0, 0.05);
}

.file-icon {
    width: 44px;
    height: 44px;
    background: var(--text-accent);
    color: #fff;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}

.file-info {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.file-name {
    font-weight: 500;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-main);
}

.file-ext {
    font-size: 12px;
    color: var(--text-sec);
    text-transform: uppercase;
    margin-top: 2px;
}

.file-download {
    color: var(--text-sec);
    font-size: 20px;
    cursor: pointer;
    transition: 0.2s;
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-download:hover {
    color: var(--text-accent);
}

/* --- КАСТОМНЫЙ АУДИОПЛЕЕР (КАК В TELEGRAM) --- */
.custom-audio-player {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 2px 0;
    min-width: 220px;
    max-width: 280px;
    margin-top: 5px;
}

/* Кнопка Play/Pause */
.play-pause-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--text-accent); /* Синий цвет тг */
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    cursor: pointer;
    flex-shrink: 0;
    transition: 0.2s;
}
.play-pause-btn:active {
    transform: scale(0.9);
}

/* Блок с информацией */
.audio-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
}

/* Название песни (если есть) */
.audio-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-main);
    margin-bottom: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Полоса прогресса */
.audio-progress-container {
    width: 100%;
    height: 3px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    cursor: pointer;
    position: relative;
    margin-bottom: 6px;
}
body.light-mode .audio-progress-container {
    background: rgba(0, 0, 0, 0.15);
}

/* Заполнение полосы прогресса */
.audio-progress-bar {
    height: 100%;
    width: 0%;
    background: var(--text-accent);
    border-radius: 2px;
    pointer-events: none;
    position: relative;
}

/* Кружочек на конце полосы прогресса */
.audio-progress-bar::after {
    content: '';
    position: absolute;
    right: -4px;
    top: -3px;
    width: 9px;
    height: 9px;
    background: var(--text-accent);
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.2s;
}
.custom-audio-player.playing .audio-progress-bar::after {
    opacity: 1; /* Показываем кружочек только при воспроизведении */
}

/* Невидимая зона для удобного тапа по таймлайну */
.audio-progress-container::before {
    content: '';
    position: absolute;
    top: -10px; bottom: -10px; left: 0; right: 0;
}

/* Время */
.audio-time {
    font-size: 12px;
    color: rgba(255,255,255,0.6);
}
body.light-mode .audio-time {
    color: rgba(0,0,0,0.5);
}

/* Скрываем стандартный аудио-тег */
.custom-audio-player audio {
    display: none;
}

/* --- ГАРАНТИРОВАННЫЕ СТИЛИ ДЛЯ ИДЕАЛЬНЫХ ВИДЕОКРУЖОЧКОВ --- */
.video-preview-box { width: 250px; height: 250px; border-radius: 50%; overflow: hidden; margin: 0 auto 20px; border: 4px solid var(--text-accent); background: #000; position: relative; -webkit-mask-image: -webkit-radial-gradient(white, black); display: flex; justify-content: center; align-items: center; }
.video-preview-box video { width: 100%; height: 100%; object-fit: cover !important; transform: scaleX(-1); }
.video-msg-wrapper { position: relative; width: 240px; height: 240px; border-radius: 50%; overflow: hidden; margin: 5px 0; -webkit-mask-image: -webkit-radial-gradient(white, black); background: #000; cursor: pointer; box-shadow: 0 2px 5px rgba(0,0,0,0.3); }
.video-msg-wrapper video { width: 100%; height: 100%; object-fit: cover !important; display: block; }
.video-mute-icon { position: absolute; bottom: 20px; right: 40px; background: rgba(0,0,0,0.6); color: #fff; border-radius: 50%; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; font-size: 14px; pointer-events: none; z-index: 10; }
@media (max-width: 400px) { .video-msg-wrapper { width: 200px; height: 200px; } .video-mute-icon { right: 30px; } }

/* --- НОВЫЙ ФУНКЦИОНАЛ (Контекстное меню, Ответы, Выделение) --- */
.msg-context-menu {
    display: none; position: absolute; background: var(--menu-bg); border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3); z-index: 1000; min-width: 180px; overflow: hidden;
}
.msg-context-menu.active { display: block; animation: fadeIn 0.15s ease; }
.msg-context-menu .menu-item {
    padding: 12px 15px; display: flex; align-items: center; gap: 12px; cursor: pointer; color: var(--text-main); font-size: 14px;
}
.msg-context-menu .menu-item:hover { background: var(--hover); }

/* Выделение сообщений */
.message.selected { background: rgba(100, 181, 239, 0.3) !important; position: relative; }
.message.selected::after {
    content: '\f00c'; font-family: 'Font Awesome 6 Free'; font-weight: 900;
    position: absolute; right: -25px; top: 50%; transform: translateY(-50%);
    color: var(--text-accent); font-size: 18px;
}

/* Панель массовых действий */
.selection-bar {
    position: absolute; top: 0; left: 0; width: 100%; height: 56px;
    background: var(--bg-header); display: none; align-items: center; padding: 0 15px;
    z-index: 40; box-shadow: 0 2px 5px rgba(0,0,0,0.2); gap: 20px;
}
.selection-bar.active { display: flex; animation: slideDown 0.2s ease; }
.selection-bar i { font-size: 20px; color: var(--text-sec); cursor: pointer; }
.selection-bar i:hover { color: var(--text-main); }
.selection-count { font-size: 18px; font-weight: 500; flex: 1; color: var(--text-main); }

/* Блок предпросмотра ответа над инпутом */
.reply-preview-box {
    display: none; background: var(--bg-app); padding: 8px 15px; border-top: 1px solid var(--border);
    align-items: center; gap: 10px; position: absolute; bottom: 100%; left: 0; width: 100%;
}
.reply-preview-box.active { display: flex; }
.reply-preview-box i { color: var(--text-accent); font-size: 20px; }
.reply-content { border-left: 2px solid var(--text-accent); padding-left: 8px; flex: 1; overflow: hidden; }
.reply-name { font-size: 13px; font-weight: 500; color: var(--text-accent); }
.reply-text { font-size: 13px; color: var(--text-sec); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Дизайн Ответа и Пересылки ВНУТРИ сообщения */
.msg-reply-block {
    border-left: 2px solid var(--text-accent); padding-left: 6px; margin-bottom: 5px;
    background: rgba(0,0,0,0.1); border-radius: 4px; font-size: 13px; padding-top: 2px; padding-bottom: 2px;
}
body.light-mode .msg-reply-block { background: rgba(255,255,255,0.4); }
.msg-reply-name { font-weight: 500; color: var(--text-accent); margin-bottom: 2px; }
.msg-forward-block { font-size: 13px; color: var(--text-sec); margin-bottom: 5px; }

/* Метка "изменено" */
.msg-edited-tag { font-size: 10px; color: rgba(255,255,255,0.4); margin-right: 4px; }
body.light-mode .msg-edited-tag { color: rgba(0,0,0,0.4); }

/* 1. Делаем запасной вариант высоты для мобилок */
body {
    height: 100dvh; 
    height: calc(var(--vh, 1vh) * 100); /* Подключаем умную высоту из JS */
}

/* 2. Жестко ограничиваем зону чата */
.chat-area {
    height: 100%;
    max-height: 100%;
    overflow: hidden; /* Не дает интерфейсу разъезжаться */
}

/* 3. Магический фикс Flexbox (min-height: 0) не дает сообщениям выдавить панель */
.messages-box {
    flex: 1 1 auto;
    min-height: 0; 
    overflow-y: auto;
}

/* 4. Запрещаем панели ввода сжиматься или исчезать */
.input-area {
    flex-shrink: 0; 
    z-index: 50; /* Держим поверх остальных элементов */
}

/* --- РЕАКЦИИ НА СООБЩЕНИЯ --- */
.reaction-strip {
    display: flex;
    padding: 10px 15px;
    gap: 15px;
    background: var(--menu-bg);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none; /* Убирает скроллбар */
}
.reaction-strip::-webkit-scrollbar { display: none; }
.reaction-strip span {
    font-size: 24px;
    cursor: pointer;
    transition: transform 0.2s;
}
.reaction-strip span:active { transform: scale(0.7); }

.message-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 5px;
    margin-bottom: -4px;
}
.reaction-bubble {
    background: rgba(0,0,0,0.25);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    border: 1px solid transparent;
    transition: 0.2s;
}
.reaction-bubble.me {
    border-color: var(--text-accent);
    background: rgba(100, 181, 239, 0.25);
}
body.light-mode .reaction-bubble { background: rgba(0,0,0,0.08); }
body.light-mode .reaction-bubble.me { background: rgba(51, 144, 236, 0.15); }

/* --- РЕАКЦИИ НА СТОРИС --- */
.story-reaction-bar {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 20px;
    z-index: 5015;
    background: rgba(0,0,0,0.4);
    padding: 10px 25px;
    border-radius: 30px;
    backdrop-filter: blur(8px);
}
.story-reaction-bar span {
    font-size: 28px;
    cursor: pointer;
    transition: 0.2s;
}
.story-reaction-bar span:active { transform: scale(0.6); }

/* Анимация всплывающего сердца в сторис */
@keyframes floatUpReaction {
    0% { opacity: 1; transform: translate(-50%, -50%) scale(0.5); }
    50% { transform: translate(-50%, -150%) scale(1.5); }
    100% { opacity: 0; transform: translate(-50%, -250%) scale(1); }
}

/* =========================================
   ИСПРАВЛЕНИЕ: ВЫПАДАЮЩЕЕ МЕНЮ (ТРИ ТОЧКИ В ШАПКЕ)
   ========================================= */
.header-menu-container {
    position: relative; /* Опорная точка для меню */
}

.chat-dropdown {
    display: none; /* ВАЖНО: Скрываем меню по умолчанию */
    position: absolute;
    top: 45px; /* Сдвигаем вниз под шапку */
    right: 15px; /* Прижимаем вправо */
    background: var(--menu-bg, #233040); /* Цвет фона меню */
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.4);
    min-width: 200px;
    z-index: 2000;
    flex-direction: column;
    overflow: hidden;
}

/* Класс, который JS добавляет при клике */
.chat-dropdown.active {
    display: flex;
    animation: fadeIn 0.15s ease-in-out;
}

.dropdown-item {
    padding: 12px 16px;
    color: var(--text-main, #ffffff);
    font-size: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background 0.2s;
}

.dropdown-item:hover {
    background: rgba(255,255,255,0.1);
}

/* Цвета меню для светлой темы */
body.light-mode .chat-dropdown {
    background: #ffffff;
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
}
body.light-mode .dropdown-item {
    color: #000000;
}
body.light-mode .dropdown-item:hover {
    background: rgba(0,0,0,0.05);
}

/* =========================================
   ИСПРАВЛЕНИЕ: ОГРОМНЫЕ СТИКЕРЫ В ЧАТЕ
   ========================================= */
.sticker-img-chat {
    max-width: 140px; /* Жестко ограничиваем размер стикера */
    max-height: 140px;
    object-fit: contain;
    background: transparent !important;
    border: none !important;
}

/* Убираем фон-пузырь у самого сообщения со стикером (как в ТГ) */
.message.sticker-msg {
    background: transparent !important;
    box-shadow: none !important;
    padding: 0 !important;
}

/* --- СТИЛИ ДЛЯ ПРОФИЛЯ ПОЛЬЗОВАТЕЛЯ --- */
.profile-modal-content { padding: 0; overflow: hidden; max-width: 360px; border-radius: 15px; }
.profile-header { background: var(--menu-bg); padding: 30px 20px 20px; text-align: center; border-bottom: 1px solid var(--border); }
.up-avatar { width: 120px; height: 120px; border-radius: 50%; object-fit: cover; margin-bottom: 15px; border: 3px solid var(--text-accent); background: #fff; }
.profile-header h2 { margin: 0; color: var(--text-main); font-size: 22px; font-weight: 600; }
.up-phone { color: var(--text-sec); margin-top: 5px; font-size: 15px; }
.profile-body { padding: 25px 20px; background: var(--bg-app); }
.profile-info-block { display: flex; align-items: center; gap: 15px; margin-bottom: 25px; }
.profile-info-block i { font-size: 24px; color: var(--text-accent); width: 30px; text-align: center; }
.profile-info-text { display: flex; flex-direction: column; }
.profile-info-text span { color: var(--text-main); font-size: 16px; word-break: break-word; line-height: 1.4; }
.profile-info-text small { color: var(--text-sec); font-size: 13px; margin-top: 4px; }

/* --- СТИЛИ ДЛЯ ИМЕН В ГРУППАХ --- */
.group-in-msg {
    padding-top: 5px !important; 
}
.msg-sender-info {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 5px;
    padding-bottom: 5px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
body.light-mode .msg-sender-info {
    border-bottom: 1px solid rgba(0,0,0,0.05);
}
.msg-sender-ava {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    object-fit: cover;
}
.msg-sender-name {
    font-size: 13px;
    font-weight: 600;
}