/* ==========================================================================
   渊古文化官网 · 全站框架统一层 (site shell lock)
   --------------------------------------------------------------------------
   背景：站点分批改造过。/、/products 只加载 site-app-v3.css；/tutorials、
        /download、/help 等页面仍会额外加载 13 套历史样式表，并且使用了
        不同的内容容器（1440px *-workspace / 1180-1220px .shell /
        calc(100vw - 32px)）。历史样式表还会按 single-screen-page 决定是否
        隐藏文档滚动条，导致视口可用宽度相差 15px，顶栏与内容区跟着左右移动。
   职责：本文件在所有页面最后加载，统一「滚动模型 + 框架 + 页面画布 + 图标」
        的几何，不改动任何页面自身的视觉设计，新旧页面都能保持原有外观。
   注意：必须保持在 site-app-v3.css 之后加载；body 需带 shell-unified 类。
   ========================================================================== */

/* 1) 桌面端统一为「工作台」滚动模型 ---------------------------------------
   文档本身不滚动，所有内容滚动都发生在 .app-content 内部。这样视口可用
   宽度恒定，不会因为某页内容长短或历史样式而多/少一条文档滚动条。
   页脚始终可见，由 flex 自适应分配内容区高度。 */
@media (min-width: 821px) {
  html,
  body.shell-unified.brand-site.app-workspace-page {
    height: 100% !important;
    min-height: 0 !important;
    max-height: 100vh !important;
    overflow: hidden !important;
    scrollbar-gutter: auto !important;
  }

  /* 关键修复：历史样式把 body 变成 flex，又给 .app-shell 加了
     margin-inline:auto，于是框架会「按各页内容宽度」收缩后各自居中。
     视口越宽（约 >1500px），各页收缩量不同，侧栏与顶栏偏得越远。
     这里把框架宽度锁死为 100% 视口宽，与页面内容、屏幕尺寸完全解耦，
     任何分辨率下所有页面的框架几何都一模一样。 */
  body.shell-unified.brand-site.app-workspace-page {
    display: block !important;
    box-sizing: border-box !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  body.shell-unified.brand-site.app-workspace-page .app-shell {
    display: grid !important;
    box-sizing: border-box !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 16px !important;
    column-gap: 16px !important;
    grid-template-columns: var(--app-sidebar) minmax(0, 1fr) !important;
    height: 100vh !important;
    min-height: 100vh !important;
    max-height: 100vh !important;
  }

  body.shell-unified.brand-site.app-workspace-page .app-main {
    box-sizing: border-box !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    margin: 0 !important;
    height: calc(100vh - 32px) !important;
    min-height: 0 !important;
    max-height: calc(100vh - 32px) !important;
  }

  body.shell-unified.brand-site.app-workspace-page .app-topbar,
  body.shell-unified.brand-site.app-workspace-page .app-footer {
    box-sizing: border-box !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    margin-inline: 0 !important;
  }

  body.shell-unified.brand-site.app-workspace-page main.app-content {
    box-sizing: border-box !important;
    flex: 1 1 auto !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    margin-inline: 0 !important;
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior: auto;
    scrollbar-gutter: stable;
  }

  body.shell-unified.brand-site.app-workspace-page .app-footer {
    flex: 0 0 auto;
  }

  /* 历史样式表给部分页面定义了 10px 滚动条，另一部分用默认 15px，
     会让内容可用宽度相差 5px。这里把滚动条规格统一，配合
     scrollbar-gutter: stable，各页画布宽度完全一致。 */
  body.shell-unified.brand-site.app-workspace-page main.app-content { scrollbar-width: thin; }
  body.shell-unified.brand-site.app-workspace-page main.app-content::-webkit-scrollbar { width: 10px; }
  body.shell-unified.brand-site.app-workspace-page main.app-content::-webkit-scrollbar-track { background: transparent; }
  body.shell-unified.brand-site.app-workspace-page main.app-content::-webkit-scrollbar-thumb {
    border: 3px solid transparent;
    border-radius: 999px;
    background: rgba(42, 83, 204, .42);
    background-clip: padding-box;
  }
}

/* 1b) 821–900px 中等窗口 --------------------------------------------------
   v3 在 max-width:900px 会把侧栏改成 fixed 并移出屏幕，但上面的桌面规则
   仍是双列 grid，.app-main 于是落进空出来的 224px 第一列，内容被压成竖条。
   这个区间改为单列；另外 v3 只在 860px 以下才显示汉堡按钮，导致
   861–900px 侧栏隐藏后无法打开导航，这里一并补齐按钮样式。 */
@media (min-width: 821px) and (max-width: 900px) {
  body.shell-unified.brand-site.app-workspace-page .app-shell {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  body.shell-unified.brand-site.app-workspace-page .app-main {
    width: 100% !important;
  }
  body.shell-unified.brand-site.app-workspace-page .app-menu-toggle {
    display: grid !important;
    width: 36px !important;
    height: 36px !important;
    place-content: center !important;
    gap: 4px !important;
    margin-right: 8px !important;
    padding: 0 !important;
    border: 1px solid var(--app-line) !important;
    border-radius: 9px !important;
    background: #fff !important;
    cursor: pointer;
  }
  body.shell-unified.brand-site.app-workspace-page .app-menu-toggle span {
    display: block !important;
    width: 15px !important;
    height: 2px !important;
    border-radius: 9px;
    background: var(--app-blue);
  }
}

/* 2) 统一页面画布 ---------------------------------------------------------
   所有前台页面共用同一个宽度与左右内边距，内容起始 x 坐标完全一致。 */
body.shell-unified.brand-site.app-workspace-page main.app-content > .app-page-frame {
  box-sizing: border-box;
  display: flow-root; /* 建立 BFC，避免首页搜索行的 margin 塌陷把整块下推 10px */
  width: 100%;
  max-width: 1440px;
  margin-inline: auto;
  padding: clamp(22px, 3.5vw, 48px) clamp(18px, 3vw, 42px) 56px;
}

/* 页面自身根容器（.shell / .home-workspace / .products-workspace /
   .jv2-help-page 等）不再各自决定横向几何，一律交给 .app-page-frame。
   纵向节奏保留各自设计，只把顶部内边距归零避免与画布叠加。 */
body.shell-unified.brand-site.app-workspace-page main.app-content > .app-page-frame > * {
  box-sizing: border-box;
  width: 100% !important;
  min-width: 0 !important;
  max-width: none !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
  padding-left: 0 !important;
  padding-right: 0 !important;
  padding-top: 0 !important;
  /* 登录页根容器自带 42px 上外边距，会让内容顶部比其它页面低一截。
     统一归零，所有页面的内容起始 y 坐标一致。 */
  margin-top: 0 !important;
}

/* 首页搜索行自带 10px 上外边距，会与容器塌陷把整块内容下推。
   只给首页工作区建立 BFC，其它页面的 flex/grid 容器不受影响。 */
body.shell-unified.brand-site.app-workspace-page main.app-content > .app-page-frame > .home-workspace {
  display: flow-root;
}

/* 3) 图标尺寸统一 ---------------------------------------------------------
   原先导航图标是 Unicode 字符（⌂ ▦ ✦ ⇩ ? ◎ ⚙），字形本身大小不一。
   现在统一为 24 网格 SVG，固定 20px 描边图标，容器统一 28px。 */
body.shell-unified.brand-site.app-workspace-page .app-nav-icon {
  display: grid !important;
  width: 28px !important;
  height: 28px !important;
  flex: 0 0 28px !important;
  place-items: center !important;
  border: 0 !important;
  border-radius: 9px !important;
  background: transparent !important;
  font-size: 0 !important;
  line-height: 0 !important;
  overflow: hidden;
}

body.shell-unified.brand-site.app-workspace-page .route-icon {
  display: grid !important;
  width: 34px !important;
  height: 34px !important;
  flex: 0 0 34px !important;
  place-items: center !important;
  font-size: 0 !important;
  line-height: 0 !important;
  overflow: hidden;
}

body.shell-unified.brand-site.app-workspace-page .app-nav-icon svg,
body.shell-unified.brand-site.app-workspace-page .route-icon svg,
body.shell-unified.brand-site.app-workspace-page .app-icon-inline {
  display: block;
  width: 20px !important;
  height: 20px !important;
  max-width: 20px !important;
  max-height: 20px !important;
  flex: 0 0 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

body.shell-unified.brand-site.app-workspace-page .route-icon svg { width: 19px !important; height: 19px !important; }

/* SVG symbol 定义容器不占位 */
.app-icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; pointer-events: none; }

/* 内容区右上角装饰光晕：v3 让它 right:-12% 伸出容器，历史样式又用
   inset:0 覆盖，导致部分页面 scrollWidth 多出约 139px。统一收进容器内，
   视觉几乎无变化，但各页滚动宽度一致。 */
body.shell-unified.brand-site.app-workspace-page main.app-content::before {
  right: 0 !important;
  left: 15% !important;
  top: -17% !important;
  bottom: auto !important;
  width: auto !important;
  height: 60% !important;
}

/* 顶栏按钮、搜索框与首页搜索行里的内联图标也统一到同一规格 */
body.shell-unified.brand-site.app-workspace-page .app-free-link .app-icon-inline,
body.shell-unified.brand-site.app-workspace-page .global-search-icon .app-icon-inline {
  width: 17px !important;
  height: 17px !important;
  max-width: 17px !important;
  max-height: 17px !important;
  flex-basis: 17px;
  stroke-width: 2.1;
}
body.shell-unified.brand-site.app-workspace-page .global-search-icon,
body.shell-unified.brand-site.app-workspace-page .home-search-icon {
  display: grid; place-items: center; font-size: 0 !important; line-height: 0 !important;
}
body.shell-unified.brand-site.app-workspace-page .home-search-icon .app-icon-inline {
  width: 22px !important; height: 22px !important; max-width: 22px !important; max-height: 22px !important; flex-basis: 22px; stroke-width: 2;
}
body.shell-unified.brand-site.app-workspace-page .home-search-apps .app-icon-inline {
  width: 27px !important; height: 27px !important; max-width: 27px !important; max-height: 27px !important; flex-basis: 27px; stroke-width: 1.8;
}

/* 4) 小屏：沿用桌面同一套「工作台」滚动模型 -------------------------------
   历史样式表只在部分页面隐藏文档滚动条，docClientW 因而相差 15px；
   v3 又用 100vw 定义顶栏 / 内容宽度，于是首页与产品页会横向溢出、切换
   导航时顶栏宽度跟着变。这里统一为「文档不滚动、内容区内部滚动」，
   并把所有 100vw 收敛为 100%，各页视口宽度与内容起始位置完全一致。 */
@media (max-width: 820px) {
  html:has(body.shell-unified.brand-site.app-workspace-page),
  body.shell-unified.brand-site.app-workspace-page {
    height: 100% !important;
    min-height: 0 !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
    overflow: hidden !important;
    scrollbar-gutter: auto !important;
  }

  /* 同样锁死框架宽度：不改小屏自己的 padding / 圆角留白，只禁止
     body flex + shell 自动居中导致的按内容收缩。 */
  body.shell-unified.brand-site.app-workspace-page {
    display: block !important;
    box-sizing: border-box !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  body.shell-unified.brand-site.app-workspace-page .app-shell {
    box-sizing: border-box !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    margin: 0 !important;
    height: 100vh !important;
    height: 100dvh !important;
    min-height: 0 !important;
    max-height: 100dvh !important;
  }

  body.shell-unified.brand-site.app-workspace-page .app-main {
    height: 100vh !important;
    height: 100dvh !important;
    min-height: 0 !important;
    max-height: 100dvh !important;
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
  }

  body.shell-unified.brand-site.app-workspace-page .app-topbar {
    width: 100% !important;
    max-width: 100% !important;
    flex: 0 0 auto;
    overflow-x: hidden;
  }

  body.shell-unified.brand-site.app-workspace-page main.app-content {
    flex: 1 1 auto !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    /* v3 小屏给内容区左右各留 8px 做圆角留白（margin-inline: 8px），
       宽度必须与之配对，否则 100% 宽 + 8px 边距会撑出 8px 横向溢出。 */
    width: calc(100% - 16px) !important;
    max-width: calc(100% - 16px) !important;
    margin-inline: 8px !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    scrollbar-width: thin;
  }

  body.shell-unified.brand-site.app-workspace-page .app-footer { flex: 0 0 auto; }

  body.shell-unified.brand-site.app-workspace-page main.app-content > .app-page-frame {
    padding: 18px 14px 38px;
  }
  body.shell-unified.brand-site.app-workspace-page main.app-content > .app-page-frame > * {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: hidden;
  }

  /* v3 在 640px 以下用 100vw 定宽，含有滚动条的视口会多算 15px */
  body.shell-unified.brand-site.app-workspace-page .home-workspace,
  body.shell-unified.brand-site.app-workspace-page .products-workspace,
  body.shell-unified.brand-site.app-workspace-page .product-detail-workspace,
  body.shell-unified.brand-site.app-workspace-page .home-hero-lead {
    width: 100% !important;
    max-width: 100% !important;
  }
  body.shell-unified.brand-site.app-workspace-page .app-topbar-actions { min-width: 0; }

  /* 帮助页产品标签原本一行排开，小屏会撑出 700px+ 的横向溢出 */
  body.shell-unified.brand-site.app-workspace-page .help-tabs {
    flex-wrap: wrap !important;
    overflow-x: visible !important;
  }
}

/* 5) 全尺寸统一内容区滚动条 -----------------------------------------------
   历史样式在不同页面把滚动条定义成 2px / 10px / 默认宽度，内容长短不同时
   clientWidth 会相差约 10px，窄屏下画布宽度因此不一致。这里统一规格并
   固定预留槽位，任何视口、任何页面内容长度下可用宽度都完全相同。 */
body.shell-unified.brand-site.app-workspace-page main.app-content {
  scrollbar-width: thin;
  scrollbar-gutter: stable;
}
body.shell-unified.brand-site.app-workspace-page main.app-content::-webkit-scrollbar { width: 10px; }
body.shell-unified.brand-site.app-workspace-page main.app-content::-webkit-scrollbar-track { background: transparent; }
body.shell-unified.brand-site.app-workspace-page main.app-content::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 999px;
  background: rgba(42, 83, 204, .42);
  background-clip: padding-box;
}
