/* === ОБНУЛЕНИЕ И БАЗОВЫЕ СТИЛИ === */
* { 
    margin: 0; 
    padding: 0;
    box-sizing: border-box;}

:root {
  --primary-color: #007bff;
  --secondary-color: #6c757d;
  --success-color: #28a745;
  --danger-color: #dc3545;
  --light-bg: #f8f9fa;
  --border-color: #dee2e6;
  --text-color: #212529;
  --shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
  --android-lime: #9ACD32; 
  --chat-bg: #f0f2f5;
  --input-blur-bg: rgba(255, 255, 255, 0.7); /* Более прозрачный фон */
}

html, body { 
    width: 100%; 
    height: 100%; 
    overflow: hidden; /* Запрещаем общий скролл страницы */
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

body { 
    background-color: #fff; 
    color: var(--text-color); 
    -webkit-tap-highlight-color: transparent; 
}

.hidden { display: none !important; }

/* === КАСТОМНЫЙ ТОНКИЙ СКРОЛЛБАР (КАК НА СКРИНЕ) === */
::-webkit-scrollbar {
    width: 5px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.25);
}

/* === АВАТАРКИ (ВСЕ ТИПЫ) === */
.mini-avatar, .header-avatar, .chat-list-avatar, .search-avatar, .settings-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    margin-right: 12px;
    flex-shrink: 0;
}
.chat-list-avatar { width: 48px; height: 48px; }
.mini-avatar { width: 35px; height: 35px; }
.settings-avatar {
    width: 100px;
    height: 100px;
    border: 3px solid var(--primary-color);
    margin: 0 auto 15px;
    display: block;
}

.letter-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    text-transform: uppercase;
    user-select: none;
}

.mini-avatar.letter-avatar { font-size: 16px; }
.header-avatar.letter-avatar { font-size: 18px; }
.chat-list-avatar.letter-avatar { font-size: 22px; }
.search-avatar.letter-avatar { font-size: 18px; }
.settings-avatar.letter-avatar { font-size: 40px; }

.profile-header-click { display: flex; align-items: center; cursor: pointer; }

/* === АВТОРИЗАЦИЯ === */
.container { width: 100%; height: 100vh; }
#auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-color), #0056b3);
}
.auth-wrapper { width: 100%; max-width: 400px; padding: 20px; }
.auth-form { background: white; padding: 40px; border-radius: 12px; box-shadow: var(--shadow); }
.auth-form h1 { text-align: center; margin-bottom: 20px; color: var(--primary-color); font-size: 28px; }
.auth-form p { color: var(--secondary-color); font-size: 14px; margin-bottom: 15px; text-align: center; line-height: 1.4; }

#recaptcha-container { margin: 10px 0; display: flex; justify-content: center; }

.input {
    width: 100%;
    padding: 12px;
    margin-bottom: 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.3s;
    outline: none;
}
.input:focus { border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1); }
.input-code { text-align: center; letter-spacing: 5px; font-size: 22px; font-weight: bold; }

.btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
    margin-top: 5px;
}
.btn-primary { background-color: var(--primary-color); color: white; }
.btn-primary:hover { background-color: #0056b3; }
.btn-primary:disabled { background-color: var(--secondary-color); cursor: not-allowed; opacity: 0.7; }
.btn-link {
    background: none;
    color: var(--primary-color);
    text-decoration: underline;
    padding: 10px;
    font-size: 13px;
    margin-top: 10px;
    width: 100%;
}

.error-message {
    margin-top: 15px;
    padding: 12px;
    background-color: #f8d7da;
    color: #721c24;
    border-radius: 6px;
    display: none;
    font-size: 13px;
    word-break: break-word;
}
.error-message.show { display: block; }

/* === МЕССЕНДЖЕР (ОСНОВНАЯ СЕТКА) === */
.messenger {
    display: flex;
    width: 100vw;
    height: 100vh;
    background-color: var(--light-bg);
    position: relative;
    overflow: hidden;
}

.sidebar {
    width: 350px;
    background: white;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.08);
    transition: transform 0.3s ease;
    z-index: 20;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 15px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.sidebar-header h2 { font-size: 20px; color: var(--text-color); }
.header-buttons { display: flex; gap: 8px; }
.btn-icon {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    transition: background-color 0.3s;
}
.btn-icon:hover { background-color: var(--light-bg); }

.input-search {
    margin: 12px;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    width: calc(100% - 24px);
    outline: none;
}
.users-list-container { border-bottom: 1px solid var(--border-color); background: white; }
.users-list { max-height: 250px; overflow-y: auto; }

.user-item, .chat-item {
    padding: 12px 15px;
    cursor: pointer;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}
.user-item:hover, .chat-item:hover { background-color: var(--light-bg); }
.chat-item.active { background-color: rgba(0, 123, 255, 0.1); border-left: 4px solid var(--primary-color); }

.chat-info-block { flex: 1; min-width: 0; }
.chat-header-info { display: flex; justify-content: space-between; align-items: center; }
.chat-username { font-weight: 600; font-size: 14px; color: var(--text-color); }
.chat-time { font-size: 11px; color: var(--secondary-color); }
.chat-preview {
    font-size: 13px;
    color: var(--secondary-color);
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chats-list { flex: 1; overflow-y: auto; }

/* === ОКНО ЧАТА (СТАБИЛЬНЫЙ FLEX) === */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    
}

.no-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--secondary-color);
}
.no-chat-icon { font-size: 60px; margin-bottom: 15px; }

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    overflow: hidden;
    position: relative;
}

/* ФОН ДИАЛОГА (СВЕТЛЫЙ) */
.chat-container::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image: url('/backgrounds/light_bg.jpg');
    background-size: cover;
    background-position: center;
    z-index: 0;
}

.chat-header, .chat-input-area, .messages-list { position: relative; z-index: 1; }

.chat-header {
    padding: 10px 15px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.9);
    z-index: 5;
    flex-shrink: 0;
}
.chat-info h3 { margin: 0; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { font-size: 12px; color: var(--secondary-color); }
.status.online { color: var(--success-color); }
.btn-back-mobile {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    margin-right: 15px;
    color: var(--primary-color);
}

/* === СПИСОК СООБЩЕНИЙ === */
.messages-list {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    /* ПРАВИЛЬНЫЙ ОТСТУП СНИЗУ:
       чтобы сообщения не прятались за прозрачной строкой ввода */
    padding-bottom: 85px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background-color: transparent !important;
}

.message { display: flex; flex-direction: column; max-width: 75%; }
.message:not(.own) { align-self: flex-start; }
.message.own { align-self: flex-end; }
.message-bubble {
    padding: 8px 12px;
    border-radius: 12px;
    word-break: break-word;
    line-height: 1.4;
    box-shadow: 0 1px 1px rgba(0,0,0,0.1);
}
.message:not(.own) .message-bubble { background: white; color: black; border-top-left-radius: 2px; }
.message.own .message-bubble { background: #dcf8c6; color: black; border-top-right-radius: 2px; }
.message-time { font-size: 10px; color: #888; margin-top: 2px; align-self: flex-end; }

.message-file img, .message-file video { max-width: 100%; border-radius: 8px; display: block; margin-bottom: 5px; }
.file-link { color: var(--primary-color); text-decoration: none; font-size: 13px; font-weight: 500; display: block; padding: 5px 0; }

/* === БЛОК ВВОДА (ПРОЗРАЧНЫЙ ANDROID STYLE) === */
.chat-input-area {
    width: 100%;
    padding: 10px 15px 15px;
    background: transparent;
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    flex-shrink: 0;
    z-index: 100;
    pointer-events: none; /* Пропускаем клики сквозь прозрачный фон к сообщениям */
}

.floating-input-container {
    pointer-events: auto; /* Возвращаем клики самому полю */
    display: flex;
    align-items: center;
    gap: 5px;
    background: var(--input-blur-bg);
    backdrop-filter: blur(15px); /* Эффект матового стекла */
    -webkit-backdrop-filter: blur(15px);
    border-radius: 28px;
    padding: 5px 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    width: 100%;
}

/* Полный сброс рамок и фонов у иконок (БЕЗ КОРОБОК) */
.btn-input-icon {
    width: 40px;
    height: 40px;
    background: transparent !important;
    border: none !important;
    outline: none !important;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 24px;
    flex-shrink: 0;
    color: #888;
    padding: 0;
    margin: 0;
    box-shadow: none !important;
    appearance: none;
    -webkit-appearance: none;
}
.btn-input-icon:active { opacity: 0.6; }

.message-input-android {
    flex: 1;
    height: 44px;
    border: none !important;
    background: transparent !important;
    padding: 0 5px;
    font-size: 16px;
    outline: none !important;
    color: black;
    min-width: 0;
}

.btn-send-android {
    color: var(--android-lime) !important;
    font-weight: bold;
}

/* Эмодзи пикер — ФИКСАЦИЯ НАЖАТИЙ ДЛЯ МОБИЛОК */
.emoji-picker-container {
    display: none;
    position: absolute;
    bottom: 75px;
    left: 15px;
    z-index: 1000;
    box-shadow: 0 5px 25px rgba(0,0,0,0.2);
    border-radius: 12px;
    overflow: hidden;
    background: white;
    pointer-events: auto !important; /* ВАЖНО: разрешаем клики по смайликам */
}
emoji-picker { width: 340px; height: 400px; --border-radius: 12px; }

/* === НАСТРОЙКИ (ПОЛНЫЙ ИСПРАВЛЕННЫЙ СТИЛЬ) === */
.modal-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
    backdrop-filter: blur(5px);
}
.settings-card {
    background: white;
    padding: 25px;
    border-radius: 20px;
    width: 90%;
    max-width: 380px;
    box-shadow: 0 15px 40px rgba(0,0,0,0.3);
    position: relative;
}
.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}
.settings-header h3 { font-size: 20px; }
.btn-close-settings {
    background: #f0f2f5;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.user-profile-info { text-align: center; margin-bottom: 25px; }
.avatar-upload-wrapper { position: relative; width: 100px; height: 100px; margin: 0 auto 15px; }
.edit-avatar-badge {
    position: absolute;
    bottom: 0; right: 0;
    background: var(--primary-color);
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid white;
    cursor: pointer;
    font-size: 14px;
}

.settings-options { border-top: 1px solid var(--border-color); padding-top: 20px; margin-bottom: 20px; }
.option-item { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; font-size: 15px; }

.theme-switch { position: relative; display: inline-block; width: 46px; height: 24px; }
.theme-switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 24px;
}
.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}
input:checked + .slider { background-color: var(--primary-color); }
input:checked + .slider:before { transform: translateX(22px); }

.btn-logout-new {
    background: #fff0f0;
    color: #ff4444;
    border: 1px solid #ffe0e0;
    margin-bottom: 10px;
    width: 100%;
    padding: 12px;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
}
.btn-back-to-chat {
    background: var(--light-bg);
    border: none;
    width: 100%;
    padding: 12px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 14px;
    color: var(--secondary-color);
}

/* === ТЕМНАЯ ТЕМА (DEEP DARK) === */
body.dark-theme { background-color: #0b141a; color: #e9edef; }

.dark-theme .chat-container::before {
    background-image: url('/backgrounds/dark_bg.jpg');
    opacity: 1;
}

.dark-theme .sidebar,
.dark-theme .chat-header,
.dark-theme .auth-form,
.dark-theme .settings-card,
.dark-theme .users-list-container {
    background-color: #1e1e1e;
    border-color: #333;
    color: #e9edef;
}

.dark-theme .main-content,
.dark-theme .messages-list {
    background-color: transparent !important;
}

.dark-theme .no-chat {
    background-color: #0b141a !important;
}

/* Тонкий скроллбар для темной темы */
.dark-theme ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
}

.dark-theme .input,
.dark-theme .input-search {
    background-color: #2a3942;
    border: none;
    color: white;
}

/* Прозрачный блок ввода для темной темы */
.dark-theme .chat-input-area {
    background: transparent;
}
.dark-theme .floating-input-container {
    background-color: rgba(42, 57, 66, 0.7);
    border: 1px solid rgba(255,255,255,0.1);
}

.dark-theme .message-input-android { color: white; }
.dark-theme .message-input-android::placeholder { color: #8696a0; }
.dark-theme .chat-item:hover, .dark-theme .user-item:hover { background-color: #2a2a2a; }
.dark-theme .chat-item.active { background-color: #2b5278; }
.dark-theme .chat-username, .dark-theme .sidebar-header h2 { color: white; }

.dark-theme .message:not(.own) .message-bubble { background-color: #202c33; color: #e9edef; }
.dark-theme .message.own .message-bubble { background-color: #005c4b; color: #e9edef; }

.dark-theme emoji-picker { --background: #1e1e1e; --border-color: #333; }
.dark-theme .btn-logout-new { background: #3d2525; border-color: #5c3030; color: #ff8080; }
.dark-theme .btn-back-to-chat, .dark-theme .btn-close-settings { background: #2a2a2a; color: #aaa; }
.dark-theme .edit-avatar-badge { border-color: #1e1e1e; }

/* === МОБИЛЬНАЯ ВЕРСИЯ === */
@media (max-width: 768px) {
  .sidebar {
      width: 100% !important;
      position: absolute;
      left: 0; top: 0;
      height: 100%;
      transition: transform 0.3s ease;
  }
  .main-content {
      position: fixed;
      top: 0; left: 0;
      width: 100%; height: 100%;
      transform: translateX(100%);
      z-index: 100;
  }
  .messenger.chat-active .main-content { transform: translateX(0); }
  .btn-back-mobile { display: block; }
  .emoji-picker-container { left: 5vw; width: 90vw; bottom: 70px; }
  emoji-picker { width: 100%; height: 350px; }
}
