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

:root {
  /* Dark Theme Palette */
  --bg-main: #0f172a;
  --bg-main-rgb: 15, 23, 42;
  /* deep, rich blue-black */
  --bg-sidebar: #020617;
  /* darker than main */
  --bg-input: #1e293b;
  /* soft floating input */
  --bg-user-msg: linear-gradient(135deg, #0ea5e9, #3b82f6);
  /* vibrant gradient */
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-user-msg: #ffffff;
  --accent: #3b82f6;
  /* nice blue accent */
  --accent-hover: #2563eb;
  --border: #334155;
  --bg-code: #0b1120;
  --code-text: #e2e8f0;
  /* very dark for code */
  --bg-inline-code: rgba(255, 255, 255, 0.1);
  --bg-table-header: rgba(255, 255, 255, 0.05);
  --bg-table-hover: rgba(255, 255, 255, 0.03);
  --hover-bg: rgba(255, 255, 255, 0.05);
  --btn-send-bg: #e2e8f0;
  --btn-send-color: #0f172a;
  --scrollbar-thumb: rgba(148, 163, 184, 0.2);
  --overlay-bg: rgba(2, 6, 23, 0.6);
  --link-color: #38bdf8;
  --link-hover: #7dd3fc;

  /* Shared values */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-float: 0 20px 25px -5px rgba(0, 0, 0, 0.2), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

[data-theme="light"] {
  /* Light Theme Palette */
  --bg-main: #ffffff;
  --bg-main-rgb: 255, 255, 255;
  --bg-sidebar: #f8fafc;
  /* very soft cool gray */
  --bg-input: #ffffff;
  --bg-user-msg: linear-gradient(135deg, #0ea5e9, #3b82f6);
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --text-user-msg: #ffffff;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --border: #e2e8f0;
  --bg-code: #0f172a;
  /* dark code block even in light mode looks premium */
  --code-text: #f8fafc;
  --bg-inline-code: rgba(0, 0, 0, 0.06);
  --bg-table-header: rgba(0, 0, 0, 0.02);
  --bg-table-hover: rgba(0, 0, 0, 0.01);
  --hover-bg: rgba(0, 0, 0, 0.04);
  --btn-send-bg: #0f172a;
  --btn-send-color: #ffffff;
  --scrollbar-thumb: rgba(100, 116, 139, 0.2);
  --overlay-bg: rgba(15, 23, 42, 0.3);
  --link-color: #2563eb;
  --link-hover: #1d4ed8;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-float: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-main);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  display: flex;
  height: 100vh;
}

#sidebar {
  width: 280px;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  padding: 12px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  z-index: 10;
  transition: margin-left 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

#sidebar-toggle-checkbox:checked~#sidebar {
  margin-left: -280px;
  border-right: none;
}

#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 4px 0 18px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.sidebar-brand-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-brand-copy strong {
  color: var(--text-primary);
  font-size: 20px;
  line-height: 1.1;
  letter-spacing: 0.04em;
}

.sidebar-brand-copy > span {
  color: var(--text-secondary);
  font-size: 12px;
}

.sidebar-toggle-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 12px;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.sidebar-toggle-btn:hover {
  background: var(--hover-bg);
  color: var(--text-primary);
}

#new-chat {
  width: 100%;
  min-height: 46px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid var(--accent);
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 180ms ease, background 180ms ease,
              box-shadow 180ms ease;
}

#new-chat:hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

/* ===== 搜索框 ===== */
#search-wrapper {
  position: relative;
  margin-bottom: 14px;
}

#search-wrapper .search-icon {
  position: absolute;
  top: 50%;
  left: 12px;
  transform: translateY(-50%);
  color: var(--text-secondary);
  pointer-events: none;
}

#search-input {
  width: 100%;
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  padding: 10px 32px 10px 38px;
  font: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

#search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(59 130 246 / 16%);
}

#search-input::placeholder {
  color: var(--text-secondary);
}

#search-clear {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
}

#search-clear:hover {
  color: var(--text-primary);
}

.chat-item-snippet {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
  width: 100%;
}

#chat-list {
  flex: 1;
  overflow-y: auto;
}

.chat-list-group {
  padding: 18px 8px 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  user-select: none;
  margin-bottom: 2px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  position: sticky;
  top: 0;
  background: var(--bg-sidebar);
  z-index: 2;
  opacity: 0.9;
}

.sidebar-section-title {
  padding: 6px 8px 8px;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chat-list-group:first-child {
  padding-top: 4px;
}

.chat-list-subgroup {
  padding: 8px 12px 6px 16px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  user-select: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-list-subgroup::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 4px;
  background: var(--border);
  border-radius: 50%;
  margin-right: 4px;
}

.chat-list-subgroup:hover,
.chat-list-group:hover {
  color: var(--text-primary);
}

.group-chevron {
  font-size: 10px;
  transition: transform 0.2s ease;
  display: inline-block;
}

.group-chevron.collapsed {
  transform: rotate(-90deg);
}

.group-count {
  font-weight: 500;
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--hover-bg);
  padding: 2px 6px;
  border-radius: 10px;
  margin-left: auto;
}

.chat-item.nested {
  padding-left: 20px;
}

.chat-item {
  padding: 10px 12px;
  margin-bottom: 2px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
  flex-wrap: wrap;
  position: relative;
}

.chat-item-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-delete {
  display: flex;
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  padding: 2px;
  flex-shrink: 0;
  border-radius: 4px;
  transition: opacity 0.2s, background 0.2s, color 0.2s;
}

.chat-item-delete:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

.chat-item:hover .chat-item-delete,
.chat-item.active .chat-item-delete {
  opacity: 1;
}

.chat-item:hover {
  background: var(--hover-bg);
  color: var(--text-primary);
}

.chat-item.active {
  background: var(--accent);
  color: white;
  box-shadow: var(--shadow-sm);
}

.sidebar-brand-mark {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  overflow: hidden;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 50%;
}

.sidebar-brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.sidebar-brand-mark .avatar-fallback {
  font-size: 13px;
  font-weight: 700;
}

.avatar-fallback[hidden] {
  display: none;
}

.chat-item.active .chat-item-delete {
  color: rgba(255, 255, 255, 0.8);
}

.chat-item.active .chat-item-delete:hover {
  color: white;
  background: rgba(255, 255, 255, 0.2);
}

/* ===== 主区域 ===== */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-main);
  position: relative;
}

/* ===== 顶栏：模型选择 ===== */
#top-bar {
  padding: 12px 24px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  z-index: 5;
  background: rgba(var(--bg-main-rgb), 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.main-toggle-btn {
  display: none;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  margin-right: 12px;
  border-radius: 8px;
  padding: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.main-toggle-btn:hover {
  background: var(--hover-bg);
  color: var(--text-primary);
}

#sidebar-toggle-checkbox:checked~#main .main-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== Model Picker ===== */
#model-picker-wrapper {
  display: none;
  position: relative;
}

#model-picker-trigger {
  background: var(--hover-bg);
  border: 1px solid transparent;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  padding: 6px 28px 6px 14px;
  border-radius: 8px;
  outline: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  transition: all 0.2s ease;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#model-picker-trigger:hover {
  background-color: var(--bg-input);
  border-color: var(--border);
}

#model-picker-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 340px;
  max-height: 480px;
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: picker-in 0.12s ease-out;
}

#model-picker-dropdown.hidden {
  display: none;
}

@keyframes picker-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.model-picker-search-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.model-picker-search-row svg {
  width: 16px;
  height: 16px;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

#model-picker-search {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  outline: none;
}

#model-picker-search::placeholder {
  color: var(--text-tertiary);
}

/* Recent chips bar */
#model-picker-recent {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

#model-picker-recent.hidden { display: none; }

.model-picker-chip {
  background: var(--hover-bg);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 12px;
  font-family: inherit;
  padding: 3px 10px;
  border-radius: 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.model-picker-chip:hover {
  background: var(--bg-input);
  border-color: var(--accent);
}

.model-picker-chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

#model-picker-list {
  overflow-y: auto;
  max-height: 420px;
  padding: 4px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}

.model-picker-section-header {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-tertiary);
  padding: 10px 16px 4px;
  user-select: none;
}

.model-picker-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
  transition: background 0.1s;
  overflow: hidden;
  white-space: nowrap;
}

.model-picker-item:hover {
  background: var(--hover-bg);
}

.model-picker-item.selected {
  color: var(--accent);
  font-weight: 600;
}

.model-picker-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.model-picker-org {
  color: var(--text-tertiary);
  font-size: 12px;
  flex-shrink: 0;
}

.model-picker-org::after {
  content: " · ";
}

.model-picker-name {
  overflow: hidden;
  text-overflow: ellipsis;
}

.model-picker-item.selected .model-picker-org {
  color: var(--accent);
  opacity: 0.7;
}

.model-picker-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 13px;
}

@media (max-width: 480px) {
  #model-picker-dropdown {
    width: calc(100vw - 24px);
    left: -8px;
  }
  #model-picker-trigger {
    max-width: 140px;
    font-size: 13px;
    padding: 5px 24px 5px 10px;
  }
}

/* ===== 消息区 ===== */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
  overflow-anchor: none;
}

#project-footer {
  flex: 0 0 auto;
  padding: 8px 16px max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  color: var(--text-secondary);
  background: var(--bg-main);
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
}

#project-footer strong,
#project-footer span {
  display: block;
}

#welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 8px;
}

#welcome p {
  font-size: 22px;
  font-weight: 600;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-align: center;
}

.welcome-logo {
  color: var(--accent);
  margin-bottom: 4px;
  opacity: 0.8;
}

.welcome-subtext {
  font-size: 14px;
  color: var(--text-secondary);
  text-align: center;
}

#welcome-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
  color: #f8fafc;
  text-align: center;
  background: radial-gradient(circle at top, #1e3a8a, #0f172a 68%);
  opacity: 1;
  transition: opacity 450ms ease;
}

#welcome-screen.hidden {
  display: grid !important;
  opacity: 0;
  pointer-events: none;
}

.welcome-card {
  width: min(100%, 560px);
  padding: 40px 32px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 24px;
  background: rgba(15, 23, 42, 0.55);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(12px);
}

.welcome-university-logo,
.welcome-logo-fallback {
  display: grid;
  place-items: center;
  width: 112px;
  height: 112px;
  margin: 0 auto 24px;
  object-fit: contain;
}

.welcome-logo-fallback {
  color: #fff;
  background: transparent;
  font-size: 28px;
  font-weight: 700;
}

.welcome-logo-fallback[hidden] {
  display: none;
}

#welcome-title {
  margin-bottom: 10px;
  font-size: clamp(30px, 6vw, 44px);
}

.welcome-subtitle {
  margin-bottom: 28px;
  color: #cbd5e1;
  font-size: 17px;
  line-height: 1.5;
}

.welcome-members {
  line-height: 1.8;
}

.welcome-career {
  margin-top: 8px;
  color: #cbd5e1;
}

.profile-choices {
  display: grid;
  gap: 10px;
  margin-top: 28px;
}

.profile-choice {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  color: #f8fafc;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease,
              box-shadow 160ms ease;
}

.profile-choice:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.14);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}

.profile-choice-primary {
  border-color: var(--accent);
  background: var(--accent);
}

.profile-choice-primary:hover {
  background: var(--accent-hover);
}

@media (prefers-reduced-motion: reduce) {
  #welcome-screen,
  .profile-choice {
    transition-duration: 0.01ms;
  }
}

@media (max-width: 480px) {
  .welcome-card {
    padding: 32px 22px;
  }

  .profile-choice {
    padding: 11px 14px;
  }
}

.message {
  max-width: 800px;
  margin: 0 auto;
  padding: 16px 24px;
  width: 100%;
  animation: messageSlideIn 0.3s ease-out forwards;
}

@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message.user {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.message-content-row {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  width: 100%;
  min-width: 0;
}

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

.message-avatar {
  position: relative;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  overflow: hidden;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 50%;
}

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

.message-avatar .avatar-fallback {
  font-size: 14px;
  font-weight: 700;
}

.message.user .bubble {
  background: var(--bg-user-msg);
  color: var(--text-user-msg);
  padding: 12px 18px;
  border-radius: 20px 20px 6px 20px;
  max-width: min(80%, calc(100% - 64px));
  white-space: pre-wrap;
  line-height: 1.6;
  box-shadow: 0 3px 10px rgb(0 0 0 / 12%);
  font-weight: 400;
}

.message.assistant .bubble {
  flex: 1;
  min-width: 0;
  line-height: 1.7;
  white-space: normal;
  padding: 8px 0;
}

.streaming-content {
  white-space: pre-wrap;
  word-break: break-word;
}

.message.assistant .bubble p {
  margin-bottom: 16px;
}

.message.assistant .bubble p:last-child {
  margin-bottom: 0;
}

.message.assistant .bubble pre {
  background: var(--bg-code);
  color: var(--code-text, #f8fafc);
  border-radius: 10px;
  padding: 36px 16px 16px;
  overflow-x: auto;
  margin: 16px 0;
  font-size: 13px;
  border: 1px solid var(--border);
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.1);
  position: relative;
}

.message.assistant .bubble pre::before {
  content: "";
  position: absolute;
  top: 13px;
  left: 16px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ef4444;
  box-shadow: 14px 0 0 #eab308, 28px 0 0 #22c55e;
}

.message.assistant .bubble code {
  font-family: "Fira Code", "JetBrains Mono", "Consolas", monospace;
  font-size: 13px;
}

.message.assistant .bubble :not(pre)>code {
  background: var(--bg-inline-code);
  padding: 3px 6px;
  border-radius: 6px;
  color: var(--accent);
  font-weight: 500;
}

.message.assistant .bubble ul,
.message.assistant .bubble ol {
  padding-left: 24px;
  margin-bottom: 16px;
}

.message.assistant .bubble ol {
  list-style-type: decimal;
}

.message.assistant .bubble li {
  margin-bottom: 8px;
  padding-left: 4px;
}

.message.assistant .bubble li::marker {
  color: var(--accent);
  font-weight: 600;
}

/* 标题 */
.message.assistant .bubble h1,
.message.assistant .bubble h2,
.message.assistant .bubble h3,
.message.assistant .bubble h4 {
  margin-top: 24px;
  margin-bottom: 12px;
  line-height: 1.4;
  font-weight: 600;
  color: var(--text-primary);
}

.message.assistant .bubble h1 {
  font-size: 1.5em;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.message.assistant .bubble h2 {
  font-size: 1.3em;
}

.message.assistant .bubble h3 {
  font-size: 1.15em;
}

.message.assistant .bubble h1:first-child,
.message.assistant .bubble h2:first-child,
.message.assistant .bubble h3:first-child {
  margin-top: 0;
}

/* 表格 */
.message.assistant .bubble table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 16px 0;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.message.assistant .bubble th,
.message.assistant .bubble td {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 12px;
  text-align: left;
}

.message.assistant .bubble th:last-child,
.message.assistant .bubble td:last-child {
  border-right: none;
}

.message.assistant .bubble tr:last-child td {
  border-bottom: none;
}

.message.assistant .bubble th {
  background: var(--bg-table-header);
  font-weight: 600;
  white-space: nowrap;
}

.message.assistant .bubble tr:hover td {
  background: var(--bg-table-hover);
}

/* 链接 */
.message.assistant .bubble a {
  color: var(--link-color);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.15s;
}

.message.assistant .bubble a:hover {
  color: var(--link-hover);
  text-decoration: underline;
}

/* 引用 */
.message.assistant .bubble blockquote {
  border-left: 4px solid var(--accent);
  padding: 8px 16px;
  margin: 16px 0;
  background: var(--hover-bg);
  border-radius: 0 8px 8px 0;
  color: var(--text-secondary);
  font-style: italic;
}

/* 分隔线 */
.message.assistant .bubble hr {
  border: none;
  height: 1px;
  background: var(--border);
  margin: 24px 0;
}

/* ===== 消息悬浮工具栏 ===== */
.message {
  position: relative;
}

.msg-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 0;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.message:hover .msg-toolbar {
  opacity: 1;
}

.message.user .doc-card {
  margin-left: 0;
}

.message.user .msg-toolbar {
  justify-content: flex-end;
  align-self: flex-end;
}

.toolbar-time {
  font-size: 12px;
  color: var(--text-secondary);
  padding: 0 6px;
  font-family: "Fira Code", "Consolas", monospace;
  opacity: 0.7;
}

.toolbar-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
}

.toolbar-btn:hover {
  color: var(--text-primary);
  background: var(--hover-bg);
}

/* ===== 编辑消息 UI ===== */
.edit-textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.5;
  padding: 12px 16px;
  resize: none;
  outline: none;
  font-family: inherit;
  max-height: 300px;
  transition: border-color 0.2s;
}

.edit-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

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

.edit-cancel-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 6px 16px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s;
}

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

.edit-submit-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 6px 16px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.edit-submit-btn:hover {
  opacity: 0.9;
}

/* 打字光标 */
.cursor {
  display: inline-block;
  width: 8px;
  height: 18px;
  background: var(--accent);
  margin-left: 4px;
  vertical-align: text-bottom;
  border-radius: 4px;
  animation: blink 1s ease-in-out infinite;
}

@keyframes blink {

  0%,
  50% {
    opacity: 1;
  }

  51%,
  100% {
    opacity: 0;
  }
}

/* ===== 输入区 ===== */
#input-area {
  padding: 0 24px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  background: linear-gradient(to top, var(--bg-main) 70%, transparent);
  z-index: 10;
}

#input-wrapper {
  max-width: 800px;
  width: 100%;
  background: var(--bg-input);
  border-radius: 24px;
  display: flex;
  flex-direction: column;
  padding: 10px 14px;
  transition: all 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-float);
}

#input-wrapper:focus-within {
  border-color: rgba(59, 130, 246, 0.5);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1), var(--shadow-float);
  transform: translateY(-2px);
}

#input-wrapper.drag-over {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.05);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2);
}

#input-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  width: 100%;
}

#user-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 15px;
  resize: none;
  max-height: 200px;
  line-height: 1.5;
  padding: 8px 0;
  font-family: inherit;
}

#user-input::placeholder {
  color: var(--text-secondary);
}

#voice-entry-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: var(--text-secondary);
  text-decoration: none;
  flex-shrink: 0;
  transition: color 0.2s, background 0.2s;
  margin-bottom: 2px;
}
#voice-entry-btn:hover {
  color: var(--accent);
  background: var(--hover-bg);
}

#send-btn {
  background: var(--btn-send-bg);
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  color: var(--btn-send-color);
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
  margin-bottom: 2px;
}

#send-btn:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: var(--shadow-md);
}

#send-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  box-shadow: none;
}

#upload-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 50%;
  transition: all 0.2s ease;
  margin-bottom: 2px;
}

#upload-btn:hover {
  color: var(--text-primary);
  background: var(--hover-bg);
}

/* ===== 图片预览区 ===== */
#image-preview {
  display: flex;
  gap: 8px;
  padding: 8px 4px;
  overflow-x: auto;
  width: 100%;
  flex-wrap: wrap;
}

#image-preview.hidden {
  display: none;
}

.preview-thumb {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
}

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

.preview-thumb .remove-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  background: rgba(0, 0, 0, 0.7);
  border: none;
  border-radius: 50%;
  color: white;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
}

.preview-thumb:hover .remove-btn {
  opacity: 1;
}

/* ===== 文档预览条 ===== */
#document-preview {
  width: 100%;
  padding: 6px 4px;
}

#document-preview.hidden {
  display: none;
}

.doc-preview-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  font-size: 13px;
  line-height: 1.4;
}

.doc-icon {
  flex-shrink: 0;
  font-size: 16px;
}

.doc-name {
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}

.doc-meta {
  color: var(--text-secondary);
  flex-shrink: 0;
}

.doc-status {
  color: var(--text-secondary);
  font-size: 12px;
}

.doc-truncated {
  color: #f59e0b;
  font-size: 12px;
  margin-left: 4px;
}

.doc-remove {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  border-radius: 4px;
  transition: color 0.15s;
}

.doc-remove:hover {
  color: #ef4444;
}

/* ===== 消息内文档卡片（气泡外独立显示） ===== */
.doc-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  margin-bottom: 6px;
  max-width: 280px;
}

.doc-card-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.12);
  color: #ef4444;
}

.doc-card-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.doc-card-name {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-card-ext {
  font-size: 0.7rem;
  color: var(--text-secondary);
  text-transform: uppercase;
}

[data-theme="light"] .doc-card {
  background: #f3f4f6;
  border-color: #e5e7eb;
}

[data-theme="light"] .doc-card-icon {
  background: rgba(239, 68, 68, 0.08);
}

/* ===== 消息内图片 ===== */
.message-images {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.message-images img {
  max-width: 300px;
  max-height: 200px;
  border-radius: 12px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.message-images img:hover {
  opacity: 0.85;
}

/* ===== 图片灯箱 ===== */
#image-lightbox {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  cursor: pointer;
}

#image-lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 8px;
}

#disclaimer {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 8px;
  text-align: center;
}

/* ===== 侧边栏底部工具栏 ===== */
#profile-switcher-row {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-top: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 12px;
}

#profile-switcher {
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg-main);
  color: var(--text-primary);
  font: inherit;
  cursor: pointer;
}

#profile-switcher:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(59 130 246 / 16%);
}

#sidebar-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 0 4px;
  margin-top: 8px;
  border-top: 1px solid var(--border);
}

#manage-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: background 0.15s, color 0.15s;
}

#manage-btn:hover {
  background: var(--hover-bg);
  color: var(--text-primary);
}

/* ===== + 按钮弹出菜单 ===== */
#plus-btn-wrapper {
  position: relative;
}

#upload-btn svg {
  transition: transform 0.3s ease;
}

#upload-btn.active svg {
  transform: rotate(135deg);
}

.plus-menu {
  position: absolute;
  bottom: 100%;
  left: 0;
  margin-bottom: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 14px 32px rgb(0 0 0 / 22%);
  overflow: hidden;
  min-width: 140px;
  z-index: 20;
  transform-origin: bottom left;
  animation: menuFadeIn 180ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes menuFadeIn {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.plus-menu.hidden {
  display: none;
}

.plus-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.plus-menu-item:hover {
  background: var(--hover-bg);
}

.plus-menu-icon {
  flex-shrink: 0;
  color: var(--text-secondary);
}

.plus-menu-divider {
  height: 1px;
  background: var(--border);
  margin: 2px 12px;
}

@media (prefers-reduced-motion: reduce) {
  #new-chat,
  .plus-menu {
    transition-duration: 0.01ms;
    animation-duration: 0.01ms;
  }
}

/* ===== 摘要卡片 ===== */
.summary-card {
  border: 1px solid rgba(59, 130, 246, 0.2);
  border-radius: 8px;
  max-width: 800px;
  margin: 4px auto;
  padding: 0;
  width: calc(100% - 48px);
  background: rgba(59, 130, 246, 0.06);
  overflow: hidden;
}

[data-theme="light"] .summary-card {
  background: rgba(59, 130, 246, 0.05);
  border-color: rgba(59, 130, 246, 0.15);
}

.summary-card summary {
  padding: 10px 14px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13px;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.summary-card summary::before {
  content: "▶ ";
  font-size: 10px;
  transition: transform 0.15s;
  display: inline-block;
}

.summary-card[open] summary::before {
  transform: rotate(90deg);
}

.summary-card summary:hover {
  color: var(--text-primary);
}

.summary-card .summary-icon {
  flex-shrink: 0;
  color: var(--accent);
}

.summary-preview {
  color: var(--text-secondary);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 400px;
  margin-left: 4px;
  opacity: 0.6;
}

.summary-card[open] .summary-preview {
  display: none;
}

.summary-card-body {
  padding: 8px 14px 12px;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.7;
  max-height: 400px;
  overflow-y: auto;
  border-top: 1px solid var(--border);
  white-space: pre-wrap;
}

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

.summary-card {
  animation: summarySlideIn 0.3s ease;
}

/* ===== 右上角主题切换圆形按钮 ===== */
#theme-toggle {
  margin-left: auto;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--bg-sidebar);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  transition: box-shadow 0.2s;
}

#theme-toggle:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

#theme-toggle {
  perspective: 200px;
}

#theme-toggle svg {
  transition: transform 0.5s ease;
}

#theme-toggle:hover svg {
  transform: rotateY(180deg);
}

#settings-btn {
  background: transparent;
  border: none;
  color: var(--accent);
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  transition: background 0.15s, color 0.15s;
}

#settings-btn:hover {
  background: rgba(59, 130, 246, 0.1);
  color: var(--accent-hover);
}

/* ===== 批量操作栏 ===== */
#batch-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 4px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--text-secondary);
}

#batch-bar.hidden {
  display: none;
}

#batch-select-all-label {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  user-select: none;
}

#batch-count {
  flex: 1;
  text-align: center;
  font-size: 12px;
}

#batch-delete-btn {
  background: #ff6b6b;
  color: #fff;
  border: none;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

#batch-delete-btn:hover {
  background: #e55a5a;
}

#batch-delete-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

#batch-cancel-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

#batch-cancel-btn:hover {
  background: var(--hover-bg);
  color: var(--text-primary);
}

/* ===== 批量勾选框 ===== */
.batch-checkbox {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--accent, #5b9bd5);
}

#sidebar-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 4px 0;
  margin-top: auto;
  font-size: 11px;
  color: var(--text-secondary);
  opacity: 0.6;
}

#sidebar-footer a {
  color: var(--text-secondary);
  text-decoration: none;
}

#sidebar-footer a:hover {
  color: var(--accent);
}

/* ===== 设置弹窗 ===== */
.hidden {
  display: none !important;
}

#settings-overlay {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  background: var(--overlay-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

#settings-panel {
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: 20px;
  width: 760px;
  max-width: 90vw;
  max-height: 85vh;
  display: flex;
  flex-direction: row;
  box-shadow: var(--shadow-float);
  overflow: hidden;
  animation: slideUpModal 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUpModal {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

#settings-sidebar {
  width: 200px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  border-radius: 20px 0 0 20px;
}

#settings-header {
  padding: 20px 20px 16px;
}

#settings-header h2 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

#current-model-display {
  font-size: 12px;
  color: var(--accent);
  font-family: "Fira Code", "JetBrains Mono", monospace;
  margin-top: 4px;
  display: block;
  font-weight: 500;
}

#settings-close {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
}

#settings-close:hover {
  background: var(--hover-bg);
  color: var(--text-primary);
  transform: rotate(90deg);
}

#settings-tabs {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 8px;
  flex: 1;
}

#settings-tabs .tab {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.2s ease;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
}

#settings-tabs .tab:hover {
  color: var(--text-primary);
  background: var(--hover-bg);
}

#settings-tabs .tab.active {
  color: var(--accent);
  background: var(--hover-bg);
}

.tab-icon {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 1.5;
  flex-shrink: 0;
}

#settings-content-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

#settings-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  flex-shrink: 0;
}

#settings-body {
  flex: 1;
  padding: 0 24px 24px;
  overflow-y: auto;
  background: var(--bg-main);
}

.prompt-editor {
  width: 100%;
  height: 400px;
  max-height: 50vh;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-primary);
  font-family: "Fira Code", "JetBrains Mono", monospace;
  font-size: 13px;
  line-height: 1.6;
  padding: 16px;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-shadow: var(--shadow-sm) inset;
}

.prompt-editor:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2), var(--shadow-sm) inset;
}

/* ===== 个性化配置 ===== */
.config-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  margin-top: 8px;
}

.config-row input[type="text"] {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 14px;
  padding: 10px 14px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.config-row input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.config-row input[type="text"]::placeholder {
  color: var(--text-secondary);
}

/* ===== 模型参数面板 ===== */
.memory-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
  padding-right: 4px;
}

.memory-panel .prompt-editor {
  flex: 1;
  min-height: 200px;
}

/* ===== 结构化记忆 ===== */
#memory-structured {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.memory-category h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary, #888);
  margin-bottom: 8px;
}

.memory-items {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.memory-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg-input, #f5f5f5);
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.4;
}

.memory-item .memory-text {
  flex: 1;
  color: var(--text-primary, #333);
  word-break: break-word;
}

.memory-item .memory-date {
  font-size: 11px;
  color: var(--text-secondary, #999);
  white-space: nowrap;
  flex-shrink: 0;
}

.memory-item .memory-delete-btn {
  background: none;
  border: none;
  color: var(--text-secondary, #999);
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
  line-height: 1;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}

.memory-item:hover .memory-delete-btn {
  opacity: 1;
}

.memory-item .memory-delete-btn:hover {
  color: #e74c3c;
}

.memory-item.memory-stale {
  opacity: 0.55;
  border-left: 2px solid var(--text-secondary);
}

.memory-item.memory-stale .memory-text::after {
  content: " (过期)";
  color: var(--text-secondary);
  font-size: 0.85em;
}

.memory-empty {
  font-size: 13px;
  color: var(--text-secondary, #999);
  padding: 4px 0;
}

.memory-add-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
}

.memory-add-form select {
  background: var(--bg-input, #f5f5f5);
  border: 1px solid var(--border, #ddd);
  border-radius: 8px;
  color: var(--text-primary, #333);
  font-size: 13px;
  padding: 7px 10px;
  outline: none;
  flex-shrink: 0;
}

.memory-add-form input[type="text"] {
  flex: 1;
  min-width: 0;
  background: var(--bg-input, #f5f5f5);
  border: 1px solid var(--border, #ddd);
  border-radius: 8px;
  color: var(--text-primary, #333);
  font-size: 13px;
  padding: 7px 10px;
  outline: none;
  font-family: inherit;
}

.memory-add-form input[type="text"]:focus {
  border-color: var(--accent, #3b82f6);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.memory-add-form button {
  background: var(--accent, #3b82f6);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.memory-add-form button:hover {
  filter: brightness(1.1);
}

.memory-hint {
  font-size: 12px;
  color: var(--text-secondary, #999);
  margin-top: -4px;
}

/* ===== 记忆工具栏 ===== */
.memory-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.memory-search-wrapper {
  flex: 1;
  position: relative;
}

.memory-search-wrapper input {
  width: 100%;
  background: var(--bg-input, #f5f5f5);
  border: 1px solid var(--border, #ddd);
  border-radius: 8px;
  color: var(--text-primary, #333);
  font-size: 13px;
  padding: 7px 28px 7px 10px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.memory-search-wrapper input:focus {
  border-color: var(--accent, #3b82f6);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.memory-search-wrapper input::placeholder {
  color: var(--text-secondary, #999);
}

.memory-search-clear {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-secondary, #999);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
}

.memory-search-clear:hover {
  color: var(--text-primary);
}

.memory-toolbar-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.memory-action-btn {
  background: transparent;
  border: 1px solid var(--border, #ddd);
  border-radius: 8px;
  color: var(--text-secondary, #999);
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.memory-action-btn:hover {
  color: var(--text-primary);
  border-color: var(--accent, #3b82f6);
  background: var(--hover-bg);
}

.memory-action-btn.loading {
  opacity: 0.5;
  cursor: wait;
  pointer-events: none;
}
.memory-action-btn.loading svg {
  animation: spin 1s linear infinite;
}

/* ===== 记忆徽章 ===== */
.memory-importance {
  font-size: 12px;
  flex-shrink: 0;
  line-height: 1;
}

.memory-importance[data-level="1"] {
  color: var(--text-secondary, #999);
}

.memory-importance[data-level="2"] {
  color: #f59e0b;
}

.memory-importance[data-level="3"] {
  color: #ef4444;
}

.memory-use-count {
  font-size: 11px;
  color: var(--accent, #3b82f6);
  background: rgba(59, 130, 246, 0.1);
  border-radius: 10px;
  padding: 1px 6px;
  flex-shrink: 0;
  white-space: nowrap;
  line-height: 1.4;
}

/* ===== 记忆搜索过滤 ===== */
.memory-item.memory-filtered,
.memory-category.memory-filtered {
  display: none;
}

/* ===== Memory Timeline ===== */
.memory-timeline {
  border: 1px solid var(--border, #ddd);
  border-radius: 12px;
  background: var(--bg-input, #f5f5f5);
  margin-bottom: 16px;
  overflow: hidden;
  animation: slideDown 0.2s ease-out;
}

@keyframes slideDown {
  from { opacity: 0; max-height: 0; }
  to   { opacity: 1; max-height: 500px; }
}

.timeline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border, #ddd);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.timeline-clear-btn {
  background: none;
  border: 1px solid var(--border, #ddd);
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 12px;
  padding: 3px 10px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.timeline-clear-btn:hover {
  color: #ef4444;
  border-color: #ef4444;
}

.timeline-list {
  max-height: 300px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 14px;
}

.timeline-empty {
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
  padding: 24px 0;
}

.timeline-day {
  background: var(--bg-input, #f5f5f5);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 6px 0 4px;
  border-bottom: 1px solid var(--border, #ddd);
  margin-bottom: 8px;
}

.timeline-batch {
  position: relative;
  padding-left: 16px;
  margin-bottom: 12px;
  border-left: 2px solid var(--border, #ddd);
}

.timeline-batch::before {
  content: '';
  position: absolute;
  left: -5px;
  top: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent, #3b82f6);
}

.timeline-batch-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.timeline-time {
  font-size: 12px;
  color: var(--text-secondary);
  font-family: "Consolas", "Menlo", monospace;
}

.timeline-source {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(59, 130, 246, 0.1);
  color: var(--accent, #3b82f6);
  text-decoration: none;
}

a.timeline-source:hover {
  background: rgba(59, 130, 246, 0.2);
}

.timeline-source.source-reflect {
  background: rgba(168, 85, 247, 0.1);
  color: #a855f7;
}

.timeline-source.source-undo {
  background: rgba(249, 115, 22, 0.1);
  color: #f97316;
}

.timeline-op {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-primary);
}

.timeline-op-tag {
  font-size: 11px;
  font-weight: 600;
  padding: 0 5px;
  border-radius: 3px;
  flex-shrink: 0;
  line-height: 1.6;
}

.timeline-op-tag.op-add    { background: rgba(34, 197, 94, 0.15); color: #22c55e; }
.timeline-op-tag.op-update,
.timeline-op-tag.op-merge  { background: rgba(59, 130, 246, 0.15); color: #3b82f6; }
.timeline-op-tag.op-delete { background: rgba(239, 68, 68, 0.15); color: #ef4444; }
.timeline-op-tag.op-undo   { background: rgba(249, 115, 22, 0.15); color: #f97316; }

.timeline-cat {
  font-size: 11px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.timeline-text {
  word-break: break-all;
}

.config-panel {
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow-y: auto;
  padding-right: 4px;
}

.config-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.config-row label {
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toggle-row {
  flex-direction: row;
  align-items: center;
}
.toggle-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}
.toggle-row .config-hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-secondary);
  flex: 1;
}

.config-val {
  font-family: "Consolas", "Menlo", monospace;
  font-size: 13px;
  color: var(--text-user-msg);
  background: var(--accent);
  padding: 2px 8px;
  border-radius: 12px;
  min-width: 40px;
  text-align: center;
  font-weight: 600;
}

.slider-label-group {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.config-row select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 14px;
  padding: 10px 14px;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}

.config-row select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.config-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
  height: 6px;
  border-radius: 3px;
}

.config-hint {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

#settings-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-main);
  flex-shrink: 0;
}

#save-status {
  font-size: 13px;
  color: var(--accent);
  font-weight: 500;
}

#save-prompts {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 24px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
}

#save-prompts:hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

/* ===== 人格指令工具栏 ===== */
.system-toolbar {
  display: flex;
  align-items: stretch;
  margin-bottom: 10px;
}

.system-toolbar .toolbar-group {
  display: flex;
  gap: 4px;
  align-items: stretch;
  width: 100%;
}

.system-toolbar .toolbar-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  text-align: center;
}

.system-toolbar .toolbar-btn:hover {
  color: var(--text-primary);
  background: var(--hover-bg);
  border-color: var(--text-secondary);
}

.system-toolbar .toolbar-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.system-toolbar .toolbar-btn.active {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.08);
}

.system-toolbar .toolbar-icon {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
  flex-shrink: 0;
}

.system-toolbar .toolbar-chevron {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.system-toolbar .toolbar-btn.active .toolbar-chevron {
  transform: rotate(180deg);
}

/* ===== 版本历史面板 ===== */
.version-history {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-main);
  overflow: hidden;
  contain: paint;
  animation: slideDown 0.25s ease-out;
}

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

.version-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: min(200px, 30vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px;
}

.version-empty {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
  padding: 20px 0;
}

.version-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-input);
  border-radius: 10px;
  transition: background 0.15s ease;
}

.version-item:hover {
  background: var(--hover-bg);
}

.version-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

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

.version-time {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.version-preview {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

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

.version-action-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  font-size: 12px;
  padding: 4px 10px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
  white-space: nowrap;
}

.version-action-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
  background: var(--hover-bg);
}

.version-action-btn.restore-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.08);
}

.version-action-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.version-loading {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
  padding: 16px 0;
}

/* ===== Diff 对比 Overlay ===== */
.diff-overlay {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  background: var(--overlay-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  animation: fadeIn 0.2s ease-out;
}

.diff-panel {
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 900px;
  max-width: 92vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-float);
  overflow: hidden;
  animation: slideUpModal 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.diff-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.diff-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.diff-version-info {
  font-size: 12px;
  color: var(--text-secondary);
  margin-left: auto;
}

.diff-close-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-secondary);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.diff-close-btn:hover {
  background: var(--hover-bg);
  color: var(--text-primary);
  transform: rotate(90deg);
}

.diff-close-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.diff-body {
  display: flex;
  gap: 1px;
  background: var(--border);
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

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

.diff-col-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.diff-content {
  flex: 1;
  margin: 0;
  padding: 16px;
  overflow-y: auto;
  font-family: "Fira Code", "JetBrains Mono", monospace;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--bg-input);
}

.diff-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.btn-primary:focus-visible,
.btn-secondary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.btn-secondary:hover {
  color: var(--text-primary);
  border-color: var(--text-secondary);
  background: var(--hover-bg);
}

/* Diff overlay 移动端适配 */
@media (max-width: 640px) {
  .diff-body {
    flex-direction: column;
    overflow-y: auto;
  }
  .diff-panel {
    max-width: 96vw;
    max-height: 90vh;
  }
}

/* 滚动条 */
::-webkit-scrollbar {
  width: 6px;
}

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

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

/* ===== 消息 meta 信息 ===== */
.message-meta {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 8px;
  opacity: 0.6;
  font-family: "Fira Code", "Consolas", monospace;
}

.message:hover .message-meta {
  opacity: 1;
}

/* ===== 记忆引用指示器 ===== */
.memory-ref-badge {
  cursor: pointer;
  color: var(--accent);
  transition: opacity 0.2s;
}
.memory-ref-badge:hover {
  opacity: 0.8;
}
.memory-ref-panel {
  margin-top: 6px;
  padding: 8px 12px;
  background: var(--bg-secondary);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}
.memory-ref-panel.hidden {
  display: none;
}
.memory-ref-category {
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 4px;
  font-size: 12px;
}
.memory-ref-category:first-child {
  margin-top: 0;
}
.memory-ref-item {
  padding-left: 8px;
  font-size: 13px;
}

/* ===== 记忆引用开关：全局隐藏 ===== */
.hide-memory-refs .memory-ref-badge,
.hide-memory-refs .memory-ref-panel {
  display: none !important;
}

/* ===== 思考链折叠块 ===== */
.thinking-block {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 13px;
  overflow: hidden;
}

.thinking-block summary {
  padding: 8px 12px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13px;
  user-select: none;
  list-style: none;
}

.thinking-block summary::before {
  content: "▶ ";
  font-size: 10px;
  transition: transform 0.15s;
  display: inline-block;
}

.thinking-block[open] summary::before {
  transform: rotate(90deg);
}

.thinking-block summary:hover {
  color: var(--text-primary);
}

.thinking-body {
  padding: 0 12px 10px;
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.6;
  max-height: 400px;
  overflow-y: auto;
  border-top: 1px solid var(--border);
}

.thinking-body p {
  margin-bottom: 8px;
}

.thinking-body p:last-child {
  margin-bottom: 0;
}

.thinking-streaming summary {
  color: var(--accent);
  animation: none;
}

.thinking-streaming summary::before {
  content: none;
}

.thinking-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: thinking-spin 0.8s linear infinite;
  vertical-align: middle;
}

@keyframes thinking-spin {
  to { transform: rotate(360deg); }
}

/* ===== 搜索状态指示器 ===== */
.search-status {
  color: var(--accent);
  font-size: 13px;
  padding: 8px 0;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: pulse 1.5s ease-in-out infinite;
}

.search-status::before {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.6;
  }
}

/* ===== Auto-learn card ===== */
.learn-card {
  position: fixed;
  right: max(24px, env(safe-area-inset-right));
  bottom: max(24px, env(safe-area-inset-bottom));
  width: min(380px, calc(100vw - 32px));
  background: var(--bg-secondary);
  color: var(--text-primary, var(--text));
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 14px;
  font-size: 13px;
  z-index: 100;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.18);
  animation: learn-toast-in 220ms ease-out;
  overflow: hidden;
}

.learn-card.fade-out {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 250ms ease, transform 250ms ease;
}

.learn-card-header {
  padding: 12px 14px 6px;
  color: var(--text-primary, var(--text));
  font-weight: 600;
}

.learn-card-details {
  padding: 4px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.learn-op {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary, #aaa);
  line-height: 1.5;
}

.learn-op-icon {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.learn-op-add .learn-op-icon { background: rgba(16, 185, 129, 0.2); color: #10b981; }
.learn-op-update .learn-op-icon { background: rgba(245, 158, 11, 0.2); color: #f59e0b; }
.learn-op-delete .learn-op-icon { background: rgba(239, 68, 68, 0.2); color: #ef4444; }
.learn-op-merge .learn-op-icon { background: rgba(99, 102, 241, 0.2); color: #6366f1; }

.learn-op-label {
  font-weight: 500;
  flex-shrink: 0;
}

.learn-op-add .learn-op-label { color: #10b981; }
.learn-op-update .learn-op-label { color: #f59e0b; }
.learn-op-delete .learn-op-label { color: #ef4444; }
.learn-op-merge .learn-op-label { color: #6366f1; }

.learn-op-cat {
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  flex-shrink: 0;
}

.learn-op-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-size: 12px;
}

.learn-card-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 6px 14px 8px;
}

.learn-undo-btn {
  background: transparent;
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 3px 12px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
}

.learn-undo-btn:hover:not(:disabled) {
  background: rgba(16, 163, 127, 0.15);
}

.learn-undo-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.learn-close-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary, #aaa);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.learn-close-btn:hover {
  color: var(--text);
}

@keyframes learn-toast-in {
  from {
    transform: translateY(8px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@media (max-width: 520px) {
  .learn-card {
    right: 16px;
    bottom: max(16px, env(safe-area-inset-bottom));
    width: calc(100vw - 32px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .learn-card,
  .learn-card.fade-out {
    animation: none;
    transition: none;
  }
}

/* ===== Linear Programming Graph ===== */
#linear-programming-graph-wrapper {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#linear-programming-graph {
  display: block;
  width: 100%;
  max-width: 520px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-main);
}

#linear-programming-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 12px;
  color: var(--text-secondary);
}

/* ===== 导入与总结面板 ===== */
#edit-import {
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  max-height: 55vh;
}

/* 拖拽上传区 */
#import-drop-zone {
  border: 2px dashed var(--border);
  border-radius: 16px;
  padding: 32px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  background: var(--bg-main);
}

#import-drop-zone:hover,
#import-drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.05);
}

#import-help {
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--hover-bg);
  padding: 12px 16px;
  border-radius: 12px;
}

#import-help summary {
  cursor: pointer;
  font-weight: 500;
  color: var(--text-primary);
}

#import-help ol {
  margin: 8px 0 0 0;
  padding-left: 20px;
  line-height: 1.8;
}

#import-help a {
  color: var(--accent);
}

.drop-zone-content svg {
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.drop-zone-content p {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.import-btn-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

#import-file-btn,
#import-folder-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s;
}

#import-file-btn:hover,
#import-folder-btn:hover {
  border-color: var(--accent);
}

#import-folder-btn {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

#import-folder-btn:hover {
  opacity: 0.9;
}

#import-parsing {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
}

#import-parsing p {
  font-size: 14px;
  color: var(--text-secondary);
}

#import-error {
  color: #e74c3c;
  font-size: 13px;
  padding: 8px 12px;
  background: rgba(231, 76, 60, 0.1);
  border-radius: 8px;
}

/* 范围切换 */
#import-scope-toggle {
  display: inline-flex;
  gap: 0;
  background: var(--bg-input);
  padding: 4px;
  border-radius: 12px;
}

.scope-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.scope-btn:hover {
  color: var(--text-primary);
}

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

.scope-btn.active {
  background: var(--bg-main);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* 对话列表 */
#import-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--text-secondary);
}

#import-list-header label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
}

#import-conv-list {
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-main);
}

.import-conv-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.1s;
  border-bottom: 1px solid var(--border);
}

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

.import-conv-item:hover {
  background: var(--hover-bg);
}

.import-conv-item input[type="checkbox"] {
  flex-shrink: 0;
  accent-color: var(--accent);
}

.import-conv-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-primary);
}

.import-conv-meta {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* 操作按钮 */
#import-actions {
  display: flex;
  gap: 10px;
}

#import-do-btn,
#summary-generate-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: opacity 0.15s;
}

#import-do-btn:hover,
#summary-generate-btn:hover {
  opacity: 0.9;
}

#import-do-btn:disabled,
#summary-generate-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 进度条 */
#import-progress {
  display: flex;
  align-items: center;
  gap: 12px;
}

#import-progress-bar {
  flex: 1;
  height: 8px;
  background: var(--bg-input);
  border-radius: 4px;
  overflow: hidden;
}

#import-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  width: 0%;
  transition: width 0.3s ease;
}

#import-progress-text {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  min-width: 100px;
  text-align: right;
}

#import-result {
  font-size: 13px;
  color: var(--accent);
  padding: 8px 0;
}

#import-result.error {
  color: #e74c3c;
}

/* 总结区 */
#summary-section {
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#summary-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text-secondary);
}

/* spinner 复用现有 @keyframes spin */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* 总结结果 */
#import-summary-result h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
}

#import-summary-result .prompt-editor {
  height: 180px;
  max-height: 30vh;
  margin-bottom: 12px;
}

#summary-notes {
  margin-bottom: 12px;
}

#summary-notes h4 {
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--text-secondary);
}

#summary-notes-content {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  padding: 8px 12px;
  background: var(--bg-input);
  border-radius: 8px;
  white-space: pre-wrap;
}

.summary-warning {
  font-size: 12px;
  color: #e6a817;
  padding: 8px 12px;
  background: rgba(230, 168, 23, 0.1);
  border-radius: 6px;
  margin-bottom: 10px;
}

.summary-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 0 0 10px 0;
}

#summary-merge-actions,
#merge-apply-actions {
  display: flex;
  gap: 10px;
}

#summary-merge-btn,
#merge-apply-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: opacity 0.15s;
}

#summary-merge-btn:hover,
#merge-apply-btn:hover {
  opacity: 0.9;
}

#summary-merge-btn:disabled,
#merge-apply-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#summary-merge-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text-secondary);
}

/* 融合结果区 */
#import-merge-result h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
}

#import-merge-result .prompt-editor {
  height: 180px;
  max-height: 30vh;
  margin-bottom: 12px;
}

.secondary-btn {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: border-color 0.15s;
}

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

#summary-apply-status {
  font-size: 13px;
  color: var(--accent);
  padding: 4px 0;
}

/* ===== 移动端侧边栏遮罩 ===== */
#sidebar-backdrop {
  display: none;
}

/* ===== 移动端适配 ===== */
@media (max-width: 768px) {
  body,
  #app {
    height: 100dvh;
  }

  /* 侧边栏：固定覆盖层 */
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    z-index: 50;
    transform: translateX(0);
    transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
    margin-left: 0 !important;
    border-right: 1px solid var(--border) !important;
  }

  .sidebar-brand-mark {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
  }

  .sidebar-brand-copy strong {
    font-size: 18px;
  }

  #sidebar-toggle-checkbox:checked ~ #sidebar {
    transform: translateX(-100%);
  }

  /* 始终显示主区域的侧边栏切换按钮 */
  .main-toggle-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
  }

  /* 侧边栏遮罩 */
  #sidebar-backdrop {
    display: block;
    position: fixed;
    top: 0; right: 0; bottom: 0; left: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 40;
  }

  #sidebar-backdrop.hidden {
    display: none;
  }

  /* 消息气泡适配 */
  .message {
    padding: 12px 16px;
  }

  .message.user .bubble {
    max-width: min(90%, calc(100% - 64px));
  }

  /* 输入区收窄 */
  #input-area {
    padding: 0 12px 12px;
  }

  /* 顶栏收窄 */
  #top-bar {
    padding: 8px 12px;
  }

  /* 设置弹窗：移动端全屏 */
  #settings-panel {
    flex-direction: column;
    max-width: 100vw;
    max-height: 100dvh;
    width: 100%;
    height: 100%;
    border-radius: 0;
  }

  #settings-sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    flex-direction: row;
    overflow-x: auto;
    flex-shrink: 0;
  }

  #settings-header {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
  }

  #settings-tabs {
    flex-direction: row;
    padding: 0 8px;
    flex: unset;
    overflow-x: auto;
  }

  #settings-tabs .tab {
    white-space: nowrap;
    flex-shrink: 0;
  }
}

/* ===== Modales de calculadoras ===== */
#linear-programming-modal,
#simplex-modal,
#transport-modal,
#eoq-modal {
  background: rgba(2, 6, 23, 0.58) !important;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

#linear-programming-modal > form,
#simplex-modal > form,
#transport-modal > form,
#eoq-modal > form {
  background: var(--bg-input) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border);
  border-radius: 16px !important;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.28);
}

#linear-programming-modal h2,
#simplex-modal h2,
#transport-modal h2,
#eoq-modal h2 {
  color: var(--text-primary);
}

#linear-programming-modal input,
#linear-programming-modal textarea,
#linear-programming-modal select,
#simplex-modal input,
#simplex-modal textarea,
#simplex-modal select,
#transport-modal input,
#transport-modal textarea,
#transport-modal select,
#eoq-modal input,
#eoq-modal textarea,
#eoq-modal select {
  box-sizing: border-box;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-main);
  color: var(--text-primary);
  font: inherit;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

#linear-programming-modal input:focus,
#linear-programming-modal textarea:focus,
#linear-programming-modal select:focus,
#simplex-modal input:focus,
#simplex-modal textarea:focus,
#simplex-modal select:focus,
#transport-modal input:focus,
#transport-modal textarea:focus,
#transport-modal select:focus,
#eoq-modal input:focus,
#eoq-modal textarea:focus,
#eoq-modal select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(59 130 246 / 20%);
}

#linear-programming-modal button,
#simplex-modal button,
#transport-modal button,
#eoq-modal button {
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--hover-bg);
  color: var(--text-primary);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease,
              box-shadow 160ms ease, border-color 160ms ease;
}

#linear-programming-modal button[type="submit"],
#simplex-modal button[type="submit"],
#transport-modal button[type="submit"],
#eoq-modal button[type="submit"] {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

#linear-programming-modal button:hover,
#simplex-modal button:hover,
#transport-modal button:hover,
#eoq-modal button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

#linear-programming-modal button[type="submit"]:hover,
#simplex-modal button[type="submit"]:hover,
#transport-modal button[type="submit"]:hover,
#eoq-modal button[type="submit"]:hover {
  background: var(--accent-hover);
}

#linear-programming-modal button:disabled,
#simplex-modal button:disabled,
#transport-modal button:disabled,
#eoq-modal button:disabled {
  opacity: 0.6;
  cursor: wait;
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  #linear-programming-modal *,
  #simplex-modal *,
  #transport-modal *,
  #eoq-modal * {
    transition-duration: 0.01ms;
  }
}
