* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --primary: #0084ff;
    --primary-dark: #0073e6;
    --bg: #f5f5f5;
    --white: #ffffff;
    --dark: #1a1a1a;
    --gray: #666666;
    --border: #e0e0e0;
    --shadow: 0 2px 8px rgba(0,0,0,0.05);
    --shadow-hover: 0 4px 12px rgba(0,0,0,0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--dark);
    height: 100vh;
    overflow: hidden;
}

/* ========== АВТОРИЗАЦИЯ ========== */
.auth-container {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #667eea, #764ba2);
}

.auth-card {
    background: var(--white);
    border-radius: 32px;
    padding: 40px 30px;
    width: 100%;
    max-width: 340px;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}

.logo {
    font-size: 64px;
    margin-bottom: 16px;
}

.auth-card h1, .auth-card h2 {
    font-size: 28px;
    margin-bottom: 8px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.auth-card p {
    color: var(--gray);
    font-size: 14px;
    margin-bottom: 24px;
}

.auth-card input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 14px;
    font-size: 16px;
    margin-bottom: 16px;
    outline: none;
    transition: all 0.2s;
    background: var(--white);
}

.auth-card input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0,132,255,0.1);
}

.auth-card button {
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 14px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.auth-card button:active {
    transform: scale(0.98);
    background: var(--primary-dark);
}

.error {
    background: #fee;
    color: #c33;
    padding: 12px;
    border-radius: 14px;
    font-size: 14px;
    margin-bottom: 20px;
}

.success {
    background: #e6ffe6;
    color: #2c6e2c;
    padding: 12px;
    border-radius: 14px;
    margin-bottom: 20px;
}

.back-link {
    display: inline-block;
    margin-top: 20px;
    color: var(--primary);
    text-decoration: none;
    font-size: 14px;
}

/* ========== ОСНОВНОЙ ИНТЕРФЕЙС ========== */
.app {
    display: flex;
    height: 100vh;
}

/* Панель чатов */
.chats-panel {
    width: 320px;
    background: var(--white);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    z-index: 10;
}

.panel-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 18px;
    background-size: cover;
    background-position: center;
    flex-shrink: 0;
}

.avatar.small {
    width: 40px;
    height: 40px;
    font-size: 16px;
}

.avatar.large {
    width: 100px;
    height: 100px;
    font-size: 48px;
    margin: 0 auto 20px;
}

.user span {
    font-weight: 600;
    font-size: 16px;
}

.buttons {
    display: flex;
    gap: 8px;
}

.btn-icon {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    text-decoration: none;
    color: var(--gray);
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.btn-icon:active {
    background: var(--bg);
}

/* Поиск */
.search-box {
    padding: 12px 16px;
    position: relative;
    border-bottom: 1px solid var(--border);
}

.search-box input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 24px;
    font-size: 14px;
    outline: none;
    background: var(--bg);
    transition: all 0.2s;
}

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

.search-results {
    position: absolute;
    top: 60px;
    left: 16px;
    right: 16px;
    background: var(--white);
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 100;
    max-height: 300px;
    overflow-y: auto;
}

.search-results.hidden {
    display: none;
}

.search-result {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.2s;
}

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

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

.chat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    text-decoration: none;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s;
}

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

.chat-item.active {
    background: rgba(0,132,255,0.05);
    border-left: 3px solid var(--primary);
}

.chat-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 18px;
    background-size: cover;
    background-position: center;
    flex-shrink: 0;
}

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

.chat-name {
    font-weight: 600;
    margin-bottom: 4px;
    font-size: 15px;
}

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

.empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--gray);
    font-size: 14px;
}

/* Панель чата */
.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    transition: transform 0.3s ease;
}

.chat-header {
    padding: 12px 16px;
    background: var(--white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.back-btn {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--primary);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    align-items: center;
    justify-content: center;
}

.back-btn:active {
    background: var(--bg);
}

.chat-user {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--dark);
    flex: 1;
}

/* Сообщения */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message {
    display: flex;
    width: 100%;
    /*animation: fadeIn 0.2s ease;*/
}

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

.message-in {
    justify-content: flex-start;
}

.message-out {
    justify-content: flex-end;
}

.message-bubble {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 18px;
    word-wrap: break-word;
    font-size: 15px;
    line-height: 1.4;
}

.message-in .message-bubble {
    background: var(--white);
    color: var(--dark);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.message-out .message-bubble {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

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

.message-out .message-time {
    text-align: right;
}

.loading {
    text-align: center;
    padding: 40px;
    color: var(--gray);
    font-size: 14px;
}

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

#messageForm {
    display: flex;
    gap: 8px;
}

#messageInput {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 24px;
    font-size: 16px;
    outline: none;
    background: var(--white);
    transition: border 0.2s;
}

#messageInput:focus {
    border-color: var(--primary);
}

#messageForm button {
    width: 44px;
    height: 44px;
    background: var(--primary);
    border: none;
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

#messageForm button:active {
    transform: scale(0.95);
    background: var(--primary-dark);
}

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

.empty-icon {
    font-size: 64px;
    margin-bottom: 20px;
    opacity: 0.6;
}

.empty-chat h2 {
    font-size: 22px;
    margin-bottom: 8px;
    color: var(--dark);
}

.empty-chat p {
    font-size: 14px;
}

.btn {
    display: inline-block;
    padding: 12px 24px;
    background: var(--primary);
    color: white;
    text-decoration: none;
    border-radius: 24px;
    margin-top: 20px;
    font-size: 14px;
    font-weight: 600;
    transition: background 0.2s, transform 0.1s;
    border: none;
    cursor: pointer;
    text-align: center;
}

.btn:active {
    transform: scale(0.98);
    background: var(--primary-dark);
}

.btn-primary {
    background: var(--primary);
    color: white;
    padding: 12px 24px;
    border-radius: 14px;
    text-decoration: none;
    display: inline-block;
    font-weight: 600;
    transition: background 0.2s;
}

.btn-primary:active {
    background: var(--primary-dark);
}

.btn-block {
    width: 100%;
    display: block;
    text-align: center;
}

/* ========== ПРОФИЛЬ ========== */
.profile-container {
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea, #764ba2);
    padding: 20px;
    overflow-y: auto;
}

.profile-header {
    max-width: 500px;
    margin: 0 auto 20px;
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.back-link, .edit-link, .message-link, .logout-link {
    color: white;
    text-decoration: none;
    padding: 8px 16px;
    background: rgba(255,255,255,0.2);
    border-radius: 20px;
    font-size: 14px;
    transition: background 0.2s;
}

.back-link:active, .edit-link:active, .message-link:active, .logout-link:active {
    background: rgba(255,255,255,0.3);
}

.profile-card {
    max-width: 500px;
    margin: 0 auto;
    background: var(--white);
    border-radius: 32px;
    padding: 40px 30px;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
}

.profile-card h1 {
    font-size: 28px;
    margin-bottom: 8px;
}

.profile-card h2 {
    font-size: 24px;
    margin-bottom: 20px;
}

.joined {
    color: var(--gray);
    font-size: 14px;
    margin-bottom: 16px;
}

.fullname {
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--dark);
}

.about {
    margin-top: 16px;
    line-height: 1.5;
    color: var(--gray);
    font-size: 14px;
}

/* Формы редактирования профиля */
.profile-card form {
    margin-top: 20px;
    text-align: left;
}

.profile-card form input,
.profile-card form textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    font-size: 16px;
    margin-bottom: 12px;
    font-family: inherit;
    resize: vertical;
    outline: none;
    transition: border 0.2s;
}

.profile-card form input:focus,
.profile-card form textarea:focus {
    border-color: var(--primary);
}

.profile-card form button {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.profile-card form button:active {
    transform: scale(0.98);
    background: var(--primary-dark);
}

.current-avatar {
    margin-top: 20px;
    text-align: center;
}

.current-avatar img {
    border-radius: 50%;
    object-fit: cover;
}

.profile-last-login {
    margin-top: 24px;
    text-align: left;
    border-top: 1px solid var(--border);
    padding-top: 20px;
}

.profile-last-login h3 {
    font-size: 18px;
    margin-bottom: 12px;
    color: var(--dark);
}

.profile-last-login p {
    font-size: 14px;
    margin-bottom: 8px;
    color: var(--gray);
}

/* ========== СТРАНИЦА ПОИСКА ========== */
.search-page {
    min-height: 100vh;
    background: var(--white);
    display: flex;
    flex-direction: column;
}

.search-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--white);
}

.search-header .back-link {
    color: var(--primary);
    background: var(--bg);
    padding: 8px 16px;
    border-radius: 20px;
}

.search-form {
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.search-form form {
    display: flex;
    gap: 8px;
}

.search-form input {
    flex: 1;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 14px;
    font-size: 16px;
    outline: none;
    transition: border 0.2s;
}

.search-form input:focus {
    border-color: var(--primary);
}

.search-form button {
    padding: 14px 20px;
    background: var(--primary);
    border: none;
    border-radius: 14px;
    font-size: 18px;
    cursor: pointer;
    color: white;
    transition: background 0.2s;
}

.search-form button:active {
    background: var(--primary-dark);
}

.search-results-list {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
}

.search-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    text-decoration: none;
    border-bottom: 1px solid var(--border);
    transition: background 0.2s;
}

.search-user:active {
    background: var(--bg);
}

.user-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 18px;
    flex-shrink: 0;
    background-size: cover;
    background-position: center;
}

.user-info {
    flex: 1;
}

.user-name {
    font-weight: 600;
    color: var(--dark);
    font-size: 16px;
}

.user-date {
    font-size: 12px;
    color: var(--gray);
    margin-top: 2px;
}

.user-action {
    font-size: 20px;
    color: var(--primary);
    opacity: 0.7;
}

/* ========== МОБИЛЬНАЯ ВЕРСИЯ ========== */
@media (max-width: 768px) {
    .chats-panel {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 100%;
        z-index: 10;
        transform: translateX(0);
    }
    
    .chats-panel.hidden {
        transform: translateX(-100%);
    }
    
    .chat-panel {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 100%;
        z-index: 20;
        background: var(--bg);
        transform: translateX(0);
    }
    
    .chat-panel.hidden {
        transform: translateX(100%);
    }
    
    .back-btn {
        display: flex;
    }
    
    .message-bubble {
        max-width: 85%;
    }
    
    .panel-header {
        padding: 12px;
    }
    
    .avatar {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }
    
    .chat-avatar {
        width: 44px;
        height: 44px;
        font-size: 16px;
    }
    
    .chat-name {
        font-size: 14px;
    }
    
    .chat-preview {
        font-size: 12px;
    }
    
    .search-user {
        padding: 10px;
    }
    
    .user-avatar {
        width: 44px;
        height: 44px;
        font-size: 16px;
    }
    
    .profile-card {
        padding: 30px 20px;
    }
    
    .profile-card h1 {
        font-size: 24px;
    }
    
    .auth-card {
        padding: 30px 20px;
    }
}