/* Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1), backdrop-filter 0.4s ease-out;
    will-change: opacity, backdrop-filter;
    pointer-events: none;
}

.sidebar-open .sidebar-overlay {
    display: block;
    opacity: 1;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* Menu Toggle Button */
.menu-toggle {
    display: flex !important;
    position: absolute;
    top: 1.5rem;
    left: 1.5rem;
    z-index: 1100;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    border: none;
    border-radius: 14px;
    width: 50px;
    height: 50px;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    padding: 12px 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.2s ease-out, box-shadow 0.3s ease-out;
    box-shadow: 0 4px 20px rgba(43, 108, 176, 0.25);
    -webkit-tap-highlight-color: transparent;
    overflow: hidden;
    outline: none;
    pointer-events: auto !important;
    will-change: transform, box-shadow, background, opacity;
    opacity: 0.9;
}

.menu-toggle span {
    display: block;
    width: 22px;
    height: 2.2px;
    background: white;
    margin: 3.5px 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s ease;
    pointer-events: none;
    transform-origin: center;
    border-radius: 3px;
    will-change: transform, opacity, width, margin;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.menu-toggle:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 24px rgba(43, 108, 176, 0.35);
    background: linear-gradient(135deg, #4a8df8, #2f6fd9);
    opacity: 1;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1), transform 0.2s ease-out;
}

.menu-toggle:active {
    transform: translateY(1px) scale(0.98);
    box-shadow: 0 2px 6px rgba(43, 108, 176, 0.15);
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0.95;
}

.menu-toggle::before {
    position: absolute;
    top: 0;
    left: -100%;
    width: 200%;
    height: 100%;
    background: linear-gradient(90deg, 
        transparent, 
        rgba(255, 255, 255, 0.25), 
        transparent
    );
    transition: transform 0.8s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 1;
}

.menu-toggle:hover::before {
    transform: translateX(50%);
}

/* Ensure the toggle button is always visible and clickable */
.menu-toggle,
.menu-toggle * {
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Hamburger to X animation */
.menu-toggle.active {
    transform: rotate(180deg);
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
}

.menu-toggle.active span:nth-child(1) {
    transform: translateY(2.5px) rotate(45deg);
    background: white;
    width: 20px;
}

.menu-toggle.active span:nth-child(2) {
    opacity: 0;
    transform: scaleX(0.2);
    margin: 0;
    height: 0;
}

.menu-toggle.active span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
    background: white;
    width: 20px;
}

/* Ensure the button is visible on all screen sizes */
.menu-toggle {
    display: fixed !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Main Content */
.content {
    margin-left: 280px;
    padding: 2rem;
    transition: margin-left 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                width 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    width: calc(100% - 280px);
    min-height: 100vh;
    box-sizing: border-box;
    will-change: margin-left, width, transform;
    position: relative;
    z-index: 1;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.sidebar.collapsed + .content {
    margin-left: 80px;
    width: calc(100% - 80px);
}

/* Mobile styles */
@media (max-width: 768px) {
    .menu-toggle {
        display: flex;
        transform: scale(0.9);
        top: 1rem;
        left: 1rem;
    }
    
    .content {
        margin-left: 0;
        width: 100%;
        padding: 1rem;
        transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1) 0.05s,
                    margin-left 0.4s cubic-bezier(0.4, 0, 0.2, 1) 0.05s,
                    width 0.4s cubic-bezier(0.4, 0, 0.2, 1) 0.05s;
        will-change: transform, margin-left, width;
        backface-visibility: hidden;
        -webkit-backface-visibility: hidden;
    }
    
    .sidebar:not(.collapsed) + .content {
        transform: translateX(280px);
        margin-left: -280px;
        width: 100%;
        transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    /* Smooth overlay for mobile */
    .sidebar-overlay {
        display: block;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        will-change: opacity, backdrop-filter;
        -webkit-backdrop-filter: blur(6px);
        backdrop-filter: blur(6px);
        background: rgba(0, 0, 0, 0.4);
    }
    
    .sidebar-open .sidebar-overlay {
        opacity: 1;
        pointer-events: auto;
        transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    }
}

/* Desktop styles */
@media (min-width: 769px) {
    .content {
        margin-left: 70px;
        width: calc(100% - 250px);
        transition: margin-left 0.4s cubic-bezier(0.4, 0, 0.2, 1),
                   width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    sidebar-component::part(sidebar) {
        transform: translateX(0) !important;
    }
}
