/* ============================================================================
 * v1357（本文件初版 v1355）· 数智人面板「矮视口 / 横屏」可用性修复
 * 叠加层，可整文件删除回滚；不动任何既有 css/js。
 * ----------------------------------------------------------------------------
 * 证据 1（prod 844x390 展开态）：#ai-avatar-fab max-height:94vh(366px)、overflow:hidden、
 *   scrollH 561 > clientH 366 → 状态行/气泡关闭键/快捷 chips 全在视口外且不可滚。
 * 证据 2（全断点含桌面）：.ai-avatar-bubble-close 被 .ai-avatar-quick-chip 遮挡（hitOk=False）。
 *
 * 两次失败的实测教训（#163 升级）：
 *   · v1355：`.dock-expanded` 特异性低于 `:not(.fullscreen-mode):not(.tv-mode):not(.body-mode)` → 被压
 *   · v1356：改成同构选择器【仍不生效】—— theme.css:201 同构 + dock-geometry.css:64
 *     双方都 !important 时按加载顺序，dock-geometry 在后面 → 我仍输。
 *   · v1357：改用【重复 id 提权】`#ai-avatar-fab#ai-avatar-fab`（项目内 contrast-aa-fix.css 已有先例），
 *     特异性 (2,4,2) 无条件胜出，不再依赖加载顺序。
 * ========================================================================== */

/* ① 全断点：气泡关闭键【几何归位】—— 实测桌面 1440x900：
      bubble rect y=577~617(z:5)，close rect y=616~644 → 关闭键向下溢出到
      .ai-avatar-quick-chips(y=618, z:8) 区域，被 chip 压住，点不到。
      单纯提 z 会让 28px 的关闭键反压住 chips（chips 才是自然语言主入口），
      故改为把关闭键收进气泡内部右上角，物理消除重叠（同时给文字留右边距）。 */
/* v1359 修正：右上角是【自家】#lx-evolve-toggle（#ai-avatar-fab 的子元素，z:800，
   rect 1394,557,26,26）的地盘，关闭键放右上必然被它压死（命中栈实测 toggle 在上）。
   → 关闭键改到气泡【左上】，物理避开右上 toggle 与底部 chips；文字左侧留位。 */
/* v1361【回滚到 v1358 方案】—— v1359(左上) / v1360(右侧居中) 均失败：
   #lx-evolve-toggle 是面板自己的子元素且位置随断点变化（桌面贴气泡右上、竖屏贴气泡右侧中部），
   与气泡关闭键存在【结构性冲突】，纯 CSS 挪位是打地鼠（三次实测：右上→左上→右中，各有断点失败）。
   v1358 是实测最优解（横屏 844×390 全绿 + 竖屏 390×844 全绿，移动端优先），故定稿于此。
   彻底解决需产品决策：① 气泡改为点击任意处/超时自动消失（去掉关闭键）
   ② 重排 #lx-evolve-toggle 位置 —— 已列入请示项，未擅动。 */
/* v1362【老板 🅰 方案】气泡关闭键 = 冗余 + 结构性冲突源，直接隐藏：
   ① JS 已有 4 秒自动消失：ai-avatar-v285.js:3781 `setTimeout(_hideChatBubble, 4e3)`（v1031）
   ② 面板折叠时同样隐藏（同文件 :1273 _hideChatBubble）
   ③ 它与自家 #lx-evolve-toggle(z:800) 物理重叠且层级更低 → 永远点不到（打地鼠三连败）
   → 隐藏后彻底消除冲突；气泡 4 秒自动消失，功能零损失。 */
html body #ai-avatar-fab#ai-avatar-fab .ai-avatar-bubble-close {
  display: none !important;
}
html body #ai-avatar-fab#ai-avatar-fab .ai-avatar-bubble-text {
  padding-right: 0 !important;
  padding-left: 0 !important;
}

@media (max-height: 520px) {
  /* ② 面板可滚 + 高度收敛（重复 id 提权） */
  html body #ai-avatar-fab#ai-avatar-fab.fab-ai.ai-dock.dock-expanded:not(.fullscreen-mode):not(.tv-mode):not(.body-mode) {
    max-height: calc(100vh - 24px) !important;
    max-height: calc(100dvh - 24px) !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
  }

  /* ③ 形象区收敛 38vh（object-fit:contain 不裁切数字人） */
  html body #ai-avatar-fab#ai-avatar-fab.fab-ai.ai-dock.dock-expanded:not(.fullscreen-mode):not(.tv-mode):not(.body-mode) .ai-dock-avatar-area {
    max-height: 38vh !important;
    flex: 0 0 auto !important;
  }
  html body #ai-avatar-fab#ai-avatar-fab.fab-ai.ai-dock.dock-expanded:not(.fullscreen-mode):not(.tv-mode):not(.body-mode) .ai-dock-avatar-area img,
  html body #ai-avatar-fab#ai-avatar-fab.fab-ai.ai-dock.dock-expanded:not(.fullscreen-mode):not(.tv-mode):not(.body-mode) .ai-dock-avatar-area canvas {
    max-height: 38vh !important;
    object-fit: contain !important;
  }

  /* ④ 折叠键常驻顶部（滚后不再跑出视口，实测 y=-15/-109/-167） */
  html body #ai-avatar-fab .ai-dock-toggle {
    position: sticky !important;
    top: 0 !important;
    z-index: 11 !important;
  }

  /* ⑤ 快捷提问（自然语言交互主入口）常驻底部 */
  html body #ai-avatar-fab .ai-avatar-quick-chips {
    position: sticky !important;
    bottom: 0 !important;
    z-index: 9 !important;
    background: var(--surface-deep, #0e1420) !important;
  }

  /* ⑥ 状态行不被挤出容器 */
  html body #ai-avatar-fab .ai-dock-info {
    flex: 0 0 auto !important;
  }
}

/* ============================================================================
 * v2163 · P1-1 根治：矮视口（height ≤ 520px）展开画布被压成横条
 * ----------------------------------------------------------------------------
 * 病灶（本文件 v1355 原 ③ 块）：只对 area 与 canvas 钉 max-height:38vh，
 *   宽度仍是 100% → aspect-ratio:var(--dock-ar) 被 max-height 单侧钳死，
 *   容器比例失控。实测 canvas CSS 宽高比：
 *     844x390  → 274.42x151.79  ar=1.8079  偏差 +121.57%（位图同步 536x296）
 *     1280x500 → 275.08x195.60  ar=1.4063  偏差 +72.36% （位图同步 268x190）
 *     640x360  → 204.56x134.83  ar=1.5172  偏差 +85.94% （位图同步 416x274）
 *   目标 430/527 = 0.8159。像素取证：两侧取样 rgb(15,15,30) 纯深底，
 *   人像被 letterbox 到中间（仅占 45%~58% 宽）——老板零容忍的"扭曲/错位"。
 * 修法：限高的同时【按 0.8159 同步收缩宽度】——width = 38vh * 0.8159，
 *   再由 aspect-ratio 派生 height = width/0.8159 = 38vh，与 max-height 恰好相等，
 *   钳位不再生效 → 比例恒定 0.8159。
 *   铁律：max-height 与 min-height 同时钉，防 !important max-* 无声 clamp。
 * ========================================================================== */
@media (max-height: 520px) {
  html body #ai-avatar-fab#ai-avatar-fab.fab-ai.ai-dock.dock-expanded:not(.fullscreen-mode):not(.tv-mode):not(.body-mode) .ai-dock-avatar-area {
    width: calc(38vh * 0.8159) !important;
    max-width: calc(38vh * 0.8159) !important;
    min-width: 0 !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: 38vh !important;
    aspect-ratio: 430 / 527 !important;
    flex: 0 0 auto !important;
    flex-shrink: 0 !important;
  }
  html body #ai-avatar-fab#ai-avatar-fab.fab-ai.ai-dock.dock-expanded:not(.fullscreen-mode):not(.tv-mode):not(.body-mode) .ai-dock-avatar-area canvas,
  html body #ai-avatar-fab#ai-avatar-fab.fab-ai.ai-dock.dock-expanded:not(.fullscreen-mode):not(.tv-mode):not(.body-mode) .ai-dock-avatar-area img {
    width: 100% !important;
    height: 100% !important;
    min-width: 0 !important;
    min-height: 0 !important;
    max-width: 100% !important;
    max-height: 100% !important;
    object-fit: cover !important;
    object-position: 50% 0% !important;
  }
}
