/*
 * 移动端基线（page.html / md 页 / view 页共用，管理界面不加载）。
 *
 * 目标：整页不横滚、表格与代码各自横滚、默认关闭浏览器下拉刷新；
 * 只在窄屏生效，不改字体/颜色，也不覆盖页面自己的 <style>。
 *
 * 为什么夹内容容器而不是 html/body：
 *   - overflow-x:hidden 会建立滚动容器，把 sticky 头部弄坏（实测 top 从 0 变成负数）；
 *   - overflow-x:clip 不建立滚动容器，sticky 与内部滚动都正常；
 *   - 夹 body 会连带裁掉挂到 body 的 Element UI 浮层，所以页面夹 #page、md 夹 .md-shell、view 夹 .pv。
 */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

a, button, [role="button"], input, select, textarea, label {
  touch-action: manipulation;
}

@media (max-width: 900px) {
  /* 1. 默认没有浏览器下拉刷新；页面显式声明后恢复（App 自带的下拉不受 CSS 控制） */
  html, body { overscroll-behavior-y: none; }
  html.cb-allow-pull, html.cb-allow-pull body { overscroll-behavior-y: auto; }

  /* 2. 页面：夹住 #page（page.html 挂载时保留这个节点），body 上的浮层不受影响。
     内容规则用 :where() 归零特异性，页面自己的 style 永远优先。 */
  #page { max-width: 100%; overflow-x: clip; }
  html.cb-hscroll #page { overflow-x: visible; }

  :where(#page) :where(img, video) { max-width: 100%; height: auto; }
  :where(#page) :where(svg, iframe) { max-width: 100%; }
  :where(#page) pre { max-width: 100%; overflow-x: auto; }
  :where(#page) :where(p, li, dd, td, th, blockquote) { overflow-wrap: break-word; }

  /* 3. md / 查看页：夹内容容器，不动 body */
  body.md-body .md-shell,
  body.pv-body .pv { max-width: 100%; overflow-x: clip; }

  /* 4. 表格单独横滚（只给平台自己的 Markdown 排版；页面表格用 .cb-table） */
  body.md-body .doc table,
  body.pv-body .doc table {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }

  body.md-body .doc :where(p, li, td, th, dd, blockquote, a),
  body.pv-body .doc :where(p, li, td, th, dd, blockquote, a) {
    overflow-wrap: break-word;
    overflow-wrap: anywhere;
  }

  body.md-body .doc :where(video, iframe),
  body.pv-body .doc :where(video, iframe) { max-width: 100%; }

  /* 5. 页面按需使用的横滚容器 */
  .cb-table {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .cb-scroll-x {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}
