/* Cadence Virtuoso Agent — 结构布局、字体排印与组件几何样式
 * 配色与主题细节由 /theme-dark.css 与 /theme-light.css 通过共享 CSS 变量契约覆盖。
 * 严格遵守 CSP style-src 'self'，全站零内联 style。
 */

:root {
  /* 默认深色兜底变量(将被 theme-dark.css / theme-light.css 覆盖) */
  --bg-window: #121318;
  --bg-topbar: #121318;
  --bg-sidebar: #14151a;
  --bg-hero: #0d0e12;
  --bg-surface: #16181e;
  --bg-surface-2: #1d2029;
  --bg-surface-hover: #21242e;
  --bg-input: #171920;
  --bg-active-nav: rgba(227, 24, 55, 0.14);

  --border-subtle: #20222b;
  --border-card: #252832;
  --border-input: #2b2f3b;
  --border-hover: rgba(227, 24, 55, 0.45);

  --text-primary: #f2f4f8;
  --text-secondary: #b5bccb;
  --text-muted: #8d95a8;
  --text-active-nav: #ffffff;
  --brand-wordmark: #ffffff;

  --brand-red: #e31837;
  --brand-red-text: #ff6b81;
  --brand-red-hover: #f02846;
  --brand-red-soft: rgba(227, 24, 55, 0.14);
  --send-bg: #c82333;
  --send-bg-hover: #dc2b3d;

  --shadow-dock: 0 4px 20px rgba(0, 0, 0, 0.35);
  --shadow-card: 0 2px 10px rgba(0, 0, 0, 0.24);
  --shadow-card-hover: 0 6px 20px rgba(0, 0, 0, 0.4);

  --wafer-image: url('/wafer-dark.svg');
  --wafer-opacity: 0.96;

  --avatar-ring-bg: #232632;
  --avatar-face-bg: #ffffff;
  --avatar-eye: #e31837;
  --avatar-stroke: #3b4052;

  --code-bg: #111319;
  --code-head-bg: #1a1d26;
  --code-border: #2a2e3a;
  --code-text: #d8dee9;
  --ciw-bg: #0c0e13;

  --tk-comment: #6f7c91;
  --tk-string: #7ee787;
  --tk-number: #f59e0b;
  --tk-keyword: #56b6c2;
  --tk-function: #c678dd;
  --tk-api: #61afef;
  --tk-param: #e5c07b;

  --ok: #3fb950;
  --warn: #e5a93c;
  --danger: #f85149;
  --info: #4da3ff;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --topbar-h: 52px;
  --inline-code-bg: rgba(148, 163, 184, 0.14);
  --inline-code-border: rgba(148, 163, 184, 0.22);
  --inline-code-text: #93c5fd;
  --mono: "JetBrains Mono", "Cascadia Mono", "Cascadia Code", Consolas, "SF Mono", Menlo, Monaco, "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", monospace;
  --sans: "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", "Segoe UI", -apple-system, BlinkMacSystemFont, "Noto Sans CJK SC", sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg-window);
  color: var(--text-primary);
  font: 14px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button, a, .nav-item, .feature-card, .doc-card, .featured-card {
  touch-action: manipulation;
}
a { color: var(--brand-red-text); text-decoration: none; }
a:hover { text-decoration: underline; }
:is(button, a, input, textarea, select, [tabindex]):focus-visible {
  outline: 2px solid var(--brand-red);
  outline-offset: 2px;
}
.topbar-search-input:focus-visible,
.sandbox-textarea:focus-visible {
  outline: none;
}
.dark-only { display: none; }
[data-theme="dark"] .dark-only { display: inline-flex; }

.app-loading {
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 13.5px;
}
.hidden { display: none !important; }
.sr-only {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* ---------- 通用图标与 SVG 色彩类 ---------- */
.icon {
  display: inline-block;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  vertical-align: middle;
}
.icon.sm { width: 15px; height: 15px; }
.icon.lg { width: 28px; height: 28px; }
.icon-accent { stroke: var(--brand-red); }
.icon-accent-fill { fill: var(--brand-red); }

.wordmark {
  display: inline-block;
  height: 19px;
  width: auto;
  flex-shrink: 0;
  color: var(--brand-wordmark);
}
.wordmark.hero-wordmark { height: 34px; }
.wordmark.auth-wordmark { height: 27px; }
.wordmark-bar { fill: var(--brand-red); }
.wordmark-text { fill: currentColor; }
.brand-divider {
  display: inline-block;
  width: 1px;
  height: 14px;
  background: var(--border-input);
  flex-shrink: 0;
}

.robot-avatar {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  display: block;
}
.robot-avatar.sm { width: 32px; height: 32px; }
.robot-avatar .avatar-ring {
  fill: var(--avatar-ring-bg);
  stroke: var(--avatar-stroke);
}
.robot-avatar .avatar-face { fill: var(--avatar-face-bg); }
.robot-avatar .avatar-eye { fill: var(--avatar-eye); }

/* ---------- 通用控件 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border-card);
  background: var(--bg-surface);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 13px;
  line-height: 1.35;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.14s, border-color 0.14s, color 0.14s, transform 0.14s;
}
.btn:hover:not(:disabled) {
  background: var(--bg-surface-hover);
  border-color: var(--border-hover);
}
.btn:focus-visible,
.input:focus-visible,
.composer-input:focus-visible {
  outline: 1.5px solid var(--brand-red);
  outline-offset: -1px;
}
.btn:disabled { opacity: 0.48; cursor: not-allowed; }
.btn.primary {
  background: var(--send-bg);
  border-color: var(--send-bg);
  color: #ffffff;
  font-weight: 500;
}
.btn.primary:hover:not(:disabled) {
  background: var(--send-bg-hover);
  border-color: var(--send-bg-hover);
  color: #ffffff;
}
.btn.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-secondary);
}
.btn.ghost:hover:not(:disabled) {
  color: var(--text-primary);
  background: var(--bg-surface-hover);
}
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn.icon-btn { padding: 5px; min-width: 30px; min-height: 30px; }
.btn.danger:hover:not(:disabled) { color: var(--danger); border-color: var(--danger); }
.btn.danger-outline {
  color: var(--danger);
  border-color: rgba(220, 38, 38, 0.45);
  background: rgba(220, 38, 38, 0.08);
}
.btn.danger-outline:hover:not(:disabled) {
  color: #ffffff;
  background: var(--danger);
  border-color: var(--danger);
}
.btn.danger-solid {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
  font-weight: 500;
}
.btn.danger-solid:hover:not(:disabled) {
  background: #b91c1c;
  border-color: #b91c1c;
  color: #ffffff;
}

.field { display: grid; gap: 5px; margin-bottom: 13px; }
.field label {
  font-size: 12.5px;
  color: var(--text-secondary);
  font-weight: 500;
}
.input {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.14s;
}
.input:focus { border-color: var(--brand-red); }
.input.compact { padding: 5px 9px; font-size: 12.5px; }
.input.wide { width: 170px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-surface-2);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  white-space: nowrap;
  font-family: var(--mono);
}
.badge.version {
  color: var(--info);
  border-color: rgba(77, 163, 255, 0.35);
  background: rgba(77, 163, 255, 0.1);
}
.badge.kind {
  color: var(--brand-red-text);
  border-color: var(--border-hover);
  background: var(--brand-red-soft);
}
.badge.ok-pill {
  color: var(--ok);
  border-color: rgba(63, 185, 80, 0.35);
  background: rgba(63, 185, 80, 0.1);
}
.badge.status-badge {
  font-family: var(--sans);
  font-weight: 500;
  font-size: 12px;
  padding: 3px 10px;
  background: var(--bg-surface);
  border-color: var(--border-card);
  color: var(--text-secondary);
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--danger); }
.dot.red { background: var(--brand-red); }

.error-text { color: var(--danger); font-size: 12.5px; min-height: 1.3em; }
.muted { color: var(--text-muted); }
.text-xs { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12.5px; }

/* ---------- 登录界面 (cādence® Virtuoso Agent 风格) ---------- */
.auth {
  position: relative;
  min-height: 100%;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg-hero);
  overflow-x: hidden;
  overflow-y: auto;
}
.auth::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: min(680px, 90vw);
  height: 420px;
  background-image: var(--wafer-image);
  background-repeat: no-repeat;
  background-position: right top;
  background-size: contain;
  opacity: var(--wafer-opacity);
  -webkit-mask-image: linear-gradient(to bottom, #000 68%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 68%, transparent 100%);
  pointer-events: none;
}
.auth-card {
  position: relative;
  z-index: 1;
  width: min(420px, 100%);
  background: var(--bg-surface);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  padding: 26px 28px 28px;
  box-shadow: var(--shadow-dock);
}
.auth-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.auth-brand { display: grid; gap: 4px; }
.auth-title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}
.auth-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 18px;
}
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 0 0 16px;
  background: var(--bg-input);
  padding: 3px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
}
.auth-tabs button {
  border: 0;
  background: transparent;
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.14s, color 0.14s;
}
.auth-tabs button.active {
  background: var(--bg-surface-2);
  color: var(--text-primary);
}
.auth-submit { width: 100%; padding: 9px 14px; font-size: 14px; margin-top: 4px; }

/* ---------- 主工作台外壳: Topbar + Body ---------- */
.app-shell {
  display: grid;
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  height: 100%;
  height: 100dvh;
  background: var(--bg-window);
  overflow: hidden;
}

/* 顶栏 (3 区平衡布局: 左侧品牌 · 居中搜索 · 右侧动作) */
.topbar {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 480px) minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  background: var(--bg-topbar);
  border-bottom: 0;
  min-width: 0;
  z-index: 50;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  justify-self: start;
}
.topbar-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  cursor: pointer;
  border: 0;
  background: transparent;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  color: inherit;
  min-width: 0;
}
.topbar-brand:hover .topbar-app-name {
  color: var(--text-primary);
}
.topbar-app-name {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
  transition: color 0.14s;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  justify-self: end;
}
.mobile-search-btn { display: none; }
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 3px 10px 3px 5px;
  border: 1px solid var(--border-card);
  border-radius: 999px;
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  transition: border-color 0.14s, color 0.14s, background 0.14s;
}
.user-chip:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
}
.user-initial {
  width: 21px;
  height: 21px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--brand-red-soft);
  color: var(--brand-red);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
}
.mobile-only { display: none; }

/* 主体容器: 左导航 + 主舞台 */
.shell-body {
  display: grid;
  grid-template-columns: 212px minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

/* ---------- 左侧导航栏 (统一外框无硬分割线) ---------- */
.nav-rail {
  display: flex;
  flex-direction: column;
  background: var(--bg-sidebar);
  border-right: 0;
  padding: 6px 12px max(14px, env(safe-area-inset-bottom)) 12px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  transform: none;
}
.nav-group {
  display: grid;
  gap: 3px;
}
.nav-group.bottom {
  margin-top: auto;
  padding-top: 16px;
}
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  padding: 9.5px 14px 9.5px 15px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 450;
  text-align: left;
  transition: background 0.14s, color 0.14s;
}
.nav-item:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}
.nav-item.active {
  background: var(--bg-active-nav);
  color: var(--text-active-nav);
  font-weight: 560;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 7px;
  bottom: 7px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--brand-red);
}
.nav-item.active .icon { color: var(--brand-red); }

/* ---------- 主内容舞台 (内嵌圆角画布) ---------- */
.stage-host {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0 12px 12px 0;
  background: var(--bg-window);
}

/* ---------- 视图 1: 首页 (Hero 舞台 + 右侧 Companion Dock 双卡片对齐) ---------- */
.home-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(380px, 26vw, 428px);
  gap: 12px;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background: transparent;
}
.home-layout.dock-collapsed {
  grid-template-columns: minmax(0, 1fr) 0;
  gap: 0;
}

.hero-stage {
  position: relative;
  overflow-x: hidden;
  overflow-y: auto;
  padding: clamp(32px, 5vh, 60px) clamp(32px, 4.5vw, 68px);
  background: var(--bg-hero);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.hero-stage::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: min(680px, 64%);
  height: min(560px, 84%);
  background-image: var(--wafer-image);
  background-repeat: no-repeat;
  background-position: right top;
  background-size: contain;
  opacity: var(--wafer-opacity);
  -webkit-mask-image: radial-gradient(ellipse 96% 92% at 100% 0%, #000 62%, transparent 100%);
  mask-image: radial-gradient(ellipse 96% 92% at 100% 0%, #000 62%, transparent 100%);
  pointer-events: none;
  z-index: 0;
}
.hero-content {
  position: relative;
  z-index: 1;
  max-width: 860px;
  width: 100%;
  margin: auto 0;
}
.hero-header {
  display: grid;
  gap: 8px;
  margin-bottom: 34px;
}
.hero-title {
  margin: 4px 0 0;
  font-size: clamp(30px, 3.2vw, 38px);
  font-weight: 700;
  line-height: 1.16;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}
.hero-subtitle {
  margin: 2px 0 0;
  font-size: 15px;
  color: var(--text-muted);
  font-weight: 400;
}

/* 3 列功能卡片 (1:1 复刻 mockup 几何比例) */
.feature-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  max-width: 820px;
}
.feature-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: stretch;
  gap: 14px;
  min-height: 148px;
  padding: 22px 22px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border-card);
  border-radius: 14px;
  box-shadow: var(--shadow-card);
  text-align: left;
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
}
.feature-card:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-hover);
  box-shadow: var(--shadow-card-hover);
}
.feature-icon-box {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  flex-shrink: 0;
}
.feature-icon-box .icon.lg {
  width: 24px;
  height: 24px;
}
.feature-card-body {
  display: grid;
  gap: 6px;
  min-width: 0;
}
.feature-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}
.feature-card-title {
  font-size: 16.5px;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}
.feature-card-desc {
  font-size: 13px;
  line-height: 1.52;
  color: var(--text-muted);
}
.feature-card-chevron {
  color: var(--text-muted);
  flex-shrink: 0;
  display: inline-flex;
  transition: transform 0.14s, color 0.14s;
}
.feature-card:hover .feature-card-chevron {
  color: var(--brand-red);
}

/* 卡片下方极简最近会话条 */
.recent-strip {
  margin-top: 24px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.recent-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-right: 2px;
}
.recent-chip {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  transition: border-color 0.14s, color 0.14s, background 0.14s;
}
.recent-chip:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
  background: var(--bg-surface-hover);
}

/* ---------- 右侧 Companion Dock 面板 (与 Hero 等高像素对齐) ---------- */
.companion-dock-wrap {
  padding: 0;
  min-height: 0;
  min-width: 0;
  display: flex;
  overflow: hidden;
}
.home-layout.dock-collapsed .companion-dock-wrap {
  padding: 0;
  opacity: 0;
  pointer-events: none;
}
.companion-dock {
  position: relative;
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  box-shadow: var(--shadow-dock);
  overflow: hidden;
}
.dock-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 12px;
  height: 46px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.dock-tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 100%;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color 0.14s;
}
.dock-tab:hover { color: var(--text-primary); }
.dock-tab.active { color: var(--text-primary); font-weight: 600; }
.dock-tab.active .icon { color: var(--brand-red); }
.dock-tab.active::after {
  content: '';
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 0;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--brand-red);
}
.dock-tabs-spacer { flex: 1; }
.dock-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---------- 对话区与欢迎态 (Companion Dock & 全屏 AI 对话共用) ---------- */
.chat-scroll {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: 18px 16px;
}
.chat-scroll.full-chat {
  padding: 26px clamp(18px, 4vw, 48px);
}
.chat-inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
  max-width: 100%;
  gap: 18px;
}
.chat-scroll.full-chat .chat-inner {
  max-width: min(960px, 100%);
  margin: 0 auto;
}

/* 机器人头像 + 欢迎气泡 + 快捷提问胶囊 (1:1 复刻 mockup 右栏) */
.welcome-block {
  display: grid;
  gap: 16px;
}
.welcome-greeting {
  display: flex;
  align-items: flex-start;
  gap: 11px;
}
.welcome-bubble {
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text-primary);
  font-size: 13.5px;
  line-height: 1.55;
}
.quick-chips {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 9px;
  padding-left: 4px;
}
.quick-chip {
  border: 1px solid var(--border-card);
  background: var(--bg-surface-2);
  color: var(--text-secondary);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  text-align: left;
  transition: border-color 0.14s, color 0.14s, background 0.14s;
}
.quick-chip:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
  background: var(--bg-surface-hover);
}

/* 消息气泡 */
.msg {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
  gap: 6px;
}
.msg.user { justify-items: end; }
.msg-meta-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  color: var(--text-muted);
}
.msg-assistant-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 0;
}
.msg-assistant-col {
  flex: 1;
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
}
.msg .bubble {
  max-width: 100%;
  min-width: 0;
  border-radius: var(--radius-md);
  padding: 11px 14px;
  overflow-wrap: anywhere;
  overflow-x: hidden;
}
.msg.user .bubble {
  background: var(--bg-surface-2);
  border: 1px solid var(--border-card);
  border-radius: 16px 16px 4px 16px;
  padding: 11px 16px;
  color: var(--text-primary);
  max-width: min(680px, 84%);
  line-height: 1.6;
}
.msg.user .bubble blockquote {
  margin-top: 8px;
  padding: 6px 11px;
  border-radius: 0 6px 6px 0;
  font-size: 12.5px;
  line-height: 1.55;
}
.msg.assistant .bubble {
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 16px 20px;
  color: var(--text-primary);
  font-size: 14.5px;
  line-height: 1.68;
  width: 100%;
}
.companion-dock .msg.assistant .bubble,
.doc-copilot-pane .msg.assistant .bubble {
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 13.5px;
  line-height: 1.6;
}
.companion-dock .msg.user .bubble,
.doc-copilot-pane .msg.user .bubble {
  max-width: 90%;
  padding: 9px 13px;
  font-size: 13.5px;
}
.msg .quote-ref {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-surface-2);
  border-left: 3px solid var(--brand-red);
  border-radius: 4px;
  padding: 3px 9px;
  max-width: min(680px, 92%);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.img-zoom-btn {
  border: 0;
  background: transparent;
  padding: 0;
  display: inline-flex;
  border-radius: 8px;
  cursor: zoom-in;
  max-width: 100%;
}
.msg-thumbs img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border-card);
  cursor: zoom-in;
  display: block;
}
.msg-meta-bar,
.msg-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}
.msg-evidence-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.msg-ops-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  flex-shrink: 0;
}
.msg-elapsed {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 2px;
}
.source-pill {
  display: inline-block;
  vertical-align: middle;
  max-width: 210px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11.5px;
  line-height: 1.45;
  font-family: var(--mono);
  border: 1px solid var(--border-card);
  background: var(--bg-surface);
  border-radius: 6px;
  padding: 2px 8px;
  color: var(--text-secondary);
  transition: border-color 0.14s, color 0.14s, background 0.14s;
}
.source-pill:hover,
.source-pill.active {
  color: var(--brand-red-text);
  border-color: var(--border-hover);
  background: var(--brand-red-soft);
}
.source-pill.agent-pill {
  color: var(--info);
  border-color: rgba(77, 163, 255, 0.35);
  background: rgba(77, 163, 255, 0.1);
}
.source-pill.more-pill {
  color: var(--text-muted);
  background: var(--bg-surface-2);
}
.web-search-btn {
  border-color: var(--border-hover);
  color: var(--brand-red-text);
  background: var(--brand-red-soft);
}

/* ---------- Markdown & SKILL IDE 代码块 ---------- */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 10px; white-space: pre-wrap; }
.md h1, .md h2, .md h3, .md h4 {
  margin: 15px 0 8px;
  line-height: 1.35;
  color: var(--text-primary);
}
.md h1 { font-size: 17px; }
.md h2 { font-size: 15.5px; border-bottom: 1px solid var(--border-subtle); padding-bottom: 5px; }
.md h3, .md h4 { font-size: 14.5px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md li { margin: 4px 0; white-space: pre-wrap; }
.md blockquote {
  margin: 0 0 10px;
  padding: 7px 13px;
  border-left: 3px solid var(--brand-red);
  border-radius: 0 6px 6px 0;
  background: var(--bg-surface);
  color: var(--text-secondary);
}
.md code.inline {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--inline-code-bg);
  border: 1px solid var(--inline-code-border);
  border-radius: 5px;
  padding: 1px 6px;
  color: var(--inline-code-text);
  font-variant-ligatures: none;
}
.md hr { border: 0; border-top: 1px solid var(--border-subtle); margin: 12px 0; }
.md table {
  border-collapse: collapse;
  margin: 0 0 10px;
  font-size: 12.5px;
  display: block;
  overflow-x: auto;
}
.md th, .md td { border: 1px solid var(--border-subtle); padding: 5px 9px; text-align: left; }
.md th { background: var(--bg-surface); font-weight: 600; }

.code-block {
  margin: 0 0 11px;
  border: 1px solid var(--code-border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--code-bg);
  max-width: 100%;
  min-width: 0;
}
.code-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 5px 8px 5px 10px;
  background: var(--code-head-bg);
  border-bottom: 1px solid var(--code-border);
  color: #9ba7b8;
  font-size: 11.5px;
}
.code-head .lang-pill {
  font-family: var(--mono);
  font-weight: 650;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 4px;
  background: rgba(97, 175, 239, 0.14);
  border: 1px solid rgba(97, 175, 239, 0.35);
  color: #7cc4ff;
}
.code-head .lang-pill.svrf {
  background: rgba(227, 24, 55, 0.16);
  border-color: rgba(227, 24, 55, 0.45);
  color: #ff8a96;
}
.code-head .line-count {
  flex: 1 0 auto;
  white-space: nowrap;
  margin-right: auto;
  font-family: var(--mono);
  font-size: 11px;
  color: #8f9cad;
}
.code-head .btn {
  background: #232733;
  border-color: #343b4b;
  color: #d0d8e4;
}
.code-head .btn:hover:not(:disabled) {
  border-color: #61afef;
  background: #2c3242;
  color: #ffffff;
}
.code-head .btn.run {
  background: rgba(227, 24, 55, 0.22);
  border-color: rgba(227, 24, 55, 0.65);
  color: #ff98a4;
}
.code-head .btn.run:hover:not(:disabled) {
  background: var(--send-bg);
  border-color: var(--send-bg);
  color: #ffffff;
}
.code-head .btn.copied {
  border-color: var(--ok);
  color: #7ee787;
}
.code-block pre {
  margin: 0;
  padding: 14px 16px;
  overflow: auto;
  max-height: 560px;
  color: var(--code-text);
  font: 13px/1.65 var(--mono);
  font-variant-ligatures: none;
  tab-size: 4;
}
.tk-comment { color: var(--tk-comment); }
.tk-string { color: var(--tk-string); }
.tk-number { color: var(--tk-number); }
.tk-keyword { color: var(--tk-keyword); font-weight: 500; }
.tk-api { color: var(--tk-api); font-weight: 500; }
.tk-param { color: var(--tk-param); }
.tk-function { color: var(--tk-function); }

/* CIW 求值控制台 */
.run-console {
  border-top: 1px solid var(--code-border);
  background: var(--ciw-bg);
  color: #cfd7e3;
  padding: 10px 12px;
  font: 12.5px/1.6 var(--mono);
  font-variant-ligatures: none;
  display: grid;
  gap: 8px;
}
.run-console .ciw-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid #222834;
}
.run-console .ciw-tag { font-weight: 700; color: #ff7a8a; }
.run-console .status { font-family: var(--sans); font-size: 12px; }
.run-console .status.ok { color: #4ade80; }
.run-console .status.bad { color: #f87171; }
.run-console .status.warn { color: #fbbf24; }
.run-console .ciw-section-label { font-size: 11px; color: #94a3b8; letter-spacing: 0.04em; }
.run-console .btn {
  background: #1e2430;
  border-color: #364054;
  color: #e2e8f0;
}
.run-console .btn:hover:not(:disabled) {
  background: #2a3242;
  border-color: #60a5fa;
  color: #ffffff;
}
.run-console .btn.danger {
  background: rgba(248, 113, 113, 0.14);
  border-color: rgba(248, 113, 113, 0.48);
  color: #fca5a5;
}
.run-console .btn.danger:hover:not(:disabled) {
  background: rgba(220, 38, 38, 0.30);
  border-color: #f87171;
  color: #ffffff;
}
.run-console pre {
  margin: 0;
  padding: 7px 9px;
  max-height: 260px;
  max-width: 100%;
  overflow-x: auto;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  background: #141820;
  border: 1px solid #252c38;
  border-radius: 5px;
}
.run-console pre.ciw-out { border-left: 2px solid var(--ok); color: #d8dee9; }
.run-console pre.ciw-err { border-left: 2px solid var(--danger); color: #fca5a5; }
.run-console pre.ciw-warn { border-left: 2px solid var(--warn); color: #fde68a; }

.media-figure { margin: 0; display: grid; gap: 5px; }
.media-figure img,
.run-console img,
.media-grid img {
  max-width: 100%;
  border-radius: 8px;
  border: 1px solid var(--code-border);
  background: #111318;
  cursor: zoom-in;
}
.media-grid { display: grid; gap: 10px; margin-top: 10px; }
.media-figure figcaption,
.media-grid figcaption { font-size: 11.5px; color: var(--text-muted); font-family: var(--mono); }

/* ---------- SSE 实时阶段条 ---------- */
.stages {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.stage {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--mono);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  background: var(--bg-surface-2);
}
.stage.current {
  color: var(--text-primary);
  border-color: var(--border-hover);
  background: var(--brand-red-soft);
}
.stage.current .dot {
  background: var(--brand-red);
  animation: pulse 1s infinite ease-in-out;
}
.stage.done .dot { background: var(--ok); }
@keyframes pulse { 50% { opacity: 0.25; } }

/* ---------- Composer 输入框 (1:1 复刻 mockup 纸夹 + 输入框 + 红色纸飞机按钮) ---------- */
.composer {
  padding: 10px 14px max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
  max-width: 100%;
  gap: 8px;
  flex-shrink: 0;
}
.composer.full-composer {
  padding: 8px clamp(18px, 4vw, 48px) max(18px, env(safe-area-inset-bottom));
  border-top: 0;
  background: transparent;
}
.composer-inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
  max-width: 100%;
  gap: 8px;
  width: 100%;
}
.composer.full-composer .composer-inner {
  max-width: min(960px, 100%);
  margin: 0 auto;
  gap: 10px;
}
.quote-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-surface-2);
  border-left: 3px solid var(--brand-red);
  padding: 4px 9px;
  border-radius: 6px;
}
.quote-bar .quote-label {
  flex-shrink: 0;
}
.quote-bar .text,
.quote-bar .quote-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.quote-bar button {
  flex-shrink: 0;
}
.pending-images { display: flex; flex-wrap: wrap; gap: 7px; }
.pending-image { position: relative; }
.pending-image img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 7px;
  border: 1px solid var(--border-card);
  cursor: zoom-in;
  transition: border-color 0.14s, transform 0.14s;
}
.pending-image img:hover {
  border-color: var(--brand-red);
}
.pending-image > button:not(.img-zoom-btn) {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 0;
  background: var(--send-bg);
  color: #ffffff;
  font-size: 11px;
  line-height: 18px;
  padding: 0;
}
.composer-row {
  display: flex;
  align-items: flex-end;
  min-width: 0;
  max-width: 100%;
  gap: 8px;
}
.composer.full-composer .composer-row {
  align-items: flex-end;
  gap: 10px;
  padding: 12px 14px 12px 16px;
  border-radius: 16px;
  border: 1.5px solid var(--border-input);
  background: var(--bg-surface);
  box-shadow: var(--shadow-dock);
  transition: border-color 0.16s, box-shadow 0.16s, background 0.16s;
}
.composer.full-composer .composer-row:hover {
  border-color: var(--border-hover);
}
.composer.full-composer .composer-row:focus-within {
  border-color: var(--brand-red);
  box-shadow: var(--shadow-dock), 0 0 0 3px var(--brand-red-soft);
}
.attach-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: background 0.14s, color 0.14s;
}
.attach-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}
.composer.full-composer .attach-btn {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  background: var(--bg-surface-2);
  color: var(--text-secondary);
}
.composer.full-composer .attach-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--brand-red);
}
.composer-input {
  flex: 1;
  min-width: 0;
  resize: none;
  min-height: 38px;
  max-height: 180px;
  padding: 8px 12px;
  border: 1px solid var(--border-input);
  border-radius: 8px;
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 13.5px;
  line-height: 1.45;
  outline: none;
  field-sizing: content;
  transition: border-color 0.14s;
}
.composer-input:focus { border-color: var(--brand-red); }
.composer.full-composer .composer-input {
  min-height: 56px;
  max-height: 240px;
  padding: 6px 4px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  font-size: 15px;
  line-height: 1.6;
}
.composer.full-composer .composer-input:focus {
  border: 0;
  background: transparent;
  box-shadow: none;
}
.composer.full-composer .composer-input:focus-visible {
  outline: none;
}
.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 0;
  background: var(--send-bg);
  color: #ffffff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: background 0.14s, transform 0.12s;
}
.composer.full-composer .send-btn {
  width: 42px;
  height: 42px;
  border-radius: 11px;
}
.composer.full-composer .attach-btn .icon,
.composer.full-composer .send-btn .icon {
  width: 18px;
  height: 18px;
}
.send-btn:hover:not(:disabled) {
  background: var(--send-bg-hover);
}
.send-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.send-btn.stop-mode {
  background: var(--bg-surface-2);
  border: 1px solid var(--brand-red);
  color: var(--brand-red);
}
.send-btn.stop-mode:hover {
  background: var(--brand-red-soft);
}
.stop-square {
  display: block;
  width: 11px;
  height: 11px;
  border-radius: 2px;
  background: currentColor;
}
.thinking-bubble {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: auto !important;
  font-size: 13px;
  color: var(--text-primary);
}
.thinking-dot {
  animation: pulse 1s infinite ease-in-out;
}
.modal:focus { outline: none; }
.composer-hint {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 18px;
  font-size: 11.5px;
  opacity: 0.78;
  color: var(--text-muted);
}

/* 拖拽上传覆盖层 */
.drop-target { position: relative; }
.drop-overlay {
  position: absolute;
  inset: 10px;
  z-index: 30;
  display: none;
  place-items: center;
  background: rgba(13, 14, 18, 0.84);
  border: 2px dashed var(--brand-red);
  border-radius: var(--radius-md);
  pointer-events: none;
}
:root[data-theme="light"] .drop-overlay {
  background: rgba(244, 245, 249, 0.9);
}
.drop-target.drop-active .drop-overlay { display: grid; }
.drop-overlay-card {
  padding: 16px 22px;
  background: var(--bg-surface);
  border: 1px solid var(--brand-red);
  border-radius: var(--radius-md);
  text-align: center;
  box-shadow: var(--shadow-dock);
}
.drop-overlay-title { font-weight: 600; color: var(--text-primary); font-size: 14px; }
.drop-overlay-sub { margin-top: 4px; font-size: 12px; color: var(--text-muted); font-family: var(--mono); }

/* ---------- 视图 2: 全屏 AI 对话工作台 ---------- */
.chat-workspace {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr) 0;
  height: 100%;
  min-height: 0;
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  background: var(--bg-hero);
  overflow: hidden;
  transition: grid-template-columns 0.16s ease;
}
.chat-workspace.inspector-open {
  grid-template-columns: 232px minmax(0, 1fr) 360px;
}
.chat-workspace.sessions-collapsed {
  grid-template-columns: 0 minmax(0, 1fr) 0;
}
.chat-workspace.sessions-collapsed.inspector-open {
  grid-template-columns: 0 minmax(0, 1fr) 360px;
}
.chat-workspace.sessions-collapsed .sessions-pane {
  border-right: 0;
  overflow: hidden;
}
.sessions-pane {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  min-height: 0;
  min-width: 0;
}
.pane-header {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.pane-header-title {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.new-thread-pill {
  border-radius: 999px;
  padding: 4px 11px;
  gap: 4px;
}
.sessions-search {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-subtle);
}
.sessions-list {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 8px max(8px, env(safe-area-inset-bottom));
  display: grid;
  align-content: start;
  gap: 4px;
}
.thread-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 10px;
  border-radius: 9px;
  border: 1px solid transparent;
  transition: background 0.12s, border-color 0.12s;
}
.thread-item:hover { background: var(--bg-surface-hover); }
.thread-item.active {
  background: var(--bg-active-nav);
  border-color: rgba(227, 24, 55, 0.22);
}
.thread-select-btn {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 2px;
  text-align: left;
  display: grid;
  gap: 2px;
  border-radius: 5px;
}
.thread-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.thread-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.thread-meta {
  display: flex;
  gap: 7px;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--mono);
}
.thread-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
}
.thread-item:hover .thread-actions,
.thread-item:focus-within .thread-actions,
.thread-item.active .thread-actions {
  opacity: 1;
  pointer-events: auto;
}
.thread-rename-input {
  width: 100%;
  padding: 3px 6px;
  font-size: 13px;
  border: 1px solid var(--brand-red);
  border-radius: 5px;
  background: var(--bg-input);
  color: var(--text-primary);
  outline: none;
}

.chat-main-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 100%;
  min-height: 0;
  background: var(--bg-hero);
}
.chat-main-pane > .pane-header .pane-header-title {
  min-width: 0;
}
.inspector-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-subtle);
  overflow: hidden;
}
.inspector-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 14px max(12px, env(safe-area-inset-bottom));
  display: grid;
  gap: 10px;
  align-content: start;
}

/* Evidence & Agent Trace 卡片 */
.inspector-section-head {
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--border-subtle);
}
.trace-list { display: grid; gap: 6px; }
.trace-item {
  border: 1px solid var(--border-card);
  border-left: 3px solid var(--info);
  border-radius: 7px;
  padding: 7px 10px;
  background: var(--bg-surface-2);
  display: grid;
  gap: 4px;
}
.trace-item.warn { border-left-color: var(--warn); }
.trace-item-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.trace-item-detail { font-size: 11.5px; color: var(--text-secondary); overflow-wrap: anywhere; }

.source-card {
  border: 1px solid var(--border-card);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--bg-surface-2);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
  gap: 6px;
}
.source-card.focused {
  border-color: var(--brand-red);
}
.source-card .manual { font-weight: 600; font-size: 13px; color: var(--text-primary); overflow-wrap: anywhere; }
.source-card .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text-muted); }
.source-card .excerpt {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: pre-wrap;
  max-height: 200px;
  overflow: auto;
  border-top: 1px dashed var(--border-subtle);
  padding-top: 7px;
}

/* ---------- 视图 3: 文档查询与函数探针 ---------- */
.page-view {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 26px clamp(20px, 4vw, 46px) max(36px, env(safe-area-inset-bottom));
  background: var(--bg-hero);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
}
.page-inner {
  max-width: 1280px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
  gap: 18px;
}
.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.page-head h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
}
.page-head p {
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}
.panel-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  box-shadow: var(--shadow-card);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
  gap: 12px;
}
.probe-search-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.probe-search-row > .input {
  flex: 1;
  min-width: 0;
  width: auto;
}
.probe-search-row .input { font-family: var(--mono); }
.module-count-label {
  white-space: nowrap;
  flex-shrink: 0;
}
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
}
.probe-summary {
  white-space: pre-wrap;
  max-width: 100%;
  overflow-x: auto;
  overflow-wrap: anywhere;
  background: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--code-border);
  padding: 11px 13px;
  border-radius: 8px;
  margin: 0;
  font: 12px/1.55 var(--mono);
}

/* ---------- 文档库、分类胶囊、模块网格与阅读器 ---------- */
.subtabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 10px;
}
.subtab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  padding: 6px 13px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.14s, color 0.14s, border-color 0.14s;
}
.subtab:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}
.subtab.active {
  background: var(--bg-active-nav);
  border-color: var(--border-hover);
  color: var(--text-active-nav);
  font-weight: 600;
}
.mini-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 3px;
}
.mini-tab {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  border-radius: 6px;
  padding: 5px 6px;
  font-size: 12px;
  font-weight: 500;
  transition: background 0.14s, color 0.14s;
}
.mini-tab.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: var(--shadow-card);
}

.cat-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.cat-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  max-width: none;
  flex-shrink: 0;
  border: 1px solid var(--border-card);
  background: var(--bg-surface);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12.5px;
  transition: border-color 0.14s, color 0.14s, background 0.14s;
}
.cat-pill:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
}
.cat-pill.active {
  background: var(--bg-active-nav);
  border-color: var(--brand-red);
  color: var(--text-active-nav);
  font-weight: 600;
}
.cat-pill .count {
  font-family: var(--mono);
  font-size: 11px;
  opacity: 0.78;
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
}
.doc-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 7px;
  padding: 14px 15px;
  background: var(--bg-surface);
  border: 1px solid var(--border-card);
  border-radius: 11px;
  box-shadow: var(--shadow-card);
  text-align: left;
  min-width: 0;
  transition: border-color 0.14s, transform 0.14s, box-shadow 0.14s;
}
.doc-card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-card-hover);
}
.doc-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}
.doc-card-title {
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.doc-card-chevron {
  color: var(--text-muted);
  flex-shrink: 0;
  display: inline-flex;
  transition: transform 0.14s, color 0.14s;
}
.doc-card:hover .doc-card-chevron {
  color: var(--brand-red);
}
.doc-card-desc {
  font-size: 12px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-top: 2px;
}
.doc-result-list {
  display: grid;
  gap: 10px;
}
.doc-result-card {
  border: 1px solid var(--border-card);
  border-radius: 9px;
  padding: 13px 15px;
  background: var(--bg-surface);
  box-shadow: var(--shadow-card);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
  gap: 7px;
  transition: border-color 0.14s, transform 0.14s, box-shadow 0.14s;
}
.doc-result-card.clickable {
  cursor: pointer;
}
.doc-result-card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-card-hover);
}
.doc-result-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.doc-result-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
  overflow-wrap: anywhere;
}
.doc-result-excerpt {
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.55;
}
.doc-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
}

/* 嵌入式同源 Cadence 文档阅读器 (/docs/*) */
.doc-viewer-shell {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-hero);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.doc-viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 44px;
  padding: 6px 14px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.doc-viewer-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.doc-viewer-meta {
  flex: 1;
  min-width: 160px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
}
.doc-viewer-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-viewer-path {
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-frame-wrap {
  flex: 1;
  min-width: 0;
  min-height: 0;
  height: 100%;
  background: var(--bg-window);
  padding: 0 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.doc-viewer-frame {
  flex: 1;
  width: 100%;
  max-width: 1280px;
  height: 100%;
  margin: 0 auto;
  min-width: 0;
  min-height: 0;
  border: 0;
  border-left: 1px solid var(--border-subtle);
  border-right: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-card);
  display: block;
  background: #ffffff;
}
.doc-viewer-frame.dark-inverted {
  filter: invert(0.9) hue-rotate(180deg);
  background: #0f1117;
}
.doc-viewer-body {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 0;
  overflow: hidden;
  transition: grid-template-columns 0.18s ease;
}
.doc-viewer-body > * {
  min-width: 0;
  min-height: 0;
}
.doc-viewer-body.copilot-open {
  grid-template-columns: minmax(0, 1fr) clamp(380px, 26vw, 430px);
}
.doc-copilot-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-subtle);
  overflow: hidden;
}
.doc-copilot-pane .code-head,
.companion-dock .code-head {
  gap: 3px;
  padding: 5px 6px;
}
.doc-copilot-pane .code-head .lang-pill,
.companion-dock .code-head .lang-pill {
  padding: 1px 5px;
  font-size: 10.5px;
}
.doc-copilot-pane .code-head .line-count,
.companion-dock .code-head .line-count {
  font-size: 10.5px;
}
.doc-copilot-pane .code-head .btn.small,
.companion-dock .code-head .btn.small {
  padding: 2px 5.5px;
  font-size: 11px;
  gap: 3px;
}
.doc-viewer-body:not(.copilot-open) .doc-copilot-pane {
  border-left: 0;
}
.doc-copilot-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.doc-copilot-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

/* ---------- 全局顶栏搜索框 (Ctrl+K 居中对齐) ---------- */
.topbar-search-wrap {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}
.topbar-search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 11px;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: 9px;
  transition: border-color 0.14s, box-shadow 0.14s, background 0.14s;
}
.topbar-search-box:focus-within {
  border-color: var(--brand-red);
  box-shadow: 0 0 0 3px var(--brand-red-soft);
  background: var(--bg-surface);
}
.topbar-search-icon {
  color: var(--text-muted);
  display: inline-flex;
  flex-shrink: 0;
}
.topbar-search-input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
}
.topbar-search-input::placeholder {
  color: var(--text-muted);
}
.kbd-hint {
  font: 11px/1 var(--mono);
  color: var(--text-muted);
  background: var(--bg-surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: 5px;
  padding: 3px 6px;
  flex-shrink: 0;
}

/* ---------- 实时搜索索引联想下拉框 ---------- */
.suggest-anchor {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
}
.suggest-anchor > .input {
  width: 100%;
}
.suggest-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  min-width: 280px;
  max-height: 420px;
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: 25;
  background: var(--bg-surface);
  border: 1px solid var(--border-card);
  border-radius: 10px;
  box-shadow: var(--shadow-dock);
  padding: 6px;
  display: grid;
  gap: 4px;
}
.topbar-search-wrap .suggest-menu {
  z-index: 55;
}
.suggest-anchor .suggest-menu {
  z-index: 25;
}
.companion-dock .suggest-menu {
  min-width: 0;
  width: 100%;
}
.suggest-menu.hidden {
  display: none;
}
.suggest-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 8px;
  font-size: 11px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-subtle);
}
.suggest-section {
  display: grid;
  gap: 6px;
  padding: 6px 6px 4px;
}
.suggest-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}
.suggest-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.suggest-chip {
  border: 1px solid var(--border-card);
  background: var(--bg-surface-2);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 11.5px;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}
.suggest-chip:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
  background: var(--bg-surface-hover);
}
.suggest-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 7px;
  padding: 7px 9px;
  text-align: left;
  transition: background 0.1s, border-color 0.1s;
}
.suggest-item:hover,
.suggest-item.active {
  background: var(--bg-active-nav);
  border-color: var(--border-hover);
}
.suggest-kind {
  font: 10.5px/1 var(--mono);
  font-weight: 600;
  padding: 3px 6px;
  border-radius: 4px;
  flex-shrink: 0;
  min-width: 44px;
  text-align: center;
}
.suggest-kind.skill {
  background: rgba(220, 30, 56, 0.12);
  color: var(--brand-red-text);
}
.suggest-kind.module {
  background: rgba(37, 99, 235, 0.12);
  color: var(--info);
}
.suggest-kind.doc {
  background: rgba(21, 128, 61, 0.12);
  color: var(--ok);
}
.suggest-kind.topic {
  background: rgba(180, 83, 9, 0.12);
  color: var(--warn);
}
.suggest-main {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 1px;
}
.suggest-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.suggest-sub {
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
mark.suggest-hl {
  background: var(--brand-red-soft);
  color: var(--brand-red-text);
  font-weight: 700;
  border-radius: 2px;
  padding: 0 1px;
}
.suggest-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 4px 2px;
  border-top: 1px solid var(--border-subtle);
  margin-top: 2px;
}
.suggest-action {
  flex: 1;
  min-width: 120px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  justify-content: center;
}
.btn-truncate {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 文档库快捷入口: 最近阅读、核心手册、零结果兜底 ---------- */
.docs-quick-section {
  display: grid;
  gap: 8px;
}
.docs-quick-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}
.featured-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.featured-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 13px 15px;
  background: var(--bg-surface);
  border: 1px solid var(--border-card);
  border-radius: 11px;
  box-shadow: var(--shadow-card);
  text-align: left;
  min-width: 0;
  transition: border-color 0.14s, transform 0.14s, box-shadow 0.14s;
}
.featured-card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-card-hover);
}
.featured-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}
.featured-card-top .badge {
  flex-shrink: 0;
}
.featured-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.featured-card-desc {
  font-size: 11.5px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.zero-rescue {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
  gap: 10px;
  padding: 18px;
}
.zero-rescue .btn {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.zero-rescue-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  overflow-wrap: anywhere;
}

/* 站内文档阅读器弹窗 */
.modal.doc-reader-modal {
  width: min(920px, 100%);
  max-height: 90vh;
  max-height: 90dvh;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow: hidden;
}
.doc-reader-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.doc-reader-titles {
  display: grid;
  gap: 5px;
  min-width: 0;
}
.doc-reader-titles h3 {
  margin: 0;
  font-size: 17px;
  color: var(--text-primary);
}
.doc-reader-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 22px;
}
.doc-reader-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface-2);
  flex-shrink: 0;
}
.doc-reader-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* 设置弹窗密码与管理配额内联表单 */
.password-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: end;
}
.password-form .field { margin: 0; }
.admin-quota-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.admin-quota-input {
  width: 72px;
  padding: 3px 6px;
  font-size: 12px;
}
.ok-text {
  color: var(--ok);
  font-size: 12.5px;
}
.table-scroll {
  overflow-x: auto;
}

@media (max-width: 720px) {
  .password-form { grid-template-columns: 1fr; }
}

.ciw-bar.queue-bar {
  justify-content: space-between;
  flex-wrap: wrap;
}
.ciw-bar.queue-bar .status {
  flex: 1;
  min-width: 180px;
}
.skill-status-pill {
  font-family: var(--mono);
  font-size: 12px;
  padding: 5px 10px;
}

/* ---------- 视图 4: SKILL 沙盒 ---------- */
.page-view.sandbox-page {
  display: flex;
  flex-direction: column;
  padding: 20px clamp(18px, 3vw, 36px) max(22px, env(safe-area-inset-bottom));
}
.page-view.sandbox-page .page-inner {
  max-width: 1640px;
  width: 100%;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.sandbox-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 16px;
  align-items: stretch;
  flex: 1;
  min-height: 460px;
}
.sandbox-editor-card {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 460px;
  transition: border-color 0.14s, box-shadow 0.14s;
}
.sandbox-editor-card:focus-within {
  border-color: var(--brand-red);
  box-shadow: 0 0 0 2px var(--brand-red-soft);
}
.ide-env-tag {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--tk-comment);
  white-space: nowrap;
}
.sandbox-editor-body {
  flex: 1;
  min-height: 360px;
  display: flex;
  align-items: stretch;
  overflow: hidden;
  background: var(--code-bg);
}
.sandbox-gutter {
  width: 44px;
  flex-shrink: 0;
  padding: 16px 8px 16px 0;
  text-align: right;
  user-select: none;
  overflow: hidden;
  white-space: pre;
  color: var(--tk-comment);
  background: rgba(0, 0, 0, 0.18);
  border-right: 1px solid var(--code-border);
  font: 14px/1.65 var(--mono);
  font-variant-ligatures: none;
}
.sandbox-textarea {
  width: 100%;
  flex: 1;
  min-width: 0;
  min-height: 360px;
  resize: none;
  border: 0;
  padding: 16px 16px;
  background: var(--code-bg);
  color: var(--code-text);
  font: 14px/1.65 var(--mono);
  font-variant-ligatures: none;
  outline: none;
  tab-size: 2;
}
.sandbox-console-card {
  background: var(--ciw-bg);
  border: 1px solid var(--code-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  height: 100%;
  min-height: 460px;
  display: flex;
  flex-direction: column;
}
.sandbox-console-body {
  padding: 14px 16px;
  display: grid;
  gap: 10px;
  align-content: start;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.ciw-welcome {
  border: 1px solid #1e2533;
  background: rgba(20, 25, 35, 0.72);
  border-radius: 8px;
  padding: 14px 16px;
  display: grid;
  gap: 9px;
}
.ciw-welcome-head {
  font-size: 12px;
  font-weight: 600;
  color: #7cc4ff;
}
.ciw-welcome-prompt {
  font-size: 12.5px;
  color: #4ade80;
}
.ciw-welcome-list {
  margin: 2px 0;
  padding-left: 18px;
  display: grid;
  gap: 5px;
  font-size: 12.5px;
  color: #9ba7b8;
}
.ciw-welcome-tip {
  padding-top: 8px;
  border-top: 1px dashed #242c3c;
  font-size: 11.5px;
  color: #7c899e;
}

/* ---------- 弹窗 (设置 / 关于 / 确认 / 证据 / 大图) ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 14, 0.65);
  display: grid;
  place-items: center;
  z-index: 70;
  padding: 16px max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  overscroll-behavior: contain;
}
.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-lg);
  width: min(680px, 94vw);
  max-height: 86vh;
  max-height: 86dvh;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 20px 22px;
  box-shadow: var(--shadow-dock);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 14px;
}
.modal.confirm-modal {
  width: min(440px, 92vw);
}
.confirm-message {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--text-secondary);
  overflow-wrap: anywhere;
}
.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}
.modal.evidence-modal {
  width: min(640px, 100%);
}
.modal-head {
  position: sticky;
  top: -20px;
  margin: -20px -22px 0;
  padding: 14px 22px 10px;
  z-index: 3;
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border-subtle);
}
.modal-head h3 { margin: 0; flex: 1; font-size: 16px; color: var(--text-primary); }
.modal-tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 8px;
}
.theme-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.theme-option {
  display: grid;
  gap: 8px;
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-card);
  background: var(--bg-surface-2);
  text-align: left;
  transition: border-color 0.14s, background 0.14s;
}
.theme-option.active {
  border-color: var(--brand-red);
  background: var(--brand-red-soft);
}
.theme-swatch {
  height: 44px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  display: flex;
  overflow: hidden;
}
.theme-swatch.dark { background: #0d0e12; }
.theme-swatch.dark .sw-rail { width: 26%; background: #14151a; border-right: 1px solid #22242c; }
.theme-swatch.dark .sw-accent { width: 100%; height: 4px; background: #e31837; }
.theme-swatch.light { background: #f4f5f9; }
.theme-swatch.light .sw-rail { width: 26%; background: #ffffff; border-right: 1px solid #e6e8ee; }
.theme-swatch.light .sw-accent { width: 100%; height: 4px; background: #e31837; }

.account-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-card);
  background: var(--bg-surface-2);
}
.account-user-info {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}
.account-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background: var(--brand-red-soft);
  border: 1px solid var(--border-hover);
  color: var(--brand-red);
  font-weight: 700;
  font-size: 15px;
  text-transform: uppercase;
}
.account-details {
  display: grid;
  gap: 3px;
  min-width: 0;
}
.account-name {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text-primary);
}
.quota-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.quota-tile {
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-card);
  background: var(--bg-surface-2);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.quota-label {
  font-size: 12.5px;
  color: var(--text-secondary);
}
.quota-val {
  font-family: var(--mono);
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text-primary);
}

.kv {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 7px 16px;
  font-size: 13px;
  overflow-wrap: anywhere;
}
.kv .k { color: var(--text-muted); }
.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table th, .data-table td {
  border-bottom: 1px solid var(--border-subtle);
  padding: 7px 8px;
  text-align: left;
  white-space: nowrap;
}
.data-table th { color: var(--text-secondary); font-weight: 600; }
.data-table th:last-child,
.data-table td.cell-actions {
  text-align: right;
}
.data-table td.cell-actions .chip-row {
  justify-content: flex-end;
}
.data-table .empty-cell {
  text-align: center;
  color: var(--text-muted);
  padding: 14px 8px;
}
.inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.inline-form .field { margin: 0; }
.inline-form .input { width: 108px; }
.inline-form .input-uses { width: 88px; }
.inline-form .input-hours { width: 110px; }
.inline-form .field-note { flex: 1; min-width: 160px; }
.inline-form .field-note .input,
.inline-form .input.wide { width: 100%; }
.inline-form > .btn { height: 37px; padding: 0 14px; }

.lightbox {
  position: relative;
  display: grid;
  place-items: center;
  max-width: 100%;
  max-height: 100%;
}
.lightbox img {
  max-width: 96vw;
  max-height: 92vh;
  max-height: 92dvh;
  border-radius: 8px;
  border: 1px solid var(--border-card);
  background: #111318;
}
.lightbox-close-btn {
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(18, 20, 26, 0.82);
  color: #ffffff;
  display: grid;
  place-items: center;
  z-index: 2;
  transition: background 0.14s, border-color 0.14s;
}
.lightbox-close-btn:hover {
  background: var(--brand-red);
  border-color: var(--brand-red);
}

.toast-stack {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  display: grid;
  gap: 8px;
  justify-items: center;
  pointer-events: none;
  max-width: min(460px, calc(100vw - 24px));
}
.toast {
  background: var(--bg-surface-2);
  color: var(--text-primary);
  border: 1px solid var(--border-hover);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: var(--shadow-dock);
  pointer-events: none;
  text-align: center;
}

.scrim {
  position: fixed;
  inset: var(--topbar-h) 0 0 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 40;
}

/* ---------- 悬停微动效仅在精确指针设备生效 ---------- */
@media (hover: hover) and (pointer: fine) {
  .feature-card:hover { transform: translateY(-2px); }
  .feature-card:hover .feature-card-chevron { transform: translateX(2px); }
  .doc-card:hover { transform: translateY(-1px); }
  .doc-card:hover .doc-card-chevron { transform: translateX(2px); }
  .featured-card:hover { transform: translateY(-1px); }
  .pending-image img:hover { transform: scale(1.03); }
}

@media (hover: none), (pointer: coarse) {
  .thread-actions {
    opacity: 1;
    pointer-events: auto;
    gap: 6px;
  }
}

/* ---------- 响应式适配 ---------- */
@media (max-width: 1200px) {
  .chat-workspace.inspector-open {
    grid-template-columns: 232px minmax(0, 1fr) 0;
  }
  .chat-workspace.sessions-collapsed.inspector-open {
    grid-template-columns: 0 minmax(0, 1fr) 0;
  }
  .inspector-pane {
    position: fixed;
    inset: var(--topbar-h) 0 0 auto;
    width: min(380px, 92vw);
    z-index: 42;
    transform: translateX(100%);
    transition: transform 0.18s ease;
    box-shadow: var(--shadow-dock);
  }
  .chat-workspace.inspector-open .inspector-pane { transform: none; }
}

@media (max-width: 1120px) {
  .home-layout { grid-template-columns: minmax(0, 1fr) 348px; }
  .feature-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .featured-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page-view.sandbox-page {
    display: block;
  }
  .page-view.sandbox-page .page-inner {
    display: grid;
    flex: none;
  }
  .sandbox-grid {
    grid-template-columns: minmax(0, 1fr);
    flex: none;
    min-height: 0;
    align-items: start;
  }
  .sandbox-editor-card,
  .sandbox-console-card {
    height: auto;
    min-height: 0;
  }
  .sandbox-editor-body {
    min-height: 280px;
  }
  .sandbox-textarea {
    min-height: 280px;
    resize: vertical;
  }
  .sandbox-console-card {
    min-height: 220px;
  }
  .doc-frame-wrap {
    padding: 0;
  }
  .doc-viewer-frame {
    max-width: none;
    border-left: 0;
    border-right: 0;
    box-shadow: none;
  }
  .doc-viewer-body,
  .doc-viewer-body.copilot-open {
    grid-template-columns: minmax(0, 1fr);
  }
  .doc-copilot-pane {
    position: fixed;
    inset: var(--topbar-h) 0 0 auto;
    width: min(380px, 92vw);
    z-index: 44;
    transform: translateX(100%);
    transition: transform 0.18s ease;
    box-shadow: var(--shadow-dock);
    border-left: 1px solid var(--border-subtle);
  }
  .doc-viewer-body.copilot-open .doc-copilot-pane {
    transform: none;
  }
}

@media (max-width: 960px) {
  .mobile-only { display: inline-flex; }
  .hide-mobile { display: none; }
  .topbar {
    border-bottom: 1px solid var(--border-subtle);
  }
  .user-chip {
    padding: 6px;
    justify-content: center;
  }
  .topbar-search-wrap {
    max-width: 220px;
  }
  .topbar-search-wrap .kbd-hint {
    display: none;
  }
  .shell-body { grid-template-columns: minmax(0, 1fr); }
  .stage-host {
    padding: 0;
    background: var(--bg-hero);
  }
  .hero-stage,
  .chat-workspace,
  .page-view,
  .doc-viewer-shell {
    border-radius: 0;
    border: 0;
    box-shadow: none;
  }
  .nav-rail {
    position: fixed;
    inset: var(--topbar-h) auto 0 0;
    width: 224px;
    z-index: 45;
    border-right: 1px solid var(--border-subtle);
    padding: 12px 10px max(14px, env(safe-area-inset-bottom)) 10px;
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    box-shadow: var(--shadow-dock);
  }
  .app-shell.nav-open .nav-rail { transform: none; }
  .home-layout,
  .home-layout.dock-collapsed {
    display: flex;
    flex-direction: column;
    gap: 0;
    overflow-y: auto;
    background: var(--bg-hero);
  }
  .home-layout.dock-collapsed .companion-dock-wrap {
    padding: 0 12px 16px;
    opacity: 1;
    pointer-events: auto;
  }
  .hero-stage {
    overflow-y: visible;
    justify-content: flex-start;
    padding: 22px 16px 18px;
    flex-shrink: 0;
  }
  .hero-stage::before {
    top: 0;
    right: 0;
    width: min(520px, 85%);
    height: 300px;
    background-position: right top;
  }
  .hero-content {
    margin: 0;
  }
  .hero-header {
    margin-bottom: 22px;
  }
  .companion-dock-wrap {
    padding: 0 12px 16px;
    height: clamp(460px, 72dvh, 660px);
    min-height: 440px;
    flex-shrink: 0;
  }
  .companion-dock {
    border-radius: 12px;
    border: 1px solid var(--border-card);
  }
  .feature-cards { grid-template-columns: minmax(0, 1fr); }
  .chat-workspace,
  .chat-workspace.inspector-open,
  .chat-workspace.sessions-collapsed,
  .chat-workspace.sessions-collapsed.inspector-open {
    grid-template-columns: minmax(0, 1fr);
  }
  .sessions-pane {
    position: fixed;
    inset: var(--topbar-h) auto 0 0;
    width: min(290px, 84vw);
    z-index: 42;
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    box-shadow: var(--shadow-dock);
  }
  .chat-workspace.sessions-collapsed .sessions-pane {
    border-right: 1px solid var(--border-subtle);
    overflow: visible;
  }
  .chat-workspace.sessions-open .sessions-pane { transform: none; }
  .thread-actions {
    opacity: 1;
    pointer-events: auto;
    gap: 4px;
  }
}

@media (max-width: 768px), (pointer: coarse) {
  .input,
  .input.compact,
  .composer-input,
  .thread-rename-input,
  .topbar-search-input,
  .admin-quota-input,
  .sandbox-textarea,
  .sandbox-gutter {
    font-size: 16px;
  }
}

@media (pointer: coarse), (max-width: 640px) {
  .btn.icon-btn {
    min-width: 36px;
    min-height: 36px;
    padding: 7px;
  }
  .btn.small {
    min-height: 32px;
    padding: 5px 10px;
  }
  .source-pill,
  .recent-chip,
  .suggest-chip {
    min-height: 30px;
    padding: 4px 10px;
  }
  .pending-image > button:not(.img-zoom-btn) {
    width: 26px;
    height: 26px;
    line-height: 26px;
    font-size: 14px;
    top: -8px;
    right: -8px;
  }
  .user-chip {
    min-width: 36px;
    min-height: 36px;
  }
}

@media (max-width: 640px) {
  :root {
    --topbar-h: 48px;
  }
  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
    gap: 6px;
  }
  .topbar-brand {
    gap: 7px;
  }
  .topbar-brand .wordmark {
    height: 16px;
  }
  .topbar-app-name {
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .topbar-search-wrap {
    display: none;
  }
  .mobile-search-btn {
    display: inline-flex;
  }
  .hero-stage::before {
    opacity: 0.45;
  }
  .suggest-menu {
    min-width: 0;
    width: 100%;
    max-height: min(44dvh, 280px);
  }
  .doc-viewer-toolbar {
    padding: 6px 10px;
    gap: 6px;
  }
  .doc-viewer-nav {
    flex-wrap: wrap;
    gap: 4px;
  }
  .doc-viewer-toolbar .btn.small {
    min-height: 30px;
    padding: 4px 8px;
  }
  .doc-viewer-meta {
    min-width: 0;
    flex: 1 1 80px;
  }
  .doc-viewer-path {
    display: none;
  }
  .chat-scroll.full-chat {
    padding: 14px 10px;
  }
  .msg-assistant-row {
    flex-direction: column;
    gap: 6px;
  }
  .msg-assistant-row > .robot-avatar {
    width: 24px;
    height: 24px;
  }
  .msg-assistant-col {
    width: 100%;
  }
  .sandbox-editor-body,
  .sandbox-textarea {
    min-height: 220px;
  }
  .sandbox-console-card {
    min-height: 180px;
  }
  .account-card {
    flex-wrap: wrap;
  }
  .kv {
    grid-template-columns: minmax(0, 1fr);
    gap: 3px;
  }
  .kv .k {
    margin-top: 6px;
    font-size: 12px;
  }
  .page-view {
    padding: 18px 14px max(28px, env(safe-area-inset-bottom));
  }
  .modal {
    padding: 16px;
  }
  .modal-head {
    top: -16px;
    margin: -16px -16px 0;
    padding: 12px 16px 10px;
  }
  .inline-form .field {
    flex: 1 1 120px;
    min-width: 0;
  }
  .inline-form .input,
  .inline-form .input-uses,
  .inline-form .input-hours,
  .inline-form .input.wide {
    width: 100%;
  }
  .inline-form > .btn {
    width: 100%;
  }
  .composer.full-composer {
    padding: 8px 10px max(10px, env(safe-area-inset-bottom));
  }
  .composer.full-composer .composer-row {
    padding: 7px 8px 7px 10px;
    border-radius: 13px;
    gap: 8px;
  }
  .composer.full-composer .composer-input {
    min-height: 40px;
    font-size: 16px;
    line-height: 1.45;
  }
  .composer.full-composer .attach-btn,
  .composer.full-composer .send-btn {
    width: 38px;
    height: 38px;
    border-radius: 9px;
  }
  .toast-stack {
    bottom: calc(76px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 520px) {
  .page-view .probe-search-row {
    flex-wrap: wrap;
  }
  .page-view .probe-search-row > .suggest-anchor,
  .page-view .probe-search-row > .input {
    flex: 1 1 100%;
  }
  .data-table.admin-users-table thead,
  .data-table.admin-invites-table thead {
    display: none;
  }
  .data-table.admin-users-table,
  .data-table.admin-users-table tbody,
  .data-table.admin-invites-table,
  .data-table.admin-invites-table tbody {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    width: 100%;
  }
  .data-table.admin-users-table tr,
  .data-table.admin-invites-table tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px 10px;
    padding: 10px 12px;
    border: 1px solid var(--border-card);
    border-radius: 8px;
    background: var(--bg-surface-2);
  }
  .data-table.admin-users-table td,
  .data-table.admin-invites-table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 0;
    border-bottom: 0;
    white-space: normal;
    overflow-wrap: anywhere;
    min-width: 0;
    text-align: left;
  }
  .data-table.admin-users-table td::before,
  .data-table.admin-invites-table td::before {
    content: attr(data-label);
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
  }
  .data-table.admin-users-table td.cell-primary,
  .data-table.admin-invites-table td.cell-primary {
    grid-column: 1 / -1;
    font-weight: 600;
    color: var(--text-primary);
    padding-bottom: 5px;
    border-bottom: 1px solid var(--border-subtle);
  }
  .data-table.admin-users-table td.cell-actions,
  .data-table.admin-invites-table td.cell-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
    padding-top: 6px;
    border-top: 1px solid var(--border-subtle);
  }
  .data-table.admin-users-table td.cell-actions::before,
  .data-table.admin-invites-table td.cell-actions::before {
    display: none;
  }
  .data-table.admin-users-table td.empty-cell,
  .data-table.admin-invites-table td.empty-cell {
    grid-column: 1 / -1;
    justify-content: center;
    padding: 10px 0;
  }
  .data-table.admin-users-table td.empty-cell::before,
  .data-table.admin-invites-table td.empty-cell::before {
    display: none;
  }
  .data-table.admin-users-table .admin-quota-input {
    width: 78px;
  }
}

@media (max-width: 480px) {
  .theme-cards,
  .quota-grid {
    grid-template-columns: 1fr;
  }
  .featured-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 420px) {
  .topbar-app-name,
  .brand-divider {
    display: none;
  }
}

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