/* =====================================================================
   AESTHETIC INTEL — SIDEBAR REFINEMENT V6
   Loaded AFTER sidebar-persistent-v5.css.

   Fixes:
   1. Toggle no longer overlaps the first/home navigation icon.
   2. WORKSPACE / PLATFORM / HELP use exactly the same typography.
   3. Expanded sidebar is intentionally narrower and more space-efficient.
   4. Navigation text, section labels, chevrons and brand copy share one
      consistent horizontal rhythm.
   5. Desktop only. Existing mobile drawer behavior remains untouched.
   ===================================================================== */

:root {
    /* 76px permanent icon rail + 228px information panel */
    --ai6-sidebar-rail: 76px;
    --ai6-sidebar-expanded: 304px;
    --ai6-panel-width: 228px;

    --ai6-text-x: 18px;
    --ai6-chevron-col: 28px;

    --ai6-panel-bg: #eef3f6;
    --ai6-panel-hover: #e7eef2;
    --ai6-panel-active: #e1ebf0;
    --ai6-line: #d5e0e5;
    --ai6-text: #34444e;
    --ai6-muted: #8c989f;
    --ai6-rail: #151a1f;
    --ai6-rail-hover: #1e272d;
    --ai6-rail-active: #273943;
    --ai6-accent: #8fb8c9;
    --ai6-ease: 240ms cubic-bezier(.22, 1, .36, 1);
}

@media (min-width: 1041px) {

    /* -------------------------------------------------------------
       REAL DESKTOP LAYOUT WIDTH
       ------------------------------------------------------------- */

    body.app-body .app-shell,
    body.app-body:not(.sidebar-expanded) .app-shell {
        grid-template-columns:
            var(--ai6-sidebar-rail) minmax(0, 1fr) !important;
        transition:
            grid-template-columns var(--ai6-ease) !important;
    }

    body.app-body.sidebar-expanded .app-shell {
        grid-template-columns:
            var(--ai6-sidebar-expanded) minmax(0, 1fr) !important;
    }

    body.app-body #sidebar.sidebar,
    body.app-body.sidebar-expanded #sidebar.sidebar,
    body.app-body:not(.sidebar-expanded) #sidebar.sidebar {
        width: 100% !important;
        min-width: 0 !important;
        max-width: none !important;
        overflow: hidden !important;
        border-right: 1px solid rgba(26, 43, 53, .12) !important;
    }

    body.app-body.sidebar-expanded #sidebar.sidebar {
        background:
            linear-gradient(90deg,
                var(--ai6-rail) 0,
                var(--ai6-rail) var(--ai6-sidebar-rail),
                var(--ai6-panel-bg) var(--ai6-sidebar-rail),
                var(--ai6-panel-bg) 100%) !important;
    }

    /* -------------------------------------------------------------
       BRAND — compact but comfortably readable
       ------------------------------------------------------------- */

    body.sidebar-expanded #sidebar .sidebar-brand,
    body.sidebar-expanded #sidebar .brand {
        min-height: 74px !important;
        flex-basis: 74px !important;
        grid-template-columns:
            var(--ai6-sidebar-rail) minmax(0, 1fr) !important;
    }

    body.sidebar-expanded #sidebar .brand-copy {
        box-sizing: border-box !important;
        min-width: 0 !important;
        padding:
            0 16px 0 var(--ai6-text-x) !important;
    }

    body.sidebar-expanded #sidebar .brand-copy strong {
        font-size: 15px !important;
        line-height: 1.12 !important;
        font-weight: 760 !important;
        letter-spacing: -.025em !important;
    }

    body.sidebar-expanded #sidebar .brand-copy small {
        margin-top: 3px !important;
        font-size: 9.5px !important;
        line-height: 1.2 !important;
        font-weight: 580 !important;
    }

    /* -------------------------------------------------------------
       COLLAPSE / EXPAND CONTROL

       The previous control occupied the rail directly above the first
       navigation row and visually collided with the Home/Dashboard icon.

       It is now anchored to the top-right of the expanded information
       panel, outside the icon column. In collapsed state it moves to the
       center of the rail, still above the first navigation item.
       ------------------------------------------------------------- */

    body.app-body #sidebar .sidebar-desktop-toggle,
    body.app-body.sidebar-expanded #sidebar .sidebar-desktop-toggle,
    body.app-body:not(.sidebar-expanded) #sidebar .sidebar-desktop-toggle {
        position: absolute !important;
        z-index: 12 !important;
        top: 80px !important;
        left: auto !important;
        bottom: auto !important;
        margin: 0 !important;

        width: 30px !important;
        height: 30px !important;
        min-width: 30px !important;
        min-height: 30px !important;

        border-radius: 9px !important;
        box-shadow: none !important;
        transition:
            background-color 150ms ease,
            border-color 150ms ease,
            color 150ms ease !important;
    }

    body.app-body.sidebar-expanded #sidebar .sidebar-desktop-toggle {
        right: 12px !important;
        color: #71818a !important;
        background: rgba(255, 255, 255, .58) !important;
        border: 1px solid #cedae0 !important;
    }

    body.app-body.sidebar-expanded #sidebar .sidebar-desktop-toggle:hover,
    body.app-body.sidebar-expanded #sidebar .sidebar-desktop-toggle:focus-visible {
        color: #263841 !important;
        background: #ffffff !important;
        border-color: #bacbd3 !important;
    }

    body.app-body:not(.sidebar-expanded) #sidebar .sidebar-desktop-toggle {
        right: 23px !important;
        color: #adbbc2 !important;
        background: rgba(255, 255, 255, .02) !important;
        border: 1px solid rgba(255, 255, 255, .13) !important;
    }

    body.app-body:not(.sidebar-expanded) #sidebar .sidebar-desktop-toggle:hover,
    body.app-body:not(.sidebar-expanded) #sidebar .sidebar-desktop-toggle:focus-visible {
        color: #ffffff !important;
        background: var(--ai6-rail-hover) !important;
        border-color: rgba(255, 255, 255, .24) !important;
    }

    body.app-body #sidebar .sidebar-desktop-toggle .nav-icon {
        width: 13px !important;
        height: 13px !important;
        min-width: 13px !important;
    }

    /* -------------------------------------------------------------
       NAVIGATION RHYTHM
       ------------------------------------------------------------- */

    body.app-body #sidebar .nav-list,
    body.app-body.sidebar-expanded #sidebar .nav-list,
    body.app-body:not(.sidebar-expanded) #sidebar .nav-list {
        margin-top: 0 !important;
        padding-top: 36px !important;
        /* reserves space for the toggle */
        padding-bottom: 10px !important;
    }

    /*
     * EVERY section label shares exactly the same typography.
     * No special-case visual treatment for Workspace / Platform / Help.
     */
    body.sidebar-expanded #sidebar .nav-section-label {
        box-sizing: border-box !important;
        display: block !important;

        width: 100% !important;
        max-width: none !important;
        height: 22px !important;
        max-height: 22px !important;

        margin: 10px 0 4px !important;
        padding:
            0 12px 0 calc(var(--ai6-sidebar-rail) + var(--ai6-text-x)) !important;

        color: var(--ai6-muted) !important;

        font-family:
            inherit !important;
        font-size: 9px !important;
        font-style: normal !important;
        font-weight: 800 !important;
        line-height: 22px !important;
        letter-spacing: .14em !important;
        text-transform: uppercase !important;
        text-align: left !important;

        white-space: nowrap !important;
        opacity: 1 !important;
        visibility: visible !important;
        transform: none !important;
    }

    /*
     * First section label should not receive extra top air.
     * It sits directly under the dedicated toggle zone.
     */
    body.sidebar-expanded #sidebar .nav-list>.nav-section-label:first-child {
        margin-top: 0 !important;
    }

    body.sidebar-expanded #sidebar .nav-link,
    body.sidebar-expanded #sidebar .nav-group-title {
        box-sizing: border-box !important;
        width: 100% !important;
        min-width: 0 !important;
        height: 44px !important;
        min-height: 44px !important;
        margin: 0 !important;

        grid-template-columns:
            var(--ai6-sidebar-rail) minmax(0, 1fr) var(--ai6-chevron-col) !important;

        color: var(--ai6-text) !important;

        font-family: inherit !important;
        font-size: 13px !important;
        font-weight: 650 !important;
        line-height: 1.16 !important;
    }

    /*
     * Text begins exactly 18px into the information panel.
     * This removes the excessive visual gap between the rail and labels.
     */
    body.sidebar-expanded #sidebar .nav-text {
        min-width: 0 !important;
        max-width: none !important;
        margin: 0 !important;
        padding:
            0 6px 0 var(--ai6-text-x) !important;

        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;

        color: var(--ai6-text) !important;
    }

    body.sidebar-expanded #sidebar .nav-group-title>.nav-icon:last-child {
        justify-self: center !important;
        width: 13px !important;
        height: 13px !important;
        margin: 0 !important;
        color: #829097 !important;
    }

    /* icon rail alignment remains mathematically centered */
    body.app-body #sidebar .nav-link::before,
    body.app-body #sidebar .nav-group-title::before {
        left: calc((var(--ai6-sidebar-rail) - 38px) / 2) !important;
        width: 38px !important;
        height: 36px !important;
        border-radius: 9px !important;
    }

    body.app-body #sidebar .nav-link::after,
    body.app-body #sidebar .nav-group-title::after {
        left: 0 !important;
        width: 3px !important;
        height: 22px !important;
        background: var(--ai6-accent) !important;
    }

    body.sidebar-expanded #sidebar .nav-link:hover,
    body.sidebar-expanded #sidebar .nav-group-title:hover {
        background:
            linear-gradient(90deg,
                transparent 0,
                transparent var(--ai6-sidebar-rail),
                var(--ai6-panel-hover) var(--ai6-sidebar-rail),
                var(--ai6-panel-hover) 100%) !important;
    }

    body.sidebar-expanded #sidebar .nav-link.active,
    body.sidebar-expanded #sidebar .nav-group.open>.nav-group-title {
        background:
            linear-gradient(90deg,
                transparent 0,
                transparent var(--ai6-sidebar-rail),
                var(--ai6-panel-active) var(--ai6-sidebar-rail),
                var(--ai6-panel-active) 100%) !important;
    }

    /* -------------------------------------------------------------
       SUBMENUS — align under the same text column
       ------------------------------------------------------------- */

    body.sidebar-expanded #sidebar .nav-group.open>.nav-submenu {
        margin:
            2px 10px 7px calc(var(--ai6-sidebar-rail) + var(--ai6-text-x)) !important;
        padding:
            2px 0 2px 11px !important;
        border-left: 1px solid #c9d6dc !important;
    }

    body.sidebar-expanded #sidebar .nav-sublink {
        min-height: 32px !important;
        padding: 5px 8px !important;
        font-size: 11.5px !important;
        line-height: 1.25 !important;
    }

    /* -------------------------------------------------------------
       USER FOOTER — compact to match narrower sidebar
       ------------------------------------------------------------- */

    body.sidebar-expanded #sidebar .sidebar-user {
        min-height: 82px !important;
        grid-template-columns:
            var(--ai6-sidebar-rail) minmax(0, 1fr) 40px !important;
        border-top: 1px solid var(--ai6-line) !important;
    }

    body.sidebar-expanded #sidebar .sidebar-user-copy {
        min-width: 0 !important;
        max-width: none !important;
        padding:
            0 6px 0 var(--ai6-text-x) !important;
    }

    body.sidebar-expanded #sidebar .sidebar-user-copy strong {
        font-size: 12px !important;
        line-height: 1.2 !important;
    }

    body.sidebar-expanded #sidebar .sidebar-user-copy small {
        font-size: 9px !important;
        line-height: 1.25 !important;
    }

    body.sidebar-expanded #sidebar .sidebar-logout {
        width: 32px !important;
        height: 32px !important;
        min-width: 32px !important;
        min-height: 32px !important;
        margin-right: 6px !important;
    }
}