/* ==========================================================================
   主题切换样式 - AI工具集主题系统
   ========================================================================== */

/* 主题切换按钮样式 */
.theme-toggle {
  position: relative;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: all var(--transition-normal);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.theme-toggle:hover {
  background: var(--bg-tertiary);
  border-color: var(--border-color-dark);
  transform: scale(1.05);
}

.theme-toggle:focus {
  outline: none;
  box-shadow: 0 0 0 3px var(--primary-color-alpha);
}

/* 主题图标样式 */
.theme-toggle .icon {
  width: 1.25rem;
  height: 1.25rem;
  transition: all var(--transition-normal);
  position: absolute;
}

.sun-icon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

.moon-icon {
  opacity: 0;
  transform: rotate(180deg) scale(0.8);
}

[data-theme="dark"] .sun-icon {
  opacity: 0;
  transform: rotate(-180deg) scale(0.8);
}

[data-theme="dark"] .moon-icon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

/* 主题切换动画效果 */
.theme-switching {
  animation: themeSwitch 0.6s ease-in-out;
}

@keyframes themeSwitch {
  0% {
    transform: scale(1) rotate(0deg);
  }
  50% {
    transform: scale(0.8) rotate(180deg);
  }
  100% {
    transform: scale(1) rotate(360deg);
  }
}

/* 主题切换时的页面过渡效果 */
html {
  transition: background-color var(--transition-slow), color var(--transition-slow);
}

body {
  transition: background-color var(--transition-slow), color var(--transition-slow);
}

/* 暗色模式下的特殊样式调整 */
[data-theme="dark"] {
  /* 滚动条样式 */
  scrollbar-width: thin;
  scrollbar-color: var(--border-color-dark) var(--bg-secondary);
}

[data-theme="dark"] ::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

[data-theme="dark"] ::-webkit-scrollbar-track {
  background: var(--bg-secondary);
  border-radius: var(--border-radius-sm);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
  background: var(--border-color-dark);
  border-radius: var(--border-radius-sm);
  transition: background var(--transition-fast);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* 暗色模式下的选中文本样式 */
[data-theme="dark"] ::selection {
  background: var(--primary-color-alpha);
  color: var(--text-primary);
}

[data-theme="dark"] ::-moz-selection {
  background: var(--primary-color-alpha);
  color: var(--text-primary);
}

/* 暗色模式下的表单元素特殊处理 */
[data-theme="dark"] .form-input,
[data-theme="dark"] .form-textarea,
[data-theme="dark"] .form-select {
  background: var(--input-bg);
  border-color: var(--border-color);
  color: var(--text-primary);
}

[data-theme="dark"] .form-input::placeholder,
[data-theme="dark"] .form-textarea::placeholder {
  color: var(--text-tertiary);
}

[data-theme="dark"] .form-input:focus,
[data-theme="dark"] .form-textarea:focus,
[data-theme="dark"] .form-select:focus {
  background: var(--input-bg);
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px var(--primary-color-alpha);
}

/* 暗色模式下的按钮特殊样式 */
[data-theme="dark"] .btn-secondary {
  background: var(--bg-tertiary);
  border-color: var(--border-color);
  color: var(--text-primary);
}

[data-theme="dark"] .btn-secondary:hover:not(:disabled) {
  background: var(--border-color);
  border-color: var(--border-color-dark);
}

[data-theme="dark"] .btn-ghost:hover:not(:disabled) {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* 暗色模式下的卡片样式 */
[data-theme="dark"] .card {
  background: var(--card-bg);
  border-color: var(--border-color);
  box-shadow: var(--shadow-md);
}

[data-theme="dark"] .card:hover {
  box-shadow: var(--shadow-lg);
  border-color: var(--border-color-dark);
}

/* 暗色模式下的标签样式 */
[data-theme="dark"] .tag {
  background: var(--bg-tertiary);
  border-color: var(--border-color);
  color: var(--text-secondary);
}

[data-theme="dark"] .tag-primary {
  background: rgba(99, 102, 241, 0.2);
  color: var(--primary-color-light);
  border-color: var(--primary-color);
}

/* 暗色模式下的提示框样式 */
[data-theme="dark"] .alert-info {
  background: rgba(99, 102, 241, 0.15);
  color: var(--primary-color-light);
}

[data-theme="dark"] .alert-success {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
}

[data-theme="dark"] .alert-warning {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
}

[data-theme="dark"] .alert-error {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
}

/* 主题切换过渡效果 */
.theme-transition {
  transition: all var(--transition-slow) ease-in-out;
}

/* 为所有可能受主题影响的元素添加过渡 */
*,
*::before,
*::after {
  transition-property: background-color, border-color, color, fill, stroke, box-shadow;
  transition-duration: var(--transition-normal);
  transition-timing-function: ease;
}

/* 但排除一些不需要过渡的元素 */
.no-transition,
.no-transition *,
input[type="range"],
progress {
  transition: none !important;
}

/* 减少动画的用户偏好设置 */
@media (prefers-reduced-motion: reduce) {
  .theme-toggle,
  .theme-toggle .icon,
  .theme-switching {
    transition: none !important;
    animation: none !important;
  }
  
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* 高对比度模式支持 */
@media (prefers-contrast: high) {
  .theme-toggle {
    border-width: 2px;
    border-color: currentColor;
  }
  
  [data-theme="dark"] .theme-toggle {
    background: var(--bg-primary);
    color: var(--text-primary);
  }
}

/* 系统主题偏好检测 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --card-bg: #1e293b;
    --input-bg: #334155;
    --code-bg: #1e293b;
    
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-tertiary: #94a3b8;
    
    --border-color: #334155;
    --border-color-light: #475569;
    --border-color-dark: #1e293b;
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
    --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.4), 0 10px 10px -5px rgba(0, 0, 0, 0.3);
  }
  
  :root:not([data-theme]) .sun-icon {
    opacity: 0;
    transform: rotate(-180deg) scale(0.8);
  }
  
  :root:not([data-theme]) .moon-icon {
    opacity: 1;
    transform: rotate(0deg) scale(1);
  }
}

/* 主题切换提示文本 */
.theme-toggle::after {
  content: attr(title);
  position: absolute;
  bottom: -2.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-primary);
  color: var(--text-primary);
  padding: 0.25rem 0.5rem;
  border-radius: var(--border-radius-sm);
  font-size: var(--font-size-xs);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  z-index: var(--z-tooltip);
}

.theme-toggle:hover::after {
  opacity: 1;
}

/* 主题切换快捷键提示 */
@media (min-width: 768px) {
  .theme-toggle[title*="Ctrl"]::after,
  .theme-toggle[title*="⌘"]::after {
    content: attr(title);
  }
}

/* 主题状态指示器（可选） */
.theme-indicator {
  position: fixed;
  top: 1rem;
  right: 1rem;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--primary-color);
  opacity: 0;
  transition: opacity var(--transition-fast);
  z-index: var(--z-tooltip);
  pointer-events: none;
}

.theme-switching + .theme-indicator {
  opacity: 1;
}

/* 主题切换时的页面遮罩效果（可选） */
.theme-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-primary);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
  z-index: var(--z-modal);
}

.theme-switching .theme-overlay {
  opacity: 0.1;
}

/* 响应式主题切换按钮 */
@media (max-width: 640px) {
  .theme-toggle {
    width: 2.25rem;
    height: 2.25rem;
    padding: 0.375rem;
  }
  
  .theme-toggle .icon {
    width: 1rem;
    height: 1rem;
  }
  
  .theme-toggle::after {
    display: none;
  }
}

/* 打印时隐藏主题切换按钮 */
@media print {
  .theme-toggle,
  .theme-indicator,
  .theme-overlay {
    display: none !important;
  }
}