/* AIBuy mobile UI fix v6 — critical: do NOT force indicator to position:relative
   That crushed the lens to ~13px and fused it into the bar.
*/

@media (max-width: 650px) {
  :root:not(#_v3) .mobile-navigation-primary,
  :root:not(#_v3) .mobile-navigation-toggle,
  :root:not(#_v3) .mobile-navigation-extra {
    isolation: auto !important;
  }

  :root:not(#_v3) .mobile-navigation-primary,
  :root:not(#_v3) .mobile-navigation-toggle,
  :root:not(#_v3) .mobile-navigation.is-expanded .mobile-navigation-extra {
    -webkit-backdrop-filter: blur(22px) saturate(160%) !important;
    backdrop-filter: blur(22px) saturate(160%) !important;
    background: rgba(255, 255, 255, 0.5) !important;
    border: 1px solid rgba(255, 255, 255, 0.65) !important;
    box-shadow:
      0 14px 34px -14px rgba(0, 0, 0, 0.28),
      0 2px 6px rgba(0, 0, 0, 0.06),
      inset 0 1px 0 rgba(255, 255, 255, 0.9) !important;
  }

  :root:not(#_v3) .mobile-navigation-primary::before,
  :root:not(#_v3) .mobile-navigation-toggle::before,
  :root:not(#_v3) .mobile-navigation-extra::before {
    z-index: 0 !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    background: radial-gradient(120% 80% at 50% -20%, rgba(255,255,255,.55), transparent 60%),
                linear-gradient(180deg, rgba(255,255,255,.45), rgba(255,255,255,.18)) !important;
    border: 1px solid rgba(255, 255, 255, 0.6) !important;
    box-shadow:
      0 14px 34px -14px rgba(0, 0, 0, 0.28),
      inset 0 1px 0 rgba(255, 255, 255, 0.95) !important;
  }

  /* icons/links above glass — NEVER include the indicator */
  :root:not(#_v3) .mobile-navigation-primary > a,
  :root:not(#_v3) .mobile-navigation-toggle > svg,
  :root:not(#_v3) .mobile-navigation-toggle > *,
  :root:not(#_v3) .mobile-navigation-extra > a {
    position: relative;
    z-index: 1;
  }

  /* ===== Lens: absolute overlay, full tab width, spring-draggable ===== */
  :root:not(#_v3) .mobile-navigation-indicator {
    position: absolute !important;
    top: 6px !important;
    left: 0 !important;
    height: 44px !important;
    width: calc((100% - 12px - 6px) / 4) !important;
    z-index: 0 !important;
    pointer-events: none !important;
    flex: none !important;
    grid-column: unset !important;
  }

  :root:not(#_v3) .mobile-navigation-indicator::before {
    background: radial-gradient(100% 90% at 50% 12%, rgba(255,255,255,.92), rgba(255,255,255,.62) 52%, rgba(255,255,255,.4)) !important;
    border: 1px solid rgba(255, 255, 255, 0.9) !important;
    box-shadow:
      inset 0 1px 1px #fff,
      inset 0 -2px 5px rgba(0, 0, 0, 0.06),
      0 3px 10px -3px rgba(0, 0, 0, 0.2) !important;
  }

  :root:not(#_v3) .mobile-navigation-primary:is([data-gesture="pressed"], [data-gesture="dragging"]) .mobile-navigation-indicator::before,
  html.aibuy-spring:not(#_v3) .mobile-navigation-primary[data-lens="up"] .mobile-navigation-indicator::before {
    background: radial-gradient(100% 90% at 50% 8%, rgba(255,255,255,.4), rgba(255,255,255,0) 50%, rgba(255,255,255,.14)) !important;
    border-color: rgba(255, 255, 255, 0.95) !important;
    box-shadow:
      inset 0 1.5px 1px rgba(255,255,255,.95),
      inset 0 -1.5px 1px rgba(255,255,255,.45),
      0 10px 24px -8px rgba(0, 0, 0, 0.28) !important;
  }

  :root:not(#_v3) .mobile-navigation-primary,
  :root:not(#_v3) .mobile-navigation-primary::before,
  :root:not(#_v3) .mobile-navigation-toggle {
    transition: none !important;
  }
  :root:not(#_v3) .mobile-navigation {
    transition: translate .2s ease, opacity .14s ease !important;
  }

  :root:not(#_v3) .mobile-navigation.is-minimized {
    background: rgba(255, 255, 255, 0.58) !important;
    border: 1px solid rgba(255, 255, 255, 0.7) !important;
    -webkit-backdrop-filter: blur(20px) saturate(150%) !important;
    backdrop-filter: blur(20px) saturate(150%) !important;
  }

  :root[data-theme="dark"]:not(#_v3) .mobile-navigation-primary,
  :root[data-theme="dark"]:not(#_v3) .mobile-navigation-toggle,
  :root[data-theme="dark"]:not(#_v3) .mobile-navigation.is-expanded .mobile-navigation-extra {
    background: rgba(255, 255, 255, 0.1) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
  }

  :root[data-theme="dark"]:not(#_v3) .mobile-navigation-indicator::before {
    background: radial-gradient(100% 90% at 50% 12%, rgba(255,255,255,.28), rgba(255,255,255,.12) 60%, rgba(255,255,255,.08)) !important;
    border-color: rgba(255, 255, 255, 0.22) !important;
    box-shadow: inset 0 1px 1px rgba(255,255,255,.3), 0 3px 10px -2px rgba(0,0,0,.4) !important;
  }

  /* AI 工具搜索不 sticky */
  :root:not(#_v3) .directory-tools-search,
  :root:not(#_v3) .directory-home-shell .directory-tools-search,
  :root:not(#_v3) .directory-home-shell.directory-tools-shell .directory-tools-search,
  :root:not(#_v3) .directory-home-shell .directory-workspace .directory-tools-search,
  :root:not(#_v3) .directory-home-shell .directory-workspace:not(.directory-workspace-matching):not(.directory-workspace-deals):not(.directory-workspace-risk) .directory-tools-search {
    position: relative !important;
    top: auto !important;
    margin-top: 56px !important;
    margin-bottom: 0 !important;
    z-index: 2 !important;
  }

  /* 对接/避坑搜索栏：顶栏滚走时真正塌高度，别只位移留白 */
  :root:not(#_v3) .match-toolbar,
  :root:not(#_v3) .match-controls,
  :root:not(#_v3) .risk-toolbar {
    position: relative !important;
    top: auto !important;
    transition: opacity .16s ease, margin .2s ease, padding .2s ease, max-height .2s ease !important;
  }

  :root:not(#_v3):has(.mobile-navigation.is-minimized) .match-board .match-controls,
  :root:not(#_v3):has(.mobile-navigation.is-scrolled-away) .match-board .match-controls,
  :root:not(#_v3) .match-board.is-browsing .match-controls,
  :root:not(#_v3):has(.mobile-navigation.is-minimized) .risk-board .risk-controls,
  :root:not(#_v3):has(.mobile-navigation.is-scrolled-away) .risk-board .risk-controls,
  :root:not(#_v3) .risk-board.is-browsing .risk-controls {
    grid-template-rows: 0fr !important;
    opacity: 0 !important;
    pointer-events: none !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
  }

  :root:not(#_v3):has(.mobile-navigation.is-minimized) .match-board .match-controls-inner,
  :root:not(#_v3):has(.mobile-navigation.is-scrolled-away) .match-board .match-controls-inner,
  :root:not(#_v3) .match-board.is-browsing .match-controls-inner {
    overflow: hidden !important;
    min-height: 0 !important;
  }

  :root:not(#_v3):has(.mobile-navigation.is-minimized) .match-board .match-toolbar,
  :root:not(#_v3):has(.mobile-navigation.is-scrolled-away) .match-board .match-toolbar,
  :root:not(#_v3) .match-board.is-browsing .match-toolbar,
  :root:not(#_v3):has(.mobile-navigation.is-minimized) .risk-board .risk-toolbar,
  :root:not(#_v3):has(.mobile-navigation.is-scrolled-away) .risk-board .risk-toolbar,
  :root:not(#_v3) .risk-board.is-browsing .risk-toolbar {
    transform: none !important;
    opacity: 0 !important;
    pointer-events: none !important;
    max-height: 0 !important;
    height: 0 !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    overflow: hidden !important;
    flex-basis: 0 !important;
  }

  :root:not(#_v3):has(.mobile-navigation.is-minimized) .match-list-scroll,
  :root:not(#_v3):has(.mobile-navigation.is-scrolled-away) .match-list-scroll,
  :root:not(#_v3) .match-board.is-browsing .match-list-scroll,
  :root:not(#_v3):has(.mobile-navigation.is-minimized) .risk-list-scroll,
  :root:not(#_v3):has(.mobile-navigation.is-scrolled-away) .risk-list-scroll,
  :root:not(#_v3) .risk-board.is-browsing .risk-list-scroll {
    padding-top: 0 !important;
    scroll-padding-top: 0 !important;
  }

  /* 帖子页也保留搜索行，别再 display:none 藏掉 */
  :root:not(#_v3) .match-columns:has(> .match-detail.open) > .match-controls,
  :root:not(#_v3) .risk-columns:has(> .risk-detail.open) > .risk-controls,
  :root:not(#_v3) .risk-columns:has(> .risk-detail.open) > .risk-toolbar {
    display: grid !important;
    grid-template-rows: 1fr !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    visibility: visible !important;
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
  }
  :root:not(#_v3) .match-columns:has(> .match-detail.open) > .match-controls .match-toolbar,
  :root:not(#_v3) .match-columns:has(> .match-detail.open) > .match-controls .match-controls-inner {
    opacity: 1 !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    pointer-events: auto !important;
    transform: none !important;
  }

  /* 帖子评论条：main 被顶栏挤出视口 50px，且 will-change:transform 会吞掉 fixed；
     bottom 额外加 50px，让评论条落在液态玻璃上方而不是叠上去 */
  :root:not(#_v3) .match-detail.open > .match-comment-slot,
  :root:not(#_v3) .risk-detail.open > .match-comment-slot,
  :root:not(#_v3) .risk-detail.open > .risk-comment-slot {
    position: absolute !important;
    left: 10px !important;
    right: 10px !important;
    width: auto !important;
    bottom: calc(10px + 56px + 8px + 50px + env(safe-area-inset-bottom, 0px)) !important;
    z-index: 72 !important;
  }
  :root:not(#_v3):has(.match-detail.open > .match-comment-slot :focus-within) .match-detail.open > .match-comment-slot,
  :root:not(#_v3):has(.risk-detail.open > .match-comment-slot :focus-within) .risk-detail.open > .match-comment-slot,
  :root:not(#_v3):has(.risk-detail.open > .risk-comment-slot :focus-within) .risk-detail.open > .risk-comment-slot {
    bottom: calc(10px + 50px + env(safe-area-inset-bottom, 0px)) !important;
  }
  :root:not(#_v3):has(.match-detail.open > .match-comment-slot :focus-within) .mobile-navigation,
  :root:not(#_v3):has(.risk-detail.open > .match-comment-slot :focus-within) .mobile-navigation,
  :root:not(#_v3):has(.risk-detail.open > .risk-comment-slot :focus-within) .mobile-navigation {
    transform: translateY(calc(100% + 24px)) !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }
}
