/* ============================================================
   mobile-chat.css · 移动端「对话台 / 协作舰桥」覆盖层
   归属：B 线（对话/舰桥适配）独占。其他线不许编辑本文件。
   规则：只写 @media (max-width:900px) 与 (pointer:coarse) 内的覆盖，
        不许改桌面端任何像素。单一正本，禁止复制页面。
   ============================================================ */

/* ============================================================
   ≤900px（含 iPad 竖 768）
   ============================================================ */
@media (max-width: 900px) {

  /* ---------- 全局地基 ---------- */
  html, body { max-width: 100%; overflow-x: hidden; }
  html { -webkit-tap-highlight-color: transparent; }
  body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }

  /* ---------- 顶栏：允许换行、接安全区 ---------- */
  .top {
    height: auto; min-height: 56px; flex-wrap: wrap; gap: 8px 10px;
    padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
    position: sticky; top: 0;
  }
  .top .btn { min-height: 44px; }
  .top .btn-sm { min-height: 38px; }
  .top .vsep { align-self: center; }
  .top #crumb { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* ---------- 底部标签栏（mobile.js 注入）层级兜底 + 键盘时隐藏 ---------- */
  #mTabbar { z-index: 1000 !important; padding-bottom: calc(8px + env(safe-area-inset-bottom)) !important; }
  #mDrawer, #mDrawerMask, .m-drawer-mask { z-index: 1100 !important; }
  html[data-kb="on"] #mTabbar { display: none !important; }

  /* ---------- 点按可视反馈 ---------- */
  .btn:active, .btn-sm:active, .ib:active, .cap-tabs button:active,
  .plus-item:active, .crew-item:active, .pick:active, .hist-item:active,
  .att-item:active, .linkcard:active, .li.link:active, .node:active,
  .m-stage-lock:active, .m-perf-btn:active {
    transform: scale(.96); opacity: .82; transition: transform .08s;
  }

  /* ---------- 触控热区 ≥44px（关键按钮） ---------- */
  .btn { min-height: 44px; }
  .btn-sm { min-height: 44px; }
  .ib { min-height: 44px; min-width: 44px; }
  .cap-tabs button { min-height: 44px; padding: 8px 14px; }
  .hist-item { padding: 12px; }
  .hist-x { min-width: 44px; min-height: 44px; padding: 10px; }
  .plus-item, .att-item { min-height: 44px; align-items: center; }
  .crew-item, .pick { min-height: 48px; }
  .li.link, .linkcard { min-height: 48px; }
  .inp, .sel { font-size: 16px; }   /* ≥16px 防 iOS 聚焦自动放大 */

  /* bot 顶栏 logo 链接热区 ≥44 */
  body[data-m-page="bot"] .top .logo {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    padding: 0 8px;
  }

  /* ============================================================
     bot.html · Bot 详情 / 对话台
     ============================================================ */
  body[data-m-page="bot"] .wrap { padding: 14px 12px; padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  body[data-m-page="bot"] .card { padding: 14px; }
  body[data-m-page="bot"] .kpi b { font-size: 19px; }
  body[data-m-page="bot"] .row2 { grid-template-columns: 1fr; }

  /* 首屏对话优先：把大图收小成一条横条，对话区至少 240px 高 */
  body[data-m-page="bot"] .hero {
    height: 96px;
    position: relative;
    overflow: hidden;
  }
  body[data-m-page="bot"] .hero::after {
    /* 压淡红色霓虹：冷色罩一层，避免被误读成告警红 */
    content: "";
    position: absolute; inset: 0;
    background: linear-gradient(180deg, rgba(20,30,55,.35), rgba(15,20,40,.55));
    mix-blend-mode: multiply;
    pointer-events: none;
  }
  body[data-m-page="bot"] .hero img {
    filter: saturate(.65) brightness(.9) hue-rotate(-8deg);
    object-position: center 30%;
  }
  body[data-m-page="bot"] .chat-log {
    min-height: 240px;
    max-height: 46vh;
  }
  body[data-m-page="bot"] .composer { flex-wrap: wrap; }
  body[data-m-page="bot"] .composer #chatSend { min-height: 44px; flex: 0 0 auto; }

  /* 对话输入条：贴底固定（微信式），压在标签栏之上；键盘弹起时浮到键盘上方 */
  body[data-m-page="bot"] .composer {
    position: fixed; left: 10px; right: 10px; z-index: 850;
    width: calc(100vw - 20px);
    max-width: calc(100vw - 20px);
    box-sizing: border-box;
    bottom: calc(var(--m-tabbar-h, 65px) + env(safe-area-inset-bottom) + var(--kb-h, 0px));
    margin: 0; padding: 8px 10px;
    background: var(--panel, #12151b);
    border: 1px solid var(--line, rgba(255,255,255,.12));
    border-radius: 12px;
    box-shadow: 0 -6px 24px rgba(0,0,0,.4);
  }
  html[data-kb="on"] body[data-m-page="bot"] .composer {
    bottom: calc(var(--kb-h, 0px) + env(safe-area-inset-bottom));
  }
  /* 浅色主题下 composer 不能是黑卡（实测 light 主题下 bot 输入条仍是 #12151b 黑底） */
  html[data-theme="light"] body[data-m-page="bot"] .composer {
    background: #ffffff;
    border-color: rgba(16,24,40,.12);
    box-shadow: 0 -6px 24px rgba(0,0,0,.12);
  }
  body[data-m-page="bot"] .wrap { padding-bottom: calc(210px + env(safe-area-inset-bottom)); }

  /* 历史抽屉：手机上全高 */
  body[data-m-page="bot"] .hist-drawer { width: 100vw; max-width: 400px; }
  body[data-m-page="bot"] .hist-item .hi-acts { opacity: 1; } /* 手机没有 hover，动作常显 */
  body[data-m-page="bot"] .hist-item .hi-acts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 10px;
  }
  body[data-m-page="bot"] .hist-item .hi-act {
    min-height: 44px;
    padding: 10px 8px;
    font-size: 13px;
    background: rgba(255,255,255,.06);
    border-radius: 8px;
    color: var(--text, #ddd);
    width: 100%;
  }

  /* ============================================================
     bridge.html · 协作舰桥
     ============================================================ */
  body[data-m-page="bridge"] .bridge {
    grid-template-columns: 1fr !important;
    height: auto !important;
    padding: 10px 10px calc(170px + env(safe-area-inset-bottom));
    gap: 10px;
  }
  body[data-m-page="bridge"] .hud { flex-wrap: wrap; gap: 6px 10px; font-size: 11px; padding: 8px 10px; }
  body[data-m-page="bridge"] .hud .grow { display: none; }

  /* 舞台：单指旋转（默认）/ 锁定后滚动（html[data-stage-lock]） */
  body[data-m-page="bridge"] .orb-wrap {
    height: auto; min-height: 320px;
    touch-action: none;               /* 默认单指=旋转 */
    position: relative;
  }
  html[data-stage-lock] body[data-m-page="bridge"] .orb-wrap { touch-action: pan-y; }
  body[data-m-page="bridge"] .orb { width: min(76vw, 320px) !important; }

  body[data-m-page="bridge"] .stream-wrap { height: 220px; min-height: 200px; margin: 0 8px 8px; }
  /* 输入条：与 bot 同一套微信式贴底（压标签栏之上，键盘时 --kb-h 浮起） */
  body[data-m-page="bridge"] .console {
    position: fixed; left: 10px; right: 10px; z-index: 850; margin: 0;
    bottom: calc(var(--m-tabbar-h, 65px) + env(safe-area-inset-bottom) + var(--kb-h, 0px));
  }
  html[data-kb="on"] body[data-m-page="bridge"] .console {
    bottom: calc(var(--kb-h, 0px) + env(safe-area-inset-bottom));
  }
  body[data-m-page="bridge"] .console-in input { font-size: 16px; min-width: 0; flex: 1 1 auto; }
  /* wave 波形条在手机上窄一点，给输入框让地方 */
  body[data-m-page="bridge"] .console-in .wave { flex: 0 0 auto; width: 18px; }
  body[data-m-page="bridge"] .console-in .wave i { height: 10px !important; }
  /* 输入框 placeholder 太长时，手机上缩短观感（不删文案，只是溢出隐藏 ellipsis） */
  body[data-m-page="bridge"] .console-in input { text-overflow: ellipsis; }
  body[data-m-page="bridge"] .left-body,
  body[data-m-page="bridge"] .right-body { height: auto; max-height: none; overflow: visible; }

  /* 选 Bot 抽屉：手机上变底部弹层 */
  body[data-m-page="bridge"] .drawer {
    left: 8px; right: 8px; width: auto; top: auto;
    bottom: calc(76px + env(safe-area-inset-bottom));
    max-height: 58vh; z-index: 91;
  }
  body[data-m-page="bridge"] .drawer-mask { z-index: 90; }
  /* 作战室抽屉：全宽 */
  body[data-m-page="bridge"] .war { width: 100vw; max-width: 100vw; }
  body[data-m-page="bridge"] .war-flow { max-height: 40vh; }

  /* 操作杆缩一点，不挡舞台 */
  body[data-m-page="bridge"] .stick-dock { transform: scale(.85); transform-origin: top right; }

  /* ---------- 舞台锁定按钮（mobile-chat.js 注入） ---------- */
  .m-stage-lock {
    position: absolute; top: 8px; right: 8px;
    width: 44px; height: 44px; z-index: 25;
    border-radius: 10px; cursor: pointer;
    background: rgba(8,10,14,.78); color: #ffd7de;
    border: 1px solid rgba(200,16,46,.45); font-size: 18px;
    display: grid; place-items: center;
  }
  .m-stage-lock.on { background: rgba(200,16,46,.25); border-color: #C8102E; }

  /* ---------- 性能切换浮动按钮 ---------- */
  .m-perf-btn {
    position: fixed; right: 10px;
    bottom: calc(132px + env(safe-area-inset-bottom));
    z-index: 999;
    min-width: 44px; min-height: 44px; height: 44px; padding: 0 12px;
    border-radius: 999px; font-size: 11px; cursor: pointer;
    background: rgba(18,21,27,.9); color: #cfd3dc;
    border: 1px solid rgba(255,255,255,.18);
    backdrop-filter: blur(6px);
    display: inline-flex; align-items: center; justify-content: center;
  }
  html[data-kb="on"] .m-perf-btn { display: none; }

  /* 窄屏不常驻（仅 bot 对话页）：页面存在离屏面板把横向布局撑到 >390px，fixed 元素
     按撑开后的布局视口对齐，会半露在输入条右缘压住发送键。bot.html 无"更多"菜单抽屉
     可收纳，本轮按"不常驻"在 bot 页隐藏；性能档位默认 low（省电）且本地持久化，
     bridge 页开关与桌面端不受影响。 */
  body[data-m-page="bot"] .m-perf-btn { display: none !important; }

  /* ---------- 轻提示 ---------- */
  .m-toast {
    position: fixed; left: 50%;
    bottom: calc(86px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    max-width: 86vw; padding: 10px 16px; border-radius: 10px;
    background: #171a21; border: 1px solid #C8102E; color: #eee;
    font-size: 12.5px; z-index: 1300;
    box-shadow: 0 12px 34px rgba(0,0,0,.55);
  }

  /* ---------- 低性能模式：关动画 / 网格 / 模糊（契约 §8） ---------- */
  html[data-perf="low"] .ring.r1,
  html[data-perf="low"] .ring.r2,
  html[data-perf="low"] .ring.r3,
  html[data-perf="low"] .sweep,
  html[data-perf="low"] .core,
  html[data-perf="low"] .console { animation: none !important; }
  html[data-perf="low"] .deck::before { display: none; }
  html[data-perf="low"] .orb-wrap { backdrop-filter: none; }

  /* ---------- 浅色主题：bridge 自绘深色背景必须翻掉（契约 §7） ---------- */
  html[data-theme="light"] body[data-m-page="bridge"] {
    background:
      radial-gradient(1200px 600px at 50% -10%, rgba(200,16,46,.08), transparent 70%),
      #f2f3f6 !important;
  }
  html[data-theme="light"] body[data-m-page="bridge"] .deck {
    background: linear-gradient(180deg, #ffffff, #eef0f3);
    border-color: rgba(0,0,0,.08);
  }
  html[data-theme="light"] body[data-m-page="bridge"] .deck::before {
    background-image:
      linear-gradient(rgba(0,0,0,.035) 1px, transparent 1px),
      linear-gradient(90deg, rgba(0,0,0,.035) 1px, transparent 1px);
  }
  html[data-theme="light"] body[data-m-page="bridge"] .stream-wrap {
    background: rgba(255,255,255,.85);
    border-color: rgba(0,0,0,.08);
  }
  html[data-theme="light"] body[data-m-page="bridge"] .stream .bub {
    background: #f3f4f7; border-color: rgba(0,0,0,.08); color: #222;
  }
  html[data-theme="light"] body[data-m-page="bridge"] .console-in {
    background: rgba(255,255,255,.96);
  }
  html[data-theme="light"] body[data-m-page="bridge"] .console-in input { color: #222; }
  html[data-theme="light"] body[data-m-page="bridge"] .console-in input::placeholder { color: #999; }
  html[data-theme="light"] body[data-m-page="bridge"] .ib:not(.go) { color: #333; border-color: rgba(0,0,0,.15); background: rgba(0,0,0,.04); }
  html[data-theme="light"] body[data-m-page="bridge"] .drawer { background: #fff; }
  html[data-theme="light"] body[data-m-page="bridge"] .stick-dock { background: rgba(255,255,255,.85); }

  /* ============================================================
     D1（第四轮）：手机端 bot 详情页"对话优先"
     DOM 顺序已是：对话卡 → 摘要条 → 运营折叠面板 → aside
     - 摘要条永远可见，≥44 热区；ops-wrap 默认 hidden，点摘要条展开
     ============================================================ */
  body[data-m-page="bot"] main.wrap.split {
    display: flex;
    flex-direction: column;
    gap: 0;
  }
  body[data-m-page="bot"] section,
  body[data-m-page="bot"] aside { min-width: 0; }

  /* 运营摘要条：固定在对话区下方、永远可见，≥44 热区 */
  body[data-m-page="bot"] .ops-summary {
    margin: 10px 12px 4px;
    min-height: 44px;
    padding: 10px 14px;
    display: flex; align-items: center; gap: 10px;
    background: var(--panel, #12151b);
    border: 1px solid var(--line, rgba(255,255,255,.12));
    border-radius: 10px;
    color: var(--text, #ddd);
    font-size: 13px;
    cursor: pointer;
    width: auto;
    text-align: left;
    box-sizing: border-box;
  }
  body[data-m-page="bot"] .ops-summary .ops-sum-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: #34d399; flex: 0 0 auto;
  }
  body[data-m-page="bot"] .ops-summary .ops-sum-text { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  body[data-m-page="bot"] .ops-summary .ops-sum-caret { color: var(--text-dim, #888); font-size: 12px; }
  body[data-m-page="bot"] .ops-summary:active { transform: scale(.98); opacity: .9; }

  /* 运营面板：默认折叠（hidden 属性），.open 展开 */
  body[data-m-page="bot"] .ops-wrap[hidden] { display: none; }
  body[data-m-page="bot"] .ops-wrap { display: block; padding: 0 12px; }
  body[data-m-page="bot"] .ops-wrap .card { margin: 10px 0; }

  /* 防止运营面板内的宽表/看板把横向布局撑爆（ob-* 等来自 panels/*） */
  body[data-m-page="bot"] .ops-wrap,
  body[data-m-page="bot"] .ops-wrap * {
    max-width: 100%;
  }
  body[data-m-page="bot"] .cap-pane,
  body[data-m-page="bot"] .kpis,
  body[data-m-page="bot"] .card { min-width: 0; }

  /* 系统分隔消息（D4 换人提示） */
  body[data-m-page="bot"] .msg.system {
    max-width: 100%;
    margin: 10px auto;
    text-align: center;
    background: transparent;
    padding: 0;
  }
  body[data-m-page="bot"] .msg.system .sys-inner {
    display: inline-block;
    font-size: 12px;
    color: var(--text-dim, #999);
    background: rgba(255,255,255,.06);
    padding: 6px 12px;
    border-radius: 999px;
    line-height: 1.5;
    max-width: 88%;
  }

  /* 快捷回答条按钮热区 ≥44（之前是 33） */
  body[data-m-page="bot"] .cc-quick-btn {
    min-height: 44px;
    padding: 8px 14px;
    font-size: 13px;
  }
}

/* ============================================================
   桌面端（≥901px）对齐手机的 D1 口径：对话优先 + 运营折叠
   本块与 app.css 平级，只覆盖 bot 页；右栏（Bot 详情）不动
   ============================================================ */
@media (min-width: 901px) {
  /* 运营摘要条：桌面端也可见，不再隐藏 */
  body[data-m-page="bot"] .ops-summary {
    display: flex !important;
    align-items: center;
    gap: 10px;
    margin: 0 0 14px;
    min-height: 44px;
    padding: 10px 16px;
    background: var(--panel, #12151b);
    border: 1px solid var(--line, rgba(255,255,255,.12));
    border-radius: 10px;
    color: var(--text, #ddd);
    font-size: 13px;
    cursor: pointer;
    text-align: left;
    box-sizing: border-box;
    width: 100%;
  }
  body[data-m-page="bot"] .ops-summary .ops-sum-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: #34d399; flex: 0 0 auto;
  }
  body[data-m-page="bot"] .ops-summary .ops-sum-text { flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  body[data-m-page="bot"] .ops-summary .ops-sum-caret { color: var(--text-dim, #888); font-size: 12px; }

  /* 运营面板：桌面端默认收起（与手机一致），.open 展开 */
  body[data-m-page="bot"] .ops-wrap[hidden] { display: none !important; }
  body[data-m-page="bot"] .ops-wrap { display: block; }

  /* 对话区主位：≥320px 可视高度，按内容撑高，max 44vh */
  body[data-m-page="bot"] .chat-log {
    min-height: 320px !important;
    max-height: 44vh;
    overflow-y: auto;
  }
  body[data-m-page="bot"] .chat-card > .card {
    display: flex;
    flex-direction: column;
  }
  body[data-m-page="bot"] .chat-card .composer {
    flex: 0 0 auto;
    position: static !important;
    width: auto !important;
    max-width: none !important;
    left: auto !important; right: auto !important;
    bottom: auto !important;
    margin-top: auto;
  }
  body[data-m-page="bot"] .composer #chatSend {
    min-height: 44px;
    min-width: 64px;
    padding: 0 20px;
  }
  body[data-m-page="bot"] .composer #chatInp {
    min-height: 44px;
    font-size: 14px;
  }
  /* 桌面端不再给 .wrap 底部留 210px 死区（那是给手机固定输入条用的） */
  body[data-m-page="bot"] .wrap { padding-bottom: 24px; }
}

/* ============================================================
   粗指针（手机/平板）增强
   ============================================================ */
@media (pointer: coarse) {
  .btn, .ib, .cap-tabs button { touch-action: manipulation; }
  /* 长交付物：触摸没有 hover，复制/引用按钮常驻可见，否则手机上根本点不到 */
  .tm-acts { opacity: 1 !important; }
  /* 表格块在手机上允许横向滑动，不撑破气泡 */
  .tm-pre { max-width: 100%; -webkit-overflow-scrolling: touch; }
}

/* ============================================================
   长交付物表格：窄屏字号/内边距收紧，横向滑动由 .tm-table-wrap 负责
   ============================================================ */
@media (max-width: 900px) {
  .tm-table { font-size: 12px; line-height: 1.5; }
  .tm-table th, .tm-table td { padding: 6px 9px; }
  .tm-table th.tm-col-wide, .tm-table td.tm-col-wide { max-width: 200px; }
  .tm-h2 { font-size: 13.5px; margin: 12px 0 5px; }
  .tm-h3 { font-size: 12.5px; margin: 9px 0 4px; }
  .tm-p { font-size: 13px; }
}
