/* ==================== БАЗОВЫЕ СБРОСЫ ==================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, sans-serif;
    background-color: #f0f2f5;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    transition: background-color 0.3s;
}

/* ==================== ЭКРАН АВТОРИЗАЦИИ ==================== */
.auth-container {
    width: 100%;
    max-width: 400px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    padding: 30px;
    transition: background 0.3s;
}
body.dark .auth-container {
    background: rgba(45, 45, 45, 0.85);
    color: #e0e0e0;
}
.auth-container h2 {
    text-align: center;
    color: #333;
    margin-bottom: 20px;
}
body.dark .auth-container h2 {
    color: #e0e0e0;
}
.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}
.tab {
    flex: 1;
    padding: 12px;
    border: none;
    background: #f0f0f0;
    cursor: pointer;
    font-size: 16px;
    border-radius: 10px;
    transition: all 0.2s;
}
.tab.active {
    background: #0078d4;
    color: white;
}
.auth-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}
.auth-form input {
    padding: 14px;
    border: 1px solid #ddd;
    border-radius: 12px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s;
    background: rgba(255,255,255,0.9);
}
body.dark .auth-form input {
    background: #3a3a3a;
    border-color: #555;
    color: white;
}
.auth-form input:focus {
    border-color: #0078d4;
}
.auth-form button {
    padding: 14px;
    background: #0078d4;
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
}
.auth-form button:hover {
    background: #005a9e;
}
.error {
    color: #d32f2f;
    font-size: 14px;
    text-align: center;
    min-height: 20px;
}

/* ==================== ОСНОВНОЙ КОНТЕЙНЕР ЧАТА ==================== */
.chat-container {
    width: 95%;
    max-width: 800px;
    height: 90vh;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(8px);
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    padding: 20px;
    transition: background 0.3s;
}
body.dark .chat-container {
    background: rgba(30, 30, 30, 0.75);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

/* --- Шапка чата --- */
.chat-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 15px;
}
.chat-header h1 {
    flex: 1;
    margin: 0;
    font-size: 1.5rem;
    color: #333;
    transition: color 0.3s;
}
body.dark .chat-header h1 {
    color: #e0e0e0;
}
.back-btn, .logout-btn {
    padding: 8px 16px;
    background: #f0f0f0;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}
body.dark .back-btn, body.dark .logout-btn {
    background: #3a3a3a;
    color: #e0e0e0;
}
.back-btn:hover, .logout-btn:hover {
    background: #e0e0e0;
}
body.dark .back-btn:hover, body.dark .logout-btn:hover {
    background: #4a4a4a;
}

/* ==================== СПИСОК ЧАТОВ ==================== */
#chatsListContainer {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
#chatsListContainer h3 {
    margin: 0 0 10px 0;
    color: #333;
}
body.dark #chatsListContainer h3 {
    color: #e0e0e0;
}
#chatsList {
    flex: 1;
    overflow-y: auto;
}
.new-chat-btn {
    padding: 8px 16px;
    background: #0078d4;
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background 0.2s;
}
.new-chat-btn:hover {
    background: #005a9e;
}
.chat-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: rgba(248, 249, 250, 0.8);
    border-radius: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: background 0.2s;
    border: 1px solid #e9ecef;
    backdrop-filter: blur(5px);
}
body.dark .chat-item {
    background: rgba(58, 58, 58, 0.8);
    border-color: #555;
    color: #e0e0e0;
}
.chat-item:hover {
    background: #e9ecef;
}
body.dark .chat-item:hover {
    background: #4a4a4a;
}
.chat-info {
    flex: 1;
    cursor: pointer;
}
.chat-name {
    color: #333;
    font-weight: 500;
}
body.dark .chat-name {
    color: #e0e0e0;
}
.chat-type {
    font-size: 14px;
    opacity: 0.7;
}

/* Кнопка удаления чата */
.delete-chat-btn {
    background: transparent;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 8px;
    opacity: 0.6;
    transition: all 0.2s;
}
.delete-chat-btn:hover {
    opacity: 1;
    background: rgba(255, 80, 80, 0.15);
    transform: scale(1.1);
}
body.dark .delete-chat-btn:hover {
    background: rgba(255, 80, 80, 0.25);
}

/* ==================== ОКНО СООБЩЕНИЙ ==================== */
#messagesContainer {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
}
#chatParticipants {
    padding: 5px 10px;
    border-radius: 20px;
    background: rgba(240, 240, 240, 0.7);
    display: inline-block;
    margin-bottom: 5px;
    font-size: 14px;
    backdrop-filter: blur(5px);
}
body.dark #chatParticipants {
    background: rgba(58, 58, 58, 0.7);
    color: #ccc;
}

/* Область сообщений */
.messages-box {
    flex: 1;
    overflow-y: auto;
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 15px;
    padding: 15px;
    margin-bottom: 15px;
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(5px);
    display: flex;
    flex-direction: column;
    gap: 4px;
}
body.dark .messages-box {
    background: rgba(30, 30, 30, 0.6);
    border-color: #444;
}

/* Сами сообщения (плашки) */
.message {
    display: flex;
    flex-direction: column;
    padding: 10px 14px;
    margin-bottom: 2px;
    border-radius: 12px;
    background: #f0f4f8;
    transition: background 0.2s;
    max-width: 75%;
    word-wrap: break-word;
}
.message.own {
    background: #dcf8c6;
    align-self: flex-end;
}
.message:not(.own) {
    align-self: flex-start;
}
body.dark .message {
    background: #0d3b5e;
    color: #bbdefb;
}
body.dark .message.own {
    background: #0078d4;
    color: white;
}

.message-sender {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 4px;
    opacity: 0.8;
    color: #1565c0;
}
.message.own .message-sender {
    color: #2e7d32;
    text-align: right;
}
body.dark .message-sender {
    color: #90caf9;
}
body.dark .message.own .message-sender {
    color: rgba(255, 255, 255, 0.9);
}
.message-text {
    word-wrap: break-word;
    line-height: 1.4;
}
.message img {
    max-width: 200px;
    max-height: 200px;
    border-radius: 12px;
    margin-top: 5px;
    cursor: pointer;
    border: 1px solid rgba(0,0,0,0.1);
}
.message.own img {
    border-color: rgba(255,255,255,0.3);
}

/* Поле ввода */
.input-area {
    display: flex;
    gap: 10px;
}
#messageInput {
    flex: 1;
    padding: 14px;
    border: 1px solid #ddd;
    border-radius: 25px;
    font-size: 16px;
    outline: none;
    background: rgba(255,255,255,0.9);
    transition: background 0.3s;
}
body.dark #messageInput {
    background: #3a3a3a;
    border-color: #555;
    color: white;
}
#sendBtn {
    padding: 14px 30px;
    background: #0078d4;
    color: white;
    border: none;
    border-radius: 25px;
    font-size: 16px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
}
#sendBtn:hover {
    background: #005a9e;
}

/* ==================== КНОПКИ: ЭМОДЗИ, ВЛОЖЕНИЯ, ГОЛОС ==================== */
.emoji-btn, .attach-btn, .voice-btn {
    padding: 10px 14px;
    background: transparent;
    border: 1px solid #ddd;
    border-radius: 25px;
    font-size: 20px;
    cursor: pointer;
    transition: background 0.2s;
    line-height: 1;
}
body.dark .emoji-btn, body.dark .attach-btn, body.dark .voice-btn {
    border-color: #555;
    color: #e0e0e0;
    background: #2d2d2d;
}
.emoji-btn:hover, .attach-btn:hover, .voice-btn:hover {
    background: #f0f0f0;
}
body.dark .emoji-btn:hover, body.dark .attach-btn:hover, body.dark .voice-btn:hover {
    background: #3a3a3a;
}
.voice-btn.recording {
    background: #ff4444;
    color: white;
    border-color: #ff4444;
    animation: pulse 1.5s infinite;
}
@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.6; }
    100% { opacity: 1; }
}

/* Эмодзи-пикер */
.emoji-picker {
    position: fixed;
    background: white;
    border-radius: 15px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.4);
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 5px;
    width: 300px;
    max-height: 250px;
    overflow-y: auto;
    z-index: 99999;
}
body.dark .emoji-picker {
    background: #2d2d2d;
    box-shadow: 0 5px 20px rgba(0,0,0,0.8);
}
.emoji-item {
    font-size: 26px;
    padding: 6px;
    cursor: pointer;
    text-align: center;
    border-radius: 8px;
    transition: background 0.15s;
    user-select: none;
}
.emoji-item:hover {
    background: #f0f0f0;
}
body.dark .emoji-item:hover {
    background: #3a3a3a;
}

/* ==================== МОДАЛЬНЫЕ ОКНА ==================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}
.modal-content {
    background: white;
    padding: 25px;
    border-radius: 20px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    transition: background 0.3s;
}
body.dark .modal-content {
    background: #2d2d2d;
    color: #e0e0e0;
}
.modal-content h3 {
    margin-top: 0;
    margin-bottom: 15px;
    color: inherit;
}
.modal-content input {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 12px;
    font-size: 16px;
    margin-bottom: 10px;
    background: white;
}
body.dark .modal-content input {
    background: #3a3a3a;
    border-color: #555;
    color: white;
}
.users-checklist {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid #ddd;
    border-radius: 12px;
    padding: 10px;
    margin: 10px 0;
}
body.dark .users-checklist {
    border-color: #555;
    background: #1e1e1e;
}
.user-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s;
}
.user-checkbox:hover {
    background: #f0f0f0;
}
body.dark .user-checkbox:hover {
    background: #3a3a3a;
}
.modal-buttons {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}
.create-btn {
    flex: 2;
    padding: 12px;
    background: #0078d4;
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
}
.cancel-btn {
    flex: 1;
    padding: 12px;
    background: #f0f0f0;
    border: none;
    border-radius: 12px;
    cursor: pointer;
}
body.dark .cancel-btn {
    background: #3a3a3a;
    color: #e0e0e0;
}
.confirm-modal {
    max-width: 350px;
    text-align: center;
}
.confirm-modal p {
    margin: 15px 0;
    color: #666;
}
body.dark .confirm-modal p {
    color: #aaa;
}
#confirmDeleteChatBtn {
    background: #d32f2f;
}
#confirmDeleteChatBtn:hover {
    background: #b71c1c;
}

/* ==================== ТЁМНАЯ ТЕМА (ФИНАЛЬНЫЕ ШТРИХИ) ==================== */
body.dark {
    background-color: #1a1a1a;
}
.theme-btn {
    margin-top: 15px;
    padding: 10px;
    background: transparent;
    border: 1px solid #ccc;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
}
body.dark .theme-btn {
    color: #e0e0e0;
    border-color: #555;
    background: #3a3a3a;
}

/* ==================== КАСТОМНАЯ ГРАФИКА (ФОНЫ И ИКОНКИ) ==================== */
/* Фоновая картинка для всей страницы (светлая тема) */
body {
    background-image: url('/static/images/bg-light.png');
    background-size: cover;
    background-attachment: fixed;
    background-position: center;
}
/* Фоновая картинка для всей страницы (тёмная тема) */
body.dark {
    background-image: url('/static/images/bg-dark.png');
    background-size: cover;
    background-attachment: fixed;
    background-position: center;
}

/* Кастомные иконки в кнопках */
.emoji-btn {
    background-image: url('/static/images/icon-emoji.png');
    background-size: 60%;
    background-repeat: no-repeat;
    background-position: center;
}
.attach-btn {
    background-image: url('/static/images/icon-attach.png');
    background-size: 60%;
    background-repeat: no-repeat;
    background-position: center;
}
.voice-btn {
    background-image: url('/static/images/icon-voice.png');
    background-size: 60%;
    background-repeat: no-repeat;
    background-position: center;
}

/* Аватар по умолчанию */
.default-avatar {
    background-image: url('/static/images/avatar-default.png');
    background-size: cover;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: inline-block;
}
/* Рамка аватарки */
.avatar-wrapper {
    position: relative;
}
.avatar-wrapper::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('/static/images/avatar-frame.png');
    background-size: contain;
    pointer-events: none;
}

/* ==================== АНИМАЦИЯ ЗАСТАВКИ ==================== */
@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.3;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Кнопка удаления сообщения */
.delete-message-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(0,0,0,0.4);
    border: none;
    color: white;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 6px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
}
.message {
    position: relative;
}
.message:hover .delete-message-btn {
    opacity: 1;
}
.delete-message-btn:hover {
    background: rgba(255, 80, 80, 0.8);
}
/* Кнопка стикеров */
.sticker-btn {
    padding: 10px 14px;
    background: transparent;
    border: 1px solid #ddd;
    border-radius: 25px;
    font-size: 20px;
    cursor: pointer;
    transition: background 0.2s;
    line-height: 1;
}
body.dark .sticker-btn {
    border-color: #555;
    color: #e0e0e0;
    background: #2d2d2d;
}
.sticker-btn:hover {
    background: #f0f0f0;
}
body.dark .sticker-btn:hover {
    background: #3a3a3a;
}

/* Панель стикеров */
.sticker-picker {
    position: fixed !important;
    background: white !important;
    border-radius: 15px !important;
    box-shadow: 0 5px 20px rgba(0,0,0,0.4) !important;
    padding: 15px !important;
    display: none; /* По умолчанию скрыта */
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 10px !important;
    width: 320px !important;
    max-height: 300px !important;
    overflow-y: auto !important;
    z-index: 99999 !important;
    left: 50% !important;
    bottom: 100px !important;
    transform: translateX(-50%) !important;
}
.sticker-picker.visible {
    display: grid !important;
}
body.dark .sticker-picker {
    background: #2d2d2d !important;
    box-shadow: 0 5px 20px rgba(0,0,0,0.8) !important;
}
.sticker-item {
    font-size: 40px;
    padding: 10px;
    cursor: pointer;
    text-align: center;
    border-radius: 12px;
    transition: background 0.15s;
    user-select: none;
}
.sticker-item:hover {
    background: #f0f0f0;
    transform: scale(1.1);
}
body.dark .sticker-item:hover {
    background: #3a3a3a;
}

/* Стикеры в сообщениях */
.message .sticker {
    font-size: 64px;
    line-height: 1;
    text-align: center;
}
/* Кнопка звонка */
.call-btn {
    padding: 8px 16px;
    background: #4caf50;
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 18px;
    transition: background 0.2s;
    line-height: 1;
}
.call-btn:hover {
    background: #388e3c;
}
body.dark .call-btn {
    background: #4caf50;
    color: white;
}