
/* ============================================
   VS Code 风格组件系统
   ============================================ */

/* 按钮基础样式 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  height: 32px;
}

.btn i {
  font-size: 14px;
}

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

/* 主按钮 - VS Code 蓝 */
.btn-primary {
  background: var(--brand-primary);
  color: var(--text-white);
  border: 1px solid var(--brand-primary);
}

.btn-primary:hover {
  background: var(--brand-primary-hover);
  border-color: var(--brand-primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 122, 204, 0.3);
}

.btn-primary:active {
  background: var(--brand-primary-active);
  border-color: var(--brand-primary-active);
  transform: translateY(0);
}

/* 辅助按钮 */
.btn-secondary {
  background: var(--bg-hover);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-active);
  border-color: var(--brand-primary);
  transform: translateY(-1px);
}

.btn-secondary:active {
  transform: translateY(0);
}

/* 图标按钮 */
.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-md);
}

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

.reset-btn {
  color: var(--color-warning);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px !important;
  height: auto !important;
}

.reset-btn:hover {
  background: rgba(245, 158, 11, 0.1) !important;
  color: var(--color-warning) !important;
  border-color: var(--color-warning) !important;
}

/* 输入框 */
.form-input {
  width: 100%;
  padding: 6px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  line-height: 1.5;
  transition: all var(--transition-fast);
}

.form-input:focus {
  border-color: var(--border-color-focus);
  background: var(--bg-input-focus);
  outline: none;
}

.form-input::placeholder {
  color: var(--text-muted);
}

.form-textarea {
  min-height: 80px;
  resize: vertical;
  font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
  line-height: 1.6;
}

/* 表单组 */
.form-group {
  margin-bottom: 12px;
}

.form-group:last-child {
  margin-bottom: 0;
}

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

/* 标签 */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: var(--brand-primary-bg);
  border: 1px solid rgba(0, 122, 204, 0.3);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 12px;
  transition: all var(--transition-fast);
}

.tag:hover {
  background: rgba(0, 122, 204, 0.25);
  border-color: rgba(0, 122, 204, 0.5);
}

.tag-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.tag-remove:hover {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

/* 目录树项 */
.tree-item {
  user-select: none;
}

.tree-item-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 13px;
  transition: background var(--transition-fast);
  user-select: none;
}

.tree-item-header:hover {
  background: var(--bg-hover);
}

.tree-item-header.selected {
  background: var(--brand-primary-bg);
  color: var(--brand-primary);
  border-left: 2px solid var(--brand-primary);
  padding-left: 6px;
}

.tree-item-icon {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
}

.tree-item-toggle {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-muted);
  font-size: 10px;
  transition: transform 0.15s ease;
}

.tree-item-toggle.expanded {
  transform: rotate(90deg);
}

.tree-item-toggle-placeholder {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.tree-item-icon.folder {
  display: flex;
  align-items: center;
  justify-content: center;
}

.tree-item-icon.folder svg {
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
}

.tree-item-icon.file {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.tree-item-icon.file svg {
  transition: all var(--transition-fast);
}

.tree-item:hover .tree-item-icon.file svg {
  color: var(--brand-primary);
}

.tree-item-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-children {
  padding-left: 16px;
}

.tree-item-children {
  padding-left: 16px;
  overflow: hidden;
  max-height: 2000px;
  transition: max-height 0.2s ease, opacity 0.2s ease;
  opacity: 1;
}

.tree-item-children.collapsed {
  max-height: 0;
  opacity: 0;
}

.tree-item-doc-file .tree-item-name {
  color: var(--text-primary);
}

.tree-item-doc-file .tree-item-icon {
  color: var(--brand-primary);
}

/* 目录树控制按钮 */
.tree-controls {
  display: flex;
  gap: 4px;
  padding: 8px;
  border-bottom: 1px solid var(--border-color);
}

.btn-sm {
  height: 26px;
  padding: 4px 8px;
  font-size: 12px;
}

/* 模态框 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.15s ease;
}

.modal {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.2s ease;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  background: var(--bg-panel);
}

.modal-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.modal-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

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

.modal-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: var(--bg-base);
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  background: var(--bg-panel);
}

/* 设置面板 */
.settings-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border-color);
  margin: -20px -20px 20px -20px;
  padding: 0 20px;
  background: var(--bg-panel);
}

.settings-tab {
  padding: 10px 16px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.settings-tab:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.settings-tab.active {
  color: var(--brand-primary);
  border-bottom-color: var(--brand-primary);
  background: transparent;
}

.settings-panel {
  display: none;
}

.settings-panel.active {
  display: block;
  animation: fadeIn 0.2s ease;
}

/* 规则项 */
.rule-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-color-light);
}

.rule-item:last-child {
  border-bottom: none;
}

.rule-checkbox {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--brand-primary);
}

.rule-label {
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
}

/* 提示词面板 */
.hints-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  width: 280px;
  max-height: 300px;
  overflow-y: auto;
  overflow-x: hidden;
  position: absolute;
  z-index: 1000;
  animation: slideUp 0.15s ease;
}

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

.hints-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}

.hints-close {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

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

.hints-content {
  padding: 4px 0;
}

.hint-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  transition: background var(--transition-fast);
}

.hint-item:hover {
  background: var(--bg-hover);
}

.hint-text {
  flex: 1;
  font-size: 12px;
  color: var(--text-primary);
  margin-right: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hint-insert {
  padding: 2px 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 11px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.hint-insert:hover {
  background: var(--brand-primary);
  color: var(--text-white);
  border-color: var(--brand-primary);
}

/* 提示词设置 */
.hint-group {
  margin-bottom: 12px;
  padding: 10px;
  background: var(--bg-hover);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

.hint-group:hover {
  border-color: var(--brand-primary);
  background: var(--bg-active);
}

.hint-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.hint-field-name {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 13px;
}

.hint-values {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.btn-danger {
  background: var(--color-danger);
  color: var(--text-white);
  border-color: var(--color-danger);
  padding: 4px 8px;
  font-size: 12px;
}

.btn-danger:hover {
  background: #E53935;
  border-color: #E53935;
}

/* 占位符样式 - 极简紧凑设计 */
.placeholder {
  display: inline;
  padding: 0 2px;
  background: rgba(0, 122, 204, 0.08);
  border: 1px solid rgba(0, 122, 204, 0.15);
  border-radius: 2px;
  color: var(--brand-primary);
  font-size: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  line-height: inherit;
  box-sizing: border-box;
  vertical-align: baseline;
}

.placeholder:hover {
  background: rgba(0, 122, 204, 0.18);
  border-color: rgba(0, 122, 204, 0.35);
  transform: translateY(-1px);
  box-shadow: 0 1px 3px rgba(0, 122, 204, 0.15);
}

/* 暗色模式下的占位符 */
body.dark-theme .placeholder {
  background: rgba(0, 122, 204, 0.18) !important;
  color: var(--brand-primary) !important;
  border-color: rgba(0, 122, 204, 0.35);
}

body.dark-theme .placeholder:hover {
  background: rgba(0, 122, 204, 0.28) !important;
  border-color: rgba(0, 122, 204, 0.55);
}

/* 已填充字段的样式 */
.field-filled {
  display: inline;
  padding: 0;
  border-bottom: 1px solid;
  font-weight: 500;
  line-height: inherit;
  vertical-align: baseline;
}

/* 正在编辑的占位符高亮样式 - 脉冲动画（使用 CSS 变量）*/
.placeholder.field-highlight,
.field-filled.field-highlight {
  background: color-mix(in srgb, var(--pulse-color, #48C774) 30%, transparent) !important;
  border-color: var(--pulse-color, #48C774) !important;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--pulse-color, #48C774) 30%, transparent),
              0 0 10px color-mix(in srgb, var(--pulse-color, #48C774) 50%, transparent);
  animation: pulse-highlight 1.5s ease-in-out infinite;
}

@keyframes pulse-highlight {
  0%, 100% {
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--pulse-color, #48C774) 30%, transparent),
                0 0 10px color-mix(in srgb, var(--pulse-color, #48C774) 50%, transparent);
  }
  50% {
    box-shadow: 0 0 0 6px color-mix(in srgb, var(--pulse-color, #48C774) 40%, transparent),
                0 0 15px color-mix(in srgb, var(--pulse-color, #48C774) 70%, transparent);
  }
}

/* 加载动画 */
.loading {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border-color);
  border-top-color: var(--brand-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* 空状态优化 */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 32px;
  text-align: center;
  color: var(--text-secondary);
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.2;
  filter: grayscale(50%);
}

.empty-state-text {
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 8px;
}

.empty-state-subtext {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* 文件图标颜色 */
.tree-item-docx .tree-item-icon {
  color: #4FC1FF;
}

.tree-item-doc .tree-item-icon {
  color: #6A6A6A;
}

.tree-item-folder .tree-item-icon {
  color: #D7BA7D;
}

/* ✅ 联动替换功能样式 */
.link-mode-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 16px;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}

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

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 26px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked + .slider {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2), 0 0 8px rgba(102, 126, 234, 0.4);
}

.toggle-switch input:checked + .slider:before {
  transform: translateX(22px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

.link-mode-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.link-mode-info .title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.link-mode-info .desc {
  font-size: 11px;
  color: var(--text-muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  background: var(--accent-blue-light);
  color: var(--accent-blue);
  font-size: 10px;
  border-radius: 10px;
  margin-left: 6px;
  font-weight: 600;
}

/* ✅ 表单标签行布局 - 解决徽章遮挡问题 */
.form-label-row {
  display: flex;
  align-items: flex-start; /* 顶部对齐，允许多行标签 */
  gap: 8px; /* 标签文字与徽章的间距 */
  margin-bottom: 6px; /* 标签行与输入框的间距（减小至6px） */
  flex-wrap: wrap; /* 允许换行显示长文本 */
  min-width: 0; /* 允许 flex 子项缩小 */
}

.form-label-row label {
  flex: 1; /* 占据可用空间 */
  min-width: 0; /* 允许缩小 */
  margin-bottom: 0;
  white-space: normal; /* 允许换行显示完整文字 */
  overflow: visible; /* 显示完整内容 */
  text-overflow: clip; /* 不使用省略号截断 */
  word-wrap: break-word; /* 长单词自动换行 */
  word-break: break-all; /* 允许在任意字符间换行（修正） */
  line-height: 1.5; /* 多行文字的间距 */
}

/* ✅ 表单已修改状态高亮 - VS Code 风格左侧指示条 */
.form-group-modified {
  position: relative;
  padding-left: 12px; /* 为左侧指示条留出空间 */
}

.form-group-modified::before {
  content: '';
  position: absolute;
  left: 0;
  top: 26px; /* 标签行高度（~20px） + margin-bottom（6px） = 26px，精确对齐输入框顶部 */
  height: 32px; /* 与 input 输入框高度一致 */
  width: 3px; /* 细长指示条 */
  background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
  border-radius: 2px;
  box-shadow: 0 0 6px rgba(102, 126, 234, 0.3); /* 柔和发光效果 */
  transition: all 0.3s ease;
}

.form-group-modified:hover::before {
  width: 4px; /* 悬停时稍微加粗 */
  box-shadow: 0 0 10px rgba(102, 126, 234, 0.5); /* 增强发光 */
}

/* 针对 textarea 的指示条高度调整 */
.form-group-modified:has(.form-textarea)::before {
  height: 80px; /* 匹配 textarea 的最小高度 */
}

.form-group-modified .form-input,
.form-group-modified .form-textarea {
  background: rgba(102, 126, 234, 0.06); /* 淡紫色背景 */
  border-color: rgba(102, 126, 234, 0.4); /* 紫色边框 */
  border-width: 1px;
  transition: all 0.3s ease;
  font-weight: 500; /* 已填写内容字重加粗 */
  color: var(--text-primary); /* 确保文本颜色为深色 */
}

.form-group-modified .form-input:focus,
.form-group-modified .form-textarea:focus {
  background: rgba(102, 126, 234, 0.1); /* 聚焦时背景加深 */
  border-color: #667eea;
  border-width: 1.5px;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1), 0 0 8px rgba(102, 126, 234, 0.2);
}

/* ✅ 已修改的输入框标识 */
.input-modified {
  background: rgba(102, 126, 234, 0.06);
  font-weight: 500;
  color: var(--text-primary);
}

/* ✅ 未填写状态的占位符样式优化 */
.form-input:not(.input-modified)::placeholder {
  color: var(--text-muted); /* 灰色占位符 */
  font-style: italic; /* 斜体区分 */
  opacity: 0.7;
}

/* ✅ 联动模式计数徽章 - 紫色渐变 */
.link-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 18px;
  padding: 0 5px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  font-size: 10px;
  font-weight: 600;
  border-radius: 9px;
  margin-left: 8px; /* 增加与标签文字的间距 */
  vertical-align: middle;
  box-shadow: 0 1px 3px rgba(102, 126, 234, 0.3);
  transition: all 0.2s ease;
  flex-shrink: 0; /* 防止徽章被压缩 */
}

.link-count-badge:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 5px rgba(102, 126, 234, 0.4);
}
