/**
 * ============================================================================
 * SISTEMA CST-ERP — SIDEBAR DINÁMICO & MODULAR CON SUBMENÚS TIPO ACORDEÓN
 * Módulo: sidebar.css
 * Estándar: Arquitectura de 4 Cuadrantes & Navegación Lateral Multi-Tenant
 * ============================================================================
 */

:root {
    --ari-header-height: 64px;
    --ari-sidebar-expanded: 260px;
    --ari-sidebar-collapsed: 70px;
    --ari-sidebar-bg: #090d16;
    --ari-sidebar-border: rgba(234, 179, 8, 0.15);
    --ari-sidebar-surface: #0f172a;
    --ari-sidebar-accent: #eab308;
    --ari-gold: #eab308;
    --ari-gold-light: #facc15;
}

/* ==========================================================================
   ARQUITECTURA DE CONTENEDOR FLEX PRINCIPAL
   ========================================================================== */
#wrapper {
    display: flex;
    min-height: 100vh;
    width: 100%;
    overflow-x: hidden;
}

/* ==========================================================================
   SECCIÓN 1 & 3: SIDEBAR LATERAL DINÁMICO
   ========================================================================== */
#sidebar-wrapper {
    width: var(--ari-sidebar-expanded);
    min-width: var(--ari-sidebar-expanded);
    max-width: var(--ari-sidebar-expanded);
    min-height: 100vh;
    background: var(--ari-sidebar-bg);
    border-right: 1px solid var(--ari-sidebar-border);
    display: flex;
    flex-direction: column;
    transition:
        width 0.28s cubic-bezier(0.4, 0, 0.2, 1),
        min-width 0.28s cubic-bezier(0.4, 0, 0.2, 1),
        max-width 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-x: hidden;
    overflow-y: auto;
    white-space: nowrap;
    position: relative;
    z-index: 1030;
    flex-shrink: 0;
}

/* SECCIÓN 1: Cabecera del Sidebar (64px exactos) */
.ari-sidebar-heading {
    height: var(--ari-header-height) !important;
    min-height: var(--ari-header-height) !important;
    max-height: var(--ari-header-height) !important;
    padding: 0 1rem !important;
    box-sizing: border-box !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    border-bottom: 1px solid var(--ari-sidebar-border) !important;
    background: linear-gradient(135deg, rgba(9, 13, 22, 0.98), rgba(15, 23, 42, 0.95)) !important;
    flex-shrink: 0;
    transition: padding 0.25s ease, justify-content 0.25s ease;
}

.ari-sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    text-decoration: none !important;
    overflow: hidden;
    white-space: nowrap;
    min-width: 0;
}

.ari-sidebar-brand-logo {
    height: 36px;
    width: 36px;
    object-fit: contain;
    flex-shrink: 0;
    border-radius: 8px;
    transition: transform 0.2s ease;
}

.ari-sidebar-brand:hover .ari-sidebar-brand-logo {
    transform: scale(1.08) rotate(-2deg);
}

.ari-sidebar-brand-text {
    font-weight: 800;
    font-size: 1.05rem;
    letter-spacing: 0.04em;
    white-space: nowrap;
    overflow: hidden;
    background: linear-gradient(135deg, #fef08a 0%, #eab308 50%, #ca8a04 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.ari-sidebar-brand-text.brand-sistema {
    background: linear-gradient(135deg, #facc15 0%, #ca8a04 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Botón Toggle en Cabecera */
.ari-sidebar-toggle {
    background: transparent !important;
    border: none !important;
    color: #94a3b8 !important;
    padding: 0.4rem !important;
    border-radius: 8px !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: color 0.2s ease, background-color 0.2s ease, transform 0.2s ease !important;
    flex-shrink: 0;
}

.ari-sidebar-toggle:hover {
    color: #facc15 !important;
    background: rgba(234, 179, 8, 0.12) !important;
    transform: scale(1.05);
}

.ari-sidebar-toggle .bi {
    font-size: 1.35rem;
}

/* SECCIÓN 3: Lista de Navegación del Sidebar */
.ari-sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.75rem 0.5rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(56, 189, 248, 0.25) transparent;
}

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

.ari-sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.ari-sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(56, 189, 248, 0.25);
    border-radius: 2px;
}

/* Títulos de Sección */
.ari-sidebar-section {
    color: #64748b !important;
    font-size: 0.7rem !important;
    font-weight: 800 !important;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 0.85rem 0.75rem 0.35rem !important;
    transition: opacity 0.2s ease;
    overflow: hidden;
    white-space: nowrap;
}

.ari-sidebar-divider {
    display: none; /* visible solo en modo colapsado */
    border: 0 !important;
    border-top: 1px solid rgba(255, 255, 255, 0.1) !important;
    margin: 0.45rem auto !important;
    width: 60% !important;
}

/* Ítems de Navegación Genéricos */
.ari-nav-item {
    display: flex !important;
    align-items: center !important;
    gap: 0.7rem !important;
    padding: 0.52rem 0.75rem !important;
    border-radius: 8px !important;
    margin-bottom: 0.15rem !important;
    text-decoration: none !important;
    color: #cbd5e1 !important;
    font-size: 0.875rem !important;
    font-weight: 500 !important;
    transition:
        background-color 0.18s ease,
        color 0.18s ease,
        border-left-color 0.18s ease,
        transform 0.12s ease !important;
    white-space: nowrap;
    overflow: hidden;
    border-left: 3px solid transparent !important;
    position: relative;
}

.ari-nav-item:hover {
    background-color: rgba(234, 179, 8, 0.1) !important;
    color: #facc15 !important;
    border-left-color: #eab308 !important;
    transform: translateX(2px) !important;
}

.ari-nav-item.active {
    background: linear-gradient(90deg, rgba(234, 179, 8, 0.22) 0%, rgba(15, 23, 42, 0.4) 100%) !important;
    border-left-color: #facc15 !important;
    color: #fef08a !important;
    font-weight: 700 !important;
    transform: none !important;
}

.ari-nav-icon {
    font-size: 1.15rem;
    flex-shrink: 0;
    transition: font-size 0.2s ease, transform 0.2s ease;
    width: 1.3rem;
    text-align: center;
}

.ari-nav-text {
    transition: opacity 0.15s ease;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

/* ==========================================================================
   GRUPOS COLAPSABLES Y SUBMENÚS (ACORDEÓN DINÁMICO)
   ========================================================================== */
.ari-nav-group {
    margin-bottom: 0.25rem;
}

/* Encabezado/Toggle del Grupo */
.ari-group-toggle {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    cursor: pointer;
    background: transparent;
    user-select: none;
    width: 100%;
    border: none;
    text-align: left;
}

.ari-group-header {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    overflow: hidden;
    min-width: 0;
}

/* Chevron animado */
.ari-group-chevron {
    font-size: 0.75rem;
    color: #64748b;
    transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1), color 0.18s ease;
    flex-shrink: 0;
    margin-left: auto;
    margin-right: 0.15rem;
}

/* Cuando el grupo está expandido */
.ari-group-toggle[aria-expanded="true"] .ari-group-chevron,
.ari-group-toggle:not(.collapsed) .ari-group-chevron {
    transform: rotate(90deg);
    color: #38bdf8;
}

.ari-group-toggle[aria-expanded="true"] {
    background-color: rgba(255, 255, 255, 0.03) !important;
}

/* Contenedor del Submenú */
.ari-submenu-collapse {
    position: relative;
    padding-left: 0.75rem;
    margin-left: 0.65rem;
    margin-top: 0.15rem;
    margin-bottom: 0.35rem;
    border-left: 1px dashed rgba(56, 189, 248, 0.25);
    transition: height 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Ítems del Submenú */
.ari-nav-subitem {
    font-size: 0.825rem !important;
    padding: 0.42rem 0.65rem !important;
    margin-bottom: 0.1rem !important;
    gap: 0.55rem !important;
    border-radius: 6px !important;
    color: #94a3b8 !important;
}

.ari-nav-subitem .ari-nav-icon {
    font-size: 0.95rem !important;
    width: 1.1rem !important;
}

.ari-nav-subitem:hover {
    color: #ffffff !important;
    background-color: rgba(14, 165, 233, 0.1) !important;
}

.ari-nav-subitem.active {
    color: #38bdf8 !important;
    background-color: rgba(14, 165, 233, 0.15) !important;
    font-weight: 700 !important;
    border-left-color: #0ea5e9 !important;
}

/* ==========================================================================
   ACENTOS CROMÁTICOS POR DOMINIO / MÓDULO
   ========================================================================== */
.ari-nav-item.accent-sistema:hover     { color: #fca5a5 !important; border-left-color: #ef4444 !important; background-color: rgba(239, 68, 68, 0.08) !important; }
.ari-nav-item.accent-admin:hover       { color: #93c5fd !important; border-left-color: #3b82f6 !important; background-color: rgba(59, 130, 246, 0.08) !important; }
.ari-nav-item.accent-inventarios:hover { color: #86efac !important; border-left-color: #10b981 !important; background-color: rgba(16, 185, 129, 0.08) !important; }
.ari-nav-item.accent-compras:hover     { color: #67e8f9 !important; border-left-color: #06b6d4 !important; background-color: rgba(6, 182, 212, 0.08) !important; }
.ari-nav-item.accent-ventas:hover      { color: #fde047 !important; border-left-color: #f59e0b !important; background-color: rgba(245, 158, 11, 0.08) !important; }
.ari-nav-item.accent-taller:hover      { color: #fdba74 !important; border-left-color: #f97316 !important; background-color: rgba(249, 115, 22, 0.08) !important; }
.ari-nav-item.accent-hoteleria:hover   { color: #d8b4fe !important; border-left-color: #a855f7 !important; background-color: rgba(168, 85, 247, 0.08) !important; }
.ari-nav-item.accent-finanzas:hover     { color: #fde047 !important; border-left-color: #f59e0b !important; background-color: rgba(245, 158, 11, 0.08) !important; }
.ari-nav-item.accent-contabilidad:hover { color: #86efac !important; border-left-color: #10b981 !important; background-color: rgba(16, 185, 129, 0.08) !important; }
.ari-nav-item.accent-reportes:hover     { color: #f472b6 !important; border-left-color: #ec4899 !important; background-color: rgba(236, 72, 153, 0.08) !important; }
.ari-nav-item.accent-rrhh:hover         { color: #bef264 !important; border-left-color: #84cc16 !important; background-color: rgba(132, 204, 22, 0.08) !important; }
.ari-nav-item.accent-soportin:hover     { color: #5eead4 !important; border-left-color: #14b8a6 !important; background-color: rgba(20, 184, 166, 0.08) !important; }

/* ==========================================================================
   FOOTER DE USUARIO EN SIDEBAR
   ========================================================================== */
.ari-sidebar-user {
    border-top: 1px solid var(--ari-sidebar-border);
    padding: 0.8rem 1rem;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.75rem;
    flex-shrink: 0;
    background: rgba(9, 13, 22, 0.95);
    overflow: hidden;
    margin-top: auto;
}

.ari-user-info {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    overflow: hidden;
    min-width: 0;
    flex-grow: 1;
}

.ari-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.85rem;
    flex-shrink: 0;
    background: linear-gradient(135deg, #facc15 0%, #ca8a04 100%);
    color: #090d16;
    border: 1.5px solid rgba(250, 204, 21, 0.45);
    box-shadow: 0 2px 10px rgba(234, 179, 8, 0.35);
}

.ari-user-details {
    overflow: hidden;
    min-width: 0;
    transition: opacity 0.2s ease;
}

.ari-user-name {
    font-weight: 700;
    font-size: 0.8rem;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.ari-user-badge {
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ari-sidebar-accent);
    line-height: 1;
    margin-top: 2px;
    display: block;
}

.ari-logout-btn {
    background: transparent !important;
    border: 1px solid rgba(239, 68, 68, 0.3) !important;
    color: rgba(239, 68, 68, 0.8) !important;
    border-radius: 6px !important;
    padding: 0.3rem 0.45rem !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: all 0.2s ease !important;
    flex-shrink: 0;
    text-decoration: none !important;
}

.ari-logout-btn:hover {
    background: rgba(239, 68, 68, 0.15) !important;
    color: #f87171 !important;
    border-color: rgba(239, 68, 68, 0.6) !important;
    transform: scale(1.05);
}

/* ==========================================================================
   SECCIÓN 2 & 4: ÁREA DE CONTENIDO & TOP NAVBAR
   ========================================================================== */
#page-content-wrapper {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background-color: var(--background);
    overflow-x: hidden;
}

.top-navbar-ari {
    height: var(--ari-header-height) !important;
    min-height: var(--ari-header-height) !important;
    max-height: var(--ari-header-height) !important;
    background: rgba(9, 13, 22, 0.95) !important;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--ari-sidebar-border) !important;
    padding: 0 1.25rem !important;
    display: flex !important;
    align-items: center !important;
    box-sizing: border-box !important;
    position: sticky;
    top: 0;
    z-index: 1020;
}

.top-navbar-ari .container-fluid {
    height: 100% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
}

.ari-mobile-sidebar-toggle {
    background: transparent !important;
    border: none !important;
    color: #38bdf8 !important;
    padding: 0.35rem !important;
    border-radius: 6px !important;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: color 0.2s ease, background-color 0.2s ease !important;
    flex-shrink: 0;
}

.ari-mobile-sidebar-toggle:hover {
    color: #7dd3fc !important;
    background: rgba(14, 165, 233, 0.12) !important;
}

/* ==========================================================================
   ESTADO COLAPSADO — MINI SIDEBAR (70px, solo iconos + tooltips)
   ========================================================================== */
#sidebar-wrapper.collapsed,
html.ari-sidebar-collapsed #sidebar-wrapper {
    width: var(--ari-sidebar-collapsed) !important;
    min-width: var(--ari-sidebar-collapsed) !important;
    max-width: var(--ari-sidebar-collapsed) !important;
}

/* Cabecera en modo colapsado */
#sidebar-wrapper.collapsed .ari-sidebar-heading,
html.ari-sidebar-collapsed #sidebar-wrapper .ari-sidebar-heading {
    justify-content: center !important;
    padding: 0 !important;
}

#sidebar-wrapper.collapsed .ari-sidebar-brand,
html.ari-sidebar-collapsed #sidebar-wrapper .ari-sidebar-brand {
    display: none !important;
}

#sidebar-wrapper.collapsed .ari-sidebar-toggle,
html.ari-sidebar-collapsed #sidebar-wrapper .ari-sidebar-toggle {
    display: flex !important;
    margin: 0 auto !important;
}

/* Ocultar títulos de sección en modo colapsado */
#sidebar-wrapper.collapsed .ari-sidebar-section,
html.ari-sidebar-collapsed #sidebar-wrapper .ari-sidebar-section {
    opacity: 0 !important;
    height: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
}

#sidebar-wrapper.collapsed .ari-sidebar-divider,
html.ari-sidebar-collapsed #sidebar-wrapper .ari-sidebar-divider {
    display: block !important;
}

/* Nav items en modo colapsado */
#sidebar-wrapper.collapsed .ari-sidebar-nav,
html.ari-sidebar-collapsed #sidebar-wrapper .ari-sidebar-nav {
    padding-left: 0.3rem !important;
    padding-right: 0.3rem !important;
}

#sidebar-wrapper.collapsed .ari-nav-item,
html.ari-sidebar-collapsed #sidebar-wrapper .ari-nav-item {
    justify-content: center !important;
    padding: 0.7rem 0 !important;
    gap: 0 !important;
    border-left: 3px solid transparent !important;
    transform: none !important;
}

#sidebar-wrapper.collapsed .ari-nav-item.active,
html.ari-sidebar-collapsed #sidebar-wrapper .ari-nav-item.active {
    background: rgba(14, 165, 233, 0.2) !important;
    border-left: 3px solid #0ea5e9 !important;
}

#sidebar-wrapper.collapsed .ari-nav-item:hover,
html.ari-sidebar-collapsed #sidebar-wrapper .ari-nav-item:hover {
    transform: scale(1.1) !important;
}

#sidebar-wrapper.collapsed .ari-nav-icon,
html.ari-sidebar-collapsed #sidebar-wrapper .ari-nav-icon {
    font-size: 1.3rem !important;
    width: auto !important;
    margin-right: 0 !important;
}

#sidebar-wrapper.collapsed .ari-nav-text,
html.ari-sidebar-collapsed #sidebar-wrapper .ari-nav-text {
    display: none !important;
}

/* Ocultar chevrons y submenús en modo colapsado */
#sidebar-wrapper.collapsed .ari-group-chevron,
html.ari-sidebar-collapsed #sidebar-wrapper .ari-group-chevron {
    display: none !important;
}

#sidebar-wrapper.collapsed .ari-group-header,
html.ari-sidebar-collapsed #sidebar-wrapper .ari-group-header {
    justify-content: center !important;
    width: 100% !important;
    gap: 0 !important;
}

#sidebar-wrapper.collapsed .ari-submenu-collapse,
html.ari-sidebar-collapsed #sidebar-wrapper .ari-submenu-collapse {
    display: none !important;
}

#sidebar-wrapper.collapsed .ari-nav-group,
html.ari-sidebar-collapsed #sidebar-wrapper .ari-nav-group {
    margin-bottom: 0.1rem;
}

/* Footer de usuario en modo colapsado */
#sidebar-wrapper.collapsed .ari-sidebar-user,
html.ari-sidebar-collapsed #sidebar-wrapper .ari-sidebar-user {
    flex-direction: column !important;
    justify-content: center !important;
    padding: 0.6rem 0 !important;
    gap: 0.4rem !important;
}

#sidebar-wrapper.collapsed .ari-user-details,
html.ari-sidebar-collapsed #sidebar-wrapper .ari-user-details {
    display: none !important;
}

/* ==========================================================================
   RESPONSIVE MOBILE (< 992px) — DRAWER CON OVERLAY
   ========================================================================== */
@media (max-width: 991.98px) {
    .ari-mobile-sidebar-toggle {
        display: flex !important;
    }

    #sidebar-wrapper {
        position: fixed !important;
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 1045;
        transform: translateX(-100%);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1) !important;
        width: var(--ari-sidebar-expanded) !important;
        min-width: var(--ari-sidebar-expanded) !important;
        max-width: var(--ari-sidebar-expanded) !important;
    }

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

    #ari-sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.65);
        z-index: 1044;
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
    }

    #ari-sidebar-overlay.active {
        display: block;
    }
}
