/* Reset и базовые стили */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0f172a;
    color: #f1f5f9;
    height: 100vh;
    overflow: hidden;
}

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

/* Загрузка */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #334155;
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

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

/* Шапка */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: #1e293b;
    border-bottom: 1px solid #334155;
}

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

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 18px;
}

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

.user-info small {
    color: #94a3b8;
    font-size: 12px;
    font-family: monospace;
}

/* Кнопки */
.btn-icon {
    background: #334155;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    color: #f1f5f9;
    cursor: pointer;
    font-size: 16px;
}

.btn-icon:hover {
    background: #475569;
}

.btn-primary {
    background: #6366f1;
    color: white;
    border: none;
    padding: 10px 16px;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: #4f46e5;
}

.btn-secondary {
    background: #334155;
    color: #f1f5f9;
    border: none;
    padding: 10px 16px;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
}

.btn-secondary:hover {
    background: #475569;
}

/* Список чатов */
.chats-container {
    height: calc(100vh - 120px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.chats-header {
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #334155;
}

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

.chat-item {
    display: flex;
    align-items: center;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 4px;
    transition: background 0.2s;
}

.chat-item:hover {
    background: #1e293b;
}

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #8b5cf6, #a78bfa);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    margin-right: 12px;
}

.chat-info {
    flex: 1;
}

.chat-name {
    font-weight: 500;
    margin-bottom: 4px;
}

.chat-status {
    font-size: 12px;
    color: #94a3b8;
    display: flex;
    align-items: center;
    gap: 4px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.online {
    background: #10b981;
}

.status-dot.offline {
    background: #64748b;
}

/* Модалки */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 100;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #1e293b;
    border-radius: 12px;
    padding: 24px;
    z-index: 101;
    min-width: 300px;
    max-width: 90vw;
}

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

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

.form-input {
    width: 100%;
    padding: 12px;
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 8px;
    color: #f1f5f9;
    font-size: 14px;
    outline: none;
}

.form-input:focus {
    border-color: #6366f1;
}

.form-hint {
    display: block;
    margin-top: 4px;
    color: #94a3b8;
    font-size: 12px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
}

/* Статус бар */
.status-bar {
    padding: 12px 16px;
    border-top: 1px solid #334155;
    background: #1e293b;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #94a3b8;
}

/* Адаптивность */
@media (max-width: 480px) {
    .modal {
        width: 95%;
        padding: 16px;
    }
    
    .chats-header {
        padding: 12px;
    }
    
    .header {
        padding: 12px;
    }
}

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

::-webkit-scrollbar-track {
    background: #1e293b;
}

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

::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

.chat-pending {
    opacity: 0.7;
    border-left: 3px solid #f59e0b;
}

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

.btn-accept, .btn-reject {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

.btn-accept {
    background: #10b981;
    color: white;
}

.btn-reject {
    background: #ef4444;
    color: white;
}

.btn-accept:hover {
    background: #0da271;
}

.btn-reject:hover {
    background: #dc2626;
}

/* Уведомления */
.notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ef4444;
    color: white;
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 20px;
    text-align: center;
}

/* Криптографическая информация */
.crypto-details {
    padding: 16px;
    background: #1e293b;
    border-radius: 8px;
    margin: 16px 0;
}

.crypto-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid #334155;
}

.crypto-item:last-child {
    margin-bottom: 0;
    border-bottom: none;
}

.crypto-item strong {
    color: #94a3b8;
    font-weight: 500;
    margin-right: 12px;
    min-width: 160px;
}

.crypto-item code {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    background: #0f172a;
    padding: 6px 8px;
    border-radius: 4px;
    word-break: break-all;
    flex: 1;
}

.crypto-note {
    margin-top: 16px;
    padding: 12px;
    background: rgba(99, 102, 241, 0.1);
    border-radius: 8px;
    border-left: 3px solid #6366f1;
    font-size: 13px;
    color: #94a3b8;
}

.crypto-status {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
}

.crypto-status.encrypted {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}

.crypto-status.unencrypted {
    background: rgba(245, 158, 11, 0.1);
    color: #f59e0b;
}

.crypto-status.error {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

/* Security indicators */
.security-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
}

.security-encrypted {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.security-unencrypted {
    background: rgba(245, 158, 11, 0.1);
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.security-error {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Warning messages */
.warning-box {
    padding: 12px;
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: 8px;
    margin: 12px 0;
    font-size: 13px;
}

.warning-box strong {
    color: #f59e0b;
}

/* Connection status */
.connection-status {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 12px;
    z-index: 9999;
    transition: all 0.3s;
}

.connection-connected {
    background: rgba(16, 185, 129, 0.9);
    color: white;
}

.connection-disconnected {
    background: rgba(239, 68, 68, 0.9);
    color: white;
}

.connection-reconnecting {
    background: rgba(245, 158, 11, 0.9);
    color: white;
}

/* Loading overlay для криптографии */
.crypto-loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.crypto-loading .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #334155;
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}

.crypto-loading p {
    color: #94a3b8;
    text-align: center;
    max-width: 300px;
}


/* Дополнительные стили для чата */
.chat-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: #0f172a;
}

.chat-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: #1e293b;
    border-bottom: 1px solid #334155;
    gap: 12px;
}

.back-btn {
    background: none;
    border: none;
    color: #f1f5f9;
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
}

.back-btn:hover {
    background: #334155;
}

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

.partner-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #8b5cf6, #a78bfa);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 16px;
}

.partner-info {
    flex: 1;
}

.partner-name {
    font-weight: 500;
    margin-bottom: 2px;
}

.partner-status {
    font-size: 12px;
    color: #94a3b8;
    display: flex;
    align-items: center;
    gap: 4px;
}

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

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 18px;
    word-wrap: break-word;
    animation: fadeIn 0.3s ease;
}

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

.message-sent {
    align-self: flex-end;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
    border-bottom-right-radius: 4px;
}

.message-received {
    align-self: flex-start;
    background: #1e293b;
    color: #f1f5f9;
    border: 1px solid #334155;
    border-bottom-left-radius: 4px;
}

.message-content {
    margin-bottom: 4px;
}

.message-time {
    font-size: 11px;
    opacity: 0.8;
    text-align: right;
}

.typing-indicator {
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #94a3b8;
    font-size: 12px;
    height: 30px;
    overflow: hidden;
}

.typing-dots {
    display: flex;
    gap: 3px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #94a3b8;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

.input-area {
    padding: 16px;
    background: #1e293b;
    border-top: 1px solid #334155;
}

.input-wrapper {
    display: flex;
    gap: 12px;
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 24px;
    padding: 8px 16px;
}

.message-input {
    flex: 1;
    background: none;
    border: none;
    color: #f1f5f9;
    font-family: inherit;
    font-size: 14px;
    outline: none;
    resize: none;
    max-height: 120px;
    min-height: 24px;
    padding: 8px 0;
}

.send-btn {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

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

.empty-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: #94a3b8;
    text-align: center;
}

.empty-chat-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.encryption-notice {
    margin-top: 20px;
    padding: 12px;
    background: #1e293b;
    border-radius: 8px;
    border: 1px solid #334155;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Мобильная адаптация */
@media (max-width: 480px) {
    .chat-header {
        padding: 8px 12px;
    }
    
    .messages-container {
        padding: 12px;
    }
    
    .input-area {
        padding: 12px;
    }
    
    .message {
        max-width: 85%;
    }
}

/* Стили для кнопки выхода */
.header-actions {
    display: flex;
    gap: 8px;
}

.logout-btn {
    background: #334155;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    color: #f1f5f9;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.logout-btn:hover {
    background: #475569;
}

.logout-btn svg {
    stroke: #f1f5f9;
}
