/* ============================================================
   SIDEBAR — estilos que requerem seletores de pseudo-elemento
   ou lógica pai→filho não coberta pelo Tailwind.
   ============================================================ */

/* Labels e badges somem quando recolhida.
   min-width: 0 é obrigatório para que flex items com flex-shrink:0 (shrink-0)
   possam ser colapsados abaixo de seu min-content width. */
#sidebar[data-collapsed="true"] .sidebar-label {
    opacity: 0;
    width: 0;
    min-width: 0;
    overflow: hidden;
    flex-shrink: 1;
}

#sidebar[data-collapsed="true"] .sidebar-badge {
    display: none;
}

/* Labels de grupo somem quando recolhida */
#sidebar[data-collapsed="true"] .sidebar-group-label {
    opacity: 0;
    height: 0;
    min-height: 0;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

/* Prevent horizontal scroll caused by overflow-y: auto implicitly setting overflow-x: auto */
#sidebar-nav {
    overflow-x: hidden;
}

/* Center establishment logo row when collapsed */
#sidebar[data-collapsed="true"] #sidebar-header > div:first-child {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
    gap: 0;
}

/* Center user trigger avatar when collapsed */
#sidebar[data-collapsed="true"] #user-menu-trigger {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
    gap: 0;
}

/* Active nav item — usa os tokens da sidebar (não os globais): no tema escuro
   --sidebar-primary é um azul claro legível sobre --sidebar-accent, enquanto
   --primary é escuro demais e some no fundo. */
.sidebar-item.active {
    background-color: var(--color-sidebar-accent);
    color: var(--color-sidebar-primary);
    font-weight: 500;
}

.sidebar-item.active .sidebar-icon {
    opacity: 0.9;
}

/* Sidebar tooltip — JS-positioned fixed element appended to body.
   CSS-only ::after is not viable here because #sidebar-nav has overflow-x: hidden
   which clips any ::after that overflows to the right. Same reason the user menu
   uses a body-level portal. sidebar.js creates and positions this element. */
#sidebar-tooltip {
    position: fixed;
    z-index: 100;
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 6px;
    background-color: var(--foreground);
    color: var(--background);
    font-size: 12px;
    line-height: 1.5;
    white-space: nowrap;
    pointer-events: none;
    translate: 0 -50%;
    opacity: 0;
    transition: opacity 0.1s ease-out;
}

#sidebar-tooltip.visible {
    opacity: 1;
}

/* Arrow pointing left toward the sidebar item */
#sidebar-tooltip::before {
    content: '';
    position: absolute;
    left: -5px;
    top: 50%;
    translate: 0 -50%;
    width: 10px;
    height: 10px;
    background-color: var(--foreground);
    rotate: 45deg;
    border-radius: 2px;
    flex-shrink: 0;
}

/* Overlay mobile */
#sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgb(0 0 0 / 40%);
    z-index: 40;
}

#sidebar-overlay.visible {
    display: block;
}

/* Mobile: sidebar como drawer */
@media (max-width: 767px) {
    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform 0.2s ease, width 0.15s ease-linear;
        width: 224px !important;
    }

    #sidebar.mobile-open {
        transform: translateX(0);
    }

    /* No mobile, labels sempre visíveis (sidebar abre em modo expandido) */
    #sidebar[data-collapsed="true"] .sidebar-label {
        opacity: 1;
        width: auto;
        min-width: unset;
        overflow: visible;
        flex-shrink: 0;
    }

    #sidebar[data-collapsed="true"] .sidebar-badge {
        display: inline-flex;
    }

    #sidebar[data-collapsed="true"] .sidebar-group-label {
        opacity: 1;
        height: auto;
        min-height: unset;
        overflow: visible;
    }

    /* Tooltip desabilitado no mobile — sidebar abre sempre expandida */
    #sidebar-tooltip {
        display: none !important;
    }
}
