/* 页头复用 base.css 的容器和输入框；这里只维护布局及交互状态。 */
.bh {
  display: block;
  position: relative;
  margin-bottom: var(--bh-margin);
  font-size: 1.6rem;
  line-height: 1.3;
  color: rgb(var(--color-text));
  isolation: isolate;
  z-index: 40;
}
.bh button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: 0;
  background: none;
}

.bh a {
  color: inherit;
  text-decoration: none;
}

.bh-surface {
  position: relative;
  z-index: 3;
  transition: background 150ms, color 150ms;
}
.bh[data-separator="true"] .bh-surface {
  border-bottom: 0.1rem solid rgba(var(--color-text), 0.08);
}

.bh-container {
  display: grid;
  grid-template-columns: 4rem minmax(0, 1fr) 4rem;
  align-items: center;
  gap: 0 1rem;
  padding-top: var(--bh-padding-top);
  padding-bottom: var(--bh-padding-bottom);
}

.bh-logo {
  display: block;
  grid-area: 1 / 2;
  justify-self: center;
  width: min(var(--bh-mobile-logo-width), 100%);
}

.bh-logo img {
  display: block;
  width: 100%;
  height: auto;
}

.bh-logo-fallback {
  font-size: 2.4rem;
  font-weight: 600;
  line-height: 1.4;
}

.bh-icon {
  display: inline-block;
  width: 2rem;
  height: 2rem;
  flex: 0 0 2rem;
}

.bh-icon svg {
  display: block;
  width: 100%;
  height: 100%;
}

.bh-drawer-toggle .bh-icon {
  position: absolute;
  inset: 0;
  margin: auto;
  transition:
    transform 200ms cubic-bezier(0.22, 1, 0.36, 1),
    opacity 160ms ease;
}

.bh-drawer-toggle .bh-icon-close {
  opacity: 0;
  transform: rotate(-90deg) scale(0.8);
}

.bh-drawer-toggle.is-active .bh-icon-menu {
  opacity: 0;
  transform: rotate(90deg) scale(0.8);
}

.bh-drawer-toggle.is-active .bh-icon-close {
  opacity: 1;
  transform: none;
}

.bh-icon-arrow {
  position: relative;
}

.bh-icon-arrow::before {
  content: "";
  position: absolute;
  top: 0.6rem;
  left: 0.6rem;
  width: 0.6rem;
  height: 0.6rem;
  border-right: 0.1rem solid currentColor;
  border-bottom: 0.1rem solid currentColor;
  transform: rotate(45deg);
}

.bh-icon-button {
  width: 4rem;
  height: 4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
}
.bh-drawer-toggle {
  grid-area: 1 / 1;
  position: relative;
}
.bh-search-toggle {
  grid-area: 1 / 3;
  justify-self: end;
}
.bh-desktop-nav,
.bh-desktop-language,
.bh-drawer {
  display: none;
}

/* 导航 */
.bh-menu-list {
  list-style: none;
  padding: 0;
}
.bh-menu-item {
  position: relative;
  min-width: 0;
}
.bh-menu-row {
  display: flex;
  align-items: center;
}

.bh-menu-label {
  display: block;
  min-width: 0;
  text-align: left;
  padding: 1.2rem;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.bh-menu-row:has(.bh-expand) .bh-menu-label {
  padding-right: 0;
}
.bh-expand {
  padding: 0 1.2rem 0 0.6rem;
  display: flex;
  align-self: stretch;
  align-items: center;
}

.bh-menu-item.is-open > .bh-menu-row .bh-menu-label,
.bh-menu-label:hover {
  text-decoration: underline;
  text-underline-offset: 0.3rem;
}
.bh-submenu {
  display: none;
}
.bh-menu-item.is-open > .bh-submenu {
  display: block;
}
.bh-submenu .bh-menu-row {
  justify-content: space-between;
}
.bh-submenu .bh-menu-label {
  flex: 1;
}

/* 语言选择 */
.bh-language {
  position: relative;
}
.bh-language-toggle {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1.2rem 0;
  white-space: nowrap;
}

.bh-language-options {
  position: absolute;
  right: 0;
  min-width: 12.7rem;
  max-height: 26.4rem;
  overflow: auto;
  padding: 0.4rem;
  z-index: 2;
}

.bh-language-options button {
  display: block;
  padding: 0.5rem 1.2rem;
  width: 100%;
  text-align: left;
  font-size: 1.4rem;
  line-height: 1.6;
  border-radius: 0.4rem;
  white-space: nowrap;
}

.bh-language-options button:hover,
.bh-language-options button.is-selected {
  background: rgba(var(--color-text), 0.05);
}

/* 粘性与首页透明状态 */
.bh.is-fixed > .bh-surface {
  position: fixed;
  inset: 0 0 auto;
  transition: transform 150ms ease, background 150ms, color 150ms;
}
.bh.is-hidden > .bh-surface {
  transform: translateY(-100%);
}
.bh.is-transparent {
  height: 0 !important;
  margin-bottom: 0;
}
.bh.is-transparent > .bh-surface {
  background: var(--bh-transparent-bg);
  color: var(--bh-transparent-text);
  border-bottom-color: transparent;
}
.bh.is-transparent:not(.is-fixed) > .bh-surface {
  position: absolute;
  inset: 0 0 auto;
}

/* 遮罩是空节点，需要覆盖 base.css 的 div:empty 隐藏规则。 */
.bh > .bh-overlay {
  display: block;
  position: fixed;
  inset: 0;
  background: rgba(var(--color-text), 0.5);
  z-index: 4;
}

/* 搜索输入框的边框、圆角、阴影和状态由 .field__input 提供。 */
.bh-search {
  position: fixed;
  inset: 0 0 auto;
  z-index: 5;
  background: rgb(var(--color-bg));
  padding: 1.9rem 2rem;
  animation: bh-slide 180ms ease-out;
}

.bh-search-form {
  max-width: 79.2rem;
  margin: auto;
  display: flex;
  gap: 1rem;
  align-items: center;
}
.bh-search-field {
  position: relative;
  flex: 1;
  min-width: 0;
}
.bh-search-field .field__input {
  padding-inline: 2rem 10.2rem;
}
.bh-search-field .field__input::-webkit-search-cancel-button {
  display: none;
}
.bh-search-field .bh-icon-button {
  position: absolute;
  top: 0;
  bottom: 0;
  right: var(--inputs-border-width);
  width: 4.4rem;
  height: auto;
}
.bh-search-field .bh-search-clear {
  right: calc(4.4rem + var(--inputs-border-width));
}

@keyframes bh-slide {
  from {
    transform: translateY(-100%);
  }
  to {
    transform: translateY(0);
  }
}

/* 桌面布局集中定义，移动端不再逐项覆盖三种桌面位置。 */
@media screen and (min-width: 990px) {
  .bh-container {
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    column-gap: 2rem;
  }
  .bh-logo {
    grid-area: 1 / 1;
    justify-self: start;
    width: var(--bh-logo-width);
  }
  .bh-logo-fallback {
    font-size: 2.8rem;
  }
  .bh-drawer-toggle {
    display: none;
  }
  .bh-desktop-nav {
    display: block;
    grid-area: 1 / 2;
    min-width: 0;
  }
  .bh-desktop-language {
    display: block;
    grid-area: 1 / 4;
  }
  .bh-search-toggle {
    justify-self: start;
  }
  .bh-desktop-nav > .bh-menu-list {
    display: flex;
    flex-wrap: wrap;
  }
  .bh-submenu {
    position: absolute;
    top: 100%;
    left: 0;
    width: 22rem;
  }
  .bh-submenu .bh-submenu {
    left: 100%;
    top: 0;
    min-height: 100%;
  }
  .bh-submenu .bh-icon-arrow {
    transform: rotate(-90deg);
  }
  .bh-menu-item.opens-left > .bh-submenu {
    left: auto;
    right: 0;
  }
  .bh-submenu .bh-menu-item.opens-left > .bh-submenu {
    right: 100%;
    left: auto;
  }
  .bh-language-options {
    top: 100%;
  }

  .bh[data-layout="top-left"] .bh-container,
  .bh[data-layout="top-center"] .bh-container {
    grid-template-columns: 1fr auto auto;
    row-gap: 1rem;
  }
  .bh[data-layout="top-left"] .bh-desktop-nav,
  .bh[data-layout="top-center"] .bh-desktop-nav {
    grid-area: 2 / 1 / 3 / -1;
  }
  .bh[data-layout="top-left"] .bh-search-toggle {
    grid-area: 1 / 2;
  }
  .bh[data-layout="top-left"] .bh-desktop-language,
  .bh[data-layout="top-center"] .bh-desktop-language {
    grid-area: 1 / 3;
  }
  .bh[data-layout="top-center"] .bh-logo {
    grid-area: 1 / 1 / 2 / -1;
    justify-self: center;
  }
  .bh[data-layout="top-center"] .bh-search-toggle {
    grid-area: 1 / 1;
  }
  .bh[data-layout="top-center"] .bh-desktop-nav > .bh-menu-list {
    justify-content: center;
  }
}

@media screen and (max-width: 989px) {
  .bh {
    margin-bottom: calc(var(--bh-margin) / 2);
  }
  .bh-container {
    padding-top: calc(var(--bh-padding-top) / 2);
    padding-bottom: calc(var(--bh-padding-bottom) / 2);
    min-height: 6rem;
  }
  .bh[data-mobile-layout="left"] .bh-logo {
    justify-self: start;
  }
  .bh.is-drawer-open > .bh-surface {
    position: fixed;
    inset: var(--bh-drawer-top, 0px) 0 auto;
    transform: none;
    z-index: 6;
  }
  .bh.is-drawer-open > .bh-overlay,
  .bh-drawer {
    top: calc(var(--bh-drawer-top, 0px) + var(--bh-height, 6rem));
  }
  .bh-drawer {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    width: calc(100% - 4rem);
    z-index: 5;
    flex-direction: column;
    background: rgb(var(--color-bg));
    overflow: auto;
    overscroll-behavior: contain;
  }
  .bh-drawer > nav {
    padding: 5.6rem 0;
    flex: 1;
  }
  .bh-drawer .bh-menu-label {
    flex: 1;
  }
  .bh-drawer [data-depth="1"] > .bh-menu-item > .bh-menu-row > .bh-menu-label {
    padding-left: 2.4rem;
  }
  .bh-drawer [data-depth="2"] > .bh-menu-item > .bh-menu-row > .bh-menu-label {
    padding-left: 4rem;
  }
  .bh-drawer [data-depth="3"] > .bh-menu-item > .bh-menu-row > .bh-menu-label {
    padding-left: 6.4rem;
  }
  .bh-drawer .is-open > .bh-menu-row .bh-icon-arrow {
    transform: rotate(180deg);
  }
  .bh-mobile-language {
    padding: 0 1.2rem 5.6rem;
  }
  .bh-mobile-language .bh-language-options {
    bottom: 100%;
    left: 0;
  }
  .bh-mobile-language .bh-language-options button {
    padding: 0.9rem 1.2rem;
  }
  .bh-search {
    padding: 0.9rem 0.5rem 0.9rem 1rem;
  }
  .bh-search-form {
    gap: 0.5rem;
  }
}
