 :root {
     --primary-color: #0c7ff2;
     --primary-50: #f0f9ff;
     --primary-100: #e0f2fe;
     --primary-200: #bae6fd;
     --primary-300: #7dd3fc;
     --primary-400: #38bdf8;
     --primary-500: #0ea5e9;
     --primary-600: #0284c7;
     --primary-700: #0369a1;
     --primary-800: #075985;
     --primary-900: #0c4a6e;

     --gray-50: #f9fafb;
     --gray-100: #f3f4f6;
     --gray-200: #e5e7eb;
     --gray-300: #d1d5db;
     --gray-400: #9ca3af;
     --gray-500: #6b7280;
     --gray-600: #4b5563;
     --gray-700: #374151;
     --gray-800: #1f2937;
     --gray-900: #111827;

     --success-500: #10b981;
     --warning-500: #f59e0b;
     --danger-500: #ef4444;

     --sidebar-width: 240px;
     --sidebar-collapsed-width: 80px;
     --navbar-height: 64px;
     --content-padding: 1.5rem;
 }

 * {
     margin: 0;
     padding: 0;
     box-sizing: border-box;
 }

 body {
     font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
     font-size: 14px;
     line-height: 1.5;
     color: var(--gray-800);
     background-color: var(--gray-50);
     min-height: 100vh;
     display: flex;
     flex-direction: column;
 }

 /* Prevent viewport-wide horizontal scrollbar, especially when sidebar is collapsed */
 html { overflow-x: hidden; }

 /* Navbar */
 .navbar {
     height: 70px;
     background-color: #ffffff;
     border-bottom: 1px solid rgba(0, 0, 0, 0.05);
     box-shadow: 0 4px 20px rgba(0, 0, 0, 0.03);
     position: fixed;
     top: 0;
     left: 0;
     right: 0;
     z-index: 1030;
     padding: 0 1.2rem;
 }

 .navbar-brand {
     font-weight: 700;
     font-size: 1.35rem;
     color: #2d3748;
     display: flex;
     align-items: center;
     gap: 0.75rem;
     transition: transform 0.2s ease;
 }

 .navbar-brand:hover {
     transform: translateX(2px);
 }



 .brand-highlight {
     color: #4f46e5;
 }

.navbar-controls {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

/* Ensure dropdown positions relative to its container and is clickable */
.navbar .dropdown { position: relative; }
.navbar .user-dropdown { pointer-events: auto; }

 .sidebar-toggle {
     width: 40px;
     height: 40px;
     border-radius: 10px;
     display: flex;
     align-items: center;
     justify-content: center;
     color: #64748b;
     cursor: pointer;
     background-color: transparent;
     border: none;
     transition: all 0.2s ease;
 }

 .sidebar-toggle:hover {
     background-color: #f1f5f9;
     color: #4f46e5;
 }

 /* Enhanced Company Selector */
 .company-selector-wrapper {
     position: relative;
     min-width: 250px;
 }

 .company-selector-icon {
     position: absolute;
     left: 12px;
     top: 50%;
     transform: translateY(-50%);
     color: #4f46e5;
     font-size: 1.2rem;
     z-index: 2;
 }

 .company-selector {
     padding-left: 2.5rem !important;
     /* Space for icon */
     border-radius: 12px !important;
     background-color: #f8fafc !important;
     border: 1px solid #eaeef3 !important;
     font-size: 0.9rem;
     cursor: pointer;
     transition: all 0.2s ease;
 }

 .company-selector:focus {
     border-color: #4f46e5 !important;
     background-color: #fff !important;
     box-shadow: 0 0 0 0.25rem rgba(79, 70, 229, 0.25) !important;
 }


 /* User Dropdown */
 .user-dropdown {
     display: flex;
     align-items: center;
     gap: 0.75rem;
     padding: 0.25rem 0.5rem;
     border-radius: 10px;
     cursor: pointer;
     transition: all 0.2s ease;
 }

 .user-dropdown:hover {
     background-color: #f1f5f9;
 }

 .user-avatar {
     width: 38px;
     height: 38px;
     border-radius: 50%;
     background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
     color: white;
     display: flex;
     align-items: center;
     justify-content: center;
     font-weight: 600;
 }

 .user-info {
     display: flex;
     flex-direction: column;
 }

 .user-name {
     font-weight: 600;
     color: #1e293b;
     font-size: 0.875rem;
 }

 .user-role {
     font-size: 0.75rem;
     color: #64748b;
 }

 .dropdown-menu {
     border: none;
     box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
     border-radius: 12px;
     padding: 0.5rem;
     margin-top: 8px;
 }

 /* Ensure navbar dropdown overlays any side UI */
 .navbar .dropdown-menu {
     z-index: 5000;
 }

 .dropdown-item {
     padding: 0.625rem 1rem;
     border-radius: 8px;
     font-size: 0.875rem;
     display: flex;
     align-items: center;
     gap: 0.75rem;
     transition: all 0.2s ease;
 }

 .dropdown-item i {
     width: 20px;
     text-align: center;
     font-size: 1rem;
     color: #64748b;
     transition: inherit;
 }

 .dropdown-item:hover {
     background-color: #f8fafc;
     color: #4f46e5;
 }

 .dropdown-item:hover i {
     color: inherit;
 }

 /* Sidebar */
 .sidebar {
     position: fixed;
     top: var(--navbar-height);
     left: 0;
     width: var(--sidebar-width);
     height: calc(100vh - var(--navbar-height));
     background: white;
     border-right: 1px solid var(--gray-200);
     overflow-x: hidden;
     overflow-y: auto;
     overflow-y: overlay;
     transition: all 0.3s ease;
     z-index: 1020;
 }

 .sidebar.collapsed {
     width: var(--sidebar-collapsed-width);
 }

 .sidebar-content {
     padding: 1rem 0;
 }

 .sidebar-section {
     margin-bottom: 1.5rem;
 }

 .sidebar-title {
     font-size: 0.75rem;
     font-weight: 600;
     color: var(--gray-500);
     text-transform: uppercase;
     letter-spacing: 0.05em;
     padding: 0 1.5rem;
     margin-bottom: 0.75rem;
 }

 .sidebar.collapsed .sidebar-title {
     display: none;
 }

.sidebar.collapsed .nav-link-text {
    opacity: 0;
    visibility: hidden;
    max-width: 0;
    overflow: hidden;
    white-space: nowrap;
}
.sidebar.collapsed .submenu-toggle {
    display: none !important;
}

 .sidebar.collapsed .nav-submenu {
     display: none !important;
 }

 .sidebar.collapsed .nav-link i {
     margin: 0 !important;
     font-size: 1.25rem;
     display: flex;
     align-items: center;
     justify-content: center;
     width: 100%;
 }

 .submenu-toggle.rotated {
     transform: rotate(180deg);
 }

 .sidebar.collapsed .sidebar-content .nav-link .submenu-toggle {
     display: none !important;
 }


 .nav-item {
     margin-bottom: 0.25rem;
 }

 .nav-link {
     display: flex;
     align-items: center;
     gap: 0.75rem;
     padding: 0.625rem 1.5rem;
     color: var(--gray-600);
     text-decoration: none;
     font-weight: 500;
     border-radius: 0;
     transition: all 0.2s ease;
     position: relative;
 }

 .nav-link:hover {
     color: var(--primary-600);
     background-color: var(--primary-50);
 }

 .nav-link.active {
     color: var(--primary-600);
     background-color: var(--primary-50);
 }

 .nav-link.active::before {
     content: '';
     position: absolute;
     left: 0;
     top: 0;
     bottom: 0;
     width: 3px;
     background: var(--primary-600);
     border-radius: 0 3px 3px 0;
 }

 .nav-link i {
     font-size: 1.1rem;
     min-width: 24px;
 }

 .nav-link-text {
     transition: all 0.3s ease;
 }


 .sidebar.collapsed .nav-link.active::before {
     display: none;
 }

 .sidebar.collapsed .nav-link:hover {
     background-color: var(--primary-50);
 }



.sidebar.collapsed .nav-link-text {
    opacity: 0;
    visibility: hidden;
}

.sidebar.collapsed .nav-link {
    justify-content: center;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
    gap: 0;
}


 /* Submenu */
 .nav-submenu {
     padding-left: 1rem;
 }

 .nav-submenu .nav-link {
     padding: 0.5rem 1rem 0.5rem 3rem;
     font-size: 0.875rem;
 }

 .nav-submenu .nav-link.active {
     color: var(--primary-600);
     background-color: transparent;
     font-weight: 500;
 }

 .nav-submenu .nav-link.active::before {
     display: none;
 }


 .submenu-toggle {
     margin-left: auto;
     transition: all 0.3s ease;
     font-size: 0.75rem;
     display: flex;
     align-items: center;
 }

 .submenu-toggle.rotated {
     transform: rotate(180deg);
 }

 .sidebar.collapsed .submenu-toggle {
     display: none;
 }

 /* Main Content */
 #mainContent {
     margin-left: var(--sidebar-width);
     margin-top: var(--navbar-height);
     padding: var(--content-padding);
     transition: all 0.3s ease;
     min-height: calc(100vh - var(--navbar-height));
     background-color: var(--gray-50);
     flex: 1;
 }

 #mainContent.sidebar-collapsed {
     margin-left: var(--sidebar-collapsed-width);
 }

 /* Cards */
 .card {
     border: none;
     border-radius: 12px;
     box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
     margin-bottom: 1.5rem;
 }

 .card-header {
     background-color: white;
     border-bottom: 1px solid var(--gray-200);
     padding: 1rem 1.5rem;
     border-radius: 12px 12px 0 0 !important;
 }

 .card-title {
     font-weight: 600;
     color: var(--gray-800);
     margin-bottom: 0;
 }

 .card-body {
     padding: 1.5rem;
 }

 /* Forms */
 .form-label {
     font-weight: 500;
     color: var(--gray-700);
     margin-bottom: 0.5rem;
     font-size: 0.875rem;
 }

 .form-control,
 .form-select {
     font-size: 0.875rem;
     border-radius: 8px;
     border: 1px solid var(--gray-300);
     padding: 0.5rem 0.875rem;
     height: calc(1.5em + 1rem);
 }

 .form-control:focus,
 .form-select:focus {
     border-color: var(--primary-400);
     box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
 }

 /* Buttons */
 .btn {
     font-weight: 500;
     border-radius: 8px;
     padding: 0.5rem 1rem;
     font-size: 0.875rem;
     transition: all 0.2s ease;
 }

 .btn-primary {
     background-color: var(--primary-600);
     border-color: var(--primary-600);
 }

 .btn-primary:hover {
     background-color: var(--primary-700);
     border-color: var(--primary-700);
 }

 /* Alerts */
 .alert {
     border-radius: 8px;
     padding: 0.75rem 1.25rem;
     font-size: 0.875rem;
     border: none;
 }

 /* Badges */
 .badge {
     font-weight: 500;
     padding: 0.35rem 0.65rem;
     border-radius: 9999px;
     font-size: 0.75rem;
 }

 .badge-success {
     background-color: rgba(16, 185, 129, 0.1);
     color: var(--success-500);
 }

 .badge-warning {
     background-color: rgba(245, 158, 11, 0.1);
     color: var(--warning-500);
 }

 .badge-danger {
     background-color: rgba(239, 68, 68, 0.1);
     color: var(--danger-500);
 }

 /* Tables */
 .table {
     font-size: 0.875rem;
 }

 .table th {
     font-weight: 600;
     color: var(--gray-700);
     background-color: var(--gray-50);
     border-bottom-width: 1px;
 }

 /* Responsive */
 @media (max-width: 991.98px) {
     .sidebar {
         transform: translateX(-100%);
     }

     .sidebar.show {
         transform: translateX(0);
     }

     #mainContent {
         margin-left: 0;
     }

     .user-info {
         display: none;
     }
 }

@media print {

    .navbar,
    .sidebar,
    footer,
    .no-print {
        display: none !important;
    }

    #mainContent {
        margin-left: 0 !important;
        padding: 0 !important;
    }
}

/* When Bootstrap modals are open, ensure sidebar/nav are below and not interactive */
body.modal-open #sidebar,
body.modal-open .sidebar-backdrop {
    z-index: 1020 !important; /* below Bootstrap modal/backdrop (1055/1050) */
    pointer-events: none;
}
body.modal-open .navbar,
body.modal-open #sidebarToggle,
body.modal-open .sidebar-toggle {
    pointer-events: none;
}

/* Ensure modals always overlay nav/sidebar regardless of custom z-indexes */
.modal-backdrop { z-index: 5000 !important; }
.modal { z-index: 5001 !important; }


/* Sub-status banner link */
.sub-banner-link { color: inherit; }

/* Help AI modal */
.hai-dialog { max-width: 520px; margin: 4vh auto; }
.hai-content { height: 88vh; max-height: 720px; }
.hai-header { background: #1e293b; }
.hai-icon { width: 28px; height: 28px; background: #3b82f6; flex-shrink: 0; }
.hai-icon-i { font-size: .75rem; }
.hai-clear-btn { font-size: .9rem; line-height: 1; background: none; }
.hai-messages { background: #f1f5f9; min-height: 0; }
.hai-welcome-icon { width: 44px; height: 44px; background: #dbeafe; }
.hai-welcome-icon-i { font-size: 1.2rem; color: #3b82f6; }
.hai-welcome-title { color: #1e293b; }
.hai-typing { display: none; background: #f1f5f9; }
.hai-typing-icon { width: 26px; height: 26px; background: #1e293b; }
.hai-typing-icon-i { font-size: .6rem; }
.hai-typing-bubble { background: #e2e8f0; }
.hai-dot-2 { animation-delay: .22s; margin: 0 3px; }
.hai-dot-3 { animation-delay: .44s; }
.hai-input-bar { background: #fff; }
.hai-slow-hint { display: none; font-size: .72rem; }
