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

.modal-content {
  background: white;
  border-radius: 10px;
  padding: 0;
  width: 90%;
  max-width: 640px;
  max-height: 90vh;
  overflow: hidden; /* 由 body 滚动，标题栏固定 */
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.2);
  position: relative;
  z-index: 1001;
  display: flex; /* 纵向布局，便于底栏固定 */
  flex-direction: column;
}

/* 模拟窗口标题栏 */
.modal-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 3rem; /* 与主窗口标题栏一致 */
  padding: 0 12px; /* 接近主头部的水平留白 */
  background: #3498db; /* 与 .app-header 相同 */
  color: #fff;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
}

/* 左侧占位以保证标题居中（与右侧关闭按钮宽度相当） */
.modal-spacer {
  width: 32px;
  flex: 0 0 32px;
}

.modal-title {
  flex: 1;
  text-align: center;
  color: #fff;
  font-weight: 600;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 20px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 6px;
  cursor: pointer;
}

.modal-close-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

.modal-form {
  /* 表单外层包裹 body + footer */
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0; /* 允许子元素正确计算高度 */
}

.modal-body {
  padding: 1.25rem 1.5rem 1.5rem;
  overflow: auto; /* 仅内容区滚动 */
  flex: 1 1 auto;
  min-height: 0;
}

.error-message {
  background: #fee;
  color: #c33;
  padding: 0.75rem;
  border-radius: 4px;
  margin-bottom: 1rem;
  border: 1px solid #fcc;
  font-size: 0.9rem;
}

.presets {
  margin-bottom: 1.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid #ecf0f1;
}

.presets label {
  display: block;
  margin-bottom: 0.5rem;
  color: #555;
  font-size: 0.9rem;
}

.preset-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.preset-btn {
  padding: 0.375rem 0.75rem;
  border: 1px solid #3498db;
  background: white;
  color: #3498db;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.preset-btn:hover,
.preset-btn.selected {
  background: #3498db;
  color: white;
}

/* 官方按钮橙色主题（Anthropic 风格） */
.preset-btn.official {
  border: 1px solid #d97706;
  color: #d97706;
}

.preset-btn.official:hover,
.preset-btn.official.selected {
  background: #d97706;
  color: white;
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  color: #555;
  font-weight: 500;
}

/* API Key 输入框容器 - 预留空间避免抖动 */
.form-group.api-key-group {
  min-height: 88px; /* 固定高度：label + input + 间距 */
  transition: opacity 0.2s ease;
}

.form-group.api-key-group.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 0.625rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 0.95rem;
  transition: border-color 0.2s;
  background: white;
  box-sizing: border-box;
}

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

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: #3498db;
}

.modal-footer {
  /* 固定在弹窗底部（非滚动区） */
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
  padding: 0.75rem 1.5rem;
  border-top: 1px solid #ecf0f1;
  background: #fff;
}

.cancel-btn,
.submit-btn {
  padding: 0.625rem 1.25rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all 0.2s;
}

.cancel-btn {
  background: #ecf0f1;
  color: #555;
}

.cancel-btn:hover {
  background: #bdc3c7;
}

.submit-btn {
  background: #27ae60;
  color: white;
}

.submit-btn:hover {
  background: #229954;
}

.field-hint {
  display: block;
  margin-top: 0.25rem;
  color: #7f8c8d;
  font-size: 0.8rem;
  line-height: 1.3;
}

/* 添加标签和选择框的样式 */
.label-with-checkbox {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.5rem;
}

.label-with-checkbox label:first-child {
  margin-bottom: 0;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: #666;
  font-weight: normal;
  margin-bottom: 0;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: auto;
  margin: 2px;
  cursor: pointer;
  transform: translateY(2px);
}
