/* --- ЦВЕТОВЫЕ ТЕМЫ (CSS Variables) --- */
:root {
    --bg-main: #e2e8f0;          /* Фон за пределами панелей */
    --bg-panel: #ffffff;         /* Фон чата и сайдбара */
    --bg-chat: #f0f2f5;          /* Фон зоны сообщений (как в WhatsApp) */
    --bg-hover: #f3f4f6;         /* Эффект наведения */
    --text-main: #111827;        /* Основной текст */
    --text-muted: #6b7280;       /* Вторичный текст */
    --border: #e5e7eb;           /* Границы */
    --accent: #3b82f6;           /* Главный синий цвет */
    --accent-hover: #2563eb;
    --msg-me: #dcf8c6;           /* Цвет моих сообщений */
    --msg-friend: #ffffff;       /* Цвет чужих сообщений */
    --online: #10b981;           /* Зеленый онлайн */
    --offline: #9ca3af;          /* Серый офлайн */
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.dark-theme {
    --bg-main: #0f172a;
    --bg-panel: #1e293b;
    --bg-chat: #0f172a;
    --bg-hover: #334155;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: #334155;
    --accent: #3b82f6;
    --msg-me: #1e3a8a;           /* Темно-синий для моих в темной теме */
    --msg-friend: #1e293b;       /* Темно-серый для чужих */
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body { 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; 
    background-color: var(--bg-main); 
    color: var(--text-main);
    height: 100vh;
    overflow: hidden; /* Убираем скролл всей страницы */
}

/* --- ГЛАВНЫЙ МАКЕТ --- */
.app-container { 
    display: flex; 
    flex-direction: row; /* Слева направо */
    width: 100vw; 
    height: 100vh; 
}

/* --- ЛЕВАЯ ЧАСТЬ: ЗОНА ЧАТА --- */
.chat-area {
    flex: 1; /* Занимает всё свободное место */
    display: flex;
    flex-direction: column;
    background: var(--bg-panel);
    position: relative;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
    padding: 20px;
    background: var(--bg-chat);
}
.empty-icon { font-size: 64px; margin-bottom: 20px; opacity: 0.5; }

#chat-section {
    display: flex; /* Переопределяется скриптом */
    flex-direction: column;
    height: 100%;
}

.chat-header {
    padding: 15px 24px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
}

.chat-title { display: flex; align-items: center; gap: 10px; }
.chat-title h3 { font-size: 16px; margin: 0; }

#chat-box { 
    flex-grow: 1; 
    overflow-y: auto; 
    padding: 20px; 
    display: flex; 
    flex-direction: column; 
    gap: 12px; 
    background: var(--bg-chat);
}

/* Сообщения */
.msg-wrapper { display: flex; flex-direction: column; max-width: 75%; }
.msg-wrapper.me { align-self: flex-end; }
.msg-wrapper.friend { align-self: flex-start; }
.msg-wrapper.system { align-self: center; max-width: 90%; margin: 10px 0;}

.msg { 
    padding: 10px 14px; 
    border-radius: 12px; 
    word-wrap: break-word; 
    font-size: 15px; 
    line-height: 1.4;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    color: var(--text-main);
}
.msg.me { background: var(--msg-me); border-bottom-right-radius: 4px; }
.msg.friend { background: var(--msg-friend); border-bottom-left-radius: 4px; }
.msg.system { background: rgba(0,0,0,0.2); color: var(--text-main); font-size: 12px; text-align: center; border-radius: 12px; box-shadow: none;}

.time { font-size: 11px; color: var(--text-muted); text-align: right; margin-top: 4px; display: block; float: right; margin-left: 10px;}

.input-area { 
    background: var(--bg-panel); 
    padding: 12px 20px; 
    display: flex; 
    gap: 8px; 
    align-items: center; 
    border-top: 1px solid var(--border); 
}
.input-area input[type="text"] { 
    flex-grow: 1; 
    border-radius: 20px; 
    border: 1px solid var(--border); 
    background: var(--bg-main); 
    color: var(--text-main);
    padding: 12px 18px; 
    outline: none;
    transition: 0.2s;
}
.input-area input[type="text"]:focus { border-color: var(--accent); }

.icon-btn { 
    background: none; border: none; font-size: 22px; cursor: pointer; 
    color: var(--text-muted); padding: 8px; border-radius: 50%; transition: 0.2s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--accent); }
.btn-send { color: var(--accent); }

/* --- ПРАВАЯ ЧАСТЬ: САЙДБАР (Контакты) --- */
.sidebar {
    width: 350px;
    min-width: 300px;
    background: var(--bg-panel);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    box-shadow: -2px 0 10px rgba(0,0,0,0.05);
    z-index: 20;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.my-profile { display: flex; align-items: center; gap: 12px; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--accent); color: white; display: flex; align-items: center; justify-content: center; font-weight: bold;}
.my-info h4 { margin: 0; font-size: 15px; }
.status { font-size: 12px; color: var(--text-muted); }
.status.connected { color: var(--online); font-weight: bold;}

.header-controls button {
    background: none; border: none; font-size: 18px; cursor: pointer;
    padding: 8px; border-radius: 8px; transition: 0.2s;
}
.header-controls button:hover { background: var(--bg-hover); }

.add-contact-box { padding: 15px 20px; border-bottom: 1px solid var(--border); background: var(--bg-main);}
.input-group { display: flex; gap: 8px; }
.input-group input { 
    flex-grow: 1; padding: 10px 14px; border-radius: 8px; border: 1px solid var(--border);
    background: var(--bg-panel); color: var(--text-main); outline: none;
}
.btn-main { 
    padding: 0 16px; background: var(--accent); color: white; border: none; 
    border-radius: 8px; cursor: pointer; font-weight: bold; transition: 0.2s; 
}
.btn-main:hover { background: var(--accent-hover); }

/* Список контактов */
.contacts-list { flex-grow: 1; overflow-y: auto; padding: 10px 0; }
.list-title { padding: 0 20px 10px; font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px;}

.contact-item {
    display: flex; align-items: center; padding: 12px 20px; cursor: pointer; transition: 0.2s;
    position: relative;
}
.contact-item:hover { background: var(--bg-hover); }
.contact-item.active { background: var(--bg-hover); border-left: 3px solid var(--accent); }

.contact-avatar { width: 40px; height: 40px; border-radius: 50%; background: #9ca3af; color: white; display: flex; align-items: center; justify-content: center; font-weight: bold; margin-right: 12px;}
.contact-info { display: flex; flex-direction: column; flex-grow: 1; }
.contact-name { font-weight: 600; font-size: 15px; }
.contact-status { font-size: 12px; color: var(--text-muted); }
.online-text { color: var(--online); }

/* Статус "в сети" (кружочки) */
.status-dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--bg-panel); }
.status-dot.online { background: var(--online); }
.status-dot.offline { background: var(--offline); }

/* --- ОСТАЛЬНЫЕ ЭЛЕМЕНТЫ (Звонки, Экран) --- */
#call-banner { 
    display: none; justify-content: space-between; align-items: center; 
    background: var(--online); color: white; padding: 12px 24px; z-index: 10;
}
.btn-end-call { background: #ef4444; color: white; border: none; padding: 8px 16px; border-radius: 8px; cursor: pointer; font-weight: bold;}
.btn-end-call:hover { background: #dc2626; }

#screen-container { /* ... (оставь как было, он позиционирован fixed) ... */ }
@keyframes pulse { 0% { transform: scale(1); } 50% { transform: scale(1.2); } 100% { transform: scale(1); } }