/* ========== 主页面样式 ========== */

/* ========== 覆盖公共变量 ========== */
:root {
  /* 侧边栏颜色 */
  --sidebar-bg: #F5F5F7;
  --sidebar-hover: #E8E8ED;
  --sidebar-active: #E0E0E5;
  --sidebar-text: #333333;
  --sidebar-text-muted: #999999;
  --sidebar-border: #E5E5EA;

  /* 聊天区域颜色 */
  --chat-bg: #FFFFFF;
  --chat-card: #FFFFFF;
  --chat-text: #333333;
  --chat-text-muted: #8E8E93;
  --chat-border: #E5E5EA;

  /* 消息颜色 */
  --ai-message-bg: #F7F7F8;
  --user-message-bg: #E8F4FF;
  --user-message-border: #D4E8FF;
}

/* ========== 页面布局 ========== */
body {
  background: var(--chat-bg);
  height: 100vh;
  display: flex;
  overflow: hidden;
}

/* ========== 左侧侧边栏 ========== */
.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.3s ease, width 0.3s ease;
}

.sidebar-header {
  padding: 16px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.sidebar-logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  overflow: hidden;
}

.sidebar-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.sidebar-brand-text {
  display: flex;
  flex-direction: column;
}

.sidebar-brand-title {
  font-weight: 600;
  font-size: 16px;
  color: var(--sidebar-text);
  line-height: 1.3;
}

.sidebar-brand-subtitle {
  font-size: 12px;
  color: var(--sidebar-text-muted);
  line-height: 1.3;
}

.new-chat-btn {
  width: 100%;
  padding: 10px 12px;
  background: var(--sidebar-hover);
  border: 1px solid var(--primary);
  border-radius: 8px;
  color: var(--primary);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  transition: background-color 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
}

.new-chat-btn:hover {
  background: var(--sidebar-active);
}

.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px 8px;
  display: flex;
  flex-direction: column;
}

.chat-history-title {
  font-size: 11px;
  font-weight: 500;
  color: var(--sidebar-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 12px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  background: var(--sidebar-bg);
  z-index: 1;
}

.chat-history-item {
  padding: 10px 12px;
  cursor: pointer;
  border-radius: 8px;
  margin-bottom: 2px;
  transition: background-color 0.15s ease;
  position: relative;
}

.chat-history-item:hover {
  background: var(--sidebar-hover);
}

.chat-history-item.active {
  background: var(--sidebar-active);
}

.chat-history-item .chat-title {
  font-size: 14px;
  color: var(--sidebar-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 24px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-history-item .chat-title .mode-icon {
  opacity: 0.5;
  flex-shrink: 0;
}

.chat-history-item .action-btns {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.chat-history-item:hover .action-btns {
  opacity: 1;
}

.chat-history-item .rename-btn,
.chat-history-item .delete-btn {
  background: transparent;
  border: none;
  color: var(--sidebar-text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: background-color 0.15s ease;
}

.chat-history-item .rename-btn:hover {
  background: var(--sidebar-active);
  color: var(--sidebar-text);
}

.chat-history-item .delete-btn:hover {
  background: rgba(255, 77, 79, 0.1);
  color: var(--error);
}

.sidebar-footer {
  padding: 8px;
  border-top: 1px solid var(--sidebar-border);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.user-info:hover {
  background: var(--sidebar-hover);
}

.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1890FF 0%, #36CFC9 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 12px;
  font-weight: 600;
}

.user-name {
  flex: 1;
  font-size: 13px;
  color: var(--sidebar-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logout-btn {
  background: transparent;
  border: none;
  color: var(--sidebar-text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: all 0.15s ease;
}

.logout-btn:hover {
  color: var(--error);
}

/* ========== 主聊天区域 ========== */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-width: 0;
  position: relative;
}

/* 顶部模型选择器 */
.chat-header {
  padding: 12px 24px;
  background: var(--chat-bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--chat-border);
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 200px;
}

.chat-header-center {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
}

.chat-header-right {
  min-width: 200px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}

.model-selector-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.model-selector {
  position: relative;
}

.model-selector select {
  appearance: none;
  padding: 8px 32px 8px 12px;
  background: var(--chat-card);
  border: 1px solid var(--chat-border);
  border-radius: 8px;
  color: var(--chat-text);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.2s ease;
  min-width: 180px;
}

.model-selector select:focus {
  outline: none;
  border-color: var(--primary);
}

.model-selector::after {
  content: '';
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--chat-text-muted);
  pointer-events: none;
}

.mobile-menu-btn {
  display: none;
  background: transparent;
  border: none;
  color: var(--chat-text);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
}

.mobile-menu-btn:hover {
  background: var(--chat-card);
}

/* 大屏侧边栏切换按钮 */
.sidebar-toggle-btn {
  display: flex;
  background: transparent;
  border: none;
  color: var(--chat-text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

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

/* 大屏侧边栏收起状态 */
.sidebar.collapsed {
  width: 0;
  overflow: hidden;
  padding: 0;
}

.sidebar.collapsed .sidebar-header,
.sidebar.collapsed .chat-history,
.sidebar.collapsed .sidebar-footer {
  opacity: 0;
  visibility: hidden;
}

.chat-title-input {
  background: transparent;
  border: none;
  color: var(--chat-text);
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  outline: none;
  text-align: center;
  max-width: 400px;
  opacity: 0;
  transition: opacity 0.2s;
}

/* ========== 消息区域 ========== */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
}

.message {
  max-width: 800px;
  margin: 0 auto 20px;
  display: flex;
  gap: 12px;
  width: 100%;
}

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

.message-content {
  flex: 1;
  min-width: 0; /* 修复 flexbox 子元素 min-width 问题 */
  padding: 0;
  border-radius: 0;
  line-height: 1.75;
  font-size: 15px;
  background: transparent;
  border: none;
  color: var(--chat-text);
  overflow-wrap: break-word;
}

/* AI 回复消息 - 无框样式 */
.assistant .message-content {
  background: transparent;
  border-radius: 0;
  padding: 0;
}

/* 用户消息 - 浅蓝色背景 */
.user .message-content {
  background: var(--user-message-bg);
  border: 1px solid var(--user-message-border);
  border-radius: 12px;
  padding: 12px 16px;
  max-width: 480px;
  width: fit-content;
  flex: none;
}

/* ========== 欢迎屏幕 ========== */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: 24px;
}

.welcome-icon {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  overflow: hidden;
  margin-bottom: 20px;
}

.welcome-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.welcome-screen h1 {
  font-size: 24px;
  font-weight: 600;
  color: var(--chat-text);
  margin-bottom: 8px;
}

.welcome-screen p {
  color: var(--chat-text-muted);
  max-width: 400px;
  line-height: 1.7;
  font-size: 14px;
}

/* ========== 输入区域 ========== */
.input-container {
  padding: 16px 24px 24px;
  background: transparent;
}

.input-wrapper {
  max-width: 800px;
  margin: 0 auto;
  background: var(--chat-card);
  border: 1px solid var(--chat-border);
  border-radius: 16px;
  padding: 8px 12px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.1);
}

.input-top-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 4px 8px;
  border-bottom: 1px solid var(--chat-border);
  margin-bottom: 8px;
}

.mode-switch-btn {
  padding: 6px 12px;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--chat-text-muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 4px;
}

.mode-switch-btn:hover {
  background: var(--chat-bg);
  color: var(--chat-text);
}

.mode-switch-btn.active {
  background: var(--primary-light);
  color: var(--primary);
}

.mode-switch-btn svg {
  width: 14px;
  height: 14px;
}

.input-main {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.input-main textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--chat-text);
  font-size: 15px;
  resize: none;
  outline: none;
  max-height: 200px;
  font-family: inherit;
  line-height: 1.5;
  padding: 4px 0;
}

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

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

.upload-btn {
  background: transparent;
  border: none;
  color: var(--chat-text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.upload-btn:hover {
  background: var(--chat-bg);
  color: var(--primary);
}

.send-btn {
  background: var(--primary);
  border: none;
  color: white;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: background-color 0.2s ease;
}

.send-btn:hover:not(:disabled) {
  background: var(--primary-hover);
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ========== 图片预览 ========== */
.image-preview-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 0;
  max-width: 100%;
}

.image-preview {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--chat-border);
}

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

.image-preview .remove-image {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  background: rgba(0, 0, 0, 0.6);
  border: none;
  border-radius: 50%;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.image-preview:hover .remove-image {
  opacity: 1;
}

/* ========== 用户消息中的图片 ========== */
.user-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.user-images img {
  max-width: 200px;
  max-height: 200px;
  border-radius: 8px;
  object-fit: cover;
}

.message-content img {
  max-width: 100%;
  border-radius: 8px;
  margin: 8px 0;
}

/* 生图模式 - 无图片提示 */
.no-image-result {
  padding: 16px 20px;
  background: var(--ai-message-bg);
  border-radius: 12px;
  color: var(--chat-text-muted);
  font-size: 15px;
  text-align: center;
}

/* 生图模式 - 图片容器（多张并排） */
.generated-images-container {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: wrap !important;
  gap: 12px;
  margin-top: 12px;
  width: 100%;
}

.generated-images-intro {
  margin-bottom: 12px;
  color: var(--chat-text);
  width: 100%;
}

/* 生图模式 - 单张图片固定大小（缩略图） */
.generated-image {
  width: 150px !important;
  height: 150px !important;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--chat-border);
  flex: 0 0 auto !important;
  box-sizing: border-box;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.generated-image:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.generated-image img {
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  object-fit: cover;
  margin: 0 !important;
  border-radius: 0;
  display: block;
}

.clickable-image {
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.clickable-image:hover {
  transform: scale(1.02);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

/* ========== 图片放大模态框 ========== */
.image-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  cursor: pointer;
}

.image-modal-content {
  position: relative;
  max-width: 90%;
  max-height: 90%;
  cursor: default;
}

.image-modal-content img {
  max-width: 100%;
  max-height: 90vh;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.image-modal-close {
  position: absolute;
  top: -40px;
  right: 0;
  width: 36px;
  height: 36px;
  border: none;
  background: rgba(255, 255, 255, 0.2);
  color: white;
  font-size: 24px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.image-modal-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* ========== 加载状态 ========== */
.loading {
  display: flex;
  gap: 6px;
  padding: 8px 0;
}

.loading-dot {
  width: 8px;
  height: 8px;
  background: var(--primary);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dot:nth-child(1) {
  animation-delay: -0.32s;
}

.loading-dot:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes bounce {
  0%, 80%, 100% {
    transform: scale(0);
  }
  40% {
    transform: scale(1);
  }
}

.streaming-indicator {
  display: inline-block;
  width: 8px;
  height: 16px;
  background: var(--primary);
  margin-left: 2px;
  animation: blink 1s infinite;
  vertical-align: middle;
  border-radius: 2px;
}

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

/* ========== 错误提示 ========== */
.error-message {
  background: var(--error-bg);
  color: var(--error);
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 12px;
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
  font-size: 14px;
}

/* ========== 侧边栏滚动条 ========== */
.chat-history::-webkit-scrollbar {
  width: 4px;
}

.chat-history::-webkit-scrollbar-thumb {
  background: transparent;
}

.chat-history:hover::-webkit-scrollbar-thumb {
  background: var(--sidebar-border);
}

.chat-history:hover::-webkit-scrollbar-thumb:hover {
  background: var(--sidebar-text-muted);
}

/* ========== 移动端适配 ========== */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 40;
}

@media (max-width: 768px) {
  .sidebar-toggle-btn {
    display: none;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    width: 260px;
  }

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

  .sidebar-overlay.open {
    display: block;
  }

  .mobile-menu-btn {
    display: flex;
  }

  .messages-container {
    padding: 16px;
  }

  .input-container {
    padding: 12px 16px 16px;
  }

  .message {
    margin-bottom: 16px;
  }

  .chat-header {
    padding: 12px 16px;
  }

  .chat-header-left {
    min-width: auto;
  }

  .chat-header-center {
    flex: 1;
    overflow: hidden;
  }

  .chat-title-input {
    max-width: 100%;
    font-size: 14px;
  }

  .chat-header-right {
    display: none;
  }

  .model-selector select {
    min-width: 120px;
  }
}

@media (max-width: 480px) {
  .welcome-screen h1 {
    font-size: 20px;
  }

  .welcome-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
  }

  .welcome-icon svg {
    width: 28px;
    height: 28px;
  }
}

/* ========== Markdown 样式 ========== */
.message-content pre {
  background: #f6f8fa;
  border-radius: 8px;
  padding: 16px;
  overflow-x: auto;
  margin: 12px 0;
  position: relative;
  border: 1px solid #e1e4e8;
  max-width: 100%;
  box-sizing: border-box;
}

/* 代码块滚动条样式 */
.message-content pre::-webkit-scrollbar {
  height: 6px;
}

.message-content pre::-webkit-scrollbar-track {
  background: transparent;
}

.message-content pre::-webkit-scrollbar-thumb {
  background: #d0d7de;
  border-radius: 3px;
}

.message-content pre::-webkit-scrollbar-thumb:hover {
  background: #afb8c1;
}

.message-content pre code {
  font-family: 'Fira Code', 'Consolas', monospace;
  font-size: 14px;
  line-height: 1.5;
  color: #24292e;
  white-space: pre;
  display: block;
}

.message-content code:not(pre code) {
  background: rgba(27, 31, 35, 0.05);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Fira Code', 'Consolas', monospace;
  font-size: 14px;
  color: #24292e;
}

.message-content p {
  margin: 0 0 12px 0;
}

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

.message-content ul,
.message-content ol {
  margin: 8px 0;
  padding-left: 24px;
}

.message-content li {
  margin: 4px 0;
}

.message-content blockquote {
  border-left: 4px solid var(--primary);
  margin: 12px 0;
  padding: 8px 16px;
  background: var(--chat-bg);
  border-radius: 0 8px 8px 0;
}

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4 {
  margin: 16px 0 8px 0;
  font-weight: 600;
}

.message-content h1 { font-size: 1.5em; }
.message-content h2 { font-size: 1.3em; }
.message-content h3 { font-size: 1.1em; }

.message-content a {
  color: var(--primary);
  text-decoration: none;
}

.message-content a:hover {
  text-decoration: underline;
}

.message-content table {
  border-collapse: collapse;
  margin: 12px 0;
  width: 100%;
}

.message-content th,
.message-content td {
  border: 1px solid var(--chat-border);
  padding: 8px 12px;
  text-align: left;
}

.message-content th {
  background: var(--chat-bg);
  font-weight: 600;
}

/* ========== 确认对话框 ========== */
.confirm-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.confirm-dialog {
  background: var(--chat-card);
  border-radius: 12px;
  padding: 24px;
  min-width: 320px;
  max-width: 400px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  animation: slideIn 0.2s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(-10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.confirm-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--chat-text);
  margin-bottom: 8px;
}

.confirm-message {
  font-size: 14px;
  color: var(--chat-text-muted);
  line-height: 1.6;
  margin-bottom: 20px;
}

.confirm-buttons {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.confirm-btn {
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.confirm-btn-cancel {
  background: transparent;
  border: 1px solid var(--chat-border);
  color: var(--chat-text);
}

.confirm-btn-cancel:hover {
  background: var(--chat-bg);
}

.confirm-btn-confirm {
  background: var(--primary);
  border: 1px solid var(--primary);
  color: white;
}

.confirm-btn-confirm:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.confirm-btn-danger {
  background: var(--error);
  border: 1px solid var(--error);
  color: white;
}

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

/* ========== 输入对话框 ========== */
.input-dialog {
  background: var(--chat-card);
  border-radius: 12px;
  padding: 24px;
  min-width: 320px;
  max-width: 400px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  animation: slideIn 0.2s ease;
}

.input-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--chat-text);
  margin-bottom: 16px;
}

.input-buttons {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 20px;
}
