/* =========================================================================
   WeKnora 移动端重设计 —— mobile-redesign.css
   仅在小屏 (max-width:768px) 生效，替换旧版 mobile-fix.css。
   原生 CSS，无外部依赖。兼容 iOS Safari 15+ / 微信内置浏览器。
   思路：布局层改造——把真实侧栏 .aside_box 移出可视区（仍保留在 DOM 供
   JS 读取与点击），由本文件 + mobile-redesign.js 注入 顶部 AppBar 与
   底部 3 Tab，主内容区用 padding 避开两条导航；不按 nth-child，不拦截
   任何请求。
   ========================================================================= */

@media (max-width: 768px) {
  :root {
    --wk-appbar-h: 48px;
    --wk-tabbar-h: 56px;
    --wk-safe-top: env(safe-area-inset-top, 0px);
    --wk-safe-bottom: env(safe-area-inset-bottom, 0px);
    --wk-keyboard: 0px;          /* 键盘弹起时由 JS 写入可视口被遮挡高度 */
    --wk-accent: #2f6bff;
    --wk-accent-soft: #eaf0ff;
    --wk-text: #1f2937;
    --wk-muted: #8a8f99;
    --wk-line: #ececec;
    --wk-bg: #ffffff;
    --wk-bg-soft: #f6f7f9;
  }

  html, body {
    max-width: 100% !important;
    overflow-x: hidden !important;
    -webkit-text-size-adjust: 100%;
  }
  * { box-sizing: border-box; }
  img, svg { max-width: 100%; }

  /* ---------- 1. 布局层：解除写死的最小宽度，主内容全宽 ---------- */
  .main {
    min-width: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    display: block !important;
  }
  .platform-route-outlet,
  .kb-list-container, .kb-list-content,
  .kb-list-main, .kb-card-wrap,
  .header, .header-title, .title-row, .header-actions,
  .resource-toolbar, .scope-filters, .category-tabs {
    min-width: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
  }

  /* ---------- 2. 真实侧栏移出可视区（DOM 保留，JS 仍可读可点） ---------- */
  .aside_box {
    position: fixed !important;
    left: -10000px !important;
    top: 0 !important;
    right: auto !important;
    bottom: auto !important;
    width: 280px !important;
    height: 100vh !important;
    flex-direction: column !important;
    z-index: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
    box-shadow: none !important;
    border: 0 !important;
  }
  /* 旧补丁把这些 display:none 了，恢复渲染以便 JS 读取内容 */
  .aside_box .logo_row,
  .aside_box .menu_bottom,
  .aside_box .submenu {
    display: flex !important;
    opacity: 1 !important;
  }
  .panel-resize-handle { display: none !important; }

  /* ---------- 3. 主内容区避开顶栏 / 底栏 ---------- */
  .platform-route-outlet {
    width: 100% !important;
    max-width: 100% !important;
    padding-top: calc(var(--wk-appbar-h) + var(--wk-safe-top)) !important;
    padding-bottom: calc(var(--wk-tabbar-h) + var(--wk-safe-bottom)) !important;
  }

  /* 隐藏应用自身重复的页内大标题（AppBar 已展示标题），但保留其操作按钮 */
  .platform-route-outlet .header .title-row > h2,
  .platform-route-outlet .header-title > h2,
  .platform-route-outlet .header .title-row h2 {
    position: absolute !important;
    left: -9999px !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
  }
  .header-subtitle { display: none !important; }

  /* ---------- 4. 注入的顶部 AppBar ---------- */
  #wk-appbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 900;
    height: calc(var(--wk-appbar-h) + var(--wk-safe-top));
    padding-top: var(--wk-safe-top);
    display: flex;
    align-items: center;
    background: #fff;
    border-bottom: 1px solid var(--wk-line);
    color: var(--wk-text);
  }
  #wk-appbar .wk-ab-left,
  #wk-appbar .wk-ab-right {
    display: flex;
    align-items: center;
    min-width: 64px;
    flex-shrink: 0;
  }
  #wk-appbar .wk-ab-left { padding-left: 6px; }
  #wk-appbar .wk-ab-right { padding-right: 6px; justify-content: flex-end; }
  #wk-appbar .wk-ab-title {
    flex: 1 1 auto;
    min-width: 0;
    text-align: center;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 6px;
  }
  .wk-btn {
    border: 0;
    background: transparent;
    color: var(--wk-text);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 10px;
    border-radius: 8px;
    -webkit-tap-highlight-color: transparent;
  }
  .wk-btn:active { background: var(--wk-bg-soft); }
  .wk-space-btn { max-width: 150px; }
  .wk-space-btn .wk-space-name {
    font-size: 14px;
    font-weight: 600;
    max-width: 108px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .wk-space-btn .wk-caret { font-size: 10px; color: var(--wk-muted); }
  .wk-back-btn svg { width: 20px; height: 20px; }
  .wk-icon-btn svg { width: 20px; height: 20px; }

  /* ---------- 5. 注入的底部 3 Tab ---------- */
  #wk-mtab {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 900;
    height: calc(var(--wk-tabbar-h) + var(--wk-safe-bottom));
    padding-bottom: var(--wk-safe-bottom);
    background: #fff;
    border-top: 1px solid var(--wk-line);
    display: flex;
    box-shadow: 0 -1px 6px rgba(0, 0, 0, .05);
  }
  #wk-mtab .wk-tab {
    flex: 1 1 0;
    min-width: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--wk-muted);
    font-size: 10px;
    line-height: 1;
    padding: 6px 0;
    -webkit-tap-highlight-color: transparent;
  }
  #wk-mtab .wk-tab svg { width: 22px; height: 22px; }
  #wk-mtab .wk-tab.is-active { color: var(--wk-accent); }
  #wk-mtab .wk-tab .wk-tab-label { font-size: 10px; }

  /* ---------- 6. 抽屉 / 底部弹层 / 遮罩 ---------- */
  .wk-mask {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, .42);
    z-index: 940;
    opacity: 0; pointer-events: none;
    transition: opacity .2s ease;
  }
  .wk-mask.show { opacity: 1; pointer-events: auto; }

  .wk-drawer {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: 84%; max-width: 320px;
    background: #fff;
    z-index: 950;
    transform: translateX(-100%);
    transition: transform .25s ease;
    display: flex; flex-direction: column;
    box-shadow: 2px 0 12px rgba(0,0,0,.12);
  }
  .wk-drawer.show { transform: translateX(0); }
  .wk-drawer-header {
    height: calc(var(--wk-appbar-h) + var(--wk-safe-top));
    padding: var(--wk-safe-top) 14px 0;
    display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid var(--wk-line);
    font-size: 15px; font-weight: 600;
  }
  .wk-drawer-body { flex: 1; overflow-y: auto; padding: 8px 0; }
  .wk-drawer-body .wk-empty { padding: 24px 16px; color: var(--wk-muted); font-size: 13px; text-align: center; }

  .wk-sheet {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    background: #fff;
    z-index: 950;
    transform: translateY(100%);
    transition: transform .25s ease;
    border-radius: 16px 16px 0 0;
    max-height: 82vh;
    overflow-y: auto;
    padding-bottom: var(--wk-safe-bottom);
  }
  .wk-sheet.show { transform: translateY(0); }
  .wk-sheet-grab { width: 36px; height: 4px; border-radius: 2px; background: #d8dbe0; margin: 8px auto 0; }
  .wk-sheet-section { padding: 10px 16px; }
  .wk-sheet-section h4 { margin: 6px 0 8px; font-size: 12px; color: var(--wk-muted); font-weight: 500; }
  .wk-sheet-row {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 4px; font-size: 14px; color: var(--wk-text);
    cursor: pointer; border-radius: 8px;
  }
  .wk-sheet-row:active { background: var(--wk-bg-soft); }
  .wk-sheet-row .wk-row-main { flex: 1; min-width: 0; }
  .wk-sheet-row .wk-row-title { font-size: 14px; }
  .wk-sheet-row .wk-row-sub { font-size: 12px; color: var(--wk-muted); margin-top: 2px; }
  .wk-sheet-row .wk-row-ico { width: 18px; height: 18px; color: var(--wk-muted); flex-shrink: 0; }
  .wk-user-card {
    display: flex; align-items: center; gap: 10px;
    padding: 14px 16px; border-bottom: 1px solid var(--wk-line);
  }
  .wk-user-card .wk-avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: var(--wk-accent-soft); color: var(--wk-accent);
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; font-weight: 600; flex-shrink: 0;
  }
  .wk-user-card .wk-u-name { font-size: 14px; font-weight: 600; }
  .wk-user-card .wk-u-space { font-size: 12px; color: var(--wk-muted); margin-top: 2px; }

  /* ---------- 7. 知识库卡片在移动端的收敛 ---------- */
  .kb-card-wrap {
    display: block !important;
    grid-template-columns: none !important;
    padding: 0 12px !important;
  }
  .kb-card {
    width: 100% !important;
    max-width: 100% !important;
    margin-bottom: 10px !important;
  }
  .resource-toolbar { flex-wrap: wrap !important; gap: 8px; }
  .search-input { width: 100% !important; }

  /* ---------- 8. 问答输入框：始终在底栏之上，键盘弹起时上移 ---------- */
  .create-chat-composer,
  .answers-input {
    position: sticky !important;
    bottom: calc(var(--wk-tabbar-h) + var(--wk-safe-bottom)) !important;
    z-index: 50;
  }
  /* 键盘弹起：底栏被键盘挡住则隐藏，输入框贴键盘上沿 */
  body.wk-kb-open .create-chat-composer,
  body.wk-kb-open .answers-input {
    bottom: var(--wk-keyboard) !important;
  }
  body.wk-kb-open #wk-mtab { display: none !important; }
  body.wk-kb-open .platform-route-outlet {
    padding-bottom: 0 !important;
  }

  /* ---------- 9. 把应用自身的浮层（用户菜单 / 切空间）重定位到可视区中央 ----------
     因为它们的触发器 .user-button 被移出了屏幕，inline 定位会跑到屏幕外，
     这里强制 fixed 居中，保证切空间可达。 */
  .user-dropdown,
  .tenant-submenu-floating {
    position: fixed !important;
    left: 12px !important;
    right: 12px !important;
    top: calc(var(--wk-appbar-h) + var(--wk-safe-top) + 8px) !important;
    bottom: auto !important;
    transform: none !important;
    max-height: 72vh;
    overflow-y: auto;
    z-index: 960 !important;
    border-radius: 12px !important;
    box-shadow: 0 8px 30px rgba(0, 0, 0, .18) !important;
  }

  /* ---------- 10. 兜底：防止任何内容撑破 375 ---------- */
  .platform-route-outlet table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
  }
  pre, code { white-space: pre-wrap; word-break: break-word; }
}

/* =========================================================================
   v3.1 修复（2026-11-27）
   1) 内容区只占 380px → 下方大空白、输入框浮在上半屏、与底部导航割裂
      根因：.main 是 display:block，子项 flex:1 失效；outlet 高度=内容自然高度
   2) 顶部 AppBar 与内容区视觉断裂（白底+分割线压住官方页面自己的头部留白）
   ========================================================================= */
@media (max-width: 768px) {
  .main {
    display: flex !important;
    flex-direction: column !important;
    height: 100vh !important;
    max-height: 100vh !important;
    overflow: hidden !important;
  }
  .platform-route-outlet {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: auto !important;
    max-height: none !important;
    display: flex !important;
    flex-direction: column !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }
  .platform-route-outlet > * { min-width: 0 !important; }

  /* 问答页：标题在上，输入区被推到最底，紧贴底部 Tab */
  .dialogue-wrap,
  .dialogue-answers {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
  }
  .create-chat-composer,
  .answers-input {
    margin-top: auto !important;
    position: static !important;
    bottom: auto !important;
    flex: 0 0 auto !important;
  }
  /* 消息区自己滚，不顶着输入框 */
  .dialogue-messages,
  .message-list,
  [class*="dialogue-message"] {
    min-height: 0 !important;
    overflow-y: auto !important;
  }

  /* AppBar 与内容融合：去掉硬分割线，只留极淡一层阴影 */
  #wk-appbar {
    border-bottom: 0 !important;
    box-shadow: 0 1px 0 rgba(0, 0, 0, .04) !important;
  }
  /* 官方页面自己的头部留白收一点，避免 AppBar 下出现"第二层标题区" */
  .platform-route-outlet .kb-list-container .header,
  .platform-route-outlet .header {
    padding-top: 6px !important;
  }
}

/* =========================================================================
   v3.3（2026-11-27，精确选择器版）
   1) 筛选区 76px → 40px（官方把 .scope-filters 写死 76，里面两个控件只有 32）
   2) 新建知识库改主色 CTA（.header-actions > .t-button）
   3) Tab 选中态改胶囊（aria-pressed="true"）
   4) 卡片纵向收紧
   ========================================================================= */
@media (max-width: 768px) {
  .resource-toolbar .scope-filters {
    height: 40px !important;
    align-items: center !important;
  }
  .resource-toolbar {
    padding-bottom: 10px !important;
  }
  .resource-toolbar .space-filter {
    width: 104px !important;
  }

  /* Tab：胶囊 + 选中柔化 */
  .category-tabs > button {
    border-radius: 999px !important;
  }
  .category-tabs > button[aria-pressed="true"] {
    background: #fff !important;
    color: var(--wk-accent) !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .06) !important;
  }
  .category-tabs > button[aria-pressed="true"] .scope-count {
    color: var(--wk-accent) !important;
  }

  /* 新建知识库：唯一主色 CTA */
  .header-actions > .t-button {
    background: var(--wk-accent) !important;
    color: #fff !important;
    border: 0 !important;
    border-radius: 10px !important;
    padding: 0 12px !important;
    height: 30px !important;
  }
  .header-actions > .t-button *,
  .header-actions > .t-button svg {
    color: #fff !important;
    fill: #fff !important;
    stroke: #fff !important;
  }

  /* 卡片收紧 */
  .kb-card {
    gap: 4px !important;
  }
  .kb-card .card-content {
    padding: 2px 0 !important;
    min-height: 0 !important;
  }
  .kb-card .card-bottom {
    margin-top: 2px !important;
    padding-top: 4px !important;
  }
}

/* ===== v3.2 视觉精修 =====
   1) 问答页：欢迎语过大且贴边 → 收字号、与内容区对齐
   2) 知识库页：header + toolbar 两块各自为政、满屏线框 → 合成一块浅灰筛选区，
      列表区留白分层；卡片描边减淡、圆角统一
   只覆盖样式，不动结构、不加节点
   ========================================================================= */
@media (max-width: 768px) {
  /* --- 问答页空态 --- */
  .dialogue-title {
    padding: 12px 16px 0 !important;
  }
  .dialogue-title > span {
    font-size: 21px !important;
    line-height: 1.42 !important;
    font-weight: 600 !important;
    letter-spacing: .2px;
  }

  /* --- 知识库页：筛选区合成一块 --- */
  .kb-list-content > .header {
    background: #f7f8fa !important;
    padding: 10px 12px 6px !important;
    border-radius: 12px 12px 0 0 !important;
  }
  .kb-list-content > .resource-toolbar {
    background: #f7f8fa !important;
    padding: 0 12px 12px !important;
    border-radius: 0 0 12px 12px !important;
    border-bottom: 1px solid #eef0f2 !important;
    margin-bottom: 10px !important;
  }
  .kb-list-content > .header .header-title {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
  }
  .kb-list-content > .header .header-title > h2 {
    margin-right: auto !important;
    font-size: 17px !important;
    font-weight: 600 !important;
  }

  /* 搜索框与筛选控件圆角/描边统一 */
  .search-input,
  .resource-toolbar .t-input__wrap,
  .resource-toolbar .t-input {
    border-radius: 10px !important;
  }
  .resource-toolbar .t-input__wrap {
    background: #fff !important;
  }

  /* --- 卡片：紧凑 + 描边减淡 --- */
  .kb-card {
    border-radius: 12px !important;
    border-color: #eef0f2 !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .04) !important;
    padding: 12px !important;
  }
  /* 无描述的卡片：不让"暂无描述"撑出大片空白 */
  .kb-card-wrap {
    padding: 0 12px !important;
  }
}


/* =========================================================================
   v3.4 目录改左侧抽屉（2026-11-27）
   官方把「目录」平铺在文档页顶部（200px，占掉首屏），改成：
   - .kb-folder-tree 提升为左侧滑出抽屉（fixed），保留原有展开/收起交互
   - AppBar 右侧给「目录」按钮，点开抽屉 + 遮罩，点遮罩关闭
   ========================================================================= */
@media (max-width: 768px) {
  .kb-folder-tree {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    bottom: 0 !important;
    width: 82vw !important;
    max-width: 320px !important;
    height: 100vh !important;
    max-height: 100vh !important;
    margin: 0 !important;
    border-radius: 0 !important;
    z-index: 970 !important;
    background: #fff !important;
    transform: translateX(-103%) !important;
    transition: transform .24s ease !important;
    box-shadow: 2px 0 14px rgba(0, 0, 0, .14) !important;
    padding-top: calc(52px + env(safe-area-inset-top, 0px)) !important;
    padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px)) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }
  body.wk-tree-open .kb-folder-tree {
    transform: translateX(0) !important;
  }
  #wk-tree-mask {
    position: fixed;
    inset: 0;
    z-index: 965;
    background: rgba(0, 0, 0, .35);
    display: none;
  }
  body.wk-tree-open #wk-tree-mask { display: block; }
  body.wk-tree-open #wk-mtab { display: none !important; }
  body.wk-tree-open .platform-route-outlet { overflow: hidden !important; }
  /* 抽屉里的行加大点击区 */
  .kb-folder-tree .kb-folder-row {
    padding: 12px 14px !important;
    font-size: 14px !important;
  }
}

/* =========================================================================
   v3.5 文档详情抽屉适配（2026-11-27）
   根因：TDesign 的 .t-drawer__content-wrapper 固定 480px 且贴右 → 375 视口下
        x=-105，左侧被裁、右侧溢出（用户截图里"文字从中间开始"就是这个）
   修法：整屏宽 + 内容宽度跟随 + 媒体/表格不撑破
   ========================================================================= */
@media (max-width: 768px) {
  .t-drawer__content-wrapper {
    width: 100vw !important;
    max-width: 100vw !important;
    left: 0 !important;
    right: auto !important;
  }
  .t-drawer__body {
    width: 100% !important;
    max-width: 100% !important;
    padding-left: 12px !important;
    padding-right: 12px !important;
  }
  .doc-markdown-root,
  .setting-drawer__section,
  .doc-content-section,
  .summary-section {
    width: 100% !important;
    max-width: 100% !important;
  }
  /* 文档里的图片 / 视频 / 表格不许撑破屏幕 */
  .doc-markdown-root img,
  .doc-markdown-root video,
  .doc-markdown-root iframe,
  .setting-drawer__section img,
  .setting-drawer__section video,
  .setting-drawer__section iframe {
    max-width: 100% !important;
    height: auto !important;
  }
  .doc-markdown-root pre,
  .doc-markdown-root table {
    max-width: 100% !important;
    overflow-x: auto !important;
    display: block !important;
  }
  .doc-markdown-root pre code { white-space: pre-wrap !important; word-break: break-word !important; }
  /* 详情抽屉里顶部操作区（编辑/刷新/预览/查看分块）允许换行 */
  .document-detail-actions,
  [class*="detail-action"] { flex-wrap: wrap !important; gap: 8px !important; }
}

/* =========================================================================
   v3.6 文档详情抽屉内容适配（2026-11-27）
   1) 「预览 / 查看分块」等按钮 32px → 36px+（触控目标）
   2) 摘要被硬截断且无省略号 → 放开 max-height/line-clamp，完整显示
   3) 预览/正文里 h1-h3 按桌面字号渲染太大 → 手机收敛到 13-17px
   ========================================================================= */
@media (max-width: 768px) {
  .t-drawer__body .t-button,
  .setting-drawer__section .t-button {
    min-height: 36px !important;
    padding: 0 14px !important;
    font-size: 13px !important;
    border-radius: 10px !important;
  }
  .setting-drawer__section .header-icon-btn,
  .setting-drawer__section [class*="icon-btn"] {
    min-width: 36px !important;
    min-height: 36px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  /* 摘要：不要硬截断 */
  .summary-section p,
  .summary-section [class*="summary-text"],
  .summary-section .t-text,
  .summary-section .text-content {
    max-height: none !important;
    overflow: visible !important;
    display: block !important;
    -webkit-line-clamp: unset !important;
    font-size: 13px !important;
    line-height: 1.65 !important;
  }

  /* 预览 / 正文排版 */
  .doc-markdown-root {
    font-size: 13px !important;
    line-height: 1.65 !important;
  }
  .doc-markdown-root h1 { font-size: 17px !important; line-height: 1.35 !important; }
  .doc-markdown-root h2 { font-size: 15px !important; line-height: 1.4 !important; }
  .doc-markdown-root h3 { font-size: 14px !important; line-height: 1.4 !important; }
  .doc-markdown-root p,
  .doc-markdown-root li,
  .doc-markdown-root td,
  .doc-markdown-root th { font-size: 13px !important; }
  .doc-markdown-root img,
  .doc-markdown-root video { border-radius: 8px !important; }
}
