/* Sidebar Enhancements - Mejoras para el menú lateral */

/* ===== MEJORAS VISUALES PARA SUBMENÚS ===== */

/* Animaciones suaves para submenús */
.submenu {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: top center;
    opacity: 0;
    transform: scaleY(0.95);
    max-height: 0;
    overflow: hidden;
    visibility: hidden;
}

.menu-item.has-submenu.active .submenu {
    opacity: 1 !important;
    transform: scaleY(1);
    max-height: none !important; /* Sin límite para permitir scroll completo */
    visibility: visible !important;
    overflow: visible !important; /* Permitir que todo el contenido sea visible */
}

/* Efecto de sombra para submenús abiertos */
.menu-item.has-submenu.active {
    position: relative;
}

.menu-item.has-submenu.active::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(180deg, rgba(59, 130, 246, 0.3), transparent);
    pointer-events: none;
    z-index: 1;
}

/* ===== INDICADORES DE ESTADO ===== */

/* Mejorar el indicador de submenú */
.submenu-toggle {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.menu-item.has-submenu.active .submenu-toggle {
    transform: rotate(180deg) scale(1.1);
}

/* ===== ACCESIBILIDAD ===== */

/* Enfoque visible para navegación con teclado */
.sidebar .menu-item a:focus {
    outline: 2px solid var(--primary-500);
    outline-offset: 2px;
    background-color: var(--primary-50);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Mejor contraste para items activos */
.menu-item.active a {
    box-shadow: 0 8px 24px rgba(59, 130, 246, 0.25);
    transform: translateX(4px) scale(1.02);
}

/* ===== RESPONSIVE MEJORADO ===== */

/* Ajustes para móviles */
@media (max-width: 768px) {
    .sidebar {
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }
    
    /* Efecto de deslizamiento para móviles */
    .sidebar.show {
        transform: translateX(0) !important;
        box-shadow: 2px 0 20px rgba(0, 0, 0, 0.15);
    }
    
    /* Asegurar que el sidebar esté oculto cuando no tiene la clase show */
    .sidebar:not(.show) {
        transform: translateX(-100%) !important;
    }
    
    /* Submenús en móviles: más grandes para touch */
    .submenu {
        font-size: 0.95rem;
    }
    
    .submenu .menu-item a {
        padding: 1rem 1.5rem;
        min-height: 48px;
        align-items: center;
    }
    
    /* Cerrar submenús al tocar fuera en móviles */
    .sidebar-overlay {
        transition: opacity 0.3s ease;
    }
}

/* ===== ESTADOS DE CARGA ===== */

/* Efecto de carga para items del menú */
.menu-item.loading a {
    opacity: 0.6;
    pointer-events: none;
}

.menu-item.loading a::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 2px;
    background: var(--primary-500);
    animation: loading-progress 1.5s ease-in-out infinite;
}

@keyframes loading-progress {
    0% { width: 0%; }
    50% { width: 100%; }
    100% { width: 0%; }
}

/* ===== TOOLTIPS PARA MÓVILES ===== */

/* Tooltips para items del menú en móviles */
@media (max-width: 768px) {
    /* Submenús en móviles: mostrar dentro del sidebar, no como pantalla completa */
    .menu-item.has-submenu .submenu {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        width: 100% !important;
        height: auto !important;
        background: rgba(0, 0, 0, 0.05) !important;
        z-index: 1 !important;
        transform: none !important;
        max-height: 0 !important;
        overflow: hidden !important;
        opacity: 0 !important;
        visibility: hidden !important;
        transition: max-height 0.3s ease, opacity 0.3s ease, visibility 0.3s ease !important;
        padding: 0 !important;
        margin: 0.5rem 0 0 2rem !important;
        display: block !important;
        pointer-events: auto !important;
    }
    
    .menu-item.has-submenu.active .submenu {
        max-height: none !important; /* Sin límite para permitir scroll completo */
        opacity: 1 !important;
        visibility: visible !important;
        padding: 0.5rem 0 !important;
        transform: none !important;
        display: block !important;
        overflow: visible !important; /* Permitir scroll */
    }
    
    /* Eliminar el pseudo-elemento ::before que causaba problemas */
    .submenu::before {
        display: none !important;
        content: none !important;
    }
    
    /* Asegurar que los items del submenu sean visibles */
    .submenu .menu-item {
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto !important;
        display: list-item !important;
        list-style: none !important;
    }
    
    .submenu .menu-item a {
        opacity: 1 !important;
        visibility: visible !important;
        color: var(--text-primary) !important;
        pointer-events: auto !important;
        display: flex !important;
    }
    
    /* Asegurar que el contenido del submenu sea visible */
    .menu-item.has-submenu.active .submenu .menu-item {
        opacity: 1 !important;
        visibility: visible !important;
        display: list-item !important;
    }
    
    .menu-item.has-submenu.active .submenu .menu-item a {
        opacity: 1 !important;
        visibility: visible !important;
        display: flex !important;
        color: var(--text-primary) !important;
    }
    
    /* Asegurar que el toggle del submenu funcione */
    .submenu-toggle {
        pointer-events: auto !important;
        cursor: pointer !important;
        -webkit-tap-highlight-color: rgba(59, 130, 246, 0.3) !important;
        touch-action: manipulation !important;
        min-width: 44px !important;
        min-height: 44px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    /* Asegurar que los enlaces con submenu sean clickeables */
    .menu-item.has-submenu > a {
        pointer-events: auto !important;
        cursor: pointer !important;
        -webkit-tap-highlight-color: rgba(59, 130, 246, 0.2) !important;
        touch-action: manipulation !important;
    }
}

/* ===== EFECTOS DE HOVER MEJORADOS ===== */

/* Efecto de hover más suave */
.menu-item a:hover {
    transform: translateX(6px);
    background: linear-gradient(135deg, var(--primary-50), rgba(59, 130, 246, 0.05));
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
}

/* Efecto de hover para submenús */
.submenu .menu-item a:hover {
    transform: translateX(8px);
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.08), rgba(59, 130, 246, 0.02));
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.1);
}

/* ===== ESTADOS ESPECIALES ===== */

/* Estado de error para items del menú */
.menu-item.error a {
    border-left: 3px solid var(--error-500);
    background: rgba(239, 68, 68, 0.05);
}

.menu-item.error a:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* Estado de advertencia para items del menú */
.menu-item.warning a {
    border-left: 3px solid var(--warning-500);
    background: rgba(245, 158, 11, 0.05);
}

.menu-item.warning a:hover {
    background: rgba(245, 158, 11, 0.1);
}

/* ===== ANIMACIONES DE ENTRADA ===== */

/* Animación de entrada para el sidebar */
.sidebar {
    animation: slideInLeft 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideInLeft {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Animación de entrada para items del menú */
.menu-item {
    animation: fadeInUp 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    animation-fill-mode: both;
}

.menu-item:nth-child(1) { animation-delay: 0.1s; }
.menu-item:nth-child(2) { animation-delay: 0.15s; }
.menu-item:nth-child(3) { animation-delay: 0.2s; }
.menu-item:nth-child(4) { animation-delay: 0.25s; }
.menu-item:nth-child(5) { animation-delay: 0.3s; }
.menu-item:nth-child(6) { animation-delay: 0.35s; }
.menu-item:nth-child(7) { animation-delay: 0.4s; }
.menu-item:nth-child(8) { animation-delay: 0.45s; }
.menu-item:nth-child(9) { animation-delay: 0.5s; }
.menu-item:nth-child(10) { animation-delay: 0.55s; }
.menu-item:nth-child(11) { animation-delay: 0.6s; }
.menu-item:nth-child(12) { animation-delay: 0.65s; }
.menu-item:nth-child(13) { animation-delay: 0.7s; }
.menu-item:nth-child(14) { animation-delay: 0.75s; }
.menu-item:nth-child(15) { animation-delay: 0.8s; }

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== SCROLLBAR PERSONALIZADO ===== */

/* Scrollbar para el sidebar-menu (donde está el scroll real) */
.sidebar-menu {
    scrollbar-width: thin;
    scrollbar-color: var(--primary-300) transparent;
}

.sidebar-menu::-webkit-scrollbar {
    width: 6px;
}

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

.sidebar-menu::-webkit-scrollbar-thumb {
    background-color: var(--primary-300);
    border-radius: 3px;
    transition: background-color 0.2s ease;
}

.sidebar-menu::-webkit-scrollbar-thumb:hover {
    background-color: var(--primary-500);
}

/* ===== ESTADO DE CARGA DEL SIDEBAR ===== */

/* Overlay de carga para el sidebar */
.sidebar-loading {
    position: relative;
}

.sidebar-loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.sidebar-loading .loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-500);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* ===== ESTILOS PARA EL MODO OSCURO (si se implementa) ===== */

/* Variables para modo oscuro */
:root[data-theme="dark"] {
    --sidebar-bg: #1f2937;
    --sidebar-border: #374151;
    --sidebar-text: #f9fafb;
    --sidebar-text-secondary: #9ca3af;
    --sidebar-hover: #374151;
    --sidebar-active: #3b82f6;
}

/* Aplicar estilos oscuros si existe la clase */
[data-theme="dark"] .sidebar {
    background: var(--sidebar-bg);
    border-right-color: var(--sidebar-border);
}

[data-theme="dark"] .sidebar .menu-item a {
    color: var(--sidebar-text);
    border-bottom-color: var(--sidebar-border);
}

[data-theme="dark"] .sidebar .menu-item a:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text);
}

[data-theme="dark"] .sidebar .menu-item.active a {
    background: var(--sidebar-active);
    color: white;
}

/* ===== MEJORAS PARA EL HEADER DEL SIDEBAR ===== */

/* Header del sidebar con efecto de vidrio */
.sidebar-header {
    backdrop-filter: blur(10px);
    background: rgba(255, 255, 255, 0.9);
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

/* Logo con efecto de brillo */
.logo i {
    position: relative;
    overflow: hidden;
}

.logo i::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(135deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    transform: rotate(45deg);
    animation: shine 3s infinite;
    pointer-events: none;
}

@keyframes shine {
    0% { transform: translateX(-100%) translateY(-100%) rotate(45deg); }
    100% { transform: translateX(100%) translateY(100%) rotate(45deg); }
}

/* ===== ESTILOS PARA EL TOGGLE DEL SIDEBAR ===== */

/* Botón de toggle con efecto de pulsado */
.sidebar-toggle {
    transition: all 0.2s ease;
    position: relative;
}

.sidebar-toggle:active {
    transform: scale(0.95);
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.2);
}

/* Efecto de ripple para el toggle */
.sidebar-toggle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(59, 130, 246, 0.3);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.3s ease, height 0.3s ease;
    pointer-events: none;
}

.sidebar-toggle:active::after {
    width: 40px;
    height: 40px;
    opacity: 0;
}

/* ===== ESTILOS PARA EL OVERLAY MÓVIL ===== */

/* Overlay para móviles con efecto de desvanecimiento */
.sidebar-overlay {
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    transition: opacity 0.3s ease;
}

.sidebar-overlay.show {
    opacity: 1 !important;
    display: block !important;
    visibility: visible !important;
}

.sidebar-overlay:not(.show) {
    opacity: 0 !important;
    pointer-events: none !important;
    display: none !important;
    visibility: hidden !important;
}

/* ===== MEJORAS DE CONTRASTE ===== */

/* Aumentar contraste para mejor accesibilidad */
@media (prefers-contrast: high) {
    .sidebar {
        border-right-width: 2px;
    }
    
    .menu-item a {
        border-bottom-width: 2px;
    }
    
    .menu-item.active a {
        border-left-width: 4px;
    }
}

/* ===== ESTILOS PARA IMPRESIÓN ===== */

/* Ocultar elementos no esenciales al imprimir */
@media print {
    .sidebar {
        display: none !important;
    }
    
    .main-content {
        margin-left: 0 !important;
    }
}