/* Общие настройки страницы */
/* Базовые настройки и темная тема */
:root {
    --bg-color: #0f0f0f;
    --surface-color: #1c1c1d;
    --text-primary: #ffffff;
    --text-secondary: #888888;
    --accent-color: #3390ec;
    --divider-color: #2c2c2e;
    --message-mine: #2b5278;
    --message-other: #1c1c1d;
}

body { 
    margin: 0; 
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; 
    display: flex; 
    height: 100vh; 
    height: 100dvh; /* ИСПРАВЛЕНО: Динамическая высота для мобильных браузеров */
    background-color: var(--bg-color); 
    color: var(--text-primary);
    overflow: hidden;
}

/* Экраны */
.screen { 
    display: none; 
    flex-direction: column; 
    width: 100%; 
    height: 100%;
}

.active-screen { 
    display: flex; 
}

/* Формы авторизации (Адаптированы под темную тему) */
#login-screen, #register-screen, #verify-screen, #forgot-screen {
    align-items: center;
    justify-content: center;
}

.box { 
    background: var(--surface-color); 
    padding: 30px; 
    border-radius: 12px; 
    width: 320px; 
    text-align: center; 
}

.box input { 
    width: 100%; 
    padding: 14px; 
    margin: 8px 0; 
    border: 1px solid var(--divider-color); 
    background: var(--bg-color);
    color: var(--text-primary);
    border-radius: 8px; 
    box-sizing: border-box; 
    outline: none; 
}

.box button { 
    width: 100%; 
    padding: 14px; 
    margin-top: 12px; 
    background: var(--accent-color); 
    color: white; 
    border: none; 
    border-radius: 8px; 
    cursor: pointer; 
    font-size: 16px; 
    font-weight: bold;
}

.box .text-btn { background: none; color: var(--accent-color); font-weight: normal; }
.error-msg { color: #ff3b30; font-size: 13px; margin-top: 10px; }

/* ГЛАВНЫЙ ИНТЕРФЕЙС (Вкладки и навигация) */
#main-header {
    background: var(--surface-color);
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--divider-color);
}

#header-title { margin: 0; font-size: 20px; }

#main-content {
    flex-grow: 1;
    overflow-y: auto;
    position: relative;
}

/* Вкладки */
.app-tab { display: none; flex-direction: column; height: 100%; }
.active-tab { display: flex; }

/* Поиск */
.search-bar-container {
    padding: 10px 15px;
    background: var(--surface-color);
    position: relative;
}

.search-icon {
    position: absolute;
    left: 25px;
    top: 22px;
    color: var(--text-secondary);
}

.search-bar-container input {
    width: 100%;
    padding: 10px 10px 10px 40px;
    border-radius: 10px;
    border: none;
    background: var(--bg-color);
    color: var(--text-primary);
    box-sizing: border-box;
    font-size: 16px;
    outline: none;
}

/* Списки (Чаты и Контакты) */
.list-container {
    list-style: none;
    padding: 0;
    margin: 0;
}

.user-item {
    padding: 10px 15px;
    display: flex;
    align-items: center;
    cursor: pointer;
}

.user-item:hover { background: var(--surface-color); }

.avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3390ec, #0056b3);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: bold;
    margin-right: 15px;
    flex-shrink: 0;
    overflow: hidden; /* Чтобы картинка не вылезала за круг */
}

/* НОВАЯ ВЕРСТКА ЭЛЕМЕНТА ЧАТА */
.item-info { 
    display: flex; 
    flex-grow: 1; 
    border-bottom: 1px solid var(--divider-color); 
    padding-bottom: 12px; 
    padding-top: 12px; 
    justify-content: space-between; 
    overflow: hidden; 
}

.item-text-content {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-grow: 1;
}

.item-name { 
    font-weight: bold; 
    font-size: 16px; 
    margin-bottom: 5px; 
}

.item-last-message { 
    color: var(--text-secondary); 
    font-size: 14px; 
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis; 
}

.item-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    margin-left: 10px;
    min-width: 45px;
}

.item-time {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.unread-badge {
    background: #3390ec;
    color: white;
    font-size: 12px;
    font-weight: bold;
    padding: 3px 8px;
    border-radius: 12px;
    min-width: 10px;
    text-align: center;
}

/* Профиль и Настройки */
.profile-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 30px 20px;
    background: var(--surface-color);
    margin-bottom: 10px;
}

.profile-avatar-large {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: var(--accent-color);
    color: white;
    font-size: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 15px;
}

.menu-list { background: var(--surface-color); }
.menu-item {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid var(--divider-color);
    cursor: pointer;
}

.menu-icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    margin-right: 15px;
}

/* Нижняя панель навигации */
#bottom-nav {
    display: flex;
    justify-content: space-around;
    background: var(--surface-color);
    padding: 10px 0;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); /* ИСПРАВЛЕНО: Отступ для системной полоски */
    border-top: 1px solid var(--divider-color);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--text-secondary);
    font-size: 11px;
    cursor: pointer;
    position: relative;
    width: 60px;
}

.nav-item i { font-size: 20px; margin-bottom: 4px; }
.nav-item.active { color: var(--accent-color); }
.badge {
    position: absolute;
    top: -5px;
    right: 10px;
    background: #ff3b30;
    color: white;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: bold;
}

/* ОКНО АКТИВНОГО ЧАТА */
#active-chat-screen {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg-color);
    z-index: 100;
}

#chat-header-bar {
    background: var(--surface-color);
    padding: 10px 15px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--divider-color);
}

.back-btn { background: none; border: none; color: var(--text-primary); font-size: 20px; cursor: pointer; margin-right: 15px; }
.chat-header-info { display: flex; align-items: center; flex-grow: 1; }
.chat-header-avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--accent-color); color: white; display: flex; align-items: center; justify-content: center; font-weight: bold; margin-right: 12px; }
.chat-header-name { font-weight: bold; font-size: 16px; }
.chat-header-status { font-size: 12px; color: var(--text-secondary); }
.more-btn { background: none; border: none; color: var(--text-primary); font-size: 20px; cursor: pointer; }

#messages-container { 
    flex-grow: 1; 
    overflow-y: auto; 
    padding: 20px; 
    display: flex; 
    flex-direction: column; 
    background-image: url('https://user-images.githubusercontent.com/15075759/28719144-86dc0f70-73b1-11e7-911d-60d70fcded21.png');
    background-color: var(--bg-color);
    background-blend-mode: overlay;
}

.message { 
    max-width: 75%; 
    padding: 10px 15px; 
    border-radius: 15px; 
    margin-bottom: 10px; 
    line-height: 1.4; 
    word-wrap: break-word;
}

.my-message { align-self: flex-end; background: var(--message-mine); border-bottom-right-radius: 4px; }
.other-message { align-self: flex-start; background: var(--surface-color); border-bottom-left-radius: 4px; }

.input-area { 
    padding: 10px 15px; 
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); /* ИСПРАВЛЕНО: Безопасный отступ для поля ввода */
    background: var(--surface-color); 
    display: flex; 
    align-items: center; 
}

.attach-btn, .send-btn { background: none; border: none; color: var(--text-secondary); font-size: 22px; cursor: pointer; padding: 0 10px; }
.send-btn { color: var(--accent-color); }

#msg-input { 
    flex-grow: 1; 
    padding: 12px 18px; 
    border-radius: 20px; 
    border: none; 
    background: var(--bg-color); 
    color: var(--text-primary);
    font-size: 16px; 
    outline: none; 
}
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    padding: 25px 30px;
    border-radius: 12px;
    text-align: center;
    min-width: 250px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

#modal-message {
    margin-bottom: 20px;
    font-size: 16px;
    color: #333;
}

#modal-ok-btn {
    padding: 10px 20px;
    background: #3390ec;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

#modal-ok-btn:hover {
    background: #2b79c7;
}

/* РАЗДЕЛИТЕЛИ ДАТ (Посередине чата) */
.date-divider {
    display: flex;
    justify-content: center;
    margin: 15px 0;
    width: 100%;
}

.date-divider span {
    background: rgba(0, 0, 0, 0.3);
    color: white;
    font-size: 12px;
    font-weight: bold;
    padding: 4px 12px;
    border-radius: 12px;
}

/* ВРЕМЯ И ГАЛОЧКИ ВНУТРИ СООБЩЕНИЯ */
.message-content {
    margin-bottom: 2px;
}

.message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    font-size: 11px;
    color: #8e8e93;
    margin-top: 4px;
    float: right;
    margin-left: 15px;
}

/* Цвет галочек на фоне своих (синих/зеленых) сообщений */
.my-message .message-meta {
    color: #a3c9f1; 
}

.msg-time {
    margin-right: 4px;
}

.msg-ticks i {
    font-size: 10px;
}

/* Две синие галочки для прочитанного */
.read-ticks {
    color: #3390ec !important; /* Яркий синий цвет Telegram */
}

/* Контекстное меню */
.context-menu {
    position: fixed; background: var(--surface-color); border-radius: 8px;
    box-shadow: 0 2px 15px rgba(0,0,0,0.6); padding: 5px 0; z-index: 9999; min-width: 160px;
}
.context-item {
    padding: 12px 15px; font-size: 15px; cursor: pointer; display: flex; align-items: center;
}
.context-item i { margin-right: 12px; font-size: 16px; }
.context-item:hover { background: var(--divider-color); }
.delete-item { color: #ff3b30; }

/* Окно удаления */
.modal-backdrop {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); z-index: 10000; align-items: center; justify-content: center;
}
.delete-modal {
    background: var(--surface-color); padding: 20px; border-radius: 12px; width: 280px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.4);
}
.delete-modal h3 { margin-top: 0; font-size: 16px; font-weight: 500; }
.delete-modal label { display: flex; align-items: center; margin: 15px 0; font-size: 14px; cursor: pointer; }
.delete-modal input[type="checkbox"] { margin-right: 10px; width: 18px; height: 18px; accent-color: var(--accent-color); }
.modal-buttons { display: flex; justify-content: flex-end; gap: 15px; margin-top: 20px; }
.modal-btn { background: none; border: none; font-size: 14px; font-weight: bold; cursor: pointer; padding: 5px 10px; }
.cancel-btn { color: var(--accent-color); }
.delete-confirm-btn { color: #ff3b30; }

/* Анимация исчезновения сообщения */
.message { transition: opacity 0.3s ease, transform 0.3s ease; }

/* === Анимация мигания красной точки записи === */
@keyframes blink {
    0% { opacity: 1; }
    50% { opacity: 0; }
    100% { opacity: 1; }
}

/* === Кнопка микрофона поверх оверлея === */
#record-btn {
    transition: transform 0.1s ease, color 0.2s;
    z-index: 11; /* Чтобы при увеличении была выше панели записи */
    background: transparent;
}

/* === ПЕРЕСЫЛКА СООБЩЕНИЙ === */
.forwarded-msg {
    font-size: 13px;
    color: var(--accent-color);
    margin-bottom: 5px;
    border-left: 2px solid var(--accent-color);
    padding-left: 8px;
    opacity: 0.9;
}

.forward-chat-item {
    display: flex;
    align-items: center;
    padding: 10px;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s;
}

.forward-chat-item:hover {
    background: var(--divider-color);
}