:root {
  --ink: #1c2430;
  --ink-2: #445061;
  --muted: #7b8798;
  --line: rgba(28, 36, 48, 0.08);
  --line-strong: rgba(28, 36, 48, 0.14);
  --jade: #1f7a62;
  --jade-deep: #176350;
  --jade-mist: rgba(31, 122, 98, 0.12);
  --jade-soft: rgba(31, 122, 98, 0.08);
  --surface: #ffffff;
  --surface-2: #f5f7f8;
  --canvas: #eef1f3;
  --rail: #f7f8f9;
  --warn: #8a5a14;
  --danger: #a61b1b;
  --font: "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --rail-w: 248px;
  --chat-max: min(820px, calc(100% - 56px));
  --fs-xs: 13px;
  --fs-sm: 14px;
  --fs-md: 16px;
  --fs-lg: 17px;
  --fs-xl: 19px;
  --fs-2xl: 22px;
  --fs-3xl: 28px;
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--fs-md);
  font-weight: 400;
  line-height: 1.6;
  background: var(--canvas);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
code {
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: 0.9em;
  color: var(--jade-deep);
  background: var(--jade-mist);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

/* Atmosphere */
.atmosphere {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
.atmosphere__wash {
  position: absolute;
  inset: 0;
  background: linear-gradient(160deg, #f2f5f6 0%, #eef1f3 55%, #e9eef0 100%);
}
.atmosphere__orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(50px);
  opacity: 0.7;
}
.atmosphere__orb--a {
  width: 38vw;
  height: 38vw;
  left: -6vw;
  top: -10vw;
  background: radial-gradient(circle, rgba(31, 122, 98, 0.12), transparent 70%);
}
.atmosphere__orb--b {
  width: 32vw;
  height: 32vw;
  right: -4vw;
  bottom: -8vw;
  background: radial-gradient(circle, rgba(100, 130, 150, 0.1), transparent 72%);
}

/* Login */
.login {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 40px 24px;
  overflow: auto;
}
.login__stage {
  position: relative;
  width: min(480px, 100%);
  padding: 36px 32px 28px;
  background: rgba(255,255,255,0.82);
  border: 1px solid var(--line);
  border-radius: 20px;
  animation: enter 0.7s var(--ease) both;
}
.login__logo {
  display: block;
  width: auto;
  height: 56px;
  object-fit: contain;
  object-position: left center;
  margin: 0 0 18px;
}
.login__mascot {
  position: absolute;
  right: 18px;
  bottom: 18px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid #fff;
  background: #0a1a3a;
  box-shadow: 0 6px 18px rgba(20, 40, 80, 0.18);
  pointer-events: none;
}
.login__mascot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 20%;
}
.login__eyebrow {
  margin: 0 0 10px;
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--jade);
}
.login__brand {
  margin: 0;
  font-size: clamp(2rem, 5vw, 2.6rem);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
}
.login__product {
  margin: 6px 0 0;
  font-size: var(--fs-lg);
  font-weight: 500;
  color: var(--jade-deep);
}
.login__lead {
  margin: 16px 0 0;
  max-width: 28em;
  color: var(--ink-2);
  font-size: var(--fs-md);
  line-height: 1.65;
}
.login__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 24px;
}
.login__toast {
  margin: 14px 0 0;
  min-height: 1.2em;
  color: var(--danger);
  font-size: var(--fs-sm);
}

/* Buttons */
.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 10px;
  font-size: var(--fs-md);
  font-weight: 600;
  transition: background 0.2s var(--ease), color 0.2s var(--ease), border-color 0.2s var(--ease);
}
.btn--primary { background: var(--jade); color: #fff; }
.btn--primary:hover { background: var(--jade-deep); }
.btn--quiet {
  background: transparent;
  color: var(--ink-2);
  border: 1px solid var(--line-strong);
}
.btn--quiet:hover { background: rgba(255,255,255,0.7); }
.btn--soft { background: var(--jade-mist); color: var(--jade-deep); }
.btn__arrow { transition: transform 0.2s var(--ease); }
.btn--primary:hover .btn__arrow { transform: translateX(2px); }

/* ========== App shell ========== */
.shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  transition: grid-template-columns 0.22s var(--ease);
}
.shell.is-rail-collapsed {
  grid-template-columns: 0 minmax(0, 1fr);
}
.shell.is-rail-collapsed .rail {
  width: 0 !important;
  min-width: 0;
  max-width: 0;
  padding: 0 !important;
  margin: 0;
  border: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
}

/* 侧栏折叠 — 豆包式图标，在顶栏文档流内，不盖字 */
.rail-toggle {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  width: 34px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  flex: 0 0 auto;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.rail-toggle:hover {
  background: rgba(28, 36, 48, 0.06);
  color: var(--ink);
}
.rail-toggle:active {
  background: rgba(28, 36, 48, 0.1);
}
.rail-toggle__svg {
  display: block;
}
.shell.is-rail-collapsed .rail-toggle {
  color: var(--ink);
}

/* Left rail — ~豆包比例 */
.rail {
  display: flex;
  flex-direction: column;
  gap: 0;
  width: var(--rail-w);
  min-width: 0;
  background: var(--rail);
  border-right: 1px solid var(--line);
  padding: 14px 12px 12px;
  min-height: 0;
  overflow: hidden;
  transition: width 0.22s var(--ease), padding 0.22s var(--ease), opacity 0.18s var(--ease);
}
.rail__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 2px 12px;
  flex: 0 0 auto;
}
.rail__logo {
  width: auto;
  height: 34px;
  object-fit: contain;
  object-position: left center;
  flex: 0 0 auto;
  display: block;
  border-radius: 6px;
  background: #fff;
}
.rail__brand-text { min-width: 0; flex: 1; }
.rail__name {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
}
.rail__sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 1px;
}
.rail__new {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  border-radius: 10px;
  min-height: 40px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: var(--fs-sm);
  font-weight: 600;
  margin: 0 2px 10px;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease);
}
.rail__new:hover {
  border-color: rgba(31, 122, 98, 0.4);
  background: var(--jade-soft);
  color: var(--jade-deep);
}
.rail__new-icon {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  background: var(--jade-mist);
  color: var(--jade-deep);
  display: grid;
  place-items: center;
  font-size: 14px;
  line-height: 1;
  font-weight: 700;
}
.rail__section {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0 2px;
}
.rail__label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  padding: 0 8px 8px;
}
.rail__search {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 2px 8px;
  padding: 0 10px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.rail__search:focus-within {
  border-color: var(--jade);
  box-shadow: 0 0 0 3px var(--jade-mist);
}
.rail__search-icon {
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  flex: 0 0 auto;
}
.rail__search input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 8px 0;
  font-size: 13px;
  color: var(--ink);
  box-shadow: none;
  border-radius: 0;
}
.rail__search input:focus {
  outline: none;
  box-shadow: none;
  border: 0;
}
.rail__search input::placeholder { color: var(--muted); }
.session-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-bottom: 8px;
}
.session-empty {
  padding: 10px 10px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
}
.session-item {
  appearance: none;
  border: 0;
  background: transparent;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.35;
  transition: background 0.15s var(--ease);
}
.session-item:hover { background: rgba(28, 36, 48, 0.05); }
.session-item.is-active {
  background: var(--jade-mist);
  color: var(--jade-deep);
  font-weight: 500;
}
.session-item__title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session-item mark {
  background: rgba(31, 122, 98, 0.18);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}
.session-item__del {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  border-radius: 5px;
  display: grid;
  place-items: center;
  color: var(--muted);
  opacity: 0;
  font-size: 14px;
  line-height: 1;
}
.session-item:hover .session-item__del { opacity: 1; }
.session-item__del:hover {
  background: rgba(166, 27, 27, 0.1);
  color: var(--danger);
}

.rail__nav {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 2px 8px;
  border-top: 1px solid var(--line);
  margin-top: 4px;
}
.rail__nav-item {
  appearance: none;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink-2);
  font-size: var(--fs-sm);
  font-weight: 500;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.rail__nav-item:hover { background: rgba(28, 36, 48, 0.05); color: var(--ink); }
.rail__nav-item.is-active {
  background: var(--jade-mist);
  color: var(--jade-deep);
}

.rail__user {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 8px;
  align-items: center;
  padding: 10px 8px 4px;
  border-top: 1px solid var(--line);
  margin-top: 4px;
}
.rail__user-name {
  font-size: var(--fs-sm);
  font-weight: 600;
  grid-column: 1;
  grid-row: 1;
}
.rail__user-meta {
  font-size: 12px;
  color: var(--muted);
  grid-column: 1;
  grid-row: 2;
}
.rail__user .user__avatar {
  grid-column: 2;
  grid-row: 1 / span 2;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 18%;
  background: #0a1a3a;
  border: 1.5px solid rgba(255,255,255,0.9);
  box-shadow: 0 0 0 1px var(--line);
  display: block;
}

/* Stage */
.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: transparent;
}
.stage__bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 8px 20px 8px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,0.72);
}
.stage__bar-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.stage__main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.module { min-height: 0; }
.module--chat {
  flex: 1;
  display: flex;
  min-height: 0;
}
.module--page {
  flex: 1;
  overflow: auto;
  background: transparent;
}

/* ===== Secondary pages ===== */
.page {
  width: min(960px, 100%);
  margin: 0 auto;
  padding: 28px 32px 56px;
  animation: enter 0.35s var(--ease) both;
}
.page__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.page__eyebrow {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--jade);
}
.page__title {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}
.page__desc {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
  max-width: 40em;
}
.page__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}
.page__grid--dev { align-items: start; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}
.panel--soft { background: rgba(255,255,255,0.55); }
.panel__head {
  padding: 16px 18px 0;
}
.panel__head h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}
.panel__head p {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
}
.panel__body {
  padding: 16px 18px 18px;
  display: grid;
  gap: 14px;
}
.panel__body--flush {
  padding: 8px 0 0;
  gap: 0;
}
.panel__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
}
.form-stack { display: grid; gap: 12px; }

.steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 10px;
  background: var(--surface-2);
  border-radius: 10px;
}
.step {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--ink-2);
  font-weight: 500;
}
.step__n {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: var(--jade-mist);
  color: var(--jade-deep);
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  flex: 0 0 auto;
}

.tips {
  margin: 0;
  padding-left: 1.1em;
  display: grid;
  gap: 6px;
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.5;
}
.endpoint {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 12px;
  color: var(--muted);
}
.endpoint code {
  font-size: 12px;
  background: transparent;
  color: var(--ink-2);
  padding: 0;
}

.module__head { margin-bottom: 24px; }
.module__head h2 {
  margin: 0 0 6px;
  font-size: var(--fs-2xl);
  font-weight: 600;
  letter-spacing: -0.01em;
}
.module__head p {
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-sm);
}

.block {
  padding: 22px 0;
  border-top: 1px solid var(--line);
}
.block:first-of-type { border-top: 0; padding-top: 0; }
.block h3 {
  margin: 0 0 4px;
  font-size: var(--fs-lg);
  font-weight: 600;
}
.block__hint {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: var(--fs-sm);
}

/* Chat */
.chat {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
}
.chat__title {
  font-size: var(--fs-lg);
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat__scope {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--muted);
  flex: 0 0 auto;
}
.chat__scope select {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: var(--fs-sm);
  color: var(--ink);
  min-width: 148px;
  max-width: 220px;
}

.chat__thread {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 20px 0 12px;
}

.chat-empty {
  width: var(--chat-max);
  margin: 10vh auto 0;
  text-align: center;
}
.chat-empty h2 {
  margin: 0 0 8px;
  font-size: var(--fs-3xl);
  font-weight: 600;
  letter-spacing: -0.02em;
}
.chat-empty p {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: var(--fs-md);
}
.ask-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.chip {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink-2);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: var(--fs-sm);
  cursor: pointer;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease), color 0.15s var(--ease);
}
.chip:hover {
  border-color: rgba(31, 122, 98, 0.35);
  background: var(--jade-soft);
  color: var(--jade-deep);
}

.bubble {
  width: var(--chat-max);
  margin: 0 auto 18px;
  display: grid;
  gap: 4px;
  animation: enter 0.25s var(--ease) both;
}
.bubble--user { justify-items: end; }
.bubble--assistant { justify-items: start; }

.bubble--user .bubble__content {
  width: fit-content;
  max-width: min(520px, 100%);
  background: var(--jade);
  color: #fff;
  border-radius: 14px 14px 4px 14px;
  padding: 11px 15px;
  font-size: 16px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.bubble--assistant .bubble__meta {
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--muted);
  padding-left: 2px;
}
.bubble--assistant .bubble__content {
  width: 100%;
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 4px 14px 14px 14px;
  padding: 14px 16px 12px;
}
.bubble__thinking {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: var(--fs-md);
}
.thinking__msg { flex: 1; min-width: 0; }
.bubble__meta [data-think-timer] {
  font-variant-numeric: tabular-nums;
  color: var(--jade-deep);
  font-weight: 600;
}
.bubble__answer--stream {
  white-space: pre-wrap;
  word-break: break-word;
}
.bubble__answer {
  font-size: var(--fs-lg);
  line-height: 1.7;
  color: var(--ink);
}
.bubble__answer[data-tone="hint"],
.bubble__answer[data-tone="empty"] { color: var(--ink-2); }

/* Markdown answer typography */
.md {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md-p {
  margin: 0;
  font-size: 16px;
  line-height: 1.8;
  color: var(--ink);
}
.md-h1, .md-h2, .md-h3 {
  margin: 6px 0 0;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
  line-height: 1.35;
}
.md-h1 { font-size: 1.25em; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.md-h2 { font-size: 1.12em; }
.md-h3 { font-size: 1.05em; color: var(--ink-2); }

.md-ol, .md-ul {
  margin: 0;
  padding-left: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  counter-reset: none;
}
.md-ol > li {
  display: grid;
  grid-template-columns: 32px 1fr;
  column-gap: 10px;
  align-items: start;
  font-size: 16px;
  line-height: 1.75;
  color: var(--ink);
}
.md-ol > li::before {
  content: attr(value) ".";
  grid-column: 1;
  grid-row: 1 / span 20;
  font-weight: 700;
  color: var(--jade);
  font-variant-numeric: tabular-nums;
  line-height: 1.7;
  text-align: right;
}
.md-ol > li > .md-li,
.md-ol > li > .md-ul {
  grid-column: 2;
}
.md-li { min-width: 0; }

.md-ul > li {
  position: relative;
  padding-left: 16px;
  font-size: 16px;
  line-height: 1.75;
  color: var(--ink);
}
.md-ul > li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 0.72em;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--jade);
}
.md-ul--nested {
  margin-top: 8px;
  gap: 6px;
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: 8px;
  border-left: 3px solid rgba(31, 122, 98, 0.35);
}
.md-ul--nested > li {
  font-size: 15px;
  color: var(--ink-2);
}
.md-ul--nested > li::before {
  background: var(--muted);
  width: 4px;
  height: 4px;
}

.md strong {
  font-weight: 700;
  color: var(--ink);
  background: linear-gradient(180deg, transparent 55%, rgba(31, 122, 98, 0.15) 55%);
}
.md em { font-style: italic; color: var(--ink-2); }
.md-code {
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: 0.86em;
  color: var(--jade-deep);
  background: var(--jade-mist);
  padding: 0.12em 0.4em;
  border-radius: 4px;
  word-break: break-all;
}
.md-a {
  color: var(--jade-deep);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}
.md-a:hover { color: var(--jade); }
.md-callout {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(138, 90, 20, 0.08);
  border-left: 3px solid var(--warn);
  color: var(--ink-2);
  font-size: 15px;
  line-height: 1.7;
}
.md-callout strong { background: none; color: var(--warn); }
.md-pre {
  margin: 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: #1c2430;
  color: #e8eef2;
  overflow: auto;
  font-size: 14px;
  line-height: 1.55;
}
.md-pre code {
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  color: inherit;
  background: transparent;
  padding: 0;
}

.bubble__cites {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.bubble__images {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 12px 0 4px;
}
.bubble__fig {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
}
.bubble__img {
  display: block;
  width: 100%;
  max-height: 420px;
  object-fit: contain;
  background: #f4f6f8;
}
.bubble__fig figcaption {
  padding: 8px 12px;
  font-size: var(--fs-xs);
  color: var(--muted);
  border-top: 1px solid var(--line);
}
.cite-detail__img {
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #f4f6f8;
}
.cite-detail__img img {
  display: block;
  width: 100%;
  max-height: 360px;
  object-fit: contain;
}
.bubble__cites-label {
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 8px;
}
.cite-row { display: flex; flex-wrap: wrap; gap: 6px; }
.cite {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--ink-2);
  border-radius: 8px;
  padding: 4px 9px;
  font-size: var(--fs-xs);
  font-weight: 500;
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cite:hover,
.cite.is-active {
  border-color: rgba(31, 122, 98, 0.35);
  background: var(--jade-mist);
  color: var(--jade-deep);
}
.cite-panel { margin-top: 10px; }
.cite-detail {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 0;
  overflow: hidden;
  box-shadow: 0 1px 0 rgba(16, 24, 40, 0.03);
}
.cite-detail__head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-start;
  padding: 12px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  font-size: var(--fs-sm);
}
.cite-detail__title {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1 1 180px;
}
.cite-detail__title strong {
  font-weight: 600;
  color: var(--ink);
  line-height: 1.35;
}
.cite-detail__meta {
  font-size: 12px;
  color: var(--muted);
  font-weight: 400;
}
.cite-detail__pct {
  margin-left: auto;
  color: var(--jade-deep);
  font-weight: 700;
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
  padding-top: 1px;
}
.cite-detail__img {
  margin: 12px 14px 0;
}
.cite-detail__body {
  padding: 12px 14px 14px;
  color: var(--ink-2);
  max-height: 280px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}
.cite-detail__empty {
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-sm);
}
.cite-detail__body .md {
  gap: 8px;
}
.cite-detail__body .md-p,
.cite-detail__body .md-ul > li,
.cite-detail__body .md-ol > li {
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink-2);
}
.cite-detail__body .md-h1,
.cite-detail__body .md-h2,
.cite-detail__body .md-h3 {
  font-size: 15px;
  margin: 2px 0 0;
  padding-bottom: 0;
  border-bottom: none;
}
.cite-detail__body .md-h1 { font-size: 16px; }
.cite-detail__body .md strong {
  background: none;
}
.cite-detail__body .md-quote {
  margin: 0;
  padding: 8px 10px;
  border-left: 3px solid rgba(31, 122, 98, 0.4);
  background: var(--jade-mist);
  border-radius: 0 8px 8px 0;
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.65;
}
.cite-detail__body .md-hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 4px 0;
}
.cite-detail__body .md-pre {
  padding: 10px 12px;
  font-size: 12px;
}
.md-quote {
  margin: 0;
  padding: 10px 12px;
  border-left: 3px solid rgba(31, 122, 98, 0.4);
  background: var(--jade-mist);
  border-radius: 0 10px 10px 0;
  color: var(--ink-2);
  font-size: 15px;
  line-height: 1.7;
}
.md-hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 4px 0;
}
.md-table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.5;
}
.md-table th,
.md-table td {
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
  color: var(--ink-2);
}
.md-table th {
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 600;
  white-space: nowrap;
}
.md-table tr:last-child td { border-bottom: 0; }
.md-table code.md-code { font-size: 0.92em; }
.cite-detail__body .md-table { font-size: 13px; }
.cite-detail__body .md-table th,
.cite-detail__body .md-table td { padding: 6px 8px; }
.cite-detail__foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}
.cite-detail__hint {
  font-size: 12px;
  color: var(--muted);
}
.cite-detail__source {
  appearance: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--jade-deep);
  text-decoration: none;
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid rgba(31, 122, 98, 0.28);
  background: #fff;
}
.cite-detail__source:hover {
  background: var(--jade-mist);
  border-color: rgba(31, 122, 98, 0.45);
}

/* In-page document viewer (Doubao-like) */
.doc-viewer {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  animation: enter 0.2s var(--ease) both;
}
.doc-viewer.hidden { display: none; }
.doc-viewer__bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.doc-viewer__back {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  flex: 0 0 auto;
}
.doc-viewer__back:hover {
  background: var(--jade-mist);
  border-color: rgba(31, 122, 98, 0.35);
  color: var(--jade-deep);
}
.doc-viewer__heading {
  min-width: 0;
  flex: 1;
}
.doc-viewer__title {
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-viewer__meta {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-viewer__scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 20px 24px 40px;
  background: linear-gradient(180deg, #f7f8fa 0%, var(--surface) 120px);
}
.doc-viewer__loading,
.doc-viewer__empty {
  width: min(720px, 100%);
  margin: 40px auto;
  color: var(--muted);
  font-size: 15px;
  text-align: center;
}
.doc-viewer__article {
  width: min(720px, 100%);
  margin: 0 auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 22px 24px 28px;
  box-shadow: 0 1px 0 rgba(16, 24, 40, 0.03);
}
.doc-viewer__article .md {
  gap: 14px;
}
.doc-viewer__pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: 13px;
  line-height: 1.7;
  color: var(--ink-2);
}
.doc-viewer__figure {
  width: min(920px, 100%);
  margin: 0 auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}
.doc-viewer__figure img {
  display: block;
  width: 100%;
  max-height: calc(100vh - 180px);
  object-fit: contain;
  background: #f4f6f8;
}
.bubble__actions { margin-top: 8px; }

.badge {
  display: inline-flex;
  padding: 1px 7px;
  border-radius: 5px;
  background: var(--jade-mist);
  color: var(--jade-deep);
  font-weight: 600;
  font-size: 11px;
}

/* Composer — full width of stage, content capped */
.chat__composer {
  flex: 0 0 auto;
  padding: 8px 24px 18px;
  background: linear-gradient(180deg, transparent, rgba(238, 241, 243, 0.95) 30%);
}
.composer {
  width: var(--chat-max);
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  padding: 12px 14px 10px;
  display: grid;
  gap: 8px;
}
.composer textarea {
  width: 100%;
  border: 0;
  background: transparent;
  resize: none;
  min-height: 52px;
  max-height: 160px;
  padding: 4px 2px;
  line-height: 1.55;
  font-size: 16px;
  box-shadow: none;
}
.composer textarea:focus {
  outline: none;
  box-shadow: none;
}
.composer textarea::placeholder { color: var(--muted); }
.composer__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.composer__ghost {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
  padding: 4px 0;
}
.composer__ghost:hover { color: var(--jade-deep); }
.composer__send {
  appearance: none;
  border: 0;
  cursor: pointer;
  background: var(--jade);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  border-radius: 10px;
  min-height: 40px;
  min-width: 80px;
  padding: 0 18px;
  transition: background 0.2s var(--ease);
}
.composer__send:hover { background: var(--jade-deep); }
.composer__send.is-busy { opacity: 0.75; cursor: wait; }
.composer__send:disabled { opacity: 0.6; cursor: not-allowed; }
.composer__hint {
  width: var(--chat-max);
  margin: 8px auto 0;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

/* Forms / libs */
.field { display: grid; gap: 6px; }
.field__label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}
input[type="text"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: var(--fs-md);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.panel input[type="text"],
.panel select {
  background: var(--surface-2);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--jade);
  box-shadow: 0 0 0 3px var(--jade-mist);
}
.form-rail, .form-row { display: grid; gap: 14px; }
.form-row {
  grid-template-columns: 1.1fr 1.1fr auto;
  align-items: end;
}
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.actions--inline { align-items: flex-end; padding-bottom: 2px; }

.file-field { position: relative; }
.file-field input[type="file"] {
  position: absolute;
  inset: 22px 0 0;
  opacity: 0;
  cursor: pointer;
  height: calc(100% - 22px);
}
.file-field__ui {
  display: grid;
  justify-items: center;
  gap: 4px;
  min-height: 120px;
  place-content: center;
  border: 1px dashed var(--line-strong);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  padding: 16px;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease), color 0.15s var(--ease);
}
.file-field__ui strong {
  font-size: 14px;
  color: var(--ink-2);
  font-weight: 600;
}
.file-field__icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--jade-mist);
  color: var(--jade-deep);
  display: grid;
  place-items: center;
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
}
.file-field:hover .file-field__ui,
.file-field.is-filled .file-field__ui {
  border-color: rgba(31, 122, 98, 0.45);
  color: var(--jade-deep);
  background: var(--jade-soft);
}
.file-field.is-filled .file-field__ui strong { color: var(--jade-deep); }

.toast {
  margin: 0;
  min-height: 1.2em;
  color: var(--warn);
  font-size: 12px;
  flex: 1;
}
.toast.is-ok { color: var(--jade-deep); }
.toast.is-err { color: var(--danger); }
.empty { color: var(--muted); padding: 16px 18px; font-size: 13px; }
.empty-block {
  display: grid;
  gap: 6px;
  margin: 8px 18px 18px;
  padding: 20px;
  border-radius: 12px;
  border: 1px dashed var(--line-strong);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}
.empty-block strong { color: var(--ink-2); font-size: 14px; }

.lib-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}
.lib-item {
  padding: 16px 16px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  display: grid;
  gap: 8px;
  transition: border-color 0.15s var(--ease), transform 0.15s var(--ease);
}
.lib-item:hover {
  border-color: rgba(31, 122, 98, 0.28);
  transform: translateY(-1px);
}
.lib-item__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.lib-item__code {
  font-weight: 700;
  font-size: 14px;
  line-height: 1.35;
}
.lib-item__name {
  color: var(--ink-2);
  font-weight: 500;
  margin-left: 4px;
}
.lib-item__meta { color: var(--muted); font-size: 12px; }
.lib-item__perms {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.perm {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
}
.perm--on {
  background: var(--jade-mist);
  color: var(--jade-deep);
}
.perm--off {
  background: rgba(28, 36, 48, 0.05);
  color: var(--muted);
}

.proj-list { display: grid; gap: 0; }
.proj-card { border-top: 1px solid var(--line); }
.proj-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 16px;
  align-items: center;
  padding: 14px 18px;
}
.proj-card:hover .proj-row { background: rgba(31, 122, 98, 0.03); }
.proj-row__title {
  font-weight: 600;
  font-size: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.proj-row__name { color: var(--ink); }
.proj-row__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  align-items: center;
}
.btn--sm {
  padding: 4px 10px;
  font-size: 12px;
  min-height: 28px;
}
.btn--ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink-2);
}
.btn--ghost:hover { border-color: var(--jade); color: var(--jade-deep); }
.proj-members {
  padding: 0 18px 14px;
  background: rgba(28, 36, 48, 0.02);
}
.proj-members.hidden { display: none; }
.proj-members__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.proj-member {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.proj-member__who {
  display: flex;
  align-items: center;
  gap: 8px;
}
.proj-member__perm {
  display: flex;
  align-items: center;
  gap: 8px;
}
.proj-access-select {
  min-width: 110px;
  padding: 4px 8px;
  font-size: 12px;
}
.proj-access-hint {
  font-size: 11px;
  color: var(--muted);
}
.proj-members__loading,
.proj-members__empty {
  font-size: 13px;
  color: var(--muted);
  padding: 8px 0;
}
.tag {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--ink-2);
}
.tag--ok { background: var(--jade-mist); color: var(--jade-deep); }
.tag--role { background: rgba(28, 36, 48, 0.06); }

.pat-box { margin-top: 4px; display: grid; gap: 10px; }
.pat-token {
  margin: 0;
  padding: 14px 16px;
  background: #1c2430;
  color: #e8eef2;
  border-radius: 12px;
  word-break: break-all;
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: 12px;
  line-height: 1.55;
}
.pat-warn {
  margin: 0;
  font-size: 12px;
  color: var(--danger);
  line-height: 1.5;
}
.pat-actions { display: flex; gap: 8px; }

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: #fff;
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.7s linear infinite;
}
.spinner--lg {
  width: 18px;
  height: 18px;
  border-color: rgba(31, 122, 98, 0.2);
  border-top-color: var(--jade);
}
@keyframes spin { to { transform: rotate(360deg); } }

.is-shake { animation: shake 0.35s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

@keyframes enter {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 860px) {
  body { overflow: auto; }
  .shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }
  .rail {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: none;
  }
  .rail__section { max-height: 160px; }
  .session-list { max-height: 140px; }
  .rail__nav { flex-direction: row; flex-wrap: wrap; }
  .form-row { grid-template-columns: 1fr; }
  .page { padding: 20px 16px 40px; }
  .page__grid { grid-template-columns: 1fr; }
  .page__head { flex-direction: column; }
  .steps { grid-template-columns: 1fr; }
  .stage__bar { padding: 8px 12px; }
  .bubble, .composer, .composer__hint, .chat-empty { width: calc(100% - 28px); }
  .chat__composer { padding: 8px 12px 16px; }
  .shell.is-rail-collapsed { grid-template-columns: 1fr; }
  .proj-row {
    grid-template-columns: 1fr;
  }
  .proj-row__meta { justify-content: flex-start; }
}
