// 订单分配阶段样式 - 纯 div+scss 实现

// CSS 变量定义
:host {
  --primary-color: #3880ff;
  --primary-rgb: 56, 128, 255;
  --secondary-color: #0cd1e8;
  --tertiary-color: #7044ff;
  --success-color: #2dd36f;
  --warning-color: #ffc409;
  --danger-color: #eb445a;
  --dark-color: #222428;
  --medium-color: #92949c;
  --light-color: #f4f5f8;
  --light-shade: #d7d8da;
  --white: #ffffff;
}

// 加载容器
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 50vh;
  padding: 20px;

  .spinner {
    width: 48px;
    height: 48px;
    margin-bottom: 16px;
    position: relative;

    .spinner-circle {
      width: 100%;
      height: 100%;
      border: 4px solid var(--light-shade);
      border-top-color: var(--primary-color);
      border-radius: 50%;
      animation: spin 0.8s linear infinite;
    }
  }

  p {
    color: var(--medium-color);
    margin: 0;
    font-size: 14px;
  }
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

// 订单分配容器
.stage-order-container {
  padding: 0;

  // 通用卡片样式
  .card {
    background: var(--white);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    margin-bottom: 16px;
    overflow: hidden;

    .card-header {
      padding: 16px;
      border-bottom: 1px solid var(--light-shade);

      .card-title {
        display: flex;
        align-items: center;
        gap: 8px;
        margin: 0;
        font-size: 16px;
        font-weight: 600;
        color: var(--dark-color);

        .icon {
          width: 20px;
          height: 20px;
          color: var(--primary-color);
          flex-shrink: 0;
        }
      }

      .card-subtitle {
        margin: 4px 0 0;
        font-size: 12px;
        color: var(--medium-color);
      }
    }

    .card-content {
      padding: 16px;
    }
  }

  // 必填标记
  .required {
    color: var(--danger-color);
    margin-left: 4px;
  }

  // 客户信息卡片
  .customer-card {
    .info-list {
      display: flex;
      flex-direction: column;
      gap: 16px;
    }

    .info-item {
      .info-text {
        .info-label {
          color: var(--medium-color);
          font-size: 12px;
          margin: 0 0 4px;
        }

        .info-value {
          color: var(--dark-color);
          font-size: 15px;
          font-weight: 500;
          margin: 0;
        }

        .preference-tags {
          display: flex;
          flex-wrap: wrap;
          gap: 6px;
          margin-top: 6px;
        }
      }
    }
  }

  // 项目基本信息卡片
  .project-info-card {
    .form-list {
      display: flex;
      flex-direction: column;
      gap: 16px;
    }

    .form-group {
      .form-label {
        display: block;
        font-weight: 500;
        color: var(--dark-color);
        margin-bottom: 8px;
        font-size: 14px;
      }

      .form-input,
      .form-select,
      .form-textarea {
        width: 100%;
        padding: 12px 16px;
        background: var(--light-color);
        border: 1px solid var(--light-shade);
        border-radius: 8px;
        font-size: 14px;
        color: var(--dark-color);
        transition: all 0.3s;
        font-family: inherit;

        &:focus {
          outline: none;
          border-color: var(--primary-color);
          background: var(--white);
          box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.1);
        }

        &::placeholder {
          color: var(--medium-color);
        }

        &:disabled {
          background: var(--light-color);
          color: var(--medium-color);
          cursor: not-allowed;
          opacity: 0.7;
        }
      }

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

      .form-select {
        cursor: pointer;
        appearance: none;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%2392949c'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 12px center;
        background-size: 20px;
        padding-right: 40px;
      }
    }
  }

  // 报价明细卡片
  .quotation-card {
    .space-section {
      margin-bottom: 24px;
      padding-bottom: 24px;
      border-bottom: 1px solid var(--light-shade);

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

      .space-header {
        display: flex;
        align-items: center;
        gap: 8px;
        margin-bottom: 16px;
        padding: 10px 14px;
        background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
        border-radius: 8px;
        color: white;

        .icon {
          width: 20px;
          height: 20px;
          flex-shrink: 0;
        }

        h3 {
          margin: 0;
          font-size: 15px;
          font-weight: 600;
        }
      }

      .process-grid {
        display: grid;
        gap: 12px;

        .process-item {
          padding: 12px;
          background-color: var(--light-color);
          border-radius: 8px;
          border: 2px solid transparent;
          transition: all 0.3s;

          &.enabled {
            background-color: white;
            border-color: rgba(var(--primary-rgb), 0.3);
            box-shadow: 0 2px 8px rgba(var(--primary-rgb), 0.1);
          }

          .process-header {
            display: flex;
            align-items: center;
            gap: 8px;
            cursor: pointer;
            margin-bottom: 8px;
            user-select: none;

            // 自定义 checkbox
            .checkbox-wrapper {
              display: inline-flex;
              align-items: center;
              cursor: pointer;
              position: relative;
              margin-right: 4px;

              .checkbox-input {
                position: absolute;
                opacity: 0;
                cursor: pointer;
                width: 0;
                height: 0;

                &:checked + .checkbox-custom {
                  background-color: var(--primary-color);
                  border-color: var(--primary-color);

                  &::after {
                    display: block;
                  }
                }

                &:disabled + .checkbox-custom {
                  opacity: 0.5;
                  cursor: not-allowed;
                }
              }

              .checkbox-custom {
                position: relative;
                height: 20px;
                width: 20px;
                background-color: var(--white);
                border: 2px solid var(--medium-color);
                border-radius: 4px;
                transition: all 0.3s;
                display: flex;
                align-items: center;
                justify-content: center;

                &::after {
                  content: '';
                  display: none;
                  width: 5px;
                  height: 10px;
                  border: solid white;
                  border-width: 0 2px 2px 0;
                  transform: rotate(45deg);
                }
              }
            }

            .badge {
              display: inline-block;
              font-size: 12px;
              padding: 4px 10px;
              border-radius: 12px;
              font-weight: 600;

              // 根据 data-color 属性设置颜色
              &[data-color="primary"] {
                background: var(--primary-color);
                color: white;
              }

              &[data-color="secondary"] {
                background: var(--secondary-color);
                color: white;
              }

              &[data-color="tertiary"] {
                background: var(--tertiary-color);
                color: white;
              }

              &[data-color="success"] {
                background: var(--success-color);
                color: white;
              }

              &[data-color="warning"] {
                background: var(--warning-color);
                color: var(--dark-color);
              }

              &[data-color="danger"] {
                background: var(--danger-color);
                color: white;
              }
            }
          }

          .process-inputs {
            display: grid;
            gap: 10px;
            padding-top: 12px;
            border-top: 1px solid var(--light-shade);

            .input-group {
              .input-label {
                display: block;
                font-size: 12px;
                color: var(--medium-color);
                margin-bottom: 6px;
                font-weight: 500;
              }

              .input-with-note {
                display: flex;
                align-items: center;
                gap: 8px;

                .input-field {
                  flex: 1;
                  padding: 8px 12px;
                  background: var(--light-color);
                  border: 1px solid var(--light-shade);
                  border-radius: 6px;
                  font-size: 14px;
                  color: var(--dark-color);
                  transition: all 0.3s;

                  &:focus {
                    outline: none;
                    border-color: var(--primary-color);
                    background: var(--white);
                    box-shadow: 0 0 0 2px rgba(var(--primary-rgb), 0.1);
                  }

                  &::placeholder {
                    color: var(--medium-color);
                  }

                  &:disabled {
                    background: var(--light-color);
                    color: var(--medium-color);
                    cursor: not-allowed;
                    opacity: 0.7;
                  }

                  // 隐藏 number input 的上下箭头
                  &[type="number"] {
                    -moz-appearance: textfield;

                    &::-webkit-outer-spin-button,
                    &::-webkit-inner-spin-button {
                      -webkit-appearance: none;
                      margin: 0;
                    }
                  }
                }

                .input-note {
                  font-size: 12px;
                  color: var(--medium-color);
                  white-space: nowrap;
                  flex-shrink: 0;
                }
              }
            }

            .process-subtotal {
              text-align: right;
              font-size: 13px;
              font-weight: 600;
              color: var(--primary-color);
              margin-top: 4px;
              padding-top: 8px;
              border-top: 1px dashed var(--light-shade);
            }
          }
        }
      }
    }

    .total-section {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 16px 20px;
      margin-top: 20px;
      background: linear-gradient(135deg, var(--success-color) 0%, #28ba62 100%);
      border-radius: 10px;
      box-shadow: 0 4px 12px rgba(45, 211, 111, 0.3);

      .total-label {
        font-size: 16px;
        font-weight: 600;
        color: white;
      }

      .total-amount {
        font-size: 24px;
        font-weight: 700;
        color: white;
        letter-spacing: 0.5px;
      }
    }
  }

  // 设计师分配卡片
  .designer-card {
    .empty-state {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      padding: 40px 20px;
      text-align: center;

      .icon-large {
        width: 64px;
        height: 64px;
        color: var(--medium-color);
        margin-bottom: 16px;
        opacity: 0.5;
      }

      p {
        color: var(--medium-color);
        margin: 0;
        font-size: 14px;
      }
    }

    .designer-grid {
      display: grid;
      gap: 12px;

      .designer-item {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 12px;
        background-color: var(--light-color);
        border-radius: 8px;
        border: 2px solid transparent;
        cursor: pointer;
        transition: all 0.3s;

        &:hover {
          background-color: var(--light-shade);
          transform: translateX(2px);
        }

        &:active {
          transform: scale(0.98);
        }

        &.selected {
          background-color: white;
          border-color: var(--primary-color);
          box-shadow: 0 4px 12px rgba(var(--primary-rgb), 0.2);

          .designer-info h4 {
            color: var(--primary-color);
          }
        }

        .designer-avatar {
          width: 48px;
          height: 48px;
          flex-shrink: 0;
          border-radius: 50%;
          overflow: hidden;
          background-color: var(--light-shade);
          display: flex;
          align-items: center;
          justify-content: center;

          img {
            width: 100%;
            height: 100%;
            object-fit: cover;
          }

          .avatar-icon {
            width: 48px;
            height: 48px;
            color: var(--medium-color);
          }
        }

        .designer-info {
          flex: 1;
          min-width: 0;

          h4 {
            margin: 0 0 4px;
            font-size: 15px;
            font-weight: 600;
            color: var(--dark-color);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            transition: color 0.3s;
          }

          p {
            margin: 0;
            font-size: 12px;
            color: var(--medium-color);
          }
        }

        .selected-icon {
          width: 28px;
          height: 28px;
          color: var(--primary-color);
          flex-shrink: 0;
        }
      }
    }
  }

  // Badge 组件
  .badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;

    &.badge-primary {
      background: var(--primary-color);
      color: white;
    }

    &.badge-secondary {
      background: var(--secondary-color);
      color: white;
    }

    &.badge-tertiary {
      background: var(--tertiary-color);
      color: white;
    }

    &.badge-success {
      background: var(--success-color);
      color: white;
    }

    &.badge-warning {
      background: var(--warning-color);
      color: var(--dark-color);
    }

    &.badge-danger {
      background: var(--danger-color);
      color: white;
    }

    &.badge-medium {
      background: var(--medium-color);
      color: white;
    }
  }

  // 操作按钮
  .action-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 16px 0;
    margin-top: 20px;

    .btn {
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
      padding: 12px 24px;
      border-radius: 8px;
      font-size: 14px;
      font-weight: 600;
      cursor: pointer;
      transition: all 0.3s;
      border: none;
      outline: none;
      height: 48px;

      .icon {
        width: 20px;
        height: 20px;
        flex-shrink: 0;
      }

      &.btn-primary {
        background: var(--primary-color);
        color: white;

        &:hover {
          background: #2f6ce5;
          transform: translateY(-2px);
          box-shadow: 0 4px 12px rgba(var(--primary-rgb), 0.3);
        }

        &:active {
          transform: translateY(0);
        }
      }

      &.btn-outline {
        background: white;
        color: var(--primary-color);
        border: 2px solid var(--primary-color);

        &:hover {
          background: var(--primary-color);
          color: white;
        }

        &:active {
          transform: scale(0.98);
        }
      }

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

// 响应式适配
@media (min-width: 768px) {
  .stage-order-container {
    .quotation-card {
      .space-section {
        .process-grid {
          grid-template-columns: repeat(2, 1fr);
        }
      }
    }

    .designer-card {
      .designer-grid {
        grid-template-columns: repeat(2, 1fr);
      }
    }
  }
}

@media (min-width: 1024px) {
  .stage-order-container {
    .quotation-card {
      .space-section {
        .process-grid {
          grid-template-columns: repeat(3, 1fr);
        }
      }
    }

    .designer-card {
      .designer-grid {
        grid-template-columns: repeat(3, 1fr);
      }
    }
  }
}

// 移动端优化
@media (max-width: 480px) {
  .stage-order-container {
    .card {
      border-radius: 10px;
      margin-bottom: 12px;

      .card-header {
        padding: 12px;

        .card-title {
          font-size: 15px;

          .icon {
            width: 18px;
            height: 18px;
          }
        }

        .card-subtitle {
          font-size: 11px;
        }
      }

      .card-content {
        padding: 12px;
      }
    }

    .quotation-card {
      .space-section {
        margin-bottom: 20px;
        padding-bottom: 20px;

        .space-header {
          padding: 8px 12px;

          .icon {
            width: 18px;
            height: 18px;
          }

          h3 {
            font-size: 14px;
          }
        }

        .process-grid {
          gap: 10px;

          .process-item {
            padding: 10px;

            .process-header {
              .checkbox-wrapper {
                .checkbox-custom {
                  height: 18px;
                  width: 18px;

                  &::after {
                    width: 4px;
                    height: 8px;
                  }
                }
              }

              .badge {
                font-size: 11px;
                padding: 3px 8px;
              }
            }
          }
        }
      }

      .total-section {
        padding: 12px 16px;

        .total-label {
          font-size: 14px;
        }

        .total-amount {
          font-size: 20px;
        }
      }
    }

    .designer-card {
      .designer-grid {
        .designer-item {
          padding: 10px;

          .designer-avatar {
            width: 40px;
            height: 40px;

            .avatar-icon {
              width: 40px;
              height: 40px;
            }
          }

          .designer-info {
            h4 {
              font-size: 14px;
            }

            p {
              font-size: 11px;
            }
          }

          .selected-icon {
            width: 24px;
            height: 24px;
          }
        }
      }
    }

    .action-buttons {
      gap: 10px;
      padding: 12px 0;

      .btn {
        padding: 10px 16px;
        font-size: 13px;
        height: 44px;

        .icon {
          width: 18px;
          height: 18px;
        }
      }
    }

    .form-group {
      .form-input,
      .form-select,
      .form-textarea {
        padding: 10px 12px;
        font-size: 13px;
      }

      .form-select {
        background-position: right 10px center;
        background-size: 18px;
        padding-right: 36px;
      }
    }
  }
}
