/* ============ CSS Variables ============ */
:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #f0f0f3;
  --surface-3: #e8e8ec;
  --border: #e0e0e5;
  --border-light: #ededf0;
  --text: #1a1a2e;
  --text-secondary: #6b6b80;
  --text-muted: #9a9ab0;
  --accent: #4a6cf7;
  --accent-hover: #3a5ce5;
  --accent-light: rgba(74, 108, 247, 0.08);
  --danger: #e5484d;
  --danger-light: rgba(229, 72, 77, 0.08);
  --user-bubble: #4a6cf7;
  --user-text: #ffffff;
  --ai-bubble: #ffffff;
  --shadow: 0 2px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 20px;
  --sidebar-w: 280px;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg: #141416;
  --surface: #1e1e22;
  --surface-2: #28282e;
  --surface-3: #33333a;
  --border: #2e2e35;
  --border-light: #25252b;
  --text: #e8e8ee;
  --text-secondary: #a0a0b0;
  --text-muted: #6a6a7a;
  --accent: #6b8aff;
  --accent-hover: #5a7aef;
  --accent-light: rgba(107, 138, 255, 0.12);
  --danger: #ff6b6b;
  --danger-light: rgba(255, 107, 107, 0.1);
  --user-bubble: #4a6cf7;
  --user-text: #ffffff;
  --ai-bubble: #28282e;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
}

/* ============ Reset ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }
*::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background var(--transition), color var(--transition);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.hidden { display: none !important; }
button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
svg { display: block; }

/* ============ Login ============ */
.login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 20px;
}
.login-card {
  text-align: center;
  width: 100%;
  max-width: 360px;
}
.login-logo {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  color: #fff;
  font-weight: 800;
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  box-shadow: 0 4px 20px rgba(74, 108, 247, 0.3);
}
.login-card h1 { font-size: 28px; font-weight: 700; margin-bottom: 8px; }
.login-sub { color: var(--text-secondary); margin-bottom: 28px; font-size: 15px; }
.login-input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  outline: none;
  margin-bottom: 16px;
  transition: border var(--transition), box-shadow var(--transition);
}
.login-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.login-tabs { display: flex; gap: 8px; margin-bottom: 22px; background: var(--surface-2); padding: 4px; border-radius: var(--radius); }
.login-tab { flex: 1; padding: 10px 0; border: none; background: transparent; color: var(--text-secondary); font-size: 15px; font-weight: 600; border-radius: calc(var(--radius) - 4px); cursor: pointer; transition: background var(--transition), color var(--transition); }
.login-tab.active { background: var(--accent); color: #fff; }
.login-form { width: 100%; }
.login-form.hidden { display: none; }
.login-hint { font-size: 12px; color: var(--text-secondary); margin: 0 0 16px; line-height: 1.5; }
.code-row { display: flex; gap: 10px; align-items: stretch; margin-bottom: 12px; }
.code-row .code-input { flex: 1; margin-bottom: 0; }
.code-row .btn-secondary { white-space: nowrap; }

/* ============ Buttons ============ */
.btn-primary {
  background: var(--accent);
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 15px;
  transition: background var(--transition), transform var(--transition);
  width: 100%;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
}
.btn-secondary:hover { background: var(--surface-2); color: var(--text); }

.btn-danger {
  background: var(--danger);
  color: #fff;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  transition: opacity var(--transition);
}
.btn-danger:hover { opacity: 0.85; }

.btn-text {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  font-size: 13px;
  transition: background var(--transition), color var(--transition);
}
.btn-text:hover { background: var(--surface-2); color: var(--accent); }

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ============ Chat View ============ */
.chat-view {
  display: flex;
  height: 100%;
}

/* ============ Sidebar ============ */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
  transition: transform var(--transition);
  z-index: 100;
}
.sidebar-header {
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border-light);
}
.sidebar-close { display: none; margin-left: auto; }
.btn-new-topic {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 12px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  transition: background var(--transition);
}
.btn-new-topic:hover { background: var(--accent-hover); }

.sidebar-section {
  padding: 12px;
  border-bottom: 1px solid var(--border-light);
}
.sidebar-section-topics {
  flex: 1;
  overflow-y: auto;
  border-bottom: none;
}
.sidebar-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  padding: 0 4px;
}

.persona-list, .topic-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 4px;
}

.persona-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  position: relative;
  -webkit-user-select: none;
  user-select: none;
}
.persona-item:hover { background: var(--surface-2); }
.persona-item.active { background: var(--accent-light); }
.persona-item.active .persona-name { color: var(--accent); }

/* Locked persona badge in chat header */
.persona-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.persona-badge-lock { flex: none; opacity: 0.7; }

/* New-topic persona picker */
.persona-picker {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 280px;
  overflow-y: auto;
}
.persona-pick-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.persona-pick-item:hover { background: var(--surface-2); }
.persona-pick-item.selected { border-color: var(--accent); background: var(--accent-light); }
.persona-pick-item input[type="radio"] { accent-color: var(--accent); flex: none; }
.persona-pick-item .persona-info { min-width: 0; }
.persona-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--surface-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}
.persona-info { flex: 1; min-width: 0; }
.persona-name {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.persona-desc {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.persona-info-btn {
  opacity: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: opacity var(--transition), color var(--transition);
}
.persona-item:hover .persona-info-btn { opacity: 1; }
.persona-info-btn:hover { color: var(--accent); }
.persona-delete {
  opacity: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: opacity var(--transition), color var(--transition);
}
.persona-item:hover .persona-delete { opacity: 1; }
.persona-delete:hover { color: var(--danger); }

/* ============ Persona Detail Modal ============ */
.persona-detail-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
  margin-bottom: 20px;
}
.persona-detail-avatar {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  font-weight: 600;
  overflow: hidden;
  flex-shrink: 0;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease;
}
.persona-detail-avatar:hover { transform: scale(1.04); box-shadow: 0 4px 16px rgba(0,0,0,.3); }
.persona-detail-avatar .avatar-img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

/* 头像放大查看（lightbox） */
#avatar-lightbox { z-index: 9000; }
#avatar-lightbox .modal-backdrop { backdrop-filter: none; background: transparent; }
.avatar-lightbox-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  cursor: zoom-out;
  user-select: none;
}
.avatar-lightbox-img {
  max-width: 90vw;
  max-height: 82vh;
  width: auto;
  height: auto;
  border-radius: 8px;
  object-fit: contain;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
  background: transparent;
}
.avatar-lightbox-text {
  width: 320px;
  height: 320px;
  border-radius: 16px;
  background: var(--accent-light);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 128px;
  font-weight: 700;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
}
.avatar-lightbox-hint { color: var(--text-muted); font-size: 13px; }
.persona-detail-head h2 { margin: 0; font-size: 20px; }
.persona-detail-body { display: flex; flex-direction: column; gap: 14px; }
.persona-detail-row { display: flex; gap: 12px; font-size: 14px; align-items: flex-start; }
.persona-detail-row-block { flex-direction: column; gap: 6px; }
.persona-detail-label { flex-shrink: 0; width: 40px; font-weight: 600; color: var(--text-secondary); }
.persona-detail-value { color: var(--text); line-height: 1.6; flex: 1; min-width: 0; word-break: break-word; }
.persona-detail-intro { white-space: pre-wrap; }
.persona-detail-uuid { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; color: var(--text-muted); word-break: break-all; user-select: all; }
.persona-detail-author { font-size: 12px; color: var(--text-muted); text-align: center; margin-top: 2px; }

/* 数据导出：选择列表 */
.export-select-toolbar { display: flex; align-items: center; justify-content: space-between; margin: 8px 0 6px; }
.export-check-all { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 13px; color: var(--text); user-select: none; }
.export-count { font-size: 12px; color: var(--text-muted); }
.export-list { max-height: 220px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 4px; }
.export-item { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 6px; cursor: pointer; user-select: none; }
.export-item:hover { background: var(--accent-light); }
.export-item input { flex-shrink: 0; margin: 0; cursor: pointer; }
.export-item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.export-item-name { font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.export-item-meta { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.export-empty { padding: 14px; text-align: center; color: var(--text-muted); font-size: 13px; }

.topic-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  position: relative;
}
.topic-item:hover { background: var(--surface-2); }
.topic-item.active { background: var(--accent-light); }
.topic-item.active .topic-name { color: var(--accent); }
.topic-icon {
  flex-shrink: 0;
  color: var(--text-muted);
}
.topic-name {
  flex: 1;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topic-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity var(--transition);
}
.topic-item:hover .topic-actions { opacity: 1; }

/* 模型回复期间锁定话题切换：侧栏话题项与「新建对话」按钮置灰且不可点击，
   内部删除/重命名按钮也随之禁用，避免回复途中误操作。 */
body.streaming-lock #topic-list .topic-item,
body.streaming-lock #custom-conv-list .topic-item,
body.streaming-lock #new-topic-btn {
  opacity: .45;
  cursor: not-allowed;
  pointer-events: none;
}
.topic-action-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
}
.topic-action-btn:hover { background: var(--surface-3); color: var(--text); }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* 积分面板 + 签到按钮 */
.sidebar-credits {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  margin: 0 8px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.credits-info {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}
.credits-label {
  font-size: 12px;
  color: var(--text-muted);
}
.credits-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.btn-checkin {
  flex-shrink: 0;
  padding: 6px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), opacity var(--transition);
}
.btn-checkin:hover { background: var(--accent-hover); }
.btn-checkin:disabled,
.btn-checkin.checked {
  background: var(--surface-3);
  color: var(--text-muted);
  cursor: default;
  opacity: .8;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  min-width: 0;
}
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}
.sidebar-user span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-footer-actions {
  display: flex;
  gap: 4px;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 99;
  opacity: 0;
  transition: opacity var(--transition);
}
.sidebar-overlay.active { display: block; opacity: 1; }

/* ============ Main Area ============ */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
  background: var(--bg);
}

/* ============ Chat Header ============ */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  gap: 12px;
  flex-shrink: 0;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.topic-title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#menu-btn { display: none; }

.model-select {
  padding: 6px 28px 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23888' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: border var(--transition);
}
.model-select:hover { border-color: var(--accent); }
.model-select.native-hidden { display: none; }

/* 自定义模型下拉（悬停显示能力） */
.model-select-wrap { position: relative; }
.model-select-trigger {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 28px 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  outline: none;
  max-width: 220px;
  position: relative;
  transition: border var(--transition);
}
.model-select-trigger:hover { border-color: var(--accent); }
.model-select-trigger.open { border-color: var(--accent); }
.model-select-trigger .mst-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.model-select-trigger .mst-caret {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
  color: #888;
  pointer-events: none;
}
.model-select-pop {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: max-content;
  min-width: 220px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0,0,0,.28);
  padding: 6px;
  z-index: 60;
}
.model-select-pop.hidden { display: none; }
.model-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.model-opt:hover { background: var(--surface-2); }
.model-opt.selected { background: var(--accent); color: #fff; }
.model-opt.disabled-opt { opacity: .5; cursor: default; }
.model-opt .model-opt-name { white-space: nowrap; flex-shrink: 0; }
.model-opt .model-opt-mult { font-size: 11px; color: var(--text-muted); margin-left: auto; flex-shrink: 0; opacity: 0.7; }
.model-opt.selected .model-opt-mult { color: rgba(255,255,255,0.7); }

/* 悬停能力提示（浮层，定位在条目左侧） */
.model-cap-tip {
  position: fixed;
  z-index: 200;
  display: flex;
  gap: 6px;
  padding: 6px 10px;
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
  pointer-events: none;
}
.cap-chip {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  line-height: 1.5;
  white-space: nowrap;
}
.cap-vision { background: rgba(74,108,247,.18); color: #7e9bff; }
.cap-think { background: rgba(236,122,255,.18); color: #e89bff; }
/* 浅色模式下让能力标签文字更深，保证浮层里可读 */
[data-theme="light"] .cap-vision { background: rgba(74,108,247,.16); color: #2849c0; }
[data-theme="light"] .cap-think { background: rgba(168,85,247,.16); color: #7a25c0; }


/* Toggle Switch */
.toggle-switch {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}
.toggle-switch input { display: none; }
.toggle-track {
  width: 36px;
  height: 20px;
  border-radius: 10px;
  background: var(--surface-3);
  position: relative;
  transition: background var(--transition);
}
.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform var(--transition);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle-switch input:checked + .toggle-track {
  background: var(--accent);
}
.toggle-switch input:checked + .toggle-track .toggle-thumb {
  transform: translateX(16px);
}
.toggle-label {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* ============ Messages ============ */
.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 0;
  scroll-behavior: smooth;
}

.message {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 20px;
  margin-bottom: 24px;
  animation: msgIn 0.3s ease;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.message-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}
.message.user .message-avatar { background: var(--accent); color: #fff; }
.message.assistant .message-avatar { background: var(--surface-3); color: var(--text); }
.message.user .message-avatar { order: 3; }
.message-role { font-size: 13px; font-weight: 600; color: var(--text); }
.message-time { font-size: 12px; color: var(--text-muted); }

/* Image avatar (applies to message, persona, user avatars) */
.avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}
.user-avatar.clickable {
  cursor: pointer;
  transition: transform .15s ease;
}
.user-avatar.clickable:hover {
  transform: scale(1.1);
}

/* Persona avatar upload UI */
.avatar-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.avatar-text-input {
  flex: 1;
  min-width: 80px;
}
.avatar-upload-area {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--surface-3);
  border: 2px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  flex-shrink: 0;
  transition: border-color .15s ease;
}
.avatar-upload-area:hover {
  border-color: var(--accent);
}
.avatar-preview-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}
.avatar-upload-placeholder {
  font-size: 11px;
  text-align: center;
  padding: 2px;
}
.btn-avatar-upload {
  padding: 6px 14px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s ease;
}
.btn-avatar-upload:hover {
  background: var(--surface-3);
}
.hidden-file-input {
  display: none;
}

.message-actions {
  margin-left: auto;
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity var(--transition);
}
.message:hover .message-actions { opacity: 1; }
.msg-action-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
}
.msg-action-btn:hover { background: var(--surface-2); color: var(--text); }

.ctx-indicator {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 11px;
  line-height: 1;
  color: var(--text-muted);
  background: var(--surface-2);
  white-space: nowrap;
}
.ctx-indicator svg { flex-shrink: 0; }
.ctx-indicator.over-limit {
  color: #fff;
  background: var(--danger, #e5484d);
}

.system-summary { justify-content: center; }
.system-summary-bubble {
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 13px;
  max-width: 90%;
  border-left: 3px solid var(--accent);
}

.message-bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.7;
  font-size: 15px;
  word-break: break-word;
  position: relative;
}
.message.user .message-bubble {
  background: var(--user-bubble);
  color: var(--user-text);
  margin-left: 36px;
  border-radius: 4px var(--radius) var(--radius) var(--radius);
}
.message.assistant .message-bubble {
  background: var(--ai-bubble);
  border: 1px solid var(--border);
  margin-left: 36px;
  border-radius: 4px var(--radius) var(--radius) var(--radius);
}

/* 流式/请求报错时显示在气泡里的红色错误文本 */
.msg-error {
  color: var(--danger, #e5484d);
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Thinking content */
.message-thinking {
  margin-left: 36px;
  margin-bottom: 8px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: max-height 0.3s ease;
}
.thinking-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--surface-2);
  transition: background var(--transition);
}
.thinking-header:hover { background: var(--surface-3); }
.thinking-icon {
  width: 14px;
  height: 14px;
  animation: spin 2s linear infinite;
}
.thinking-icon.idle { animation: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.thinking-toggle-arrow {
  margin-left: auto;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.thinking-toggle-arrow.open { transform: rotate(180deg); }
.thinking-body {
  padding: 10px 14px;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
  white-space: pre-wrap;
  max-height: 300px;
  overflow-y: auto;
  opacity: 1;
  transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.25s ease;
}
.thinking-body.collapsed {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  overflow: hidden;
  opacity: 0;
}

/* Typing indicator */
.typing-dots {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}
.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing 1.4s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ============ Markdown Content ============ */
.message-bubble p { margin-bottom: 8px; }
.message-bubble p:last-child { margin-bottom: 0; }
.message-bubble h1, .message-bubble h2, .message-bubble h3,
.message-bubble h4, .message-bubble h5, .message-bubble h6 {
  margin: 12px 0 8px;
  font-weight: 600;
  line-height: 1.3;
}
.message-bubble h1 { font-size: 1.4em; }
.message-bubble h2 { font-size: 1.25em; }
.message-bubble h3 { font-size: 1.1em; }
.message-bubble h4 { font-size: 1em; }
.message-bubble ul, .message-bubble ol {
  margin: 8px 0;
  padding-left: 24px;
}
.message-bubble li { margin-bottom: 4px; }
.message-bubble code {
  font-family: "SF Mono", "Fira Code", "Cascadia Code", Consolas, monospace;
  font-size: 0.9em;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(128,128,128,0.15);
}
.message.user .message-bubble code {
  background: rgba(255,255,255,0.2);
}
.message-bubble pre {
  margin: 8px 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.message-bubble pre code {
  display: block;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.5;
  overflow-x: auto;
  background: rgba(0,0,0,0.06);
  border-radius: 0;
}
[data-theme="dark"] .message-bubble pre code {
  background: rgba(0,0,0,0.3);
}
.message.user .message-bubble pre code {
  background: rgba(0,0,0,0.2);
}
.message-bubble blockquote {
  margin: 8px 0;
  padding: 8px 12px;
  border-left: 3px solid var(--accent);
  background: var(--accent-light);
  border-radius: 0 4px 4px 0;
}
.message.user .message-bubble blockquote {
  background: rgba(255,255,255,0.1);
  border-left-color: rgba(255,255,255,0.5);
}
.message-bubble table {
  margin: 8px 0;
  border-collapse: collapse;
  width: 100%;
  font-size: 14px;
}
.message-bubble th, .message-bubble td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
.message-bubble th { background: var(--surface-2); font-weight: 600; }
.message.user .message-bubble th { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.2); }
.message.user .message-bubble td { border-color: rgba(255,255,255,0.2); }
.message-bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}
.message.user .message-bubble hr { border-top-color: rgba(255,255,255,0.3); }
.message-bubble a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.message.user .message-bubble a { color: #bfdbff; }
.message-bubble strong { font-weight: 700; }
.message-bubble del { opacity: 0.6; }

/* Code block with header */
.code-block {
  margin: 8px 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}
.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: var(--surface-2);
  font-size: 12px;
  color: var(--text-muted);
}
.code-block-header button {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  color: var(--text-secondary);
  transition: background var(--transition);
}
.code-block-actions { display: flex; align-items: center; gap: 6px; }
.code-block-header button:hover { background: var(--surface-3); color: var(--text); }
/* highlight.js (atom-one-dark) — dark code blocks that read well in both themes */
.code-block {
  background: #282c34;
  border-color: #21252b;
}
.code-block-header {
  background: #21252b;
  color: #9da5b4;
  border-bottom: 1px solid #181a1f;
}
.code-block-header button { color: #9da5b4; background: transparent; }
.code-block-header button:hover { background: #2c313a; color: #fff; }
.code-block pre {
  margin: 0;
  border-radius: 0;
  background: #282c34;
}
.code-block pre code,
.code-block pre code.hljs {
  border-radius: 0;
  background: transparent;
  color: #abb2bf;
}
[data-theme="dark"] .code-block { background: #21252b; border-color: #181a1f; }
[data-theme="dark"] .code-block-header { background: #181a1f; }
[data-theme="dark"] .code-block pre { background: #21252b; }

/* ============ Edit mode ============ */
.edit-textarea {
  width: 100%;
  min-height: 60px;
  padding: 8px 12px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  resize: vertical;
  outline: none;
}
.edit-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  justify-content: flex-end;
}
.edit-actions button {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
}
.edit-save { background: var(--accent); color: #fff; }
.edit-cancel { background: var(--surface-2); color: var(--text-secondary); }

/* ============ Welcome ============ */
.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
}
.welcome-logo {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  color: #fff;
  font-weight: 800;
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}
.welcome h2 { font-size: 22px; margin-bottom: 8px; }
.welcome p { color: var(--text-secondary); font-size: 14px; }

/* ============ Input Area ============ */
.input-area {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.input-wrapper {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 8px 8px 16px;
  transition: border var(--transition), box-shadow var(--transition);
}
.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}
.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.message-input {
  flex: 1;
  border: none;
  background: none;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  resize: none;
  outline: none;
  max-height: 200px;
  padding: 4px 0;
}
.message-input::placeholder { color: var(--text-muted); }
.btn-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition), transform var(--transition), opacity var(--transition);
}
.btn-send:hover { background: var(--accent-hover); }
.btn-send:active { transform: scale(0.92); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }
/* Continue-generation button removed (pause feature removed) */

/* ============ Attachment (multimodal image) ============ */
.btn-attach {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition), color var(--transition), opacity var(--transition);
  cursor: pointer;
}
.btn-attach:hover { background: var(--surface-3, var(--surface-2)); color: var(--text); }
.btn-attach:disabled { opacity: 0.35; cursor: not-allowed; }
.attachment-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.attachment-preview.hidden { display: none; }
.attachment-thumb {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
}
.attachment-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.attachment-thumb .thumb-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.attachment-thumb .thumb-remove:hover { background: #e5484d; }
/* Images rendered inside a chat message bubble */
.message-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.msg-image {
  max-width: 220px;
  max-height: 220px;
  border-radius: 8px;
  border: 1px solid var(--border);
  object-fit: cover;
  cursor: zoom-in;
}

/* ============ Modals ============ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
/* 人格详情弹窗常从全屏页（人格广场/设置）内部打开，需层级更高，否则会渲染在其下方而看似「点了没反应」 */
#persona-detail-modal { z-index: 1200; }
/* 确认框层级最高 */
#confirm-modal { z-index: 1300; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(2px);
}
.modal-card {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.2s ease;
}
.modal-card-sm { max-width: 360px; }
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-card h2 { font-size: 20px; margin-bottom: 20px; }

/* ---------- Persona Plaza (人格广场) ---------- */
.modal-card-lg { max-width: 640px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h2 { margin-bottom: 0; }
.plaza-body { display: flex; flex-direction: column; gap: 22px; }

/* 人格广场全屏页面的工具栏（搜索 + 上传） */
.plaza-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.plaza-toolbar .text-input { flex: 1 1 auto; min-width: 0; }

/* 上传人格：点击按钮后展开的选择面板 */
.plaza-upload-panel {
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 14px;
  margin-bottom: 18px;
}
.plaza-upload-panel-title {
  font-size: 13px; font-weight: 600; color: var(--text-secondary);
  margin-bottom: 10px;
}
.plaza-upload-panel .plaza-empty { padding: 4px 2px; }
.plaza-section-title { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 12px; }
.plaza-grid { display: flex; flex-direction: column; gap: 10px; }
.plaza-card { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); -webkit-user-select: none; user-select: none; }
.plaza-card-avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--accent-light); color: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 18px; font-weight: 600; flex-shrink: 0; overflow: hidden; }
.plaza-card-avatar.sm { width: 34px; height: 34px; font-size: 15px; }
.plaza-card-avatar .avatar-img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.plaza-card-info { flex: 1; min-width: 0; }
.plaza-card-name { font-size: 14px; font-weight: 600; color: var(--text); }
.plaza-card-desc { font-size: 12px; color: var(--text-muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plaza-card-author { font-size: 11px; color: var(--text-muted); margin-top: 4px; opacity: 0.85; }
.plaza-card-action { flex-shrink: 0; }
.plaza-mine { display: flex; flex-direction: column; gap: 10px; }
.plaza-mine-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); -webkit-user-select: none; user-select: none; }
.plaza-mine-info { flex: 1; min-width: 0; }
.plaza-empty { font-size: 13px; color: var(--text-muted); padding: 8px 2px; text-align: center; }

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.form-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  outline: none;
  transition: border var(--transition), box-shadow var(--transition);
}
.form-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.form-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  outline: none;
  resize: vertical;
  line-height: 1.6;
  transition: border var(--transition), box-shadow var(--transition);
}
.form-textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}
.confirm-message { color: var(--text-secondary); font-size: 15px; line-height: 1.6; }

/* ============ 用户设置 Modal ============ */
/* ============ 用户设置：全屏覆盖聊天界面 ============ */
.settings-fullscreen { padding: 0; }
.settings-fullscreen .modal-backdrop {
  background: var(--bg);
  backdrop-filter: none;
}
.settings-fullscreen .modal-card {
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  border-radius: 0;
  box-shadow: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  animation: settingsSlideIn 0.22s ease;
}
@keyframes settingsSlideIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.settings-fullscreen .modal-header {
  padding: 18px 28px;
  margin-bottom: 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.settings-fullscreen .modal-title { font-size: 20px; }
.settings-fullscreen .modal-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 28px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  box-sizing: border-box;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-title { font-size: 18px; font-weight: 700; color: var(--text); }
.modal-close {
  border: none; background: transparent; color: var(--text-secondary);
  font-size: 18px; cursor: pointer; line-height: 1; padding: 4px; border-radius: 6px;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-body { display: flex; flex-direction: column; gap: 18px; }
/* 设置弹窗滚动条：融入暗色主题 */
.settings-group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--surface-2);
}
.settings-label { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 10px; }
.settings-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.settings-hint { font-size: 12px; color: var(--text-secondary); margin-top: 8px; line-height: 1.5; }
.settings-credits-val { font-size: 14px; color: var(--text); }
.settings-credits-val b { color: var(--accent); font-size: 16px; margin-left: 2px; }
.text-input {
  flex: 0 1 220px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  outline: none;
  font-size: 13px;
}
.text-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.flex-1 { flex: 1 1 auto; min-width: 160px; }
.file-btn {
  display: inline-flex; align-items: center; cursor: pointer;
  padding: 8px 12px; border-radius: var(--radius-sm);
  background: var(--accent); color: #fff; font-size: 13px; font-weight: 600;
  border: 1px solid var(--accent);
}
.file-btn:hover { background: var(--accent-hover); }
input[type="color"] {
  width: 38px; height: 34px; padding: 2px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface); cursor: pointer;
}
.btn-sm {
  padding: 7px 12px; font-size: 13px; font-weight: 600; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; transition: background var(--transition), border var(--transition);
}
.btn-sm:hover { background: var(--surface-2); border-color: var(--accent); }
.btn-primary.btn-sm { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary.btn-sm:hover { background: var(--accent-hover); }

/* 自定义模型模式 */
.settings-label-row { display: flex; align-items: center; justify-content: space-between; }

/* Beta 徽章（自定义模型模式设置项） */
.beta-tag {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.6;
  letter-spacing: .4px;
  color: #fff;
  background: var(--accent, #4a6cf7);
  border-radius: 999px;
  vertical-align: middle;
}
.custom-panel { margin-top: 4px; padding: 14px; border: 1px dashed var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.custom-search { width: 100%; flex: 1 1 100%; margin-top: 12px; }
.settings-sublabel { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-top: 14px; margin-bottom: 6px; }
.custom-model-list, .custom-added-list {
  max-height: 220px; overflow-y: auto; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface); padding: 6px;
}
.custom-model-list:empty::after, .custom-added-list:empty::after {
  content: '（暂无）'; display: block; padding: 10px; color: var(--text-muted); font-size: 12px; text-align: center;
}
.cm-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm); font-size: 13px;
}
.cm-item:hover { background: var(--surface-2); }
.cm-item .cm-name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cm-item .cm-id { font-size: 11px; color: var(--text-muted); }
.cm-add-btn, .cm-del-btn {
  flex: 0 0 auto; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); border-radius: var(--radius-sm); padding: 4px 10px;
  font-size: 12px; cursor: pointer;
}
.cm-add-btn { color: var(--accent); border-color: var(--accent); }
.cm-add-btn:hover { background: var(--accent); color: #fff; }
.cm-del-btn:hover { border-color: #e5484d; color: #e5484d; }
.cm-item.cm-active { background: var(--accent-light); }
.cm-item.cm-active .cm-name { color: var(--accent); font-weight: 600; }
.muted { color: var(--text-muted); }


/* ============ HTML Preview Modal ============ */
.html-preview-modal { padding: 0; }
.html-preview-card {
  position: relative;
  width: 92vw;
  height: 88vh;
  max-width: 1200px;
  background: #fff;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}
.html-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #21252b;
  color: #fff;
  flex-shrink: 0;
}
.html-preview-title { font-size: 14px; font-weight: 600; }
.html-preview-header-actions { display: flex; gap: 6px; }
.html-preview-header-actions button {
  width: 30px; height: 28px;
  background: transparent;
  border: 1px solid #3a3f4b;
  color: #cfd3dc;
  border-radius: 5px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition);
}
.html-preview-header-actions button:hover { background: #2c313a; color: #fff; }
.html-preview-iframe { flex: 1; width: 100%; border: 0; background: #fff; }


/* New-chat modal: required field + empty state */
.required-star { color: #e5484d; margin-left: 2px; }
.form-hint { font-size: 12px; color: var(--text-muted); font-weight: normal; margin-left: 4px; }
.form-empty { margin-top: 10px; font-size: 13px; color: var(--text-muted); line-height: 1.7; }
.btn-link {
  background: none; border: none; padding: 0 4px;
  color: var(--primary); cursor: pointer; font-size: 13px;
  text-decoration: underline;
}
.btn-primary:disabled, .btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============ Toast ============ */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  background: var(--text);
  color: var(--bg);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 2000;
  animation: toastIn 0.3s ease;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ============ Responsive ============ */
@media (max-width: 768px) {
  :root { --sidebar-w: 280px; }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100%;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: flex; }
  .sidebar-overlay.active { display: block; }

  #menu-btn { display: flex; }

  .message { padding: 0 12px; }
  .message-bubble { margin-left: 0 !important; }

  .chat-header { padding: 8px 12px; gap: 8px; }
  .toggle-label { display: none; }
  .header-right { gap: 8px; }

  .input-area { padding: 8px 12px 12px; }
  .login-card h1 { font-size: 24px; }

  .messages { padding: 12px 0; }

  .message-actions { opacity: 1; }
  .persona-delete { opacity: 1; }
  .persona-info-btn { opacity: 1; }
  .topic-actions { opacity: 1; }

  .model-select { font-size: 12px; padding: 6px 24px 6px 8px; }
}

@media (max-width: 480px) {
  .message-bubble { padding: 10px 12px; font-size: 14px; }
  .thinking-body { font-size: 11px; }
  .modal-card { padding: 20px; }
}

/* Scrollbar styling */

/* 自定义模型模式：云端话题与本地对话分属两个独立容器，
   靠 body 上的 custom-mode-active 标记切换显隐，从根本上避免
   「云端话题在自定义模式显示 / 本地对话在云端显示」的串味。 */
body.custom-mode-active #topic-list { display: none; }
body:not(.custom-mode-active) #custom-conv-list { display: none; }

/* 自定义模式标识（仅开启自定义模式时显示，云端模式不显示） */
.context-bar {
  display: inline-flex;
  align-items: center;
  margin-left: 10px;
  padding: 2px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--accent, #6ea8fe);
  background: rgba(110, 168, 254, 0.12);
  border: 1px solid rgba(110, 168, 254, 0.35);
}

/* ============ 全局滚动条：统一融入暗色主题 ============ */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
*::-webkit-scrollbar,
html::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
*::-webkit-scrollbar-track,
html::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb,
html::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
*::-webkit-scrollbar-thumb:hover,
html::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

