/* Общие стили */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    height: 100vh;
    overflow: hidden;
}

/* Утилиты */
.hidden {
    display: none !important;
}

/* Экран входа/регистрации */
.auth-screen {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    padding: 20px;
}

.auth-container {
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    padding: 40px;
    width: 100%;
    max-width: 400px;
    animation: slideUp 0.5s ease-out;
}

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

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

.auth-header h1 {
    color: #333;
    margin-bottom: 10px;
    font-size: 2rem;
}

.auth-header p {
    color: #666;
    font-size: 1rem;
}

.auth-tabs {
    display: flex;
    margin-bottom: 30px;
    border-radius: 10px;
    overflow: hidden;
    background: #f5f5f5;
}

.tab-btn {
    flex: 1;
    padding: 12px;
    border: none;
    background: transparent;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

.tab-btn.active {
    background: #667eea;
    color: white;
}

.auth-form {
    display: none;
}

.auth-form.active {
    display: block;
}

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

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: #333;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e1e5e9;
    border-radius: 10px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.form-group input:focus {
    outline: none;
    border-color: #667eea;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
}

/* Основной интерфейс мессенджера */
.messenger-app {
    display: flex;
    height: 100vh;
    background: white;
    border-radius: 20px;
    margin: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

/* Боковая панель */
.sidebar {
    width: 350px;
    background: #f8f9fa;
    border-right: 1px solid #e1e5e9;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid #e1e5e9;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.user-avatar {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.2rem;
}

.user-details {
    display: flex;
    flex-direction: column;
}

.username {
    font-weight: 600;
    color: #333;
    font-size: 1rem;
}

.status {
    font-size: 0.8rem;
    color: #28a745;
}

.search-container {
    padding: 20px;
    position: relative;
}

.search-container input {
    width: 100%;
    padding: 12px 16px 12px 40px;
    border: 2px solid #e1e5e9;
    border-radius: 25px;
    font-size: 0.9rem;
    transition: border-color 0.3s ease;
}

.search-container input:focus {
    outline: none;
    border-color: #667eea;
}

.search-container i {
    position: absolute;
    left: 30px;
    top: 50%;
    transform: translateY(-50%);
    color: #999;
}

.users-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 20px 20px;
}

.user-item {
    display: flex;
    align-items: center;
    padding: 15px;
    border-radius: 10px;
    cursor: pointer;
    transition: background-color 0.3s ease;
    margin-bottom: 5px;
}

.user-item:hover {
    background: #e9ecef;
}

.user-item.active {
    background: #667eea;
    color: white;
}

.user-item.active .user-name {
    color: white;
}

.user-item.active .user-status {
    color: rgba(255, 255, 255, 0.8);
}

.user-avatar-small {
    width: 35px;
    height: 35px;
    background: #ddd;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    font-size: 1rem;
}

.user-details-small {
    flex: 1;
}

.user-name {
    font-weight: 500;
    color: #333;
    margin-bottom: 2px;
}

.user-status {
    font-size: 0.8rem;
    color: #666;
}

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

.chat-header {
    padding: 20px;
    border-bottom: 1px solid #e1e5e9;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.chat-name {
    font-weight: 600;
    color: #333;
    font-size: 1.1rem;
}

.chat-status {
    font-size: 0.9rem;
    color: #666;
}

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

.btn-icon {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: #f8f9fa;
    color: #666;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    font-size: 1rem;
}

.btn-icon:hover:not(:disabled) {
    background: #667eea;
    color: white;
    transform: scale(1.1);
}

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

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f8f9fa;
}

.welcome-message {
    text-align: center;
    color: #666;
    margin-top: 50px;
}

.welcome-message i {
    font-size: 3rem;
    margin-bottom: 20px;
    color: #667eea;
}

.message {
    margin-bottom: 15px;
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

.message.sent {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 30px;
    height: 30px;
    background: #ddd;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.message-content {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
}

.message.sent .message-content {
    background: #667eea;
    color: white;
    border-bottom-right-radius: 5px;
}

.message.received .message-content {
    background: white;
    color: #333;
    border-bottom-left-radius: 5px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.message-time {
    font-size: 0.7rem;
    color: #999;
    margin-top: 5px;
}

.message-input-container {
    padding: 20px;
    border-top: 1px solid #e1e5e9;
    background: white;
}

.message-input-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #f8f9fa;
    border-radius: 25px;
    padding: 8px 15px;
}

.message-input-wrapper input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    font-size: 1rem;
    padding: 8px 0;
}

/* Модальное окно видеозвонка */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.call-container {
    background: white;
    border-radius: 20px;
    padding: 30px;
    width: 90%;
    max-width: 600px;
    text-align: center;
}

.call-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

.call-status {
    font-size: 1.2rem;
    font-weight: 600;
    color: #333;
}

.video-container {
    position: relative;
    background: #000;
    border-radius: 15px;
    overflow: hidden;
    margin-bottom: 30px;
    height: 400px;
}

#remote-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000;
}

#local-video {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 120px;
    height: 90px;
    border-radius: 10px;
    object-fit: cover;
    border: 2px solid white;
    background: #000;
}

.call-controls {
    display: flex;
    justify-content: center;
    gap: 20px;
}

.call-controls .btn-icon {
    width: 50px;
    height: 50px;
    font-size: 1.2rem;
}

/* Уведомления */
.notifications {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1001;
}

.notification {
    background: white;
    border-radius: 10px;
    padding: 15px 20px;
    margin-bottom: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    border-left: 4px solid #667eea;
    animation: slideInRight 0.3s ease-out;
    max-width: 300px;
}

.notification.success {
    border-left-color: #28a745;
}

.notification.error {
    border-left-color: #dc3545;
}

.notification.warning {
    border-left-color: #ffc107;
}

.notification.info {
    border-left-color: #17a2b8;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Адаптивность для мобильных устройств */
@media (max-width: 768px) {
    .messenger-app {
        margin: 0;
        border-radius: 0;
        height: 100vh;
    }
    
    .sidebar {
        width: 100%;
        position: absolute;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .chat-area {
        width: 100%;
    }
    
    .call-container {
        width: 95%;
        padding: 20px;
    }
    
    .video-container {
        height: 250px;
    }
    
    #local-video {
        width: 80px;
        height: 60px;
        top: 10px;
        right: 10px;
    }
    
    .notifications {
        top: 10px;
        right: 10px;
        left: 10px;
    }
    
    .notification {
        max-width: none;
    }
}

@media (max-width: 480px) {
    .auth-container {
        margin: 10px;
        padding: 30px 20px;
    }
    
    .call-container {
        padding: 15px;
    }
    
    .video-container {
        height: 200px;
    }
    
    .call-controls {
        gap: 15px;
    }
    
    .call-controls .btn-icon {
        width: 45px;
        height: 45px;
        font-size: 1rem;
    }
}

/* Поддержка safe-area-insets для современных мобильных устройств */
@supports (padding: max(0px)) {
    .messenger-app {
        padding-top: max(20px, env(safe-area-inset-top));
        padding-bottom: max(20px, env(safe-area-inset-bottom));
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
    }
}

/* Стили для iOS Safari */
@supports (-webkit-touch-callout: none) {
    .message-input-wrapper input {
        font-size: 16px; /* Предотвращает зум на iOS */
    }
    
    .search-container input {
        font-size: 16px; /* Предотвращает зум на iOS */
    }
}
