/* ============================================================
 * HT Editor · 左侧面板（图页 / 图元 / 组件 / 资源）
 * ============================================================ */

.lib-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ---- 顶部 Tab ---- */
.lib-tabs {
  display: flex;
  gap: 2px;
  padding: 6px 8px 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  flex-shrink: 0;
}
.lib-tab {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color .12s, border-color .12s, background .12s;
  font-family: var(--font);
}
.lib-tab:hover { color: var(--text); background: var(--bg-elevated); }
.lib-tab.active { color: var(--primary); border-bottom-color: var(--primary); background: var(--primary-soft); }

/* ---- 面板容器 ---- */
.lib-pane { display: none; flex: 1; flex-direction: column; min-height: 0; }
.lib-pane.active { display: flex; }

.lib-bar {
  display: flex;
  gap: 4px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.lib-bar.cols3 { flex-wrap: wrap; }
.lib-bar.cols3 .lib-btn { flex: 1 1 30%; }
.lib-btn {
  flex: 1;
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-panel-2);
  color: var(--text);
  font-size: 12px;
  border-radius: var(--radius-sm);
  padding: 4px 6px;
  cursor: pointer;
  transition: border-color .12s, background .12s, color .12s;
  font-family: var(--font);
  white-space: nowrap;
}
.lib-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.lib-btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.lib-btn.primary:hover { background: var(--primary-hover); color: #fff; }

.lib-body { flex: 1; overflow: auto; padding: 6px 6px 12px; }
.lib-foot {
  flex-shrink: 0;
  padding: 6px 8px;
  border-top: 1px solid var(--border);
}
.lib-search {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12px;
  padding: 5px 8px;
  outline: none;
  font-family: var(--font);
}
.lib-search:focus { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }

/* ============================================================
 * 图页（图纸树）
 * ============================================================ */
.pg-tree-root { padding: 2px 0; }
.pg-folder { margin: 1px 0; }
.pg-folder-head {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  cursor: grab;
  font-size: 12px;
  color: var(--text);
  user-select: none;
}
.pg-folder-head:active { cursor: grabbing; }
.pg-folder-head:hover { background: var(--bg-elevated); }
.pg-folder-head .tw { width: 10px; height: 10px; flex-shrink: 0; color: var(--text-dim); transition: transform .12s; }
.pg-folder.open > .pg-folder-head .tw { transform: rotate(90deg); }
.pg-folder-head .fi { color: var(--warning); flex-shrink: 0; }
.pg-folder-head .fn { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pg-folder-head .cnt { font-size: 10px; color: var(--text-mute); }

.pg-folder-children { padding-left: 14px; display: none; }
.pg-folder.open > .pg-folder-children { display: block; }

.pg-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 22px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  color: var(--text-dim);
  user-select: none;
  border: 1px solid transparent;
}
.pg-item:hover { background: var(--bg-elevated); color: var(--text); }
.pg-item.active { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }
.pg-item .pi { width: 13px; height: 13px; flex-shrink: 0; color: var(--primary); }
.pg-item .pn { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pg-item.drag-over { border-color: var(--primary); background: var(--primary-soft); }
.pg-folder-head.drag-over { border: 1px dashed var(--primary); }
.pg-folder-head.drop-before { box-shadow: inset 0 2px 0 var(--primary); }
.pg-folder-head.drop-after { box-shadow: inset 0 -2px 0 var(--primary); }
.pg-folder-head.drop-into { background: var(--primary-soft); border: 1px dashed var(--primary); }
.mat-folder-head.drag-over { background: var(--primary-soft); border-radius: 4px; }

.pg-empty { padding: 24px 10px; text-align: center; color: var(--text-mute); font-size: 12px; line-height: 1.7; }
.pg-empty .btn {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  background: var(--bg-panel-2);
  font-size: 12px;
  font-family: var(--font);
}
.pg-empty .btn:hover { color: var(--primary); border-color: var(--primary); }

/* ============================================================
 * 图元（自定义图元库）
 * ============================================================ */
.sym-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
  border: 1px solid transparent;
  user-select: none;
}
.sym-item:hover { background: var(--bg-elevated); }
.sym-item .thumb {
  width: 30px; height: 30px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-panel-2);
  display: grid; place-items: center;
  flex-shrink: 0;
  overflow: hidden;
}
.sym-item .thumb svg { width: 24px; height: 24px; }
.sym-item .sn { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sym-item .act { opacity: 0; transition: opacity .12s; }
.sym-item:hover .act { opacity: 1; }
.sym-item .act button {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 3px;
  border-radius: 4px;
  line-height: 1;
}
.sym-item .act button:hover { color: var(--danger); background: var(--bg-elevated); }

/* ============================================================
 * 资源
 * ============================================================ */
.as-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
  border: 1px solid transparent;
  user-select: none;
}
.as-item:hover { background: var(--bg-elevated); }
.as-item .thumb {
  width: 30px; height: 30px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-panel-2);
  display: grid; place-items: center;
  flex-shrink: 0;
  overflow: hidden;
}
.as-item .thumb img { max-width: 26px; max-height: 26px; }
.as-item .thumb svg { width: 24px; height: 24px; }
.as-item .an { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.as-item .asz { font-size: 10px; color: var(--text-mute); }
.as-item .act { opacity: 0; transition: opacity .12s; }
.as-item:hover .act { opacity: 1; }
.as-item .act button {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 3px;
  border-radius: 4px;
  line-height: 1;
}
.as-item .act button:hover { color: var(--danger); background: var(--bg-elevated); }

/* 拖拽状态 */
.dragging-row { opacity: .45; }

/* ============================================================
 * ht-library.js 追加样式（同步状态 / 右键菜单 / 轻提示 / 预览弹层 / 角标）
 * ============================================================ */
.lib-sync {
  flex-shrink: 0;
  padding: 4px 8px;
  border-top: 1px solid var(--border);
  font-size: 10px;
  color: var(--text-mute);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- 自建右键菜单 ---- */
.lib-ctx {
  position: fixed;
  z-index: 4000;
  min-width: 132px;
  padding: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .38);
  display: flex;
  flex-direction: column;
}
.lib-ctx-item {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-size: 12px;
  font-family: var(--font);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
}
.lib-ctx-item:hover { background: var(--primary-soft); color: var(--primary); }
.lib-ctx-item.danger { color: var(--danger); }
.lib-ctx-item.danger:hover { background: rgba(255, 92, 92, .14); color: var(--danger); }
.lib-ctx-sep { height: 1px; margin: 4px 2px; background: var(--border); }
/* 二级子菜单（导出 ▸） */
.lib-ctx-item.has-sub { position: relative; display: flex; align-items: center; }
.lib-ctx-item.has-sub .lib-ctx-arrow { margin-left: auto; padding-left: 12px; opacity: .7; font-size: 10px; }
.lib-ctx.sub {
  position: absolute; left: 100%; top: -5px;
  display: none; min-width: 150px; margin-left: 2px;
}
.lib-ctx-item.has-sub:hover > .lib-ctx.sub { display: flex; }
.lib-ctx-item.has-sub.open > .lib-ctx.sub { display: flex; }
.lib-ctx-item.has-sub:hover { background: var(--primary-soft); color: var(--primary); }
.lib-ctx-item.has-sub.open { background: var(--primary-soft); color: var(--primary); }

/* ---- 素材广场（对标墨刀素材广场） ---- */
.mat-cats { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.mat-cat { padding: 3px 9px; font-size: 11px; font-family: inherit; color: var(--text-mute); background: transparent; border: 1px solid var(--border); border-radius: 11px; cursor: pointer; }
.mat-cat:hover { color: var(--primary); border-color: var(--primary); }
.mat-cat.on { color: #fff; background: var(--primary); border-color: var(--primary); }
.mat-body { padding: 8px; }
.mat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mat-group-head { grid-column: 1 / -1; font-size: 11px; color: var(--text-mute); padding: 6px 2px 2px; border-bottom: 1px dashed var(--border); margin-bottom: 2px; }
.mat-folder-head { color: var(--text-dim); cursor: default; }
.mat-folder-head::before { content: '▸ '; color: var(--warning); }
.mat-card { position: relative; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; cursor: pointer; background: var(--bg-input); transition: border-color .15s, transform .15s; }
.mat-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.mat-card:active { cursor: grabbing; }
.mat-card .mat-star { position: absolute; right: 3px; top: 3px; width: 18px; height: 18px; padding: 0; line-height: 17px; text-align: center; font-size: 12px; color: var(--text-mute); background: rgba(0,0,0,.38); border: none; border-radius: 50%; cursor: pointer; z-index: 2; }
.mat-card .mat-star:hover { color: #f5c542; }
.mat-card .mat-star.on { color: #f5c542; }
.mat-card .mat-badge { position: absolute; left: 3px; top: 3px; padding: 0 5px; height: 16px; line-height: 16px; font-size: 10px; color: #fff; background: rgba(37,99,235,.9); border-radius: 8px; z-index: 2; }
.mat-card .mt { display: block; width: 100%; height: 66px; background: #0b1120; }
.mat-card .mt svg { width: 100%; height: 100%; display: block; }
.mat-card .mn { padding: 4px 6px; font-size: 11px; color: var(--text-dim); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mat-empty { font-size: 11px; color: var(--text-mute); text-align: center; padding: 24px 0; }
/* 3D「我的素材」：存为素材按钮 */
.mat-mine-bar { display: flex; gap: 6px; margin-bottom: 8px; }
.mat-add-btn {
  flex: 1; padding: 5px 8px; font-size: 11px; font-family: inherit;
  background: transparent; color: var(--text-mute);
  border: 1px dashed var(--border); border-radius: 6px; cursor: pointer;
}
.mat-add-btn:hover { color: var(--primary); border-color: var(--primary); }
/* 3D「我的素材」文件夹头（自带 ▸/▾，取消 ::before 箭头） */
.mat3d-folder {
  display: flex; align-items: center; gap: 4px;
  padding: 5px 8px; margin: 2px 0; border-radius: 4px;
  font-size: 11px; color: var(--text-dim); cursor: pointer; user-select: none;
}
.mat3d-folder::before { content: none; }
.mat3d-folder:hover, .mat3d-folder.drop-into { background: var(--primary-soft); color: var(--primary); }

/* ---- 轻量提示 ---- */
.lib-toast {
  position: fixed;
  left: 50%;
  bottom: 46px;
  transform: translateX(-50%);
  z-index: 4100;
  max-width: 70vw;
  padding: 7px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  color: var(--text);
  font-size: 12px;
  font-family: var(--font);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .38);
}

/* ---- 预览弹层 ---- */
.lib-lightbox {
  position: fixed;
  inset: 0;
  z-index: 4200;
  background: rgba(0, 0, 0, .55);
  display: grid;
  place-items: center;
  padding: 24px;
}
.lib-lb-card {
  display: flex;
  flex-direction: column;
  min-width: 220px;
  max-width: 88vw;
  background: var(--bg-panel, var(--bg-elevated));
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 12px 48px rgba(0, 0, 0, .5);
}
.lib-lb-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.lib-lb-title {
  flex: 1;
  font-size: 12px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lib-lb-close {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
}
.lib-lb-close:hover { color: var(--danger); background: var(--bg-elevated); }
.lib-lb-body { display: grid; place-items: center; padding: 12px; overflow: auto; }
.lib-lb-body img {
  max-width: 80vw;
  max-height: 70vh;
  object-fit: contain;
  background: repeating-conic-gradient(var(--bg-input) 0% 25%, var(--bg-panel-2) 0% 50%) 0 0 / 16px 16px;
}

/* ---- 资源类型角标 ---- */
.lib-dxf { font-size: 9px; font-weight: 700; letter-spacing: .5px; color: var(--warning); }

/* ---- 拖到根区域的提示 ---- */
.pg-tree-root.drag-over { outline: 1px dashed var(--primary); outline-offset: -2px; border-radius: var(--radius-sm); }

/* ============================================================
 * 缩略图视图拉动栏 / 图纸缩略图 / 资源拖拽导入
 * ============================================================ */
.lib-viewbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-top: 1px solid var(--border);
  color: var(--text-mute);
}
.lib-viewbar .vb-ico { display: grid; place-items: center; flex-shrink: 0; }
.lib-viewbar input[type="range"] {
  flex: 1;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
  background: transparent;
}

.pg-thumb {
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  background: var(--bg-panel-2);
  display: grid;
  place-items: center;
}
.pg-thumb canvas { display: block; }

/* 图元缩略图跟随拉动条尺寸 */
.sym-item .thumb svg { width: 100%; height: 100%; }

/* 资源栏目：文件拖拽导入高亮 */
.lib-pane.file-drag-over { outline: 2px dashed var(--primary); outline-offset: -3px; background: var(--primary-soft); }

/* ============================================================
 * 左侧面板多选 / 框选
 * ============================================================ */
.sym-item.sel,
.as-item.sel,
.pg-item.sel {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}
.sym-item.sel .sn,
.as-item.sel .an,
.pg-item.sel .pn { color: var(--primary); }

.lib-marquee {
  position: fixed;
  z-index: 5000;
  border: 1px dashed var(--primary);
  background: var(--primary-soft);
  pointer-events: none;
}

/* ============================================================
 * 回收站对话框
 * ============================================================ */
.tr-modal { width: 620px; max-width: 92vw; }
.tr-modal h3 { display: flex; align-items: baseline; gap: 8px; }
.tr-sub { font-size: 11px; font-weight: normal; color: var(--text-mute); }
.tr-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tr-tab {
  padding: 4px 10px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-app);
  color: var(--text-dim);
  cursor: pointer;
  font-family: inherit;
}
.tr-tab:hover { border-color: var(--primary); color: var(--text); }
.tr-tab.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.tr-list { max-height: 46vh; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-app); }
.tr-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 12px; }
.tr-row:last-child { border-bottom: 0; }
.tr-row:hover { background: var(--bg-elevated); }
.tr-ico { flex-shrink: 0; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 4px; background: var(--bg-panel-2); font-size: 12px; color: var(--text-dim); }
.tr-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.tr-kind { flex-shrink: 0; font-size: 11px; color: var(--text-mute); min-width: 32px; }
.tr-time { flex-shrink: 0; font-size: 11px; color: var(--text-mute); font-family: var(--font-mono); }
.tr-acts { flex-shrink: 0; display: flex; gap: 6px; }
.tr-btn {
  padding: 3px 10px;
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
}
.tr-btn:hover { border-color: var(--primary); color: var(--primary); }
.tr-btn.danger:hover { border-color: var(--danger); color: var(--danger); }
.tr-empty { padding: 26px; text-align: center; font-size: 12px; color: var(--text-mute); }
.modal .btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
