/* ==========================================================================
   代码导出工作区
   ========================================================================== */

.export-workspace {
  flex-direction: column;
  padding: 14px 16px 16px;
  gap: 12px;
  min-height: 0;
}

.export-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
  min-height: 52px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  background: var(--bg-panel);
}
.export-heading {
  display: flex;
  align-items: center;
  gap: 10px;
}
.export-heading > svg {
  color: var(--accent-hover);
}
.export-title {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
}
.export-subtitle {
  font-size: 11px;
  color: var(--text-faint);
  line-height: 1.4;
}
.export-options {
  display: flex;
  align-items: center;
  gap: 10px;
}
.export-option {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
}
.export-option .select {
  width: 154px;
  height: 30px;
  font-size: 12px;
}

.export-body {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 12px;
}

.export-sidebar {
  width: 316px;
  flex: none;
}
.export-sidebar .panel-body {
  display: flex;
  flex-direction: column;
  padding-bottom: 0;
  overflow: hidden;
}
.export-sidebar-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.export-sidebar-body .file-tree {
  flex: 1 1 42%;
  min-height: 130px;
  max-height: 46%;
}
.export-sidebar-body .export-warnings {
  flex: none;
  max-height: 200px;
}

.export-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.export-status {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  flex: none;
  min-height: 22px;
  padding: 0 2px;
}
.export-status .chip {
  height: 24px;
}

/* ---------------------------- 文件树 ---------------------------- */

.file-tree {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 8px 8px 4px;
}
.file-group {
  margin-bottom: 8px;
}
.file-group-title {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-faint);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.file-group-count {
  margin-left: auto;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-faint);
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 6px;
  line-height: 16px;
}
.file-item {
  display: flex;
  align-items: center;
  gap: 2px;
  width: 100%;
  padding: 4px 4px 4px 8px;
  margin-bottom: 2px;
  border: 1px solid transparent;
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--text-dim);
  font-size: 12.5px;
  text-align: left;
}
.file-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.file-item.active {
  background: var(--accent-weak);
  border-color: rgba(99, 102, 241, 0.35);
  color: var(--text);
}
.file-item.active svg {
  color: var(--accent-hover);
}
.file-main {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  padding: 3px 0;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.file-main svg {
  flex: none;
  opacity: 0.8;
}
.file-actions {
  display: flex;
  align-items: center;
  gap: 0;
  flex: none;
  opacity: 0.18;
  transition: opacity 0.12s var(--ease);
}
.file-item:hover .file-actions,
.file-item.active .file-actions {
  opacity: 1;
}
.file-badge {
  flex: none;
  margin-left: 4px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--accent-weak);
  color: var(--accent-text);
  font-size: 10px;
  font-weight: 600;
}
.file-badge.live {
  background: var(--success-weak);
  color: var(--success);
}
.file-item.disabled {
  opacity: 0.65;
  cursor: default;
}
.file-item.disabled:hover {
  background: transparent;
  color: var(--text-dim);
}
.file-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-code);
  font-size: 12px;
}
.file-size {
  flex: none;
  font-size: 10.5px;
  color: var(--text-faint);
}
.file-hint {
  padding: 4px 10px 8px;
  font-size: 11px;
  line-height: 1.6;
  color: var(--text-faint);
}

.export-generating {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 12px;
  font-size: 12.5px;
  color: var(--text-dim);
}

.export-error {
  padding: 16px;
  color: var(--text-dim);
  font-size: 12.5px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------------------------- 代码面板 ---------------------------- */

.code-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  background: var(--bg-panel);
  overflow: hidden;
}
.code-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
  height: 42px;
  padding: 0 10px 0 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
}
.code-path {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  font-family: var(--font-code);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
}
.code-path svg {
  color: var(--accent-hover);
  flex: none;
}
.code-path span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.code-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-faint);
  flex: none;
}
.code-meta .chip {
  height: 20px;
  font-size: 10px;
}
.code-scroll {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: flex-start;
  overflow: auto;
  background: var(--bg-inset);
}
.line-gutter {
  position: sticky;
  left: 0;
  z-index: 1;
  flex: none;
  margin: 0;
  padding: 14px 10px 20px 14px;
  min-width: 56px;
  text-align: right;
  font-family: var(--font-code);
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--text-faint);
  user-select: none;
  background: var(--bg-inset);
  border-right: 1px solid var(--border);
}
.code-pre {
  margin: 0;
  padding: 14px 20px 20px 14px;
  font-family: var(--font-code);
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--text);
  tab-size: 4;
  min-width: max-content;
}
.code-content {
  font-family: inherit;
  white-space: pre;
}
.code-pre .tok-comment {
  color: var(--text-faint);
}

.export-empty {
  margin: auto;
  height: 100%;
}

/* ---------------------------- 提示列表 ---------------------------- */

.export-warnings {
  flex: none;
  max-height: 240px;
  overflow: auto;
  margin: 0 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.export-warnings-empty {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  font-size: 11.5px;
  color: var(--success);
}
.export-warnings-header {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 8px 6px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--warn);
}
.export-warnings-header .faint {
  margin-left: auto;
  font-weight: 400;
}
.export-warnings-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-bottom: 4px;
}
.warning-item {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  padding: 5px 8px;
  border: none;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-dim);
  font-size: 11.5px;
  line-height: 1.45;
  text-align: left;
  cursor: pointer;
}
.warning-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.warning-dot {
  flex: none;
  width: 6px;
  height: 6px;
  margin-top: 4px;
  border-radius: 50%;
  background: var(--warn);
}
.warning-item.is-error .warning-dot {
  background: var(--danger);
}
.warning-text {
  flex: 1;
  min-width: 0;
}

/* 文件多选 */
.file-selection-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin: 8px 8px 4px;
  padding: 6px 8px;
  border: 1px solid rgba(99, 102, 241, 0.35);
  border-radius: var(--radius-s);
  background: var(--accent-weak);
}
.file-selection-bar[hidden] {
  display: none;
}
.file-selection-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent-text);
  padding: 0 2px;
}
.file-item.selected {
  background: var(--accent-weak);
  border-color: rgba(99, 102, 241, 0.5);
  color: var(--text);
}
.file-item.selected .file-actions {
  opacity: 1;
}

/* ==========================================================================
   代码管理面板（v1.1）：导出页左侧的自定义模块 / 函数 / 覆盖列表
   ========================================================================== */

.code-manager {
  flex: none;
  max-height: 46%;
  overflow: auto;
  padding: 2px 8px 8px;
  border-top: 1px solid var(--border);
}

.cm-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 2px 5px;
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-panel);
}
.cm-section-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  text-transform: uppercase;
}
.cm-count {
  min-width: 16px;
  height: 16px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 600;
  line-height: 14px;
  text-align: center;
}

.cm-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 5px 5px 7px;
  border-radius: var(--radius-s);
}
.cm-row:hover {
  background: var(--bg-hover);
}
.cm-row-icon {
  flex: none;
  color: var(--text-faint);
}
.cm-row-body {
  flex: 1;
  min-width: 0;
}
.cm-row-title {
  font-family: var(--font-code);
  font-size: 11.5px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cm-row-sub {
  margin-top: 1px;
  font-size: 10.5px;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cm-actions {
  display: flex;
  align-items: center;
  flex: none;
  opacity: 0.25;
  transition: opacity 0.12s var(--ease);
}
.cm-row:hover .cm-actions {
  opacity: 1;
}
.cm-empty {
  padding: 2px 6px 8px;
  font-size: 11px;
  line-height: 1.65;
  color: var(--text-faint);
}

/* ---------------------------- 函数编辑弹窗 ---------------------------- */

.cm-function-form .cm-code {
  font-family: var(--font-code);
  font-size: 12.5px;
  line-height: 1.6;
  min-height: 148px;
  tab-size: 4;
  white-space: pre;
  overflow: auto;
}
.cm-form-grid {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 12px;
}
.cm-param-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg-inset);
}
.cm-param-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr) auto;
  gap: 6px;
  align-items: center;
}
.cm-param-list .btn-sm {
  align-self: flex-start;
  margin-top: 2px;
}
.cm-error {
  min-height: 18px;
  margin: 2px 0 4px;
  font-size: 12px;
  color: var(--danger);
}
.cm-preview-title {
  margin: 8px 0 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}
.cm-function-preview {
  max-height: 230px;
  margin: 0;
  padding: 11px 13px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--bg-inset);
  color: var(--text);
  font-family: var(--font-code);
  font-size: 12px;
  line-height: 1.65;
  white-space: pre;
  tab-size: 4;
}

/* 小屏适配 */
@media (max-width: 1240px) {
  .export-sidebar {
    width: 280px;
  }
  .export-options {
    display: none;
  }
}
