.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s ease;
}

.loading-logo { display: flex; flex-direction: column; align-items: center; gap: 14px; margin-bottom: 22px; }
.loading-logo span { font-size: 43px; font-weight: bold; color: var(--accent); letter-spacing: 5px; animation: pulse 1.5s infinite; }
.loading-spinner { width: 36px; height: 36px; border: 3px solid var(--border-color); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
.loading-text { margin-top: 14px; color: var(--text-muted); font-size: 13px; }

.main-screen { display: flex; height: 100vh; height: 100dvh; width: 100%; position: relative; }

.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-min-width);
    max-width: var(--sidebar-max-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: relative;
    flex-shrink: 0;
    z-index: 10;
    transition: none;
}

.sidebar-header {
    height: var(--header-height);
    padding: 0 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    gap: 11px;
}

.menu-btn, .search-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--border-radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--text-primary);
    background: transparent;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s ease;
    flex-shrink: 0;
    pointer-events: auto;
}

.menu-btn:hover, .search-btn:hover { background: var(--bg-tertiary); color: var(--accent); }

.sidebar-menu {
    position: fixed;
    top: 0;
    left: 0;
    width: 270px;
    height: 100vh;
    height: 100dvh;
    background: var(--bg-secondary);
    z-index: var(--z-sidebar);
    display: none;
    flex-direction: column;
    box-shadow: var(--shadow-xl);
    border-right: 1px solid var(--border-color);
    animation: slideInLeft 0.15s ease;
    pointer-events: auto;
    overflow-y: auto;
}

.close-menu-btn {
    width: 28px;
    height: 28px;
    border-radius: var(--border-radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    cursor: pointer;
    transition: all 0.2s ease;
    position: absolute;
    top: 12px;
    right: 12px;
    pointer-events: auto;
    z-index: 3;
}

.close-menu-btn:hover { background: var(--bg-quaternary); color: var(--text-primary); }

.menu-profile {
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    cursor: pointer;
    background: transparent;
    transition: background 0.2s ease;
    border-radius: var(--border-radius);
    margin: 0 11px 11px;
    position: relative;
}

.menu-profile:hover { background: var(--bg-tertiary); }

.menu-avatar-wrapper {
    position: relative;
    width: 45px;
    height: 45px;
    flex-shrink: 0;
}

.menu-avatar {
    width: 45px;
    height: 45px;
    border-radius: var(--border-radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: white;
    background: var(--accent);
    overflow: hidden;
}

.menu-avatar img { width: 100%; height: 100%; object-fit: cover; }

.menu-avatar-badge {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--bg-secondary);
    color: white;
    font-size: 9px;
    cursor: pointer;
    z-index: 2;
}

.menu-profile-info { flex: 1; min-width: 0; }
.menu-name { font-weight: 600; font-size: calc(14px * var(--text-scale, 1)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-username { font-size: calc(12px * var(--text-scale, 1)); color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.menu-items { flex: 1; overflow-y: auto; padding: 4px 0; }

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 18px;
    color: var(--text-primary);
    cursor: pointer;
    background: transparent;
    width: 100%;
    transition: background 0.2s ease;
    font-size: calc(14px * var(--text-scale, 1));
    border: none;
    text-align: left;
    pointer-events: auto;
}

.menu-item:hover { background: var(--bg-tertiary); }
.menu-item:active { background: rgba(255, 255, 255, 0.05); }

.menu-item i {
    width: 22px;
    color: var(--accent);
    font-size: 16px;
    text-align: center;
    flex-shrink: 0;
}

.menu-item .menu-item-text { flex-grow: 1; }
.menu-item .menu-item-value { color: var(--text-muted); font-size: 0.9em; }

.menu-item.danger { color: var(--danger); }
.menu-item.danger i { color: var(--danger); }
.menu-item.danger:hover { background: var(--danger-light); }

.menu-divider { height: 1px; background: var(--border-color); margin: 4px 0; }

.chat-list { flex: 1; overflow-y: auto; padding: 7px; position: relative; }

.chat-folder-list {
    display: flex;
    gap: 5px;
    padding: 5px 6px;
    overflow-x: auto;
    scroll-behavior: smooth;
    scrollbar-width: none;
    -ms-overflow-style: none;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    background: var(--bg-secondary);
    border-radius: 20px;
    margin: 3px 7px 0;
}

.chat-folder-list::-webkit-scrollbar { height: 0; }

.folder-tab {
    padding: 6px 13px;
    border-radius: 20px;
    font-size: calc(13px * var(--text-scale, 1));
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    color: #ffffff;
    background: transparent;
    transition: all 0.2s ease;
    pointer-events: auto;
}

.folder-tab:hover { background: rgba(255,255,255,0.08); }
.folder-tab.active { border: 1px solid var(--accent); color: #ffffff; background: transparent; }
.folder-add { background: transparent; border: 1px solid var(--border-color); color: var(--text-secondary); padding: 6px 9px; font-size: 16px; }
.folder-add:hover { background: rgba(255,255,255,0.08); }

.chat-item {
    display: flex;
    align-items: center;
    padding: 10px;
    border-radius: var(--border-radius);
    cursor: pointer;
    margin-bottom: 3px;
    animation: fadeIn 0.3s ease;
    background: transparent;
    transition: background 0.2s ease;
    position: relative;
    overflow: hidden;
    pointer-events: auto;
}

.chat-item:hover { background: var(--bg-tertiary); }
.chat-item.active { background: var(--accent); }
.chat-item.active .chat-item-name,
.chat-item.active .chat-item-message,
.chat-item.active .chat-item-meta { color: white; }

.chat-avatar-wrapper { position: relative; margin-right: 11px; flex-shrink: 0; }

.chat-avatar-sm {
    width: 54px;
    height: 54px;
    border-radius: var(--border-radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 500;
    color: white;
    background: var(--accent);
    overflow: hidden;
}

.chat-avatar-sm img { width: 100%; height: 100%; object-fit: cover; }

.online-indicator {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 13px;
    height: 13px;
    background: var(--success);
    border: 2px solid var(--bg-secondary);
    border-radius: var(--border-radius-full);
}

.chat-item-info { flex: 1; min-width: 0; }
.chat-item-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 3px; gap: 7px; }
.chat-item-name { font-weight: 600; font-size: calc(14px * var(--text-scale, 1)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 162px; }
.chat-item-meta { font-size: calc(11px * var(--text-scale, 1)); color: var(--text-muted); flex-shrink: 0; margin-left: 7px; }
.chat-item-last { display: flex; justify-content: space-between; align-items: center; }
.chat-item-message { font-size: calc(13px * var(--text-scale, 1)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; color: var(--text-secondary); }
.pinned-icon { color: var(--accent); font-size: 11px; margin-right: 4px; }

.unread-badge {
    background: var(--accent);
    color: white;
    font-size: 11px;
    font-weight: 600;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    flex-shrink: 0;
    margin-left: 7px;
}

.chat-area { flex: 1; display: flex; flex-direction: column; background: var(--bg-primary); position: relative; overflow: hidden; }
.empty-chat { flex: 1; display: flex; align-items: center; justify-content: center; }

.empty-state { text-align: center; animation: fadeIn 0.5s ease; padding: 36px; }
.empty-state h3 { font-size: calc(22px * var(--text-scale, 1)); margin-bottom: 7px; }
.empty-state p { font-size: calc(14px * var(--text-scale, 1)); margin-bottom: 22px; }

.active-chat {
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    background-image: url('/images/fon.png');
    background-size: cover;
    background-position: center;
}

.chat-header {
    height: var(--header-height);
    padding: 0 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    position: relative;
    z-index: 2;
    backdrop-filter: blur(10px);
    pointer-events: auto;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 11px;
    cursor: pointer;
    padding: 7px 11px;
    border-radius: var(--border-radius);
    background: transparent;
    transition: background 0.2s ease;
    flex: 1;
    min-width: 0;
    pointer-events: auto;
}

.chat-header-left:hover { background: var(--bg-tertiary); }

.back-btn-mobile {
    display: none;
    width: 36px;
    height: 36px;
    border-radius: var(--border-radius-full);
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    margin-right: 7px;
    cursor: pointer;
    flex-shrink: 0;
    border: 1px solid var(--border-color);
    transition: all 0.2s ease;
    pointer-events: auto;
}

.chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--border-radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 500;
    color: white;
    background: var(--accent);
    overflow: hidden;
    flex-shrink: 0;
}

.chat-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-header-info { display: flex; flex-direction: column; min-width: 0; }
.chat-title { font-size: calc(14px * var(--text-scale, 1)); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-subtitle { font-size: calc(12px * var(--text-scale, 1)); color: var(--text-muted); white-space: nowrap; }

.chat-header-right { display: flex; align-items: center; gap: 7px; flex-shrink: 0; }

.header-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--border-radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s ease;
    pointer-events: auto;
}

.header-btn:hover { background: var(--bg-quaternary); color: var(--accent); }
.header-btn i { pointer-events: none; }

.resize-handle {
    position: absolute;
    top: 0;
    right: -3px;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    z-index: 15;
    background: transparent;
    transition: background 0.2s;
}

.resize-handle:hover, .resize-handle.active { background: var(--accent); opacity: 0.5; }

.info-panel {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: var(--info-width);
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    display: none;
    flex-direction: column;
    z-index: var(--z-sidebar);
    animation: slideInRight 0.3s ease;
    pointer-events: auto;
}

.info-header {
    height: var(--header-height);
    padding: 0 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
}

.info-header h3 { font-size: 16px; font-weight: 600; }
.close-info-btn { font-size: 18px; color: var(--text-muted); cursor: pointer; transition: color 0.2s ease; pointer-events: auto; background: none; border: none; }
.close-info-btn:hover { color: var(--text-primary); }
.info-content { flex: 1; overflow-y: auto; padding: 18px; }

.fab-new-chat {
    position: absolute;
    bottom: 18px;
    right: 18px;
    width: 40px;
    height: 40px;
    border-radius: 20px;
    background: var(--accent);
    color: white;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    z-index: 25;
    border: none;
    transition: transform 0.2s, opacity 0.2s;
    opacity: 0.85;
}

.fab-new-chat:hover { transform: scale(1.1); opacity: 1; }
.fab-new-chat.close-state { transform: rotate(90deg); }

.fab-new-story {
    position: absolute;
    bottom: 66px;
    right: 25px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    z-index: 24;
    border: none;
    transition: transform 0.2s;
    opacity: 0.85;
}

.fab-new-story:hover { transform: scale(1.1); opacity: 1; }

.fab-context-menu {
    position: absolute;
    bottom: 66px;
    right: 18px;
    background: var(--bg-secondary);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 4px;
    z-index: 26;
    display: none;
    animation: scaleIn 0.15s ease;
    border: 1px solid var(--border-color);
    opacity: 0.95;
    min-width: 180px;
}

.fab-context-menu .context-menu-item { padding: 10px 14px; font-size: 13px; }

.maintenance-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 20px;
}