/**
 * incuCommunity - Sidenav Styles
 *
 * Overlay sidebar navigation with collapsible icon-only mode.
 * Uses design system CSS variables from bricks-child/style.css.
 *
 * Layout breakdown:
 *   Desktop (>=1200px)  - Collapsed sidebar (64px icons) always visible,
 *                         expands as overlay on toggle
 *   Tablet (992-1200px) - Sidenav hidden, hamburger button visible,
 *                         opens as overlay
 *   Mobile (<992px)     - Sidenav hidden, bottom bar shown instead
 */

/* ==========================================================================
   0. BRICKS BUILDER EDITOR — show sidenav expanded for visual editing
   ========================================================================== */

body[data-builder-window="iframe"] .incuc-sidenav {
    position: relative !important;
    transform: none !important;
    width: 260px !important;
    top: auto !important;
    bottom: auto !important;
    left: auto !important;
    z-index: auto !important;
    border-right: 1px solid var(--incuc-border, #e2e8f0);
    background: var(--incuc-surface, #ffffff);
}

body[data-builder-window="iframe"] .incuc-sidenav .incuc-sidenav__label {
    opacity: 1 !important;
    width: auto !important;
}

body[data-builder-window="iframe"] .incuc-sidenav .incuc-sidenav__link {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 12px !important;
    padding: 12px 16px !important;
}

body[data-builder-window="iframe"] .incuc-sidenav .incuc-sidenav__toggle {
    display: none !important;
}

/* ==========================================================================
   0b. LOGGED-OUT GUARD
   ========================================================================== */

body:not(.incuc-logged-in) .incuc-sidenav,
body:not(.incuc-logged-in) .incuc-sidenav-backdrop,
body:not(.incuc-logged-in) .incuc-sidenav-hamburger,
body:not(.incuc-logged-in) .incuc-mobile-bar {
    display: none !important;
}

/* ==========================================================================
   0b. BRICKS ELEMENT OVERRIDES
   When sidenav is built with native Bricks blocks, neutralize their defaults.
   ========================================================================== */

.incuc-sidenav .brxe-block,
.incuc-sidenav .brxe-text-basic {
    margin: 0;
    padding: 0;
}

.incuc-sidenav .incuc-sidenav__link.brxe-block {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: var(--incuc-space-3, 12px);
    padding: 12px var(--incuc-space-4, 16px);
    border-left: 3px solid transparent;
}

.incuc-sidenav .incuc-sidenav__icon .brxe-icon {
    font-size: 18px !important;
    width: auto;
    height: auto;
    line-height: 1;
}

.incuc-sidenav .incuc-sidenav__icon.brxe-block {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.incuc-sidenav .incuc-sidenav__label.brxe-text-basic {
    opacity: 1;
    overflow: hidden;
    flex: 1;
    min-width: 0;
    font-family: var(--incuc-font-family, 'Inter', sans-serif);
    font-size: var(--incuc-text-sm, 0.875rem);
    font-weight: var(--incuc-font-medium, 500);
}

.incuc-sidenav .incuc-sidenav__item.brxe-block {
    list-style: none;
}

.incuc-sidenav .incuc-sidenav__menu.brxe-block {
    list-style: none;
    margin: 0;
    padding: var(--incuc-space-2, 8px) 0;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
}

.incuc-sidenav .incuc-sidenav__toggle.brxe-block {
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.incuc-sidenav .incuc-sidenav__toggle .brxe-icon {
    font-size: 18px !important;
}

.incuc-sidenav .incuc-sidenav__bottom.brxe-block {
    margin-top: auto;
}

.incuc-sidenav .incuc-sidenav__badge.brxe-block {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    width: auto !important;
    max-width: 40px;
    height: 18px !important;
    min-height: 0 !important;
    padding: 0 5px;
    border-radius: 9px;
    background-color: var(--incuc-error, #ef4444);
    color: #ffffff;
    font-size: 11px;
    font-weight: var(--incuc-font-semibold, 600);
    line-height: 1;
    flex-shrink: 0;
}

/* ==========================================================================
   1. SIDENAV - BASE (overlay model)
   ========================================================================== */

.incuc-sidenav {
    position: fixed;
    top: var(--incuc-header-height, 64px);
    left: 0;
    bottom: 0;
    width: var(--incuc-sidenav-width, 260px);
    background: var(--incuc-surface);
    border-right: 1px solid var(--incuc-border);
    z-index: var(--incuc-z-sticky, 100);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Overlay: hidden by default, slides in */
    transform: translateX(-100%);
    transition: transform 200ms ease,
                width 200ms ease;
    /* Prevent FOUC: hide until JS initializes */
    visibility: hidden;
}

.incuc-sidenav.incuc-sidenav--ready {
    visibility: visible;
}

/* Open state: slide in */
.incuc-sidenav.incuc-sidenav--open {
    transform: translateX(0);
}

/* ==========================================================================
   2. TOGGLE BUTTON
   ========================================================================== */

.incuc-sidenav__toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--incuc-sidenav-collapsed-width, 64px);
    height: 48px;
    padding: 0;
    background: none;
    border: none;
    border-bottom: 1px solid var(--incuc-border);
    cursor: pointer;
    color: var(--incuc-text-secondary);
    font-size: var(--incuc-text-base, 1rem);
    transition: color var(--incuc-transition-fast, 150ms) ease,
                background-color var(--incuc-transition-fast, 150ms) ease;
    flex-shrink: 0;
}

.incuc-sidenav__toggle:hover {
    color: var(--incuc-text);
    background-color: var(--incuc-surface-hover);
}

.incuc-sidenav__toggle:focus-visible {
    outline: 2px solid var(--incuc-primary);
    outline-offset: -2px;
}

/* ==========================================================================
   3. MENU LIST
   ========================================================================== */

.incuc-sidenav__menu {
    list-style: none;
    margin: 0;
    padding: var(--incuc-space-2, 8px) 0;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Custom thin scrollbar */
.incuc-sidenav__menu::-webkit-scrollbar {
    width: 4px;
}

.incuc-sidenav__menu::-webkit-scrollbar-track {
    background: transparent;
}

.incuc-sidenav__menu::-webkit-scrollbar-thumb {
    background-color: var(--incuc-border);
    border-radius: var(--incuc-radius-sm, 0.25rem);
}

.incuc-sidenav__menu::-webkit-scrollbar-thumb:hover {
    background-color: var(--incuc-text-muted);
}

/* Firefox scrollbar */
.incuc-sidenav__menu {
    scrollbar-width: thin;
    scrollbar-color: var(--incuc-border) transparent;
}

/* ==========================================================================
   4. SIDENAV ITEMS
   ========================================================================== */

.incuc-sidenav__item {
    position: relative;
    margin: 0;
    padding: 0;
}

/* ==========================================================================
   5. SIDENAV LINK
   ========================================================================== */

.incuc-sidenav__link {
    display: flex;
    align-items: center;
    gap: var(--incuc-space-3, 12px);
    padding: 12px var(--incuc-space-4, 16px);
    color: var(--incuc-text-secondary);
    text-decoration: none;
    font-family: var(--incuc-font-family, 'Inter', sans-serif);
    font-size: var(--incuc-text-sm, 0.875rem);
    font-weight: var(--incuc-font-medium, 500);
    line-height: 1.4;
    border-left: 3px solid transparent;
    transition: background-color 150ms ease,
                color 150ms ease,
                border-color 150ms ease,
                padding 200ms ease,
                gap 200ms ease;
    cursor: pointer;
    white-space: nowrap;
    position: relative;
}

.incuc-sidenav__link:hover {
    background-color: var(--incuc-surface-hover);
    color: var(--incuc-text);
    text-decoration: none;
}

.incuc-sidenav__link:focus-visible {
    outline: 2px solid var(--incuc-primary);
    outline-offset: -2px;
}

/* Active item */
.incuc-sidenav__item--active > .incuc-sidenav__link {
    background-color: var(--incuc-primary-light);
    color: var(--incuc-primary);
    border-left-color: var(--incuc-primary);
}

.incuc-sidenav__item--active > .incuc-sidenav__link:hover {
    background-color: var(--incuc-primary-light);
    color: var(--incuc-primary-hover);
}

/* ==========================================================================
   6. ICON
   ========================================================================== */

.incuc-sidenav__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    font-size: 18px;
    position: relative;
}

/* ==========================================================================
   7. LABEL (collapsible)
   ========================================================================== */

.incuc-sidenav__label {
    opacity: 1;
    width: auto;
    overflow: hidden;
    transition: opacity 200ms ease,
                width 200ms ease,
                flex 200ms ease;
    flex: 1;
    min-width: 0;
}

/* ==========================================================================
   8. BADGE
   ========================================================================== */

.incuc-sidenav__badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background-color: var(--incuc-error, #ef4444);
    color: #ffffff;
    font-size: 11px;
    font-weight: var(--incuc-font-semibold, 600);
    line-height: 1;
    flex-shrink: 0;
    transition: transform var(--incuc-transition-slow, 300ms) ease,
                top var(--incuc-transition-slow, 300ms) ease,
                right var(--incuc-transition-slow, 300ms) ease;
}

/* Hide badge when value is empty or zero */
.incuc-sidenav__badge:empty {
    display: none;
}

/* ==========================================================================
   9. BOTTOM SECTION
   ========================================================================== */

.incuc-sidenav__bottom {
    margin-top: auto;
    border-top: 1px solid var(--incuc-border);
    padding: var(--incuc-space-2, 8px) 0;
}

.incuc-sidenav__bottom .incuc-sidenav__link {
    color: var(--incuc-text-muted);
}

.incuc-sidenav__bottom .incuc-sidenav__link:hover {
    color: var(--incuc-text-secondary);
    background-color: var(--incuc-surface-hover);
}

/* ==========================================================================
   10. BACKDROP
   ========================================================================== */

.incuc-sidenav-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: transparent;
    z-index: calc(var(--incuc-z-sticky, 100) - 1);
    pointer-events: none;
}

.incuc-sidenav-backdrop.active {
    pointer-events: auto;
}

/* ==========================================================================
   11. HAMBURGER TOGGLE BUTTON (outside sidenav, for tablet)
   ========================================================================== */

.incuc-sidenav-hamburger {
    position: fixed;
    top: calc(var(--incuc-header-height, 64px) + 12px);
    left: 12px;
    z-index: calc(var(--incuc-z-sticky, 100) + 1);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--incuc-surface);
    border: 1px solid var(--incuc-border);
    border-radius: var(--incuc-radius-md, 0.5rem);
    box-shadow: var(--incuc-shadow-sm);
    cursor: pointer;
    color: var(--incuc-text-secondary);
    font-size: 18px;
    transition: background-color var(--incuc-transition-fast, 150ms) ease,
                color var(--incuc-transition-fast, 150ms) ease,
                opacity var(--incuc-transition-fast, 150ms) ease;
    padding: 0;
}

.incuc-sidenav-hamburger:hover {
    background: var(--incuc-surface-hover);
    color: var(--incuc-text);
}

body.admin-bar .incuc-sidenav-hamburger {
    top: calc(var(--incuc-header-height, 64px) + 32px + 12px);
}

/* Hide hamburger on desktop (collapsed sidebar is visible) */
@media (min-width: 1200px) {
    .incuc-sidenav-hamburger {
        display: none;
    }
}

/* ==========================================================================
   12. CONTENT AREA — NO PUSH (overlay model)
   ========================================================================== */

/* Content stays at full width — sidenav overlays on top */
body.incuc-has-sidenav #brx-content,
body.incuc-has-sidenav #brx-footer {
    margin-left: 0;
    max-width: 100vw;
    overflow-x: hidden;
    transition: none;
}

/* Bricks containers respect full width */
body.incuc-has-sidenav #brx-content .brxe-container,
body.incuc-has-sidenav #brx-footer .brxe-container {
    max-width: 100%;
    box-sizing: border-box;
}

/* Header: no padding adjustment needed for overlay */
body.incuc-has-sidenav #brx-header .brxe-section > .brxe-container,
body.incuc-has-sidenav header.brxe-section > .brxe-container {
    padding-left: 24px;
    transition: none;
}

/* Admin bar offset */
body.admin-bar .incuc-sidenav {
    top: calc(var(--incuc-header-height, 64px) + 32px);
}

body.admin-bar.incuc-has-sidenav #brx-header .brxe-section,
body.admin-bar.incuc-has-sidenav header.brxe-section {
    top: 32px;
}

/* ==========================================================================
   13. MOBILE BOTTOM BAR - BASE
   ========================================================================== */

.incuc-mobile-bar {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--incuc-surface);
    border-top: 1px solid var(--incuc-border);
    z-index: var(--incuc-z-header, 200);
    align-items: center;
    justify-content: space-around;
    padding: 0;
}

/* ==========================================================================
   14. MOBILE BAR ITEMS
   ========================================================================== */

.incuc-mobile-bar__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    height: 100%;
    padding: var(--incuc-space-1, 4px) 0;
    color: var(--incuc-text-muted);
    text-decoration: none;
    transition: color var(--incuc-transition-fast, 150ms) ease;
    cursor: pointer;
    position: relative;
}

.incuc-mobile-bar__item:hover {
    color: var(--incuc-text-secondary);
    text-decoration: none;
}

/* Active mobile item */
.incuc-mobile-bar__item--active {
    color: var(--incuc-primary);
}

.incuc-mobile-bar__item--active:hover {
    color: var(--incuc-primary-hover);
}

/* ==========================================================================
   15. MOBILE BAR ICON
   ========================================================================== */

.incuc-mobile-bar__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    position: relative;
    line-height: 1;
    margin-bottom: 2px;
}

/* ==========================================================================
   16. MOBILE BAR BADGE (dot style, no number)
   ========================================================================== */

.incuc-mobile-bar__badge {
    position: absolute;
    top: -2px;
    right: -6px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--incuc-error, #ef4444);
    border: 2px solid var(--incuc-surface);
}

.incuc-mobile-bar__badge:empty {
    /* Still show as a dot even when empty */
}

/* ==========================================================================
   17. MOBILE BAR LABEL
   ========================================================================== */

.incuc-mobile-bar__label {
    font-family: var(--incuc-font-family, 'Inter', sans-serif);
    font-size: var(--incuc-text-xs, 0.75rem);
    font-weight: var(--incuc-font-medium, 500);
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 64px;
}

/* ==========================================================================
   18. RESPONSIVE - DESKTOP (>=1200px) — permanent collapsed sidebar
   ========================================================================== */

@media (min-width: 1200px) {
    /* Desktop: collapsed sidebar visible immediately (no JS dependency) */
    .incuc-sidenav {
        transform: translateX(0);
        width: var(--incuc-sidenav-collapsed-width, 64px);
        visibility: visible;
    }

    /* When expanded (overlay), full width */
    .incuc-sidenav.incuc-sidenav--open {
        width: var(--incuc-sidenav-width, 260px);
    }

    /* Collapsed state: labels hidden, icons centered */
    .incuc-sidenav:not(.incuc-sidenav--open) .incuc-sidenav__label {
        opacity: 0;
        width: 0;
        flex: 0 0 0px;
        overflow: hidden;
    }

    .incuc-sidenav:not(.incuc-sidenav--open) .incuc-sidenav__link {
        /* Center 20px icon in 64px collapsed width: (64 - 3px border - 20px icon) / 2 ≈ 20px */
        padding: 12px 20px;
        gap: 0;
        border-left-color: transparent;
    }

    .incuc-sidenav:not(.incuc-sidenav--open) .incuc-sidenav__item--active > .incuc-sidenav__link {
        background-color: var(--incuc-primary-light);
        color: var(--incuc-primary);
        border-left-color: transparent;
    }

    .incuc-sidenav:not(.incuc-sidenav--open) .incuc-sidenav__toggle {
        padding: 0;
    }

    /* Badge repositioned when collapsed */
    .incuc-sidenav:not(.incuc-sidenav--open) .incuc-sidenav__badge {
        position: absolute;
        top: 2px;
        right: 6px;
        min-width: 16px;
        height: 16px;
        padding: 0 4px;
        font-size: 10px;
    }

    /* Tooltips when collapsed */
    .incuc-sidenav:not(.incuc-sidenav--open) .incuc-sidenav__link[data-tooltip]::after {
        content: attr(data-tooltip);
        position: absolute;
        left: calc(100% + 8px);
        top: 50%;
        transform: translateY(-50%);
        padding: 6px 12px;
        background-color: var(--incuc-text, #1e293b);
        color: #ffffff;
        font-size: var(--incuc-text-xs, 0.75rem);
        font-weight: var(--incuc-font-medium, 500);
        white-space: nowrap;
        border-radius: var(--incuc-radius-md, 0.5rem);
        box-shadow: var(--incuc-shadow-md);
        z-index: var(--incuc-z-overlay, 300);
        pointer-events: none;
        opacity: 0;
        transition: opacity 150ms ease;
    }

    .incuc-sidenav:not(.incuc-sidenav--open) .incuc-sidenav__link[data-tooltip]:hover::after {
        opacity: 1;
    }
}

/* ==========================================================================
   19. RESPONSIVE - TABLET (992px - 1200px)
   ========================================================================== */

@media (max-width: 1199.98px) and (min-width: 992px) {
    /* Sidenav hidden by default, opens as full overlay */
    .incuc-sidenav {
        transform: translateX(-100%);
        width: var(--incuc-sidenav-width, 260px);
    }

    .incuc-sidenav.incuc-sidenav--open {
        transform: translateX(0);
    }

    /* Show hamburger on tablet */
    .incuc-sidenav-hamburger {
        display: flex;
    }

    /* No push on content */
    body.incuc-has-sidenav #brx-content,
    body.incuc-has-sidenav #brx-footer {
        margin-left: 0;
    }

    body.incuc-has-sidenav #brx-header .brxe-section > .brxe-container,
    body.incuc-has-sidenav header.brxe-section > .brxe-container {
        padding-left: 24px;
    }
}

/* ==========================================================================
   20. RESPONSIVE - MOBILE (<992px)
   ========================================================================== */

@media (max-width: 991.98px) {
    /* Hide sidenav on mobile */
    .incuc-sidenav {
        display: none;
    }

    /* Show mobile bottom bar */
    .incuc-mobile-bar {
        display: flex;
    }

    /* Hide hamburger on mobile (bottom bar replaces it) */
    .incuc-sidenav-hamburger {
        display: none;
    }

    /* No push, add bottom padding for the bar */
    body.incuc-has-sidenav #brx-content,
    body.incuc-has-sidenav #brx-footer {
        margin-left: 0;
        padding-bottom: 56px;
    }

    /* Remove header padding on mobile */
    body.incuc-has-sidenav #brx-header .brxe-section > .brxe-container,
    body.incuc-has-sidenav header.brxe-section > .brxe-container {
        padding-left: 24px;
    }
}

/* ==========================================================================
   21. ACCESSIBILITY & REDUCED MOTION
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .incuc-sidenav,
    .incuc-sidenav__link,
    .incuc-sidenav__label,
    .incuc-sidenav__badge,
    .incuc-sidenav__toggle,
    .incuc-sidenav-backdrop,
    .incuc-sidenav-hamburger,
    .incuc-mobile-bar__item {
        transition: none;
    }
}
