/* ═══════════════════════════════════════════════
   SoundFlow 音律 — Web App Stylesheet
   Theme: Dark default, Light + Auto support
   ═══════════════════════════════════════════════ */

:root {
  --font-display: 'Sora', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', monospace;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --radius-sm: 3px;
  --radius-md: 6px;
  --radius-lg: 10px;
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  /* Dark defaults */
  --bg-deep: #0a0a0b;
  --bg-base: #111114;
  --bg-surface: #18181c;
  --bg-elevated: #1e1e24;
  --bg-hover: #24242b;
  --border-subtle: #282830;
  --border-strong: #34343d;
  --text-primary: #e4e1db;
  --text-secondary: #8b887f;
  --text-tertiary: #5e5c58;
  --accent-warm: #d4a574;
  --accent-warm-dim: #8b6b4a;
  --accent-warm-glow: rgba(212,165,116,0.12);
  --accent-cool: #6b9eb8;
  --accent-cool-dim: #3d5d6e;
  --red: #c56b5b;
  --green: #5c8a6e;
  --yellow: #c4a85c;
  --body-bg: #050508;
  --body-grad-1: rgba(212,165,116,0.03);
  --body-grad-2: rgba(107,158,184,0.02);
  --window-shadow: 0 0 0 1px rgba(255,255,255,0.02), 0 24px 80px rgba(0,0,0,0.6);
}

[data-theme="light"] {
  --bg-deep: #f0ede6;
  --bg-base: #faf9f5;
  --bg-surface: #ffffff;
  --bg-elevated: #f5f3ee;
  --bg-hover: #edeae3;
  --border-subtle: #e2dfd7;
  --border-strong: #c8c4ba;
  --text-primary: #1f1e1a;
  --text-secondary: #6b6860;
  --text-tertiary: #9a968c;
  --accent-warm: #b8753a;
  --accent-warm-dim: #c9955e;
  --accent-warm-glow: rgba(184,117,58,0.08);
  --accent-cool: #4d7d94;
  --accent-cool-dim: #5d8fa6;
  --red: #b8574a;
  --green: #4a7a5c;
  --yellow: #b8973e;
  --body-bg: #f5f3ee;
  --body-grad-1: rgba(184,117,58,0.02);
  --body-grad-2: rgba(77,125,148,0.015);
  --window-shadow: 0 0 0 1px rgba(0,0,0,0.04), 0 16px 60px rgba(0,0,0,0.12);
}

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

html, body {
  height: 100%;
  background: var(--body-bg);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* Layout */
.app-shell {
  width: 100vw; height: 100vh;
  display: flex; flex-direction: column;
  background: var(--bg-base);
  transition: background-color 0.35s ease;
}

/* Titlebar */
.titlebar {
  height: 40px; min-height: 40px;
  background: var(--bg-deep);
  border-bottom: 1px solid var(--border-subtle);
  display: flex; align-items: center;
  padding: 0 12px; gap: 12px;
  user-select: none;
  transition: background-color 0.35s ease, border-color 0.35s ease;
}
.titlebar-dots { display: flex; gap: 7px; }
.titlebar-dot {
  width: 11px; height: 11px;
  border-radius: 50%; cursor: pointer;
  transition: filter 0.15s;
}
.titlebar-dot.close { background: #ed6a5e; }
.titlebar-dot.min  { background: #f5bd4f; }
.titlebar-dot.max  { background: #61c454; }
.titlebar-dot:hover { filter: brightness(1.15); }
.titlebar-title {
  position: absolute; left: 50%; transform: translateX(-50%);
  font-family: var(--font-display); font-size: 11px;
  font-weight: 600; color: var(--text-secondary);
  letter-spacing: 0.04em;
}
.titlebar-actions {
  display: flex; align-items: center; gap: 4px;
  margin-left: auto;
}
.titlebar-btn {
  width: 26px; height: 26px; display: flex;
  align-items: center; justify-content: center;
  border-radius: var(--radius-sm); cursor: pointer;
  color: var(--text-tertiary); transition: all 0.2s;
  background: none; border: none; font: inherit;
}
.titlebar-btn:hover { color: var(--text-primary); background: var(--bg-hover); }
.titlebar-btn.active { color: var(--accent-warm); }

/* AI 工具按钮 — 更醒目的设计 */
.ai-btn {
  width: auto !important;
  height: 28px;
  padding: 0 10px;
  gap: 6px;
  color: var(--accent-warm-dim) !important;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-radius: var(--radius-md);
  position: relative;
}
.ai-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}
.ai-btn:hover {
  color: var(--accent-warm) !important;
  background: var(--accent-warm-glow);
}
.ai-btn:hover::after {
  box-shadow: 0 0 12px var(--accent-warm-dim);
  opacity: 0.25;
}
.ai-btn.active {
  color: var(--accent-warm) !important;
  background: var(--accent-warm-glow);
}
.ai-btn span {
  white-space: nowrap;
}

/* Body */
.app-body { flex: 1; display: flex; overflow: hidden; }

/* Empty state */
.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px; padding: 48px;
}
.empty-state-icon { color: var(--text-tertiary); opacity: 0.5; margin-bottom: 8px; }
.empty-state-title {
  font-family: var(--font-display); font-size: 20px;
  font-weight: 600; color: var(--text-primary);
}
.empty-state-desc { color: var(--text-secondary); font-size: 13px; text-align: center; }

/* Drop zone */
.drop-zone {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: 48px; margin: 40px auto;
  max-width: 520px; text-align: center;
  cursor: pointer; transition: all 0.2s;
  background: var(--bg-surface);
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--accent-warm-dim);
  background: var(--accent-warm-glow);
}
.drop-zone-icon { margin-bottom: 12px; color: var(--text-tertiary); }
.drop-zone-title {
  font-family: var(--font-display); font-size: 15px;
  color: var(--text-secondary); margin-bottom: 4px;
}
.drop-zone-hint { font-size: 11px; color: var(--text-tertiary); }

/* Workspace Layout */
.workspace { flex: 1; display: none; flex-direction: column; overflow: hidden; }
.workspace.active { display: flex; }

/* Toolbar */
.toolbar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 16px; border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-deep); min-height: 42px;
  transition: background-color 0.35s ease;
}
.toolbar-file {
  font-size: 12px; font-weight: 500; flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.toolbar-meta {
  font-family: var(--font-mono); font-size: 10px;
  color: var(--text-tertiary);
}

/* ═══ Player Bar ═══ */
.player-bar {
  display: none; align-items: center; gap: 8px;
  padding: 6px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  min-height: 40px;
  margin-right: 240px; /* align with waveform (settings panel width) */
}
.player-bar.active { display: flex; }
.player-btn {
  width: 30px; height: 30px; display: flex;
  align-items: center; justify-content: center;
  border-radius: var(--radius-sm); cursor: pointer;
  background: none; border: 1px solid var(--border-subtle);
  color: var(--text-primary); transition: all 0.15s;
  flex-shrink: 0;
}
.player-btn:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.player-btn.play { background: var(--accent-warm); border-color: var(--accent-warm); color: #1a1a1a; }
.player-btn.play:hover { filter: brightness(1.1); }
.player-btn.sm { width: 22px; height: 22px; }
.player-time {
  font-family: var(--font-mono); font-size: 11px;
  color: var(--text-secondary); min-width: 40px;
  text-align: center; user-select: none; flex-shrink: 0;
}

/* Seek bar */
.seek-bar-wrap { flex: 1; position: relative; height: 28px; display: flex; align-items: center; cursor: pointer; }
.seek-bar-track {
  width: 100%; height: 4px; background: var(--bg-hover);
  border-radius: 2px; position: relative; overflow: visible;
}
.seek-bar-fill {
  height: 100%; background: var(--accent-warm);
  border-radius: 2px; width: 0%; transition: width 0.05s linear;
  position: relative;
}
.seek-bar-thumb {
  position: absolute; right: -5px; top: -3px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent-warm); opacity: 0;
  transition: opacity 0.15s;
}
.seek-bar-wrap:hover .seek-bar-thumb { opacity: 1; }

/* Main workspace area */
.workspace-main {
  flex: 1; display: flex; overflow: hidden;
}

/* Left panel: waveform + envelope */
.workspace-editor {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; min-width: 0;
}

/* Video Preview */
.video-preview-wrap {
  display: none; max-height: 240px;
  background: #000; position: relative;
  border-bottom: 1px solid var(--border-subtle);
}
.video-preview-wrap.active { display: block; }
.video-preview-wrap video {
  width: 100%; height: 100%; max-height: 240px;
  display: block; object-fit: contain;
}

/* ═══ Unified Waveform + Envelope Canvas ═══ */
.waveform-panel {
  flex: 1; position: relative;
  background: var(--bg-surface);
  cursor: crosshair;
  min-height: 180px;
}
.waveform-panel canvas { width: 100%; height: 100%; display: block; }

/* ═══ Envelope Controls Bar ═══ */
.envelope-ctrl {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px;
  background: var(--bg-deep);
  border-top: 1px solid var(--border-subtle);
  min-height: 32px;
  user-select: none;
}
.envelope-ctrl-left {
  display: flex; align-items: center; gap: 8px;
  color: var(--text-secondary);
}
.envelope-ctrl-left svg { color: var(--accent-warm-dim); flex-shrink: 0; }
.envelope-label {
  font-family: var(--font-display); font-size: 10px;
  font-weight: 600; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--text-secondary);
}
.envelope-hint {
  font-size: 10px; color: var(--text-tertiary);
  margin-left: 4px;
}
.envelope-ctrl-right {
  display: flex; align-items: center; gap: 12px;
  font-family: var(--font-mono); font-size: 11px;
}
.envelope-pos { color: var(--text-secondary); }
.envelope-db {
  color: var(--accent-warm); font-weight: 500; min-width: 48px; text-align: right;
}

/* Toggle switch (shared) */
.toggle-sw {
  width: 30px; height: 18px; border-radius: 9px;
  background: var(--border-strong); position: relative;
  cursor: pointer; transition: background 0.2s; flex-shrink: 0;
}
.toggle-sw.on { background: var(--accent-warm-dim); }
.toggle-sw::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 14px; height: 14px; border-radius: 50%;
  background: #fff; transition: transform 0.2s var(--ease-out-expo);
}
.toggle-sw.on::after { transform: translateX(12px); }

.timeline-toggle {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--text-secondary); cursor: pointer;
  font-family: var(--font-body);
}

/* Right panel: settings */
.settings-panel {
  width: 240px; min-width: 240px;
  background: var(--bg-deep);
  border-left: 1px solid var(--border-subtle);
  padding: 16px; display: flex; flex-direction: column;
  gap: 16px; overflow-y: auto;
  transition: background-color 0.35s ease;
}
.settings-section { }
.settings-label {
  font-family: var(--font-display); font-size: 10px; font-weight: 600;
  color: var(--text-tertiary); text-transform: uppercase;
  letter-spacing: 0.05em; margin-bottom: 6px;
}
.settings-select {
  width: 100%; padding: 6px 8px;
  background: var(--bg-surface); color: var(--text-primary);
  border: 1px solid var(--border-subtle); border-radius: var(--radius-sm);
  font-family: var(--font-mono); font-size: 12px;
  outline: none; cursor: pointer;
  transition: border-color 0.15s;
}
.settings-select:focus { border-color: var(--accent-warm-dim); }

.btn-primary {
  width: 100%; padding: 10px 16px;
  background: var(--accent-warm); color: #1a1a1a;
  border: none; border-radius: var(--radius-sm);
  font-family: var(--font-display); font-size: 13px;
  font-weight: 600; cursor: pointer;
  transition: all 0.15s;
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; filter: none; transform: none; }

/* Progress */
.progress-wrap {
  display: none; flex-direction: column; gap: 4px;
}
.progress-wrap.active { display: flex; }
.progress-bar {
  width: 100%; height: 4px; background: var(--bg-surface);
  border-radius: 2px; overflow: hidden;
}
.progress-fill {
  height: 100%; background: var(--accent-warm);
  border-radius: 2px; transition: width 0.2s linear;
}
.progress-label {
  font-family: var(--font-mono); font-size: 10px;
  color: var(--text-tertiary); text-align: right;
}

/* ═══ AI Tools Panel (slide-out from right) ═══ */
.ai-panel {
  position: fixed; top: 0; right: -360px;
  width: 340px; height: 100vh;
  background: var(--bg-base); z-index: 200;
  border-left: 1px solid var(--border-subtle);
  display: flex; flex-direction: column;
  transition: right 0.3s var(--ease-out-expo);
  box-shadow: -8px 0 30px rgba(0,0,0,0.4);
}
.ai-panel.open { right: 0; }
.ai-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-deep);
}
.ai-panel-title {
  font-family: var(--font-display); font-size: 13px;
  font-weight: 600; color: var(--text-primary);
  display: flex; align-items: center; gap: 8px;
}
.ai-panel-title svg { color: var(--accent-warm); }
.ai-panel-close {
  width: 26px; height: 26px; display: flex;
  align-items: center; justify-content: center;
  border-radius: var(--radius-sm); cursor: pointer;
  background: none; border: none; color: var(--text-tertiary);
  transition: all 0.15s;
}
.ai-panel-close:hover { color: var(--text-primary); background: var(--bg-hover); }
.ai-panel-body {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}

/* AI Card */
.ai-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.ai-card-hdr {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
}
.ai-card-title {
  font-family: var(--font-display); font-size: 12px;
  font-weight: 600; color: var(--text-primary);
}
.ai-card-body {
  padding: 14px;
  display: none;
}
.ai-card-body.open { display: block; }
.ai-slider-row {
  display: flex; justify-content: space-between;
  font-size: 11px; color: var(--text-secondary);
  margin-bottom: 6px;
}
.ai-val {
  font-family: var(--font-mono); font-size: 11px;
  color: var(--accent-warm); min-width: 36px; text-align: right;
}
.ai-slider {
  width: 100%; height: 4px; -webkit-appearance: none;
  appearance: none; background: var(--bg-hover);
  border-radius: 2px; outline: none; cursor: pointer;
  margin-bottom: 8px;
}
.ai-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px;
  border-radius: 50%; background: var(--accent-warm);
  border: 2px solid var(--bg-surface); cursor: pointer;
}
.ai-hint {
  font-size: 10px; color: var(--text-tertiary);
  line-height: 1.5; margin-top: 4px;
}

/* EQ bands */
.eq-bands {
  display: flex; justify-content: space-around;
  align-items: flex-end; gap: 12px;
  height: 160px; padding: 0 8px;
}
.eq-band {
  display: flex; flex-direction: column;
  align-items: center; gap: 6px; flex: 1;
}
.eq-band-label {
  font-size: 10px; color: var(--text-tertiary);
  text-align: center; line-height: 1.4;
}
.ai-slider.vertical {
  width: 120px; height: 4px;
  -webkit-appearance: none; appearance: none;
  transform: rotate(-90deg);
  transform-origin: center center;
  margin: 50px -44px;
}
.ai-slider.vertical::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px;
  border-radius: 50%; background: var(--accent-warm);
  border: 2px solid var(--bg-surface); cursor: pointer;
}

/* AI status indicator */
.ai-status {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font-size: 11px; color: var(--text-secondary);
}
.ai-status-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-tertiary); flex-shrink: 0;
}
.ai-status-dot.active { background: var(--accent-warm); }
.ai-status-text { flex: 1; }

/* Output notification */
.output-toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--bg-elevated); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md); padding: 14px 18px;
  display: none; align-items: center; gap: 10px;
  box-shadow: var(--window-shadow);
  z-index: 100;
}
.output-toast.show { display: flex; }
.output-toast .check {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--green); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; flex-shrink: 0;
}
.output-toast .info { font-size: 12px; line-height: 1.5; }
.output-toast .info strong { font-weight: 500; }

/* Utility */
.hidden { display: none !important; }
