// 项目问卷组件 - 移动端优先设计

// CSS 变量
:host {
  --primary-color: #3880ff;
  --success-color: #2dd36f;
  --warning-color: #ffc409;
  --danger-color: #eb445a;
  --dark-color: #222428;
  --medium-color: #92949c;
  --light-color: #f4f5f8;
  --white: #ffffff;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.16);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

// 重置样式
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

// 顶部导航栏
.survey-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: var(--white);
  box-shadow: var(--shadow-sm);

  .header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    padding: 0 16px;
    max-width: 640px;
    margin: 0 auto;
  }

  .back-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--dark-color);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);

    &:active {
      background: var(--light-color);
      transform: scale(0.95);
    }

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

  .header-title {
    flex: 1;
    margin: 0 16px;
    font-size: 18px;
    font-weight: 600;
    color: var(--dark-color);
    text-align: center;
  }

  .header-spacer {
    width: 40px;
  }
}

// 主容器
.survey-container {
  min-height: 100vh;
  height:100vh;
  overflow-y:auto;
  padding-top: 56px;
  background: linear-gradient(180deg, #f8f9fa 0%, #ffffff 100%);
}

// 状态视图(加载/错误)
.status-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 56px);
  padding: 32px 24px;
  text-align: center;

  .status-text {
    margin: 16px 0 0;
    font-size: 16px;
    color: var(--medium-color);
  }
}

// 加载动画
.spinner {
  width: 48px;
  height: 48px;
  position: relative;

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

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

// 错误视图
.error-view {
  .error-icon-wrapper {
    width: 80px;
    height: 80px;
    margin-bottom: 24px;
    border-radius: 50%;
    background: rgba(235, 68, 90, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;

    .error-icon {
      width: 48px;
      height: 48px;
      color: var(--danger-color);
    }
  }

  .error-title {
    margin: 0 0 12px;
    font-size: 20px;
    font-weight: 600;
    color: var(--dark-color);
  }

  .error-message {
    margin: 0 0 24px;
    font-size: 15px;
    color: var(--medium-color);
    line-height: 1.5;
  }

  .info-box {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    margin-bottom: 24px;
    background: rgba(255, 196, 9, 0.1);
    border-radius: var(--radius-md);
    border-left: 4px solid var(--warning-color);
    text-align: left;

    .icon {
      width: 24px;
      height: 24px;
      color: var(--warning-color);
      flex-shrink: 0;
      margin-top: 2px;
    }

    .info-text {
      flex: 1;

      .info-title {
        margin: 0 0 4px;
        font-size: 14px;
        font-weight: 600;
        color: var(--dark-color);
      }

      .info-desc {
        margin: 0;
        font-size: 13px;
        color: var(--medium-color);
        line-height: 1.4;
      }
    }
  }
}

// 欢迎页
.welcome-view {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 16px 32px;

  .user-card {
    text-align: center;
    margin-bottom: 24px;
    animation: fadeInUp 0.6s ease;

    .user-avatar {
      width: 80px;
      height: 80px;
      margin: 0 auto 16px;
      border-radius: 50%;
      overflow: hidden;
      box-shadow: var(--shadow-md);

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

    .user-greeting {
      margin: 0 0 8px;
      font-size: 24px;
      font-weight: 600;
      color: var(--dark-color);
    }

    .user-subtitle {
      margin: 0;
      font-size: 15px;
      color: var(--medium-color);
    }
  }

  .intro-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
    animation: fadeInUp 0.6s ease 0.1s both;

    .intro-header {
      display: flex;
      align-items: flex-start;
      gap: 12px;
      margin-bottom: 20px;

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

      h3 {
        margin: 0;
        font-size: 18px;
        font-weight: 600;
        color: var(--dark-color);
        line-height: 1.4;
      }
    }

    .intro-body {
      margin-bottom: 20px;

      .intro-text {
        margin: 0 0 12px;
        font-size: 15px;
        color: var(--dark-color);
        line-height: 1.6;

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

    .info-tags {
      display: flex;
      justify-content: space-around;
      gap: 12px;
      padding-top: 20px;
      border-top: 1px solid var(--light-color);

      .info-tag {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 8px;
        flex: 1;

        .icon {
          width: 24px;
          height: 24px;
          color: var(--primary-color);
          opacity: 0.8;
        }

        span {
          font-size: 13px;
          font-weight: 500;
          color: var(--medium-color);
        }
      }
    }
  }

  .btn-start {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 56px;
    background: var(--primary-color);
    color: var(--white);
    border: none;
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 600;
    box-shadow: var(--shadow-md);
    cursor: pointer;
    transition: var(--transition);
    animation: fadeInUp 0.6s ease 0.2s both;

    &:active {
      transform: translateY(2px);
      box-shadow: var(--shadow-sm);
    }

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

// 答题页
.questionnaire-view {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 16px 32px;

  .progress-section {
    margin-bottom: 24px;

    .progress-bar-wrapper {
      margin-bottom: 12px;

      .progress-bar {
        height: 6px;
        background: var(--light-color);
        border-radius: 3px;
        overflow: hidden;

        .progress-fill {
          height: 100%;
          background: linear-gradient(90deg, var(--primary-color) 0%, #5a9cff 100%);
          border-radius: 3px;
          transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        }
      }
    }

    .progress-info {
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 4px;
      font-size: 14px;

      .progress-current {
        font-size: 18px;
        font-weight: 600;
        color: var(--primary-color);
      }

      .progress-separator {
        color: var(--medium-color);
      }

      .progress-total {
        color: var(--medium-color);
      }
    }
  }

  .question-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
    animation: slideInRight 0.4s ease;

    .section-badge {
      display: inline-block;
      padding: 4px 12px;
      margin-bottom: 16px;
      background: rgba(56, 128, 255, 0.1);
      color: var(--primary-color);
      border-radius: 12px;
      font-size: 12px;
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 0.5px;
    }

    .question-content {
      .question-title {
        margin: 0 0 20px;
        font-size: 17px;
        font-weight: 600;
        color: var(--dark-color);
        line-height: 1.5;

        .question-number {
          color: var(--primary-color);
          margin-right: 8px;
        }

        .question-text {
          display: inline;
        }

        .required-star {
          color: var(--danger-color);
          margin-left: 4px;
        }
      }

      .options-list {
        display: flex;
        flex-direction: column;
        gap: 12px;

        .option-item {
          display: flex;
          align-items: center;
          gap: 12px;
          padding: 16px;
          background: var(--white);
          border: 2px solid var(--light-color);
          border-radius: var(--radius-md);
          cursor: pointer;
          transition: var(--transition);

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

          &.selected {
            border-color: var(--primary-color);
            background: rgba(56, 128, 255, 0.05);

            .option-radio .radio-outer {
              border-color: var(--primary-color);

              .radio-inner {
                transform: scale(1);
                background: var(--primary-color);
              }
            }

            .option-checkbox .checkbox-box {
              border-color: var(--primary-color);
              background: var(--primary-color);

              .checkmark {
                opacity: 1;
                transform: scale(1);
              }
            }

            .option-label {
              color: var(--primary-color);
              font-weight: 600;
            }
          }

          .option-radio {
            flex-shrink: 0;

            .radio-outer {
              width: 24px;
              height: 24px;
              border: 2px solid var(--medium-color);
              border-radius: 50%;
              display: flex;
              align-items: center;
              justify-content: center;
              transition: var(--transition);

              .radio-inner {
                width: 12px;
                height: 12px;
                border-radius: 50%;
                transform: scale(0);
                transition: var(--transition);
              }
            }
          }

          .option-checkbox {
            flex-shrink: 0;

            .checkbox-box {
              width: 24px;
              height: 24px;
              border: 2px solid var(--medium-color);
              border-radius: 6px;
              display: flex;
              align-items: center;
              justify-content: center;
              transition: var(--transition);

              .checkmark {
                width: 14px;
                height: 14px;
                color: var(--white);
                opacity: 0;
                transform: scale(0);
                transition: var(--transition);
              }
            }
          }

          .option-label {
            flex: 1;
            font-size: 15px;
            color: var(--dark-color);
            line-height: 1.4;
            transition: var(--transition);
          }
        }
      }

      .input-wrapper {
        margin-top: 12px;

        .text-input,
        .textarea-input {
          width: 100%;
          padding: 14px 16px;
          border: 2px solid var(--light-color);
          border-radius: var(--radius-md);
          font-size: 15px;
          color: var(--dark-color);
          background: var(--white);
          font-family: inherit;
          transition: var(--transition);

          &:focus {
            outline: none;
            border-color: var(--primary-color);
            box-shadow: 0 0 0 4px rgba(56, 128, 255, 0.1);
          }

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

        .textarea-input {
          resize: vertical;
          min-height: 100px;
          line-height: 1.5;
        }
      }
    }
  }

  .nav-buttons {
    display: flex;
    gap: 12px;

    .btn-nav {
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
      height: 50px;
      border: none;
      border-radius: var(--radius-md);
      font-size: 15px;
      font-weight: 600;
      cursor: pointer;
      transition: var(--transition);

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

      &.btn-prev {
        background: var(--white);
        color: var(--dark-color);
        border: 2px solid var(--light-color);

        &:active:not(:disabled) {
          transform: translateX(-2px);
          background: var(--light-color);
        }

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

      &.btn-next {
        background: var(--primary-color);
        color: var(--white);
        box-shadow: var(--shadow-sm);

        &:active {
          transform: translateX(2px);
          box-shadow: none;
        }
      }
    }
  }
}

// 结果页
.result-view {
  max-width: 640px;
  margin: 0 auto;
  padding: 32px 16px;
  text-align: center;

  .success-icon-wrapper {
    width: 80px;
    height: 80px;
    margin: 0 auto 24px;
    border-radius: 50%;
    background: rgba(45, 211, 111, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: scaleIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);

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

  .result-title {
    margin: 0 0 8px;
    font-size: 24px;
    font-weight: 600;
    color: var(--dark-color);
    animation: fadeInUp 0.6s ease 0.1s both;
  }

  .result-subtitle {
    margin: 0 0 8px;
    font-size: 16px;
    font-weight: 500;
    color: var(--medium-color);
    animation: fadeInUp 0.6s ease 0.2s both;
  }

  .result-desc {
    margin: 0 0 32px;
    font-size: 14px;
    color: var(--medium-color);
    animation: fadeInUp 0.6s ease 0.3s both;
  }

  .result-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
    text-align: left;
    animation: fadeInUp 0.6s ease 0.4s both;

    .result-card-title {
      margin: 0 0 20px;
      font-size: 16px;
      font-weight: 600;
      color: var(--dark-color);
      text-align: center;
    }

    .result-list {
      .result-item {
        display: flex;
        gap: 12px;
        padding: 12px 0;
        border-bottom: 1px solid var(--light-color);

        &:first-child {
          padding-top: 0;
        }

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

        .result-label {
          min-width: 80px;
          font-size: 14px;
          font-weight: 600;
          color: var(--medium-color);
          flex-shrink: 0;
        }

        .result-value {
          flex: 1;
          font-size: 14px;
          color: var(--dark-color);
          line-height: 1.5;
          word-break: break-word;
        }
      }
    }

    .result-divider {
      height: 1px;
      background: var(--light-color);
      margin: 20px 0;
    }
  }

  .btn-primary {
    width: 100%;
    height: 50px;
    background: var(--primary-color);
    color: var(--white);
    border: none;
    border-radius: var(--radius-md);
    font-size: 16px;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: var(--transition);
    animation: fadeInUp 0.6s ease 0.5s both;

    &:active {
      transform: translateY(2px);
      box-shadow: none;
    }
  }
}

// 动画
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

// 平板适配 (>= 768px)
@media (min-width: 768px) {
  .survey-header .header-content {
    max-width: 768px;
  }

  .welcome-view,
  .questionnaire-view,
  .result-view {
    max-width: 768px;
    padding-left: 32px;
    padding-right: 32px;
  }

  .intro-card,
  .question-card,
  .result-card {
    padding: 32px;
  }

  .btn-start,
  .btn-primary {
    height: 56px;
    font-size: 17px;
  }

  .nav-buttons .btn-nav {
    height: 52px;
  }
}

// 小屏适配 (<= 375px)
@media (max-width: 375px) {
  .survey-header {
    .header-title {
      font-size: 16px;
    }
  }

  .welcome-view {
    .user-greeting {
      font-size: 20px;
    }

    .intro-card {
      padding: 20px;

      .intro-header h3 {
        font-size: 16px;
      }

      .intro-text {
        font-size: 14px;
      }
    }
  }

  .questionnaire-view {
    .question-card {
      padding: 20px;

      .question-title {
        font-size: 16px;
      }

      .option-item {
        padding: 14px;

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

    .nav-buttons .btn-nav {
      height: 48px;
      font-size: 14px;
    }
  }

  .result-view {
    .result-title {
      font-size: 20px;
    }

    .result-card {
      padding: 20px;
    }
  }
}
