/* ========== 全局变量 ========== */
:root {
  --sidebar-width: 240px;
  --sidebar-collapsed-width: 60px;
  --primary-color: #4a6cf7;
  --primary-light: #e8f1fd;
  --light-bg: #f8f9fa;
  --dark-text: #16181a;
  --gray-200: #edf2f7;
  --gray-300: #e2e8f0;
  --gray-400: #cbd5e0;
  --danger-color: #e53e3e;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
  --border-radius: 12px;
  --chat-max-width: 900px;
}

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

body {
  margin: 0;
  height: 100vh;
  display: flex;
  overflow: hidden;
  color: var(--dark-text);
  font-family: 'Segoe UI', 'SF Pro Display', -apple-system, sans-serif;
  background: #f7fafc;
}

/* ========== 侧边栏 ========== */
#sidebar {
  width: var(--sidebar-width);
  background: #f0f3ff;
  border-right: 1px solid var(--gray-300);
  height: 100%;
  transition: all 0.3s ease;
  position: relative;
  box-shadow: var(--shadow-sm);
  z-index: 1000;
  display: flex;
  flex-direction: column;
}

#sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
}

.sidebar-header {
  padding: 0.75rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--gray-300);
  height: 56px;
}

.logo {
  display: flex;
  align-items: center;
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--primary-color);
  gap: 0.5rem;
  transition: opacity 0.3s ease;
}

#sidebar.collapsed .logo {
  opacity: 0;
}

.collapse-btn {
  background: 0 0;
  border: none;
  font-size: 1.1rem;
  color: #718096;
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.collapse-btn:hover {
  background: var(--gray-200);
}

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 0;
}

.quick-actions {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 1rem;
}

.quick-btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  color: var(--dark-text);
  text-decoration: none;
  font-size: 0.9rem;
  transition: background 0.2s;
  border: 1px solid transparent;
  margin: 0 0.75rem;
}

.quick-btn.active {
  background: var(--primary-light);
  color: var(--primary-color);
  border-color: var(--primary-color);
}

.quick-btn:hover:not(.active) {
  background: var(--gray-200);
  border-color: var(--gray-300);
}

.quick-btn i {
  font-size: 1rem;
  min-width: 20px;
  text-align: center;
}

.history-title {
  font-size: 0.75rem;
  color: #718096;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 1rem 0 0.5rem 0.75rem;
  padding-left: 0.25rem;
}

.history-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--dark-text);
  margin: 0 0.75rem;
  cursor: pointer;
  transition: background 0.2s;
}

.history-item:hover {
  background: var(--gray-200);
}

.history-item-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
  flex: 1;
}

.history-actions {
  display: none;
  gap: 0.25rem;
}

.history-item:hover .history-actions {
  display: flex;
}

.sidebar-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--gray-300);
  position: relative;
}

.user-section {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-color);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  transition: all 0.2s;
  margin-left: 1rem;
}

.user-avatar:hover {
  transform: scale(1.05);
}

.user-info {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-name {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--dark-text);
}

.user-menu-btn {
  background: 0 0;
  border: none;
  color: #718096;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.user-menu-btn:hover {
  background: var(--gray-200);
}

.shortcut-icons {
  display: flex;
  gap: 2rem;
  justify-content: center;
}

.shortcut-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--gray-300);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #718096;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.9rem;
}

.shortcut-btn:hover {
  background: var(--primary-color);
  color: #fff;
  border-color: var(--primary-color);
}

#userDropdown {
  position: absolute;
  top: auto;
  bottom: 100%;
  right: 0;
  background: #fff;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--gray-300);
  padding: 0.5rem 0;
  z-index: 1000;
  display: none;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  color: var(--dark-text);
  text-decoration: none;
  font-size: 0.9rem;
  transition: background 0.2s;
}

.dropdown-item:hover {
  background: var(--primary-light);
  color: var(--primary-color);
}

.dropdown-item i {
  font-size: 1rem;
  min-width: 20px;
  text-align: center;
}

/* ========== 响应式：折叠侧边栏 ========== */
#sidebar.collapsed .logo,
#sidebar.collapsed .user-info,
#sidebar.collapsed .quick-btn span,
#sidebar.collapsed .history-item-title,
#sidebar.collapsed .user-avatar,
#sidebar.collapsed .history-title {
  display: none;
}

#sidebar.collapsed .quick-btn,
#sidebar.collapsed .history-item {
  justify-content: center;
  padding: 0.75rem 0;
}

#sidebar.collapsed .user-section {
  justify-content: center;
}

#sidebar.collapsed .shortcut-icons {
  display: none;
}

/* ========== 主内容区 ========== */
#main-content {
  flex: 1;
  overflow: hidden;
  background: #f7fafc;
  transition: margin-left 0.3s;
  display: flex;
  flex-direction: column;
}

#main-content.sidebar-collapsed {
  margin-left: calc(var(--sidebar-collapsed-width) - var(--sidebar-width));
}

.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: var(--chat-max-width);
  width: 100%;
  margin: 0 auto;
  position: relative;
  height: 100%;
}

.chat-messages-container-w {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  scrollbar-width: none;
}

.chat-messages-container {
  flex: 1;
  padding: 1.5rem 1rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.chat-messages-container::-webkit-scrollbar {
  display: none;
}

.welcome-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 2rem;
}

.welcome-box {
  text-align: center;
  color: #4a5568;
  max-width: 500px;
  width: 100%;
  animation: fadeIn 0.5s ease forwards;
}

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

.welcome-title {
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 1rem;
  color: var(--primary-color);
}

.welcome-subtitle {
  font-size: 1rem;
  color: #718096;
  line-height: 1.5;
}

.message {
  max-width: 85%;
  animation: fadeIn 0.3s ease-in-out;
}

.user-message {
  align-self: flex-end;
  background: var(--primary-color);
  color: white;
  padding: 0.75rem 1rem;
  border-radius: 18px 18px 4px 18px;
}

.ai-message {
  align-self: flex-start;
  background: none;
  border: none;
  overflow: hidden;
}

/* ========== 图片生成专用样式 ========== */

/* 加载动画容器 */
.loading-container {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.05);
  border: 1px solid var(--gray-300);
}

.loading-spinner {
  display: flex;
  align-items: center;
  gap: 12px;
}

.spinner-circle {
  width: 50px;
  height: 50px;
  border: 4px solid #f3f3f3;
  border-top: 4px solid var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 10px;
}

.spinner-text {
  font-size: 14px;
  color: #666;
}

.loading-steps {
  display: flex;
  justify-content: space-between;
  max-width: 400px;
  margin: 0 auto;
}

.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  opacity: 0.3;
  transition: opacity 0.3s ease;
}

.step.active {
  opacity: 1;
}

.step.completed {
  opacity: 0.7;
}

.step-icon {
  font-size: 20px;
  margin-bottom: 5px;
}

.step-text {
  font-size: 12px;
  text-align: center;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* 图片结果容器 */
.image-result-wrapper {
  max-width: 600px;
  margin: 0 auto;
  position: relative;
  padding: 1rem;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.05);
}

.image-result {
  width: 100%;
  border-radius: 8px;
  display: block;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.image-result.loaded {
  opacity: 1;
}

.image-actions {
  position: absolute;
  bottom: 12px;
  right: 12px;
  display: flex;
  gap: 0.5rem;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.image-result-wrapper:hover .image-actions {
  opacity: 1;
}

.image-action-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--gray-300);
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  color: #6c757d;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.image-action-btn:hover {
  background: var(--primary-light);
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.image-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  font-size: 12px;
  color: #666;
}

.action-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #718096;
    cursor: pointer;
    transition: all .2s;
    font-size: .9rem;
    background: 0 0;
    border: none;
}

.prompt-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.size-badge {
  background: var(--primary-color);
  color: white;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
}

/* 流式文本输出 */
.streaming-text {
  margin-top: 12px;
  line-height: 1.6;
  color: #333;
  font-size: 0.95rem;
}

/* ========== 输入区域 ========== */
.input-center {
  display: flex;
  justify-content: center;
  margin-bottom: 2rem;
  padding: 1rem;
  background: #f7fafc;
  border-top: 1px solid var(--gray-300);
  position: sticky;
  bottom: 0;
  z-index: 100;
}

.input-card {
  background: white;
  border-radius: 24px;
  box-shadow: 0 4px 6px rgba(0,0,0,0.05);
  padding: 1rem;
  border: 1px solid var(--gray-300);
  width: 100%;
}

.input-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.prompt-input {
  width: 100%;
  min-height: 100px;
  max-height: 200px;
  padding: 0.75rem;
  border: 1px solid #fff;
  border-radius: 12px;
  font-size: 0.95rem;
  resize: none;
  line-height: 1.5;
}

.prompt-input:focus {
  outline: none;
}

.control-and-send {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.control-row {
  display: flex;
  gap: 0.75rem;
}

.dropdown {
  position: relative;
  width: 120px;
}

.dropdown-toggle {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  background: white;
  font-size: 0.85rem;
  color: #6c757d;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: all 0.2s;
}

.dropdown-toggle:hover,
.dropdown-toggle:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(74, 108, 247, 0.25);
}

.dropdown-menu-x {
  position: absolute;
  bottom: 100%;
  left: 0;
  z-index: 1000;
  display: none;
  min-width: 100%;
  padding: 0.5rem 0;
  margin: 0.125rem 0 0;
  font-size: 0.875rem;
  background: white;
  border: 1px solid rgba(0,0,0,.15);
  border-radius: 6px;
  box-shadow: 0 -0.5rem 1rem rgba(0,0,0,0.15);
  transform: translateY(5px);
  list-style: none;
}

.dropdown-menu-x.show {
  display: block;
}

.dropdown-item {
  padding: 0.5rem 1rem;
  cursor: pointer;
  transition: all 0.2s;
}

.dropdown-item:hover {
  background: var(--primary-light);
  color: var(--primary-color);
}

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary-color);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.send-btn:hover:not(:disabled) {
  background: #3a5ce5;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.send-btn:disabled {
  background: var(--gray-300);
  cursor: not-allowed;
}

/* ========== 固定免责声明 ========== */
.fixed-disclaimer {
  position: absolute;
  bottom: 10px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.75rem;
  color: #718096;
  padding: 0.5rem;
  background: rgba(247, 250, 252, 0.8);
  z-index: 150;
}

/* ========== 错误消息 ========== */
.error-message {
  padding: 20px;
  background: #ffeaea;
  border: 1px solid #ffcccc;
  border-radius: 8px;
  color: #d63031;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.retry-btn {
  padding: 8px 16px;
  background: #007bff;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.retry-btn:hover {
  background: #0056b3;
}

/* ========== Toast 通知 ========== */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 12px 20px;
  border-radius: 4px;
  color: white;
  z-index: 1000;
  opacity: 0;
  transform: translateY(-20px);
  transition: all 0.3s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-success {
  background: #28a745;
}

.toast-error {
  background: #dc3545;
}

.toast-warning {
  background: #ffc107;
  color: #212529;
}

.toast-info {
  background: #17a2b8;
}

/* ========== 响应式设计 ========== */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 60px;
  }
  #sidebar {
    width: var(--sidebar-width);
  }
}