/* --- Sidebar: Expanded / Rail --- */
/* Part of the Viljoen Legacy Design System */

:root {
    --v-sidebar-width: 280px;
    --v-sidebar-rail-width: 60px;
    --v-sidebar-transition: 0.4s cubic-bezier(0.19, 1, 0.22, 1);
    --v-main-gutter: 1.5rem;
}

/* Rail (60px, icon-only) is the default/base state. Expanded (280px) is an override.
   Both are always-visible — no hover-reveal, no hidden sliver (PRJ-042). */
#sidebarMenu {
    width: var(--v-sidebar-rail-width) !important;
    position: fixed !important;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 2000 !important;
    background-color: var(--color-charcoal) !important;
    box-shadow: none;
    transition: width var(--v-sidebar-transition);
    border-right: 2px solid var(--color-gold);
    overflow: visible !important;
    /* Allow sub-menus to protrude */
}

#sidebarMenu.pinned,
body.sidebar-pinned #sidebarMenu,
html.early-sidebar-pinned #sidebarMenu {
    width: var(--v-sidebar-width) !important;
    border-right-color: rgba(255, 255, 255, 0.1);
}

/* Main Content Adjustment */
main {
    transition: padding-left var(--v-sidebar-transition) !important;
    padding-left: calc(var(--v-sidebar-rail-width) + var(--v-main-gutter)) !important;
    width: 100% !important;
    padding-top: 40px !important;
    padding-right: var(--v-main-gutter) !important;
    display: block !important;
    box-sizing: border-box !important;
    /* NO overflow: hidden here - it kills position: sticky */
}

body.sidebar-pinned main,
html.early-sidebar-pinned main {
    padding-left: calc(var(--v-sidebar-width) + var(--v-main-gutter)) !important;
}

/* Rail-mode nav rendering (desktop only — mobile keeps its own drawer, unaffected).
   Rail is the default; :not(.sidebar-pinned) keeps expanded mode from needing a
   separate "undo" block — each property has one rule, not an apply/override pair.

   IMPORTANT: these rules must target only TOP-LEVEL sidebar items, not items
   inside a .v-submenu flyout. `.sidebar .nav-link` alone also matches
   `.sidebar .v-submenu .nav-link` (submenu children live under .sidebar in the
   DOM), which broke flyouts in rail mode — most submenu children have no icon,
   so hiding their label left the flyout rendering empty/blank rows. Flyouts
   should always render as normal full-width text lists regardless of the
   parent rail's collapsed state, so every selector below is scoped to
   `.sidebar-sticky > ul > li.nav-item` (direct top-level items only). */
@media (min-width: 769px) {

    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .sidebar-sticky>ul>li.nav-item>.sidebar-heading span,
    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .sidebar-sticky>ul>li.nav-header,
    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .sidebar-sticky>ul>li.nav-item>.nav-link>span,
    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .sidebar-sticky>ul>li.nav-item>.nav-link .active-child-label {
        display: none !important;
    }

    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .sidebar-sticky>ul>li.nav-item>.nav-link,
    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .sidebar-sticky>ul>li.nav-item>form>.nav-link,
    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .sidebar-sticky>ul>li.nav-item>button.nav-link {
        text-align: center;
        padding: 0.75rem 0 !important;
    }

    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .sidebar-sticky>ul>li.nav-item>.nav-link>i,
    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .sidebar-sticky>ul>li.nav-item>form>.nav-link>i,
    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .sidebar-sticky>ul>li.nav-item>button.nav-link>i {
        margin-right: 0 !important;
        font-size: 1.15rem;
    }

    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .sidebar-sticky>ul>li.nav-item>.v-has-submenu {
        padding-right: 0 !important;
    }

    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .sidebar-sticky>ul>li.nav-item>.v-has-submenu::after {
        display: none;
    }

    /* Company block (PRJ-136): the name cannot fit in 60px, so rail shows the company
       Baobab roundel instead (the company icon, Style Guide §3); the letterhead and the
       hover title carry the name. */
    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .sidebar-company {
        padding: 1rem 0 0.5rem;
        flex-direction: column;
        gap: 0.35rem;
    }

    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .sidebar-company #sidebarPin {
        margin-left: 0;
    }

    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .sidebar-company-toggle {
        justify-content: center;
        padding: 0;
    }

    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .sidebar-company-seal {
        display: block;
    }

    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .sidebar-company .v-rail-hide {
        display: none !important;
    }

    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .sidebar-company-neutral {
        justify-content: center;
    }

    /* Rail: open beside the roundel, like the nav flyouts, not over it */
    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .sidebar-company .dropdown-menu[data-bs-popper] {
        top: 0;
        left: calc(100% + 10px);
    }

    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .sidebar-brand-line {
        justify-content: center;
    }

    /* Footer: username and company name are unreadable at 60px — collapse to
       icon-only. Logout/dropdown affordances remain reachable via their icons. */
    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .sidebar-footer {
        padding: 1rem 0.25rem;
    }

    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .user-profile {
        justify-content: center !important;
        gap: 0;
    }

    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .user-profile .v-rail-hide,
    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .user-profile a {
        display: none !important;
    }

    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .sidebar-footer .v-rail-hide {
        display: none !important;
    }
}

/* 
   Centering & Margins (Standard Option A)
   Works for different monitor sizes and zoom levels.
*/
.v-transaction-layout {
    margin: 0 auto !important;
    max-width: 1600px !important;
    /* Premium readable width */
    width: 100% !important;
    padding-left: 2.5rem !important;
    padding-right: 2.5rem !important;
    box-sizing: border-box !important;
    transition: max-width 0.3s ease;
}

@media (max-width: 1400px) {
    .v-transaction-layout {
        max-width: 100% !important;
        padding-left: 1.5rem !important;
        padding-right: 1.5rem !important;
    }
}

.v-crm-container,
.v-crm-sticky-top {
    margin: 0 auto !important;
}

.ledger-container {
    width: 100% !important;
    max-width: none !important;
    background: transparent !important;
}

/* ── Company block (PRJ-136) ──────────────────────────────────────────────
   Top of the sidebar: which company you are in. The whole block is the
   switcher toggle. Expanded shows name + legal suffix with the chevron right after
   the name, leaving the top-right corner for the Expanded/Rail pin; rail shows the
   Baobab roundel with the pin under it. */
.sidebar-company > .dropdown {
    flex: 1 1 auto;
    min-width: 0;
}

.sidebar-company {
    position: relative;
    z-index: 3;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1.25rem 0.75rem 1rem 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex: 0 0 auto;
}

.sidebar-company-toggle {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.25rem 0.25rem 0.25rem 0;
    border: none;
    background: transparent;
    color: #fff;
    text-align: left;
    cursor: pointer;
    border-radius: 6px;
}

.sidebar-company-toggle:focus-visible {
    outline: 2px solid var(--color-gold);
    outline-offset: 2px;
}

.sidebar-company-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 0 1 auto;
}

.sidebar-company-name {
    font-family: var(--font-header);
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1.25;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-company-suffix {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.55);
    margin-top: 0.1rem;
}

.sidebar-company-chevron {
    flex: 0 0 auto;
    align-self: flex-start;
    margin: 0.35rem 0 0 -0.35rem;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.55);
    transition: color 0.2s ease, transform 0.2s ease;
}

.sidebar-company-toggle:hover .sidebar-company-chevron,
.sidebar-company-toggle:hover .sidebar-company-name {
    color: var(--color-gold);
}

.sidebar-company-toggle[aria-expanded="true"] .sidebar-company-chevron {
    transform: rotate(180deg);
}

/* Rail only (shown by the rail block above) */
.sidebar-company-seal {
    display: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    transition: box-shadow 0.2s ease;
}

.sidebar-company-toggle:hover .sidebar-company-seal {
    box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.45);
}

.sidebar-company-neutral {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: rgba(255, 255, 255, 0.75);
    font-family: var(--font-header);
}

/* Both company menus use data-bs-display="static": main.css forces
   `transform: translateY(0) !important` on every open .dropdown-menu, which
   cancels Popper's offset and drops the menu on top of its own toggle. Static
   display positions with top/left instead, which that rule leaves alone. */
.sidebar-company .dropdown-menu {
    max-height: 70vh;
    overflow-y: auto;
    z-index: 2300;
}

.sidebar-company .dropdown-menu[data-bs-popper] {
    top: calc(100% + 6px);
    left: 0;
    margin-top: 0;
}

/* The current company: palette, not Bootstrap blue */
.sidebar-company .dropdown-item.active,
.sidebar-company .dropdown-item:active {
    background: rgba(212, 175, 55, 0.16);
    color: var(--color-gold);
    font-weight: 600;
}

.v-letterhead .dropdown-item.active,
.v-letterhead .dropdown-item:active {
    background: rgba(212, 175, 55, 0.14);
    color: var(--color-charcoal);
    font-weight: 600;
}

.v-letterhead .dropdown-item {
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ── Footer brand line (PRJ-136): Baobab signs off at the bottom ───────── */
.sidebar-brand-line {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-top: 0.6rem;
    margin-top: 0.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    color: #a1a1a1;
    font-size: 0.7rem;
}

.sidebar-brand-mark {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    opacity: 0.85;
}

.sidebar-brand-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1 1 auto;
    line-height: 1.35;
}

.sidebar-brand-update {
    color: inherit;
    opacity: 0.6;
    text-decoration: none;
    margin-left: 0.15rem;
}

.sidebar-brand-db {
    font-family: 'Roboto Mono', monospace;
    font-size: 0.62rem;
    opacity: 0.8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-brand-db i {
    font-size: 0.6rem;
}

#sidebarPin {
    color: rgba(255, 255, 255, 0.4);
    transition: color 0.2s ease, transform 0.2s ease;
    cursor: pointer;
    font-size: 1.05rem;
    padding: 5px;
    border: none;
    background: transparent;
    margin-left: auto;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
}

#sidebarPin:hover {
    color: var(--color-gold);
}

#sidebarPin i.bi-pin-angle-fill {
    color: var(--color-gold);
    transform: rotate(-45deg);
    /* Professional pinned indicator */
}

/* Rail mode indicator — matches the gold "active" treatment given to the
   pinned icon above, so the toggle always shows an active affordance */
#sidebarPin i.bi-distribute-vertical {
    color: var(--color-gold);
}

/* Hierarchy adjustments to ensure no content loss. Height comes from the
   sidebar's flex column (main.css .sidebar-sticky: flex 1 1 auto, min-height 0),
   so the nav fills whatever the company block and footer leave (PRJ-136). */
.sidebar .sidebar-sticky {
    padding-top: 5px !important;
    overflow-y: auto;
    overflow-x: visible;
}

/* ── Mobile Top Bar ────────────────────────────────────────────────────── */
#mobileTopBar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 70px;
    background: var(--color-charcoal);
    border-bottom: 1px solid var(--color-gold);
    display: flex;
    align-items: center;
    padding: 0 12px;
    /* Above #sidebarMenu (2000) so the hamburger/close toggle stays in the same
       visible slot while the drawer is open, instead of being covered by it. */
    z-index: 2200;
}

#mobileHamburger {
    background: transparent;
    border: none;
    color: white;
    padding: 8px;
    line-height: 1;
    cursor: pointer;
}

.mobile-topbar-wordmark {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--color-gold);
    font-family: var(--font-header);
    font-weight: 700;
    font-size: 1.5rem;
    letter-spacing: 0.5px;
    margin-right: 40px;
}

.mobile-topbar-logo {
    height: 65px;
    width: auto;
}

/* Mobile top bar carries the company (PRJ-136); the Baobab wordmark is only
   shown when no company is active (signed out, company picker). */
.mobile-topbar-company {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-right: 40px;
    color: #fff;
    font-family: var(--font-header);
    font-weight: 700;
    font-size: 1.15rem;
}

.mobile-topbar-company .company-icon {
    width: 28px;
    height: 28px;
    flex: 0 0 auto;
}

.mobile-topbar-company-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Letterhead line (PRJ-136) ─────────────────────────────────────────────
   Desktop only. Not sticky: it sits in main's top band (body.has-letterhead
   trims main's 40px padding to make room), so no page shifts down. Its own
   stacking context keeps the Switch company menu above list sticky headers
   (.v-crm-sticky-top is z 1020). */
.v-letterhead {
    display: none;
}

@media (min-width: 769px) {
    body.has-letterhead main {
        padding-top: 10px !important;
    }

    .v-letterhead {
        display: flex;
        align-items: center;
        gap: 1rem;
        position: relative;
        z-index: 1030;
        height: 30px;
        max-width: 1600px;
        margin: 0 auto;
        padding: 0 0.25rem;
    }

    .v-letterhead-name {
        flex: 0 1 auto;
        min-width: 0;
        font-size: 0.72rem;
        font-weight: 600;
        letter-spacing: 0.18em;
        text-transform: uppercase;
        color: var(--color-charcoal);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .v-letterhead-rule {
        flex: 1 1 auto;
        min-width: 2rem;
        height: 1px;
        background: rgba(44, 53, 57, 0.18);
    }

    .v-letterhead-switch {
        border: none;
        background: transparent;
        padding: 0.25rem 0;
        font-size: 0.78rem;
        color: var(--color-charcoal);
        text-decoration: underline;
        text-decoration-color: rgba(44, 53, 57, 0.35);
        text-underline-offset: 3px;
        white-space: nowrap;
        cursor: pointer;
    }

    .v-letterhead-switch:hover,
    .v-letterhead-switch[aria-expanded="true"] {
        color: var(--color-gold-hover, #c29d2b);
        text-decoration-color: currentColor;
    }

    .v-letterhead .dropdown-menu {
        min-width: 260px;
    }

    .v-letterhead .dropdown-menu[data-bs-popper] {
        top: calc(100% + 4px);
        right: 0;
        left: auto;
        margin-top: 0;
    }
}

/* Mobile responsive resets */
@media (max-width: 768px) {
    #sidebarMenu {
        transform: translateX(-100%) !important;
        width: 85% !important;
        /* Clears the fixed #mobileTopBar (now above the drawer, z-index 2200)
           so the close (X) toggle isn't hidden behind the drawer's own header. */
        padding-top: 70px !important;
    }

    #sidebarMenu.show {
        transform: translateX(0) !important;
    }

    /* The pin is hidden here (d-none d-md-inline-flex in base.html) -- rail/expanded
       modes are desktop-only. The drawer's company block keeps its expanded look. */
    .sidebar-company {
        padding-top: 0.75rem;
    }

    /* Reset main horizontal padding symmetrically on mobile */
    main,
    body.sidebar-pinned main,
    html.early-sidebar-pinned main {
        margin-left: 0 !important;
        padding-top: 78px !important;
        /* Clears fixed 70px #mobileTopBar */
        padding-left: 1rem !important;
        /* Balanced left gutter */
        padding-right: 1rem !important;
        /* Balanced right gutter */
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .v-sticky-header-bar-wrapper.sticky-top {
        top: 133px !important;
    }
}

/* --- GEOMETRY-STABLE STICKY HEADER (PRJ-011) --- */
.v-sticky-header-bar-wrapper {
    background: var(--bg-main);
}

.v-sticky-header-bar {
    border-radius: 12px 12px 0 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateZ(0);
    /* Hardware acceleration */
    will-change: padding, border-radius, box-shadow;
}

/* Compact State (Visual Only, No Layout Shift) */
.v-sticky-header-bar.is-compact {
    padding-top: 0.5rem !important;
    padding-bottom: 0.5rem !important;
    border-radius: 0 !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1) !important;
    border-color: rgba(0, 0, 0, 0.05) !important;
}

/* Sticky behavior is handled by bootstrap .sticky-top + wrapper */
.v-sticky-header-bar-wrapper.sticky-top {
    transition: background-color 0.3s ease;
}

.v-header-body-flow {
    transition: opacity 0.3s ease;
}

/* Ensure no layout jumps from browser scroll anchoring */
.v-transaction-layout {
    overflow-anchor: none;
}
/* ===== Sidebar footer menu: "your account" =====
   A full-width, 44px-tall tap target that opens upward. The company menu moved to the top of the
   sidebar (PRJ-136, .sidebar-company) and shares the dropdown styling below. */
.sidebar-footer .user-menu-toggle {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    min-height: 44px;
    padding: 0.5rem 0.75rem;
    border: 0;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--color-off-white);
    font-size: 0.9rem;
    text-align: left;
    text-decoration: none;
}

.sidebar-footer .user-menu-toggle:hover {
    background: rgba(255, 255, 255, 0.12);
    color: var(--color-gold) !important;
}

.sidebar-footer .user-menu-toggle > i:first-child {
    font-size: 1.25rem;
    color: var(--color-gold);
}

.sidebar-footer .user-menu-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-footer .dropdown-menu,
.sidebar-company .dropdown-menu {
    min-width: 15rem;
    max-width: calc(100vw - 2rem);
    padding: 0.4rem;
    border-radius: 10px;
    font-size: 0.9rem;
}

.sidebar-footer .dropdown-item,
.sidebar-company .dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    min-height: 44px;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    white-space: normal;
}

.sidebar-footer .dropdown-item i,
.sidebar-company .dropdown-item i {
    width: 1.1rem;
    text-align: center;
    opacity: 0.85;
}

.sidebar-footer .dropdown-header,
.sidebar-company .dropdown-header {
    padding: 0.5rem 0.75rem 0.25rem;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.sidebar-footer .menu-who {
    padding: 0.4rem 0.75rem 0.5rem;
}

.sidebar-footer .menu-who-email {
    color: rgba(255, 255, 255, 0.6);
}

.sidebar-footer .menu-logout {
    color: #e8a09f;
}

.sidebar-footer .menu-logout:hover {
    color: #fff;
    background: var(--color-crimson, #A62C2B);
}

/* Collapsed rail: icon only, centred; the menu still opens from the icon. */
html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .sidebar-footer .user-menu-toggle {
    justify-content: center;
    padding: 0.5rem 0;
}

/* PRJ-120: count pill on a menu entry that carries a `badge` (the Takealot Needs-you count). Pinned/expanded: at the end of
   the row. Collapsed rail: the label is hidden, so the pill moves onto the icon's corner and stays visible. */
.sidebar .nav-link { position: relative; }
.sidebar .nav-link .v-nav-badge {
    margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
    background: var(--color-crimson); color: #fff; font-size: .7rem; font-weight: 700; line-height: 20px;
    display: inline-block; text-align: center;
}
@media (min-width: 769px) {
    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .sidebar-sticky>ul>li.nav-item>.nav-link>span.v-nav-badge {
        display: inline-block !important; position: absolute; top: 4px; right: 8px;
        min-width: 16px; height: 16px; padding: 0 4px; font-size: .6rem; line-height: 16px; border-radius: 8px;
    }
}
