/* ============================================================
   LIBRARY SIDEBAR CONTAINER
   ============================================================ */
#library-sidebar {
    position: fixed;
    top: 50%;
    left: -472px; /* Desktop: Peeks 40px */
    width: 512px;
    height: 85vh;
    transform: translateY(-50%);
    background: #1a1a1a;
    z-index: 999999;
    display: flex;
    flex-direction: column;
    border: 1px solid #333;
    border-left: none;
    border-radius: 0 12px 12px 0;
    box-shadow: 5px 0 25px rgba(0,0,0,0.6);
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#library-sidebar.active {
    left: 0 !important;
}

/* ============================================================
   TOGGLE HANDLE (The Trigger)
   ============================================================ */
#sidebar-toggle-handle {
    position: absolute;
    right: 0;
    top: 0;
    width: 40px;
    height: 55px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #888;
    font-size: 1.1rem;
    z-index: 10;
    transition: all 0.2s ease;
}

#sidebar-toggle-handle:hover { color: #fff; }

/* ============================================================
   MOBILE OVERRIDES (The Blue Tab Logic)
   ============================================================ */
@media (max-width: 1024px) {
    #library-sidebar {
        top: 0;
        left: -100% !important; /* Forces it completely off-screen */
        width: 100%;            /* Full screen width */
        height: 100%;           /* Full screen height */
        transform: none;        /* Remove the desktop centering */
        border-radius: 0;       /* Remove curved corners on mobile */
    }

    /* Keep the active state anchored to 0 */
    #library-sidebar.active {
        left: 0 !important;
    }

    /* When the sidebar is ACTIVE (Open), the handle sits top right */
    #library-sidebar.active #sidebar-toggle-handle {
        left: auto !important;
        right: 15px !important; 
        top: 15px !important;
        background: rgba(255, 255, 255, 0.1) !important; 
        border-radius: 50% !important;
        width: 44px !important;
        height: 44px !important;
    }

    /* When the sidebar is INACTIVE (Closed), it shows the Blue Tab */
    #library-sidebar:not(.active) #sidebar-toggle-handle {
        left: 100% !important; 
        right: auto !important;
        top: 44px !important; /* Positioned below top UI bars */
        background: #1489EF !important;
        border-radius: 0 8px 8px 0; /* Tab shape */
        width: 48px !important;
        height: 48px !important;
        display: none; /* Only show if logged in */
    }

    /* Reveal blue tab if logged in */
    body.user-logged-in #library-sidebar:not(.active) #sidebar-toggle-handle {
        display: flex !important;
        color: #ffffff !important; /* Forces the icon to be white */
    }
}

/* ============================================================
   INTERNAL UI (Header, List, Items)
   ============================================================ */
.sidebar-header {
    position: relative;
    display: flex;
    align-items: center;
    height: 55px;
    margin-top: 10px;
    background: transparent;
}

.sidebar-header h3 {
    margin: 0;
    padding-left: 15px;
    flex-grow: 1;
    color: #efefef;
    font-size: 1rem;
    opacity: 0;
    transition: opacity 0.2s;
}

#library-sidebar.active h3 { opacity: 1; }

#library-list-container {
    flex-grow: 1;
    padding: 10px;
    overflow-y: auto;
    direction: rtl; /* Scrollbar on left */
}

#library-list-container > * { direction: ltr; }

.library-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    margin-bottom: 8px;
    background: #222;
    border: 1px solid #333;
    border-radius: 8px;
}

.item-info { flex-grow: 1; min-width: 0; cursor: pointer; }

.item-title {
    color: #efefef;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-meta { color: #666; font-size: 0.75rem; }

.item-actions { display: flex; gap: 5px; }

.lib-action-btn {
    width: 30px;
    height: 30px;
    background: #2e2e2e;
    border: 1px solid #444;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #aaa;
    cursor: pointer;
}