/* ========== 全局样式 ========== */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:root {
  --bg-primary: #0f0f14;
  --bg-secondary: #1a1a24;
  --bg-panel: #1e1e2e;
  --border-color: #2a2a3e;
  --text-primary: #e4e4ef;
  --text-secondary: #8888a0;
  --text-muted: #555570;

  --color-idle: #555570;
  --color-warning: #facc15;
  --color-thinking: #60a5fa;
  --color-responding: #a78bfa;
  --color-error: #f87171;

  --accent: #7c3aed;
  --accent-hover: #6d28d9;

  --radius: 12px;
  --radius-sm: 8px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  overflow: hidden;
  overflow-x: hidden;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px;
}

/* ========== 应用骨架：侧栏 + 主区 ========== */

.app-shell {
  display: flex;
  height: 100vh;
  height: 100dvh;
  background: var(--bg-primary);
}

.sidebar {
  width: 240px;
  min-width: 200px;
  height: 100vh;
  height: 100dvh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-new-session {
  margin: 12px;
  padding: 10px 16px;
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}

.sidebar-new-session:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.sidebar-session-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px;
}

.sidebar-session-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-bottom: 4px;
  transition: background 0.15s;
}

.sidebar-session-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.sidebar-session-item.active {
  background: rgba(124, 58, 237, 0.2);
  border: 1px solid rgba(124, 58, 237, 0.4);
}

.sidebar-session-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--border-color);
}

.sidebar-session-avatar.default {
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 0.9rem;
  font-weight: 600;
}

.sidebar-session-info {
  flex: 1;
  min-width: 0;
}

.sidebar-session-name {
  display: inline-block;
  max-width: 7em;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

.sidebar-session-settings {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  transition: color 0.2s, background 0.2s;
}

.sidebar-session-settings:hover {
  color: var(--accent);
  background: rgba(124, 58, 237, 0.15);
}

.sidebar-settings {
  padding: 12px;
  margin: 8px;
  border: none;
  background: var(--bg-panel);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
}

.sidebar-settings:hover {
  color: var(--accent);
  background: rgba(124, 58, 237, 0.15);
}

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* ========== 聊天主区 ========== */

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-placeholder {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 48px 24px;
}

.msg {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  line-height: 1.5;
  word-break: break-word;
}

.msg-user {
  flex-direction: row-reverse;
  justify-content: flex-start;
}

.msg-assistant {
  justify-content: flex-start;
}

.msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--border-color);
}

.msg-avatar-default {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 600;
  color: white;
  background: var(--accent);
}

.msg-user .msg-avatar-default {
  background: rgba(255, 255, 255, 0.3);
}

.msg-body {
  max-width: min(80%, 640px);
  width: fit-content;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px 0;
}

.msg-user .msg-body {
  align-items: flex-end;
}

.msg-body-has-html {
  width: min(80%, 640px);
}

.msg-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  max-width: 100%;
  box-sizing: border-box;
}

.msg-bubble-has-html {
  width: 100%;
}

.msg-user .msg-bubble {
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 4px;
}

.msg-assistant .msg-bubble {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 4px;
}

.msg-nickname {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.msg-user .msg-nickname {
  color: rgba(255, 255, 255, 0.85);
}

.msg-content {
  white-space: pre-wrap;
}

.msg-content-has-html {
  width: 100%;
  min-width: 0;
}

.msg-content-text {
  white-space: pre-wrap;
}

.msg-content-markdown {
  white-space: normal;
  line-height: 1.6;
}

.msg-content-markdown p {
  margin: 0;
}

.msg-content-markdown p + p,
.msg-content-markdown p + ul,
.msg-content-markdown p + ol,
.msg-content-markdown p + pre,
.msg-content-markdown p + blockquote,
.msg-content-markdown ul + p,
.msg-content-markdown ol + p,
.msg-content-markdown pre + p,
.msg-content-markdown blockquote + p {
  margin-top: 4px;
}

.msg-content-markdown h1,
.msg-content-markdown h2,
.msg-content-markdown h3,
.msg-content-markdown h4,
.msg-content-markdown h5,
.msg-content-markdown h6 {
  margin: 10px 0 6px;
  line-height: 1.35;
}

.msg-content-markdown h1 { font-size: 1.08rem; }
.msg-content-markdown h2 { font-size: 1.03rem; }
.msg-content-markdown h3 { font-size: 0.98rem; }
.msg-content-markdown h4,
.msg-content-markdown h5,
.msg-content-markdown h6 { font-size: 0.92rem; }

.msg-content-markdown ul,
.msg-content-markdown ol {
  margin: 8px 0;
  padding-left: 1.25em;
}

.msg-content-markdown li + li {
  margin-top: 3px;
}

.msg-content-markdown code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  padding: 1px 4px;
  border-radius: 6px;
  background: rgba(148, 163, 184, 0.16);
}

.msg-content-markdown pre {
  margin: 8px 0;
  padding: 10px;
  border-radius: 8px;
  overflow: auto;
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid var(--border-color);
}

.msg-content-markdown pre code {
  display: block;
  padding: 0;
  background: transparent;
}

.msg-content-markdown blockquote {
  margin: 8px 0;
  padding: 6px 10px;
  border-left: 3px solid rgba(125, 211, 252, 0.7);
  background: rgba(125, 211, 252, 0.08);
  border-radius: 6px;
}

.msg-content-markdown hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 10px 0;
}

.msg-content-text + .msg-content-text {
  margin-top: 6px;
}

.msg-content-text + .msg-html-preview,
.msg-html-preview + .msg-content-text,
.msg-html-preview + .msg-html-preview {
  margin-top: 8px;
}

.msg-html-preview {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 44px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  box-shadow: none;
  overflow: hidden;
}

.autoimg {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
}
.autoimg.autoimg-pending {
  display: block;
  width: 100%;
  min-height: 80px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px dashed rgba(255, 255, 255, 0.2);
  position: relative;
}
.autoimg.autoimg-pending::after {
  content: "生成中…";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 12px;
  color: rgba(229, 231, 235, 0.7);
}
.autoimg.autoimg-error {
  display: block;
  min-height: 40px;
  padding: 10px;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: rgba(252, 165, 165, 1);
  font-size: 12px;
}

.msg-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.msg-user .msg-actions {
  align-self: flex-end;
}

.msg-btn-delete,
.msg-btn-edit,
.msg-btn-play,
.msg-btn-audio-list,
.msg-btn-immediate,
.msg-btn-compression,
.msg-btn-greeting-nav {
  padding: 4px 10px;
  font-size: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
}

.msg-btn-delete:hover,
.msg-btn-edit:hover,
.msg-btn-play:hover,
.msg-btn-audio-list:hover,
.msg-btn-immediate:hover,
.msg-btn-compression:hover,
.msg-btn-greeting-nav:hover {
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.msg-btn-compression.is-compressed {
  border-color: rgba(251, 191, 36, 0.65);
  color: #fcd34d;
  background: rgba(251, 191, 36, 0.08);
}

.msg-btn-compression.is-compressed:hover {
  color: #fde68a;
  border-color: rgba(251, 191, 36, 0.85);
}

.msg-edit-compression-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  line-height: 1.4;
}

.compression-section {
  margin-top: 16px;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
}

.compression-section + .compression-section {
  margin-top: 12px;
}

.compression-section-title {
  font-weight: 600;
  margin-bottom: 8px;
}

.compression-prompt-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 6px;
}

.msg-btn-play {
  border-color: rgba(96, 165, 250, 0.6);
  color: #93c5fd;
}

.msg-btn-play.playing {
  border-color: rgba(248, 113, 113, 0.7);
  color: #fca5a5;
}

.msg-btn-immediate {
  border-color: rgba(74, 222, 128, 0.65);
  color: #86efac;
}

.msg-btn-audio-list {
  border-color: rgba(167, 139, 250, 0.65);
  color: #c4b5fd;
}

.tts-audio-list-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 903;
  background: rgba(0, 0, 0, 0.45);
  align-items: center;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-bottom));
  box-sizing: border-box;
  overflow: hidden;
}

.tts-audio-list-panel {
  width: min(440px, 100%);
  max-height: min(calc(100vh - 32px), min(70vh, 560px));
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.tts-audio-list-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-color);
}

.tts-audio-list-title {
  font-weight: 600;
  font-size: 0.95rem;
}

.tts-audio-list-close {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
}

.tts-audio-list-close:hover {
  color: var(--text-primary);
}

.tts-audio-list-body {
  flex: 1 1 auto;
  min-height: 0;
  max-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 8px 12px;
}

.tts-audio-list-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 8px;
  align-items: start;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.8rem;
}

.tts-audio-list-row:last-child {
  border-bottom: none;
}

.tts-audio-list-idx {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.tts-audio-list-preview {
  word-break: break-word;
  color: var(--text-secondary);
}

.tts-audio-list-status {
  white-space: nowrap;
  color: var(--text-muted);
  font-size: 0.72rem;
}

.tts-audio-list-footer {
  flex-shrink: 0;
  padding: 12px 14px;
  border-top: 1px solid var(--border-color);
}

.tts-audio-list-resume:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.msg-greeting-switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-right: 2px;
}

.msg-btn-greeting-nav {
  min-width: 28px;
  padding: 4px 8px;
}

.msg-greeting-switch-label {
  min-width: 34px;
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.character-prompt-list {
  max-height: 220px;
  overflow: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--bg-panel);
}

.character-prompt-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: 6px 8px;
  text-align: left;
  cursor: pointer;
}

.character-prompt-item.active {
  border-color: rgba(96, 165, 250, 0.8);
  box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.25) inset;
}

.character-prompt-item-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 0.85rem;
}

.audio-voice-item-meta {
  margin-left: auto;
  font-size: 0.74rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.character-prompt-list-empty {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 8px 6px;
}

#sessionAudioVoicePreview,
#ccAudioVoicePreview {
  width: 100%;
  max-width: 420px;
}

.prompt-attr-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

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

.llm-api-row .form-input {
  flex: 1;
}

#llmApiKeyToggleBtn {
  min-width: 64px;
  flex-shrink: 0;
}

.msg-edit-wrap {
  width: 100%;
  max-width: 100%;
  padding: 8px 0;
}

.msg-edit-textarea {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  font-size: 0.9rem;
  font-family: inherit;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  color: var(--text-primary);
  resize: none;
  overflow: hidden;
}

.msg-edit-textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.msg-edit-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.msg-edit-actions .btn {
  padding: 6px 14px;
  font-size: 0.85rem;
}

.msg-assistant .msg-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

/* ========== 底部输入栏 ========== */

.input-dock {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  padding: 10px 16px 12px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

.input-dock-editor-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
}

/* 回复角色：输入框左侧入口 + 上推二级面（含搜索与列表） */
.send-agent-menu-wrap {
  position: relative;
  flex: 0 0 auto;
  min-width: 0;
  max-width: 40vw;
}

.send-agent-menu-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  min-width: 0;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-panel);
  color: var(--text-primary);
  font-size: 0.9rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

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

.send-agent-menu-btn-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1 1 auto;
  text-align: left;
}

.send-agent-menu-btn-chevron {
  flex: 0 0 auto;
  font-size: 0.7rem;
  opacity: 0.75;
}

.send-agent-menu-btn-dot {
  flex: 0 0 auto;
}

@keyframes send-agent-menu-btn-selected {
  0% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent, #60a5fa) 0%, transparent);
  }
  40% {
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent, #60a5fa) 50%, transparent);
  }
  100% {
    box-shadow: 0 0 0 0 transparent;
  }
}

.send-agent-menu-btn--just-selected {
  animation: send-agent-menu-btn-selected 0.5s ease-out both;
}

@media (prefers-reduced-motion: reduce) {
  .send-agent-menu-btn--just-selected {
    animation: none;
  }
}

/* [hidden] 的 display:none 会被下方 .send-agent-dropdown 的 display:flex 覆盖，必须显式关 */
.send-agent-dropdown[hidden] {
  display: none !important;
}

.send-agent-dropdown {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  min-width: min(100vw - 32px, 280px);
  max-width: min(100vw - 24px, 320px);
  max-height: min(50vh, 360px);
  padding: 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-panel);
  box-shadow: 0 8px 28px color-mix(in srgb, #000 35%, transparent);
}

.send-agent-dropdown-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 8px 6px 10px;
  border-bottom: 1px solid color-mix(in srgb, var(--border-color) 90%, transparent);
  flex: 0 0 auto;
}

.send-agent-dropdown-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.send-agent-dropdown-close {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin: -4px -4px -4px 0;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.send-agent-dropdown-close:hover,
.send-agent-dropdown-close:focus {
  background: color-mix(in srgb, var(--text-primary) 8%, var(--bg-panel));
  color: var(--text-primary);
  outline: none;
}

.send-agent-dropdown-body {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  padding: 8px;
  padding-top: 6px;
}

.send-agent-search {
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 6px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-secondary, var(--bg-panel));
  color: var(--text-primary);
  font-size: 0.9rem;
}

.send-agent-search:focus {
  border-color: var(--accent);
  outline: none;
}

.send-agent-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.send-agent-list-empty {
  padding: 10px 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}

.send-agent-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-primary);
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
}

.send-agent-list-item:hover,
.send-agent-list-item:focus {
  background: color-mix(in srgb, var(--text-primary) 6%, var(--bg-panel));
  outline: none;
}

.send-agent-list-item.is-selected {
  background: color-mix(in srgb, var(--accent, #60a5fa) 12%, var(--bg-panel));
}

.send-agent-list-item-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1;
}

.send-agent-state-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #22c55e;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--text-primary) 20%, transparent);
}

.send-agent-state-dot[data-state="idle"] {
  background: #22c55e;
  box-shadow: none;
}

.send-agent-state-dot[data-state="thinking"] {
  background: #ef4444;
  box-shadow: 0 0 8px color-mix(in srgb, #ef4444 55%, transparent);
}

.send-agent-state-dot[data-state="responding"] {
  background: #ef4444;
  box-shadow: 0 0 8px color-mix(in srgb, #ef4444 55%, transparent);
}

.send-agent-select-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

.session-character-toolbar-row .form-select {
  flex: 1;
  min-width: 0;
}

.input-dock .text-input {
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-panel);
}

.input-dock .text-input:focus {
  border-color: var(--accent);
  outline: none;
}

.status-widget {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
}

.status-widget .status-ring-wrapper {
  width: 32px;
  height: 32px;
}

.status-widget .status-ring-wrapper .status-dot {
  width: 12px;
  height: 12px;
}

.status-widget .status-state-label {
  font-size: 0.8rem;
  font-weight: 600;
}

.status-widget .status-detail {
  font-size: 0.7rem;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.input-dock .status-section {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
}

.input-dock .status-section .status-ring-wrapper {
  width: 32px;
  height: 32px;
}

.input-dock .status-section .status-dot {
  width: 12px;
  height: 12px;
}

.input-dock .status-section .status-info {
  min-width: 0;
}

.input-dock .status-section .status-state-label {
  font-size: 0.8rem;
}

.input-dock .status-section .status-detail {
  font-size: 0.7rem;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-float-scroll-actions {
  position: fixed;
  right: 14px;
  bottom: 86px;
  z-index: 35;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-float-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background: var(--bg-panel);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  transition: transform 0.12s ease, border-color 0.2s ease, background 0.2s ease;
}

.chat-float-btn:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
  background: var(--bg-secondary);
}

.chat-float-btn:active {
  transform: scale(0.95);
}

/* ========== 登录页 ========== */

.login-page {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.login-card {
  width: 100%;
  max-width: 360px;
  padding: 32px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
}

.login-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 8px;
  text-align: center;
}

.login-subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  text-align: center;
  margin-bottom: 24px;
}

.login-input {
  width: 100%;
  padding: 12px 16px;
  margin-bottom: 16px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 1rem;
}

.login-input:focus {
  border-color: var(--accent);
  outline: none;
}

.login-submit {
  width: 100%;
  padding: 12px;
}

/* ========== 全局设置（居中弹窗） ========== */

.drawer-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(560px, 94vw);
  max-width: 560px;
  /* 固定高度：内容在 .drawer-body 内滚动 */
  height: min(640px, 85vh);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  z-index: 903;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.drawer-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

.drawer-title {
  font-size: 1rem;
  font-weight: 600;
}

.drawer-close {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  border-radius: 4px;
  transition: color 0.2s, background 0.2s;
}

.drawer-close:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.drawer-tabs {
  flex-shrink: 0;
  display: flex;
  flex-wrap: nowrap;
  gap: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  border-bottom: 1px solid var(--border-color);
}

.drawer-tab {
  flex: 0 0 auto;
  padding: 10px 12px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
}

.drawer-tab:hover {
  color: var(--text-primary);
}

.drawer-tab.active {
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
  margin-bottom: -1px;
}

.drawer-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
}

.drawer-tab-pane {
  display: none;
}

.drawer-tab-pane.active {
  display: block;
}

.llm-preset-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.llm-preset-save-actions {
  margin-top: 4px;
}

.drawer-body .config-item {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  margin-bottom: 16px;
}

.preset-manager {
  margin: 12px 0 16px;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
}

.preset-manager-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.preset-title {
  font-size: 0.9rem;
  font-weight: 600;
}

.preset-import-hint {
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--text-secondary);
  margin: 0 0 12px;
}

.preset-subnav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}

.preset-group-nav-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.preset-subnav-btn {
  font-size: 0.8rem;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  color: var(--text-primary);
  cursor: pointer;
}

.preset-subnav-btn:hover {
  border-color: var(--accent, #3b82f6);
}

.preset-subnav-btn.active {
  border-color: var(--accent, #3b82f6);
  background: var(--bg-panel);
  box-shadow: 0 0 0 1px var(--accent, #3b82f6) inset;
}

.preset-filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  margin-bottom: 8px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.preset-filter-row label {
  white-space: nowrap;
}

.preset-pool-as-group-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.preset-pool-as-group-row .form-input {
  flex: 1;
  min-width: 120px;
  max-width: 240px;
}

.preset-list .preset-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.preset-list .preset-item .preset-item-title {
  flex: 1;
  min-width: 0;
}

.preset-item-hint {
  font-size: 0.75rem;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.preset-group-toolbar {
  margin-bottom: 8px;
}

.preset-group-rename-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.preset-group-rename-row .form-input {
  flex: 1;
  min-width: 140px;
  max-width: 320px;
}

.preset-group-section-title {
  font-size: 0.88rem;
  font-weight: 600;
  margin: 8px 0 6px;
  color: var(--text-primary);
}

.preset-group-member-row,
.preset-group-panel .preset-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.preset-group-member-row .preset-item-title,
.preset-group-panel .preset-item .preset-item-title {
  flex: 1;
  min-width: 0;
  text-align: left;
}

.preset-group-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 8px 0 4px;
}

.preset-scope-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.preset-scope-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.preset-scope-toggle {
  display: flex;
  gap: 16px;
}

.preset-scope-option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.preset-scope-option input {
  cursor: pointer;
}

.preset-category-row {
  margin-bottom: 10px;
}

.form-row-fields .form-group {
  margin-bottom: 8px;
}

.form-row-fields {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 8px 12px;
  margin-bottom: 10px;
}

.form-row-fields .form-group label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.form-row-fields input.form-input,
.form-row-fields select.form-input {
  width: 100%;
  padding: 6px 8px;
}

.preset-category-row label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.preset-list {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
}

.preset-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
}

.preset-item:last-child {
  border-bottom: none;
}

.preset-item.active {
  background: rgba(124, 58, 237, 0.2);
}

.preset-item-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.85rem;
}

.preset-preview {
  margin-top: 12px;
  border-top: 1px solid var(--border-color);
  padding-top: 12px;
}

.preset-preview-head {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}

.preset-enabled-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

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

.tts-filter-manager {
  margin: 4px 0 0;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
}

.tts-filter-header {
  margin-bottom: 10px;
}

.tts-filter-title {
  display: block;
  font-size: 0.92rem;
  font-weight: 600;
}

.tts-filter-subtitle {
  display: block;
  margin-top: 2px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.tts-filter-form {
  padding: 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  margin-bottom: 10px;
}

.tts-filter-form .form-group {
  margin-bottom: 10px;
}

.tts-filter-form .form-group:last-child {
  margin-bottom: 0;
}

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

.tts-filter-list {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
}

.tts-filter-empty {
  padding: 12px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.tts-filter-item {
  padding: 10px;
  border-bottom: 1px solid var(--border-color);
}

.tts-filter-item:last-child {
  border-bottom: none;
}

.tts-filter-item-main {
  display: grid;
  grid-template-columns: 1fr 16px 1fr;
  gap: 8px;
  align-items: center;
}

.tts-filter-token {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 6px 8px;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.78rem;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tts-filter-arrow {
  text-align: center;
  color: var(--text-secondary);
}

.tts-filter-item-actions {
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.btn-secondary {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  cursor: pointer;
  margin-top: 8px;
  transition: border-color 0.2s, color 0.2s;
}

.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.switch-user-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.backup-import-options {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 6px;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.backup-import-options label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.current-user-badge {
  display: inline-flex;
  align-items: center;
  max-width: 240px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  color: var(--text-secondary);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ========== 二级弹窗遮罩（全局设置 / 会话设置 / 账号导入导出） ========== */

.modal-overlay,
.drawer-overlay {
  position: fixed;
  inset: 0;
  z-index: 902;
  background: rgba(0, 0, 0, 0.52);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* ========== 会话设置弹窗 ========== */

.modal-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90vw;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  z-index: 903;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

.modal-title {
  font-size: 1rem;
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  border-radius: 4px;
  transition: color 0.2s, background 0.2s;
}

.modal-close:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
}

.modal-body {
  padding: 16px;
}

.account-export-panel {
  max-width: min(520px, 96vw);
}

.account-export-hint {
  margin: 0 0 12px;
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--text-secondary);
}

.account-export-include-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
}

.account-export-opt {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--text-primary);
  cursor: pointer;
  user-select: none;
}

.account-export-opt input {
  flex-shrink: 0;
}

.account-export-session-section {
  margin-bottom: 12px;
}

.account-export-subtitle {
  font-size: 0.88rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.account-export-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.account-export-session-list {
  max-height: min(280px, 40vh);
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  background: var(--bg-panel);
  margin-bottom: 12px;
}

.account-export-empty {
  font-size: 0.88rem;
  color: var(--text-muted);
  padding: 6px 2px;
}

.account-export-session-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.account-export-session-row:hover {
  background: rgba(255, 255, 255, 0.04);
}

.account-export-session-row input[type="checkbox"] {
  flex-shrink: 0;
}

.account-modal-session-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--border-color);
}

.account-modal-session-avatar-default {
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 0.8rem;
  font-weight: 600;
}

.account-export-session-text {
  flex: 1;
  min-width: 0;
}

.account-export-session-title {
  display: block;
  font-size: 0.9rem;
  color: var(--text-primary);
  word-break: break-word;
}

.account-export-size-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.session-settings-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.session-settings-tab {
  border: 1px solid var(--border-color);
  background: var(--bg-panel);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.85rem;
  cursor: pointer;
}

.session-settings-tab.active {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.session-settings-pane {
  display: none;
}

.session-settings-pane.active {
  display: block;
}

.character-card-list-header {
  margin-bottom: 10px;
}

.character-card-list-root {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.character-card-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
}

.character-card-list-name {
  flex: 1;
  min-width: 0;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.character-card-list-actions {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  gap: 6px;
}

.character-card-list-empty {
  padding: 12px;
  font-size: 0.88rem;
  color: var(--text-muted);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-sm);
}

.form-hint-muted {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--text-muted);
}

.character-card-edit-panel {
  max-width: min(560px, 96vw);
}

.character-card-edit-body {
  max-height: min(78vh, 720px);
  overflow-y: auto;
}

.character-card-edit-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.character-card-edit-tab {
  border: 1px solid var(--border-color);
  background: var(--bg-panel);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.85rem;
  cursor: pointer;
}

.character-card-edit-tab.active {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.character-card-edit-pane {
  display: none;
}

.character-card-edit-pane.active {
  display: block;
}

.character-card-edit-footer-actions {
  margin-top: 4px;
}

.session-character-meta {
  margin-top: -6px;
  margin-bottom: 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.section-title-label {
  margin-bottom: 0 !important;
}

.section-title-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  border-color: var(--accent);
  outline: none;
}

.form-select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 34px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position:
    calc(100% - 16px) calc(50% - 2px),
    calc(100% - 11px) calc(50% - 2px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

.form-select:hover {
  border-color: var(--text-muted);
}

.form-select:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.form-select option {
  background: var(--bg-panel);
  color: var(--text-primary);
}

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

.avatar-edit {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar-preview {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--border-color);
  flex-shrink: 0;
  overflow: hidden;
}

.avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.modal-actions {
  margin-top: 20px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.btn-danger {
  background: #dc2626;
  border: 1px solid #dc2626;
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.btn-danger:hover {
  background: #b91c1c;
  border-color: #b91c1c;
}

/* ========== 标题 ========== */

.header {
  text-align: center;
  margin-bottom: 32px;
}

.header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

/* ========== 状态指示器 ========== */

.status-section {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 24px;
  padding: 12px 24px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
}

/* 状态圆点容器 */
.status-ring-wrapper {
  position: relative;
  width: 56px;
  height: 56px;
  flex-shrink: 0;
}

/* 中心状态圆点 */
.status-ring-wrapper .status-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-idle);
  transform: translate(-50%, -50%);
  transition: background 0.3s ease, box-shadow 0.3s ease;
}

/* 状态信息文本 */
.status-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 100px;
}

.status-state-label {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.status-detail {
  font-size: 0.75rem;
  font-family: "SF Mono", "Fira Code", monospace;
  color: var(--text-muted);
  line-height: 1.3;
  min-height: 1em;
}

/* ---------- 各状态样式 ---------- */

/* idle */
.state-idle .status-dot {
  background: var(--color-idle);
}
.state-idle .status-state-label {
  color: var(--text-secondary);
}

/* thinking */
.state-thinking .status-dot {
  background: var(--color-thinking);
  animation: spin 1.2s linear infinite;
  box-shadow: 0 0 12px var(--color-thinking);
  border-radius: 4px;
}
.state-thinking .status-state-label {
  color: var(--color-thinking);
}

/* responding */
.state-responding .status-dot {
  background: var(--color-responding);
  animation: flow 1.5s ease-in-out infinite;
  box-shadow: 0 0 14px var(--color-responding);
}
.state-responding .status-state-label {
  color: var(--color-responding);
}

@keyframes spin {
  0% { transform: translate(-50%, -50%) rotate(0deg); }
  100% { transform: translate(-50%, -50%) rotate(360deg); }
}

@keyframes flow {
  0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.8; }
  50% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; }
}

/* ========== 控制按钮 ========== */

.controls {
  display: flex;
  justify-content: center;
  margin-bottom: 24px;
}

.btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 32px;
  border: none;
  border-radius: 999px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  outline: none;
}

.btn-xs {
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 0.74rem;
  font-weight: 600;
}

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

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.4);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-icon {
  font-size: 0.9rem;
}

/* ========== 文本输入 ========== */

.text-input-section {
  margin-bottom: 16px;
}

.text-input-wrapper {
  display: flex;
  gap: 8px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 6px 6px 6px 16px;
  transition: border-color 0.2s ease;
}

.text-input-wrapper:focus-within {
  border-color: var(--accent);
}

.text-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  min-width: 0;
}

.text-input::placeholder {
  color: var(--text-muted);
}

.btn-regenerate {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 1.05rem;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: white;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, transform 0.1s ease;
}
.btn-regenerate:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: scale(1.05);
}
.btn-regenerate:active:not(:disabled) {
  transform: scale(0.95);
}
.btn-regenerate:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-send {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: white;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, transform 0.1s ease;
}

.btn-send:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.btn-send:active {
  transform: scale(0.95);
}

.btn-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* 历史上下文开关 - 无文字图标样式 */
.history-checkbox-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  padding: 0;
  cursor: pointer;
  user-select: none;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  transition: transform 0.1s ease;
}

.history-checkbox-wrapper:hover {
  transform: scale(1.05);
}

.history-checkbox {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.history-toggle-btn {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.history-toggle-icon {
  position: relative;
  width: 16px;
  height: 16px;
  border: 1.8px solid currentColor;
  border-radius: 50%;
  opacity: 0.9;
}

.history-toggle-icon::before,
.history-toggle-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  background: currentColor;
  border-radius: 2px;
  transform-origin: bottom center;
}

.history-toggle-icon::before {
  width: 2px;
  height: 5px;
  transform: translate(-50%, -100%);
}

.history-toggle-icon::after {
  width: 2px;
  height: 6px;
  transform: translate(-15%, -85%) rotate(45deg);
}

.history-toggle-btn::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 2px;
  background: rgba(248, 113, 113, 0.85);
  transform: rotate(-35deg);
  border-radius: 2px;
  opacity: 0.95;
  transition: opacity 0.2s ease;
}

.history-checkbox:checked + .history-toggle-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.35);
}

.history-checkbox:not(:checked) + .history-toggle-btn:hover {
  border-color: var(--text-muted);
  background: rgba(42, 42, 62, 0.8);
}

.history-checkbox:checked + .history-toggle-btn::after {
  opacity: 0;
}

.history-checkbox:focus-visible + .history-toggle-btn {
  outline: 2px solid rgba(124, 58, 237, 0.75);
  outline-offset: 2px;
}

/* 任务队列面板 */
.queue-panel {
  margin-top: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.queue-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border-color);
}

.queue-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.queue-badge {
  font-size: 0.65rem;
  font-weight: 700;
  color: white;
  background: var(--accent);
  padding: 0 6px;
  border-radius: 999px;
  min-width: 18px;
  text-align: center;
  line-height: 1.5;
}

.queue-clear-btn {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}

.queue-clear-btn:hover {
  color: var(--color-error);
  background: rgba(248, 113, 113, 0.1);
}

.queue-list {
  max-height: 200px;
  overflow-y: auto;
}

.queue-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.8rem;
  transition: background 0.15s;
}

.queue-item:last-child {
  border-bottom: none;
}

.queue-item:hover {
  background: rgba(255, 255, 255, 0.02);
}

.queue-item-index {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--border-color);
  padding: 0 6px;
  border-radius: 999px;
  flex-shrink: 0;
  line-height: 1.6;
}

.queue-item-text {
  flex: 1;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.queue-item-status {
  flex-shrink: 0;
  font-size: 0.65rem;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 999px;
}

.queue-item-status.waiting {
  color: var(--color-warning);
  background: rgba(250, 204, 21, 0.1);
}

.queue-item-status.executing {
  color: var(--color-thinking);
  background: rgba(96, 165, 250, 0.15);
  animation: status-pulse 1.5s ease-in-out infinite;
}

@keyframes status-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.queue-item-remove {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.7rem;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}

.queue-item:hover .queue-item-remove {
  opacity: 1;
}

.queue-item-remove:hover {
  color: var(--color-error);
}

/* ========== 面板 ========== */

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.panel-icon {
  font-size: 1rem;
}

.panel-body {
  padding: 16px;
}

.transcript-area,
.ai-reply-area {
  min-height: 80px;
  max-height: 300px;
  overflow-y: auto;
  font-size: 0.95rem;
  line-height: 1.8;
  word-break: break-word;
}

.placeholder {
  color: var(--text-muted);
  font-style: italic;
}

.transcript-interim {
  color: var(--text-secondary);
  font-style: italic;
}

.transcript-final {
  color: var(--text-primary);
}

.ai-reply-text {
  color: var(--text-primary);
  white-space: pre-wrap;
}

/* 打字机光标 */
.typing-cursor {
  display: none;
  width: 2px;
  height: 1.1em;
  background: var(--color-responding);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.8s step-end infinite;
}

.typing-cursor.active {
  display: inline-block;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ========== 对话记录 ========== */

.history-panel {
  margin-bottom: 16px;
}

.history-panel details {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

.history-panel summary {
  padding: 10px 16px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.history-count {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-secondary);
  padding: 1px 7px;
  border-radius: 999px;
}

.history-body {
  padding: 8px 12px 12px;
  max-height: 500px;
  overflow-y: auto;
}

.history-empty {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-style: italic;
  text-align: center;
  padding: 12px 0;
}

.history-entry {
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.history-entry:last-child {
  margin-bottom: 0;
}

.history-entry-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.history-entry-index {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--border-color);
  padding: 1px 8px;
  border-radius: 999px;
}

.history-entry-time {
  font-size: 0.7rem;
  font-family: "SF Mono", "Fira Code", monospace;
  color: var(--text-muted);
}

.history-user,
.history-ai {
  font-size: 0.85rem;
  line-height: 1.6;
  padding: 4px 0;
}

.history-user {
  color: var(--color-thinking);
}

.history-user::before {
  content: "用户：";
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.75rem;
}

.history-ai {
  color: var(--text-primary);
  white-space: pre-wrap;
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px dashed var(--border-color);
}

.history-ai::before {
  content: "AI：";
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.75rem;
}

/* ========== 配置面板 ========== */

.config-panel,
.log-panel {
  margin-bottom: 16px;
}

.config-panel details,
.log-panel details {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

.config-panel summary,
.log-panel summary {
  padding: 10px 16px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  user-select: none;
}

.config-body {
  padding: 12px 16px 16px;
}

.config-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.config-item label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.config-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.config-control input[type="range"] {
  width: 160px;
  accent-color: var(--accent);
}

.config-control span {
  font-size: 0.8rem;
  color: var(--text-muted);
  min-width: 50px;
  text-align: right;
}

/* ========== 日志 ========== */

.log-body {
  padding: 8px 16px 12px;
  max-height: 200px;
  overflow-y: auto;
  font-family: "SF Mono", "Fira Code", "Cascadia Code", monospace;
  font-size: 0.75rem;
  line-height: 1.6;
  color: var(--text-muted);
}

.log-entry {
  padding: 1px 0;
}

.log-entry .log-time {
  color: var(--text-muted);
  margin-right: 6px;
}

.log-entry.log-info {
  color: var(--color-thinking);
}

.log-entry.log-warn {
  color: var(--color-warning);
}

.log-entry.log-error {
  color: var(--color-error);
}

/* ========== 滚动条 ========== */

::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ========== 响应式 ========== */

@media (max-width: 480px) {
  .container {
    padding: 16px 12px;
  }

  .header h1 {
    font-size: 1.4rem;
  }

  .btn {
    padding: 10px 24px;
    font-size: 0.9rem;
  }
}

/* ========== 移动端布局：侧边栏置顶 ========== */
@media (max-width: 900px) and (hover: none) and (pointer: coarse) {
  :root {
    --mobile-topbar-height: 72px;
    /* 角色横条 + 输入行（约两行） */
    --mobile-dock-height: 118px;
    --mobile-topbar-total-height: calc(var(--mobile-topbar-height) + env(safe-area-inset-top, 0px));
  }

  html,
  body {
    width: 100%;
    max-width: 100vw;
    height: 100%;
    overflow-x: hidden;
    overflow-y: hidden;
  }

  .app-shell {
    flex-direction: column;
    width: 100%;
    height: var(--app-vh, 100dvh);
    max-width: 100vw;
    overflow: hidden;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 30;
    width: 100%;
    min-width: 0;
    height: var(--mobile-topbar-total-height);
    max-height: var(--mobile-topbar-total-height);
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    padding: calc(8px + env(safe-area-inset-top, 0px)) 10px 8px;
    gap: 10px;
    flex-direction: row;
    align-items: center;
    overflow: hidden;
  }

  .sidebar-new-session {
    margin: 0;
    flex-shrink: 0;
    white-space: nowrap;
  }

  .sidebar-session-list {
    flex: 1;
    min-width: 0;
    padding: 0;
    overflow-x: auto;
    overflow-y: hidden;
    max-height: none;
    display: flex;
    align-items: stretch;
    gap: 6px;
  }

  .sidebar-session-item {
    margin-bottom: 0;
    flex-shrink: 0;
    min-width: 130px;
    max-width: 72vw;
  }

  .sidebar-settings {
    margin: 0;
    padding: 10px;
    align-self: auto;
    flex-shrink: 0;
  }

  .main-area {
    flex: 1;
    min-height: 0;
    width: 100%;
    height: var(--app-vh, 100dvh);
    max-width: 100vw;
    margin-top: 0;
    padding-top: var(--mobile-topbar-total-height);
    padding-bottom: 0;
    overflow: hidden;
  }

  .chat-main,
  .queue-panel {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .chat-messages {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    padding-bottom: 16px;
  }

  .chat-main {
    box-sizing: border-box;
    padding-bottom: calc(var(--mobile-dock-height) + env(safe-area-inset-bottom, 0px));
  }

  body.mobile-keyboard-open .chat-main {
    padding-bottom: calc(var(--mobile-dock-height) + 8px);
  }

  .input-dock {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    min-height: var(--mobile-dock-height);
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .input-dock .status-section {
    gap: 0;
    padding: 4px;
    min-width: 40px;
    width: 40px;
    justify-content: center;
  }

  .input-dock .status-section .status-info {
    display: none;
  }

  .input-dock .status-section .status-ring-wrapper {
    width: 28px;
    height: 28px;
  }

  .input-dock .status-section .status-dot {
    width: 10px;
    height: 10px;
  }

  .chat-float-scroll-actions {
    right: 12px;
    bottom: calc(var(--mobile-dock-height) + env(safe-area-inset-bottom, 0px) + 12px);
  }

  body.mobile-keyboard-open .input-dock {
    padding-bottom: 8px;
  }

  body.mobile-keyboard-open .chat-float-scroll-actions {
    bottom: calc(var(--mobile-dock-height) + 10px);
  }
}
