* { box-sizing: border-box; }

:root {
  --orange: #ff9500;
  --orange-dim: #cc7800;
  --bg: #0a0a0a;
  --panel: #161616;
  --panel-border: #2a2a2a;
  --field-bg: #1e1e1e;
  --field-border: #3a3a3a;
  --text: #f2f2f2;
  --text-muted: #9a9a9a;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

.muted { color: var(--text-muted); font-size: 14px; }

.error { color: #ff6b5e; font-size: 14px; }

/* Login screen */

#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  padding: 32px;
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
  width: 320px;
  text-align: center;
}

.login-mark {
  height: 56px;
  margin: 0 auto;
  display: block;
}

/* Real text, not a rasterized image — renders crisply at any size and
   never looks "broken"/pixelated the way baking the wordmark into an SVG
   text element did at small dimensions. */
.brand-text {
  font-size: 22px;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.01em;
}

.brand-text .brand-s { color: var(--orange); }

.login-brand-text {
  font-size: 28px;
  margin: 4px 0 12px;
}

.login-card input {
  width: 100%;
  margin: 16px 0;
  padding: 10px 12px;
  border: 1px solid var(--field-border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--field-bg);
  color: var(--text);
}

.login-card input::placeholder { color: var(--text-muted); }

/* App shell */

.topbar {
  background: #000;
  color: var(--text);
  padding: 10px 24px;
  border-bottom: 1px solid var(--panel-border);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
}

.topbar-mark {
  height: 24px;
  display: block;
  justify-self: start;
}

.topbar-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  justify-self: center;
  text-align: center;
  white-space: nowrap;
}

/* Compact read/edit widget in the header's top-right corner — same data
   as before, just shrunk down so it doesn't compete for attention with the
   trigger form. */

.topbar-billing {
  display: flex;
  gap: 8px;
  justify-self: end;
}

.mini-billing-card {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
}

.mini-billing-card .mini-provider {
  color: var(--text-muted);
  font-weight: 600;
}

.mini-billing-card .mini-balance {
  color: #fff;
  font-weight: 700;
}

.mini-billing-card.low .mini-balance { color: #ff6b5e; }

.mini-billing-card input[type="number"] {
  width: 64px;
  font-size: 11px;
  padding: 3px 5px;
  background: var(--field-bg);
  border: 1px solid var(--field-border);
  color: var(--text);
  border-radius: 4px;
}

.mini-billing-card button {
  padding: 3px 7px;
  font-size: 11px;
}

.layout {
  max-width: 1200px;
  margin: 24px auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.panel h2 {
  font-size: 16px;
  margin: 0 0 16px;
  color: var(--text);
}

/* Form — laid out horizontally: one row of fields, wrapping on narrow
   screens, with the scope checkboxes + submit button on their own row
   underneath. */

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
  margin-bottom: 16px;
}

.form-row label {
  display: flex;
  flex-direction: column;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  flex: 1 1 170px;
  min-width: 170px;
}

.form-row-bottom {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.scope-block { flex: 1 1 320px; }

.scope-title {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}

#run-form input[type="text"],
#run-form select {
  width: 100%;
  margin-top: 6px;
  padding: 9px 10px;
  border: 1px solid var(--field-border);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 400;
  color: var(--text);
  background: var(--field-bg);
}

#run-form input[type="text"]::placeholder { color: var(--text-muted); }

.row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.row.space-between {
  justify-content: space-between;
  align-items: center;
}

.row select {
  flex: 1;
}

.checkbox-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 8px;
}

.checkbox-row .checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 400;
  font-size: 14px;
  color: var(--text);
}

.checkbox-row input {
  width: auto;
  margin: 0;
  accent-color: var(--orange);
}

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 700;
  background: var(--orange);
  color: #1a1000;
}

button:hover:not(:disabled) { background: #ffa726; }

button:disabled {
  opacity: 0.5;
  cursor: default;
}

button.secondary {
  background: var(--field-bg);
  color: var(--text);
  border: 1px solid var(--field-border);
  padding: 8px 12px;
  font-weight: 600;
}

button.secondary:hover:not(:disabled) { border-color: var(--orange); color: var(--orange); background: var(--field-bg); }

button.small {
  padding: 6px 10px;
  font-size: 12px;
}

button.approve { background: #2fa14a; color: #fff; }
button.reject { background: #d94f42; color: #fff; }

#run-status {
  margin-top: 12px;
  font-size: 14px;
}

#run-status.success { color: #4fd67a; }
#run-status.error { color: #ff6b5e; }

/* Validation */

#run-form input.invalid,
#run-form select.invalid {
  border-color: #ff6b5e;
  background: #2a1512;
}

#run-form .checkbox-row.invalid {
  border-color: #ff6b5e;
  background: #2a1512;
}

/* Runs table */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--panel-border);
  color: var(--text);
}

th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #1f1f1f; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 14px;
}

.pagination button:disabled {
  opacity: 0.4;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.badge-queued { background: #2a2a2a; color: #cfcfcf; }
.badge-processing { background: #4a2f00; color: var(--orange); }
.badge-done { background: #143d22; color: #4fd67a; }
.badge-error { background: #3d1512; color: #ff6b5e; }
.badge-skipped { background: #2a2a2a; color: #9a9a9a; }

/* Gallery */

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

.gallery-item {
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--field-bg);
}

.gallery-item img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  background: #0a0a0a;
}

.gallery-item .meta {
  padding: 8px;
  font-size: 12px;
}

.gallery-item .meta .subtype {
  font-weight: 600;
  display: block;
  margin-bottom: 4px;
  color: var(--text);
}

.gallery-item .actions {
  display: flex;
  gap: 6px;
  padding: 0 8px 8px;
}

/* Billing */

.billing-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.billing-card {
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 16px;
  background: var(--field-bg);
}

.billing-card h3 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--text);
}

.billing-card .balance {
  font-size: 24px;
  font-weight: 700;
  margin: 4px 0;
  color: var(--text);
}

.billing-card .balance.low { color: #ff6b5e; }

.billing-card .checkpoint {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.billing-card .update-row {
  display: flex;
  gap: 8px;
}

.billing-card .update-row input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--field-border);
  border-radius: 8px;
  font-size: 13px;
  background: var(--panel);
  color: var(--text);
}

/* Progress overlay — shown after "Start generation" is clicked, polls
   /api/runs/:id/progress and animates the ring via stroke-dashoffset. */

.progress-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.progress-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 36px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-width: 260px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
}

.progress-ring-wrap {
  position: relative;
  width: 160px;
  height: 160px;
}

.progress-ring {
  width: 160px;
  height: 160px;
  transform: rotate(-90deg);
}

.progress-ring-bg {
  fill: none;
  stroke: var(--field-bg);
  stroke-width: 10;
}

.progress-ring-fill {
  fill: none;
  stroke: var(--orange);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 326.7;
  stroke-dashoffset: 326.7;
  transition: stroke-dashoffset 0.5s ease;
}

.progress-ring-fill.error { stroke: #ff6b5e; }

.progress-percent {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 800;
  color: var(--text);
}

.progress-label {
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
  max-width: 260px;
}
