/* ============================================
   PORTFOLIOSHIELD DESIGN SYSTEM
   SIDEBAR.CSS - ATOMIC COMPONENT

   Self-contained, namespace-isolated sidebar module
   ⚠️ ALL RULES SCOPED WITH #app-sidebar
   ============================================ */

/* ============================================
   SIDEBAR BASE STRUCTURE
   ============================================ */

#app-sidebar.sidebar {
    width: var(--sidebar-collapsed);
    background: linear-gradient(180deg, #1e1e2f 0%, #16161f 100%);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    z-index: var(--z-sidebar);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    transition: width var(--sidebar-transition);
    overflow-x: hidden;
    font-family: 'Inter', sans-serif;
    font-size: 0.88rem;

    /* Espaciado dinámico basado en viewport height */
    --nav-available-height: calc(100vh - 215px);  /* 88px logo + 127px footer */
    --item-spacing: clamp(0px, calc((var(--nav-available-height) - 540px) / 14), 4px);  /* Espaciado unificado para mantener iconos alineados */
}

#app-sidebar.sidebar.expanded {
    width: var(--sidebar-expanded);
}

/* ============================================
   LOGO AREA
   ============================================ */

#app-sidebar .sidebar-logo {
    height: var(--logo-height);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 9px 0;  /* Solo padding vertical - sin horizontal para centrado perfecto */
    background: linear-gradient(180deg, rgba(16, 185, 129, 0.08) 0%, transparent 100%);
    border-bottom: 1px solid rgba(16, 185, 129, 0.15);
    position: relative;
    overflow: hidden;
}

#app-sidebar .sidebar-logo img {
    width: auto;
    filter: drop-shadow(0 4px 16px rgba(16, 185, 129, 0.35));
    transition: opacity 0.2s ease;
}

#app-sidebar .sidebar-logo .logo-collapsed {
    display: block;
    opacity: 1;
    position: absolute;
    left: 50%;  /* Centrado perfecto horizontal */
    transform: translateX(-50%);
    height: 40px;
}

#app-sidebar .sidebar-logo .logo-expanded {
    display: block;
    opacity: 0;
    position: absolute;
    left: 50%;  /* Centrado perfecto horizontal */
    transform: translateX(-50%);
    pointer-events: none;
    height: 70px;
}

#app-sidebar.sidebar.expanded .logo-collapsed {
    opacity: 0;
    pointer-events: none;
}

#app-sidebar.sidebar.expanded .logo-expanded {
    opacity: 1;
    pointer-events: auto;
}

/* ============================================
   TOGGLE BUTTON
   ============================================ */

#app-sidebar .sidebar-toggle {
    position: absolute;
    top: 86px;
    right: -12px;
    width: 24px;
    height: 24px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    z-index: 10;
}

#app-sidebar .sidebar-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    transform: scale(1.1);
}

#app-sidebar .sidebar-toggle .icon-collapsed {
    display: block;
}

#app-sidebar .sidebar-toggle .icon-expanded {
    display: none;
}

#app-sidebar.sidebar.expanded .sidebar-toggle .icon-collapsed {
    display: none;
}

#app-sidebar.sidebar.expanded .sidebar-toggle .icon-expanded {
    display: block;
}

/* ============================================
   NAVIGATION AREA
   ============================================ */

#app-sidebar .sidebar-nav,
#app-sidebar .nav-content {
    flex: 1;
    padding: 4px 8px;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
    max-height: var(--nav-available-height);  /* Limita la altura al espacio disponible */
}

#app-sidebar .sidebar-nav::-webkit-scrollbar,
#app-sidebar .nav-content::-webkit-scrollbar {
    width: 4px;
}

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

/* Nav Groups */
#app-sidebar .nav-group {
    margin-bottom: 0;
}

#app-sidebar .nav-group:first-child .section-label {
    padding-top: 2px;
}

/* Section Labels */
#app-sidebar .section-label {
    font-size: 10px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.5);
    text-transform: uppercase;
    letter-spacing: 1.1px;
    padding: 0 14px;
    margin-bottom: var(--item-spacing);  /* Espaciado unificado */
    border-bottom: none !important;
    transition: opacity 0.2s ease, height 0.2s ease;
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    /* Tightened header height 24→18px to claw back ~24px total (4 sections) */
    height: 18px;
}

/* Separador: línea que empieza donde termina el texto */
#app-sidebar .section-label::after {
    content: '';
    flex: 1;
    height: 1px;
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.25) 0%,
        rgba(255, 255, 255, 0.15) 50%,
        transparent 100%
    );
}

#app-sidebar.sidebar:not(.expanded) .section-label {
    opacity: 0;
    pointer-events: none;
    /* Mantiene height: 24px y margin-bottom: var(--item-spacing) del estado expandido */
    /* NO cambiar display, height ni margin - solo ocultar visualmente */
}

/* ============================================
   MENU ITEMS
   ============================================ */

#app-sidebar .nav-item,
#app-sidebar .menu-item,
#app-sidebar a.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    /* Tightened just enough for Events to fit without scrolling while
       staying readable. IMPORTANT: padding vertical + min-height must
       match the collapsed state below or icons shift position when the
       sidebar toggles. */
    padding: 6px 14px;
    margin: 0 0 var(--item-spacing) 0;  /* Espaciado unificado - mantiene iconos alineados */
    min-height: 36px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: rgba(255, 255, 255, 0.65);
    font-size: 0.95rem;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    border-left: 3px solid transparent;
}

#app-sidebar .nav-item:hover,
#app-sidebar .menu-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    transform: translateX(2px);
}

#app-sidebar .nav-item.active,
#app-sidebar .menu-item.active,
#app-sidebar a.menu-item.active {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
    border-left-color: #3b82f6;
    box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.2);
}

/* ============================================
   ICONS & LABELS
   ============================================ */

/* Icons */
#app-sidebar .nav-icon,
#app-sidebar .menu-item .icon,
#app-sidebar .i {
    font-size: 18px;
    width: 20px;
    height: 20px;
    text-align: center;
    flex-shrink: 0;
    color: rgba(255, 255, 255, 0.5);
    transition: color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Lucide SVG icons inherit color and size */
#app-sidebar .nav-icon svg.lucide-icon,
#app-sidebar .menu-item .icon svg.lucide-icon {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    stroke-width: 2;
}

#app-sidebar .nav-item:hover .nav-icon,
#app-sidebar .menu-item:hover .icon {
    color: rgba(255, 255, 255, 0.9);
}

#app-sidebar .nav-item.active .nav-icon,
#app-sidebar .menu-item.active .icon {
    color: #3b82f6;
}

/* Labels */
#app-sidebar .nav-label {
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

#app-sidebar.sidebar.expanded .nav-label {
    opacity: 1;
    pointer-events: auto;
}

/* ============================================
   BADGES
   ============================================ */

#app-sidebar .menu-item .badge,
#app-sidebar .nav-item .badge {
    margin-left: auto;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    font-size: 11px;  /* Aumentado de 9px a 11px para mejor legibilidad */
    font-weight: 600;
    padding: 3px 7px;  /* Aumentado proporcionalmente */
    border-radius: 10px;
    min-width: 20px;  /* Aumentado de 18px a 20px */
    text-align: center;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}

#app-sidebar .menu-item .badge.green,
#app-sidebar .nav-item .badge.green {
    background: linear-gradient(135deg, var(--accent-green), #059669);
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}

#app-sidebar .menu-item .badge.alert,
#app-sidebar .nav-item .badge.alert {
    background: linear-gradient(135deg, var(--accent-red), #dc2626);
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}

/* ============================================
   COLLAPSED STATE
   ============================================ */

#app-sidebar.sidebar:not(.expanded) .badge,
#app-sidebar.sidebar:not(.expanded) .nav-label {
    display: none;
}

#app-sidebar.sidebar:not(.expanded) .nav-item,
#app-sidebar.sidebar:not(.expanded) .menu-item {
    /* Padding-top/bottom + min-height MUST match the expanded rule above
       so icons stay in the exact same vertical position when toggling
       between collapsed and expanded. Horizontal padding drops to 0
       since the label is hidden. */
    padding: 6px 0;
    margin: 0 0 var(--item-spacing) 0;
    min-height: 36px;
    border-left: none;
    justify-content: center;
    align-items: center;
    border-radius: 8px;
}

#app-sidebar.sidebar:not(.expanded) .nav-item.active,
#app-sidebar.sidebar:not(.expanded) .menu-item.active {
    background: rgba(59, 130, 246, 0.15);
    box-shadow: inset 3px 0 0 #3b82f6, inset 0 0 0 1px rgba(59, 130, 246, 0.2);  /* Border izquierdo + glow */
}

/* ============================================
   DIVIDERS
   ============================================ */

#app-sidebar .nav-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.08);
    margin: 8px 8px;
}

/* ============================================
   FOOTER
   ============================================ */

#app-sidebar .sidebar-footer {
    padding: 4px 8px 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(0, 0, 0, 0.2);
    margin-top: auto;
}

#app-sidebar .sidebar-footer .menu-item,
#app-sidebar .sidebar-footer .nav-item {
    padding: 6px 14px;
    font-size: 0.875rem;  /* 14px - Más legible */
    margin-bottom: 0;  /* Sin margin en footer - items compactos */
}

/* ============================================
   CONNECTION STATUS
   ============================================ */

#app-sidebar .connection-status {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    margin-top: 2px;
    font-size: 11px;
    color: var(--text-muted);
}

#app-sidebar .status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-yellow);
}

#app-sidebar .status-dot.connected {
    background: var(--accent-green);
}

#app-sidebar .status-dot.error {
    background: var(--accent-red);
}

/* ============================================
   RESPONSIVE (MOBILE)
   ============================================ */

@media (max-width: 768px) {
    #app-sidebar.sidebar {
        transform: translateX(-100%);
    }

    #app-sidebar.sidebar.expanded {
        transform: translateX(0);
    }
}
