/* ============================================================
   AI中台 移动端适配（纯新增覆盖层）
   仅 @media (max-width: 768px) 下生效，桌面端不受影响
   !important 用于压过组件 scoped 样式（组件 CSS 可能动态后注入）
   ============================================================ */

/* ---- PWA 全局基础优化（桌面端无副作用，刘海屏 env() 为 0） ----
   注意：safe-area 的 top/bottom 已由前端 theme.css 的
   --safe-top/--safe-bottom 变量精确处理（header/输入区），
   此处不再给 body 加 padding，避免 standalone 模式双倍留白。 */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  overscroll-behavior: none;
  /* 禁止 iOS 橡皮筋 */
  -webkit-overflow-scrolling: touch;
}

/* 防止点击 300ms 延迟 */
button, a, input, textarea, select {
  touch-action: manipulation;
}

@media (max-width: 768px) {
  /* iOS Safari 禁止自动缩放字体 */
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  /* ---- 布局：聊天界面全屏 ---- */
  /* 侧边栏（会话列表）滑出屏幕外，内容区占满全宽 */
  .layout-container {
    overflow: hidden;
  }
  .aside-container {
    transform: translateX(-100%) !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 78vw !important;
    max-width: 300px;
    z-index: 1200 !important;
    box-shadow: 0 0 24px rgba(0, 0, 0, 0.18);
  }
  .layout-container-main {
    margin-left: 0 !important;
    width: 100% !important;
  }
  /* 顶部导航：内边距（高度由下方 standalone 修复块统一处理） */
  .layout-header .header-container {
    padding: 0 8px !important;
  }

  /* ---- 聊天页 ---- */
  .chat-with-id-container {
    height: 100%;
  }
  .chat-warp {
    min-height: 0;
    flex: 1 1 auto;
  }
  .chat-with-id-container .chat-warp .el-bubble-list {
    /* 移动端消息区高度适配（输入区更矮） */
    max-height: calc(100vh - 168px - var(--safe-top, 0px) - var(--safe-bottom, 0px)) !important;
  }
  /* 输入区：贴底 + 底部安全区（iPhone Home 条） */
  .sender-wrapper {
    padding-bottom: calc(8px + var(--safe-bottom, 0px)) !important;
  }
  .chat-sender {
    border-radius: 16px !important;
  }

  /* ---- 登录/对话框 ---- */
  .form-container {
    width: 100% !important;
    padding: 16px !important;
    margin: 0 !important;
  }
  .login-header {
    padding: 8px 12px !important;
  }

  /* ---- 底部备案（移动端） ---- */
  .site-footer {
    height: auto !important;
    min-height: 30px;
    flex-wrap: wrap;
    gap: 6px 10px;
    padding: 4px 8px !important;
    font-size: 11px !important;
  }
  .site-copyright {
    width: 100%;
    text-align: center;
  }

  /* ---- AI 生成提示（移动端） ---- */
  .ai-disclaimer {
    font-size: 11px !important;
    padding: 2px 0 4px !important;
  }

  /* ---- 通用 ---- */
  .logo-img {
    width: 32px !important;
    height: 32px !important;
  }
}

/* ============================================================
   手机端对话界面重新设计（纯新增覆盖层，仅 ≤600px）
   顶栏：移动端专用（☰ 历史 / 标题 / ＋ 新建）由 Header 组件渲染
   抽屉：MobileSessionDrawer 组件 scoped 样式自理
   此处仅覆盖第三方组件（vue-element-plus-x 气泡等）
   ============================================================ */
@media (max-width: 600px) {
  /* ---- 消息气泡：用户右对齐蓝色气泡，AI 左对齐浅灰 ---- */
  .el-bubble-end .el-bubble-content {
    background: #409EFF !important;
    color: #ffffff !important;
    border-radius: 16px 4px 16px 16px !important;
    box-shadow: 0 2px 10px rgba(64, 158, 255, 0.28) !important;
    max-width: 84vw !important;
    padding: 10px 14px !important;
    line-height: 1.5 !important;
  }
  .el-bubble-end .user-content {
    color: #ffffff !important;
  }
  /* 用户消息隐藏头像，视觉更紧凑 */
  .el-bubble-end .el-bubble-avatar {
    display: none !important;
  }
  /* 用户气泡内图片 */
  .el-bubble-end .user-image-item {
    border-radius: 8px !important;
    border-color: rgba(255, 255, 255, 0.35) !important;
  }
  /* 用户气泡的复制/编辑按钮（蓝底上弱化为白色半透明） */
  .el-bubble-end .copy-button-container .copy-btn {
    color: rgba(255, 255, 255, 0.65) !important;
  }
  .el-bubble-end .copy-button-container .copy-btn:hover {
    background: rgba(255, 255, 255, 0.18) !important;
    color: #ffffff !important;
  }

  /* ---- AI 消息：头像稍小、内容区右边界留白 ---- */
  .el-bubble-start .el-bubble-avatar {
    width: 28px !important;
    height: 28px !important;
  }
  .el-bubble-start .el-bubble-content {
    max-width: 90vw !important;
  }

  /* ---- 消息区顶部留白（顶栏更矮） ---- */
  .el-bubble-list {
    padding-top: 14px !important;
  }

  /* ---- 默认页（新对话）专家按钮：等宽一排 ---- */
  .expert-bar {
    width: calc(100% - 24px);
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
  }
  .expert-bar button {
    flex: 1;
    min-height: 40px;
    padding: 8px 6px;
    font-size: 12px;
    border-radius: 10px;
  }

  /* ---- 欢迎语 ---- */
  .welcome-text {
    font-size: 24px !important;
    line-height: 28px !important;
    margin-top: 24px !important;
    margin-bottom: 20px !important;
  }
  /* ---- AI 消息：白色气泡（页面浅灰蓝底 #f0f3f7 上层次分明） ---- */
  .el-bubble-start .el-bubble-content {
    background: #ffffff !important;
    border-radius: 4px 16px 16px 16px !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05) !important;
    padding: 10px 12px !important;
  }
  /* AI 消息中的 markdown 容器内边距（与气泡叠加后视觉舒适） */
  .el-bubble-start .elx-xmarkdown-container {
    padding: 2px 4px !important;
  }

  /* ---- 移动端顶栏：纯白不透明，压过 theme.css 磨砂 ---- */
  .mobile-header {
    background: #ffffff !important;
    border-bottom: 0.5px solid rgba(0, 0, 0, 0.06) !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
  }

  /* ---- 抽屉头部安全区（iPhone 刘海） ---- */
  .msd-header {
    padding-top: calc(0px + var(--safe-top, 0px)) !important;
    height: calc(56px + var(--safe-top, 0px)) !important;
  }
}

/* ════════════════════════════════════════════════════════════
   2026-08-31 standalone(PWA) 修复 + 移动端按钮统一（纯覆盖，桌面零影响）
   根因：theme.css .layout-header { padding-top: var(--safe-top) } 未被覆盖，
   添加到主屏幕(standalone)后 safe-top=47px(刘海)，顶栏 48px 高 + 47px padding
   → mobile-header 被挤出屏幕、按钮沉入刘海区域点不动、布局错乱。
   修复：el-header 高度 = 48px + safe-top（内容区保持 48px，位于刘海下方）。
   ════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  /* 顶栏：总高 = 48px 内容 + 刘海安全区；padding-top 保留 safe-top，内容不被刘海遮挡 */
  .layout-header {
    height: calc(48px + var(--safe-top, 0px)) !important;
    padding-top: var(--safe-top, 0px) !important;
    padding-bottom: 0 !important;
    box-sizing: border-box !important;
  }
  /* 消息区高度：显式 = 100dvh - 顶栏(48+safe-top) - 底部备案(30)，不依赖 flex 父链 */
  .chat-warp {
    height: calc(100dvh - 78px - var(--safe-top, 0px)) !important;
    min-height: 0;
  }
  /* 消息列表：dvh 动态视口更稳；180px ≈ 顶栏48+输入区~100+底部备案32 */
  .el-bubble-list {
    max-height: calc(100dvh - 200px - var(--safe-top, 0px) - var(--safe-bottom, 0px)) !important;
  }
  /* 底部备案：避开 iPhone Home 指示条 */
  .site-footer {
    padding-bottom: calc(4px + var(--safe-bottom, 0px)) !important;
  }
}

@media (max-width: 600px) {
  /* ── 顶栏按钮统一：与输入区 4 按钮同风格（浅蓝底 / 品牌蓝 / 10px 圆角） ── */
  .mobile-header {
    position: relative;
    z-index: 21 !important;
  }
  .mobile-header .mh-btn {
    /* 黄金比例 64:40 ≈ 1.6:1，纯图标按钮，无文字 */
    width: 64px !important;
    height: 40px !important;
    border-radius: 12px !important;
    flex-shrink: 0;
    pointer-events: auto !important;
    -webkit-tap-highlight-color: transparent;
    background: var(--el-color-primary-light-9, #ecf5ff) !important;
    color: var(--el-color-primary, #409eff) !important;
    box-sizing: border-box;
    transition: background-color 0.2s ease;
  }
  .mobile-header .mh-btn:active {
    background: var(--el-color-primary-light-7, #d9ecff) !important;
  }

  /* ── 专家按钮统一：浅蓝底蓝边，选中实底白字 ── */
  .expert-bar button {
    background: var(--el-color-primary-light-9, #ecf5ff) !important;
    border: 1px solid var(--el-color-primary-light-7, #d9ecff) !important;
    color: var(--el-color-primary, #409eff) !important;
    font-weight: 500;
  }
  .expert-bar button.active {
    background: var(--el-color-primary, #409eff) !important;
    border-color: var(--el-color-primary, #409eff) !important;
    color: #ffffff !important;
    font-weight: 600;
  }
}
