:root {
  --bg: #0e1116;
  --bg-panel: #161b23;
  --bg-card: #1d242f;
  --border: #2a323f;
  --text: #e6e9ef;
  --text-dim: #8b94a3;
  --accent: #6c8cff;
  --accent-strong: #4f6ef7;
  --ok: #3ecf8e;
  --warn: #f5b455;
  --err: #f4696b;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ---------- Шапка ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 20px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.logo { font-size: 20px; font-weight: 700; white-space: nowrap; }
.tabs { display: flex; gap: 6px; flex: 1; }
.tab {
  background: transparent;
  color: var(--text-dim);
  border: none;
  padding: 8px 16px;
  font-size: 15px;
  border-radius: 8px;
  cursor: pointer;
}
.tab:hover { color: var(--text); background: var(--bg-card); }
.tab.active { color: #fff; background: var(--accent-strong); }
.status { display: flex; align-items: center; gap: 8px; color: var(--text-dim); font-size: 13px; }
.status .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--err); }
.status.online .dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }

main { padding: 20px; max-width: 1500px; margin: 0 auto; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
h2 { font-size: 16px; color: var(--text-dim); font-weight: 600; margin: 18px 0 10px; }

.empty-hint { color: var(--text-dim); padding: 24px; text-align: center; border: 1px dashed var(--border); border-radius: var(--radius); }

/* ---------- Генерация ---------- */
.generate-layout { display: grid; grid-template-columns: 420px 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .generate-layout { grid-template-columns: 1fr; } }

.panel { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }

.mode-switch { display: grid; grid-template-columns: 1fr; gap: 6px; margin-bottom: 10px; }
.mode-btn {
  text-align: left; padding: 10px 14px; border-radius: 10px;
  background: var(--bg-card); color: var(--text); border: 1px solid var(--border); cursor: pointer; font-size: 14px;
}
.mode-btn.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, var(--bg-card)); }
.mode-description { color: var(--text-dim); font-size: 13px; margin-bottom: 12px; min-height: 18px; }

.form-field { margin-bottom: 12px; }
.form-field label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 5px; }
.form-field textarea, .form-field input, .form-field select {
  width: 100%; background: var(--bg-card); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; font-size: 14px;
  font-family: inherit;
}
.form-field textarea { min-height: 74px; resize: vertical; }
.form-field textarea:focus, .form-field input:focus, .form-field select:focus { outline: none; border-color: var(--accent); }
.seed-row { display: flex; gap: 6px; }
.seed-row input { flex: 1; }
.seed-row .dice { flex: 0 0 auto; width: 40px; }

.btn {
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text);
  padding: 9px 16px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { width: 100%; background: var(--accent-strong); border-color: var(--accent-strong); font-weight: 600; padding: 12px; }
.btn.primary:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--err); border-color: var(--err); background: transparent; }
.form-error { color: var(--err); font-size: 13px; margin-top: 10px; }

#dropzone-wrap { margin-bottom: 12px; }
.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 18px; text-align: center; color: var(--text-dim); cursor: pointer; font-size: 13px;
}
.dropzone.drag { border-color: var(--accent); color: var(--accent); }
.dropzone img { max-width: 100%; max-height: 160px; border-radius: 8px; margin-top: 8px; }

/* очередь и результат */
.active-jobs { display: flex; flex-direction: column; gap: 10px; }
.job-card { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.job-card .job-top { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.job-card .job-mode { font-weight: 600; }
.badge { font-size: 12px; padding: 3px 9px; border-radius: 20px; white-space: nowrap; }
.badge.queued { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.badge.running { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent); }
.badge.completed { background: color-mix(in srgb, var(--ok) 20%, transparent); color: var(--ok); }
.badge.failed { background: color-mix(in srgb, var(--err) 20%, transparent); color: var(--err); }

.progress { height: 8px; background: var(--bg-card); border-radius: 6px; margin-top: 10px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--ok)); transition: width .3s; }
.job-error { color: var(--err); font-size: 13px; margin-top: 8px; word-break: break-word; }
.job-outputs { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.job-outputs img, .job-outputs video { max-height: 150px; border-radius: 8px; border: 1px solid var(--border); }

.result-preview { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; min-height: 120px; }
.result-preview img, .result-preview video { max-width: 100%; max-height: 420px; border-radius: 8px; display: block; margin: 0 auto; }


/* ---------- Галерея ---------- */
.gallery-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.chips { display: flex; gap: 6px; }
.chip {
  background: var(--bg-card); color: var(--text-dim); border: 1px solid var(--border);
  padding: 7px 14px; border-radius: 20px; cursor: pointer; font-size: 13px;
}
.chip.active { color: #fff; background: var(--accent-strong); border-color: var(--accent-strong); }
#gallery-search {
  flex: 1; min-width: 180px; background: var(--bg-panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; font-size: 14px;
}
#gallery-search:focus { outline: none; border-color: var(--accent); }
#gallery-sort { background: var(--bg-panel); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px; }
.gallery-meta { color: var(--text-dim); font-size: 13px; margin-bottom: 10px; }

.gallery-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px;
}
.gcard {
  position: relative; border-radius: var(--radius); overflow: hidden; cursor: pointer;
  background: var(--bg-card); border: 1px solid var(--border); aspect-ratio: 1 / 1;
}
.gcard img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gcard .gtype {
  position: absolute; top: 8px; left: 8px; font-size: 11px; padding: 2px 8px;
  border-radius: 12px; background: rgba(0,0,0,.55); color: #fff;
}
.gcard .gprompt {
  position: absolute; bottom: 0; left: 0; right: 0; padding: 14px 8px 6px;
  font-size: 11px; color: #ddd;
  background: linear-gradient(transparent, rgba(0,0,0,.8));
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.gcard .gnoimg { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 40px; background: linear-gradient(135deg, #1d242f, #2a323f); }
.gactions { position: absolute; top: 8px; right: 8px; display: flex; gap: 4px; }
.gbtn {
  border: none; border-radius: 6px; padding: 3px 8px; font-size: 11px; font-weight: 600;
  cursor: pointer; background: rgba(0,0,0,.65); color: #fff;
}
.gbtn:hover { background: var(--accent-strong); }
.load-more { text-align: center; margin-top: 16px; }

/* ---------- История ---------- */
.jobs-list { display: flex; flex-direction: column; gap: 10px; }
.job-row { display: grid; grid-template-columns: 150px 170px 1fr 110px; gap: 12px; align-items: center;
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px; }
.job-row .jtime { color: var(--text-dim); font-size: 13px; }
.job-row .jprompt { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-dim); }
@media (max-width: 800px) { .job-row { grid-template-columns: 1fr 1fr; } }

/* ---------- Лайтбокс ---------- */
.lightbox { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.lightbox[hidden] { display: none; }
.lightbox-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.82); }
.lightbox-body {
  position: relative; max-width: min(1200px, 94vw); max-height: 94vh; display: flex; flex-direction: column;
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; gap: 12px;
}
.lightbox-close { position: absolute; top: 10px; right: 10px; z-index: 2; }
.lightbox-media img, .lightbox-media video { max-width: 100%; max-height: 70vh; border-radius: 8px; display: block; margin: 0 auto; }
.lightbox-info { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-dim); overflow: auto; }
.lightbox-info .lprompt { color: var(--text); white-space: pre-wrap; max-height: 120px; overflow: auto; }
.lightbox-actions { display: flex; gap: 10px; margin-top: 4px; }
