/* --- 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);
}

/* 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: var(--v-sidebar-rail-width) !important;
    width: 100% !important;
    padding-top: 40px !important;
    padding-right: 0 !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: var(--v-sidebar-width) !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;
    }

    /* Watermark: version/DB detail text is unreadable at 60px and not worth the
       vertical space — hide it and let the logo take a bit more room */
    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .sidebar-watermark {
        padding: 1.5rem 0.25rem 0.75rem 0.25rem;
    }

    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .sidebar-watermark img {
        max-width: 44px;
    }

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

    /* 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) .company-switcher .dropdown-toggle {
        text-align: center;
        padding: 0.25rem 0;
    }

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

    html:not(.early-sidebar-pinned) body:not(.sidebar-pinned) .company-switcher .dropdown-toggle i {
        margin-right: 0 !important;
        font-size: 1rem;
    }
}

/* 
   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;
}

/* Sidebar Branding & Tools Header */
.sidebar-header-tools {
    position: absolute;
    top: 5px;
    right: 5px;
    z-index: 2100;
}

#sidebarPin {
    color: rgba(255, 255, 255, 0.4);
    transition: color 0.2s ease, transform 0.2s ease;
    cursor: pointer;
    font-size: 1.15rem;
    padding: 5px;
    border: none;
    background: transparent;
}

#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 */
.sidebar .sidebar-sticky {
    padding-top: 5px !important;
    overflow-y: auto;
    overflow-x: visible;
    height: calc(100vh - 120px);
    /* Adjust based on branding height */
}

/* ── Mobile Top Bar ────────────────────────────────────────────────────── */
#mobileTopBar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 52px;
    background: var(--color-charcoal);
    border-bottom: 1px solid var(--color-gold);
    display: flex;
    align-items: center;
    padding: 0 12px;
    z-index: 1099;
}

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

.mobile-topbar-wordmark {
    flex: 1;
    text-align: center;
    color: var(--color-gold);
    font-family: 'Merriweather', serif;
    font-size: 0.9rem;
    letter-spacing: 0.5px;
    margin-right: 40px;
}

/* Mobile responsive resets */
@media (max-width: 768px) {
    #sidebarMenu {
        transform: translateX(-100%) !important;
        width: 85% !important;
    }

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

    main {
        margin-left: 0 !important;
        padding-top: 60px !important;
    }

    /* Sticky document header bars — clear the fixed 52px mobile top bar AND the
       mobile sticky portal stacked below it (~63px at rest). PRJ-006: coupled to
       .mobile-sticky-portal's top offset in mobile_interactions.css — if that
       portal's height changes, this value needs to grow/shrink to match. */
    .v-sticky-header-bar-wrapper.sticky-top {
        top: 115px !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;
}
