/* ========================================
   SIDEBAR NAVIGATION
   ======================================== */

/* Main sidebar container */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 70px;
    height: 100vh;
    padding: 0;
    z-index: 1000;
    background: var(--app-sidebar-bg);
    backdrop-filter: blur(var(--visual-blur-lg));
    -webkit-backdrop-filter: blur(var(--visual-blur-lg));
    border-right: 1px solid var(--visual-divider);
    border-radius: 0;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
    overflow: hidden;
}

    /* Ensure collapsed text hidden by default; reveal on hover or when pinned */
    .sidebar .sidebar-link-text {
        opacity: 0;
        width: 0;
        pointer-events: none;
        transition: all 0.3s ease;
    }

    .sidebar:hover .sidebar-link-text,
    .sidebar.pinned .sidebar-link-text {
        opacity: 1;
        width: auto;
        pointer-events: auto;
    }

    /* Ensure hover expansion works universally */
    .sidebar:hover {
        width: 280px;
        background: var(--app-sidebar-bg);
    }

/* SUBMENU STYLES */
.sidebar-item.has-submenu {
    position: relative;
}

.sidebar-arrow {
    margin-left: auto;
    transition: transform 0.3s ease;
    font-size: 12px;
    opacity: 0.7;
}

.sidebar-item.has-submenu.open .sidebar-arrow {
    transform: rotate(90deg);
}

.sidebar-submenu {
    height: 0;
    overflow: hidden;
    opacity: 0;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    margin: 4px 8px;
    padding: 0;
    will-change: height, opacity;
    transition: opacity 180ms ease;
}

.sidebar-item.has-submenu.open .sidebar-submenu {
    opacity: 1;
    padding: 8px 0;
}

.sidebar-subitem {
    list-style: none;
    margin: 0;
}

.sidebar-sublink {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px 8px 32px;
    color: var(--text-muted, rgba(255, 255, 255, 0.7));
    text-decoration: none;
    font-size: 13px;
    transition: all 0.3s ease;
    border-radius: 6px;
    margin: 2px 8px;
}

    .sidebar-sublink:hover {
        background: var(--visual-surface-subtle);
        color: var(--text-primary, white);
    }

    .sidebar-sublink .sidebar-link-icon {
        width: 16px;
        height: 16px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 12px;
    }

    .sidebar-sublink .sidebar-link-text {
        flex: 1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

/* DESKTOP: Comportamento normal com hover e pin */
@media (min-width: 769px) {
    .sidebar.pinned {
        width: 280px;
    }

    .sidebar:hover:not(.pinned) {
        width: 280px;
        background: var(--app-sidebar-bg);
    }

    /* Estado colapsado por padrão */
    .sidebar:not(.pinned) .sidebar-header {
        padding: 20px 15px;
        justify-content: flex-start;
    }

    .sidebar:not(.pinned):not(:hover) .sidebar-title {
        opacity: 0;
        width: 0;
        pointer-events: none;
    }

    .sidebar:not(.pinned):not(:hover) .sidebar-toggle {
        opacity: 0;
        pointer-events: none;
    }

    .sidebar:not(.pinned):not(:hover) .sidebar-menu {
        padding: 0 5px;
    }

    .sidebar:not(.pinned):not(:hover) .sidebar-link {
        padding: 12px;
        justify-content: center;
        gap: 0;
    }

    .sidebar:not(.pinned):not(:hover) .sidebar-link-text {
        opacity: 0;
        width: 0;
        pointer-events: none;
    }

    .sidebar:not(.pinned):not(:hover) .sidebar-footer {
        padding: 15px 5px;
    }

    .sidebar:not(.pinned):not(:hover) .user-profile {
        justify-content: center;
        margin-bottom: 10px;
        gap: 0 !important;
    }

    .sidebar:not(.pinned):not(:hover) .user-avatar {
        margin: 0;
    }

    .sidebar:not(.pinned):not(:hover) .user-info {
        display: none;
    }

    /* Esconder submenus quando colapsado */
    .sidebar:not(.pinned):not(:hover) .sidebar-submenu {
        max-height: 0 !important;
        opacity: 0 !important;
        padding: 0 !important;
    }

    .sidebar:not(.pinned):not(:hover) .sidebar-arrow {
        display: none;
        opacity: 0;
        pointer-events: none;
    }

    /* Centralizar ícones de menus com submenu quando colapsado */
    .sidebar:not(.pinned):not(:hover) .sidebar-item.has-submenu .sidebar-link {
        justify-content: center !important;
        gap: 0 !important;
    }

    /* Ocultar qualquer rolagem no conteúdo quando colapsado */
    .sidebar:not(.pinned):not(:hover) .sidebar-content {
        overflow: hidden;
    }

    .sidebar:not(.pinned):not(:hover) .user-actions {
        opacity: 0;
        height: 0;
        overflow: hidden;
        pointer-events: none;
    }

    /* Tooltips apenas no desktop */
    .sidebar:not(.pinned):not(:hover) .sidebar-link::before {
        content: attr(data-tooltip);
        position: absolute;
        left: 80px;
        top: 50%;
        transform: translateY(-50%);
        background: rgba(0, 0, 0, 0.9);
        color: white;
        padding: 8px 12px;
        border-radius: 6px;
        font-size: 12px;
        white-space: nowrap;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
        z-index: 1000;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    }

    .sidebar:not(.pinned):not(:hover) .sidebar-link:hover::before {
        opacity: 1;
    }
}

/* MOBILE: Menu deslizante sempre expandido quando aberto */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 280px !important; /* Sempre expandido no mobile */
        transition: transform 0.3s ease;
        z-index: 1001;
    }

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

    /* Overlay para mobile */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: var(--visual-overlay-side-panel);
        z-index: 1000;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
    }

        .sidebar-overlay.active {
            opacity: 1;
            visibility: visible;
        }

    /* No mobile, sempre mostrar conteúdo expandido */
    .sidebar .sidebar-header {
        padding: 20px !important;
        justify-content: flex-start !important;
    }

    /* Mostrar botão de fechar apenas no mobile */
    .mobile-close-btn {
        display: flex !important;
    }

    /* Esconder botão do hambúrguer quando menu estiver aberto no mobile */
    body.mobile-menu-open .mobile-menu-btn {
        display: none !important;
    }

    .sidebar .sidebar-title {
        opacity: 1 !important;
        width: auto !important;
        pointer-events: auto !important;
    }

    .sidebar .sidebar-menu {
        padding: 0 15px !important;
    }

    .sidebar .sidebar-link, .sidebar a.sidebar-link {
        padding: 12px 16px !important;
        justify-content: flex-start !important;
        gap: 12px !important;
    }

    .sidebar .sidebar-link-text {
        opacity: 1 !important;
        width: auto !important;
        pointer-events: auto !important;
    }

    .sidebar .sidebar-footer {
        padding: 15px !important;
    }

    .sidebar .user-profile {
        justify-content: flex-start !important;
        margin-bottom: 15px !important;
    }

    .sidebar .user-info {
        opacity: 1 !important;
        width: auto !important;
        pointer-events: auto !important;
    }

    .sidebar .user-actions {
        opacity: 1 !important;
        height: auto !important;
        overflow: visible !important;
        pointer-events: auto !important;
    }

    /* Esconder tooltips no mobile */
    .sidebar .sidebar-link::before {
        display: none !important;
    }
}

.sidebar-header {
    padding: 20px 15px;
    border-bottom: 1px solid var(--visual-divider);
    display: flex;
    align-items: center;
    gap: 15px;
    min-height: 80px;
    position: relative;
}

.sidebar-logo {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 18px;
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--app-primary-color), var(--app-primary-light));
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    position: relative;
}

.sidebar-title {
    color: var(--text-primary, white);
    font-weight: 600;
    font-size: 1.2rem;
    opacity: 1;
    transition: opacity 0.3s ease;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-toggle {
    position: absolute;
    top: 50%;
    right: 15px;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    border-radius: 4px;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted, rgba(255, 255, 255, 0.7)) !important;
    font-size: 10px;
    transition: all 0.3s ease;
    opacity: 0.6;
}

    .sidebar-toggle:hover {
        background: var(--visual-surface-subtle);
        color: var(--text-primary, white) !important;
        opacity: 1;
    }

    /* Garantir que o ícone mantenha o estilo correto em todos os estados */
    .sidebar-toggle i,
    .sidebar-toggle:before,
    .sidebar-toggle:after {
        color: inherit !important;
        font-size: inherit !important;
    }

        /* Forçar cor correta para o ícone em todos os estados */
        .sidebar-toggle,
        .sidebar-toggle *,
        .sidebar-toggle i,
        .sidebar-toggle i:before {
            color: var(--text-muted, rgba(255, 255, 255, 0.7)) !important;
        }

            .sidebar-toggle:hover,
            .sidebar-toggle:hover *,
            .sidebar-toggle:hover i,
            .sidebar-toggle:hover i:before {
                color: var(--text-primary, white) !important;
            }

            /* Garantir que o ícone não tenha cor vermelha em nenhum estado */
            .sidebar-toggle:not(:hover) {
                color: var(--text-muted, rgba(255, 255, 255, 0.7)) !important;
            }

                .sidebar-toggle:not(:hover) *,
                .sidebar-toggle:not(:hover) i,
                .sidebar-toggle:not(:hover) i:before {
                    color: var(--text-muted, rgba(255, 255, 255, 0.7)) !important;
                }

            /* Forçar cor específica para ícones FontAwesome */
            .sidebar-toggle .fas,
            .sidebar-toggle .fas:before {
                color: inherit !important;
            }

/* CSS mais específico para garantir cor correta */
.sidebar .sidebar-toggle {
    color: var(--text-muted, rgba(255, 255, 255, 0.7)) !important;
}

    .sidebar .sidebar-toggle i {
        color: var(--text-muted, rgba(255, 255, 255, 0.7)) !important;
    }

    .sidebar .sidebar-toggle:hover {
        color: var(--text-primary, white) !important;
    }

        .sidebar .sidebar-toggle:hover i {
            color: var(--text-primary, white) !important;
        }

/* Botão de fechar mobile - esconder no desktop */
.mobile-close-btn {
    position: absolute;
    top: 50%;
    right: 45px;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    border-radius: 4px;
    width: 20px;
    height: 20px;
    display: none; /* Escondido por padrão */
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted, rgba(255, 255, 255, 0.7));
    font-size: 10px;
    transition: all 0.3s ease;
    opacity: 0.6;
}

    .mobile-close-btn:hover {
        background: var(--visual-surface-subtle);
        color: var(--text-primary, white);
        opacity: 1;
    }

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px 0;
}

    .sidebar-content::-webkit-scrollbar {
        width: 4px;
    }

    .sidebar-content::-webkit-scrollbar-track {
        background: var(--visual-surface-subtle);
    }

    .sidebar-content::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.3);
        border-radius: 2px;
    }

        .sidebar-content::-webkit-scrollbar-thumb:hover {
            background: rgba(255, 255, 255, 0.5);
        }

.sidebar-menu {
    list-style: none;
    padding: 0 15px;
}

.sidebar-item {
    margin-bottom: 5px;
}

.sidebar-link, a.sidebar-link {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-radius: 8px;
    color: var(--text-secondary, rgba(255, 255, 255, 0.8));
    text-decoration: none;
    transition: all 0.3s ease;
    position: relative;
    gap: 12px;
    min-height: 44px;
}

    .sidebar-link:hover, a.sidebar-link:hover {
        background: var(--visual-surface-subtle);
        color: var(--text-primary, white);
    }

.sidebar-link-icon {
    font-size: 18px;
    flex-shrink: 0;
    width: 20px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--icon-color, white);
}

.sidebar-link-text {
    opacity: 1;
    transition: all 0.3s ease;
    white-space: nowrap;
    overflow: hidden;
}

/* Menu de dois níveis */
/* removidos estilos de submenu (revert) */

.sidebar-footer {
    border-top: 1px solid var(--visual-divider);
    padding: 15px;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 15px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 14px;
    flex-shrink: 0;
}

.user-info {
    flex: 1;
    opacity: 1;
    transition: all 0.3s ease;
    white-space: nowrap;
    overflow: hidden;
}

.user-name {
    color: var(--text-primary, white);
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 2px;
}

.user-company {
    color: var(--text-muted, rgba(255, 255, 255, 0.6));
    font-size: 11px;
}

.user-actions {
    display: flex;
    flex-direction: column;
    gap: 3px;
    opacity: 1;
    transition: all 0.3s ease;
}

.user-action {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 4px;
    color: var(--text-muted, rgba(255, 255, 255, 0.7));
    text-decoration: none;
    font-size: 11px;
    transition: all 0.3s ease;
}

    .user-action:hover {
        background: var(--visual-surface-subtle);
        color: var(--text-primary, white);
    }

    .user-action.logout:hover {
        background: rgba(239, 68, 68, 0.2);
        color: #ef4444;
    }

/* Layout responsivo */
.main-content {
    margin-left: 70px;
    margin-top: 0;
    padding: 20px;
    transition: margin-left 0.3s ease;
    min-height: 100vh;
    isolation: isolate;
    overflow-x: clip;
}

.sidebar.pinned ~ .main-content {
    margin-left: 280px;
}
