/* ============================================================
   主题层：参考 FlowHMI 工业 HMI 风格
   - 浅色侧栏 / 白色顶栏 / 深蓝主色 / 柔和卡片 / 1px 浅边框
   - 在 style.css 之后加载，覆盖视觉样式（不改动结构与交互）
   ============================================================ */

/* ---------------- 设计令牌 ---------------- */
:root {
  --bg: #F7F9FC;
  --panel: #FFFFFF;
  --sidebar: #FFFFFF;
  --sidebar-2: #FFFFFF;
  --sidebar-text: #475467;

  --accent: #1F4E79;
  --accent-2: #1A4368;
  --accent-soft: #EAF2FA;
  --primary: #1F4E79;

  --text: #101828;
  --muted: #667085;
  --muted-2: #98A2B3;

  --border: #E7EDF6;
  --border-2: #D9E2F3;
  --divider: #EFF3F9;

  --danger: #DC2626;
  --danger-soft: #FEE4E2;
  --success: #15803D;
  --success-soft: #ECFDF3;
  --warn: #B45309;
  --warn-soft: #FFFAEB;
  --orange: #B45309;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 2px rgba(16, 24, 40, .03);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, .18);

  --font-sans: "Segoe UI", "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", system-ui, sans-serif;
  --font-mono: Consolas, "Cascadia Mono", "Courier New", monospace;
}

body {
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  font-variant-numeric: tabular-nums;
}

* {
  scrollbar-width: thin;
  scrollbar-color: #C9D4E4 transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: #C9D4E4; border: 2px solid transparent; background-clip: content-box; border-radius: 999px; }
*::-webkit-scrollbar-thumb:hover { background: #AAB9CE; background-clip: content-box; }

::selection { background: var(--accent-soft); color: var(--primary); }

/* ---------------- 应用外壳 ---------------- */
#app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.app-body { flex: 1; min-height: 0; display: flex; }

.titlebar {
  flex: none;
  height: 32px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px 0 16px;
  background: #FFFFFF;
  border-bottom: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--muted);
  user-select: none;
}
.titlebar-brand { font-weight: 600; color: var(--primary); letter-spacing: .01em; }
.titlebar-sep { color: #D9E2F3; }
.titlebar-page { color: var(--muted); }
.titlebar-spacer { flex: 1; }
.titlebar-note { font-size: 11px; color: var(--muted-2); }

/* ---------------- 左侧导航 ---------------- */
.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: #FFFFFF;
  border-right: 1px solid var(--border);
  color: var(--text);
  padding: 0 12px 16px;
  overflow-y: auto;
}

.brand { height: 72px; padding: 0 4px; gap: 10px; }
.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--primary);
  box-shadow: none;
  font-size: 17px;
}
.brand-text strong { color: var(--text); font-size: 14.5px; font-weight: 700; letter-spacing: -.01em; }
.brand-text span { color: var(--muted); font-size: 10.5px; margin-top: 2px; }

.nav { margin-top: 0; padding: 0; gap: 0; }
.nav-group {
  padding: 14px 8px 5px;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 16px;
  letter-spacing: .06em;
  color: #667085;
}
.nav-item {
  height: 34px;
  padding: 0 10px;
  border-radius: 6px;
  color: var(--text-2, #475467);
  font-size: 13px;
  font-weight: 500;
  gap: 10px;
  background: transparent;
}
.nav-item svg { width: 16px; height: 16px; color: #667085; opacity: 1; }
.nav-item:hover { background: #F2F5F9; color: var(--text); }
.nav-item:hover svg { color: #475467; }
.nav-item.active {
  background: var(--accent-soft);
  color: var(--primary);
  font-weight: 600;
  box-shadow: none;
}
.nav-item.active svg { color: var(--primary); }
.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 7px;
  bottom: 7px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--primary);
}
.nav-dot { right: 10px; width: 6px; height: 6px; background: #F59E0B; box-shadow: 0 0 0 3px rgba(245, 158, 11, .18); }

.sidebar-foot {
  margin-top: auto;
  padding: 14px 8px 2px;
  border-top: 1px solid var(--border);
}
.sidebar-foot .hint { font-size: 11px; color: var(--muted-2); line-height: 1.8; }

/* ---------------- 右侧主区 / 顶栏 ---------------- */
.main { background: var(--bg); }

.topbar {
  flex: none;
  height: auto;
  min-height: 78px;
  align-items: flex-end;
  gap: 16px;
  padding: 12px 24px 14px;
  background: #FFFFFF;
  border-bottom: 1px solid var(--border);
}
.topbar-title { display: flex; flex-direction: column; gap: 0; min-width: 0; }
.page-kicker {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  line-height: 16px;
  margin-bottom: 2px;
}
.topbar-title h1 {
  font-size: 20px;
  font-weight: 700;
  line-height: 28px;
  color: var(--text);
  letter-spacing: -.01em;
  white-space: nowrap;
}
.topbar-title p {
  margin-top: 2px;
  font-size: 12.5px;
  line-height: 18px;
  color: var(--muted);
  max-width: 720px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-actions { margin-left: auto; align-items: center; gap: 8px; padding-bottom: 2px; flex-wrap: wrap; }

.content { padding: 14px 24px 32px; }

/* ---------------- 按钮 ---------------- */
.btn {
  height: 36px;
  padding: 0 14px;
  gap: 7px;
  border-radius: 8px;
  border: 1px solid var(--border-2);
  background: #FFFFFF;
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
}
.btn svg { width: 15px; height: 15px; }
.btn:hover { background: #F2F5F9; border-color: #C6D5E9; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #FFFFFF; box-shadow: none; }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-primary:disabled { background: #B6C6D8; border-color: #B6C6D8; }
.btn-secondary { background: #FFFFFF; border-color: var(--border-2); color: var(--primary); }
.btn-danger, .btn-danger-ghost {
  background: #FFFFFF;
  border-color: #FCCFCB;
  color: var(--danger);
}
.btn-danger:hover, .btn-danger-ghost:hover { background: #FFF8F7; border-color: #F3B1AB; }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-solid:hover { background: #B91C1C; border-color: #B91C1C; }
.btn-ghost { border-color: transparent; background: transparent; color: #475467; font-weight: 500; }
.btn-ghost:hover { background: #F2F5F9; border-color: transparent; color: var(--text); }
.btn-sm { height: 30px; padding: 0 11px; font-size: 12.5px; border-radius: 7px; gap: 6px; }
.btn-sm svg { width: 14px; height: 14px; }
.btn-xs { height: 26px; padding: 0 9px; font-size: 12px; border-radius: 6px; }
.btn-xs svg { width: 13px; height: 13px; }
.btn-icon { width: 30px; height: 30px; border-radius: 6px; color: #667085; }
.btn-icon svg { width: 16px; height: 16px; }
.btn-icon:hover { background: #F2F5F9; color: var(--text); }
.btn-link { color: #2E75B6; font-size: 12.5px; font-weight: 500; }
.btn-link.danger { color: var(--danger); }

/* ---------------- 表单 ---------------- */
.field > label { font-size: 12.5px; font-weight: 500; color: #475467; }
.field .req { color: var(--danger); }

.input, .select, .textarea {
  height: 36px;
  padding: 0 11px;
  border: 1px solid var(--border-2);
  border-radius: 8px;
  background: #FFFFFF;
  font-size: 13px;
  color: var(--text);
}
.textarea { height: auto; min-height: 84px; padding: 9px 11px; line-height: 1.6; }
.input:hover, .select:hover, .textarea:hover { border-color: #C6D5E9; }
.input:focus, .select:focus, .textarea:focus {
  border-color: #2E75B6;
  box-shadow: 0 0 0 3px rgba(46, 117, 182, .14);
}
.input::placeholder, .textarea::placeholder { color: var(--muted-2); }
.input[readonly] { background: #F8FAFC; color: #475467; }
.input.invalid, .select.invalid, .textarea.invalid { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(220, 38, 38, .12); }

.select {
  appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  cursor: pointer;
}
.error-text { font-size: 12px; color: var(--danger); }
.kbd { border-color: var(--border-2); background: #F8FAFC; color: #475467; }

/* ---------------- 卡片 / 工具栏 ---------------- */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-head {
  padding: 13px 16px;
  border-bottom: 1px solid var(--divider);
  background: #FFFFFF;
  border-radius: var(--radius) var(--radius) 0 0;
}
.card-title { font-size: 15px; font-weight: 600; color: var(--text); }
.card-sub { font-size: 12px; color: var(--muted); font-weight: 400; }
.card-body { padding: 16px; }
.toolbar { padding: 14px 16px; gap: 10px; }
.toolbar-right { gap: 8px; }

/* ---------------- 表格 ---------------- */
.table thead th {
  height: 38px;
  padding: 0 12px;
  background: #F2F5F9;
  border-bottom: 1px solid var(--border);
  color: #667085;
  font-size: 12px;
  font-weight: 600;
}
.table tbody td {
  height: 44px;
  padding: 0 12px;
  border-bottom: 1px solid var(--divider);
  color: #475467;
  font-size: 13px;
}
.table tbody tr:hover { background: #F8FAFC; }
.table tbody tr:last-child td { border-bottom: 0; }
.cell-strong { color: var(--text); font-weight: 600; }
.cell-sub { color: var(--muted); font-size: 11.5px; }
.thumb { border-radius: 8px; border-color: var(--border); }
.thumb-sm { border-radius: 5px; border-color: var(--border); }
.link-url { color: #2E75B6; }

/* ---------------- 徽标 / 标签 / 状态 ---------------- */
.badge {
  height: 22px;
  padding: 0 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
}
.badge-me { background: var(--warn-soft); color: var(--warn); }
.badge-el { background: var(--accent-soft); color: #2E75B6; }
.badge-soft { background: #F2F5F9; color: #667085; }
.tag { height: 20px; border-radius: 4px; font-size: 10.5px; padding: 0 6px; background: #F2F5F9; color: #667085; }
.tag-p0 { background: var(--accent-soft); color: var(--primary); }
.tag-p1 { background: var(--warn-soft); color: var(--warn); }
.tag-p2 { background: #F1EDFF; color: #6D4AC4; }
.status-pill { font-size: 12px; }
.status-ok { color: var(--success); }
.status-warn { color: var(--warn); }
.status-err { color: var(--danger); }

/* ---------------- 分页 ---------------- */
.pager { padding: 12px 16px; border-top: 1px solid var(--divider); }
.pager-info { font-size: 12px; color: var(--muted); }
.pager-btns button {
  min-width: 30px;
  height: 30px;
  padding: 0 9px;
  border: 1px solid var(--border-2);
  border-radius: 6px;
  background: #FFFFFF;
  color: #475467;
  font-size: 12.5px;
}
.pager-btns button:hover:not(:disabled) { border-color: #C6D5E9; background: #F2F5F9; }
.pager-btns button.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.pager-size { font-size: 12px; color: var(--muted); }
.pager-size .select { height: 30px; }

/* ---------------- 弹窗 / Toast / 空状态 ---------------- */
.modal { border-radius: 12px; box-shadow: var(--shadow-lg); }
.modal-head { padding: 18px 20px 10px; }
.modal-title { font-size: 16px; font-weight: 600; color: var(--text); }
.modal-sub { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.modal-close { background: #F2F5F9; border-radius: 6px; color: #667085; }
.modal-close:hover { background: #E4E7EC; color: var(--text); }
.modal-body { padding: 6px 20px 18px; }
.modal-foot {
  padding: 12px 20px;
  background: #F8FAFC;
  border-top: 1px solid var(--divider);
  border-radius: 0 0 12px 12px;
}

.toast-root { top: auto; bottom: 24px; right: 24px; left: auto; transform: none; align-items: flex-end; }
.toast {
  background: #FFFFFF;
  color: var(--text);
  border: 1px solid var(--border-2);
  box-shadow: 0 8px 24px rgba(15, 23, 42, .12);
  font-size: 13px;
  padding: 11px 14px;
  border-radius: 8px;
  min-width: 220px;
  max-width: 420px;
}
.toast svg { color: #15803D; width: 16px; height: 16px; }
.toast-error svg { color: var(--danger); }
.toast-info svg { color: #2E75B6; }

.empty { padding: 44px 20px; }
.empty-icon { width: 44px; height: 44px; border-radius: 50%; background: #F2F5F9; color: #98A2B3; margin-bottom: 10px; }
.empty-title { font-size: 13px; font-weight: 600; color: #475467; }
.empty-sub { font-size: 12px; color: var(--muted-2); max-width: 360px; }
.loading { color: var(--muted); }

/* ---------------- 选型工作台 ---------------- */
.sel-actionbar {
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 14px;
  margin-bottom: 14px;
}
.picker-panel { box-shadow: var(--shadow); }
.picker-toolbar { border-bottom: 1px solid var(--divider); }
.picker-list { background: #FFFFFF; }
.picker-item { border-radius: 8px; }
.picker-item:hover { background: #F8FAFC; border-color: var(--border); }
.picker-item-name { color: var(--text); font-size: 13px; }
.picker-item-meta { color: var(--muted); font-size: 11.5px; }
.qty-input, .remark-input { border-radius: 6px; }
.qty-input { height: 28px; border-color: var(--border-2); font-size: 12.5px; }
.qty-input:focus { border-color: #2E75B6; box-shadow: 0 0 0 2px rgba(46, 117, 182, .14); }
.remark-input { height: 28px; font-size: 12.5px; }
.remark-input:focus { border-color: #2E75B6; box-shadow: 0 0 0 2px rgba(46, 117, 182, .1); }
.sel-table th { background: #F2F5F9; color: #667085; font-size: 11.5px; border-bottom: 1px solid var(--border); }
.sel-table td { border-bottom: 1px solid var(--divider); }
.sel-table tr:hover td { background: #F8FAFC; }
.totals { background: #F8FAFC; border-top: 1px solid var(--divider); border-radius: 0 0 var(--radius) var(--radius); }
.kpi-value { color: var(--text); font-size: 16px; }
.kpi-value.accent { color: var(--primary); }
.kpi-label { color: var(--muted); font-size: 11px; }
.sel-name-input { height: 32px; }

/* ---------------- 元器件库：目录 + 编辑 ---------------- */
.lib-tree-panel { box-shadow: var(--shadow); }
.lib-tree-search { padding: 0 12px 10px; }
.lib-tree-foot { background: #F8FAFC; border-top: 1px solid var(--divider); }
.tree-group-row { color: #475467; font-size: 12.5px; }
.tree-cat-row { color: #667085; }
.tree-group-row:hover, .tree-cat-row:hover { background: #F8FAFC; }
.tree-count { background: #F2F5F9; color: #667085; }
.tree-comp-row { color: #475467; }
.tree-comp-row:hover { background: #F8FAFC; }
.tree-comp-row.active { background: var(--accent-soft); color: var(--primary); }
.tree-comp-model { color: var(--muted-2); }
.lib-detail-panel { box-shadow: var(--shadow); }
.detail-img-big, .img-preview-box, .img-preview-lg { border-color: var(--border); background: #F8FAFC; }
.detail-name { font-size: 19px; color: var(--text); }
.editor-name { font-size: 17px; font-weight: 700; }
.editor-meta { color: var(--muted); }
.editor-foot { border-top: 1px solid var(--divider); }
.editor-actions { gap: 8px; }

/* 目录（选型工作台） */
.dir-toggle { border-color: var(--border-2); border-radius: 8px; height: 34px; color: #475467; }
.dir-toggle:hover { border-color: #C6D5E9; background: #F8FAFC; }
.dir-toggle-current { color: var(--primary); }
.dir-tree { border-color: var(--border); background: #F8FAFC; }
.dir-row { color: #475467; }
.dir-row:hover { background: #EFF5FC; }
.dir-row.active { background: var(--accent-soft); color: var(--primary); }
.dir-l1 { color: #334155; }
.dir-l2 { color: #667085; }
.dir-count { background: #F2F5F9; color: #667085; }

/* ---------------- 导入 / 设置 / 说明 ---------------- */
.import-preview-wrap { border-color: var(--border); border-radius: 8px; }
.mini-table th { background: #F2F5F9; color: #667085; border-bottom: 1px solid var(--border); }
.mini-table td { border-bottom: 1px solid var(--divider); }
.summary-pill { background: #F2F5F9; color: #475467; border-radius: 6px; }
.summary-ok { background: var(--success-soft); color: var(--success); }
.summary-warn { background: var(--warn-soft); color: var(--warn); }
.summary-err { background: var(--danger-soft); color: var(--danger); }
.callout { border-radius: 8px; }
.callout-info { background: var(--accent-soft); color: #1F4E79; border: 1px solid #C9DDF3; }
.callout-warn { background: var(--warn-soft); color: var(--warn); border: 1px solid #FEE4A6; }
.form-section > .label { color: #475467; font-size: 12.5px; }
.radio-row label { font-size: 13px; color: #374151; }
.settings-note, .desc { color: var(--muted); }
.about-page .card { box-shadow: var(--shadow); }
.feature-item { font-size: 12.5px; color: #374151; }
.confirm-list { color: #374151; font-size: 12.5px; }
.doc-block p { color: #374151; }

/* 选型工作台左右卡片等高 */
.workbench { align-items: stretch; }
.sel-panel { display: flex; min-width: 0; }
.sel-panel > .card { flex: 1; display: flex; flex-direction: column; }
.sel-list-wrap { flex: 1; max-height: none; }
.sel-table { width: 100%; }

/* ---------------- 响应式 ---------------- */
@media (max-width: 1180px) {
  .workbench { grid-template-columns: 320px minmax(0, 1fr); }
}
@media (max-width: 960px) {
  .sidebar { width: 196px; flex: 0 0 196px; }
  .lib-layout { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; flex-direction: column; gap: 10px; padding-bottom: 12px; }
  .topbar-actions { margin-left: 0; padding-bottom: 0; }
}


/* ============================================================
   页头压缩 / 选型操作栏单行 / 左栏加宽 / 目录树添加按钮
   ============================================================ */

/* 页头：单行紧凑 */
.topbar {
  height: 58px;
  min-height: 0;
  padding: 0 24px;
  align-items: center;
  gap: 14px;
}
.topbar-heading {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
  flex: 1;
}
.topbar-heading .page-kicker {
  flex: 0 0 auto;
  margin: 0;
  padding: 2px 7px;
  font-size: 10px;
  line-height: 15px;
  border-radius: 4px;
  background: #F2F5F9;
  color: #667085;
  font-weight: 700;
  letter-spacing: .07em;
  white-space: nowrap;
}
.topbar-heading h1 {
  flex: 0 0 auto;
  font-size: 18px;
  line-height: 24px;
  font-weight: 700;
  white-space: nowrap;
  color: var(--text);
}
.page-sub-inline {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (max-width: 1280px) {
  .page-sub-inline { display: none; }
}

/* 选型操作栏：一排 */
.sel-actionbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  padding: 9px 12px;
}
.sel-actionbar .spacer { flex: 1; }
.sel-name-input { width: 220px; height: 32px; flex: 0 1 220px; }
.sel-editor-input { width: 100px; height: 32px; flex: 0 0 100px; }
.sel-actionbar-btns { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.sel-actionbar-btns .btn { height: 30px; }
@media (max-width: 1180px) {
  .sel-actionbar { flex-wrap: wrap; }
  .sel-actionbar-btns { flex-wrap: wrap; }
}

/* 左栏加宽（元器件库目录 / 选型目录） */
.lib-layout { grid-template-columns: 380px minmax(0, 1fr); }
.workbench { grid-template-columns: 380px minmax(0, 1fr); }
@media (max-width: 1366px) {
  .lib-layout { grid-template-columns: 360px minmax(0, 1fr); }
  .workbench { grid-template-columns: 360px minmax(0, 1fr); }
}
@media (max-width: 1180px) {
  .lib-layout { grid-template-columns: 330px minmax(0, 1fr); }
  .workbench { grid-template-columns: 330px minmax(0, 1fr); }
}
@media (max-width: 960px) {
  .lib-layout { grid-template-columns: 1fr; }
  .workbench { grid-template-columns: 1fr; }
}

/* 选型目录树：点击行加入，右侧 + 按钮 */
.tree-comp-add { cursor: pointer; }
.tree-comp-add .sel-tree-add {
  width: 22px;
  height: 22px;
  min-width: 22px;
  padding: 0;
  border-radius: 5px;
  opacity: .45;
  margin-left: 2px;
  flex: 0 0 auto;
  transition: opacity .15s;
}
.tree-comp-add:hover .sel-tree-add { opacity: 1; }
.sel-tree-add svg { width: 12px; height: 12px; }
.tree-comp-add .tree-comp-model { max-width: 64px; }
.picker-panel { max-height: calc(100vh - 130px); }

/* ============================================================
   高度自适应：工作台/元器件库卡片贴合视口，列表内部滚动
   ============================================================ */
.workbench {
  height: calc(100vh - 202px);
  min-height: 520px;
  align-items: stretch;
}
.workbench .picker-panel { max-height: none; height: 100%; }
.workbench .sel-panel { height: 100%; }
.workbench .sel-panel > .card { height: 100%; }
.workbench .sel-list-wrap { flex: 1; max-height: none; overflow: auto; }
.workbench .picker-panel .lib-tree { flex: 1; min-height: 0; }

.lib-layout {
  height: calc(100vh - 136px);
  min-height: 520px;
  align-items: stretch;
}
.lib-layout .lib-tree-panel { max-height: none; height: 100%; }
.lib-layout .lib-detail-panel { min-height: 0; height: 100%; overflow: auto; }

.tree-comp-add .tree-comp-model { max-width: 80px; }

@media (max-width: 960px) {
  .workbench, .lib-layout { height: auto; min-height: 0; }
  .workbench .picker-panel, .workbench .sel-panel { height: auto; }
  .lib-layout .lib-tree-panel, .lib-layout .lib-detail-panel { height: auto; }
}

/* 修正：grid 行高约束 + 子项可收缩（保证内部滚动而不是撑高页面） */
.workbench { grid-template-rows: minmax(0, 1fr); }
.workbench > * { min-height: 0; }
.workbench .workbench-side, .workbench .sel-panel { min-width: 0; min-height: 0; }
.lib-layout { grid-template-rows: minmax(0, 1fr); }
.lib-layout > * { min-height: 0; min-width: 0; }


/* 选型清单底部操作栏（按钮从顶部移到底部右侧） */
.sel-actionbar { gap: 10px; }
.sel-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--divider);
  background: #FFFFFF;
  border-radius: 0 0 var(--radius) var(--radius);
  flex-wrap: wrap;
}
.sel-footer .spacer { flex: 1; }
.sel-footer .sel-actionbar-btns { flex-wrap: wrap; }
.sel-footer .btn { height: 30px; }
.totals { border-radius: 0; }
.tree-comp-model { max-width: 82px; }


/* 选型清单标题栏右侧操作按钮 */
.sel-list-head {
  align-items: center;
  gap: 12px;
}
.sel-head-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.sel-head-actions .btn { height: 30px; }
.sel-list-head .card-title { flex: 0 0 auto; }
@media (max-width: 1600px) {
  .snap-hint { display: none; }
}
@media (max-width: 1180px) {
  .sel-head-actions { margin-left: 0; }
}
.totals { border-radius: 0 0 var(--radius) var(--radius); }


/* 选型清单底部：清空 / 另存为 / 保存 */
.sel-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--divider);
  background: #FFFFFF;
  border-radius: 0 0 var(--radius) var(--radius);
  flex-wrap: wrap;
}
.sel-footer .spacer { flex: 1; }
.sel-footer .sel-head-actions { margin-left: 0; }
.sel-footer .btn { height: 30px; }
.totals { border-radius: 0; }


/* 合计行右侧：清空 / 另存为 / 保存 */
.sel-totals-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.sel-totals-actions .btn { height: 30px; }
.totals { border-radius: 0 0 var(--radius) var(--radius); }


/* ============================================================
   目录：只显示分类/品牌子项 + 下方元器件列表
   ============================================================ */
.dir-mode {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  background: #F2F5F9;
  border-radius: 7px;
  flex: 0 0 auto;
}
.dir-mode button {
  height: 26px;
  padding: 0 10px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: #667085;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.dir-mode button:hover { color: var(--text); }
.dir-mode button.on {
  background: #FFFFFF;
  color: var(--primary);
  box-shadow: 0 1px 2px rgba(16, 24, 40, .08);
}

.dir-tree-only {
  flex: 0 0 auto;
  max-height: 300px;
  overflow: auto;
  padding: 4px 8px 8px;
  border-bottom: 1px solid var(--divider);
}
.tree-node-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 7px;
  font-size: 12.5px;
  color: #475467;
  cursor: pointer;
}
.tree-node-row:hover { background: #F8FAFC; }
.tree-node-row.active {
  background: var(--accent-soft);
  color: var(--primary);
  font-weight: 600;
}
.tree-node-sub { padding-left: 26px; color: #667085; }
.tree-group-row { cursor: pointer; }
.tree-group-row .tree-add-cat {
  width: 20px;
  height: 20px;
  min-width: 20px;
  padding: 0;
  border-radius: 5px;
  opacity: .5;
  margin-left: 2px;
}
.tree-group-row:hover .tree-add-cat { opacity: 1; }
.tree-add-cat svg { width: 12px; height: 12px; }

.comp-mini-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  border-bottom: 1px solid var(--divider);
  background: #F8FAFC;
  font-size: 11.5px;
  color: #667085;
  flex: 0 0 auto;
}
.comp-mini-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 4px 8px;
}
.comp-mini-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.comp-mini-row:hover { background: #F8FAFC; }
.comp-mini-row.active { background: var(--accent-soft); }
.comp-mini-info { flex: 1; min-width: 0; }
.comp-mini-name {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.comp-mini-model {
  font-weight: 400;
  color: #667085;
  font-size: 11.5px;
  margin-left: 4px;
}
.comp-mini-meta {
  margin-top: 2px;
  font-size: 11px;
  color: #667085;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.comp-mini-add {
  width: 22px;
  height: 22px;
  min-width: 22px;
  padding: 0;
  border-radius: 5px;
  opacity: .45;
  flex: 0 0 auto;
  transition: opacity .15s;
}
.comp-mini-row:hover .comp-mini-add { opacity: 1; }
.comp-mini-add svg { width: 12px; height: 12px; }


/* 品牌目录内的机械/电气分组行 */
.tree-node-group {
  padding-left: 22px;
  color: #475467;
  font-weight: 500;
  cursor: pointer;
}
.tree-node-group:hover { background: #F8FAFC; }
.tree-node-group .tree-arrow { width: 12px; }


/* 目录树内的元器件叶子节点 */
.dir-tree-only { flex: 1; max-height: none; }
.tree-comp-leaf {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px 5px 38px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  color: #374151;
}
.tree-comp-leaf:hover { background: #F8FAFC; }
.tree-comp-leaf.active { background: var(--accent-soft); color: var(--primary); font-weight: 600; }
.tree-comp-leaf .tree-comp-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tree-comp-leaf .tree-comp-model {
  color: #98A2B3;
  font-size: 10.5px;
  max-width: 88px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tree-leaf-add {
  width: 20px;
  height: 20px;
  min-width: 20px;
  padding: 0;
  border-radius: 5px;
  opacity: .45;
  flex: 0 0 auto;
  transition: opacity .15s;
}
.tree-comp-leaf:hover .tree-leaf-add { opacity: 1; }
.tree-leaf-add svg { width: 12px; height: 12px; }


/* 目录层级：一级 / 二级 / 三级 缩进拉开，避免层级混淆 */
.tree-group-row { padding-left: 8px; }
.tree-cat-row { padding-left: 30px; font-size: 12px; }
.tree-node-group {
  padding-left: 30px;
  font-weight: 600;
  color: #334155;
  font-size: 12.5px;
}
.tree-node-sub { padding-left: 56px; color: #667085; font-size: 12px; }
.tree-comp-leaf { padding-left: 56px; }
.tree-comp-leaf.leaf-brand { padding-left: 78px; }
.tree-comp-leaf .tree-comp-model { max-width: 78px; }


/* ============================================================
   目录层级视觉增强：缩进 + 竖向引导线 + 字重/颜色
   ============================================================ */
.lib-tree-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.lib-tree-foot .btn { flex: 0 0 auto; }

/* 一级：类型 / 品牌 */
.tree-group-row {
  padding: 8px 8px 8px 6px;
  font-weight: 700;
  font-size: 13px;
  color: #101828;
  background: #F8FAFC;
  margin-top: 2px;
}
.tree-group-row .tree-arrow { width: 16px; color: #667085; font-size: 12px; }
.tree-group-row .tree-count { background: #E4E7EC; color: #475467; }

/* 二级：类型下的分类 / 品牌下的机械、电气 */
.tree-cat-row,
.tree-node-group {
  padding: 7px 8px 7px 44px;
  font-weight: 600;
  font-size: 12.5px;
  color: #1F4E79;
  background-image: linear-gradient(#E4E7EC, #E4E7EC);
  background-size: 1px 100%;
  background-position: 20px 0;
  background-repeat: no-repeat;
  border-radius: 0;
}
.tree-node-group { font-weight: 600; }

/* 三级：二级分类 */
.tree-node-sub {
  padding: 7px 8px 7px 80px;
  font-weight: 400;
  font-size: 12px;
  color: #475467;
  background-image: linear-gradient(#E4E7EC, #E4E7EC), linear-gradient(#E4E7EC, #E4E7EC);
  background-size: 1px 100%, 1px 100%;
  background-position: 20px 0, 52px 0;
  background-repeat: no-repeat;
}

/* 元器件叶子（类型模式第 3 级 / 品牌模式第 4 级） */
.tree-comp-leaf {
  padding: 6px 8px 6px 80px;
  background-image: linear-gradient(#E4E7EC, #E4E7EC), linear-gradient(#E4E7EC, #E4E7EC);
  background-size: 1px 100%, 1px 100%;
  background-position: 20px 0, 52px 0;
  background-repeat: no-repeat;
}
.tree-comp-leaf.leaf-brand {
  padding-left: 114px;
  background-image: linear-gradient(#E4E7EC, #E4E7EC), linear-gradient(#E4E7EC, #E4E7EC), linear-gradient(#E4E7EC, #E4E7EC);
  background-size: 1px 100%, 1px 100%, 1px 100%;
  background-position: 20px 0, 52px 0, 86px 0;
}
.tree-comp-leaf .tree-comp-name { font-size: 12px; }
.tree-comp-leaf .tree-comp-model { font-size: 10.5px; }


/* 品牌下只有一类（机械或电气）时：分类直接挂在品牌下，缩进少一级 */
.tree-node-direct {
  padding-left: 44px;
  background-image: linear-gradient(#E4E7EC, #E4E7EC);
  background-size: 1px 100%;
  background-position: 20px 0;
  background-repeat: no-repeat;
}


/* ============================================================
   元器件库右侧参数编辑区：重新排版（图片在左，字段 3 列紧凑）
   ============================================================ */
.editor-top { display: flex; gap: 18px; align-items: flex-start; }
.editor-img {
  width: 150px;
  flex: 0 0 150px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.img-preview-lg { width: 150px; height: 150px; }
.editor-img .img-picker-actions { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.editor-img .img-picker-actions .btn { justify-content: center; }
.editor-main { flex: 1; min-width: 0; }
.editor-name-row { display: flex; align-items: center; gap: 10px; }
.editor-name-input { font-size: 16px; font-weight: 700; height: 38px; flex: 1; }
.editor-meta { font-size: 12px; color: var(--muted); margin-top: 8px; line-height: 1.7; }
.editor-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr 1fr;
  gap: 14px 16px;
  margin-top: 16px;
}
.editor-grid .form-row-full { grid-column: 1 / -1; }
.editor-cats { display: flex; gap: 8px; }
.editor-cats .select:first-child { width: 40%; }
.editor-cats .select:last-child { flex: 1; }
@media (max-width: 1500px) {
  .editor-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 1100px) {
  .editor-grid { grid-template-columns: 1fr; }
}


/* 参数编辑：图片移到右侧 */
.editor-top { align-items: flex-start; }
.editor-img {
  width: 200px;
  flex: 0 0 200px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  background: #FAFBFD;
  align-items: stretch;
}
.editor-img-title { font-size: 12px; font-weight: 500; color: #667085; }
.img-preview-lg { width: 100%; height: 164px; }
.editor-img .img-picker-tip { font-size: 11px; line-height: 1.5; }
@media (max-width: 1500px) {
  .editor-img { width: 180px; flex: 0 0 180px; }
  .img-preview-lg { height: 148px; }
}
@media (max-width: 1100px) {
  .editor-top { flex-wrap: wrap; }
  .editor-img {
    width: 100%;
    flex: 1 1 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
  }
  .editor-img-title { flex: 0 0 100%; }
  .img-preview-lg { width: 140px; height: 140px; flex: 0 0 140px; }
  .editor-img .img-picker-actions { flex: 1; min-width: 160px; }
}
