@import '../../style/variables.less';
@import './variables.less';
@import '../components/Layout/index.less';
@import '../components/ProCollapse/style/index.less';
@import '../components/ProFooter/style/index.less';
@import '../components/ProHeader/style/index.less';
@import '../components/TabsManager/style/index.less';

.pro-layout {
  // 菜单上方保留完整底色，丝带在右半部轻轻隆起，再向右侧回落。
  --header-bg-image:
    linear-gradient(90deg, @pro-layout-shell-bg @pro-layout-menu-open-width, transparent 52%),
    radial-gradient(
      ellipse 46% 110px at 76% 138px,
      transparent 74%,
      rgba(169, 205, 248, 0.32) 88%,
      rgba(255, 255, 255, 0.62) 98%,
      transparent 103%
    ),
    linear-gradient(100deg, @pro-layout-shell-bg 25%, #ecf5fc 67%, @pro-layout-shell-bg 100%);
  --pro-layout-tab-corner-radius: 8px;
  --pro-layout-menu-fold-width: @pro-layout-menu-fold-width;

  &.pro-layout-show-collapsed-menu-label {
    --pro-layout-menu-fold-width: @pro-layout-menu-label-width;
  }

  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: @pro-layout-shell-bg;
  position: relative;

  // 背景图层：固定在顶部，延伸到可视区域下方，z-index低于header和content让内容显示在背景之上
  &::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 200px;
    background-image: var(--header-bg-image);
    background-repeat: no-repeat;
    background-position: top center;
    background-size: 100% 200px;
    pointer-events: none;
    z-index: 1;
  }

  .pro-layout-menu-open {
    .pro-layout-open-menu-lv1 {
      h2 {
        font-weight: bold;
      }
    }
  }

  // pro-collapse折叠调整
  .pro-collapse {
    border-radius: var(--zaui-border-radius, 8px);
    &.@{ant-prefix}-collapse-borderless {
      background: #fff;
    }
    &.pro-collapse-no-title {
      .pro-collapse-content {
        border-radius: var(--zaui-border-radius, 8px) !important;
        padding: var(--zaui-space-size-md, 16px);
      }
      .pro-header-no-describe {
        padding: 0 !important;
      }
    }
    .@{ant-prefix}-collapse-item-active {
      &.pro-collapse-panel {
        & > .@{ant-prefix}-collapse-header {
          border-radius: var(--zaui-border-radius, 8px) var(--zaui-border-radius, 8px) 0 0 !important;
        }
      }
    }

    .pro-collapse-content {
      border-radius: 0 0 var(--zaui-border-radius, 8px) var(--zaui-border-radius, 8px);
      padding: var(--zaui-space-size-md, 16px);

      .pro-form {
        margin-bottom: 0;
      }
    }
    &.pro-collapse-level2 {
      .pro-collapse-panel .@{ant-prefix}-collapse-header {
        background: #fff;
      }
      .pro-collapse-content {
        padding-bottom: var(--zaui-space-size-sm, 8px);
      }
    }

    .pro-collapse-panel {
      .@{ant-prefix}-collapse-header {
        border-radius: var(--zaui-border-radius, 8px) !important;
        background: #e4f2fe;
      }
      .pro-collapse-level2-collapse {
        .@{ant-prefix}-collapse-header {
          border-radius: 0 !important;
        }
      }
    }
  }

  // pro-header调整
  .pro-header {
    &.pro-header-no-describe {
      padding: 10px var(--zaui-space-size-md, 16px) !important;
      .pro-header-top {
        padding-bottom: 0;
      }
    }
    &.pro-header-has-describe {
      .pro-header-nav-open {
        border-radius: 0 0 var(--zaui-border-radius, 8px) var(--zaui-border-radius, 8px);
      }
    }
    border-radius: 0 0 var(--zaui-border-radius, 8px) var(--zaui-border-radius, 8px);
  }

  .pro-layout-menu-open,
  .pro-layout-menu {
    box-shadow: none;
  }

  .pro-layout-open-menu .@{ant-prefix}-menu-title-content div .pro-layout-icon {
    position: relative;
    z-index: 1;
    color: var(--zaui-text, #343434);
  }
  .pro-layout-menu-fold {
    background: @pro-layout-shell-bg;

    .pro-layout-menu-fold-list {
      background: @pro-layout-shell-bg;
      border-right: none;
      li {
        position: relative;
        background: @pro-layout-shell-bg;

        & > div {
          position: relative;
          z-index: 1;
        }

        &.active {
          background: transparent;
          border-radius: var(--zaui-border-radius, 8px);

          div .pro-layout-icon {
            color: #fff;
          }

          h2 {
            color: var(--zaui-base-bg, #ffffff);
          }

          &::before {
            position: absolute;
            top: 4px;
            left: 5px;
            width: calc(100% - 10px);
            height: 38px;
            background-color: var(--zaui-brand, #006aff);
            border-radius: var(--zaui-border-radius, 8px);
            opacity: 1 !important;
            content: '';
          }
        }

        &:hover {
          background: transparent;

          &::before {
            position: absolute;
            top: 4px;
            left: 5px;
            width: calc(100% - 10px);
            height: 38px;
            background-color: var(--zaui-brand, #006aff);
            border-radius: var(--zaui-border-radius, 8px);
            opacity: 0.08;
            content: '';
          }
        }

        div .pro-layout-icon {
          color: var(--zaui-text, #343434);
        }
      }
    }
  }

  .pro-layout-menu-fold-show-label .pro-layout-menu-fold-list li {
    &.active::before,
    &:hover::before {
      top: 0;
      left: 8px;
      width: calc(100% - 16px);
      height: 56px;
    }
  }

  .pro-layout-menu-collapsed {
    background: @pro-layout-shell-bg;
    border-right: none;
    &:hover {
      background: transparent !important;
    }
    &:hover::after {
      position: absolute;
      top: 5px;
      left: 5px;
      width: calc(100% - 10px);
      height: 40px;
      background-color: var(--zaui-brand, #006aff);
      border-radius: var(--zaui-border-radius, 8px);
      opacity: 0.08;
      content: '';
    }

    &::before {
      position: absolute;
      top: 0;
      left: var(--zaui-space-size-sm, 8px);
      width: calc(100% - 16px);
      height: 1px;
      background: #dee0e3;
      content: '';
    }
  }

  .pro-layout-row {
    .pro-layout-arrow {
      border-color: var(--zaui-text, #343434);
    }
  }
  .@{ant-prefix}-menu-root {
    overflow-x: hidden !important;
    border: none !important;
  }

  .anticon-caret-down {
    color: #999 !important;
    inset-inline-end: 8px;
  }

  .pro-layout-row .pro-layout-menu {
    background: @pro-layout-shell-bg;
  }

  .pro-layout-open-menu {
    background: @pro-layout-shell-bg;

    .@{ant-prefix}-menu {
      background: @pro-layout-shell-bg;
    }

    .@{ant-prefix}-menu-root {
      background: @pro-layout-shell-bg;
    }

    .@{ant-prefix}-menu-sub {
      background: @pro-layout-shell-bg !important;
    }
  }

  .pro-layout-open-menu
    .@{ant-prefix}-menu-root
    > .@{ant-prefix}-menu-submenu
    .@{ant-prefix}-menu-sub {
    background: @pro-layout-shell-bg;
  }

  .pro-layout-open-menu .@{ant-prefix}-menu-title-content div h2 {
    color: var(--zaui-text, #343434);
    padding-right: 26px;
  }
  .@{ant-prefix}-menu-item-only-child {
    .@{ant-prefix}-menu-title-content div h2 {
      padding-right: 16px;
    }
  }

  .pro-layout-open-menu .@{ant-prefix}-menu-item:hover,
  .pro-layout-open-menu .@{ant-prefix}-menu-submenu-title:hover,
  .pro-layout-open-menu .@{ant-prefix}-menu-item-selected {
    position: relative;
    background-color: transparent !important;

    &:before {
      position: absolute;
      left: var(--zaui-space-size-sm, 8px);
      width: calc(100% - 8px);
      min-height: 38px;
      height: 80%;
      background-color: var(--zaui-brand, #006aff);
      border-radius: var(--zaui-border-radius, 8px);
      opacity: 0.08;
      content: '';
    }
  }

  .pro-layout-open-menu .@{ant-prefix}-menu-item-selected {
    &::before {
      background-color: color-mix(in srgb, var(--zaui-brand, #006aff) 20%, @pro-layout-shell-bg);
      opacity: 1;
    }

    .@{ant-prefix}-menu-title-content {
      position: relative;
    }

    &::after {
      display: none;
    }

    background: transparent !important;

    h2 {
      color: var(--zaui-brand, #006aff) !important;
    }
  }

  /** Tab 栏 Portal 挂载点（位于 header 渐变区，内容区之上） */
  .pro-layout-tabs-bar-wrapper {
    // 与 pro-layout-content 对齐：同样的左右边距，无内边距让 tab 从左侧直接对齐
    margin-right: var(--zaui-space-size-md, 16px);
    margin-left: @pro-layout-menu-fold-size;
    padding: 0;
    // 滚动时固定在 header 和 notice 正下方
    position: sticky;
    top: calc(var(--pro-layout-header-height, 64px) + var(--pro-layout-notice-height, 0px));
    z-index: 89;
    // 与 ::before 渐变层像素级对齐：滚动时遮住上滚的白色内容，同时保持渐变背景可见
    // background-color 作为实体打底，防止渐变图片浅色区域透出白色内容
    background-color: @pro-layout-shell-bg;
    background-image: var(--header-bg-image);
    background-repeat: no-repeat;
    background-position: top center;
    background-size: 100% 200px;
    background-attachment: fixed;
    // 高度动画：CSS Grid 技巧，支持不定高度平滑过渡
    display: grid;
    grid-template-rows: 0fr;
    transition:
      margin-left 0.3s cubic-bezier(0.2, 0, 0, 1),
      grid-template-rows 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    // 菜单展开时与内容区同步右移
    &.tabs-menu-open {
      margin-left: @pro-layout-menu-open-width;
    }

    // Tab 存在时展开
    &.tabs-visible {
      grid-template-rows: 1fr;

      // 弧外显示同坐标的布局背景，滚动时仍覆盖下方内容的直角。
      &::after {
        content: '';
        position: absolute;
        top: 100%;
        right: 0;
        width: var(--pro-layout-tab-corner-radius);
        height: var(--pro-layout-tab-corner-radius);
        background: inherit;
        mask-image: radial-gradient(circle at bottom left, transparent calc(var(--pro-layout-tab-corner-radius) - 0.5px), #000 var(--pro-layout-tab-corner-radius));
        pointer-events: none;
      }
    }

    // Grid 子元素需要 overflow: hidden 才能实现 0fr 收起
    > * {
      overflow: hidden;
      min-height: 0;
    }
  }

  /** 内容区 */
  .pro-layout-content {
    position: relative;
    z-index: 10;
    flex: 1;
    margin-top: 0;
    margin-right: var(--zaui-space-size-md, 16px);
    margin-bottom: 0;
    margin-left: @pro-layout-menu-fold-size;
    padding: 0 var(--zaui-space-size-md, 16px);
    background: #ffffff;
    border-top: 1px solid rgb(235 236 238);
    border-right: 1px solid rgb(235 236 238);
    border-left: 1px solid rgb(235 236 238);
    border-bottom: none;
    border-radius: var(--zaui-border-radius, 8px) var(--zaui-border-radius, 8px) 0 0;
    transition: all 0.24s ease;

    // Tab 存在时：顶部边框透明（不用 none，避免 transition:all 产生黑色闪烁）、移除顶部圆角，与 Tab 栏无缝衔接；补上顶部 padding
    &-has-tabs {
      border-top-color: transparent;
      border-radius: 0;
      padding-top: var(--zaui-space-size-md, 16px);

      // 圆弧由内容区独立绘制并随内容滚动；sticky Tab 栏始终保持在其上方。
      // 与内容区外边框对齐，同时遮住底层直角，避免缩放时出现断线或双重圆弧。
      &::before {
        content: '';
        position: absolute;
        box-sizing: border-box;
        top: -1px;
        right: -1px;
        width: var(--pro-layout-tab-corner-radius);
        height: var(--pro-layout-tab-corner-radius);
        background: #ffffff;
        border-top: 1px solid rgb(235 236 238);
        border-right: 1px solid rgb(235 236 238);
        border-top-right-radius: var(--pro-layout-tab-corner-radius);
        pointer-events: none;
      }

      .pro-layout-tabs-content {
        > .tab-pane {
          // ProStep 以 ProHeader 开头时，仅去掉 tabs 内容区的顶部留白。
          // 保留右侧内边距，让 ProStep wrapper 继续为贴右步骤条预留 16px 间距。
          > .pro-step-wrapper:has(> .pro-header:first-child) {
            margin-top: calc(-1px - var(--zaui-space-size-md, 16px));
          }

          > .pro-header.pro-header-no-describe:first-child {
            padding: 0 !important;

            .pro-header-title,
            .pro-header-top {
              margin: 0;
              padding: 0;
            }
          }
        }
      }
    }
  }

  // 纯净模式：隐藏背景图
  &.pro-layout-pure {
    &::before {
      display: none;
    }
  }

  // iframe 嵌入 pure 模式：背景固定为白色，覆盖布局底色与外部全局样式
  &.pro-layout-iframe-pure {
    background: #fff;
  }

  .pro-layout-row-pure {
    .pro-layout-content {
      margin: 0 !important;
      background: #fff;
      border: none;
    }
  }

  .pro-layout-row-top-pure {
    .pro-layout-content {
      margin-top: 0 !important;
    }
  }

  .pro-layout-row-left-pure {
    .pro-layout-content {
      margin-left: 0 !important;
    }
  }

  .pro-layout-header-pure + .pro-layout-row {
    .pro-layout-sider-new-nav {
      top: 0 !important;
    }
  }
}
