/* ============================================================
   style.css — 错题管理系统样式
   移动优先（Mobile First）+ 桌面端媒体查询增强
   ============================================================ */

:root {
  --primary: #4a7dff;
  --primary-dark: #3563d8;
  --success: #2bad6b;
  --danger: #e05252;
  --bg: #f3f5f9;
  --card: #ffffff;
  --text: #23293d;
  --text-2: #6b7591;
  --border: #e4e8f0;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(35, 41, 61, .07);
  --header-h: 56px;
  --bottomnav-h: calc(56px + env(safe-area-inset-bottom));
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { text-decoration: none; color: inherit; }

/* ==================== 布局骨架 ==================== */

.app-shell { min-height: 100vh; }

/* 顶栏（手机端） */
.app-header {
  position: sticky; top: 0; z-index: 50;
  height: var(--header-h);
  display: flex; align-items: center;
  padding: 0 16px;
  padding-top: env(safe-area-inset-top);
  background: var(--primary);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.05rem; }
.brand-logo { font-size: 1.3rem; }
.side-nav { display: none; } /* 手机端隐藏侧边导航，用底部导航 */

.app-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 14px calc(var(--bottomnav-h) + 70px);
}

/* 底部导航（手机端） */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  height: var(--bottomnav-h);
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: #fff;
  border-top: 1px solid var(--border);
}
.bottom-nav .nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; font-size: .72rem; color: var(--text-2);
}
.bottom-nav .nav-item span { font-size: 1.25rem; line-height: 1; }
.bottom-nav .nav-item.active { color: var(--primary); font-weight: 600; }

/* 悬浮新增按钮 */
.fab {
  position: fixed; z-index: 49;
  right: 18px; bottom: calc(var(--bottomnav-h) + 16px);
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary); color: #fff;
  font-size: 1.9rem; line-height: 54px; text-align: center;
  box-shadow: 0 4px 14px rgba(74, 125, 255, .45);
}
.fab:active { transform: scale(.94); }

/* ==================== 通用组件 ==================== */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border: none; border-radius: 10px;
  background: #eef1f7; cursor: pointer; font-size: .95rem;
  transition: filter .15s, transform .1s;
  min-height: 42px; /* 触屏友好 */
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text-2); }
.btn.lg { padding: 13px 26px; font-size: 1.02rem; }
.btn.sm { padding: 5px 12px; min-height: 32px; font-size: .82rem; border-radius: 8px; }
.btn[disabled] { opacity: .45; pointer-events: none; }

.chip {
  border: 1px solid var(--border); background: #fff;
  border-radius: 999px; padding: 6px 14px; font-size: .85rem;
  cursor: pointer; white-space: nowrap; color: var(--text-2);
  display: inline-flex; align-items: center; gap: 5px;
  min-height: 34px;
}
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip.on .dot { background: #fff !important; }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.lg { width: 12px; height: 12px; }

.tag {
  display: inline-block; padding: 1px 9px; border-radius: 999px;
  font-size: .75rem; font-weight: 600;
}
.tag.gray { background: #eef1f7; color: var(--text-2); }

.status { font-size: .78rem; font-weight: 700; padding: 2px 10px; border-radius: 999px; }
.status.lg { font-size: .9rem; padding: 4px 14px; }
.st-pending { background: #fdeaea; color: #d04444; }
.st-doing   { background: #fff4e0; color: #c07f10; }
.st-done    { background: #e3f7ec; color: #1d9455; }

.empty {
  text-align: center; color: var(--text-2);
  padding: 60px 20px; font-size: .95rem;
}
.empty.sm { padding: 26px 10px; font-size: .85rem; }

.tip { font-size: .82rem; color: var(--text-2); margin-top: 10px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--bottomnav-h) + 20px); z-index: 200;
  transform: translateX(-50%) translateY(20px);
  background: rgba(30, 36, 56, .92); color: #fff;
  padding: 10px 22px; border-radius: 999px; font-size: .9rem;
  opacity: 0; transition: all .3s; pointer-events: none;
  max-width: 86vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: rgba(208, 68, 68, .95); }

/* Modal 确认框 */
.modal-mask {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(20, 25, 45, .5);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal {
  background: #fff; border-radius: var(--radius);
  padding: 22px; width: 100%; max-width: 360px;
}
.modal h3 { font-size: 1.05rem; margin-bottom: 8px; }
.modal p { font-size: .9rem; color: var(--text-2); margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* 图片灯箱 */
.lightbox {
  position: fixed; inset: 0; z-index: 400;
  background: rgba(0, 0, 0, .9);
  display: flex; align-items: center; justify-content: center;
}
.lightbox img { max-width: 96vw; max-height: 92vh; object-fit: contain; }

/* ==================== 列表页 ==================== */

.stat-row { display: flex; gap: 10px; margin-bottom: 10px; }
.stat-chip {
  background: var(--card); border-radius: 10px; box-shadow: var(--shadow);
  padding: 8px 14px; font-size: .85rem; color: var(--text-2);
}
.stat-chip b { color: var(--primary); font-size: 1.05rem; }
.stat-chip.done b { color: var(--success); }

.search-box { margin-bottom: 10px; }
.search-box input {
  width: 100%; padding: 11px 16px;
  border: 1px solid var(--border); border-radius: 10px; background: #fff;
  font-size: .95rem; outline: none;
}
.search-box input:focus { border-color: var(--primary); }

.filter-row {
  display: flex; gap: 8px; overflow-x: auto;
  padding: 4px 0 8px; -webkit-overflow-scrolling: touch;
}
.filter-row::-webkit-scrollbar { display: none; }

.card-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin-top: 4px; }

.q-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; overflow: hidden; cursor: pointer;
  transition: transform .12s;
}
.q-card:active { transform: scale(.985); }

.q-card .thumb {
  width: 96px; min-height: 96px; flex-shrink: 0;
  background: #e9edf4 center/cover no-repeat;
  display: flex; align-items: center; justify-content: center;
}
.no-img { color: #aab3c5; font-size: .78rem; }

.q-body { flex: 1; padding: 10px 12px; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.q-title {
  font-weight: 600; font-size: .95rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.q-meta { display: flex; gap: 6px; flex-wrap: wrap; }
.q-foot {
  margin-top: auto;
  display: flex; align-items: center; justify-content: space-between;
}
.time { font-size: .75rem; color: #a4adc0; }

/* ==================== 详情页 ==================== */

.detail {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 16px;
}
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.detail-head h2 { font-size: 1.15rem; line-height: 1.4; }

.kv-row { display: flex; flex-direction: column; gap: 2px; margin-bottom: 6px; }
.kv { display: flex; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--border); font-size: .9rem; }
.kv .k { color: var(--text-2); width: 76px; flex-shrink: 0; }
.kv .v { flex: 1; }

.sec-title {
  font-weight: 700; font-size: .92rem; margin: 16px 0 8px;
  padding-left: 10px; border-left: 3px solid var(--primary);
}
.text-block {
  background: #f7f9fc; border-radius: 10px; padding: 12px 14px;
  font-size: .9rem; color: var(--text); word-break: break-word;
}

.img-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.img-cell {
  position: relative; aspect-ratio: 1;
  background: #e9edf4 center/cover no-repeat;
  border-radius: 10px; cursor: zoom-in; overflow: hidden;
}
.img-cell .img-del {
  position: absolute; top: 4px; right: 4px; z-index: 2;
  width: 26px; height: 26px; border-radius: 50%; border: none;
  background: rgba(0, 0, 0, .55); color: #fff; font-size: 1rem;
  cursor: pointer; line-height: 1;
}

.detail-actions { display: flex; gap: 10px; margin-top: 22px; flex-wrap: wrap; }
.detail-actions .btn { flex: 1; min-width: 100px; }

/* ==================== 表单页 ==================== */

.form {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 16px;
}
.form h2 { font-size: 1.15rem; margin-bottom: 14px; }

.field { display: block; margin-bottom: 14px; }
.f-label { display: block; font-size: .85rem; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.f-label i { font-style: normal; font-weight: 400; color: #a4adc0; }

.field input[type="text"], .field select, .field textarea, .cat-add input {
  width: 100%; padding: 11px 13px;
  border: 1px solid var(--border); border-radius: 10px;
  font-size: .95rem; outline: none; background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); }
.field textarea { resize: vertical; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* 上传区 */
.upload-zone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 16px; text-align: center; transition: border-color .15s, background .15s;
}
.upload-zone.over { border-color: var(--primary); background: #f0f5ff; }
.up-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.up-btn { cursor: pointer; }
.up-tip { font-size: .78rem; color: #a4adc0; margin-top: 10px; }
.up-progress { margin-top: 10px; font-size: .85rem; color: var(--primary); }

#formImgs { margin-top: 12px; }
#formImgs .img-cell { cursor: default; }

.form-actions { display: flex; gap: 10px; margin-top: 20px; }
.form-actions .btn-primary { flex: 2; }
.form-actions .btn-ghost { flex: 1; }

/* ==================== 分类管理 ==================== */

.cat-add { display: flex; gap: 10px; margin-bottom: 16px; }
.cat-add input { flex: 1; }

.cat-list { display: flex; flex-direction: column; gap: 8px; }
.cat-item {
  display: flex; align-items: center; gap: 10px;
  background: #f7f9fc; border-radius: 10px; padding: 10px 14px;
}
.cat-name { font-weight: 600; font-size: .95rem; }
.cat-count { margin-left: auto; font-size: .8rem; color: var(--text-2); }

/* ============================================================
   桌面端适配（≥768px）
   ============================================================ */
@media (min-width: 768px) {

  .app-shell { display: flex; }

  /* 侧边栏 */
  .app-header {
    position: sticky; top: 0; height: 100vh;
    width: 220px; flex-shrink: 0;
    flex-direction: column; align-items: stretch;
    padding: 22px 14px;
  }
  .brand { margin-bottom: 28px; justify-content: center; font-size: 1.1rem; }
  .side-nav { display: flex; flex-direction: column; gap: 6px; }
  .side-nav .nav-item {
    padding: 11px 16px; border-radius: 10px;
    font-size: .95rem; color: rgba(255, 255, 255, .82);
    transition: background .15s;
  }
  .side-nav .nav-item:hover { background: rgba(255, 255, 255, .12); }
  .side-nav .nav-item.active { background: rgba(255, 255, 255, .2); color: #fff; font-weight: 600; }

  .app-main {
    flex: 1; max-width: none;
    padding: 26px 30px 60px;
  }

  /* 隐藏手机端专属元素 */
  .bottom-nav { display: none; }
  .fab { bottom: 30px; right: 34px; width: 60px; height: 60px; line-height: 58px; }

  /* 列表：多列卡片 */
  .card-grid { grid-template-columns: repeat(2, 1fr); gap: 16px; }
  .q-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(35, 41, 61, .12); }
  .q-card .thumb { width: 130px; min-height: 110px; }

  /* 内容最大宽度控制 */
  .detail, .form { max-width: 760px; padding: 26px 28px; }
  .list-head { max-width: 1100px; }

  .img-grid { grid-template-columns: repeat(4, 1fr); gap: 12px; }

  .toast { bottom: 36px; }
}

/* 超宽屏（≥1280px）：三列卡片 */
@media (min-width: 1280px) {
  .card-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ============================================================
   v2 AI 化升级：看板 / 拍卷 / 诊断确认
   ============================================================ */

/* ---------- 薄弱点看板 ---------- */

.board-head {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}

/* 销号进度环（--pct: 0-100） */
.ring {
  width: 84px; height: 84px; border-radius: 50%; flex-shrink: 0;
  background: conic-gradient(var(--success) calc(var(--pct) * 1%), #edf0f6 0);
  display: flex; align-items: center; justify-content: center;
}
.ring-in {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--card);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.ring-in b { font-size: 1.05rem; color: var(--success); line-height: 1.2; }
.ring-in span { font-size: .68rem; color: var(--text-2); }

.board-stats { display: flex; gap: 8px; flex-wrap: wrap; flex: 1; min-width: 180px; }
.btn-scan { margin-left: auto; }

.focus-strip {
  background: #fff8ec; border: 1px solid #ffe1ad;
  border-radius: var(--radius); padding: 10px 14px;
  font-size: .85rem; color: #8a5a00; margin: 12px 0;
}
.focus-strip b { color: #c0780a; }

/* 列切换 Tab（手机端） */
.board-tabs { display: flex; gap: 8px; margin: 12px 0 10px; }
.board-tab {
  flex: 1; border: 1px solid var(--border); background: #fff;
  border-radius: 10px; padding: 8px 4px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-size: .78rem; color: var(--text-2);
}
.board-tab b { font-size: 1rem; color: var(--text); }
.board-tab.on { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary) inset; }

.board-cols { display: grid; grid-template-columns: 1fr; gap: 12px; }
.board-col { display: none; flex-direction: column; gap: 10px; align-content: flex-start; }
.board-col.show { display: flex; }
.board-col-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 2px 4px;
}
.board-col-head b { color: var(--text-2); }

/* 薄弱点卡片 */
.kcard { cursor: default; }
.kcard .q-foot { align-items: center; gap: 8px; flex-wrap: wrap; }
.tag-warn { background: #fff4e0; color: #c07f10; }
.tag-old { background: #eef1f7; color: #8a94a6; }

/* 掌握度条 */
.mastery {
  position: relative; flex: 1; min-width: 72px; height: 8px;
  background: #edf0f6; border-radius: 999px; overflow: hidden;
}
.mastery i {
  position: absolute; top: 0; left: 0; bottom: 0;
  background: linear-gradient(90deg, #ffb84d, var(--success));
  border-radius: 999px;
}
.mastery.na {
  background: none; height: auto; min-width: 0;
  font-size: .72rem; color: #a4adc0;
}

/* ---------- 拍卷 ---------- */

.resume-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: #fff8ec; border: 1px solid #ffe1ad;
  border-radius: var(--radius); padding: 10px 12px;
  font-size: .85rem; margin-bottom: 12px;
}
.resume-bar span { flex: 1; min-width: 140px; }

.page-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.page-item {
  display: flex; align-items: center; gap: 10px;
  background: #f7f9fc; border-radius: 10px; padding: 8px 10px;
}
.page-thumb {
  position: relative; width: 64px; height: 84px; flex-shrink: 0;
  background: #e9edf4 center/cover no-repeat; border-radius: 8px;
}
.blur-badge {
  position: absolute; left: 4px; bottom: 4px;
  background: rgba(224, 82, 82, .92); color: #fff;
  font-size: .62rem; padding: 1px 6px; border-radius: 999px;
}
.page-info { flex: 1; font-size: .88rem; font-weight: 600; }
.page-ops { display: flex; gap: 4px; }

/* 诊断进度 */
.diag-wait { text-align: center; }
.diag-progress {
  height: 10px; background: #edf0f6; border-radius: 999px;
  overflow: hidden; margin: 14px 0 10px;
}
.diag-progress i {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--primary), #7ba2ff);
  border-radius: 999px; transition: width .3s;
}
.diag-status { font-size: .9rem; color: var(--text-2); }
.err-text { color: var(--danger); }

/* ---------- 诊断确认页 ---------- */

.dg { padding-bottom: 86px; } /* 给底部固定栏让位 */
.dg-head {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px;
}

.top3 { display: grid; grid-template-columns: 1fr; gap: 10px; }
.top3-card {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px;
}
.top3-name { font-weight: 700; font-size: .95rem; margin-bottom: 4px; }
.top3-meta { font-size: .82rem; color: var(--text-2); }
.top3-meta b { color: var(--danger); }

.dg-page { margin-bottom: 16px; }
.dg-page-title {
  font-size: .85rem; font-weight: 700; color: var(--text-2);
  padding: 8px 2px 6px;
}
.dg-view-img { color: var(--primary); font-weight: 400; cursor: pointer; }

.dg-item {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px; margin-bottom: 10px;
  border: 1px solid transparent;
}
.dg-item.low { border-color: #ffd28f; background: #fffaf2; }
.dg-item-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.dg-no { font-weight: 700; font-size: 1rem; }
.low-badge {
  background: #fff4e0; color: #c07f10;
  font-size: .68rem; padding: 1px 8px; border-radius: 999px;
}
.dg-item-body { display: flex; flex-direction: column; gap: 8px; }

/* 对/错/存疑 三态切换 */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg-btn {
  border: none; background: #fff; padding: 7px 14px;
  font-size: .85rem; cursor: pointer; color: var(--text-2);
  border-right: 1px solid var(--border);
}
.seg-btn:last-child { border-right: none; }
.seg-btn.on.right { background: #e3f7ec; color: #1d9455; font-weight: 700; }
.seg-btn.on.wrong { background: #fdeaea; color: #d04444; font-weight: 700; }
.seg-btn.on.pending { background: #fff4e0; color: #c07f10; font-weight: 700; }

.dg-cause {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px;
  font-size: .88rem; background: #fff; outline: none; max-width: 220px;
}
.dg-kp { justify-content: flex-start; }
.dg-note {
  font-size: .78rem; color: var(--text-2);
  background: #f7f9fc; border-radius: 8px; padding: 8px 10px;
}

/* 底部固定确认栏 */
.dg-bar {
  position: fixed; left: 0; right: 0; bottom: var(--bottomnav-h); z-index: 40;
  display: flex; align-items: center; gap: 12px;
  background: #fff; border-top: 1px solid var(--border);
  padding: 10px 14px;
}
.dg-bar-info { flex: 1; font-size: .8rem; color: var(--text-2); }

/* 知识点选择弹窗 */
.kp-modal { max-width: 480px; max-height: 76vh; display: flex; flex-direction: column; }
.kp-tree { overflow-y: auto; margin: 6px 0 12px; }
.kp-unit {
  font-size: .8rem; font-weight: 700; color: var(--text-2);
  margin: 10px 0 6px;
}
.kp-items { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- v2 桌面端增强 ---------- */
@media (min-width: 768px) {
  .board-tabs { display: none; } /* 桌面直接三列，无需 Tab */
  .board-cols { grid-template-columns: repeat(3, 1fr); gap: 14px; align-items: start; }
  .board-col { display: flex; }
  .top3 { grid-template-columns: repeat(3, 1fr); }
  .dg-bar { left: 220px; bottom: 0; } /* 避开侧边栏 */
}
