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

:root {
    --primary-color: #4a90d9;
    --primary-dark: #3a7bc8;
    --secondary-color: #f5f5f5;
    --text-color: #333;
    --text-light: #666;
    --border-color: #ddd;
    --success-color: #4caf50;
    --error-color: #f44336;
    --message-out-bg: #4a90d9;
    --message-in-bg: #f0f0f0;
    --header-bg: #fff;
    --sidebar-bg: #fff;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.15);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: #f8f9fa;
    color: var(--text-color);
    height: 100vh;
    overflow: hidden;
}

#app {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.screen {
    display: none;
    height: 100%;
    width: 100%;
}

.screen.active {
    display: flex;
    flex-direction: column;
}

/* Экран входа */
#login-screen {
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
}

.login-container {
    background: #fff;
    padding: 40px 30px;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

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

.login-container h1 {
    color: var(--text-color);
    margin-bottom: 30px;
    font-size: 24px;
}

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

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

.form-group input[type="text"],
.form-group input[type="password"] {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.3s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: normal;
}

.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary {
    background: var(--primary-color);
    color: #fff;
}

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

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

.btn-block {
    width: 100%;
}

.btn-loader {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.hidden {
    display: none !important;
}

.error-message {
    margin-top: 15px;
    padding: 12px;
    background: #ffebee;
    color: var(--error-color);
    border-radius: 8px;
    font-size: 14px;
}

/* Чат экран */
.chat-header {
    background: var(--header-bg);
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
    z-index: 100;
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.current-chat-info {
    display: flex;
    flex-direction: column;
}

#current-chat-name {
    font-weight: 600;
    font-size: 16px;
}

.status-indicator {
    font-size: 12px;
    color: var(--success-color);
}

.status-indicator.disconnected {
    color: var(--error-color);
}

.icon-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.3s;
}

.icon-btn:hover {
    background: var(--secondary-color);
}

.chat-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Боковая панель контактов */
.contacts-panel {
    width: 300px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s;
}

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

.contacts-header h2 {
    font-size: 18px;
}

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

.search-box input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-size: 14px;
}

.contacts-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.contact-item {
    display: flex;
    align-items: center;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.3s;
    gap: 12px;
}

.contact-item:hover {
    background: var(--secondary-color);
}

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

.contact-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--primary-color);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 600;
}

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

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

.contact-status {
    font-size: 12px;
    color: var(--text-light);
}

.contact-presence {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ccc;
}

.contact-presence.online {
    background: var(--success-color);
}

.contact-presence.away {
    background: #ff9800;
}

.contact-presence.dnd {
    background: var(--error-color);
}

.add-contact-section {
    padding: 16px;
    border-top: 1px solid var(--border-color);
}

/* Основная область чата */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #e5ddd5;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.welcome-message {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
}

.welcome-icon {
    font-size: 64px;
    margin-bottom: 20px;
}

.welcome-message h3 {
    margin-bottom: 10px;
    color: var(--text-color);
}

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

.message {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 12px;
    word-wrap: break-word;
}

.message.out {
    background: var(--message-out-bg);
    color: #fff;
    align-self: flex-end;
    margin-left: auto;
}

.message.in {
    background: var(--message-in-bg);
    color: var(--text-color);
    align-self: flex-start;
}

.message-header {
    font-size: 12px;
    margin-bottom: 4px;
    opacity: 0.8;
}

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

.message-form {
    padding: 12px 16px;
    background: var(--header-bg);
    border-top: 1px solid var(--border-color);
}

.message-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}

.message-input-wrapper input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 24px;
    font-size: 15px;
}

.message-input-wrapper input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--primary-color);
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    transition: background 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

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

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    background: #fff;
    padding: 24px;
    border-radius: 16px;
    width: 90%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.3s;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

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

.modal-header h3 {
    font-size: 18px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 4px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.modal-actions .btn {
    flex: 1;
}

/* Уведомления */
.notification-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.notification {
    background: #fff;
    padding: 16px 20px;
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 300px;
    animation: slideIn 0.3s;
    border-left: 4px solid var(--primary-color);
}

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

.notification-icon {
    font-size: 24px;
}

.notification-content {
    flex: 1;
}

.notification-title {
    font-weight: 600;
    margin-bottom: 4px;
}

.notification-message {
    font-size: 14px;
    color: var(--text-light);
}

/* Адаптивность */
.mobile-only {
    display: none;
}

@media (max-width: 768px) {
    .contacts-panel {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        width: 280px;
        z-index: 200;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }

    .contacts-panel.open {
        transform: translateX(0);
    }

    .mobile-only {
        display: block;
    }

    .login-container {
        padding: 30px 20px;
    }

    .message {
        max-width: 85%;
    }

    .notification {
        min-width: auto;
        width: calc(100vw - 40px);
    }
}

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

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}
