:root {
    --primary: #3498db;
    --primary-dark: #2980b9;
    --secondary: #2c3e50;
    --light: #ecf0f1;
    --dark: #34495e;
    --success: #2ecc71;
    --danger: #e74c3c;
    --warning: #f39c12;
    --info: #1abc9c;
    --gray: #95a5a6;
    --light-gray: #bdc3c7;
    --chat-user: #3498db;
    --chat-bot: #e3f2fd;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; line-height: 1.6; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: #333; min-height: 100vh; }

.container { 
    max-width: 1400px; 
    margin: 0 auto; 
    display: flex; 
    flex-direction: column; 
    height: 100vh; 
    padding: 20px; 
}

/* --- HEADER --- */
header { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    margin-bottom: 20px; 
    color: white; 
}
.header-left { display: flex; align-items: center; gap: 15px; }
.logo h1 { font-size: 2rem; margin-bottom: 0; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3); line-height: 1.2; }
.logo .tagline { font-size: 1rem; opacity: 0.9; }

.menu-toggle { display: none; background: none; border: none; color: white; font-size: 1.8rem; cursor: pointer; }

.header-right { display: flex; align-items: center; gap: 20px; }
.header-downloads { display: flex; gap: 10px; }
.dl-icon { 
    display: flex; align-items: center; justify-content: center; width: 40px; height: 40px; 
    border-radius: 50%; color: white; text-decoration: none; font-size: 1.2rem;
    transition: all 0.3s; background: rgba(255, 255, 255, 0.2); 
}
.dl-icon:hover { background: rgba(255, 255, 255, 0.4); transform: translateY(-2px); }

.auth-buttons { display: flex; gap: 10px; align-items: center; }
.auth-btn { padding: 8px 16px; border-radius: 20px; border: none; font-weight: 600; cursor: pointer; transition: all 0.3s ease; white-space: nowrap; }
.login-btn { background: white; color: var(--primary); }
.login-btn:hover { background: #f0f0f0; }
.register-btn { background: var(--primary); color: white; }
.register-btn:hover { background: var(--primary-dark); }
.user-info { display: flex; align-items: center; gap: 10px; }
.user-login { font-weight: bold; font-size: 1.1rem; }

/* --- ОСНОВНАЯ ВЕРСТКА --- */
.app-layout {
    display: flex;
    flex: 1;
    gap: 20px;
    min-height: 0; /* Важно для прокрутки чата */
    margin-bottom: 20px;
    position: relative;
}

.card { background: white; border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15); overflow: hidden; }

/* --- SIDEBAR --- */
.sidebar { 
    width: 280px; 
    display: flex; 
    flex-direction: column; 
    padding: 15px; 
    flex-shrink: 0;
}
.new-chat-btn { 
    width: 100%; padding: 12px; background: var(--success); color: white; border: none; 
    border-radius: 8px; font-weight: bold; font-size: 1rem; cursor: pointer; 
    display: flex; align-items: center; justify-content: center; gap: 8px; transition: background 0.3s; 
}
.new-chat-btn:hover { background: #27ae60; }

.dialog-list { 
    margin-top: 15px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; 
    padding-right: 5px; /* Для скроллбара */
}
.dialog-list::-webkit-scrollbar { width: 5px; }
.dialog-list::-webkit-scrollbar-thumb { background: #ccc; border-radius: 10px; }

.dialog-item { 
    padding: 12px 15px; border-radius: 8px; cursor: pointer; transition: all 0.2s; 
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500;
    color: var(--secondary); background: #f8f9fa; border: 1px solid transparent;
}
.dialog-item:hover { background: #f0f5ff; border-color: #d0e1ff; }
.dialog-item.active { background: var(--primary); color: white; border-color: var(--primary-dark); }

/* --- CHAT SECTION --- */
.chat-section { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.chat-header { padding: 15px 20px; background: var(--primary); color: white; display: flex; align-items: center; gap: 10px; }
.chat-controls { display: flex; padding: 15px; background: #f0f5ff; border-bottom: 1px solid #ddd; flex-wrap: wrap; gap: 15px; align-items: center; }
.control-group { display: flex; align-items: center; gap: 8px; }
.control-group label { font-weight: 500; white-space: nowrap; }
select, input[type="text"] { padding: 8px 12px; border-radius: 6px; border: 1px solid #ccc; font-family: inherit; }

.microphone-btn { padding: 8px 16px; background: var(--info); color: white; border: none; border-radius: 20px; cursor: pointer; display: flex; align-items: center; gap: 8px; transition: background 0.3s; }
.microphone-btn:hover { background: #17a98c; }
.microphone-btn.active { background: var(--danger); }

.chat-messages { flex: 1; padding: 20px; overflow-y: auto; background: #f5f8fa; display: flex; flex-direction: column; gap: 15px; }
.message { max-width: 80%; padding: 12px 16px; border-radius: 18px; line-height: 1.4; position: relative; animation: fadeIn 0.3s ease; word-break: break-word; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.user-message { align-self: flex-end; background: var(--chat-user); color: white; border-bottom-right-radius: 4px; }
.bot-message { align-self: flex-start; background: var(--chat-bot); color: #333; border-bottom-left-radius: 4px; }
.message-time { font-size: 0.7rem; opacity: 0.7; margin-top: 5px; text-align: right; }

.message-actions { display: none; position: absolute; bottom: -15px; right: 10px; background: white; border-radius: 12px; box-shadow: 0 2px 5px rgba(0,0,0,0.2); padding: 2px 5px; z-index: 10; gap: 5px; }
.message:hover .message-actions { display: flex; }
.message-actions button { background: none; border: none; cursor: pointer; font-size: 0.85rem; padding: 4px; color: #555; transition: color 0.2s; }
.message-actions button:hover { color: var(--primary); }
.user-message .message-actions { left: 10px; right: auto; }

.chat-input { display: flex; padding: 20px; background: white; border-top: 1px solid #e0e0e0; align-items: flex-end; }
.chat-input-wrapper { flex: 1; position: relative; display: flex; align-items: center; background: #f9f9f9; border-radius: 24px; border: 1px solid #ddd; padding: 5px 15px; min-height: 46px; }
.chat-input textarea { flex: 1; border: none; outline: none; font-size: 1rem; resize: none; background: transparent; max-height: 120px; padding: 8px 0; font-family: inherit; }
.file-input-wrapper { position: relative; margin-right: 10px; }
.file-input-wrapper input[type="file"] { position: absolute; left: 0; top: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.attach-btn { background: none; border: none; color: var(--gray); font-size: 1.2rem; cursor: pointer; padding: 8px; border-radius: 50%; transition: all 0.3s; }
.attach-btn:hover { color: var(--primary); background: #f0f0f0; }
.chat-input button { margin-left: 10px; width: 46px; height: 46px; border-radius: 50%; border: none; background: var(--primary); color: white; cursor: pointer; transition: background 0.3s; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.chat-input button:hover { background: var(--primary-dark); }
.hint { position: absolute; bottom: -20px; right: 10px; font-size: 0.75rem; color: var(--gray); }

/* --- УВЕДОМЛЕНИЯ И МОДАЛКИ --- */
.notification { position: fixed; top: 20px; right: 20px; padding: 15px 20px; border-radius: 8px; color: white; font-weight: 500; z-index: 1000; max-width: 350px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); display: flex; align-items: center; gap: 10px; transform: translateX(100%); opacity: 0; transition: all 0.3s ease; }
.notification.show { transform: translateX(0); opacity: 1; }
.notification.success { background: var(--success); }
.notification.error { background: var(--danger); }
.notification.info { background: var(--info); }

footer { grid-column: 1 / -1; text-align: center; color: white; opacity: 0.8; }

.modal { display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.7); align-items: center; justify-content: center; }
.modal-content { background-color: white; border-radius: 12px; width: 100%; max-width: 400px; box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3); overflow: hidden; }
.modal-header { background: var(--primary); color: white; padding: 15px 20px; display: flex; justify-content: space-between; align-items: center; }
.modal-header h2 { margin: 0; font-size: 1.5rem; }
.modal-close, .recovery-close { font-size: 1.8rem; cursor: pointer; transition: all 0.3s; }
.modal-close:hover, .recovery-close:hover { color: var(--light-gray); }

#registerForm, #loginForm, #recoveryForm{ padding: 20px; }
.recovery-link { text-align: center; margin-top: 15px; }
.recovery-link a { color: #007bff; text-decoration: none; font-size: 14px; }
.form-group { margin-bottom: 15px; }
.form-group label { display: block; margin-bottom: 5px; font-weight: 500; color: var(--secondary); }
.form-group input { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 6px; font-size: 1rem; }
.form-group input:focus { outline: none; border-color: var(--primary); }
.modal-btn { width: 100%; padding: 12px; background: var(--primary); color: white; border: none; border-radius: 6px; font-size: 1rem; font-weight: 600; cursor: pointer; transition: background 0.3s; }
.modal-btn:hover { background: var(--primary-dark); }
.response-message { margin-top: 15px; padding: 10px; border-radius: 6px; text-align: center; display: none; }
.response-message.success { background: #d4edda; color: #155724; display: block; }
.response-message.error { background: #f8d7da; color: #721c24; display: block; }

.image-preview-container { margin-top: 10px; position: relative; display: inline-block; }
.image-preview { max-width: 75px; max-height: 75px; border-radius: 8px; border: 1px solid #ddd; }
.remove-image { position: absolute; top: -8px; right: -8px; background: var(--danger); color: white; border: none; border-radius: 50%; max-width: 24px; max-height: 24px; font-size: 14px; cursor: pointer; display: flex; align-items: center; justify-content: center; }

/* АДАПТИВНОСТЬ */
@media (max-width: 900px) {
    header { flex-wrap: wrap; gap: 15px; }
    .header-right { width: 100%; justify-content: space-between; }
}

@media (max-width: 750px) {
    .menu-toggle { display: block; }
    .header-right { justify-content: flex-end; }
    
    .sidebar { 
        position: absolute; 
        left: -320px; /* Спрятана за экраном */
        top: 0; 
        height: 100%; 
        z-index: 100; 
        transition: left 0.3s ease; 
        box-shadow: 5px 0 15px rgba(0,0,0,0.2);
    }
    .sidebar.open { left: 0; }
    
    .chat-controls { flex-direction: column; align-items: stretch; }
    .control-group { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 500px) {
    .modal-content { width: 95%; margin: 10px; }
    .auth-btn { padding: 8px 12px; font-size: 0.9rem; }
    .logo h1 { font-size: 1.5rem; }
    .dl-icon { width: 32px; height: 32px; font-size: 1rem; }
}
@media (max-width: 410px) {
    .chat-input { padding: 10px; }
    .chat-input-wrapper { min-height: 36px; padding: 3px 10px; }
    .attach-btn { font-size: 1rem; padding: 6px; margin-right: 5px; }
    .chat-input button { width: 36px; height: 36px; margin-left: 5px; }
    .chat-input textarea { font-size: 0.9rem; padding: 6px 0; }
    .hint { font-size: 0.65rem; bottom: -18px; }
}