/* ==================== 全局重置 ==================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #0a0a0f;
  color: #e0e0e0;
  height: 100vh;
  overflow: hidden;
}

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

/* ==================== 侧边栏 ==================== */
.sidebar {
  width: 280px;
  background: #12121a;
  border-right: 1px solid #1f1f2e;
  display: flex;
  flex-direction: column;
  height: 100vh;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid #1f1f2e;
}

.sidebar-header h1 {
  color: #4da6ff;
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 12px;
  text-shadow: 0 0 8px rgba(77, 166, 255, 0.5);
}

.sidebar-header button {
  background: #1a1a2e;
  border: 1px solid #2a2a40;
  color: #e0e0e0;
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  width: 100%;
  font-size: 14px;
  transition: all 0.2s;
}

.sidebar-header button:hover {
  background: #1e1e30;
  border-color: #4da6ff;
}

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

.session-list::-webkit-scrollbar {
  width: 6px;
}

.session-list::-webkit-scrollbar-thumb {
  background: #2a2a40;
  border-radius: 3px;
}

.session-list::-webkit-scrollbar-thumb:hover {
  background: #3a3a50;
}

.sidebar-empty {
  color: #888;
  font-size: 14px;
  padding: 8px;
  text-align: center;
}

.session-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: #c0c0d0;
  padding: 12px;
  margin-bottom: 4px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.2s;
}

.session-item:hover {
  background: #1e1e30;
}

.session-item.active {
  background: #1e2a3a;
  color: #4da6ff;
}

.sidebar-footer {
  padding: 15px;
  border-top: 1px solid #1f1f2e;
  font-size: 14px;
  color: #888;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ==================== 主区域 ==================== */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-width: 0;
}

.topbar {
  height: 60px;
  background: #0f0f18;
  border-bottom: 1px solid #1f1f2e;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  flex-shrink: 0;
}

.topbar select {
  background: #1a1a2e;
  border: 1px solid #2a2a40;
  color: #e0e0e0;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  outline: none;
}

.topbar select:focus {
  border-color: #4da6ff;
}

#tokenLimitHint {
  font-size: 13px;
  color: #888;
  white-space: nowrap;
}

.settings-btn {
  background: transparent;
  border: none;
  color: #4da6ff;
  font-size: 20px;
  cursor: pointer;
  padding: 5px;
  transition: transform 0.2s;
}

.settings-btn:hover {
  transform: scale(1.1);
}

.auth-buttons {
  margin-left: auto;
  display: flex;
  gap: 10px;
}

.auth-buttons button {
  background: #1a1a2e;
  border: 1px solid #2a2a40;
  color: #e0e0e0;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

.auth-buttons button:hover {
  background: #1e1e30;
  border-color: #4da6ff;
}

/* ==================== 聊天容器 ==================== */
.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: linear-gradient(180deg, #0a0a0f 0%, #0f0f1a 100%);
}

.chat-container::-webkit-scrollbar {
  width: 8px;
}

.chat-container::-webkit-scrollbar-thumb {
  background: #2a2a40;
  border-radius: 4px;
}

.chat-container::-webkit-scrollbar-thumb:hover {
  background: #3a3a50;
}

#emptyState {
  color: #555;
  text-align: center;
  margin-top: 80px;
  font-size: 18px;
  user-select: none;
}

/* ==================== 消息样式 ==================== */
.message {
  max-width: 800px;
  margin: 0 auto 20px;
  padding: 16px;
  border-radius: 12px;
  background: #131322;
  border: 1px solid #1e1e30;
  word-break: break-word;
  position: relative;
}

.message.user {
  background: #0f1a2e;
  border-color: #1a3a5c;
}

.message.assistant {
  background: #12121f;
  animation: glow 3s infinite;
}

.message-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 13px;
  color: #888;
  flex-wrap: wrap;
}

.message-head .role {
  font-weight: 600;
  color: #e0e0e0;
  font-size: 14px;
}

.message-head span:not(.role) {
  background: #1a1a2e;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  color: #aaa;
}

.message-content {
  line-height: 1.7;
  font-size: 15px;
  color: #e0e0e0;
  word-wrap: break-word;
}

.message-content p {
  margin-bottom: 8px;
}

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
  margin: 16px 0 8px;
  color: #4da6ff;
}

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

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

.message-content code {
  background: #1a1a2e;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "Consolas", "Monaco", monospace;
  font-size: 13px;
  color: #4da6ff;
}

.message-content pre {
  background: #1a1a2e;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}

.message-content pre code {
  background: transparent;
  padding: 0;
  color: #e0e0e0;
}

.message-content blockquote {
  border-left: 3px solid #4da6ff;
  padding-left: 12px;
  color: #aaa;
  margin: 8px 0;
}

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

.message-content th,
.message-content td {
  border: 1px solid #2a2a40;
  padding: 6px 10px;
  text-align: left;
}

.message-content th {
  background: #1a1a2e;
  color: #4da6ff;
}

.message-content a {
  color: #4da6ff;
  text-decoration: none;
}

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

/* 消息操作按钮 */
.message-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}

.message-actions button {
  background: #1a1a2e;
  border: 1px solid #2a2a40;
  color: #e0e0e0;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.message-actions button:hover {
  background: #1e1e30;
  border-color: #4da6ff;
  color: #4da6ff;
}

/* 编辑区域 */
.edit-area {
  width: 100%;
  min-height: 100px;
  padding: 10px;
  border: 1px solid #2a2a40;
  border-radius: 8px;
  background: #1a1a2e;
  color: #e0e0e0;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.6;
  resize: vertical;
  outline: none;
}

.edit-area:focus {
  border-color: #4da6ff;
}

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

.edit-actions button {
  background: #1a1a2e;
  border: 1px solid #2a2a40;
  color: #e0e0e0;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.edit-actions button:hover {
  background: #1e1e30;
  border-color: #4da6ff;
}

/* ==================== 输入区域 ==================== */
/* ==================== 输入区布局调整 ==================== */
.input-area {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 20px;
  background: #0f0f18;
  border-top: 1px solid #1f1f2e;
  flex-shrink: 0;
}

.input-options {
  display: flex;
  align-items: center;
  gap: 16px;
}

.input-box {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.input-box textarea {
  flex: 1;
  background: #1a1a2e;
  border: 1px solid #2a2a40;
  color: #e0e0e0;
  padding: 12px;
  border-radius: 10px;
  resize: none;
  /* 禁用原生缩放，使用拖拽手柄 */
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.2s;
}

.input-box textarea:focus {
  border-color: #4da6ff;
}

.drag-handle {
  width: 12px;
  cursor: ns-resize;
  background: #2a2a40;
  border-radius: 6px;
  transition: background 0.2s;
}

.drag-handle:hover {
  background: #4da6ff;
}

/* 发送按钮 */
.input-area button#sendBtn {
  align-self: flex-end;
  padding: 10px 24px;
  background: #4da6ff;
  border: none;
  color: #fff;
  border-radius: 10px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  transition: all 0.2s;
}

.input-area button#sendBtn:hover:not(:disabled) {
  background: #3a8ee6;
  box-shadow: 0 0 12px rgba(77, 166, 255, 0.4);
}

.input-area button#sendBtn:disabled {
  background: #2a2a40;
  color: #888;
  cursor: not-allowed;
}

/* 思考模式开关 */
.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 14px;
  color: #ccc;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: #4da6ff;
  cursor: pointer;
}

/* 思考内容区域 */
.message-thinking {
  background: #1a1a2e;
  border-left: 3px solid #4da6ff;
  padding: 8px 12px;
  margin-bottom: 8px;
  border-radius: 6px;
  font-size: 13px;
  color: #aaa;
  white-space: pre-wrap;
  word-break: break-word;
}

.message-thinking .thinking-label {
  font-weight: 600;
  color: #4da6ff;
  margin-right: 6px;
}

.input-area textarea {
  flex: 1;
  background: #1a1a2e;
  border: 1px solid #2a2a40;
  color: #e0e0e0;
  padding: 12px;
  border-radius: 10px;
  resize: none;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.2s;
}

.input-area textarea:focus {
  border-color: #4da6ff;
}

.input-area button {
  background: #4da6ff;
  border: none;
  color: #fff;
  padding: 0 24px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  transition: all 0.2s;
}

.input-area button:hover:not(:disabled) {
  background: #3a8ee6;
  box-shadow: 0 0 12px rgba(77, 166, 255, 0.4);
}

.input-area button:disabled {
  background: #2a2a40;
  color: #888;
  cursor: not-allowed;
}

/* ==================== 弹窗 ==================== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal.hidden {
  display: none;
}

.modal-box {
  background: #12121f;
  padding: 24px;
  border-radius: 12px;
  width: 340px;
  color: #e0e0e0;
  border: 1px solid #2a2a40;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
}

.modal-box h2 {
  margin-bottom: 16px;
  color: #4da6ff;
  font-size: 18px;
}

.modal-box input[type="text"],
.modal-box input[type="password"] {
  width: 100%;
  padding: 10px;
  margin-bottom: 12px;
  background: #1a1a2e;
  border: 1px solid #2a2a40;
  color: #e0e0e0;
  border-radius: 8px;
  outline: none;
  font-size: 14px;
}

.modal-box input[type="text"]:focus,
.modal-box input[type="password"]:focus {
  border-color: #4da6ff;
}

.modal-box label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  color: #ccc;
}

.modal-box input[type="range"] {
  width: 100%;
  margin: 8px 0 16px;
  background: #1a1a2e;
  height: 4px;
  border-radius: 2px;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
}

.modal-box input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #4da6ff;
  cursor: pointer;
}

.modal-box input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #4da6ff;
  cursor: pointer;
  border: none;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 16px 0;
  cursor: pointer;
  font-size: 14px;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: #4da6ff;
  cursor: pointer;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.modal-actions button {
  background: #4da6ff;
  border: none;
  color: #fff;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.2s;
}

.modal-actions button:hover {
  background: #3a8ee6;
}

.modal-actions button#cancelLogin,
.modal-actions button#closeSettings {
  background: #1a1a2e;
  border: 1px solid #2a2a40;
  color: #e0e0e0;
}

.modal-actions button#cancelLogin:hover,
.modal-actions button#closeSettings:hover {
  background: #1e1e30;
}

/* ==================== 蓝色流光动画 ==================== */
@keyframes glow {
  0% {
    box-shadow: 0 0 5px rgba(77, 166, 255, 0.2);
  }

  50% {
    box-shadow: 0 0 15px rgba(77, 166, 255, 0.5);
  }

  100% {
    box-shadow: 0 0 5px rgba(77, 166, 255, 0.2);
  }
}

/* ==================== Toast 提示 ==================== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1a1a2e;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 999;
  border: 1px solid #2a2a40;
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.5);
  animation: fadeInUp 0.3s ease;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translate(-50%, 10px);
  }

  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* 思考内容折叠 */
.message-thinking {
  background: #1a1a2e;
  border-left: 3px solid #4da6ff;
  padding: 8px 12px;
  margin-bottom: 8px;
  border-radius: 6px;
  font-size: 13px;
  color: #aaa;
  white-space: pre-wrap;
  word-break: break-word;
  cursor: pointer;
}
.message-thinking.collapsed .thinking-content {
  display: none;
}
.message-thinking .thinking-label {
  font-weight: 600;
  color: #4da6ff;
  margin-right: 6px;
  user-select: none;
}

/* 删除按钮 */
.delete-btn {
  background: #4a1515;
  border: 1px solid #6b2a2a;
  color: #ff6b6b;
}
.delete-btn:hover {
  background: #6b1a1a;
  border-color: #ff4d4d;
}

/* 会话列表项删除按钮 */
.session-item-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  margin-bottom: 4px;
}
.session-item-wrapper .session-item {
  flex: 1;
}
.session-delete-btn {
  background: transparent;
  border: none;
  color: #888;
  cursor: pointer;
  padding: 5px;
  font-size: 14px;
  visibility: hidden;
}
.session-item-wrapper:hover .session-delete-btn {
  visibility: visible;
}
.session-delete-btn:hover {
  color: #ff6b6b;
}

/* 小按钮 */
.small-btn {
  background: #1a1a2e;
  border: 1px solid #2a2a40;
  color: #e0e0e0;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.small-btn:hover {
  border-color: #4da6ff;
  color: #4da6ff;
}

/* ==================== 代码块操作按钮 ==================== */
.code-block-wrapper {
  position: relative;
  margin: 8px 0;
}

.code-block-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  z-index: 10;
  opacity: 0;
  transition: opacity 0.2s;
}

.code-block-wrapper:hover .code-block-actions {
  opacity: 1;
}

.code-action-btn {
  background: #2a2a40;
  border: 1px solid #4a4a60;
  color: #e0e0e0;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  transition: all 0.2s;
}

.code-action-btn:hover {
  background: #3a3a50;
  border-color: #4da6ff;
  color: #4da6ff;
}

/* 保证 pre 代码块在包装器中正常显示 */
.code-block-wrapper pre {
  margin: 0;
  padding-top: 40px; /* 为按钮留出空间 */
}

.code-lang-tag {
  font-size: 12px;
  font-weight: 600;
  color: #4da6ff;
  background: #1a1a2e;
  padding: 4px 8px;
  border-radius: 6px;
  margin-right: 6px;
  user-select: none;
}

/* 分支切换按钮 */
.branch-control {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  margin: 12px 0;
  padding: 6px;
}

.branch-control button {
  background: #1a1a2e;
  border: 1px solid #2a2a40;
  color: #e0e0e0;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}

.branch-control button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.branch-control span {
  font-size: 14px;
  color: #888;
}

.code-lang-tag {
  font-size: 12px;
  font-weight: 600;
  color: #4da6ff;
  background: #1a1a2e;
  padding: 4px 8px;
  border-radius: 6px;
  margin-right: 6px;
  user-select: none;
}


.branch-btn {
  background: #1a1a2e;
  border: 1px solid #2a2a40;
  color: #ccc;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.branch-btn.active {
  background: #1e2a3a;
  color: #4da6ff;
  border-color: #4da6ff;
}



/* 分支切换器（位于用户消息右下角，小尺寸） */
.branch-switcher {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 8px;
  font-size: 12px;
  color: #888;
}

.branch-arrow {
  background: transparent;
  border: none;
  color: #aaa;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  transition: color 0.2s;
}

.branch-arrow:hover:not(:disabled) {
  color: #4da6ff;
}

.branch-arrow:disabled {
  opacity: 0.3;
  cursor: default;
}

.branch-indicator {
  font-weight: 600;
  color: #4da6ff;
  min-width: 40px;
  text-align: center;
}