/* ============================================================
   nav-grouped.css
   Hybrid pinned/unpinned nav interaction model.
   Used by main sidebar nav and admin aside nav.

   Class namespace: .fp-nav-*
   Theme tokens only (no hardcoded hex outside var() fallbacks).
   JS toggles .is-pinned, .is-hovered, .has-active-route.
   CSS owns all visual transitions.
   ============================================================ */

/* ------------------------------------------------------------
   Container
   ------------------------------------------------------------ */
.fp-nav-grouped {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    width: 100%;
    background: var(--bg-sidebar);
    color: var(--text-primary);
}

/* ------------------------------------------------------------
   Section (collapsible group)
   ------------------------------------------------------------ */
.fp-nav-section {
    position: relative;
    display: flex;
    flex-direction: column;
    border-left: 2px solid transparent;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

/* Active-route accent bar on the section's left edge */
.fp-nav-section.has-active-route {
    border-left-color: var(--sidebar-active-text, var(--cam-yellow));
}

/* ------------------------------------------------------------
   Section header (the clickable/hoverable row)
   ------------------------------------------------------------ */
.fp-nav-section-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: transparent;
    border: 0;
    color: var(--text-muted);
    text-align: left;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
    font-size: 0.7rem;
    line-height: 1.2;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.fp-nav-section-header:hover,
.fp-nav-section-header:focus-visible {
    color: var(--text-primary);
    background-color: var(--sidebar-active-bg, transparent);
}

.fp-nav-section-header:focus {
    outline: none;
}

.fp-nav-section-header:focus-visible {
    outline: 2px solid var(--sidebar-active-text, var(--cam-yellow));
    outline-offset: 2px;
}

/* Header layout: icon | label | badge | chevron */
.fp-nav-section-header > .bi {
    flex: 0 0 auto;
}

.fp-nav-section-header > .fp-nav-section-label,
.fp-nav-section-header > span:not(.fp-nav-chevron):not(.fp-nav-badge) {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Pinned header: subtle background tint + brighter text */
.fp-nav-section.is-pinned > .fp-nav-section-header {
    color: var(--text-primary);
    background-color: var(--sidebar-active-bg, transparent);
}

/* Active-route header: nudge the label color toward primary so
   the group reads as "current" even when collapsed */
.fp-nav-section.has-active-route > .fp-nav-section-header {
    color: var(--text-primary);
}

/* ------------------------------------------------------------
   Chevron
   ------------------------------------------------------------ */
.fp-nav-chevron {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    opacity: 0.7;
    transform: rotate(0deg);
    transition: transform 0.15s ease, opacity 0.15s ease;
}

.fp-nav-section-header:hover .fp-nav-chevron,
.fp-nav-section.is-pinned > .fp-nav-section-header .fp-nav-chevron {
    opacity: 1;
}

/* Pinned: rotate ~90deg to point down */
.fp-nav-section.is-pinned > .fp-nav-section-header .fp-nav-chevron {
    transform: rotate(90deg);
}

/* ------------------------------------------------------------
   Badge (coexists inside header; NavMenu already renders markup)
   ------------------------------------------------------------ */
.fp-nav-section-header .fp-nav-badge {
    flex: 0 0 auto;
    margin-left: 0.25rem;
}

/* ------------------------------------------------------------
   Section body (flyout panel / accordion content)
   ------------------------------------------------------------ */
.fp-nav-section-body {
    display: none;
    flex-direction: column;
    gap: 0.125rem;
    padding: 0.25rem 0.5rem 0.5rem;
}

/* NavLink defaults inside a section body — keep existing sizing,
   only add the active accent treatment using theme tokens. */
.fp-nav-section-body .nav-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.625rem;
    color: var(--text-muted);
    border-left: 2px solid transparent;
    border-radius: 2px;
    transition: color 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.fp-nav-section-body .nav-link:hover {
    color: var(--text-primary);
    background-color: var(--sidebar-active-bg, transparent);
}

.fp-nav-section-body .nav-link:focus {
    outline: none;
}

.fp-nav-section-body .nav-link:focus-visible {
    outline: 2px solid var(--sidebar-active-text, var(--cam-yellow));
    outline-offset: 2px;
}

.fp-nav-section-body .nav-link.active {
    color: var(--sidebar-active-text, var(--cam-yellow));
    background-color: var(--sidebar-active-bg, transparent);
    border-left-color: var(--sidebar-active-text, var(--cam-yellow));
}

/* ------------------------------------------------------------
   LG+ (>= 992px): flyout behavior
   Section body hidden by default; pinned OR hovered reveals it
   as an absolutely positioned flyout to the right of the header.
   Does NOT push other content.
   ------------------------------------------------------------ */
@media (min-width: 992px) {
    .fp-nav-section {
        /* Establish positioning context for the flyout */
        position: relative;
    }

    .fp-nav-section-body {
        display: none;
        position: absolute;
        left: 100%;
        top: 0;
        min-width: 220px;
        padding: 0.5rem;
        background: var(--bg-sidebar);
        border: 1px solid var(--border);
        border-radius: 4px;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
        z-index: 1040;
    }

    .fp-nav-section.is-hovered > .fp-nav-section-body,
    .fp-nav-section.is-pinned > .fp-nav-section-body {
        display: flex;
    }

    /* Pinned on desktop: render inline (accordion-style) instead of
       a flyout, so pinning behaves like "keep open in place". */
    .fp-nav-section.is-pinned > .fp-nav-section-body {
        position: static;
        left: auto;
        top: auto;
        min-width: 0;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        background: transparent;
        padding: 0.25rem 0.5rem 0.5rem;
    }

    /* If a section has both is-pinned and is-hovered, pinned wins
       (inline) — no conflicting flyout appears. */
    .fp-nav-section.is-pinned.is-hovered > .fp-nav-section-body {
        position: static;
    }
}

/* ------------------------------------------------------------
   < 992px: accordion behavior
   Hover is disabled; tap-to-expand. Multiple sections may be open.
   Section body renders inline below the header.
   ------------------------------------------------------------ */
@media (max-width: 991.98px) {
    .fp-nav-section-body {
        /* Reset any desktop flyout rules explicitly */
        position: static;
        left: auto;
        top: auto;
        min-width: 0;
        background: transparent;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        z-index: auto;
    }

    /* Ignore hover on touch/narrow viewports — only pinned (tapped)
       sections expand. */
    .fp-nav-section.is-hovered:not(.is-pinned) > .fp-nav-section-body {
        display: none;
    }

    .fp-nav-section.is-pinned > .fp-nav-section-body {
        display: flex;
    }

    /* Slightly larger tap targets on narrow viewports */
    .fp-nav-section-header {
        padding: 0.625rem 0.75rem;
    }

    .fp-nav-section-body .nav-link {
        padding: 0.5rem 0.625rem;
    }
}

/* ------------------------------------------------------------
   Admin nav variant — fixed 220px aside.
   Same visual language; flyout width tuned to match the aside.
   ------------------------------------------------------------ */
aside.fp-nav-grouped {
    width: 220px;
    flex: 0 0 220px;
}

@media (min-width: 992px) {
    aside.fp-nav-grouped .fp-nav-section-body {
        /* Flyout sits flush against the 220px aside */
        min-width: 220px;
    }
}

/* ------------------------------------------------------------
   Reduced motion: disable transitions for users who opt out.
   ------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
    .fp-nav-section,
    .fp-nav-section-header,
    .fp-nav-chevron,
    .fp-nav-section-body .nav-link {
        transition: none;
    }
}
