/**
 * xuye/header block styles — fixed top bar, dropdowns, mobile menu.
 * Mirror of prototypes/xuye/styles.css .site-header section.
 * Breakpoints: 1080px / 680px (prototype breaks, no new ones).
 */
@layer xuye-block {
  .xuye-x-header {
    position: fixed;
    z-index: 30;
    top: 0;
    left: 0;
    width: 100%;
    min-height: 84px;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 26px;
    padding: 0 max(42px, calc((100vw - 1280px) / 2));
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid rgba(223, 232, 236, 0.92);
    box-shadow: 0 14px 34px rgba(10, 28, 38, 0.08);
    backdrop-filter: blur(14px);
  }

  body.home .xuye-x-header {
    min-height: 76px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.84) 0%, rgba(255, 255, 255, 0.56) 100%);
    border-bottom-color: rgba(255, 255, 255, 0.22);
    box-shadow: none;
    backdrop-filter: blur(10px);
    transition: min-height 220ms ease, background 220ms ease, border-color 220ms ease, box-shadow 220ms ease;
  }

  body.home.xuye-x-is-scrolled .xuye-x-header {
    min-height: 76px;
    background: rgba(255, 255, 255, 0.97);
    border-bottom-color: rgba(223, 232, 236, 0.96);
    box-shadow: 0 14px 34px rgba(10, 28, 38, 0.08);
    backdrop-filter: blur(16px);
  }

  .xuye-x-header__brand {
    display: inline-flex;
    align-items: center;
    min-width: 132px;
  }

  .xuye-x-header__brand img {
    width: 142px;
    height: auto;
  }

  .xuye-x-header__nav {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0;
    min-height: 84px;
  }

  body.home .xuye-x-header__nav {
    min-height: 76px;
  }

  .xuye-x-header__nav > a,
  .xuye-x-nav-group > a {
    display: inline-flex;
    min-height: 84px;
    align-items: center;
    padding: 0 18px;
    color: var(--wp--preset--color--ink-soft, #111820);
    font-size: clamp(1.06rem, 0.86vw, 1.16rem);
    font-weight: 700;
    line-height: 1;
    white-space: nowrap;
  }

  body.home .xuye-x-header__nav > a,
  body.home .xuye-x-nav-group > a {
    min-height: 76px;
  }

  .xuye-x-nav-group > a::after {
    content: "";
    width: 8px;
    height: 8px;
    margin-left: 12px;
    border-right: 3px solid var(--wp--preset--color--red, #d71920);
    border-bottom: 3px solid var(--wp--preset--color--red, #d71920);
    transform: rotate(45deg) translateY(-2px);
  }

  .xuye-x-header__nav > a:hover,
  .xuye-x-nav-group:hover > a,
  .xuye-x-nav-group:focus-within > a {
    color: var(--wp--preset--color--teal-dark, #045e64);
    background: var(--wp--preset--color--soft, #f5f8fa);
  }

  .xuye-x-nav-group {
    position: relative;
  }

  .xuye-x-nav-menu {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 238px;
    padding: 12px 0;
    opacity: 0;
    pointer-events: none;
    transform: translateY(8px);
    background: #fff;
    border: 1px solid var(--wp--preset--color--line, #dfe8ec);
    box-shadow: var(--wp--preset--shadow--card, 0 18px 50px rgba(10, 28, 38, 0.12));
    transition: none;
  }

  .xuye-x-nav-group:hover .xuye-x-nav-menu,
  .xuye-x-nav-group:focus-within .xuye-x-nav-menu {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
  }

  .xuye-x-nav-menu a {
    display: block;
    padding: 11px 18px;
    color: #26343d;
    font-size: 0.95rem;
    font-weight: 800;
  }

  .xuye-x-nav-menu a:hover {
    color: var(--wp--preset--color--teal-dark, #045e64);
    background: var(--wp--preset--color--soft, #f5f8fa);
  }

  .xuye-x-menu-toggle {
    display: none;
    cursor: pointer;
  }

  .xuye-x-menu-toggle svg {
    width: 22px;
    height: 22px;
  }

  .xuye-x-menu-toggle__close {
    display: none;
  }

  body.xuye-x-open .xuye-x-menu-toggle__open {
    display: none;
  }

  body.xuye-x-open .xuye-x-menu-toggle__close {
    display: block;
  }

  .xuye-x-header__actions {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
  }

  .xuye-x-lang-switch {
    position: relative;
  }

  .xuye-x-lang-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-width: 66px;
    height: 48px;
    padding: 0 12px;
    border: 1px solid rgba(0, 140, 145, 0.22);
    border-radius: 6px;
    background: #f8fcfc;
    color: var(--wp--preset--color--teal-dark, #045e64);
    font-size: 0.92rem;
    font-weight: 700;
    cursor: pointer;
  }

  body.home .xuye-x-header__cta {
    box-shadow: 0 12px 28px rgba(0, 140, 145, 0.16);
  }

  .xuye-x-lang-globe {
    width: 19px;
    height: 19px;
    fill: currentColor;
  }

  .xuye-x-lang-caret {
    transition: transform 0.18s ease;
  }

  .xuye-x-lang-switch.xuye-x-open .xuye-x-lang-caret {
    transform: rotate(180deg);
  }

  .xuye-x-lang-btn:hover {
    color: #fff;
    background: var(--wp--preset--color--teal, #008c91);
    border-color: var(--wp--preset--color--teal, #008c91);
  }

  .xuye-x-lang-btn:hover .xuye-x-lang-globe { fill: #fff; }

  /* Dropdown listbox */
  .xuye-x-lang-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 80;
    min-width: 172px;
    margin: 0;
    padding: 6px;
    list-style: none;
    background: #fff;
    border: 1px solid var(--wp--preset--color--line, #dfe8ec);
    border-radius: 8px;
    box-shadow: 0 18px 40px rgba(10, 28, 38, 0.16);
    opacity: 0;
    transform: translateY(-6px);
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.16s ease, transform 0.16s ease, visibility 0s linear 0.16s;
  }

  .xuye-x-lang-switch.xuye-x-open .xuye-x-lang-menu {
    opacity: 1;
    transform: none;
    visibility: visible;
    pointer-events: auto;
    transition-delay: 0s;
  }

  .xuye-x-lang-menu button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    border: 0;
    border-radius: 5px;
    background: none;
    color: #26343d;
    font-size: 0.86rem;
    font-weight: 700;
    text-align: left;
    cursor: pointer;
  }

  .xuye-x-lang-menu button:hover {
    background: var(--wp--preset--color--soft, #f5f8fa);
  }

  .xuye-x-lang-short {
    display: inline-grid;
    place-items: center;
    min-width: 28px;
    height: 20px;
    border-radius: 4px;
    background: var(--wp--preset--color--soft, #f5f8fa);
    color: var(--wp--preset--color--muted, #60707b);
    font-size: 10px;
    font-weight: 900;
    letter-spacing: 0.04em;
  }

  .xuye-x-lang-menu button.xuye-x-active {
    color: var(--wp--preset--color--teal-dark, #045e64);
  }

  .xuye-x-lang-menu button.xuye-x-active .xuye-x-lang-short {
    background: rgba(0, 140, 145, 0.12);
    color: var(--wp--preset--color--teal-dark, #045e64);
  }

  .xuye-x-lang-menu button.xuye-x-active::after {
    content: "✓";
    margin-left: auto;
    font-weight: 900;
  }

  /* ── Mega menu panel (Products / Industries) ── */
  .xuye-x-nav-group--mega {
    position: static;
  }

  .xuye-x-nav-mega {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    z-index: 40;
    background: #fff;
    border-top: 1px solid var(--wp--preset--color--line, #dfe8ec);
    border-bottom: 1px solid var(--wp--preset--color--line, #dfe8ec);
    box-shadow: 0 24px 48px rgba(10, 28, 38, 0.14);
    opacity: 0;
    pointer-events: none;
    transform: translateY(8px);
    visibility: hidden;
    /* exit 延迟 0.25s,给鼠标穿过间隙的时间;enter 立即(下方 delay 归零) */
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s 0.25s;
  }

  .xuye-x-nav-mega::before {
    content: "";
    position: absolute;
    top: -24px;
    left: 0;
    right: 0;
    height: 24px;
  }

  .xuye-x-nav-group--mega:hover .xuye-x-nav-mega,
  .xuye-x-nav-group--mega:focus-within .xuye-x-nav-mega {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
    visibility: visible;
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s 0s;
  }

  .xuye-x-mega {
    width: min(1120px, calc(100% - 40px));
    margin: 0 auto;
    padding: 18px 0 22px;
  }

  /* Products: left category rail + right card panel (mm megamenu pattern). */
  .xuye-x-mega--tabs {
    display: grid;
    grid-template-columns: 208px minmax(0, 1fr);
    gap: 22px;
  }

  .xuye-x-mega-tabs {
    display: grid;
    gap: 4px;
    align-content: start;
    padding-right: 16px;
    border-right: 1px solid var(--wp--preset--color--line, #dfe8ec);
  }

  .xuye-x-mega-tab {
    padding: 9px 12px;
    border: 0;
    border-left: 3px solid transparent;
    border-radius: 6px;
    background: none;
    color: var(--wp--preset--color--ink, #0b131a);
    text-align: left;
    cursor: pointer;
    transition: background 0.16s ease, border-color 0.16s ease;
  }

  .xuye-x-mega-tab strong {
    font-size: 0.9rem;
    font-weight: 800;
  }

  .xuye-x-mega-tab:hover {
    background: var(--wp--preset--color--soft, #f5f8fa);
  }

  .xuye-x-mega-tab.xuye-x-active {
    background: rgba(0, 140, 145, 0.08);
    border-left-color: var(--wp--preset--color--teal, #008c91);
  }

  .xuye-x-mega-panel {
    display: none;
  }

  .xuye-x-mega-panel.xuye-x-active {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
  }

  .xuye-x-mega-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
  }

  .xuye-x-mega-card {
    display: block;
    border: 1px solid var(--wp--preset--color--line, #dfe8ec);
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
    text-decoration: none;
    color: var(--wp--preset--color--ink, #0b131a);
    transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
  }

  .xuye-x-mega-card:hover {
    border-color: var(--wp--preset--color--teal, #008c91);
    box-shadow: 0 12px 26px rgba(10, 28, 38, 0.12);
    transform: translateY(-2px);
  }

  .xuye-x-mega-card img {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 10;
    object-fit: cover;
    background: var(--wp--preset--color--soft, #f5f8fa);
  }

  .xuye-x-mega-card strong {
    display: block;
    padding: 9px 11px 10px;
    font-size: 0.85rem;
    line-height: 1.25;
  }

  /* Card excerpt is hidden inside the compact mega panel to keep it short. */
  .xuye-x-mega-card small {
    display: none;
  }

  .xuye-x-mega-more,
  .xuye-x-mega-all {
    display: inline-block;
    color: var(--wp--preset--color--teal-dark, #045e64);
    font-size: 0.85rem;
    font-weight: 800;
    text-decoration: none;
  }

  /* Inside a tab panel, "View all …" spans its own row under the cards. */
  .xuye-x-mega-panel .xuye-x-mega-more {
    grid-column: 1 / -1;
    margin-top: 4px;
  }

  .xuye-x-mega-more {
    margin-top: 14px;
  }

  .xuye-x-mega-all {
    margin-top: 10px;
    padding: 9px 12px;
  }

  .xuye-x-mega-more:hover,
  .xuye-x-mega-all:hover {
    text-decoration: underline;
  }
}

@layer xuye-responsive {
  @media (max-width: 1080px) {
    .xuye-x-header {
      min-height: 72px;
      grid-template-columns: auto 1fr auto auto;
    }

    body.home .xuye-x-header,
    body.home.xuye-x-is-scrolled .xuye-x-header {
      min-height: 72px;
    }

    .xuye-x-header__cta {
      display: none;
    }

    .xuye-x-header__actions {
      order: 3;
    }

    .xuye-x-lang-btn {
      min-width: 44px;
      height: 40px;
    }

    .xuye-x-menu-toggle {
      order: 4;
      display: inline-grid;
      justify-self: end;
      place-items: center;
      width: 44px;
      height: 40px;
      border: 1px solid var(--wp--preset--color--line, #dfe8ec);
      border-radius: 6px;
      background: #fff;
      color: var(--wp--preset--color--ink, #0b131a);
    }

    .xuye-x-header__nav {
      position: fixed;
      top: 72px;
      left: 0;
      right: 0;
      display: none;
      flex-direction: column;
      gap: 0;
      align-items: stretch;
      /* Panel scrolls internally instead of scrolling the page behind it. */
      max-height: calc(100vh - 72px);
      overflow-y: auto;
      -webkit-overflow-scrolling: touch;
      overscroll-behavior: contain;
      padding: 10px 16px 18px;
      background: #fff;
      border: 1px solid var(--wp--preset--color--line, #dfe8ec);
      border-radius: 0 0 8px 8px;
      box-shadow: var(--wp--preset--shadow--card, 0 18px 50px rgba(10, 28, 38, 0.12));
    }

    body.home .xuye-x-header__nav {
      top: 72px;
    }

    body.xuye-x-open .xuye-x-header__nav {
      display: flex;
    }

    /* Lock the page behind the open menu so touch-scroll moves the panel. */
    body.xuye-x-open {
      overflow: hidden;
    }

    .xuye-x-header__nav > a,
    .xuye-x-nav-group > a {
      min-height: auto;
      padding: 15px;
      font-size: 1rem;
      border-radius: 6px;
    }

    body.home .xuye-x-header__nav > a,
    body.home .xuye-x-nav-group > a {
      min-height: auto;
    }

    .xuye-x-header__nav > a:hover,
    .xuye-x-nav-group:hover > a,
    .xuye-x-nav-group:focus-within > a {
      background: var(--wp--preset--color--soft, #f5f8fa);
    }

    .xuye-x-nav-group {
      width: 100%;
    }

    /* Submenus are collapsed by default; a parent tap adds .xuye-x-open. */
    .xuye-x-nav-menu {
      position: static;
      display: none;
      min-width: 0;
      padding: 0 0 8px 18px;
      transform: none;
      background: transparent;
      border: 0;
      box-shadow: none;
    }

    .xuye-x-nav-group.xuye-x-open > .xuye-x-nav-menu,
    .xuye-x-nav-group.xuye-x-open .xuye-x-nav-mega {
      display: block;
    }

    /* Chevron flips to indicate the expanded state. */
    .xuye-x-nav-group.xuye-x-open > a::after {
      transform: rotate(-135deg) translateY(2px);
    }

    .xuye-x-nav-menu a {
      padding: 10px 12px;
      color: var(--wp--preset--color--muted, #60707b);
      font-size: 0.82rem;
    }

    /* Mega panel degrades to an inline 2-col card grid inside the mobile nav. */
    .xuye-x-nav-group--mega {
      position: static;
      width: 100%;
    }

    .xuye-x-nav-mega {
      position: static;
      display: none;
      opacity: 1;
      visibility: visible;
      pointer-events: auto;
      transform: none;
      border: 0;
      box-shadow: none;
      transition: none;
    }

    /* Mobile mega panel aligns flush with the nav panel — no extra left indent. */
    .xuye-x-mega {
      width: auto;
      padding: 4px 0 10px;
    }

    .xuye-x-mega-grid,
    .xuye-x-mega-panel.xuye-x-active {
      grid-template-columns: 1fr 1fr;
      gap: 8px;
    }

    /* Category rail becomes a horizontal chip row above the cards. */
    .xuye-x-mega--tabs {
      grid-template-columns: 1fr;
      gap: 10px;
    }

    .xuye-x-mega-tabs {
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
      padding-right: 0;
      padding-bottom: 8px;
      border-right: 0;
      border-bottom: 1px solid var(--wp--preset--color--line, #dfe8ec);
    }

    .xuye-x-mega-tab {
      border-left: 0;
      border-bottom: 2px solid transparent;
      border-radius: 6px 6px 0 0;
      padding: 6px 10px;
    }

    .xuye-x-mega-tab.xuye-x-active {
      border-left-color: transparent;
      border-bottom-color: var(--wp--preset--color--teal, #008c91);
    }

    .xuye-x-mega-more {
      margin-top: 10px;
    }
  }

  @media (max-width: 680px) {
    .xuye-x-header {
      min-height: 64px;
      padding: 0 16px;
      gap: 10px;
    }

    body.home .xuye-x-header,
    body.home.xuye-x-is-scrolled .xuye-x-header {
      min-height: 64px;
    }

    .xuye-x-header__nav,
    body.home .xuye-x-header__nav {
      top: 64px;
    }

    .xuye-x-header__brand {
      min-width: auto;
    }

    .xuye-x-header__brand img {
      width: 124px;
    }

    .xuye-x-lang-btn {
      min-width: 42px;
      height: 38px;
      font-size: 0.82rem;
    }
  }
}
