@use './variables.module.scss' as vars;

#app {

  .main-container {
    min-height: 100%;
    transition: margin-left .28s;
    margin-left: vars.$base-sidebar-width;
    position: relative;
  }

  .sidebarHide {
    margin-left: 0!important;
  }

  .sidebar-container {
    transition: width 0.28s;
    width: vars.$base-sidebar-width !important;
    height: 100%;
    position: fixed;
    font-size: 0px;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1001;
    overflow: hidden;
    
    background: var(--sidebar-bg-image);
    -webkit-box-shadow: 2px 0 6px rgba(0,21,41,.35);
    box-shadow: 0px 0px 8px 0px rgba(0, 0, 0, 0.1);

    // =============================================
    // 侧边栏主题适配 (sideTheme)
    // =============================================
    
    // 1. 侧边栏暗色主题 (theme-dark)
    &.theme-dark {
      --sidebar-bg: rgba(15, 23, 42, 0.85); // Slate 900
      --sidebar-text: #94a3b8; // Slate 400
      --menu-hover: rgba(30, 41, 59, 0.6); // Slate 800
      --menu-active-bg: rgba(56, 189, 248, 0.15); // Sky 400
      --menu-active-text: #38bdf8; // Sky 400
      --menu-active-border: rgba(56, 189, 248, 0.3);
      --menu-item-hover: rgba(30, 41, 59, 0.6); // Slate 800
      
      // 星空粒子背景
      background-color: #0f172a !important;
      background-image: 
        radial-gradient(white, rgba(255,255,255,.2) 2px, transparent 3px),
        radial-gradient(white, rgba(255,255,255,.15) 1px, transparent 2px),
        radial-gradient(white, rgba(255,255,255,.1) 2px, transparent 3px),
        linear-gradient(to bottom, #0f172a, #1e293b) !important;
      background-size: 550px 550px, 350px 350px, 250px 250px, 100% 100% !important;
      background-position: 0 0, 40px 60px, 130px 270px, 0 0;
      animation: star-move 100s linear infinite;
      
      backdrop-filter: blur(10px);
      -webkit-backdrop-filter: blur(10px);
      border-right: 1px solid rgba(255, 255, 255, 0.05);
      
      .el-menu {
        background: transparent !important;
      }
      
      .el-menu-item, .el-sub-menu__title {
        color: var(--sidebar-text) !important;
        
        &:hover {
          background-color: var(--menu-item-hover) !important;
          color: #fff !important;
          box-shadow: inset 0 0 20px rgba(56, 189, 248, 0.15);
          transform: translateX(4px);
        }
      }
      
      .is-active > .el-sub-menu__title {
        color: #fff !important;
      }
    }

    @keyframes star-move {
      0% { background-position: 0 0, 40px 60px, 130px 270px, 0 0; }
      100% { background-position: 550px 550px, 390px 410px, 380px 520px, 0 0; }
    }

    // 2. 侧边栏亮色主题 (theme-light)
    &.theme-light {
      --sidebar-bg: rgba(255, 255, 255, 0.85); // 半透明白
      --sidebar-bg-image: none;
      --sidebar-text: #475569; // Slate 600
      --menu-hover: rgba(255, 255, 255, 0.6);
      --menu-active-bg: rgba(255, 255, 255, 0.9); // 选中项高亮白
      --menu-active-text: #2563eb; // Blue 600
      --menu-active-border: transparent;
      --menu-item-hover: rgba(241, 245, 249, 0.5); // Slate 100
      
      background: var(--sidebar-bg) !important;
      backdrop-filter: blur(12px); // 启用磨砂
      -webkit-backdrop-filter: blur(12px);
      border-right: 1px solid rgba(0, 0, 0, 0.05);
      animation: none;

      .el-menu {
        background: transparent !important;
      }

      .el-menu-item, .el-sub-menu__title {
        color: var(--sidebar-text) !important;
        margin: 4px 10px !important;
        border-radius: 8px !important;
        
        &:hover {
          background-color: var(--menu-item-hover) !important;
          color: var(--menu-active-text) !important;
          transform: translateY(-1px);
          box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05); // 轻微阴影
        }
      }
      
      .is-active > .el-sub-menu__title {
        color: var(--menu-active-text) !important;
        font-weight: 600;
      }

      // 浅色模式下的选中状态 - 悬浮玻璃块
      .el-menu-item.is-active {
        background: linear-gradient(135deg, rgba(239, 246, 255, 0.8) 0%, rgba(219, 234, 254, 0.8) 100%) !important; // 柔和的淡蓝渐变
        border: 1px solid rgba(255, 255, 255, 0.6); // 半透明白边框
        border-right: none;
        color: #2563eb !important; // Blue 600
        font-weight: 600;
        box-shadow: 0 4px 12px rgba(37, 99, 235, 0.08), inset 0 0 0 1px rgba(255, 255, 255, 0.5); // 柔和蓝影+内发光
        backdrop-filter: blur(5px);
        
        &::after {
          display: none;
        }

        .svg-icon {
          color: #2563eb !important;
          filter: drop-shadow(0 2px 4px rgba(37, 99, 235, 0.15));
        }
      }
    }

    // reset element-ui css
    .horizontal-collapse-transition {
      transition: 0s width ease-in-out, 0s padding-left ease-in-out, 0s padding-right ease-in-out;
    }

    .scrollbar-wrapper {
      overflow-x: hidden !important;
    }

    // 滚动条样式美化
    .el-scrollbar__bar.is-vertical {
      right: 0px;
      width: 4px;
      .el-scrollbar__thumb {
        background-color: var(--el-text-color-secondary); // 自适应滚动条颜色
        opacity: 0.3;
        &:hover {
          opacity: 0.5;
        }
      }
    }

    .el-scrollbar {
      height: 100%;
    }

    &.has-logo {
      .el-scrollbar {
        height: calc(100% - 50px);
      }
    }

    .is-horizontal {
      display: none;
    }

    a {
      display: inline-block;
      width: 100%;
      overflow: hidden;
    }

    .svg-icon {
      margin-right: 12px;
      font-size: 18px;
      vertical-align: -0.3em;
      transition: all 0.3s;
      color: var(--sidebar-text); // 自适应图标颜色
    }

    .el-menu {
      border: none;
      height: 100%;
      width: 100% !important;
      background-color: transparent !important;
    }

    .el-menu-item, .el-sub-menu__title {
      overflow: hidden !important;
      text-overflow: ellipsis !important;
      white-space: nowrap !important;
      height: 48px !important;
      line-height: 48px !important;
      margin: 4px 10px !important;
      border-radius: 8px !important;
      transition: all 0.3s cubic-bezier(0.25, 0.8, 0.5, 1);
      color: var(--sidebar-text) !important;
      display: flex !important; // 使用 flex 布局保证垂直居中
      align-items: center !important;
      padding-left: 12px !important; // 统一左侧内边距
    }

    // 修复折叠菜单样式
    .el-menu--collapse {
      .el-menu-item, .el-sub-menu__title {
        margin: 4px 0 !important; // 折叠时取消左右margin
        padding: 0 !important; // 强制取消所有padding
        justify-content: center !important; // 图标居中
        border-radius: 0 !important;
        text-align: center;
        
        .svg-icon {
          margin-right: 0 !important; // 折叠时取消图标右间距
          margin-left: 0 !important;  // 确保左边也没有间距
          font-size: 18px;
        }
        
        span {
          display: none !important;
          width: 0;
          height: 0;
          overflow: hidden;
        }
        
        .el-sub-menu__icon-arrow {
          display: none !important;
        }
      }
      
      // 修复折叠后弹出菜单的样式
      .el-sub-menu {
        &.is-active > .el-sub-menu__title {
           color: var(--menu-active-text) !important;
           background-color: var(--menu-item-hover) !important;
        }
      }
    }

    // 修复子菜单缩进问题 - 多级菜单层级区分
    // 二级菜单项和二级目录标题（在一级目录下）
    .nest-menu .el-menu-item,
    .nest-menu .el-sub-menu__title {
      padding-left: 48px !important;
    }
    
    // 三级菜单项和三级目录标题（在二级目录下）
    .nest-menu .nest-menu .el-menu-item,
    .nest-menu .nest-menu .el-sub-menu__title {
      padding-left: 64px !important;
    }
    
    // 四级菜单项
    .nest-menu .nest-menu .nest-menu .el-menu-item,
    .nest-menu .nest-menu .nest-menu .el-sub-menu__title {
      padding-left: 80px !important;
    }

    .el-menu-item .el-menu-tooltip__trigger {
      display: inline-block !important;
    }

    // menu hover
    .sub-menu-title-noDropdown,
    .el-sub-menu__title {
      color: var(--sidebar-text) !important;
      position: relative; // 为伪元素定位
      overflow: hidden;   // 防止光效溢出

      &:hover {
        background-color: var(--menu-item-hover) !important;
        color: #fff !important;
        box-shadow: inset 0 0 20px rgba(56, 189, 248, 0.15); // 稍微增强内发光
        transform: translateX(4px); // 轻微右移，增加交互感
      }
    }

    & .theme-dark .is-active > .el-sub-menu__title {
      color: var(--menu-active-text) !important;
      font-weight: 600;
    }

    & .nest-menu .el-sub-menu>.el-sub-menu__title,
    & .el-sub-menu .el-menu-item {
      min-width: calc(vars.$base-sidebar-width - 20px) !important;
      position: relative; // 定位
      overflow: hidden;

      &:hover {
        background-color: var(--menu-item-hover) !important;
        color: #fff !important;
        box-shadow: inset 0 0 20px rgba(56, 189, 248, 0.15); // 稍微增强内发光
        transform: translateX(4px); // 轻微右移
      }
    }

    & .theme-dark .nest-menu .el-sub-menu>.el-sub-menu__title,
    & .theme-dark .el-sub-menu .el-menu-item {
      background-color: transparent;
      
      &:hover {
        background-color: var(--menu-item-hover) !important;
      }
    }

    // 选中状态样式重写 - 磨砂玻璃质感 (Glassmorphism) - 自适应版
    .el-menu-item.is-active {
      background: rgba(56, 189, 248, 0.15) !important; // 稍微调高透明度
      backdrop-filter: blur(12px);
      -webkit-backdrop-filter: blur(12px);
      box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2), 
                  inset 0 0 0 1px rgba(255, 255, 255, 0.1); // 内部微光边框
      border: 1px solid rgba(56, 189, 248, 0.2); // 外部边框
      color: #fff !important;
      font-weight: 600;
      position: relative;
      overflow: hidden; // 确保光效不溢出
      
      &::before {
        display: none;
      }

      // 中速流光掠过效果
      &::after {
        content: "";
        position: absolute;
        top: 0;
        left: -100%;
        width: 60%;
        height: 100%;
        background: linear-gradient(
          to right,
          rgba(255, 255, 255, 0) 0%,
          rgba(255, 255, 255, 0.15) 50%,
          rgba(255, 255, 255, 0) 100%
        );
        transform: skewX(-25deg);
        animation: sidebar-shine 2s infinite; // 2s 中速循环
      }

      .svg-icon {
        color: #fff !important;
        filter: drop-shadow(0 0 5px rgba(56, 189, 248, 0.5));
        position: relative;
        z-index: 1; // 确保图标在光效之上
      }
      
      span {
        position: relative;
        z-index: 1; // 确保文字在光效之上
      }
    }

    @keyframes sidebar-shine {
      0% { left: -100%; }
      20% { left: 200%; } // 快速划过
      100% { left: 200%; } // 停留一段时间
    }
  }

  .hideSidebar {
    .sidebar-container {
      width: 54px !important;
    }

    .main-container {
      margin-left: 54px;
    }

    .sub-menu-title-noDropdown {
      padding: 0 !important;
      position: relative;

      .el-tooltip {
        padding: 0 !important;

        .svg-icon {
          margin-left: 20px;
        }
      }
    }

    .el-sub-menu {
      overflow: hidden;

      &>.el-sub-menu__title {
        padding: 0 !important;

        .svg-icon {
          margin-left: 20px;
        }

      }
    }

    .el-menu--collapse {
      .el-sub-menu {
        &>.el-sub-menu__title {
          &>span {
            height: 0;
            width: 0;
            overflow: hidden;
            visibility: hidden;
            display: inline-block;
          }
          &>i {
            height: 0;
            width: 0;
            overflow: hidden;
            visibility: hidden;
            display: inline-block;
          }
        }
      }
    }
  }

  .el-menu--collapse .el-menu .el-sub-menu {
    min-width: vars.$base-sidebar-width !important;
  }

  // mobile responsive
  .mobile {
    .main-container {
      margin-left: 0px;
    }

    .sidebar-container {
      transition: transform .28s;
      width: vars.$base-sidebar-width !important;
    }

    &.hideSidebar {
      .sidebar-container {
        pointer-events: none;
        transition-duration: 0.3s;
        transform: translate3d(-(vars.$base-sidebar-width), 0, 0);
      }
    }
  }

  .withoutAnimation {

    .main-container,
    .sidebar-container {
      transition: none;
    }
  }
}

// when menu collapsed
.el-menu--vertical {
  &>.el-menu {
    .svg-icon {
      margin-right: 16px;
    }
  }

  .nest-menu .el-sub-menu>.el-sub-menu__title,
  .el-menu-item {
    &:hover {
      // you can use $sub-menuHover
      background-color: rgba(0, 0, 0, 0.06) !important;
    }
  }

  // the scroll bar appears when the sub-menu is too long
  >.el-menu--popup {
    max-height: 100vh;
    overflow-y: auto;

    &::-webkit-scrollbar-track-piece {
      background: #d3dce6;
    }

    &::-webkit-scrollbar {
      width: 6px;
    }

    &::-webkit-scrollbar-thumb {
      background: #99a9bf;
      border-radius: 20px;
    }
  }
}

// =============================================
// 全局弹出菜单样式优化 (Popper Menu)
// =============================================
.el-menu--popup {
  min-width: 180px;
  border-radius: 12px !important; // 大圆角
  padding: 6px !important; // 整体内边距
  box-shadow: 0 10px 30px -10px rgba(0,0,0,0.15), 
              0 4px 10px -4px rgba(0,0,0,0.1) !important; // 柔和深阴影
  border: 1px solid var(--el-border-color-lighter) !important;

  // 菜单项
  .el-menu-item {
    height: 40px;
    line-height: 40px;
    margin: 2px 0; // 上下间距
    padding: 0 12px !important;
    border-radius: 8px !important; // 子项圆角
    color: var(--el-text-color-regular);
    transition: all 0.2s;

    &:hover {
      background-color: var(--el-color-primary-light-9) !important;
      color: var(--el-color-primary) !important;
    }

    &.is-active {
      background-color: var(--el-color-primary) !important;
      color: #fff !important;
      font-weight: 500;
      box-shadow: 0 2px 8px rgba(var(--el-color-primary-rgb), 0.25);
    }

    .svg-icon {
      margin-right: 10px;
      font-size: 16px;
      vertical-align: -0.2em;
    }
  }
}

// 暗色模式下的弹出菜单适配
html.dark .el-menu--popup {
  background-color: #1e293b !important; // Slate 800
  border: 1px solid #334155 !important; // Slate 700

  .el-menu-item {
    color: #cbd5e1; // Slate 300

    &:hover {
      background-color: #334155 !important; // Slate 700
      color: #fff !important;
    }

    &.is-active {
      background-color: var(--el-color-primary) !important;
      color: #fff !important;
    }
  }
}
