/**
 * NGA Sidebar Layout
 * Estrutura: Header fixo + Sidebar fixo (scroll) + Main (scroll) com Content + Footer
 */

/* ========================================
   VARIÁVEIS CSS
   ======================================== */
:root {
    --header-height: 60px;
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 100px;
    --sidebar-bg: #1e293b;
    --sidebar-text: #e2e8f0;
    --sidebar-text-muted: #94a3b8;
    --sidebar-hover-bg: #334155;
    --sidebar-active-bg: var(--nga-primary-color, #667eea);
    --sidebar-active-text: #ffffff;
    --sidebar-section-title-bg: #0f172a;
    --sidebar-border: #334155;
    --sidebar-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --sidebar-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
}

/* ========================================
   LAYOUT PRINCIPAL
   ======================================== */

/* Body para layout com sidebar */
body {
    margin: 0;
    padding: 0;
    padding-top: var(--header-height); /* Espaço para o header fixo */
}

/* Header fixo no topo */
header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: var(--header-height);
    z-index: 1050;
    background: var(--nga-primary-color, #667eea);
}

/* Container principal: Sidebar + Main */
.sidebar-layout-container {
    display: flex;
    height: calc(100vh - var(--header-height));
    overflow: hidden;
    position: relative;
}

/* Container quando não há sidebar (usuário não logado) */
.sidebar-layout-container.no-sidebar {
    display: block;
    height: auto;
    min-height: calc(100vh - var(--header-height));
    overflow: visible;
}

/* Sidebar fixo com scroll vertical */
.sidebar-wrapper {
    width: var(--sidebar-width);
    height: 100%;
    flex-shrink: 0;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    box-shadow: var(--sidebar-shadow);
    transition: var(--sidebar-transition);
    position: relative;
}

/* Sidebar colapsada */
.sidebar-wrapper.collapsed {
    width: var(--sidebar-collapsed-width);
}

/* Main com scroll vertical */
.main-wrapper {
    flex: 1;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    transition: var(--sidebar-transition);
    padding-top: 2rem;
}

/* Main quando não há sidebar (usuário não logado) */
.main-wrapper.full-width {
    width: 100%;
    height: auto;
    min-height: calc(100vh - var(--header-height));
    overflow-y: visible;
    overflow-x: visible;
}

/* Content área */
.content-wrapper {
    flex: 0 0 auto;  /* Não cresce/encolhe, tamanho automático */
    width: 100%;     /* Ocupa largura total disponível */
    min-width: 0;    /* CRÍTICO: permite flex funcionar corretamente com overflow */
    padding: 1rem;   /* Espaçamento interno apropriado */
}

/* Footer dentro do main */
.footer-wrapper {
    width: 100%;
    margin-top: auto;
}

/* ========================================
   SIDEBAR CONTENT
   ======================================== */
.sidebar-content {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Scrollbar customizada */
.sidebar-wrapper::-webkit-scrollbar {
    width: 6px;
}

.sidebar-wrapper::-webkit-scrollbar-track {
    background: var(--sidebar-section-title-bg);
}

.sidebar-wrapper::-webkit-scrollbar-thumb {
    background: var(--sidebar-border);
    border-radius: 3px;
}

.sidebar-wrapper::-webkit-scrollbar-thumb:hover {
    background: var(--sidebar-hover-bg);
}

/* ========================================
   SIDEBAR HEADER
   ======================================== */
.sidebar-header {
    padding: 1.5rem 1rem;
    background: var(--sidebar-section-title-bg);
    border-bottom: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--sidebar-active-text);
}

.sidebar-brand i {
    font-size: 1.5rem;
    color: var(--nga-secondary-color, #f6ad55);
}

.sidebar-brand-text {
    transition: var(--sidebar-transition);
    white-space: nowrap;
}

.sidebar-toggle-btn {
    background: transparent;
    border: none;
    color: var(--sidebar-text);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    transition: var(--sidebar-transition);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-toggle-btn:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-active-text);
}

.sidebar-toggle-btn i {
    transition: transform 0.3s ease;
}

.sidebar-wrapper.collapsed .sidebar-toggle-btn i {
    transform: rotate(180deg);
}

/* ========================================
   PLAN BADGE (Sidebar Header)
   ======================================== */
.plan-badge-container {
    display: flex;
    align-items: center;
}

.plan-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: 20px;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.plan-badge:hover {
    transform: scale(1.05);
    filter: brightness(0.85);
    text-decoration: none;
}

.plan-badge i {
    font-size: 1rem;
    color: inherit;
}

.plan-badge .plan-name {
    white-space: nowrap;
    transition: opacity 0.3s ease, width 0.3s ease, margin 0.3s ease;
}

.plan-badge-empty {
    background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
}

/* Plan Badge quando Sidebar Collapsed */
.sidebar-wrapper.collapsed .plan-badge {
    padding: 10px;
    justify-content: center;
}

.sidebar-wrapper.collapsed .plan-badge .plan-name {
    opacity: 0;
    width: 0;
    margin: 0;
    overflow: hidden;
}

.sidebar-wrapper.collapsed .plan-badge i {
    font-size: 1.2rem;
}

/* ========================================
   UPGRADE BADGE (Recursos Bloqueados)
   ======================================== */
.sidebar-link-locked {
    opacity: 0.8;
    position: relative;
}

.sidebar-link-locked:hover {
    opacity: 1;
}

.sidebar-sublink-locked {
    opacity: 0.8;
    position: relative;
}

.sidebar-sublink-locked:hover {
    opacity: 1;
}

.upgrade-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #ffd700 0%, #ff8c00 100%);
    color: #1a1a2e;
    font-size: 0.6rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: auto;
    box-shadow: 0 2px 6px rgba(255, 215, 0, 0.4);
    animation: pulse-gold 2s infinite;
    flex-shrink: 0;
}

.upgrade-badge i {
    font-size: 0.55rem;
    width: auto;
}

/* Badge menor para sublinks */
.sidebar-sublink-locked .upgrade-badge {
    font-size: 0.55rem;
    padding: 1px 5px;
}

.sidebar-sublink-locked .upgrade-badge i {
    font-size: 0.5rem;
}

/* Animação de pulse dourado */
@keyframes pulse-gold {
    0%, 100% {
        box-shadow: 0 2px 6px rgba(255, 215, 0, 0.4);
    }
    50% {
        box-shadow: 0 2px 12px rgba(255, 215, 0, 0.7);
    }
}

/* Esconder badge quando sidebar colapsada */
.sidebar-wrapper.collapsed .upgrade-badge {
    display: none;
}

/* ========================================
   SIDEBAR NAVIGATION
   ======================================== */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0;
}

/* Sections */
.sidebar-section {
    margin-bottom: 0.5rem;
}

.sidebar-section-title {
    padding: 0.75rem 1rem;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--sidebar-text-muted);
    background: var(--sidebar-section-title-bg);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 1px solid var(--sidebar-border);
    cursor: pointer;
    border: none;
    width: 100%;
    text-align: left;
    transition: var(--sidebar-transition);
    justify-content: space-between;
}

.sidebar-section-title:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-active-text);
}

.sidebar-section-title i:first-child {
    font-size: 1rem;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-section-title .sidebar-arrow {
    margin-left: auto;
}

.sidebar-section-title[aria-expanded="true"] .sidebar-arrow {
    transform: rotate(180deg);
}

/* Links */
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: var(--sidebar-transition);
    border-left: 3px solid transparent;
    cursor: pointer;
    background: transparent;
    border-right: none;
    border-top: none;
    border-bottom: none;
    width: 100%;
    text-align: left;
    font-size: 0.9rem;
}

.sidebar-link i {
    width: 20px;
    text-align: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.sidebar-link span {
    transition: var(--sidebar-transition);
    white-space: nowrap;
}

.sidebar-link:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-active-text);
    border-left-color: var(--nga-secondary-color, #f6ad55);
}

.sidebar-link.active {
    background: rgba(246, 173, 85, 0.85); /* nga-secondary-color com 85% de opacidade */
    color: var(--nga-primary-color, #667eea);
    border-left-color: var(--nga-primary-color, #667eea);
    font-weight: 600;
    font-size: 1.05rem;
}

.sidebar-link.active i {
    color: var(--nga-primary-color, #667eea);
}

/* Dropdown toggle */
.sidebar-dropdown-toggle {
    justify-content: space-between;
}

.sidebar-arrow {
    transition: transform 0.3s ease;
    font-size: 0.8rem;
    color: var(--sidebar-text-muted);
    margin-left: auto;
}

.sidebar-dropdown-toggle[aria-expanded="true"] .sidebar-arrow {
    transform: rotate(180deg);
}

/* Submenus */
.sidebar-submenu {
    background: rgba(0, 0, 0, 0.2);
    padding: 0.25rem 0;
}

.sidebar-sublink {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1rem 0.625rem 2.75rem;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: var(--sidebar-transition);
    font-size: 0.85rem;
    border-left: 3px solid transparent;
}

.sidebar-sublink i {
    width: 18px;
    text-align: center;
    font-size: 0.95rem;
    color: var(--sidebar-text-muted);
}

.sidebar-sublink:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-active-text);
    border-left-color: var(--nga-secondary-color, #f6ad55);
}

.sidebar-sublink:hover i {
    color: var(--nga-secondary-color, #f6ad55);
}

.sidebar-sublink.active {
    background: rgba(246, 173, 85, 0.85); /* nga-secondary-color com 85% de opacidade */
    color: var(--nga-primary-color, #667eea);
    border-left-color: var(--nga-primary-color, #667eea);
    font-weight: 600;
    font-size: 1.05rem;
}

.sidebar-sublink.active i {
    color: var(--nga-primary-color, #667eea);
}

/* Submenus aninhados (Nível 2) */
.sidebar-submenu-nested {
    padding-left: 0;
    background: rgba(0, 0, 0, 0.3);
}

.sidebar-submenu-nested .sidebar-sublink {
    padding-left: 3.5rem;
    font-size: 0.8rem;
}

.sidebar-submenu-nested .sidebar-sublink i {
    width: 16px;
    font-size: 0.85rem;
}

/* Botões de dropdown dentro de submenus */
.sidebar-submenu .sidebar-dropdown-toggle {
    padding-left: 2.75rem;
    font-size: 0.875rem;
    font-weight: 500;
}

.sidebar-submenu .sidebar-dropdown-toggle .sidebar-arrow {
    font-size: 0.7rem;
}

.sidebar-submenu .sidebar-dropdown-toggle i:first-child {
    width: 18px;
    font-size: 1rem;
}

/* ========================================
   SIDEBAR FOOTER
   ======================================== */
.sidebar-footer {
    padding: 1rem;
    background: var(--sidebar-section-title-bg);
    border-top: 1px solid var(--sidebar-border);
    flex-shrink: 0;
    position: relative;
}

.sidebar-user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--sidebar-text);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: var(--sidebar-transition);
}

.sidebar-user-info:hover {
    background: var(--sidebar-hover-bg);
}

.sidebar-user-name {
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.sidebar-user-arrow {
    font-size: 0.8rem;
    transition: transform 0.3s ease;
    color: var(--sidebar-text-muted);
}

.sidebar-user-info[aria-expanded="true"] .sidebar-user-arrow {
    transform: rotate(180deg);
}

/* Foto de perfil na sidebar */
.sidebar-profile-photo-container {
    position: relative;
    width: 36px;
    height: 36px;
    display: inline-block;
    flex-shrink: 0;
}

.sidebar-profile-photo {
    width: 36px;
    height: 36px;
    object-fit: cover;
    border-radius: 50%;
    border: 2px solid var(--nga-secondary-color, #f6ad55);
    transition: all 0.3s ease;
    background: transparent;
}

.sidebar-default-avatar {
    position: absolute;
    top: 0;
    left: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--nga-secondary-color, #f6ad55);
    color: var(--sidebar-section-title-bg);
    border: 2px solid var(--nga-secondary-color, #f6ad55);
}

.sidebar-avatar-initials {
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    user-select: none;
}

.sidebar-default-avatar i {
    font-size: 24px;
    color: var(--sidebar-section-title-bg);
}

.sidebar-user-info:hover .sidebar-profile-photo,
.sidebar-user-info:hover .sidebar-default-avatar {
    transform: scale(1.1);
    border-color: var(--sidebar-active-text);
}

/* Menu dropdown do usuário */
/* Seletor mais específico para sobrescrever .dropdown-menu de nga-unified.css */
.sidebar-user-menu.dropdown-menu {
    min-width: 280px;
    max-width: 320px;
    background: #ffffff !important;
    background-color: #ffffff !important;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    margin-top: 0.5rem;
    padding: 0.5rem 0;
}

.sidebar-user-menu.dropdown-menu .dropdown-header {
    color: #64748b !important;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.75rem 1rem 0.5rem;
    background: #f8fafc !important;
    margin-bottom: 0.25rem;
}

.sidebar-user-menu.dropdown-menu .dropdown-item,
.sidebar-user-menu.dropdown-menu li a {
    color: #334155 !important;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-user-menu.dropdown-menu .dropdown-item i {
    width: 18px;
    text-align: center;
    color: #64748b !important;
}

.sidebar-user-menu.dropdown-menu .dropdown-item:hover,
.sidebar-user-menu.dropdown-menu li a:hover {
    background: #f1f5f9 !important;
    color: var(--nga-primary-color, #667eea) !important;
    padding-left: 1.25rem;
}

.sidebar-user-menu.dropdown-menu .dropdown-item:hover i {
    color: var(--nga-primary-color, #667eea) !important;
}

.sidebar-user-menu.dropdown-menu .dropdown-item.text-danger:hover {
    background: #fee2e2 !important;
    color: #dc2626 !important;
}

.sidebar-user-menu.dropdown-menu .dropdown-item.text-danger:hover i {
    color: #dc2626 !important;
}

.sidebar-user-menu.dropdown-menu .dropdown-divider {
    margin: 0.5rem 0;
    border-color: #e2e8f0 !important;
    border-top: 1px solid #e2e8f0 !important;
}

.sidebar-user-menu.dropdown-menu form {
    margin: 0;
}

.sidebar-user-menu.dropdown-menu button.dropdown-item {
    width: 100%;
    text-align: left;
    background: transparent !important;
    border: none;
    cursor: pointer;
}

/* ========================================
   SIDEBAR COLLAPSED STATE
   ======================================== */
.sidebar-wrapper.collapsed .sidebar-brand-text,
.sidebar-wrapper.collapsed .sidebar-section-title span,
.sidebar-wrapper.collapsed .sidebar-link span,
.sidebar-wrapper.collapsed .sidebar-sublink span,
.sidebar-wrapper.collapsed .sidebar-arrow,
.sidebar-wrapper.collapsed .sidebar-user-name,
.sidebar-wrapper.collapsed .sidebar-user-arrow {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

.sidebar-wrapper.collapsed .sidebar-dropdown-toggle .sidebar-arrow,
.sidebar-wrapper.collapsed .sidebar-section-title .sidebar-arrow {
    display: none;
}

.sidebar-wrapper.collapsed .sidebar-user-info {
    justify-content: center;
    padding: 0.5rem 0;
}

.sidebar-wrapper.collapsed .sidebar-profile-photo-container,
.sidebar-wrapper.collapsed .sidebar-profile-photo,
.sidebar-wrapper.collapsed .sidebar-default-avatar {
    width: 42px;
    height: 42px;
}

.sidebar-wrapper.collapsed .sidebar-avatar-initials {
    font-size: 18px;
}

/* Posicionar dropdown à direita quando sidebar colapsada */
.sidebar-wrapper.collapsed .sidebar-user-menu {
    position: fixed !important;
    bottom: 1rem;
    left: calc(var(--sidebar-collapsed-width) + 10px) !important;
    right: auto !important;
    transform: none !important;
}

/* ========================================
   MOBILE
   ======================================== */
.sidebar-toggle-mobile {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 1060;
    background: var(--nga-primary-color, #667eea);
    color: white;
    border: none;
    border-radius: 50%;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    cursor: pointer;
}

.sidebar-toggle-mobile i {
    font-size: 1.5rem;
}

.offcanvas.offcanvas-start {
    width: 280px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
}

.offcanvas-header {
    background: var(--sidebar-section-title-bg);
    border-bottom: 1px solid var(--sidebar-border);
}

.offcanvas-title {
    color: var(--sidebar-active-text);
    font-weight: 700;
}

.offcanvas .btn-close {
    filter: invert(1);
}

/* Offcanvas Sidebar com Footer Fixo no Bottom */
#offcanvasSidebar .offcanvas-body {
    display: flex;
    flex-direction: column;
    padding: 0;
}

#offcanvasSidebar .sidebar-nav {
    flex: 1;
    overflow-y: auto;
}

#offcanvasSidebar .sidebar-footer {
    border-top: 1px solid var(--sidebar-border);
    background: var(--sidebar-section-title-bg);
    margin-top: auto;
}

/* Dropdown do usuário no offcanvas - abrir para cima */
#offcanvasSidebar .sidebar-user-menu {
    bottom: 100% !important;
    top: auto !important;
    left: 0 !important;
    right: 0 !important;
    transform: none !important;
    margin-bottom: 0.5rem;
    max-height: 60vh;
    overflow-y: auto;
}

/* ========================================
   RESPONSIVIDADE
   ======================================== */
@media (max-width: 991.98px) {
    .sidebar-wrapper {
        display: none;
    }

    .main-wrapper {
        margin-left: 0;
        width: 100%;
    }
}

@media (min-width: 992px) {
    .sidebar-toggle-mobile {
        display: none;
    }
}

/* ========================================
   PRINT
   ======================================== */
@media print {
    .sidebar-wrapper,
    .sidebar-toggle-mobile {
        display: none !important;
    }

    .main-wrapper {
        margin-left: 0 !important;
        width: 100% !important;
    }
}
