/**
 * 「产品知识 · 左树」样式（客户版阶段 1-1）。
 *
 * 几何与类名逐条来自 5177 的 `素材库产品清单样式`（下称 5177-CSS，
 * 行号即该文件行号）；**颜色一律用客户版设计令牌 var(--wb-*)**（取 tokens.css；本文件不写死色值，
 * 与 `npm run check:design` 的口径一致）。
 *
 * 命名一律沿用 5177 的原类名（`product-knowledge-tree-*` / `product-tree-search-*` /
 * `quote-product-structure-context-menu` / `product-structure-create-*` / `quote-category-empty-note`），
 * 这样搬过来的 tree-search.js、move-picker.js 与后续 5177 代码都能直接命中。
 *
 * 接线（阶段 1-2，本阶段只允许建四个文件，index.html 不动）：把本文件挂进页面时加一行
 * `<link rel="stylesheet" href="styles/taxonomy-tree.css">`（放在 app.css 之后）。
 */

/* ============================================================
 * 1. 面板容器与树（5177-CSS:3145-3323）
 * ============================================================ */

.product-knowledge-tree {
  display: grid;
  /* 5177-CSS:3147：auto auto minmax(0,1fr)（标题 / 未归类 / 列表）；第 4 行留给客户版的状态行。
     2026-10-01 修正：左树确实有「未归类」按钮（阶段 1-4 加的），旧模板把它挤成 0 高、
     与列表重叠（价目表树是拉满高度的，直接暴露了这个 bug）；价目表树与产品知识树共用这份。 */
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-height: 0;
  position: relative;
  overflow: hidden;
  border: 1px solid var(--wb-border);
  border-radius: var(--wb-radius-button);
  background: var(--wb-panel-bg);
  box-shadow: var(--wb-shadow-soft);
}

.product-knowledge-tree-list {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  /* 基础规则在 5177-CSS:3199 是 `6px 6px max(72vh, 560px)`，但当前 5177 在同一个
     产品知识工作台里有一条覆盖（quote-library-product-list.css:7498-7501）：
     吸顶形态下那截底部留白只会变成「滚到底还空一大片」，所以压回 6px。
     客户版照当前真机口径，不再复制已经失效的基础值。 */
  padding: 6px;
  scrollbar-gutter: stable;
}

.product-knowledge-tree-group {
  display: grid;
  gap: 2px;
}

.product-knowledge-tree-row {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 4px;
  padding-left: calc(var(--product-list-depth, 0) * 24px);
}

.product-knowledge-tree-toggle {
  min-width: 20px;
  min-height: 28px;
  border: 0;
  background: transparent;
  color: var(--wb-text-secondary);
  cursor: pointer;
  font-size: var(--wb-fs-13);
  font-weight: var(--wb-fw-900);
  padding: 0;
}

.product-knowledge-tree-item {
  min-height: 30px;
  overflow: hidden;
  border: 1px solid transparent;
  border-radius: var(--wb-radius-control);
  background: transparent;
  color: var(--wb-text-primary);
  cursor: pointer;
  font-size: var(--wb-fs-15);
  font-weight: var(--wb-fw-800);
  /* button 的 UA line-height 是 normal；5177 的树节点继承 body 的 1.5，
     一级/二级放大后行高差 1px，这里显式继承回来。 */
  line-height: var(--wb-font-line-height);
  padding: 4px 8px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 5177-CSS:3240-3260：三级（最终产品）行本身是"素"的，悬停/选中才浮起来 */
.product-knowledge-tree-item--final-product {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

.product-knowledge-tree-item--final-product:hover {
  border-color: var(--wb-border);
  background: var(--wb-panel-bg-soft);
  box-shadow: var(--wb-shadow-control);
}

.product-knowledge-tree-item--final-product.active {
  border-color: var(--wb-accent);
  background: var(--wb-table-row-selected-bg);
  box-shadow: var(--wb-focus-ring), var(--wb-shadow-control);
}

.product-knowledge-tree-item:hover,
.product-knowledge-tree-item.active {
  border-color: var(--wb-border-strong);
  background: var(--wb-table-row-hover-bg);
  color: var(--wb-accent-ink);
}

/* 5177-CSS:7449-7461：一级 / 二级类目在树里放大（2026-10-24 业务方要求树字体整体放大） */
.product-knowledge-tree-row[data-product-tree-level="1"] .product-knowledge-tree-item {
  min-height: calc(30px * 1.35);
  font-size: calc(var(--wb-fs-15) * 1.35);
}

.product-knowledge-tree-row[data-product-tree-level="2"] .product-knowledge-tree-item {
  min-height: calc(30px * 1.15);
  font-size: calc(var(--wb-fs-15) * 1.15);
}

/* 2026-11-05 #36 老板拍：层级字号拉开——三级 15、四级 13、五级及更深 12（不再继续缩）。
   只动字号；字重/颜色沿用 .product-knowledge-tree-item 的统一口径；行高保持 30 不塌。 */
.product-knowledge-tree-row[data-product-tree-level="3"] .product-knowledge-tree-item {
  min-height: 30px;
  font-size: var(--wb-fs-15);
}

.product-knowledge-tree-row[data-product-tree-level="4"] .product-knowledge-tree-item {
  min-height: 30px;
  font-size: var(--wb-fs-13);
}

.product-knowledge-tree-row[data-product-tree-level="5"] .product-knowledge-tree-item,
.product-knowledge-tree-row[data-product-tree-level="6"] .product-knowledge-tree-item,
.product-knowledge-tree-row[data-product-tree-level="7"] .product-knowledge-tree-item,
.product-knowledge-tree-row[data-product-tree-level="8"] .product-knowledge-tree-item {
  min-height: 30px;
  font-size: var(--wb-fs-12);
}

/* 空态（5177-CSS:5374-5378） */
.quote-category-empty-note {
  color: var(--wb-text-secondary);
  font-size: var(--wb-fs-13);
  font-weight: var(--wb-fw-700);
}

/* 状态行（客户版新增：5177 的状态在整块工作台的状态条上） */
.product-tree-status {
  margin: 0;
  border-top: 1px solid var(--wb-border);
  color: var(--wb-text-secondary);
  font-size: var(--wb-fs-12);
  min-height: 22px;
  padding: 4px 8px;
}

.product-tree-status:empty {
  display: none;
}

/* ============================================================
 * 2. 同级拖动排序的落点标记（5177-CSS:3292-3323）
 * ============================================================ */

.product-knowledge-tree-item.dragging {
  opacity: .55;
}

.product-knowledge-tree-item.drag-over-before {
  box-shadow: inset 0 3px 0 var(--wb-accent);
}

.product-knowledge-tree-item.drag-over-after {
  box-shadow: inset 0 -3px 0 var(--wb-accent);
}

.product-knowledge-tree-item.drag-over-invalid {
  border-color: var(--wb-banner-danger-border);
  background: var(--wb-banner-danger-bg);
  color: var(--wb-banner-danger-ink);
  box-shadow: inset 0 0 0 2px var(--wb-banner-danger-border);
}

.product-knowledge-tree-list.is-pointer-dragging,
.product-knowledge-tree-list.is-pointer-dragging .product-knowledge-tree-item {
  user-select: none;
  -webkit-user-select: none;
}

/* ============================================================
 * 3. 树内搜索（5177-CSS:16601-16764）
 * ============================================================ */

.product-tree-search-heading {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  min-height: 51px;
  overflow: visible;
  border-bottom: 1px solid var(--wb-border-strong);
  background: linear-gradient(180deg, var(--wb-panel-bg-soft), var(--wb-fill-soft));
  color: var(--wb-accent-ink);
  font-size: var(--wb-fs-13);
  font-weight: var(--wb-fw-800);
  padding: 6px 8px;
}

.product-tree-search-heading > span:first-child {
  flex: 0 0 auto;
  white-space: nowrap;
}

.product-tree-search {
  position: relative;
  flex: 1 1 150px;
  min-width: 72px;
  max-width: 280px;
  margin-left: auto;
  direction: ltr;
}

/* 面板开着下拉时不能被自己的 overflow 裁掉（5177-CSS:16632-16635） */
.product-knowledge-tree:has(.product-tree-search.is-open) {
  overflow: visible;
  z-index: 5;
}

.product-tree-search input[type="search"] {
  width: 100%;
  min-width: 0;
  height: 32px;
  border: 1px solid var(--wb-border-strong);
  border-radius: 7px;
  background: var(--wb-surface);
  color: var(--wb-text-primary);
  font: inherit;
  font-size: var(--wb-fs-14);
  font-weight: 650;
  line-height: 1.2;
  padding: 5px 30px 5px 9px;
  text-align: left;
  direction: ltr;
  unicode-bidi: plaintext;
  outline: none;
  box-sizing: border-box;
}

.product-tree-search input[type="search"]:focus {
  border-color: var(--wb-accent-ink);
  box-shadow: var(--wb-focus-ring);
}

.product-tree-search input[type="search"]::-webkit-search-cancel-button {
  appearance: none;
}

.product-tree-search-clear {
  position: absolute;
  top: 50%;
  right: 4px;
  z-index: 2;
  width: 24px;
  height: 24px;
  min-height: 0;
  border: 0;
  border-radius: var(--wb-radius-pill);
  background: transparent;
  color: var(--wb-text-secondary);
  cursor: pointer;
  font-size: var(--wb-fs-18);
  line-height: 1;
  padding: 0;
  transform: translateY(-50%);
}

.product-tree-search-clear:hover {
  color: var(--wb-accent-ink);
}

.product-tree-search-results {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  right: auto;
  z-index: var(--wb-z-menu);
  width: min(460px, calc(100vw - 32px));
  max-width: max(100%, 460px);
  max-height: min(680px, 64vh);
  overflow: auto;
  border: 1px solid var(--wb-border-strong);
  border-radius: var(--wb-radius-button);
  background: var(--wb-panel-bg);
  box-shadow: var(--wb-shadow-menu);
  padding: 5px;
  scrollbar-gutter: stable;
}

.product-tree-search-results[hidden] {
  display: none;
}

.product-tree-search-result {
  display: block;
  width: 100%;
  min-height: 34px;
  border: 0;
  border-radius: var(--wb-radius-control);
  background: transparent;
  color: var(--wb-text-primary);
  cursor: pointer;
  font-size: var(--wb-fs-13);
  font-weight: var(--wb-fw-700);
  line-height: 1.4;
  padding: 7px 9px;
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
}

.product-tree-search-result:hover,
.product-tree-search-result.is-active {
  background: var(--wb-table-row-hover-bg);
  color: var(--wb-accent-ink);
}

.product-tree-search-result mark {
  border-radius: 2px;
  background: var(--wb-warning-bg);
  color: inherit;
  padding: 0 1px;
}

.product-tree-search-empty {
  color: var(--wb-text-secondary);
  font-size: var(--wb-fs-13);
  font-weight: 650;
  padding: 12px 10px;
  text-align: left;
}

/* ============================================================
 * 4. 右键菜单（5177-CSS:10859-10897）
 * ============================================================ */

.quote-product-structure-context-menu {
  position: fixed;
  z-index: var(--wb-z-menu);
  display: grid;
  gap: 4px;
  min-width: 142px;
  border: 1px solid var(--wb-menu-border);
  border-radius: var(--wb-radius-button);
  background: var(--wb-menu-bg);
  padding: 6px;
  box-shadow: var(--wb-shadow-menu);
  /* 反向补偿（2026-10-01 板块缩放）：菜单挂在缩放区（.card 内容）里，fixed 的尺寸与
   * 指针坐标都会被缩 0.70；照 5177 的除算（素材库样式:716、发票样式:2697）。
   * 2026-11-04：菜单改挂 body 门户（脱离缩放区），门户里不再做反向补偿。 */
  zoom: calc(1 / var(--workbench-section-scale, 1));
  max-width: calc(100vw - 16px);
}
body > .quote-product-structure-context-menu { zoom: 1; }
.quote-product-structure-context-menu button {
  white-space: nowrap;
}

.quote-product-structure-context-menu strong {
  color: var(--wb-text-secondary);
  font-size: var(--wb-fs-12);
  font-weight: var(--wb-fw-700);
  padding: 2px 4px 4px;
}

.quote-product-structure-context-menu button {
  justify-content: flex-start;
  min-height: 30px;
  border: 0;
  border-radius: var(--wb-radius-control);
  background: transparent;
  color: var(--wb-text-primary);
  padding: 6px 9px;
  text-align: left;
  font-size: var(--wb-fs-13);
  font-weight: var(--wb-fw-800);
  cursor: pointer;
}

.quote-product-structure-context-menu button:hover,
.quote-product-structure-context-menu button:focus-visible {
  background: var(--wb-accent-soft);
  outline: none;
}

.quote-product-structure-context-menu button.is-danger {
  color: var(--wb-danger);
}

/* ============================================================
 * 5. 新增类目对话框（5177-CSS:16202-16273）
 * ============================================================ */

.product-structure-create-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--wb-z-backdrop);
  display: grid;
  place-items: center;
  background: var(--wb-overlay-bg);
}

.product-structure-create-dialog {
  display: grid;
  gap: var(--wb-space-5);
  width: min(480px, calc(100vw - 32px));
  border: 1px solid var(--wb-menu-border);
  border-radius: var(--wb-radius-panel);
  background: var(--wb-panel-bg);
  padding: var(--wb-space-8);
  box-shadow: var(--wb-shadow-modal);
  /* 反向补偿：弹窗在缩放区里，尺寸与居中都被缩 0.70；照 5177 的除算（发票样式:6212 等）。 */
  zoom: calc(1 / var(--workbench-section-scale, 1));
}

.product-structure-create-dialog h3,
.product-structure-create-dialog p {
  margin: 0;
}

.product-structure-create-dialog h3 {
  color: var(--wb-text-primary);
  font-size: var(--wb-fs-19);
  font-weight: var(--wb-fw-900);
  cursor: grab;
  user-select: none;
}

.product-structure-create-dialog label {
  display: grid;
  gap: var(--wb-space-2);
  color: var(--wb-text-primary);
  font-weight: var(--wb-fw-800);
}

.product-structure-create-dialog input {
  min-height: 42px;
  border: 1px solid var(--wb-input-border);
  border-radius: var(--wb-radius-button);
  background: var(--wb-input-bg);
  color: var(--wb-text-primary);
  padding: 8px 10px;
  font: inherit;
}

.product-structure-create-dialog input:focus {
  border-color: var(--wb-accent);
  box-shadow: var(--wb-focus-ring);
  outline: none;
}

.product-structure-create-feedback {
  min-height: 20px;
  color: var(--wb-toast-error-ink);
  font-size: var(--wb-fs-13);
  font-weight: var(--wb-fw-700);
}

.product-structure-create-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--wb-space-4);
}

.product-structure-create-actions button {
  min-height: var(--wb-control-height-sm);
  border: 1px solid var(--wb-border);
  border-radius: var(--wb-radius-button);
  background: var(--wb-btn-bg);
  color: var(--wb-text-primary);
  cursor: pointer;
  font-size: var(--wb-fs-13);
  font-weight: var(--wb-fw-800);
  padding: 6px 14px;
}

.product-structure-create-actions button.primary-action {
  border-color: var(--wb-btn-primary-border);
  background: linear-gradient(180deg, var(--wb-accent-btn-top), var(--wb-accent-btn-bottom));
  color: var(--wb-btn-primary-ink);
}

.product-structure-create-actions button:disabled {
  cursor: default;
  opacity: var(--wb-disabled-opacity);
}

/* ============================================================
 * 6. 移动到其他类目对话框（5177 的 类目移动选择器样式）
 *
 * 5177 是「从左到右逐级展开」的级联列：第 1 列一级类目，点中后右边长出第 2 列，
 * 以此类推。客户版此前只搬了 move-picker.js 的逻辑、没搬这份样式，弹窗退回浏览器
 * 默认外观（粗边框 + 按钮挤成一排），和 5177 的左右列不一致。
 *
 * 几何（宽高 / 列宽 / 内边距）逐条照 5177 原值；颜色换客户版令牌。弹窗挂在 body，
 * 不在 `main > .view > .card > *` 的缩放区里，所以这里不需要反向 zoom 补偿。
 * ============================================================ */

.taxonomy-tree-move-dialog {
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(900px, calc(100vw - 32px));
  height: min(590px, calc(100vh - 32px));
  max-width: none;
  max-height: none;
  padding: 20px;
  border: 1px solid var(--wb-border-strong);
  border-radius: var(--wb-radius-panel);
  background: var(--wb-panel-bg);
  color: var(--wb-text-primary);
  box-shadow: var(--wb-shadow-modal);
}

.taxonomy-tree-move-dialog[open] {
  display: flex;
  flex-direction: column;
  gap: var(--wb-space-4);
}

.taxonomy-tree-move-dialog::backdrop {
  background: var(--wb-overlay-bg);
}

.taxonomy-tree-move-dialog h3,
.taxonomy-tree-move-dialog p {
  margin: 0;
}

.taxonomy-tree-move-dialog h3 {
  color: var(--wb-text-primary);
  font-size: var(--wb-fs-19);
  font-weight: var(--wb-fw-900);
}

/* 级联列：从第 1 列一直向右排，整块可横向滚动。 */
.taxonomy-tree-move-columns {
  display: flex;
  flex: 1;
  min-height: 100px;
  overflow: auto;
  border: 1px solid var(--wb-border);
  border-radius: var(--wb-radius-control);
  background: var(--wb-panel-bg-soft);
}

.taxonomy-tree-move-columns[hidden] {
  display: none;
}

.taxonomy-tree-move-column {
  flex: 0 0 190px;
  width: 190px;
  overflow-y: auto;
  padding: var(--wb-space-3);
  border-right: 1px solid var(--wb-border);
  background: var(--wb-panel-bg);
}

.taxonomy-tree-move-column:last-child {
  border-right: 0;
}

.taxonomy-tree-move-column h4 {
  margin: 0 0 var(--wb-space-3);
  color: var(--wb-text-secondary);
  font-size: var(--wb-fs-13);
  font-weight: var(--wb-fw-800);
}

.taxonomy-tree-move-column button {
  display: block;
  width: 100%;
  margin: 3px 0;
  padding: 9px;
  border: 1px solid var(--wb-border);
  border-radius: var(--wb-radius-control);
  background: var(--wb-btn-bg);
  color: var(--wb-text-primary);
  cursor: pointer;
  font: inherit;
  font-weight: var(--wb-fw-800);
  text-align: left;
  overflow-wrap: anywhere;
}

.taxonomy-tree-move-column button:hover:not(:disabled) {
  border-color: var(--wb-btn-hover-border);
  background: var(--wb-btn-hover-bg);
  color: var(--wb-btn-hover-ink);
  box-shadow: var(--wb-btn-hover-shadow);
}

.taxonomy-tree-move-column button[aria-pressed="true"] {
  border-color: var(--wb-accent);
  background: var(--wb-accent-soft);
  color: var(--wb-accent-ink);
}

.taxonomy-tree-move-dialog button:disabled {
  cursor: not-allowed;
  opacity: var(--wb-disabled-opacity);
}

.taxonomy-tree-move-dialog > label > input[type="text"] {
  display: block;
  width: 100%;
  min-height: var(--wb-input-height);
  margin-top: var(--wb-space-3);
  padding: var(--wb-space-4);
  border: 1px solid var(--wb-input-border);
  border-radius: var(--wb-radius-button);
  background: var(--wb-input-bg);
  color: var(--wb-input-ink);
  box-shadow: var(--wb-input-shadow);
  direction: ltr;
  text-align: left;
  font: inherit;
}

.taxonomy-tree-move-dialog > label > input[type="text"]:focus {
  border-color: var(--wb-input-focus-border);
  box-shadow: var(--wb-input-focus-shadow);
  outline: none;
}

.taxonomy-tree-move-collapse {
  font-size: var(--wb-fs-14);
  line-height: 1.6;
}

.taxonomy-tree-move-collapse[hidden] {
  display: none;
}

.taxonomy-tree-move-status {
  min-height: 40px;
  max-height: 85px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.taxonomy-tree-move-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--wb-space-3);
}

.taxonomy-tree-move-actions button {
  min-height: 36px;
  padding: 8px 14px;
  border: 1px solid var(--wb-btn-border);
  border-radius: var(--wb-radius-button);
  background: var(--wb-btn-bg);
  color: var(--wb-btn-ink);
  cursor: pointer;
  font: inherit;
  font-weight: var(--wb-fw-800);
}

.taxonomy-tree-move-actions button:hover:not(:disabled) {
  border-color: var(--wb-btn-hover-border);
  background: var(--wb-btn-hover-bg);
  color: var(--wb-btn-hover-ink);
  box-shadow: var(--wb-btn-hover-shadow);
}

/* 撤销这类危险动作收在「更多」里，展开后才出现，并且用底色提示这是非常规操作。 */
.taxonomy-tree-move-advanced {
  padding: var(--wb-space-3) var(--wb-space-4);
  border: 1px solid var(--wb-toast-error-border);
  border-radius: var(--wb-radius-control);
  background: var(--wb-toast-error-bg);
  font-size: var(--wb-fs-14);
  line-height: 1.6;
}

.taxonomy-tree-move-note {
  color: var(--wb-toast-error-ink);
}

.taxonomy-tree-move-advanced button {
  margin-top: var(--wb-space-2);
  min-height: 36px;
  padding: 8px 14px;
  border: 1px solid var(--wb-btn-danger-border);
  border-radius: var(--wb-radius-button);
  background: var(--wb-btn-bg);
  color: var(--wb-btn-danger-ink);
  cursor: pointer;
  font: inherit;
  font-weight: var(--wb-fw-800);
}

.taxonomy-tree-move-advanced button:hover:not(:disabled) {
  background: var(--wb-btn-danger-hover-bg);
}

/* ============================================================
 * 7. 响应式（沿用客户版断点 920px，tokens.css --wb-breakpoint-narrow）
 * ============================================================ */

@media (max-width: 920px) {
  .product-tree-search-heading {
    flex-wrap: wrap;
    gap: var(--wb-space-2);
  }

  .product-tree-search {
    flex: 1 1 100%;
    max-width: none;
  }
}
