/* 
 * 移动端浏览器兼容性修复
 * 专门针对：鸿蒙浏览器、华为浏览器、小米浏览器、OPPO浏览器、VIVO浏览器等
 * 优先级：最高
 */

/* ===== 强制层级修复 ===== */
@media screen and (max-width: 980px) {
  
  /* 使用最高优先级选择器 */
  html body div.mobile-menu-toggle,
  body div.mobile-menu-toggle,
  .mobile-menu-toggle {
    z-index: 1001 !important;
    position: fixed !important;
    display: block !important;
  }

  html body aside.side,
  body aside.side,
  .side {
    z-index: 1000 !important;
    position: fixed !important;
  }

  html body div.mobile-overlay,
  body div.mobile-overlay,
  .mobile-overlay {
    z-index: 999 !important;
    position: fixed !important;
    pointer-events: none !important;
    display: none !important;
  }

  html body div.mobile-overlay.show,
  body div.mobile-overlay.show,
  .mobile-overlay.show {
    display: block !important;
    pointer-events: auto !important;
  }

  /* 确保侧边栏内容可点击 */
  html body aside.side *,
  body aside.side *,
  .side * {
    pointer-events: auto !important;
  }

  html body aside.side a,
  body aside.side a,
  .side a,
  html body aside.side button,
  body aside.side button,
  .side button,
  html body aside.side .nav-item,
  body aside.side .nav-item,
  .side .nav-item {
    pointer-events: auto !important;
    touch-action: manipulation !important;
    cursor: pointer !important;
  }

  /* 主题按钮 */
  html body button.theme-toggle,
  body button.theme-toggle,
  .theme-toggle {
    z-index: 90 !important;
    position: fixed !important;
  }

  /* ===== 输入框修复 ===== */
  
  /* 聊天输入区域 */
  html body div.composer,
  body div.composer,
  .composer {
    position: -webkit-sticky !important;
    position: sticky !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 10 !important;
    flex-shrink: 0 !important;
    background: #161310 !important;
    padding: 12px 0 80px !important;
    margin: 0 !important;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.2) !important;
    -webkit-box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.2) !important;
  }

  /* 输入框容器 */
  html body div.composer div.box,
  body div.composer div.box,
  .composer .box {
    position: relative !important;
    z-index: 12 !important;
    pointer-events: auto !important;
    background: rgba(31,27,23,.82) !important;
    border: 1px solid rgba(255,255,255,.12) !important;
  }

  /* 输入框元素 */
  html body div.composer textarea,
  body div.composer textarea,
  .composer textarea,
  html body div.composer input,
  body div.composer input,
  .composer input,
  html body div.composer button,
  body div.composer button,
  .composer button {
    pointer-events: auto !important;
    touch-action: manipulation !important;
    -webkit-tap-highlight-color: rgba(255, 138, 61, 0.3) !important;
  }

  /* ===== 布局修复 ===== */
  
  /* 聊天页面容器 */
  html body div.chat-page,
  body div.chat-page,
  .chat-page {
    height: 100vh !important;
    height: -webkit-fill-available !important;
    display: flex !important;
    display: -webkit-flex !important;
    flex-direction: column !important;
    -webkit-flex-direction: column !important;
    overflow: hidden !important;
  }

  /* 消息列表 */
  html body div.msgs,
  body div.msgs,
  .msgs {
    flex: 1 !important;
    -webkit-flex: 1 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
  }

  /* ===== 禁用可能干扰的样式 ===== */
  
  /* 移除自定义光标 */
  html body .cur,
  body .cur,
  .cur,
  html body .cur-dot,
  body .cur-dot,
  .cur-dot {
    display: none !important;
    pointer-events: none !important;
  }

  /* 确保背景元素不干扰 */
  html body .bg-wrap,
  body .bg-wrap,
  .bg-wrap,
  html body .noise,
  body .noise,
  .noise,
  html body .grid-lines,
  body .grid-lines,
  .grid-lines,
  html body .orb,
  body .orb,
  .orb {
    z-index: 0 !important;
    pointer-events: none !important;
  }

  /* ===== 强制重置可能冲突的样式 ===== */
  
  * {
    -webkit-tap-highlight-color: rgba(255, 138, 61, 0.2) !important;
  }

  a, button, input, textarea, select {
    cursor: pointer !important;
    -webkit-user-select: auto !important;
    user-select: auto !important;
  }

  /* 防止浏览器缩放 */
  input, textarea, select {
    font-size: 16px !important;
  }

  /* ===== 额外的兼容性修复 ===== */
  
  /* 修复华为/鸿蒙浏览器的 viewport 问题 */
  html {
    height: 100% !important;
    height: -webkit-fill-available !important;
  }

  body {
    min-height: 100vh !important;
    min-height: -webkit-fill-available !important;
  }

  /* 修复 sticky 定位在部分浏览器的问题 */
  @supports not (position: sticky) {
    html body div.composer,
    body div.composer,
    .composer {
      position: fixed !important;
    }
  }

  /* 修复弹性布局兼容性 */
  .chat,
  .chat-layout,
  .chat-wrap {
    display: -webkit-box !important;
    display: -webkit-flex !important;
    display: flex !important;
    -webkit-box-orient: vertical !important;
    -webkit-box-direction: normal !important;
    -webkit-flex-direction: column !important;
    flex-direction: column !important;
  }
}

/* ===== 针对特定浏览器的额外修复 ===== */

/* 鸿蒙浏览器 */
@media screen and (max-width: 980px) {
  @supports (-webkit-overflow-scrolling: touch) {
    html body div.composer,
    body div.composer,
    .composer {
      padding-bottom: 90px !important;
    }
  }
}

/* UC浏览器 */
@media screen and (-webkit-min-device-pixel-ratio: 0) and (max-width: 980px) {
  html body aside.side,
  body aside.side,
  .side {
    -webkit-transform: translateX(-100%) !important;
    transform: translateX(-100%) !important;
  }

  html body aside.side.mobile-open,
  body aside.side.mobile-open,
  .side.mobile-open {
    -webkit-transform: translateX(0) !important;
    transform: translateX(0) !important;
  }
}

/* 小米浏览器 */
@media screen and (max-width: 980px) {
  html body div.mobile-overlay,
  body div.mobile-overlay {
    -webkit-backdrop-filter: blur(0) !important;
    backdrop-filter: blur(0) !important;
  }
}

/* 强制重置 - 最后的保险 */
@media screen and (max-width: 980px) {
  [class*="mobile-menu-toggle"] {
    z-index: 1001 !important;
  }
  
  [class*="side"]:not([class*="inside"]) {
    z-index: 1000 !important;
  }
  
  [class*="mobile-overlay"] {
    z-index: 999 !important;
  }
}
