/*
 * 小聆 · 控制台设计系统（/static/site.css）
 *
 * 定位：所有「控制台页面」（对话 / 盒子 / 记忆 / 人格 / 点歌 / 语音 / 调研）共用的
 * 外壳、设计令牌与组件样式。纯 CSS、零依赖：不引外部字体 / CSS / 图片。
 *
 * 依赖 style.css 的聊天基础样式（.bubble / .composer 等），本文件在其后加载，
 * 负责：调色板与令牌 → 侧栏外壳 → 通用组件 → 各页补充 → 响应式。
 *
 * 主题：默认跟随系统；<html data-theme="light|dark"> 手动覆盖（由 site.js 写入，
 * localStorage 键 linxi_theme）。调色板与 style.css 的 :root 同名同源，改色两边一起改。
 */

/* ==========================================================================
   1. 设计令牌（颜色 / 间距 / 圆角 / 阴影 / 字号）
   ========================================================================== */

:root {
  color-scheme: light;

  /* 颜色 · 浅色 */
  --bg: #f3f5f9;
  --bg-soft: #eef1f7;
  --surface: #ffffff;
  --surface-2: #f5f7fb;
  --surface-3: #eaeef5;
  --side-bg: #ffffff;
  --text: #182031;
  --text-soft: #4b5768;
  --muted: #7b8799;
  --border: #e3e8f0;
  --border-strong: #cfd7e3;
  --accent: #3568f0;
  --accent-2: #6b8dff;
  --accent-ink: #ffffff;
  --accent-soft: rgba(53, 104, 240, 0.1);
  --user-bg: #3568f0;
  --user-ink: #ffffff;
  --assistant-bg: #ffffff;
  --danger: #d0432a;
  --danger-soft: rgba(208, 67, 42, 0.1);
  --ok: #15935c;
  --ok-soft: rgba(21, 147, 92, 0.12);
  --warn: #b47a09;
  --warn-soft: rgba(180, 122, 9, 0.12);
  --info: #2f7fd1;
  --ring: rgba(53, 104, 240, 0.22);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 6px 20px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 18px 48px rgba(16, 24, 40, 0.14);
  --code-bg: #f2f5fa;

  /* 尺寸 */
  --nav-w: 208px;
  --stage-max: 1120px;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 20px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 22px;
  --space-6: 30px;

  /* 字号 */
  --fs-xs: 11.5px;
  --fs-sm: 12.5px;
  --fs-base: 14px;
  --fs-md: 15px;
  --fs-lg: 18px;
  --fs-xl: 22px;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Cascadia Mono", monospace;

  /* 由 app.js 的 visualViewport 监听覆盖；无 JS 时退回 100dvh */
  --app-height: 100dvh;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0c1017;
    --bg-soft: #0f141d;
    --surface: #141a24;
    --surface-2: #1a212d;
    --surface-3: #222b3a;
    --side-bg: #10151e;
    --text: #e8edf4;
    --text-soft: #b3bdcc;
    --muted: #8592a5;
    --border: #26303e;
    --border-strong: #354253;
    --accent: #6d97ff;
    --accent-2: #8fb1ff;
    --accent-ink: #0b1220;
    --accent-soft: rgba(109, 151, 255, 0.14);
    --user-bg: #3364e0;
    --user-ink: #ffffff;
    --assistant-bg: #161d28;
    --danger: #ff8168;
    --danger-soft: rgba(255, 129, 104, 0.14);
    --ok: #3fd394;
    --ok-soft: rgba(63, 211, 148, 0.14);
    --warn: #e8ad3d;
    --warn-soft: rgba(232, 173, 61, 0.14);
    --info: #6cb5ff;
    --ring: rgba(109, 151, 255, 0.3);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.42);
    --shadow-lg: 0 22px 56px rgba(0, 0, 0, 0.55);
    --code-bg: #0f151f;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c1017;
  --bg-soft: #0f141d;
  --surface: #141a24;
  --surface-2: #1a212d;
  --surface-3: #222b3a;
  --side-bg: #10151e;
  --text: #e8edf4;
  --text-soft: #b3bdcc;
  --muted: #8592a5;
  --border: #26303e;
  --border-strong: #354253;
  --accent: #6d97ff;
  --accent-2: #8fb1ff;
  --accent-ink: #0b1220;
  --accent-soft: rgba(109, 151, 255, 0.14);
  --user-bg: #3364e0;
  --user-ink: #ffffff;
  --assistant-bg: #161d28;
  --danger: #ff8168;
  --danger-soft: rgba(255, 129, 104, 0.14);
  --ok: #3fd394;
  --ok-soft: rgba(63, 211, 148, 0.14);
  --warn: #e8ad3d;
  --warn-soft: rgba(232, 173, 61, 0.14);
  --info: #6cb5ff;
  --ring: rgba(109, 151, 255, 0.3);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.42);
  --shadow-lg: 0 22px 56px rgba(0, 0, 0, 0.55);
  --code-bg: #0f151f;
}

/* 无 JS 时 [hidden] 兜底：author 样式会盖掉浏览器默认 display:none */
[hidden] {
  display: none !important;
}

/* ==========================================================================
   2. 控制台外壳：左侧栏（桌面） / 顶部横向条（窄屏） + 内容舞台
   ========================================================================== */

.shell {
  display: grid;
  grid-template-columns: var(--nav-w) minmax(0, 1fr);
  height: 100vh;
  height: var(--app-height, 100dvh);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ---------------- 左侧栏 ---------------- */
.side {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-height: 0;
  padding: 18px 12px calc(14px + env(safe-area-inset-bottom, 0px));
  padding-left: calc(12px + env(safe-area-inset-left, 0px));
  background: var(--side-bg);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.side-brand {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 2px 8px 6px;
  text-decoration: none;
  color: var(--text);
  border-radius: var(--radius-sm);
  -webkit-tap-highlight-color: transparent;
}

.side-brand:hover .brand-name {
  color: var(--accent);
}

.side-brand .brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 700;
  flex: 0 0 auto;
  box-shadow: 0 4px 14px var(--ring);
}

.side-brand .brand-name {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.side-brand-sub {
  flex: 1 1 100%;
  padding-left: 38px;
  color: var(--muted);
  font-size: var(--fs-xs);
  line-height: 1.4;
  white-space: nowrap;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1 1 auto;
}

.side-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  font-size: var(--fs-base);
  line-height: 1.4;
  text-decoration: none;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.side-link svg {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  opacity: 0.8;
}

.side-link:hover {
  color: var(--text);
  background: var(--surface-2);
}

.side-link.is-active {
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

.side-link.is-active svg {
  opacity: 1;
}

.side-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: var(--fs-xs);
}

.side-foot-text {
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-soft);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.theme-toggle:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.theme-toggle svg {
  width: 16px;
  height: 16px;
}

/* 三态主题图标：auto / light / dark，由 site.js 写 data-theme-mode 控制显示 */
.theme-toggle .theme-icon {
  display: none;
}

.theme-toggle[data-theme-mode="auto"] .theme-icon-auto,
.theme-toggle[data-theme-mode="light"] .theme-icon-light,
.theme-toggle[data-theme-mode="dark"] .theme-icon-dark {
  display: block;
}

/* ---------------- 内容舞台 ---------------- */
.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.stage-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
  padding: 16px calc(var(--space-5) + env(safe-area-inset-right, 0px)) 14px
    var(--space-5);
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.stage-head-main {
  flex: 1 1 280px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stage-title {
  margin: 0;
  color: var(--text);
  font-size: var(--fs-lg);
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: 0.2px;
}

.stage-desc {
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-sm);
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.stage-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex: 0 0 auto;
}

.stage-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: var(--space-5) calc(var(--space-5) + env(safe-area-inset-right, 0px))
    calc(32px + env(safe-area-inset-bottom, 0px)) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* 对话页：消息区 + 底部输入框，自己管滚动 */
.stage-body.is-chat {
  padding: 0;
  gap: 0;
  overflow: hidden;
}

/* 语音页：状态区固定 + 记录区自己滚 */
.stage-body.is-voice {
  padding: 0;
  gap: 0;
  overflow: hidden;
}

/* 盒子页：日志卡撑满剩余高度，日志内部滚 */
.stage-body.is-device {
  gap: 12px;
  overflow: hidden;
}

/* 页面内容容器：只负责排布，不再自己滚动（滚动交给 .stage-body） */
.page-main {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  width: 100%;
  max-width: var(--stage-max);
  margin: 0 auto;
}

.page-main.is-fill {
  flex: 1 1 auto;
}

.page-head {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 0 2px;
}

.page-head .page-title {
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: 700;
  line-height: 1.4;
}

.page-desc {
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-sm);
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.page-badge {
  color: var(--muted);
  font-size: var(--fs-xs);
  white-space: nowrap;
}

/* ==========================================================================
   3. 登录页（/login，v0.33 后台密码）
   ========================================================================== */

.login-body {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6) var(--space-4);
  background: var(--bg);
  color: var(--text);
}

.login-shell {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-lg);
  font-weight: 700;
}

.login-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
}

.login-title {
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: 700;
}

.login-desc {
  margin: 0 0 var(--space-3);
  color: var(--muted);
  font-size: var(--fs-sm);
  line-height: 1.6;
}

.login-desc code {
  padding: 1px 4px;
  border-radius: 4px;
  background: var(--code-bg);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
}

.login-label {
  color: var(--text-soft);
  font-size: var(--fs-sm);
  font-weight: 600;
}

.login-input {
  width: 100%;
}

.login-status {
  min-height: 18px;
}

.login-submit {
  width: 100%;
  justify-content: center;
}

.login-foot {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: var(--fs-xs);
}

/* 侧栏底部的退出登录：与主题按钮同一行，不抢视觉。 */
.side-logout {
  margin-left: auto;
}

/* ==========================================================================
   4. 状态：状态行 / 状态胶囊 / 连接指示
   ========================================================================== */

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 0 2px;
}

.status-line {
  flex: 1 1 auto;
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-sm);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.status-line:empty {
  display: none;
}

.status-line::before {
  content: "";
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  margin-top: 0.45em;
  border-radius: 50%;
  background: var(--muted);
  transition: background-color 0.2s ease;
}

.status-line[data-state="busy"]::before {
  background: var(--accent);
}

.status-line[data-state="busy"] {
  color: var(--text-soft);
}

.status-line[data-state="ok"]::before {
  background: var(--ok);
}

.status-line[data-state="warn"]::before {
  background: var(--warn);
}

.status-line[data-state="warn"] {
  color: var(--warn);
}

.status-line[data-state="error"]::before {
  background: var(--danger);
}

.status-line[data-state="error"] {
  color: var(--danger);
}

/* 顶部状态胶囊：连接 / 实时 / 在线状态（site.js Linxi.statusPill 写入 data-state） */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: var(--fs-sm);
  line-height: 1.4;
  white-space: nowrap;
}

.pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.5;
  flex: 0 0 auto;
}

.pill[data-state="ok"],
.pill[data-state="connected"],
.pill[data-state="online"] {
  color: var(--ok);
  border-color: var(--ok);
  background: var(--ok-soft);
}

.pill[data-state="ok"]::before,
.pill[data-state="connected"]::before,
.pill[data-state="online"]::before {
  opacity: 1;
  box-shadow: 0 0 0 3px var(--ok-soft);
}

.pill[data-state="busy"],
.pill[data-state="reconnecting"] {
  color: var(--warn);
  border-color: var(--warn);
  background: var(--warn-soft);
}

.pill[data-state="busy"]::before,
.pill[data-state="reconnecting"]::before {
  opacity: 1;
  animation: pill-pulse 1.4s ease-in-out infinite;
}

.pill[data-state="error"],
.pill[data-state="offline"] {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--danger-soft);
}

.pill[data-state="error"]::before,
.pill[data-state="offline"]::before {
  opacity: 1;
}

@keyframes pill-pulse {
  0%,
  100% {
    opacity: 0.35;
  }
  50% {
    opacity: 1;
  }
}

/* 兼容旧聊天页的 .conn 结构（纯前端连接判断） */
.conn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: var(--fs-sm);
  color: var(--muted);
  white-space: nowrap;
}

.conn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  flex: 0 0 auto;
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.conn[data-state="online"] .conn-dot {
  background: var(--ok);
  box-shadow: 0 0 0 3px var(--ok-soft);
}

.conn[data-state="offline"] .conn-dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

/* ==========================================================================
   5. 按钮
   ========================================================================== */

.btn {
  min-height: 38px;
  min-width: 0;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: var(--fs-base);
  font-weight: 600;
  line-height: 1.4;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
  transition: opacity 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-primary:not(:disabled):hover {
  filter: brightness(1.06);
}

.btn-ghost {
  background: var(--surface-2);
  color: var(--text-soft);
  border-color: var(--border);
}

.btn-ghost:not(:disabled):hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: #ffffff;
}

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}

.btn-sm {
  min-height: 32px;
  padding: 0 11px;
  border-radius: 9px;
  font-size: var(--fs-sm);
}

.btn.is-confirm {
  background: var(--danger);
  color: #ffffff;
  border-color: var(--danger);
}

.btn:focus-visible,
.side-link:focus-visible,
.seg-btn:focus-visible,
.theme-toggle:focus-visible,
.chip-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-link {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: inherit;
  cursor: pointer;
  text-decoration: underline;
}

/* 发送 / 停止（style.css 里也有，这里是新令牌下的补充） */
.btn-send {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-stop {
  background: var(--surface-2);
  color: var(--danger);
  border-color: var(--border);
}

/* ==========================================================================
   6. 工具栏 / 分段控件 / 分类 chip
   ========================================================================== */

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-left: auto;
}

.seg {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.seg-btn {
  padding: 5px 11px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-soft);
  font-size: var(--fs-sm);
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.seg-btn.is-active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow);
}

[data-theme="dark"] .seg-btn.is-active {
  background: var(--surface-3);
}

/* 分类多选 chip（盒子页）：并集筛选，aria-pressed 表达状态 */
.chip-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.chip-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-soft);
  font-size: var(--fs-sm);
  line-height: 1.4;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.chip-toggle:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.chip-toggle[aria-pressed="true"] {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
  font-weight: 600;
}

.chip-toggle .chip-count {
  color: var(--muted);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   7. 表单
   ========================================================================== */

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  color: var(--text-soft);
  font-size: var(--fs-sm);
}

/* 行内字段（标签 + 控件）：不参与压缩，工具栏空间不够时整组换行，
   否则窄屏会把「日志」「行数」这类两字标签挤成竖排。 */
.field-inline {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 6px;
  color: var(--text-soft);
  font-size: var(--fs-sm);
  white-space: nowrap;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-base);
  line-height: 1.5;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-select {
  width: auto;
  min-width: 96px;
}

.form-textarea {
  min-height: 62px;
  resize: vertical;
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--muted);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.form-error {
  margin: 0;
  color: var(--danger);
  font-size: var(--fs-sm);
  overflow-wrap: anywhere;
}

.form-error:empty {
  display: none;
}

.search-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-row .form-input {
  flex: 1 1 160px;
  width: auto;
  min-width: 0;
}

.search-row .btn {
  flex: 0 0 auto;
}

/* ==========================================================================
   8. 卡片 / 徽标 / 空状态 / 骨架
   ========================================================================== */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.card-head .card-title {
  flex: 1 1 auto;
  margin: 0;
}

.card-title {
  margin: 0 0 8px;
  color: var(--text);
  font-size: var(--fs-md);
  font-weight: 650;
  line-height: 1.45;
}

.card-text {
  margin: 0;
  color: var(--text-soft);
  font-size: var(--fs-base);
  line-height: 1.65;
}

.card-head-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-soft);
  font-size: var(--fs-xs);
  white-space: nowrap;
}

.badge-ok {
  border-color: var(--ok);
  color: var(--ok);
}

.badge-warn {
  border-color: var(--warn);
  color: var(--warn);
}

.badge-danger {
  border-color: var(--danger);
  color: var(--danger);
}

.empty-note {
  margin: 0;
  padding: 22px 14px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: var(--fs-base);
  line-height: 1.7;
  text-align: center;
  overflow-wrap: anywhere;
}

.empty-note:empty {
  display: none;
}

/* 空状态（对话页 / 列表页通用） */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: auto;
  padding: 26px 18px;
  max-width: 40ch;
  text-align: center;
  color: var(--muted);
  font-size: var(--fs-base);
  line-height: 1.7;
}

.empty-state-title {
  margin: 0;
  color: var(--text-soft);
  font-size: var(--fs-md);
  font-weight: 650;
}

.empty-state-desc {
  margin: 0;
}

/* 骨架屏：接口未就绪 / 数据加载中 */
.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(
    90deg,
    var(--surface-2) 0%,
    var(--surface-3) 40%,
    var(--surface-2) 80%
  );
  background-size: 220% 100%;
  animation: skeleton-sweep 1.4s ease-in-out infinite;
}

.skeleton-line {
  height: 12px;
  margin: 8px 0;
}

.skeleton-line.w-60 {
  width: 60%;
}

.skeleton-line.w-40 {
  width: 40%;
}

@keyframes skeleton-sweep {
  0% {
    background-position: 130% 0;
  }
  100% {
    background-position: -80% 0;
  }
}

/* 页面级提示条（接口未就绪 / 降级提醒） */
.banner {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-soft);
  font-size: var(--fs-sm);
  line-height: 1.6;
}

.banner[data-kind="warn"] {
  border-color: var(--warn);
  background: var(--warn-soft);
  color: var(--warn);
}

.banner[data-kind="error"] {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
}

.banner[data-kind="ok"] {
  border-color: var(--ok);
  background: var(--ok-soft);
  color: var(--ok);
}

/* ==========================================================================
   9. 通用工具类 / 状态卡
   ========================================================================== */

.muted {
  color: var(--muted);
}

.small {
  font-size: var(--fs-sm);
}

.wrap-anywhere {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* 统计卡：盒子页 / 概览用 */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.stat-label {
  color: var(--muted);
  font-size: var(--fs-xs);
}

.stat-value {
  color: var(--text);
  font-size: var(--fs-md);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.stat-value.is-ok {
  color: var(--ok);
}

.stat-value.is-warn {
  color: var(--warn);
}

.stat-value.is-bad {
  color: var(--danger);
}

.stat-sub {
  color: var(--muted);
  font-size: var(--fs-xs);
  line-height: 1.5;
}

.kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

.kv {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.kv-label {
  color: var(--muted);
  font-size: var(--fs-xs);
}

.kv-value {
  color: var(--text);
  font-size: var(--fs-sm);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  padding: 2px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-soft);
  font-size: var(--fs-sm);
  overflow-wrap: anywhere;
}

/* ==========================================================================
   10. 记忆页
   ========================================================================== */

.list-head {
  padding: 0 2px;
  color: var(--muted);
  font-size: var(--fs-sm);
}

.group-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.fact-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fact-group-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 0 2px;
}

.fact-group-title {
  margin: 0;
  color: var(--text-soft);
  font-size: var(--fs-sm);
  font-weight: 650;
}

.fact-group-count {
  color: var(--muted);
  font-size: var(--fs-xs);
}

.fact {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.fact[data-status="archived"] {
  border-style: dashed;
  opacity: 0.88;
}

.fact[data-status="deleted"] {
  border-style: dashed;
  opacity: 0.75;
}

.fact-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: var(--fs-sm);
}

.fact-subject {
  color: var(--text-soft);
  font-weight: 650;
}

.fact-sep {
  color: var(--muted);
}

.fact-key {
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text-soft);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  overflow-wrap: anywhere;
}

.fact-value {
  color: var(--text);
  font-size: var(--fs-md);
  line-height: 1.6;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.fact-value.is-empty {
  color: var(--muted);
  font-size: var(--fs-sm);
}

.fact-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: var(--fs-xs);
  line-height: 1.7;
}

.fact-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.fact-error {
  margin: 0;
  color: var(--danger);
  font-size: var(--fs-sm);
  overflow-wrap: anywhere;
}

.fact-editor {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.fact-editor-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.versions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}

.versions-hint {
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-sm);
}

.versions-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.version-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.version-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: var(--fs-xs);
}

.version-diff {
  color: var(--text-soft);
  font-size: var(--fs-sm);
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.version-diff .version-old {
  color: var(--muted);
  text-decoration: line-through;
}

.version-diff .version-arrow {
  margin: 0 4px;
  color: var(--muted);
}

.version-diff .version-new {
  color: var(--text);
}

.version-actions {
  display: flex;
  justify-content: flex-end;
}

/* ==========================================================================
   11. 人格页
   ========================================================================== */

.persona-hero {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.persona-affection {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.persona-affection-value {
  color: var(--accent);
  font-size: 34px;
  font-weight: 750;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.persona-affection-label {
  color: var(--muted);
  font-size: var(--fs-sm);
}

.level-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.level-seg {
  position: relative;
  overflow: hidden;
  padding: 6px 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  text-align: center;
}

.level-seg-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 0;
  background: var(--accent);
  opacity: 0.22;
  transition: width 0.3s ease;
}

.level-seg.is-done .level-seg-fill {
  width: 100%;
}

.level-seg-label {
  position: relative;
  color: var(--text-soft);
  font-size: var(--fs-xs);
  line-height: 1.5;
  white-space: nowrap;
}

.level-seg.is-done .level-seg-label,
.level-seg.is-current .level-seg-label {
  color: var(--accent);
  font-weight: 650;
}

.level-caption {
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-xs);
  line-height: 1.6;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.history-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  color: var(--muted);
  font-size: var(--fs-xs);
}

.history-field {
  color: var(--text-soft);
  font-size: var(--fs-sm);
  font-weight: 650;
}

.history-diff {
  color: var(--text-soft);
  font-size: var(--fs-sm);
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.history-diff .history-old {
  color: var(--muted);
  text-decoration: line-through;
}

.history-diff .history-arrow {
  margin: 0 4px;
  color: var(--muted);
}

.history-diff .history-new {
  color: var(--text);
}

.history-reason {
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-sm);
  line-height: 1.55;
  overflow-wrap: anywhere;
}

/* AI 提示词编辑卡（v0.17 persona.js） */
.prompt-card .page-desc {
  margin: 0;
}

.prompt-textarea {
  min-height: 190px;
  font-size: var(--fs-sm);
  line-height: 1.7;
  tab-size: 2;
}

.prompt-card .status-line {
  margin: 0;
}

.prompt-card .form-actions {
  margin-top: 2px;
}

/* ==========================================================================
   12. 点歌页
   ========================================================================== */

.player-card {
  position: sticky;
  top: 4px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface);
}

.now-playing {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.now-title {
  color: var(--text);
  font-size: var(--fs-md);
  font-weight: 700;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.now-title.is-idle {
  color: var(--muted);
  font-size: var(--fs-base);
  font-weight: 500;
}

.now-artists {
  color: var(--muted);
  font-size: var(--fs-sm);
  overflow-wrap: anywhere;
}

.now-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: var(--fs-xs);
}

.player-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.player-time {
  margin-left: auto;
  color: var(--muted);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.player-progress {
  width: 100%;
  height: 6px;
  accent-color: var(--accent);
}

.volume-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: var(--fs-sm);
}

.volume-row input[type="range"] {
  flex: 1 1 auto;
  max-width: 200px;
  height: 22px;
  accent-color: var(--accent);
}

.volume-value {
  min-width: 40px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.audio-hidden {
  display: none;
}

.song-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.song-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.song-item.is-current {
  border-color: var(--accent);
}

.song-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.song-name {
  color: var(--text);
  font-size: var(--fs-base);
  font-weight: 600;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.song-sub {
  color: var(--muted);
  font-size: var(--fs-xs);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.song-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
}

.song-duration {
  color: var(--muted);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.login-card .card-head {
  align-items: center;
}

.qr-box {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.qr-img {
  width: 220px;
  height: 220px;
  display: block;
  border-radius: var(--radius-sm);
  background: #fff;
  padding: 8px;
  box-sizing: content-box;
  border: 1px solid var(--border);
}

.manual-login {
  margin-top: 12px;
  color: var(--muted);
  font-size: var(--fs-sm);
}

.manual-login summary {
  cursor: pointer;
  user-select: none;
}

.cookie-input {
  margin-top: 8px;
  width: 100%;
  resize: vertical;
  font-family: inherit;
  font-size: var(--fs-sm);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.cookie-actions {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ==========================================================================
   13. 调研报告页
   ========================================================================== */

.research-link {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  overflow-wrap: anywhere;
}

.research-link:hover {
  border-bottom-color: currentColor;
}

.research-report {
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: var(--fs-base);
  line-height: 1.75;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  tab-size: 2;
}

.research-sources {
  margin: 8px 0 0;
  padding-left: 20px;
  display: grid;
  gap: 6px;
  overflow-wrap: anywhere;
}

.research-sources a {
  color: var(--accent);
}

.research-source-site {
  color: var(--muted);
  font-size: var(--fs-xs);
}

#research-report a,
#research-sources a {
  overflow-wrap: anywhere;
}

/* ==========================================================================
   14. 对话页（覆盖 style.css 的聊天样式，统一到控制台外观）
   ========================================================================== */

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 18px 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: var(--stage-max);
  margin: 0 auto;
}

/*
 * 消息少时贴底显示，多到需要滚动时不影响从顶部滚起：
 * 伪元素作为第一个 flex 子项吃掉多余空间；overflow 时它的 margin-top:auto 自动归零。
 */
.messages::before {
  content: "";
  flex: 0 0 auto;
  margin-top: auto;
}

.msg-body {
  max-width: min(88%, 620px);
}

.bubble {
  border-radius: 15px;
  font-size: var(--fs-md);
  line-height: 1.65;
}

.bubble-assistant {
  background: var(--assistant-bg);
  border-color: var(--border);
}

.composer {
  flex: 0 0 auto;
  width: 100%;
  max-width: var(--stage-max);
  margin: 0 auto;
  padding: 8px 18px calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.composer-inner {
  align-items: flex-end;
}

.input {
  border-radius: 13px;
  background: var(--surface-2);
}

.composer-hint {
  margin: 5px 2px 0;
  color: var(--muted);
  font-size: var(--fs-xs);
  text-align: center;
  user-select: none;
}

/* 「正在听…」实时文本（盒子 / 网页语音识别中的提示，放在输入框上方） */
.listening-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: var(--stage-max);
  margin: 0 auto;
  padding: 6px 18px 0;
  color: var(--accent);
  font-size: var(--fs-sm);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.listening-hint[hidden] {
  display: none;
}

.listening-hint::before {
  content: "";
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pill-pulse 1.2s ease-in-out infinite;
}

/* 对话气泡下方的元信息：来源标记 / 时间 / 首字延迟 / token */
.turn-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 5px;
  padding: 0 3px;
  color: var(--muted);
  font-size: var(--fs-xs);
  line-height: 1.5;
}

.turn-source {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-soft);
  font-size: var(--fs-xs);
  white-space: nowrap;
}

.turn-source[data-source="device"] {
  border-color: var(--ok);
  color: var(--ok);
}

.turn-source[data-source="voice"] {
  border-color: var(--info);
  color: var(--info);
}

.turn-source[data-source="text"] {
  border-color: var(--accent);
  color: var(--accent);
}

.turn-meta-sep {
  color: var(--border-strong);
}

/* 历史消息的轻量时间戳 */
.msg-time {
  margin-top: 4px;
  padding: 0 3px;
  color: var(--muted);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   15. 响应式
   --------------------------------------------------------------------------
   断点：959（平板竖屏 / 侧栏变顶栏）、560（手机）、420（小屏手机）。
   手机端目标：
   - 不出现横向滚动；长路径 / SHA 允许任意折行；
   - 触控目标 ≥ 36px；输入框 16px 字号（否则 iOS 聚焦会放大整页）；
   - 导航单行横滑、隐藏分组标题，当前项由 site.js 自动滚进可视区；
   - 顶栏「标题」和「状态/动作」各占一行，动作可以换行，不再被裁掉。
   ========================================================================== */

@media (max-width: 959px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }

  .side {
    flex-direction: row;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    padding-top: calc(8px + env(safe-area-inset-top, 0px));
    padding-left: calc(10px + env(safe-area-inset-left, 0px));
    border-right: 0;
    border-bottom: 1px solid var(--border);
    overflow: visible;
  }

  .side-brand {
    flex: 0 0 auto;
    padding: 0;
    gap: 6px;
  }

  .side-brand .brand-mark {
    width: 26px;
    height: 26px;
    border-radius: 8px;
    font-size: 13px;
  }

  .side-brand .brand-name {
    font-size: 15px;
  }

  .side-brand-sub {
    display: none;
  }

  /* 横向导航条里分组标题没有位置，继续显示会被 flex 挤成竖排（曾出现「设\n备」） */
  .side-nav-label {
    display: none;
  }

  .side-nav {
    flex-direction: row;
    flex: 1 1 auto;
    min-width: 0;
    gap: 2px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .side-nav::-webkit-scrollbar {
    display: none;
  }

  .side-link {
    flex: 0 0 auto;
    gap: 6px;
    padding: 7px 10px;
    min-height: 40px;
    font-size: var(--fs-sm);
  }

  .side-link svg {
    width: 16px;
    height: 16px;
  }

  .side-foot {
    flex: 0 0 auto;
    gap: 4px;
    padding: 0;
    border-top: 0;
  }

  .side-foot-text {
    display: none;
  }

  .side-logout {
    margin-left: 0;
  }

  .stage-head {
    padding: 12px 14px 10px;
    gap: 8px 10px;
  }

  /* 标题独占一行，状态/动作换行铺满：长状态胶囊（如「日志：实时事件已连接」）不再被裁掉 */
  .stage-head-main {
    flex: 1 1 100%;
  }

  .stage-actions {
    flex: 1 1 100%;
    min-width: 0;
  }

  .stage-title {
    font-size: var(--fs-md);
  }

  .stage-desc {
    display: none;
  }

  .stage-body {
    padding: 14px 12px calc(26px + env(safe-area-inset-bottom, 0px));
    gap: 10px;
  }

  .stage-body.is-chat,
  .stage-body.is-voice {
    padding: 0;
    gap: 0;
  }

  .messages {
    padding: 12px 12px 8px;
  }

  .composer {
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
  }

  .listening-hint {
    padding: 6px 14px 0;
  }

  .player-card {
    position: static;
  }

  /* 设备条：手机上一行放得下「状态 + 摘要 + 打开」，左右留白收紧 */
  .device-strip {
    padding: 6px 12px;
    padding-left: calc(12px + env(safe-area-inset-left, 0px));
    padding-right: calc(12px + env(safe-area-inset-right, 0px));
    gap: 6px;
  }

  .toast-host {
    bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px));
    left: var(--space-4);
    right: var(--space-4);
    max-width: none;
    align-items: flex-end;
  }
}

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

  .toolbar-actions {
    margin-left: 0;
  }

  .card {
    padding: 12px;
    border-radius: 14px;
  }

  .card-head {
    flex-wrap: wrap;
    row-gap: 8px;
  }

  /* 触控友好：手机上的主要动作不低于 40px（分段/胶囊不低于 32px） */
  .btn {
    min-height: 40px;
  }

  .btn-sm {
    min-height: 36px;
  }

  .seg-btn {
    min-height: 32px;
    padding: 6px 10px;
  }

  .chip-toggle {
    min-height: 32px;
  }

  .side-link {
    min-height: 38px;
  }

  /* iOS 对 <16px 的输入框会在聚焦时放大整页；手机端统一到 16px */
  .form-input,
  .form-select,
  .form-textarea {
    font-size: 16px;
  }

  /* 搜索行在手机上可以换行，按钮保持自身宽度（不再被拉成整条蓝色横条） */
  .search-row {
    flex-wrap: wrap;
  }

  .search-row .form-input {
    flex: 1 1 160px;
  }

  .search-row .btn {
    flex: 0 0 auto;
  }

  /* 带多个按钮的行（如「导入歌单 / 导入红心」）在手机上把输入框单独放一行 */
  .search-row.is-stack {
    justify-content: flex-end;
  }

  .search-row.is-stack .form-input {
    flex: 1 1 100%;
  }

  .form-actions {
    flex-wrap: wrap;
  }

  .stage-actions {
    gap: 6px;
  }

  .persona-affection-value {
    font-size: 30px;
  }

  .song-item {
    align-items: flex-start;
  }

  .song-actions {
    align-self: center;
  }

  /* 手机键盘没有 Shift+Enter，这行提示只占高度 */
  .composer-hint {
    display: none;
  }

  .msg-body {
    max-width: 100%;
  }

  /* 登录页：手机上靠上排，避免键盘弹出时上下跳 */
  .login-body {
    align-items: flex-start;
    padding: max(32px, 9vh) var(--space-4) var(--space-6);
  }
}

@media (max-width: 480px) {
  /* 390 宽：品牌只留图标，导航横滑，标点不换行也不截断 */
  .side {
    gap: 4px;
    padding: 7px 8px;
    padding-top: calc(7px + env(safe-area-inset-top, 0px));
    padding-left: calc(8px + env(safe-area-inset-left, 0px));
  }

  .side-brand {
    gap: 0;
  }

  .side-brand .brand-mark {
    width: 24px;
    height: 24px;
    border-radius: 7px;
    font-size: 12px;
  }

  .side-brand .brand-name {
    display: none;
  }

  .side-nav {
    gap: 0;
    min-width: 0;
    padding-right: 2px;
  }

  .side-link {
    gap: 4px;
    padding: 6px 7px;
    font-size: 11.5px;
  }

  .side-link svg {
    width: 15px;
    height: 15px;
  }

  .theme-toggle {
    width: 28px;
    height: 28px;
  }

  .side-logout {
    padding: 0 9px;
    font-size: var(--fs-xs);
  }

  /* 状态胶囊字号收紧，让「网页/盒子 + 在线 + 新对话」尽量排在一行 */
  .stage-actions .pill {
    font-size: var(--fs-xs);
    padding: 4px 9px;
  }
}

@media (max-width: 380px) {
  .brand-name {
    font-size: 15px;
  }

  .side-logout {
    padding: 0 7px;
  }
}

/* ==========================================================================
   16. 动效偏好 / 无 JS 提示
   ========================================================================== */

.noscript {
  margin: 0;
  padding: 16px;
  text-align: center;
  color: var(--danger);
  font-size: var(--fs-base);
}

@media (prefers-reduced-motion: reduce) {
  .level-seg-fill,
  .status-line::before,
  .pill::before,
  .listening-hint::before,
  .skeleton {
    animation: none !important;
    transition: none !important;
  }
}

/* ==========================================================================
   17. 导航分组（v0.34：导航由 site.js 单一来源渲染）
   ========================================================================== */

.side-nav-label {
  display: block;
  margin: var(--space-3) 0 var(--space-1);
  padding: 0 var(--space-2);
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
}

.side-nav-label:first-child {
  margin-top: 0;
}

.side-icon {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
}

/* 图标仍由 .side-link svg 控制尺寸，这里只包一层，避免后续换图标时改结构。 */

/* ==========================================================================
   18. 设备条（全站一行，点击进盒子页）
   ========================================================================== */

.device-strip {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: var(--space-2);
  padding: 6px var(--space-5);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-soft);
  font-size: var(--fs-sm);
  text-decoration: none;
  cursor: pointer;
}

.device-strip:hover {
  background: var(--surface-3);
}

.device-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--muted);
}

.device-dot[data-state="idle"] {
  background: var(--ok);
}

.device-dot[data-state="playing"],
.device-dot[data-state="talking"] {
  background: var(--info);
}

.device-dot[data-state="offline"] {
  background: var(--muted);
}

.device-dot[data-state="error"] {
  background: var(--danger);
}

.device-text {
  flex: 0 0 auto;
  color: var(--text);
  font-weight: 600;
}

.device-summary {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--muted);
}

.device-summary[hidden] {
  display: none;
}

.device-go {
  flex: 0 0 auto;
  color: var(--accent);
  font-size: var(--fs-xs);
}

/* ==========================================================================
   19. 轻提示（toast）
   ========================================================================== */

.toast-host {
  position: fixed;
  right: var(--space-4);
  bottom: var(--space-4);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-width: min(360px, calc(100vw - 2 * var(--space-4)));
  pointer-events: none;
}

.toast {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  color: var(--text);
  font-size: var(--fs-sm);
  line-height: 1.5;
  overflow-wrap: anywhere;
  animation: toast-in 0.16s ease-out;
}

.toast[data-kind="ok"] {
  border-left-color: var(--ok);
}

.toast[data-kind="error"] {
  border-left-color: var(--danger);
}

.toast[data-kind="warn"] {
  border-left-color: var(--warn);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ==========================================================================
   20. 播放器：输出说明（点歌页 / 盒子页共用组件）
   ========================================================================== */

.player-output {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  padding-top: var(--space-2);
  border-top: 1px dashed var(--border);
}

.player-output .btn-link {
  padding: 0;
  font-size: var(--fs-xs);
}

/* ==========================================================================
   21. 对话页排版收敛（v0.34）
   ========================================================================== */

/* 助手列比原来宽一点：长回答按 620px 折行太碎；窄屏仍按百分比收。 */
.msg-body {
  max-width: min(92%, 760px);
}

/* 工具调用从「竖排灰字」改成一行小标签：一屏能扫完，不再像代码块。 */
.tool-list {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 7px;
}

.tool-item {
  padding: 1px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  font-size: var(--fs-xs);
  line-height: 1.6;
  color: var(--text-soft);
}

.tool-item[data-status="done"] {
  color: var(--muted);
}

.tool-item[data-status="error"] {
  border-color: var(--danger);
}

/* 引用：默认收进一个折叠块，展开后双列排，避免把回答挤成一长条链接表。 */
.citation-box {
  max-width: 100%;
  padding: 6px 10px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.citation-summary {
  cursor: pointer;
  color: var(--text-soft);
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 1.6;
  list-style-position: inside;
}

.citation-box .citation-list {
  margin: 6px 0 0;
  padding-left: 1.4em;
  font-size: var(--fs-xs);
  line-height: 1.6;
}

@media (min-width: 960px) {
  .citation-box .citation-list {
    columns: 2;
    column-gap: 24px;
  }

  .citation-box .citation-item {
    break-inside: avoid;
  }
}

/* ==========================================================================
   22. 弹层（sheet）与歌曲行补充（v0.45）
   --------------------------------------------------------------------------
   点歌页的「加入歌单」「歌曲更多操作」用自绘弹层：手机底部抽屉、桌面居中面板。
   ========================================================================== */

body.sheet-open {
  overflow: hidden;
}

.sheet-host {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.sheet-overlay {
  position: absolute;
  inset: 0;
  background: rgba(12, 16, 23, 0.45);
  animation: sheet-fade 0.14s ease-out;
}

.sheet-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  width: min(440px, 100%);
  max-height: min(82vh, 660px);
  overflow: auto;
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: sheet-in 0.16s ease-out;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.sheet-title {
  margin: 0;
  color: var(--text);
  font-size: var(--fs-md);
  font-weight: 650;
  line-height: 1.4;
}

.sheet-desc {
  margin: 0;
  color: var(--muted);
  font-size: var(--fs-sm);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.sheet-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.sheet-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sheet-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: var(--fs-base);
  text-align: left;
  cursor: pointer;
}

.sheet-item:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.sheet-item:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 1px;
}

.sheet-item.is-danger {
  color: var(--danger);
}

.sheet-item[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

.sheet-item-name {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.sheet-item-meta {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: var(--fs-xs);
}

.sheet-field {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.sheet-field .form-input {
  flex: 1 1 auto;
  min-width: 0;
}

/* 按钮不参与压缩：否则手机上「新建并加入」会被挤掉半个字 */
.sheet-field .btn {
  flex: 0 0 auto;
}

.sheet-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
}

@keyframes sheet-fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes sheet-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes sheet-up {
  from {
    transform: translateY(20%);
  }
  to {
    transform: none;
  }
}

/* 歌曲行：可选勾选、行内按钮不换行挤压、播放器下的当前歌动作 */
.song-check {
  display: inline-flex;
  align-items: center;
  padding: 2px 2px 2px 0;
}

.song-check input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.song-actions .btn {
  white-space: nowrap;
}

.upnext-note {
  color: var(--muted);
  font-size: var(--fs-xs);
}

.playlist-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin: 0 0 var(--space-3);
}

.playlist-toolbar .toolbar-actions {
  margin-left: auto;
}

.check-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-soft);
  font-size: var(--fs-sm);
}

.check-inline input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.voice-hint {
  margin: var(--space-3) 0 0;
  color: var(--muted);
  font-size: var(--fs-xs);
  line-height: 1.6;
}

/* 最近搜过：.chip 原本只用于 span，做成按钮后补交互外观 */
button.chip {
  font-family: inherit;
  cursor: pointer;
}

button.chip:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.sheet-list .empty-note {
  margin: 0;
}

.now-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 0;
}

.card-details > summary {
  cursor: pointer;
  color: var(--text);
  font-size: var(--fs-md);
  font-weight: 600;
  list-style: none;
}

.card-details > summary::-webkit-details-marker {
  display: none;
}

.card-details > summary::after {
  content: "展开";
  float: right;
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 400;
}

.card-details[open] > summary::after {
  content: "收起";
}

.card-details-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-top: var(--space-3);
}

/* 手机：底部抽屉，拇指够得到；歌曲行按钮允许换行，不挤成一列字 */
@media (max-width: 560px) {
  .sheet-host {
    align-items: flex-end;
    padding: 0;
  }

  .sheet-panel {
    width: 100%;
    max-height: 84vh;
    border-radius: var(--radius) var(--radius) 0 0;
    border-bottom: 0;
    padding-bottom: max(var(--space-4), env(safe-area-inset-bottom));
    animation: sheet-up 0.18s ease-out;
  }

  /* 歌曲行在手机上改两行：标题占一行，三个动作排到下一行右对齐，
     否则「播放 / ＋歌单 / ···」会把标题挤成两三个字一行。 */
  .song-item {
    flex-wrap: wrap;
    row-gap: 6px;
  }

  .song-main {
    flex: 1 1 auto;
  }

  .song-actions {
    flex: 0 0 100%;
    flex-wrap: wrap;
    justify-content: flex-end;
    max-width: none;
  }

  .song-actions .btn {
    padding: 6px 9px;
  }

  .playlist-toolbar .toolbar-actions {
    width: 100%;
    margin-left: 0;
  }

  .playlist-toolbar .toolbar-actions .btn {
    flex: 1 1 auto;
  }
}

/* ==========================================================================
   23. 窄屏收尾覆盖（必须放在文件末尾）
   --------------------------------------------------------------------------
   .side-nav-label 的基础样式在第 17 节，位置在本文件「响应式」之后；
   同优先级下后者胜出，所以窄屏隐藏分组标题只能写在这里。
   ========================================================================== */

@media (max-width: 959px) {
  .side-nav-label {
    display: none;
  }
}