/* Sidebar Component - Optimized Design */

/* Base Sidebar */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 1040;
  transition: width var(--transition-smooth);
  overflow: hidden;
}

/* Enhanced Brand Section */
.sidebar-brand {
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  border-bottom: 1px solid var(--border-color);
  transition: all var(--transition-smooth);
  height: var(--navbar-height); /* Misma altura que el navbar */
  background: var(--bg-light);
  position: relative;
}

.sidebar-brand::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(var(--accent-color-rgb), 0.1), transparent);
    transition: left 0.5s ease;
}

.sidebar-brand:hover::before {
    left: 100%;
}

.sidebar-brand:hover {
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-light) 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(var(--accent-color-rgb), 0.1);
}

.sidebar-brand svg {
    min-width: 28px;
    height: 28px;
    flex-shrink: 0;
    transition: all 0.3s ease;
    z-index: 2;
    filter: drop-shadow(0 2px 4px rgba(var(--accent-color-rgb), 0.3));
}

.sidebar-brand:hover svg {
    transform: scale(1.1) rotate(5deg);
    filter: drop-shadow(0 4px 8px rgba(var(--accent-color-rgb), 0.5));
}

.sidebar-brand span {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
    transition: all 0.3s ease;
    position: relative;
    z-index: 2;
    white-space: nowrap;
}

.sidebar-brand:hover span {
    transform: translateX(2px);
}

/* Enhanced Content Area */
.sidebar-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem;
    padding-bottom: 100px;
}

/* Custom Scrollbar */
.sidebar-content::-webkit-scrollbar {
    width: 4px;
}

.sidebar-content::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-content::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.sidebar-content::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Enhanced Navigation Items */
.sidebar-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    color: var(--text-primary);
    text-decoration: none;
    border-radius: 8px;
    margin-bottom: 0.25rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.sidebar-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--accent-color);
    transform: scaleY(0);
    transition: transform 0.3s ease;
}

.sidebar-item:hover {
    background: var(--bg-light);
    color: var(--accent-color);
    transform: translateX(4px);
}

.sidebar-item:hover::before {
    transform: scaleY(1);
}

.sidebar-item.active {
    background: rgba(var(--accent-color-rgb), 0.1);
    color: var(--accent-color);
    font-weight: 500;
}

.sidebar-item.active::before {
    transform: scaleY(1);
}

.sidebar-item i {
    font-size: 1.2rem;
    min-width: 24px;
    width: 24px;
    margin-right: 0.75rem;
    text-align: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.sidebar-item span {
    flex: 1;
    transition: all 0.3s ease;
    white-space: nowrap;
}

/* Enhanced Section Titles */
.nav-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin: 1.5rem 0 0.75rem 0;
    padding: 0 0.5rem;
    text-transform: uppercase;
    transition: all 0.3s ease;
}

/* Enhanced Footer */
.sidebar-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 1rem;
    background: linear-gradient(135deg, var(--bg-light) 0%, var(--bg-secondary) 100%);
    border-top: 1px solid var(--border-color);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.sidebar-footer::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent-color), transparent);
    opacity: 0.3;
}

.footer-buttons {
    display: flex;
    gap: 0.5rem;
    width: 100%;
}

.btn-sidebar-action {
    flex: 1;
    height: 44px;
    padding: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.btn-sidebar-action::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--accent-color);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.btn-sidebar-action:hover::before {
    opacity: 0.1;
}

.btn-sidebar-action:hover {
    border-color: var(--accent-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(var(--accent-color-rgb), 0.2);
}

.btn-sidebar-action:active {
    transform: scale(0.95);
}

.btn-sidebar-action i {
    font-size: 1.1rem;
    color: var(--accent-color);
    position: relative;
    z-index: 1;
    transition: all 0.3s ease;
}

/* ==================== COLLAPSED STATE - CORREGIDO ==================== */
.sidebar.collapsed {
    width: 70px;
}

/* Brand en estado colapsado */
.sidebar.collapsed .sidebar-brand {
    padding: 1.25rem 0.75rem;
    justify-content: center;
}

.sidebar.collapsed .sidebar-brand span {
    opacity: 0;
    visibility: hidden;
    transform: translateX(-20px);
    position: absolute;
}

.sidebar.collapsed .sidebar-brand svg {
    margin: 0;
}

/* Items en estado colapsado - CORREGIDO */
.sidebar.collapsed .sidebar-item {
    padding: 0.75rem;
    justify-content: center;
    position: relative;
    margin-bottom: 0.5rem;
}

.sidebar.collapsed .sidebar-item:hover {
    background: var(--bg-light);
    color: var(--accent-color);
    transform: none; /* Eliminar translateX en estado colapsado */
    border-radius: 8px;
}

.sidebar.collapsed .sidebar-item:hover::before {
    transform: scaleY(1);
}

.sidebar.collapsed .sidebar-item i {
    margin-right: 0;
    font-size: 1.3rem;
    width: auto;
    min-width: auto;
    text-align: center;
}

.sidebar.collapsed .sidebar-item span {
    opacity: 0;
    visibility: hidden;
    transform: translateX(-20px);
    position: absolute;
}

/* Section titles en estado colapsado */
.sidebar.collapsed .nav-section-title {
    opacity: 0;
    visibility: hidden;
    height: 0;
    margin: 0.5rem 0;
    overflow: hidden;
}

/* Footer en estado colapsado - CORREGIDO */
.sidebar.collapsed .footer-buttons {
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
    justify-content: center;
}

.sidebar.collapsed .btn-sidebar-action {
    width: 44px;
    height: 44px;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

/* ==================== TOOLTIPS PARA ESTADO COLAPSADO - MEJORADO ==================== */
.sidebar.collapsed .sidebar-item {
    position: relative;
}

.sidebar.collapsed .sidebar-item:hover::after {
    content: attr(data-tooltip);
    position: fixed;
    left: 85px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    white-space: nowrap;
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
    z-index: 1050;
    pointer-events: none;
    animation: tooltipFade 0.2s ease;
}

@keyframes tooltipFade {
    from {
        opacity: 0;
        transform: translateY(-50%) translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(-50%) translateX(0);
    }
}

/* ==================== THEME TOGGLE CENTRADO - CORREGIDO ==================== */
#theme-toggle {
    position: relative;
    overflow: hidden;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#theme-toggle::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--accent-color);
    opacity: 0;
    transition: opacity 0.3s ease;
}

#theme-toggle:hover::before {
    opacity: 0.1;
}

#theme-toggle:hover {
    border-color: var(--accent-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(var(--accent-color-rgb), 0.2);
}

/* Contenedor de iconos centrado */
.theme-toggle-container {
    position: relative;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Iconos del tema */
.theme-icon-sun,
.theme-icon-moon {
    position: absolute;
    font-size: 1.1rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--text-primary);
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
}

/* Estados del tema - CORREGIDOS */
[data-theme="light"] .theme-icon-sun {
    opacity: 0;
    transform: rotate(180deg) scale(0);
}

[data-theme="light"] .theme-icon-moon {
    opacity: 1;
    transform: rotate(0) scale(1);
    color: var(--accent-color);
}

[data-theme="dark"] .theme-icon-sun {
    opacity: 1;
    transform: rotate(0) scale(1);
    color: #fbbf24;
}

[data-theme="dark"] .theme-icon-moon {
    opacity: 0;
    transform: rotate(-180deg) scale(0);
}

/* Animación del hover */
#theme-toggle:hover .theme-icon-sun,
#theme-toggle:hover .theme-icon-moon {
    transform: scale(1.1);
}

/* ==================== SIDEBAR COLAPSADO - TEMA TOGGLE ==================== */
.sidebar.collapsed #theme-toggle {
    width: 44px;
    height: 44px;
}

.sidebar.collapsed .theme-toggle-container {
    width: 20px;
    height: 20px;
}

/* ==================== RESPONSIVE MEJORADO ==================== */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
        width: 280px;
        box-shadow: none;
    }

    .sidebar.show {
        transform: translateX(0);
        box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);
    }

    .sidebar.collapsed {
        width: 280px;
    }

    .sidebar.collapsed .sidebar-brand span,
    .sidebar.collapsed .sidebar-item span,
    .sidebar.collapsed .nav-section-title {
        opacity: 1;
        visibility: visible;
        transform: translateX(0);
        position: static;
    }

    .sidebar.collapsed .sidebar-item {
        padding: 0.75rem 1rem;
        justify-content: flex-start;
    }

    .sidebar.collapsed .sidebar-item:hover {
        transform: translateX(4px); /* Restaurar en móvil */
    }

    .sidebar.collapsed .sidebar-item i {
        margin-right: 0.75rem;
        font-size: 1.2rem;
    }

    .sidebar.collapsed .footer-buttons {
        flex-direction: row;
    }

    .sidebar.collapsed .btn-sidebar-action {
        width: auto;
        flex: 1;
    }

    .sidebar.collapsed .nav-section-title {
        height: auto;
        margin: 1.5rem 0 0.75rem 0;
        opacity: 1;
        visibility: visible;
    }

    /* Mobile Overlay */
    body.sidebar-open::after {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1039;
        backdrop-filter: blur(4px);
        animation: overlayFade 0.3s ease;
    }

    @keyframes overlayFade {
        from { opacity: 0; }
        to { opacity: 1; }
    }
}

/* ==================== THEME TOGGLE ESPECÍFICO ==================== */
#theme-toggle {
    position: relative;
    overflow: hidden;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Estados del tema - CORREGIDOS */
[data-theme="light"] .theme-icon-sun {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(180deg) scale(0);
}

[data-theme="light"] .theme-icon-moon {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(0) scale(1);
    color: var(--accent-color);
}

/* ==================== FOOTER BUTTONS MEJORADO ==================== */
.footer-buttons {
    display: flex;
    gap: 0.5rem;
    width: 100%;
    align-items: center;
    justify-content: center;
}

.btn-sidebar-action {
    flex: 1;
    height: 44px;
    padding: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.btn-sidebar-action::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--accent-color);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.btn-sidebar-action:hover::before {
    opacity: 0.1;
}

.btn-sidebar-action:hover {
    border-color: var(--accent-color);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(var(--accent-color-rgb), 0.2);
}

.btn-sidebar-action:active {
    transform: scale(0.95);
}

.btn-sidebar-action i {
    font-size: 1.1rem;
    color: var(--accent-color);
    position: relative;
    z-index: 1;
    transition: all 0.3s ease;
}

/* ==================== RESPONSIVE MEJORADO ==================== */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
        width: 280px;
        box-shadow: none;
    }

    .sidebar.show {
        transform: translateX(0);
        box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);
    }

    .sidebar.collapsed {
        width: 280px;
    }

    .sidebar.collapsed .sidebar-brand span,
    .sidebar.collapsed .sidebar-item span,
    .sidebar.collapsed .nav-section-title {
        opacity: 1;
        visibility: visible;
        transform: translateX(0);
        position: static;
    }

    .sidebar.collapsed .sidebar-item {
        padding: 0.75rem 1rem;
        justify-content: flex-start;
    }

    .sidebar.collapsed .sidebar-item:hover {
        transform: translateX(4px); /* Restaurar en móvil */
    }

    .sidebar.collapsed .sidebar-item i {
        margin-right: 0.75rem;
        font-size: 1.2rem;
    }

    .sidebar.collapsed .footer-buttons {
        flex-direction: row;
    }

    .sidebar.collapsed .btn-sidebar-action {
        width: auto;
        flex: 1;
    }

    .sidebar.collapsed .nav-section-title {
        height: auto;
        margin: 1.5rem 0 0.75rem 0;
        opacity: 1;
        visibility: visible;
    }

    /* Mobile Overlay */
    body.sidebar-open::after {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1039;
        backdrop-filter: blur(4px);
        animation: overlayFade 0.3s ease;
    }

    @keyframes overlayFade {
        from { opacity: 0; }
        to { opacity: 1; }
    }
}

/* ==================== THEME TOGGLE ESPECÍFICO ==================== */
#theme-toggle {
    position: relative;
    overflow: hidden;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Estados del tema - CORREGIDOS */
[data-theme="light"] .theme-icon-sun {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(180deg) scale(0);
}

[data-theme="light"] .theme-icon-moon {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(0) scale(1);
    color: var(--accent-color);
}