/* ============================================================================
   AI 数字人控制面 · 视觉系统
   暗色为主、极光点缀；浅色为等价的干净版本。单一来源：CSS 变量。
   ========================================================================== */

:root {
  --radius-xs: 8px;
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --radius-xl: 28px;

  --font: "Inter", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, Consolas, monospace;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dur: 220ms;

  --rail: 250px;
  --maxw: 1320px;
}

/* ------------------------------------------------------------------ 暗色 */
html[data-theme="dark"] {
  --bg: #07090f;
  --bg-2: #0b0e18;
  --bg-3: #101423;
  --panel: rgba(255, 255, 255, 0.042);
  --panel-2: rgba(255, 255, 255, 0.07);
  --panel-solid: #12172a;
  --line: rgba(255, 255, 255, 0.085);
  --line-2: rgba(255, 255, 255, 0.16);
  --text: #edf0fa;
  --text-2: #b7bdd4;
  --muted: #8b93ae;
  --accent: #8b6bff;
  --accent-soft: rgba(139, 107, 255, 0.16);
  --accent-line: rgba(139, 107, 255, 0.42);
  --teal: #3ddcc4;
  --ok: #4ade9b;
  --warn: #ffbb5c;
  --danger: #ff6f85;
  --shadow: 0 24px 60px -28px rgba(0, 0, 0, 0.95);
  --glow: 0 0 0 1px rgba(255, 255, 255, 0.05), 0 18px 50px -24px rgba(139, 107, 255, 0.55);
  --grain-opacity: 0.035;
  --aurora-1: rgba(124, 92, 255, 0.4);
  --aurora-2: rgba(45, 212, 191, 0.24);
  --aurora-3: rgba(255, 107, 138, 0.14);
  --rail-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.035), transparent 42%);
  color-scheme: dark;
}

/* ------------------------------------------------------------------ 浅色 */
html[data-theme="light"] {
  --bg: #f4f6fc;
  --bg-2: #ffffff;
  --bg-3: #eef1f9;
  --panel: #ffffff;
  --panel-2: #f7f8fd;
  --panel-solid: #ffffff;
  --line: #e3e7f2;
  --line-2: #cfd5e6;
  --text: #131726;
  --text-2: #3c4463;
  --muted: #6b7391;
  --accent: #5b45d6;
  --accent-soft: rgba(91, 69, 214, 0.1);
  --accent-line: rgba(91, 69, 214, 0.32);
  --teal: #0e9f8c;
  --ok: #12855c;
  --warn: #a46800;
  --danger: #c62f45;
  --shadow: 0 18px 44px -30px rgba(23, 31, 61, 0.4);
  --glow: 0 0 0 1px rgba(23, 31, 61, 0.05), 0 16px 40px -28px rgba(91, 69, 214, 0.5);
  --grain-opacity: 0.016;
  --aurora-1: rgba(124, 92, 255, 0.22);
  --aurora-2: rgba(45, 212, 191, 0.16);
  --aurora-3: rgba(255, 107, 138, 0.1);
  --rail-bg: #ffffff;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  letter-spacing: 0.005em;
  overflow: hidden;
}

/* 极光背景 */
body::before {
  content: "";
  position: fixed;
  inset: -30% -10% auto -10%;
  height: 88vh;
  background:
    radial-gradient(46% 52% at 18% 8%, var(--aurora-1) 0%, transparent 62%),
    radial-gradient(40% 46% at 74% 2%, var(--aurora-2) 0%, transparent 58%),
    radial-gradient(34% 40% at 52% 26%, var(--aurora-3) 0%, transparent 60%);
  filter: blur(28px);
  pointer-events: none;
  z-index: 0;
}

/* 细颗粒 */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
  opacity: var(--grain-opacity);
  pointer-events: none;
  z-index: 1;
  mix-blend-mode: overlay;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line-2);
  border-radius: 99px;
  border: 3px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }

/* ============================================================ 应用骨架 */
#app { display: flex; height: 100vh; position: relative; z-index: 2; }

.rail {
  width: var(--rail);
  flex: 0 0 var(--rail);
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 22px 16px 16px;
  border-right: 1px solid var(--line);
  background: var(--rail-bg);
  backdrop-filter: blur(18px);
  min-height: 0;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 20px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--accent), var(--teal));
  box-shadow: 0 10px 26px -12px var(--accent);
  flex: 0 0 38px;
}
.brand-mark svg { width: 21px; height: 21px; }
.brand-name { font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; }

.nav-group { font-size: 10.5px; letter-spacing: 0.14em; color: var(--muted); padding: 16px 12px 7px; text-transform: uppercase; }

/* 导航自身滚动，账号/退出固定在 rail 底部；低高度窗口下底部按钮保持可达 */
.rail-nav {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: grid;
  gap: 2px;
  align-content: start;
  padding-right: 3px;
  scrollbar-gutter: stable;
}
.rail-foot { flex: 0 0 auto; margin-top: 8px; display: grid; gap: 10px; }

.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), transform var(--dur) var(--ease);
  font-size: 13.5px;
  position: relative;
  user-select: none;
}
.nav-item svg { width: 17px; height: 17px; flex: 0 0 17px; opacity: 0.82; }
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--text);
}
.nav-item.active svg { opacity: 1; color: var(--accent); }
.nav-item.active::after {
  content: ""; position: absolute; left: -16px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 18px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.nav-item .badge { margin-left: auto; font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.rail-user {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: var(--radius-sm);
  background: var(--panel); border: 1px solid var(--line);
}
.avatar-dot {
  width: 30px; height: 30px; border-radius: 50%; flex: 0 0 30px;
  display: grid; place-items: center; font-size: 12px; font-weight: 600;
  background: linear-gradient(145deg, var(--accent), var(--teal)); color: #fff;
}
.rail-user .who { font-size: 12.5px; font-weight: 600; line-height: 1.25; }
.rail-user .role { font-size: 11px; color: var(--muted); }

/* ============================================================ 主区域 */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 30px;
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  position: sticky; top: 0; z-index: 30;
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 640; letter-spacing: -0.01em; }
.topbar .crumbs { font-size: 11.5px; color: var(--muted); letter-spacing: 0.04em; }
.topbar .spacer { flex: 1; }

.scroll { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 26px 30px 60px; }
.wrap { max-width: var(--maxw); margin: 0 auto; }

/* ============================================================ 基础控件 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-2);
  background: var(--panel-2);
  color: var(--text);
  font: inherit; font-size: 13px; font-weight: 550;
  cursor: pointer;
  transition: all var(--dur) var(--ease);
  white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; }
.btn:hover { border-color: var(--muted); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn.primary {
  background: linear-gradient(140deg, var(--accent), color-mix(in srgb, var(--accent) 62%, var(--teal)));
  border-color: transparent; color: #fff;
  box-shadow: 0 12px 30px -16px var(--accent);
}
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 18%, transparent); }
.btn.sm { height: 30px; padding: 0 11px; font-size: 12px; border-radius: 9px; }
.btn.icon { width: 34px; padding: 0; }
.btn.icon.sm { width: 30px; }

.input, .select, .textarea {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-2);
  background: var(--bg-2);
  color: var(--text);
  font: inherit; font-size: 13px;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.textarea { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; line-height: 1.65; }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input::placeholder, .textarea::placeholder { color: var(--muted); }
.select { appearance: none; padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b93ae' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
}

.field { display: grid; gap: 7px; }
.field > label { font-size: 12px; color: var(--muted); font-weight: 560; letter-spacing: 0.01em; }
.field .hint { font-size: 11.5px; color: var(--muted); line-height: 1.5; }

/* 弹窗里的可勾选清单（分配用户等） */
.pick-list {
  display: grid; gap: 6px;
  max-height: 220px; overflow-y: auto;
  padding: 2px;
}
.pick-item {
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-2);
  cursor: pointer;
  transition: border-color var(--dur) var(--ease);
}
.pick-item:hover { border-color: var(--accent); }
.pick-item:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }

/* 音色库选择行：一行放下 名称 / 性别 / 场景 / ID，ID 靠右且可省略 */
.voice-list {
  /* 底部渐隐，暗示「还能往下滚」——否则最后一行被硬切成半行，看着像渲染错位 */
  mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 14px), transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, #000 0, #000 calc(100% - 14px), transparent 100%);
}
/* 整行是容器，左边「选中区」和右边「试听」是两个独立按钮。
   不能把试听按钮塞进原来的 button 里（button 不能嵌套），所以行本身降级成 div。 */
.voice-row {
  display: flex; align-items: center; gap: 6px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-2);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.voice-row:hover { border-color: var(--accent); }
.voice-row.on {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.voice-pick {
  display: flex; align-items: center; gap: 8px;
  flex: 1 1 auto; min-width: 0;
  padding: 9px 4px 9px 11px;
  border: 0; background: transparent;
  color: var(--text);
  font: inherit; font-size: 13px;
  text-align: left; cursor: pointer;
}
.voice-row .voice-name { font-weight: 550; white-space: nowrap; }
.voice-row .voice-id {
  margin-left: auto;
  color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 42%;
}
.voice-play {
  flex: 0 0 auto;
  display: grid; place-items: center;
  width: 28px; height: 28px; margin-right: 7px;
  padding: 0;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease),
    background var(--dur) var(--ease);
}
.voice-play:hover { color: var(--accent); border-color: var(--accent); }
.voice-play.playing {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}
.voice-play.loading { opacity: 0.5; cursor: progress; }
.voice-play.off { opacity: 0.3; cursor: not-allowed; }

/* 声音页表格里的试听按钮是普通 .btn.icon（不是 .voice-play），
   所以 .playing 得单独给一套样式——否则点了之后界面毫无变化，看不出在放。 */
.btn.icon[data-play].playing {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}
.btn.icon[data-play].loading { opacity: 0.5; cursor: progress; }

/* 原生文件选择框默认是系统浅色皮肤，在深色主题里非常突兀，这里统一成设计系统样式 */
input[type="file"] {
  font: inherit; font-size: 12px; color: var(--muted);
  padding: 6px 10px;
  border: 1px dashed var(--line-2);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  cursor: pointer;
  max-width: 100%;
}
input[type="file"]::file-selector-button {
  height: 26px;
  margin-right: 10px;
  padding: 0 11px;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  background: var(--bg-3, var(--bg-2));
  color: var(--text);
  font: inherit; font-size: 12px;
  cursor: pointer;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
input[type="file"]::file-selector-button:hover { border-color: var(--accent); color: var(--accent); }
input[type="file"]:hover { border-color: var(--accent); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }

/* ============================================================ 卡片 */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}
.card.pad { padding: 18px 20px; }
.card-head {
  display: flex; align-items: center; gap: 12px;
  padding: 15px 20px; border-bottom: 1px solid var(--line);
}
.card-head h2, .card-head h3 { margin: 0; font-size: 13.5px; font-weight: 620; letter-spacing: -0.005em; }
.card-head .sub { font-size: 11.5px; color: var(--muted); }
.card-head .spacer { flex: 1; }
.card-body { padding: 18px 20px; }

.section-title { display: flex; align-items: center; gap: 10px; margin: 30px 0 14px; }
.section-title h2 { font-size: 14px; margin: 0; font-weight: 620; }
.section-title .line { flex: 1; height: 1px; background: var(--line); }

/* ============================================================ 人物工作区 */
.workspace-shell { display: grid; gap: 16px; }
.workspace-head {
  position: sticky;
  top: 0;
  z-index: 12;
  display: grid;
  gap: 11px;
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}
.workspace-context {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.workspace-context > label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 560;
  white-space: nowrap;
}
.workspace-context .spacer { flex: 1; }
.workspace-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}
.workspace-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 31px;
  padding: 0 11px;
  flex: 0 0 auto;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--text-2);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  transition: all var(--dur) var(--ease);
}
.workspace-tab:hover { background: var(--panel-2); color: var(--text); }
.workspace-tab.on {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--text);
}
.workspace-tab.on svg { color: var(--accent); }
.workspace-body { min-width: 0; }
.profile-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 13px;
}
.profile-grid > div { display: grid; gap: 4px; min-width: 0; }
.profile-grid .k { font-size: 11.5px; color: var(--muted); }
.profile-grid .v {
  font-size: 13px;
  font-weight: 560;
  color: var(--text);
  overflow-wrap: anywhere;
}
.persona-prompt {
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--text-2);
  font-size: 12.5px;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* 统计卡 */
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat {
  position: relative; overflow: hidden;
  padding: 17px 18px 15px;
  border-radius: var(--radius-md);
  background: var(--panel);
  border: 1px solid var(--line);
  transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.stat:hover { transform: translateY(-2px); border-color: var(--line-2); }
.stat .k { font-size: 11.5px; color: var(--muted); letter-spacing: 0.03em; display: flex; align-items: center; gap: 6px; }
.stat .v { font-size: 27px; font-weight: 660; letter-spacing: -0.025em; line-height: 1.28; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat .d { font-size: 11.5px; color: var(--muted); }
.stat::after {
  content: ""; position: absolute; right: -34px; top: -34px;
  width: 96px; height: 96px; border-radius: 50%;
  background: radial-gradient(circle, var(--accent-soft), transparent 68%);
  pointer-events: none;
}

/* 状态点 */
.dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 7px; display: inline-block; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 18%, transparent); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 18%, transparent); }
.dot.bad { background: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 18%, transparent); }
.dot.idle { background: var(--muted); }

.tag {
  display: inline-flex; align-items: center; gap: 6px;
  height: 22px; padding: 0 9px;
  border-radius: 999px;
  font-size: 11.5px; font-weight: 540;
  border: 1px solid var(--line-2);
  color: var(--text-2); background: var(--panel-2);
  white-space: nowrap;
}
.tag.accent { color: var(--accent); border-color: var(--accent-line); background: var(--accent-soft); }
.tag.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 36%, transparent); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.tag.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 36%, transparent); background: color-mix(in srgb, var(--warn) 12%, transparent); }
.tag.bad { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 36%, transparent); background: color-mix(in srgb, var(--danger) 12%, transparent); }

/* ============================================================ 人物卡 */
.persona-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 15px; }

.persona {
  position: relative; overflow: hidden;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 20px;
  /* 列宽必须由容器决定：默认的 auto 列会被最宽的 flex 子项按 min-content 撑开，
     卡片宽度不够时整行溢出、再被 overflow:hidden 裁掉，按钮就「看不见」了 */
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px;
  transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  cursor: pointer;
}
.persona > * { min-width: 0; }
.persona:hover { transform: translateY(-3px); border-color: var(--accent-line); box-shadow: var(--glow); }
.persona::before {
  content: ""; position: absolute; inset: 0 auto auto 0; height: 3px; width: 100%;
  background: linear-gradient(90deg, var(--pc, var(--accent)), transparent 72%);
  opacity: 0.9;
}
.persona-top { display: flex; align-items: center; gap: 13px; }
.persona-av {
  width: 52px; height: 52px; border-radius: 16px; flex: 0 0 52px;
  display: grid; place-items: center;
  font-size: 19px; font-weight: 640; color: #fff;
  background: linear-gradient(150deg, var(--pc, var(--accent)), color-mix(in srgb, var(--pc, var(--accent)) 42%, #101528));
  box-shadow: 0 12px 26px -14px var(--pc, var(--accent));
  overflow: hidden;
}
.persona-av img { width: 100%; height: 100%; object-fit: cover; }
/* 人物卡全身封面：contain 完整显示不裁切，浅色底衬托带背景的形象渲染图 */
.persona-av.persona-av-full img { object-fit: contain; padding: 6px; }
.persona-av.persona-av-full {
  background:
    radial-gradient(120% 90% at 50% 0%, color-mix(in srgb, var(--pc, var(--accent)) 26%, transparent), transparent 70%),
    linear-gradient(170deg, color-mix(in srgb, var(--pc, var(--accent)) 14%, var(--panel)), color-mix(in srgb, var(--pc, var(--accent)) 8%, var(--panel)));
  box-shadow: none;
}
.persona-name { font-size: 15px; font-weight: 640; letter-spacing: -0.01em; }
.persona-desc { font-size: 12px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 34px; }
.persona-metrics { display: flex; gap: 16px; }
.persona-metrics div { display: grid; }
.persona-metrics .n { font-size: 15px; font-weight: 620; font-variant-numeric: tabular-nums; }
.persona-metrics .l { font-size: 10.5px; color: var(--muted); letter-spacing: 0.04em; }
/* 底部信息与操作分两行：一行六个元素在 300px 的卡片里必然溢出，
   拆行后无论卡片多窄都不会被裁掉 */
.persona-foot { display: grid; gap: 9px; padding-top: 10px; border-top: 1px solid var(--line); }
.persona-foot-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.persona-foot-row .spacer { flex: 1; }
.persona-actions { display: flex; align-items: center; gap: 6px; }
.persona-actions .btn { flex: 0 0 auto; }
.persona-actions .spacer { flex: 1; }

.persona.add {
  align-items: center; justify-items: center; justify-content: center;
  border-style: dashed; color: var(--muted);
  min-height: 208px;
}
.persona.add:hover { color: var(--accent); border-color: var(--accent-line); background: var(--accent-soft); }
.persona.add .plus { width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; border: 1px solid var(--line-2); margin-bottom: 6px; }

/* ============================================================ 表格 */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  text-align: left; padding: 10px 14px;
  font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted); font-weight: 600;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr { transition: background var(--dur) var(--ease); }
.tbl tbody tr:hover { background: var(--panel-2); }
.tbl .mono { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
.tbl .num { font-variant-numeric: tabular-nums; }
/* 可点击行走查：会话记录点一行看回放，未命中回流点一行看上下文。
   只加 cursor 不够——鼠标移上去没有反馈，用户不会想到能点。 */
.tbl tbody tr.clickable { cursor: pointer; }
.tbl tbody tr.clickable:hover { background: var(--accent-soft); }

/* ======================================================== 会话回放 */
.replay { display: grid; gap: 14px; }
.replay-item {
  display: grid; gap: 8px; padding: 14px 16px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--panel);
}
.replay-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.replay-head .spacer { flex: 1; }
.replay-head .mono-sm { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.bubble {
  max-width: 78%; padding: 9px 13px; border-radius: 13px;
  font-size: 13px; line-height: 1.66; white-space: pre-wrap; word-break: break-word;
}
.bubble.user {
  justify-self: end;
  background: var(--accent-soft); border: 1px solid var(--accent-line);
  border-bottom-right-radius: 4px;
}
.bubble.bot {
  justify-self: start;
  background: var(--panel-2); border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}
.replay-raw { font-size: 11.5px; color: var(--warn); padding-left: 4px; }
.replay-fixes { font-size: 11.5px; color: var(--muted); padding-left: 4px; }
.replay-meta { font-size: 11px; color: var(--muted); letter-spacing: 0.02em; }

/* ============================================================ 弹窗 */
.modal-mask {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(5, 7, 14, 0.62);
  backdrop-filter: blur(8px);
  display: grid; place-items: center;
  padding: 24px;
  animation: fade var(--dur) var(--ease);
}
.modal {
  width: min(680px, 100%);
  max-height: 88vh;
  display: flex; flex-direction: column;
  background: var(--panel-solid);
  border: 1px solid var(--line-2);
  border-radius: var(--radius-xl);
  box-shadow: 0 40px 100px -40px rgba(0, 0, 0, 0.9);
  animation: pop 260ms var(--ease);
  overflow: hidden;
}
.modal.wide { width: min(920px, 100%); }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 20px 24px 14px; }
.modal-head h3 { margin: 0; font-size: 15.5px; font-weight: 640; }
.modal-head .sub { font-size: 11.5px; color: var(--muted); }
.modal-head .spacer { flex: 1; }
.modal-body { padding: 6px 24px 20px; overflow-y: auto; display: grid; gap: 15px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 15px 24px 20px; border-top: 1px solid var(--line); background: var(--panel-2); }

@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(0.985) } to { opacity: 1; transform: none } }

/* ============================================================ 提示 */
#toasts { position: fixed; right: 22px; bottom: 22px; z-index: 200; display: grid; gap: 9px; }
.toast {
  min-width: 250px; max-width: 400px;
  padding: 12px 15px;
  border-radius: var(--radius-sm);
  background: var(--panel-solid);
  border: 1px solid var(--line-2);
  box-shadow: 0 20px 46px -22px rgba(0, 0, 0, 0.8);
  font-size: 13px;
  display: flex; gap: 10px; align-items: flex-start;
  animation: slide-in 240ms var(--ease);
}
.toast.ok { border-left: 3px solid var(--ok); }
.toast.bad { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--accent); }
@keyframes slide-in { from { opacity: 0; transform: translateX(16px) } to { opacity: 1; transform: none } }

/* ============================================================ 空态 / 加载 */
.empty { display: grid; place-items: center; gap: 9px; padding: 46px 20px; color: var(--muted); text-align: center; }
.empty .ico { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; border: 1px dashed var(--line-2); }
.empty .t { font-size: 13px; color: var(--text-2); font-weight: 560; }
.empty .s { font-size: 12px; max-width: 320px; line-height: 1.6; }

.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--panel) 25%, var(--panel-2) 37%, var(--panel) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { 0% { background-position: 100% 0 } 100% { background-position: 0 0 } }

/* ============================================================ 登录页 */

/* 登录页背景：对齐 XiMengFlow 的画布风格——深紫黑径向渐变 + 紫/浅紫环境光晕
   + 细网格 + 粒子网络动画（canvas，见 app.js 的 startLoginCanvas）。
   关键点：#app 是 display:flex 的外壳，.login-wrap 作为其子项必须 flex:1
   占满整行，否则会收缩成内容宽度贴在左边（place-items:center 就地空转）。 */
.login-wrap {
  flex: 1;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
  z-index: 2;
  overflow: hidden;
  background: radial-gradient(120% 90% at 50% 0%, #130b26 0%, #0a0616 55%, #060310 100%);
}
.login-wrap::before {
  /* 细网格纹理，颜色与 XiMengFlow 的 --canvas-grid-line(#ffffff05) 同级 */
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 46px 46px;
  -webkit-mask-image: radial-gradient(75% 65% at 50% 40%, #000 25%, transparent 100%);
  mask-image: radial-gradient(75% 65% at 50% 40%, #000 25%, transparent 100%);
  pointer-events: none;
}
/* 环境光晕：对应 --canvas-ambient-orb-primary/secondary（8b5cf6 / c084fc） */
.login-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(64px);
  pointer-events: none;
}
.login-orb-a {
  width: 540px;
  height: 540px;
  right: -130px;
  top: -150px;
  background: radial-gradient(circle, rgba(139, 92, 246, 0.35), transparent 65%);
}
.login-orb-b {
  width: 480px;
  height: 480px;
  left: -150px;
  bottom: -170px;
  background: radial-gradient(circle, rgba(192, 132, 252, 0.22), transparent 65%);
}
.login-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}
.login-card {
  position: relative;
  z-index: 1;
  width: min(420px, 100%);
  padding: 34px 32px 30px;
  border-radius: var(--radius-xl);
  /* 深紫玻璃卡：登录页背景恒为深色，卡片配色与应用主题解耦，写死深色系 */
  background: rgba(23, 18, 46, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow:
    0 40px 100px -40px rgba(0, 0, 0, 0.8),
    0 0 70px -24px rgba(139, 92, 246, 0.45);
  backdrop-filter: blur(24px);
  display: grid;
  gap: 17px;
}
/* 深色卡片内的文字与输入框：脱离浅色主题变量，直接给暗色系配色 */
.login-card h1 { margin: 0; font-size: 21px; font-weight: 660; letter-spacing: -0.02em; color: #fff; }
.login-card p.sub { margin: 0; font-size: 12.5px; color: rgba(255, 255, 255, 0.55); }
.login-card .field label { color: rgba(255, 255, 255, 0.65); }
.login-card .input {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.14);
  color: #fff;
  caret-color: #fff;
}
.login-card .input::placeholder { color: rgba(255, 255, 255, 0.32); }
.login-card .input:focus {
  border-color: #8b5cf6;
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.18);
  outline: none;
}
.login-card .hint {
  font-size: 11.5px;
  text-align: center;
  color: rgba(255, 255, 255, 0.45);
}
.login-card .hint .mono-sm { color: rgba(255, 255, 255, 0.62); }
.login-card .err { min-height: 18px; font-size: 12.5px; color: #fca5a5; }
.login-card .mark {
  width: 46px;
  height: 46px;
  border-radius: 15px;
  display: grid;
  place-items: center;
  background: linear-gradient(150deg, var(--accent), var(--teal));
  box-shadow: 0 16px 38px -18px var(--accent);
}
.login-foot {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 18px;
  text-align: center;
  font-size: 11.5px;
  letter-spacing: 0.12em;
  color: rgba(255, 255, 255, 0.42);
  pointer-events: none;
}

/* ============================================================ 会话调试 */
.talk { display: grid; grid-template-columns: 1fr 320px; gap: 16px; }
.chat-log {
  flex: 1;
  min-height: 320px;
  max-height: 58vh;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.bubble { max-width: 78%; padding: 11px 14px; border-radius: 16px; font-size: 13.5px; line-height: 1.62; position: relative; word-break: break-word; }
.bubble.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 5px; }
.bubble.bot { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.bubble.sys { align-self: center; background: transparent; border: 1px dashed var(--line-2); color: var(--muted); font-size: 11.5px; padding: 5px 11px; border-radius: 999px; }
.bubble .who { font-size: 10.5px; opacity: 0.7; margin-bottom: 3px; letter-spacing: 0.04em; }

.mic-orb {
  width: 92px; height: 92px; border-radius: 50%;
  display: grid; place-items: center; margin: 0 auto;
  background: radial-gradient(circle at 34% 30%, color-mix(in srgb, var(--accent) 90%, #fff 10%), var(--accent));
  box-shadow: 0 0 0 8px var(--accent-soft), 0 22px 50px -22px var(--accent);
  cursor: pointer; transition: all var(--dur) var(--ease);
  border: none;
}
.mic-orb svg { width: 34px; height: 34px; color: #fff; }
.mic-orb:hover { transform: scale(1.04); }
.mic-orb.live { box-shadow: 0 0 0 10px color-mix(in srgb, var(--danger) 22%, transparent), 0 0 46px -6px var(--danger); background: radial-gradient(circle at 34% 30%, #ff8f9f, var(--danger)); animation: pulse 1.8s infinite; }
@keyframes pulse { 0%,100% { transform: scale(1) } 50% { transform: scale(1.035) } }

.meter { height: 4px; border-radius: 99px; background: var(--panel-2); overflow: hidden; }
.meter > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--teal), var(--accent)); transition: width 90ms linear; }

.kv { display: grid; gap: 9px; }
.kv > div { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 12.5px; }
.kv .k { color: var(--muted); }
.kv .v { font-weight: 560; font-variant-numeric: tabular-nums; text-align: right; }

/* ---- 嘴型预览（face_anim 旁路）：右栏 320px，画布按 240×120 原尺寸画，放大会糊 */
.face-prev { display: grid; gap: 11px; }
.face-canvas {
  display: block;
  width: 100%;
  max-width: 240px;
  height: auto;
  margin: 0 auto;
  border-radius: 14px;
  background: #080b14;
}
.face-toggle {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--text-2);
  cursor: pointer; user-select: none; line-height: 1.5;
}
.face-toggle input[type="checkbox"] {
  width: 14px; height: 14px; margin: 0;
  accent-color: var(--accent); cursor: pointer; flex: 0 0 14px;
}
.face-toggle input[type="checkbox"]:disabled { cursor: not-allowed; }
.face-toggle:has(input:disabled) { color: var(--muted); cursor: not-allowed; }
.face-stat {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.55;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

/* 拖拽上传 */
.dropzone {
  border: 1px dashed var(--line-2);
  border-radius: var(--radius-md);
  padding: 26px 18px;
  text-align: center;
  color: var(--muted);
  transition: all var(--dur) var(--ease);
  cursor: pointer;
  display: grid; gap: 7px; place-items: center;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.dropzone .t { font-size: 13px; color: var(--text-2); font-weight: 550; }
.dropzone .s { font-size: 11.5px; }

/* 分段控件 */
.seg { display: inline-flex; padding: 3px; gap: 3px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 11px; }
.seg button {
  height: 28px; padding: 0 12px; border: none; background: transparent; color: var(--muted);
  font: inherit; font-size: 12.5px; border-radius: 8px; cursor: pointer; transition: all var(--dur) var(--ease);
}
.seg button.on { background: var(--panel-solid); color: var(--text); box-shadow: 0 3px 10px -4px rgba(0, 0, 0, 0.5); }

.hr { height: 1px; background: var(--line); margin: 4px 0; }

.link { color: var(--accent); cursor: pointer; text-decoration: none; }
.link:hover { text-decoration: underline; }

.mono-sm { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }

/* ============================================================ 展示层：素材 / 背景 */

.asset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 12px;
  margin-top: 16px;
}
.asset-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-solid);
  padding: 8px;
  display: grid;
  gap: 6px;
  transition: border-color var(--dur) var(--ease);
}
.asset-card:hover { border-color: var(--accent-line); }
/* 防重叠：长关键词（老库整句文案）不许把卡片撑爆叠到邻卡——
   网格项 min-width:0 + 卡片裁剪 + 标签单行截断省略 */
.asset-card { min-width: 0; overflow: hidden; }
.asset-card .row { min-width: 0; }
.asset-card .tag {
  display: inline-block;
  max-width: 100%; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  vertical-align: middle; line-height: 20px;
}
.asset-card.is-bg { border-color: var(--accent-line); box-shadow: 0 0 0 1px var(--accent-line) inset; }
.asset-thumb-wrap {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  overflow: hidden;
  background: var(--line);
}
.asset-thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.asset-kind {
  position: absolute; left: 6px; bottom: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 6px;
  background: rgba(0, 0, 0, 0.55); color: #fff;
}
.asset-name {
  font-size: 12.5px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.asset-sub { font-size: 11.5px; color: var(--muted); }

.stage-preview {
  border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--line); background: var(--line);
}
.stage-bg { width: 100%; max-height: 320px; object-fit: cover; display: block; }
.stage-preview-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 12px; font-size: 12px; color: var(--muted);
  background: var(--panel-solid); border-top: 1px solid var(--line);
}

/* ============================================================ 响应式 */
@media (max-width: 1080px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .talk { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .profile-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  :root { --rail: 74px; }
  .rail { padding: 16px 10px; align-items: center; }
  .brand-name, .brand-sub, .nav-item span, .nav-group, .rail-user .who, .rail-user .role { display: none; }
  .nav-item { justify-content: center; padding: 11px; }
  .nav-item.active::after { display: none; }
  .rail-nav { padding-right: 0; }
  .rail-user { justify-content: center; padding: 8px; }
  .rail-foot { justify-items: stretch; }
  .rail-foot .row { gap: 5px; }
  .rail-foot .btn span { display: none; }
  .rail-foot .btn { flex: 1 1 0; min-width: 0; padding: 0; justify-content: center; }
  .scroll { padding: 18px 16px 50px; }
  .topbar { padding: 13px 16px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .stat-grid { grid-template-columns: 1fr; }
  .modal { border-radius: var(--radius-lg); }
}
