/* Basic styles for the vertical sidebar */
body {
    display: flex;
}

.sidebar {
    width: 260px;
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    background-color: #fff; /* Light mode background */
    border-right: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s, border-color 0.3s;
    z-index: 1000;
}

.sidebar-header {
    padding: 0.8rem 1.5rem;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #e0e0e0;
    transition: border-color 0.3s;
}

/* Center title when no preview flag present */
.sidebar-header.no-preview-flag {
    justify-content: center;
    position: relative;
}
.sidebar-header.no-preview-flag .sidebar-title {
    margin-left: 0.4rem;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    width: max-content;
}

.sidebar-header img {
    margin-left: -24px;
    height: 80px; /* Force exact height */
    width: auto; /* Keep aspect ratio */
}

.sidebar-logo {
    /* Using the existing icon style */
    font-size: 1.8rem;
    margin-right: 10px;
}

.sidebar-title {
    font-size: 1.2rem;
    font-weight: 600;
    color: #333;
    transition: color 0.3s;
}

.sidebar-nav {
    flex-grow: 1;
    padding: 1rem 0;
    overflow-y: auto;
}

.nav-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.nav-item {
    margin: 0.2rem 0;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    color: #555;
    text-decoration: none;
    transition: background-color 0.2s, color 0.2s;
    border-radius: 4px;
    margin: 0 1rem;
}

.nav-link i {
    margin-right: 1rem;
    font-size: 1.2rem;
    width: 20px; /* Ensure icons align */
    text-align: center;
}

.nav-link span {
    /* Ensure text part is visible */
    white-space: nowrap;
}


.nav-link:hover {
    background-color: #f0f0f0;
    color: #111;
}

.nav-link.active {
    background-color: #e0e0f0; /* Example active color */
    color: #357abd; /* Example active text color */
    font-weight: 500;
}

.nav-separator {
    height: 1px;
    background-color: #e0e0e0;
    margin: 1rem 1.5rem;
    transition: background-color 0.3s;
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid #e0e0e0;
    transition: border-color 0.3s;
    position: relative; /* Ensure stacking context */
    z-index: 50; /* Ensure it is above sidebar-nav */
}

.user-profile {
    display: flex;
    align-items: center;
}

.user-profile-img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 10px;
    object-fit: cover;
}

.user-profile-info {
    line-height: 1.2;
    flex-grow: 1; /* Allow it to take available space */
    min-width: 0; /* Important for flex items to allow shrinking and ellipsis */
}

.user-profile-name {
    font-weight: 600;
    color: #333;
    font-size: 0.8rem; /* Reduced font size */
    transition: color 0.3s;
    display: block; /* Keep name on its own line */
    white-space: nowrap; /* Prevent name wrapping */
    overflow: hidden; /* Hide overflow for name */
    text-overflow: ellipsis; /* Add ellipsis for long names */
}

.user-profile-email {
    font-size: 0.5rem; /* Reduced font size */
    color: #777;
    transition: color 0.3s;
    display: block; /* Keep email on its own line below name */
    white-space: nowrap; /* Prevent email wrapping */
    overflow: hidden; /* Hide overflow for email */
    text-overflow: ellipsis; /* Add ellipsis for long emails */
}

/* Dark Mode Styles */
body.dark-mode .sidebar {
    background-color: #1a1a1a; /* Slightly different dark */
    border-right-color: #333;
}

body.dark-mode .sidebar-header,
body.dark-mode .sidebar-footer {
    border-color: #333;
}

body.dark-mode .sidebar-title,
body.dark-mode .user-profile-name {
    color: #e0e0e0;
}

body.dark-mode .nav-link {
    color: #aaa;
}

body.dark-mode .nav-link:hover {
    background-color: #2a2a2a;
    color: #fff;
}

body.dark-mode .nav-link.active {
    background-color: #2a2a4a; /* Example dark active color */
    color: #77aaff; /* Example dark active text color */
}

body.dark-mode .nav-separator {
    background-color: #333;
}

body.dark-mode .user-profile-email {
    color: #888;
}

/* Adjust main content area */
main.content-wrapper {
    margin-left: 260px; /* Same as sidebar width */
    width: calc(100% - 260px);
    transition: margin-left 0.3s, width 0.3s;
}

/* Styles for collapsed sidebar */
.sidebar-toggle-btn { /* Style for the toggle button */
    background: none;
    border: none;
    color: #555;
    font-size: 1.6rem;
    cursor: pointer;
    margin-left: auto; /* Push it to the right */
    padding: 0 0.5rem;
}
body.dark-mode .sidebar-toggle-btn {
    color: #aaa;
}


body.sidebar-collapsed .sidebar {
    width: 80px; /* Width when collapsed */
}

body.sidebar-collapsed main.content-wrapper {
    margin-left: 80px; /* Adjust content margin */
    width: calc(100% - 80px); /* Adjust content width */
}

body.sidebar-collapsed .sidebar-header {
    padding: 0.8rem 0em;
    justify-content: center; /* Center the logo */
}

body.sidebar-collapsed .sidebar-header img {
    margin-left: 0px; /* Center logo */
    margin-right: 7px; /* Center logo */
    height: 80px; /* Force exact height */
    width: auto; /* Keep aspect ratio */
    flex-shrink: 0; /* Prevent shrinking */
    cursor: pointer; /* Show that it's clickable */
}

body.sidebar-collapsed .sidebar-toggle-btn {
    display: none; /* Hide hamburger menu in collapsed state */
}


body.sidebar-collapsed .sidebar-logo-text {
    display: none !important;
}

body.sidebar-collapsed .sidebar-title,
body.sidebar-collapsed .preview-flag, /* Hide title and preview flag */
body.sidebar-collapsed .nav-link span, /* Hide text in nav links */
body.sidebar-collapsed .user-profile-info, /* Hide user name/email */
body.sidebar-collapsed .sidebar-footer .dropdown > button > div > span.ms-1, /* Hide ONLY the language code text span */
body.sidebar-collapsed .sidebar-footer #sidebar-qrcode-btn span /* Hide text in QR button */
 {
    display: none;
}

body.sidebar-collapsed .nav-link {
    justify-content: center; /* Center icon */
    margin: 0 0.5rem; /* Adjust margin */
    padding: 0.75rem 1rem; /* Adjust padding */
}

body.sidebar-collapsed .nav-link i {
    margin-right: 0; /* Remove margin from icon */
}

body.sidebar-collapsed .sidebar-logo {
     margin-right: 0; /* Remove margin from logo */
}

body.sidebar-collapsed .sidebar-footer {
    padding: 1rem; /* Adjust padding */
}

body.sidebar-collapsed .user-profile {
    justify-content: center; /* Center profile image */
}
body.sidebar-collapsed .user-profile-img {
    margin-right: 0; /* Remove margin from profile image */
}
body.sidebar-collapsed .user-profile a.btn {
    display: none; /* Hide logout button */
}

body.sidebar-collapsed .sidebar-footer .dropdown > button,
body.sidebar-collapsed .sidebar-footer #sidebar-qrcode-btn {
    justify-content: center; /* Center icon in buttons */
}
body.sidebar-collapsed .sidebar-footer .dropdown > button i,
body.sidebar-collapsed .sidebar-footer #sidebar-qrcode-btn i {
    margin-right: 0 !important; /* Remove margin from icons in buttons */
}

/* Ensure dropdowns in sidebar work correctly */
.sidebar-footer .dropdown-menu {
    /* Position relative to the button */
    position: absolute !important; 
    /* Adjust if needed based on final layout */
    top: auto !important;
    bottom: 100% !important; /* Positions the bottom edge at the top edge of the button */
    left: 0 !important;
    will-change: transform; /* Keep will-change in case transforms are added later */
    margin-bottom: 0.5rem !important; /* Increase gap slightly */
    z-index: 10000 !important; /* Ensure it is on top of everything */
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15) !important; /* Add shadow for better visibility (upwards) */
    background-color: var(--color-bg); /* Use theme background */
    border: 1px solid var(--color-border-strong) !important; /* Stronger border */
}

body.dark-mode .sidebar-footer .dropdown-menu {
    background-color: #2a2a2a;
    border-color: #333;
}

body.dark-mode .sidebar-footer .dropdown-item {
    color: #aaa;
}

body.dark-mode .sidebar-footer .dropdown-item:hover {
    background-color: #3a3a3a;
    color: #fff;
}

/* Style for buttons in footer */
.sidebar-footer .btn {
    font-size: 0.9rem; /* Slightly smaller text */
}

/* Mobile Off-Canvas Styles (e.g., below 992px) */
@media (max-width: 991.98px) {
    .sidebar {
        position: fixed;
        left: 0; /* Keep for positioning context */
        transform: translateX(-100%); /* Hide sidebar off-screen using transform */
        top: 0;
        height: 100dvh; /* Use dynamic viewport height */
        z-index: 1050; /* Ensure sidebar is above overlay */
        transition: transform 0.3s ease-in-out; /* Use transform for transition */
        box-shadow: 0 0 15px rgba(0,0,0,0.2); /* Add shadow for better separation */
        padding-bottom: 10px; 
        box-sizing: border-box; /* Include padding in height calculation */
    }

    .sidebar.sidebar-mobile-open {
        transform: translateX(0); /* Show sidebar using transform */
    }

    .sidebar-footer {
         /* Optional: Ensure footer doesn't shrink if content above is short */
         flex-shrink: 0;
    }

    main.content-wrapper {
        margin-left: 0; /* Full width content */
        width: 100%;
        transition: none; /* No transition needed for content on mobile */
    }

    /* Hide desktop toggle button on mobile if a different mobile toggle is used */
    /* .sidebar-toggle-btn { display: none; } */
    /* If using the same button, ensure it's visible and positioned correctly, e.g., in the navbar */

    /* Hide collapsed styles on mobile as they are not needed */
    body.sidebar-collapsed .sidebar {
        width: 260px; /* Reset width */
    }
    body.sidebar-collapsed main.content-wrapper {
        margin-left: 0; /* Reset margin */
        width: 100%; /* Reset width */
    }
    /* Reset other collapsed styles if necessary */
    body.sidebar-collapsed .sidebar-header,
    body.sidebar-collapsed .nav-link,
    body.sidebar-collapsed .nav-link i,
    body.sidebar-collapsed .sidebar-logo,
    body.sidebar-collapsed .sidebar-footer,
    body.sidebar-collapsed .user-profile {
        /* Reset specific collapsed styles if they interfere */
        padding: initial;
        justify-content: initial;
        margin: initial;
    }
    body.sidebar-collapsed .sidebar-title,
    body.sidebar-collapsed .preview-flag,
     body.sidebar-collapsed .nav-link span,
     body.sidebar-collapsed .user-profile-info,
     body.sidebar-collapsed .sidebar-footer .dropdown > button > div > span.ms-1,
     body.sidebar-collapsed .sidebar-footer #sidebar-qrcode-btn span,
     body.sidebar-collapsed .user-profile a.btn {
        display: initial; /* Show elements again */
     }
}

/* Overlay for mobile sidebar */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1040; /* Below sidebar, above content */
    display: none; /* Hidden by default */
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

.sidebar-overlay.sidebar-overlay-visible {
    display: block;
    opacity: 1;
}
