/* Prevent horizontal overflow on mobile */
@media (max-width: 767px) {
    html, body {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100vw !important;
    }
    
    .admin-wrapper {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100vw !important;
    }
    
    .main-content {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100vw !important;
    }
}

/* Extra mobile fixes for under 576px */
@media (max-width: 575px) {
    * {
        box-sizing: border-box !important;
    }
    
    .horizontal-nav, .horizontal-nav * {
        box-sizing: border-box !important;
    }
}

/* Horizontal Navigation Bar - RESTORED */
.horizontal-nav {
    background: var(--admin-menu-bg);
    border-bottom: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    position: sticky;
    top: 70px; /* Stick under the topbar */
    z-index: 1020 !important; /* Lower z-index to allow modals above */
    overflow: visible !important; /* Allow dropdowns to overflow completely */
    padding: 0.5rem 0 0.25rem 0; /* Minimal padding to match reference spacing */
    margin-bottom: 0.25rem !important; /* Add space between nav and content */
    width: 100% !important; /* Ensure it stays within viewport */
    max-width: 100vw !important; /* Prevent exceeding viewport width */
    font-family: var(--admin-font-family, 'PT Sans'), sans-serif !important;
}

/* Navigation Menu Container */
.nav-menu {
    display: flex;
    align-items: center;
    gap: 0;
    padding: 0;
    margin: 0;
    overflow: visible !important; /* Allow dropdowns to overflow completely */
    width: 100%;
    max-width: 100%;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}

/* Navigation Dropdown Container */
.nav-dropdown {
    position: relative !important;
    overflow: visible !important; /* CRITICAL: Allow dropdowns to overflow */
}

/* Ensure proper container behavior */
.horizontal-nav .container-fluid {
    overflow: visible !important; /* CRITICAL: Allow dropdowns to overflow completely */
    width: 100% !important;
    max-width: 100% !important;
    padding-left: 1rem !important;
    padding-right: 1rem !important;
}

.admin-wrapper {
    overflow: visible !important;
}

/* CRITICAL: Ensure all containers allow dropdown overflow */
.main-content {
    overflow: visible !important;
}

.content-area {
    overflow: visible !important;
}

/* Ensure body and html allow dropdowns to overflow */
body {
    overflow-x: hidden !important;
    overflow-y: auto !important;
}

html {
    overflow-x: hidden !important;
    overflow-y: auto !important;
}

.nav-menu::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}

/* Navigation Items */
.nav-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    color: var(--admin-menu-text);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    white-space: nowrap;
    border-bottom: 3px solid transparent;
    transition: all 0.3s ease;
    position: relative;
}

.nav-item:hover {
    color: var(--admin-menu-hover);
    background: rgba(255,255,255,0.1);
    border-bottom-color: rgba(255,255,255,0.5);
    transform: translateY(-1px);
}

.nav-item.active {
    color: var(--admin-menu-active);
    background: rgba(255,255,255,0.15);
    border-bottom-color: var(--admin-menu-active);
    box-shadow: inset 0 -3px 0 var(--admin-menu-active);
}

/* Icons */
.nav-item i {
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
}

/* DROPDOWN ITEMS — horizontal nav menus */
.nav-dropdown .dropdown-item {
    color: var(--admin-horizontal-dropdown-text) !important;
    padding: 8px 14px !important;
    font-size: 0.84rem !important;
    font-weight: 500 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 10px !important;
    text-decoration: none !important;
    text-align: start !important;
    direction: ltr !important;
    border: none !important;
    background: transparent !important;
    transition: background .15s, color .15s, transform .15s !important;
    position: relative !important;
    overflow: hidden !important;
    border-radius: 8px !important;
    margin: 1px 6px !important;
}

.nav-dropdown .dropdown-item:hover {
    background-color: var(--admin-horizontal-dropdown-hover-bg) !important;
    color: var(--admin-horizontal-dropdown-hover-text) !important;
    transform: none !important;
    padding-left: 14px !important;
}

.nav-dropdown .dropdown-item:focus {
    background-color: var(--admin-horizontal-dropdown-hover-bg) !important;
    color: var(--admin-horizontal-dropdown-hover-text) !important;
    outline: none !important;
    box-shadow: none !important;
}

.nav-dropdown .dropdown-item:active {
    transform: none !important;
    background-color: var(--admin-horizontal-dropdown-hover-bg) !important;
}

/* DROPDOWN ITEM ICONS — uses currentColor so it adapts to any bg */
.nav-dropdown .dropdown-item i {
    width: 28px !important;
    height: 28px !important;
    font-size: .82rem !important;
    text-align: center !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: rgba(128,128,128,0.12) !important;
    border-radius: 7px !important;
    transition: background .15s, transform .15s !important;
    flex-shrink: 0 !important;
    color: inherit !important;
}

.nav-dropdown .dropdown-item:hover i {
    background: rgba(128,128,128,0.2) !important;
    transform: scale(1.06) !important;
    box-shadow: none !important;
}

/* DROPDOWN SECTION HEADERS — adapts to bg via text color variable */
.nav-dropdown .dropdown-header {
    font-size: .62rem !important;
    font-weight: 700 !important;
    text-transform: uppercase !important;
    letter-spacing: .06em !important;
    padding: 10px 14px 4px !important;
    margin: 0 6px !important;
    color: var(--admin-horizontal-dropdown-text) !important;
    opacity: .45 !important;
    background: transparent !important;
    border-radius: 0 !important;
}
.nav-dropdown .dropdown-header i {
    font-size: .68rem;
}

/* DROPDOWN DIVIDERS — neutral gray that works on any bg */
.nav-dropdown .dropdown-divider {
    margin: 4px 14px !important;
    border-color: rgba(128,128,128,.15) !important;
    opacity: 1 !important;
}

/* DROPDOWN SEPARATORS — remove old item-to-item borders */
.nav-dropdown .dropdown-item + .dropdown-item {
    border-top: none !important;
}

/* FIRST AND LAST ITEMS — inherit container radius */
.nav-dropdown .dropdown-item:first-child {
    border-top-left-radius: 8px !important;
    border-top-right-radius: 8px !important;
}
.nav-dropdown .dropdown-item:last-child {
    border-bottom-left-radius: 8px !important;
    border-bottom-right-radius: 8px !important;
}

/* DROPDOWN STYLING - HORIZONTAL NAV ONLY */
.horizontal-nav .dropdown-menu[style*="display: block"],
.horizontal-nav .dropdown-menu.show,
.nav-dropdown .dropdown-menu[style*="display: block"],
.nav-dropdown .dropdown-menu.show {
    display: block !important;
    position: absolute !important;
    top: 100% !important;
    left: 0 !important;
    z-index: 99999 !important;
    background-color: var(--admin-horizontal-dropdown-bg) !important;
    border: 1px solid rgba(128,128,128,0.15) !important;
    border-radius: 14px !important;
    box-shadow: 0 12px 36px rgba(0,0,0,0.15), 0 0 0 1px rgba(0,0,0,0.04) !important;
    margin: 6px 0 0 0 !important;
    min-width: 240px !important;
    max-width: 300px !important;
    max-height: 70vh !important;
    overflow-y: auto !important;
    transform: none !important;
    inset: auto !important;
    opacity: 1 !important;
    visibility: visible !important;
    clip: auto !important;
    width: auto !important;
    height: auto !important;
    padding: 6px !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
    pointer-events: auto !important;
    text-align: start !important;
    direction: ltr !important;
    animation: navDropIn .15s ease !important;
}

@keyframes navDropIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* CRITICAL: Default hidden state for all dropdown menus */
.nav-dropdown .dropdown-menu {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: auto !important;
}

.nav-dropdown .dropdown-menu * {
    pointer-events: auto !important;
}

/* NUCLEAR OVERRIDE: Ensure dropdown shows when custom JS activates it */
.horizontal-nav .nav-dropdown .dropdown-menu.show,
.horizontal-nav .nav-dropdown .dropdown-menu[style*="display: block"],
.nav-dropdown .dropdown-menu.show,
.nav-dropdown .dropdown-menu[style*="display: block"],
.nav-dropdown .dropdown-menu[style*="display:block"] {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
    z-index: 99999 !important;
}

/* Smart positioning - prevent going off-screen */
.nav-dropdown {
    position: relative !important;
}

/* Auto-position dropdown to prevent overflow */
.nav-dropdown .dropdown-menu {
    position: absolute !important;
    top: 100% !important;
    left: 0 !important;
    right: auto !important;
    transform: none !important;
    z-index: 1050 !important; /* Ensure dropdowns appear above content */
    margin-top: 0.25rem !important;
    contain: none !important; /* Prevent CSS containment from clipping */
}

/* When dropdown would go off right edge, align to right */
.nav-dropdown.dropdown-right .dropdown-menu {
    left: auto !important;
    right: 0 !important;
}

/* When dropdown would go off bottom, show above */
.nav-dropdown.dropdown-up .dropdown-menu {
    top: auto !important;
    bottom: 100% !important;
    margin: 0 0 8px 0 !important;
}

/* Center dropdown for mobile screens */
.nav-dropdown.dropdown-center .dropdown-menu {
    left: 50% !important;
    transform: translateX(-50%) !important;
}

/* Dropdown scrollbar styling - Dynamic colors will be set via inline CSS */

/* Mobile Navigation Menu Styles */
.mobile-nav-menu {
    background: var(--admin-menu-bg);
    border-bottom: 1px solid rgba(255,255,255,0.08);
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    padding: 0.75rem 0;
    display: none;
}

@media (max-width: 991px) {
    .mobile-nav-menu { display: block !important; }
    .horizontal-nav { display: none !important; }
}

.mobile-nav-items {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0 8px;
}

.mobile-nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    color: var(--admin-menu-text);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.88rem;
    border-radius: 10px;
    transition: all 0.2s ease;
    background: transparent;
}
.mobile-nav-item:hover {
    color: #fff;
    background: rgba(255,255,255,0.12);
    text-decoration: none;
}
.mobile-nav-item i {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 0.85rem;
    background: rgba(255,255,255,0.1);
    flex-shrink: 0;
}
.mobile-nav-item:hover i {
    background: rgba(255,255,255,0.2);
}

.mobile-nav-section {
    margin-top: 2px;
}
.mobile-nav-section-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    color: var(--admin-menu-text);
    font-weight: 600;
    font-size: 0.88rem;
    border: none;
    width: 100%;
    text-align: left;
    background: transparent;
    border-radius: 10px;
    transition: all 0.2s ease;
    cursor: pointer;
    margin: 0;
}
.mobile-nav-section-header:hover {
    color: #fff;
    background: rgba(255,255,255,0.12);
}
.mobile-nav-section-header:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(255,255,255,0.2);
}
.mobile-nav-section-header i {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 0.85rem;
    background: rgba(255,255,255,0.1);
    flex-shrink: 0;
}

.mobile-nav-section-items {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 4px 0 4px 22px;
}
.mobile-nav-subitem {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    color: rgba(255,255,255,0.75);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.82rem;
    border-radius: 8px;
    transition: all 0.2s ease;
    border-left: 2px solid rgba(255,255,255,0.1);
}
.mobile-nav-subitem:hover {
    color: #fff;
    background: rgba(255,255,255,0.08);
    border-left-color: rgba(255,255,255,0.4);
    text-decoration: none;
}
.mobile-nav-subitem i {
    font-size: 0.8rem;
    width: 18px;
    text-align: center;
    opacity: 0.7;
}

/* Mobile Menu Toggle Button */
.mobile-menu-toggle {
    background: rgba(255,255,255,0.1) !important;
    border: 1px solid rgba(255,255,255,0.2) !important;
    color: white !important;
    padding: 0.5rem 0.75rem !important;
    border-radius: 8px !important;
    transition: all 0.3s ease !important;
}

.mobile-menu-toggle:hover {
    background: rgba(255,255,255,0.2) !important;
    color: white !important;
    transform: translateY(-2px) !important;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2) !important;
}

/* Notification Dropdown Responsive */
.notification-dropdown {
    width: 350px !important;
    max-width: 90vw !important;
}

@media (max-width: 767px) {
    .notification-dropdown {
        width: 300px !important;
        max-width: 95vw !important;
    }
}

@media (max-width: 575px) {
    .notification-dropdown {
        width: 280px !important;
        max-width: 95vw !important;
    }
}

/* Bootstrap 5 Responsive Breakpoints */

/* Large screens (xl) - 1200px and up - Full menu */
@media (min-width: 1200px) {
    .nav-menu {
        flex-wrap: nowrap;
        overflow-x: visible;
    }
    
    .nav-item {
        min-width: auto;
    }
    
    .nav-item span {
        display: inline;
    }
}

/* Large screens (lg) - 992px to 1199px - Slightly condensed */
@media (min-width: 992px) and (max-width: 1199px) {
    .nav-item {
        padding: 0.8rem 1.2rem;
        font-size: 0.85rem;
    }
    
    .nav-item span {
        display: inline;
    }
}

/* Medium screens (md) - 768px to 991px - More condensed */
@media (min-width: 768px) and (max-width: 991px) {
    .horizontal-nav {
        overflow: visible !important;
    }
    
    .nav-menu {
        overflow-x: auto;
        overflow-y: visible;
        flex-wrap: nowrap;
        scrollbar-width: thin;
        scrollbar-color: rgba(255,255,255,0.3) transparent;
        padding-bottom: 0.5rem;
    }
    
    .nav-menu::-webkit-scrollbar {
        height: 4px;
        display: block;
    }
    
    .nav-menu::-webkit-scrollbar-track {
        background: rgba(255,255,255,0.1);
        border-radius: 2px;
    }
    
    .nav-menu::-webkit-scrollbar-thumb {
        background: rgba(255,255,255,0.3);
        border-radius: 2px;
    }
    
    .nav-menu::-webkit-scrollbar-thumb:hover {
        background: rgba(255,255,255,0.5);
    }
    
    .nav-item {
        padding: 0.8rem 1rem;
        font-size: 0.8rem;
        flex-shrink: 0;
    }
    
    .nav-item span {
        display: inline;
    }
    
    .nav-dropdown .dropdown-menu {
        min-width: 250px !important;
        max-width: 300px !important;
    }
}

/* Small screens (sm) - 576px to 767px - Additional mobile optimizations */
@media (min-width: 576px) and (max-width: 767px) {
    .content-area {
        padding-top: 1rem !important;
    }
}

/* Extra small screens (xs) - up to 575px - Additional mobile optimizations */
@media (max-width: 575px) {
    .content-area {
        padding-top: 1rem !important;
    }
    
    .mobile-nav-item { padding: 9px 12px; font-size: 0.84rem; }
    .mobile-nav-item i { width: 30px; height: 30px; font-size: 0.8rem; }
    .mobile-nav-subitem { padding: 7px 12px; font-size: 0.78rem; }
}

/* Remove all sidebar margins since we're using horizontal nav */
.main-content {
    margin-left: 0 !important;
    width: 100% !important;
}

.admin-footer {
    margin-left: 0 !important;
    width: 100% !important;
}

/* BREADCRUMB CONTAINER - RESPONSIVE PADDING */
nav[aria-label="breadcrumb"] {
    padding: 0 2rem !important; /* MATCH content-area horizontal padding */
    margin: 0 0 1.5rem 0 !important; /* Bottom margin to separate from content */
}

/* Responsive breadcrumb padding */
@media (min-width: 576px) and (max-width: 767px) {
    nav[aria-label="breadcrumb"] {
        padding: 0 1rem !important;
    }
    
    .content-area {
        padding: 0 0 2rem 0 !important;
    }
    
    .horizontal-nav {
        margin-bottom: 1rem !important;
    }
}

@media (max-width: 575px) {
    nav[aria-label="breadcrumb"] {
        padding: 0 0.5rem !important;
    }
    
    .content-area {
        padding: 0 0 1.5rem 0 !important;
    }
    
    .horizontal-nav {
        margin-bottom: 0.5rem !important;
    }
    
    .breadcrumb {
        font-size: 0.8rem !important;
    }
    
    .breadcrumb-item {
        max-width: 150px !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
    }
}

/* Content area - zero horizontal padding; container-fluid handles gutters */
.content-area {
    flex: 1;
    padding: 0 0 2rem 0 !important;
    background: transparent;
    margin: 0 !important;
}

/* Ensure proper spacing when mobile menu is active */
@media (max-width: 991px) {
    .content-area {
        padding-top: 0.5rem !important;
    }
}

/* Smooth transitions for mobile menu */
.mobile-nav-menu {
    transition: all 0.3s ease;
}

@media (max-width: 767px) {
    .mobile-nav-item,
    .mobile-nav-subitem { min-height: 44px; }
}
.mobile-nav-menu .collapse {
    background: transparent;
    border-radius: 0;
    margin-top: 0;
    padding-top: 0;
}

/* When breadcrumbs exist - ZERO TOP PADDING */
body:has(.breadcrumb) .content-area {
    padding: 0 0 2rem 0 !important;
}

/* Breadcrumb styling - PROPER MARGINS */
.breadcrumb {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%) !important;
    padding: 1rem !important;
    margin: 0 !important; /* No margin on breadcrumb itself */
    border-radius: 10px !important;
    border-left: 4px solid #667eea !important;
    box-shadow: 0 3px 12px rgba(0,0,0,0.15) !important;
    border: 1px solid rgba(0,0,0,0.08) !important;
}

.breadcrumb-item {
    font-size: 0.9rem !important;
    font-weight: 500 !important;
}

.breadcrumb-item a {
    color: #495057 !important;
    text-decoration: none !important;
    transition: all 0.3s ease !important;
    font-weight: 500 !important;
}

.breadcrumb-item a:hover {
    color: #667eea !important;
    font-weight: 600 !important;
    text-shadow: 0 1px 2px rgba(102, 126, 234, 0.2) !important;
}

.breadcrumb-item.active {
    color: #212529 !important;
    font-weight: 700 !important;
}

.breadcrumb-item + .breadcrumb-item::before {
    content: "›" !important;
    color: #6c757d !important;
    margin: 0 0.6rem !important;
    font-weight: 600 !important;
    font-size: 1.1rem !important;
}

/* Dashboard content - ensure proper spacing after breadcrumbs */
.welcome-header,
.dashboard-card:first-child,
.row:first-child {
    margin-top: 0 !important; /* Remove extra top margin from first content element */
}

/* When no breadcrumbs exist - ZERO TOP PADDING */
.content-area:not(:has(.breadcrumb)) {
    padding: 0 0 2rem 0 !important;
}
/* Fallback for browsers that don't support :has() - ZERO TOP PADDING */
body:not(.has-breadcrumbs) .content-area {
    padding: 0 0 2rem 0 !important;
}
