/* Shared admin shell: fixed gradient sidebar + top bar + main area (matches admin/dashboard.php) */
:root {
    --admin-primary: #4f46e5;
    --admin-secondary: #7c3aed;
    --sidebar-width: 260px;
    --scrollbar-size: 16px;
    --scrollbar-thumb: #94a3b8;
    --scrollbar-thumb-hover: #64748b;
    --scrollbar-track: #e2e8f0;
    --sidebar-scrollbar-thumb: rgba(255, 255, 255, 0.55);
    --sidebar-scrollbar-track: rgba(0, 0, 0, 0.2);
}

html.admin-shell-active,
html:has(body.admin-dashboard) {
    overflow: hidden;
    height: 100%;
    max-height: 100%;
}

body.admin-dashboard {
    margin: 0;
    padding: 0;
    overflow: hidden !important;
    overflow-x: hidden;
    max-width: 100%;
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    min-height: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

body.admin-dashboard::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
}

.sidebar-wrapper {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: var(--sidebar-width);
    max-width: min(var(--sidebar-width), 100vw);
    height: 100dvh;
    max-height: 100dvh;
    background: linear-gradient(180deg, var(--admin-primary) 0%, var(--admin-secondary) 100%);
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    overscroll-behavior: contain;
}

.sidebar-header,
.sidebar-search {
    flex: 0 0 auto;
    flex-shrink: 0;
}

.sidebar-nav-scroll {
    flex: 1 1 auto;
    height: 0;
    min-height: 0;
    overflow-y: scroll;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
    scrollbar-width: auto;
    scrollbar-color: var(--sidebar-scrollbar-thumb) var(--sidebar-scrollbar-track);
    -ms-overflow-style: scrollbar;
    scrollbar-gutter: stable;
}

.sidebar-nav-scroll .sidebar-menu {
    overflow: visible;
    height: auto;
    min-height: min-content;
}

/* Fallback when scroll wrapper is missing (older cached markup) */
.sidebar-wrapper > .sidebar-menu {
    flex: 1 1 0;
    height: 0;
    min-height: 0;
    overflow-y: scroll;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
    scrollbar-width: auto;
    scrollbar-color: rgba(255, 255, 255, 0.55) rgba(0, 0, 0, 0.18);
}

.sidebar-nav-scroll::-webkit-scrollbar,
.sidebar-wrapper > .sidebar-menu::-webkit-scrollbar {
    width: var(--scrollbar-size, 16px);
    display: block;
}

.sidebar-nav-scroll::-webkit-scrollbar-track,
.sidebar-wrapper > .sidebar-menu::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.15);
}

.sidebar-nav-scroll::-webkit-scrollbar-thumb,
.sidebar-wrapper > .sidebar-menu::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.5);
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    background-clip: padding-box;
    min-height: 40px;
}

.sidebar-nav-scroll::-webkit-scrollbar-thumb:hover,
.sidebar-wrapper > .sidebar-menu::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.65);
    border: 1px solid rgba(0, 0, 0, 0.1);
    background-clip: padding-box;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    min-height: 60px;
    box-sizing: border-box;
    padding: 0 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.1);
}

.sidebar-mobile-close {
    display: none;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

.sidebar-mobile-close:hover {
    background: rgba(255, 255, 255, 0.28);
}

.admin-mobile-menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--admin-primary) 0%, var(--admin-secondary) 100%);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.35);
}

.admin-mobile-menu-btn:hover,
.admin-mobile-menu-btn:focus {
    color: #fff;
    filter: brightness(1.08);
    outline: none;
    box-shadow: 0 2px 12px rgba(79, 70, 229, 0.45);
}

.sidebar-search {
    padding: 12px 15px 10px 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-search .sidebar-search-inner {
    position: relative;
}

.sidebar-search .sidebar-search-inner .fa-search {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #64748b;
    font-size: 0.85rem;
    pointer-events: none;
    z-index: 2;
}

.sidebar-search input[type="search"] {
    width: 100%;
    padding: 0.45rem 0.65rem 0.45rem 2rem;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.95);
    color: #1e1b4b;
    font-size: 0.875rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.sidebar-search input[type="search"]::placeholder {
    color: #64748b;
}

.sidebar-search input[type="search"]:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.45);
    background: #fff;
}

.sidebar-search-empty {
    font-size: 0.8rem;
    opacity: 0.85;
}

.sidebar-brand {
    color: white;
    font-size: 1.15rem;
    font-weight: 700;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
}

.sidebar-brand:hover {
    color: white;
    text-decoration: none;
}

.sidebar-brand i {
    font-size: 1.5rem;
}

.sidebar-menu {
    list-style: none;
    padding: 10px 0 28px 0;
    margin: 0;
}

.sidebar-menu .nav-item {
    margin: 3px 10px;
}

.sidebar-menu .nav-item:last-child {
    margin-bottom: 15px;
}

.sidebar-menu .nav-link {
    color: rgba(255, 255, 255, 0.9);
    padding: 12px 15px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    transition: all 0.3s ease;
    font-weight: 500;
    font-size: 0.95rem;
    position: relative;
    width: 100%;
}

.sidebar-menu .nav-link span {
    flex: 1;
    min-width: 0;
}

.sidebar-menu .nav-link i {
    width: 20px;
    text-align: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.sidebar-menu .nav-link:hover {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    transform: translateX(5px);
}

.sidebar-menu .nav-link.active {
    background: rgba(255, 255, 255, 0.25);
    color: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.sidebar-menu .nav-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 60%;
    background: white;
    border-radius: 0 4px 4px 0;
}

.sidebar-menu .nav-link.dropdown-toggle {
    justify-content: space-between;
}

.sidebar-menu .dropdown-toggle::after {
    margin-left: auto;
    transition: transform 0.3s ease;
    border-top-color: rgba(255, 255, 255, 0.7);
    border-width: 0.4em 0.4em 0;
    margin-top: 0.2em;
}

.sidebar-menu .dropdown-toggle[aria-expanded="true"]::after {
    transform: rotate(180deg);
}

.sidebar-menu .dropdown-toggle[aria-expanded="true"] {
    background: rgba(255, 255, 255, 0.2);
}

.sidebar-menu .dropdown-menu {
    background: rgba(0, 0, 0, 0.3);
    border: none;
    border-radius: 8px;
    margin: 5px 0 5px 20px;
    padding: 8px 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    min-width: 200px;
    position: static !important;
    transform: none !important;
    float: none !important;
    display: block;
    opacity: 1;
    visibility: visible;
}

.sidebar-menu .nav-item.dropdown {
    position: relative;
}

.sidebar-menu .nav-item.dropdown .dropdown-menu {
    display: none;
    position: static !important;
    float: none !important;
    transform: none !important;
    will-change: auto !important;
}

.sidebar-menu .nav-item.dropdown.show .dropdown-menu,
.sidebar-menu .nav-item.dropdown .dropdown-menu.show {
    display: block !important;
}

.sidebar-menu .dropdown-item {
    color: rgba(255, 255, 255, 0.9);
    padding: 10px 20px 10px 15px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 12px;
    white-space: nowrap;
    overflow: visible;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    text-decoration: none;
}

.sidebar-menu .dropdown-item i {
    width: 18px;
    text-align: center;
    flex-shrink: 0;
    font-size: 1rem;
}

.sidebar-menu .dropdown-item:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border-left-color: white;
    padding-left: 18px;
}

.sidebar-menu .dropdown-item.active {
    background: rgba(255, 255, 255, 0.25);
    color: white;
    border-left-color: white;
    font-weight: 600;
}

.top-bar {
    position: fixed;
    top: 0;
    right: 0;
    left: var(--sidebar-width);
    height: 60px;
    max-width: 100%;
    background: white;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    z-index: 1050;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    transition: left 0.3s ease;
    overflow: visible;
    box-sizing: border-box;
}

.top-bar-brand,
.top-bar-actions,
.top-bar .admin-shell-user-dropdown {
    overflow: visible;
}

.top-bar .admin-shell-user-dropdown .dropdown-menu {
    z-index: 1060;
    margin-top: 0.35rem;
    min-width: 12rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.top-bar-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.top-bar .min-w-0 {
    min-width: 0;
}

.main-content-wrapper {
    margin-left: var(--sidebar-width);
    box-sizing: border-box;
    height: 100dvh;
    max-height: 100dvh;
    min-height: 0;
    background: #f5f7fa;
    transition: margin-left 0.3s ease;
    padding-top: 60px;
    width: calc(100% - var(--sidebar-width));
    max-width: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    scrollbar-width: auto;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

body.admin-dashboard .main-content-wrapper::-webkit-scrollbar {
    width: var(--scrollbar-size, 16px);
}

body.admin-dashboard .main-content-wrapper::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

body.admin-dashboard .main-content-wrapper::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 10px;
    border: 2px solid var(--scrollbar-track);
    min-height: 40px;
}

body.admin-dashboard .main-content-wrapper::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

.main-content {
    padding: 30px;
    max-width: 100%;
    overflow-x: hidden;
    box-sizing: border-box;
}

@media (max-width: 768px) {
    .main-content {
        padding: 16px 12px 22px;
    }
}

@media (max-width: 576px) {
    .main-content {
        padding: 12px 10px 18px;
    }
}

main.admin-layout-page-main {
    display: block;
    max-width: 100%;
}

@media (max-width: 768px) {
    .admin-mobile-menu-btn {
        display: inline-flex;
    }

    .sidebar-mobile-close {
        display: inline-flex;
    }

    .sidebar-wrapper {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 1065;
    }

    .sidebar-wrapper.mobile-open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
    }

    .main-content-wrapper {
        position: fixed;
        top: 60px;
        left: 0;
        right: 0;
        bottom: 0;
        margin-left: 0;
        width: 100% !important;
        height: auto !important;
        max-height: none !important;
        padding-top: 0 !important;
        overflow-y: scroll !important;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
    }

    .sidebar-wrapper.mobile-open .sidebar-nav-scroll {
        overflow-y: scroll !important;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
    }

    .top-bar {
        left: 0;
        padding-left: 12px;
        padding-right: 12px;
    }

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

    .top-bar-title {
        font-size: 0.95rem;
    }

    .top-bar-actions {
        flex-shrink: 0;
    }

    .top-bar-home-text {
        display: inline;
    }

    .top-bar-user-name {
        max-width: 90px;
        display: inline-block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        vertical-align: bottom;
    }

    .sidebar-menu .dropdown-menu {
        margin-left: 15px;
        min-width: auto;
    }

    .mobile-toggle {
        display: none !important;
    }

    body.admin-shell-layout.sidebar-mobile-open {
        overflow: hidden !important;
        touch-action: none;
    }

    body.admin-shell-layout.sidebar-mobile-open .sidebar-wrapper,
    body.admin-shell-layout.sidebar-mobile-open .sidebar-nav-scroll {
        touch-action: pan-y;
    }
}

@media (max-width: 400px) {
    .top-bar {
        padding-left: 12px;
    }

    .top-bar-home .top-bar-home-text {
        display: none !important;
    }

    .top-bar-home .fa-home {
        margin-right: 0 !important;
    }

    .top-bar-user-name {
        max-width: 60px;
    }
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

@media (max-width: 768px) {
    .sidebar-overlay.active {
        display: block;
        z-index: 1060;
    }
}

/* Super Admin shell (uses same sidebar scroll as admin) */
body.super-admin-dashboard {
    margin: 0;
    padding: 0;
    overflow: hidden !important;
    height: 100dvh;
    max-height: 100dvh;
    min-height: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Teacher / Student: Bootstrap column sidebar (#sidebarMenu) */
body.app-portal-layout {
    display: flex;
    flex-direction: column;
    overflow: hidden !important;
    height: 100dvh;
    max-height: 100dvh;
    min-height: 0;
}

body.app-portal-layout > nav.navbar,
body.app-portal-layout > .navbar {
    flex: 0 0 auto;
    position: relative;
    z-index: 1040;
    overflow: visible !important;
}

/* Let header dropdowns (notifications, profile) render above sidebar/main */
body.app-portal-layout .navbar .container-fluid,
body.app-portal-layout .navbar .navbar-collapse {
    overflow: visible !important;
}

@media (min-width: 992px) {
    body.app-portal-layout .navbar .navbar-collapse {
        overflow: visible !important;
    }
}

body.app-portal-layout .navbar .nav-item.dropdown {
    position: relative;
}

body.app-portal-layout .notification-dropdown {
    z-index: 1060 !important;
}

body.app-portal-layout > .container-fluid {
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

body.app-portal-layout .container-fluid > .row {
    flex: 1 1 0;
    min-height: 0;
    height: 100%;
    margin: 0;
}

body.app-portal-layout .app-role-sidebar.sidebar {
    min-height: 0;
    height: 100%;
    max-height: 100%;
    padding: 0;
    overflow: hidden;
}

body.app-portal-layout .app-sidebar-shell {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

body.app-portal-layout .app-sidebar-search-wrap {
    flex: 0 0 auto;
}

body.app-portal-layout .app-sidebar-nav-scroll {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: scroll;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    scrollbar-width: auto;
    scrollbar-color: var(--sidebar-scrollbar-thumb) var(--sidebar-scrollbar-track);
    scrollbar-gutter: stable;
}

body.app-portal-layout .app-sidebar-nav-scroll::-webkit-scrollbar {
    width: var(--scrollbar-size, 16px);
    display: block;
}

body.app-portal-layout .app-sidebar-nav-scroll::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.15);
}

body.app-portal-layout .app-sidebar-nav-scroll::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.5);
    border-radius: 10px;
}

/* Mobile: page scroll in main column (body overflow is hidden on app-portal-layout) */
@media (max-width: 767.98px) {
    body.app-portal-layout > .container-fluid {
        flex: 1 1 0;
        min-height: 0;
        overflow-y: scroll !important;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
        overscroll-behavior-y: contain;
    }

    body.app-portal-layout .container-fluid > .row {
        height: auto;
        min-height: min-content;
    }

    body.app-portal-layout .app-sidebar-nav-scroll {
        overflow-y: scroll !important;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
    }

    body.app-portal-layout #sidebarMenu.sidebar.show,
    body.app-portal-layout #sidebarMenu.sidebar.collapsing {
        max-height: min(70dvh, 480px);
    }
}

@media (min-width: 768px) {
    body.app-portal-layout .container-fluid > .row > main,
    body.app-portal-layout .container-fluid > .row > .sd-main,
    body.app-portal-layout .container-fluid > .row > .col-md-9,
    body.app-portal-layout .container-fluid > .row > .col-lg-10 {
        height: 100%;
        max-height: 100%;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
        scrollbar-width: auto;
        scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
    }
}
