/* ═══════════════════════════════════════════════════════════════════
   SIDEBAR — css/components/sidebar.css
   ═══════════════════════════════════════════════════════════════════
   Primary navigation: brand header, year/term badge pills, collapsible
   nav groups, a "hub" overlay that expands a section into a full module
   picker, and the pinned user-profile footer.

   All colors come from the semantic tokens in base/variables.css
   (--sidebar-bg, --sidebar-text, etc). Those tokens already flip value
   between [data-theme="dark"]/[data-theme="light"] — this file never
   needs to re-declare per-theme colors itself.
   ═══════════════════════════════════════════════════════════════════ */

/* ─────────────────────────────────────────────────────────────────
   SHELL
   ───────────────────────────────────────────────────────────────── */

.sidebar {
    width: var(--sidebar-w, 272px);
    min-width: var(--sidebar-w, 272px);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    position: relative;
    z-index: 100;
    box-shadow: 4px 0 40px rgba(0, 0, 0, 0.3);
    transition: width var(--transition), background var(--transition), transform 0.38s cubic-bezier(0.22, 1, 0.36, 1);
}

/* Thin animated accent hairline on the sidebar's trailing edge */
.sidebar::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 1px;
    background: linear-gradient(180deg, transparent 0%, var(--accent-glow, rgba(59, 130, 246, 0.18)) 30%, rgba(139, 92, 246, 0.35) 60%, transparent 100%);
    animation: sidebarEdgeGlow 4s ease-in-out infinite alternate;
}

@keyframes sidebarEdgeGlow {
    0% {
        opacity: 0.3;
    }

    100% {
        opacity: 0.8;
    }
}

/* Entrance (replaces GSAP stagger from the original mockup) */
.sidebar-header,
.nav-group,
.user-profile {
    animation: sidebarFadeIn 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.nav-group:nth-child(1) {
    animation-delay: 0.02s;
}

.nav-group:nth-child(2) {
    animation-delay: 0.05s;
}

.nav-group:nth-child(3) {
    animation-delay: 0.08s;
}

.nav-group:nth-child(4) {
    animation-delay: 0.11s;
}

.nav-group:nth-child(5) {
    animation-delay: 0.14s;
}

.nav-group:nth-child(6) {
    animation-delay: 0.17s;
}

.nav-group:nth-child(7) {
    animation-delay: 0.20s;
}

.nav-group:nth-child(8) {
    animation-delay: 0.23s;
}

.user-profile {
    animation-delay: 0.3s;
}

@keyframes sidebarFadeIn {
    from {
        opacity: 0;
        transform: translateX(-12px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@media (prefers-reduced-motion: reduce) {

    .sidebar-header,
    .nav-group,
    .user-profile,
    .sidebar::after {
        animation: none;
    }
}

/* ─────────────────────────────────────────────────────────────────
   HEADER / BRAND
   ───────────────────────────────────────────────────────────────── */

.sidebar-header {
    padding: 16px 16px 12px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--sidebar-border);
}

.school-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-box {
    width: 46px;
    height: 46px;
    border-radius: 12px;
    background: linear-gradient(135deg, #1a3a5c 0%, var(--accent) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 16px var(--accent-glow, rgba(59, 130, 246, 0.18));
    position: relative;
    overflow: hidden;
}

.logo-box::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.15) 0%, transparent 60%);
}

.logo-box svg {
    width: 24px;
    height: 24px;
    fill: var(--text-inverse, #f1f5f9);
    position: relative;
    z-index: 1;
}

.brand-text {
    flex: 1;
    min-width: 0;
}

.brand-name {
    font-family: 'Syne', sans-serif;
    font-size: 13px;
    font-weight: 700;
    color: var(--sidebar-text);
    letter-spacing: 0.3px;
    line-height: 1.2;
}

.brand-sub {
    font-size: 10px;
    color: var(--sidebar-text-muted);
    letter-spacing: 0.2px;
    margin-top: 1px;
}

/* Sidebar collapse toggle (desktop only) — sits opposite the logo */
.sidebar-collapse-btn {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    border: 1px solid var(--sidebar-border);
    background: transparent;
    color: var(--sidebar-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all var(--transition-fast, 0.15s ease);
}

.sidebar-collapse-btn:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text);
}

.sidebar-collapse-btn svg {
    width: 13px;
    height: 13px;
    transition: transform 0.3s ease;
}

.sidebar.collapsed .sidebar-collapse-btn svg {
    transform: rotate(180deg);
}

/* ─────────────────────────────────────────────────────────────────
   BADGE ROW — Academic Year / Term selector (Rule #9: everything in
   the app reads state.currentYear / state.currentTerm from here)
   ───────────────────────────────────────────────────────────────── */

.badge-row {
    display: flex;
    gap: 6px;
    margin-top: 10px;
    position: relative;
    flex-wrap: wrap;
    align-items: center;
}

.badge-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px 4px 8px;
    border-radius: 99px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--sidebar-border);
    font-size: 10.5px;
    font-weight: 500;
    color: var(--sidebar-text-dim);
    cursor: pointer;
    user-select: none;
    transition: background var(--transition), border-color var(--transition);
}

.badge-pill:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.18);
}

.badge-pill strong {
    color: var(--sidebar-text);
    font-weight: 600;
}

.badge-pill .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.badge-pill .dot.green {
    background: var(--success);
}

.badge-pill .dot.blue {
    background: var(--accent);
}

.badge-pill .dot.locked {
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--warning);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--sidebar-bg);
}

.badge-pill .dot.locked svg {
    width: 7px;
    height: 7px;
}

.badge-pill .badge-chevron {
    font-size: 9px;
    opacity: 0.5;
    transition: transform 0.25s ease;
}

.badge-pill.open .badge-chevron {
    transform: rotate(180deg);
}

/* Badge dropdown (year / term picker) */
.badge-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 200px;
    background: var(--badge-dropdown-bg, var(--sidebar-bg));
    border: 1px solid var(--sidebar-border);
    border-radius: 12px;
    padding: 8px 0;
    box-shadow: var(--shadow);
    z-index: 300;
    display: none;
    animation: badgeDropIn 0.18s cubic-bezier(0.22, 1, 0.36, 1);
}

.badge-dropdown.open {
    display: block;
}

@keyframes badgeDropIn {
    from {
        opacity: 0;
        transform: translateY(-6px) scale(0.97);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.badge-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    font-size: 13px;
    color: var(--sidebar-text-dim);
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
}

.badge-dropdown-item:hover {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-text);
}

.badge-dropdown-item.active {
    color: var(--sidebar-text);
    background: var(--sidebar-active-bg);
}

.badge-dropdown-item.locked {
    opacity: 0.6;
}

.badge-dropdown-item .lock-icon {
    font-size: 9px;
    color: var(--warning);
    margin-left: 4px;
}

.badge-dropdown-item .check {
    font-size: 12px;
    color: var(--sidebar-active-color);
    opacity: 0;
    margin-left: auto;
    transition: opacity 0.15s;
}

.badge-dropdown-item.active .check {
    opacity: 1;
}

/* Help button — restyled from the original bright yellow/red FAB to match
   the shell's accent system instead of clashing with it */
.help-button {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 1px solid var(--sidebar-border);
    background: var(--accent-glow, rgba(59, 130, 246, 0.18));
    color: var(--accent-light, #60a5fa);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all var(--transition-fast, 0.15s ease);
    position: relative;
}

.help-button:hover {
    background: rgba(59, 130, 246, 0.28);
    transform: scale(1.08);
}

.help-button svg {
    width: 12px;
    height: 12px;
}

.help-button .tooltip {
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--dropdown-bg, var(--sidebar-bg));
    border: 1px solid var(--sidebar-border);
    color: var(--sidebar-text);
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 9px;
    font-weight: 600;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, top 0.2s;
}

.help-button:hover .tooltip {
    top: -34px;
    opacity: 1;
}

/* ─────────────────────────────────────────────────────────────────
   NAVIGATION
   ───────────────────────────────────────────────────────────────── */

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 8px 12px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.08) transparent;
}

.sidebar-nav::-webkit-scrollbar {
    width: 3px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 10px;
}

.nav-section-label {
    padding: 12px 10px 4px;
    font-size: 9px;
    font-weight: 700;
    color: var(--sidebar-text-muted);
    text-transform: uppercase;
    letter-spacing: 1.4px;
}

.nav-group {
    margin: 1px 0;
}

.nav-group-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--sidebar-text-muted);
    font-size: 13px;
    font-weight: 500;
    user-select: none;
    transition: background 0.18s, color 0.18s;
}

.nav-group-header svg,
.nav-group-header i {
    width: 18px;
    flex-shrink: 0;
    font-size: 15px;
    text-align: center;
    color: var(--sidebar-text-muted);
    transition: color 0.2s, stroke 0.2s;
}

.nav-group-header svg {
    height: 18px;
    stroke: var(--sidebar-text-muted);
}

.nav-group-header .label {
    flex: 1;
}

.nav-group-header:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text);
}

.nav-group-header:hover svg {
    stroke: var(--sidebar-text-dim);
}

.nav-group-header:hover i {
    color: var(--sidebar-text-dim);
}

.nav-group-header.open {
    color: var(--sidebar-text);
}

.nav-group-header.open svg:first-of-type {
    stroke: var(--sidebar-active-color);
}

.nav-group-header.open i {
    color: var(--sidebar-active-color);
}

.nav-chevron {
    width: 10px;
    height: 10px;
    flex-shrink: 0;
    color: var(--sidebar-text-muted);
    transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1), color 0.2s;
}

.nav-group-header.open .nav-chevron {
    transform: rotate(90deg);
    color: var(--sidebar-text-dim);
}

/* Children */
.nav-children {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.32s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.25s ease, margin 0.25s ease;
    opacity: 0;
    margin-left: 22px;
    padding-left: 10px;
    border-left: 1px solid var(--sidebar-border);
}

.nav-children.open {
    grid-template-rows: 1fr;
    opacity: 1;
    margin-bottom: 4px;
}

.nav-children-inner {
    overflow: hidden;
    padding: 3px 0 3px 2px;
}

.nav-child {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--sidebar-text-muted);
    font-size: 12.5px;
    margin: 1px 0;
    transition: background 0.15s, color 0.15s;
}

.nav-child .child-dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--sidebar-text-muted);
    flex-shrink: 0;
    transition: background 0.2s, transform 0.2s;
}

.nav-child .child-label {
    flex: 1;
}

.nav-child:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--sidebar-text-dim);
}

.nav-child:hover .child-dot {
    background: var(--sidebar-text-dim);
}

.nav-child.active {
    color: var(--sidebar-active-color);
}

.nav-child.active .child-dot {
    background: var(--accent);
    transform: scale(1.4);
}

.child-badge {
    margin-left: auto;
    font-size: 9px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 99px;
    line-height: 16px;
    flex-shrink: 0;
    background: rgba(var(--accent-rgb, 59, 130, 246), 0.22);
    color: var(--accent-light, #60a5fa);
}

.child-badge.red {
    background: rgba(var(--danger-rgb, 239, 68, 68), 0.2);
    color: #fca5a5;
}

.child-badge.green {
    background: rgba(var(--success-rgb, 16, 185, 129), 0.2);
    color: #6ee7b7;
}

.child-badge.amber {
    background: rgba(var(--warning-rgb, 245, 158, 11), 0.2);
    color: #fde68a;
}

/* ─────────────────────────────────────────────────────────────────
   USER PROFILE (pinned footer)
   ───────────────────────────────────────────────────────────────── */

.user-profile {
    flex-shrink: 0;
    padding: 12px 14px;
    border-top: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--sidebar-surface, #0d1625);
}

.user-profile .user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1e3a5f, var(--accent));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    color: var(--accent-light, #60a5fa);
    flex-shrink: 0;
    border: 1.5px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 12px var(--accent-glow, rgba(59, 130, 246, 0.18));
}

.user-profile .user-info {
    flex: 1;
    min-width: 0;
}

.user-profile .user-name {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--sidebar-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-profile .user-role {
    font-size: 10px;
    color: var(--sidebar-text-muted);
    text-transform: capitalize;
    letter-spacing: 0.2px;
}

.user-profile .logout-btn {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--sidebar-text-muted);
    transition: background 0.2s, color 0.2s;
    flex-shrink: 0;
}

.user-profile .logout-btn:hover {
    background: rgba(var(--danger-rgb, 239, 68, 68), 0.12);
    color: var(--danger);
}

.user-profile .logout-btn i {
    font-size: 13px;
}

/* ─────────────────────────────────────────────────────────────────
   HUB OVERLAY — expands a nav section's label into a full module grid
   ───────────────────────────────────────────────────────────────── */

.hub-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5, 10, 20, 0.82);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 500;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: hubFadeIn 0.25s ease;
}

.hub-overlay.show {
    display: flex;
}

@keyframes hubFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.hub-panel {
    background: linear-gradient(145deg, var(--sidebar-surface, #0d1625) 0%, var(--topbar-bg) 100%);
    border: 1px solid var(--card-border, rgba(255, 255, 255, 0.07));
    border-radius: 24px;
    width: 100%;
    max-width: 860px;
    max-height: 85vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow), 0 0 0 1px var(--accent-glow, rgba(59, 130, 246, 0.18));
    animation: hubSlideUp 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes hubSlideUp {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.hub-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--card-border, rgba(255, 255, 255, 0.07));
    flex-shrink: 0;
}

.hub-header-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.hub-header h2 {
    font-family: 'Syne', sans-serif;
    font-size: 18px;
    font-weight: 700;
    color: var(--sidebar-text);
    flex: 1;
}

.hub-header-sub {
    font-size: 12px;
    color: var(--sidebar-text-muted);
    margin-top: 1px;
}

.hub-close {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: none;
    background: rgba(255, 255, 255, 0.06);
    color: var(--sidebar-text-muted);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
    flex-shrink: 0;
}

.hub-close:hover {
    background: rgba(var(--danger-rgb, 239, 68, 68), 0.15);
    color: var(--danger);
}

.hub-body {
    overflow-y: auto;
    padding: 20px 24px 24px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.08) transparent;
}

.hub-body::-webkit-scrollbar {
    width: 4px;
}

.hub-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 99px;
}

.hub-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
}

.hub-card {
    background: var(--card-bg, rgba(255, 255, 255, 0.03));
    border: 1px solid var(--card-border, rgba(255, 255, 255, 0.07));
    border-radius: 14px;
    padding: 16px 14px 14px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    transition: background 0.22s, border-color 0.22s, transform 0.22s, box-shadow 0.22s;
}

.hub-card:hover {
    background: var(--card-hover, rgba(59, 130, 246, 0.08));
    border-color: var(--accent-glow, rgba(59, 130, 246, 0.18));
    transform: translateY(-3px);
    box-shadow: 0 8px 28px var(--accent-glow, rgba(59, 130, 246, 0.18));
}

.hub-card:active {
    transform: translateY(-1px);
}

.hub-card-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    margin-bottom: 2px;
}

.hub-card-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--card-text, #e2e8f0);
    line-height: 1.3;
}

.hub-card-desc {
    font-size: 11px;
    color: var(--card-text-muted, #475569);
    line-height: 1.4;
}

/* ─────────────────────────────────────────────────────────────────
   MOBILE OVERLAY (backdrop behind sidebar when open on small screens)
   ───────────────────────────────────────────────────────────────── */

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0);
    backdrop-filter: blur(0px);
    z-index: 90;
    transition: background 0.35s ease, backdrop-filter 0.35s ease;
}

.sidebar-overlay.show {
    display: block;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(4px);
}

/* ─────────────────────────────────────────────────────────────────
   RESPONSIVE
   ───────────────────────────────────────────────────────────────── */

@media (max-width: 820px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(-100%);
        border-radius: 0 20px 20px 0;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: 8px 0 60px rgba(0, 0, 0, 0.4);
    }

    .sidebar-collapse-btn {
        display: none;
    }
}

@media (max-width: 480px) {
    .sidebar {
        width: 260px;
        min-width: 260px;
    }
}

/* Collapsed state — desktop only */
@media (min-width: 821px) {
    .sidebar.collapsed {
        width: 64px;
        min-width: 64px;
    }

    .sidebar.collapsed .brand-text,
    .sidebar.collapsed .badge-row,
    .sidebar.collapsed .nav-section-label,
    .sidebar.collapsed .nav-group-header .label,
    .sidebar.collapsed .nav-chevron,
    .sidebar.collapsed .nav-children,
    .sidebar.collapsed .user-profile .user-info,
    .sidebar.collapsed .user-profile .logout-btn {
        display: none;
    }

    .sidebar.collapsed .nav-group-header,
    .sidebar.collapsed .user-profile {
        justify-content: center;
        padding: 8px;
    }

    /* Collapsed hover flyout — shows children as a floating panel instead
     of the inline expand, so navigation still works when collapsed */
    .sidebar.collapsed .nav-group {
        position: relative;
    }

    .sidebar.collapsed .nav-group:hover .nav-children-flyout {
        display: block;
    }

    .nav-children-flyout {
        display: none;
        position: absolute;
        left: calc(100% + 8px);
        top: 0;
        min-width: 200px;
        background: var(--dropdown-bg, var(--sidebar-bg));
        border: 1px solid var(--sidebar-border);
        border-radius: 10px;
        padding: 6px 0;
        box-shadow: var(--shadow);
        z-index: 150;
        animation: badgeDropIn 0.15s ease;
    }
}