/* ReaChat 主题系统 */

/* 深色主题 */
[data-theme="dark"] {
  /* 颜色系统 */
  --color-primary: #8b5cf6;
  --color-primary-hover: #7c3aed;
  --color-primary-light: rgba(139, 92, 246, 0.1);
  
  /* 背景色 */
  --bg-primary: #1e293b;
  --bg-secondary: #0f172a;
  --bg-tertiary: #334155;
  --bg-overlay: rgba(0, 0, 0, 0.8);
  
  /* 文本色 */
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-tertiary: #64748b;
  --text-inverse: #0f172a;
  
  /* 边框色 */
  --border-primary: #334155;
  --border-secondary: #475569;
  --border-focus: var(--color-primary);
  
  /* 阴影 (深色主题下调整) */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 10px 10px -5px rgba(0, 0, 0, 0.4);
}

/* 深色主题特殊样式调整 */
[data-theme="dark"] .message.assistant .message-bubble {
  background: var(--bg-tertiary);
  border-color: var(--border-primary);
}

[data-theme="dark"] .message-text pre {
  background: rgba(255, 255, 255, 0.05);
}

[data-theme="dark"] .message-text code {
  background: rgba(255, 255, 255, 0.1);
}

/* 暗色主题富文本样式 */
[data-theme="dark"] .message-text .markdown-blockquote {
  background: rgba(255, 255, 255, 0.05);
  color: #b3b3b3;
  border-left-color: var(--color-primary);
}

[data-theme="dark"] .message-text .markdown-table {
  background: #1a1a1a;
}

[data-theme="dark"] .message-text .markdown-table thead {
  background: #2a2a2a;
}

[data-theme="dark"] .message-text .markdown-table th {
  color: #ffffff;
  border-bottom-color: #404040;
}

[data-theme="dark"] .message-text .markdown-table td {
  color: #cccccc;
  border-bottom-color: #404040;
}

[data-theme="dark"] .message-text .markdown-table tbody tr:nth-child(even) {
  background: #222222;
}

[data-theme="dark"] .message-text .markdown-table tbody tr:hover {
  background: #333333;
}

[data-theme="dark"] .message-text .markdown-image {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .message-text .markdown-hr {
  background: linear-gradient(90deg, transparent, #404040, transparent);
}

[data-theme="dark"] .message-action-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .quick-action-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--color-primary);
}

/* 自动主题 - 跟随系统设置 */
.theme-auto {
  /* 默认使用浅色主题变量 */
}

@media (prefers-color-scheme: dark) {
  .theme-auto {
    /* 颜色系统 */
    --color-primary: #8b5cf6;
    --color-primary-hover: #7c3aed;
    --color-primary-light: rgba(139, 92, 246, 0.1);
    
    /* 背景色 */
    --bg-primary: #1e293b;
    --bg-secondary: #0f172a;
    --bg-tertiary: #334155;
    --bg-overlay: rgba(0, 0, 0, 0.8);
    
    /* 文本色 */
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-tertiary: #64748b;
    --text-inverse: #0f172a;
    
    /* 边框色 */
    --border-primary: #334155;
    --border-secondary: #475569;
    --border-focus: var(--color-primary);
    
    /* 阴影 */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 10px 10px -5px rgba(0, 0, 0, 0.4);
  }
  
  .theme-auto .message.assistant .message-bubble {
    background: var(--bg-tertiary);
    border-color: var(--border-primary);
  }
  
  .theme-auto .message-text pre {
    background: rgba(255, 255, 255, 0.05);
  }
  
  .theme-auto .message-text code {
    background: rgba(255, 255, 255, 0.1);
  }
  
  /* 自动主题暗色模式富文本样式 */
  .theme-auto .message-text .markdown-blockquote {
    background: rgba(255, 255, 255, 0.05);
    color: #b3b3b3;
    border-left-color: var(--color-primary);
  }

  .theme-auto .message-text .markdown-table {
    background: #1a1a1a;
  }

  .theme-auto .message-text .markdown-table thead {
    background: #2a2a2a;
  }

  .theme-auto .message-text .markdown-table th {
    color: #ffffff;
    border-bottom-color: #404040;
  }

  .theme-auto .message-text .markdown-table td {
    color: #cccccc;
    border-bottom-color: #404040;
  }

  .theme-auto .message-text .markdown-table tbody tr:nth-child(even) {
    background: #222222;
  }

  .theme-auto .message-text .markdown-table tbody tr:hover {
    background: #333333;
  }

  .theme-auto .message-text .markdown-image {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  }

  .theme-auto .message-text .markdown-hr {
    background: linear-gradient(90deg, transparent, #404040, transparent);
  }
  
  .theme-auto .message-action-btn:hover {
    background: rgba(255, 255, 255, 0.1);
  }
  
  .theme-auto .quick-action-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--color-primary);
  }
}

/* 主题切换按钮状态 */
[data-theme="light"] .theme-toggle .moon-icon {
  opacity: 0;
}

[data-theme="dark"] .theme-toggle .sun-icon {
  opacity: 0;
}

.theme-auto .theme-toggle .sun-icon,
.theme-auto .theme-toggle .moon-icon {
  opacity: 0.5;
}

@media (prefers-color-scheme: dark) {
  .theme-auto .theme-toggle .sun-icon {
    opacity: 0;
  }
  
  .theme-auto .theme-toggle .moon-icon {
    opacity: 1;
  }
}

@media (prefers-color-scheme: light) {
  .theme-auto .theme-toggle .sun-icon {
    opacity: 1;
  }
  
  .theme-auto .theme-toggle .moon-icon {
    opacity: 0;
  }
}

/* 主题过渡动画 */
* {
  transition: background-color var(--transition-normal), 
              border-color var(--transition-normal), 
              color var(--transition-normal);
}

/* 禁用过渡动画的元素 */
.loading-spinner,
.message-input,
input,
textarea,
select {
  transition: none;
}

/* 高对比度主题支持 */
@media (prefers-contrast: high) {
  :root {
    --border-primary: #000000;
    --border-secondary: #000000;
    --text-tertiary: var(--text-secondary);
  }
  
  [data-theme="dark"] {
    --border-primary: #ffffff;
    --border-secondary: #ffffff;
    --text-tertiary: var(--text-secondary);
  }
}

/* 减少动画偏好 */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* 打印样式 */
@media print {
  .sidebar,
  .chat-header,
  .chat-input-container,
  .notification-container,
  .modal {
    display: none !important;
  }
  
  .main-content {
    margin: 0 !important;
    box-shadow: none !important;
  }
  
  .chat-messages {
    height: auto !important;
    overflow: visible !important;
  }
  
  .message {
    page-break-inside: avoid;
  }
  
  .message-bubble {
    max-width: 100% !important;
    border: 1px solid #ccc !important;
    background: white !important;
    color: black !important;
  }
}