/* =================================================================
   WF Portal — Side Navigation (Global)
   -----------------------------------------------------------------
   The collapsible left-rail layout. Additive + parallel to nav.css
   (the top nav): selecting which shell renders is a per-tenant choice
   (AuthState.NavLayout) made in MainLayout. Both shells reuse the same
   --theme-nav-* tokens so the rail tracks the tenant brand exactly like
   the top bar does. Styles are global (not scoped) because Blazor
   NavLink renders <a> tags outside the component CSS-isolation scope.
   ================================================================= */

/* ── Shell flex modes ─────────────────────────────────────────────
   .wf-shell is the single flex child of #app (the Blazor wrapper is
   display:contents, so .wf-shell inherits #app's flex column).

   !important on display: the framework hack `#app > div:first-child {
   display: contents }` in root.css lands on .wf-shell when Blazor renders
   the layout root directly under #app (specificity 1,1,1 beats .wf-shell).
   That dissolved the shell and dumped the rail + main into #app's flex
   COLUMN — the rail stacked ABOVE the content. Forcing display keeps the
   shell a real flex box in every render path (side row / top column). */
.wf-shell {
    display: flex !important;
    flex: 1;
    min-height: 0;
}
.wf-shell--top  { flex-direction: column; }
.wf-shell--side { flex-direction: row; }

/* ── The rail ─────────────────────────────────────────────────────── */

.wf-sidebar {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    width: 232px;
    /* Definite height (not just align-stretch). Flex-stretch can be treated as
       indefinite for the nested body{flex:1} resolution, which let the column
       run ~one row past the fold on desktop and clipped the last footer item
       (the account/tenant switcher) below the viewport — while the mobile
       drawer, which has a definite height via top/bottom, showed it. height:100%
       of the definite-height shell pins the footer inside the viewport. */
    height: 100%;
    min-height: 0;
    background: var(--theme-nav-background);
    border-right: 1px solid var(--theme-nav-border);
    transition: width 160ms ease;
}

/* Head — brand + collapse toggle */
.wf-sidebar-head {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    height: 3.5rem;
    padding: 0 0.65rem 0 0.85rem;
    border-bottom: 1px solid var(--theme-nav-border);
    flex-shrink: 0;
}
.wf-sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    flex: 1;
    min-width: 0;
    color: var(--theme-nav-text-hover);
    text-decoration: none !important;
    font-weight: 700;
    font-size: 1.02rem;
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
}
.wf-sidebar-brand:hover { opacity: 0.85; color: var(--theme-nav-text-hover); }
.wf-sidebar-brandmark {
    font-size: 1.3rem;
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--theme-primary), var(--theme-offset));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.wf-sidebar-brandname { overflow: hidden; text-overflow: ellipsis; }
.wf-sidebar-logo { height: 26px; width: auto; object-fit: contain; flex-shrink: 0; }

.wf-sidebar-collapse {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.9rem;
    height: 1.9rem;
    flex-shrink: 0;
    border: none;
    background: transparent;
    color: var(--theme-nav-text);
    border-radius: var(--theme-radius-button);
    cursor: pointer;
    font-size: 0.85rem;
    transition: color 150ms ease, background-color 150ms ease;
}
.wf-sidebar-collapse:hover {
    color: var(--theme-nav-text-hover);
    background: var(--theme-nav-hover-background);
}

/* Body — scrollable nav list */
.wf-sidebar-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.6rem;
}
.wf-sidebar-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}
.wf-sidebar-item { position: relative; }

/* Links + group toggles share .wf-sidebar-link */
.wf-sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    width: 100%;
    padding: 0.5rem 0.7rem;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--theme-nav-text);
    text-decoration: none !important;
    border: none;
    background: transparent;
    border-radius: var(--theme-radius-button);
    cursor: pointer;
    white-space: nowrap;
    text-align: left;
    transition: color 140ms ease, background-color 140ms ease;
}
.wf-sidebar-link:hover {
    color: var(--theme-nav-text-hover);
    background: var(--theme-nav-hover-background);
    text-decoration: none !important;
}
.wf-sidebar-link.active {
    color: var(--theme-nav-text-active) !important;
    background: var(--theme-nav-hover-background) !important;
    box-shadow: inset 2px 0 0 var(--theme-nav-text-active);
}
.wf-sidebar-link > i:first-child {
    font-size: 1rem;
    width: 1.25rem;
    text-align: center;
    flex-shrink: 0;
    opacity: 0.8;
}
.wf-sidebar-link:hover > i:first-child,
.wf-sidebar-link.active > i:first-child { opacity: 1; }
.wf-sidebar-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Caret on group toggles */
.wf-sidebar-caret {
    flex: 0 0 auto;
    width: auto !important;
    font-size: 0.6rem !important;
    opacity: 0.45 !important;
    transition: transform 200ms ease;
}
.wf-sidebar-group.is-open > .wf-sidebar-grouptoggle .wf-sidebar-caret,
.wf-sidebar-footitem.is-open > .wf-sidebar-foottoggle .wf-sidebar-caret {
    transform: rotate(180deg);
    opacity: 0.8 !important;
}

/* Sub-list — inline accordion (no flyouts), with a guide line */
.wf-sidebar-sub {
    list-style: none;
    margin: 0.12rem 0 0.3rem 1.45rem;
    padding: 0.05rem 0 0.05rem 0.4rem;
    border-left: 1px solid var(--theme-nav-divider);
    display: none;
}
.wf-sidebar-group.is-open > .wf-sidebar-sub {
    display: block;
    animation: wf-sidebar-sub-in 140ms ease-out;
}
@keyframes wf-sidebar-sub-in {
    from { opacity: 0; transform: translateY(-3px); }
    to   { opacity: 1; transform: translateY(0); }
}
.wf-sidebar-sublink {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
    color: var(--theme-nav-text);
    text-decoration: none !important;
    border-radius: var(--theme-radius-button);
    white-space: nowrap;
    transition: color 140ms ease, background-color 140ms ease;
}
.wf-sidebar-sublink:hover {
    color: var(--theme-nav-text-hover);
    background: var(--theme-nav-hover-background);
    text-decoration: none !important;
}
.wf-sidebar-sublink.active {
    color: var(--theme-nav-text-active) !important;
    background: var(--theme-nav-hover-background) !important;
    font-weight: 600;
}
.wf-sidebar-sublink > i:first-child {
    font-size: 0.9rem;
    width: 1.1rem;
    text-align: center;
    flex-shrink: 0;
    opacity: 0.7;
}
.wf-sidebar-sublink:hover > i:first-child,
.wf-sidebar-sublink.active > i:first-child { opacity: 1; }

/* Section label (pinned-item Header type 6) */
.wf-sidebar-sectionlabel {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 0.7rem 0.25rem;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--theme-nav-text);
    opacity: 0.6;
}
.wf-sidebar-sectionlabel > i:first-child { font-size: 0.8rem; }

/* ── Footer: account + language (popovers open upward) ────────────── */
.wf-sidebar-foot {
    border-top: 1px solid var(--theme-nav-border);
    /* A touch more bottom padding so the last item isn't jammed at the edge. */
    padding: 0.5rem 0.5rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    flex-shrink: 0;
}
.wf-sidebar-footitem { position: relative; }
.wf-sidebar-account .wf-avatar { margin: -0.05rem 0; }

/* -- The profile strip - self-service profile + session control --
   A compact elevated bar between the language bar and the tenant
   switcher: profile opens the OTP-confirmed profile dialog; the trailing
   icon is the session control (logout when signed in, login when not). */
.wf-profile-strip {
    display: flex;
    align-items: stretch;
    gap: 0.2rem;
    padding: 0.15rem;
    border: 1px solid var(--theme-nav-divider);
    border-radius: var(--theme-radius-button);
    background: color-mix(in srgb, var(--theme-nav-hover-background) 55%, transparent);
}
.wf-profile-strip-main { min-width: 0; }
.wf-profile-strip-logout {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 2rem;
    border: none;
    background: transparent;
    color: var(--theme-nav-text);
    border-radius: var(--theme-radius-button);
    cursor: pointer;
    font-size: 0.95rem;
    transition: color 140ms ease, background-color 140ms ease;
}
.wf-profile-strip-logout:hover {
    color: var(--theme-danger);
    background: var(--theme-nav-hover-background);
}
/* Collapsed rail: icon-only strip — hide the trailing session button (logout
   stays in the account popover); the profile icon still opens the dialog. */
.wf-sidebar.is-collapsed .wf-profile-strip-logout { display: none; }

.wf-sidebar-popover {
    display: none;
    position: absolute;
    bottom: calc(100% + 0.35rem);
    left: 0;
    right: 0;
    min-width: 12rem;
    list-style: none;
    margin: 0;
    padding: 0.375rem;
    background: var(--theme-nav-dropdown-background);
    border: 1px solid var(--theme-nav-border);
    border-radius: var(--theme-radius);
    box-shadow:
        0 4px 6px rgba(0, 0, 0, .2),
        0 12px 28px rgba(0, 0, 0, .35);
    max-height: 60vh;
    overflow-y: auto;
    z-index: 1041;
    animation: wf-sidebar-pop-in 120ms ease-out;
}
@keyframes wf-sidebar-pop-in {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}
.wf-sidebar-footitem.is-open .wf-sidebar-popover { display: block; }

.wf-sidebar-popitem {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
    font-weight: 450;
    color: var(--theme-nav-text-hover);
    text-decoration: none !important;
    border: none;
    background: none;
    border-radius: var(--theme-radius-button);
    cursor: pointer;
    text-align: left;
    transition: background-color 120ms ease;
}
.wf-sidebar-popitem:hover { background: var(--theme-nav-dropdown-hover); }
.wf-sidebar-popitem.active { background: var(--theme-primary-muted); color: var(--theme-primary); }
.wf-sidebar-popitem > i:first-child { font-size: 0.9rem; width: 1.25rem; text-align: center; opacity: 0.6; }
.wf-sidebar-pophdr {
    padding: 0.4rem 0.75rem 0.25rem;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--theme-nav-text);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.wf-sidebar-popdivider {
    margin: 0.3rem 0.5rem;
    border: none;
    height: 1px;
    background: var(--theme-nav-divider);
}
.wf-sidebar-logout { color: var(--theme-danger) !important; }
.wf-sidebar-logout > i:first-child { opacity: 0.75 !important; }

/* ── Collapsed (icon) rail ────────────────────────────────────────── */
.wf-sidebar.is-collapsed { width: 64px; }
.wf-sidebar.is-collapsed .wf-sidebar-text,
.wf-sidebar.is-collapsed .wf-sidebar-caret,
.wf-sidebar.is-collapsed .wf-sidebar-brand { display: none; }
.wf-sidebar.is-collapsed .wf-sidebar-head { justify-content: center; padding: 0 0.5rem; }
.wf-sidebar.is-collapsed .wf-sidebar-link,
.wf-sidebar.is-collapsed .wf-sidebar-foottoggle {
    justify-content: center;
    gap: 0;
    padding: 0.55rem;
}
.wf-sidebar.is-collapsed .wf-sidebar-link > i:first-child { font-size: 1.1rem; width: auto; }
.wf-sidebar.is-collapsed .wf-sidebar-sub { display: none !important; }
.wf-sidebar.is-collapsed .wf-sidebar-sectionlabel { justify-content: center; padding: 0.5rem 0; }
.wf-sidebar.is-collapsed .wf-sidebar-popover { left: 0; right: auto; min-width: 13rem; }

/* ── Mobile (off-canvas drawer) ───────────────────────────────────── */
.wf-sidebar-mobilebar { display: none; }
.wf-sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1039;
    background: transparent;
}

@media (max-width: 767.98px) {
    .wf-shell--side { padding-top: 3.25rem; }

    .wf-sidebar-mobilebar {
        display: flex;
        align-items: center;
        gap: 0.6rem;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 3.25rem;
        padding: 0 0.85rem;
        background: var(--theme-nav-background);
        border-bottom: 1px solid var(--theme-nav-border);
        z-index: 1038;
    }
    .wf-sidebar-burger {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 2.1rem;
        height: 2.1rem;
        border: none;
        background: transparent;
        color: var(--theme-nav-text-hover);
        border-radius: var(--theme-radius-button);
        font-size: 1.2rem;
        cursor: pointer;
    }
    .wf-sidebar-burger:hover { background: var(--theme-nav-hover-background); }
    .wf-sidebar-mobilebrand {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        color: var(--theme-nav-text-hover);
        text-decoration: none !important;
        font-weight: 700;
        font-size: 1rem;
        white-space: nowrap;
        overflow: hidden;
    }

    .wf-sidebar-backdrop { background: rgba(0, 0, 0, .45); }

    .wf-sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 1040;
        width: 268px;
        transform: translateX(-100%);
        transition: transform 200ms ease;
        border-right: 1px solid var(--theme-nav-border);
    }
    .wf-sidebar.is-mobile-open { transform: translateX(0); }

    /* The collapse toggle is meaningless on mobile (drawer is full width) */
    .wf-sidebar-collapse { display: none; }
}
