:root {
  --bg: #0a0c0f;
  --surface: #12151a;
  --surface-2: #171b21;
  --elevated: #1c2128;
  --line: #242b34;
  --line-soft: #1b212a;
  --text: #e9edf2;
  --muted: #8b95a3;
  --faint: #5a6472;
  --accent: #00aeef;
  --accent-hi: #38c3f7;
  --accent-soft: rgba(0, 174, 239, .12);
  --accent-line: rgba(0, 174, 239, .32);
  --ink: #04222f;
  --success: #3ddc84;
  --warn: #ffb020;
  --danger: #ff6470;
  --r-sm: 8px;
  --r: 11px;
  --r-lg: 16px;
  --sh: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.28);
  --font-head: 'Outfit', system-ui, sans-serif;
  --font: 'Plus Jakarta Sans', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--danger); font-size: 13px; min-height: 16px; }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: #2a323d transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: #262d37; border-radius: 20px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: #333c48; background-clip: content-box; }

/* Brand */
.brand { font-family: var(--font-head); font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 9px; letter-spacing: -.01em; }
.brand.lg { font-size: 22px; }
.brand b { font-weight: 800; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft), 0 0 14px var(--accent); }

/* Buttons */
button { font-family: inherit; cursor: pointer; }
.primary { background: linear-gradient(180deg, var(--accent-hi), var(--accent)); color: var(--ink); border: 0; padding: 10px 16px; border-radius: var(--r); font-weight: 700; font-size: 13.5px; transition: filter .15s, transform .05s; box-shadow: 0 4px 14px rgba(0,174,239,.28); }
.primary:hover:not(:disabled) { filter: brightness(1.06); }
.primary:active:not(:disabled) { transform: translateY(1px); }
.primary:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }
.primary.lg { padding: 13px 18px; font-size: 15px; }
.block { width: 100%; }
.ghost { background: var(--surface-2); border: 1px solid var(--line); color: var(--text); padding: 9px 14px; border-radius: var(--r-sm); font-size: 13px; transition: border-color .15s, background .15s; }
.ghost:hover:not(:disabled) { border-color: var(--accent-line); background: var(--elevated); }
.ghost:disabled { opacity: .4; cursor: not-allowed; }
.ghost.sm { padding: 6px 10px; font-size: 12px; }
.icon-btn { background: transparent; border: 1px solid var(--line); color: var(--muted); width: 34px; height: 34px; border-radius: var(--r-sm); font-size: 15px; display: grid; place-items: center; transition: .15s; }
.icon-btn:hover { color: var(--danger); border-color: var(--danger); }

/* Chips */
.chip { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 20px; display: inline-flex; align-items: center; gap: 5px; }
.chip-accent { color: var(--accent-hi); background: var(--accent-soft); border: 1px solid var(--accent-line); }
.chip-soft { color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); }

/* ===== Login ===== */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 50% -10%, rgba(0,174,239,.10), transparent 60%), var(--bg); }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 34px; width: 360px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--sh); }
.login-card p { margin: -4px 0 6px; font-size: 13px; }
.login-card .field span { color: var(--muted); }

/* ===== App shell ===== */
.app { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.topbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 0 18px; height: 56px; border-bottom: 1px solid var(--line); background: var(--surface); flex-shrink: 0; }
.topbar-hint { text-align: center; font-size: 12.5px; color: var(--faint); }
.top-right { display: flex; align-items: center; gap: 12px; justify-content: flex-end; }
.user-chip { font-size: 12.5px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); padding: 5px 11px; border-radius: 20px; }

.workspace { flex: 1; display: grid; grid-template-columns: 340px 1fr 288px; min-height: 0; }

/* ===== Rails ===== */
.rail { background: var(--surface); min-height: 0; display: flex; flex-direction: column; }
.rail-left { border-right: 1px solid var(--line); }
.rail-right { border-left: 1px solid var(--line); padding: 16px; overflow-y: auto; }
.rail-scroll { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 22px; }
.rail-foot { border-top: 1px solid var(--line); padding: 14px 16px; background: linear-gradient(180deg, transparent, rgba(0,0,0,.15)); display: flex; flex-direction: column; gap: 8px; }

/* Groups */
.group { display: flex; flex-direction: column; gap: 13px; }
.group-head, .group-head-inline { font-family: var(--font-head); font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); display: flex; align-items: center; gap: 9px; }
.step { width: 20px; height: 20px; border-radius: 6px; background: var(--accent-soft); color: var(--accent-hi); border: 1px solid var(--accent-line); display: grid; place-items: center; font-size: 11px; }
.group-toggle { width: 100%; background: transparent; border: 0; padding: 0; display: flex; align-items: center; justify-content: space-between; }
.chev { color: var(--faint); font-size: 12px; transition: transform .15s; }

/* Fields */
.field { display: flex; flex-direction: column; gap: 7px; font-size: 13px; }
.field > span { color: var(--muted); font-weight: 600; font-size: 12.5px; }
.field input[type=text], .field input[type=password], .field textarea, .login-card input {
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text); padding: 10px 12px; border-radius: var(--r-sm); font-size: 13.5px; font-family: inherit; transition: border-color .15s, box-shadow .15s; width: 100%; }
.field textarea { resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
::placeholder { color: var(--faint); }

/* Custom select */
.select-wrap { position: relative; }
.select-wrap::after { content: '▾'; position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; font-size: 11px; }
.select-wrap select, .field select { -webkit-appearance: none; appearance: none; width: 100%; background: var(--surface-2); border: 1px solid var(--line); color: var(--text); padding: 10px 30px 10px 12px; border-radius: var(--r-sm); font-size: 13.5px; font-family: inherit; cursor: pointer; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }

/* Recipe card */
.recipe-card { background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: var(--r); padding: 12px 13px; display: flex; flex-direction: column; gap: 10px; }
.recipe-desc { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.5; }

/* Recipe vars */
.recipe-vars { display: flex; flex-direction: column; gap: 14px; }
.check-field { display: flex; align-items: flex-start; gap: 10px; font-size: 13px; cursor: pointer; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm); transition: border-color .15s; }
.check-field:hover { border-color: var(--accent-line); }
.check-field input { accent-color: var(--accent); width: 16px; height: 16px; margin-top: 1px; flex-shrink: 0; }
.check-field span { color: var(--text); line-height: 1.4; }

/* Prompt editor */
.prompt-panel { display: flex; flex-direction: column; gap: 9px; margin-top: 4px; }
.prompt-panel textarea { background: #070a0d; border: 1px solid var(--line); color: #b8c4d0; padding: 12px; border-radius: var(--r-sm); font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 11.5px; line-height: 1.6; resize: vertical; }
.prompt-actions { display: flex; align-items: center; gap: 10px; }
.hint { color: var(--faint); font-size: 11.5px; }

/* Status */
.status { font-size: 12.5px; min-height: 16px; color: var(--muted); }
.status.loading { color: var(--accent-hi); }
.status.error { color: var(--danger); }
.status.ok { color: var(--success); }

/* ===== Canvas ===== */
.canvas-col { display: flex; flex-direction: column; min-height: 0; background:
  radial-gradient(900px 500px at 50% 0%, rgba(0,174,239,.05), transparent 55%), var(--bg); }
.canvas { position: relative; flex: 1; margin: 18px; border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; display: grid; place-items: center;
  background: repeating-conic-gradient(#0e1116 0% 25%, #0c0f13 0% 50%) 50% / 26px 26px; }

.dropzone { position: absolute; inset: 0; display: grid; place-items: center; cursor: pointer; transition: background .15s; }
.dropzone.drag { background: var(--accent-soft); }
.dropzone.drag::after { content: ''; position: absolute; inset: 14px; border: 2px dashed var(--accent-line); border-radius: var(--r); }
.dz-inner { text-align: center; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 4px; }
.dz-icon { color: var(--accent); width: 74px; height: 74px; border-radius: 50%; background: var(--accent-soft); border: 1px solid var(--accent-line); display: grid; place-items: center; margin-bottom: 10px; }
.dz-title { margin: 0; font-family: var(--font-head); font-weight: 600; font-size: 16px; color: var(--text); }
.dz-sub { margin: 0; font-size: 13px; }
/* preview de la referencia recién subida */
.dropzone img { max-height: 74vh; max-width: 94%; border-radius: var(--r); box-shadow: var(--sh); }

/* Compare */
.compare { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; }
.compare-view { position: relative; display: grid; user-select: none; border-radius: var(--r); overflow: hidden; box-shadow: var(--sh); max-height: 100%; }
.compare-view > #afterImg { grid-area: 1 / 1; display: block; max-height: calc(100vh - 190px); max-width: 100%; width: auto; object-fit: contain; }
.before-clip { grid-area: 1 / 1; position: relative; width: 50%; height: 100%; overflow: hidden; }
.before-clip img { position: absolute; top: 0; left: 0; height: 100%; width: auto; max-width: none; }
/* el before debe calzar pixel a pixel con el after: se ajusta por JS */
.compare-handle { position: absolute; top: 0; bottom: 0; left: 50%; width: 2px; background: rgba(255,255,255,.9); transform: translateX(-1px); pointer-events: none; box-shadow: 0 0 10px rgba(0,0,0,.5); }
.compare-handle .grip { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); width: 34px; height: 34px; border-radius: 50%; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.5); display: grid; place-items: center; }
.compare-handle .grip::before { content: '⟨ ⟩'; font-size: 12px; color: #04222f; letter-spacing: -2px; }
#slider { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: ew-resize; margin: 0; }
.tag { position: absolute; top: 12px; font-size: 10.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; background: rgba(6,10,14,.72); backdrop-filter: blur(4px); color: #cfd8e2; padding: 4px 9px; border-radius: 20px; pointer-events: none; }
.tag-left { left: 12px; } .tag-right { right: 12px; }

/* Loading overlay */
.loading-overlay { position: absolute; inset: 0; background: rgba(8,11,14,.82); backdrop-filter: blur(3px); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; z-index: 5; }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 3px solid rgba(255,255,255,.12); border-top-color: var(--accent); animation: spin .8s linear infinite; margin-bottom: 12px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { margin: 0; font-family: var(--font-head); font-weight: 600; font-size: 15px; }
.loading-sub { margin: 0; font-size: 12.5px; color: var(--muted); }

/* Canvas toolbar */
.canvas-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 18px 16px; }
.bar-left, .bar-right { display: flex; align-items: center; gap: 10px; }
.warn-inline { font-size: 11.5px; color: var(--warn); max-width: 340px; line-height: 1.35; }

/* ===== Gallery ===== */
.rail-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; font-family: var(--font-head); font-size: 14px; font-weight: 700; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.grid figure { margin: 0; position: relative; border-radius: var(--r-sm); overflow: hidden; border: 1px solid var(--line); cursor: pointer; aspect-ratio: 1; transition: border-color .15s, transform .1s; }
.grid figure:hover { border-color: var(--accent-line); transform: translateY(-2px); }
.grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.grid figcaption { position: absolute; left: 0; right: 0; bottom: 0; font-size: 10px; padding: 12px 8px 6px; color: #dfe6ee; background: linear-gradient(transparent, rgba(4,7,10,.85)); opacity: 0; transition: opacity .15s; }
.grid figure:hover figcaption { opacity: 1; }
.gal-empty { color: var(--faint); font-size: 12.5px; text-align: center; padding: 30px 10px; line-height: 1.6; }

.chip-warn { color: var(--warn) !important; background: rgba(255,176,32,.10) !important; border-color: rgba(255,176,32,.35) !important; }

/* ===== Admin modal ===== */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(4,6,9,.72); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 24px; }
.modal-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); width: min(920px, 100%); max-height: 88vh; display: flex; flex-direction: column; box-shadow: var(--sh); overflow: hidden; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; padding: 20px 22px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-family: var(--font-head); font-size: 18px; }
.modal-head .sub { margin: 3px 0 0; font-size: 12.5px; }
.modal-body { padding: 20px 22px; overflow-y: auto; display: flex; flex-direction: column; gap: 18px; }

.admin-list { display: flex; flex-direction: column; gap: 12px; }
.urow { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 15px; display: flex; flex-direction: column; gap: 12px; }
.urow-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.urow-head .uses { font-size: 12px; color: var(--muted); }
.urow-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 11px; }
.mini { display: flex; flex-direction: column; gap: 5px; font-size: 12px; }
.mini > span { color: var(--muted); font-size: 11.5px; }
.mini input[type=text], .mini input[type=number], .mini select { background: var(--elevated); border: 1px solid var(--line); color: var(--text); padding: 8px 10px; border-radius: var(--r-sm); font-size: 13px; font-family: inherit; width: 100%; }
.mini.check { flex-direction: row; align-items: center; gap: 8px; margin-top: 20px; }
.mini.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.urow-brands { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; font-size: 12px; padding-top: 2px; border-top: 1px dashed var(--line-soft); padding-top: 11px; }
.mini-label { color: var(--muted); }
.bchk { display: inline-flex; align-items: center; gap: 6px; color: var(--text); cursor: pointer; }
.bchk input { accent-color: var(--accent); }
.urow-actions { display: flex; align-items: center; gap: 9px; }
.urow-actions .spacer { flex: 1; }
.sm { padding: 7px 12px !important; font-size: 12.5px !important; }
.primary.sm { border-radius: var(--r-sm); }
.f-del { color: var(--danger); border-color: transparent; }
.f-del:hover { border-color: var(--danger); background: transparent; }

.admin-new { border-top: 1px solid var(--line); padding-top: 16px; }
.admin-new h3 { margin: 0 0 12px; font-family: var(--font-head); font-size: 14px; }
.new-grid { display: grid; grid-template-columns: 1fr 1fr auto 1fr auto; gap: 10px; align-items: center; }
.new-grid input, .new-grid select { background: var(--surface-2); border: 1px solid var(--line); color: var(--text); padding: 9px 11px; border-radius: var(--r-sm); font-size: 13px; font-family: inherit; }
.ok-msg { color: var(--success); font-size: 13px; }

/* ===== Responsive ===== */
@media (max-width: 760px) {
  .urow-grid { grid-template-columns: 1fr 1fr; }
  .new-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 1180px) {
  .workspace { grid-template-columns: 300px 1fr; }
  .rail-right { display: none; }
}
@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .rail-left { border-right: 0; border-bottom: 1px solid var(--line); max-height: 46vh; }
  .canvas { margin: 12px; }
}
