// 全局变量定义
$primary-color: #165DFF;
$secondary-color: #6B7280;
$success-color: #00B42A;
$warning-color: #FFAA00;
$error-color: #F53F3F;
$text-primary: #333333;
$text-secondary: #666666;
$text-tertiary: #999999;
$border-color: #E5E7EB;
$bg-light: #F9FAFB;
$bg-white: #FFFFFF;
$shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
$shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
$shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

// 对话框容器
.api-dialog {
  min-width: 700px;
  max-width: 900px;
  max-height: 90vh;
  border-radius: 12px;
  overflow: hidden;
  background-color: $bg-white;
  display: flex;
  flex-direction: column;
}

// 对话框头部
.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid $border-color;
  background-color: $bg-light;
  flex-shrink: 0;

  .dialog-title {
    font-size: 18px;
    font-weight: 600;
    color: $text-primary;
    margin: 0;
  }

  .close-btn {
    color: $text-tertiary;
    padding: 4px;
    border-radius: 6px;
    transition: all 0.2s ease;

    &:hover {
      background-color: #E5E7EB;
      color: $text-secondary;
    }
  }
}

// 对话框内容
.dialog-content {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

// 表单区域
.form-section {
  margin-bottom: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid $border-color;

  &:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
  }

  .section-title {
    font-size: 16px;
    font-weight: 600;
    color: $text-primary;
    margin-bottom: 16px;
  }

  .config-description,
  .empty-config {
    background-color: #F0F9FF;
    border: 1px solid #D1E9FF;
    border-radius: 6px;
    padding: 12px 16px;
    margin-bottom: 16px;

    p {
      font-size: 13px;
      color: $text-secondary;
      margin: 0;
      line-height: 1.4;
    }
  }

  .empty-config {
    text-align: center;
    color: $text-tertiary;
    background-color: $bg-light;
    border-color: $border-color;
  }
}

// 表单组
.form-group {
  margin-bottom: 16px;

  .form-field {
    width: 100%;
    .mat-form-field-wrapper {
      .mat-form-field-flex {
        border-radius: 8px;
      }

      .mat-form-field-outline {
        border-radius: 8px;
      }

      .mat-form-field-infix {
        padding: 10px 0;

        input,
        textarea {
          font-size: 14px;
          color: $text-primary;
        }

        .mat-input-element {
          &::placeholder {
            color: $text-tertiary;
          }
        }

        textarea {
          resize: vertical;
          min-height: 80px;
        }
      }

      .mat-form-field-label {
        font-size: 14px;
        color: $text-secondary;
      }

      .mat-form-field-suffix {
        .mat-icon {
          color: $text-tertiary;
        }
      }

      .mat-form-field-error {
        font-size: 12px;
        color: $error-color;
      }
    }
  }

  // 激活状态切换
  .toggle-wrapper {
    .active-toggle {
      display: flex;
      justify-content: flex-start;
      .mat-slide-toggle-content {
        font-size: 14px;
        color: $text-secondary;
      }
    }
  }
}

// 配置字段区域
.config-fields {
  margin-bottom: 24px;
}

.config-field-item {
  background-color: $bg-light;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  border: 1px solid $border-color;

  .config-field-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;

    .field-index {
      font-size: 12px;
      font-weight: 500;
      color: $text-secondary;
      background-color: $bg-white;
      padding: 4px 12px;
      border-radius: 12px;
    }

    .remove-btn {
      color: $error-color;
      padding: 4px;
    }
  }

  .config-field-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;

    .key-field,
    .value-field {
      .mat-form-field-wrapper {
        .mat-form-field-flex {
          border-radius: 6px;
        }
        .mat-form-field-outline {
          border-radius: 6px;
        }
        .mat-form-field-infix {
          .mat-input-element {
            font-size: 13px;
          }
        }
        .mat-form-field-label {
          font-size: 13px;
        }
        .mat-form-field-error {
          font-size: 11px;
          color: $error-color;
        }
      }
    }

    .value-field {
      .mat-form-field-wrapper {
        .mat-form-field-infix {
          textarea {
            resize: vertical;
            min-height: 60px;
          }
        }
      }
    }
  }
}

// 添加配置字段
.add-config-field {
  background-color: #F0F9FF;
  border: 2px dashed $primary-color;
  border-radius: 8px;
  padding: 16px;

  .add-field-content {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 12px;
    align-items: end;

    .key-field,
    .value-field {
      .mat-form-field-wrapper {
        .mat-form-field-flex {
          border-radius: 6px;
        }
        .mat-form-field-outline {
          border-radius: 6px;
        }
        .mat-form-field-infix {
          .mat-input-element {
            font-size: 13px;
          }
        }
        .mat-form-field-label {
          font-size: 13px;
        }
      }
    }

    .add-btn {
      height: 40px;
      min-width: auto;
      width: 40px;
      padding: 0;
      border-radius: 6px;
      display: flex;
      align-items: center;
      justify-content: center;

      &:disabled {
        opacity: 0.5;
        cursor: not-allowed;
      }
    }
  }
}

// 配置提示
.config-tips {
  background-color: $bg-light;
  border-radius: 8px;
  padding: 16px;
  border: 1px solid $border-color;

  .tips-title {
    font-size: 13px;
    font-weight: 600;
    color: $text-secondary;
    margin-bottom: 8px;
  }

  .tips-list {
    list-style-type: none;
    padding: 0;
    margin: 0;

    li {
      font-size: 12px;
      color: $text-tertiary;
      margin-bottom: 4px;
      padding-left: 16px;
      position: relative;

      &:last-child {
        margin-bottom: 0;
      }

      &::before {
        content: "•";
        position: absolute;
        left: 0;
        color: $primary-color;
        font-weight: bold;
      }
    }
  }
}

// 元信息区域
.meta-info {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;

  .meta-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px;
    background-color: $bg-light;
    border-radius: 6px;
    border: 1px solid $border-color;

    label {
      font-size: 12px;
      color: $text-secondary;
      font-weight: 500;
    }

    .meta-value {
      font-size: 13px;
      color: $text-primary;
      font-family: 'Courier New', monospace;
    }
  }
}

// 对话框底部
.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 20px 24px;
  border-top: 1px solid $border-color;
  background-color: $bg-light;
  flex-shrink: 0;

  .cancel-btn {
    padding: 8px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: $text-secondary;
    background-color: $bg-white;
    border: 1px solid $border-color;
    transition: all 0.2s ease;

    &:hover {
      background-color: #F3F4F6;
      border-color: $text-tertiary;
    }
  }

  .save-btn {
    padding: 8px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    background-color: $primary-color;
    color: $bg-white;
    transition: all 0.2s ease;
    box-shadow: $shadow-sm;

    &:hover {
      background-color: #0E4BD8;
      box-shadow: $shadow-md;
      transform: translateY(-1px);
    }
  }
}

// 响应式设计
@media (max-width: 992px) {
  .api-dialog {
    min-width: auto;
    width: 95vw;
    max-width: 800px;
    max-height: 95vh;
  }

  .config-field-content,
  .add-field-content {
    grid-template-columns: 1fr !important;
  }

  .add-field-content {
    gap: 8px !important;
  }

  .add-btn {
    width: 100% !important;
    justify-content: center;
  }
}

@media (max-width: 768px) {
  .dialog-header,
  .dialog-content,
  .dialog-footer {
    padding: 16px;
  }

  .dialog-title {
    font-size: 16px !important;
  }

  .meta-info {
    grid-template-columns: 1fr !important;
  }
}

@media (max-width: 480px) {
  .api-dialog {
    width: 100vw;
    max-width: none;
    border-radius: 0;
    max-height: 100vh;
  }

  .cancel-btn,
  .save-btn {
    padding: 6px 16px !important;
    font-size: 13px !important;
  }
}

// 滚动条样式
.dialog-content {
  &::-webkit-scrollbar {
    width: 6px;
  }

  &::-webkit-scrollbar-track {
    background: $bg-light;
    border-radius: 3px;
  }

  &::-webkit-scrollbar-thumb {
    background: $border-color;
    border-radius: 3px;
  }

  &::-webkit-scrollbar-thumb:hover {
    background: $text-tertiary;
  }
}