:root {
  --sidebar-width: 260px;
  --primary-color: #10a37f;
  --bg-color: #ffffff;
  --sidebar-bg: #202123;
  --chat-bg: #f7f7f8;
  --border-color: #d9d9e3;
  --text-color: #374151;
  --input-bg: #ffffff;
  --modal-bg: #ffffff;
  --tag-bg: #f0f0f0;
}

body.dark-mode {
  --bg-color: #343541;
  --chat-bg: #444654;
  --border-color: #4d4d4f;
  --text-color: #aaa;
  --input-bg: #40414f;
  --modal-bg: #202123;
  --tag-bg: #4d4d4f;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* 全局滚动条美化 */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(180, 180, 180, 0.3);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(150, 150, 150, 0.5);
}

body {
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  height: 100vh;
  height: 100dvh;
  display: flex;
  overflow: hidden;
  background-color: var(--bg-color);
  color: var(--text-color);
}

/* 侧边栏 */
#sidebar {
  width: var(--sidebar-width);
  background-color: var(--sidebar-bg);
  color: white;
  display: flex;
  flex-direction: column;
  padding: 10px;
  flex-shrink: 0;
  transition: transform 0.3s ease;
  z-index: 1000;
}
.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.new-chat-btn {
  border: 1px solid #4d4d4f;
  padding: 12px;
  border-radius: 5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-grow: 1;
  transition: background 0.2s;
}
.header-left {
  display: flex;
  align-items: center;
}

/* 响应式设计 */
@media (max-width: 768px) {
  #sidebar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
  }
  #sidebar.show {
    transform: translateX(0);
  }
  #sidebar-toggle-mobile,
  #sidebar-close-mobile {
    display: block !important;
  }
  .sidebar-header {
    gap: 12px;
    padding-right: 5px;
  }
  .new-chat-btn {
    padding: 8px 12px;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #sidebar-close-mobile {
    flex-shrink: 0;
    padding: 10px;
    margin-right: -10px;
  }
  .chat-item .delete-chat-btn {
    opacity: 0.8 !important;
    color: #ff4d4d;
    visibility: visible !important;
  }
  .message-content {
    width: 95%;
    gap: 10px;
  }
  .avatar {
    width: 24px;
    height: 24px;
    font-size: 12px;
  }
  .message-text {
    font-size: 14px;
  }
  header h2 {
    font-size: 16px;
  }
  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
  }
  .sidebar-overlay.show {
    display: block;
  }
  #time-navigator {
    display: none !important;
  }
  .scroll-time-badge {
    right: 10px;
    top: 60px;
    font-size: 10px;
    padding: 3px 8px;
  }
}
.new-chat-btn:hover {
  background: #2a2b32;
}
#chat-list {
  flex-grow: 1;
  overflow-y: auto;
}
.chat-item {
  padding: 10px;
  margin: 5px 0;
  border-radius: 5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  transition: background 0.2s;
  user-select: none;
}
.chat-item span {
  flex-grow: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item:hover {
  background: #2a2b32;
}
.chat-item.active {
  background: #343541;
}
.chat-item .delete-chat-btn {
  opacity: 0;
  transition: opacity 0.2s;
  padding: 5px;
}
.chat-item:hover .delete-chat-btn {
  opacity: 0.6;
}
.chat-item .delete-chat-btn:hover {
  opacity: 1;
  color: #ff4d4d;
}

/* 主聊天区域 */
#main-content {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-color);
  position: relative;
  color: var(--text-color);
}
header {
  padding: 8px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-color);
}
.header-btns {
  display: flex;
  align-items: center;
}
.header-btns button {
  color: var(--text-color);
  opacity: 0.7;
  transition: opacity 0.2s;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 14px;
}
.header-btns button:hover {
  opacity: 1;
}
#chat-container {
  flex-grow: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 5px 0;
}
.message-row {
  width: 100%;
  padding: 12px 0;
  display: flex;
  justify-content: center;
}
.message-row.user-row {
  background: var(--bg-color);
}
.message-row.ai-row {
  background: var(--chat-bg);
  border-top: 1px solid rgba(0, 0, 0, 0.03);
  border-bottom: 1px solid rgba(0, 0, 0, 0.03);
}
.message-content {
  max-width: 800px;
  width: 90%;
  display: flex;
  gap: 12px;
  position: relative;
}
.avatar {
  width: 28px;
  height: 28px;
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}
.user-avatar {
  background: #5436da;
  color: white;
}
.ai-avatar {
  background: var(--primary-color);
  color: white;
}
.message-text {
  flex-grow: 1;
  line-height: 1.5;
  font-size: 14.5px;
  color: var(--text-color);
  overflow-wrap: break-word;
  min-width: 0;
}
.message-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  flex-shrink: 0;
}
.msg-action-btn {
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.2s;
  font-size: 13px;
  visibility: hidden; /* 默认隐藏按钮 */
}
.message-row:hover .msg-action-btn {
  visibility: visible;
}
.msg-action-btn:hover {
  opacity: 1;
}
.delete-msg:hover {
  color: #ff4d4d;
}

/* 时间相关样式 */
.time-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 15px 0;
  color: var(--text-color);
  opacity: 0.4;
  font-size: 11px;
}
.time-divider span {
  background: var(--bg-color);
  padding: 0 10px;
  position: relative;
  z-index: 1;
}
.message-time-label {
  font-size: 11px;
  opacity: 0.4;
  margin: 0;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-weight: 300;
  white-space: nowrap;
  pointer-events: none;
  font-style: normal;
}
.ai-row .time-divider span {
  background: var(--chat-bg);
}

.scroll-time-badge {
  position: absolute;
  right: 20px;
  top: 70px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  z-index: 100;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}
.scroll-time-badge.show {
  opacity: 1;
}

/* 回到底部按钮 */
#scroll-to-bottom {
  position: absolute;
  right: 20px;
  bottom: 120px;
  width: 36px;
  height: 36px;
  background: var(--input-bg);
  border: 1px solid var(--border-color);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s;
  z-index: 100;
  color: var(--text-color);
}
#scroll-to-bottom.show {
  opacity: 1;
  pointer-events: auto;
}
#scroll-to-bottom:hover {
  background: var(--tag-bg);
  transform: translateY(-2px);
}

#time-navigator {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 90;
}
.time-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border-color);
  cursor: pointer;
  transition: all 0.2s;
}
.time-dot:hover {
  background: var(--primary-color);
  transform: scale(1.5);
}
.time-dot::after {
  content: attr(data-label);
  position: absolute;
  right: 20px;
  background: var(--sidebar-bg);
  color: white;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  white-space: nowrap;
  display: none;
}
.time-dot:hover::after {
  display: block;
}

/* 输入区域 */
.input-container {
  padding: 12px 20px calc(24px + env(safe-area-inset-bottom)) 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--bg-color);
}
@media (max-width: 768px) {
  .input-container {
    padding: 10px 10px calc(15px + env(safe-area-inset-bottom)) 10px;
  }
}
.quick-prompts {
  max-width: 800px;
  width: 90%;
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  overflow-x: auto;
  padding-bottom: 5px;
}
.prompt-tag {
  padding: 5px 12px;
  background: var(--tag-bg);
  border-radius: 15px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  color: var(--text-color);
  border: 1px solid var(--border-color);
}
.prompt-tag:hover {
  background: var(--border-color);
}
#question-form {
  max-width: 800px;
  width: 90%;
  position: relative;
  display: flex;
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  background: var(--input-bg);
}
#question-input {
  flex: 1;
  padding: 14px;
  padding-right: 45px;
  border: none;
  outline: none;
  font-size: 16px;
  resize: none;
  background: var(--input-bg);
  color: var(--text-color);
  max-height: 200px;
  overflow-y: auto;
}
#question-input::-webkit-scrollbar {
  width: 5px;
}
#question-input::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 5px;
}

#send-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--primary-color);
  cursor: pointer;
  font-size: 20px;
}

/* 弹窗样式 */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-content {
  background: var(--modal-bg);
  color: var(--text-color);
  padding: 30px;
  border-radius: 10px;
  width: 500px;
  max-width: 95%;
  max-height: 90vh;
  overflow-y: auto;
}
.form-group {
  margin-bottom: 15px;
}
.form-group label {
  display: block;
  margin-bottom: 5px;
  font-weight: bold;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--input-bg);
  color: var(--text-color);
}
.modal-actions {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.btn {
  padding: 8px 16px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  cursor: pointer;
  background: var(--input-bg);
  color: var(--text-color);
}
.btn-primary {
  background: var(--primary-color);
  color: white;
  border: none;
}

/* Prompts Editor */
#prompts-editor-list {
  margin-top: 10px;
}
.prompt-edit-item {
  display: flex;
  gap: 5px;
  margin-bottom: 10px;
}
.prompt-edit-item input {
  flex: 1;
}

/* Markdown 样式微调 */
.code-block-wrapper {
  position: relative;
  margin: 15px 0;
  border-radius: 8px;
  overflow: hidden;
}

.message-text pre {
  background: #282c34;
  padding: 0;
  margin: 0;
  max-width: 100%;
  overflow: auto;
}
.message-text code {
  font-family: "Fira Code", "Consolas", monospace;
  background: rgba(0, 0, 0, 0.1);
  padding: 2px 4px;
  border-radius: 3px;
}
.dark-mode .message-text code {
  background: rgba(255, 255, 255, 0.1);
}
.message-text pre code {
  background: none;
  display: block;
  padding: 35px 15px 15px;
  color: #abb2bf;
}
.message-text table {
  border-collapse: collapse;
  width: 100%;
  margin: 10px 0;
}
.message-text ul,
.message-text ol {
  padding-left: 2em;
  margin-bottom: 0em;
}
.message-text li {
  margin-bottom: 0em;
}
.message-text ul {
  list-style-type: disc;
  margin-bottom: 1em;
}
.message-text ul ul {
  list-style-type: circle;
  margin-bottom: 0em;
}
.message-text ul ul ul {
  list-style-type: square;
  margin-bottom: 0em;
}
.message-text th,
.message-text td {
  border: 1px solid var(--border-color);
  padding: 8px;
  text-align: left;
}
.message-text blockquote {
  border-left: 4px solid var(--primary-color);
  padding-left: 15px;
  color: #666;
  font-style: italic;
}
.dark-mode .message-text blockquote {
  color: #aaa;
}

/* 代码块增强相关样式 */
.code-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 30px;
  background: #21252b;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 12px;
  color: #abb2bf;
  font-size: 12px;
  font-family: sans-serif;
}

.copy-btn {
  background: none;
  border: 1px solid #4d4d4f;
  color: #abb2bf;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  transition: all 0.2s;
}

.copy-btn:hover {
  background: #3e4451;
  color: white;
}

#loading {
  display: none;
  margin-top: 10px;
  color: var(--text-color);
  font-size: 14px;
}

/* KaTeX 居中优化 */
.katex-display {
  margin: 1em 0;
  overflow-x: auto;
  overflow-y: hidden;
}

/* 图片查看器弹窗 */
.image-gallery-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0, 0, 0, 0.9);
  z-index: 2000;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
}

.image-gallery-modal.show {
  display: flex;
}

.gallery-header {
  height: 60px;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(5px);
  z-index: 2002;
  color: white;
  flex-shrink: 0;
}

.gallery-controls {
  display: flex;
  gap: 20px;
}

.gallery-controls button {
  background: none;
  border: none;
  color: white;
  font-size: 20px;
  cursor: pointer;
  padding: 8px;
  border-radius: 4px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery-controls button:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: scale(1.1);
}

.gallery-close {
  background: none;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
  padding: 8px;
  border-radius: 4px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery-close:hover {
  background: rgba(255, 0, 0, 0.3);
  transform: scale(1.1);
}

.gallery-body {
  flex: 1;
  width: 100%;
  height: calc(100% - 60px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  position: relative;
  overflow: hidden;
}

.gallery-body:active {
  cursor: grabbing;
}

#modal-image {
  max-width: 95%;
  max-height: 95%;
  object-fit: contain;
  transition: transform 0.1s ease-out; /* 缩放和旋转的基础过渡 */
  transform-origin: center center;
  will-change: transform;
}

/* 聊天中的图片样式优化 */
.message-text img {
  cursor: zoom-in;
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.message-text img:hover {
  transform: scale(1.02);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.dark-mode .message-text img {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

@media (max-width: 768px) {
  .gallery-controls {
    gap: 10px;
  }
  .gallery-controls button {
    font-size: 18px;
    padding: 6px;
  }
  .gallery-header {
    padding: 0 10px;
  }
}
