/**
 * 侧边栏导航优化样式
 *
 * 使用硬件加速的 CSS 过渡替代 jQuery 动画
 * 提升侧边栏展开/收缩的性能表现
 *
 * @package OneNav
 * @version 1.0.0
 */

/* ========================================
   硬件加速基础设置
   ======================================== */

.sidebar-menu-inner,
.sidebar-item,
.sidebar-item > ul,
.sidebar-item > a,
.sidebar-more {
    /* 启用硬件加速 */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    will-change: auto;
}

/* 仅在动画时启用 will-change */
.sidebar-item.transitioning,
.sidebar-item.transitioning > ul {
    will-change: height, opacity, transform;
}

/* ========================================
   子菜单展开/收缩动画（CSS 过渡替代 jQuery）
   ======================================== */

.sidebar-item > ul {
    display: block !important;
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    visibility: hidden;
    -webkit-transition: max-height 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                        opacity 0.2s ease-out,
                        visibility 0s linear 0.25s;
    transition: max-height 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.2s ease-out,
                visibility 0s linear 0.25s;
}

/* 展开状态 */
.sidebar-item.sidebar-show > ul {
    max-height: 1000px; /* 足够大的值以容纳子菜单 */
    opacity: 1;
    visibility: visible;
    -webkit-transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                        opacity 0.2s ease-in 0.05s,
                        visibility 0s linear 0s;
    transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.2s ease-in 0.05s,
                visibility 0s linear 0s;
}

/* ========================================
   箭头旋转动画优化
   ======================================== */

.sidebar-more {
    -webkit-transition: -webkit-transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-show > .sidebar-more {
    -webkit-transform: scale(0.8) rotate(90deg);
    transform: scale(0.8) rotate(90deg);
}

/* ========================================
   菜单项悬停效果优化
   ======================================== */

.sidebar-menu-inner a {
    position: relative;
    -webkit-transition: color 0.2s ease,
                        background-color 0.2s ease;
    transition: color 0.2s ease,
                background-color 0.2s ease;
}

.sidebar-menu-inner a::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.05);
    opacity: 0;
    border-radius: 5px;
    -webkit-transition: opacity 0.2s ease;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.sidebar-menu-inner a:hover::before {
    opacity: 1;
}

/* ========================================
   当前激活项样式
   ======================================== */

.sidebar-menu-inner a.sidebar-current {
    color: #fff;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 5px;
}

.sidebar-menu-inner a.sidebar-current::after {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    width: 3px;
    height: 60%;
    background: var(--theme-color, #f1404b);
    border-radius: 0 3px 3px 0;
    -webkit-transform: translateY(-50%);
    transform: translateY(-50%);
}

/* ========================================
   滚动区域优化
   ======================================== */

.sidebar-scroll {
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

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

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

.sidebar-scroll::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

.sidebar-scroll::-webkit-scrollbar-thumb:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

/* ========================================
   移动端优化
   ======================================== */

@media (max-width: 991.98px) {
    /* 移动端使用更快的动画 */
    .sidebar-item > ul {
        -webkit-transition: max-height 0.2s cubic-bezier(0.4, 0, 0.2, 1),
                            opacity 0.15s ease-out,
                            visibility 0s linear 0.2s;
        transition: max-height 0.2s cubic-bezier(0.4, 0, 0.2, 1),
                    opacity 0.15s ease-out,
                    visibility 0s linear 0.2s;
    }

    .sidebar-item.sidebar-show > ul {
        -webkit-transition: max-height 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                            opacity 0.15s ease-in 0.03s,
                            visibility 0s linear 0s;
        transition: max-height 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                    opacity 0.15s ease-in 0.03s,
                    visibility 0s linear 0s;
    }

    .sidebar-more {
        -webkit-transition: -webkit-transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
        transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    }
}

/* ========================================
   减少动画模式（尊重用户偏好）
   ======================================== */

@media (prefers-reduced-motion: reduce) {
    .sidebar-item > ul,
    .sidebar-item.sidebar-show > ul,
    .sidebar-more,
    .sidebar-menu-inner a,
    .sidebar-menu-inner a::before {
        -webkit-transition: none !important;
        transition: none !important;
    }

    .sidebar-item > ul {
        max-height: none;
        opacity: 1;
        visibility: hidden;
        display: none !important;
    }

    .sidebar-item.sidebar-show > ul {
        visibility: visible;
        display: block !important;
    }
}

/* ========================================
   骨架屏加载状态
   ======================================== */

.sidebar-menu-inner.loading .sidebar-item {
    pointer-events: none;
}

.sidebar-menu-inner.loading .sidebar-item > a > span,
.sidebar-menu-inner.loading .sidebar-item > a > i {
    background: linear-gradient(90deg,
        rgba(255, 255, 255, 0.1) 25%,
        rgba(255, 255, 255, 0.2) 50%,
        rgba(255, 255, 255, 0.1) 75%);
    background-size: 200% 100%;
    -webkit-animation: skeleton-loading 1.5s infinite;
    animation: skeleton-loading 1.5s infinite;
    color: transparent !important;
    border-radius: 4px;
}

@-webkit-keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* ========================================
   性能提示：禁用不必要的动画层
   ======================================== */

.sidebar-nav:not(:hover) .sidebar-more::after {
    display: none;
}

/* 仅在视口内的元素启用动画 */
.sidebar-item:not(.in-viewport) > ul {
    -webkit-transition: none;
    transition: none;
}
