/* ============================================================
   原生代 · AI Natives — Design System v1
   基于 ui-ux-pro-max-skill:
     Palette: Developer Tool / IDE (Code dark + run green)
     Typography: Fira Code / Fira Sans (technical, precise)
     Style: Vibrant & Block-based (youth-focused, high contrast)
   Brand overlay:
     - 品牌主色青绿渐变 (#06B6D4 → #14B8A6 → #10B981)
     - 全局可复用 #brandGrad (SVG), --brand-* tokens (CSS)
   ============================================================ */

[hidden] { display: none !important; }

:root {
  /* 基础色：护眼深灰蓝配色（由 ui-ux-pro-max-skill 查询 "Developer Tool / IDE" 确认）
     从"纯黑高对比"调整为"深灰柔和"，减少长时间编码眼疲劳。
     色对比度验证（WCAG AA 要求 ≥4.5:1）：
     #E2E8F0 on #0F172A = 14.2:1 ✓
     #8B9EB8 on #0F172A =  6.0:1 ✓ */
  --bg:           #0F172A;  /* slate-900 最深（原 #020617 slate-950 太黑） */
  --bg-1:         #1A2332;  /* 面板（深灰蓝，在 bg-0 和 bg-2 之间平滑过渡） */
  --bg-2:         #243044;  /* 卡片（原 #1E293B 略亮，减少和面板的跳跃感） */
  --bg-3:         #334155;  /* slate-700 hover/border 保留 */
  --line:         rgba(255, 255, 255, .06);   /* 柔和分隔线（原 rgba .1 太硬） */
  --line-strong:  rgba(255, 255, 255, .12);   /* 强分隔（按钮/输入框边） */

  --text:         #E2E8F0;  /* slate-200 柔白（原 #F8FAFC 纯白刺眼） */
  --text-dim:     #8B9EB8;  /* 略带蓝的灰（原 #94A3B8 纯灰） */
  --text-muted:   #64748B;  /* slate-500 */

  /* 品牌色 —— 由 /opt/logo.png 均值采样：rgb(8,152,189) ≈ #0898BD */
  --brand-solid:  #0898BD;  /* 真实 logo 纯色，用于 logo 氛围/焦点/装饰 */
  --brand-solid-hover: #0AA8CE;
  /* 渐变仅保留给 CTA 按钮，强度比之前 减弱 ~12%（降饱和 + 淡色停 stop） */
  --brand-1:      #22A5C2;  /* 从 #06B6D4 降饱和：S -16% */
  --brand-2:      #0898BD;  /* logo 主色居中 */
  --brand-3:      #2AB48B;  /* 从 #10B981 降饱和：S -18% */
  --brand-grad:   linear-gradient(135deg, var(--brand-1), var(--brand-2), var(--brand-3));
  --brand-glow:   0 0 0 1px rgba(8, 152, 189, .28), 0 6px 20px -6px rgba(8, 152, 189, .20);

  /* 语义色 */
  --cta:          #22C55E;  /* green-500 编译成功 */
  --warn:         #F59E0B;  /* amber-500 */
  --err:          #EF4444;  /* red-500 */
  --info:         #06B6D4;  /* cyan-500 */

  /* 间距/圆角/阴影 */
  --r-1: 6px;
  --r-2: 10px;
  --r-3: 14px;
  --r-4: 20px;
  --shadow-1: 0 1px 0 rgba(255,255,255,.03) inset, 0 1px 2px rgba(0,0,0,.4);
  --shadow-2: 0 4px 12px rgba(0,0,0,.35);
  --shadow-3: 0 24px 48px -12px rgba(0,0,0,.55);

  /* z */
  --z-base: 1;
  --z-topbar: 20;
  --z-overlay: 40;
  --z-modal: 50;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  /* 界面字体：Fira Sans 英文 + 中文系统字体回退
     优先级：macOS → Windows → Linux → sans-serif */
  font-family: 'Fira Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI',
    'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei',
    'WenQuanYi Micro Hei', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* 表单元素继承字体（默认浏览器不继承 font-family） */
button, input, select, textarea {
  font-family: inherit;
}

body::before {
  /* 微妙的径向光晕背景，符合 Vibrant & Block-based 但不喧哗 */
  content: '';
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(ellipse 700px 400px at 12% 0%,  rgba(8, 152, 189, .09), transparent 60%),
    radial-gradient(ellipse 600px 300px at 90% 8%,  rgba(16, 185, 129, .05), transparent 60%);
}

/* code 等宽 —— 必须同时 disable calt+liga，Fira Code 的 `>=` / `->` / `=>` 等
   符号连字由 calt 驱动；初学者看不懂 ≥ 这种粘合符号 */
code, kbd, pre, .mono,
#logBody, .log-tail, #serialMonitor {
  font-family: 'Fira Code', 'SF Mono', Menlo, Consolas,
    'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', monospace;
  font-feature-settings: 'calt' 0, 'liga' 0;
  font-variant-ligatures: none;  /* Firefox 的备用禁连字 */
}

/* textarea 和 select 用界面字体（中英混排场景，不强制代码字体） */
textarea, select, .tb-select {
  font-family: inherit;  /* 继承 body 的 Fira Sans + 中文回退 */
}
#aiPrompt {
  /* AI 提示输入框用界面字体，中文提示词更舒服 */
  font-family: inherit;
}

/* ============================================================
   App 布局
   ============================================================ */
#app {
  position: relative;
  z-index: var(--z-base);
  height: 100vh;
  display: grid;
  grid-template-rows: 64px 1fr;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: var(--bg);
  padding: 24px;
}
.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  padding: 28px;
  background: var(--bg-1);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-2);
  box-shadow: var(--shadow-3);
}
.login-logo {
  height: 44px;
  width: auto;
}
.login-card h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}
.login-card label {
  display: grid;
  gap: 6px;
  color: var(--text-dim);
  font-size: 13px;
}
.login-card input {
  height: 42px;
  padding: 0 12px;
  color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-1);
  outline: none;
}
.login-card input:focus {
  border-color: var(--brand-2);
  box-shadow: var(--brand-glow);
}
.login-error {
  min-height: 20px;
  margin: 0;
  color: var(--err);
}
.user-badge {
  color: var(--text-dim);
  font-size: 12px;
  white-space: nowrap;
}

#layout {
  display: grid;
  /* 五列：左栏 | resizer | 中栏 | resizer | 右栏；三栏宽度由 CSS 变量驱动便于 JS 调整 */
  grid-template-columns:
    var(--left-w, 240px)
    4px
    minmax(0, 1fr)
    4px
    var(--right-w, 260px);
  min-height: 0;
  gap: 0;
  border-top: 1px solid var(--line);
}

/* 拖拽分隔条 */
.resizer {
  background: transparent;
  cursor: col-resize;
  position: relative;
  z-index: 5;
  transition: background 150ms ease;
  user-select: none;
}
.resizer::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  left: 1px; right: 1px;
  background: var(--line);
  transition: background 150ms ease;
}
.resizer:hover::before,
.resizer.dragging::before {
  background: var(--brand-2);
}
.resizer.dragging {
  background: rgba(8, 152, 189, .08);
}
/* 拖拽时全局禁用选中和 cursor 固定，避免鼠标离开 resizer 后 cursor 变回箭头 */
body.resizing,
body.resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}

/* ============================================================
   顶部工具栏
   ============================================================ */
#topbar {
  z-index: var(--z-topbar);
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 20px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
  color: var(--text);
  cursor: pointer;
}
.brand-mark {
  flex: none;
  height: 36px;
  width: auto;
  display: block;
  filter: drop-shadow(0 2px 8px rgba(8, 152, 189, .35));
  transition: filter 200ms ease, transform 200ms ease;
}
.brand:hover .brand-mark {
  filter: drop-shadow(0 4px 16px rgba(8, 152, 189, .55));
  transform: translateY(-1px);
}

.brand-slogan {
  padding-left: 14px;
  border-left: 1px solid rgba(148, 163, 184, .2);
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 400;
  letter-spacing: .4px;
  line-height: 1.2;
  white-space: nowrap;
}

.topbar-sep {
  flex: 1;
  height: 24px;
  border-left: 1px solid var(--line);
  margin: 0 4px;
}

.topbar-controls {
  display: flex; align-items: center; gap: 12px;
}
.tb-field {
  display: flex; align-items: center; gap: 8px;
  padding: 0 10px 0 14px; height: 40px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-2);
  transition: border-color 150ms ease;
}
.tb-field:focus-within { border-color: var(--brand-2); box-shadow: var(--brand-glow); }
.tb-label { font-size: 11px; color: var(--text-muted); letter-spacing: .5px; text-transform: uppercase; }
.tb-select {
  background: transparent; color: var(--text); border: none; outline: none;
  font-size: 13px; padding: 0 4px; cursor: pointer; appearance: none;
}
.tb-select option { background: var(--bg-1); color: var(--text); }

/* ============================================================
   Button
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 0 16px; height: 40px;
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--r-2);
  font-family: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer; white-space: nowrap;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease, transform 150ms ease;
}
.btn:hover { background: var(--bg-3); border-color: var(--brand-2); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; border-color: var(--brand-2); box-shadow: var(--brand-glow); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:disabled:hover { background: var(--bg-2); border-color: var(--line-strong); }

.btn-primary {
  background: var(--brand-grad); color: #020617;
  border: none;
  font-weight: 600;
  box-shadow: var(--brand-glow);
}
.btn-primary:hover { filter: brightness(1.08); background: var(--brand-grad); }
.btn-primary .icon { stroke: #020617; }

.btn-ghost {
  background: transparent;
  border-color: rgba(148, 163, 184, .18);  /* slate-400 18%，细淡 */
}
.btn-ghost:hover {
  background: rgba(148, 163, 184, .06);
  border-color: rgba(20, 184, 166, .35);    /* hover 时品牌色边 */
}

.btn-mini {
  padding: 0 10px; height: 28px; font-size: 12px;
  border-radius: var(--r-1);
}

.icon { width: 16px; height: 16px; flex: none; }
.icon-sm { width: 14px; height: 14px; flex: none; }

/* ============================================================
   Status 徽章
   ============================================================ */
.status {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0 10px; height: 26px; border-radius: 999px;
  font-size: 11px; font-weight: 500;
  border: 1px solid transparent;
}
.status::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
}
.status-off { background: rgba(239,68,68,.12); color: #FCA5A5; border-color: rgba(239,68,68,.25); }
.status-on  { background: rgba(34,197,94,.12);  color: #86EFAC; border-color: rgba(34,197,94,.25); }

.cstatus {
  display: inline-flex; align-items: center;
  padding: 0 10px; height: 26px; border-radius: 999px;
  font-size: 11px; font-weight: 500;
}
.cstatus.idle { background: var(--bg-2); color: var(--text-dim); border: 1px solid var(--line-strong); }
.cstatus.busy { background: rgba(245,158,11,.12); color: #FCD34D; border: 1px solid rgba(245,158,11,.28); }
.cstatus.ok   { background: rgba(34,197,94,.12); color: #86EFAC; border: 1px solid rgba(34,197,94,.28); }
.cstatus.err  { background: rgba(239,68,68,.12); color: #FCA5A5; border: 1px solid rgba(239,68,68,.28); }
.cstatus.warn { background: rgba(245,158,11,.15); color: #FBBF24; border: 1px solid rgba(245,158,11,.35); }

/* ============================================================
   左栏 / 右栏 共享
   ============================================================ */
aside {
  background: var(--bg-1);
  display: flex; flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
#leftPane  { border-right: 1px solid var(--line); }
#rightPane { border-left:  1px solid var(--line); }

.pane-section {
  display: flex; flex-direction: column;
  min-height: 0;
  border-bottom: 1px solid var(--line);
}
.pane-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 10px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
.pane-head:hover { color: var(--text-dim); }
.pane-title { font-weight: 600; }

.pane-foot {
  margin-top: auto; padding: 12px 16px;
  text-align: center; color: var(--text-muted);
  font-size: 11px; line-height: 1.5;
  border-top: 1px solid var(--line);
}

/* 折叠（details）*/
details.collapsible > summary { list-style: none; }
details.collapsible > summary::-webkit-details-marker { display: none; }
details.collapsible .chev { width: 14px; height: 14px; transition: transform 200ms ease; color: var(--text-muted); }
details.collapsible[open] .chev { transform: rotate(180deg); }

.monitor-body {
  display: flex; flex-direction: column; gap: 6px;
  padding: 0 16px 14px;
  min-height: 0;
}
#serialMonitor {
  margin: 0; padding: 10px 12px;
  min-height: 120px; max-height: 30vh;
  background: var(--bg);
  border: 1px solid var(--line-strong); border-radius: var(--r-2);
  font-size: 11px; color: #CBD5E1;
  white-space: pre-wrap; word-break: break-all;
  overflow-y: auto; overflow-x: hidden;
}

/* ============================================================
   Session / Version 列表
   ============================================================ */
.list {
  list-style: none; margin: 0;
  padding: 4px 10px 10px;
  overflow-y: auto; min-height: 0;
  display: flex; flex-direction: column; gap: 4px;
}

.list-item {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-2);
  cursor: pointer;
  text-align: left; width: 100%;
  font: inherit; color: var(--text);
  transition: background 150ms ease, border-color 150ms ease;
}
.list-item:hover { background: var(--bg-2); border-color: var(--line-strong); }
.list-item:focus-visible { outline: none; border-color: var(--brand-2); box-shadow: var(--brand-glow); }
.list-item.active {
  background: linear-gradient(135deg, rgba(6,182,212,.08), rgba(16,185,129,.08));
  border-color: rgba(20,184,166,.35);
}
.list-item.active::before {
  content: ''; position: absolute;
}

.list-item .star {
  width: 14px; height: 14px; color: var(--text-muted);
  transition: color 150ms ease;
}
.list-item .star.active { color: #FBBF24; fill: #FBBF24; }
.list-item .star:hover { color: #FBBF24; }

.list-item-main {
  min-width: 0;
}
.list-item-title {
  font-size: 13px; font-weight: 500; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.list-item-sub {
  font-size: 11px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 2px;
}
.list-item-aside {
  font-size: 10px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .5px;
}

.version-item .list-item-aside .badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
}
.badge-ai      { background: rgba(6,182,212,.15);  color: #7DD3FC; }
.badge-fix     { background: rgba(245,158,11,.15); color: #FBBF24; }
.badge-initial { background: rgba(148,163,184,.15); color: #CBD5E1; }
.badge-restore { background: rgba(16,185,129,.15); color: #6EE7B7; }

/* ============================================================
   Tab 切换（右栏）
   ============================================================ */
.tab-head {
  display: flex; align-items: stretch;
  padding: 12px 10px 0;
  border-bottom: 1px solid var(--line);
  background: var(--bg-1);
}
.tab {
  flex: 1;
  padding: 10px 8px;
  background: transparent; border: none;
  color: var(--text-muted);
  font: inherit; font-weight: 500; font-size: 12px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 150ms ease, border-color 150ms ease;
}
.tab:hover { color: var(--text-dim); }
.tab.active { color: var(--text); border-bottom-color: var(--brand-2); }
.tab:focus-visible { outline: none; color: var(--text); }

.tab-panel { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.tab-panel[hidden] { display: none; }

.version-actions {
  padding: 10px 12px 4px;
  display: flex; justify-content: flex-end;
}

/* 会话条目扩展：删除/星标按钮 hover 才显示 */
.list-item .item-actions {
  display: flex; gap: 4px; opacity: 0;
  transition: opacity 150ms ease;
}
.list-item:hover .item-actions,
.list-item.active .item-actions { opacity: 1; }
.item-action-btn {
  width: 22px; height: 22px; padding: 3px;
  background: transparent; border: none; border-radius: 4px;
  color: var(--text-muted); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.item-action-btn:hover { background: rgba(255,255,255,.08); color: var(--text); }
.item-action-btn.danger:hover { color: #FCA5A5; }

.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 48px 24px; color: var(--text-muted);
  text-align: center;
}
.empty-state p { margin: 8px 0 0; font-size: 13px; color: var(--text-dim); }
.empty-state small { font-size: 11px; }

/* ============================================================
   中栏 Monaco + AI + Log
   ============================================================ */
#centerPane {
  display: grid;
  grid-template-rows: 1fr auto auto;
  min-width: 0; min-height: 0;
  background: var(--bg);
}

#editor {
  min-width: 0; min-height: 0;
  border-bottom: 1px solid var(--line);
}

/* AI 面板 */
#aiPanel {
  padding: 14px 18px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 10px;
}
.ai-head {
  display: flex; align-items: center; gap: 10px;
  font-size: 12px; font-weight: 600; color: var(--text);
}
.ai-head .brand-icon { color: var(--brand-2); }
.ai-sub {
  font-size: 10px; color: var(--text-muted);
  font-weight: 400; letter-spacing: .3px;
  flex: 1;
}
.ai-status-pill { margin-left: auto; }

.ai-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: stretch;
}
#aiPrompt {
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--r-2);
  padding: 10px 12px; font-size: 13px;
  resize: vertical; min-height: 44px; max-height: 140px;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
#aiPrompt:focus { border-color: var(--brand-2); box-shadow: var(--brand-glow); }
#aiPrompt::placeholder { color: var(--text-muted); }
.ai-row .btn { align-self: stretch; height: auto; }

/* Log 半折叠 —— 折叠时只占一行，展开时固定 40 + 200 = 240px，不挤 Monaco */
#logPanel {
  background: var(--bg-1);
  border-top: 1px solid var(--line);
  display: flex; flex-direction: column;
  min-height: 0;
}
#logPanel:not([open]) .log-head .log-tail { display: inline-block; }
#logPanel[open] .log-head .log-tail { display: none; }
.log-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 18px;
  cursor: pointer; user-select: none;
}
.log-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--text-muted); font-weight: 600;
}
.log-tail {
  flex: 1;
  font-family: 'Fira Code', monospace; font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#logBody {
  margin: 0; padding: 12px 18px;
  background: var(--bg);
  font-size: 11px;
  color: #CBD5E1;
  /* 展开时固定 200px 可滚动，不挤 Monaco */
  height: 200px;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  border-top: 1px solid var(--line);
}
#logPanel:not([open]) #logBody { display: none; }
#logBody .err  { color: #FCA5A5; }
#logBody .ok   { color: #86EFAC; }
#logBody .info { color: #7DD3FC; }

/* ============================================================
   可访问性与偏好
   ============================================================ */
*:focus-visible { outline: none; }

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

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--bg-3); border-radius: 999px;
  border: 2px solid var(--bg-1);
}
::-webkit-scrollbar-thumb:hover { background: #475569; }

/* ============================================================
   响应式 (1024 以下收起右栏，768 以下再收起左栏)
   ============================================================ */
@media (max-width: 1280px) {
  #layout { --left-w: 220px; --right-w: 240px; }
}
@media (max-width: 1024px) {
  #layout {
    grid-template-columns: var(--left-w, 220px) 4px minmax(0, 1fr);
  }
  #rightPane,
  #resizerRight { display: none; }
}
@media (max-width: 768px) {
  #app { grid-template-rows: auto minmax(0, 1fr); }
  #topbar {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 10px;
    min-width: 0;
    padding: 10px 12px;
  }
  .brand {
    flex: 1 1 100%;
    min-width: 0;
  }
  .brand-mark { height: 30px; }
  .brand-slogan,
  .topbar-sep,
  .tb-field { display: none; }
  .topbar-controls {
    width: 100%;
    min-width: 0;
    flex-wrap: wrap;
    gap: 8px;
  }
  .topbar-controls .btn {
    height: 34px;
    padding: 0 10px;
    font-size: 12px;
  }
  .topbar-controls .status,
  .topbar-controls .cstatus,
  .topbar-controls .user-badge {
    height: 24px;
    font-size: 10px;
  }
  #layout { grid-template-columns: minmax(0, 1fr); }
  #leftPane,
  #resizerLeft { display: none; }
}

/* ========== 已学会的库折叠面板（命题 4）========== */
.lib-map-panel {
  margin-top: 2px;
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  background: var(--bg-2);
}
.lib-map-head {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  cursor: pointer; user-select: none;
  font-size: 12px; color: var(--text-dim);
  list-style: none;
}
.lib-map-head::-webkit-details-marker { display: none; }
.lib-map-head:hover { color: var(--text); }
.lib-map-title { flex: 1; }
.lib-map-title b { color: var(--brand-2); font-weight: 600; padding: 0 2px; }
.lib-map-panel .chev {
  width: 14px; height: 14px; color: var(--text-muted);
  transition: transform 200ms ease;
}
.lib-map-panel[open] .chev { transform: rotate(180deg); }
.lib-map-body {
  border-top: 1px solid var(--line);
  padding: 8px 12px;
  max-height: 160px; overflow-y: auto;
}
.lib-map-list {
  list-style: none; margin: 0; padding: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 14px;
  font-family: 'Fira Code', ui-monospace, monospace;
  font-size: 11px;
  font-feature-settings: 'calt' 0, 'liga' 0;
}
.lib-map-list li {
  display: contents;
}
.lib-map-list .lm-header {
  color: var(--text);
  white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.lib-map-list .lm-lib {
  color: var(--text-dim);
  text-align: right;
  white-space: nowrap;
}
.lib-map-list .lm-empty {
  grid-column: 1 / -1;
  color: var(--text-muted);
  padding: 4px 0;
  font-family: inherit;
  font-size: 11px;
  text-align: center;
}

/* ========== AI 对话面板（右栏 Tab）========== */
.tab-panel[data-panel="ai-chat"] {
  padding: 0;
  min-height: 0;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}
/* ========== 风格 A · 分点结构气泡 ========== */
.chat-bubble {
  max-width: 92%;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

/* 用户气泡：右对齐青绿渐变，右上角直角 */
.chat-bubble.bubble-user {
  align-self: flex-end;
  background: linear-gradient(135deg, #06B6D4, #0898BD);
  color: #fff;
  padding: 10px 14px;
  border-radius: 16px 16px 4px 16px;
  font-size: 14px;
  line-height: 1.55;
  box-shadow: 0 2px 8px rgba(8, 152, 189, .18);
  white-space: pre-wrap;
}

/* AI 气泡：左对齐深灰蓝，左上角直角 */
.chat-bubble.bubble-ai {
  align-self: flex-start;
  background: #1A2332;
  border: 0.5px solid rgba(255, 255, 255, .08);
  border-radius: 4px 16px 16px 16px;
  padding: 12px 16px;
  color: #E2E8F0;
}

/* 顶部说明（meta） */
.bubble-meta {
  font-size: 11px;
  color: #64748B;
  margin-bottom: 8px;
  letter-spacing: .2px;
}

/* 正文普通段落 */
.bubble-body {
  font-size: 13px;
  line-height: 1.7;
  color: #E2E8F0;
}
.bubble-body > p {
  margin: 0 0 6px;
}
.bubble-body > p:last-child {
  margin-bottom: 0;
}

/* 分点列表：青色圆点 + flex 对齐 */
.bubble-points {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.bubble-points li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 13px;
  line-height: 1.6;
  color: #E2E8F0;
}
.bubble-points li::before {
  content: '';
  flex-shrink: 0;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #0898BD;
  margin-top: 7px;
}

/* 步骤列表：圆形数字编号 */
.bubble-steps {
  list-style: none;
  counter-reset: step;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.bubble-steps li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 13px;
  line-height: 1.6;
  color: #E2E8F0;
  counter-increment: step;
}

/* 列表项文本容器：包住所有文字和行内代码，让它们按普通 inline flow 排列
   flex: 1 1 0 让它占满剩余空间；min-width: 0 允许在 flex 容器内被压缩
   否则 nowrap 的 .inline-code 会把这个 span 撑得超出气泡宽度 */
.bubble-points li > .bubble-li-text,
.bubble-steps li > .bubble-li-text {
  flex: 1 1 0;
  min-width: 0;
  display: block;
  word-break: break-word;
  overflow-wrap: break-word;
}
.bubble-steps li::before {
  content: counter(step);
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(8, 152, 189, .2);
  color: #0898BD;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}

/* 底部引导问题 */
.bubble-guide {
  border-top: 0.5px solid rgba(255, 255, 255, .06);
  padding-top: 8px;
  margin-top: 10px;
  font-size: 12px;
  color: #0898BD;
  line-height: 1.55;
}

/* 行内代码 · 青色高亮 */
.chat-bubble.bubble-ai .inline-code {
  font-family: 'Fira Code', ui-monospace, monospace;
  font-feature-settings: 'calt' 0, 'liga' 0;
  background: rgba(8, 152, 189, .15);
  color: #5DCAA5;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

/* 粗体 */
.chat-bubble.bubble-ai .bubble-bold {
  font-weight: 500;
  color: #F1F5F9;
}

/* 上下块间距（meta → 内容 → guide）*/
.bubble-meta + .bubble-points,
.bubble-meta + .bubble-steps,
.bubble-meta + .bubble-body {
  margin-top: 0;
}
.bubble-body + .bubble-points,
.bubble-body + .bubble-steps,
.bubble-points + .bubble-body,
.bubble-steps + .bubble-body {
  margin-top: 8px;
}

/* loading 气泡 */
.chat-bubble.loading {
  align-self: flex-start;
  background: #1A2332;
  border: 0.5px solid rgba(255, 255, 255, .08);
  border-radius: 4px 16px 16px 16px;
  padding: 10px 14px;
  color: #64748B;
  font-style: italic;
  font-size: 13px;
}
.chat-bubble.loading::after {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  background: #0898BD;
  border-radius: 50%;
  margin-left: 4px;
  animation: chatPulse 1.2s ease-in-out infinite;
}
@keyframes chatPulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}
.chat-empty {
  color: var(--text-muted);
  text-align: center;
  padding: 32px 16px;
  font-size: 12px;
}
.chat-input-row {
  border-top: 1px solid var(--line);
  padding: 10px 12px;
  background: var(--bg-1);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: stretch;
}
#chatInput {
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--r-2);
  padding: 8px 10px; font-size: 12.5px;
  resize: vertical; min-height: 40px; max-height: 120px;
  outline: none;
  font-family: inherit;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
#chatInput:focus { border-color: var(--brand-2); box-shadow: var(--brand-glow); }
#chatInput::placeholder { color: var(--text-muted); }
#chatSendBtn { align-self: stretch; height: auto; padding: 0 14px; }

/* ========== 按钮 disabled 统一样式（节流保护）========== */
.btn[disabled],
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(40%);
  pointer-events: none;
}


/* ============================================================
   Teacher dashboard - polished workspace
   ============================================================ */
.teacher-dashboard {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: none;
  align-items: stretch;
  justify-content: stretch;
  padding: 0;
  background: rgba(15, 23, 42, .92);
  backdrop-filter: blur(14px);
}
.td-shell {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: 64px 96px minmax(0, 1fr);
  gap: 0;
  background: var(--bg);
  color: var(--text);
}
.td-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  padding: 0 22px;
  background: rgba(26, 35, 50, .96);
  border-bottom: 1px solid var(--line);
}
.td-brandline {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 14px;
}
.td-kicker {
  display: inline-flex;
  align-items: center;
  height: 26px;
  padding: 0 10px;
  color: var(--brand-1);
  background: rgba(8, 152, 189, .12);
  border: 1px solid rgba(8, 152, 189, .24);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.td-topbar h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1;
  letter-spacing: 0;
}
.td-head-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: var(--text-dim);
  font-size: 12px;
}
.td-summary {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 1px;
  padding: 1px 22px 0;
  background: var(--line);
  border-bottom: 1px solid var(--line);
}
.td-card {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 6px;
  padding: 14px 14px 12px;
  background: var(--bg-1);
}
.td-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.td-card-label,
.td-card-sub,
.td-row-meta,
.td-row-sub,
.td-muted,
.td-error-item span {
  color: var(--text-dim);
  font-size: 12px;
}
.td-card-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--brand-2);
  box-shadow: 0 0 0 3px rgba(8, 152, 189, .12);
}
.td-card-value {
  align-self: center;
  font-size: 26px;
  line-height: 1;
  font-weight: 700;
}
.td-card-attention .td-card-dot { background: var(--warn); box-shadow: 0 0 0 3px rgba(245, 158, 11, .14); }
.td-card-compile .td-card-dot { background: var(--cta); box-shadow: 0 0 0 3px rgba(34, 197, 94, .14); }
.td-workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(420px, 1.1fr) minmax(320px, .88fr) minmax(340px, .92fr);
  grid-template-rows: minmax(0, 1fr) minmax(220px, .54fr);
  grid-template-areas:
    "roster inspector feed"
    "roster issues feed";
  gap: 1px;
  padding: 1px 22px 22px;
  background: var(--line);
}
.td-roster { grid-area: roster; }
.td-inspector { grid-area: inspector; }
.td-feed { grid-area: feed; }
.td-issues { grid-area: issues; }
.td-roster,
.td-inspector,
.td-feed,
.td-issues {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--bg-1);
}
.td-section-head {
  min-width: 0;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
}
.td-section-head.compact {
  align-items: start;
}
.td-section-head h3 {
  margin: 0;
  font-size: 14px;
  line-height: 1.15;
  letter-spacing: 0;
}
.td-section-head p {
  margin: 4px 0 0;
  color: var(--text-dim);
  font-size: 12px;
}
.td-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}
.td-tools input,
.td-tools select {
  height: 34px;
  min-width: 0;
  color: var(--text);
  background: var(--bg-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-1);
  padding: 0 10px;
  outline: none;
}
.td-tools input { width: 170px; }
.td-tools input:focus,
.td-tools select:focus {
  border-color: var(--brand-2);
  box-shadow: var(--brand-glow);
}
.td-table-wrap,
.td-list,
.td-detail-body {
  min-height: 0;
  overflow: auto;
}
.td-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
.td-table th,
.td-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.td-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--text-dim);
  background: var(--bg-1);
  font-size: 12px;
  font-weight: 600;
}
.td-table tbody tr {
  cursor: pointer;
  transition: background 120ms ease, box-shadow 120ms ease;
}
.td-table tbody tr:hover,
.td-table tbody tr.active {
  background: rgba(8, 152, 189, .13);
  box-shadow: inset 3px 0 0 var(--brand-2);
}
.td-table tbody tr.needs-help .td-name strong {
  color: #FBBF24;
}
.td-name {
  display: grid;
  gap: 2px;
}
.td-name strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.td-name small,
.td-help-text {
  color: #FBBF24;
  font-size: 11px;
}
.td-online { color: var(--cta); }
.td-offline { color: var(--text-dim); }
.td-empty,
.td-empty-cell {
  color: var(--text-dim);
  text-align: center;
  padding: 20px;
}
.td-detail-body {
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 16px;
}
.td-detail-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.td-detail-title strong {
  min-width: 0;
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.td-pill {
  flex: 0 0 auto;
  padding: 2px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--text-dim);
  font-size: 12px;
}
.td-pill.on {
  color: var(--cta);
  border-color: rgba(34, 197, 94, .45);
  background: rgba(34, 197, 94, .08);
}
.td-facts {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 9px 12px;
  margin: 0;
}
.td-facts dt {
  color: var(--text-dim);
  font-size: 12px;
}
.td-facts dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}
.td-latest-project,
.td-error-box {
  display: grid;
  gap: 8px;
  padding: 12px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--r-1);
}
.td-list {
  display: grid;
  align-content: start;
}
.td-list-item,
.td-error-item {
  width: 100%;
  display: grid;
  gap: 5px;
  padding: 12px 14px;
  color: var(--text);
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
}
.td-list-item {
  cursor: pointer;
}
.td-list-item:hover {
  background: rgba(8, 152, 189, .10);
}
.td-error-item {
  border-left: 3px solid rgba(239, 68, 68, .72);
}
.td-error-box {
  border-color: rgba(239, 68, 68, .28);
}
.td-error-box p,
.td-error-item p {
  margin: 0;
  color: var(--text-dim);
  font-size: 12px;
  overflow-wrap: anywhere;
}
@media (max-width: 1120px) {
  .td-summary {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .td-shell {
    grid-template-rows: 64px auto minmax(0, 1fr);
  }
  .td-workspace {
    grid-template-columns: minmax(360px, 1fr) minmax(320px, .85fr);
    grid-template-rows: minmax(360px, 1fr) minmax(220px, .52fr) minmax(220px, .52fr);
    grid-template-areas:
      "roster inspector"
      "roster issues"
      "feed feed";
  }
}
@media (max-width: 720px) {
  .teacher-dashboard {
    overflow: auto;
    align-items: start;
  }
  .td-shell {
    min-height: 100vh;
    height: auto;
    grid-template-rows: auto auto auto;
  }
  .td-topbar {
    align-items: start;
    gap: 12px;
    padding: 14px;
  }
  .td-brandline,
  .td-head-meta {
    align-items: start;
    flex-direction: column;
    gap: 8px;
  }
  .td-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 1px 14px 0;
  }
  .td-workspace {
    grid-template-columns: 1fr;
    grid-template-rows: repeat(4, auto);
    grid-template-areas:
      "roster"
      "inspector"
      "feed"
      "issues";
    padding: 1px 14px 14px;
  }
  .td-roster,
  .td-inspector,
  .td-feed,
  .td-issues {
    min-height: 260px;
  }
  .td-section-head {
    align-items: stretch;
    flex-direction: column;
  }
  .td-tools input,
  .td-tools select {
    flex: 1 1 0;
    width: auto;
  }
  .td-table th:nth-child(2),
  .td-table td:nth-child(2),
  .td-table th:nth-child(5),
  .td-table td:nth-child(5) {
    display: none;
  }
}

