/* /css/sidebar.css */

#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width-expanded);
    background-color: var(--sidebar-bg-color);
    border-right: 1px solid var(--sidebar-border-color);
    z-index: 1000;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease, background-color 0.4s ease;
}

#main-content {
    padding: 0.75rem 1rem 1rem;
    padding-left: calc(var(--sidebar-width-expanded) + var(--main-content-left-padding-gap));
    transition: padding-left 0.3s ease;
    width: 100%;
    min-height: 100vh;
    box-sizing: border-box;
}

#sidebar ul.nav {
    margin-top: 1rem;
}

body.sidebar-collapsed #sidebar {
    width: var(--sidebar-width-collapsed);
}

body.sidebar-collapsed #main-content {
    padding-left: calc(var(--sidebar-width-collapsed) + var(--main-content-left-padding-gap));
}

body.sidebar-collapsed .user-notes-container {
    display: none;
    opacity: 0;
    pointer-events: none;
}

body.sidebar-hidden #sidebar {
    width: 0;
    transform: translateX(-100%);
    border-right: none;
}

body.sidebar-hidden #main-content {
    padding-left: var(--main-content-left-padding-gap);
}

.sidebar-header-area {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 0.5rem;
    border-bottom: 1px solid var(--sidebar-border-color);
    position: relative;
    height: 60px;
    transition: justify-content 0.3s ease, opacity 0.3s ease;
}

body.sidebar-hidden .sidebar-header-area {
    opacity: 0;
    pointer-events: none;
}

.sidebar-header-area .btn,
.sidebar-header-area .btn:focus,
.sidebar-header-area .btn:active {
    box-shadow: none !important;
}

.sidebar-header-area .btn,
.sidebar-header-btn,
#hideSidebarBtn,
#sidebar-toggle-btn {
    width: 38px;
    height: 38px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background-color: rgba(0, 0, 0, 0.04);
    border: 1px solid var(--sidebar-border-color);
    color: var(--sidebar-text-color);
    border-radius: 50%;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.sidebar-header-area .btn i,
.sidebar-header-btn i,
#hideSidebarBtn i,
#sidebar-toggle-btn i {
    font-size: 1.25rem;
    line-height: 1;
    color: currentColor;
}

.sidebar-header-area .btn:hover,
.sidebar-header-btn:hover,
#hideSidebarBtn:hover,
#sidebar-toggle-btn:hover {
    background-color: rgba(0, 0, 0, 0.08);
    border-color: var(--sidebar-border-color);
    color: var(--sidebar-text-color);
}

.sidebar-header-area .btn:focus-visible,
.sidebar-header-btn:focus-visible,
#hideSidebarBtn:focus-visible,
#sidebar-toggle-btn:focus-visible {
    outline: 2px solid var(--apple-accent-color);
    outline-offset: 2px;
}

/* Dark Mode support for Sidebar Header Buttons */
[data-bs-theme="dark"] .sidebar-header-area .btn,
[data-bs-theme="dark"] .sidebar-header-btn,
[data-bs-theme="dark"] #hideSidebarBtn,
[data-bs-theme="dark"] #sidebar-toggle-btn {
    background-color: rgba(255, 255, 255, 0.08);
    border-color: var(--sidebar-border-color);
    color: var(--sidebar-text-color);
}

[data-bs-theme="dark"] .sidebar-header-area .btn:hover,
[data-bs-theme="dark"] .sidebar-header-btn:hover,
[data-bs-theme="dark"] #hideSidebarBtn:hover,
[data-bs-theme="dark"] #sidebar-toggle-btn:hover {
    background-color: rgba(255, 255, 255, 0.16);
    border-color: rgba(255, 255, 255, 0.25);
    color: #ffffff;
}

.sidebar-logo-container {
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.5rem;
    overflow: hidden;
    transition: opacity 0.3s ease, width 0.3s ease;
}

.sidebar-logo {
    max-height: 32px;
    max-width: 100%;
    object-fit: contain;
}

body.sidebar-collapsed .sidebar-logo-container,
body.sidebar-hidden .sidebar-logo-container {
    display: none !important;
}

.sidebar-favicon {
    width: 20px;
    height: 20px;
    object-fit: contain;
}

body.sidebar-collapsed #sidebar-toggle-btn.has-custom-favicon {
    background-color: transparent !important;
    border: none !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}

body.sidebar-collapsed #sidebar-toggle-btn.has-custom-favicon i {
    display: none !important;
}

body.sidebar-collapsed #sidebar-toggle-btn.has-custom-favicon .sidebar-favicon {
    display: block !important;
    width: 28px;
    height: 28px;
}

#hideSidebarBtn {
    transition: opacity 0.3s ease, transform 0.3s ease;
}

body.sidebar-collapsed #hideSidebarBtn {
    opacity: 0;
    pointer-events: none;
    display: none;
}

#sidebar-toggle-btn {
    transition: transform 0.3s ease;
    position: static;
    top: auto;
    right: auto;
    left: auto;
    transform: none;
}

body.sidebar-collapsed #sidebar-toggle-btn i {
    transform: rotate(180deg);
}

body.sidebar-collapsed .sidebar-header-area {
    justify-content: center;
}

#sidebar .nav-link {
    font-weight: 500;
    border-radius: 0.6rem;
    margin-top: 0.25rem;
    padding: 0.6rem 1rem;
    transition: all 0.25s ease, box-shadow 0.2s ease;
    color: var(--sidebar-text-color);
}

#sidebar .nav-link:not(.active):hover {
    background-color: var(--sidebar-link-hover-bg);
    transform: translateY(-2px);
    box-shadow: none;
    color: var(--sidebar-text-color);
}

#sidebar .nav-link.active {
    background-color: var(--sidebar-link-active-bg);
    background: linear-gradient(135deg, color-mix(in srgb, var(--sidebar-link-active-bg, #6c63ff) 100%, white 25%), var(--sidebar-link-active-bg, #6c63ff));
    color: var(--sidebar-active-link-text-color);
    font-weight: 600;
    box-shadow: 0 0 12px var(--button-glow);
}

#sidebar .nav-link.active:hover {
    background-color: var(--accent-hover);
    transform: translateY(-3px);
    box-shadow: 0 0 12px var(--button-glow);
}

[data-bs-theme="dark"] #sidebar .nav-link.active {
    color: var(--sidebar-active-link-text-color);
}

#sidebar .nav-item {
    margin-bottom: 0.25rem;
}

#sidebar .nav-link .sidebar-icon {
    width: 1.5rem;
    text-align: center;
    font-size: 1.2rem;
}

#sidebar .nav-link span {
    margin-left: 1rem;
    white-space: nowrap;
}

body.sidebar-collapsed #sidebar .nav-link span,
body.sidebar-hidden #sidebar .nav-link span {
    opacity: 0;
    pointer-events: none;
    display: none;
}

body.sidebar-collapsed #sidebar .nav-link {
    justify-content: center;
}

.sidebar-portal-btn-container {
    margin-top: auto;
}

body.sidebar-collapsed .sidebar-portal-btn-container .nav-link {
    justify-content: center;
    padding: 0.6rem 0;
}

body.sidebar-hidden .sidebar-portal-btn-container {
    opacity: 0;
    pointer-events: none;
}

.user-profile-footer {
    padding: 0.6rem 1rem;
    border-top: 1px solid var(--sidebar-border-color);
    width: 100%;
    box-sizing: border-box;
    background-color: transparent;
}

body.sidebar-hidden .user-profile-footer {
    opacity: 0;
    pointer-events: none;
}

body.sidebar-collapsed .user-profile-footer {
    align-items: center;
    padding-left: 0;
    padding-right: 0;
}

.user-profile-trigger {
    cursor: pointer;
    width: 100%;
    padding: 0.5rem;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    transition: background-color 0.25s ease, transform 0.2s ease;
    border-radius: 0.6rem;
    gap: 0.7rem;
}

.user-profile-trigger:hover {
    background-color: var(--sidebar-link-hover-bg);
    transform: translateY(-2px);
}

body.sidebar-collapsed .user-profile-trigger {
    justify-content: center;
    padding: 0.5rem 0;
    margin-bottom: 0;
}

.user-avatar-display {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--user-avatar-bg-color);
    color: var(--user-avatar-text-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.1rem;
    flex-shrink: 0;
    opacity: 1;
    pointer-events: auto;
    transition: opacity 0.3s ease, background-color 0.25s ease;
}

body.sidebar-collapsed .user-avatar-display {
    margin-right: 0;
    margin-left: 0;
}

.user-full-name {
    font-size: 1rem;
    font-weight: bold;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 1;
    pointer-events: auto;
    transition: opacity 0.3s ease;
}

body.sidebar-collapsed .user-full-name {
    opacity: 0;
    pointer-events: none;
    display: none;
}

#showSidebarBtn {
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 999;
    display: none;
    background-color: var(--apple-accent-color);
    color: white;
    border: none;
    border-radius: 0.5rem;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 1.2rem;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

[data-bs-theme="dark"] #showSidebarBtn {
    color: #1c1c1e;
}

body.sidebar-hidden #showSidebarBtn.has-custom-favicon {
    display: flex;
    opacity: 1;
    background-color: transparent !important;
    padding: 0;
    width: 48px;
    height: 48px;
}

body.sidebar-hidden #showSidebarBtn.has-custom-favicon i {
    display: none !important;
}

.sidebar-favicon-big {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

body.sidebar-hidden #showSidebarBtn.has-custom-favicon .sidebar-favicon-big {
    display: block !important;
}

/* === Sidebar Notes Scrolling Fix === */
.user-notes-container {
    min-height: 0;
}

.notes-list {
    overflow-y: auto;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.notes-list::-webkit-scrollbar {
    display: none;
}

/* === Popover Menu Styles === */
.user-popover-menu,
#menuPopover {
    position: fixed;
    z-index: 1050;
    display: none;
    min-width: 200px;
    background-color: var(--sidebar-bg-color);
    border: 1px solid var(--sidebar-border-color);
    border-radius: 0.6rem;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    padding: 0.5rem;
    opacity: 0;
    visibility: hidden;
    transform: scale(0.95) translateY(5px);
    transition: opacity 0.15s ease-out, transform 0.15s ease-out, visibility 0.15s;
}

.user-popover-menu.show,
#menuPopover.show {
    display: block;
    opacity: 1;
    visibility: visible;
    transform: scale(1) translateY(0);
}

.user-popover-menu .popover-link {
    display: block;
    padding: 0.6rem 0.8rem;
    color: var(--sidebar-text-color);
    text-decoration: none;
    border-radius: 0.4rem;
    transition: background-color 0.2s ease;
    white-space: nowrap;
}

.user-popover-menu .popover-link:hover {
    background-color: var(--sidebar-link-hover-bg);
    color: var(--sidebar-text-color);
}

.user-popover-menu .popover-avatar {
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, var(--apple-accent-color, #6c63ff), var(--accent-hover, #5850ec));
    font-size: 0.78rem;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.user-popover-menu .popover-section-label {
    opacity: 0.7;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.user-popover-menu .popover-divider {
    height: 1px;
    background-color: var(--bs-border-color-translucent, rgba(255, 255, 255, 0.08));
    margin: 4px 0;
}


/* === Collapsed Sidebar Tooltip Styles === */
.tooltip {
    z-index: 1080 !important;
}

/* MODIFIED: This now uses the solid sidebar background color and a border */
.tooltip-inner {
    background-color: var(--sidebar-bg-color);
    /* Use solid background */
    color: var(--sidebar-text-color);
    border-radius: 0.5rem;
    padding: 0.5rem 0.9rem;
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--sidebar-border-color);
    /* Add border to match popover */
}

/* This hides the arrow */
.tooltip .tooltip-arrow {
    display: none !important;
}

/* ==========================================================================
   Mobile Responsive Sidebar (< 992px)
   Disables icon-mode (collapsed) and push-toggle mode on small screens (phones).
   Sidebar opens as a full-screen overlay (100vw x 100dvh) without displacing
   or squeezing main-content. When closed, it stays hidden as a top-left button.
   ========================================================================== */
@media (max-width: 991.98px) {
    /* 1. Main content NEVER gets displaced or squeezed on small screens */
    #main-content,
    body.sidebar-collapsed #main-content,
    body.sidebar-hidden #main-content,
    body:not(.sidebar-hidden) #main-content {
        padding-left: var(--main-content-left-padding-gap) !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        transition: none !important;
    }

    /* 2. On small screens, icon mode (collapsed) and toggle mode are disabled */
    body.sidebar-collapsed #sidebar {
        width: 100vw !important;
    }

    body.sidebar-collapsed #sidebar-toggle-btn,
    #sidebar-toggle-btn {
        display: none !important;
    }

    /* 3. Full-screen sidebar overlay on small screens */
    #sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        max-width: 100vw !important;
        height: 100% !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        z-index: 10060 !important;
        border-right: none !important;
        box-shadow: none !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        background-color: var(--sidebar-bg-color) !important;
        transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.2s ease !important;
    }

    /* When open (not sidebar-hidden) */
    body:not(.sidebar-hidden) #sidebar {
        transform: translateX(0) !important;
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto !important;
    }

    /* When closed (sidebar-hidden) */
    body.sidebar-hidden #sidebar {
        transform: translateX(-100%) !important;
        opacity: 0 !important;
        visibility: hidden !important;
        pointer-events: none !important;
        width: 0 !important;
    }

    /* 4. Header area inside full-screen sidebar: Logo on left, Close "X" on right */
    .sidebar-header-area {
        height: 64px !important;
        padding: 0.75rem 1rem !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        border-bottom: 1px solid var(--sidebar-border-color) !important;
        flex-shrink: 0 !important;
    }

    .sidebar-logo-container {
        display: flex !important;
        align-items: center !important;
        justify-content: flex-start !important;
        order: 1 !important;
        margin-right: auto !important;
        padding: 0 !important;
    }

    .sidebar-logo {
        max-height: 34px !important;
    }

    #hideSidebarBtn {
        display: flex !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        order: 2 !important;
        margin-left: auto !important;
        margin-right: 0 !important;
        width: 40px !important;
        height: 40px !important;
        font-size: 1.45rem !important;
        background-color: rgba(var(--bs-body-color-rgb, 0, 0, 0), 0.06) !important;
        border: 1px solid var(--sidebar-border-color) !important;
        color: var(--sidebar-text-color) !important;
        border-radius: 50% !important;
    }

    #hideSidebarBtn:hover,
    #hideSidebarBtn:active {
        background-color: rgba(var(--bs-body-color-rgb, 0, 0, 0), 0.12) !important;
    }

    [data-bs-theme="dark"] #hideSidebarBtn {
        background-color: rgba(255, 255, 255, 0.1) !important;
        border-color: rgba(255, 255, 255, 0.15) !important;
        color: #ffffff !important;
    }

    /* 5. Navigation items inside full-screen sidebar */
    #sidebar ul.nav {
        margin-top: 1rem !important;
        padding: 0 1rem !important;
        flex-shrink: 0 !important;
    }

    #sidebar .nav-item {
        margin-bottom: 0.4rem !important;
    }

    #sidebar .nav-link {
        font-size: 1.05rem !important;
        padding: 0.85rem 1.15rem !important;
        border-radius: 0.75rem !important;
        display: flex !important;
        align-items: center !important;
        justify-content: flex-start !important;
    }

    #sidebar .nav-link span {
        display: inline-block !important;
        opacity: 1 !important;
        pointer-events: auto !important;
        margin-left: 0.85rem !important;
        font-size: 1.05rem !important;
        font-weight: 500 !important;
        white-space: normal !important;
    }

    #sidebar .nav-link .sidebar-icon {
        font-size: 1.35rem !important;
        width: 1.75rem !important;
    }

    /* 6. Show sidebar button in top left when closed */
    #showSidebarBtn {
        top: 0.75rem !important;
        left: 0.75rem !important;
        z-index: 10040 !important;
        border-radius: 0.65rem !important;
    }

    body.sidebar-hidden #showSidebarBtn {
        display: flex !important;
    }

    body:not(.sidebar-hidden) #showSidebarBtn {
        display: none !important;
    }

    /* 7. User profile footer on mobile */
    .user-profile-footer {
        padding: 0.85rem 1rem !important;
        margin-top: auto !important;
        border-top: 1px solid var(--sidebar-border-color) !important;
        flex-shrink: 0 !important;
    }

    .user-profile-trigger {
        padding: 0.65rem 0.85rem !important;
    }

    .user-full-name {
        display: inline-block !important;
        opacity: 1 !important;
        font-size: 1.05rem !important;
    }

    /* 8. User notes container on mobile */
    .user-notes-container {
        padding: 0 1rem !important;
        margin-top: 1rem !important;
    }

    /* 9. User Popover positioning on mobile */
    .user-popover-menu {
        position: fixed !important;
        left: 1rem !important;
        right: 1rem !important;
        width: auto !important;
        max-width: calc(100vw - 2rem) !important;
        bottom: 5.5rem !important;
        top: auto !important;
        z-index: 10070 !important;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25) !important;
    }

    /* 10. Lock body scrolling when full-screen sidebar is open */
    body.mobile-sidebar-open {
        overflow: hidden !important;
    }
}