* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2196f3;
    --primary-dark: #1976d2;
    --secondary-color: #4caf50;
    --danger-color: #f44336;
    --warning-color: #ff9800;
    --dark-bg: #1e1e1e;
    --light-bg: #f5f5f5;
    --chat-bg: #ffffff;
    --message-mine: #e3f2fd;
    --message-theirs: #f5f5f5;
    --border-color: #e0e0e0;
    --text-primary: #333333;
    --text-secondary: #666666;
    --shadow: 0 2px 10px rgba(0,0,0,0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: var(--text-primary);
}

/* ==================== АВТОРИЗАЦИЯ ==================== */

.auth-container {
    background: white;
    border-radius: 20px;
    padding: 40px;
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 450px;
    margin: 20px auto;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.auth-header {
    text-align: center;
    margin-bottom: 30px;
}

.auth-logo {
    width: 80px;
    height: 80px;
    margin-bottom: 15px;
}

.auth-header h1 {
    font-size: 28px;
    color: var(--primary-color);
    margin-bottom: 5px;
}

.auth-header p {
    color: var(--text-secondary);
    font-size: 14px;
}

.auth-tabs {
    display: flex;
    margin-bottom: 30px;
    border-bottom: 2px solid var(--border-color);
}

.auth-tab {
    flex: 1;
    text-align: center;
    padding: 10px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.3s;
    font-weight: 500;
}

.auth-tab.active {
    color: var(--primary-color);
    border-bottom: 2px solid var(--primary-color);
}

.auth-form {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-primary);
    font-weight: 500;
    font-size: 14px;
}

.form-group input {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    font-size: 16px;
    transition: all 0.3s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

.form-group input.error {
    border-color: var(--danger-color);
}

.emoji-keyboard {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 8px;
    margin: 20px 0;
    max-height: 200px;
    overflow-y: auto;
    padding: 10px;
    background: var(--light-bg);
    border-radius: 10px;
}

.emoji-btn {
    font-size: 24px;
    padding: 8px;
    border: 2px solid transparent;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    transition: all 0.2s;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.emoji-btn:hover {
    background: var(--primary-color);
    color: white;
    transform: scale(1.1);
}

.emoji-btn.selected {
    border-color: var(--primary-color);
    background: #e3f2fd;
}

.emoji-display {
    display: flex;
    gap: 10px;
    margin: 20px 0;
    justify-content: center;
}

.emoji-slot {
    width: 60px;
    height: 60px;
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    background: var(--light-bg);
    transition: all 0.3s;
}

.emoji-slot.filled {
    border-style: solid;
    border-color: var(--primary-color);
    background: #e3f2fd;
    transform: scale(1.05);
}

.btn {
    width: 100%;
    padding: 14px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.btn:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-danger {
    background: var(--danger-color);
}

.btn-danger:hover {
    background: #d32f2f;
}

.error-message {
    background: #ffebee;
    color: var(--danger-color);
    padding: 12px;
    border-radius: 10px;
    margin-bottom: 20px;
    font-size: 14px;
    border-left: 4px solid var(--danger-color);
}

.success-message {
    background: #e8f5e8;
    color: var(--secondary-color);
    padding: 12px;
    border-radius: 10px;
    margin-bottom: 20px;
    font-size: 14px;
    border-left: 4px solid var(--secondary-color);
}

.attempts-info {
    text-align: center;
    margin-top: 15px;
    color: var(--text-secondary);
    font-size: 13px;
}

.auth-footer {
    margin-top: 20px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 12px;
}

/* ==================== ИНТЕРФЕЙС ЧАТА ==================== */

.chat-interface {
    display: flex;
    height: 100vh;
    width: 100%;
    background: white;
    position: fixed;
    top: 0;
    left: 0;
}

/* Сайдбар */
.sidebar {
    width: 350px;
    background: white;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    background: white;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 18px;
}

.sidebar-actions {
    display: flex;
    gap: 10px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: var(--light-bg);
    cursor: pointer;
    font-size: 20px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: var(--primary-color);
    color: white;
    transform: scale(1.05);
}

/* Список чатов */
.chats-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 5px;
    position: relative;
}

.chat-item:hover {
    background: var(--light-bg);
}

.chat-item.active {
    background: #e3f2fd;
}

.chat-item-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    position: relative;
    flex-shrink: 0;
}

.chat-item-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.avatar-placeholder {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: bold;
}

.online-indicator {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background: var(--secondary-color);
    border: 2px solid white;
    border-radius: 50%;
}

.chat-item-info {
    flex: 1;
    min-width: 0;
}

.chat-item-name {
    font-weight: 600;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-last {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-meta {
    text-align: right;
    font-size: 12px;
}

.chat-item-time {
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.unread-badge {
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    min-width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    padding: 0 5px;
}

/* Область чата */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
}

.chat-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: white;
}

.chat-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: bold;
}

.chat-status {
    font-size: 13px;
    color: var(--text-secondary);
}

.chat-actions {
    display: flex;
    gap: 10px;
}

/* Сообщения */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f8f9fa;
}

.messages {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.date-separator {
    text-align: center;
    margin: 20px 0;
}

.date-separator span {
    background: var(--light-bg);
    padding: 5px 15px;
    border-radius: 20px;
    font-size: 12px;
    color: var(--text-secondary);
}

.message {
    display: flex;
    gap: 10px;
    max-width: 70%;
}

.message.mine {
    margin-left: auto;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    flex-shrink: 0;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.message-content {
    background: white;
    padding: 12px;
    border-radius: 15px;
    box-shadow: var(--shadow);
    position: relative;
}

.message.mine .message-content {
    background: var(--primary-color);
    color: white;
}

.message-author {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 5px;
    color: var(--primary-color);
}

.message.mine .message-author {
    color: rgba(255,255,255,0.9);
}

.message-text {
    word-wrap: break-word;
    line-height: 1.4;
}

.message-attachments {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 5px;
    margin-top: 10px;
}

.attachment {
    cursor: pointer;
    border-radius: 8px;
    overflow: hidden;
}

.attachment img {
    width: 100%;
    height: 100px;
    object-fit: cover;
    transition: transform 0.2s;
}

.attachment:hover img {
    transform: scale(1.05);
}

.message-time {
    font-size: 11px;
    margin-top: 5px;
    text-align: right;
    opacity: 0.7;
}

/* Ввод сообщения */
.message-input-container {
    padding: 20px;
    background: white;
    border-top: 1px solid var(--border-color);
}

.attachments-preview {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.attachment-preview {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: 8px;
    overflow: hidden;
}

.attachment-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.remove-attachment {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 50%;
    background: var(--danger-color);
    color: white;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--light-bg);
    border-radius: 25px;
    padding: 10px 15px;
}

.input-wrapper textarea {
    flex: 1;
    border: none;
    background: transparent;
    padding: 8px 0;
    max-height: 100px;
    resize: none;
    font-size: 14px;
    outline: none;
}

.send-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.send-btn:hover {
    transform: scale(1.1);
    background: var(--primary-dark);
}

.emoji-picker {
    display: flex;
    gap: 5px;
    margin-top: 10px;
    overflow-x: auto;
    padding: 5px;
}

.emoji-picker-btn {
    font-size: 24px;
    padding: 5px;
    border: none;
    background: transparent;
    cursor: pointer;
    transition: transform 0.2s;
}

.emoji-picker-btn:hover {
    transform: scale(1.2);
}

/* Пустое состояние */
.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    color: var(--text-secondary);
}

/* Модальные окна */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 20px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    background: white;
    z-index: 1;
}

.close-modal {
    font-size: 24px;
    cursor: pointer;
    background: none;
    border: none;
    color: var(--text-secondary);
}

.close-modal:hover {
    color: var(--danger-color);
}

.modal-body {
    padding: 20px;
}

.modal-body input {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    margin-bottom: 15px;
}

/* Результаты поиска */
.search-results {
    max-height: 300px;
    overflow-y: auto;
}

.search-result {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    cursor: pointer;
    border-radius: 10px;
    transition: background 0.2s;
}

.search-result:hover {
    background: var(--light-bg);
}

.search-result-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    position: relative;
}

.search-result-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.search-result-info {
    flex: 1;
}

.search-result-name {
    font-weight: 500;
}

/* Информация о чате */
.chat-info {
    padding: 10px;
}

.members-list {
    margin-top: 15px;
}

.member-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px;
    border-radius: 10px;
    margin-bottom: 5px;
}

.member-item:hover {
    background: var(--light-bg);
}

.member-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.member-avatar {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    position: relative;
}

.member-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.remove-member {
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 50%;
    background: var(--danger-color);
    color: white;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Просмотр изображений */
.image-viewer {
    background: transparent;
    box-shadow: none;
}

.image-viewer img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
}

/* Выбранные участники группы */
.selected-members {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 15px 0;
}

.selected-member {
    background: var(--primary-color);
    color: white;
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.selected-member button {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 16px;
}

/* Групповые действия */
.group-actions {
    margin-top: 20px;
    display: flex;
    gap: 10px;
}

/* Скроллбар */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--light-bg);
}

::-webkit-scrollbar-thumb {
    background: #bdbdbd;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #9e9e9e;
}

/* Адаптивность */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        position: fixed;
        z-index: 10;
        transform: translateX(-100%);
        transition: transform 0.3s;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .chat-area {
        width: 100%;
    }
    
    .emoji-keyboard {
        grid-template-columns: repeat(5, 1fr);
    }
    
    .modal-content {
        width: 95%;
        margin: 10px;
    }
}

/* Анимации */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message {
    animation: slideIn 0.3s ease;
}

/* Стили для поля ввода сообщений */
.message-input-container {
    padding: 15px 20px;
    background: white;
    border-top: 1px solid var(--border-color);
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--light-bg);
    border-radius: 25px;
    padding: 8px 15px;
    border: 2px solid transparent;
    transition: all 0.3s;
}

.input-wrapper:focus-within {
    border-color: var(--primary-color);
    background: white;
}

.input-wrapper textarea {
    flex: 1;
    border: none;
    background: transparent;
    padding: 8px 0;
    max-height: 100px;
    min-height: 40px;
    resize: none;
    font-size: 15px;
    outline: none;
    font-family: inherit;
    line-height: 1.4;
}

.send-btn {
    width: 45px;
    height: 45px;
    border: none;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    cursor: pointer;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-btn:hover {
    transform: scale(1.1);
    background: var(--primary-dark);
}

.send-btn:active {
    transform: scale(0.95);
}

.message-hint {
    text-align: right;
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 5px;
    opacity: 0.7;
}

/* Стили для сообщений */
.messages {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
}

.message {
    display: flex;
    gap: 10px;
    max-width: 80%;
    animation: fadeIn 0.3s ease;
}

.message.mine {
    margin-left: auto;
    flex-direction: row-reverse;
}

.message .message-content {
    background: white;
    padding: 12px 15px;
    border-radius: 18px;
    box-shadow: var(--shadow);
    position: relative;
    word-break: break-word;
}

.message.mine .message-content {
    background: var(--primary-color);
    color: white;
}

.message-author {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--primary-color);
}

.message.mine .message-author {
    color: rgba(255,255,255,0.9);
}

.message-text {
    line-height: 1.4;
    font-size: 14px;
}

.message-time {
    font-size: 10px;
    margin-top: 4px;
    text-align: right;
    opacity: 0.7;
}

/* Анимация */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Пустой чат */
.no-messages {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px;
    font-style: italic;
}