/* =============================================================
 * 移动端（H5 自适应）样式 —— 2026-11-05 新增
 * -------------------------------------------------------------
 * 隔离约定（务必遵守）：
 *   1. 本文件所有规则都包在 @media(max-width:820px) 内，桌面端一条都不生效；
 *   2. 不修改 style.css 的任何既有规则，只做覆盖；
 *   3. 回滚 = 删掉 index.html 里引用本文件的那一行 <link>。
 * 目标：手机上「壳层可点、信息分层、手指够得着」，不追求把桌面搬过来。
 * ============================================================= */

@media (max-width: 820px) {

  /* ---------- 1. 壳层：侧栏变成抽屉 ---------- */
  .app { display: flex; min-height: 100vh; }

  .side {
    position: fixed; left: 0; top: 0; bottom: 0; height: 100%;
    width: min(282px, 84vw); flex: 0 0 auto;
    transform: translateX(-100%);
    transition: transform .24s ease;
    /* z-index 必须压过 .top(1000)：否则顶栏横条盖住抽屉顶部（品牌区整个被吃掉）。
       1050/1060 在顶栏之上、modal(1600) 之下。 */
    z-index: 1060;
    box-shadow: 0 0 34px rgba(0, 0, 0, .45);
  }
  body:not(.side-off) .side { transform: translateX(0); }

  /* 抽屉打开时的遮罩（点击遮罩由 app.js 收起侧栏）。
     ⚠️ 必须限定 :has(.side)：登录/注册/忘记密码页没有侧栏，body 也没有 side-off 类，
     不加这个限定的话全屏遮罩会盖住登录表单，手机上点不了账号密码输入框（2026-11-05 事故）。
     ⚠️ z-index 也要盖过 .top(1000)：否则抽屉开着时顶栏还能点、视觉上也没压暗。 */
  body:not(.side-off):has(.side)::after {
    content: '';
    position: fixed; inset: 0;
    background: rgba(8, 10, 18, .52);
    z-index: 1050;
  }

  /* 侧栏开关：从小半圆改成 44px 的汉堡位（手指够得着）。
     ⚠️ z-index 必须压过 .top(1000)——.top 有背景色，1000 以下的汉堡会被它盖住，
     看起来就是「侧边栏按钮消失不见了」（2026-11-05 用户反馈）。 */
  .side-tgl {
    left: 0; top: 10px; transform: none;
    width: 44px; height: 44px;
    border-radius: 0 12px 12px 0;
    z-index: 1070;
    background: var(--panel);
    transition: opacity .18s ease, left .24s ease;
  }
  body:not(.side-off) .side-tgl { opacity: 0; pointer-events: none; }

  /* 导航项加大点击区 */
  .nav a { min-height: 44px; font-size: 14.5px; }
  .nav .grp { padding: 12px 10px 6px; }

  /* ---------- 2. 顶栏：不换行、不挤压 ---------- */
  .top {
    height: 54px;
    padding: 0 10px 0 52px;
    gap: 8px;
    flex-wrap: nowrap;
  }
  .top .crumb {
    font-size: 14px;
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  .top .wb-tabs { margin-left: 0; flex: 0 0 auto; }
  .top .wb-tabs button,
  .top .wb-tabs .t { white-space: nowrap; }
  /* 顶栏动作区可以横滑，不挤爆标题；素材计数徽章手机上隐藏（空间宝贵） */
  #top-actions {
    flex: 0 1 auto;
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }
  #top-actions::-webkit-scrollbar { display: none; }
  #top-actions .btn { flex: 0 0 auto; white-space: nowrap; }
  #top-actions .badge { display: none; }

  /* 用户区瘦身：金币只留数字 */
  .user-cluster { gap: 6px; }
  .coin-chip { padding: 4px 8px; }
  .coin-chip .coin-unit { display: none; }
  .avatar { width: 32px; height: 32px; font-size: 13px; }

  /* 用户弹层贴右边缘，别超出屏幕 */
  .user-pop { right: 6px; width: min(300px, calc(100vw - 24px)); }

  /* ---------- 3. 内容区：留白收紧 ---------- */
  .content { padding: 12px; }
  .content.wbfill { padding: 8px; }

  /* ---------- 4. 通用：手指尺寸与滚动 ---------- */
  /* 关键动作按钮不低于 40px；.xs 这类紧凑按钮保 34px 不破坏排版 */
  .btn { min-height: 38px; }
  .btn.xs { min-height: 34px; }
  .btn.sm { min-height: 36px; }

  /* 表格类一律允许横向滚动（工作台 / 用户管理 / 素材列表）。
     display:block + max-width:100% + 自滚动：不溢出时渲染不变，溢出时表格自己滑，
     不会把整页 layout viewport 撑大（手机浏览器会被迫整体缩小页面，字号全毁）。 */
  .content table,
  .modal .box table {
    display: block;
    width: max-content;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .wb-tblwrap, .tb-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* 工具条（我的空间页签/排序/多选）允许换行，别横向撑爆 */
  .st-tools, .card .hd, .set-pane-hd { flex-wrap: wrap; }

  /* 弹窗：全屏化，别再用 22px 外边距挤成一条 */
  .modal { padding: 0; align-items: flex-end; }
  .modal .box {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 92vh !important;
    border-radius: 16px 16px 0 0;
  }
  .modal .box.wbp,
  .modal .box.wbmax { height: 92vh !important; max-height: 92vh !important; }
  .ch-modal { padding: 0; align-items: flex-end; }
  .ch-modal .box.wbp { width: 100% !important; height: 92vh !important; border-radius: 16px 16px 0 0; }

  /* 抽屉（右侧滑出）在手机上改成全宽 */
  .drawer { width: 100% !important; max-width: 100% !important; }

  /* 底部备案条不要挡住操作按钮 */
  #beianFooter { font-size: 10px; opacity: .5; bottom: 2px; right: 6px; }

  /* 画布顶部工具条：一行放不下时自己横滑，绝不换行——
     换行的第二行（已保存/缩放%）会叠在画布节点上，看起来「界面凌乱」。
     2026-11-05 二轮：5 个按钮 + 缩放% 在 390px 上原生放不下（505px），
     压缩 gap/内边距/字号并隐藏「已保存」与分隔线后全部一屏可见，
     删除按钮不再只剩 1/3。 */
  .bc-top {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    gap: 4px;
    padding: 6px 8px;
  }
  .bc-top::-webkit-scrollbar { display: none; }
  .bc-top > * { flex: 0 0 auto; }
  .bc-top .bc-sp { flex: 1 1 auto !important; }   /* 弹性空隙仍在，右端对齐 */
  .bc-top .bc-btn { padding: 5px 7px; font-size: 12px; }
  .bc-top .bc-vr, .bc-top .bc-save { display: none; }

  /* ---------- 7. 画布：把触摸手势还给应用 ---------- */
  /* touch-action:none 是画布手势的前提：否则浏览器接管拖动/双指缩放（整页缩放），
     应用层只能收到 pointercancel。桌面端无此需求（mobile.css 不生效）。 */
  .bc-canvas {
    touch-action: none;
    -webkit-touch-callout: none;   /* iOS 长按不弹系统菜单 */
    -webkit-user-select: none;
    user-select: none;
  }
  .bc-tip { display: none; }       /* 「左键拖空白…」鼠标操作提示对触屏无意义 */

  /* 素材卡 / 素材库弹出层：手机上全屏底部抽屉 */
  .wtag-pop, .agd-selpop { max-width: 100vw !important; }

  /* ---------- 5. 画布底部资产库抽屉（mylib-dock）：分类树恢复左侧竖排侧栏 ----------
     ⚠️ 不要在这里写 height：抽屉高度由 mylib.js 管理（内联 style + localStorage），
     样式表里的 height（含 !important）会压过内联值，拖拽调高就失效了。
     只给一个上限防呆。
     ⚠️ 折叠态不能沿用桌面的 transform 定位：transform 会让内部 position:fixed 的
     详情弹窗（#ml-detail）/灯箱（#ml-zoom）被困在 dock 坐标系里——弹窗贴底错位、
     手势坐标全偏（2026-11-05 用户反馈「详情弹窗 UI 显示不正常」的根因之一）。
     手机端折叠改用 top 定位，dock 永远不带 transform。 */
  .mylib-dock { max-height: 72vh; transition: none; }
  body.on-board .mylib-dock:not(.open) {
    transform: none;
    top: 100%;
    margin-top: calc(-1 * var(--mb-sheetbar, 30px));
    bottom: auto;
  }
  /* 左侧分类栏（像电脑端）：竖排 + 窄化 + 小字号；ml-treecol 是贴着树的折叠细条 */
  .ml-body { flex-direction: row; }
  .ml-tree {
    width: 112px; flex: 0 0 112px;
    display: flex; flex-direction: column;
    overflow-x: hidden; overflow-y: auto;
    border-right: 1px solid #2a2a30;
    border-bottom: 0;
    gap: 3px;
    padding: 6px 3px 10px;
    font-size: 11.5px;
    scrollbar-width: none;
  }
  .ml-tree::-webkit-scrollbar { display: none; }
  .ml-tnode {
    flex: 0 0 auto;
    min-height: 26px;
    font-size: 11.5px;
    padding-top: 2px !important; padding-bottom: 2px !important;
    /* padding-left 不覆盖：保留层级缩进（项目 → 分类 → 子文件夹） */
    border: 1px solid #2f2f36; border-radius: 6px;
    background: #1a1a1e;
    gap: 2px;
  }
  .ml-tnode.sel { border-color: var(--brand, #4f46e5); }
  .ml-tar { width: 14px; font-size: 12px; }   /* 竖排侧栏里展开箭头重新有意义 */
  .ml-tar-ph { width: 14px; }
  .ml-tacts { display: none; }     /* 重命名/删除按钮手机上先收起 */
  .ml-treecol {
    flex: 0 0 16px; width: 16px; min-width: 0; max-width: none;
    display: flex; align-items: center; justify-content: center;
    background: #151518; color: #8f96a3;
    border: 0; border-right: 1px solid #2a2a30;
    padding: 0; font-size: 13px; line-height: 1; cursor: pointer;
  }
  .ml-treecol:active { background: #1d1d22; color: #d8e94e; }
  .mylib-dock.ml-tree-off .ml-tree { display: none; }
  .mylib-dock.ml-tree-off .ml-treecol { flex-basis: 20px; width: 20px; }
  .ml-main { min-height: 0; }
  .ml-q { min-width: 0; }

  /* ---------- 微信浏览器长按弹「转发给朋友 / 保存到手机」菜单的根治 ----------
     微信（iOS WKWebView / 安卓 X5）的长按图片菜单只认 <img>/<video> 元素本身。
     把网格缩略图 img 设为 pointer-events:none，触摸落点变成外层容器 div，
     微信就不再把它当图片处理；卡片点击 / 长按拖拽全走容器冒泡，完全不受影响。
     （安卓 contextmenu 事件拦截已在 board.js lpBindBody 里，双保险。）
     详情弹窗 / 灯箱的大图要点击放大，保留 pointer-events，只关长按 callout。 */
  .ml-thumb img, .bc-lib-it img {
    pointer-events: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none; user-select: none;
  }
  .ml-card, .bc-lib-it {
    -webkit-touch-callout: none;
    -webkit-user-select: none; user-select: none;
    /* 只允许浏览器接管「竖向滚动列表」这一种手势：双击缩放、双指捏合整页
       缩放（微信长按素材被接管成缩放的根源）在卡片上全部禁掉。
       长按拖拽是 JS 事件链（board.js lpBindDrag），不受 touch-action 影响。 */
    touch-action: pan-y;
  }
  .ml-dbox img, .ml-zoom img {
    -webkit-touch-callout: none;
    -webkit-user-select: none; user-select: none;
  }

  /* 选择资产弹窗（libOpen，.lib-* 那套）：左栏变顶部 chip，分区可折叠 */
  .lib-body { flex-direction: column; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .lib-side {
    flex: 0 0 auto;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: 0;
    border-bottom: 1px solid var(--wb-line, var(--line));
    padding: 8px 10px;
    gap: 6px;
    scrollbar-width: none;
  }
  .lib-side::-webkit-scrollbar { display: none; }
  .lib-side .cat { flex: 0 0 auto; min-height: 38px; padding: 8px 14px; }
  .lib-main { overflow-y: auto; padding: 10px 12px; }

  /* 分区里的横向滚排 → 两列网格（避免横滑手势与画布冲突） */
  .lib-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; overflow-x: visible; }
  .lib-row > * { width: auto !important; flex: none !important; }
  .lib-video-card { flex: none !important; }

  /* 分区折叠：mobile.js 在点击标题时切换 .m-fold */
  .lib-ghead { cursor: pointer; min-height: 40px; }
  .lib-sec.m-fold .lib-row,
  .lib-sec.m-fold .lib-grid,
  .lib-sec.m-fold .lib-dropzone { display: none; }

  /* 素材卡：跟随屏幕宽度自适应（一行两列铺满，不留大空白）。
     桌面是固定 132px 宽 + 124x93 缩略图；手机改成弹性卡片，缩略图按 4:3 等比伸缩。 */
  .ml-card {
    width: auto;
    flex: 1 1 140px;
    max-width: calc(50% - 7px);
  }
  .ml-thumb {
    width: 100%;
    height: auto;
    aspect-ratio: 4 / 3;
  }

  /* Agent 面板顶栏：品牌按钮/模式徽标在窄屏不换行（桌面定宽会把文字挤成竖排），
     进度条让位收缩。 */
  .agd-top { gap: 8px; padding-left: 10px; padding-right: 10px; }
  .agd-top-left { gap: 6px; }
  .agd-brand, .agd-mode {
    white-space: nowrap;
    flex: 0 0 auto;
    padding: 0 8px;
  }
  .agd-top-right { flex: 1 1 auto; min-width: 0; justify-content: flex-end; }
  .agd-prog { flex: 1 1 40px; width: auto; min-width: 36px; }
  .agd-prog-num { flex: 0 0 auto; }

  /* Agent 面板：三列 → tab（tab 条由 mobile.js 注入） */
  .agd-vgrip { display: none; }
  .agd-main { flex-direction: column; }
  .agd-col { display: none !important; }
  .agd-col-ch, .agd-col-edit, .agd-col-assets { flex: 0 0 246px; }
  .agd-main[data-mtab="ch"] .agd-col-ch,
  .agd-main[data-mtab="edit"] .agd-col-edit,
  .agd-main[data-mtab="assets"] .agd-col-assets {
    display: flex !important;
    flex: 1 1 auto !important;
    min-height: 0;
  }
  .m-agd-tabs {
    display: flex; gap: 6px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--wb-line, var(--line));
    background: var(--wb-panel-2, #27272c);
    flex: 0 0 auto;
  }
  .m-agd-tabs button {
    flex: 1; min-height: 38px;
    border-radius: 9px;
    border: 1px solid var(--wb-line-strong, #484850);
    background: transparent;
    color: var(--wb-text-2, #c8cbe0);
    font-weight: 650; font-size: 13px;
    cursor: pointer;
  }
  .m-agd-tabs button.on {
    background: var(--brand, #4f46e5);
    border-color: var(--brand, #4f46e5);
    color: #fff;
  }

  /* 模型条（章节列底部）压缩成一行不换行 */
  .agd-ebar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .agd-ebar::-webkit-scrollbar { display: none; }

  /* 素材卡：左 1/4 媒体 + 右 3/4 文本，在窄屏保持可用即可（已按比例伸缩） */
  .agd-modal { width: 100% !important; max-width: 100% !important; }

  /* ---------- 8. AI 写作底条：风格/字数/预估/按钮强制一行 ---------- */
  .agd-wz-bar { flex-wrap: nowrap; gap: 6px; }
  .agd-wz-stat, .agd-aprice { display: none; }        /* 状态与单价手机上收起，省宽度 */
  .agd-wz-sel { max-width: 92px; min-width: 0; flex: 0 1 auto; }
  .agd-wz-wcwrap { flex: 0 0 auto; font-size: 11.5px; gap: 3px; }
  .agd-wz-wc { width: 50px; }
  .agd-wz-est {
    flex: 0 1 auto; min-width: 0;
    font-size: 11px; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
  }
  .agd-ebtn.agd-wz-gen { flex: 0 0 auto; padding: 0 10px; white-space: nowrap; }

  /* ---------- 9. 顶栏用户区：头像好点、弹层压住抽屉/工具条 ---------- */
  /* 手机上 mylib-dock(900)/bc-sheets(950) 会盖住顶栏弹层 —— .top 的层叠上下文
     （backdrop-filter 创建）必须整体提到它们之上；modal 再在其上。 */
  .top { z-index: 1000; }
  .user-cluster .avatar { width: 40px; height: 40px; }
  .user-pop { z-index: 1001; }

  /* 弹窗（设置 / 账户明细 / 各类确认）：压在所有面板之上；
     标题栏吸顶 —— 面板再高，✕ 关闭钮也始终在可视区里 */
  .modal { z-index: 1600; }
  .modal .box { max-height: 86vh !important; }
  .modal .box .dhd {
    position: sticky; top: 0; z-index: 5;
    background: var(--panel, #1c1c21);
    box-shadow: 0 1px 0 var(--line, #2a2a30);
  }

  /* ---------- 10. Agent 资产列：手机单列，pad 双列（桌面维持原样） ---------- */
  .agd-mgrid, .agd-agrid { grid-template-columns: 1fr; }
  @media (min-width: 601px) {
    .agd-mgrid, .agd-agrid { grid-template-columns: 1fr 1fr; }
  }

  /* ---------- 11. 工作台：场次卡不再挤压 ---------- */
  /* 桌面 .wb-scenes 两列 × .sc-grid 三列，390px 屏每格只剩 ~60px，文字全竖排。
     手机改成单列场次卡 + 卡内三区（参考设定/视频提示词/视频预览）纵向堆叠。 */
  .wb-scenes { grid-template-columns: 1fr; }
  .sc-grid { grid-template-columns: 1fr; }
  .sc-cell { border-right: 0; border-bottom: 1px solid #2c2c34; }
  .sc-cell:last-of-type { border-bottom: 0; }
  .sc-head { flex-wrap: wrap; }

  /* ---------- 12. 资产详情弹窗：竖排（预览在上、表单在下） ---------- */
  /* 桌面 .ml-dbody 是「左 300px 预览 + 右表单」两列；390px 屏上表单被挤到 3px 宽，
     标签全部竖排（2026-11-05 用户反馈）。手机改上下堆叠，预览区手势缩放由 mobile.js 接管。 */
  .ml-dbox {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 92vh !important;
    border-radius: 16px 16px 0 0;
  }
  .ml-dbody { flex-direction: column; gap: 12px; }
  .ml-dprev {
    width: 100% !important;
    min-height: 0;
    max-height: 46vh;
  }
  /* 手势缩放挂载点（mobile.js 会往图片上写 transform；容器裁掉越界部分） */
  .ml-dprev.m-gz, .ml-zoom.m-gz, .agd-modal-b.m-gz { overflow: hidden; touch-action: none; }

  /* ---------- 8. 图片编辑器（画布 ✎，#bc-ime）：手机端全屏化 + 手指尺寸 ----------
     ⚠️ IME 样式是 board.js 运行时注入 <head> 末尾的（ensureIMEStyle），比本文件晚加载，
     同特异性会盖回来 —— 关键覆盖一律 !important。 */
  #bc-ime { z-index: 9000; }
  #bc-ime .bc-ime {
    width: 100vw !important;
    max-height: 96vh !important;
    border-radius: 0 !important;
    overflow-y: auto;
  }
  #bc-ime .bc-ime-hd { padding: 12px 14px; font-size: 14px; }
  #bc-ime .bc-ime-hd .bc-ime-name { max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  /* 工具条换行（用户拍板：一行显示不全就换行），按钮加到手指高度 */
  #bc-ime .bc-ime-bar {
    flex-wrap: wrap;
    padding: 8px 10px;
    gap: 6px;
  }
  #bc-ime .bc-ime-bar button { padding: 9px 13px; font-size: 13.5px; min-height: 38px; }
  #bc-ime .bc-ime-sep { display: none; }   /* 窄屏分隔线没意义，靠换行分组 */
  #bc-ime .bc-ime-brushopt { width: 100%; justify-content: flex-start; padding: 8px 12px; }
  #bc-ime .bc-ime-brushopt input[type=range] { width: 34vw; }
  #bc-ime .bc-ime-zoom { margin-left: 0; }
  #bc-ime .bc-ime-zoom button { min-height: 34px !important; padding: 5px 12px !important; }
  #bc-ime .bc-ime-stage { padding: 10px; }
  #bc-ime .bc-ime-cvwrap { width: 94vw !important; height: 50vh !important; max-height: 50vh !important; }
  /* 裁剪框角柄 / 取消钮放大到手指尺寸，并移到框内侧 —— 外挂定位会被
     cvwrap 的 overflow:hidden 裁掉（选框铺满画布时角柄只剩 16px 可点条带） */
  #bc-ime .bc-ime-crop-h { width: 28px !important; height: 28px !important; right: 8px !important; bottom: 8px !important; }
  #bc-ime .bc-ime-crop-x { width: 30px !important; height: 30px !important; right: 6px !important; top: 6px !important; font-size: 15px !important; }
  #bc-ime .bc-ime-tip { padding: 8px 12px; line-height: 1.6; }

  /* ---------- 9. 我的空间（#/storage）：表格一行放不下 → 每行拆卡片竖排换行 ---------- */
  .content table.st-tbl { display: block; width: 100%; max-width: 100%; overflow: visible; }
  .content table.st-tbl thead { display: none; }
  .content table.st-tbl tbody { display: block; }
  .content table.st-tbl tr {
    display: block;
    padding: 12px 4px;
    border-bottom: 1px dashed #2e2e34;
  }
  .content table.st-tbl tr:last-child { border-bottom: 0; }
  .content table.st-tbl td {
    display: block;
    width: auto;
    padding: 3px 0;
    text-align: left !important;
    white-space: normal;
    word-break: break-word;
  }
  /* 带 data-l 的单元格前缀灰色小标签，替代表头 */
  .content table.st-tbl td[data-l]::before {
    content: attr(data-l) "：";
    font-size: 11px;
    color: #8a8f98;
    margin-right: 6px;
  }
  /* 多选勾选框与文件名同行：勾选格变行内块 */
  .content table.st-tbl td.st-ckc { display: inline-block; width: auto; vertical-align: top; margin-right: 8px; }
  .content table.st-tbl td.st-ckc + td { display: inline-block; width: calc(100% - 44px); vertical-align: top; }
  /* 操作按钮行靠左，别挤在右边裁掉 */
  .content table.st-tbl td .row { justify-content: flex-start !important; margin-top: 8px; }
  .content table.st-tbl .st-name { word-break: break-all; }
}
