/* ============================================
   流光数图 SparkMotion — 全局样式
   配色：深蓝 + 霓虹青 / 暗色编辑器风格
   ============================================ */

/* --- CSS Variables --- */
:root {
  --color-bg:           #0f1117;
  --color-surface:      #1a1d27;
  --color-surface-2:    #232733;
  --color-border:       #2e3345;
  --color-text:         #e1e4ed;
  --color-text-muted:   #8389a3;
  --color-primary:      #5b8def;
  --color-primary-dim:  #3d5fa8;
  --color-accent:       #34d399;
  --color-accent-dim:   #1f7a56;
  --color-danger:       #f87171;
  --color-warning:      #fbbf24;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,.5);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.6);

  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  --font-sans:  'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;

  --sidebar-w: 240px;
  --propside-w: 320px;
  --topbar-h:   48px;
  --timeline-h: 180px;

  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
}

/* --- Reset --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  outline: none;
  transition: border-color var(--transition-fast);
}
input:focus, textarea:focus, select:focus {
  border-color: var(--color-primary);
}

/* --- Utility Classes --- */
.flex       { display: flex; }
.flex-col   { display: flex; flex-direction: column; }
.flex-1     { flex: 1; }
.flex-center{ display: flex; align-items: center; justify-content: center; }
.gap-4      { gap: 4px; }
.gap-8      { gap: 8px; }
.gap-12     { gap: 12px; }
.gap-16     { gap: 16px; }
.p-8        { padding: 8px; }
.p-12       { padding: 12px; }
.p-16       { padding: 16px; }
.p-24       { padding: 24px; }
.hidden     { display: none !important; }
.truncate   { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-text-muted); }

/* --- Layout --- */
#app { height: 100%; }

/* Top Bar */
.topbar {
  height: var(--topbar-h);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  z-index: 100;
  position: relative;
}
.topbar-logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-accent);
  letter-spacing: -0.3px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar-logo .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--color-accent);
  animation: pulse-dot 2s infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.5); }
}
.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Button styles */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition-fast);
  white-space: nowrap;
}
.btn-primary {
  background: var(--color-primary);
  color: #fff;
}
.btn-primary:hover { background: #4a7de0; }
.btn-accent {
  background: var(--color-accent);
  color: #000;
}
.btn-accent:hover { background: #2ec48a; }
.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
}
.btn-ghost:hover { background: var(--color-surface-2); color: var(--color-text); }
.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { background: #e05858; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-lg { padding: 10px 24px; font-size: 15px; }

/* Dialog / Modal */
.dialog-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 500;
}
.dialog {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  min-width: 360px;
  max-width: 90vw;
  box-shadow: var(--shadow-lg);
}
.dialog h3 { margin-bottom: 16px; font-size: 16px; }
.dialog-footer { margin-top: 20px; display: flex; justify-content: flex-end; gap: 8px; }

/* Card */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 16px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.card:hover {
  border-color: var(--color-primary-dim);
  box-shadow: var(--shadow-md);
}

/* --- Home Page --- */
.home-page {
  height: calc(100% - var(--topbar-h));
  overflow-y: auto;
  padding: 40px;
}
.home-hero {
  text-align: center;
  padding: 60px 0 40px;
}
.home-hero h1 {
  font-size: 36px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--color-accent), var(--color-primary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 12px;
}
.home-hero p {
  color: var(--color-text-muted);
  font-size: 16px;
}
.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-top: 32px;
}
.project-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  transition: all var(--transition-normal);
}
.project-card:hover {
  border-color: var(--color-primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.project-card-thumb {
  height: 140px;
  background: var(--color-surface-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 40px;
  color: var(--color-text-muted);
}
.project-card-body {
  padding: 12px 16px;
}
.project-card-body h4 {
  font-size: 14px; font-weight: 600; margin-bottom: 4px;
}
.project-card-body .meta {
  font-size: 11px; color: var(--color-text-muted);
}
.project-card-menu {
  position: absolute;
  top: 8px; right: 8px;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  color: var(--color-text-muted);
  font-size: 16px;
  opacity: 0;
  transition: opacity var(--transition-fast);
}
.project-card:hover .project-card-menu { opacity: 1; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--color-text-muted);
}
.empty-state .icon { font-size: 64px; margin-bottom: 16px; }
.empty-state h3 { font-size: 18px; color: var(--color-text); margin-bottom: 8px; }

/* --- Editor Layout --- */
.editor-page {
  height: calc(100% - var(--topbar-h));
  display: flex;
  flex-direction: column;
}
.editor-main {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* Sidebar (layer panel) */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.sidebar-header {
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
  display: flex; align-items: center; justify-content: space-between;
}

/* Layer item */
.layer-item {
  display: flex; align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background var(--transition-fast);
}
.layer-item:hover { background: var(--color-surface-2); }
.layer-item.selected {
  background: var(--color-surface-2);
  border-left-color: var(--color-primary);
}
.layer-item .layer-icon {
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.layer-item .layer-name {
  flex: 1;
  font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.layer-item .layer-vis {
  width: 20px; height: 20px;
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  color: var(--color-text-muted);
  font-size: 14px;
}

/* Canvas */
.canvas-area {
  flex: 1;
  background: var(--color-bg);
  display: flex; align-items: center; justify-content: center;
  position: relative;
  overflow: hidden;
}
.canvas-stage {
  position: relative;
  background: #fff;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.canvas-layer {
  position: absolute;
  overflow: hidden;
}

/* Property Panel */
.propside {
  width: var(--propside-w);
  min-width: var(--propside-w);
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.propside-header {
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
}
.propside-section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
}
.propside-section h4 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-muted);
  margin-bottom: 10px;
}
.form-group { margin-bottom: 10px; }
.form-group:last-child { margin-bottom: 0; }
.form-group label {
  display: block;
  font-size: 12px;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}
.form-group input,
.form-group select {
  width: 100%;
}

/* --- Data Grid --- */
.data-grid-wrapper {
  overflow: auto;
  max-height: 300px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}
.data-grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.data-grid th, .data-grid td {
  border: 1px solid var(--color-border);
  padding: 4px 8px;
  min-width: 80px;
  text-align: left;
}
.data-grid th {
  background: var(--color-surface-2);
  font-weight: 600;
  position: sticky; top: 0;
}
.data-grid td {
  background: var(--color-surface);
}
.data-grid td[contenteditable="true"]:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
}

/* --- Timeline --- */
.timeline {
  height: var(--timeline-h);
  min-height: var(--timeline-h);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex; flex-direction: column;
}
.timeline-toolbar {
  height: 32px;
  display: flex; align-items: center;
  padding: 0 12px;
  gap: 8px;
  border-bottom: 1px solid var(--color-border);
}
.timeline-canvas-wrap {
  flex: 1;
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
}
.timeline-canvas {
  display: block;
}

/* --- Preview page --- */
.preview-page {
  height: calc(100% - var(--topbar-h));
  display: flex; align-items: center; justify-content: center;
  background: #000;
}
.preview-page .canvas-stage {
  box-shadow: none;
}

/* --- Export page --- */
.export-page {
  height: calc(100% - var(--topbar-h));
  overflow-y: auto;
  padding: 40px;
  max-width: 600px;
  margin: 0 auto;
}

/* --- AI Panel --- */
.ai-panel {
  border-top: 1px solid var(--color-border);
  padding: 12px 16px;
}
.ai-panel textarea {
  width: 100%;
  min-height: 60px;
  resize: vertical;
}
.ai-response {
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--color-surface-2);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--color-accent);
  white-space: pre-wrap;
}

/* --- Templates page --- */
.template-market {
  height: calc(100% - var(--topbar-h));
  overflow-y: auto;
  padding: 40px;
}

/* --- Toast --- */
.toast-container {
  position: fixed;
  top: 56px;
  right: 16px;
  z-index: 1000;
  display: flex; flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  font-size: 13px;
  box-shadow: var(--shadow-md);
  animation: toast-in .3s ease;
  max-width: 320px;
}
.toast.success { border-color: var(--color-accent); }
.toast.error   { border-color: var(--color-danger); }
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

/* --- Inline color swatches --- */
.color-swatch {
  display: inline-block;
  width: 16px; height: 16px;
  border-radius: 4px;
  vertical-align: middle;
  margin-right: 6px;
  border: 1px solid var(--color-border);
}
