/* ============================================
   工作台增强样式 - Workspace Enhancements
   ============================================ */

/* ---- CSS Variables ---- */
:root {
  --ws-accent: #4d9fff;
  --ws-accent-soft: rgba(77, 159, 255, 0.12);
  --ws-success: #4ade80;
  --ws-warning: #fbbf24;
  --ws-danger: #f87171;
  --ws-surface: rgba(16, 22, 32, 0.95);
  --ws-surface-hover: rgba(22, 30, 44, 0.95);
  --ws-border: rgba(255, 255, 255, 0.1);
  --ws-text: rgba(240, 248, 255, 0.95);
  --ws-text-secondary: rgba(180, 200, 220, 0.75);
  --ws-text-muted: rgba(140, 160, 180, 0.55);
}

/* ==================== 1. 智能提示词补全 ==================== */
.prompt-autocomplete {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 100%;
  margin-bottom: 8px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--ws-surface);
  border: 1px solid var(--ws-border);
  border-radius: 12px;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.4);
  z-index: 100;
  display: none;
}

.prompt-autocomplete.visible {
  display: block;
  animation: slideUp 0.2s ease;
}

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

.autocomplete-section {
  padding: 8px 0;
  border-bottom: 1px solid var(--ws-border);
}

.autocomplete-section:last-child {
  border-bottom: none;
}

.autocomplete-label {
  padding: 6px 14px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ws-text-muted);
}

.autocomplete-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.autocomplete-item:hover,
.autocomplete-item.active {
  background: var(--ws-accent-soft);
}

.autocomplete-item-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.autocomplete-item-content {
  flex: 1;
  min-width: 0;
}

.autocomplete-item-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--ws-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.autocomplete-item-desc {
  font-size: 11px;
  color: var(--ws-text-muted);
  margin-top: 2px;
}

.autocomplete-item-kbd {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ws-text-muted);
}

/* ==================== 2. 提示词模板插入器 ==================== */
.prompt-templates-trigger {
  position: absolute;
  right: 50px;
  bottom: 12px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--ws-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ws-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  z-index: 10;
}

.prompt-templates-trigger:hover {
  border-color: var(--ws-accent);
  color: var(--ws-accent);
  background: var(--ws-accent-soft);
}

.prompt-templates-trigger svg {
  width: 16px;
  height: 16px;
}

.prompt-templates-panel {
  position: absolute;
  right: 0;
  bottom: 100%;
  margin-bottom: 8px;
  width: 320px;
  max-height: 360px;
  overflow-y: auto;
  background: var(--ws-surface);
  border: 1px solid var(--ws-border);
  border-radius: 14px;
  box-shadow: 0 -16px 48px rgba(0, 0, 0, 0.45);
  z-index: 101;
  display: none;
}

.prompt-templates-panel.visible {
  display: block;
  animation: slideUp 0.2s ease;
}

.templates-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--ws-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.templates-header h4 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.templates-close {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--ws-text-muted);
  cursor: pointer;
}

.templates-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--ws-text);
}

.templates-category {
  padding: 12px 16px 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ws-text-muted);
}

.template-item {
  display: block;
  width: 100%;
  padding: 10px 16px;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease;
}

.template-item:hover {
  background: var(--ws-accent-soft);
}

.template-item-text {
  font-size: 13px;
  color: var(--ws-text);
  line-height: 1.5;
}

.template-item-preview {
  font-size: 11px;
  color: var(--ws-text-muted);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==================== 3. 字数统计 ==================== */
.prompt-stats {
  position: absolute;
  left: 14px;
  bottom: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 11px;
  color: var(--ws-text-muted);
  z-index: 5;
}

.prompt-char-count {
  display: flex;
  align-items: center;
  gap: 4px;
}

.prompt-char-count.warning {
  color: var(--ws-warning);
}

.prompt-char-count.danger {
  color: var(--ws-danger);
}

.prompt-char-count.optimal {
  color: var(--ws-success);
}

.char-bar {
  width: 60px;
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.char-bar-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--ws-accent);
  transition: width 0.2s ease, background 0.2s ease;
}

.char-bar-fill.warning {
  background: var(--ws-warning);
}

.char-bar-fill.danger {
  background: var(--ws-danger);
}

.char-bar-fill.optimal {
  background: var(--ws-success);
}

/* ==================== 4. 可视化比例选择器 ==================== */
.visual-ratio-selector {
  display: flex;
  gap: 8px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  border: 1px solid var(--ws-border);
}

.ratio-option {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 8px;
  border-radius: 10px;
  border: 2px solid transparent;
  background: transparent;
  cursor: pointer;
  transition: all 0.2s ease;
}

.ratio-option:hover {
  background: rgba(255, 255, 255, 0.05);
}

.ratio-option.active {
  border-color: var(--ws-accent);
  background: var(--ws-accent-soft);
}

.ratio-preview {
  width: 100%;
  max-width: 48px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
}

.ratio-preview::after {
  content: '';
  position: absolute;
  inset: 4px;
  border: 1px dashed rgba(255, 255, 255, 0.3);
  border-radius: 2px;
}

.ratio-option[data-ratio="16:9"] .ratio-preview {
  aspect-ratio: 16/9;
}

.ratio-option[data-ratio="9:16"] .ratio-preview {
  aspect-ratio: 9/16;
  max-width: 32px;
}

.ratio-option[data-ratio="1:1"] .ratio-preview {
  aspect-ratio: 1/1;
  max-width: 40px;
}

.ratio-option[data-ratio="4:3"] .ratio-preview {
  aspect-ratio: 4/3;
  max-width: 44px;
}

.ratio-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--ws-text-secondary);
}

.ratio-option.active .ratio-label {
  color: var(--ws-accent);
}

.ratio-desc {
  font-size: 10px;
  color: var(--ws-text-muted);
}

/* ==================== 5. 时长滑块 ==================== */
.duration-slider-wrap {
  padding: 12px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  border: 1px solid var(--ws-border);
}

.duration-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.duration-label {
  font-size: 12px;
  color: var(--ws-text-secondary);
}

.duration-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--ws-accent);
}

.duration-slider {
  position: relative;
  height: 32px;
  display: flex;
  align-items: center;
}

.duration-track {
  position: absolute;
  left: 0;
  right: 0;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

.duration-fill {
  position: absolute;
  left: 0;
  height: 6px;
  background: linear-gradient(90deg, var(--ws-accent), #7c3aed);
  border-radius: 3px;
  transition: width 0.15s ease;
}

.duration-input {
  position: relative;
  width: 100%;
  height: 32px;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
  z-index: 2;
}

.duration-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  cursor: grab;
  transition: transform 0.15s ease;
}

.duration-input::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.duration-input::-webkit-slider-thumb:active {
  cursor: grabbing;
  transform: scale(1.1);
}

.duration-marks {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  padding: 0 2px;
}

.duration-mark {
  font-size: 10px;
  color: var(--ws-text-muted);
}

/* ==================== 6. 预设快捷组合 ==================== */
.presets-bar {
  display: flex;
  gap: 8px;
  padding: 12px 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.presets-bar::-webkit-scrollbar {
  display: none;
}

.preset-chip {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid var(--ws-border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--ws-text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.preset-chip:hover {
  border-color: var(--ws-accent);
  color: var(--ws-text);
  background: var(--ws-accent-soft);
}

.preset-chip.active {
  border-color: var(--ws-accent);
  background: var(--ws-accent);
  color: white;
}

.preset-chip-icon {
  font-size: 14px;
}

.preset-chip-info {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.1);
}

.preset-chip.active .preset-chip-info {
  background: rgba(255, 255, 255, 0.2);
}

/* ==================== 7. 生成历史面板 ==================== */
.history-panel {
  position: fixed;
  top: 0;
  right: -380px;
  width: 380px;
  height: 100vh;
  background: var(--ws-surface);
  border-left: 1px solid var(--ws-border);
  z-index: 200;
  transition: right 0.3s ease;
  display: flex;
  flex-direction: column;
}

.history-panel.open {
  right: 0;
  box-shadow: -20px 0 60px rgba(0, 0, 0, 0.4);
}

.history-header {
  padding: 20px;
  border-bottom: 1px solid var(--ws-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.history-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-count {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--ws-accent-soft);
  color: var(--ws-accent);
}

.history-close {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--ws-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.history-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--ws-text);
}

.history-close svg {
  width: 20px;
  height: 20px;
}

.history-filters {
  padding: 12px 20px;
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--ws-border);
}

.history-filter {
  padding: 6px 12px;
  border-radius: 16px;
  border: 1px solid var(--ws-border);
  background: transparent;
  color: var(--ws-text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.history-filter:hover {
  border-color: var(--ws-border);
  background: rgba(255, 255, 255, 0.05);
}

.history-filter.active {
  border-color: var(--ws-accent);
  background: var(--ws-accent-soft);
  color: var(--ws-accent);
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.history-item {
  display: flex;
  gap: 12px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid transparent;
  margin-bottom: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.history-item:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--ws-border);
}

.history-thumb {
  width: 72px;
  height: 72px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  overflow: hidden;
  flex-shrink: 0;
}

.history-thumb img,
.history-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.history-thumb-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ws-text-muted);
  font-size: 20px;
}

.history-info {
  flex: 1;
  min-width: 0;
}

.history-prompt {
  font-size: 12px;
  color: var(--ws-text);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 8px;
}

.history-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 11px;
  color: var(--ws-text-muted);
}

.history-meta span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.history-status {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 500;
}

.history-status.success {
  background: rgba(74, 222, 128, 0.15);
  color: var(--ws-success);
}

.history-status.processing {
  background: rgba(77, 159, 255, 0.15);
  color: var(--ws-accent);
}

.history-status.failed {
  background: rgba(248, 113, 113, 0.15);
  color: var(--ws-danger);
}

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

.history-action-btn {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--ws-border);
  background: transparent;
  color: var(--ws-text-secondary);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.history-action-btn:hover {
  border-color: var(--ws-accent);
  color: var(--ws-accent);
}

.history-toggle-btn {
  position: fixed;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--ws-border);
  background: var(--ws-surface);
  color: var(--ws-text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  transition: all 0.2s ease;
}

.history-toggle-btn:hover {
  border-color: var(--ws-accent);
  color: var(--ws-accent);
  background: var(--ws-accent-soft);
}

.history-toggle-btn svg {
  width: 20px;
  height: 20px;
}

.history-toggle-btn .badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--ws-accent);
  color: white;
  font-size: 10px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ==================== 8. 快捷键提示 ==================== */
.shortcuts-hint {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
  padding: 10px 20px;
  background: var(--ws-surface);
  border: 1px solid var(--ws-border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
}

.shortcuts-hint.visible {
  opacity: 1;
  visibility: visible;
}

.shortcut-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--ws-text-secondary);
}

.shortcut-key {
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--ws-border);
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: var(--ws-text);
}

/* ==================== 9. 生成进度可视化 ==================== */
.generation-progress {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  width: 400px;
  max-width: calc(100vw - 40px);
  padding: 20px;
  background: var(--ws-surface);
  border: 1px solid var(--ws-border);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  z-index: 150;
  display: none;
}

.generation-progress.visible {
  display: block;
  animation: slideUp 0.3s ease;
}

.progress-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.progress-title {
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}

.progress-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--ws-border);
  border-top-color: var(--ws-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.progress-eta {
  font-size: 12px;
  color: var(--ws-text-muted);
}

.progress-bar-wrap {
  margin-bottom: 12px;
}

.progress-bar {
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--ws-accent), #7c3aed);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.progress-stages {
  display: flex;
  justify-content: space-between;
}

.progress-stage {
  font-size: 11px;
  color: var(--ws-text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.progress-stage.active {
  color: var(--ws-accent);
}

.progress-stage.done {
  color: var(--ws-success);
}

.progress-stage-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ws-border);
}

.progress-stage.active .progress-stage-dot {
  background: var(--ws-accent);
  animation: pulse 1s ease-in-out infinite;
}

.progress-stage.done .progress-stage-dot {
  background: var(--ws-success);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ==================== 10. 草稿自动保存提示 ==================== */
.draft-indicator {
  position: fixed;
  bottom: 20px;
  left: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--ws-surface);
  border: 1px solid var(--ws-border);
  border-radius: 10px;
  font-size: 12px;
  color: var(--ws-text-muted);
  z-index: 50;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s ease;
}

.draft-indicator.visible {
  opacity: 1;
  transform: translateY(0);
}

.draft-indicator.saving {
  color: var(--ws-accent);
}

.draft-indicator.saved {
  color: var(--ws-success);
}

.draft-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.draft-indicator.saving .draft-dot {
  animation: pulse 0.8s ease-in-out infinite;
}

/* ==================== 11. 参数面板优化 ==================== */
.params-panel {
  background: rgba(12, 16, 24, 0.85);
  border: 1px solid var(--ws-border);
  border-radius: 16px;
  padding: 16px;
  margin-top: 16px;
}

.params-section {
  margin-bottom: 20px;
}

.params-section:last-child {
  margin-bottom: 0;
}

.params-section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--ws-text-secondary);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.params-section-title svg {
  width: 14px;
  height: 14px;
  color: var(--ws-text-muted);
}

/* ==================== 12. 移动端适配 ==================== */
@media (max-width: 768px) {
  .history-panel {
    width: 100%;
    right: -100%;
  }

  .history-toggle-btn {
    right: 12px;
    width: 40px;
    height: 40px;
  }

  .shortcuts-hint {
    display: none;
  }

  .generation-progress {
    bottom: 80px;
    width: calc(100vw - 24px);
    left: 12px;
    transform: none;
  }

  .presets-bar {
    padding: 8px 0;
  }

  .preset-chip {
    padding: 6px 12px;
    font-size: 11px;
  }

  .visual-ratio-selector {
    flex-wrap: wrap;
  }

  .ratio-option {
    min-width: calc(50% - 4px);
  }

  .prompt-templates-panel {
    width: calc(100vw - 24px);
    right: -8px;
  }
}

/* ==================== 13. 动画优化 ==================== */
@media (prefers-reduced-motion: reduce) {
  .prompt-autocomplete.visible,
  .prompt-templates-panel.visible,
  .generation-progress.visible,
  .history-panel {
    animation: none;
  }

  .progress-spinner,
  .progress-stage.active .progress-stage-dot,
  .draft-indicator.saving .draft-dot {
    animation: none;
  }
}
