/* ==========================================================
   添加试卷页 —— 上传 / 生成 / 保存
   复用 common.css 的设计令牌（变量、卡片、按钮、提示条等）
   ========================================================== */

.ap-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 22px;
}

/* ---------- 基本信息 ---------- */
.ap-fields {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.ap-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 220px;
  flex: 1;
}
.ap-field.grow { flex: 2; }
.ap-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.ap-label .req { color: var(--bad); }
.ap-label .hint { font-weight: 400; color: var(--text-3); font-size: 12px; }
.ap-input {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.ap-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

/* ---------- 上传区 ---------- */
.ap-uploads { display: grid; gap: 14px; }
.ap-zone {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 14px;
  background: var(--surface-2);
  transition: border-color .15s, background .15s;
}
.ap-zone.drag {
  border-color: var(--accent);
  background: #eff6ff;
}
.ap-zone-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.ap-zone-title { font-size: 14px; font-weight: 700; color: var(--text); }
.ap-zone-title .req { color: var(--bad); }
.ap-zone-title .hint { font-weight: 400; color: var(--text-3); }
.ap-zone-sub { font-size: 12px; color: var(--text-2); margin-top: 2px; }

.ap-thumbs { display: flex; flex-wrap: wrap; gap: 10px; }
.ap-thumb {
  position: relative;
  width: 108px;
  height: 108px;
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
  background: #fff;
  box-shadow: var(--shadow-sm);
}
.ap-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.ap-thumb-n {
  position: absolute;
  left: 6px;
  top: 6px;
  background: rgba(15, 23, 42, .6);
  color: #fff;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
}
.ap-thumb-x {
  position: absolute;
  right: 5px;
  top: 5px;
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 50%;
  background: rgba(220, 38, 38, .88);
  color: #fff;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.ap-thumb-x:hover { background: #b91c1c; }
.ap-empty {
  font-size: 12px;
  color: var(--text-3);
  padding: 6px 2px;
}

/* ---------- 操作与状态 ---------- */
.ap-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
  flex-wrap: wrap;
}
.ap-status { font-size: 13px; color: var(--text-2); }
.ap-status.bad { color: var(--bad); }
.ap-status.ok { color: var(--ok); }
.ap-status a { font-weight: 600; }

/* ---------- 预览 ---------- */
.ap-preview {
  border-top: 1px solid var(--line);
  margin-top: 22px;
  padding-top: 18px;
}
.ap-preview .section-title { margin-top: 0; }
.ap-preview-body { margin-top: 4px; }
.ap-preview-stats .stat-row { margin-bottom: 0; }
.ap-preview-note { margin-top: 12px; }
.ap-preview-tip {
  font-size: 13px;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

/* ---------- 试题配图预览 ---------- */
.ap-figure-wrap { margin-top: 14px; }
.ap-figure-title { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.ap-figure-strip { display: flex; flex-wrap: wrap; gap: 10px; }
.ap-fig {
  position: relative;
  width: 150px;
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
  background: #fff;
  box-shadow: var(--shadow-sm);
}
.ap-fig img { width: 100%; max-height: 160px; object-fit: contain; background: #fff; display: block; }
.ap-fig-meta {
  font-size: 11px;
  color: var(--text-2);
  padding: 4px 8px 7px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}
.ap-fig-x {
  position: absolute;
  right: 5px;
  top: 5px;
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 50%;
  background: rgba(220, 38, 38, .88);
  color: #fff;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.ap-fig-x:hover { background: #b91c1c; }
.ap-fig-edit {
  position: absolute;
  right: 28px;
  top: 5px;
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 50%;
  background: rgba(37, 99, 235, .85);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.ap-fig-edit:hover { background: #1d4ed8; }

/* ---------- 配图裁剪微调 ---------- */
.ap-fig-editor-box { width: min(620px, calc(100vw - 32px)); }
.ap-fig-editor-stage {
  display: flex;
  justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px;
  margin-bottom: 8px;
}
.ap-fig-editor-stage canvas {
  max-width: 100%;
  cursor: crosshair;
  touch-action: none;
}

/* ---------- 手动添加配图 ---------- */
.ap-addfig-btn { margin-top: 10px; }
.ap-addfig-srcs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.ap-addfig-src {
  width: 64px;
  border: 2px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  background: #fff;
  text-align: center;
}
.ap-addfig-src img { width: 100%; height: 48px; object-fit: cover; display: block; }
.ap-addfig-src span { display: block; font-size: 11px; color: var(--text-2); padding: 2px 0; }
.ap-addfig-src.sel { border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37, 99, 235, .2); }
.ap-addfig-form { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.ap-addfig-form label { font-size: 13px; color: var(--text); display: inline-flex; align-items: center; gap: 6px; }
.ap-addfig-form input, .ap-addfig-form select {
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
  color: var(--text);
}

/* ---------- 使用说明 ---------- */
.ap-tips {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px 20px;
}
.ap-tips .section-title { margin-top: 0; }
.ap-tips ol { margin: 8px 0 0; padding-left: 20px; color: var(--text-2); font-size: 13px; line-height: 1.9; }
.ap-tips code {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 12px;
}

@media (max-width: 720px) {
  .ap-field { min-width: 100%; }
  .ap-thumb { width: 86px; height: 86px; }
}

/* ---------- 生成模型设置弹窗 ---------- */
.ap-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.ap-box {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(15, 23, 42, .25);
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  overflow: auto;
  padding: 22px 24px;
}
.ap-box h3 { font-size: 17px; font-weight: 700; margin: 0 0 6px; color: var(--text); }
.ap-sub { font-size: 13px; color: var(--text-2); line-height: 1.7; margin: 0 0 16px; }
.ap-sub b { color: var(--bad); }
.ap-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.ap-field label { font-size: 13px; font-weight: 600; color: var(--text); }
.ap-field input {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  outline: none;
}
.ap-field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.ap-msg { font-size: 13px; color: var(--text-2); min-height: 18px; margin-bottom: 12px; }
.ap-msg.ok { color: var(--ok); }
.ap-msg.bad { color: var(--bad); }
.ap-box .btn-row { display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- 深色主题 ---------- */
.dark .ap-input { background: var(--surface); }
.dark .ap-zone.drag { background: #172554; }
.dark .ap-thumb, .dark .ap-fig, .dark .ap-addfig-src { background: var(--surface); }
.dark .ap-addfig-form input, .dark .ap-addfig-form select { background: var(--surface); }
.dark .ap-box { background: var(--surface); }
.dark .ap-field input { background: var(--surface); }
