/* ══════════════════════════════════════════════════════════════
   赫境私域 · 移动端顶栏重排  v4
   hz_mobile_top.css  ·  2026-11-16

   v3 → v4 变更：
     ① 胶囊图标终于修好：thPaint() 原来用 textContent 整体赋值，
        把 <i> 删掉换成 emoji；已改为 innerHTML + <i> + <span>。
        本表相应处理：
          桌面 —— .hz-cap-txt 正常显示（图标 + 文字，与原来一致）
          手机 —— .hz-cap-txt 收掉，只留 17px 图标
     ② LOGO 加宽：26px → 30px 高（宽约 91px），右侧留白从
        107px 收到更自然的值（用户口径：「LOGO 宽度可以适当宽一些，
        LOGO 右侧有一些空隙了」）
     ③ 图标颜色跟随 JS 设的状态色（金 = 正常，红 = 余额不足）
   ══════════════════════════════════════════════════════════════ */

@media (max-width: 900px) {

  /* ── ① header：一行，两端对齐 ─────────────────────────── */
  body > .container > header,
  .container > header {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
    flex-wrap: nowrap !important;
    gap: 6px !important;
    padding: 6px 0 !important;
    margin-top: 0 !important;
    overflow: visible !important;
  }

  /* ── ② LOGO：30px 高（v3 是 26px，用户说右侧还有空隙）───── */
  .container > header #site-header {
    flex: 0 0 auto !important;
    flex-shrink: 0 !important;
    margin: 0 !important;
    font-size: 15px !important;
    line-height: 1 !important;
    display: flex !important;
    align-items: center !important;
    gap: 5px !important;
    min-width: 0 !important;
    position: relative !important;
    z-index: 2 !important;
  }
  .container > header #site-header img {
    height: 30px !important;
    width: auto !important;
    max-width: 148px !important;
    vertical-align: middle !important;
    display: block !important;
  }
  .container > header #site-header > span {
    display: none !important;
  }

  /* ── ③ user-bar ───────────────────────────────────────── */
  .container > header .user-bar {
    width: auto !important;
    flex: 0 1 auto !important;
    justify-content: flex-end !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 4px !important;
    font-size: 11px !important;
    margin-left: auto !important;
    min-width: 0 !important;
    position: relative !important;
    z-index: 1 !important;
  }

  .container > header .user-bar #user-name,
  .container > header .user-bar .role,
  .container > header .user-bar .dash-lang-link {
    display: none !important;
  }

  /* ── ④ 按钮统一 30px ─────────────────────────────────── */
  .container > header .user-bar > button,
  .container > header .user-bar > .btn-sm,
  .container > header .user-bar > .nav-dropdown > .btn-sm {
    min-height: 30px !important;
    height: 30px !important;
    padding: 0 8px !important;
    font-size: 11px !important;
    border-radius: 15px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 3px !important;
    line-height: 1 !important;
    white-space: nowrap !important;
    flex: 0 0 auto !important;
  }

  .container > header .user-bar > button.nav-theme-btn {
    width: 30px !important;
    min-width: 30px !important;
    padding: 0 !important;
  }

  /* ── ⑤ TokenHub 圆钮：图标要看得见 ───────────────────────
     结构（v4 起由 thPaint 输出）：
       <i class="ph ph-currency-circle-dollar"></i>
       <span class="hz-cap-txt">名字 · 余额</span>
     手机端：收掉 span，只留图标。
     ⚠ 关键教训：绝不能给按钮设 font-size:0 来"藏文字" ——
       textContent 时代会把 emoji 一起压没；即使现在结构分开了，
       font-size:0 也会让图标字号继承为 0。改用 span 显隐。       */
  .container > header .user-bar #hz-th-capsule {
    position: relative !important;
    width: 30px !important;
    min-width: 30px !important;
    max-width: 30px !important;
    height: 30px !important;
    min-height: 30px !important;
    padding: 0 !important;
    margin-left: 0 !important;
    font-size: 0 !important;        /* 兜底：万一 span 没被收掉也不撑宽 */
    overflow: hidden !important;
    flex: 0 0 auto !important;
    border-radius: 50% !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    line-height: 1 !important;
    box-sizing: border-box !important;
    background: rgba(138, 98, 18, .10) !important;
    border: 1px solid rgba(138, 98, 18, .42) !important;
    box-shadow: 0 1px 3px rgba(138, 98, 18, .10) !important;
  }

  /* 手机端把文字收掉 */
  .container > header .user-bar #hz-th-capsule .hz-cap-txt {
    display: none !important;
  }

  /* 图标：正常流 + 写死尺寸（绝对定位 width:auto 会塌成 0x0） */
  /* 精确居中：inset:0 + margin:auto。
     之前用 flex 居中实测 dx=-2px（隐藏 span 与字体基线共同造成的亚像素偏差），
     用户肉眼能看出偏左。绝对定位 + inset 0 + margin auto 与兄弟节点、
     字体度量完全解耦，是唯一的精确解。 */
  .container > header .user-bar #hz-th-capsule > i {
    position: absolute !important;
    inset: 0 !important;
    margin: auto !important;
    transform: none !important;
    display: block !important;
    width: 17px !important;
    min-width: 17px !important;
    max-width: 17px !important;
    height: 17px !important;
    min-height: 17px !important;
    max-height: 17px !important;
    line-height: 17px !important;
    padding: 0 !important;
    text-align: center !important;
    font-size: 17px !important;
    font-family: Phosphor, monospace !important;
    font-style: normal !important;
    color: #8a6212 !important;
    visibility: visible !important;
    opacity: 1 !important;
  }
  .container > header .user-bar #hz-th-capsule > i::before {
    font-size: 17px !important;
    line-height: 17px !important;
    color: #8a6212 !important;
    display: block !important;
    width: 17px !important;
    text-align: center !important;
    visibility: visible !important;
    opacity: 1 !important;
  }
  .container > header .user-bar #hz-th-capsule > svg {
    width: 17px !important;
    height: 17px !important;
    display: block !important;
    color: #8a6212 !important;
  }

  .container > header .user-bar #settings-tab {
    padding: 0 9px !important;
  }
}

/* ── ⑥ 桌面端：让 thPaint 输出的 span 正常显示 ──────────── */
@media (min-width: 901px) {
  #hz-th-capsule .hz-cap-txt {
    display: inline !important;
  }
  #hz-th-capsule > i {
    margin-right: 4px;
    font-size: 15px;
    vertical-align: -1px;
  }
}

/* ── ⑦ 380px 及以下 ───────────────────────────────────── */
@media (max-width: 380px) {
  .container > header #site-header img {
    height: 28px !important;
    max-width: 132px !important;
  }
  .container > header .user-bar {
    gap: 3px !important;
  }
  .container > header .user-bar > button,
  .container > header .user-bar > .btn-sm,
  .container > header .user-bar > .nav-dropdown > .btn-sm {
    height: 28px !important;
    min-height: 28px !important;
    padding: 0 7px !important;
    font-size: 10.5px !important;
  }
  .container > header .user-bar #hz-th-capsule,
  .container > header .user-bar > button.nav-theme-btn {
    width: 28px !important;
    min-width: 28px !important;
    max-width: 28px !important;
    height: 28px !important;
    min-height: 28px !important;
  }
  .container > header .user-bar #hz-th-capsule > i {
    width: 16px !important;
    min-width: 16px !important;
    max-width: 16px !important;
    height: 16px !important;
    min-height: 16px !important;
    max-height: 16px !important;
    line-height: 16px !important;
    font-size: 16px !important;
  }
  .container > header .user-bar #hz-th-capsule > i::before {
    font-size: 16px !important;
    line-height: 16px !important;
    width: 16px !important;
  }
  .container > header .user-bar #settings-tab {
    width: 28px !important;
    min-width: 28px !important;
    max-width: 28px !important;
    padding: 0 !important;
    font-size: 0 !important;
    position: relative !important;
  }
  .container > header .user-bar #settings-tab > i {
    position: absolute !important;
    left: 50% !important;
    top: 50% !important;
    transform: translate(-50%, -50%) !important;
    font-size: 15px !important;
  }
}

/* ── ⑧ 340px 极窄 ─────────────────────────────────────── */
@media (max-width: 340px) {
  .container > header #site-header img {
    height: 26px !important;
    max-width: 118px !important;
  }
  .container > header .user-bar > button,
  .container > header .user-bar > .btn-sm,
  .container > header .user-bar > .nav-dropdown > .btn-sm,
  .container > header .user-bar #hz-th-capsule,
  .container > header .user-bar > button.nav-theme-btn,
  .container > header .user-bar #settings-tab {
    width: 26px !important;
    min-width: 26px !important;
    max-width: 26px !important;
    height: 26px !important;
    min-height: 26px !important;
    padding: 0 !important;
  }
  .container > header .user-bar #hz-th-capsule > i,
  .container > header .user-bar #settings-tab > i {
    width: 15px !important;
    min-width: 15px !important;
    max-width: 15px !important;
    height: 15px !important;
    min-height: 15px !important;
    max-height: 15px !important;
    line-height: 15px !important;
    font-size: 15px !important;
  }
}


/* ══════════════════════════════════════════════════════════════
   顶栏层叠上下文 —— 修「设置下拉菜单被下方统计数字遮盖」
   hz-dropdown-z · 2026-11-16

   根因：header 是 static 定位且无 z-index，整条顶栏在根层叠上下文里
        不占优先级；下方内容 DOM 在后，任一祖先一旦建立层叠上下文
        （transform/filter/isolation/position+z-index 都算）就整体压过顶栏。
        .nav-dropdown 的 z-index:100 只在它自己的上下文内有效，救不了。

   桌面 + 手机都生效（此 bug 与视口无关，故不放进媒体查询）。
   ══════════════════════════════════════════════════════════════ */

body > .container > header,
.container > header {
  position: relative !important;
  z-index: 900 !important;
  isolation: isolate !important;   /* 自成层叠上下文，不被外部层级影响 */
}

.container > header .user-bar {
  position: relative !important;
  z-index: 910 !important;
}

.container > header .nav-dropdown {
  position: relative !important;
  z-index: 950 !important;
}

.container > header .dropdown-menu {
  z-index: 9999 !important;
}

/* 下拉里可能嵌了二级元素，一并抬高 */
.container > header .dropdown-menu .dropdown-item {
  position: relative !important;
  z-index: 1 !important;
}
