/* ==================== 正则面板 - 完整重写 ==================== */

/* 主容器 */
.regex-panel {
  padding: 16px;
  height: 100%;
  overflow-y: auto;
  background: var(--color-bg-primary);
  color: var(--color-text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* 头部 */
.regex-panel-header {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--color-border);
}

.regex-panel-header h2 {
  margin: 0 0 8px 0;
  font-size: 22px;
  font-weight: 600;
  color: var(--color-text-primary);
}

.subtitle {
  margin: 0;
  font-size: 13px;
  color: var(--color-text-muted);
}

/* ==================== 左右布局 ==================== */

.regex-layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  height: calc(100% - 80px);
}

.regex-left {
  overflow-y: auto;
  padding-right: 12px;
}

.regex-right {
  overflow-y: auto;
}

/* ==================== 可折叠区域 ==================== */

.regex-section {
  margin-bottom: 16px;
  background: var(--color-bg-secondary);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--color-border);
}

.regex-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--color-bg-tertiary);
  cursor: pointer;
  user-select: none;
  transition: background 0.2s;
}

.regex-section-header:hover {
  background: var(--color-bg-hover);
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.collapse-icon {
  font-size: 12px;
  color: var(--color-text-muted);
  transition: transform 0.2s;
}

.section-icon {
  font-size: 16px;
}

.section-title h4 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text-primary);
}

.rule-count {
  font-size: 12px;
  color: var(--color-text-muted);
}

.btn-add-rule-small {
  padding: 4px 12px;
  background: var(--color-accent);
  border: none;
  border-radius: 4px;
  color: white;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-add-rule-small:hover {
  background: var(--color-accent-hover);
}

.regex-section-content {
  padding: 12px;
  background: var(--color-bg-primary);
}

.empty-rules {
  text-align: center;
  padding: 20px;
  color: var(--color-text-muted);
  font-size: 13px;
}

/* ==================== 规则列表 ==================== */

.rules-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rule-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--color-bg-tertiary);
  border-radius: 6px;
  transition: all 0.2s;
  border: 1px solid transparent;
}

.rule-item:hover {
  background: var(--color-bg-hover);
  border-color: var(--color-border);
}

.rule-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.rule-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rule-badges {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.rule-badge {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  white-space: nowrap;
}

.rule-badge.disabled {
  background: var(--color-error);
  color: white;
}

.rule-badge.prompt {
  background: var(--color-info);
  color: white;
}

.rule-badge.markdown {
  /* 注意：Markdown 徽章使用固定紫色，作为功能标识色 */
  background: #8844ff;
  color: white;
}

.rule-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.icon-btn {
  padding: 4px 6px;
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: 4px;
  font-size: 14px;
  transition: all 0.2s;
}

.icon-btn:hover {
  background: var(--color-bg-elevated);
  color: var(--color-text-primary);
}

/* 开关按钮 */
.toggle-switch {
  position: relative;
  width: 40px;
  height: 22px;
  display: inline-block;
  cursor: pointer;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--color-border);
  transition: 0.3s;
  border-radius: 22px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
  background-color: var(--color-accent);
}

.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(18px);
}

/* ==================== 右侧信息卡片 ==================== */

.regex-info-card {
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 16px;
}

.regex-info-card h4 {
  margin: 0 0 12px 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text-primary);
}

.regex-info-card ul {
  margin: 0;
  padding-left: 20px;
  list-style: none;
}

.regex-info-card li {
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--color-text-secondary);
  line-height: 1.5;
}

.regex-info-card li strong {
  color: var(--color-text-primary);
}

.quick-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-quick {
  padding: 10px 16px;
  background: var(--color-accent);
  border: none;
  border-radius: 6px;
  color: white;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-quick:hover {
  background: var(--color-accent-hover);
}

/* ==================== 编辑器弹窗 ==================== */

.regex-editor-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.regex-editor-modal {
  width: 90%;
  max-width: 800px;
  max-height: 90vh;
  background: var(--color-bg-primary);
  border-radius: 12px;
  border: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.regex-editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: var(--color-bg-secondary);
  border-bottom: 1px solid var(--color-border);
}

.regex-editor-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--color-text-primary);
}

.close-btn {
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s;
}

.close-btn:hover {
  background: var(--color-bg-tertiary);
  color: var(--color-text-primary);
}

.regex-editor-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-secondary);
}

.form-group small {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  color: var(--color-text-muted);
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 8px 12px;
  background: var(--color-bg-tertiary);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  color: var(--color-text-primary);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--color-accent);
}

.form-group textarea {
  resize: vertical;
  min-height: 60px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

/* 紧凑选项布局 */
.form-row.compact-options {
  gap: 12px;
  margin-bottom: 12px;
}

.form-section h4 {
  margin: 0 0 8px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text-primary);
}

.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* 紧凑的 checkbox 组 - 使用网格布局 */
.checkbox-group.compact {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px 12px;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--color-text-secondary);
  padding: 4px 0;
}

.checkbox-group.compact .checkbox-item {
  padding: 2px 0;
  font-size: 12px;
}

.checkbox-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.form-group.small {
  margin-bottom: 0;
}

.regex-editor-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 20px;
  background: var(--color-bg-secondary);
  border-top: 1px solid var(--color-border);
}

.btn-cancel,
.btn-save {
  padding: 8px 20px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-cancel {
  background: var(--color-bg-tertiary);
  color: var(--color-text-primary);
}

.btn-cancel:hover {
  background: var(--color-bg-hover);
}

.btn-save {
  background: var(--color-accent);
  color: white;
}

.btn-save:hover {
  background: var(--color-accent-hover);
}

.btn-save:disabled {
  background: var(--color-border);
  cursor: not-allowed;
}

/* ==================== 响应式 ==================== */

@media (max-width: 1200px) {
  .regex-layout {
    grid-template-columns: 1fr;
  }
  
  .regex-right {
    display: none;
  }
}
