/* 产品类目层级侧边栏：产品中心页 + product_cat 中间层级归档页（末级不含）。
   沿用产品页体系：白底、1px #edf0f5 实边、8px 圆角、#2b6cb0 单一强调色。 */

.nh-cat-layout {
  display: grid;
  grid-template-columns: 288px minmax(0, 1fr);
  gap: 32px;
  align-items: start;
}

.nh-cat-sidebar {
  position: sticky;
  top: calc(var(--navbar-height, 64px) + 24px);
  overflow: hidden;
  border: 1px solid var(--gray-200, #edf0f5);
  border-radius: 8px;
  background: #fff;
}

.nh-cat-sidebar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200, #edf0f5);
  background: var(--gray-100, #f7f8fa);
}

.nh-cat-sidebar__title {
  color: var(--gray-900, #111827);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.5;
}

/* 面板开关：仅 ≤1024px 显示，桌面端始终展开 */
.nh-cat-sidebar__panel-toggle {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--gray-200, #edf0f5);
  border-radius: 6px;
  background: #fff;
  color: var(--gray-600, #6b7280);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.nh-cat-sidebar__panel-toggle:hover,
.nh-cat-sidebar__panel-toggle:focus-visible {
  border-color: var(--blue-500, #2b6cb0);
  color: var(--blue-500, #2b6cb0);
}

.nh-cat-sidebar__panel {
  padding: 8px;
}

.nh-cat-sidebar__all {
  display: block;
  padding: 9px 12px;
  border-radius: 6px;
  color: var(--gray-600, #6b7280);
  font-size: 14px;
  line-height: 1.5;
  text-decoration: none;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.nh-cat-sidebar__all:hover,
.nh-cat-sidebar__all:focus-visible {
  background: var(--gray-100, #f7f8fa);
  color: var(--blue-500, #2b6cb0);
}

.nh-cat-sidebar__all.is-active {
  background: #eaf2fb;
  color: var(--blue-500, #2b6cb0);
  font-weight: 700;
}

.nh-cat-sidebar__tree {
  margin: 0;
  padding: 0;
  list-style: none;
}

.nh-cat-sidebar__tree--child {
  margin-left: 12px;
  padding-left: 10px;
  border-left: 1px solid var(--gray-200, #edf0f5);
}

.nh-cat-sidebar__row {
  display: flex;
  align-items: stretch;
  border-radius: 6px;
  transition: background-color 0.2s ease;
}

.nh-cat-sidebar__row:hover {
  background: var(--gray-100, #f7f8fa);
}

.nh-cat-sidebar__link {
  display: flex;
  min-width: 0;
  flex: 1;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  color: var(--gray-900, #111827);
  font-size: 14px;
  line-height: 1.5;
  text-decoration: none;
}

.nh-cat-sidebar__link:hover,
.nh-cat-sidebar__link:focus-visible {
  color: var(--blue-500, #2b6cb0);
}

.nh-cat-sidebar__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nh-cat-sidebar__count {
  flex: none;
  min-width: 22px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--gray-100, #f7f8fa);
  color: var(--gray-600, #6b7280);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  line-height: 18px;
  text-align: center;
}

/* 当前类目及其祖先链（归档页中间层级） */
.nh-cat-sidebar__item.is-active > .nh-cat-sidebar__row {
  background: #eaf2fb;
}

.nh-cat-sidebar__item.is-active > .nh-cat-sidebar__row .nh-cat-sidebar__link {
  color: var(--blue-500, #2b6cb0);
  font-weight: 700;
}

.nh-cat-sidebar__item.is-active > .nh-cat-sidebar__row .nh-cat-sidebar__count {
  background: #d7e6f7;
  color: var(--blue-500, #2b6cb0);
}

.nh-cat-sidebar__toggle {
  flex: none;
  display: flex;
  width: 32px;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--gray-600, #6b7280);
  cursor: pointer;
}

.nh-cat-sidebar__toggle:hover,
.nh-cat-sidebar__toggle:focus-visible {
  color: var(--blue-500, #2b6cb0);
}

.nh-cat-sidebar__chevron {
  width: 16px;
  height: 16px;
  transition: transform 0.2s ease;
}

.nh-cat-sidebar__toggle[aria-expanded='false'] .nh-cat-sidebar__chevron {
  transform: rotate(-90deg);
}

@media (max-width: 1024px) {
  .nh-cat-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 24px;
  }

  .nh-cat-sidebar {
    position: static;
  }

  .nh-cat-sidebar__panel-toggle {
    display: flex;
  }

  /* 折叠面板：默认收起，JS 加 is-open 展开。
     visibility 一并过渡 —— 收起时移出 tab 焦点序列，否则键盘可聚焦到零高度容器内的
     不可见链接，并令其 scrollTop 漂移。visibility 为离散属性，展开时立即生效，
     收起时延至过渡结束，动画不受影响。 */
  .nh-cat-sidebar__panel {
    max-height: 0;
    padding-block: 0;
    overflow: hidden;
    visibility: hidden;
    transition: max-height 0.3s ease, padding-block 0.3s ease, visibility 0.3s ease;
  }

  .nh-cat-sidebar.is-open .nh-cat-sidebar__panel {
    max-height: 70vh;
    padding-block: 8px;
    overflow-y: auto;
    visibility: visible;
  }

  .nh-cat-sidebar.is-open .nh-cat-sidebar__panel-toggle .nh-cat-sidebar__chevron {
    transform: rotate(180deg);
  }

  /* 无 JS 时面板保持展开，层级仍可访问 */
  .nh-cat-sidebar:not([data-sidebar-ready]) .nh-cat-sidebar__panel {
    max-height: none;
    padding-block: 8px;
    visibility: visible;
  }

  .nh-cat-sidebar:not([data-sidebar-ready]) .nh-cat-sidebar__panel-toggle {
    display: none;
  }
}
