/**
 * Enhanced Sidebar Styles
 * Professional sidebar navigation with submenus, animations, and responsive design
 */

/* ============================================
   CSS Variables for Sidebar
   ============================================ */
:root {
    --sidebar-bg: #ffffff;
    --sidebar-hover-bg: rgba(var(--primary-green-rgb, 10, 72, 111), 0.08);
    --sidebar-active-bg: var(--primary-green, #0a486f);
    --sidebar-text: #495057;
    --sidebar-text-hover: var(--primary-green, #0a486f);
    --sidebar-text-active: #ffffff;
    --sidebar-border: rgba(0, 0, 0, 0.06);
    --sidebar-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    --sidebar-transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --primary-green-rgb: 10, 72, 111;
}

/* External User Primary Colors - Green */
body.user-external {
    --sidebar-hover-bg: rgba(46, 157, 98, 0.08);
    --sidebar-active-bg: #2E9D62;
    --sidebar-text-hover: #2E9D62;
    --primary-green-rgb: 46, 157, 98;
}

/* ============================================
   Sidebar Base Enhancements
   ============================================ */
.sidebar {
    background: var(--sidebar-bg);
    box-shadow: var(--sidebar-shadow);
    border-right: 1px solid var(--sidebar-border);
}

/* Improved scrollbar */
.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
    margin: 8px 0;
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.12);
    border-radius: 4px;
}

.sidebar:hover::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
}

/* ============================================
   Navigation Items
   ============================================ */
.sidebar-nav {
    padding: 1rem 0;
}

.nav-item {
    padding: 4px;
    border-radius: 8px;
    overflow: hidden;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 13px 18px;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: 8px;
    transition: all var(--sidebar-transition);
    position: relative;
    gap: 14px;
}

.nav-link i:first-child {
    font-size: 1.2rem;
    min-width: 24px;
    text-align: center;
    transition: all var(--sidebar-transition);
}

.nav-link span {
    font-size: 0.9rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    opacity: 0;
    transition: opacity var(--sidebar-transition);
}

.sidebar.expanded .nav-link span {
    opacity: 1;
}

/* Hover State */
.nav-link:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-text-hover);
    transform: none;
}

.nav-link:hover i:first-child {
    transform: scale(1.08);
    color: var(--sidebar-text-hover);
}

/* Logout Link Override */
.nav-link.logout-link {
    color: #dc3545 !important;
}

.nav-link.logout-link:hover {
    background: rgba(220, 53, 69, 0.1) !important;
    color: #dc3545 !important;
}

.nav-link.logout-link i:first-child {
    color: #dc3545 !important;
}

.nav-link.logout-link:hover i:first-child {
    color: #dc3545 !important;
}

/* Active State */
.nav-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-text-active);
    transform: none;
    box-shadow: 0 2px 8px rgba(var(--primary-green-rgb, 10, 72, 111), 0.25);
}

.nav-link.active::before {
    display: none; /* Remove the left bar, using rounded bg instead */
}

.nav-link.active i,
.nav-link.active span {
    color: var(--sidebar-text-active);
}

.nav-link.active:hover {
    background: var(--sidebar-active-bg);
    filter: brightness(1.1);
}

/* ============================================
   Submenu Styles
   ============================================ */
.nav-item.has-submenu {
    position: relative;
}

.nav-item.has-submenu > .nav-link {
    padding-right: 14px;
}

/* Chevron indicator */
.nav-item.has-submenu > .nav-link .submenu-chevron {
    font-size: 0.6rem;
    margin-left: auto;
    opacity: 0.5;
    transition: all var(--sidebar-transition);
    flex-shrink: 0;
}

.nav-item.has-submenu.open > .nav-link .submenu-chevron {
    transform: rotate(90deg);
    opacity: 0.8;
}

.nav-item.has-submenu > .nav-link:hover .submenu-chevron {
    opacity: 0.7;
}

/* Submenu container */
.nav-item.has-submenu .submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    margin: 0;
    padding: 0;
}

.nav-item.has-submenu.open .submenu {
    max-height: 300px;
}

/* Submenu links */
.submenu-link {
    display: flex;
    align-items: center;
    padding: 11px 18px 11px 50px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all var(--sidebar-transition);
    position: relative;
    border-radius: 6px;
    margin: 3px 10px;
}

/* Dot indicator */
.submenu-link::before {
    content: '';
    position: absolute;
    left: 26px;
    top: 50%;
    transform: translateY(-50%);
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--sidebar-text);
    opacity: 0.25;
    transition: all var(--sidebar-transition);
}

/* Hover state */
.submenu-link:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-text-hover);
    padding-left: 52px;
}

.submenu-link:hover::before {
    opacity: 0.5;
    background: var(--sidebar-text-hover);
    transform: translateY(-50%) scale(1.2);
}

/* Active state */
.submenu-link.active {
    background: rgba(var(--primary-green-rgb, 10, 72, 111), 0.12);
    color: var(--sidebar-text-hover);
    font-weight: 600;
}

.submenu-link.active::before {
    opacity: 1;
    background: var(--sidebar-text-hover);
    width: 7px;
    height: 7px;
}

/* Hide submenu when sidebar is collapsed */
.sidebar:not(.expanded) .submenu {
    display: none !important;
}

.sidebar:not(.expanded) .submenu-chevron {
    display: none !important;
}

/* ============================================
   Bottom Navigation
   ============================================ */
.bottom-nav {
    margin-top: auto;
    border-top: 1px solid var(--sidebar-border);
}



.bottom-nav .nav-link {
    color: var(--sidebar-text);
    opacity: 0.85;
}

.bottom-nav .nav-link:hover {
    opacity: 1;
}

/* Logout link styling */
.logout-link {
    color: #dc3545!important;
}

.logout-link:hover {
    background: rgba(220, 53, 69, 0.1);
    color: #dc3545!important;
}

/* ============================================
   Course Navigation Toggle Button
   ============================================ */
.course-nav-toggle-btn {
    position: fixed;
    left: 65px;
    top: 135px;
    width: 44px;
    height: 44px;
    background: var(--primary-green, #0a486f);
    color: white;
    border: none;
    border-radius: 10px;
    padding: 8px;
    cursor: pointer;
    z-index: 9999;
    box-shadow: 0 3px 12px rgba(var(--primary-green-rgb, 10, 72, 111), 0.3);
    transition: all 0.25s ease;
    display: none !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
}

@media (min-width: 768px) {
    .course-nav-toggle-btn {
        left: 65px;
    }
}

.course-nav-toggle-btn.visible {
    display: flex !important;
}

.course-nav-toggle-btn:hover {
    background: #073a57;
    transform: scale(1.05);
    box-shadow: 0 4px 16px rgba(var(--primary-green-rgb, 10, 72, 111), 0.4);
}

.course-nav-toggle-btn:active {
    transform: scale(0.98);
}

.course-nav-toggle-btn i {
    font-size: 1.3rem;
}

.course-nav-toggle-btn .toggle-label {
    font-size: 0.55rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1;
}

/* ============================================
   Course Navigation Close Button
   ============================================ */
.course-nav-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.12);
    border: none;
    border-radius: 8px;
    width: 34px;
    height: 34px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.course-nav-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ============================================
   Modal Backdrop Fixes
   ============================================ */
/* Ensure modal backdrop is behind modal but above other content */
.modal-backdrop {
    opacity: 0.5 !important;
    z-index: 1040 !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background-color: rgba(0, 0, 0, 0.5) !important;
}

/* Ensure modal is above sidebar (1000), navbar (1001), and backdrop (1040) */
.modal {
    backdrop-filter: none !important;
    z-index: 1055 !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    outline: 0 !important;
}

.modal.show {
    display: block !important;
}

.modal-dialog {
    position: relative !important;
    width: auto !important;
    margin: 1.75rem auto !important;
    pointer-events: none !important;
    z-index: 1056 !important;
}

.modal-content {
    position: relative !important;
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    pointer-events: auto !important;
    background-color: #ffffff !important;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15) !important;
    border: none !important;
    border-radius: 12px !important;
    z-index: 1057 !important;
    outline: 0 !important;
}

/* ============================================
   Responsive Adjustments
   ============================================ */
@media (max-width: 768px) {
    .nav-item {
        margin: 1px 4px;
    }
    
    .nav-link {
        padding: 10px 12px;
    }
    
    .submenu-link {
        padding: 8px 12px 8px 40px;
    }
    
    .submenu-link::before {
        left: 20px;
    }
}

/* ============================================
   Low-Height Screen Adjustments
   ============================================ */

/* Low-height screens (≤800px height) */
@media (max-height: 800px) {
    .nav-item {
        padding: 2px;
    }
    
    .nav-link {
        padding: 10px 14px;
        gap: 10px;
    }
    
    .nav-link i:first-child {
        font-size: 1.1rem;
        min-width: 22px;
    }
    
    .nav-link span {
        font-size: 0.85rem;
    }
    
    .submenu-link {
        padding: 8px 12px 8px 38px;
        font-size: 0.8rem;
    }
    
    .submenu-link::before {
        left: 24px;
    }
    
    .bottom-nav {
        padding-top: 0.25rem;
    }
}

/* Very low-height screens (≤700px height) */
@media (max-height: 700px) {
    .nav-item {
        padding: 1px;
    }
    
    .nav-link {
        padding: 8px 12px;
        gap: 8px;
    }
    
    .nav-link i:first-child {
        font-size: 1rem;
        min-width: 20px;
    }
    
    .nav-link span {
        font-size: 0.8rem;
    }
    
    .submenu-link {
        padding: 6px 10px 6px 36px;
        font-size: 0.75rem;
    }
    
    .submenu-link::before {
        left: 22px;
    }
}

/* Low-height desktop (width ≥769px but height ≤800px) */
@media (min-width: 769px) and (max-height: 800px) {
    .nav-link {
        padding: 9px 14px;
    }
    
    .nav-link i:first-child {
        font-size: 1.05rem;
        min-width: 23px;
    }
}

/* Low-height desktop - very low (width ≥769px but height ≤700px) */
@media (min-width: 769px) and (max-height: 700px) {
    .nav-link {
        padding: 7px 12px;
    }
    
    .nav-link i:first-child {
        font-size: 0.95rem;
        min-width: 21px;
    }
    
    .nav-link span {
        font-size: 0.8rem;
    }
}

/* ============================================
   Tooltip for collapsed sidebar
   ============================================ */
.sidebar:not(.expanded) .nav-item {
    position: relative;
}

.sidebar:not(.expanded) .nav-link::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    background: #1a1a2e;
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    margin-left: 10px;
    z-index: 1001;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.sidebar:not(.expanded) .nav-link:hover::after {
    opacity: 1;
    visibility: visible;
}

/* ============================================
   Animation for page load
   ============================================ */
@keyframes slideInNav {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.sidebar-nav .nav-item {
    animation: slideInNav 0.3s ease forwards;
    opacity: 0;
}

.sidebar-nav .nav-item:nth-child(1) { animation-delay: 0.05s; }
.sidebar-nav .nav-item:nth-child(2) { animation-delay: 0.1s; }
.sidebar-nav .nav-item:nth-child(3) { animation-delay: 0.15s; }
.sidebar-nav .nav-item:nth-child(4) { animation-delay: 0.2s; }
.sidebar-nav .nav-item:nth-child(5) { animation-delay: 0.25s; }
.sidebar-nav .nav-item:nth-child(6) { animation-delay: 0.3s; }
.sidebar-nav .nav-item:nth-child(7) { animation-delay: 0.35s; }
.sidebar-nav .nav-item:nth-child(8) { animation-delay: 0.4s; }

.bottom-nav .nav-item {
    animation-delay: 0.45s;
}

