/* ─── Navbar ─────────────────────────────────────────────────────────────── */
#main-navbar {
    background: var(--oc-navbar-bg);
    border-bottom: 1px solid var(--oc-primary);
    height: 60px;
    padding: 0.5rem 0;
    z-index: 500;
    margin-left: 200px;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
}

#main-navbar .toggle-btn {
    color: var(--oc-primary);
    font-size: 28px;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
    line-height: 1;
}

#main-navbar .goto-dashboard {
    width: 30px;
    margin-top: 2px;
}

#main-navbar.full-width {
    margin-left: 0;
}

/* ─── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
    background-color: var(--oc-sidebar-bg);
    width: 200px;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    padding: 5px 0 0;
    box-shadow: 0 2px 5px 0 rgb(0 0 0 / 5%), 0 2px 10px 0 rgb(0 0 0 / 5%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 600;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar a {
    color: var(--oc-sidebar-text);
    text-decoration: none;
}

.sidebar .sidebar-brand {
    display: block;
    flex-shrink: 0;
    padding: 10px 10px 12px;
    border-bottom: 1px solid var(--oc-primary);
    margin-bottom: 4px;
}

.sidebar .sidebar-brand img {
    width: 180px;
}

.sidebar.hide {
    transform: translateX(-100%);
}

.sidebar .dropdown-toggle::after {
    display: none;
}

/* ─── Sidebar Nav ────────────────────────────────────────────────────────── */
/* The list is the part of the sidebar that scrolls, at every width. The logo above it and Log Out below it
   keep their place, so Log Out stays in the window however many entries the list holds. At 992px and wider
   the sidebar itself must not clip (see the flyout block below), so the list, not the sidebar, is the box
   that scrolls there. */
.sidebar-nav {
    list-style: none;
    padding-left: 0;
    margin: 0;
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--oc-sidebar-text) var(--oc-sidebar-bg);
}

.sidebar-nav .nav-link,
.sidebar-nav .nav-link span {
    display: flex;
    align-items: center;
    color: var(--oc-sidebar-text);
    font-size: 15px;
}

.sidebar-nav .nav-link i.nav-icon {
    width: 24px;
    font-size: 18px;
    text-align: center;
    margin-right: 10px;
    flex-shrink: 0;
}

.sidebar-nav .nav-link .chevron {
    margin-left: auto;
    font-size: 12px;
    transition: transform 0.25s ease;
}

.sidebar-nav .nav-item {
    border-radius: 0;
    display: block;
}

.sidebar-nav .nav-item > .nav-link {
    padding: 0.55rem 0.75rem;
    /* Transparent by default so turning the marker on does not shift the label sideways. */
    border-left: 4px solid transparent;
}

/* Current-page marker.
   These rules used to target `.nav-item.active`, i.e. the <li>. Blazor's <NavLink> puts the
   `active` class on the <a> it renders, not on the parent <li>, so the selector matched nothing and
   the sidebar gave no indication of which page you were on. */
.sidebar-nav > .nav-item > .nav-link.active {
    border-left-color: var(--oc-primary);
    background: var(--oc-sidebar-hover);
    color: var(--oc-text-light);
}

.sidebar-nav > .nav-item > .nav-link.active span,
.sidebar-nav > .nav-item > .nav-link.active i {
    color: var(--oc-text-light);
}

/* A parent whose flyout holds the current page is marked too, otherwise landing on
   /Reports/NetSales left every top-level entry looking inactive. */
.sidebar-nav > .nav-item:has(.dropdown-item.active) > .nav-link {
    border-left-color: var(--oc-primary);
    color: var(--oc-text-light);
}

.sidebar-nav .dropdown-menu {
    background-color: var(--oc-sidebar-bg);
    border: none;
    border-radius: 0;
    padding: .25rem 0;
    margin: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

.sidebar-nav .dropdown-menu .dropdown-item {
    color: var(--oc-sidebar-text);
    padding: 0.4rem 1rem;
    font-size: 14px;
    white-space: normal;
}

/* :focus is listed because Bootstrap's own .dropdown-item:focus paints a light grey background, and the
   sidebar's light text on it is unreadable for a keyboard user. */
.sidebar-nav .dropdown-menu .dropdown-item:hover,
.sidebar-nav .dropdown-menu .dropdown-item:focus,
.sidebar-nav .dropdown-menu .dropdown-item.active {
    background-color: var(--oc-sidebar-hover);
    color: var(--oc-text-light);
}

@media (hover: hover) {
    .sidebar a:hover {
        color: var(--oc-text-light);
    }

    .sidebar-nav .nav-item:hover {
        background: var(--oc-sidebar-hover);
    }

    .sidebar-nav .nav-item:hover > .nav-link {
        color: var(--oc-text-light);
    }
}

/* ─── Sidebar bottom ─────────────────────────────────────────────────────── */
.sidebar-bottom {
    list-style: none;
    flex-shrink: 0;
    padding: 0;
    margin: 0;
    margin-top: auto;
    border-top: 1px solid #444;
}

.sidebar-bottom .nav-link {
    padding: 0.55rem 0.75rem;
    display: flex;
    align-items: center;
    color: var(--oc-sidebar-text);
    font-size: 15px;
}

.sidebar-bottom .nav-link i {
    width: 24px;
    font-size: 18px;
    text-align: center;
    margin-right: 10px;
}

.sidebar-bottom .nav-link:hover {
    color: var(--oc-text-light);
    background: var(--oc-sidebar-hover);
}

/* ─── Content ────────────────────────────────────────────────────────────── */
#content {
    width: calc(100% - 200px);
    margin-left: 200px;
    margin-top: 60px;
    height: calc(100vh - 60px);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#content.full-width {
    margin-left: 0;
    width: 100%;
}

/* ─── Backdrop (mobile only) ──────────────────────────────────────────────── */
.sidebar-backdrop {
    display: none;
}

@media (max-width: 768px) {
    .sidebar-backdrop {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.35);
        z-index: 599;
    }
}

/* ─── Desktop flyout submenus (>=992px) ──────────────────────────────────── */
/* Each group opens a flyout beside the sidebar. A flyout that starts at its own row runs past the bottom of
   the window for a low row such as Settings, so its last entries could not be seen or clicked. The flyout
   is therefore positioned against .sidebar, not against its row: .dropend is static, so the containing
   block of the flyout is .sidebar (position: fixed), an ancestor of the scrolling .sidebar-nav. The list
   then cannot clip the flyout, and a hidden flyout adds nothing to the list's scroll height.
   wwwroot/lib/js/sidebarFlyout.js sets the three --oc-flyout-* properties when a row is hovered, focused or
   clicked: the row's top, moved up just far enough for the whole flyout to fit in the window, the row's
   right edge, and the window height. Without the script the fallbacks open the flyout at the top of the
   window. A click on the row then pins it, and the keyboard reaches it, but hover can lose it on the way:
   the flyout may not reach down to a low row, and it starts beyond the list's scrollbar.
   A hidden flyout keeps pointer events. While it fades out it still takes the pointer, so a pointer that
   crosses the list's scrollbar on its way to the flyout hovers the row again instead of closing it. An
   overlay scrollbar lies inside the row, so the row's right edge alone does not close that gap. Once the
   fade ends, visibility: hidden takes no pointer. */
@media (min-width: 992px) {
    .sidebar {
        overflow: visible;
    }

    .sidebar-nav .dropend {
        position: static;
    }

    .sidebar-nav .dropend > .dropdown-menu {
        position: absolute;
        top: var(--oc-flyout-top, 0px);
        left: var(--oc-flyout-left, 100%);
        max-height: var(--oc-flyout-max-height, 100%);
        overflow-x: hidden;
        overflow-y: auto;
        overscroll-behavior: contain;
        scrollbar-width: thin;
        scrollbar-color: var(--oc-sidebar-text) var(--oc-sidebar-bg);
        display: block;
        visibility: hidden;
        opacity: 0;
        transform: translateX(-12px);
        transition: visibility 0.2s ease, opacity 0.25s ease, transform 0.25s ease;
        min-width: 200px;
    }

    /* open-mobile is the class a click on the row sets (the Toggle methods of Shared/NavMenu.razor). Despite
       its name it applies at this width too: a click pins the flyout open. */
    .sidebar-nav .dropend:hover > .dropdown-menu,
    .sidebar-nav .dropend > .dropdown-menu.open-mobile {
        visibility: visible;
        opacity: 1;
        transform: translateX(0);
    }

    /* Every flyout has the same z-index (Bootstrap's .dropdown-menu) in the .sidebar stacking context, so
       the later row painted on top: a pinned Settings flyout, moved up to fit the window, covered half of
       a hovered Reports flyout. The hovered flyout is raised above a pinned one. */
    .sidebar-nav .dropend:hover > .dropdown-menu {
        z-index: 1001;
    }

    .sidebar-nav .dropend:hover > .nav-link .chevron,
    .sidebar-nav .dropend > .nav-link .chevron.chevron-open {
        transform: rotate(90deg);
    }
}

/* ─── Tablet accordion submenus (<=991px) ────────────────────────────────── */
/* A group opens in place and pushes the rows below it down; the list scrolls to reach them.
   - relative, not static: the menu stays in the flow and also becomes the containing block of the
     absolutely positioned "(opens in a new tab)" text of User Settings. With static, that text escaped the
     closed menu's overflow and added an empty stretch to the bottom of the scrolling list.
   - A closed menu has no padding and is hidden, so it takes no height, no click and no keyboard focus.
   - An open menu has no height limit. A fixed cap (it was 500px) clipped the last entries of a long group,
     such as Report Settings, and a tap where a clipped entry should be landed on the row below it. */
@media (max-width: 991.98px) {
    .sidebar-nav .dropdown-menu {
        position: relative !important;
        display: block !important;
        max-height: 0;
        overflow: hidden;
        padding-top: 0;
        padding-bottom: 0;
        visibility: hidden;
        opacity: 0;
        box-shadow: none !important;
        border: none;
        margin-left: 1rem;
        background-color: var(--oc-sidebar-bg);
        transition: opacity 0.35s ease-out;
    }

    .sidebar-nav .dropdown-menu.open-mobile {
        max-height: none;
        padding-top: .25rem;
        padding-bottom: .25rem;
        visibility: visible;
        opacity: 1;
        transition: opacity 0.4s ease-in;
    }

    .sidebar-nav .nav-link .chevron {
        transition: transform 0.3s ease;
    }

    .sidebar-nav .nav-link .chevron.chevron-open {
        transform: rotate(90deg);
    }
}

/* ─── Mobile (<=768px) ───────────────────────────────────────────────────── */
@media (max-width: 768px) {
    #content {
        margin-left: 0;
        width: 100%;
        margin-top: 60px;
    }

    /* The navbar stays full width on a phone.
       It previously had `margin-left: 280px`, which on a 390px screen pushed the sidebar toggle and
       the logo almost entirely off the right edge whenever the sidebar was open, leaving no visible
       way to close it. `z-index: 601` also lifted it above the 600 sidebar, so it covered the
       sidebar's logo. The sidebar is an overlay here, so it belongs on top. */
    #main-navbar {
        margin-left: 0;
        z-index: 500;
    }

    .sidebar {
        width: 280px;
    }

    .sidebar.hide {
        transform: translateX(-100%);
    }
}
