/* ==========================================================================
   DeepChat Chat —UI clone
   Tokens lifted from the live app (--dsw-* design system), light + dark.
   ========================================================================== */

:root {
  /* ---- static palette ---- */
  --ds-deepchat-50: #edf3fe;
  --ds-deepchat-100: #e4edfd;
  --ds-deepchat-200: #d3e2ff;
  --ds-deepchat-300: #b7c8fe;
  --ds-deepchat-400: #679efe;
  --ds-deepchat-450: #5686fe;
  --ds-deepchat-500: #3964fe;
  --ds-deepchat-600: #4868b2;

  --ds-nb-00: #ffffff;
  --ds-nb-50: #f9fafb;
  --ds-nb-60: #f5f6f7;
  --ds-nb-75: #f1f3f5;
  --ds-nb-100: #ebeef2;
  --ds-nb-150: #e9ecf2;
  --ds-nb-200: #e1e5ee;
  --ds-nb-300: #cfd3d6;
  --ds-nb-400: #adb2b8;
  --ds-nb-500: #979da6;
  --ds-nb-600: #81858c;
  --ds-nb-700: #61666b;
  --ds-nb-850: #2c2c2e;
  --ds-nb-950: #151517;
  --ds-nb-1000: #0f1115;

  --ds-red-500: #ef4444;
  --ds-red-600: #ec1313;
  --ds-green-500: #22c55e;

  /* ---- semantic aliases (light) ---- */
  --brand: var(--ds-deepchat-500);
  --brand-hover: var(--ds-deepchat-450);
  --bg-base: var(--ds-nb-00);
  --bg-sidebar: var(--ds-nb-50);
  --bg-layer-1: var(--ds-nb-00);
  --bg-layer-2: var(--ds-nb-00);
  --bg-hover: rgba(38, 49, 72, .06);
  --bg-active: rgba(38, 49, 72, .1);
  --bg-selected: rgba(57, 100, 254, .1);
  --bg-user-bubble: var(--ds-nb-75);
  --bg-inline-code: var(--ds-nb-100);
  --bg-code-block: var(--ds-nb-50);
  --bg-code-banner: var(--ds-nb-50);
  --bg-mask: rgba(0, 0, 0, .24);
  --bg-mask-soft: rgba(0, 0, 0, .12);
  --bg-dialog: var(--ds-nb-00);

  --text-primary: var(--ds-nb-1000);
  --text-secondary: var(--ds-nb-700);
  --text-tertiary: var(--ds-nb-600);
  --text-dimmed: var(--ds-nb-400);

  --border-l1: rgba(0, 0, 0, .04);
  --border-l2: rgba(0, 0, 0, .1);
  --border-l3: rgba(0, 0, 0, .12);
  --border-l4: rgba(0, 0, 0, .16);

  --shadow-composer: 0 4px 12px rgba(0, 0, 0, .02), 0 2px 2px rgba(72, 104, 178, .01), 0 30px 60px rgba(72, 104, 178, .03);
  --shadow-popover: 0 4px 16px rgba(0, 0, 0, .08), 0 1px 4px rgba(0, 0, 0, .04);
  --shadow-pill: 0 1px 2px rgba(0, 0, 0, .04);

  --radius-pill: 100px;
  --radius-composer: 24px;
  --radius-bubble: 20px;
  --radius-item: 10px;

  --font-sans: "Inter", "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei",
    system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;

  --sidebar-w: 261px;
  --header-h: 56px;
  --transition: 180ms cubic-bezier(.4, 0, .2, 1);

  /* brand alias used by the inlined wordmark SVG */
  --dsw-alias-brand-primary: var(--brand);
  color-scheme: light;
}

[data-theme="dark"] {
  --bg-base: var(--ds-nb-950);
  --bg-sidebar: #1b1b1c;
  --bg-layer-1: #232324;
  --bg-layer-2: #2c2c2e;
  --bg-hover: rgba(255, 255, 255, .06);
  --bg-active: rgba(255, 255, 255, .1);
  --bg-selected: rgba(57, 100, 254, .22);
  --bg-user-bubble: #2c2c2e;
  --bg-inline-code: #2c2c2e;
  --bg-code-block: #232324;
  --bg-code-banner: #2c2c2e;
  --bg-mask: rgba(0, 0, 0, .5);
  --bg-mask-soft: rgba(0, 0, 0, .4);
  --bg-dialog: #232324;

  --text-primary: #f2f3f5;
  --text-secondary: #b8bdc4;
  --text-tertiary: #979da6;
  --text-dimmed: #61666b;

  --border-l1: rgba(255, 255, 255, .06);
  --border-l2: rgba(255, 255, 255, .1);
  --border-l3: rgba(255, 255, 255, .14);
  --border-l4: rgba(255, 255, 255, .18);

  --shadow-composer: 0 4px 12px rgba(0, 0, 0, .24), 0 30px 60px rgba(0, 0, 0, .32);
  --shadow-popover: 0 4px 20px rgba(0, 0, 0, .5), 0 1px 4px rgba(0, 0, 0, .3);
  --shadow-pill: 0 1px 2px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-base);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  padding: 0;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

svg { display: block; flex: none; }

::selection { background: rgba(57, 100, 254, .18); }

/* scrollbars */
.scroll-area { scrollbar-width: thin; scrollbar-color: transparent transparent; }
.scroll-area:hover { scrollbar-color: var(--ds-nb-300) transparent; }
.scroll-area::-webkit-scrollbar { width: 8px; height: 8px; }
.scroll-area::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: content-box;
}
.scroll-area:hover::-webkit-scrollbar-thumb { background: var(--ds-nb-300); background-clip: content-box; }
[data-theme="dark"] .scroll-area:hover::-webkit-scrollbar-thumb { background: #4a4b4f; background-clip: content-box; }

/* ==========================================================================
   App shell
   ========================================================================== */

.app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg-base);
}

/* ------------------------------- sidebar -------------------------------- */

.sidebar {
  width: var(--sidebar-w);
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-l1);
  transition: margin-left var(--transition), width var(--transition);
  overflow: hidden;
}

.app[data-sidebar="collapsed"] .sidebar {
  margin-left: calc(-1 * var(--sidebar-w));
}

.sb-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 62px;
  padding: 6px 4px 0 4px;
  margin: 0 12px;
  flex: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 4px;
  border-radius: 8px;
  outline: none;
}
.brand svg { height: 23px; width: auto; color: var(--brand); }
.brand-wordmark { display: block; }

.sb-actions { display: flex; align-items: center; gap: 6px; }

.icon-btn {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.icon-btn:active { background: var(--bg-active); }
.icon-btn.is-active { background: var(--bg-active); color: var(--text-primary); }
.icon-btn.sm { width: 28px; height: 28px; }
.icon-btn[disabled] { color: var(--text-dimmed); cursor: default; }
.icon-btn[disabled]:hover { background: none; }

/* search */
.sb-search {
  margin: 8px 12px 0;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 10px;
  border-radius: var(--radius-item);
  background: var(--bg-layer-1);
  border: 1px solid var(--border-l2);
  flex: none;
}
.sb-search svg { color: var(--text-dimmed); }
.sb-search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: none;
  font: inherit;
  color: var(--text-primary);
}
.sb-search input::placeholder { color: var(--text-dimmed); }
.sb-search[hidden] { display: none; }

/* new chat */
.sb-new { padding: 8px 12px 4px; flex: none; }

.new-chat {
  width: 100%;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--radius-pill);
  background: var(--bg-layer-1);
  border: 1px solid var(--border-l1);
  box-shadow: var(--shadow-pill);
  color: var(--text-primary);
  font-size: 14px;
  transition: background var(--transition), transform var(--transition);
}
.new-chat:hover { background: var(--bg-layer-1); filter: brightness(.985); }
[data-theme="dark"] .new-chat:hover { filter: brightness(1.12); }
.new-chat:active { transform: scale(.995); }
.new-chat svg { color: var(--text-primary); }

/* history */
.sb-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 32px 12px 8px;
}

.hist-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 30px;
  padding: 8px 10px 0;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-tertiary);
  letter-spacing: .01em;
  user-select: none;
}
.hist-label .label-actions { opacity: 0; transition: opacity var(--transition); }
.hist-label:hover .label-actions { opacity: 1; }

.hist-item {
  position: relative;
  display: flex;
  align-items: center;
  height: 36px;
  padding: 0 10px;
  margin: 1px 0;
  border-radius: var(--radius-item);
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
}
.hist-item:hover { background: var(--bg-hover); }
.hist-item.active { background: var(--bg-selected); }
.hist-item .title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hist-item .row-more {
  width: 22px;
  height: 22px;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  color: var(--text-secondary);
  margin-right: -4px;
}
.hist-item:hover .row-more,
.hist-item.menu-open .row-more { display: inline-flex; }
.hist-item .row-more:hover { background: var(--bg-active); }
.hist-empty {
  padding: 24px 10px;
  text-align: center;
  font-size: 13px;
  color: var(--text-dimmed);
}

/* sidebar footer */
.sb-foot {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border-l1);
}
.user-chip {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px;
  border-radius: var(--radius-item);
  transition: background var(--transition);
}
.user-chip:hover { background: var(--bg-hover); }
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  overflow: hidden;
  flex: none;
  background: linear-gradient(135deg, #6b8afd, #2f4c8f);
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .02em;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-name {
  font-size: 14px;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* -------------------------------- main ---------------------------------- */

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg-base);
}

.chat-head {
  height: var(--header-h);
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 0 16px;
  position: relative;
  z-index: 5;
}
.chat-head .head-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }

.chat-title {
  font-size: 14px;
  font-weight: 400;
  color: var(--text-primary);
  margin: 0;
  max-width: 46ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.app[data-sidebar="collapsed"] .chat-head { padding-left: 8px; }
.chat-head .expand-btn { display: none; }
.app[data-sidebar="collapsed"] .chat-head .expand-btn { display: inline-flex; }

/* scroll body */
.chat-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  scroll-behavior: smooth;
}

/* home (empty) state */
.welcome {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 24px 4px;
}
.app[data-view="home"] .chat-scroll { justify-content: center; }
.app[data-view="chat"] .composer-wrap { margin-top: auto; }
.app[data-view="home"] .chat-title,
.app[data-view="home"] .head-actions { visibility: hidden; }
.app[data-view="home"] .welcome { display: flex; }
.welcome-mark { display: none; }

/* persona cards (home state) */
.persona-picker { width: 100%; max-width: 720px; }
.persona-hint {
  text-align: center;
  font-size: 13px;
  color: var(--text-dimmed);
  margin: 0 0 14px;
}
.persona-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.persona-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--border-l2);
  background: var(--bg-elevated, var(--bg-card, transparent));
  cursor: pointer;
  text-align: left;
  color: var(--text-primary);
  transition: border-color var(--transition), transform var(--transition), background var(--transition);
}
.persona-card:hover { transform: translateY(-2px); border-color: var(--ds-deepchat-300, var(--brand)); }
.persona-card[aria-pressed="true"] {
  border-color: var(--brand);
  background: var(--ds-deepchat-50, rgba(57,100,254,.08));
}
.persona-emoji {
  font-size: 26px; line-height: 1; width: 38px; text-align: center;
}
.persona-meta { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.persona-name { font-size: 15px; font-weight: 600; }
.persona-tag { font-size: 12px; color: var(--text-dimmed); }
.persona-desc { font-size: 12px; color: var(--text-secondary, var(--text-dimmed)); margin-top: 2px; }
.persona-card-wrap { position: relative; display: flex; flex-direction: column; }
.persona-card-wrap .persona-card { flex: 1; }
.persona-src { font-size: 10px; font-weight: 400; padding: 1px 6px; border-radius: 8px; margin-left: 4px; vertical-align: middle; }
.persona-src.private { background: rgba(57,100,254,.14); color: var(--brand); }
.persona-src.global { background: rgba(0,150,100,.14); color: #12805a; }
.persona-card-tools { display: flex; gap: 10px; justify-content: flex-end; padding: 0 8px 4px; }
.persona-card-tools button { border: none; background: none; color: var(--text-dimmed); font-size: 11px; cursor: pointer; padding: 2px 4px; }
.persona-card-tools button:hover { color: var(--brand); }
.persona-action {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-radius: 14px;
  border: 1px dashed var(--border-l2);
  background: transparent; cursor: pointer; text-align: left;
  color: var(--text-dimmed); transition: border-color var(--transition), background var(--transition);
}
.persona-action:hover { border-color: var(--brand); background: var(--ds-deepchat-50, rgba(57,100,254,.05)); }
.form-error { color: #d93025; font-size: 12px; margin: 6px 0 0; }
/* 用户侧：定制进度列表 */
.pr-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border-l1);
}
.pr-item:first-child { padding-top: 2px; }
.pr-item:last-child { border-bottom: 0; }
.pr-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pr-head b { font-size: 14px; color: var(--text-primary); }
.pr-status {
  flex: none; font-size: 11px; padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--border-l2); color: var(--text-tertiary);
}
.pr-status.pending { color: #9a6700; border-color: rgba(154,103,0,.35); }
.pr-status.done { color: #12805a; border-color: rgba(18,128,90,.35); }
.pr-status.rejected { color: var(--ds-red-600); border-color: rgba(236,19,19,.35); }
.pr-style { margin-top: 4px; font-size: 12px; color: var(--text-secondary); }
.pr-detail {
  margin-top: 6px; font-size: 12px; line-height: 1.6; color: var(--text-secondary);
  white-space: pre-wrap; word-break: break-word;
}
.pr-note { margin-top: 6px; font-size: 12px; color: var(--brand); }
.pr-time { margin-top: 6px; font-size: 11px; color: var(--text-dimmed); }
.welcome-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 24px;
  line-height: 32px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 26px;
  white-space: nowrap;
}
.welcome-mark-inline { width: 30px; height: 26px; color: var(--brand); }
.welcome-mark-inline svg { width: 30px; height: 26px; }

/* thread */
.thread {
  display: none;
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding: 24px 24px 0;
  flex: 0 0 auto;
}
.app[data-view="chat"] .thread { display: block; }
.app[data-view="chat"] .chat-scroll { justify-content: flex-start; }

.turn { margin-bottom: 28px; }

/* user turn */
.turn-user {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
.bubble {
  max-width: 76%;
  background: var(--bg-user-bubble);
  border-radius: var(--radius-bubble);
  padding: 10px 16px;
  font-size: 16px;
  line-height: 24px;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
}
.turn-tools {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity var(--transition);
  margin-right: -6px;
}
.turn-user:hover .turn-tools { opacity: 1; }

/* assistant turn */
.turn-ai { font-size: 16px; line-height: 28px; }

.think {
  margin-bottom: 14px;
}
.think-head {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  padding: 0 8px 0 0;
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 14px;
  user-select: none;
}
.think-head:hover { color: var(--text-primary); }
.think-head .chev { transition: transform var(--transition); }
.think[data-open="false"] .chev { transform: rotate(-90deg); }
.think-body {
  border-left: 2px solid var(--border-l2);
  margin: 6px 0 2px 9px;
  padding: 2px 0 2px 18px;
  font-size: 14px;
  line-height: 24px;
  color: var(--text-secondary);
}
.think-body p { margin: 0 0 8px; }
.think-body ul { margin: 0 0 8px; padding-left: 18px; }
.think[data-open="false"] .think-body { display: none; }

.answer { color: var(--text-primary); }
.answer.is-streaming::after {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-left: 2px;
  border-radius: 50%;
  background: var(--brand);
  vertical-align: middle;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* markdown */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 12px; }
.md h1, .md h2, .md h3, .md h4 {
  margin: 22px 0 10px;
  font-weight: 600;
  line-height: 1.4;
}
.md h1 { font-size: 22px; }
.md h2 { font-size: 20px; }
.md h3 { font-size: 18px; }
.md h4 { font-size: 16px; }
.md ul, .md ol { margin: 0 0 12px; padding-left: 26px; }
.md li { margin: 4px 0; }
.md li > p { margin: 0 0 6px; }
.md li::marker { color: var(--text-tertiary); }
.md strong { font-weight: 600; }
.md em { font-style: italic; }
.md hr { border: 0; border-top: 1px solid var(--border-l2); margin: 20px 0; }
.md blockquote {
  margin: 0 0 12px;
  padding: 2px 0 2px 14px;
  border-left: 3px solid var(--border-l3);
  color: var(--text-secondary);
}
.md a { color: var(--brand); text-decoration: underline; text-underline-offset: 2px; }
.md code {
  font-family: var(--font-mono);
  font-size: .875em;
  background: var(--bg-inline-code);
  padding: 2px 5px;
  border-radius: 5px;
}
.md table {
  border-collapse: collapse;
  margin: 0 0 14px;
  font-size: 14px;
  width: 100%;
}
.md th, .md td {
  border: 1px solid var(--border-l2);
  padding: 7px 12px;
  text-align: left;
}
.md th { background: var(--bg-code-block); font-weight: 600; }

/* code block */
.code-block {
  margin: 0 0 14px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-code-block);
  border: 1px solid var(--border-l1);
}
.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px 6px 14px;
  font-size: 12px;
  color: var(--text-tertiary);
  background: var(--bg-code-banner);
  border-bottom: 1px solid var(--border-l1);
}
.copy-code {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 12px;
}
.copy-code:hover { background: var(--bg-hover); color: var(--text-primary); }
.code-block pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
}
.code-block code {
  background: none;
  padding: 0;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-primary);
  white-space: pre;
}

/* citations + sources */
.cite {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 15px;
  height: 15px;
  padding: 0 3px;
  margin: 0 2px;
  border-radius: 4px;
  background: var(--bg-inline-code);
  color: var(--text-secondary);
  font-size: 10px;
  line-height: 1;
  vertical-align: 1px;
  cursor: pointer;
}
.cite:hover { background: var(--bg-active); }

.sources {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px 0 8px;
  margin-top: 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-l2);
  color: var(--text-secondary);
  font-size: 13px;
}
.sources:hover { background: var(--bg-hover); }
.source-dots { display: inline-flex; }
.source-dots i {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  display: block;
  margin-left: -4px;
  border: 1px solid var(--bg-base);
  background: var(--ds-nb-200);
}
.source-dots i:first-child { margin-left: 0; }

.disclaimer {
  margin: 14px 0 0;
  font-size: 13px;
  line-height: 20px;
  color: var(--text-dimmed);
  font-style: italic;
}

.turn-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-top: 10px;
  color: var(--text-tertiary);
}
.turn-actions .icon-btn { color: var(--text-tertiary); }
.turn-actions .icon-btn:hover { color: var(--text-primary); }
.turn-actions .icon-btn.liked { color: var(--brand); }

/* composer */
.composer-wrap {
  position: sticky;
  bottom: 0;
  z-index: 4;
  flex: none;
  width: 100%;
  max-width: 840px;
  margin: 0 auto;
  padding: 8px 32px 12px;
  background: linear-gradient(to bottom, transparent, var(--bg-base) 28px);
}

.composer {
  border-radius: var(--radius-composer);
  background: var(--bg-layer-1);
  border: .6667px solid var(--border-l2);
  box-shadow: var(--shadow-composer);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.composer:focus-within {
  border-color: var(--border-l3);
  box-shadow: var(--shadow-composer), 0 0 0 3px rgba(57, 100, 254, .06);
}

.composer textarea {
  display: block;
  width: 100%;
  min-height: 60px;
  max-height: 40vh;
  resize: none;
  border: 0;
  outline: 0;
  background: none;
  padding: 12px 12px 0 16px;
  font-family: inherit;
  font-size: 16px;
  line-height: 24px;
  color: var(--text-primary);
  overflow-y: auto;
}
.composer textarea::placeholder { color: var(--text-dimmed); }

.composer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px 10px 12px;
}
.chips { display: flex; align-items: center; gap: 6px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px 0 10px;
  border-radius: 18px;
  border: .6667px solid var(--border-l2);
  color: var(--text-primary);
  font-size: 13px;
  line-height: 1;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.chip:hover { background: var(--bg-hover); }
.chip svg { color: currentColor; }
.chip[aria-pressed="true"] {
  background: var(--ds-deepchat-50);
  border-color: var(--ds-deepchat-300);
  color: var(--brand);
}
[data-theme="dark"] .chip[aria-pressed="true"] {
  background: rgba(57, 100, 254, .16);
  border-color: rgba(103, 158, 254, .45);
  color: #8ab0ff;
}

.composer-right { display: flex; align-items: center; gap: 6px; }

.send {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--ds-nb-200);
  color: #fff;
  transition: background var(--transition), transform var(--transition);
}
.send:not([disabled]) { background: var(--brand); }
.send:not([disabled]):hover { background: var(--brand-hover); }
.send:not([disabled]):active { transform: scale(.94); }
.send[disabled] { cursor: default; }
[data-theme="dark"] .send[disabled] { background: #3a3b3e; color: #6d7175; }
.send.is-stop {
  background: var(--brand);
  color: #fff;
}
.send.is-stop svg { animation: none; }

.composer-hint {
  text-align: center;
  font-size: 12px;
  line-height: 20px;
  color: var(--text-dimmed);
  padding: 4px 0 6px;
  user-select: none;
}

/* ==========================================================================
   Popovers / menus / modal
   ========================================================================== */

.popover {
  position: fixed;
  z-index: 60;
  min-width: 148px;
  padding: 5px;
  border-radius: 12px;
  background: var(--bg-dialog);
  box-shadow: var(--shadow-popover);
  border: 1px solid var(--border-l1);
  animation: pop-in 120ms ease-out;
}
@keyframes pop-in {
  from { opacity: 0; transform: translateY(-4px) scale(.98); }
  to { opacity: 1; transform: none; }
}
.popover[hidden] { display: none; }

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--text-primary);
  white-space: nowrap;
}
.menu-item:hover { background: var(--bg-hover); }
.menu-item.danger { color: var(--ds-red-600); }
.menu-item .shortcut { margin-left: auto; color: var(--text-dimmed); font-size: 12px; }
.menu-sep { height: 1px; margin: 5px 6px; background: var(--border-l2); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 44px;
  transform: translate(-50%, 12px);
  z-index: 90;
  padding: 9px 16px;
  border-radius: 10px;
  background: #353638;
  color: #fff;
  font-size: 13px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .18);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition), transform var(--transition);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ==========================================================================
   Responsive
   ========================================================================== */

.scrim {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--bg-mask);
  animation: fade-in 160ms ease-out;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 45;
    box-shadow: 0 0 40px rgba(0, 0, 0, .12);
  }
  .app[data-sidebar="collapsed"] .sidebar { margin-left: calc(-1 * var(--sidebar-w)); }
  .app[data-sidebar="open"] .scrim { display: block; }
  .chat-head { padding-left: 8px; }
  .chat-head .expand-btn { display: inline-flex; }
  .thread, .composer-wrap { padding-left: 16px; padding-right: 16px; }
  .welcome-title { font-size: 20px; line-height: 28px; }
  .bubble { max-width: 88%; }
  .app[data-sidebar="collapsed"] .chat-head .expand-btn { display: inline-flex; }
}

@media (min-width: 861px) {
  .app[data-sidebar="collapsed"] .chat-head .expand-btn { display: inline-flex; }
}

/* print-ish nicety */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ==========================================================================
   后台专用样式（仅 admin- 前缀，不触碰用户侧 .persona-*）
   ========================================================================== */

.admin-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  margin-left: 6px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--ds-red-600, #ef4444);
  color: #fff;
  font-size: 11px;
  line-height: 1;
  vertical-align: middle;
}
.admin-badge[hidden] { display: none; }

.admin-badge-status.pending { background: rgba(245, 158, 11, .14); color: #b45309; }
.admin-badge-status.done { background: rgba(34, 197, 94, .14); color: #178a45; }
.admin-badge-status.rejected { background: rgba(239, 68, 68, .13); color: #ce2b2b; }
[data-theme="dark"] .admin-badge-status.pending { background: rgba(245, 158, 11, .2); color: #fbbf24; }
[data-theme="dark"] .admin-badge-status.done { background: rgba(34, 197, 94, .2); color: #5fd98d; }
[data-theme="dark"] .admin-badge-status.rejected { background: rgba(239, 68, 68, .22); color: #ff8b8b; }

table.data td.admin-desc {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: help;
}

.admin-handle-note {
  margin-top: 4px;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-req-summary {
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg-inline-code, var(--bg-hover));
  line-height: 1.5;
}

.admin-modal-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.admin-modal-form .field { display: flex; flex-direction: column; gap: 6px; }
.admin-modal-form .field label { font-size: 12px; color: var(--text-secondary); }
.admin-modal-form .input {
  width: 100%;
  box-sizing: border-box;
}
.admin-modal-form textarea.input { resize: vertical; min-height: 64px; }
.admin-modal-form .opt { color: var(--text-dimmed); font-weight: 400; }
