.cp-sidebar {
    position: fixed;
    top: var(--header-height, 70px);
    right: -320px;
    width: 70px;
    height: calc(100vh - var(--header-height, 70px));
    background-color: var(--bg-panel);
    border-left: 1px solid var(--border-color);
    z-index: var(--z-sidebar);
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: -10px 0 20px rgba(0, 0, 0, 0.4);
    overflow-x: hidden;
    white-space: nowrap;
}

.cp-sidebar.open { right: 0; }
.cp-sidebar.expanded { width: 320px; }

.cp-sidebar-header,
.cp-friends-list,
.cp-add-friend {
    width: 320px;
    min-width: 320px;
    box-sizing: border-box;
}

.cp-sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background-color: var(--bg-header-tabs);
    border-bottom: 1px solid var(--border-color);
}

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

.cp-icon-btn {
    background: none; border: none; color: var(--text-dim); cursor: pointer;
    padding: 4px; transition: var(--transition); display: flex;
}
.cp-icon-btn:hover { color: var(--text-pure); }
.cp-icon-btn svg { width: 22px; height: 22px; }

#pinFriendsBtn { transition: color 0.2s, background 0.2s; }
#pinFriendsBtn svg { transform: rotate(45deg); transition: transform 0.3s ease; }
#pinFriendsBtn.pinned { color: var(--primary); background: rgba(var(--primary-rgb), 0.1); border-radius: 6px; }
#pinFriendsBtn.pinned svg { transform: rotate(0deg); }

.cp-sidebar-tabs { display: flex; gap: 4px; }
.cp-tab-btn {
    position: relative; background: transparent; border: none; color: var(--text-dim);
    width: 40px; height: 40px; padding: 0; border-radius: 8px; cursor: pointer;
    transition: var(--transition); display: flex; justify-content: center; align-items: center; flex-shrink: 0;
}
.cp-tab-btn svg { width: 20px; height: 20px; }
.cp-tab-btn:hover { color: var(--text-pure); background: var(--border-lighter); }
.cp-tab-btn.active { color: var(--primary); background: rgba(var(--primary-rgb), 0.1); }

.cp-sidebar:not(.expanded) .cp-tab-btn.active { order: -1; }

.cp-badge {
    position: absolute; top: 0; right: -2px; background: var(--danger); color: white; font-size: 9px;
    font-weight: bold; min-width: 14px; height: 14px; border-radius: 7px; display: flex;
    justify-content: center; align-items: center; border: 2px solid var(--bg-header-tabs);
}

.cp-tab-content { display: none; flex-direction: column; flex: 1; overflow: hidden; }
.cp-tab-content.active { display: flex; }

.cp-friends-list { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 10px 0; }

.cp-section { margin-bottom: 5px; }
.cp-section-title { padding: 12px 15px 6px 15px; font-size: 0.75rem; text-transform: uppercase; font-weight: 700; color: var(--text-dim); letter-spacing: 0.5px; user-select: none; }
.cp-section-header { display: flex; justify-content: space-between; align-items: center; padding: 10px 15px; font-size: 0.75rem; text-transform: uppercase; font-weight: 700; color: var(--text-dim); letter-spacing: 0.5px; user-select: none; cursor: pointer; transition: all 0.2s; }
.cp-section-header:hover { color: var(--text-main); }
.cp-section-header .chevron { width: 16px; height: 16px; transition: transform 0.2s ease; transform: rotate(-90deg); }
.cp-section-header.open .chevron { transform: rotate(0deg); }
.cp-section-content { display: none; }
.cp-section-header.open + .cp-section-content { display: block; }

.cp-friend-item {
    display: flex; align-items: center; padding: 10px 15px; gap: 15px;
    cursor: pointer; transition: var(--transition); user-select: none; width: 100%; box-sizing: border-box;
}
.cp-friend-item:hover { background-color: var(--bg-item); }

.cp-friend-item .cp-layered-avatar { overflow: visible !important; }
.cp-friend-item .cp-layered-avatar > div { border-radius: 50%; overflow: hidden; }

.cp-friend-item.online .cp-layered-avatar::after {
    content: ''; position: absolute; bottom: 0; right: -2px; width: 12px; height: 12px;
    background: var(--success); border: 2px solid var(--bg-panel); border-radius: 50%; z-index: 5;
}
.cp-friend-item.is-favorite .cp-layered-avatar::before {
    content: '★'; position: absolute; bottom: -4px; left: -4px; color: var(--warning); font-size: 14px;
    display: flex; justify-content: center; align-items: center; border-radius: 50%; text-shadow: 0 1px 3px rgba(0,0,0,0.8); z-index: 6;
}

.cp-friend-item.offline .cp-layered-avatar { opacity: 0.6; }

.cp-friend-info { display: flex; flex-direction: column; min-width: 0; }
.cp-name { color: var(--text-pure); font-weight: 600; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cp-tag { color: var(--text-dim); font-weight: 400; font-size: 0.85rem; }
.cp-status { color: var(--text-dim); font-size: 0.8rem; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cp-friend-item.online .cp-status { color: var(--primary); }

.cp-request-actions { display: flex; gap: 8px; align-items: center; }
.req-btn { width: 32px !important; height: 32px !important; padding: 0 !important; border-radius: 8px; border: none; cursor: pointer; display: flex; justify-content: center; align-items: center; transition: var(--transition); flex-shrink: 0; }
.req-btn svg { width: 18px !important; height: 18px !important; display: block !important; stroke: currentColor !important; stroke-width: 2.5px !important; fill: none !important; }
.req-btn.accept { background: rgba(var(--success-rgb), 0.1); color: var(--success); }
.req-btn.accept:hover { background: var(--success); color: var(--text-pure); transform: scale(1.05); }
.req-btn.reject { background: rgba(var(--danger-rgb), 0.1); color: var(--danger); }
.req-btn.reject:hover { background: var(--danger); color: var(--text-pure); transform: scale(1.05); }

.request-item:hover { background-color: var(--bg-item); }

.cp-add-friend { display: flex; padding: 15px; background-color: var(--bg-header-tabs); border-top: 1px solid var(--border-color); gap: 8px; align-items: center; }
.cp-add-inputs-wrapper { flex: 1; min-width: 0; display: flex; align-items: center; background: var(--bg-panel); border: 1px solid var(--border-color); border-radius: 6px; padding: 0 8px; transition: var(--transition); }
.cp-add-inputs-wrapper:focus-within { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(var(--primary-rgb), 0.2); }
.cp-add-inputs-wrapper input { background: transparent; border: none; color: var(--text-pure); font-size: 0.9rem; padding: 10px 0; outline: none; }
#addFriendName { flex: 1; min-width: 0; width: 100%; }
.cp-hash { color: var(--text-dim); font-weight: bold; margin: 0 4px; user-select: none; }
#addFriendTag { width: 45px; text-align: left; flex-shrink: 0; }
.cp-add-friend button { background: var(--primary); color: white; border: none; border-radius: 6px; padding: 0; width: 40px; height: 40px; flex-shrink: 0; cursor: pointer; display: flex; justify-content: center; align-items: center; transition: var(--transition); }
.cp-add-friend button:hover { background: var(--primary-hover); }
.cp-add-friend button svg { width: 20px; height: 20px; }

.cp-context-menu { position: fixed; background: var(--bg-panel); border: 1px solid var(--border-color); border-radius: 6px; box-shadow: var(--shadow-md); padding: 6px 0; min-width: 190px; z-index: 9999; display: none; }
.cp-menu-item { display: block; width: 100%; text-align: left; padding: 10px 18px; background: none; border: none; color: var(--text-main); font-size: 0.9rem; font-weight: 500; cursor: pointer; transition: background 0.2s; text-transform: none; letter-spacing: normal; }
.cp-menu-item:hover { background: var(--bg-item); color: var(--text-pure); }
.cp-menu-item.danger { color: var(--danger); }
.cp-menu-item.danger:hover { background: rgba(var(--danger-rgb), 0.1); }
.cp-menu-divider { height: 1px; background: var(--border-color); margin: 4px 0; }

.cp-sidebar-toast { position: absolute; bottom: 80px; left: 50%; transform: translateX(-50%) translateY(20px); width: 85%; padding: 12px; border-radius: 8px; text-align: center; font-size: 0.85rem; font-weight: 600; z-index: 2000; opacity: 0; pointer-events: none; transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.cp-sidebar-toast.error { background: rgba(var(--danger-rgb), 0.15); border: 1px solid rgba(var(--danger-rgb), 0.3); color: var(--danger); box-shadow: 0 10px 25px rgba(0,0,0,0.5); }
.cp-sidebar-toast.success { background: rgba(var(--success-rgb), 0.15); border: 1px solid rgba(var(--success-rgb), 0.3); color: var(--success); box-shadow: 0 10px 25px rgba(0,0,0,0.5); }
.cp-sidebar-toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.cp-empty-state { padding: 20px 15px; color: var(--text-dim); font-size: 0.85rem; text-align: center; font-style: italic; user-select: none; }

.cp-sidebar:not(.expanded) .cp-name,
.cp-sidebar:not(.expanded) .cp-status,
.cp-sidebar:not(.expanded) .cp-request-actions,
.cp-sidebar:not(.expanded) .cp-sidebar-actions,
.cp-sidebar:not(.expanded) .cp-section-title,
.cp-sidebar:not(.expanded) .cp-empty-state { opacity: 0; pointer-events: none; }
.cp-sidebar:not(.expanded) .cp-add-inputs-wrapper { display: none; }
.cp-sidebar:not(.expanded) .cp-tab-btn:not(.active) { display: none; }
.cp-sidebar:not(.expanded) .cp-section-header { height: 2px; width: 40px; padding: 0; margin: 8px 15px; background-color: var(--border-color); border-radius: 2px; }
.cp-sidebar:not(.expanded) .cp-section-header span, .cp-sidebar:not(.expanded) .cp-section-header .chevron { display: none; }
.cp-name, .cp-status, .cp-request-actions, .cp-section-header span, .cp-section-header .chevron, .cp-sidebar-actions, .cp-tab-btn, .cp-section-title, .cp-empty-state { transition: opacity 0.2s ease; }

@media (max-width: 900px) {
    .cp-sidebar {
        right: -100vw;
    }
    .cp-sidebar.open, .cp-sidebar.expanded {
        width: 100vw;
        right: 0;
    }
    .cp-sidebar-header,
    .cp-friends-list,
    .cp-add-friend {
        width: 100vw;
        min-width: 100vw;
    }
    #pinFriendsBtn {
        display: none;
    }
}