/* =========================================================
   品管圈智能质改工作台 · 设计令牌与样式
   设计依据：DESIGN.md（参考图 image-to-code 提取）
   ========================================================= */

:root {
  /* 颜色 */
  --bg: #f0f1f3;
  --surface: #ffffff;
  --surface-soft: #f7f8fa;
  --border: #e3e6eb;
  --border-strong: #d4d9e0;

  --text: #232a36;
  --text-2: #5a6270;
  --text-3: #757f8e;

  --accent: #1d3a6e;
  --accent-hover: #27497f;
  --accent-soft: #e8eef7;
  --accent-line: #c9d6ea;

  --green: #1f7a44;
  --green-soft: #e5f2e8;
  --green-line: #bfe0c9;

  --warm: #b4533b;
  --warm-soft: #fbeae5;

  --danger: #b4343a;
  --danger-soft: #fbe7e8;

  --sidebar-bg: #f0f1f3;
  --topbar-bg: rgba(255, 255, 255, 0.92);

  /* 圆角体系（一条规则） */
  --r-card: 12px;
  --r-ctrl: 10px;
  --r-thumb: 8px;
  --r-pill: 999px;

  /* 间距 */
  --pad-card: 20px;
  --gap: 16px;
  --gap-lg: 24px;

  /* 阴影（贴近底色，非纯黑） */
  --shadow-card: 0 1px 2px rgba(35, 42, 54, 0.05);
  --shadow-pop: 0 8px 24px rgba(35, 42, 54, 0.1);

  /* 字体 */
  --font-sans: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, -apple-system, sans-serif;
  --font-mono: "SF Mono", "Cascadia Mono", Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }

/* ---------- 应用壳 ---------- */
.app-shell {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100dvh;
}

/* ---------- 侧边导航 ---------- */
.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100dvh;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 14px;
}

.brand-mark {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 13px; font-weight: 600; line-height: 1.35; color: var(--text); }
.brand-text small { font-size: 11px; color: var(--text-3); margin-top: 2px; white-space: nowrap; }

.side-nav {
  flex: 1;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.side-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--r-ctrl);
  color: var(--text-2);
  text-decoration: none;
  position: relative;
  transition: background 0.18s ease, color 0.18s ease;
}

.side-nav-item svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.side-nav-item:hover { background: #e7eaee; color: var(--text); }
.side-nav-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.side-nav-item.active {
  background: var(--surface);
  color: var(--accent);
  font-weight: 500;
  box-shadow: var(--shadow-card);
}

.side-nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 20%;
  bottom: 20%;
  width: 3px;
  border-radius: var(--r-pill);
  background: var(--accent);
}

.sidebar-foot { padding: 14px 12px; border-top: 1px solid var(--border); }

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--r-ctrl);
}

.avatar {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: var(--r-pill);
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 600;
}

.avatar-sm { width: 30px; height: 30px; font-size: 12px; }

.user-meta { display: flex; flex-direction: column; min-width: 0; }
.user-meta strong { font-size: 13px; font-weight: 600; }
.user-meta small { font-size: 11px; color: var(--text-3); }

/* ---------- 主区域 ---------- */
.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

.menu-btn { display: none; }

.breadcrumb { display: flex; align-items: center; gap: 8px; color: var(--text-3); font-size: 13px; }
.breadcrumb .current { color: var(--text); font-weight: 500; }
.crumb-sep { color: var(--border-strong); }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }

.icon-btn {
  position: relative;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: var(--r-ctrl);
  background: transparent;
  color: var(--text-2);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
}

.icon-btn svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn:hover { background: #e7eaee; color: var(--text); }
.icon-btn:active { transform: scale(0.96); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.icon-btn .dot {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 7px;
  height: 7px;
  border-radius: var(--r-pill);
  background: var(--warm);
  border: 1.5px solid var(--topbar-bg);
}

.top-user { display: flex; align-items: center; gap: 8px; }
.top-user-name { font-size: 13px; font-weight: 500; }

.content {
  flex: 1;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--gap-lg);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.grid-row {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(0, 5fr);
  gap: var(--gap);
  align-items: start;
}

.col-main, .col-side { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-card);
  padding: var(--pad-card);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.card-title { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: 0.01em; }
.muted { color: var(--text-3); font-size: 12px; }

/* ---------- 标签 ---------- */
.tag {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 10px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}

.tag-primary { background: var(--accent); color: #fff; }
.tag-blue { background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent-line); }
.tag-green { background: var(--green-soft); color: var(--green); border: 1px solid var(--green-line); }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 18px;
  border-radius: var(--r-ctrl);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, transform 0.06s ease;
}

.btn:active { transform: translateY(1px) scale(0.99); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-ghost {
  background: var(--surface);
  color: var(--text-2);
  border-color: var(--border-strong);
}
.btn-ghost:hover { background: var(--surface-soft); color: var(--text); }

.card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.action-right { display: flex; gap: 10px; }

/* ---------- 答题卡 ---------- */
.quiz-count { color: var(--text-2); font-size: 13px; }
.quiz-count b { color: var(--accent); font-weight: 700; }

.quiz-timer {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--r-ctrl);
  padding: 4px 10px;
  font-variant-numeric: tabular-nums;
}

.quiz-timer.danger { color: var(--danger); background: var(--danger-soft); border-color: #f0c4c6; }

.q-dots {
  display: flex;
  gap: 5px;
  margin: 2px 0 14px;
}

.q-dot {
  flex: 1;
  height: 6px;
  border-radius: var(--r-pill);
  background: #e4e7ec;
}
.q-dot.done { background: var(--accent); }
.q-dot.now { background: var(--accent-line); box-shadow: inset 0 0 0 1px var(--accent); }

.eyebrow { margin: 0 0 6px; font-size: 11px; letter-spacing: 0.06em; color: var(--text-3); }

.quiz-question {
  margin: 0 0 16px;
  font-size: 20px;
  line-height: 1.4;
  font-weight: 600;
  max-width: 32em;
}

.options { display: flex; flex-direction: column; gap: 10px; }

.option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-ctrl);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.06s ease;
}

.option:hover { border-color: var(--accent-line); background: var(--surface-soft); }
.option:active { transform: scale(0.995); }
.option:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.opt-key {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: var(--r-pill);
  background: var(--surface-soft);
  border: 1px solid var(--border-strong);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
}

.option.selected { border-color: var(--accent); background: var(--accent-soft); }
.option.selected .opt-key { background: var(--accent); border-color: var(--accent); color: #fff; }
.option.correct { border-color: var(--green-line); background: var(--green-soft); }
.option.correct .opt-key { background: var(--green); border-color: var(--green); color: #fff; }
.option.wrong { border-color: #eab6b8; background: var(--danger-soft); }
.option.wrong .opt-key { background: var(--danger); border-color: var(--danger); color: #fff; }
.option[disabled] { cursor: default; opacity: 1; }
.option[disabled]:hover { background: var(--surface); }
.option[disabled].correct:hover { background: var(--green-soft); }
.option[disabled].wrong:hover { background: var(--danger-soft); }

.form-error { margin: 10px 0 0; color: var(--danger); font-size: 12px; }

.quiz-feedback {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: var(--r-ctrl);
  border: 1px solid var(--green-line);
  background: var(--green-soft);
  color: var(--green);
}

.quiz-feedback.fail { border-color: #eab6b8; background: var(--danger-soft); color: var(--danger); }
.quiz-feedback .feedback-title { margin: 0 0 2px; font-weight: 600; font-size: 13px; }
.quiz-feedback .feedback-note { margin: 0; font-size: 12px; line-height: 1.6; }

/* ---------- 当前课程卡 ---------- */
.course-card { display: flex; gap: 16px; }

.course-thumb {
  position: relative;
  flex: none;
  width: 148px;
  aspect-ratio: 16 / 10;
  border-radius: var(--r-thumb);
  background: linear-gradient(145deg, #dbe4f2, #c3d2ea);
  display: grid;
  place-items: center;
  color: var(--accent);
}

.course-thumb svg { width: 34px; height: 34px; fill: none; stroke: currentColor; stroke-width: 1.4; stroke-linejoin: round; }

.play-badge {
  position: absolute;
  width: 34px;
  height: 34px;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.92);
  color: var(--accent);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-pop);
}

.play-badge svg { width: 18px; height: 18px; fill: currentColor; stroke: none; }

.course-info { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; }
.course-info h3 { margin: 6px 0 2px; font-size: 15px; font-weight: 600; }
.course-sub { margin: 0 0 10px; font-size: 12px; color: var(--text-2); }

.mini-progress {
  width: 100%;
  height: 6px;
  border-radius: var(--r-pill);
  background: #e4e7ec;
  overflow: hidden;
}

.mini-bar {
  display: block;
  height: 100%;
  width: 0;
  border-radius: var(--r-pill);
  background: var(--accent);
  transition: width 0.9s cubic-bezier(0.16, 1, 0.3, 1);
}

.course-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 14px;
}

.resume-hint { font-size: 12px; color: var(--text-3); }

/* ---------- 课程目录 ---------- */
.chapter-list { list-style: none; margin: 0; padding: 0; }

.chapter { border-bottom: 1px solid var(--border); }
.chapter:last-child { border-bottom: none; }

.chapter-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 12px 0;
  border: none;
  background: none;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  border-radius: var(--r-ctrl);
}

.chapter-toggle:hover { color: var(--accent); }
.chapter-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.chapter-toggle .state {
  flex: none;
  width: 16px;
  height: 16px;
  transition: transform 0.18s ease;
  color: var(--text-3);
}
.chapter.open .chapter-toggle .state { transform: rotate(90deg); }

.lesson-list {
  list-style: none;
  margin: 0 0 10px;
  padding: 0 0 0 18px;
  display: none;
  flex-direction: column;
  gap: 2px;
}

.chapter.open .lesson-list { display: flex; }

.lesson {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--r-ctrl);
  font-size: 13px;
  color: var(--text-2);
}

.lesson .state { flex: none; width: 16px; height: 16px; }
.lesson .state svg { width: 16px; height: 16px; display: block; }

.lesson.done { color: var(--green); }
.lesson.done .state { color: var(--green); }
.lesson.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.lesson.locked { color: var(--text-3); }

.chapter-empty { padding: 8px 10px; font-size: 12px; color: var(--text-3); }

.related-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.related-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: var(--r-pill);
  background: var(--surface-soft);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 12px;
  text-decoration: none;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.related-link svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.related-link:hover { border-color: var(--accent-line); color: var(--accent); }
.related-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- PDCA ---------- */
.pdca-layout {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 4fr);
  gap: 20px;
  align-items: center;
}

.pdca-diagram {
  position: relative;
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
}

.pdca-diagram svg { display: block; width: 100%; height: auto; }

.pdca-node {
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), filter 0.2s ease;
}

.pdca-node:hover, .pdca-node:focus-visible, .pdca-node.active { transform: scale(1.14); filter: none; }
.pdca-node:focus-visible { outline: none; }

.pdca-node circle.node-ring { fill: var(--surface); stroke: var(--accent-line); stroke-width: 1.5; transition: fill 0.15s ease, stroke 0.15s ease; }
.pdca-node text.node-label { fill: var(--accent); font-size: 10px; font-weight: 600; text-anchor: middle; dominant-baseline: central; font-family: var(--font-sans); }
.pdca-node.active circle.node-ring { fill: var(--accent); stroke: var(--accent); }
.pdca-node.active text.node-label { fill: #fff; }

.pdca-core text { font-family: var(--font-sans); font-weight: 600; text-anchor: middle; dominant-baseline: central; }
.pdca-core .core-letter { font-size: 15px; fill: var(--accent); }
.pdca-core .core-name { font-size: 7.5px; fill: var(--text-2); }

.pdca-detail {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--r-ctrl);
  padding: 16px;
  min-height: 132px;
}

.pdca-detail .step-no { font-size: 11px; color: var(--text-3); letter-spacing: 0.06em; margin: 0 0 4px; }
.pdca-detail h3 { margin: 0 0 6px; font-size: 16px; font-weight: 600; color: var(--accent); }
.pdca-detail p { margin: 0; font-size: 13px; color: var(--text-2); line-height: 1.65; }

/* ---------- 知识库统计 ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.stat {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--r-ctrl);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat .num { font-size: 20px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.stat .label { font-size: 11px; color: var(--text-3); }

.stat .num.warm { color: var(--warm); }
.stat .num.green { color: var(--green); }

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

.stat-row { display: flex; flex-direction: column; gap: 6px; }
.stat-row .row-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-2); }
.stat-row .row-val { font-family: var(--font-mono); font-weight: 600; color: var(--text); }

.bar-track {
  height: 5px;
  border-radius: var(--r-pill);
  background: #e4e7ec;
  overflow: hidden;
}

.bar-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: var(--r-pill);
  background: var(--accent);
  transition: width 1s cubic-bezier(0.16, 1, 0.3, 1);
}

.stats-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.stats-foot a { color: var(--accent); font-size: 13px; font-weight: 500; text-decoration: none; }
.stats-foot a:hover { text-decoration: underline; }
.stats-foot svg { width: 14px; height: 14px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- 抽屉遮罩 ---------- */
.drawer-mask {
  position: fixed;
  inset: 0;
  background: rgba(35, 42, 54, 0.4);
  z-index: 40;
}

/* ---------- 卡片入场 ---------- */
.card.reveal { animation: card-in 0.45s cubic-bezier(0.16, 1, 0.3, 1) both; }

@keyframes card-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* ---------- 响应式 ---------- */
@media (max-width: 1199px) {
  .grid-row { grid-template-columns: 1fr; }
  .col-side { display: grid; grid-template-columns: 1fr 1fr; }
}

@media (max-width: 899px) {
  .app-shell { grid-template-columns: 72px 1fr; }
  .brand { justify-content: center; padding: 16px 8px; }
  .brand-text { display: none; }
  .side-nav { padding: 8px; }
  .side-nav-item { justify-content: center; padding: 10px; }
  .side-nav-item .nav-label { display: none; }
  .side-nav-item.active::before { left: auto; right: -8px; }
  .sidebar-foot { padding: 10px 8px; }
  .user-meta { display: none; }
  .user-card { justify-content: center; padding: 4px; }
}

@media (max-width: 767px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    width: 232px;
    transition: transform 0.24s cubic-bezier(0.16, 1, 0.3, 1);
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-pop); }
  .brand { justify-content: flex-start; padding: 18px 16px 14px; }
  .brand-text { display: flex; }
  .side-nav { padding: 8px 12px; }
  .side-nav-item { justify-content: flex-start; padding: 9px 12px; }
  .side-nav-item .nav-label { display: inline; }
  .side-nav-item.active::before { left: 0; right: auto; }
  .sidebar-foot { padding: 14px 12px; }
  .user-meta { display: flex; }
  .user-card { justify-content: flex-start; padding: 8px; }

  .menu-btn { display: grid; }
  .topbar { padding: 0 14px; }
  .content { padding: 16px 14px; }
  .top-user-name { display: none; }

  .col-side { grid-template-columns: 1fr; }
  .course-card { flex-direction: column; }
  .course-thumb { width: 100%; aspect-ratio: 16 / 7; }
  .pdca-layout { grid-template-columns: 1fr; }
  .pdca-detail { min-height: 0; }
  .quiz-question { font-size: 17px; }
  .card-actions { flex-direction: column-reverse; align-items: stretch; }
  .action-right { flex-direction: column; }
  .btn { width: 100%; }
}

/* ---------- 动效与无障碍 ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
