/* main.css - Базовые стили и layout */

/* ==================== RESET & BASE STYLES ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Цвета светлой темы */
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #e0e7ff;
    --secondary: #8b5cf6;
    --accent: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;

    /* Оттенки серого */
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;

    /* Фоны */
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;
    --bg-overlay: rgba(0, 0, 0, 0.5);

    /* Текст */
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-tertiary: #9ca3af;
    --text-inverse: #ffffff;

    /* Границы */
    --border-color: #e5e7eb;
    --border-radius: 12px;
    --border-radius-sm: 8px;
    --border-radius-lg: 16px;
    --border-radius-xl: 24px;

    /* Тени */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);

    /* Анимации */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 350ms ease;

    /* Размеры */
    --header-height: 64px;
    --nav-width: 72px;
    --sidebar-width: 400px;
    --right-panel-width: 280px;
    --mobile-nav-height: 60px;

    /* Цвета для сообщений */
    --message-in: #f3f4f6;
    --message-out: #dcfce7;
}

[data-theme="dark"] {
    --primary: #818cf8;
    --primary-hover: #6366f1;
    --primary-light: rgba(99, 102, 241, 0.2);
    --bg-primary: #111827;
    --bg-secondary: #1f2937;
    --bg-tertiary: #374151;
    --bg-overlay: rgba(0, 0, 0, 0.7);
    --text-primary: #f9fafb;
    --text-secondary: #d1d5db;
    --text-tertiary: #9ca3af;
    --border-color: #374151;
    --message-in: #374151;
    --message-out: #1f2937;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.5;
    color: var(--text-primary);
    background: #f0f2f5;
    min-height: 100vh;
    overflow-x: hidden;
}

[data-theme="dark"] body {
    background: #0f1419;
}

/* ==================== TYPOGRAPHY ==================== */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.2;
    margin-bottom: 0.5rem;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1rem; }

p { margin-bottom: 1rem; }

a {
    color: var(--primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover { color: var(--primary-hover); }

small {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* ==================== LAYOUT ==================== */
.app-wrapper {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    position: relative;
    background: var(--bg-primary);
    min-height: 100vh;
    box-shadow: var(--shadow-xl);
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.app-header {
    height: var(--header-height);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: relative;
    z-index: 150;
}

.app-main {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

/* ==================== НАВИГАЦИЯ (БУРГЕР + САЙДБАР) - ИСПРАВЛЕНО ==================== */
/* Кнопка бургера теперь в main area, слева от chat-info */
.menu-toggle {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    display: block;
    z-index: 200;
    position: relative;
    margin-right: 1rem;
}

/* Сайдбар навигации - теперь внутри .app-main, не fixed */
.sidebar-nav-container {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 72px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: width var(--transition-normal);
    overflow: hidden;
}

.sidebar-nav-container.active {
    width: 240px;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    padding: 0;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    width: 100%;
    border: none;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    text-align: left;
    font-size: 0.9rem;
    transition: all var(--transition-fast);
    white-space: nowrap;
    position: relative;
}

.nav-item span {
    display: none;
    transition: display var(--transition-fast);
}

.sidebar-nav-container.active .nav-item span {
    display: inline;
}

.nav-item i {
    min-width: 28px;
    text-align: center;
    font-size: 1.5rem;
}

.nav-item.active {
    background: var(--primary-light);
    color: var(--primary);
}

.sidebar-nav .nav-item:first-child {
    margin-top: 0;
    padding-top: 1rem;
}

.badge {
    position: absolute;
    right: 1rem;
    background: var(--danger);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    min-width: 1.25rem;
    height: 1.25rem;
    border-radius: 0.625rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.375rem;
}

.badge.hidden { display: none; }

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
}

.sidebar-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 1rem;
    font-size: 1rem;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.sidebar-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

/* ==================== ПАНЕЛЬ КОНТЕНТА ==================== */
.sidebar-content-container {
    position: absolute;
    left: 72px;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    z-index: 90;
    transform: translateX(-100%);
    transition: transform var(--transition-normal);
    opacity: 0;
}

.sidebar-content-container.active {
    transform: translateX(0);
    opacity: 1;
}

.sidebar-content-container.hidden {
    display: none;
}

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

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

/* ==================== ОБЛАСТЬ ЧАТА ==================== */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    position: relative;
    margin-left: 72px;
    transition: margin-left var(--transition-normal);
}

.chat-area.hidden {
    display: none;
}

/* ==================== ПРАВАЯ ПАНЕЛЬ ==================== */
.right-panel {
    position: fixed;
    right: -280px;
    top: var(--header-height);
    bottom: 0;
    width: var(--right-panel-width);
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    z-index: 160;
    transition: right var(--transition-normal);
}

.right-panel.active {
    right: 0;
}

/* ==================== ОВЕРЛЕЙ ==================== */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-overlay);
    backdrop-filter: blur(5px);
    z-index: 80;
    transition: opacity var(--transition-normal);
    opacity: 0;
    pointer-events: none;
}

.overlay.active {
    opacity: 0.5;
    pointer-events: auto;
}

/* ==================== МОБИЛЬНАЯ НАВИГАЦИЯ ==================== */
.mobile-nav {
    display: none;
}

/* ==================== HEADER ==================== */
.header-title {
    display: none !important;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.close-sidebar-content {
    background: none !important;
    border: none !important;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.25rem;
    padding: 0.5rem;
    border-radius: 50%;
    transition: all var(--transition-fast);
}

.close-sidebar-content:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-tertiary);
    border-radius: var(--border-radius);
    font-size: 0.875rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--gray-400);
}

.status-dot.online {
    background: var(--accent);
    animation: pulse 2s infinite;
}

.header-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: all var(--transition-fast);
}

.header-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* ==================== ПОЛЬЗОВАТЕЛЬСКОЕ МЕНЮ ==================== */
.user-menu {
    position: relative;
}

.user-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1rem;
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    width: 280px;
    background: var(--bg-primary);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-xl);
    z-index: 1000;
    display: none;
}

.dropdown-menu.active {
    display: block;
    animation: slideDown var(--transition-normal);
}

.dropdown-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.75rem 1rem;
    border: none;
    background: none;
    text-align: left;
    color: var(--text-primary);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.dropdown-item:hover {
    background: var(--bg-tertiary);
}

.dropdown-item.logout {
    color: var(--danger);
}

/* ==================== CHAT HEADER ==================== */
.chat-header {
    height: 72px;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-primary);
    flex-shrink: 0;
}

.chat-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.chat-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1.25rem;
}

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

.chat-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 1rem;
}

.chat-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    max-width: 100%;
}

.chat-meta span {
    white-space: nowrap;
}

.chat-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chat-actions .header-btn {
    width: 44px;
    height: 44px;
    font-size: 1.1rem;
}

/* ==================== MESSAGES AREA ==================== */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.typing-indicator {
    padding: 1rem 1.5rem;
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-style: italic;
}

.typing-indicator.hidden {
    display: none;
}

/* ==================== MESSAGE INPUT ==================== */
.chat-input-container {
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-primary);
}

.message-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
}

.message-input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.875rem;
    resize: none;
    min-height: 44px;
    max-height: 120px;
    transition: border-color var(--transition-fast);
    line-height: 1.4;
}

.message-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.input-tools {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.input-tool-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    transition: all var(--transition-fast);
}

.input-tool-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
    transform: translateY(-2px);
}

.send-btn {
    background: var(--primary);
    color: white;
    border: none;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* ==================== MESSAGES ==================== */
.message {
    max-width: 75%;
    padding: 0.75rem 1.25rem;
    border-radius: 20px;
    box-shadow: var(--shadow-sm);
    position: relative;
    animation: messageSlide 0.3s ease;
}

.message-incoming {
    background: var(--message-in);
    border-bottom-left-radius: 4px;
    align-self: flex-start;
}

.message-outgoing {
    background: var(--message-out);
    border-bottom-right-radius: 4px;
    align-self: flex-end;
    color: #166534;
}

.message-body {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    margin-bottom: 0.25rem;
}

.message-sender {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-time {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    white-space: nowrap;
    flex-shrink: 0;
}

.message-content {
    word-wrap: break-word;
    line-height: 1.4;
}

.message-text {
    font-size: 0.875rem;
}

.message-status {
    position: absolute;
    bottom: 0.5rem;
    right: 0.75rem;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.message-status.read {
    color: var(--accent);
}

.message-status i {
    font-size: 0.625rem;
}

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

/* ==================== AUTH SECTION ==================== */
.auth-section {
    min-height: 100vh;
    display: none;
    flex-direction: column;
    background: linear-gradient(135deg, var(--primary-light) 0%, transparent 100%);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2000;
}

.auth-section.active {
    display: flex;
}

.auth-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.auth-header {
    text-align: center;
    margin-bottom: 3rem;
}

.auth-header .logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.auth-header .logo img {
    width: 64px;
    height: 64px;
    border-radius: var(--border-radius);
}

.auth-header h1 {
    font-size: 3rem;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.auth-header .subtitle {
    color: var(--text-secondary);
    font-size: 1.25rem;
}

.auth-forms {
    width: 100%;
    max-width: 400px;
    background: var(--bg-primary);
    border-radius: var(--border-radius-lg);
    padding: 2.5rem;
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border-color);
}

.auth-form {
    display: none;
}

.auth-form.active {
    display: block;
    animation: fadeIn var(--transition-normal);
}

.auth-form h2 {
    text-align: center;
    margin-bottom: 2rem;
    color: var(--text-primary);
}

.auth-footer {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
    text-align: center;
    color: var(--text-secondary);
}

.auth-error {
    margin-top: 1rem;
    padding: 1rem;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--danger);
    border-radius: var(--border-radius-sm);
    color: var(--danger);
    text-align: center;
}

.auth-features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 2rem;
    padding: 3rem 2rem;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
}

.feature {
    text-align: center;
    padding: 1.5rem;
}

.feature i {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    color: var(--primary);
}

.feature h3 {
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.feature p {
    color: var(--text-secondary);
    margin: 0;
}

.password-wrapper {
    position: relative;
}

.toggle-password {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 0.25rem;
}

.input-with-hint {
    position: relative;
}

.input-with-hint .hint {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
}

.input-with-hint input {
    padding-left: 2rem;
}

/* ==================== ANIMATIONS ==================== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ==================== SCROLLBAR ==================== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--gray-400);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
    background: var(--gray-700);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
    background: var(--gray-600);
}

/* ==================== FORMS ==================== */
.input-group {
    margin-bottom: 1rem;
}

.input-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

.input-group input,
.input-group textarea,
.input-group select {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.875rem;
    transition: all var(--transition-fast);
}

.input-group input:focus,
.input-group textarea:focus,
.input-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.input-group textarea {
    min-height: 100px;
    resize: vertical;
}

/* ==================== UTILITIES ==================== */
.hidden { display: none !important; }
.visible { display: block !important; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }
.text-danger { color: var(--danger); }
.text-success { color: var(--accent); }
.bg-primary { background: var(--bg-primary); }
.bg-secondary { background: var(--bg-secondary); }
.bg-tertiary { background: var(--bg-tertiary); }
.rounded { border-radius: var(--border-radius); }
.rounded-sm { border-radius: var(--border-radius-sm); }
.rounded-lg { border-radius: var(--border-radius-lg); }
.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow-md { box-shadow: var(--shadow-md); }
.shadow-lg { box-shadow: var(--shadow-lg); }
.text-center { text-align: center; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.w-full { width: 100%; }
.h-full { height: 100%; }
