/* css/nav-menu.css - 全站 2 级分类导航样式（桌面下拉面板 + 移动抽屉） */
/* UI 主色：#FF6B35 橙 / #7C3AED 紫 / #00C9A7 青 */

:root {
  --tb-nav-height: 56px;
  /* 新分类导航的停靠位置：桌面停在旧固定顶栏（68px）下方，避免滚动后两层重叠。
     移动端旧顶栏已隐藏，停靠 0。 */
  --tb-top-offset: 68px;
  --tb-nav-bg: rgba(255, 255, 255, 0.92);
  --tb-nav-border: rgba(15, 23, 42, 0.06);
  --tb-panel-bg: #ffffff;
  --tb-panel-shadow: 0 24px 48px -12px rgba(16, 24, 40, 0.18);
  --tb-cat-active-bg: rgba(255, 107, 53, 0.08);
}

/* 只有注入了新导航的页面才调整 body 顶部留白（由 nav-menu.js 打标记）。
   新导航是 sticky 自带占位，body 只需让出「旧固定顶栏」那一段；
   移动端旧顶栏隐藏，留白归零，避免首页/工具页顶部多出 54px 空档。 */
body.tb-has-topnav {
  /* fixed 后本条不再占文档流，留白需覆盖「旧顶栏 + 本条」两段高度 */
  padding-top: calc(var(--tb-top-offset) + var(--tb-nav-height));
}

/* ===== 顶部导航条 ===== */
.tb-topnav {
  /* fixed 而非 sticky：sticky 在页面滚到顶/底（尤其 overscroll 回弹）时
     会随文档流短暂位移，看起来像抖动并盖住上一行；fixed 位置恒定，不再遮挡 */
  position: fixed;
  top: var(--tb-top-offset);
  left: 0;
  right: 0;
  z-index: 90;
  height: var(--tb-nav-height);
  background: var(--tb-nav-bg);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--tb-nav-border);
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.04);
}

.tb-topnav::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 107, 53, 0.03), rgba(124, 58, 237, 0.03));
  pointer-events: none;
}

.tb-nav-inner {
  position: relative;
  max-width: 1280px;
  height: 100%;
  margin: 0 auto;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.tb-nav-logo {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 17px;
  font-weight: 800;
  color: #1E2937;
  text-decoration: none;
  flex-shrink: 0;
  transition: transform 0.2s;
}

@media (max-width: 1100px) {
  .tb-nav-logo span { display: none; }
}

.tb-nav-logo:hover {
  transform: scale(1.02);
}

.tb-nav-logo-icon {
  font-size: 22px;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #FF6B35, #E85A2A);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 4px 12px rgba(255, 107, 53, 0.25);
}

.tb-nav-menu {
  display: flex;
  align-items: center;
  gap: 2px;
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  mask-image: linear-gradient(90deg, transparent, #000 8px, #000 calc(100% - 8px), transparent);
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 8px, #000 calc(100% - 8px), transparent);
}

.tb-nav-menu::-webkit-scrollbar { display: none; }

.tb-nav-item { flex-shrink: 0; }

.tb-nav-link {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px 11px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: #475569;
  /* 不设 flex-shrink:0 —— 窄屏需要靠收缩避免溢出（实测加 0 反而挤出滚动条） */
  text-decoration: none;
  white-space: nowrap;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

/* 英文态分类名更长，12 项在 1280px 内会挤出横向滚动，压一点内边距和字号 */
html[lang^="en"] .tb-nav-link { padding: 8px 8px; font-size: 12.5px; }

.tb-nav-link:hover,
.tb-nav-link.active {
  background: rgba(255, 107, 53, 0.08);
  color: #FF6B35;
}

.tb-nav-link.active::after {
  content: '';
  position: absolute;
  bottom: -9px;
  left: 50%;
  transform: translateX(-50%);
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #FF6B35;
}

.tb-nav-link-icon { font-size: 16px; }

.tb-nav-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.tb-nav-search-btn,
.tb-nav-theme-btn,
.tb-nav-mobile-toggle {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8f7fb;
  border: 1px solid transparent;
  color: #475569;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 17px;
}

.tb-nav-search-btn:hover,
.tb-nav-theme-btn:hover,
.tb-nav-mobile-toggle:hover {
  background: #fff;
  border-color: rgba(255, 107, 53, 0.2);
  color: #FF6B35;
}

.tb-nav-search-btn svg {
  width: 18px;
  height: 18px;
}

/* 主题按钮：桌面由旧 nav-top 提供，新导航仅在移动端显示，避免重复 */
.tb-nav-theme-btn {
  display: none;
}

.tb-nav-mobile-toggle {
  display: none;
  font-size: 18px;
}

/* ===== 下拉 mega panel ===== */
.tb-megapanel {
  /* fixed 而非 absolute：导航是 sticky，滚动后会固定在 --tb-top-offset 处，
     面板用 fixed 才能始终贴在导航下沿（absolute 会随文档滚走） */
  position: fixed;
  top: calc(var(--tb-top-offset) + var(--tb-nav-height));
  left: 0;
  right: 0;
  z-index: 89;
  background: var(--tb-panel-bg);
  border-bottom: 1px solid var(--tb-nav-border);
  box-shadow: var(--tb-panel-shadow);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: opacity 0.2s, transform 0.25s, visibility 0.2s;
  pointer-events: none;
  max-height: calc(100vh - var(--tb-top-offset) - var(--tb-nav-height) - 24px);
  overflow-y: auto;
}

.tb-megapanel.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

.tb-megapanel-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px;
}

.tb-megapanel-head {
  display: grid;
  /* 左侧宽度由 JS 按子行业数量算（列数越多越宽），见 showMegaPanel() */
  grid-template-columns: var(--tb-cats-width, 220px) 1fr;
  gap: 24px;
  min-height: 320px;
}

/* 左侧子行业列表 */
.tb-megapanel-cats {
  background: #f8f7fb;
  border-radius: 16px;
  padding: 16px;
}

.tb-megapanel-cats-title {
  font-size: 16px;
  font-weight: 700;
  color: #1E2937;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tb-megapanel-cat-list {
  list-style: none;
  margin: 0;
  padding: 0;
  /* 子行业多的大类（工程制造 69 个）单列要滚动才能看全，改为多列平铺。
     列数由 JS 按数量注入 --tb-cat-cols。 */
  display: grid;
  grid-template-columns: repeat(var(--tb-cat-cols, 1), minmax(0, 1fr));
  gap: 2px 8px;
  align-content: start;
}

.tb-megapanel-cat-item {
  display: flex;
  align-items: center;
  gap: 10px;
  /* 多列后要塞进更多行，纵向 padding 由 9px 压到 4px（行高 42→37px） */
  padding: 4px 10px;
  border-radius: 10px;
  cursor: pointer;
  min-width: 0;
  transition: all 0.15s;
  font-size: 14px;
  color: #475569;
}

.tb-megapanel-cat-item:hover,
.tb-megapanel-cat-item.active {
  background: var(--tb-cat-active-bg);
  color: #FF6B35;
}

.tb-cat-icon { font-size: 18px; flex-shrink: 0; }
/* 不再截断：分类名已统一压到 4 字以内，宁可换行也要显示完整 */
.tb-cat-name { flex: 1; min-width: 0; line-height: 1.3; word-break: break-word; }
.tb-cat-count {
  font-size: 11px;
  font-weight: 600;
  color: #94a3b8;
  background: rgba(0, 0, 0, 0.04);
  padding: 2px 7px;
  border-radius: 999px;
}

.tb-megapanel-cat-item.active .tb-cat-count {
  background: rgba(255, 107, 53, 0.12);
  color: #FF6B35;
}

/* 右侧工具网格 */
.tb-megapanel-tools {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.tb-megapanel-tools-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid #f0eff4;
}

.tb-tools-header-icon { font-size: 24px; }
.tb-tools-header-name {
  flex: 1;
  font-size: 18px;
  font-weight: 700;
  color: #1E2937;
}
.tb-tools-header-more {
  font-size: 13px;
  font-weight: 600;
  color: #FF6B35;
  text-decoration: none;
  white-space: nowrap;
}
.tb-tools-header-more:hover { text-decoration: underline; }

.tb-megapanel-tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.tb-megapanel-tool-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid #f0eff4;
  text-decoration: none;
  transition: all 0.2s;
}

.tb-megapanel-tool-card:hover {
  border-color: rgba(255, 107, 53, 0.25);
  box-shadow: 0 8px 20px rgba(16, 24, 40, 0.06);
  transform: translateY(-2px);
}

.tb-tool-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.tb-tool-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tb-tool-name {
  font-size: 14px;
  font-weight: 600;
  color: #1E2937;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tb-tool-desc {
  font-size: 12px;
  color: #6B7280;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tb-megapanel-empty {
  padding: 40px 0;
  text-align: center;
  color: #94a3b8;
  font-size: 14px;
}

/* ===== 移动端抽屉 ===== */
.tb-mobile-drawer {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
}

.tb-mobile-drawer.open { display: block; }

.tb-mobile-drawer-mask {
  position: absolute;
  inset: 0;
  background: rgba(15, 15, 26, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.tb-mobile-drawer-panel {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(86vw, 360px);
  background: #fff;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.tb-mobile-drawer.open .tb-mobile-drawer-panel {
  transform: translateX(0);
}

.tb-mobile-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid #f0eff4;
}

.tb-mobile-drawer-title {
  font-size: 16px;
  font-weight: 700;
  color: #1E2937;
}

.tb-mobile-drawer-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: #f8f7fb;
  color: #475569;
  font-size: 16px;
  cursor: pointer;
}

.tb-mobile-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px 24px;
}

.tb-mobile-section {
  border-bottom: 1px solid #f0eff4;
}

.tb-mobile-section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 4px;
  font-size: 15px;
  font-weight: 600;
  color: #1E2937;
  cursor: pointer;
}

.tb-mobile-section-head::after {
  content: '›';
  margin-left: auto;
  font-size: 18px;
  color: #94a3b8;
  transition: transform 0.2s;
}

.tb-mobile-section.open .tb-mobile-section-head::after {
  transform: rotate(90deg);
}

.tb-mobile-section-icon { font-size: 18px; }
.tb-mobile-section-count {
  margin-left: auto;
  font-size: 12px;
  font-weight: 500;
  color: #94a3b8;
  background: rgba(0, 0, 0, 0.04);
  padding: 1px 7px;
  border-radius: 999px;
}

.tb-mobile-section-list {
  list-style: none;
  margin: 0;
  padding: 0 0 8px 8px;
  display: none;
}

.tb-mobile-section.open .tb-mobile-section-list { display: block; }

.tb-mobile-section-item a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  border-radius: 10px;
  text-decoration: none;
  color: #475569;
  font-size: 14px;
}

.tb-mobile-section-item a:hover {
  background: rgba(255, 107, 53, 0.06);
  color: #FF6B35;
}

.tb-mobile-cat-icon { font-size: 16px; }
.tb-mobile-cat-count {
  margin-left: auto;
  font-size: 11px;
  color: #94a3b8;
  background: rgba(0, 0, 0, 0.04);
  padding: 1px 6px;
  border-radius: 999px;
}

/* ===== 响应式 ===== */
@media (max-width: 991px) {
  .tb-nav-menu {
    gap: 0;
    mask-image: none;
    -webkit-mask-image: none;
  }
  .tb-nav-link { padding: 8px 10px; font-size: 13px; }
}

@media (max-width: 767px) {
  :root { --tb-nav-height: 52px; --tb-top-offset: 0px; }
  .tb-nav-menu {
    display: none;
  }
  /* 移动端保留搜索 + 主题 + 汉堡：顶部只有这一层导航，功能不能丢 */
  .tb-nav-search-btn,
  .tb-nav-theme-btn,
  .tb-nav-mobile-toggle {
    display: flex;
  }
  .tb-megapanel { display: none; }
  .tb-megapanel-inner { padding: 0; }
}

@media (min-width: 768px) {
  .tb-mobile-drawer { display: none !important; }
}

/* 暗色模式 */
body.dark .tb-topnav {
  --tb-nav-bg: rgba(26, 26, 46, 0.92);
  --tb-nav-border: rgba(255, 255, 255, 0.06);
}
body.dark .tb-nav-logo { color: #e2e8f0; }
body.dark .tb-nav-link { color: #94a3b8; }
body.dark .tb-nav-link:hover,
body.dark .tb-nav-link.active { background: rgba(255, 107, 53, 0.1); color: #ff9a6c; }
body.dark .tb-nav-search-btn,
body.dark .tb-nav-mobile-toggle { background: #1a1a2e; color: #94a3b8; }
body.dark .tb-nav-search-btn:hover,
body.dark .tb-nav-mobile-toggle:hover { background: #252540; color: #ff9a6c; }
body.dark .tb-megapanel { background: #1a1a2e; border-bottom-color: #2a2a42; }
body.dark .tb-megapanel-cats { background: #252540; }
body.dark .tb-megapanel-cats-title,
body.dark .tb-tools-header-name,
body.dark .tb-tool-name { color: #e2e8f0; }
body.dark .tb-megapanel-cat-item { color: #94a3b8; }
body.dark .tb-megapanel-cat-item:hover,
body.dark .tb-megapanel-cat-item.active { background: rgba(255, 107, 53, 0.12); color: #ff9a6c; }
body.dark .tb-tool-desc { color: #94a3b8; }
body.dark .tb-megapanel-tool-card { background: #1a1a2e; border-color: #2a2a42; }
body.dark .tb-megapanel-tool-card:hover { border-color: rgba(255, 107, 53, 0.3); }
body.dark .tb-mobile-drawer-panel { background: #1a1a2e; }
body.dark .tb-mobile-drawer-head { border-bottom-color: #2a2a42; }
body.dark .tb-mobile-section { border-bottom-color: #2a2a42; }
body.dark .tb-mobile-section-head { color: #e2e8f0; }
body.dark .tb-mobile-section-item a { color: #94a3b8; }
body.dark .tb-mobile-section-item a:hover { background: rgba(255, 107, 53, 0.1); color: #ff9a6c; }
body.dark .tb-mobile-drawer-close { background: #252540; color: #94a3b8; }
