:root {
  --bg: #000000;
  --bg-soft: #0a0a0a;
  --ink: #f2f2f2;
  --muted: #9a9a9a;
  --line: #2a2a2a;
  --panel: #0d0d0d;
  --accent: #ff003c;
  --accent-soft: #ff335f;
  --accent-glow: rgba(255, 0, 60, 0.45);
  --error: #ff6b6b;
  --radius: 14px;
  --font: "DM Sans", sans-serif;
  /* Fixed height for both IO cards — change only this value to resize both */
  --io-card-height: 420px;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(700px 360px at 15% -8%, rgba(255, 0, 60, 0.18) 0%, transparent 55%),
    radial-gradient(560px 300px at 100% 8%, rgba(255, 0, 60, 0.08) 0%, transparent 50%),
    var(--bg);
}

a {
  color: var(--accent-soft);
  text-decoration: none;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
}

.auth-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow:
    0 0 0 1px rgba(255, 0, 60, 0.08),
    0 18px 40px rgba(0, 0, 0, 0.55);
  padding: 1.75rem 1.5rem 1.85rem;
}

.brand {
  margin: 0 0 0.35rem;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  text-shadow: 0 0 12px var(--accent-glow);
  text-align: center;
}

.brand-left {
  text-align: left;
}

.auth-card h1 {
  margin: 0 0 1.5rem;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  text-align: center;
  color: #fff;
}

.auth-form {
  display: grid;
  gap: 1rem;
}

.field {
  display: grid;
  gap: 0.4rem;
  position: relative;
}

.field label,
.field-label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
}

input[type="email"],
input[type="password"],
input[type="text"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
  color: var(--ink);
  padding: 0.7rem 0.8rem;
  font: inherit;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input::placeholder,
textarea::placeholder {
  color: #666;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 0, 60, 0.2), 0 0 18px rgba(255, 0, 60, 0.15);
}

select option,
select optgroup {
  background: #111;
  color: var(--ink);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  padding: 0.85rem 1rem;
  cursor: pointer;
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-primary {
  width: 100%;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  box-shadow: 0 0 20px var(--accent-glow);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-soft);
  box-shadow: 0 0 28px rgba(255, 0, 60, 0.65);
}

.btn-outline {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
}

.btn-outline:hover:not(:disabled) {
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 0 16px rgba(255, 0, 60, 0.2);
}

.btn-sm {
  padding: 0.55rem 0.9rem;
  font-size: 0.85rem;
  width: auto;
}

.btn-auto {
  width: auto;
  min-width: 140px;
}

.error {
  margin-bottom: 1rem;
  color: #ffb3b3;
  background: #1a0508;
  border: 1px solid rgba(255, 0, 60, 0.45);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  box-shadow: 0 0 16px rgba(255, 0, 60, 0.15);
  font-size: 0.9rem;
}

.field-error {
  color: var(--error);
  font-size: 0.82rem;
}

.navbar {
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(12px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.navbar-inner {
  width: min(1600px, calc(100% - 3rem));
  margin: 0 auto;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.navbar-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  color: inherit;
}

.navbar-mark {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 14px var(--accent-glow);
}

.navbar-title {
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #fff;
}

.navbar-right {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.navbar-user {
  color: var(--muted);
  font-size: 0.88rem;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dashboard {
  width: min(1600px, calc(100% - 3rem));
  margin: 0 auto;
  padding: 1.75rem 0 3rem;
}

.page-intro {
  margin-bottom: 1.25rem;
}

.page-intro h1 {
  margin: 0;
  font-size: clamp(1.4rem, 2.4vw, 1.85rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  color: #fff;
}

.page-intro .muted,
.empty-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.empty-hint {
  font-size: 0.88rem;
  padding: 0.35rem 0.15rem;
}

.workflow-panel {
  display: grid;
  gap: 1.25rem;
}

.io-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.25rem;
  /* both columns same height — driven by the fixed card height */
  align-items: start;
}

.io-column {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  align-items: center;
}

/* ── Fixed-size IO card — never grows, never shrinks ─────────────────────── */
.io-card {
  width: 100%;
  /* hard fixed height — content clips inside, card never resizes */
  height: var(--io-card-height);
  min-height: var(--io-card-height);
  max-height: var(--io-card-height);
  overflow: hidden;
  position: relative; /* anchor for the inset loader */
}

/* override panel-block grid for io-card so children stack via flex */
.io-card.panel-block {
  display: flex;
  flex-direction: column;
}

.btn-io {
  width: min(220px, 100%);
}

.btn-io.is-disabled {
  opacity: 0.45;
  pointer-events: none;
  box-shadow: none;
}

.output-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 0.85rem;
  overflow: hidden;
}

.output-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.25rem;
  align-items: stretch;
}

.control-card {
  /* stretch already handled by align-items: stretch above */
}

.panel-block {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow:
    0 0 0 1px rgba(255, 0, 60, 0.08),
    0 18px 40px rgba(0, 0, 0, 0.55);
  padding: 1.35rem 1.5rem 1.5rem;
  display: grid;
  gap: 1rem;
  min-height: 0;
}

.panel-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
  text-shadow: 0 0 10px rgba(255, 0, 60, 0.35);
}

.file-drop {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
  cursor: pointer;
  padding: 1rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.file-drop[hidden] {
  display: none;
}

.file-drop:hover {
  border-color: var(--accent);
  box-shadow: 0 0 18px rgba(255, 0, 60, 0.15);
}

.file-drop-text {
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.image-preview-wrap {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-soft);
}

.image-preview-wrap[hidden] {
  display: none;
}

.image-preview-wrap img {
  display: block;
  width: 100%;
  max-height: 280px;
  object-fit: contain;
}

/* input body: stacks file-drop and preview in the same slot, fixed height */
.input-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.input-body .file-drop {
  flex: 1;
  min-height: 0;
}

.input-body .image-preview-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.input-body .image-preview-wrap[hidden] {
  display: none;
}

.input-body .image-preview-wrap img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* ── Gallery ─────────────────────────────────────────────────────────────── */

.gallery-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  flex: 1;
  min-height: 0;
}

.gallery-viewer {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
  flex: 1;
  min-height: 0;
}

.gallery-image-wrap {
  flex: 1;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  /* needed so the absolute empty-state is contained */
  position: relative;
}

.gallery-image-wrap img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* hide broken-image icon when no src is set */
.gallery-image-wrap img:not([src]),
.gallery-image-wrap img[src=""] {
  display: none;
}

.gallery-nav {
  flex-shrink: 0;
  align-self: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.gallery-nav:hover:not(:disabled) {
  border-color: var(--accent);
  box-shadow: 0 0 14px rgba(255, 0, 60, 0.25);
}

.gallery-nav:disabled {
  opacity: 0.25;
  cursor: not-allowed;
}

.gallery-nav-arrow {
  width: 0;
  height: 0;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
}

.gallery-nav-arrow--left {
  border-right: 8px solid var(--muted);
  margin-right: 2px;
}

.gallery-nav-arrow--right {
  border-left: 8px solid var(--muted);
  margin-left: 2px;
}

.gallery-nav:hover:not(:disabled) .gallery-nav-arrow--left {
  border-right-color: var(--accent-soft);
}

.gallery-nav:hover:not(:disabled) .gallery-nav-arrow--right {
  border-left-color: var(--accent-soft);
}

.gallery-counter {
  margin: 0;
  text-align: center;
  font-size: 0.82rem;
  color: var(--muted);
  letter-spacing: 0.04em;
}

/* ── Image-type collapsible dropdown ─────────────────────────────────────── */

.multidd-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.multidd-trigger:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 0, 60, 0.15);
}

.multidd-trigger[aria-expanded="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 0, 60, 0.2), 0 0 18px rgba(255, 0, 60, 0.15);
}

.multidd-arrow {
  flex-shrink: 0;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--muted);
  transition: transform 0.15s ease;
}

.multidd-trigger[aria-expanded="true"] .multidd-arrow {
  transform: rotate(180deg);
  border-top-color: var(--accent-soft);
}

.multidd-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 20;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.multidd-panel[hidden] {
  display: none;
}

.multidd-list {
  display: grid;
  gap: 0;
  max-height: 220px;
  overflow-y: auto;
  padding: 0.4rem;
}

.multi-option {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink);
  font-size: 0.93rem;
  transition: background 0.1s ease;
}

.multi-option:hover {
  background: rgba(255, 0, 60, 0.08);
}

.multi-option input {
  accent-color: var(--accent);
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}

.prompt-table-wrap {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-soft);
}

.prompt-table {
  width: 100%;
  border-collapse: collapse;
}

.prompt-table th,
.prompt-table td {
  padding: 0.9rem 1rem;
  text-align: left;
  vertical-align: middle;
}

.prompt-table thead th {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--line);
}

.prompt-table .col-expand {
  width: 88px;
  text-align: right;
}

.prompt-row {
  border-bottom: 1px solid var(--line);
}

.prompt-row.is-open {
  background: rgba(255, 0, 60, 0.06);
}

.prompt-name-cell {
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
}

.prompt-action-cell {
  text-align: right;
}

.expand-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.expand-btn:hover {
  border-color: var(--accent);
  box-shadow: 0 0 14px rgba(255, 0, 60, 0.2);
}

.expand-arrow {
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--muted);
  transition: transform 0.15s ease, border-top-color 0.15s ease;
}

.prompt-row.is-open .expand-arrow {
  transform: rotate(180deg);
  border-top-color: var(--accent-soft);
}

.prompt-detail-row td {
  padding: 0;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.prompt-detail-cell {
  padding: 0.9rem 1rem 1rem !important;
}

.prompt-editor {
  min-height: 160px;
  resize: vertical;
  line-height: 1.5;
}

/* ── Card-level loader (inside output card) ──────────────────────────────── */

.card-loader {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  background: rgba(8, 0, 2, 0.93);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  text-align: center;
  padding: 2rem 1.25rem;
  overflow: hidden;
  z-index: 10;
}

.card-loader[hidden] {
  display: none;
}

.card-loader-starfield {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(6px);
}

.modal-overlay[hidden] {
  display: none !important;
}

.modal-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow:
    0 0 0 1px rgba(255, 0, 60, 0.1),
    0 24px 50px rgba(0, 0, 0, 0.65);
  padding: 1.4rem 1.35rem 1.35rem;
}

.modal-card h3 {
  margin: 0 0 0.55rem;
  color: #fff;
  font-size: 1.15rem;
}

.modal-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.modal-actions {
  margin-top: 1.25rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.7rem;
}

.card-loader-starfield,
.starfield {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.star {
  position: absolute;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 8px rgba(255, 0, 60, 0.9);
  animation: twinkle linear infinite;
}

.loader-core {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid rgba(255, 0, 60, 0.25);
  border-top-color: var(--accent);
  box-shadow: 0 0 28px var(--accent-glow);
  animation: spin 1s linear infinite;
  z-index: 1;
}

.loader-text {
  margin: 0.75rem 0 0;
  color: #fff;
  font-weight: 600;
  z-index: 1;
}

.loader-subtext {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  z-index: 1;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes twinkle {
  0%,
  100% {
    opacity: 0.15;
    transform: scale(0.7);
  }
  50% {
    opacity: 1;
    transform: scale(1.25);
  }
}

/* ── Input card header (title + remove button) ───────────────────────────── */

.io-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 1.6rem;
}

.remove-image-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
  flex-shrink: 0;
}

.remove-image-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 10px rgba(255, 0, 60, 0.25);
}

.remove-image-btn[hidden] {
  display: none;
}

/* ── Output empty state — centred inside the image box ───────────────────── */

.output-empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  text-align: center;
  padding: 1rem;
  pointer-events: none;
}

.output-empty-state p {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.output-empty-icon {
  width: 44px;
  height: 44px;
  color: var(--muted);
  opacity: 0.35;
}

.output-empty-state[hidden] {
  display: none;
}

@media (max-width: 980px) {
  .io-grid,
  .controls-grid {
    grid-template-columns: 1fr;
  }

  .navbar-inner,
  .dashboard {
    width: calc(100% - 1.5rem);
  }

  .navbar-user {
    display: none;
  }

  .btn-io {
    width: 100%;
  }

  .multidd-list {
    max-height: 180px;
  }
}
