/* ── Image Generation Flow Editor (Drawflow) ── */

/* Helpers extracted from inline cssText (shared with imagegen-pipeline/-app/-nodes) */
.igen-thumb { width:100%; max-height:240px; object-fit:contain; border-radius:6px; display:block; }
.igen-thumb-220 { width:100%; max-height:220px; object-fit:contain; border-radius:6px; display:block; }
.igen-thumb-label { font-size:10px; color:#888; margin-top:4px; text-align:center; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.igen-thumb-label-3 { font-size:10px; color:#888; margin-top:3px; text-align:center; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.igen-result { max-width:100%; max-height:200px; border-radius:4px; display:block; margin:0 auto; }
.igen-svg-16 { width:16px; height:16px; }
.igen-canvas-fill { width:100%; height:100%; position:absolute; top:0; left:0; }
.igen-port-dot { width:8px; height:8px; border-radius:50%; display:inline-block; margin-right:8px; }

/* ═══════════════════════════════════════════════════════════
   Imagegen app — Generate + Gallery tabs (Phase 1 step 12)
   Tokens only; view toggle = OscarUI.iconButton, menu = OscarUI.menu.
   ═══════════════════════════════════════════════════════════ */

/* ── Shared toolbar (gallery search + view toggle) ───────────── */
.ig-toolbar {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  margin-bottom: var(--space-2);
}
.ig-toolbar .ou-search { flex: 1; }

/* View toggle chips — OscarUI.iconButton, sized to match the file app */
.ig-view-toggle {
  display: flex;
  gap: var(--space-1);
  flex-shrink: 0;
}
.ig-view-btn.ou-icon-btn { width: 28px; height: 24px; }
.ig-view-btn.ou-icon-btn svg { width: 14px; height: 14px; }

/* ── Generate tab ────────────────────────────────────────────── */
.ig-hint {
  font-size: var(--fs-sm);
  color: var(--text-dim);
  margin-bottom: var(--space-2);
}
.ig-prompt-input {
  min-height: 120px;
  resize: vertical;
}
.ig-attachments {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-bottom: var(--space-2);
}
.ig-attach {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}
.ig-attach img { width: 100%; height: 100%; object-fit: cover; }
.ig-attach-file {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-size: var(--fs-xs);
  color: var(--text-dim);
  text-align: center;
  padding: var(--space-1);
  word-break: break-all;
}
.ig-attach-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: var(--radius-pill);
  border: none;
  background: var(--overlay-3);
  color: var(--text);
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ig-attach-remove svg { width: 12px; height: 12px; }
.ig-attach-remove:hover { background: var(--border-strong); }
.ig-dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  margin-bottom: var(--space-2);
}
.ig-dropzone.ig-dragover {
  border-color: var(--accent);
  background: var(--overlay-1);
}
.ig-dropzone-label { font-size: var(--fs-md); color: var(--text-dim); }
.ig-dropzone-sub {
  font-size: var(--fs-xs);
  color: var(--text-faint);
  margin-top: var(--space-1);
}
.ig-btn-row { padding: var(--space-2) 0; display: flex; gap: var(--space-2); }
.ig-status {
  padding: var(--space-2) 0;
  font-size: var(--fs-md);
  color: var(--text-dim);
}
.ig-preview {
  margin-top: var(--space-3);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
}
.ig-preview img {
  width: 100%;
  max-height: 300px;
  object-fit: contain;
  display: block;
  background: var(--bg);
}
.ig-preview-info {
  padding: var(--space-2);
  font-size: var(--fs-sm);
  color: var(--text-dim);
}

/* ── Gallery: grid view ──────────────────────────────────────── */
.ig-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--space-3);
  padding: 0 0 var(--space-4);
}
.ig-card {
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
}
.ig-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-1);
}
.ig-card-thumb {
  width: 100%;
  padding-bottom: 100%;
  position: relative;
  background: var(--bg);
}
.ig-card-thumb img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.ig-dots-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 28px;
  height: 28px;
  border-radius: var(--radius);
  background: var(--overlay-3);
  border: none;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
  padding: 0;
}
.ig-dots-btn svg { width: 16px; height: 16px; }
.ig-card:hover .ig-dots-btn { opacity: 1; }
.ig-card-info {
  padding: var(--space-2);
  font-size: var(--fs-xs);
  color: var(--text-dim);
}
.ig-card-name {
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ig-card-meta { margin-top: 2px; }
.ig-card-tags {
  margin-top: var(--space-1);
  display: flex;
  gap: var(--space-1);
  flex-wrap: wrap;
}
.ig-card-prompt {
  margin-top: var(--space-1);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-style: italic;
}
.ig-mini-tag {
  font-size: 9px;
  padding: 1px 5px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--c, var(--border));
  color: var(--c, var(--text-dim));
  white-space: nowrap;
}

/* ── Gallery: list view ──────────────────────────────────────── */
.ig-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.ig-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  background: var(--surface);
  border-radius: var(--radius);
  cursor: pointer;
  position: relative;
  transition: background 0.15s;
}
.ig-row:hover { background: var(--overlay-1); }
.ig-row-thumb {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg);
}
.ig-row-info { flex: 1; min-width: 0; font-size: var(--fs-sm); }
.ig-row-name {
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ig-row-meta {
  color: var(--text-dim);
  margin-top: 2px;
  font-size: var(--fs-xs);
}
.ig-row-prompt {
  color: var(--text-dim);
  margin-top: 2px;
  font-size: var(--fs-xs);
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ig-row .ig-dots-btn {
  position: static;
  width: 32px;
  height: 32px;
  background: none;
  color: var(--text-dim);
  opacity: 1;
  flex-shrink: 0;
}
.ig-row .ig-dots-btn:hover { background: var(--overlay-2); color: var(--text); }

/* ── Image detail modal ──────────────────────────────────────── */
.ig-detail-img-wrap {
  width: 100%;
  max-height: 400px;
  overflow: hidden;
  display: flex;
  justify-content: center;
  background: var(--bg);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-3);
}
.ig-detail-img-wrap img { max-width: 100%; max-height: 400px; object-fit: contain; }
.ig-detail-section {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
}
.ig-detail-label {
  font-size: var(--fs-xs);
  color: var(--text-dim);
  margin-bottom: var(--space-1);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.ig-detail-label + .ig-detail-label { margin-top: var(--space-2); }
.ig-detail-textarea {
  width: 100%;
  min-height: 80px;
  padding: var(--space-2);
  font-size: var(--fs-md);
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  resize: vertical;
  line-height: 1.5;
  box-sizing: border-box;
}
.ig-detail-input {
  width: 100%;
  padding: var(--space-1) var(--space-2);
  font-size: var(--fs-md);
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-sizing: border-box;
}
.ig-detail-save-row { margin-top: var(--space-2); display: flex; gap: var(--space-2); }
.ig-detail-actions {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* Canvas */
.igf-canvas {
  flex: 1;
  min-height: 400px;
  background: #1a1a2e;
  position: relative;
}
.igf-canvas .drawflow {
  width: 100%;
  height: 100%;
}

/* Toolbar */
.igf-toolbar {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  align-items: center;
  flex-wrap: wrap;
  background: var(--surface);
}
.igf-hint {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}

/* Add node dropdown */
.igf-add-wrap {
  position: relative;
}
.igf-add-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 100;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 0;
  min-width: 160px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.igf-add-menu button {
  display: block;
  width: 100%;
  padding: 8px 16px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}
.igf-add-menu button:hover {
  background: rgba(255,255,255,.06);
}

/* ── Drawflow overrides ── */
.drawflow .drawflow-node {
  background: #2a2a3a;
  border: 1px solid #444;
  border-radius: 10px;
  min-width: 220px;
  color: #eee;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0,0,0,.3);
}
.drawflow .drawflow-node.selected {
  border-color: var(--accent, #3b7dd8);
  box-shadow: 0 0 0 2px var(--accent, #3b7dd8), 0 4px 16px rgba(0,0,0,.4);
}
.drawflow .drawflow-node .drawflow_content_node {
  padding: 0;
}

/* Connection lines */
.drawflow .connection .main-path {
  stroke: #5a6a7a;
  stroke-width: 2px;
}
.drawflow .connection .main-path:hover,
.drawflow .connection.selected .main-path {
  stroke: var(--accent, #3b7dd8);
  stroke-width: 3px;
}

/* Input/output dots */
.drawflow .drawflow-node .input,
.drawflow .drawflow-node .output {
  width: 14px;
  height: 14px;
  border: 2px solid #666;
  background: #333;
  border-radius: 50%;
}
.drawflow .drawflow-node .input:hover,
.drawflow .drawflow-node .output:hover {
  border-color: var(--accent, #3b7dd8);
  background: var(--accent, #3b7dd8);
}

/* ── Node type styles ── */
.igf-node {
  padding: 12px;
}
.igf-node-title {
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}

/* Prompt node */
.igf-type-prompt .drawflow_content_node { border-left: 3px solid #4ecdc4; }
.igf-prompt textarea {
  width: 100%;
  min-height: 60px;
  background: #1a1a2a;
  border: 1px solid #444;
  border-radius: 6px;
  color: #eee;
  padding: 8px;
  font-size: 12px;
  resize: vertical;
  font-family: inherit;
  line-height: 1.4;
  box-sizing: border-box;
}
.igf-prompt textarea:focus {
  border-color: #4ecdc4;
  outline: none;
}

/* Image Input node */
.igf-type-imageInput .drawflow_content_node { border-left: 3px solid #45b7d1; }
.igf-upload-zone {
  padding: 20px 12px;
  border: 2px dashed #444;
  border-radius: 6px;
  text-align: center;
  color: #888;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.igf-upload-zone:hover,
.igf-upload-zone.igf-dragover {
  border-color: #45b7d1;
  background: rgba(69,183,209,.08);
}
.igf-thumb {
  width: 100%;
  max-height: 120px;
  object-fit: contain;
  border-radius: 6px;
  margin-top: 8px;
}

/* Image Gen node — all-in-one Krea-style */
.igf-type-imageGen .drawflow_content_node { border-left: 3px solid #a855f7; }
.igf-type-imageGen { min-width: 260px; }

/* Generated image preview at top of node */
.igf-gen-preview {
  background: #151525;
  border-radius: 6px;
  min-height: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #555;
  font-size: 11px;
  overflow: hidden;
  margin-bottom: 8px;
}
.igf-gen-preview img {
  width: 100%;
  max-height: 240px;
  object-fit: contain;
  border-radius: 6px;
  display: block;
}

/* Built-in prompt textarea */
.igf-gen-prompt {
  width: 100%;
  min-height: 50px;
  background: #1a1a2a;
  border: 1px solid #444;
  border-radius: 6px;
  color: #eee;
  padding: 8px;
  font-size: 12px;
  resize: vertical;
  font-family: inherit;
  line-height: 1.4;
  box-sizing: border-box;
  margin-bottom: 6px;
}
.igf-gen-prompt:focus { border-color: #a855f7; outline: none; }

/* Field rows */
.igf-field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
}
.igf-field span {
  font-size: 11px;
  color: #888;
  white-space: nowrap;
  min-width: 40px;
}
.igf-field select {
  flex: 1;
  background: #1a1a2a;
  border: 1px solid #444;
  border-radius: 4px;
  color: #eee;
  padding: 4px 6px;
  font-size: 11px;
  font-family: inherit;
  min-width: 0;
}
.igf-field select:focus { border-color: #a855f7; outline: none; }

/* Collapsible settings */
.igf-settings-toggle {
  font-size: 11px;
  color: #888;
  cursor: pointer;
  padding: 4px 0;
  user-select: none;
  border-top: 1px solid rgba(255,255,255,.06);
  margin-top: 4px;
}
.igf-settings-toggle:hover { color: #bbb; }
.igf-settings-body {
  padding-top: 6px;
}

/* Status indicator */
.igf-status {
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  text-align: center;
  min-height: 16px;
  margin-bottom: 6px;
}
.igf-status:empty { display: none; }
.igf-status-running { background: rgba(255,204,0,.15); color: #ffcc00; }
.igf-status-done { background: rgba(0,204,102,.15); color: #00cc66; }
.igf-status-error { background: rgba(255,68,68,.15); color: #ff4444; }

/* Preview node */
.igf-type-preview .drawflow_content_node { border-left: 3px solid #f97316; }
.igf-preview-area {
  min-height: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #666;
  font-size: 12px;
  background: #1a1a2a;
  border-radius: 6px;
  padding: 8px;
  overflow: hidden;
}
.igf-preview-area img {
  max-width: 100%;
  max-height: 200px;
  border-radius: 4px;
}

/* Text Combine node */
.igf-type-textCombine .drawflow_content_node { border-left: 3px solid #eab308; }
.igf-text-combine label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: #aaa;
}
.igf-text-combine input {
  flex: 1;
  background: #1a1a2a;
  border: 1px solid #444;
  border-radius: 4px;
  color: #eee;
  padding: 4px 6px;
  font-size: 12px;
  font-family: inherit;
}

/* ── Drawflow background grid ── */
.drawflow {
  background: #1a1a2e;
  background-image:
    linear-gradient(rgba(255,255,255,.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.03) 1px, transparent 1px);
  background-size: 20px 20px;
}

/* ── Delete button on nodes ── */
.drawflow .drawflow-delete {
  background: #ff4444;
  color: white;
  border: none;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  top: -8px;
  right: -8px;
}
