/* CSS Variables */
:root {
    --sidebar-width: 260px;
    --sidebar-mini-width: 70px;
    --header-height: 60px;
    --primary-blue: #1e40af;
    --primary-blue-dark: #1e3a8a;
    --accent-color: #3b82f6;
    --light-color: #f8fafc;
    --dark-color: #1f2937;
    --text-light: #6b7280;
    --border-color: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;
}

/* Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--light-color);
    color: var(--dark-color);
    line-height: 1.6;
    font-size: 14px;
    overflow-x: hidden;
}

/* Main Layout */
.main-wrapper {
    min-height: 100vh;
    position: relative;
}

/* Sidebar Styles */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: linear-gradient(180deg, var(--primary-blue) 0%, var(--primary-blue-dark) 100%);
    z-index: 1000;
    transition: all var(--transition-normal);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    flex-shrink: 0;
}

.sidebar-logo {
    padding: 1rem;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.1);
}

.logo-link {
    display: block;
    text-decoration: none;
    color: white;
}

.company-logo {
    max-width: 120px;
    height: auto;
    max-height: 40px;
    object-fit: contain;
    transition: all var(--transition-normal);
}

.sidebar-logo-text {
    display: block;
    color: white;
    font-size: 0.875rem;
    font-weight: 600;
    margin-top: 0.5rem;
    opacity: 1;
    transition: all var(--transition-normal);
}

/* Sidebar Navigation */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem 0;
}

.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

#sidebarMenu {
    list-style: none;
    padding: 0;
    margin: 0;
}

.nav-item {
    margin: 0 0.5rem; /* Add horizontal margin for better spacing */
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 0.875rem 1rem; /* Increased padding */
    color: rgba(255, 255, 255, 0.9) !important;
    text-decoration: none;
    transition: all var(--transition-fast);
    position: relative;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: 8px; /* Rounded corners for nav items */
    margin-bottom: 2px; /* Space between nav items */
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.15);
    color: white !important;
    transform: translateX(2px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.nav-link.active {
    background: var(--accent-color);
    color: white !important;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

/* Enhanced Icon Styling with Better Spacing */
.nav-link i {
    width: 28px !important; /* Larger icon container */
    height: 28px !important;
    margin-right: 1rem !important; /* Increased margin from icon to text */
    font-size: 1.2rem !important; /* Slightly larger icons */
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex-shrink: 0 !important;
    transition: all var(--transition-fast) !important;
    padding: 4px !important; /* Padding around icons */
    border-radius: 6px !important; /* Rounded icon background */
    background: rgba(255, 255, 255, 0.05) !important; /* Subtle background */
}

/* Icon hover effects */
.nav-link:hover i {
    background: rgba(255, 255, 255, 0.2) !important;
    transform: scale(1.05) !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1) !important;
}

/* Active state icon styling */
.nav-link.active i {
    background: rgba(255, 255, 255, 0.25) !important;
    transform: scale(1.05) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
}

.nav-link-text {
    flex: 1;
    transition: all var(--transition-normal);
    white-space: nowrap;
    opacity: 1;
    font-weight: 500;
}

.nav-link .bi-chevron-down {
    margin-left: auto;
    margin-right: 0;
    transition: transform var(--transition-fast);
    font-size: 0.875rem;
    padding: 2px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.1);
}

.nav-link[aria-expanded="true"] .bi-chevron-down {
    transform: rotate(180deg);
    background: rgba(255, 255, 255, 0.2);
}

/* Dropdown Styles */
.collapse {
    background: rgba(0, 0, 0, 0.15);
    transition: all var(--transition-normal);
    border-radius: 0 0 8px 8px;
    margin: 0 0.5rem;
}

.submenu {
    list-style: none;
    padding: 0.5rem 0;
    margin: 0;
}

/* Improved Submenu Items */
.submenu .nav-item {
    margin: 0 0.25rem;
}

.submenu .nav-link {
    padding: 0.625rem 1rem 0.625rem 2.5rem;
    font-size: 0.8rem;
    font-weight: 400;
    margin-bottom: 1px;
}

.submenu .nav-link i {
    width: 22px !important; /* Slightly smaller for submenu */
    height: 22px !important;
    font-size: 1rem !important;
    margin-right: 0.75rem !important;
    padding: 2px !important;
}

.submenu .nav-link:hover i {
    background: rgba(255, 255, 255, 0.15) !important;
}

/* Divider */
.nav-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
    margin: 1rem 1.5rem;
}

/* Top Navbar */
.top-navbar {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: var(--header-height);
    background: var(--primary-blue);
    box-shadow: var(--shadow-md);
    z-index: 999;
    transition: left var(--transition-normal);
    border: none;
}

.top-navbar .container-fluid {
    height: 100%;
}

.top-navbar .btn-link {
    color: white !important;
    border: none;
    background: none;
    padding: 0.5rem;
    border-radius: 0.375rem;
    transition: all var(--transition-fast);
}

.top-navbar .btn-link:hover {
    background: rgba(255, 255, 255, 0.1);
}

.top-navbar .form-control {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 0.875rem;
}

.top-navbar .form-control::placeholder {
    color: rgba(255, 255, 255, 0.7);
}

.top-navbar .form-control:focus {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: 0 0 0 0.2rem rgba(255, 255, 255, 0.1);
    color: white;
}

.top-navbar .btn-outline-light {
    border-color: rgba(255, 255, 255, 0.2);
    color: white;
}

.top-navbar .btn-outline-light:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
}

/* Notification Badge */
.notification-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 18px;
    height: 18px;
    border-radius: 50%;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* Dropdown Menus */
.dropdown-menu {
    border: none;
    box-shadow: var(--shadow-lg);
    border-radius: 0.5rem;
    padding: 0.5rem 0;
    min-width: 200px;
}

.notification-dropdown {
    width: 320px;
}

.dropdown-header {
    padding: 0.75rem 1rem;
    font-weight: 600;
    color: var(--dark-color);
    border-bottom: 1px solid var(--border-color);
}

.dropdown-item {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    transition: all var(--transition-fast);
}

.dropdown-item:hover {
    background: var(--light-color);
}

.dropdown-item i {
    width: 16px;
    margin-right: 0.5rem;
}

/* Main Content */
.main-content {
    margin-top: var(--header-height);
    margin-left: var(--sidebar-width);
    padding: 1.5rem;
    transition: margin-left var(--transition-normal);
    min-height: calc(100vh - var(--header-height));
    background: var(--light-color);
}

.page-content {
    max-width: 100%;
}

/* Mini Sidebar Styles with Enhanced Icon Spacing */
.sidebar-mini .sidebar {
    width: var(--sidebar-mini-width);
}

.sidebar-mini .sidebar-logo {
    padding: 0.75rem 0.5rem;
}

.sidebar-mini .company-logo {
    max-width: 32px;
    max-height: 32px;
}

.sidebar-mini .sidebar-logo-text {
    opacity: 0;
    height: 0;
    margin: 0;
    overflow: hidden;
}

.sidebar-mini .nav-item {
    margin: 0 0.25rem;
}

.sidebar-mini .nav-link {
    justify-content: center;
    padding: 0.875rem 0.5rem;
}

.sidebar-mini .nav-link-text {
    opacity: 0;
    width: 0;
    overflow: hidden;
    margin: 0;
}

/* Enhanced Mini Mode Icon Styling */
.sidebar-mini .nav-link i {
    width: 32px !important; /* Larger icons in mini mode */
    height: 32px !important;
    margin: 0 !important;
    font-size: 1.3rem !important;
    padding: 6px !important; /* More padding in mini mode */
    background: rgba(255, 255, 255, 0.08) !important;
}

.sidebar-mini .nav-link:hover i {
    background: rgba(255, 255, 255, 0.25) !important;
    transform: scale(1.1) !important;
}

.sidebar-mini .nav-link.active i {
    background: rgba(255, 255, 255, 0.3) !important;
    transform: scale(1.1) !important;
}

.sidebar-mini .nav-link .bi-chevron-down {
    display: none;
}

.sidebar-mini .submenu .nav-link {
    justify-content: center;
    padding: 0.625rem 0.5rem;
}

.sidebar-mini .submenu .nav-link i {
    width: 28px !important;
    height: 28px !important;
    font-size: 1.1rem !important;
}

.sidebar-mini .top-navbar {
    left: var(--sidebar-mini-width);
}

.sidebar-mini .main-content {
    margin-left: var(--sidebar-mini-width);
}

/* Hover Expansion for Mini Sidebar */
.sidebar-mini.sidebar-hover-expanded .sidebar {
    width: var(--sidebar-width);
    box-shadow: var(--shadow-lg), 4px 0 20px rgba(0, 0, 0, 0.15);
}

.sidebar-mini.sidebar-hover-expanded .sidebar-logo {
    padding: 1rem;
}

.sidebar-mini.sidebar-hover-expanded .company-logo {
    max-width: 120px;
    max-height: 40px;
}

.sidebar-mini.sidebar-hover-expanded .sidebar-logo-text {
    opacity: 1;
    height: auto;
    margin-top: 0.5rem;
}

.sidebar-mini.sidebar-hover-expanded .nav-item {
    margin: 0 0.5rem;
}

.sidebar-mini.sidebar-hover-expanded .nav-link {
    justify-content: flex-start;
    padding: 0.875rem 1rem;
}

.sidebar-mini.sidebar-hover-expanded .nav-link-text {
    opacity: 1;
    width: auto;
    margin-left: 0;
}

.sidebar-mini.sidebar-hover-expanded .nav-link i {
    width: 28px !important;
    height: 28px !important;
    margin-right: 1rem !important;
    font-size: 1.2rem !important;
    padding: 4px !important;
}

.sidebar-mini.sidebar-hover-expanded .nav-link .bi-chevron-down {
    display: inline-block;
}

.sidebar-mini.sidebar-hover-expanded .submenu .nav-link {
    justify-content: flex-start;
    padding: 0.625rem 1rem 0.625rem 2.5rem;
}

/* Tooltips for Mini Sidebar */
.sidebar-mini .nav-link::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 15px);
    top: 50%;
    transform: translateY(-50%);
    background: var(--dark-color);
    color: white;
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.75rem;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-fast);
    z-index: 1001;
    pointer-events: none;
    box-shadow: var(--shadow-md);
}

.sidebar-mini .nav-link::before {
    content: '';
    position: absolute;
    left: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%);
    border: 5px solid transparent;
    border-right-color: var(--dark-color);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-fast);
    z-index: 1001;
}

.sidebar-mini .nav-link:hover::after,
.sidebar-mini .nav-link:hover::before {
    opacity: 1;
    visibility: visible;
}

.sidebar-mini.sidebar-hover-expanded .nav-link::after,
.sidebar-mini.sidebar-hover-expanded .nav-link::before {
    display: none;
}

/* Mobile Sidebar Overlay */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

.sidebar-overlay.show {
    opacity: 1;
    visibility: visible;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform var(--transition-normal);
    }
    
    .sidebar.show {
        transform: translateX(0);
        z-index: 1001;
    }

    /* Reset nav item margins on mobile */
    .nav-item {
        margin: 0 0.5rem;
    }

    /* Adjust icon sizes for mobile */
    .nav-link i {
        width: 26px !important;
        height: 26px !important;
        font-size: 1.1rem !important;
        padding: 3px !important;
    }
    
    .top-navbar {
        left: 0 !important;
    }
    
    .main-content {
        margin-left: 0 !important;
    }
    
    .sidebar-mini .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar-mini .sidebar.show {
        transform: translateX(0);
        width: var(--sidebar-width);
    }
    
    .sidebar-mini .top-navbar {
        left: 0 !important;
    }
    
    .sidebar-mini .main-content {
        margin-left: 0 !important;
    }
    
    /* Hide tooltips on mobile */
    .nav-link::after,
    .nav-link::before {
        display: none !important;
    }
    
    /* Adjust search bar on mobile */
    .top-navbar .input-group {
        display: none !important;
    }
}

@media (max-width: 576px) {
    .main-content {
        padding: 1rem;
    }
    
    .top-navbar .container-fluid {
        padding: 0 1rem;
    }
    
    .dropdown-menu {
        width: calc(100vw - 2rem) !important;
        max-width: 300px;
    }

    /* Further adjust icon sizes for very small screens */
    .nav-link i {
        width: 24px !important;
        height: 24px !important;
        font-size: 1rem !important;
        padding: 2px !important;
    }
}

/* Animation Classes */
.fade-in {
    animation: fadeIn 0.5s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* FIXED MOBILE EXPIRY POPUP WITH PROPER SCROLLING */
@media (max-width: 768px) {
    /* Force proper mobile positioning for all expiry dropdowns */
    .dropdown-menu[data-bs-popper],
    .user-expiry-dropdown {
        position: fixed !important;
        top: 70px !important;
        right: 10px !important;
        left: auto !important;
        transform: none !important;
        width: calc(100vw - 20px) !important;
        max-width: 350px !important;
        min-width: 300px !important;
        z-index: 9999 !important;
        margin-top: 0 !important;
        
        /* CRITICAL: Enable scrolling */
        max-height: calc(100vh - 80px) !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important; /* Smooth scrolling on iOS */
    }
    
    /* Ensure dropdown content is mobile-optimized */
    .user-expiry-dropdown .p-3,
    .user-expiry-dropdown .p-2 {
        padding: 1rem !important;
    }
    
    .user-expiry-dropdown .small {
        font-size: 0.875rem !important;
        line-height: 1.4 !important;
    }
    
    /* Make buttons more touch-friendly */
    .user-expiry-dropdown .btn {
        min-height: 44px !important;
        font-size: 0.875rem !important;
        padding: 12px 16px !important;
        margin-bottom: 8px !important;
    }
    
    /* Stack phone number sections vertically */
    .user-expiry-dropdown .d-flex.justify-content-between {
        flex-direction: column !important;
        gap: 8px !important;
    }
    
    /* Better spacing for mobile cards */
    .user-expiry-dropdown .bg-light.rounded {
        margin-bottom: 1rem !important;
        padding: 1rem !important;
    }
    
    .user-expiry-dropdown .border.rounded {
        margin-bottom: 1rem !important;
        padding: 1rem !important;
    }
    
    /* Dropdown header improvements - make it sticky */
    .user-expiry-dropdown .dropdown-header {
        padding: 1rem !important;
        font-size: 1rem !important;
        border-radius: 12px 12px 0 0 !important;
        position: sticky !important;
        top: 0 !important;
        z-index: 10 !important;
        background: inherit !important;
    }
    
    /* Add padding to the bottom for better scrolling */
    .user-expiry-dropdown > *:last-child {
        padding-bottom: 1rem !important;
    }
    
    /* Improve scrollbar appearance on mobile */
    .user-expiry-dropdown::-webkit-scrollbar {
        width: 6px;
    }
    
    .user-expiry-dropdown::-webkit-scrollbar-track {
        background: rgba(0, 0, 0, 0.1);
        border-radius: 3px;
    }
    
    .user-expiry-dropdown::-webkit-scrollbar-thumb {
        background: rgba(0, 0, 0, 0.3);
        border-radius: 3px;
    }
    
    .user-expiry-dropdown::-webkit-scrollbar-thumb:hover {
        background: rgba(0, 0, 0, 0.5);
    }
}

@media (max-width: 576px) {
    /* Even smaller screens */
    .dropdown-menu[data-bs-popper],
    .user-expiry-dropdown {
        width: calc(100vw - 10px) !important;
        right: 5px !important;
        max-width: none !important;
        max-height: calc(100vh - 70px) !important; /* Adjust for smaller screens */
    }
    
    /* Make text more readable on small screens */
    .user-expiry-dropdown {
        font-size: 14px !important;
    }
    
    .user-expiry-dropdown .small {
        font-size: 13px !important;
    }
}

/* iOS Safari specific fixes */
@supports (-webkit-touch-callout: none) {
    @media (max-width: 768px) {
        .dropdown-menu[data-bs-popper],
        .user-expiry-dropdown {
            position: fixed !important;
            -webkit-transform: none !important;
            transform: none !important;
            -webkit-overflow-scrolling: touch !important;
        }
    }
}

/* Prevent dropdown from being cut off */
.dropdown {
    position: static !important;
}

@media (max-width: 768px) {
    .dropdown {
        position: relative !important;
    }
    
    /* Ensure proper stacking */
    .navbar .dropdown-menu {
        z-index: 9999 !important;
    }
    
    /* Add scroll indicator for better UX */
    .user-expiry-dropdown::after {
        content: "";
        position: sticky;
        bottom: 0;
        height: 10px;
        background: linear-gradient(transparent, rgba(255, 255, 255, 0.8));
        pointer-events: none;
        display: block;
    }
}


/* Smooth Transitions */
.sidebar,
.top-navbar,
.main-content,
.nav-link,
.nav-link-text,
.sidebar-logo,
.company-logo,
.sidebar-logo-text {
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

/* Focus Styles for Accessibility */
.nav-link:focus {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: -2px;
}

.btn:focus {
    box-shadow: 0 0 0 0.2rem rgba(255, 255, 255, 0.25);
}

/* Print Styles */
@media print {
    .sidebar,
    .top-navbar,
    .sidebar-overlay {
        display: none !important;
    }
    
    .main-content {
        margin: 0 !important;
        padding: 0 !important;
    }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    .sidebar {
        border-right: 2px solid white;
    }
    
    .nav-link {
        border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}