/* ==========================================================================
   Navigation CSS - Top Navbar & Navigation Controls
   ========================================================================== */

/* 1. Top Navbar Structure
   ========================================================================== */
body .app-container .top-navbar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: var(--navbar-height) !important;
    background-color: #ffffff !important;
    z-index: var(--z-navbar);
    padding: 0 1rem;
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

/* Container Layout */
.top-navbar .container-fluid {
    height: 72px;
    margin: 36px auto;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: transparent;  /* Remove background color */
    width: 100%;
    max-width: none;
    padding: 0 1rem;
}

/* 2. Navigation Controls
   ========================================================================== */
.nav-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 100%;
    padding: 0;
}

.control-item {
    height: 48px;
    width: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.control-item .btn-link,
.control-item .nav-link {
    height: 100%;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin: 0;
    color: var(--primary-color) !important;
    text-decoration: none;
    border: none;
    background: transparent !important;
    border-radius: 4px;
}

.control-item .btn-link:hover,
.control-item .nav-link:hover {
    background-color: rgba(0, 0, 0, 0.05) !important;
}

.nav-controls .control-item i {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    font-size: 1.2rem;
    color: var(--primary-color) !important;
}

/* 3. Logo Container
   ========================================================================== */
.logo-container {
    height: 100%;
    display: flex;
    align-items: center;
    padding: 0 1rem;
}

.logo-container a {
    height: 100%;
    display: flex;
    align-items: center;
}

.logo {
    height: 40px;
    width: auto;
    max-height: 40px;
}

.logo-long {
    height: 40px;
    max-width: 200px;
    display: block;
    transition: all 0.3s ease;
}

/* Make logo 25% larger when sidebar is open (not collapsed) */
body:not(.sidebar-collapsed) .logo-long {
    height: 50px;
    max-width: 250px;
    transform: scale(1.5);
    padding-left: 25%;
}

.logo-square {
    height: 40px;
    max-width: 40px;
    display: none;
    margin-left: -66%;
}

.logo-small {
    display: none;
    max-height: 32px;
}

/* 4. Portal and Organization Selectors
   ========================================================================== */
.navbar-center {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 100%;
    padding: 0 8px;
    margin: 0;
    margin-left: auto;
}

.selector-container {
    position: relative;
    height: 48px;
    min-width: 180px;
}

.selector-container .dropdown {
    height: 100%;
}

.selector-container .dropdown-toggle {
    height: 48px;
    width: 100%;
    padding: 0 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--primary-color) !important;
    background: rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    white-space: nowrap;
    justify-content: flex-start;
    cursor: pointer;
    transition: all 0.2s ease;
}

.selector-container .dropdown-toggle span {
    color: var(--primary-color) !important;
}

.selector-container .dropdown-toggle i {
    color: var(--primary-color) !important;
}

.selector-container .dropdown-toggle:hover {
    background: rgba(0, 0, 0, 0.1);
}

.selector-container .dropdown-toggle:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(var(--primary-color), 0.2);
}

/* Ensure the dropdown button doesn't change on click */
.selector-container .dropdown-toggle:active,
.selector-container .dropdown-toggle:focus {
    background: rgba(0, 0, 0, 0.05);
    box-shadow: none;
}

.selector-container .dropdown-toggle span {
    font-weight: 500;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.selector-container .dropdown-toggle i {
    font-size: 16px;
    opacity: 0.8;
    flex-shrink: 0;
}

/* 5. Navbar Dropdowns
   ========================================================================== */
.navbar-right .dropdown-menu {
    background-color: var(--primary-color);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    box-shadow: var(--shadow-lg);
    min-width: 200px;
}

.navbar-right .dropdown-menu .dropdown-item {
    display: block;
    width: 100%;
    padding: 0.75rem 1rem;
    color: var(--primary-text) !important;
    padding: 0.75rem 1rem;
}

.navbar-right .dropdown-menu .dropdown-item i {
    width: 20px;
    text-align: center;
    font-size: 1em;
}

.navbar-right .dropdown-menu .dropdown-item:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Portal and Org Selector Dropdown Styles - ULTRA SPECIFIC */
.navbar-center .selector-container .dropdown .dropdown-menu,
.navbar-center .selector-container .dropdown-menu,
.selector-container .dropdown .dropdown-menu,
/* REMOVED - This was conflicting with Bootstrap's .show class */

/* REMOVED - Let Bootstrap handle dropdown display naturally */

.navbar-center .selector-container .dropdown-item {
    color: var(--primary-text) !important;
    padding: 0.75rem 1rem;
    display: block;
}

.navbar-center .selector-container .dropdown-item:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* CONSISTENT POSITIONING FOR ALL TOP NAVBAR DROPDOWNS */
.top-navbar .dropdown-menu {
    position: absolute !important;
    top: 100% !important;
    left: 0 !important;
    z-index: var(--z-dropdown) !important;
    min-width: 200px !important;
    max-height: 400px !important;
    overflow-y: auto !important;
    margin-top: 4px !important;
    background-color: var(--primary-color) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    border-radius: 4px !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
    transform: none !important;
    clip: none !important;
    clip-path: none !important;
}

.selector-container .dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: var(--z-dropdown);
    min-width: 200px;
    max-height: 400px;
    overflow-y: auto;
    margin-top: 4px;
    background-color: var(--primary-color);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* REMOVED - Let Bootstrap handle .show class naturally */

.selector-container .dropdown-item {
    color: var(--primary-text) !important;
    padding: 0.75rem 1rem;
    display: block;
}

.selector-container .dropdown-item:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* 6. Theme Toggle
   ========================================================================== */
.theme-toggle-wrapper {
    width: 48px;  /* Reduced from 96px */
    height: 48px;  /* Match other control items */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: transparent;
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;  /* Reduced from 60px */
    height: 24px;  /* Reduced from 34px */
    margin: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.1);
    transition: 0.4s;
    border-radius: 34px;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.slider:before {
    content: "";
    position: absolute;
    height: 18px;  /* Reduced knob size */
    width: 18px;  /* Reduced knob size */
    left: 2px;  /* Adjusted positioning */
    bottom: 2px;  /* Adjusted positioning */
    background-color: white;
    transition: 0.4s;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

input:checked + .slider {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

input:focus + .slider {
    box-shadow: 0 0 1px var(--primary-color);
}

input:checked + .slider:before {
    transform: translateX(20px);  /* Adjusted for smaller size */
}

/* Hover effect */
.theme-toggle-wrapper:hover .slider {
    border-color: rgba(255, 255, 255, 0.3);
}

/* 7. Dark Theme Navigation Adjustments
   ========================================================================== */

/* Dark theme navbar override - make more specific */
body.dark-theme .app-container .top-navbar,
body.dark-theme.authenticated .app-container .top-navbar,
body.dark-theme:not(.authenticated) .app-container .top-navbar {
    background-color: var(--primary-color) !important;
    background: var(--primary-color) !important;
    border-bottom: none !important;
}

/* Add this new rule to catch any other potential overrides */
body.dark-theme nav.top-navbar[style*="background-color"] {
    background-color: var(--primary-color) !important;
    background: var(--primary-color) !important;
}

/* Dark theme container override */
body.dark-theme .top-navbar .container-fluid {
    background: transparent !important;  /* Force transparent background in dark mode */
}

/* Control items in dark mode */
body.dark-theme .nav-controls .control-item .btn-link,
body.dark-theme .nav-controls .control-item .nav-link {
    color: var(--primary-text) !important;  /* Force white text/icons */
    background: transparent !important;
}

body.dark-theme .nav-controls .control-item .btn-link:hover,
body.dark-theme .nav-controls .control-item .nav-link:hover {
    background-color: rgba(255, 255, 255, 0.1) !important;
}

body.dark-theme .nav-controls .control-item i {
    color: var(--primary-text) !important;  /* Force white icons */
}

/* Theme toggle specific adjustments for dark mode */
body.dark-theme .theme-toggle-wrapper .switch {
    background-color: transparent;
}

body.dark-theme .slider {
    background-color: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
}

body.dark-theme input:checked + .slider {
    background-color: var(--primary-text);
    border-color: var(--primary-text);
}

body.dark-theme input:checked + .slider:before {
    background-color: var(--primary-color);
}

/* Dark theme selector overrides */
body.dark-theme .selector-container .dropdown-toggle {
    color: var(--primary-text) !important;
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

body.dark-theme .selector-container .dropdown-toggle span,
body.dark-theme .selector-container .dropdown-toggle i {
    color: var(--primary-text) !important;
}

body.dark-theme .selector-container .dropdown-toggle:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* Dark theme dropdown overrides */
body.dark-theme .dropdown-menu {
    background-color: var(--dark-bg);
    border-color: rgba(255, 255, 255, 0.1);
}

body.dark-theme .dropdown-item {
    color: var(--dark-text);
}

body.dark-theme .dropdown-item:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* 8. Logo Theme Display Rules
   ========================================================================== */

/* Add specific display rules for theme modes */
body:not(.dark-theme) .logo.dark-mode,
body.dark-theme .logo.light-mode {
    display: none;
}

body.dark-theme .logo.dark-mode,
body:not(.dark-theme) .logo.light-mode {
    display: block;
}

/* Theme-specific logo display */
body:not(.dark-theme) .logo.dark-mode,
body.dark-theme .logo.light-mode {
    display: none !important;
}

body.dark-theme .logo.dark-mode,
body:not(.dark-theme) .logo.light-mode {
    display: block;
    opacity: 1;
}

/* 9. Responsive Navigation Adjustments
   ========================================================================== */

/* Mobile Adjustments */
@media (max-width: 767px) {
    /* Adjust navbar height for mobile */
    body .app-container .top-navbar {
        height: 60px !important;
        transition: transform 0.3s ease;
    }
    
    /* Hidden state for top navbar */
    body .app-container .top-navbar.hidden {
        transform: translateY(-100%);
    }
    
    .top-navbar .container-fluid {
        height: 60px;
        margin: 0;
        padding: 0 1rem;
    }
    
    /* MOBILE TOP BAR LAYOUT FIXES */
    /* Hide center selectors on mobile */
    .navbar-center {
        display: none !important;
    }
    
    /* Move hamburger to LEFT and center logo */
    .navbar-left {
        display: flex !important;
        align-items: center !important;
        gap: 1rem !important;
        flex: 1 !important;
    }
    
    /* Hide desktop hamburger, show mobile hamburger on LEFT */
    .navbar-right .mobile-menu-toggle {
        display: none !important;
    }
    
    .navbar-left .mobile-menu-toggle {
        display: flex !important;
        order: -1; /* Put hamburger first */
    }
    
    /* Center the logo */
    .logo-container {
        display: flex !important;
        justify-content: center !important;
        flex: 1 !important;
        text-align: center !important;
    }
    
    .logo-long {
        display: none;
    }
    
    .logo-small {
        display: block;
        max-width: 80px;
        height: 32px;
    }
    
    /* Mobile navigation controls - ONLY THEME TOGGLE */
    .navbar-right {
        gap: 4px;
        flex: none !important; /* Don't grow */
    }
    
    /* Hide specific controls on mobile - keep only theme toggle */
    .navbar-right .control-item:has(a[href*="help"]),
    .navbar-right .control-item:has(.dropdown-toggle),
    .navbar-right .control-item:has(form[action*="logout"]) {
        display: none !important;
    }
    
    .control-item {
        height: 40px;
        width: 40px;
    }
    
    /* Default: hide mobile elements */
    .mobile-only,
    .mobile-bottom-nav {
        display: none !important;
    }
    
    /* Show mobile elements ONLY on mobile AND when authenticated */
    @media (max-width: 767px) {
        .mobile-only {
            display: flex !important;
        }
        
        /* Mobile bottom nav - ONLY for authenticated users */
        body.authenticated .mobile-bottom-nav {
            display: flex !important;
            position: fixed !important;
            bottom: 0 !important;
            left: 0 !important;
            right: 0 !important;
            z-index: 10000 !important;
        }
        
        /* Hide mobile bottom nav for unauthenticated users */
        body:not(.authenticated) .mobile-bottom-nav {
            display: none !important;
        }
        
        /* Hide desktop-only elements on mobile */
        .desktop-only {
            display: none !important;
        }
    }
    
    /* Add hamburger menu button for mobile - ONLY for authenticated users */
    body.authenticated .mobile-menu-toggle {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        background: transparent !important;
        border: none !important;
        color: var(--primary-color) !important;
        font-size: 1.2rem;
        cursor: pointer;
        border-radius: 4px;
        outline: none !important;
        box-shadow: none !important;
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
    }
    
    /* Hide hamburger menu for non-authenticated users */
    body:not(.authenticated) .mobile-menu-toggle {
        display: none !important;
    }
    
    body.authenticated .mobile-menu-toggle:hover {
        background-color: rgba(0, 0, 0, 0.05) !important;
    }
    
    body.authenticated .mobile-menu-toggle:focus {
        outline: none !important;
        box-shadow: none !important;
    }
    
    body.authenticated .mobile-menu-toggle:active {
        background-color: rgba(0, 0, 0, 0.1) !important;
    }
    
    /* Dark theme mobile menu toggle - ONLY for authenticated users */
    body.dark-theme.authenticated .mobile-menu-toggle {
        color: white !important;
    }
    
    body.dark-theme.authenticated .mobile-menu-toggle:hover {
        background-color: rgba(255, 255, 255, 0.1);
    }
    
    /* Mobile Bottom Navigation */
    .mobile-bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 70px;
        background-color: #ffffff;
        border-top: 1px solid var(--border-color);
        display: flex;
        align-items: center;
        justify-content: space-around;
        z-index: 1000;
        padding: 0 10px;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
        transition: transform 0.3s ease;
    }
    
    /* Hidden state for bottom navbar */
    .mobile-bottom-nav.hidden {
        transform: translateY(100%);
    }
    
    .mobile-bottom-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        text-decoration: none;
        color: var(--text-muted);
        font-size: 12px;
        padding: 8px 4px;
        border-radius: 8px;
        transition: all 0.2s ease;
        min-width: 50px;
        text-align: center;
    }
    
    .mobile-bottom-nav-item:hover {
        color: var(--primary-color);
        background-color: rgba(0, 0, 0, 0.05);
        text-decoration: none;
    }
    
    .mobile-bottom-nav-item i {
        font-size: 18px;
        margin-bottom: 4px;
    }
    
    .mobile-bottom-nav-item span {
        font-weight: 500;
        font-size: 11px;
    }
    
    .mobile-bottom-nav-center {
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 0 10px;
    }
    
    .mobile-center-logo {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 45px;
        height: 45px;
        background-color: rgba(255, 255, 255, 0.9);
        border: 2px solid var(--border-color);
        border-radius: 50%;
        padding: 6px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
        transition: transform 0.2s ease;
        position: relative;
        overflow: hidden;
    }
    
    .mobile-center-logo:hover {
        transform: scale(1.05);
    }
    
    .mobile-center-logo .logo-square {
        width: 29px !important;
        height: 29px !important;
        max-width: 29px !important;
        max-height: 29px !important;
        object-fit: contain !important;
        display: block !important;
        filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
        margin: auto;
    }
    
    /* Hide the logo that's not for current theme */
    .mobile-center-logo .logo-square.light-mode {
        display: block !important;
    }
    
    .mobile-center-logo .logo-square.dark-mode {
        display: none !important;
    }
    
    body.dark-theme .mobile-center-logo .logo-square.light-mode {
        display: none !important;
    }
    
    body.dark-theme .mobile-center-logo .logo-square.dark-mode {
        display: block !important;
    }
    
    .mobile-center-logo img:not(.logo-square) {
        width: 100%;
        height: 100%;
        object-fit: contain;
        border-radius: 50%;
    }
    
    /* Dark theme mobile bottom nav */
    body.dark-theme .mobile-bottom-nav {
        background-color: var(--surface-color);
        border-top-color: rgba(255, 255, 255, 0.1);
    }
    
    body.dark-theme .mobile-bottom-nav-item {
        color: var(--text-muted);
    }
    
    body.dark-theme .mobile-bottom-nav-item:hover {
        color: var(--primary-text);
        background-color: rgba(255, 255, 255, 0.1);
    }
    
    body.dark-theme .mobile-center-logo {
        background-color: rgba(0, 0, 0, 0.9);
        border-color: rgba(255, 255, 255, 0.2);
    }
    
    /* MOBILE SIDEBAR POSITIONING */
    #sidebar {
        position: fixed !important;
        top: 0 !important;
        left: -100% !important;
        width: 100% !important;
        height: 100vh !important;
        z-index: var(--z-sidebar) !important;
        background: var(--sidebar-bg) !important;
        transition: left 0.3s ease !important;
        overflow-y: auto !important;
    }
    
    #sidebar.show {
        left: 0 !important;
    }
    
    /* Mobile sidebar overlay */
    .sidebar-overlay {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
        background: rgba(0, 0, 0, 0.5) !important;
        z-index: var(--z-sidebar-overlay) !important;
        opacity: 0 !important;
        visibility: hidden !important;
        transition: all 0.3s ease !important;
    }
    
    .sidebar-overlay.show {
        opacity: 1 !important;
        visibility: visible !important;
    }
    
    /* Prevent body scroll when sidebar is open */
    body.sidebar-open {
        overflow: hidden !important;
    }
    
    /* Adjust content padding for mobile bottom nav */
    @media (max-width: 767px) {
        .content-wrapper {
            padding-bottom: 80px; /* Space for bottom nav */
        }
        
        #content {
            padding-bottom: 80px; /* Space for bottom nav */
        }
        
        /* Hide bottom nav when sidebar is open */
        body.sidebar-open .mobile-bottom-nav {
            transform: translateY(100%) !important;
            transition: transform 0.3s ease !important;
            visibility: hidden !important;
        }
    }
}

/* Tablet adjustments */
@media (max-width: 991px) {
    .navbar-center .selector-container {
        min-width: 150px;
    }
    
    .selector-container .dropdown-toggle {
        padding: 0 8px;
        font-size: 0.875rem;
    }
}

/* Target navbar sections specifically */
body .app-container .top-navbar .navbar-right {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
}

body .app-container .top-navbar .nav-controls {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    height: 100% !important;
    background: transparent !important;
}

/* Navbar sections layout */
.navbar-left {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.navbar-center {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    margin-right: 1rem;
}

.navbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Debugging styles - remove after fixing */
.debug { border: 1px solid red; }
.navbar-left.debug { border-color: blue; }
.navbar-center.debug { border-color: green; }
.navbar-right.debug { border-color: yellow; }
