:root {
  --bg: #0c0e13;
  --surface: #181b22;
  --surface-2: #232831;
  --surface-3: #2a3140;
  --border: #2e333d;
  --border-strong: #3a4150;
  --text: #ebeef4;
  --text-dim: #c2c8d4;
  --muted: #8b94a3;
  --accent: #6aa9ff;
  --accent-hover: #87bbff;
  --accent-soft: rgba(106,169,255,0.12);
  --success: #5fce8a;
  --warn: #f0b450;
  --error: #ff6b6b;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

code { background: var(--surface-2); padding: 1px 6px; border-radius: 4px; font-size: 0.9em; font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; }

/* ============================== Header ============================== */

.page-header {
  max-width: 980px;
  margin: 0 auto;
  padding: 36px 22px 4px;
}
.page-header h1 {
  margin: 0 0 6px;
  font-size: 1.8rem;
  letter-spacing: -0.01em;
}
.subtitle {
  margin: 0 0 14px;
  color: var(--text-dim);
  font-size: 0.97rem;
}
.preset-banner {
  display: inline-block;
  background: var(--surface);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 0.82rem;
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
}

/* ============================== Pipeline ============================== */

.pipeline {
  max-width: 980px;
  margin: 0 auto;
  padding: 16px 22px 80px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ============================== Step ============================== */

.step {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 1px 0 rgba(255,255,255,0.02), 0 8px 24px rgba(0,0,0,0.18);
}

.step-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  background: linear-gradient(180deg, rgba(255,255,255,0.02), transparent);
  border-bottom: 1px solid var(--border);
}

.step-num {
  width: 34px; height: 34px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 1.05rem;
  border: 1px solid rgba(106,169,255,0.3);
}

.step-title-wrap { flex: 1; min-width: 0; }
.step-title-wrap h2 {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: -0.01em;
}
.step-sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.optional-badge {
  display: inline-block;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 0.7rem;
  padding: 1px 7px;
  border-radius: 4px;
  margin-left: 6px;
  font-weight: 500;
  vertical-align: middle;
}

.step-status {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  text-transform: lowercase;
  letter-spacing: 0.02em;
}
.step-status[data-status="idle"] {
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
}
.step-status[data-status="busy"] {
  background: rgba(240, 180, 80, 0.12);
  color: var(--warn);
  border: 1px solid rgba(240, 180, 80, 0.3);
}
.step-status[data-status="done"] {
  background: rgba(95, 206, 138, 0.12);
  color: var(--success);
  border: 1px solid rgba(95, 206, 138, 0.3);
}

.step-body { padding: 18px; }

/* ============================== Sub-tabs (modos) ============================== */

.step-tabs {
  display: flex;
  gap: 4px;
  margin: -4px 0 16px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.step-tab {
  flex: 1;
  background: transparent;
  color: var(--muted);
  border: 0;
  padding: 8px 12px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 500;
  font-family: inherit;
}
.step-tab:hover { color: var(--text); }
.step-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.step-info {
  padding: 10px 14px;
  background: var(--surface-2);
  border-left: 3px solid var(--border-strong);
  border-radius: 4px;
  color: var(--text-dim);
  font-size: 0.88rem;
  margin: 0 0 14px;
}

.step-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}

/* ============================== Form fields ============================== */

.row { margin-bottom: 14px; }
.row:last-child { margin-bottom: 0; }
.row.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

label {
  display: block;
  font-size: 0.88rem;
  color: var(--muted);
}
label > span { display: block; margin-bottom: 6px; }

input[type="number"],
input[type="text"],
textarea,
select {
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 0.95rem;
  font-family: inherit;
}
textarea { resize: vertical; }

/* Custom file input styling */
input[type="file"] {
  width: 100%;
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
  padding: 14px;
  font-size: 0.92rem;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
input[type="file"]:hover {
  border-color: var(--accent);
  background: var(--surface-3);
  color: var(--text);
}
input[type="file"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}
input[type="file"]::file-selector-button {
  background: var(--accent);
  color: #0b1220;
  border: 0;
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  margin-right: 12px;
  transition: background 0.15s ease;
}
input[type="file"]::file-selector-button:hover {
  background: var(--accent-hover);
}

input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  border-color: transparent;
}

.preview { margin-top: 10px; }
.preview img { max-width: 240px; max-height: 180px; border-radius: 8px; border: 1px solid var(--border); display: block; }

/* ============================== Buttons ============================== */

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.92rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s;
}
button:hover, .btn:hover {
  background: var(--surface-3);
  border-color: var(--border-strong);
}
button:active, .btn:active { transform: translateY(1px); }
button:disabled, .btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

button.primary, .btn.primary {
  background: var(--accent);
  color: #0b1220;
  border-color: var(--accent);
  font-weight: 600;
}
button.primary:hover, .btn.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
button.small, .btn.small { padding: 5px 10px; font-size: 0.82rem; }

/* ============================== Advanced collapsible ============================== */

.adv-prompts {
  margin: 14px 0;
  border-top: 1px dashed var(--border);
  padding-top: 12px;
}
.adv-prompts > summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.86rem;
  padding: 4px 0;
  user-select: none;
}
.adv-prompts > summary:hover { color: var(--text); }
.adv-prompts textarea {
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 0.82rem;
  line-height: 1.45;
}

/* ============================== Result ============================== */

.step-result {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.step-result h3 {
  margin: 0 0 12px;
  font-size: 0.92rem;
  color: var(--muted);
  font-weight: 500;
}
.result-grid {
  display: grid;
  grid-template-columns: minmax(200px, 280px) 1fr;
  gap: 16px;
  align-items: start;
}
.result-grid-pair {
  grid-template-columns: 1fr 1fr;
}
.result-grid-pair .result-item {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.result-thumb { aspect-ratio: 1 / 1; }
.result-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
}
.result-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 12px;
}

/* ============================== Thumbs ============================== */

.thumb {
  background-color: #2a2f38;
  background-image:
    linear-gradient(45deg, #3a414d 25%, transparent 25%),
    linear-gradient(-45deg, #3a414d 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #3a414d 75%),
    linear-gradient(-45deg, transparent 75%, #3a414d 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  cursor: zoom-in;
}
.thumb img { max-width: 100%; max-height: 100%; display: block; }

.svg-thumb {
  background-color: #fafafa;
  background-image: none;
  cursor: default;
  padding: 12px;
}
.svg-thumb svg { display: block; }

/* ============================== References (locales / subidas) ============================== */

.local-refs-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 8px;
}
.local-refs-header .label { font-size: 0.88rem; color: var(--muted); }
.local-refs-hint {
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--muted);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  word-break: break-all;
}

.upload-action {
  display: flex; align-items: center; gap: 10px; margin-top: 6px;
}
.upload-hint { color: var(--muted); font-size: 0.88rem; }
.field-label { display: block; margin-bottom: 4px; font-size: 0.92rem; color: var(--muted); }
.refs-preview {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 10px;
}
.ref-thumb {
  position: relative;
  width: 72px; height: 72px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background-color: #2a2f38;
  background-image:
    linear-gradient(45deg, #3a414d 25%, transparent 25%),
    linear-gradient(-45deg, #3a414d 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #3a414d 75%),
    linear-gradient(-45deg, transparent 75%, #3a414d 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
}
.ref-thumb img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; display: block; }
.ref-thumb .ref-remove,
.ref-thumb .ref-process {
  position: absolute; width: 20px; height: 20px;
  padding: 0; border-radius: 50%; border: 0;
  font-size: 13px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.ref-remove { top: 2px; right: 2px; background: rgba(0,0,0,0.7); color: #fff; }
.ref-remove:hover { background: var(--error); }
.ref-process { bottom: 2px; right: 2px; background: var(--accent); color: #0b1220; font-weight: 700; }
.ref-process:hover { background: var(--accent-hover); }
.local-ref { border-color: var(--accent); }

/* ============================== Layers grid (paso 4) ============================== */

.grid-layers {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.layer-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  display: flex; flex-direction: column;
}
.layer-thumb { aspect-ratio: 1 / 1; border: 0; border-radius: 0; }
.layer-meta {
  padding: 9px 12px;
  display: flex; justify-content: space-between; align-items: center;
  border-top: 1px solid var(--border);
  font-size: 0.86rem;
}
.layer-meta .name { font-weight: 600; }
.layer-meta a { color: var(--accent); text-decoration: none; }
.layer-meta a:hover { color: var(--accent-hover); text-decoration: underline; }

/* ============================== Global status / error ============================== */

.global-status {
  position: fixed; bottom: 18px; left: 18px; right: 18px;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 12px 16px;
  display: flex; align-items: center; gap: 12px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.5);
  max-width: 460px;
  z-index: 50;
}
.spinner {
  width: 18px; height: 18px;
  flex-shrink: 0;
  border: 2px solid var(--surface-3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.global-status p { margin: 0; font-size: 0.9rem; }

.global-error {
  position: fixed; bottom: 18px; right: 18px; left: 18px;
  background: rgba(255,107,107,0.12);
  color: var(--error);
  border: 1px solid rgba(255,107,107,0.4);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 0.9rem;
  max-width: 460px;
  z-index: 51;
  box-shadow: 0 12px 30px rgba(0,0,0,0.5);
}

/* ============================== Lightbox ============================== */

.lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.88);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  cursor: zoom-out;
  z-index: 100;
  background-image:
    linear-gradient(45deg, rgba(255,255,255,0.04) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255,255,255,0.04) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255,255,255,0.04) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255,255,255,0.04) 75%);
  background-size: 24px 24px;
  background-color: #0a0d12;
}
.lightbox img { max-width: 100%; max-height: 100%; box-shadow: 0 12px 40px rgba(0,0,0,0.6); }

.seed-info { color: var(--muted); font-weight: normal; font-size: 0.85rem; margin-left: 8px; }

/* ============================== Chat (paso 1) ============================== */

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 120px;
  max-height: 480px;
  overflow-y: auto;
  padding: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 12px;
}

.chat-bubble {
  max-width: 80%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 0.93rem;
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.chat-bubble.user {
  align-self: flex-end;
  background: var(--accent-soft);
  border: 1px solid rgba(106, 169, 255, 0.3);
  border-bottom-right-radius: 4px;
  color: var(--text);
}
.chat-bubble.assistant {
  align-self: flex-start;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  color: var(--text);
}
.chat-bubble .chat-text {
  margin: 0;
}
.chat-bubble .chat-image {
  display: block;
  margin-top: 10px;
  max-width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: zoom-in;
}
.chat-bubble .chat-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.chat-bubble .chat-attachment-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  cursor: zoom-in;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.chat-input-row textarea {
  flex: 1;
  resize: vertical;
  min-height: 56px;
}
.chat-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.chat-actions button {
  min-width: 90px;
}

.chat-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  margin-bottom: 6px;
}

/* ============================== Toggle row ============================== */

.toggle-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
}
.toggle-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
.toggle-hint {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 2px;
  line-height: 1.4;
}

/* ============================== Responsive ============================== */

@media (max-width: 720px) {
  .result-grid { grid-template-columns: 1fr; }
  .row.grid { grid-template-columns: 1fr; }
  .global-status, .global-error { left: 12px; right: 12px; bottom: 12px; max-width: none; }
  .step-tabs { flex-direction: column; }
}
