/* Library sidebar — fixed to the browser viewport's left edge, independent
   of .library-container's centering/max-width (issue #411). Split out of
   library.css purely for the 800-line file cap.

   --library-sidebar-offset is set by an inline script in layout.leaf that
   measures the actual rendered height of the global header (.banner +
   nav.main-nav in base.leaf), which varies with the banner image's
   responsive width. The fallback below covers the brief window before
   that script runs and any no-JS case. */
.sidebar {
    position: fixed;
    top: var(--library-sidebar-offset, 190px);
    bottom: 0;
    left: 0;
    z-index: 100;
    width: var(--library-sidebar-width, 240px);
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
    color: #fff;
    border-right: 1px solid rgba(255,255,255,0.08);
    box-shadow: inset -8px 0 20px rgba(15,23,42,0.35);
    transition: transform 0.25s ease;
}

.sidebar-header {
    flex-shrink: 0;
    padding: 24px 14px 12px;
}

.back-link {
    display: inline-block;
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    font-size: 0.9rem;
    margin-bottom: 12px;
    transition: color 0.2s ease;
}

.back-link:hover {
    color: rgba(255, 255, 255, 0.95);
}

.sidebar-title {
    margin: 0;
    font-size: 1.2rem;
    color: #fff;
    font-weight: 600;
    line-height: 1.3;
}

/* The lessons/courses list scrolls independently within its own region —
   the sidebar-header above and the sidebar-footer below stay in view. */
.sidebar-nav {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 10px;
}

.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 10px;
    color: rgba(255, 255, 255, 0.75);
    text-decoration: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.2s ease;
    position: relative;
}

.sidebar-nav-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.95);
}

.sidebar-nav-item.active {
    background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
    color: #fff;
    box-shadow: 0 4px 12px rgba(217, 119, 6, 0.4);
}

.sidebar-nav-item.active:hover {
    background: linear-gradient(135deg, #b45309 0%, #92400e 100%);
}

.nav-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    stroke-width: 2;
}

.nav-label {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-nav-item .lesson-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 24px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    flex-shrink: 0;
}

.sidebar-nav-item.active .lesson-number {
    background: rgba(255, 255, 255, 0.25);
}

.sidebar-nav-item .lock-icon {
    font-size: 0.8rem;
    margin-right: 0.25rem;
}

/* Public Videos link (issue #411) — pinned outside/below the scrollable
   .sidebar-nav region so it's always visible without scrolling. */
.sidebar-footer {
    flex-shrink: 0;
    padding: 14px 10px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* Mobile hamburger toggle and drawer backdrop — both no-ops above the
   768px breakpoint (see the media query below for their actual behavior). */
.sidebar-toggle {
    display: none;
}

.sidebar-backdrop {
    display: none;
}

@media (max-width: 768px) {
    /* A permanently fixed 240px sidebar isn't usable on a phone viewport —
       it would occupy a large share of the screen at all times. Rhett's
       feedback on the first pass (issue #411): hide it by default and
       reveal it as a slide-in drawer via a hamburger button instead of the
       old stacked-in-flow layout. The button itself now renders inline in
       nav.main-nav's own row (issue #466), left of the user menu — no
       longer independently fixed-positioned against the viewport. */
    .sidebar-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        border: none;
        border-radius: 8px;
        background: #0f172a;
        color: #fff;
        font-size: 1.2rem;
        line-height: 1;
        cursor: pointer;
        box-shadow: 0 2px 6px rgba(15, 23, 42, 0.35);
        flex-shrink: 0;
    }

    .sidebar {
        top: var(--library-sidebar-offset, 190px);
        width: min(80vw, 300px);
        z-index: 250;
        border-radius: 0 12px 12px 0;
        box-shadow: 4px 0 20px rgba(15, 23, 42, 0.4);
        transform: translateX(-100%);
    }

    .sidebar.sidebar-open {
        transform: translateX(0);
    }

    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 200;
        background: rgba(15, 23, 42, 0.5);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s ease;
    }

    .sidebar-backdrop.sidebar-open {
        opacity: 1;
        pointer-events: auto;
    }
}

/* Theater mode (issue #435) — desktop-width mirror of the mobile drawer
   above: same translateX(-100%) hide mechanic, applied above the 768px
   breakpoint instead of below it. Scoped to min-width: 769px so it never
   collides with the mobile drawer's own transform/`.sidebar-open` logic. */
@media (min-width: 769px) {
    .library-page.theater-mode .sidebar {
        transform: translateX(-100%);
    }
}
