/* SciLadder · 科阶 — 学习页「阶段抽屉 + 纸张」组件样式 */

/* 一、吸顶包裹：topbar + 阶段选择器（像抽屉把手一样始终可点） */
.session-sticky {
  position: sticky;
  top: 0;
  z-index: 32;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  padding: 8px 0 10px;
  margin: 0 0 10px;
}

/* 滚动时内容从玻璃条下方穿过：暖白渐变 + 轻模糊做「纸面下沿」 */
.session-sticky::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: -24px 0 0;
  pointer-events: none;
  background: linear-gradient(
    to bottom,
    #f9f8f8 0%,
    #f9f8f8 72%,
    rgba(249, 248, 248, 0.9) 90%,
    rgba(249, 248, 248, 0) 100%
  );
  backdrop-filter: blur(8px);
}

/* 契约要求：topbar 原先自身 sticky，进入吸顶容器后改为静态 */
.session-sticky .topbar {
  position: static;
  top: auto;
  z-index: auto;
  margin: 0;
  flex-shrink: 0;
}

.stage-pills {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1 1 auto;
  min-width: 0;
  /* 5px 内边距给 :focus-visible 焦点环留空间，负 margin 抵消视觉偏移 */
  padding: 5px;
  margin: -5px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.stage-pills::-webkit-scrollbar { display: none; }

/* ---------- 单个阶段 pill ---------- */
.stage-pill {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: var(--ds-r-pill);
  background: transparent;
  color: var(--ds-muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 170ms var(--ds-ease-std),
    border-color 170ms var(--ds-ease-std), color 170ms var(--ds-ease-std),
    box-shadow 170ms var(--ds-ease-std), transform 120ms var(--ds-ease-std);
}
.stage-pill:hover { background: rgba(255, 255, 255, 0.72); color: var(--ds-heading); }
.stage-pill:active { transform: scale(0.975); }

.stage-pill-key {
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}
.stage-pill-title { font-size: 12.5px; font-weight: 500; }
.stage-pill[data-stage="EXT"] .stage-pill-key { font-size: 12px; font-weight: 600; letter-spacing: 0.01em; }

/* done：已完成、白底淡边、品牌深色字，可点回看 */
.stage-pill[data-status="done"] {
  background: rgba(255, 255, 255, 0.86);
  border-color: var(--ds-border-subtle);
  color: var(--ds-brand-ink);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(21, 36, 67, 0.04);
}
.stage-pill[data-status="done"]:hover {
  background: #fff;
  border-color: rgba(77, 107, 254, 0.26);
  box-shadow: 0 2px 10px -3px rgba(77, 107, 254, 0.22);
  color: var(--ds-brand-deep);
}

/* active：当前抽屉，品牌填充 + 柔光（JS 同时写 data-status="active" 与 .is-active） */
.stage-pill[data-status="active"],
.stage-pill.is-active {
  background: linear-gradient(135deg, var(--ds-brand) 0%, var(--ds-brand-medium) 100%);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 10px -2px rgba(77, 107, 254, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
}
.stage-pill[data-status="active"]:hover,
.stage-pill.is-active:hover {
  background: linear-gradient(135deg, var(--ds-brand-medium) 0%, var(--ds-brand) 100%);
  color: #fff;
}
.stage-pill[data-status="active"] .stage-pill-title,
.stage-pill.is-active .stage-pill-title {
  opacity: 0.94;
}

/* next：下一个可进入但尚无内容，虚线边 + 品牌字 */
.stage-pill[data-status="next"] { border: 1px dashed rgba(77, 107, 254, 0.38); background: hsla(0, 0%, 100%, 0.32); color: var(--ds-brand-ink); }
.stage-pill[data-status="next"]:hover { border-color: rgba(77, 107, 254, 0.55); background: var(--ds-brand-soft); color: var(--ds-brand-deep); }

/* locked / disabled：未解锁，置灰不可点 */
.stage-pill[data-status="locked"],
.stage-pill[disabled] {
  border-color: var(--ds-border-subtle);
  background: hsla(0, 0%, 100%, 0.26);
  color: var(--ds-faint);
  opacity: 0.58;
  box-shadow: none;
  cursor: not-allowed;
}
.stage-pill[data-status="locked"]:hover,
.stage-pill[disabled]:hover {
  background: hsla(0, 0%, 100%, 0.26);
  color: var(--ds-faint);
}
.stage-pill[disabled]:active { transform: none; }

/* 完成勾选徽记：仅 done 显示 */
.stage-pill-check {
  display: none;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--ds-brand-soft);
  color: var(--ds-brand-ink);
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
}
.stage-pill-check::before { content: "✓"; transform: translateY(-0.5px); }
.stage-pill[data-status="done"] .stage-pill-check { display: inline-flex; }

/* 「最新阶段」小圆点 */
.stage-pill[data-latest="true"]::after {
  content: "";
  flex-shrink: 0;
  width: 5px;
  height: 5px;
  margin-left: 1px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.6;
}
.stage-pill[data-status="active"][data-latest="true"]::after,
.stage-pill.is-active[data-latest="true"]::after {
  background: #fff;
  opacity: 0.92;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.18);
}

/* 二、抽屉卡片（玻璃大卡：head / body / foot 三段） */
.stage-drawer {
  position: relative;
  display: flex;
  flex-direction: column;
  margin: 0 0 18px;
  border-radius: var(--ds-r-card);
  border: 1px solid var(--ds-border-glass);
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.64) 0%,
    rgba(255, 255, 255, 0.5) 100%
  );
  box-shadow: var(--ds-shadow-card);
  backdrop-filter: blur(var(--ds-blur)) saturate(140%);
}

/* 抽屉进入：JS 加 .is-entering，约 200ms 后移除 */
.stage-drawer.is-entering { animation: drawer-enter 200ms var(--ds-ease-out); }
@keyframes drawer-enter {
  from {
    opacity: 0;
    transform: translateY(9px) scale(0.996);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- 抽屉头：阶段徽章 + 标题 + 计数 + 工具 ---------- */
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 15px 22px 13px;
  border-bottom: 1px solid var(--ds-border-subtle);
  border-radius: var(--ds-r-card) var(--ds-r-card) 0 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.46), rgba(255, 255, 255, 0));
}
.drawer-head-main {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 auto;
}
.drawer-stage-key {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  height: 26px;
  padding: 0 10px;
  border: 1px solid rgba(77, 107, 254, 0.16);
  border-radius: var(--ds-r-pill);
  background: var(--ds-brand-soft);
  color: var(--ds-brand-ink);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.03em;
  font-variant-numeric: tabular-nums;
}
.drawer-title {
  margin: 0;
  min-width: 0;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.005em;
  color: var(--ds-heading);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.drawer-sub {
  flex-shrink: 0;
  margin-left: 2px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--ds-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.drawer-tools {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}
.drawer-delete-paper:hover:not([disabled]) { background: var(--ds-danger-soft); color: var(--ds-danger); }
.drawer-delete-paper[disabled] { opacity: 0.4; cursor: not-allowed; }

/* 阶段专属的 key 徽章配色（与现有 .layer-l1~l4 语义一致） */
.stage-drawer[data-stage="L1"] .drawer-stage-key { background: var(--ds-brand-soft); border-color: rgba(77, 107, 254, 0.16); color: var(--ds-brand-ink); }
.stage-drawer[data-stage="L2"] .drawer-stage-key { background: rgba(3, 105, 161, 0.1); border-color: rgba(3, 105, 161, 0.18); color: #0369a1; }
.stage-drawer[data-stage="L3"] .drawer-stage-key { background: var(--ds-warning-soft); border-color: var(--ds-warning-border); color: var(--ds-warning-ink); }
.stage-drawer[data-stage="L4"] .drawer-stage-key { background: rgba(124, 58, 237, 0.1); border-color: rgba(124, 58, 237, 0.2); color: var(--ds-violet); }
.stage-drawer[data-stage="EXT"] .drawer-stage-key { background: var(--ds-success-soft); border-color: var(--ds-success-border); color: var(--ds-success-ink); }

/* ---------- 抽屉主体：纸张 + 右侧导轨 ---------- */
.drawer-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 14px;
  padding: 18px 18px 16px 22px;
}

/* 三、纸张：每轮「用户提问 + AI 回答」一张白纸 */
.paper-scroll { min-width: 0; }
.paper-scroll.is-switching .paper,
.stage-drawer.is-switching .paper {
  animation: paper-switch 160ms var(--ds-ease-out);
}
@keyframes paper-switch {
  from {
    opacity: 0.3;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.paper {
  position: relative;
  padding: 20px 22px 24px;
  border-radius: 20px;
  border: 1px solid var(--ds-border-subtle);
  background: #fff;
  box-shadow: 0 0 0 1px rgba(21, 36, 67, 0.02), 0 1px 2px rgba(21, 36, 67, 0.04),
    0 18px 40px -30px rgba(21, 36, 67, 0.4);
}
/* 流式生成中的纸张：品牌色细边提示「正在写」 */
.paper[data-live="true"] { border-color: rgba(77, 107, 254, 0.16); }

/* 用户提问：品牌柔光气泡（沿用 .msg-user .msg-bubble 的语言，独立实现） */
.paper-q { display: flex; flex-direction: column; align-items: flex-end; }
.paper-q-label {
  margin: 0 4px 5px 0;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.02em;
  color: var(--ds-brand-ink);
  opacity: 0.78;
}
.paper-q-text {
  max-width: 82%;
  margin: 0;
  padding: 11px 15px;
  border: 1px solid rgba(77, 107, 254, 0.14);
  border-radius: 18px 18px 6px 18px;
  background: var(--ds-brand-soft);
  color: var(--ds-ink);
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* AI 回答 */
.paper-a { margin-top: 18px; min-width: 0; }
.paper-a-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.paper-a-meta .who {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ds-ink-soft);
}
.paper-a-meta .paper-time {
  margin-left: auto;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--ds-faint);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* 流式生成状态行（.spinner + 文案） */
.paper-live-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0 6px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ds-brand-ink);
}
.paper-live-status .spinner { width: 13px; height: 13px; }

/* 生成失败 / 待重试（与既有 .msg-error 同一语义） */
.paper-error {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding: 11px 13px;
  border: 1px solid var(--ds-danger-border);
  border-radius: var(--ds-r-input);
  background: var(--ds-danger-soft);
  color: #9f1239;
  font-size: 12.5px;
}
.paper-error .err-text { flex: 1 1 180px; line-height: 1.55; }
.paper-error .btn { flex-shrink: 0; margin-left: auto; }

.paper-content.md {
  max-width: 700px;
  font-size: 14.5px;
  line-height: 1.75;
  color: var(--ds-ink);
}

/* 四、右侧纸张导轨：竖排小横块（文档缩略轨） */
.paper-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  align-self: start;
  gap: 9px;
  padding: 4px 2px;
}
.paper-rail[hidden] { display: none; }
.paper-rail-label {
  padding: 2px 0;
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.01em;
  color: var(--ds-muted);
  font-variant-numeric: tabular-nums;
}
.paper-rail-bars {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  max-height: min(52vh, 440px);
  padding: 3px;
  overflow-y: auto;
  scrollbar-width: none;
  overscroll-behavior: contain;
}
.paper-rail-bars::-webkit-scrollbar { display: none; }
.paper-bar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  min-height: 24px; /* 触控目标 ≥24px，视觉横块仅 4~5px */
  padding: 0;
  border-radius: var(--ds-r-pill);
  background: transparent;
  cursor: pointer;
}
.paper-bar::before {
  content: "";
  width: 16px;
  height: 4px;
  border-radius: var(--ds-r-pill);
  background: rgba(21, 36, 67, 0.16);
  transition: width 160ms var(--ds-ease), height 160ms var(--ds-ease),
    background-color 160ms var(--ds-ease-std), box-shadow 160ms var(--ds-ease-std);
}
.paper-bar:not([aria-current="true"]):not(.is-active):hover::before { width: 20px; background: rgba(21, 36, 67, 0.32); }
/* 当前纸张：JS 会同时写 .is-active 与 aria-current="true" */
.paper-bar[aria-current="true"]::before,
.paper-bar.is-active::before {
  width: 24px;
  height: 5px;
  background: var(--ds-brand);
  box-shadow: 0 0 0 3px rgba(77, 107, 254, 0.12);
}
.paper-bar[aria-current="true"]:hover::before,
.paper-bar.is-active:hover::before {
  background: var(--ds-brand-medium);
}

/* 五、空态 / 未开始 / 锁定 / 已删除 */
.drawer-empty {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  grid-column: 1 / -1; /* 空态时 .drawer-body 里只有它一个子节点，横跨整行 */
  align-items: center;
  justify-content: center;
  min-height: 260px;
  padding: 38px 24px 34px;
  text-align: center;
}
.drawer-empty-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 54px;
  height: 54px;
  margin-bottom: 14px;
  border: 1px solid rgba(77, 107, 254, 0.16);
  border-radius: 18px;
  background: var(--ds-brand-soft);
  color: var(--ds-brand-ink);
  font-size: 22px;
  line-height: 1;
}
.drawer-empty-icon svg { width: 24px; height: 24px; }
.drawer-empty-icon .spinner { width: 20px; height: 20px; border-width: 2.5px; }
.drawer-empty h3 {
  margin: 0 0 6px;
  font-size: 16.5px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--ds-heading);
}
.drawer-empty p {
  max-width: 46ch;
  margin: 0;
  font-size: 13px;
  line-height: 1.75;
  color: var(--ds-muted);
}
.drawer-empty .btn { height: 40px; margin-top: 18px; }
/* 未开始的下一阶段：品牌色引导 */
.drawer-empty[data-variant="next"] .drawer-empty-icon {
  background: linear-gradient(150deg, var(--ds-brand) 0%, #7c9cff 100%);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 6px 18px -8px rgba(77, 107, 254, 0.6);
}
/* 锁定：全部降为灰阶 */
.drawer-empty[data-variant="locked"] .drawer-empty-icon {
  background: var(--ds-bg-sunken);
  border-color: var(--ds-border-subtle);
  color: var(--ds-faint);
  box-shadow: none;
}
.drawer-empty[data-variant="locked"] h3 { color: var(--ds-ink-soft); }
.drawer-empty[data-variant="locked"] p { color: var(--ds-faint); }
/* 已删除 / 清空：暖色提示 */
.drawer-empty[data-variant="deleted"] .drawer-empty-icon { background: var(--ds-warning-soft); border-color: var(--ds-warning-border); color: var(--ds-warning-ink); }

/* 六、抽屉底栏：阶段 CTA + 提示 */
.drawer-foot {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 13px 22px 16px;
  border-top: 1px solid var(--ds-border-subtle);
  border-radius: 0 0 var(--ds-r-card) var(--ds-r-card);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.5));
}
.drawer-foot:empty,
.drawer-foot[hidden] {
  display: none;
}
.drawer-cta {
  flex: 0 0 auto;
  height: 40px;
  padding: 0 18px;
  font-size: 13.5px;
}
.drawer-cta.drawer-cta-secondary { border-color: rgba(77, 107, 254, 0.2); background: var(--ds-brand-soft); color: var(--ds-brand-ink); }
.drawer-cta.drawer-cta-secondary:hover { border-color: rgba(77, 107, 254, 0.3); background: var(--ds-brand-soft-2); color: var(--ds-brand-deep); }
.drawer-foot-hint {
  margin: 0 0 0 auto;
  font-size: 12px;
  line-height: 1.6;
  color: var(--ds-faint);
}
/* 历史回看 / 全部完成时只有提示文案，居中而不是靠右 */
.drawer-foot:not(:has(.drawer-cta)) .drawer-foot-hint { width: 100%; margin: 0; text-align: center; }

/* 七、焦点可见（覆盖 style.css 中全局 :focus-visible 的 6px 圆角） */
.stage-pill:focus-visible,
.stage-back-latest:focus-visible {
  border-radius: var(--ds-r-pill);
  box-shadow: var(--ds-ring-offset);
}
.stage-pill[data-status="active"]:focus-visible,
.stage-pill.is-active:focus-visible {
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--ds-brand-medium);
}
.stage-pill[data-status="locked"]:focus-visible { box-shadow: var(--ds-ring); }
.paper-bar:focus-visible { border-radius: var(--ds-r-pill); box-shadow: var(--ds-ring); }
.drawer-cta:focus-visible,
.drawer-empty .btn:focus-visible {
  border-radius: var(--ds-r-pill);
  box-shadow: var(--ds-ring-offset);
}
.stage-drawer .icon-btn:focus-visible { border-radius: var(--ds-r-control); box-shadow: var(--ds-ring); }

/* 八、桌面（≥960）：960 内容宽、24px 圆角玻璃卡、导轨靠右吸顶 */
@media (min-width: 960px) {
    .session-sticky { gap: 10px; padding: 10px 0 12px; margin-bottom: 12px; }
    .stage-pill { height: 40px; padding: 0 14px; font-size: 13px; }
    .stage-pill-key { font-size: 13px; }
    .stage-pill-title { font-size: 13px; }

    .stage-drawer { margin-bottom: 22px; }
    .drawer-head { padding: 17px 24px 15px; }
    .drawer-title { font-size: 19px; }
    .drawer-body { gap: 16px; padding: 20px 20px 18px 24px; }
    .paper { padding: 24px 26px 28px; border-radius: var(--ds-r-card); }
    .paper-q-text { font-size: 14px; }
    .paper-content.md { font-size: 15px; line-height: 1.75; }
    .drawer-foot { padding: 14px 24px 18px; }
    .drawer-cta { height: 42px; padding: 0 20px; font-size: 14px; }

  /* 纸张导轨吸顶在玻璃把手下方，纸张多时自身可滚动 */
  .paper-rail {
    position: sticky;
    top: 140px;
    gap: 10px;
    padding: 2px 0;
  }
    .paper-rail-bars { max-height: min(56vh, 440px); }
    .paper-bar { width: 28px; }
}

/* 九、移动端（≤640）：pill 只留 key + 横向滚动；抽屉内边距收紧；无横向溢出 */
@media (max-width: 640px) {
    .session-sticky { gap: 6px; padding: 6px 0 8px; margin-bottom: 8px; }
    .session-sticky::before { inset: -20px 0 0; }
    .stage-pills { gap: 2px; padding: 5px; margin: -5px; }
    .stage-pill { gap: 4px; height: 34px; padding: 0 10px; }
    .stage-pill-key { font-size: 12px; }
    .stage-pill-title { display: none; }
    .stage-pill-check { width: 12px; height: 12px; font-size: 8px; }

    .stage-drawer { margin-bottom: 14px; border-radius: 20px; }
    .drawer-head { gap: 8px; padding: 12px 14px 11px; border-radius: 20px 20px 0 0; }
  .drawer-head-main {
    gap: 8px;
    flex-wrap: wrap; /* 极窄屏（如 320px）且标题/计数较长时换行，避免挤压工具按钮 */
    row-gap: 1px;
  }
  .drawer-stage-key {
    min-width: 34px;
    height: 22px;
    padding: 0 8px;
    font-size: 11px;
  }
    .drawer-title { font-size: 16px; }
    .drawer-sub { font-size: 11px; }
    .drawer-tools .icon-btn { min-width: 34px; min-height: 34px; }

    .drawer-body { gap: 6px; padding: 12px 9px 12px 12px; }
    .paper { padding: 15px 14px 18px; border-radius: 18px; }
    .paper-q-label { margin-bottom: 4px; font-size: 11px; }
  .paper-q-text {
    max-width: 100%;
    padding: 10px 13px;
    border-radius: 16px 16px 5px 16px;
    font-size: 13.5px;
  }
    .paper-a { margin-top: 14px; }
    .paper-a-meta { margin-bottom: 8px; }
    .paper-a-meta .paper-time { font-size: 11px; }
    .paper-live-status { font-size: 12px; }
    .paper-error { padding: 9px 11px; font-size: 12px; }
    .paper-content.md { font-size: 14px; line-height: 1.72; }

    .paper-rail { gap: 6px; padding: 2px 0; }
  .paper-rail-label {
    display: none; /* 小屏用抽屉头的「第 n / m 段对话」即可，导轨只留横块 */
  }
    .paper-rail-bars { gap: 2px; max-height: min(46vh, 300px); padding: 2px; }
    .paper-bar { width: 22px; min-height: 24px; }
    .paper-bar::before { width: 14px; height: 4px; }
    .paper-bar:not([aria-current="true"]):not(.is-active):hover::before { width: 17px; }
  .paper-bar[aria-current="true"]::before,
  .paper-bar.is-active::before {
    width: 18px;
    height: 4px;
  }

    .drawer-empty { min-height: 220px; padding: 30px 16px 28px; }
  .drawer-empty-icon {
    width: 48px;
    height: 48px;
    margin-bottom: 12px;
    border-radius: 16px;
    font-size: 20px;
  }
    .drawer-empty h3 { font-size: 15.5px; }
    .drawer-empty p { font-size: 12.5px; }
    .drawer-empty .btn { height: 38px; margin-top: 16px; }

    .drawer-foot { gap: 8px; padding: 11px 14px 14px; border-radius: 0 0 20px 20px; }
    .drawer-cta { flex: 1 1 100%; height: 40px; }
  .drawer-foot-hint {
    order: 2;
    width: 100%;
    margin: 0;
    font-size: 11.5px;
    text-align: center;
  }
}

/* 触屏（无 hover）时：非当前横块保持原长，避免点按后抽动；当前横块样式由基础规则决定 */
@media (hover: none) {
    .paper-bar:not([aria-current="true"]):not(.is-active):hover::before { width: 16px; background: rgba(21, 36, 67, 0.16); }
}

/* 十、无障碍 / 降级 */
@media (prefers-reduced-motion: reduce) {
  .stage-drawer.is-entering,
  .paper-scroll.is-switching .paper,
  .stage-drawer.is-switching .paper {
    animation: none;
  }
  .stage-pill,
  .stage-back-latest,
  .paper-bar::before {
    transition: none;
  }
  .stage-pill:active,
  .stage-back-latest:active {
    transform: none;
  }
}

@media (prefers-reduced-transparency: reduce) {
    .session-sticky::before { background: #f9f8f8; backdrop-filter: none; }
  .stage-bar,
  .stage-drawer {
    background: #fff;
    backdrop-filter: none;
  }
  .drawer-head,
  .drawer-foot {
    background: transparent;
  }
}

@media (prefers-contrast: more) {
  .stage-bar,
  .stage-drawer {
    border-color: var(--ds-border);
  }
  .stage-pill[data-status="done"],
  .stage-pill[data-status="next"] {
    border-color: var(--ds-border);
  }
    .stage-pill[data-status="locked"] { opacity: 0.75; }
    .paper-bar::before { background: rgba(21, 36, 67, 0.4); }
}

/* v11.1：阶段胶囊并入标题栏 + 纸张连续排列（右侧横块=定位滑条） */
.topbar.has-stages { flex-wrap: nowrap; }
.topbar.has-stages .topbar-titles { flex: 1 1 auto; min-width: 0; }
.topbar-stages {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  margin-left: 8px;
  padding: 3px;
  border-radius: var(--ds-r-pill);
  background: rgba(0, 0, 0, 0.04);
}
.topbar-stages .stage-pills {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: none;
  min-width: 0;
  padding: 0;
  margin: 0;
  overflow: visible;
}
.topbar-stages .stage-pill {
  min-height: 30px;
  height: 30px;
  padding: 0 11px;
  gap: 5px;
  font-size: 12.5px;
}
.topbar-stages .stage-pill-key { font-size: 12.5px; }
.topbar-stages .stage-pill-check { width: 12px; height: 12px; flex-shrink: 0; }
.topbar-stages .stage-pill[data-status="active"],
.topbar-stages .stage-pill.is-active {
  background: var(--ds-brand-btn);
  color: #fff;
  box-shadow: 0 4px 10px -4px rgba(77, 107, 254, 0.55);
}
.topbar-stages .stage-pill[data-status="active"] .stage-pill-check,
.topbar-stages .stage-pill.is-active .stage-pill-check {
  display: none;
}

/* 纸张连续排列：同一阶段内所有纸张纵向排布 */
.paper-scroll { display: flex; flex-direction: column; gap: 18px; }
.paper { scroll-margin-top: 128px; }
.paper-rail { position: sticky; top: 96px; }

@media (max-width: 899px) {
    .topbar.has-stages { flex-wrap: wrap; row-gap: 6px; }
  .topbar.has-stages .topbar-stages {
    order: 10;
    flex: 1 1 100%;
    margin-left: 0;
    justify-content: flex-start;
    overflow-x: auto;
    scrollbar-width: none;
  }
    .topbar.has-stages .topbar-stages::-webkit-scrollbar { display: none; }
    .topbar.has-stages .topbar-stages .stage-pills { overflow: visible; }
    .paper { scroll-margin-top: 150px; }
    .paper-rail { top: 122px; }
}

@media (prefers-reduced-motion: reduce) {
  .paper-scroll.is-switching .paper,
  .stage-drawer.is-switching .paper {
    animation: none;
  }
}

/* v12：桌面左侧竖栏 —— 标题栏 + 阶段导航 + 操作搬到左侧，释放上下视野 */

/* ---------- 通用（移动端保持 v11.1 外观）：新包裹层透明 ---------- */
.session-rail { display: contents; }
.rail-nav { display: contents; }
.rail-nav-label { display: none; }
.session-main { display: block; }
.icon-btn-label { display: none; }
.stage-pill-title,
.stage-pill-count { display: none; }

@media (min-width: 1024px) {
  :root {
    --rail-w: 268px;
    --rail-gap: 26px;
    --rail-pad: 16px;
    --rail-edge: 28px;
  }

  /* 内容列：左侧留出固定竖栏的位置（竖栏 fixed 不占流），内容仍居中 */
  .page.page-session {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: var(--rail-pad) var(--rail-edge) var(--rail-pad)
      calc(var(--rail-pad) + var(--rail-w) + var(--rail-gap));
  }
    body.has-composer .page.page-session { padding-bottom: var(--composer-space, 190px); }
  .page.page-session .session-main {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: var(--col-session);
    margin: 0 auto;
    min-width: 0;
  }

  /* ---------- 左侧竖栏：固定在视口的玻璃面板（不随页面滚动） ---------- */
  .page.page-session .session-rail {
    position: fixed;
    z-index: 36;
    top: var(--rail-pad);
    left: var(--rail-pad);
    width: var(--rail-w);
    max-height: calc(100vh - var(--rail-pad) * 2);
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 16px 14px 14px;
    box-sizing: border-box;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-radius: 24px;
    border: 1px solid var(--ds-border-subtle);
    background: linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.62) 0%,
      rgba(255, 255, 255, 0.42) 100%
    );
    box-shadow: 0 2px 18px -6px rgba(21, 36, 67, 0.1);
    backdrop-filter: blur(16px) saturate(140%);
    scrollbar-width: thin;
  }
  .session-rail .session-sticky {
    position: static;
    top: auto;
    z-index: auto;
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;
    gap: 0;
    padding: 0;
    margin: 0;
  }
  .session-rail .session-sticky::before { display: none; }
  .session-rail .topbar {
    position: static;
    top: auto;
    z-index: auto;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
  }
  .session-rail .topbar.has-stages { flex-wrap: wrap; }
  .session-rail .topbar > .icon-btn {
    flex: 0 0 auto;
    min-width: 34px;
    min-height: 34px;
    margin-left: -3px;
  }
    .session-rail .topbar-titles { flex: 1 1 0; min-width: 0; padding: 0; }
  .session-rail .topbar-title {
    font-size: 15px;
    line-height: 1.4;
    white-space: normal;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
  .session-rail .topbar-sub {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    margin-top: 3px;
    font-size: 11.5px;
    line-height: 1.5;
    white-space: normal;
    overflow: hidden;
  }

  /* 阶段导航：竖向胶囊列表（每行 key + 阶段标题 + 纸张数） */
  .session-rail .rail-nav {
    order: 10;
    flex: 1 1 100%;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 14px;
  }
  .session-rail .rail-nav-label {
    display: block;
    padding: 0 10px 2px;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.1em;
    color: var(--ds-faint);
  }
  .session-rail .topbar-stages {
    order: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    flex: 0 0 auto;
    margin: 0;
    padding: 0;
    border-radius: 0;
    background: transparent;
    overflow: visible;
  }
  .session-rail .topbar-stages .stage-pills {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    flex: 1 1 auto;
    gap: 3px;
    min-width: 0;
    padding: 2px;
    margin: -2px;
    overflow: visible;
  }
  .session-rail .topbar-stages .stage-pill {
    width: 100%;
    height: auto;
    min-height: 40px;
    justify-content: flex-start;
    gap: 8px;
    padding: 7px 10px;
    border-radius: 12px;
    text-align: left;
    white-space: normal;
  }
  .session-rail .topbar-stages .stage-pill:hover { transform: none; }
  .session-rail .topbar-stages .stage-pill:active { transform: none; }
  /* 勾选位统一占位：done 显示，其余隐藏但保留宽度，保证行内容左对齐 */
    .session-rail .topbar-stages .stage-pill-check { display: inline-flex; visibility: hidden; }
    .session-rail .topbar-stages .stage-pill[data-status="done"] .stage-pill-check { visibility: visible; }
    .session-rail .topbar-stages .stage-pill[data-status="active"] .stage-pill-check { display: inline-flex; visibility: hidden; }
  .session-rail .topbar-stages .stage-pill[data-latest="true"]::after { display: none; }
    .session-rail .topbar-stages .stage-pill-key { flex: 0 0 auto; font-size: 12px; }
  .session-rail .topbar-stages .stage-pill-title {
    display: inline;
    flex: 1 1 auto;
    min-width: 0;
    font-size: 12.5px;
    font-weight: 500;
    line-height: 1.35;
    text-align: left;
  }
  .session-rail .topbar-stages .stage-pill-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    margin-left: 2px;
    border-radius: 999px;
    background: rgba(21, 36, 67, 0.07);
    color: var(--ds-muted);
    font-size: 11px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
  }
  .session-rail .topbar-stages .stage-pill-count.is-empty { visibility: hidden; }
    .session-rail .topbar-stages .stage-pill[data-status="active"] .stage-pill-count { background: rgba(255, 255, 255, 0.24); color: #fff; }
    .session-rail .topbar-stages .stage-pill[data-status="done"] .stage-pill-count { background: var(--ds-brand-soft); color: var(--ds-brand-ink); }

  /* 导出 / 删除：竖栏底部文字按钮 */
  .session-rail .topbar-actions {
    order: 20;
    flex: 1 1 100%;
    display: flex;
    gap: 8px;
    margin-top: 6px;
    padding-top: 14px;
    border-top: 1px solid var(--ds-border-subtle);
  }
  .session-rail .topbar-actions .icon-btn {
    flex: 1 1 0;
    min-width: 0;
    min-height: 38px;
    height: 38px;
    padding: 0 10px;
    gap: 7px;
    border: 1px solid var(--ds-border-subtle);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.66);
    color: var(--ds-ink-soft);
    font-size: 12.5px;
    font-weight: 500;
  }
    .session-rail .topbar-actions .icon-btn:hover { background: #fff; border-color: rgba(77, 107, 254, 0.28); color: var(--ds-brand-ink); }
    .session-rail .topbar-actions .icon-btn.danger:hover { background: var(--ds-danger-soft); border-color: rgba(200, 60, 60, 0.25); color: var(--ds-danger); }
    .session-rail .topbar-actions .icon-btn svg { width: 16px; height: 16px; }
    .session-rail .icon-btn-label { display: inline; white-space: nowrap; }

  /* 非分层插件（socratic 等）：讲解深度工具也在竖栏内 */
  .session-rail .topbar.has-tools { flex-wrap: wrap; row-gap: 6px; }
  .session-rail .topbar.has-tools .topbar-tools {
    order: 15;
    flex: 1 1 100%;
    flex-wrap: wrap;
    margin-top: 10px;
    padding: 12px 0 0;
    border-top: 1px solid var(--ds-border-subtle);
    border-left: 0;
  }

  /* 插件 / 临时会话徽记：竖栏底部（桌面） */
  .session-rail .chips-row {
    margin-top: auto;
    padding: 14px 2px 0;
    gap: 5px;
    border-top: 1px solid var(--ds-border-subtle);
  }
  .session-rail .chips-row .badge { font-size: 10.5px; }

  /* 纸张定位/高亮不再需要避开吸顶栏 */
  .paper { scroll-margin-top: 20px; }
  .paper-rail { top: 24px; }

  /* 底部输入区与内容列对齐 */
    .composer { left: calc(var(--rail-pad) + var(--rail-w) + var(--rail-gap)); right: var(--rail-edge); padding: 0; }
    .composer-inner { max-width: var(--col-session); margin: 0 auto; }
}

/* 中间宽度（1024–1199）内容列较窄时，纸张内边距略收，保持可读行宽 */
@media (min-width: 1024px) and (max-width: 1199px) {
  .session-main .paper { border-radius: 20px; }
}
