/**
 * Sidebar - Estilos Mejorados
 * App Closers - Sistema de navegación lateral
 */

/* ============================================
   VARIABLES DE SIDEBAR
   ============================================ */
:root {
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 72px;
    --sidebar-bg: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    --sidebar-border: #e2e8f0;
    --sidebar-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    
    /* Section titles */
    --section-color: #64748b;
    --section-bg: transparent;
    
    /* Items */
    --item-color: #475569;
    --item-hover-bg: #f1f5f9;
    --item-hover-color: #1e293b;
    --item-active-bg: linear-gradient(90deg, rgba(59, 130, 246, 0.08) 0%, rgba(59, 130, 246, 0.03) 100%);
    --item-active-color: #2563eb;
    --item-active-indicator: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
    
    /* Footer */
    --footer-bg: #f8fafc;
    --footer-border: #e2e8f0;
    
    /* Transitions */
    --sidebar-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================
   CONTENEDOR PRINCIPAL
   ============================================ */
.sidebar-container {
    position: fixed;
    top: 64px; /* altura del navbar */
    left: 0;
    z-index: 40;
    width: var(--sidebar-width);
    height: calc(100vh - 64px);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    box-shadow: var(--sidebar-shadow);
    transition: width var(--sidebar-transition), transform var(--sidebar-transition);
    overflow: hidden;
    /* Asegurar que nada desborde */
    contain: layout style paint;
}

.sidebar-inner {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* ============================================
   HEADER CON TOGGLE
   ============================================ */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 12px 16px;
    border-bottom: 1px solid var(--sidebar-border);
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(8px);
}

.sidebar-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: #64748b;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.sidebar-toggle-btn:hover {
    background: #f1f5f9;
    color: #1e293b;
}

.sidebar-toggle-btn svg {
    transition: transform var(--sidebar-transition);
}

/* ============================================
   NAVEGACIÓN
   ============================================ */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 0;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

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

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

.sidebar-nav::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

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

/* ============================================
   SECCIONES / TÍTULOS
   ============================================ */
.sidebar-section {
    margin-top: 20px;
    margin-bottom: 8px;
    padding: 0 12px;
}

.sidebar-section:first-child {
    margin-top: 12px;
}

.sidebar-section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: #94a3b8;
    transition: all var(--sidebar-transition);
    white-space: nowrap;
    overflow: hidden;
}

.sidebar-section-title::before {
    content: '';
    flex: 0 0 8px;
    height: 2px;
    background: linear-gradient(90deg, #cbd5e1 0%, transparent 100%);
    border-radius: 1px;
}

.sidebar-section-title::after {
    content: '';
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, transparent 0%, #e2e8f0 50%, transparent 100%);
}

.section-text {
    flex-shrink: 0;
    transition: opacity var(--sidebar-transition);
}

/* Badge en título de sección */
.section-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    font-size: 10px;
    font-weight: 700;
    color: white;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    border-radius: 9px;
    margin-left: auto;
    box-shadow: 0 1px 3px rgba(239, 68, 68, 0.3);
}

/* Featured item (Dashboard) */
.sidebar-item-featured {
    margin-bottom: 4px;
}

.sidebar-item-featured .item-icon svg {
    color: #3b82f6;
}

.sidebar-item-featured:not(.active):hover .item-icon svg {
    color: #2563eb;
}

/* ============================================
   ITEMS DE NAVEGACIÓN - Scoped al sidebar
   ============================================ */
.sidebar-container .sidebar-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 2px 12px;
    padding: 10px 12px;
    color: var(--item-color);
    text-decoration: none;
    border-radius: 10px;
    transition: all 0.2s ease;
    overflow: visible; /* Cambiado de hidden a visible para que los badges se vean */
}

.sidebar-container .sidebar-item:hover {
    background: var(--item-hover-bg);
    color: var(--item-hover-color);
    transform: translateX(2px);
}

.sidebar-container .sidebar-item:hover .item-icon {
    transform: scale(1.1);
}

.sidebar-container .sidebar-item:hover .item-icon svg {
    color: #3b82f6;
}

/* Estado activo */
.sidebar-container .sidebar-item.active {
    background: var(--item-active-bg);
    color: var(--item-active-color);
    font-weight: 600;
}

.sidebar-container .sidebar-item.active .item-indicator {
    opacity: 1;
    transform: translateY(-50%) scaleY(1);
}

.sidebar-container .sidebar-item.active .item-icon svg {
    color: var(--item-active-color);
}

/* Indicador lateral - Solo dentro del sidebar */
.sidebar-container .item-indicator {
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%) scaleY(0);
    width: 4px;
    height: 24px;
    background: var(--item-active-indicator);
    border-radius: 0 4px 4px 0;
    opacity: 0;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Icono - Scoped al sidebar */
.sidebar-container .item-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.sidebar-container .item-icon svg {
    width: 20px;
    height: 20px;
    color: #94a3b8;
    transition: color 0.2s ease;
}

/* Texto - Scoped al sidebar */
.sidebar-container .item-text {
    flex: 1;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity var(--sidebar-transition);
}

/* Badge de notificaciones - Flotante */
.sidebar-container .sidebar-item .notification-badge {
    position: absolute !important;
    top: 4px !important;
    right: 6px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-width: 20px !important;
    height: 20px !important;
    padding: 0 6px !important;
    font-size: 11px !important;
    font-weight: 700 !important;
    color: white !important;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%) !important;
    border-radius: 10px !important;
    box-shadow: 0 2px 4px rgba(239, 68, 68, 0.3) !important;
    animation: pulse-badge 2s infinite;
    flex-shrink: 0 !important;
    z-index: 100 !important;
    border: 2px solid white !important;
    line-height: 1 !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Variante Warning (amarillo/naranja) */
.sidebar-container .sidebar-item .notification-badge.badge-warning {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%) !important;
    box-shadow: 0 2px 4px rgba(245, 158, 11, 0.3) !important;
    animation: pulse-badge-warning 2s infinite;
}

/* Variante Danger (rojo) - default */
.sidebar-container .sidebar-item .notification-badge.badge-danger {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%) !important;
    box-shadow: 0 2px 4px rgba(239, 68, 68, 0.3) !important;
    animation: pulse-badge 2s infinite;
}

/* Variante Info (azul) */
.notification-badge.badge-info {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
    animation: pulse-badge-info 2s infinite;
}

/* Variante Success (verde) */
.notification-badge.badge-success {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    box-shadow: 0 2px 4px rgba(34, 197, 94, 0.3);
    animation: none;
}

@keyframes pulse-badge {
    0%, 100% {
        box-shadow: 0 2px 4px rgba(239, 68, 68, 0.3);
    }
    50% {
        box-shadow: 0 2px 8px rgba(239, 68, 68, 0.5);
    }
}

@keyframes pulse-badge-warning {
    0%, 100% {
        box-shadow: 0 2px 4px rgba(245, 158, 11, 0.3);
    }
    50% {
        box-shadow: 0 2px 8px rgba(245, 158, 11, 0.5);
    }
}

@keyframes pulse-badge-info {
    0%, 100% {
        box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
    }
    50% {
        box-shadow: 0 2px 8px rgba(59, 130, 246, 0.5);
    }
}

/* ============================================
   FOOTER DEL USUARIO
   ============================================ */
.sidebar-footer {
    padding: 12px;
    background: var(--footer-bg);
    border-top: 1px solid var(--footer-border);
}

.user-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    transition: all var(--sidebar-transition);
}

.user-avatar {
    position: relative;
    flex-shrink: 0;
}

.avatar-img {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    object-fit: cover;
}

.avatar-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    font-size: 14px;
    font-weight: 700;
    color: white;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    border-radius: 10px;
}

.status-dot {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 12px;
    height: 12px;
    background: #22c55e;
    border: 2px solid white;
    border-radius: 50%;
}

.user-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    transition: opacity var(--sidebar-transition);
}

.user-name {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: #1e293b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-role {
    display: block;
    font-size: 12px;
    color: #64748b;
}

.user-actions {
    display: flex;
    gap: 4px;
    transition: opacity var(--sidebar-transition);
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    color: #64748b;
    background: #f1f5f9;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.action-btn:hover {
    background: #e2e8f0;
    color: #1e293b;
}

.action-btn-danger:hover {
    background: #fef2f2;
    color: #dc2626;
}

/* ============================================
   SIDEBAR COLAPSADA
   ============================================ */
.sidebar-container.collapsed {
    width: var(--sidebar-collapsed-width);
}

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

.sidebar-container.collapsed .section-text,
.sidebar-container.collapsed .section-badge,
.sidebar-container.collapsed .item-text,
.sidebar-container.collapsed .user-info,
.sidebar-container.collapsed .user-actions {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

/* Badge flotante visible incluso cuando está colapsado */
.sidebar-container.collapsed .sidebar-item .notification-badge {
    opacity: 1 !important;
    width: auto !important;
    display: inline-flex !important;
    top: 4px !important;
    right: 4px !important;
    min-width: 18px !important;
    height: 18px !important;
    font-size: 10px !important;
    padding: 0 4px !important;
    visibility: visible !important;
}

.sidebar-container.collapsed .sidebar-section-title {
    justify-content: center;
    padding: 4px 8px;
}

.sidebar-container.collapsed .sidebar-section-title::before,
.sidebar-container.collapsed .sidebar-section-title::after {
    display: none;
}

.sidebar-container.collapsed .sidebar-section {
    margin-top: 12px;
    margin-bottom: 4px;
}

.sidebar-container.collapsed .sidebar-item {
    justify-content: center;
    padding: 12px;
    margin: 4px 8px;
}

.sidebar-container.collapsed .user-card {
    justify-content: center;
    padding: 10px;
}

.sidebar-container.collapsed .item-indicator {
    left: 0;
}

/* ============================================
   TOOLTIP (para modo colapsado)
   ============================================ */
.sidebar-tooltip {
    position: fixed;
    z-index: 9999;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 500;
    color: white;
    background: #1e293b;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    white-space: nowrap;
    opacity: 0;
    transform: translateX(-4px);
    transition: all 0.2s ease;
    pointer-events: none;
}

.sidebar-tooltip.visible {
    opacity: 1;
    transform: translateX(0);
}

.sidebar-tooltip::before {
    content: '';
    position: absolute;
    left: -6px;
    top: 50%;
    transform: translateY(-50%);
    border: 6px solid transparent;
    border-right-color: #1e293b;
}

/* ============================================
   OVERLAY MOBILE
   ============================================ */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 35;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

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

/* ============================================
   RESPONSIVE - MOBILE
   ============================================ */
@media (max-width: 1024px) {
    .sidebar-container {
        transform: translateX(-100%);
    }
    
    .sidebar-container.mobile-open {
        transform: translateX(0);
    }
    
    .sidebar-container.collapsed {
        width: var(--sidebar-width);
    }
}

@media (max-width: 640px) {
    .sidebar-container {
        top: 56px;
        height: calc(100vh - 56px);
        width: 100%;
        max-width: 300px;
    }
}

/* ============================================
   AJUSTE DEL CONTENIDO PRINCIPAL
   ============================================ */

/* Desktop (1025px+): sidebar visible, contenido con margen */
.main-content {
    margin-left: 0;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@media screen and (min-width: 1025px) {
    .main-content {
        margin-left: 280px !important;
    }
    
    body.sidebar-collapsed .main-content {
        margin-left: 72px !important;
    }
}

/* ============================================
   HOVER EFFECTS AVANZADOS - Solo dentro del sidebar
   ============================================ */
.sidebar-container .sidebar-item::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at var(--mouse-x, 50%) var(--mouse-y, 50%), 
                rgba(59, 130, 246, 0.08) 0%, 
                transparent 60%);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    border-radius: inherit;
    z-index: -1;
}

.sidebar-container .sidebar-item:hover::after {
    opacity: 1;
}

/* Tracking mouse position for gradient effect */
.sidebar-container .sidebar-item {
    --mouse-x: 50%;
    --mouse-y: 50%;
}

/* ============================================
   ANIMACIONES DE ENTRADA
   ============================================ */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.sidebar-menu > li {
    animation: slideIn 0.3s ease forwards;
    opacity: 0;
}

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

