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

:root {
  --bg: #0b0d12;
  --bg2: #12151e;
  --bg3: #1a1e2e;
  --bg4: #232840;
  --border: #2a2f45;
  --text: #e4e6f2;
  --text2: #8b91ab;
  --text3: #585e78;
  --accent: #6c8aff;
  --accent2: #4a68f0;
  --accent-glow: rgba(108, 138, 255, 0.15);
  --green: #3dd68c;
  --red: #f06292;
  --yellow: #ffca62;
  --orange: #ff8c5a;
  --purple: #b48eff;
  --cyan: #56d4e0;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.5);
  --max-w: 960px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: rgba(11, 13, 18, 0.85);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
}
.logo-icon { font-size: 20px; }
.logo-text { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }

.nav-links { display: flex; gap: 4px; }
.nav-link {
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  color: var(--text2);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: all 0.15s;
}
.nav-link:hover { background: var(--bg3); color: var(--text); }
.nav-link.active { background: var(--accent-glow); color: var(--accent); }

/* Main content */
#app {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 32px 24px 80px;
}

/* Hero heading */
.hero { text-align: center; margin-bottom: 36px; }
.hero h1 {
  font-size: 28px;
  font-weight: 800;
  line-height: 1.25;
  background: linear-gradient(135deg, var(--accent) 0%, var(--purple) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}
.hero p { color: var(--text2); font-size: 15px; max-width: 520px; margin: 0 auto; }

/* Generator form */
.gen-form { margin-bottom: 28px; }
.textarea-wrap { position: relative; margin-bottom: 12px; }
.gen-textarea {
  width: 100%;
  min-height: 100px;
  padding: 16px 18px;
  padding-bottom: 32px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
}
.gen-textarea:focus { border-color: var(--accent); }
.gen-textarea::placeholder { color: var(--text3); }
.char-count {
  position: absolute;
  bottom: 10px;
  right: 14px;
  font-size: 11px;
  color: var(--text3);
}

.gen-actions { display: flex; gap: 10px; align-items: center; }

/* Inspiration chips */
.chips-section { margin-bottom: 28px; }
.chips-label { font-size: 12px; color: var(--text3); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 10px; }
.chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  display: inline-block;
  padding: 6px 14px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text2);
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip:hover { background: var(--bg4); color: var(--text); border-color: var(--accent); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
  font-family: inherit;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent2); }
.btn-primary:hover:not(:disabled) { background: var(--accent2); }
.btn-secondary { background: var(--bg3); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg4); }
.btn-ghost { background: transparent; color: var(--text2); }
.btn-ghost:hover:not(:disabled) { background: var(--bg3); color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-green { background: rgba(61,214,140,0.15); color: var(--green); border-color: rgba(61,214,140,0.25); }
.btn-green:hover:not(:disabled) { background: rgba(61,214,140,0.25); }

/* Spinner */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Result panel */
.result-panel {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-top: 24px;
  animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.result-title { font-size: 18px; font-weight: 700; margin-bottom: 16px; }

/* Flow diagram */
.flow-canvas-wrap {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 20px;
  margin-bottom: 20px;
  overflow-x: auto;
}
.flow-diagram {
  display: flex;
  align-items: center;
  gap: 0;
  min-height: 80px;
}
.flow-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 120px;
  flex-shrink: 0;
}
.flow-node-box {
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  border: 1.5px solid;
  text-align: center;
  min-width: 110px;
  max-width: 180px;
}
.flow-node-name { font-size: 12.5px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.flow-node-type { font-size: 10.5px; color: var(--text3); margin-top: 2px; }
.flow-arrow {
  font-size: 20px;
  color: var(--text3);
  flex-shrink: 0;
  padding: 0 4px;
}

/* Node colors by category */
.flow-node-trigger .flow-node-box { background: rgba(61,214,140,0.1); border-color: rgba(61,214,140,0.4); }
.flow-node-action .flow-node-box { background: rgba(108,138,255,0.1); border-color: rgba(108,138,255,0.4); }
.flow-node-utility .flow-node-box { background: rgba(180,142,255,0.1); border-color: rgba(180,142,255,0.4); }

/* Node list */
.node-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.node-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 16px;
  font-size: 12px;
  color: var(--text2);
}
.node-tag-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}
.dot-trigger { background: var(--green); }
.dot-action { background: var(--accent); }
.dot-utility { background: var(--purple); }

/* Action row */
.action-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

/* Share section */
.share-section {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.share-url {
  flex: 1;
  padding: 7px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-size: 13px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.share-hint { font-size: 12px; color: var(--text3); margin-top: 8px; }

/* JSON accordion */
.json-accordion { margin-top: 8px; }
.json-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--text2);
  font-size: 13px;
  cursor: pointer;
  padding: 6px 0;
  font-family: inherit;
}
.json-toggle:hover { color: var(--text); }
.json-body {
  margin-top: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  max-height: 400px;
  overflow: auto;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
  display: none;
}
.json-body.open { display: block; }

/* JSON syntax highlighting */
.json-key { color: var(--accent); }
.json-str { color: var(--green); }
.json-num { color: var(--orange); }
.json-bool { color: var(--purple); }
.json-null { color: var(--text3); }

/* Gallery */
.gallery-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.gallery-title { font-size: 22px; font-weight: 700; }
.gallery-count { color: var(--text3); font-size: 13px; }

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}
@media (max-width: 640px) {
  .gallery-grid { grid-template-columns: 1fr; }
}

.gallery-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  color: inherit;
  display: block;
}
.gallery-card:hover {
  border-color: var(--accent);
  background: var(--bg3);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.card-desc {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 12px;
}
.card-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.card-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  background: var(--accent-glow);
  color: var(--accent);
}
.card-time { font-size: 11px; color: var(--text3); }
.card-types {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.card-type-tag {
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 10px;
  background: var(--bg4);
  color: var(--text3);
}

/* Shared workflow view */
.shared-view { animation: fadeIn 0.3s ease; }
.shared-quote {
  background: var(--bg3);
  border-left: 3px solid var(--accent);
  padding: 16px 20px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-bottom: 24px;
  font-size: 16px;
  color: var(--text);
  font-style: italic;
  line-height: 1.6;
}
.shared-footer {
  text-align: center;
  padding: 24px 0;
  color: var(--text3);
  font-size: 13px;
  border-top: 1px solid var(--border);
  margin-top: 32px;
}
.shared-footer a { color: var(--accent); text-decoration: none; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text2);
}
.empty-icon { font-size: 40px; opacity: 0.4; margin-bottom: 12px; }
.empty-state h3 { font-size: 16px; margin-bottom: 6px; color: var(--text); }
.empty-state p { font-size: 13px; max-width: 320px; margin: 0 auto; }

/* Error */
.error-box {
  background: rgba(240,98,146,0.1);
  border: 1px solid rgba(240,98,146,0.3);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  color: var(--red);
  font-size: 13px;
  margin-top: 16px;
}

/* Toast */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toast {
  background: var(--bg4);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 13px;
  max-width: 340px;
  box-shadow: var(--shadow);
  animation: slideIn 0.2s ease;
}
.toast-success { border-left: 3px solid var(--green); }
.toast-error { border-left: 3px solid var(--red); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Loading bar */
.loading-bar {
  width: 100%;
  height: 3px;
  background: var(--bg3);
  border-radius: 2px;
  overflow: hidden;
  margin: 20px 0;
}
.loading-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--purple));
  border-radius: 2px;
  animation: loadPulse 1.5s ease-in-out infinite;
  width: 40%;
}
@keyframes loadPulse {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 28px;
}

/* Toggle switch */
.toggle-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.toggle-track {
  width: 36px;
  height: 20px;
  border-radius: 10px;
  background: var(--bg4);
  border: 1px solid var(--border);
  position: relative;
  transition: all 0.2s;
}
.toggle-track.on { background: var(--accent-glow); border-color: var(--accent); }
.toggle-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text3);
  position: absolute;
  top: 2px;
  left: 2px;
  transition: all 0.2s;
}
.toggle-track.on .toggle-thumb { left: 18px; background: var(--accent); }
.toggle-label { font-size: 13px; color: var(--text2); }

/* Back link */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text2);
  text-decoration: none;
  font-size: 13px;
  margin-bottom: 16px;
}
.back-link:hover { color: var(--accent); }

/* Responsive */
@media (max-width: 640px) {
  .topbar { padding: 0 16px; }
  #app { padding: 20px 16px 60px; }
  .hero h1 { font-size: 22px; }
  .result-panel { padding: 16px; }
  .flow-canvas-wrap { padding: 12px; }
  .action-row { flex-direction: column; }
}
