:root {
  --bg: #0f1115;
  --panel: #161a21;
  --panel-2: #1d222b;
  --border: #2a303b;
  --text: #e8ebf0;
  --muted: #8b93a3;
  --accent: #7c5cff;
  --accent-2: #a58cff;
  --ok: #3ccf8e;
  --warn: #f5b942;
  --err: #ff5c7a;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); background: var(--bg); color: var(--text);
  font-size: 14px; line-height: 1.45;
}
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 18px; }
h2 { font-size: 15px; }
p { margin: 0; }
a.link { color: var(--accent-2); text-decoration: none; }
a.link:hover { text-decoration: underline; }
code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- barra superior */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon { font-size: 26px; }
.brand p { color: var(--muted); font-size: 12px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.spend { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.spend-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.spend-value { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- layout */
.layout {
  display: grid; grid-template-columns: 290px minmax(380px, 1fr) minmax(360px, 1.1fr);
  gap: 16px; padding: 16px 20px; height: calc(100vh - 63px);
}
.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.panel-head { padding: 14px 16px 10px; border-bottom: 1px solid var(--border); }
.panel-head h2 { margin-bottom: 8px; }
.form-head, .jobs-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.form-head h2 { margin-bottom: 2px; }
.jobs-head h2 { margin: 0; }
.count-badge { background: var(--panel-2); border-radius: 999px; padding: 0 8px; font-size: 12px; color: var(--muted); margin-left: 4px; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .panel { max-height: none; }
  .model-list { max-height: 320px; }
  .job-list { max-height: none; }
}

/* ---------- inputs */
input[type=text], input[type=search], input[type=number], input[type=password], input[type=url], textarea, select {
  width: 100%; background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 11px; font: inherit; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 60px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field .label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; display: flex; justify-content: space-between; }
.field .label .req { color: var(--accent-2); }
.field .help { font-size: 12px; color: var(--muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .field-row { grid-template-columns: 1fr; } }

.btn {
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  padding: 9px 14px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-2); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.danger:hover { border-color: var(--err); color: var(--err); }

/* pills (enum) */
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pills button {
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  padding: 6px 12px; border-radius: 999px; font: inherit; cursor: pointer; font-size: 13px;
}
.pills button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* slider */
.slider { display: flex; align-items: center; gap: 12px; }
.slider input[type=range] { flex: 1; accent-color: var(--accent); }
.slider input[type=number] { width: 84px; }

/* toggle */
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 11px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }
.toggle input { display: none; }
.toggle .knob { width: 38px; height: 22px; border-radius: 999px; background: #3a4150; position: relative; transition: background .15s; flex-shrink: 0; }
.toggle .knob::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; }
.toggle input:checked + .knob { background: var(--accent); }
.toggle input:checked + .knob::after { left: 19px; }

/* dropzone */
.dropzone {
  border: 1.5px dashed var(--border); border-radius: 10px; padding: 14px; text-align: center;
  color: var(--muted); cursor: pointer; transition: border-color .15s, background .15s; position: relative;
  background: var(--panel-2);
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: rgba(124, 92, 255, .06); }
.dropzone input[type=file] { display: none; }
.dropzone .dz-hint { font-size: 12px; }
.dropzone .dz-hint strong { color: var(--text); }
.dropzone.uploading { border-color: var(--warn); }
.dz-url { margin-top: 8px; display: flex; gap: 6px; }
.dz-url input { font-size: 12px; padding: 6px 9px; }
.dz-url button { white-space: nowrap; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.thumb { position: relative; width: 96px; height: 96px; border-radius: 8px; overflow: hidden; background: #000; border: 1px solid var(--border); }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; }
.thumb .audio-icon { display: flex; align-items: center; justify-content: center; height: 100%; font-size: 28px; }
.thumb .rm { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.7); color: #fff; border: 0; border-radius: 50%; width: 22px; height: 22px; cursor: pointer; font-size: 13px; line-height: 1; }
.thumb .uploading-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.55); font-size: 11px; color: #fff; }

/* ---------- modelos */
.models .panel-head input { margin-top: 2px; }
.mode-filters { display: flex; gap: 4px; padding: 8px 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.mode-filters button { border: 1px solid transparent; background: transparent; color: var(--muted); padding: 4px 9px; border-radius: 999px; font: inherit; font-size: 12px; cursor: pointer; }
.mode-filters button.active { background: var(--panel-2); color: var(--text); border-color: var(--border); }
.model-list { overflow-y: auto; flex: 1; padding: 8px; }
.model-group { margin-bottom: 8px; }
.model-group h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 8px 8px 4px; display: flex; justify-content: space-between; }
.model-group h3 .tag { font-weight: 500; text-transform: none; letter-spacing: 0; }
.model-item {
  width: 100%; text-align: left; background: transparent; border: 1px solid transparent; color: var(--text);
  padding: 8px 10px; border-radius: 8px; cursor: pointer; font: inherit; display: flex; flex-direction: column; gap: 2px;
}
.model-item:hover { background: var(--panel-2); }
.model-item.active { background: rgba(124, 92, 255, .14); border-color: var(--accent); }
.model-item .mi-name { font-weight: 500; font-size: 13px; }
.model-item .mi-sub { font-size: 11px; color: var(--muted); }
.legacy-sep { font-size: 11px; color: var(--muted); padding: 12px 8px 4px; border-top: 1px solid var(--border); margin-top: 8px; }

/* ---------- formulario */
.form form { overflow-y: auto; flex: 1; padding: 16px; }
.advanced { margin: 6px 0 14px; border: 1px solid var(--border); border-radius: 8px; padding: 0 12px; }
.advanced summary { cursor: pointer; padding: 10px 0; color: var(--muted); font-size: 13px; }
.advanced[open] summary { border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.estimate {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: linear-gradient(135deg, rgba(124,92,255,.14), rgba(124,92,255,.04));
  border: 1px solid rgba(124,92,255,.35); border-radius: 10px; padding: 12px 14px; margin-bottom: 14px;
}
.estimate-main { display: flex; flex-direction: column; }
.estimate-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.estimate-value { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.estimate-sub { font-size: 12px; color: var(--muted); text-align: right; max-width: 55%; }
.estimate.error { border-color: rgba(255,92,122,.5); background: rgba(255,92,122,.06); }
.estimate.loading .estimate-value { opacity: .5; }
.actions { display: flex; gap: 12px; align-items: center; }
.actions .count { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.actions .count input { width: 64px; }
.actions .primary { flex: 1; padding: 12px; font-size: 15px; }
.form-error { color: var(--err); font-size: 13px; margin-top: 10px; white-space: pre-wrap; }

/* ---------- trabajos */
.job-list { overflow-y: auto; flex: 1; padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.job-list .empty { color: var(--muted); font-size: 13px; padding: 12px; }
.job { display: grid; grid-template-columns: 180px 1fr; gap: 12px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px; }
@media (max-width: 600px) { .job { grid-template-columns: 1fr; } }
.job-media { background: #000; border-radius: 8px; overflow: hidden; min-height: 100px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; text-align: center; padding: 6px; }
.job-media video { width: 100%; max-height: 240px; display: block; background: #000; }
.job-media .spinner { width: 26px; height: 26px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.job-body { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.job-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.job-model { font-weight: 600; font-size: 13px; }
.job-time { font-size: 12px; margin-left: auto; }
.job-prompt { font-size: 13px; color: var(--text); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.job-meta { font-size: 12px; }
.job-error { color: var(--err); font-size: 12px; }
.job-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; }
.chip { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--panel); border: 1px solid var(--border); text-transform: uppercase; letter-spacing: .04em; }
.chip.queued { color: var(--warn); border-color: rgba(245,185,66,.4); }
.chip.in_progress { color: var(--accent-2); border-color: rgba(165,140,255,.5); }
.chip.completed { color: var(--ok); border-color: rgba(60,207,142,.5); }
.chip.failed, .chip.nsfw { color: var(--err); border-color: rgba(255,92,122,.5); }
.chip.canceled, .chip.stale { color: var(--muted); }

/* ---------- diálogo */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 14px; padding: 0; max-width: 520px; width: calc(100% - 32px); }
dialog::backdrop { background: rgba(0,0,0,.6); }
.dialog-body { padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.dialog-body h2 { font-size: 17px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* toast */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--border); padding: 10px 16px; border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.5); z-index: 50; font-size: 13px; max-width: 90vw; }
.toast.err { border-color: var(--err); }
.toast.ok { border-color: var(--ok); }
