:root {
    /* Light Mode Variables */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --border-color: #dee2e6;
    --link-color: #007bff;
    --input-bg: #ffffff;

    /* Sidebar (light defaults keep existing look) */
    --sidebar-bg: var(--primary-color, #3394BF);
    --sidebar-text: #ffffff;
    --sidebar-hover-bg: rgba(255, 255, 255, 0.12);
    --sidebar-active-bg: rgba(255, 255, 255, 0.18);
}

[data-bs-theme="dark"] {
    /* Dark Mode Variables */
    --bg-primary: #121212;
    --bg-secondary: #1e1e1e;
    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --border-color: #444444;
    --link-color: #8ab4f8;
    --input-bg: #2b2b2b;

    /* Sidebar (dark) */
    --sidebar-bg: #0f172a;           /* slate-900 */
    --sidebar-text: #e5e7eb;         /* gray-200 */
    --sidebar-hover-bg: rgba(148, 163, 184, 0.12);
    --sidebar-active-bg: rgba(148, 163, 184, 0.18);
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Common component overrides */
/* Dark-mode-only overrides to avoid changing light-mode styling */
[data-bs-theme="dark"] input,
[data-bs-theme="dark"] select,
[data-bs-theme="dark"] textarea,
[data-bs-theme="dark"] .card,
[data-bs-theme="dark"] .navbar {
    background-color: var(--bg-secondary);
    border-color: var(--border-color);
    color: var(--text-primary);
}

a {
    color: var(--link-color);
}

/* Components that had hard-coded light backgrounds */
.sticky-header {
    background-color: var(--bg-primary) !important;
}

.modal-content,
.dropdown-menu {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.table {
    color: var(--text-primary);
}

.table-bordered > :not(caption) > * {
    border-color: var(--border-color);
}

/* Sidebar + top navbar theme alignment */
.sidebar {
    background-color: var(--sidebar-bg) !important;
    color: var(--sidebar-text) !important;
}

.sidebar .sidebar-item {
    color: var(--sidebar-text) !important;
}

[data-bs-theme="dark"] .sidebar .sidebar-nav .nav-link,
[data-bs-theme="dark"] .sidebar .toggle-node,
[data-bs-theme="dark"] .sidebar .parent-node i {
    color: var(--sidebar-text) !important;
}

[data-bs-theme="dark"] .sidebar .sidebar-nav .nav-link:hover,
[data-bs-theme="dark"] .sidebar .sidebar-nav .nav-link:focus-visible {
    background-color: var(--sidebar-hover-bg) !important;
}

[data-bs-theme="dark"] .sidebar .sidebar-nav .nav-link.active,
[data-bs-theme="dark"] .sidebar .sidebar-nav .nav-link[aria-current="page"] {
    background-color: var(--sidebar-active-bg) !important;
    color: var(--sidebar-text) !important;
}

[data-bs-theme="dark"] .top-navbar {
    background-color: var(--bg-secondary) !important;
    border-bottom: 1px solid var(--border-color);
}

[data-bs-theme="dark"] .top-navbar .nav-link,
[data-bs-theme="dark"] .top-navbar .dropdown-item,
[data-bs-theme="dark"] .navbar-text {
    color: var(--text-primary) !important;
}

[data-bs-theme="dark"] .top-navbar .dropdown-item:hover,
[data-bs-theme="dark"] .top-navbar .dropdown-item:focus-visible {
    background-color: var(--bg-primary);
}

.login-text {
    color: var(--text-primary) !important;
}

[data-bs-theme="dark"] body.login-bg .login-text,
[data-bs-theme="dark"] .login-bg .login-text {
    color: #f9fafb !important; /* force light text on dark background */
}

[data-bs-theme="dark"] .login-bg a {
    color: var(--link-color) !important;
}

/* In dark mode, keep login page background dark,
   but don't affect light-mode background */
[data-bs-theme="dark"] body.login-bg {
    background-color: #121212 !important;
}


/* Ensure login button hover stays consistent in light mode */
.login-btn:hover {
    background: rgb(51, 148, 191) !important;
    color: #ffffff !important;
}

[data-bs-theme="dark"] .select2-container .select2-selection--single,
[data-bs-theme="dark"] .select2-container .select2-selection--multiple {
    background-color: var(--input-bg) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
}

[data-bs-theme="dark"] .select2-container--default .select2-selection--single .select2-selection__rendered,
[data-bs-theme="dark"] .select2-container--default .select2-selection--multiple .select2-selection__rendered {
    color: var(--text-primary) !important;
}

[data-bs-theme="dark"] .select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: var(--text-secondary) !important;
}

[data-bs-theme="dark"] .select2-container--default .select2-selection--single .select2-selection__arrow b {
    border-color: var(--text-secondary) transparent transparent transparent !important;
}

[data-bs-theme="dark"] .select2-container .select2-dropdown {
    background-color: var(--bg-secondary) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
}

[data-bs-theme="dark"] .select2-results__option {
    background-color: transparent !important;
    color: var(--text-primary) !important;
}

[data-bs-theme="dark"] .select2-results__option--highlighted[aria-selected],
[data-bs-theme="dark"] .select2-container--default .select2-results__option--highlighted[aria-selected] {
    background-color: var(--sidebar-hover-bg) !important;
    color: var(--sidebar-text) !important;
}

[data-bs-theme="dark"] .select2-container--default .select2-results__option[aria-selected="true"] {
    background-color: var(--sidebar-active-bg) !important;
    color: var(--sidebar-text) !important;
}

/* Select2 bootstrap theme (your project uses select2-bootstrap-theme) */
[data-bs-theme="dark"] .select2-container--bootstrap .select2-selection {
    background-color: var(--input-bg) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
}

[data-bs-theme="dark"] .select2-container--bootstrap .select2-selection__rendered {
    color: var(--text-primary) !important;
}

[data-bs-theme="dark"] .select2-container--bootstrap .select2-selection__placeholder {
    color: var(--text-secondary) !important;
}

[data-bs-theme="dark"] .select2-container--bootstrap .select2-selection__arrow b {
    border-top-color: var(--text-secondary) !important;
}

[data-bs-theme="dark"] .select2-container--bootstrap .select2-dropdown {
    background-color: var(--bg-secondary) !important;
    border-color: var(--border-color) !important;
    color: var(--text-primary) !important;
}

[data-bs-theme="dark"] .select2-container--bootstrap .select2-results__option {
    color: var(--text-primary) !important;
}

/* Status badges: keep readable colors in dark mode */
[data-bs-theme="dark"] .badge-warning,
[data-bs-theme="dark"] .bg-warning,
[data-bs-theme="dark"] .badge.bg-warning {
    background-color: #ffc107 !important;
    color: #212529 !important;
}

[data-bs-theme="dark"] .badge-success,
[data-bs-theme="dark"] .bg-success,
[data-bs-theme="dark"] .badge.bg-success {
    background-color: #28a745 !important;
    color: #ffffff !important;
}

[data-bs-theme="dark"] .badge-danger,
[data-bs-theme="dark"] .bg-danger,
[data-bs-theme="dark"] .badge.bg-danger {
    background-color: #dc3545 !important;
    color: #ffffff !important;
}

[data-bs-theme="dark"] .badge-secondary,
[data-bs-theme="dark"] .bg-secondary,
[data-bs-theme="dark"] .badge.bg-secondary {
    background-color: #6c757d !important;
    color: #ffffff !important;
}

/* SweetAlert2 popups in dark mode */
[data-bs-theme="dark"] .swal2-popup {
    background: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color);
}

[data-bs-theme="dark"] .swal2-title {
    color: var(--text-primary) !important;
}

[data-bs-theme="dark"] .swal2-html-container {
    color: var(--text-primary) !important;
}

[data-bs-theme="dark"] .swal2-actions .swal2-styled.swal2-confirm {
    background-color: #4f46e5 !important; /* indigo */
    color: #ffffff !important;
}

[data-bs-theme="dark"] .swal2-actions .swal2-styled.swal2-cancel {
    background-color: #374151 !important;
    color: #e5e7eb !important;
}

/* Scrollable error textarea/content inside SweetAlert */
[data-bs-theme="dark"] .swal2-container textarea,
[data-bs-theme="dark"] .swal2-container pre,
[data-bs-theme="dark"] .swal2-container .swal2-textarea {
    background-color: #111827 !important;
    color: #f9fafb !important;
    border-color: var(--border-color) !important;
}

/* Generic Bootstrap helpers in dark mode */
[data-bs-theme="dark"] .bg-light {
    background-color: #111827 !important; /* near black, matches body */
    color: var(--text-primary) !important;
}

/* Profile page specific tweaks */
[data-bs-theme="dark"] .profile-sidebar-item {
    color: var(--text-primary) !important;
}

[data-bs-theme="dark"] .active-item.profile-sidebar-item {
    background-color: #1980ac !important;
    color: #ffffff !important;
}

[data-bs-theme="dark"] .highlight {
    background-color: #064e3b; /* dark green */
    color: #bbf7d0;
}

/* Page headers and section titles in dark mode */
[data-bs-theme="dark"] h1,
[data-bs-theme="dark"] h2,
[data-bs-theme="dark"] h3,
[data-bs-theme="dark"] .card-header h5,
[data-bs-theme="dark"] .card-header h6,
[data-bs-theme="dark"] .heading {
    color: #f9fafb !important;
}