:root {
    --primary-color: #28a745; /* IMV Green */
    --secondary-color: #6c757d;
    --sidebar-width: 250px;
    --header-height: 60px;
    --bg-light: #f4f6f9;
    --text-light: #333;
    --bg-dark: #1e1e2f;
    --text-dark: #f4f6f9;
    --sidebar-bg-light: #ffffff;
    --sidebar-bg-dark: #27293d;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-light);
    color: var(--text-light);
    transition: background-color 0.3s, color 0.3s;
}

body.dark-mode {
    background-color: var(--bg-dark);
    color: var(--text-dark);
}

.wrapper {
    display: flex;
    width: 100%;
}

/* Sidebar */
#sidebar {
    width: var(--sidebar-width);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 999;
    background: var(--sidebar-bg-light);
    color: #333;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
}

body.dark-mode #sidebar {
    background: var(--sidebar-bg-dark);
    color: #fff;
    box-shadow: 2px 0 10px rgba(0,0,0,0.3);
}

.sidebar-header-wrapper {
    position: sticky;
    top: 0;
    z-index: 10;
    background: inherit;
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

body.dark-mode .sidebar-header-wrapper {
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

#sidebar .sidebar-header {
    padding: 20px;
    background: rgba(0,0,0,0.02);
    text-align: center;
}

body.dark-mode #sidebar .sidebar-header {
    background: rgba(255,255,255,0.02);
}

.sidebar-logo {
    max-width: 80%;
    transition: transform 0.3s;
}

.sidebar-search .input-group-text {
    border-color: rgba(0,0,0,0.1);
}

body.dark-mode .sidebar-search .input-group-text {
    border-color: rgba(255,255,255,0.1);
}

#sidebarSearch::placeholder {
    color: rgba(0,0,0,0.4);
}

body.dark-mode #sidebarSearch::placeholder {
    color: rgba(255,255,255,0.4);
}

#sidebarSearch {
    color: inherit !important;
}

/* Scroll Container */
.sidebar-scroll-container {
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--primary-color) transparent;
    position: relative;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* Visual Indicators for Scroll */
.sidebar-scroll-container::before,
.sidebar-scroll-container::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    height: 20px;
    z-index: 5;
    pointer-events: none;
    transition: opacity 0.3s;
    opacity: 0;
}

.sidebar-scroll-container::before {
    top: 0;
    background: linear-gradient(to bottom, rgba(0,0,0,0.05), transparent);
}

.sidebar-scroll-container::after {
    bottom: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.05), transparent);
}

.sidebar-scroll-container.can-scroll-up::before {
    opacity: 1;
}

.sidebar-scroll-container.can-scroll-down::after {
    opacity: 1;
}

body.dark-mode .sidebar-scroll-container::before {
    background: linear-gradient(to bottom, rgba(0,0,0,0.2), transparent);
}

body.dark-mode .sidebar-scroll-container::after {
    background: linear-gradient(to top, rgba(0,0,0,0.2), transparent);
}

/* Custom Scrollbar */
.sidebar-scroll-container::-webkit-scrollbar {
    width: 5px;
}

.sidebar-scroll-container::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-scroll-container::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 10px;
    opacity: 0.5;
}

/* Menu Items */
#sidebar ul.components {
    padding: 10px 0;
}

#sidebar ul li.menu-item, 
#sidebar ul li.menu-group {
    padding: 2px 10px;
}

#sidebar ul li a {
    color: inherit;
    text-decoration: none;
    display: flex;
    align-items: center;
    padding: 12px 15px;
    border-radius: 8px;
    transition: all 0.2s;
    font-size: 0.95rem;
    position: relative;
    overflow: hidden;
}

#sidebar ul li a:hover {
    background: rgba(var(--primary-color-rgb, 40, 167, 69), 0.1);
    color: var(--primary-color);
    transform: translateX(5px);
}

#sidebar ul li a.active {
    background: var(--primary-color);
    color: #fff;
    box-shadow: 0 4px 10px rgba(var(--primary-color-rgb, 40, 167, 69), 0.3);
}

#sidebar ul li a i {
    margin-right: 12px;
    width: 20px;
    text-align: center;
    font-size: 1.1rem;
}

/* Sidebar menu count badge (e.g. new portal requests on Administration) */
#sidebar ul li a .menu-badge {
    flex-shrink: 0;
    padding: 0.35em 0.6em;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1;
}

/* Collapsible Groups */
.menu-group > a.dropdown-toggle::after {
    content: '\f107';
    font-family: 'Font Awesome 5 Free';
    font-weight: 900;
    margin-left: auto;
    transition: transform 0.3s;
}

.menu-group > a[aria-expanded="true"].dropdown-toggle::after {
    transform: rotate(180deg);
}

.menu-group ul {
    padding-left: 15px;
    margin-top: 5px;
    border-left: 1px solid rgba(0,0,0,0.05);
    margin-left: 25px;
}

body.dark-mode .menu-group ul {
    border-left: 1px solid rgba(255,255,255,0.05);
}

/* Footer */
.sidebar-footer {
    border-top: 1px solid rgba(0,0,0,0.05);
    background: inherit;
    z-index: 10;
}

body.dark-mode .sidebar-footer {
    border-top: 1px solid rgba(255,255,255,0.05);
}

.logout-btn {
    transition: all 0.3s;
}

.logout-btn:hover {
    background-color: #dc3545;
    color: #fff;
    box-shadow: 0 4px 10px rgba(220, 53, 69, 0.3);
}

.version-info {
    font-size: 0.75rem;
    opacity: 0.6;
    color: inherit;
}

/* Content */
#content {
    width: calc(100% - var(--sidebar-width));
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: all 0.3s;
}

/* Header */
.main-header {
    height: var(--header-height);
    background: #fff;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

body.dark-mode .main-header {
    background: #27293d;
    color: #fff;
}

/* Sidebar Toggled State (Desktop: Collapsed) */
#sidebar.toggled {
    width: 80px;
}

#sidebar.toggled .sidebar-header {
    padding: 15px 5px;
}

#sidebar.toggled .sidebar-logo {
    max-width: 40px;
}

#sidebar.toggled .sidebar-search {
    display: none;
}

#sidebar.toggled .sidebar-scroll-container {
    overflow: visible; /* Show submenus over content when collapsed */
}

#sidebar.toggled ul li a span,
#sidebar.toggled .menu-group > a::after {
    display: none;
}

#sidebar.toggled ul li a {
    text-align: center;
    padding: 15px 10px;
    justify-content: center;
}

#sidebar.toggled ul li a i {
    margin-right: 0;
    font-size: 1.3rem;
}

#sidebar.toggled .menu-group ul {
    position: absolute;
    left: 80px;
    top: 0;
    width: 200px;
    background: inherit;
    box-shadow: 5px 5px 15px rgba(0,0,0,0.1);
    padding-left: 0;
    margin-left: 0;
    border-left: none;
    display: none;
    border-radius: 0 8px 8px 0;
}

#sidebar.toggled .menu-group:hover ul {
    display: block !important;
    z-index: 1000;
}

#sidebar.toggled .menu-group ul li a {
    text-align: left;
    justify-content: flex-start;
    padding: 10px 20px;
}

#sidebar.toggled .menu-group ul li a span {
    display: inline;
}

#sidebar.toggled .user-welcome,
#sidebar.toggled .sidebar-footer span,
#sidebar.toggled .version-info {
    display: none;
}

#sidebar.toggled .logout-btn {
    padding: 12px;
}

#sidebar.toggled .logout-btn i {
    margin-right: 0;
}

#content.toggled {
    margin-left: 80px;
    width: calc(100% - 80px);
}

/* Responsive */
@media (max-width: 768px) {
    #sidebar {
        margin-left: -250px;
    }
    
    /* On mobile, toggled means OPEN/VISIBLE */
    #sidebar.toggled {
        margin-left: 0;
        width: 250px;
    }
    
    #sidebar.toggled .sidebar-header img {
        display: block; /* Show logo on mobile open */
    }
    #sidebar.toggled .sidebar-header::after {
        display: none;
    }
    #sidebar.toggled ul li a span {
        display: inline;
    }
    #sidebar.toggled ul li a {
        justify-content: flex-start;
        text-align: left;
        padding: 10px 20px;
    }
    #sidebar.toggled ul li a i {
        margin-right: 10px;
    }
    
    #content {
        margin-left: 0;
        width: 100%;
    }
    #content.toggled {
        margin-left: 0;
    }
}

body.dark-mode .main-header {
    background: var(--sidebar-bg-dark);
    color: #fff;
}

/* Dashboard Tiles */
.tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    padding: 20px;
}

.tile {
    background: #fff;
    border-radius: 10px;
    padding: 30px;
    text-align: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    transition: transform 0.2s;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 180px;
}

body.dark-mode .tile {
    background: var(--sidebar-bg-dark);
    color: #fff;
}

.tile:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.tile i {
    font-size: 2.5rem;
    margin-bottom: 15px;
    color: var(--primary-color);
}

.tile h5 {
    font-size: 1.1rem;
    margin: 0;
}

/* Deadline Widgets */
.deadline-widget .deadline-btn {
    max-width: 340px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.deadline-widget .deadline-countdown {
    min-width: 52px;
    font-size: 0.75rem;
}

.deadline-widget .dropdown-menu {
    min-width: 240px;
}

.deadline-widget .dropdown-item-text {
    white-space: normal;
}

body.dark-mode .deadline-widget .dropdown-menu {
    background: #2e2e3d;
    color: #fff;
}

body.dark-mode .deadline-widget .dropdown-item-text {
    color: #dee2e6;
}

/* System Banner */
.system-banner {
    width: 100%;
}

.system-banner-inner {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 0.65rem 20px;
    font-size: 0.95rem;
    font-weight: 500;
    line-height: 1.4;
    border-bottom: 1px solid rgba(0, 0, 0, 0.15);
}

.system-banner-icon {
    flex-shrink: 0;
    margin-top: 0.1rem;
    font-size: 1rem;
    line-height: 1.4;
}

.system-banner-text {
    flex: 1 1 auto;
    white-space: pre-line;
    word-break: break-word;
}

/* Colour swatches + preview box (settings page) */
.banner-swatch {
    display: inline-block;
    width: 0.85rem;
    height: 0.85rem;
    border-radius: 3px;
    vertical-align: -1px;
    border: 1px solid rgba(0, 0, 0, 0.15);
}

.banner-swatch-green {
    background-color: #198754;
}

.banner-swatch-yellow {
    background-color: #ffc107;
}

.banner-swatch-red {
    background-color: #dc3545;
}

.banner-preview-box {
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.12);
}

body.dark-mode .banner-preview-box {
    border-color: rgba(255, 255, 255, 0.15);
}

/* Green */
.system-banner-green {
    background-color: #198754;
    color: #fff;
}

/* Yellow */
.system-banner-yellow {
    background-color: #ffc107;
    color: #212529;
}

/* Red */
.system-banner-red {
    background-color: #dc3545;
    color: #fff;
}

/* Dark mode: the same solid colours, so the status of the banner never
   changes meaning between light and dark mode. */
body.dark-mode .system-banner-green {
    background-color: #198754;
    color: #fff;
}

body.dark-mode .system-banner-yellow {
    background-color: #ffc107;
    color: #212529;
}

body.dark-mode .system-banner-red {
    background-color: #dc3545;
    color: #fff;
}

/* Responsive */
@media (max-width: 768px) {
    #sidebar {
        margin-left: calc(-1 * var(--sidebar-width));
    }
    #sidebar.active {
        margin-left: 0;
    }
    #content {
        width: 100%;
        margin-left: 0;
    }
}
