/* ============================================================
   SKKK LMS — Modern Sidebar  (Bootstrap 5 + FA 6)
   ============================================================ */

:root {
    --sb-width:          260px;
    --sb-collapsed-w:    72px;
    --sb-bg-from:        #0f1729;
    --sb-bg-to:          #1a2744;
    --sb-accent:         #667eea;
    --sb-accent-soft:    rgba(102,126,234,.12);
    --sb-border:         rgba(255,255,255,.06);
    --sb-text:           #c8d0e0;
    --sb-text-dim:       #7b8a9e;
    --sb-transition:     all .25s cubic-bezier(.4,0,.2,1);
    --topbar-h:          60px;
}

/* ── Base ── */
*,*::before,*::after { box-sizing: border-box; }

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    position: fixed;
    inset-block: 0;
    left: 0;
    width: var(--sb-width);
    background: linear-gradient(160deg, var(--sb-bg-from) 0%, var(--sb-bg-to) 100%);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: var(--sb-transition);
    box-shadow: 4px 0 24px rgba(0,0,0,.25);
    overflow: hidden;
}

/* ── Collapsed state ── */
.sidebar.collapsed { width: var(--sb-collapsed-w); }

/* Suppress transition while restoring saved state on page load */
body.sidebar-no-transition .sidebar,
body.sidebar-no-transition .main-content { transition: none !important; }

.sidebar.collapsed .logo-text-wrap,
.sidebar.collapsed .nav-text,
.sidebar.collapsed .submenu-arrow,
.sidebar.collapsed .sidebar-user-info,
.sidebar.collapsed .btn-logout-text { display: none; }

.sidebar.collapsed .submenu { display: none !important; }
.sidebar.collapsed .nav-link { justify-content: center; padding-inline: 0; }
.sidebar.collapsed .nav-icon { margin: 0; }
.sidebar.collapsed .sidebar-user { justify-content: center; }
.sidebar.collapsed .btn-logout { justify-content: center; }
.sidebar.collapsed .sidebar-collapse-btn i { transform: rotate(180deg); }

.sidebar.collapsed .sidebar-header {
    flex-direction: column;
    justify-content: center;
    gap: .625rem;
    padding: 1rem .5rem;
}
.sidebar.collapsed .logo-wrap { justify-content: center; }

/* ── Header ── */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.125rem 1.25rem;
    border-bottom: 1px solid var(--sb-border);
    flex-shrink: 0;
    min-height: var(--topbar-h);
}

.logo-wrap {
    display: flex;
    align-items: center;
    gap: .75rem;
    overflow: hidden;
}

.logo-icon-box {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1rem;
    color: #fff;
    box-shadow: 0 4px 12px rgba(102,126,234,.4);
}

.logo-title {
    display: block;
    font-size: .9rem;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    letter-spacing: .02em;
}

.logo-sub {
    display: block;
    font-size: .68rem;
    color: var(--sb-text-dim);
    white-space: nowrap;
}

.sidebar-collapse-btn {
    flex-shrink: 0;
    background: none;
    border: 1px solid var(--sb-border);
    color: var(--sb-text-dim);
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: .7rem;
    transition: var(--sb-transition);
}

.sidebar-collapse-btn:hover {
    background: var(--sb-accent-soft);
    border-color: rgba(102,126,234,.4);
    color: #fff;
}

.sidebar-collapse-btn i { transition: transform .25s ease; }

/* ── Nav ── */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: .75rem 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(102,126,234,.25) transparent;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(102,126,234,.25);
    border-radius: 4px;
}

.nav-menu {
    list-style: none;
    margin: 0;
    padding: 0 .75rem;
}

.nav-item { margin-bottom: 2px; }

.nav-link {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .7rem .875rem;
    color: var(--sb-text);
    text-decoration: none;
    border-radius: 8px;
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--sb-transition);
    border: 1px solid transparent;
}

.nav-link:hover {
    background: var(--sb-accent-soft);
    color: #fff;
    border-color: rgba(102,126,234,.15);
}

.nav-link:focus,
.nav-link:focus-visible,
.nav-link:active {
    background: var(--sb-accent-soft);
    color: #fff;
    border-color: rgba(102,126,234,.15);
    outline: none;
    box-shadow: none;
}

.nav-link.active {
    background: linear-gradient(90deg, rgba(102,126,234,.2), rgba(102,126,234,.08));
    color: #a8b8ff;
    border-color: rgba(102,126,234,.25);
    font-weight: 600;
}

.nav-icon {
    width: 20px;
    text-align: center;
    font-size: .95rem;
    flex-shrink: 0;
    color: inherit;
}

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

.submenu-arrow {
    margin-left: auto;
    font-size: .65rem;
    color: var(--sb-text-dim);
    transition: transform .22s ease;
    flex-shrink: 0;
}

.submenu-arrow i.rotated { transform: rotate(90deg); }

/* ── Submenu ── */
.submenu {
    list-style: none;
    margin: 2px 0 0;
    padding: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height .3s ease;
}

.submenu.show { max-height: 600px; }

.submenu-link {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .55rem .875rem .55rem 2.6rem;
    color: var(--sb-text-dim);
    text-decoration: none;
    font-size: .82rem;
    border-radius: 7px;
    transition: var(--sb-transition);
    border: 1px solid transparent;
}

.submenu-link:hover {
    background: var(--sb-accent-soft);
    color: #cdd5e0;
    border-color: rgba(102,126,234,.1);
}

.submenu-link.active {
    color: #a8b8ff;
    background: rgba(102,126,234,.1);
}

.submenu-link i { font-size: .78rem; width: 14px; color: inherit; }

.submenu-title { display: none; }

/* ── Flyout submenu (collapsed sidebar, hover) ── */
.sidebar.collapsed .submenu.flyout-show {
    display: block !important;
    position: fixed;
    max-height: none;
    min-width: 210px;
    margin: 0;
    padding: .4rem;
    background: var(--sb-bg-to);
    border: 1px solid var(--sb-border);
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(0,0,0,.45);
    z-index: 2000;
    animation: flyoutIn .15s ease;
}

.sidebar.collapsed .submenu.flyout-show .submenu-title {
    display: block;
    padding: .3rem .75rem .5rem;
    margin-bottom: .3rem;
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--sb-text-dim);
    border-bottom: 1px solid var(--sb-border);
}

.sidebar.collapsed .submenu.flyout-show .submenu-link {
    padding: .55rem .75rem;
}

@keyframes flyoutIn {
    from { opacity: 0; transform: translateX(-6px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* ── Footer: User + Logout ── */
.sidebar-footer {
    padding: 1rem .875rem;
    border-top: 1px solid var(--sb-border);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: .6rem;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .5rem .625rem;
    border-radius: 10px;
    background: rgba(255,255,255,.04);
    border: 1px solid var(--sb-border);
}

.sidebar-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    flex-shrink: 0;
    object-fit: cover;
    border: 2px solid rgba(102,126,234,.4);
}

.sidebar-user-info {
    overflow: hidden;
    flex: 1;
}

.sidebar-user-name {
    display: block;
    font-size: .8rem;
    font-weight: 600;
    color: #e2e8f4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    display: block;
    font-size: .68rem;
    color: var(--sb-text-dim);
}

.logout-form { width: 100%; }

.btn-logout {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: .65rem;
    padding: .6rem .875rem;
    background: none;
    border: 1px solid rgba(239,68,68,.2);
    border-radius: 8px;
    color: #f87272;
    font-size: .82rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--sb-transition);
    text-align: left;
}

.btn-logout:hover {
    background: rgba(239,68,68,.1);
    border-color: rgba(239,68,68,.4);
    color: #fc8181;
}

.btn-logout i { font-size: .9rem; }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
    margin-left: var(--sb-width);
    min-height: 100vh;
    transition: var(--sb-transition);
    background: #f1f5f9;
    display: flex;
    flex-direction: column;
}

.main-content.sidebar-collapsed {
    margin-left: var(--sb-collapsed-w);
}

/* ============================================================
   TOP BAR
   ============================================================ */
.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--topbar-h);
    background: #fff;
    border-bottom: 1px solid #e8edf4;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.75rem;
    box-shadow: 0 1px 0 rgba(0,0,0,.06);
    flex-shrink: 0;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: .875rem;
}

.topbar-mobile-toggle {
    display: none;
    background: none;
    border: 1px solid #e2e8f0;
    border-radius: 7px;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #64748b;
    font-size: .9rem;
    transition: background .15s;
}

.topbar-mobile-toggle:hover { background: #f8fafc; }

.topbar-breadcrumb {
    font-size: .82rem;
    color: #64748b;
}

.topbar-breadcrumb .bc-current {
    color: #1e293b;
    font-weight: 600;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: .5rem;
}

/* User dropdown in topbar */
.topbar-user-btn {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .375rem .75rem .375rem .375rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 2rem;
    cursor: pointer;
    transition: var(--sb-transition);
    text-decoration: none;
}

.topbar-user-btn:hover { background: #f1f5f9; border-color: #cbd5e1; }

.topbar-user-btn img {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    object-fit: cover;
}

.topbar-user-btn .topbar-username {
    font-size: .82rem;
    font-weight: 600;
    color: #334155;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar-user-btn .topbar-caret {
    font-size: .65rem;
    color: #94a3b8;
}

/* Dropdown menu */
.topbar-dropdown .dropdown-menu {
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,.1);
    padding: .375rem;
    min-width: 180px;
}

.topbar-dropdown .dropdown-item {
    border-radius: 7px;
    font-size: .83rem;
    padding: .55rem .75rem;
    color: #374151;
    display: flex;
    align-items: center;
    gap: .625rem;
}

.topbar-dropdown .dropdown-item:hover { background: #f1f5f9; }

.topbar-dropdown .dropdown-divider { margin: .25rem 0; border-color: #f1f5f9; }

.topbar-dropdown .dropdown-item.text-danger { color: #ef4444 !important; }
.topbar-dropdown .dropdown-item.text-danger:hover { background: #fef2f2; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        z-index: 1050;
    }
    .sidebar.show-mobile { transform: translateX(0); }
    .main-content { margin-left: 0 !important; }
    .topbar-mobile-toggle { display: flex; }
    .topbar-username { display: none; }
}

@media (max-width: 576px) {
    .topbar { padding: 0 1rem; }
}
