/* 主容器 - sidebar-content已有padding，这里不需要 */
.preset-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 0;
  gap: 8px;
  background: var(--color-bg-subtle);
  overflow-y: auto;
}

/* 工具提示 */
.tooltip {
  position: fixed;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.85);
  color: white;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  z-index: var(--z-tooltip); /* ✅ 组件层 - 悬浮提示 */
  pointer-events: none;
  box-shadow: var(--shadow-md);
  transform: translate(-50%, -100%);
  margin-top: -6px;
}

/* 预设头部 - 紧凑布局 */
.preset-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--color-bg-elevated);
  border-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.preset-select-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
}

.preset-select {
  flex: 1;
  padding: 5px 8px;
  background: var(--color-bg-tertiary);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 12px;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
}

.preset-select:hover {
  border-color: var(--color-border-focus);
  background: var(--color-bg-elevated);
}

.preset-select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px var(--color-accent-light);
}

.preset-select:disabled {
  background: #f1f3f5;
  cursor: not-allowed;
  color: #adb5bd;
}

/* 操作下拉菜单 */
.actions-dropdown {
  position: relative;
}

.dropdown-toggle {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 14px;
  padding: 0;
}

.dropdown-toggle:hover {
  background: var(--color-bg-tertiary);
  border-color: var(--color-border-focus);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.dropdown-menu {
  position: fixed;
  margin-top: 4px;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  box-shadow: var(--shadow-lg);
  z-index: var(--z-dropdown-menu); /* ✅ 组件层 - 下拉菜单 */
  min-width: 140px;
  padding: 4px;
}

.dropdown-item {
  width: 100%;
  padding: 8px 12px;
  background: transparent;
  border: none;
  border-radius: 4px;
  font-size: 12px;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 8px;
}

.dropdown-item:hover:not(:disabled) {
  background: var(--color-bg-tertiary);
  color: var(--color-text-primary);
}

.dropdown-item:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.dropdown-item.delete-item {
  color: #dc3545;
}

.dropdown-item.delete-item:hover:not(:disabled) {
  background: #fff5f5;
  color: #c82333;
}

/* 对话框 */
.preset-save-dialog,
.preset-edit-dialog,
.preset-import-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--color-bg-elevated);
  padding: 16px;
  border-radius: 6px;
  box-shadow: var(--shadow-lg);
  z-index: var(--z-modal-content); /* ✅ 弹窗层 - 对话框内容 */
  min-width: 280px;
}

.preset-save-dialog input,
.preset-edit-dialog input {
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 12px;
  background: var(--color-bg-tertiary);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 13px;
  transition: all 0.2s ease;
}

.preset-save-dialog input:focus,
.preset-edit-dialog input:focus {
  outline: none;
  border-color: #4a6cf7;
  box-shadow: 0 0 0 2px rgba(74, 108, 247, 0.1);
}

.preset-import-dialog textarea {
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 12px;
  background: var(--color-bg-tertiary);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 12px;
  font-family: inherit;
  resize: vertical;
  min-height: 100px;
}

.preset-import-dialog textarea:focus {
  outline: none;
  border-color: #4a6cf7;
  box-shadow: 0 0 0 2px rgba(74, 108, 247, 0.1);
}

.dialog-buttons {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.dialog-buttons button {
  padding: 6px 12px;
  border: none;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.dialog-buttons button:first-child {
  background: var(--color-accent);
  color: white;
}

.dialog-buttons button:first-child:hover {
  background: var(--color-accent-hover);
}

.dialog-buttons button:last-child {
  background: var(--color-bg-secondary);
  color: var(--color-text-secondary);
}

.dialog-buttons button:last-child:hover {
  background: var(--color-bg-tertiary);
}

/* 组件编辑对话框 */
.component-edit-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--color-bg-elevated);
  border-radius: 8px;
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(0, 0, 0, 0.1);
  z-index: var(--z-modal-content); /* ✅ 弹窗层 - 确保在最高层 */
  min-width: 900px;
  max-width: calc(100vw - 60px); /* 左右各留30px边距 */
  max-height: calc(100vh - 100px); /* 上下留出空间，避免遮挡顶部栏 */
  display: flex;
  flex-direction: column;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
}

.dialog-header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: #2c3e50;
}

.dialog-header .close-btn {
  background: none;
  border: none;
  font-size: 20px;
  color: #adb5bd;
  cursor: pointer;
  padding: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease;
}

.dialog-header .close-btn:hover {
  color: #495057;
}

.dialog-content {
  padding: 24px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ✅ 角色选择器 */
.component-role-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: 6px;
}

.role-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.role-select {
  flex: 1;
  padding: 6px 10px;
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 12px;
  color: var(--color-text-primary);
  cursor: pointer;
  transition: all 0.2s ease;
}

.role-select:hover {
  border-color: var(--color-accent-light);
}

.role-select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px var(--color-accent-light);
}

.component-textarea {
  width: 100%;
  padding: 14px;
  background: var(--color-bg-tertiary);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.7;
  resize: vertical;
  min-height: 500px;
  transition: all 0.2s ease;
}

.component-textarea:focus {
  outline: none;
  border-color: #4a6cf7;
  box-shadow: 0 0 0 2px rgba(74, 108, 247, 0.1);
}

.component-textarea[readonly] {
  background: #f1f3f5;
  cursor: default;
}

.dialog-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-top: 1px solid var(--color-border);
}

.token-count {
  font-size: 11px;
  color: #6c757d;
  font-weight: 500;
}

/* 参数设置区域 - 紧凑布局 */
.preset-parameters-container {
  background: var(--color-bg-elevated);
  border-radius: 4px;
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}

.parameters-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: var(--color-bg-tertiary);
  cursor: pointer;
  transition: background 0.2s ease;
  gap: 8px; /* 标题和参数之间的间距 */
}

.parameters-header:hover {
  background: #f1f3f5;
}

.parameters-header span:first-child {
  font-size: 12px;
  font-weight: 600;
  color: #2c3e50;
  flex-shrink: 0; /* 不压缩标题 */
}

/* 标题栏中的参数 */
.header-parameter {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1; /* 占据中间空间 */
  justify-content: center; /* 居中显示 */
}

.header-param-label {
  font-size: 11px;
  font-weight: 500;
  color: #495057;
  cursor: help;
  white-space: nowrap;
}

.header-param-input {
  width: 45px;
  padding: 3px 4px;
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  font-size: 11px;
  text-align: center;
  transition: all 0.2s ease;
}

.header-param-input:focus {
  outline: none;
  border-color: #4a6cf7;
  box-shadow: 0 0 0 2px rgba(74, 108, 247, 0.1);
}

.expand-icon {
  font-size: 10px;
  color: #6c757d;
  transition: transform 0.3s ease;
}

.expand-icon.expanded {
  transform: rotate(180deg);
}

.preset-parameters {
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); /* 减小最小宽度，让窄屏也能显示多列 */
  gap: 6px;
}

.parameter-row-compact {
  display: flex;
  flex-direction: row; /* 改为横向布局 */
  align-items: center; /* 垂直居中 */
  justify-content: space-between; /* 两端对齐 */
  gap: 4px; /* 参数名和输入框之间的间距 */
  min-width: 0; /* 允许收缩 */
  padding: 2px 4px; /* 内边距 */
  background: var(--color-bg-tertiary); /* 添加背景色，形成容器感 */
  border: 1px solid var(--color-border); /* 添加边框 */
  border-radius: 4px; /* 圆角 */
}

.parameter-label-compact {
  font-size: 11px;
  font-weight: 500;
  color: #495057;
  cursor: help;
  white-space: nowrap; /* 防止参数名换行 */
  overflow: hidden; /* 超出隐藏 */
  text-overflow: ellipsis; /* 省略号 */
  flex: 1; /* 占据剩余空间 */
  min-width: 0; /* 允许收缩 */
}

.parameter-input-compact {
  width: 45px; /* 固定小宽度 */
  padding: 3px 4px; /* 减小padding */
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  font-size: 11px;
  text-align: center;
  transition: all 0.2s ease;
  flex-shrink: 0; /* 不压缩输入框 */
}

.parameter-input-compact:focus {
  outline: none;
  border-color: #4a6cf7;
  box-shadow: 0 0 0 2px rgba(74, 108, 247, 0.1);
}

/* 预设组件区域 - 减少padding */
.preset-components-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--color-bg-elevated);
  border-radius: 4px;
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}

.components-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: var(--color-bg-tertiary);
  border-bottom: 1px solid var(--color-border);
}

.components-header h3 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  color: #2c3e50;
}

.add-component-btn {
  padding: 3px 8px;
  background: #4a6cf7;
  color: white;
  border: none;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.add-component-btn:hover {
  background: #3a5ce5;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(74, 108, 247, 0.2);
}

.components-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px;
}

.drag-indicator {
  height: 3px;
  background: #4a6cf7;
  border-radius: 2px;
  opacity: 0;
  transition: opacity 0.2s ease;
  margin: 3px 0;
}

.drag-indicator.visible {
  opacity: 0.5;
}

.prompt-component-item {
  display: flex;
  align-items: center;
  padding: 6px 8px;
  margin-bottom: 4px;
  background: var(--color-bg-tertiary);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  transition: all 0.2s ease;
  cursor: grab;
}

.prompt-component-item:hover {
  background: var(--color-bg-elevated);
  border-color: var(--color-border-focus);
  box-shadow: var(--shadow-sm);
}

.prompt-component-item.disabled {
  opacity: 0.6;
}

.prompt-component-item.marker {
  background: rgba(74, 108, 247, 0.05);
  border-color: rgba(74, 108, 247, 0.2);
}

.prompt-component-item.dragging {
  opacity: 0.5;
  cursor: grabbing;
}

.component-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.component-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.drag-handle {
  color: #adb5bd;
  cursor: grab;
  font-size: 11px;
  user-select: none;
  transition: color 0.2s ease;
}

.drag-handle:hover {
  color: #6c757d;
}

.toggle-btn {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  cursor: pointer;
  font-size: 9px;
  transition: all 0.2s ease;
}

.toggle-btn:hover {
  border-color: var(--color-border-focus);
  background: var(--color-bg-tertiary);
}

.toggle-btn.enabled {
  background: #4a6cf7;
  color: white;
  border-color: #4a6cf7;
}

.toggle-btn.enabled:hover {
  background: #3a5ce5;
}

.component-name {
  font-size: 11px;
  font-weight: 500;
  color: #2c3e50;
  flex: 1;
}

.component-marker-badge {
  padding: 1px 6px;
  background: rgba(74, 108, 247, 0.1);
  color: #4a6cf7;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
}

.component-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.edit-btn {
  padding: 3px 6px;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  font-size: 10px;
  font-weight: 500;
  color: #495057;
  cursor: pointer;
  transition: all 0.2s ease;
}

.edit-btn:hover {
  background: var(--color-bg-tertiary);
  border-color: var(--color-border-focus);
}

.delete-btn {
  padding: 3px 6px;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  font-size: 10px;
  font-weight: 500;
  color: #dc3545;
  cursor: pointer;
  transition: all 0.2s ease;
}

.delete-btn:hover {
  background: #fff5f5;
  border-color: #ff6b6b;
}

/* 分页控件 */
.pagination-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 10px 6px;
  margin-top: 8px;
  border-top: 1px solid var(--color-border-light);
}

.pagination-btn {
  padding: 5px 12px;
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  color: var(--color-text-secondary);
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s ease;
  font-weight: 500;
}

.pagination-btn:hover:not(:disabled) {
  background: var(--color-bg-elevated);
  border-color: var(--color-border-focus);
  color: var(--color-text-primary);
}

.pagination-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.pagination-info {
  font-size: 12px;
  color: var(--color-text-secondary);
  font-weight: 500;
  min-width: 80px;
  text-align: center;
}

/* ✅ 页码跳转容器 */
.page-jump-container {
  display: flex;
  gap: 4px;
  align-items: center;
}

.page-jump-input {
  width: 50px;
  padding: 4px 6px;
  font-size: 12px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: var(--color-bg-primary);
  color: var(--color-text-primary);
  text-align: center;
  outline: none;
  transition: all 0.15s ease;
}

.page-jump-input:hover {
  border-color: var(--color-border-focus);
}

.page-jump-input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px var(--color-accent-light);
}

.btn-jump {
  padding: 5px 8px;
  font-size: 12px;
  min-width: 40px;
}

.page-size-selector {
  padding: 4px 8px;
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  color: var(--color-text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.page-size-selector:hover {
  border-color: var(--color-border-focus);
}

.page-size-selector:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px var(--color-accent-light);
}

/* 滚动条样式 */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--color-bg-tertiary);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb {
  background: var(--color-scrollbar);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-scrollbar-hover);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .preset-panel {
    padding: 10px;
    gap: 10px;
  }

  .preset-header {
    flex-direction: column;
    align-items: stretch;
  }

  .preset-select-container {
    flex-direction: column;
    align-items: stretch;
  }

  .preset-actions {
    justify-content: center;
  }

  .component-edit-dialog {
    min-width: 85vw;
  }
}
