:root {
  --bg: #101216;
  --panel: #181b21;
  --panel-2: #1e222a;
  --border: #2b3038;
  --border-soft: #23272f;
  --text: #ECE9E2;
  --text-muted: #8b8f9c;
  --text-faint: #5b6070;
  --accent: #c98a3e;
  --accent-hover: #d99a4e;
  --accent-soft: #3a2c1a;
  --success: #7fbf82;
  --success-soft: #1c2b1e;
  --error: #e0796a;
  --error-soft: #2e1c1a;
  --radius: 10px;
  --font-ui: 'Space Grotesk', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  min-height: 100vh;
}

.app { max-width: 1360px; margin: 0 auto; padding: 0 28px 60px; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 26px 0 22px;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 28px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  font-size: 22px;
  color: var(--accent);
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-title { font-weight: 600; font-size: 17px; letter-spacing: -0.01em; }
.brand-sub { font-size: 12.5px; color: var(--text-muted); font-family: var(--font-mono); }

.status {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 20px;
  background: var(--panel);
}
.status.ok { color: var(--success); border-color: #2c3f2c; }
.status.err { color: var(--error); border-color: #4a2c27; }

/* ---------- Mode switch ---------- */
.mode-switch {
  display: flex;
  gap: 8px;
  margin-bottom: 26px;
  padding: 5px;
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  width: fit-content;
}
.mode-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 14px;
  padding: 10px 22px;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.mode-btn:hover { color: var(--text); }
.mode-btn.active {
  background: var(--accent);
  color: #17120a;
}
.mode-panel[hidden] { display: none; }

/* ---------- Layout ---------- */
.layout {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Responsive multi-column grid used inside .panel-input to group related
   sections side by side instead of one long vertical column. Collapses to
   a single column automatically on narrow viewports. */
.top-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px 28px;
  align-items: start;
  margin-bottom: 4px;
}
.top-grid .grid-col { min-width: 0; }
.top-grid .grid-col .panel-head:first-child { margin-top: 0; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 22px;
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.panel-head-tight { margin-top: 26px; }
.panel-head h2 { font-size: 15px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.step {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 5px;
  padding: 3px 6px;
}
.results-meta {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}

.hint { font-size: 12.5px; color: var(--text-muted); line-height: 1.5; margin: 2px 0 16px; }

.step-optional { font-weight: 400; color: var(--text-faint); font-size: 11px; margin-left: 4px; }

/* ---------- Quick action (input-stage recolor) ---------- */
.quick-action {
  margin: 22px 0 26px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-2);
}
.quick-action-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.quick-action-head h2 { font-size: 15px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.quick-tag {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 5px;
  padding: 3px 7px;
  white-space: nowrap;
}
.quick-action .hint { margin-bottom: 12px; }
.quick-action .primary-btn { margin-top: 4px; }

/* ---------- Dropzone ---------- */
.dropzone {
  display: block;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  min-height: 190px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color .15s ease, background .15s ease;
  background: var(--panel-2);
  overflow: hidden;
  position: relative;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--panel); }
.dropzone-empty {
  text-align: center;
  color: var(--text-faint);
  padding: 24px;
}
.dropzone-empty svg { color: var(--text-faint); margin-bottom: 8px; }
.dropzone-empty p { margin: 0; font-size: 13.5px; color: var(--text-muted); line-height: 1.5; }
.dropzone-empty span { color: var(--text-faint); font-size: 12px; }
.dropzone-preview {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  background: #0c0d10;
}

/* ---------- Custom Collapsible Dropdown ---------- */
.custom-dropdown {
  position: relative;
  width: 100%;
  margin-bottom: 12px;
  user-select: none;
}

.dropdown-header {
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--text);
  transition: border-color 0.15s ease;
}

.dropdown-header:hover {
  border-color: var(--accent);
}

.dropdown-arrow {
  font-size: 10px;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}

.custom-dropdown.open .dropdown-arrow {
  transform: rotate(180deg);
  color: var(--accent);
}

.dropdown-list {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 340px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.custom-dropdown.open .dropdown-list {
  display: block;
}

.dropdown-group-title {
  padding: 8px 12px 4px;
  background: #14161b;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  color: var(--accent);
  border-bottom: 1px solid var(--border-soft);
  position: sticky;
  top: 0;
  z-index: 2;
}

.dropdown-item {
  padding: 8px 12px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-soft);
  transition: background 0.12s ease;
}

.dropdown-item:last-child {
  border-bottom: none;
}

.dropdown-item:hover {
  background: var(--panel-2);
}

.dropdown-item.checked {
  background: var(--panel-2);
}

.dropdown-item input[type="checkbox"] {
  margin-top: 3px;
  accent-color: var(--accent);
  cursor: pointer;
}

.dropdown-item-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.dropdown-item-title {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
}

.dropdown-item-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.35;
}

.secondary-btn {
  margin-top: 4px;
  margin-bottom: 22px;
  background: var(--panel-2);
  color: var(--accent);
  border: 1px solid var(--accent);
}
.secondary-btn:hover:not(:disabled) { background: var(--accent-soft); filter: none; }

/* ---------- Video mode ---------- */
.video-prompt-field { margin-bottom: 6px; }
.video-prompt-field textarea {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 13px 14px;
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.55;
  resize: vertical;
}
.video-prompt-field textarea:focus { outline: none; border-color: var(--accent); }

/* ---------- Prompt rows ---------- */
.prompt-list { display: flex; flex-direction: column; gap: 10px; }
.prompt-row {
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 10px 10px 10px 12px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.prompt-row .idx {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
  padding-top: 8px;
  min-width: 16px;
}
.prompt-row-main { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.row-title-input {
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 13px;
  padding: 4px 0 0;
  border-bottom: 1px dashed transparent;
}
.row-title-input:focus { outline: none; border-bottom-color: var(--accent); }
.row-title-input::placeholder { color: var(--text-faint); font-weight: 400; }
.prompt-row textarea {
  width: 100%;
  resize: vertical;
  min-height: 58px;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.5;
  padding: 6px 0;
}
.prompt-row textarea:focus { outline: none; }
.prompt-row-footer { display: flex; justify-content: flex-end; }
.row-model-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-faint);
}
.row-model-select {
  width: 100%;
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 3px 6px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  max-width: 220px;
}
.row-model-select:not([value=""]) { color: var(--accent); border-color: var(--accent-soft); }
.prompt-row .remove-btn {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 6px;
  border-radius: 6px;
}
.prompt-row .remove-btn:hover { color: var(--error); background: var(--error-soft); }

.text-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-family: var(--font-ui);
  font-size: 13px;
  cursor: pointer;
  padding: 10px 0 0;
}
.text-btn:hover { text-decoration: underline; }

.ghost-btn {
  margin-left: auto;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.ghost-btn:hover { color: var(--text); border-color: var(--accent); }

/* ---------- Product details ---------- */
.details-row { display: flex; gap: 12px; margin-bottom: 12px; }
.details-row .field { flex: 1; min-width: 0; }
.field-wide { flex: 1 1 100%; }
.details-row input[type="text"] {
  width: 100%;
  min-width: 0;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 9px 10px;
  font-family: var(--font-ui);
  font-size: 13px;
}
.details-row input[type="text"]::placeholder { color: var(--text-faint); }

/* ---------- Settings ---------- */
.settings-row { display: flex; gap: 12px; margin-bottom: 12px; }
.field { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--text-muted); }
.field select {
  width: 100%;
  min-width: 0;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 9px 10px;
  font-family: var(--font-ui);
  font-size: 13px;
  text-overflow: ellipsis;
}

/* ---------- Buttons ---------- */
.primary-btn {
  width: 100%;
  margin-top: 20px;
  background: var(--accent);
  color: #17120a;
  border: none;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 14px;
  padding: 13px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: filter .15s ease, transform .05s ease;
}
.primary-btn:hover:not(:disabled) { background: var(--accent-hover); }
.primary-btn:active:not(:disabled) { transform: translateY(1px); }
.primary-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.cost-note { text-align: center; font-family: var(--font-mono); font-size: 11.5px; color: var(--text-faint); margin: 10px 0 0; }

/* ---------- Results ---------- */
.results-empty {
  border: 1px dashed var(--border-soft);
  border-radius: var(--radius);
  padding: 60px 20px;
  text-align: center;
  color: var(--text-faint);
}
.results-empty p { margin: 4px 0; font-size: 13.5px; }
.results-empty-sub { font-size: 12px; color: var(--text-faint); }

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.result-card {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel-2);
  display: flex;
  flex-direction: column;
}
.result-media {
  aspect-ratio: 1 / 1;
  background: #0c0d10;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.result-media img { width: 100%; height: 100%; object-fit: cover; }
.video-card .result-media { aspect-ratio: 16 / 9; }
.video-card .result-media video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.video-meta { font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); }
.result-body { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.result-label { font-size: 12.5px; font-weight: 600; }
.result-prompt {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.4;
  max-height: 54px;
  overflow: hidden;
}
.result-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 2px; gap: 8px; }
.result-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.result-tag {
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 3px 7px;
  border-radius: 5px;
}
.result-tag.success { color: var(--success); background: var(--success-soft); }
.result-tag.failed { color: var(--error); background: var(--error-soft); }
.result-tag.pending { color: var(--accent); background: var(--accent-soft); }
.download-link, .video-download {
  font-size: 11.5px;
  color: var(--accent);
  text-decoration: none;
  font-family: var(--font-mono);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}
.download-link:hover, .video-download:hover { text-decoration: underline; }

.spinner {
  width: 22px; height: 22px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-msg { font-size: 11.5px; color: var(--error); padding: 0 4px; line-height: 1.4; }

/* ---------- Recolor ---------- */
.recolor-row {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  align-items: center;
}
.recolor-row:first-of-type {
  padding-top: 8px;
  border-top: 1px dashed var(--border-soft);
}
.recolor-input, .recolor-model-select {
  flex: 1;
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 8px;
  font-family: var(--font-ui);
  font-size: 12px;
}
.recolor-model-select { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-muted); }
.recolor-input::placeholder { color: var(--text-faint); }
.fabric-upload-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 6px 8px;
  font-family: var(--font-ui);
  font-size: 11.5px;
  cursor: pointer;
  white-space: nowrap;
  max-width: 130px;
  overflow: hidden;
}
.fabric-upload-btn:hover { border-color: var(--accent); color: var(--text); }
.fabric-filename { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recolor-btn {
  flex-shrink: 0;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 6px;
  padding: 6px 10px;
  font-family: var(--font-ui);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.recolor-btn:hover:not(:disabled) { background: var(--accent); color: #17120a; }
.recolor-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Focus ---------- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; border-color: var(--accent); }
.details-row input[type="text"]:focus, .field select:focus,
.recolor-input:focus, .recolor-model-select:focus { outline: none; border-color: var(--accent); }

/* ---------- Topbar right side (status, user, admin, logout) ---------- */
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.user-email { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  font-family: var(--font-ui); font-weight: 600; font-size: 13px;
  padding: 8px 14px; cursor: pointer; text-decoration: none;
  transition: background .15s ease, border-color .15s ease;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #17120a; border-color: var(--accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--error-soft); color: var(--error); border-color: #4a2c27; }
.btn-danger:hover:not(:disabled) { border-color: var(--error); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; padding: 12px 16px; font-size: 14px; }

/* ---------- Form controls (login + admin) ---------- */
.form-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.form-field > label, .form-label { font-size: 12.5px; color: var(--text-muted); font-weight: 500; }
.input, .form-field input:not([type="checkbox"]), .form-field select, .form-field textarea {
  width: 100%; min-width: 0;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 10px 12px;
  font-family: var(--font-ui); font-size: 14px;
}
.form-field textarea { min-height: 320px; resize: vertical; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.55; }
.form-field input::placeholder { color: var(--text-faint); }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); margin-bottom: 14px; }
.check-row input { accent-color: var(--accent); }
.form-row { display: grid; grid-template-columns: 1fr 1fr 110px; gap: 12px; }
.form-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.msg { font-size: 13px; }
.msg.ok { color: var(--success); }
.msg.bad { color: var(--error); }
.input-group { display: flex; gap: 8px; }
.input-group .input, .input-group input { flex: 1; }
code { font-family: var(--font-mono); font-size: 12px; background: var(--panel-2); border: 1px solid var(--border-soft); border-radius: 4px; padding: 1px 5px; color: var(--accent); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 32px; }
.login-card .brand { margin-bottom: 26px; }
.login-card h1 { font-size: 18px; margin: 0 0 4px; font-weight: 600; letter-spacing: -0.01em; }
.login-card .hint { margin: 0 0 22px; }
.login-card .error-msg { margin-top: 14px; padding: 0; font-size: 13px; min-height: 18px; }

/* ---------- Admin ---------- */
.admin-grid { display: grid; grid-template-columns: 340px 1fr; gap: 20px; align-items: start; }
.users-grid { display: grid; grid-template-columns: 360px 1fr; gap: 20px; align-items: start; }
.pane { display: none; }
.pane.active { display: block; }
#promptsPane.active { display: grid; grid-template-columns: 340px 1fr; gap: 20px; align-items: start; }
.panel.flush { padding: 0; }
.list { max-height: calc(100vh - 200px); overflow: auto; }
.list-head { padding: 12px 14px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border-soft); position: sticky; top: 0; background: var(--panel); z-index: 1; font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); }
.item { padding: 10px 14px; border-bottom: 1px solid var(--border-soft); cursor: pointer; font-size: 14px; }
.item:last-child { border-bottom: none; }
.item:hover { background: var(--panel-2); }
.item.active { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--accent); }
.item small { display: block; color: var(--text-muted); font-family: var(--font-mono); font-size: 11px; margin-top: 2px; }
.item.off { opacity: .5; }
.stack { padding: 0; }
.stack-title { font-weight: 600; font-size: 15px; margin-bottom: 16px; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
th { font-size: 12px; font-weight: 500; color: var(--text-muted); }
tbody tr:last-child td { border-bottom: none; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 5px; font-family: var(--font-mono); font-size: 11px; }
.badge.admin { background: var(--accent-soft); color: var(--accent); }
.badge.user { background: var(--panel-2); color: var(--text-muted); border: 1px solid var(--border-soft); }
.badge.off { background: var(--error-soft); color: var(--error); }
.badge.on { background: var(--success-soft); color: var(--success); }
.cred { background: var(--success-soft); border: 1px solid #2c3f2c; color: var(--text); padding: 12px 14px; border-radius: 8px; font-size: 13px; margin-top: 14px; word-break: break-all; line-height: 1.6; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }

@media (max-width: 900px) {
  #promptsPane.active, .users-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; gap: 14px; }
}