@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Playfair+Display:wght@600&display=swap');

:root {
  color-scheme: light;
  --bg: #f5f5f7;
  --panel: #ffffff;
  --panel-dark: #e5e5ea;
  --primary: #1d1d1f;
  --primary-dark: #0d0d0d;
  --accent: #6e6e73;
  --text: #1d1d1f;
  --muted: #86868b;
  --border: #d2d2d7;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.04);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Space Grotesk', 'Segoe UI', sans-serif;
  color: var(--text);
  background: var(--bg);
  height: 100vh;
  overflow: hidden;
  display: flex;
  gap: 20px;
  padding: 20px;
  box-sizing: border-box;
}

.bg-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(40px);
  opacity: 0;
  z-index: 0;
}

.orb-1 {
  width: 520px;
  height: 520px;
  background: radial-gradient(circle at 30% 30%, rgba(210, 210, 215, 0.6), transparent 70%);
  top: -140px;
  left: -120px;
}

.orb-2 {
  width: 420px;
  height: 420px;
  background: radial-gradient(circle at 30% 30%, rgba(199, 199, 204, 0.55), transparent 70%);
  bottom: -160px;
  right: -120px;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image: linear-gradient(transparent 92%, rgba(31, 25, 18, 0.08) 92%),
    linear-gradient(90deg, transparent 92%, rgba(31, 25, 18, 0.08) 92%);
  background-size: 80px 80px;
  opacity: 0;
  z-index: 0;
}

.app {
  flex: 1;
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  width: 300px;
  flex-shrink: 0;
  background: var(--panel);
  border-radius: 0;
  padding: 20px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  border: none;
  animation: floatIn 0.6s ease;
  position: relative;
  height: calc(100vh - 40px);
}

.sidebar-close {
  position: absolute;
  top: 16px;
  right: 16px;
  display: none;
  z-index: 102;
}

/* 默认隐藏 menu toggle（宽屏不需要） */
.menu-toggle {
  display: none !important;
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 50;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  pointer-events: none;
}

.sidebar-overlay.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 0;
  background: linear-gradient(140deg, #1d1d1f, #424245);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-family: 'Playfair Display', serif;
  font-size: 22px;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}

.brand-title {
  font-size: 18px;
  font-weight: 700;
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 1px;
  text-transform: uppercase;
}

.sidebar-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-header h3 {
  margin: 0;
  font-size: 14px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
}

.topic-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
  padding-right: 6px;
}

.topic-card {
  padding: 16px;
  border-radius: 0;
  background: var(--panel-dark);
  border: none;
  cursor: grab;
  transition: 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topic-card:active {
  cursor: grabbing;
}

/* 拖拽中的元素 */
.topic-card.dragging {
  opacity: 0.5;
  transform: scale(0.98);
}

/* 拖拽经过的目标元素 */
.topic-card.drag-over {
  background: #d4d4d8;
  transform: translateY(2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.topic-card.active {
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.08);
  background: #e5e5ea;
  border-left: 3px solid var(--primary);
}

.topic-card h4 {
  margin: 0;
  font-size: 15px;
  flex: 1;
  min-width: 0;
}

.topic-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topic-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.sidebar-footer {
  margin-top: 18px;
}

.chat {
  flex: 1;
  min-height: 0;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 0;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow);
  border: none;
  backdrop-filter: blur(12px);
  animation: floatIn 0.8s ease;
}

.chat-header {
  flex: 0 0 auto;
}

.topic-info {
  width: 100%;
}

.topic-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}

.topic-title-row .menu-toggle {
  flex-shrink: 0;
}

.topic-info h2 {
  margin: 0;
  font-size: 24px;
  flex: 1;
  min-width: 0;
}

.topic-info p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  max-width: 50%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header-controls {
  flex-shrink: 0;
}

.messages {
  flex: 1;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 0;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.message {
  max-width: 75%;
  padding: 12px 18px;
  border-radius: 0;
  line-height: 1.6;
  font-size: 14px;
  word-break: break-word;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.05);
  animation: popIn 0.3s ease;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
}

.message.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #1d1d1f, #424245);
  color: #fff;
}

.message.assistant {
  align-self: flex-start;
  background: #ffffff;
  border: none;
}

.message.error {
  background: #fff1f0;
  border: none;
  color: #9f2d1f;
}

.message pre {
  background: #f8f6f1;
  padding: 12px;
  border-radius: 12px;
  overflow-x: auto;
  border: none;
}

.message code {
  font-family: 'SFMono-Regular', 'Fira Code', monospace;
  font-size: 13px;
}

.message pre code {
  background: none;
  padding: 0;
}

.message a {
  color: inherit;
  text-decoration: underline;
}

.message > *:first-child {
  margin-top: 0;
}

/* 复制按钮是最后一个子元素，不需要 margin-bottom */
.message > .message-copy-btn {
  margin-bottom: 0;
}

.message p {
  margin: 0;
  line-height: inherit;
}

.message p + p {
  margin-top: 8px;
}

/* 消息内容容器 */
.message-content {
  flex: 1;
}

/* 复制按钮 */
.message-copy-btn {
  position: absolute;
  bottom: -28px;
  left: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  background: #fff;
  border: 1px solid var(--border);
  padding: 4px 8px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  border-radius: 0;
  transition: opacity 0.3s ease 1s;
  opacity: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  white-space: nowrap;
  z-index: 10;
}

/* 用户消息的复制按钮靠右对齐 */
.message.user .message-copy-btn {
  right: 0;
  left: auto;
}

/* 鼠标在消息上时显示按钮 */
.message:hover .message-copy-btn {
  opacity: 1;
  transition: opacity 0.3s ease 0.1s;
}

/* 鼠标在按钮上时保持显示 */
.message-copy-btn:hover {
  opacity: 1;
  transition: opacity 0s;
}

.message-copy-btn:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text);
}

.message.user .message-copy-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.message-copy-btn.copied {
  color: #10b981;
}

.message-copy-btn.copied:hover {
  background: rgba(16, 185, 129, 0.1);
}

.message-copy-btn svg {
  flex-shrink: 0;
}

.message-copy-btn span {
  white-space: nowrap;
}

/* 思维链小气泡 */
.message-reasoning {
  background: rgba(0, 0, 0, 0.04);
  border: 1px solid rgba(0, 0, 0, 0.08);
  padding: 6px 10px;
  font-size: 11px;
  color: var(--muted);
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 200px;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  margin-bottom: 6px;
}

/* 助手消息的思维链样式 */
.message.assistant .message-reasoning {
  background: rgba(0, 0, 0, 0.04);
  border-color: rgba(0, 0, 0, 0.08);
}

/* 用户消息的思维链样式（通常不会有，但保持一致） */
.message.user .message-reasoning {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.7);
}

/* 思维链文本预览 */
.reasoning-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 展开图标 */
.reasoning-expand {
  flex-shrink: 0;
  font-size: 10px;
  opacity: 0.6;
}

/* hover 效果 */
.message-reasoning:hover {
  background: rgba(0, 0, 0, 0.08);
  border-color: rgba(0, 0, 0, 0.15);
  max-width: 100%;
}

.message.assistant .message-reasoning:hover {
  background: rgba(0, 0, 0, 0.08);
}

.message.user .message-reasoning:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* 加载动画状态 */
.message-reasoning.loading {
  cursor: wait;
}

.message-reasoning.loading .reasoning-dots {
  font-family: monospace;
  min-width: 20px;
  display: inline-block;
}

.composer {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0;
  flex: 0 0 auto;
}

#messageInput {
  width: 100%;
  border: 1px solid var(--border);
  resize: vertical;
  font-family: inherit;
  font-size: 15px;
  outline: none;
  border-radius: 0;
  padding: 10px 12px;
  transition: all 0.2s ease;
}

#messageInput:focus {
  border-color: #007aff;
  box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.15);
}

.composer-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: nowrap;
}

.composer-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.composer-left .ghost-btn {
  flex-shrink: 0;
}

.composer-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

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

.control-inline label {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.control-inline select {
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 4px 8px;
  font-family: inherit;
  font-size: 13px;
  background: #fff;
  transition: all 0.2s ease;
}

.control-inline select:focus {
  outline: none;
  border-color: #007aff;
  box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.15);
}

.hint {
  font-size: 12px;
  color: var(--muted);
}

.primary-btn,
.ghost-btn,
.icon-btn {
  border: none;
  border-radius: 0;
  padding: 8px 14px;
  font-family: inherit;
  cursor: pointer;
  transition: 0.2s ease;
}

.primary-btn {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  transition: all 0.2s ease;
}

.primary-btn:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(30, 41, 59, 0.2);
}

.ghost-btn {
  background: #fff;
  border: none;
  color: var(--text);
  transition: all 0.2s ease;
}

.ghost-btn:hover {
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.06);
  background: var(--panel-dark);
}

.icon-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  display: grid;
  place-items: center;
  background: #fff;
  border: none;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.06);
  background: var(--panel-dark);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(29, 29, 31, 0.5);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 200;
}

.modal.open {
  display: flex;
}

.modal-content {
  width: min(680px, 90vw);
  max-height: 90vh;
  overflow-y: auto;
  background: #fff;
  border-radius: 0;
  padding: 28px 32px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.12);
  animation: popIn 0.3s ease;
}

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

.modal-header h3 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  color: var(--primary);
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 4px;
}

.card {
  padding: 18px 20px;
  border-radius: 0;
  border: 1px solid var(--border);
  background: #fafafa;
  transition: box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
}

/* 居中的卡片（用于重置按钮） */
.card-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 24px 20px;
  border-color: rgba(159, 45, 31, 0.3);
  background: linear-gradient(135deg, #fff8f7, #fff);
}

.card-center .ghost-btn {
  font-size: 15px;
  padding: 10px 20px;
  font-weight: 600;
  border: 1px solid rgba(159, 45, 31, 0.4);
}

.form-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--primary);
}

.field input,
.field textarea,
.field select {
  padding: 11px 14px;
  border-radius: 0;
  border: 1px solid var(--border);
  font-family: inherit;
  font-size: 14px;
  transition: all 0.2s ease;
  background: #fff;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: #007aff;
  box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.15);
  background: #fff;
}

.field input::placeholder,
.field textarea::placeholder {
  color: #b0b0b5;
}

.field textarea {
  resize: vertical;
  line-height: 1.5;
}

/* Range slider wrapper */
.range-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.range-wrap input[type="range"] {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.range-wrap input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.range-wrap input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.range-wrap span {
  min-width: 40px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  color: var(--primary);
}

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

.profile-list {
  display: grid;
  gap: 12px;
}

.profile-item {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 14px 16px;
  border-radius: 0;
  border: 1px solid var(--border);
  background: #fff;
  transition: box-shadow 0.2s ease;
}

.profile-item:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.profile-item > div:first-child {
  flex: 1;
  min-width: 0;
}

.profile-item > div:first-child > div:first-child {
  font-weight: 500;
  color: var(--primary);
  margin-bottom: 4px;
}

.profile-meta {
  font-size: 12px;
  color: var(--muted);
}

.muted {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

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

@keyframes floatIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 980px) {
  /* 窄屏时 body 变成块级布局 */
  body {
    flex-direction: column;
    padding: 0;
  }

  /* 隐藏侧栏（默认收起） */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 320px;
    max-width: 85vw;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    border-radius: 0;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .app {
    width: 100%;
    padding: 0;
    height: 100vh;
  }

  /* 窄屏时移除多余的分块感 */
  .chat {
    background: transparent;
    border-radius: 0;
    padding: 16px;
    box-shadow: none;
    border: none;
    backdrop-filter: none;
  }

  .messages {
    background: transparent;
    border-radius: 0;
    padding: 8px;
  }

  .sidebar-close {
    display: grid;
  }

  /* 窄屏时显示 menu toggle 按钮 */
  .menu-toggle {
    display: grid !important;
  }

  /* 窄屏时标题和模型选择保持在一行 */
  .topic-title-row {
    flex-wrap: nowrap;
    gap: 12px;
  }

  .chat-header-controls {
    flex-shrink: 0;
  }

  .topic-info h2 {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .composer-main {
    flex-wrap: nowrap;
  }

  .composer-left {
    gap: 8px;
  }
}

@media (max-width: 640px) {
  body {
    overflow: auto;
  }

  .chat {
    padding: 12px;
  }

  .messages {
    max-height: none;
    padding: 4px;
  }

  .topic-card {
    min-width: 200px;
  }

  .composer-left {
    gap: 6px;
  }

  /* 超窄屏时也确保按钮不换行 */
  .composer-main {
    flex-wrap: nowrap;
  }

  /* 窄屏时隐藏发送提示和用户提示词 */
  .composer-right .hint,
  .topic-info p {
    display: none;
  }
}

/* 冲突解决弹窗样式 */
.conflict-info {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 16px 0;
  padding: 16px;
  background: #fafafa;
  border-radius: 0;
  border: 1px solid var(--border);
}

.conflict-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.conflict-item strong {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
}

.conflict-item span {
  font-size: 14px;
  color: var(--text);
  padding-left: 12px;
}

/* 冲突弹窗的按钮样式 */
#conflictModal .form-actions {
  justify-content: center;
}

#conflictModal .form-actions .primary-btn {
  min-width: 140px;
}

/* 上下文截断标记样式 */
.context-cutoff {
  margin: 16px 0;
  padding: 12px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  position: relative;
}

.cutoff-line {
  width: 100%;
  height: 2px;
  background: repeating-linear-gradient(
    to right,
    var(--border) 0px,
    var(--border) 8px,
    transparent 8px,
    transparent 16px
  );
  border-radius: 1px;
}

.cutoff-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  color: var(--muted);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.cutoff-label svg {
  flex-shrink: 0;
  opacity: 0.6;
}

.cutoff-label span {
  white-space: nowrap;
}

/* 语言切换器样式 */
.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 12px;
}

.language-switcher {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--panel-dark);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px;
  transition: all 0.2s ease;
}

.language-switcher:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.lang-option {
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 500;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s ease;
  position: relative;
}

.lang-option:hover {
  color: var(--text);
  background: rgba(0, 0, 0, 0.05);
}

.lang-option.active {
  background: #fff;
  color: var(--primary);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
  font-weight: 600;
}

.lang-divider {
  width: 1px;
  height: 16px;
  background: var(--border);
}

/* 窄屏适配 */
@media (max-width: 640px) {
  .sidebar-footer {
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
  }

  .language-switcher {
    justify-content: center;
  }
}
