﻿<template>
  <div class="new-product-value-page student-training-shell">
    <main class="training-core">
      <section class="task-header">
        <div class="task-badge">
          <el-icon><Operation /></el-icon>
          核心实训 · 产品开发基础
        </div>
        <h1 class="task-title">{{ taskTitle }}</h1>
      </section>

      <TrainingTaskBrief :background="taskBackground" :goals="taskGoals" :requirements="taskRequirement" :show-material="false" />

      <section class="task-card">
        <div class="workbench-head workbench-head--actions-only">
          <div class="workbench-actions">
            <TrainingMaterialButton :material-name="taskConfig?.materialName" :material-url="taskConfig?.materialUrl" />
            <button type="button" class="outline-action" @click="exportOutcome">
              <el-icon><Download /></el-icon>
              导出实训成果
            </button>
          </div>
        </div>

        <nav class="step-indicator" aria-label="新产品调查与分析步骤">
          <template v-for="(step, index) in steps" :key="step.no">
            <button
              type="button"
              :class="['step-tab', { active: currentStep === step.no, complete: currentStep > step.no }]"
              :aria-label="`切换至第 ${step.no} 步：${step.name}`"
              :aria-current="currentStep === step.no ? 'step' : undefined"
              @click="currentStep = step.no"
            >
              <span class="step-marker" aria-hidden="true">
                {{ String(step.no).padStart(2, '0') }}
              </span>
              <span class="step-copy">
                <strong class="step-name" :title="step.name">{{ step.name }}</strong>
                <span class="step-action">{{ currentStep === step.no ? '当前步骤' : '点击切换' }} <span aria-hidden="true">→</span></span>
              </span>
            </button>
            <span v-if="index < steps.length - 1" class="step-connector" aria-hidden="true" />
          </template>
        </nav>

        <section v-show="currentStep === 1" class="step-content active-step">
          <div class="step-card">
            <div class="step-title-row">
              <div>
                <p class="section-eyebrow">Step 01</p>
                <h3>{{ getStepName(1) }}</h3>
              </div>
              <span class="step-chip">卖点分类练习</span>
            </div>
            <p class="step-desc">查看案例产品详情，仔细阅读主图及详情页信息，对下列产品卖点进行三层次分类。</p>

            <div class="training-table-wrap classification-table-wrap">
              <table class="training-data-table classification-table">
                <thead>
                  <tr>
                    <th>序号</th>
                    <th>卖点</th>
                    <th>三层次分类</th>
                  </tr>
                </thead>
                <tbody>
                  <tr v-for="(point, index) in STEP_ONE_SELLING_POINTS" :key="point.id" :class="feedbackClass(point.id)">
                    <td class="classification-number">{{ index + 1 }}</td>
                    <td class="classification-selling-point">{{ point.text }}</td>
                    <td class="classification-select-cell">
                      <el-select v-model="classifications[point.id]" placeholder="请选择分类" :disabled="checking" @change="clearFeedback(point.id)">
                        <el-option v-for="category in LAYER_OPTIONS" :key="category" :label="category" :value="category" />
                      </el-select>
                      <p v-if="checkResult?.itemsById?.[point.id]" class="classification-feedback">
                        {{ checkResult.itemsById[point.id].message }}
                      </p>
                    </td>
                  </tr>
                </tbody>
              </table>
            </div>
            <p v-if="checkResult" class="classification-summary" :class="{ 'is-success': checkResult.allCorrect }">
              本次判题：{{ checkResult.correctCount }} / {{ checkResult.totalCount }} 项分类正确
            </p>
          </div>
        </section>

        <section v-show="currentStep === 2" class="step-content active-step">
          <div class="step-card">
            <div class="step-title-row">
              <div>
                <p class="section-eyebrow">Step 02</p>
                <h3>{{ getStepName(2) }}</h3>
              </div>
              <span class="step-chip">实地调研记录</span>
            </div>
            <p class="step-desc">请以真实消费者身份进入电商平台，通过搜索、浏览和对比，采集 1 个 AI 产品的真实数据，并完成产品三层次分析。</p>

            <div class="survey-form">
              <section class="survey-field-group">
                <p class="survey-field-title"><b>01</b> 选择调研平台</p>
                <el-radio-group v-model="step2Form.platform" class="survey-options">
                  <el-radio v-for="option in STEP_TWO_PLATFORM_OPTIONS" :key="option.value" :label="option.value" class="survey-option">
                    <strong>{{ option.label }}</strong><span>{{ option.description }}</span>
                  </el-radio>
                </el-radio-group>
              </section>

              <section class="survey-field-group">
                <p class="survey-field-title"><b>02</b> 确定调研场景</p>
                <el-radio-group v-model="step2Form.scene" class="survey-options">
                  <el-radio v-for="option in STEP_TWO_SCENE_OPTIONS" :key="option.value" :label="option.value" class="survey-option">
                    <strong>{{ option.label }}</strong><span>{{ option.description }}</span>
                  </el-radio>
                </el-radio-group>
                <input v-if="step2Form.scene === '其他场景'" v-model.trim="step2Form.customScene" class="input-single custom-scene-input" placeholder="请填写其他调研场景" maxlength="60" />
              </section>

              <section class="survey-field-group">
                <p class="survey-field-title"><b>03</b> 设计搜索关键词</p>
                <p class="survey-field-hint">遵循“核心词 + 属性词 + 场景词”。例如：“AI智能音箱 语音控制 家居”“AI办公鼠标 语音转写 会议”。</p>
                <input v-model.trim="step2Form.keyword" class="input-single" placeholder="请输入搜索关键词" maxlength="120" />
              </section>

              <section class="survey-field-group">
                <p class="survey-field-title"><b>04</b> 记录产品信息并上传图片</p>
                <p class="survey-field-hint">请在搜索结果中按“销量”排序，从排名前 10 的产品中选择 1 款产品；上传主图及详情页截图，最多 5 张。</p>
                <label class="product-name-field">
                  <span>产品名称</span>
                  <input v-model.trim="step2Form.productName" class="input-single" placeholder="请输入产品名称" maxlength="120" />
                </label>
                <label class="image-upload-trigger" :class="{ disabled: uploadingImages || step2Form.images.length >= MAX_STEP_TWO_IMAGES }">
                  <input type="file" accept="image/*" multiple :disabled="uploadingImages || step2Form.images.length >= MAX_STEP_TWO_IMAGES" @change="uploadStepTwoImages" />
                  <span>{{ uploadingImages ? '图片上传中…' : `上传产品图片（${step2Form.images.length}/${MAX_STEP_TWO_IMAGES}）` }}</span>
                </label>
                <div v-if="step2Form.images.length" class="product-image-list">
                  <figure v-for="(image, index) in step2Form.images" :key="`${image.url}-${index}`" class="product-image-card">
                    <button type="button" class="product-image-preview" @click="previewStepTwoImage(image.url)">
                      <img :src="image.url" :alt="`${step2Form.productName || '产品'}图片 ${index + 1}`" />
                    </button>
                    <figcaption :title="image.name">{{ image.name }}</figcaption>
                    <button type="button" class="remove-image-button" :aria-label="`删除图片 ${index + 1}`" @click="removeStepTwoImage(index)">删除</button>
                  </figure>
                </div>
              </section>
            </div>
          </div>
        </section>

        <section v-show="currentStep === 3" class="step-content active-step">
          <div class="step-card">
            <div class="step-title-row">
              <div>
                <p class="section-eyebrow">Step 03</p>
                <h3>{{ getStepName(3) }}</h3>
              </div>
              <span class="step-chip">产品1 / 产品2 / 产品3</span>
            </div>
            <p class="step-desc">
              根据查找的产品，从核心层、有形层、延伸层开展三层次分析，对比不同产品如何创造用户价值。
            </p>

            <div class="training-table-wrap">
              <table class="training-data-table layer-table">
                <thead>
                  <tr>
                    <th>分析维度</th>
                    <th>内容要求</th>
                    <th>实例：AI学习机</th>
                    <th>产品1</th>
                    <th>产品2</th>
                    <th>产品3</th>
                  </tr>
                </thead>
                <tbody>
                  <tr v-for="row in step3Rows" :key="row.dimension">
                    <td class="dimension-cell">{{ row.dimension }}</td>
                    <td class="requirement-cell">{{ row.requirement }}</td>
                    <td class="example-cell">{{ row.example }}</td>
                    <td><textarea v-model="row.product1" class="cell-textarea" /></td>
                    <td><textarea v-model="row.product2" class="cell-textarea" /></td>
                    <td><textarea v-model="row.product3" class="cell-textarea" /></td>
                  </tr>
                </tbody>
              </table>
            </div>
          </div>
        </section>

        <section v-show="currentStep === 4" class="step-content active-step">
          <div class="step-card">
            <div class="step-title-row">
              <div>
                <p class="section-eyebrow">Step 04</p>
                <h3>{{ getStepName(4) }}</h3>
              </div>
              <span class="step-chip">价值判断</span>
            </div>
            <p class="step-desc">根据上面分析，围绕核心层、有形层、延伸层回答以下问题，并形成产品开发启发。</p>

            <label class="field-block">
              <span>核心层价值：AI 技术解决了用户什么真实问题？</span>
              <textarea v-model="step4Form.coreValue" class="input-field" rows="5" />
            </label>
            <label class="field-block">
              <span>有形层价值：哪些功能、设计或参数最能体现差异化？</span>
              <textarea v-model="step4Form.tangibleValue" class="input-field" rows="5" />
            </label>
            <label class="field-block">
              <span>延伸层价值：哪些服务、内容、生态或售后能增强竞争优势？</span>
              <textarea v-model="step4Form.extendedValue" class="input-field" rows="5" />
            </label>
          </div>
        </section>

        <div class="step-navigation">
          <button type="button" class="btn-nav" :disabled="currentStep === 1" @click="prevStep">
            <el-icon><ArrowLeft /></el-icon>
            上一步
          </button>
          <button type="button" class="btn-nav btn-save" :disabled="saving || checking || uploadingImages" @click="saveCurrentProgress">
            <el-icon><CircleCheck /></el-icon>
            保存当前进度
          </button>
          <button type="button" class="btn-nav btn-primary" :disabled="currentStep === steps.length || saving || checking || uploadingImages" @click="nextStep">
            {{ checking ? "正在判题" : "下一步" }}
            <el-icon><ArrowRight /></el-icon>
          </button>
        </div>

        <div class="task-actions">
          <button type="button" class="btn-nav btn-submit" :disabled="saving" @click="submitTask">
            <el-icon><CircleCheck /></el-icon>
            提交任务
          </button>
          <button type="button" class="btn-nav" :disabled="saving" @click="resetExample">
            <el-icon><RefreshLeft /></el-icon>
            清空填写
          </button>
        </div>
      </section>
    </main>

    <el-dialog v-model="imagePreviewOpen" title="产品图片预览" width="min(760px, 92vw)" append-to-body>
      <img v-if="imagePreviewUrl" :src="imagePreviewUrl" alt="产品图片大图" class="product-image-full" />
    </el-dialog>

    <TrainingAiSidebar
      :study-tip="currentStudyTip"
      reference-title="产品三层次分析参考"
      reference-text="· 核心层：用户购买的根本利益与真实痛点<br />· 有形层：功能、外观、品牌、包装、参数等可感知内容<br />· 延伸层：售后、内容服务、会员权益、生态兼容、数据安全等附加价值"
      assist-text="建议先把电商页面中的主图、参数、详情页、评价和售后承诺分别归入三层次，再比较哪些层次能形成差异化。"
      :progress-items="progressItems"
    />
  </div>
</template>

<script setup>
import {
  ArrowLeft,
  ArrowRight,
  CircleCheck,
  DataAnalysis,
  Download,
  Operation,
  Opportunity,
  RefreshLeft,
  Search,
  TrendCharts,
} from "@element-plus/icons-vue";
import { getTrainingTaskByKey } from "@/api/trainingTask";
import { checkNewProductSurveyStepOne, checkNewProductSurveyStepTwo, getStudentTrainingAnswer, saveStudentTrainingAnswer, uploadStudentTrainingFile } from "@/api/studentTrainingAnswer";
import useUserStore from "@/store/modules/user";
import { extractTrainingStepNames } from "@/views/training/taskKeyMap";
import TrainingAiSidebar from "@/views/components/TrainingAiSidebar.vue";
import TrainingMaterialButton from "@/views/components/TrainingMaterialButton.vue";
import TrainingTaskBrief from "@/views/components/TrainingTaskBrief.vue";

const TASK_KEY = "new-product-survey";
const { proxy } = getCurrentInstance();
const userStore = useUserStore();

const taskConfig = ref(null);
const saving = ref(false);
const checking = ref(false);
const uploadingImages = ref(false);
const imagePreviewOpen = ref(false);
const imagePreviewUrl = ref("");
const draftReady = ref(false);
const currentStep = ref(1);

const defaultSteps = [
  { no: 1, name: "产品卖点的三层次分类", icon: Search },
  { no: 2, name: "选定调查平台与产品", icon: DataAnalysis },
  { no: 3, name: "AI产品三层次分析", icon: TrendCharts },
  { no: 4, name: "AI应用价值分析", icon: Operation },
];

const defaultGoals = [
  "理解市场驱动、技术推动等不同类型产品开发的核心逻辑，培养市场意识，能分析新技术在互联网产品中的应用场景。",
  "掌握运用电商平台开展市场调查的方法，能结合产品三层次理论分析互联网新产品。",
  "能通过分析，理解企业如何通过不同产品层次创造差异化竞争优势。",
];

const taskTitle = computed(() => taskConfig.value?.taskName || "新产品调查与分析");
const taskGoals = computed(() => parseArray(taskConfig.value?.objectives, defaultGoals));
const taskBackground = computed(
  () =>
    taskConfig.value?.background ||
    "2024年，生成式AI技术爆发式发展，催生大量消费端新产品，如AI智能音箱、AI学习机、AI玩具等。DeepSeek的出现降低了国内企业使用AI技术开发产品的成本，企业希望借助电商平台数据，为未来产品开发提供思路。"
);
const taskRequirement = computed(
  () =>
    taskConfig.value?.requirements ||
    "请借助电商平台完成新产品调查，围绕产品三层次提取核心层、有形层、延伸层信息，并结合AI技术价值形成分析结论。"
);

const steps = computed(() => {
  const configured = extractTrainingStepNames(taskConfig.value?.steps, defaultSteps.map((item) => item.name)).slice(0, 4);
  return defaultSteps.map((step, index) => ({
    ...step,
    name: configured[index] || step.name,
  }));
});

const LAYER_OPTIONS = ["核心层", "有形层", "延伸层"];
const MAX_STEP_TWO_IMAGES = 5;

const STEP_TWO_PLATFORM_OPTIONS = [
  { value: "京东", label: "京东", description: "3C/智能硬件类目数据全、评价真实" },
  { value: "天猫", label: "天猫", description: "品牌 AI 产品丰富，详情页设计成熟" },
  { value: "抖音电商", label: "抖音电商", description: "爆款 AI 玩具/家居新品多，价格带清晰" },
];

const STEP_TWO_SCENE_OPTIONS = [
  { value: "AI智能家居", label: "AI智能家居", description: "如 AI 音箱、AI 台灯、AI 门锁" },
  { value: "AI智能办公", label: "AI智能办公", description: "如 AI 鼠标、AI 录音笔、AI 翻译机" },
  { value: "AI儿童玩具", label: "AI儿童玩具", description: "如 AI 早教机器人、AI 对话玩偶" },
  { value: "AI学习设备", label: "AI学习设备", description: "如 AI 学习机、AI 点读笔" },
  { value: "AI美妆辅助", label: "AI美妆辅助", description: "如 AI 皮肤检测仪、AI 试妆镜" },
  { value: "其他场景", label: "其他场景", description: "填写你发现的其他高流量 AI 应用场景" },
];

const STEP_ONE_SELLING_POINTS = [
  { id: "selling-point-1", text: "生日礼物女孩子毕业儿童3到6岁10小女童" },
  { id: "selling-point-2", text: "AI智能机器人毛绒玩具" },
  { id: "selling-point-3", text: "豆包+DeepSeek六大混合模型，多语种AI对话" },
  { id: "selling-point-4", text: "覆盖百科、算术、语文、诗词、AI翻译等，早教能力强，还具备情绪感知安抚功能" },
  { id: "selling-point-5", text: "安全亲肤，零甲醛零荧光剂，母婴级不掉毛" },
  { id: "selling-point-6", text: "柔软手感，舒心无忧，内赠USB充电线" },
  { id: "selling-point-7", text: "嘴巴会动，翅膀煽动，脖子扭动，触摸感应触发，说话跳舞同步" },
  { id: "selling-point-8", text: "可自由定制角色/专属音色，打造宝宝专属小伙伴，适配哄睡、早教、陪伴多场景" },
  { id: "selling-point-9", text: "快递免运费，预计7小时内发货" },
  { id: "selling-point-10", text: "大促价保、假一赔四、极速退款、7天无理由退换" },
  { id: "selling-point-11", text: "店铺优惠后169元起" },
];

const createStep2Form = () => ({ platform: "", scene: "", customScene: "", keyword: "", productName: "", images: [] });

const createStep3Rows = () => [
  {
    dimension: "核心层",
    requirement: "说明产品解决的核心痛点、用户需求和核心利益。",
    example: "解决学生学习效率低、家长辅导时间不足等痛点，提供个性化学习支持。",
    product1: "",
    product2: "",
    product3: "",
  },
  {
    dimension: "有形层",
    requirement: "记录功能、设计、品牌、参数、包装、价格等可见要素。",
    example: "护眼屏、AI语音互动、拍照搜题、错题本、课程资源、学习报告。",
    product1: "",
    product2: "",
    product3: "",
  },
  {
    dimension: "延伸层",
    requirement: "分析售后、会员、内容更新、物流、生态兼容和数据安全等附加服务。",
    example: "课程持续更新、家长端管理、云端错题同步、售后保修、会员内容权益。",
    product1: "",
    product2: "",
    product3: "",
  },
];

const createStep4Form = () => ({
  coreValue: "",
  tangibleValue: "",
  extendedValue: "",
});

const classifications = ref({});
const checkResult = ref(null);
const step2Form = ref(createStep2Form());
const step3Rows = ref(createStep3Rows());
const step4Form = ref(createStep4Form());

const getLocalDraftKey = () => {
  const userInfo = userStore.userInfo || {};
  const userKey = userInfo.userId || userInfo.user_id || userInfo.username || userInfo.userName || "anonymous";
  return `${TASK_KEY}:draft:${userKey}`;
};

const currentStudyTip = computed(() => {
  const tips = {
    1: "当前步骤建议：先从案例或电商详情页中拆出核心层、有形层、延伸层，不要把功能和用户利益混在一起。",
    2: "当前步骤建议：选择一个主流电商平台与真实 AI 产品，用“核心词 + 属性词 + 场景词”搜索并保留主图、详情页截图。",
    3: "当前步骤建议：同一维度横向比较 3 个产品，重点找出 AI 技术在哪一层创造了差异化。",
    4: "当前步骤建议：把前面三步的发现收束为产品开发启发，说明哪些价值值得继续强化。",
  };
  return tips[currentStep.value];
});

const progressItems = computed(() =>
  steps.value.map((step) => ({
    text: `${currentStep.value > step.no ? "已完成" : currentStep.value === step.no ? "进行中" : "待完成"}：${step.name}`,
    status: currentStep.value > step.no ? "done" : currentStep.value === step.no ? "doing" : "",
  }))
);

onMounted(async () => {
  loadDraft();
  await loadTaskConfig();
  await loadSavedAnswer();
  draftReady.value = true;
});

watch(
  [classifications, checkResult, step2Form, step3Rows, step4Form, currentStep],
  () => persistDraft(),
  { deep: true }
);

function parseArray(value, fallback) {
  if (Array.isArray(value)) {
    return value.length ? value : fallback;
  }
  if (!value) {
    return fallback;
  }
  try {
    const parsed = JSON.parse(value);
    return Array.isArray(parsed) && parsed.length ? parsed : fallback;
  } catch (error) {
    const list = String(value)
      .split(/[；;|]/)
      .map((item) => item.trim())
      .filter(Boolean);
    return list.length ? list : fallback;
  }
}

function getStepName(no) {
  return steps.value.find((item) => item.no === no)?.name || defaultSteps[no - 1]?.name || "";
}

async function loadTaskConfig() {
  try {
    const res = await getTrainingTaskByKey(TASK_KEY);
    taskConfig.value = res?.data || null;
  } catch (error) {
    taskConfig.value = null;
  }
}

async function loadSavedAnswer() {
  try {
    const res = await getStudentTrainingAnswer(TASK_KEY);
    const answer = res?.data;
    if (answer && applySavedAnswer(answer)) {
      clearDraft();
    }
  } catch (error) {
    // 后端不可用时，页面仍允许学生直接填写。
  }
}

function safeParse(value) {
  if (!value) return null;
  if (typeof value === "object") return value;
  try {
    return JSON.parse(value);
  } catch (error) {
    return null;
  }
}

function applySavedAnswer(value) {
  const parsed = safeParse(value);
  if (!parsed || typeof parsed !== "object") return false;

  if (parsed.step1Answer || parsed.step2Answer || parsed.step3Answer || parsed.step4Answer) {
    let loaded = false;
    const step1Parsed = safeParse(parsed.step1Answer);
    if (step1Parsed?.step1Form || step1Parsed?.step2Form || step1Parsed?.step2Rows || step1Parsed?.step3Rows || step1Parsed?.step4Form) {
      loaded = applySavedAnswer(step1Parsed) || loaded;
    } else {
      loaded = applyStep1Answer(step1Parsed || parsed.step1Answer) || loaded;
    }
    loaded = applyStep2Answer(parsed.step2Answer) || loaded;
    loaded = applyStep3Answer(parsed.step3Answer) || loaded;
    loaded = applyStep4Answer(parsed.step4Answer) || loaded;
    currentStep.value = Math.min(Math.max(Number(parsed.currentStep || currentStep.value || 1), 1), 4);
    return loaded;
  }

  let loaded = false;
  loaded = applyStep1Answer(parsed.step1Form || parsed) || loaded;
  loaded = applyStep2Answer(parsed.step2Form || parsed.step2Answer || parsed.step2Rows || parsed.rows2 || parsed.platformRows) || loaded;
  loaded = applyStep3Answer(parsed.step3Rows || parsed.rows3 || parsed.layerRows) || loaded;
  loaded = applyStep4Answer(parsed.step4Form || parsed.aiValue || parsed.valueAnalysis) || loaded;
  currentStep.value = Math.min(Math.max(Number(parsed.currentStep || 1), 1), 4);
  return loaded;
}

function applyStep1Answer(value) {
  const parsed = safeParse(value);
  if (!parsed || typeof parsed !== "object") return false;
  const source = parsed.classifications || parsed.step1Form || parsed;
  const restored = STEP_ONE_SELLING_POINTS.reduce((result, point) => {
    if (LAYER_OPTIONS.includes(source?.[point.id])) {
      result[point.id] = source[point.id];
    }
    return result;
  }, {});
  classifications.value = restored;
  checkResult.value = normalizeCheckResult(parsed.checkResult);
  return Object.keys(restored).length > 0;
}

function normalizeCheckResult(value) {
  if (!value || typeof value !== "object" || !Array.isArray(value.items)) return null;
  const itemsById = value.items.reduce((result, item) => {
    if (item?.id) result[item.id] = item;
    return result;
  }, {});
  return {
    items: value.items,
    itemsById,
    correctCount: Number(value.correctCount || 0),
    totalCount: Number(value.totalCount || value.items.length),
    allCorrect: Boolean(value.allCorrect),
  };
}

function feedbackClass(id) {
  const item = checkResult.value?.itemsById?.[id];
  if (!item) return "";
  return item.correct ? "classification-row--correct" : "classification-row--incorrect";
}

function clearFeedback(id) {
  if (checkResult.value?.itemsById?.[id]) {
    checkResult.value = null;
  }
}

function hasCompletedClassifications() {
  return STEP_ONE_SELLING_POINTS.every((point) => LAYER_OPTIONS.includes(classifications.value[point.id]));
}

function buildCheckItems() {
  return STEP_ONE_SELLING_POINTS.map((point) => ({ id: point.id, category: classifications.value[point.id] }));
}

async function uploadStepTwoImages(event) {
  const input = event.target;
  const files = Array.from(input?.files || []);
  input.value = "";
  if (!files.length) return;
  if (files.some((file) => !file.type?.startsWith("image/"))) {
    proxy?.$modal?.msgWarning("只能上传图片文件");
    return;
  }
  if (step2Form.value.images.length + files.length > MAX_STEP_TWO_IMAGES) {
    proxy?.$modal?.msgWarning(`产品图片最多上传 ${MAX_STEP_TWO_IMAGES} 张`);
    return;
  }

  uploadingImages.value = true;
  try {
    for (const file of files) {
      const data = new FormData();
      data.append("file", file);
      const res = await uploadStudentTrainingFile(data);
      const url = res?.url || res?.fileName || res?.data?.url || res?.data?.fileName || "";
      if (!url) throw new Error("图片上传失败，请重试");
      step2Form.value.images.push({ name: res?.originalFilename || file.name, url });
    }
    proxy?.$modal?.msgSuccess("产品图片上传成功");
  } catch (error) {
    proxy?.$modal?.msgError(error?.message || "图片上传失败，请稍后重试");
  } finally {
    uploadingImages.value = false;
  }
}

function removeStepTwoImage(index) {
  step2Form.value.images.splice(index, 1);
}

function previewStepTwoImage(url) {
  imagePreviewUrl.value = url;
  imagePreviewOpen.value = true;
}

function applyStep2Answer(value) {
  const parsed = safeParse(value);
  if (!parsed || Array.isArray(parsed) || typeof parsed !== "object") return false;
  const source = parsed.step2Form || parsed;
  const fields = ["platform", "scene", "customScene", "keyword", "productName"];
  const images = Array.isArray(source.images)
    ? source.images.filter((image) => image?.url).slice(0, MAX_STEP_TWO_IMAGES).map((image) => ({ name: image.name || "产品图片", url: image.url }))
    : [];
  const hasValue = fields.some((field) => String(source[field] || "").trim()) || images.length;
  if (!hasValue) return false;
  step2Form.value = { ...createStep2Form(), ...pickFields(source, fields), images };
  return true;
}

function applyStep3Answer(value) {
  const parsed = safeParse(value);
  const rows = Array.isArray(parsed) ? parsed : parsed?.step3Rows || parsed?.rows || parsed?.layerRows;
  if (!Array.isArray(rows) || !rows.length) return false;
  step3Rows.value = normalizeRows(rows, createStep3Rows(), "dimension");
  return true;
}

function applyStep4Answer(value) {
  const parsed = safeParse(value);
  if (!parsed || typeof parsed !== "object") return false;
  const source = parsed.step4Form || parsed;
  const fields = Object.keys(createStep4Form());
  const hasValue = fields.some((key) => source[key] !== undefined && source[key] !== null && source[key] !== "");
  if (!hasValue) return false;
  step4Form.value = { ...createStep4Form(), ...pickFields(source, fields) };
  return true;
}

function pickFields(source, fields) {
  return fields.reduce((target, key) => {
    if (source[key] !== undefined && source[key] !== null) {
      target[key] = source[key];
    }
    return target;
  }, {});
}

function normalizeRows(rows, fallback, matchKey = "") {
  if (!Array.isArray(rows) || !rows.length) return fallback;
  if (matchKey) {
    const rowMap = rows.reduce((map, row) => {
      if (row?.[matchKey]) {
        map[row[matchKey]] = row;
      }
      return map;
    }, {});
    return fallback.map((row, index) => ({
      ...row,
      ...(rowMap[row[matchKey]] || rows[index] || {}),
    }));
  }
  return fallback.map((row, index) => ({
    ...row,
    ...(rows[index] || {}),
  }));
}

function buildAnswerPayload(status) {
  const saveAction = status === "SUBMITTED" ? "SUBMIT" : status === "RESET" ? "RESET" : "SAVE";
  return {
    saveAction,
    currentStep: currentStep.value,
    step1Answer: JSON.stringify({ classifications: classifications.value, checkResult: checkResult.value }),
    step2Answer: JSON.stringify(step2Form.value),
    step3Answer: JSON.stringify(step3Rows.value),
    step4Answer: JSON.stringify(step4Form.value),
  };
}

async function saveAnswer(status = "IN_PROGRESS", silent = false) {
  saving.value = true;
  try {
    await saveStudentTrainingAnswer(TASK_KEY, buildAnswerPayload(status));
    if (!silent) {
      proxy?.$modal?.msgSuccess(status === "SUBMITTED" ? "提交成功" : "保存成功");
    }
  } finally {
    saving.value = false;
  }
}

function saveCurrentProgress() {
  return saveAnswer("IN_PROGRESS");
}

function submitTask() {
  return saveAnswer("SUBMITTED");
}

async function nextStep() {
  if (currentStep.value === 2) {
    checking.value = true;
    try {
      await checkNewProductSurveyStepTwo(step2Form.value);
      await saveAnswer("IN_PROGRESS", true);
      proxy?.$modal?.msgSuccess("第二步信息已校验并保存");
      advanceStep();
    } catch (error) {
      proxy?.$modal?.msgWarning(error?.message || "请完善第二步调研信息后再进入下一步");
    } finally {
      checking.value = false;
    }
    return;
  }
  if (currentStep.value !== 1) {
    advanceStep();
    return;
  }
  if (!hasCompletedClassifications()) {
    proxy?.$modal?.msgWarning("请完成全部卖点分类后再进入下一步");
    return;
  }
  checking.value = true;
  try {
    const res = await checkNewProductSurveyStepOne(buildCheckItems());
    checkResult.value = normalizeCheckResult(res?.data);
    await saveAnswer("IN_PROGRESS", true);
    if (checkResult.value?.allCorrect) {
      proxy?.$modal?.msgSuccess("分类全部正确，已进入下一步");
      advanceStep();
    } else {
      proxy?.$modal?.msgWarning("存在分类错误，请根据提示修改后重新判题");
    }
  } catch (error) {
    proxy?.$modal?.msgError(error?.message || "判题失败，请稍后重试");
  } finally {
    checking.value = false;
  }
}

function advanceStep() {
  if (currentStep.value < steps.value.length) {
    currentStep.value += 1;
  }
}

function prevStep() {
  if (currentStep.value > 1) {
    currentStep.value -= 1;
  }
}

function resetExample() {
  classifications.value = {};
  checkResult.value = null;
  step2Form.value = createStep2Form();
  imagePreviewUrl.value = "";
  imagePreviewOpen.value = false;
  step3Rows.value = createStep3Rows();
  step4Form.value = createStep4Form();
  currentStep.value = 1;
  clearDraft();
}

function buildOutcome() {
  return {
    taskKey: TASK_KEY,
    taskName: taskTitle.value,
    taskId: taskConfig.value?.id || "",
    currentStep: currentStep.value,
    steps: steps.value.map((item) => item.name),
    classifications: classifications.value,
    checkResult: checkResult.value,
    step2Form: step2Form.value,
    step3Rows: step3Rows.value,
    step4Form: step4Form.value,
  };
}

function persistDraft() {
  if (!draftReady.value) return;
  try {
    localStorage.setItem(getLocalDraftKey(), JSON.stringify(buildOutcome()));
  } catch (error) {
    // 本地草稿只是兜底，后端保存仍是主来源。
  }
}

function loadDraft() {
  try {
    const raw = localStorage.getItem(getLocalDraftKey());
    if (raw) {
      applySavedAnswer(raw);
    }
  } catch (error) {
    clearDraft();
  }
}

function clearDraft() {
  try {
    localStorage.removeItem(getLocalDraftKey());
  } catch (error) {
    // 忽略浏览器存储异常。
  }
}

function exportOutcome() {
  const content = buildOutcome();
  const blob = new Blob([JSON.stringify(content, null, 2)], { type: "application/json;charset=utf-8" });
  const url = URL.createObjectURL(blob);
  const link = document.createElement("a");
  link.href = url;
  link.download = "新产品调查与分析-实训成果.json";
  link.click();
  URL.revokeObjectURL(url);
}
</script>

<style lang="scss" scoped>
.new-product-value-page {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(720px, 1fr) 340px;
  gap: 24px;
  width: 100%;
  min-height: calc(100vh - 106px);
  padding: 0 0 32px;
  color: #eef5ff;
  background: transparent;
}

.training-core {
  padding: 28px;
  border: 1px solid rgba(0, 180, 255, 0.25);
  border-radius: 36px;
  background: rgba(8, 18, 28, 0.6);
  box-shadow: 0 22px 48px rgba(0, 0, 0, 0.22), inset 0 1px 0 rgba(169, 229, 255, 0.08);
  backdrop-filter: blur(8px);
}

.task-header {
  margin-bottom: 24px;
}

.task-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 12px;
  padding: 4px 14px;
  border: 1px solid rgba(0, 170, 255, 0.5);
  border-radius: 30px;
  color: #d6f6ff;
  background: rgba(0, 170, 255, 0.2);
  font-size: 12px;
  font-weight: 700;
}

.task-title {
  margin: 0;
  color: transparent;
  background: linear-gradient(135deg, #ffffff, #8bcbff);
  -webkit-background-clip: text;
  background-clip: text;
  font-size: 30px;
  line-height: 1.3;
  font-weight: 900;
}

.goal-bg,
.task-card,
.step-card {
  margin-bottom: 28px;
  padding: 18px 22px;
  border: 1px solid rgba(82, 174, 226, 0.42);
  border-radius: 26px;
  background: rgba(0, 25, 42, 0.64);
}

.goal-bg {
  p {
    margin: 0;
    color: #d7ecff;
    font-size: 14px;
    line-height: 1.8;
  }
}

.subtitle-icon {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  color: #b9e2ff;
  font-weight: 800;
}

.subtitle-icon--spaced {
  margin-top: 12px;
}

.workbench-head,
.step-title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
}

.workbench-head {
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(0, 180, 255, 0.2);

  h3 {
    margin: 4px 0 8px;
    color: #ffffff;
    font-size: 26px !important;
    font-weight: 800 !important;
    line-height: 1.3 !important;
  }
}

.workbench-head--actions-only {
  justify-content: flex-end;
  margin-bottom: 18px;
  padding-bottom: 0;
  border-bottom: 0;
}

.workbench-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.section-eyebrow {
  margin: 0;
  color: #71dfff;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.4;
}

.workbench-description {
  margin: 0;
  color: #d7ecff;
  font-size: 15px;
  font-weight: 400;
  line-height: 1.8;
}

.outline-action,
.btn-nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 18px;
  border: 1px solid rgba(99, 217, 255, 0.55);
  border-radius: 999px;
  color: #e9fbff;
  background: rgba(17, 126, 178, 0.36);
  font-family: inherit;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;

  &:hover:not(:disabled) {
    transform: translateY(-1px);
    border-color: rgba(116, 235, 255, 0.85);
    background: rgba(18, 146, 204, 0.5);
  }

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

.step-indicator {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0;
  width: calc(100% + 24px);
  margin: 0 -12px 32px;
  padding: 18px 22px;
  overflow-x: auto;
  border: 1px solid rgba(0, 180, 255, 0.3);
  border-radius: 18px;
  background:
    linear-gradient(90deg, rgba(6, 42, 61, 0.58), rgba(1, 18, 31, 0.42)),
    rgba(0, 0, 0, 0.3);
  box-shadow: inset 0 1px 0 rgba(145, 233, 255, 0.08);
  scrollbar-width: thin;
}

.step-tab {
  display: flex;
  flex: 1 0 145px;
  align-items: center;
  min-width: 0;
  min-height: 66px;
  padding: 8px 10px;
  border: 1px solid rgba(68, 141, 177, 0.35);
  border-radius: 8px;
  color: #9ab3d0;
  background: rgba(3, 27, 43, 0.52);
  box-shadow: inset 0 1px 0 rgba(135, 221, 255, 0.04);
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: transform 0.2s ease, color 0.2s ease, border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;

  &:hover {
    border-color: rgba(89, 223, 255, 0.82);
    color: #ffffff;
    background: rgba(8, 92, 131, 0.52);
    box-shadow: 0 7px 18px rgba(0, 0, 0, 0.24), inset 0 1px 0 rgba(152, 239, 255, 0.16);
    transform: translateY(-2px);

    .step-action {
      color: #9bf4ff;
    }
  }

  &:focus-visible {
    outline: 2px solid #72e8ff;
    outline-offset: 4px;
  }

  &.active {
    border-color: rgba(89, 226, 255, 0.85);
    color: #ffffff;
    background: linear-gradient(115deg, rgba(4, 109, 155, 0.78), rgba(5, 62, 102, 0.64));
    box-shadow: 0 0 18px rgba(24, 183, 235, 0.22), inset 0 1px 0 rgba(176, 246, 255, 0.2);

    .step-marker {
      border-color: #72e8ff;
      color: #ffffff;
      background: linear-gradient(135deg, #08b7e8, #1375d0);
      box-shadow: 0 0 0 5px rgba(25, 179, 237, 0.14), 0 0 18px rgba(46, 208, 255, 0.58);
    }

  }

  &.complete {
    color: #dffbff;

    .step-marker {
      border-color: rgba(84, 230, 221, 0.85);
      color: #062b37;
      background: #6ef0e1;
      box-shadow: 0 0 12px rgba(79, 231, 218, 0.35);
    }
  }
}

.step-marker {
  display: inline-flex;
  flex: 0 0 38px;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(101, 176, 208, 0.6);
  border-radius: 50%;
  color: #a6c4d9;
  background: rgba(3, 25, 40, 0.8);
  box-shadow: inset 0 0 12px rgba(38, 174, 233, 0.08);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.04em;
  transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.step-copy {
  display: grid;
  min-width: 0;
  gap: 4px;
  margin-left: 10px;
}

.step-name {
  display: -webkit-box;
  overflow: hidden;
  color: inherit;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.25;
  text-overflow: ellipsis;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.step-action {
  color: #66b6d4;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  line-height: 1;
  transition: color 0.2s ease;
}

.step-connector {
  position: relative;
  flex: 0 1 40px;
  min-width: 18px;
  height: 2px;
  margin: 0 8px;
  overflow: visible;
  background: rgba(98, 169, 201, 0.34);

  &::after {
    position: absolute;
    top: 50%;
    right: -1px;
    width: 6px;
    height: 6px;
    border-top: 1px solid #73b1ce;
    border-right: 1px solid #73b1ce;
    content: '';
    transform: translateY(-50%) rotate(45deg);
  }
}

.step-tab.complete + .step-connector {
  background: linear-gradient(90deg, #6ef0e1, #1cb8e9);
  box-shadow: 0 0 9px rgba(53, 218, 235, 0.46);

  &::after {
    border-color: #63e6f1;
  }
}

.step-content {
  animation: fade 0.2s ease;
}

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

.step-card {
  margin-bottom: 0;
}

.step-title-row {
  margin-bottom: 14px;

  h3 {
    margin: 4px 0 0;
    color: #ffffff;
    font-size: 22px;
    font-weight: 900;
  }
}

.step-chip {
  flex: 0 0 auto;
  padding: 6px 12px;
  border: 1px solid rgba(106, 226, 255, 0.45);
  border-radius: 999px;
  color: #c8f4ff;
  background: rgba(0, 127, 184, 0.25);
  font-size: 12px;
  font-weight: 800;
}

.step-desc {
  margin: 0 0 20px;
  color: #d7ecff;
  font-size: 15px;
  line-height: 1.8;
}

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

  &.three {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.field-block {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
  color: #dff5ff;
  font-size: 14px;
  font-weight: 800;

  > span {
    line-height: 1.6;
  }
}

.input-field,
.input-single,
.cell-input,
.cell-textarea {
  width: 100%;
  border: 1px solid rgba(45, 95, 126, 0.95);
  border-radius: 14px;
  color: #eef5ff;
  background: #0f1a24;
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;

  &::placeholder {
    color: #8299aa;
  }

  &:focus {
    border-color: rgba(92, 224, 255, 0.7);
    box-shadow: 0 0 0 3px rgba(0, 174, 255, 0.13);
  }
}

.input-field {
  min-height: 110px;
  padding: 12px 14px;
  resize: vertical;
  line-height: 1.65;
}

.input-single {
  min-height: 42px;
  padding: 0 14px;
}

.price-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.price-option {
  min-height: 42px;
  border: 1px solid rgba(45, 95, 126, 0.95);
  border-radius: 14px;
  color: #b9d6e8;
  background: rgba(15, 26, 36, 0.86);
  font-family: inherit;
  font-weight: 800;
  cursor: pointer;

  &.active {
    color: #ffffff;
    border-color: rgba(92, 224, 255, 0.75);
    background: linear-gradient(95deg, #0a6b9e, #0a5c86);
  }
}

.survey-form {
  display: grid;
  gap: 18px;
}

.survey-field-group {
  padding: 16px;
  border: 1px solid rgba(74, 186, 234, 0.24);
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(8, 51, 77, 0.48), rgba(1, 21, 36, 0.5));
}

.survey-field-title {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0 0 12px;
  color: #f0fbff;
  font-size: 16px;
  font-weight: 900;

  b {
    display: inline-grid;
    width: 24px;
    height: 24px;
    place-items: center;
    border-radius: 50%;
    color: #062236;
    background: #66dcff;
    font-size: 12px;
  }
}

.survey-field-hint {
  margin: -4px 0 13px 33px;
  color: #a9cee2;
  font-size: 13px;
  line-height: 1.65;
}

.survey-options {
  display: grid;
  gap: 9px;
}

:deep(.survey-option.el-radio) {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: start;
  height: auto;
  margin-right: 0;
  padding: 10px 12px;
  border: 1px solid rgba(67, 140, 181, 0.38);
  border-radius: 12px;
  color: #c9e8f7;
  background: rgba(5, 30, 48, 0.52);
  transition: border-color 0.18s ease, background 0.18s ease;

  .el-radio__label {
    display: grid;
    gap: 4px;
    padding-left: 9px;
    white-space: normal;
  }

  strong {
    color: #f2fbff;
    font-weight: 800;
  }

  span {
    color: #9fc6da;
    font-size: 12px;
    line-height: 1.55;
  }

  &.is-checked {
    border-color: rgba(100, 226, 255, 0.82);
    background: rgba(8, 109, 151, 0.38);
  }
}

.custom-scene-input {
  margin-top: 10px;
}

.product-name-field {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  color: #dff5ff;
  font-size: 14px;
  font-weight: 800;
}

.image-upload-trigger {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  border: 1px dashed rgba(104, 224, 255, 0.75);
  border-radius: 12px;
  color: #e8fbff;
  background: rgba(13, 107, 151, 0.34);
  font-weight: 800;
  cursor: pointer;
  transition: background 0.18s ease, transform 0.18s ease;

  input {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  &:hover:not(.disabled) {
    transform: translateY(-1px);
    background: rgba(21, 144, 194, 0.48);
  }

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

.product-image-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.product-image-card {
  display: grid;
  gap: 7px;
  min-width: 0;
  margin: 0;
  padding: 8px;
  border: 1px solid rgba(79, 169, 217, 0.35);
  border-radius: 12px;
  background: rgba(1, 18, 31, 0.62);

  figcaption {
    overflow: hidden;
    color: #b9d9e8;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.product-image-preview {
  aspect-ratio: 1.2;
  overflow: hidden;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: #06131d;
  cursor: zoom-in;

  img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.2s ease;
  }

  &:hover img {
    transform: scale(1.05);
  }
}

.remove-image-button {
  justify-self: start;
  padding: 0;
  border: 0;
  color: #ff9eaf;
  background: transparent;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.product-image-full {
  display: block;
  width: 100%;
  max-height: 72vh;
  object-fit: contain;
}

.training-table-wrap {
  overflow-x: auto;
  border: 1px solid rgba(0, 180, 255, 0.22);
  border-radius: 22px;
  background: rgba(1, 14, 26, 0.72);
}

.training-data-table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;

  th,
  td {
    border: 1px solid rgba(77, 167, 220, 0.2);
    padding: 12px;
    vertical-align: top;
  }

  th {
    color: #eaffff;
    background: rgba(8, 55, 82, 0.98);
    font-size: 14px;
    font-weight: 900;
    text-align: center;
  }

  td {
    color: #d7f1ff;
    background: rgba(1, 14, 26, 0.48);
  }
}

.cell-input {
  min-height: 38px;
  padding: 0 10px;
}

.cell-textarea {
  min-height: 118px;
  padding: 10px;
  resize: vertical;
  line-height: 1.6;
}

.dimension-cell {
  color: #eafaff;
  font-weight: 900;
  text-align: center;
}

.requirement-cell,
.example-cell {
  min-width: 170px;
  color: #cfe8f8;
  line-height: 1.65;
}

.example-cell {
  color: #f5d99d;
}

.example-hint {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px solid rgba(250, 204, 21, 0.28);
  border-radius: 16px;
  color: #f6e5a7;
  background: rgba(120, 92, 8, 0.16);
  font-size: 13px;
  line-height: 1.6;
}

.step-navigation,
.task-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
  margin-top: 22px;
}

.task-actions {
  gap: 52px;
  margin-top: 36px;
}

.task-actions .btn-nav {
  min-width: 172px;
  min-height: 64px;
  padding: 0 28px;
  border: 1px solid #2c83aa;
  border-radius: 6px;
  color: #dff7ff;
  background: rgba(13, 64, 88, 0.62);
  box-shadow: none;
  font-size: 24px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0;
  text-shadow: none;
}

.task-actions .btn-nav .el-icon {
  display: none;
}

.task-actions .btn-nav:hover:not(:disabled) {
  border-color: #46b5e7;
  color: #ffffff;
  background: rgba(18, 85, 116, 0.78);
}

.btn-primary,
.btn-submit,
.btn-save {
  border-color: rgba(92, 224, 255, 0.7);
  color: #ffffff;
  background: linear-gradient(95deg, #0b84bd, #096491);
}

.task-actions .btn-submit,
.task-actions .btn-save {
  border-color: #2c83aa;
  color: #dff7ff;
  background: rgba(13, 64, 88, 0.62);
}

.classification-table-wrap {
  margin-top: 20px;
}

.classification-table th:first-child,
.classification-table td:first-child {
  width: 84px;
  text-align: center;
}

.classification-table th:last-child,
.classification-table td:last-child {
  width: 240px;
}

.classification-number {
  color: #9bdcff;
  font-weight: 800;
}

.classification-selling-point {
  line-height: 1.65;
}

.classification-select-cell :deep(.el-select) {
  width: 100%;
}

.classification-row--correct td {
  background: rgba(23, 181, 121, 0.12);
}

.classification-row--incorrect td {
  background: rgba(239, 91, 91, 0.13);
}

.classification-feedback,
.classification-summary {
  margin: 8px 0 0;
  color: #ffb1b1;
  font-size: 12px;
  line-height: 1.45;
}

.classification-row--correct .classification-feedback,
.classification-summary.is-success {
  color: #86e7bd;
}

.classification-summary {
  margin-top: 16px;
  font-size: 14px;
  font-weight: 700;
}

@media (max-width: 1100px) {
  .new-product-value-page {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .training-core {
    padding: 18px;
    border-radius: 24px;
  }

  .step-indicator,
  .step-navigation,
  .task-actions,
  .workbench-actions,
  .workbench-head,
  .step-title-row {
    flex-direction: column;
    align-items: stretch;
  }

  .step-tab,
  .outline-action,
  .btn-nav {
    width: 100%;
  }

  .step-indicator {
    width: 100%;
    margin: 0 0 32px;
    padding: 16px;
    border-radius: 20px;
    overflow-x: visible;
  }

  .step-tab {
    flex: 0 0 auto;
    min-width: 0;
  }

  .step-connector {
    flex: 0 0 20px;
    align-self: flex-start;
    width: 2px;
    min-width: 0;
    height: 20px;
    margin: 4px 0 4px 18px;

    &::after {
      top: auto;
      right: auto;
      bottom: -1px;
      left: 50%;
      transform: translateX(-50%) rotate(135deg);
    }
  }

  .form-grid,
  .form-grid.three,
  .price-options {
    grid-template-columns: 1fr;
  }

  .classification-table {
    min-width: 720px;
  }
}
</style>


