/**
 * 「产品知识 · 左树」样式（客户版阶段 1-1）。
 *
 * 几何与类名逐条来自 5177 的 `src/styles/quote-library-product-list.css`（下称 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:3184：底部留一大截，保证拖到列表底端时落点仍然可见 */
  padding: 6px 6px max(72vh, 560px);
  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: 24px;
  border: 0;
  background: transparent;
  color: var(--wb-text-secondary);
  cursor: pointer;
  font-size: var(--wb-fs-12);
  font-weight: var(--wb-fw-900);
  padding: 0;
}

.product-knowledge-tree-item {
  min-height: 26px;
  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-13);
  font-weight: var(--wb-fw-800);
  padding: 4px 7px;
  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：一级 / 二级类目在树里放大（1.5 倍 / 1.2 倍） */
.product-knowledge-tree-row[data-product-tree-level="1"] .product-knowledge-tree-item {
  min-height: calc(26px * 1.5);
  font-size: calc(var(--wb-fs-13) * 1.5);
}

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

/* 空态（5177-CSS:5374-5378） */
.quote-category-empty-note {
  color: var(--wb-text-secondary);
  font-size: var(--wb-fs-12);
  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-12);
  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-13);
  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 的除算（09-quote-library-2.css:716、invoice.css:2697）。 */
  zoom: calc(1 / var(--workbench-section-scale, 1));
}

.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-modal);
  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 的除算（invoice.css: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);
}

.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. 响应式（沿用客户版断点 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;
  }
}
