// 注意：以下变量应该从共享样式文件导入，但由于导入问题暂时在此重新定义
// 未来优化目标：修复导入问题，使用共享的_variables.scss文件
$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);

// 主容器
.system-settings {
  padding: 24px;
  min-height: 100vh;
  background-color: $bg-light;
}

// 页面标题区域
.page-header {
  display: flex;
  flex-direction: column;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid $border-color;

  .page-title {
    font-size: 24px;
    font-weight: 600;
    color: $text-primary;
    margin: 0 0 4px 0;
  }

  .page-description {
    font-size: 14px;
    color: $text-tertiary;
    margin: 0;
  }
}

// 标签页导航
.tab-navigation {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  background-color: $bg-white;
  border-radius: 12px;
  padding: 4px;
  box-shadow: $shadow-sm;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: $border-color $bg-light;

  &::-webkit-scrollbar {
    height: 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;
  }

  .tab-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    background-color: transparent;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: $text-secondary;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;

    &:hover {
      background-color: $bg-light;
      color: $text-primary;
    }

    &.active {
      background-color: $primary-color;
      color: $bg-white;
    }
  }
}

// 标签页内容
.tab-content {
  animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

// 搜索区域
.search-section {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;

  .search-input-wrapper {
    flex: 1;
    min-width: 300px;
    position: relative;
    display: flex;
    align-items: center;

    .search-icon {
      position: absolute;
      left: 12px;
      color: $text-tertiary;
      z-index: 1;
    }

    .search-input {
      width: 100%;
      padding: 10px 12px 10px 40px;
      border: 1px solid $border-color;
      border-radius: 8px;
      font-size: 14px;
      color: $text-primary;
      background-color: $bg-white;
      transition: all 0.2s ease;
      box-shadow: $shadow-sm;

      &:focus {
        outline: none;
        border-color: $primary-color;
        box-shadow: 0 0 0 3px rgba(22, 93, 255, 0.1);
      }

      &::placeholder {
        color: $text-tertiary;
      }
    }

    .clear-search-btn {
      position: absolute;
      right: 8px;
      color: $text-tertiary;
      padding: 4px;
    }
  }

  .create-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background-color: $primary-color;
    color: $bg-white;
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    box-shadow: $shadow-sm;

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

// 项目状态流样式
.workflow-stages-list {
  background-color: $bg-white;
  border-radius: 12px;
  padding: 24px;
  box-shadow: $shadow-sm;

  .stage-item {
    position: relative;
    margin-bottom: 24px;

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

    &.disabled {
      opacity: 0.6;
    }

    .stage-header {
      display: flex;
      align-items: flex-start;
      gap: 16px;

      .stage-order {
        flex-shrink: 0;
        width: 32px;
        height: 32px;
        border-radius: 50%;
        background-color: $primary-color;
        color: $bg-white;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 14px;
        font-weight: 600;
        margin-top: 4px;
      }

      .stage-info {
        flex: 1;

        .stage-name {
          font-size: 16px;
          font-weight: 600;
          color: $text-primary;
          margin: 0 0 4px 0;
        }

        .stage-description {
          font-size: 14px;
          color: $text-secondary;
          margin: 0;
          line-height: 1.5;
        }
      }

      .stage-controls {
        display: flex;
        align-items: center;
        gap: 16px;
        flex-shrink: 0;

        .stage-toggle {
          .mat-slide-toggle-content {
            font-size: 14px;
          }
        }

        .action-buttons {
          display: flex;
          gap: 8px;

          .action-btn {
            width: 36px;
            height: 36px;
            border-radius: 6px;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.2s ease;
            background-color: transparent;
            border: 1px solid $border-color;
            color: $text-secondary;

            &:hover {
              border-color: currentColor;
              transform: translateY(-1px);
            }

            &.mat-primary {
              color: $primary-color;
            }

            &.mat-warn {
              color: $error-color;
            }
          }
        }
      }
    }

    .stage-divider {
      position: relative;
      height: 48px;
      margin-left: 16px;
      padding-left: 16px;
      border-left: 2px dashed $border-color;

      svg {
        position: absolute;
        top: 0;
        left: -10px;
        transform: translateY(-50%);
        background-color: $bg-white;
        padding: 4px;
        border-radius: 50%;
        border: 2px solid $bg-white;
      }
    }
  }
}

// SOP模板样式
.sop-templates-list,
.pricing-rules-list,
.performance-rules-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(600px, 1fr));
  gap: 20px;

  .template-item,
  .rule-item {
    background-color: $bg-white;
    border-radius: 12px;
    padding: 24px;
    box-shadow: $shadow-sm;
    transition: all 0.2s ease;

    &:hover {
      box-shadow: $shadow-md;
      transform: translateY(-2px);
    }

    &.disabled {
      opacity: 0.6;
    }

    .template-header,
    .rule-header {
      display: flex;
      justify-content: space-between;
      align-items: flex-start;
      margin-bottom: 16px;
      gap: 20px;

      .template-info,
      .rule-info {
        flex: 1;

        .template-title-row,
        .rule-title-row {
          display: flex;
          align-items: center;
          gap: 12px;
          margin-bottom: 8px;

          .template-name,
          .rule-name {
            font-size: 16px;
            font-weight: 600;
            color: $text-primary;
            margin: 0;
            flex: 1;
          }

          .template-category,
          .rule-category,
          .rule-metric {
            padding: 4px 12px;
            border-radius: 16px;
            font-size: 12px;
            font-weight: 500;
            color: $primary-color;
            background-color: #E6F0FF;
            white-space: nowrap;
          }
        }

        .template-description,
        .rule-description {
          font-size: 14px;
          color: $text-secondary;
          margin: 0;
          line-height: 1.5;
        }
      }

      .template-controls,
      .rule-controls {
        display: flex;
        align-items: center;
        gap: 16px;
        flex-shrink: 0;

        .template-toggle,
        .rule-toggle {
          .mat-slide-toggle-content {
            font-size: 14px;
          }
        }

        .action-buttons {
          display: flex;
          gap: 8px;

          .action-btn {
            width: 36px;
            height: 36px;
            border-radius: 6px;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.2s ease;
            background-color: transparent;
            border: 1px solid $border-color;
            color: $text-secondary;

            &:hover {
              border-color: currentColor;
              transform: translateY(-1px);
            }

            &.mat-primary {
              color: $primary-color;
            }

            &.mat-warn {
              color: $error-color;
            }
          }
        }
      }
    }

    .template-steps,
    .rule-formula,
    .rule-details {
      background-color: $bg-light;
      border-radius: 8px;
      padding: 16px;

      .steps-header,
      .formula-label,
      .detail-row {
        font-size: 13px;
        font-weight: 600;
        color: $text-secondary;
        margin-bottom: 12px;
      }

      .steps-list {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;

        .step-item {
          display: flex;
          align-items: center;
          gap: 6px;
          padding: 6px 12px;
          background-color: $bg-white;
          border-radius: 16px;
          border: 1px solid $border-color;
          font-size: 13px;
          color: $text-secondary;

          .step-number {
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background-color: $primary-color;
            color: $bg-white;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 11px;
            font-weight: 600;
            flex-shrink: 0;
          }

          .step-name {
            white-space: nowrap;
          }
        }
      }

      .formula-content {
        font-size: 14px;
        color: $text-primary;
        font-family: 'Courier New', monospace;
        background-color: $bg-white;
        padding: 8px 12px;
        border-radius: 4px;
        border: 1px solid $border-color;
      }

      .detail-row {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 8px;

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

        .detail-value {
          font-size: 14px;
          color: $text-primary;
          font-weight: 500;
        }
      }
    }
  }
}

// 系统配置样式
.system-config-section {
  background-color: $bg-white;
  border-radius: 12px;
  padding: 24px;
  box-shadow: $shadow-sm;
  margin-bottom: 24px;

  .section-title {
    font-size: 16px;
    font-weight: 600;
    color: $text-primary;
    margin: 0 0 20px 0;
    padding-bottom: 12px;
    border-bottom: 1px solid $border-color;
  }

  .config-items {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  .config-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-radius: 8px;
    background-color: $bg-light;

    .config-info {
      flex: 1;
      margin-right: 20px;

      .config-name {
        font-size: 14px;
        font-weight: 500;
        color: $text-primary;
        margin-bottom: 4px;
      }

      .config-description {
        font-size: 12px;
        color: $text-tertiary;
        line-height: 1.4;
      }
    }

    .config-toggle {
      .mat-slide-toggle-content {
        font-size: 14px;
      }
    }

    .config-select {
      min-width: 160px;
      border-radius: 6px;
    }

    .config-input {
      width: 120px;
      .mat-form-field-wrapper {
        .mat-form-field-flex {
          border-radius: 6px;
        }
        .mat-form-field-outline {
          border-radius: 6px;
        }
      }
    }
  }
}

// 系统配置操作按钮
.system-config-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  padding: 20px;
  background-color: $bg-white;
  border-radius: 12px;
  box-shadow: $shadow-sm;

  .save-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background-color: $primary-color;
    color: $bg-white;
    border-radius: 8px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    box-shadow: $shadow-sm;

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

  .reset-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    color: $text-secondary;
    background-color: transparent;
    border: 1px solid $border-color;
    border-radius: 8px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;

    &:hover {
      background-color: $bg-light;
      border-color: $text-tertiary;
      color: $text-primary;
    }
  }
}

// 无数据状态
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  text-align: center;
  background-color: $bg-white;
  border-radius: 12px;
  box-shadow: $shadow-sm;

  svg {
    margin-bottom: 16px;
    opacity: 0.5;
  }

  p {
    font-size: 16px;
    color: $text-tertiary;
    margin-bottom: 24px;
  }

  button {
    border-radius: 8px;
    padding: 8px 24px;
    font-size: 14px;
    font-weight: 500;
  }
}

// 响应式设计
@media (max-width: 1200px) {
  .sop-templates-list,
  .pricing-rules-list,
  .performance-rules-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 992px) {
  .system-settings {
    padding: 16px;
  }

  .search-section {
    flex-direction: column;
    gap: 12px;
  }

  .search-input-wrapper {
    min-width: 100% !important;
  }

  .stage-header,
  .template-header,
  .rule-header,
  .config-item {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 12px !important;
  }

  .stage-info,
  .template-info,
  .rule-info,
  .config-info {
    margin-right: 0 !important;
    width: 100% !important;
  }

  .stage-controls,
  .template-controls,
  .rule-controls {
    width: 100% !important;
    justify-content: space-between;
  }

  .system-config-actions {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 768px) {
  .workflow-stages-list,
  .sop-templates-list,
  .pricing-rules-list,
  .performance-rules-list,
  .system-config-section,
  .system-config-actions {
    padding: 16px;
  }

  .page-title {
    font-size: 20px !important;
  }
}

@media (max-width: 480px) {
  .system-settings {
    padding: 12px;
  }

  .tab-btn {
    padding: 10px 16px !important;
    font-size: 13px !important;
  }

  .create-btn,
  .save-btn,
  .reset-btn {
    padding: 8px 16px !important;
    font-size: 13px !important;
  }
}

// 顶部：工作流搜索 + 右侧悬浮按钮
.workflow-search {
  position: relative;
  align-items: center;

  .fab-add {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
    box-shadow: $shadow-md;

    &:hover {
      box-shadow: $shadow-lg;
      transform: translateY(-50%) scale(1.03);
    }
  }
}

// 横向时间轴
.workflow-timeline {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  align-items: center;
  gap: 24px;
  padding: 16px 20px;
  background: $bg-white;
  border-radius: 12px;
  box-shadow: $shadow-sm;
  margin-bottom: 20px;
  position: relative;

  &::before {
    content: '';
    position: absolute;
    left: 40px;
    right: 40px;
    top: 50%;
    height: 2px;
    background: $border-color;
    z-index: 0;
  }

  .timeline-step {
    position: relative;
    text-align: center;

    .node {
      width: 32px;
      height: 32px;
      border-radius: 50%;
      background: $primary-color;
      color: $bg-white;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      box-shadow: $shadow-sm;
      position: relative;
      z-index: 1;
    }

    .label {
      margin-top: 8px;
      font-size: 14px;
      color: $text-primary;
      font-weight: 600;
    }

    &.last::after {
      display: none;
    }
  }
}

// 两列卡片
.timeline-stage-cards {
  display: flex;
  flex-direction: column;
  gap: 20px;

  .stage-cards-row {
    background: $bg-white;
    border-radius: 12px;
    box-shadow: $shadow-sm;
    padding: 16px 16px 8px;

    .stage-title {
      font-size: 16px;
      font-weight: 700;
      color: $primary-color;
      margin: 0 0 12px;
    }

    .stage-grid {
      display: grid;
      grid-template-columns: repeat(2, minmax(320px, 1fr));
      gap: 16px;

      @media (max-width: 1024px) {
        grid-template-columns: 1fr;
      }

      .stage-card {
        position: relative;
        background: $bg-white;
        border-radius: 12px;
        box-shadow: $shadow-sm;
        padding: 16px;
        transition: transform .2s ease, box-shadow .2s ease;
        overflow: hidden;

        &:hover {
          transform: translateY(-2px) scale(1.01);
          box-shadow: $shadow-md;
        }

        &.muted {
          background: $bg-light;
        }

        &.disabled { opacity: .6; }

        .card-actions {
          position: absolute;
          top: 8px;
          right: 8px;
          display: flex;
          gap: 4px;
          opacity: 0;
          transition: opacity .2s ease;
        }

        &:hover .card-actions { opacity: 1; }

        .stage-name {
          font-size: 16px;
          font-weight: 700;
          color: $primary-color;
          margin-bottom: 6px;
        }

        .stage-desc {
          font-size: 14px;
          color: $text-secondary;
          line-height: 1.6;
          margin-bottom: 12px;
        }

        .stage-ops {
          .stage-toggle {
            font-size: 12px;
          }
        }

        .hint-title {
          font-size: 14px;
          font-weight: 600;
          color: $text-secondary;
          margin-bottom: 8px;
        }
        .hint-list { margin: 0; padding-left: 18px; color: $text-tertiary; }
      }
    }
  }
}

.bulk-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: $bg-white;
  border: 1px solid $border-color;
  border-radius: 10px;
  padding: 10px 14px;
  margin: 8px 0 16px;
  box-shadow: $shadow-sm;

  .bulk-left {
    display: flex;
    align-items: center;
    gap: 10px;
    color: $text-secondary;
    font-size: 14px;
  }
  .bulk-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
  }
}

.timeline-stage-cards .stage-card {
  position: relative;
  .bulk-check {
    position: absolute;
    left: 12px;
    top: 12px;
    z-index: 2;
  }
}

.workflow-timeline .timeline-step .label {
  letter-spacing: 0.5px;
}

// 统计卡片区域（系统配置页）
.stats-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.stat-card {
  background: $bg-white;
  padding: 20px;
  border-radius: 12px;
  box-shadow: $shadow-sm;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  border: 1px solid $border-color;

  &:hover {
    transform: translateY(-2px);
    box-shadow: $shadow-md;
  }

  .label {
    font-size: 13px;
    color: $text-tertiary;
    margin-bottom: 8px;
  }

  .value {
    font-size: 24px;
    font-weight: 600;
    color: $text-primary;
    margin-bottom: 4px;
  }

  .unit {
    font-size: 12px;
    color: $text-tertiary;
  }
}

// 图表区域
.charts-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 24px;
}

.chart-wrapper {
  background: $bg-white;
  padding: 20px;
  border-radius: 12px;
  box-shadow: $shadow-sm;
  border: 1px solid $border-color;
}

.chart-container {
  height: 300px;
  margin-top: 12px;
}

// 响应式优化
@media (max-width: 1024px) {
  .charts-container {
    grid-template-columns: 1fr;
  }
  .stats-cards {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .stats-cards {
    grid-template-columns: 1fr;
  }
}