/* =====================================================================
   电测智伴 —— 全套样式表
   课程：《电气测量技术》  面向：开放教育（远程教育）成人学生
   零第三方依赖：不引用任何外部字体 / CDN / 图标库，全部离线可用。
   目录：
     1. 设计变量与主题
     2. 基础重置与排版
     3. 应用布局（顶部栏 / 侧栏 / 内容区 / 页脚）
     4. 按钮、徽章、表单
     5. 卡片与栅格
     6. 表格、键值表、时间线、统计卡
     7. 进度条、标签页、薄弱度色条、空状态、上传区
     8. 智能学伴（悬浮球 + 抽屉 + 消息气泡 + 引用卡片）
     9. 轻提示 Toast、模态框 Modal、骨架屏
    10. 响应式（窄屏 → 底部导航）
    11. 深色模式
    12. 打印样式
   ===================================================================== */

/* ---------------------------------------------------------- 1. 设计变量 */
:root {
  /* 主题色（需求指定） */
  --c-primary: #1d4ed8;
  --c-primary-dark: #1e40af;
  --c-primary-soft: #e8efff;
  --c-accent: #0ea5e9;
  --c-accent-soft: #e0f4ff;
  --c-ok: #22c55e;
  --c-ok-soft: #e7f9ee;
  --c-warn: #f59e0b;
  --c-warn-soft: #fff5e2;
  --c-danger: #ef4444;
  --c-danger-soft: #fdecec;

  /* 中性色 */
  --c-bg: #f4f7fb;
  --c-surface: #ffffff;
  --c-surface-2: #f8fafc;
  --c-surface-3: #eef2f7;
  --c-text: #0f172a;
  --c-text-2: #475569;
  --c-text-3: #64748b;
  --c-border: #e2e8f0;
  --c-border-strong: #cbd5e1;
  --c-shadow-color: 15 23 42;

  /* 字体栈：中文优先 */
  --font-sans: "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB",
    "Source Han Sans SC", "Noto Sans CJK SC", system-ui, -apple-system,
    "Segoe UI", Roboto, Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", Consolas, "Courier New", monospace;

  /* 字号 */
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-base: 14px;
  --fs-md: 15px;
  --fs-lg: 17px;
  --fs-xl: 21px;
  --fs-2xl: 27px;

  /* 圆角 */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  /* 阴影 */
  --shadow-sm: 0 1px 2px rgb(var(--c-shadow-color) / 0.06);
  --shadow: 0 2px 10px rgb(var(--c-shadow-color) / 0.08);
  --shadow-md: 0 6px 20px rgb(var(--c-shadow-color) / 0.12);
  --shadow-lg: 0 18px 48px rgb(var(--c-shadow-color) / 0.22);

  /* 尺寸 */
  --topbar-h: 60px;
  --sidebar-w: 200px;
  --drawer-w: min(420px, 92vw);

  /* 层级 */
  --z-sidebar: 20;
  --z-fab: 60;
  --z-drawer: 70;
  --z-modal: 80;
  --z-toast: 90;

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ------------------------------------------------- 2. 基础重置与排版 */
*,
*::before,
*::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.65;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}

/* ------------------------------------------------------------------
 * [hidden] 强制隐藏（全局兜底）
 *
 * 本项目反复踩到的坑：元素的 class 里写了 display:flex / inline-flex / table，
 * 由于 CSS 优先级高于 [hidden] 的 UA 默认样式，设置 el.hidden = true 后
 * **元素依然显示**（例如已登录时顶栏仍出现「登录」按钮）。
 * 这里统一兜底：带 hidden 属性的一律不显示；需要「隐藏但保留布局」的场景
 * 请改用其它 class 控制，不要依赖 hidden。
 * ------------------------------------------------------------------ */
[hidden] { display: none !important; }

h1, h2, h3, h4 { margin: 0 0 8px; line-height: 1.35; font-weight: 700; }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
p { margin: 0 0 10px; }
a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code, kbd, samp { font-family: var(--font-mono); font-size: 0.92em; }
code {
  background: var(--c-surface-3);
  border-radius: var(--radius-sm);
  padding: 1px 5px;
}
hr { border: 0; border-top: 1px solid var(--c-border); margin: 14px 0; }
small, .text-sm { font-size: var(--fs-sm); }
.text-muted { color: var(--c-text-3); }
.text-ok { color: var(--c-ok); }
.text-warn { color: var(--c-warn); }
.text-danger { color: var(--c-danger); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mono { font-family: var(--font-mono); }
.nowrap { white-space: nowrap; }

/* 无障碍：跳转/隐藏文本 */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* 统一的键盘焦点样式 */
:focus-visible {
  outline: 2px solid var(--c-accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* 滚动条（Chromium/Firefox） */
* { scrollbar-width: thin; scrollbar-color: var(--c-border-strong) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb {
  background: var(--c-border-strong);
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-track { background: transparent; }

/* --------------------------------------------------------- 3. 应用布局 */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: var(--topbar-h) minmax(0, 1fr) auto;
  grid-template-areas:
    "topbar topbar"
    "sidebar view"
    "footer footer";
  min-height: 100vh;
  min-height: 100dvh;
}

/* ---- 顶部栏 ---- */
.topbar {
  grid-area: topbar;
  position: sticky;
  top: 0;
  z-index: var(--z-sidebar);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  box-shadow: var(--shadow-sm);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
/* 品牌 LOG：新图标（透明底 PNG），不再用 emoji + 渐变方块 */
img.brand-logo {
  display: block;
  width: 40px;
  height: 40px;
  flex: none;
  object-fit: contain;
  /* 透明底图标在深浅背景下都能看清，加一点柔和投影 */
  filter: drop-shadow(0 1px 2px rgba(29, 78, 216, .18));
}
.brand-text { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.brand-name {
  font-size: var(--fs-md);
  font-weight: 700;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-course { font-size: var(--fs-xs); color: var(--c-text-3); line-height: 1.3; }

.topbar-right { display: flex; align-items: center; gap: 10px; flex: none; }
.student-picker { display: flex; align-items: center; gap: 6px; }
.student-picker-label { font-size: var(--fs-xs); color: var(--c-text-3); white-space: nowrap; }

/* ---- 左侧导航 ---- */
.sidebar {
  grid-area: sidebar;
  position: sticky;
  top: var(--topbar-h);
  align-self: start;
  height: calc(100vh - var(--topbar-h));
  height: calc(100dvh - var(--topbar-h));
  padding: 12px 10px;
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  overflow-y: auto;
  z-index: var(--z-sidebar);
}
.nav-list { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--c-text-2);
  font-size: var(--fs-base);
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.nav-item:hover { background: var(--c-surface-2); color: var(--c-primary); text-decoration: none; }
.nav-item.active {
  background: var(--c-primary-soft);
  color: var(--c-primary-dark);
  border-left-color: var(--c-primary);
  font-weight: 700;
}
.nav-ico { width: 20px; text-align: center; flex: none; font-size: 15px; }
.nav-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-sep { height: 1px; background: var(--c-border); margin: 8px 4px; }
.nav-group-title {
  font-size: var(--fs-xs);
  color: var(--c-text-3);
  padding: 6px 12px 0;
  letter-spacing: 0.04em;
}

/* ---- 主内容区 ---- */
.view {
  grid-area: view;
  min-width: 0;
  padding: 18px 20px 30px;
  outline: none;
}
.view > .page-head { margin-bottom: 14px; }
.page-head h1, .page-head h2 { margin-bottom: 4px; }
.view section + section { margin-top: 16px; }
.view .toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.view .toolbar .spacer { flex: 1 1 auto; }

/* ---- 页脚 ---- */
.appfooter {
  grid-area: footer;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 10px 20px 14px;
  font-size: var(--fs-xs);
  color: var(--c-text-3);
  border-top: 1px solid var(--c-border);
  background: var(--c-surface);
}
.dot-sep { opacity: 0.6; }
.health { display: inline-flex; align-items: center; gap: 5px; }
.health::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.health-online { color: var(--c-ok); }
.health-offline { color: var(--c-danger); font-weight: 700; }
.health-unknown { color: var(--c-text-3); }

/* ------------------------------------------- 4. 按钮、徽章、表单 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--c-border-strong);
  border-radius: var(--radius);
  background: var(--c-surface);
  color: var(--c-text);
  font-family: inherit;
  font-size: var(--fs-base);
  font-weight: 600;
  line-height: 1.4;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease),
    transform 0.08s var(--ease), box-shadow 0.15s var(--ease);
}
.btn:hover { background: var(--c-surface-2); }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn:disabled, .btn.is-loading {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}
.btn-primary {
  background: var(--c-primary);
  border-color: var(--c-primary);
  color: #fff;
}
.btn-primary:hover { background: var(--c-primary-dark); border-color: var(--c-primary-dark); }
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--c-text-2);
}
.btn-ghost:hover { background: var(--c-surface-3); color: var(--c-primary); }
.btn-danger {
  background: var(--c-danger);
  border-color: var(--c-danger);
  color: #fff;
}
.btn-danger:hover { filter: brightness(0.93); }
.btn-ok { background: var(--c-ok); border-color: var(--c-ok); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: var(--fs-sm); border-radius: var(--radius-sm); }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  background: var(--c-primary-soft);
  color: var(--c-primary-dark);
  font-size: var(--fs-sm);
  font-weight: 700;
  line-height: 1.5;
  white-space: nowrap;
}
.badge-ok { background: var(--c-ok-soft); color: #15803d; }
.badge-warn { background: var(--c-warn-soft); color: #b45309; }
.badge-danger { background: var(--c-danger-soft); color: #b91c1c; }
.badge-accent { background: var(--c-accent-soft); color: #0369a1; }
.badge-plain { background: var(--c-surface-3); color: var(--c-text-2); }
.points-badge { font-size: var(--fs-base); }

.input, .select, .textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--c-border-strong);
  border-radius: var(--radius);
  background: var(--c-surface);
  color: var(--c-text);
  font-family: inherit;
  font-size: var(--fs-base);
  line-height: 1.5;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgb(29 78 216 / 0.14);
}
.select {
  width: auto;
  min-width: 156px;
  max-width: 42vw;
  padding-right: 30px;
  cursor: pointer;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--c-text-3) 50%),
    linear-gradient(135deg, var(--c-text-3) 50%, transparent 50%);
  background-position: calc(100% - 15px) 51%, calc(100% - 10px) 51%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.textarea { resize: vertical; min-height: 72px; }
.form-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 10px; }
.form-row > label { display: flex; flex-direction: column; gap: 4px; font-size: var(--fs-sm); color: var(--c-text-2); }
.field-label { font-size: var(--fs-sm); color: var(--c-text-2); margin-bottom: 4px; display: block; }
.checkbox-row { display: flex; align-items: center; gap: 7px; font-size: var(--fs-base); }

/* ------------------------------------------------ 5. 卡片与栅格 */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  margin-bottom: 14px;
}
.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-md);
  font-weight: 700;
  margin: 0 0 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--c-border);
}
.card-title .card-title-extra { margin-left: auto; font-weight: 500; font-size: var(--fs-sm); color: var(--c-text-3); }
.card-sub { font-size: var(--fs-sm); color: var(--c-text-3); margin: -4px 0 10px; }
.card-hover { transition: box-shadow 0.15s var(--ease), transform 0.15s var(--ease); }
.card-hover:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.card-flush { padding: 0; overflow: hidden; }
.card-danger { border-left: 4px solid var(--c-danger); }
.card-warn { border-left: 4px solid var(--c-warn); }
.card-ok { border-left: 4px solid var(--c-ok); }

.grid-2, .grid-3, .grid-4 { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-auto { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.row-between { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }

/* ------------------------------- 6. 表格、键值表、时间线、统计卡 */
.table-wrap { width: 100%; overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-base);
  background: var(--c-surface);
}
.table th, .table td {
  padding: 9px 12px;
  text-align: left;
  border-bottom: 1px solid var(--c-border);
  vertical-align: middle;
}
.table thead th {
  background: var(--c-surface-2);
  color: var(--c-text-2);
  font-size: var(--fs-sm);
  font-weight: 700;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}
.table tbody tr:hover { background: var(--c-surface-2); }
.table tbody tr.is-clickable { cursor: pointer; }
.table tbody tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }

.kv {
  display: grid;
  grid-template-columns: minmax(90px, auto) minmax(0, 1fr);
  gap: 6px 14px;
  font-size: var(--fs-base);
}
.kv dt { color: var(--c-text-3); }
.kv dd { margin: 0; color: var(--c-text); word-break: break-word; }
.kv-inline { display: flex; flex-wrap: wrap; gap: 6px 18px; }

.timeline { list-style: none; margin: 0; padding: 0 0 0 6px; }
.timeline > li {
  position: relative;
  padding: 0 0 14px 20px;
  border-left: 2px solid var(--c-border);
}
.timeline > li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline > li::before {
  content: "";
  position: absolute;
  left: -7px; top: 5px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--c-surface);
  border: 2px solid var(--c-primary);
}
.timeline > li.ok::before { border-color: var(--c-ok); }
.timeline > li.warn::before { border-color: var(--c-warn); }
.timeline > li.danger::before { border-color: var(--c-danger); }
.timeline .tl-title { font-weight: 600; }
.timeline .tl-meta { font-size: var(--fs-xs); color: var(--c-text-3); }

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  box-shadow: var(--shadow-sm);
}
.stat-num {
  font-size: 30px;
  font-weight: 800;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  color: var(--c-primary);
}
.stat-label { font-size: var(--fs-sm); color: var(--c-text-2); }
.stat-unit { font-size: var(--fs-base); font-weight: 600; color: var(--c-text-3); margin-left: 2px; }
.stat-ok .stat-num { color: var(--c-ok); }
.stat-warn .stat-num { color: var(--c-warn); }
.stat-danger .stat-num { color: var(--c-danger); }
.stat-accent .stat-num { color: var(--c-accent); }
.stat-hint { font-size: var(--fs-xs); color: var(--c-text-3); }

/* --------------------------- 7. 进度条、标签页、薄弱度、空态、上传 */
.progress {
  position: relative;
  height: 9px;
  border-radius: var(--radius-pill);
  background: var(--c-surface-3);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, var(--c-primary), var(--c-accent));
  transition: width 0.35s var(--ease);
}
.progress-bar.ok { background: var(--c-ok); }
.progress-bar.warn { background: var(--c-warn); }
.progress-bar.danger { background: var(--c-danger); }
.progress-sm { height: 6px; }
.progress-lg { height: 13px; }
.progress-text { font-size: var(--fs-xs); color: var(--c-text-3); margin-top: 3px; }

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  border-bottom: 1px solid var(--c-border);
  margin-bottom: 14px;
}
.tab {
  padding: 8px 14px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--c-text-2);
  font-family: inherit;
  font-size: var(--fs-base);
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius) var(--radius) 0 0;
}
.tab:hover { background: var(--c-surface-2); color: var(--c-primary); }
.tab.active { color: var(--c-primary-dark); border-bottom-color: var(--c-primary); background: var(--c-primary-soft); }
.tab-panel[hidden] { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  background: var(--c-surface-3);
  color: var(--c-text-2);
  font-size: var(--fs-xs);
  line-height: 1.7;
  white-space: nowrap;
}
.chip-primary { background: var(--c-primary-soft); color: var(--c-primary-dark); }
.chip-ok { background: var(--c-ok-soft); color: #15803d; }
.chip-warn { background: var(--c-warn-soft); color: #b45309; }
.chip-danger { background: var(--c-danger-soft); color: #b91c1c; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip[data-removable] { cursor: pointer; }
.chip[data-removable]:hover { filter: brightness(0.95); }

/* 薄弱度色条：宽度与颜色都由 JS 按 0-100 给出 */
.span-weakness {
  display: block;
  position: relative;
  width: 100%;
  min-width: 70px;
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--c-surface-3);
  overflow: hidden;
}
.span-weakness > i,
.span-weakness .span-fill {
  display: block;
  height: 100%;
  width: var(--w, 0%);
  border-radius: var(--radius-pill);
  background: var(--span-color, var(--c-ok));
  transition: width 0.35s var(--ease);
}
.span-weakness-label { font-size: var(--fs-xs); color: var(--c-text-3); }

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 34px 18px;
  text-align: center;
  color: var(--c-text-3);
  border: 1px dashed var(--c-border-strong);
  border-radius: var(--radius-lg);
  background: var(--c-surface-2);
}
.empty-ico { font-size: 30px; line-height: 1; }
.empty-title { font-weight: 700; color: var(--c-text-2); }

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 26px 18px;
  text-align: center;
  color: var(--c-text-2);
  background: var(--c-surface-2);
  border: 2px dashed var(--c-border-strong);
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}
.dropzone:hover { border-color: var(--c-primary); background: var(--c-primary-soft); }
.dropzone.is-drag { border-color: var(--c-primary); background: var(--c-primary-soft); }
.dropzone-ico { font-size: 28px; }
.dropzone-hint { font-size: var(--fs-sm); color: var(--c-text-3); }
.dropzone input[type="file"] { display: none; }
.file-list { list-style: none; margin: 10px 0 0; padding: 0; font-size: var(--fs-sm); }
.file-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 9px;
  border-radius: var(--radius-sm);
  background: var(--c-surface-2);
  margin-bottom: 5px;
}
.file-list .file-size { margin-left: auto; color: var(--c-text-3); font-size: var(--fs-xs); }
.file-remove {
  border: 0; background: transparent; cursor: pointer;
  color: var(--c-danger); font-size: var(--fs-base); line-height: 1;
  padding: 2px 4px; border-radius: var(--radius-sm);
}
.file-remove:hover { background: var(--c-danger-soft); }

/* ---------------------------------------- 8. 智能学伴 */
.companion-fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: var(--z-fab);
  width: 56px; height: 56px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(140deg, var(--c-primary), var(--c-accent));
  color: #fff;
  font-size: 24px;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: transform 0.18s var(--ease), box-shadow 0.18s var(--ease);
}
.companion-fab:hover { transform: scale(1.06); }
.companion-fab:active { transform: scale(0.98); }
.companion-fab.is-open { background: var(--c-text-2); }
.fab-ico { pointer-events: none; }

.drawer {
  position: fixed;
  top: 0; right: 0;
  z-index: var(--z-drawer);
  width: var(--drawer-w);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--c-surface);
  border-left: 1px solid var(--c-border);
  box-shadow: var(--shadow-lg);
  transform: translateX(105%);
  visibility: hidden;
  transition: transform 0.25s var(--ease), visibility 0.25s var(--ease);
}
.drawer.is-open { transform: translateX(0); visibility: visible; }
.drawer-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--c-border);
  background: var(--c-surface);
  flex: none;
}
.drawer-title { font-weight: 700; font-size: var(--fs-md); }
.drawer-head .btn { margin-left: auto; }
.drawer-body { flex: 1 1 auto; overflow-y: auto; padding: 14px; }

.companion-context {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 12px 0;
  padding: 7px 10px;
  border-radius: var(--radius);
  background: var(--c-accent-soft);
  border: 1px solid rgb(14 165 233 / 0.28);
  color: #075985;
  font-size: var(--fs-sm);
  flex: none;
}
.companion-context[hidden] { display: none; }

/* ---------- 学伴：作答方式徽章（题库优先 / 引导式 / 外部大模型） ---------- */
.msg-mode {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 8px; padding: 6px 10px; border-radius: var(--radius);
  background: var(--c-surface-2, #f4f7fb); border: 1px dashed var(--c-border);
}
.msg-mode-tag {
  font-size: var(--fs-xs, 0.78rem); font-weight: 700; color: var(--c-primary);
  padding: 1px 8px; border-radius: var(--radius-pill);
  background: rgba(59, 130, 246, 0.12); white-space: nowrap;
}
.msg-mode-tip { font-size: var(--fs-xs, 0.78rem); color: var(--c-text-3); }
.msg-mode.mode-bank { background: rgba(22, 163, 74, 0.08); border-color: rgba(22, 163, 74, 0.35); }
.msg-mode.mode-bank .msg-mode-tag { color: #15803d; background: rgba(22, 163, 74, 0.14); }
.msg-mode.mode-llm { background: rgba(147, 51, 234, 0.07); border-color: rgba(147, 51, 234, 0.3); }
.msg-mode.mode-llm .msg-mode-tag { color: #7e22ce; background: rgba(147, 51, 234, 0.12); }

/* ---------- 学伴：苏格拉底式追问（可点） ---------- */
.msg-followups { margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--c-border); }
.msg-followups-label { font-size: var(--fs-xs, 0.78rem); color: var(--c-text-3); margin-bottom: 6px; }
button.followup {
  display: block; width: 100%; text-align: left; cursor: pointer;
  margin-top: 6px; padding: 7px 10px; border-radius: var(--radius);
  font: inherit; font-size: var(--fs-sm);
  color: var(--c-primary); background: rgba(59, 130, 246, 0.07);
  border: 1px solid rgba(59, 130, 246, 0.25);
}
button.followup:hover { background: rgba(59, 130, 246, 0.15); border-color: var(--c-primary); }

/* ---------- 学伴：你可能想问（来自学情诊断） ---------- */
.companion-suggest { padding: 8px 12px 0; }
.companion-suggest[hidden] { display: none; }
.suggest-loading { font-size: var(--fs-xs, 0.78rem); color: var(--c-text-3); padding: 4px 0; }
.suggest-head { font-size: var(--fs-xs, 0.78rem); color: var(--c-text-3); margin-bottom: 6px; }
.suggest-row { display: flex; flex-wrap: wrap; gap: 6px; max-height: 132px; overflow-y: auto; }
button.suggest-chip {
  cursor: pointer; font: inherit; font-size: var(--fs-xs, 0.78rem);
  text-align: left; padding: 6px 10px; border-radius: var(--radius-pill);
  color: var(--c-text-2); background: var(--c-surface-2, #f2f5fa);
  border: 1px solid var(--c-border); max-width: 100%;
}
button.suggest-chip:hover { border-color: var(--c-primary); color: var(--c-primary); }
.suggest-kp {
  display: inline-block; margin-right: 6px; padding: 0 6px;
  border-radius: var(--radius-pill); background: rgba(59, 130, 246, 0.12);
  color: var(--c-primary); font-weight: 700;
}
.companion-context .ctx-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.companion-context .btn { margin-left: auto; flex: none; }

.companion-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--c-surface-2);
}
.msg { display: flex; flex-direction: column; max-width: 92%; animation: msgIn 0.18s var(--ease); }
.msg .msg-body {
  padding: 9px 12px;
  border-radius: var(--radius-lg);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  box-shadow: var(--shadow-sm);
  word-break: break-word;
  overflow-wrap: anywhere;
  font-size: var(--fs-base);
}
.msg .msg-body > :first-child { margin-top: 0; }
.msg .msg-body > :last-child { margin-bottom: 0; }
.msg .msg-body p { margin: 0 0 8px; }
.msg .msg-body ul, .msg .msg-body ol { margin: 0 0 8px; padding-left: 20px; }
.msg .msg-body li { margin-bottom: 3px; }
.msg .msg-body pre {
  margin: 0 0 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--c-surface-3);
  overflow-x: auto;
}
.msg .msg-body code { background: rgb(15 23 42 / 0.07); color: var(--c-primary-dark); }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.user .msg-body {
  background: var(--c-primary);
  border-color: var(--c-primary);
  color: #fff;
  border-bottom-right-radius: var(--radius-sm);
}
.msg.user .msg-body code { background: rgb(255 255 255 / 0.22); color: #fff; }
.msg.bot { align-self: flex-start; }
.msg.bot .msg-body { border-bottom-left-radius: var(--radius-sm); }
.msg.bot .msg-body img, .msg.user .msg-body img {
  max-width: 100%;
  border-radius: var(--radius);
  margin-bottom: 6px;
  display: block;
}
.msg-time { font-size: var(--fs-xs); color: var(--c-text-3); margin-top: 3px; padding: 0 4px; }
.msg-error .msg-body { border-color: var(--c-danger); background: var(--c-danger-soft); }

.typing .msg-body { display: inline-flex; align-items: center; gap: 4px; min-height: 34px; }
.typing-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--c-text-3);
  animation: typingBounce 1.1s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: 0.16s; }
.typing-dot:nth-child(3) { animation-delay: 0.32s; }
@keyframes typingBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.45; }
  40% { transform: translateY(-4px); opacity: 1; }
}
@keyframes msgIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.cite-list { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.cite {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--c-border);
  border-left: 3px solid var(--c-accent);
  border-radius: var(--radius);
  background: var(--c-surface);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  font-size: var(--fs-sm);
  color: var(--c-text);
  transition: background 0.15s var(--ease), transform 0.12s var(--ease);
}
.cite:hover { background: var(--c-accent-soft); transform: translateX(2px); }
.cite .cite-title { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cite .cite-score { margin-left: auto; color: var(--c-text-3); font-size: var(--fs-xs); flex: none; }
.cite .cite-kind { flex: none; font-size: var(--fs-xs); color: var(--c-accent); font-weight: 700; }
.cite-snippet { font-size: var(--fs-xs); color: var(--c-text-3); margin: 4px 0 0; }

.companion-input-area {
  flex: none;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--c-border);
  background: var(--c-surface);
}
.companion-textarea { min-height: 46px; max-height: 140px; resize: vertical; }
.companion-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.companion-actions #companion-send { margin-left: auto; }
.shot-preview { display: block; max-width: 100%; max-height: 240px; margin: 10px auto 0; border-radius: var(--radius); border: 1px solid var(--c-border); }

/* screenshot 模态里的“框选截图”舞台 */
.shot-stage {
  position: relative;
  margin-top: 10px;
  border: 2px dashed var(--c-border-strong);
  border-radius: var(--radius);
  background: var(--c-surface-2);
  min-height: 220px;
  display: grid;
  place-items: center;
  overflow: hidden;
  cursor: crosshair;
  user-select: none;
  touch-action: none;
}
.shot-stage canvas { display: block; max-width: 100%; height: auto; }
.shot-stage .shot-hint { position: absolute; inset: auto 8px 8px 8px; font-size: var(--fs-xs); color: var(--c-text-3); text-align: center; pointer-events: none; }
.shot-marquee {
  position: absolute;
  border: 2px solid var(--c-accent);
  background: rgb(14 165 233 / 0.18);
  pointer-events: none;
  display: none;
}

/* ----------------------------------- 9. Toast / Modal / 骨架屏 */
.toast-layer {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  width: min(560px, 94vw);
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 9px 14px;
  border-radius: var(--radius);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-left: 4px solid var(--c-primary);
  box-shadow: var(--shadow-md);
  font-size: var(--fs-base);
  animation: toastIn 0.2s var(--ease);
}
.toast-ok { border-left-color: var(--c-ok); }
.toast-warn { border-left-color: var(--c-warn); }
.toast-danger { border-left-color: var(--c-danger); }
.toast-hide { animation: toastOut 0.22s var(--ease) forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-8px); } }

.modal-layer {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgb(15 23 42 / 0.45);
}
.modal-layer.is-open { display: flex; }
.modal {
  width: min(680px, 96vw);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--c-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modalIn 0.18s var(--ease);
}
@keyframes modalIn { from { opacity: 0; transform: translateY(10px) scale(0.99); } to { opacity: 1; transform: none; } }
.modal-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--c-border);
  flex: none;
}
.modal-title { font-weight: 700; font-size: var(--fs-md); margin: 0; }
.modal-close {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: var(--c-text-3);
  font-size: 18px;
  line-height: 1;
  padding: 3px 7px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.modal-close:hover { background: var(--c-surface-3); color: var(--c-danger); }
.modal-body { padding: 14px; overflow-y: auto; flex: 1 1 auto; }
.modal-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--c-border);
  background: var(--c-surface-2);
  flex: none;
}
.modal-foot .btn { min-width: 84px; }
.modal-foot .spacer { flex: 1 1 auto; }

/* 骨架屏 */
.skeleton { padding: 4px 0; }
.sk-line, .sk-card {
  background: linear-gradient(90deg, var(--c-surface-3) 25%, var(--c-surface-2) 37%, var(--c-surface-3) 63%);
  background-size: 400% 100%;
  border-radius: var(--radius-sm);
  animation: skShimmer 1.3s ease-in-out infinite;
}
.sk-line { height: 12px; margin-bottom: 10px; }
.sk-line.w40 { width: 40%; }
.sk-line.w60 { width: 60%; }
.sk-line.w80 { width: 80%; }
.sk-card { height: 88px; margin-bottom: 12px; border-radius: var(--radius-lg); }
.sk-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
@keyframes skShimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

.loading-inline { display: inline-flex; align-items: center; gap: 8px; color: var(--c-text-3); font-size: var(--fs-sm); }
.spinner {
  width: 15px; height: 15px;
  border: 2px solid var(--c-border-strong);
  border-top-color: var(--c-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-card { border-left: 4px solid var(--c-danger); }
.error-detail {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--c-surface-3);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--c-text-2);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 180px;
  overflow: auto;
}

/* ------------------------------------------------- 10. 响应式 */
@media (max-width: 1080px) {
  :root { --sidebar-w: 168px; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  :root { --topbar-h: 56px; }
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: var(--topbar-h) minmax(0, 1fr) auto auto;
    grid-template-areas:
      "topbar"
      "view"
      "sidebar"
      "footer";
    padding-bottom: 62px; /* 给底部导航留位置 */
  }
  .brand-course { display: none; }
  .brand-name { font-size: var(--fs-base); }
  .student-picker-label { display: none; }
  .select { min-width: 118px; max-width: 40vw; }
  .points-badge { font-size: var(--fs-sm); padding: 3px 8px; }

  /* 侧栏 → 底部固定导航条 */
  .sidebar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    top: auto;
    height: auto;
    border-right: 0;
    border-top: 1px solid var(--c-border);
    padding: 5px 6px calc(5px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -4px 16px rgb(var(--c-shadow-color) / 0.08);
    overflow-x: auto;
    overflow-y: hidden;
  }
  .nav-list { flex-direction: row; gap: 2px; }
  .nav-item {
    flex: 1 0 auto;
    flex-direction: column;
    gap: 2px;
    padding: 6px 10px;
    font-size: 11px;
    border-left: 0;
    border-top: 3px solid transparent;
    border-radius: var(--radius-sm);
    min-width: 60px;
  }
  .nav-item.active { border-left-color: transparent; border-top-color: var(--c-primary); }
  .nav-ico { font-size: 17px; width: auto; }
  .nav-text { font-size: 11px; }

  .view { padding: 12px 12px 18px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .stat-num { font-size: 26px; }
  .card { padding: 13px; border-radius: var(--radius); }
  .companion-fab { right: 14px; bottom: 76px; }
  .appfooter { padding: 8px 12px 12px; }
}

@media (max-width: 420px) {
  .nav-text { display: none; }
  .nav-item { min-width: 46px; }
  .modal { width: 100%; max-height: 92vh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ------------------------------------------------- 11. 深色模式 */
/* 深色变量集中一处定义，供“跟随系统”和“手动强制深色”两种方式复用。 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --c-primary: #3b82f6;
    --c-primary-dark: #93c5fd;
    --c-primary-soft: #1c2f55;
    --c-accent: #38bdf8;
    --c-accent-soft: #10344a;
    --c-ok: #4ade80;
    --c-ok-soft: #123322;
    --c-warn: #fbbf24;
    --c-warn-soft: #3a2c0b;
    --c-danger: #f87171;
    --c-danger-soft: #3d1a1a;

    --c-bg: #0b1220;
    --c-surface: #121a2b;
    --c-surface-2: #182238;
    --c-surface-3: #22304b;
    --c-text: #e7eefb;
    --c-text-2: #b6c4da;
    --c-text-3: #8ea0bb;
    --c-border: #26334d;
    --c-border-strong: #3a4a68;
    --c-shadow-color: 0 0 0;

    --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow: 0 2px 10px rgb(0 0 0 / 0.45);
    --shadow-md: 0 6px 20px rgb(0 0 0 / 0.5);
    --shadow-lg: 0 18px 48px rgb(0 0 0 / 0.6);
  }
  /* 深色下把浅色底徽章的文字压暗一档，保证对比度 */
  :root:not([data-theme="light"]) .badge { color: #dbeafe; }
  :root:not([data-theme="light"]) .badge-ok { color: #bbf7d0; }
  :root:not([data-theme="light"]) .badge-warn { color: #fde68a; }
  :root:not([data-theme="light"]) .badge-danger { color: #fecaca; }
  :root:not([data-theme="light"]) .badge-accent { color: #bae6fd; }
  :root:not([data-theme="light"]) .badge-plain { color: var(--c-text-2); }
  :root:not([data-theme="light"]) .chip-primary { color: #dbeafe; }
  :root:not([data-theme="light"]) .chip-ok { color: #bbf7d0; }
  :root:not([data-theme="light"]) .chip-warn { color: #fde68a; }
  :root:not([data-theme="light"]) .chip-danger { color: #fecaca; }
  :root:not([data-theme="light"]) .companion-context { color: #bae6fd; }
  :root:not([data-theme="light"]) .msg.bot .msg-body code { background: rgb(255 255 255 / 0.12); color: #bfdbfe; }
  :root:not([data-theme="light"]) .modal-layer { background: rgb(0 0 0 / 0.6); }
}

/* 手动强制深色：由 store.applyTheme('dark') 写到 <html data-theme="dark"> */
:root[data-theme="dark"] {
  color-scheme: dark;
  --c-primary: #3b82f6;
  --c-primary-dark: #93c5fd;
  --c-primary-soft: #1c2f55;
  --c-accent: #38bdf8;
  --c-accent-soft: #10344a;
  --c-ok: #4ade80;
  --c-ok-soft: #123322;
  --c-warn: #fbbf24;
  --c-warn-soft: #3a2c0b;
  --c-danger: #f87171;
  --c-danger-soft: #3d1a1a;

  --c-bg: #0b1220;
  --c-surface: #121a2b;
  --c-surface-2: #182238;
  --c-surface-3: #22304b;
  --c-text: #e7eefb;
  --c-text-2: #b6c4da;
  --c-text-3: #8ea0bb;
  --c-border: #26334d;
  --c-border-strong: #3a4a68;
  --c-shadow-color: 0 0 0;

  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
  --shadow: 0 2px 10px rgb(0 0 0 / 0.45);
  --shadow-md: 0 6px 20px rgb(0 0 0 / 0.5);
  --shadow-lg: 0 18px 48px rgb(0 0 0 / 0.6);
}
:root[data-theme="dark"] .badge { color: #dbeafe; }
:root[data-theme="dark"] .badge-ok { color: #bbf7d0; }
:root[data-theme="dark"] .badge-warn { color: #fde68a; }
:root[data-theme="dark"] .badge-danger { color: #fecaca; }
:root[data-theme="dark"] .badge-accent { color: #bae6fd; }
:root[data-theme="dark"] .badge-plain { color: var(--c-text-2); }
:root[data-theme="dark"] .chip-primary { color: #dbeafe; }
:root[data-theme="dark"] .chip-ok { color: #bbf7d0; }
:root[data-theme="dark"] .chip-warn { color: #fde68a; }
:root[data-theme="dark"] .chip-danger { color: #fecaca; }
:root[data-theme="dark"] .companion-context { color: #bae6fd; }
:root[data-theme="dark"] .msg.bot .msg-body code { background: rgb(255 255 255 / 0.12); color: #bfdbfe; }
:root[data-theme="dark"] .modal-layer { background: rgb(0 0 0 / 0.6); }
:root[data-theme="light"] { color-scheme: light; }

/* ------------------------------------------------- 12. 打印样式 */
@media print {
  :root {
    --c-bg: #ffffff;
    --c-surface: #ffffff;
    --c-surface-2: #ffffff;
    --c-surface-3: #ffffff;
    --c-text: #000000;
    --c-text-2: #222222;
    --c-text-3: #444444;
    --c-border: #999999;
    --c-border-strong: #666666;
  }
  html, body { background: #fff !important; color: #000 !important; }
  .app { display: block; padding: 0; min-height: 0; }

  /* 隐藏导航与交互控件，只留内容 */
  .topbar, .sidebar, .appfooter,
  #companion-fab, #companion-drawer,
  #toast-layer, #modal-layer,
  .btn, .tabs, .toast, .modal-layer, .dropzone,
  .no-print { display: none !important; }

  .view { padding: 0 !important; overflow: visible !important; }
  .card {
    box-shadow: none !important;
    border: 1px solid var(--c-border) !important;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .table { font-size: 11pt; }
  .table thead th { position: static; background: #fff !important; }
  .grid-2, .grid-3, .grid-4, .grid-auto { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  a { color: #000 !important; text-decoration: none; }
  a[href]::after { content: ""; }
  .stat-num { color: #000 !important; }
  .progress { border: 1px solid var(--c-border); }
  .progress-bar { background: #555 !important; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .span-weakness > i, .span-weakness .span-fill { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}

/* ============ 顶栏窄屏自适应（避免页面横向溢出） ============ */
@media (max-width: 1200px) {
  .topbar { gap: 8px; padding: 0 10px; }
  .topbar-right { gap: 6px; flex-wrap: wrap; justify-content: flex-end; min-width: 0; }
  .student-picker { min-width: 0; }
}
@media (max-width: 1024px) {
  .brand-course { display: none; }
  .topbar-right .points-badge { display: none; }        /* 积分徽标在窄屏隐藏，侧栏仍可见 */
  .topbar-right .app-health { display: none; }
}
@media (max-width: 860px) {
  .topbar { flex-wrap: nowrap; }
  .brand-name { max-width: 34vw; }
  .select { min-width: 104px; max-width: 34vw; }
  .points-badge { font-size: var(--fs-xs); padding: 2px 7px; }
}
@media (max-width: 620px) {
  .topbar-right .btn { padding: 5px 9px; font-size: var(--fs-xs); }
  .brand-name { max-width: 30vw; font-size: var(--fs-base); }
}

/* ============ 中等宽度（≤1180px）：顶栏内容收窄，避免横向溢出 ============
 * 现象：学生身份徽章（348px）+ 学生下拉框（480px）+ 账号按钮在 1024px 下
 *       合计约 1036px，而侧栏还占 200px，顶栏被挤出 6~32px（文档出现横向滚动）。
 * 做法：徽章与学生下拉框限制宽度并省略号，收紧间距。 */
@media (max-width: 1180px) {
  .topbar { gap: 8px; }
  .topbar-right { gap: 6px; }
  .auth-badge {
    max-width: 22vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .student-picker .select { max-width: 26vw; }
}
@media (max-width: 960px) {
  .auth-badge { max-width: 18vw; }
  .student-picker .select { max-width: 24vw; }
  .topbar-right .btn { padding: 5px 10px; }
}

/* ====================================================================
 * 窄屏外壳（平板 + 手机 H5）：单列 + 横向导航条
 * --------------------------------------------------------------------
 * 现象：<=720px 时侧栏仍是固定 200px 宽、顶栏 right 区不换行，
 *       导致文档宽被撑到 669px（390px 视口下横向溢出）。
 * 做法：主区单列通栏；侧栏改为**顶栏下方的横向滚动导航条**
 *       （不用 JS、不用抽屉，触摸滑动即可切换栏目）。
 * ==================================================================== */
@media (max-width: 860px) {
  html, body { overflow-x: hidden; }
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    /* 侧栏排到第二行，作为横向导航条 */
    grid-template-areas:
      "topbar"
      "sidebar"
      "view"
      "footer";
    min-height: 100dvh;
  }

  /* ---- 顶栏：紧凑一行 ---- */
  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 12px;
    position: sticky;
    top: 0;
  }
  /* 手机上只留 LOGO（品牌名在横向导航与页内已有，避免与账号区挤在一起被裁） */
  .brand { gap: 0; flex: none; }
  img.brand-logo { width: 30px; height: 30px; }
  .brand-text { display: none; }
  /* 账号区：允许收缩，徽章/下拉框超长用省略号，绝不压到品牌 */
  .topbar-right {
    gap: 6px;
    flex: 1 1 auto;
    min-width: 0;
    flex-wrap: nowrap;
    justify-content: flex-end;
    overflow: hidden;
  }
  .auth-badge {
    flex: 0 1 auto;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .student-picker { flex: 0 1 auto; min-width: 0; }
  .student-picker-label { display: none; }        /* 标签占位，手机隐藏只留下拉框 */
  .student-picker .select {
    min-width: 0; max-width: 34vw; font-size: var(--fs-xs); padding: 4px 6px;
  }
  .points-badge { font-size: var(--fs-xs); padding: 2px 8px; white-space: nowrap; flex: none; }

  /* ---- 侧栏 → 横向导航条 ---- */
  .sidebar {
    position: static;
    height: auto;
    width: 100%;
    padding: 6px 10px;
    border-right: 0;
    border-bottom: 1px solid var(--c-border);
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
  }
  .sidebar::-webkit-scrollbar { display: none; }
  .nav-list {
    display: flex;
    flex-direction: row;
    gap: 8px;
    width: max-content;              /* 由内容决定宽度，配合横向滚动 */
    min-width: 100%;
  }
  .nav-item {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 13px;
    border-radius: var(--radius-pill, 999px);
    font-size: var(--fs-sm);
    white-space: nowrap;
    scroll-snap-align: start;
    min-height: 40px;                /* 触控目标 */
  }
  .nav-ico { font-size: 15px; }
  .nav-text { font-size: var(--fs-sm); }

  /* ---- 内容区 ---- */
  .view { padding: 12px 12px 22px; }
  .page-head h1 { font-size: 1.25rem; }

  /* ---- 页脚：手机上压成一行，减少占高 ---- */
  .appfooter {
    padding: 8px 12px;
    font-size: var(--fs-xs);
    flex-wrap: wrap;
    gap: 4px 6px;
  }
  .appfooter .dot-sep { display: none; }

  /* ---- 实训交互场景：手机端 iframe 高度按视口给足 ---- */
  #lab-workspace.scene-mode .scene-frame { height: min(72vh, 560px); }
}

/* 更窄的手机（<=420px）：进一步收紧 */
@media (max-width: 420px) {
  .topbar { padding: 7px 10px; }
  .view { padding: 10px 10px 20px; }
  .nav-item { padding: 7px 11px; }
  .points-badge { display: none; }   /* 极窄屏保导航与账号按钮，积分在页内看 */
}
