:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #66727f;
  --border: #d7dde3;
  --brand: #1d4f73;
  --brand-dark: #153a55;
  --danger: #9f1d1d;
  --ok: #1f6f43;
  --warn: #96610a;
}

* {
  box-sizing: border-box;
}

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

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

a:hover {
  text-decoration: underline;
}

.topbar {
  align-items: center;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 24px;
  justify-content: space-between;
  min-height: 64px;
  padding: 0 32px;
}

.brand {
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
}

.nav {
  align-items: center;
  display: flex;
  gap: 18px;
}

.nav form {
  margin: 0;
}

.credit-badge {
  background: #eef4f7;
  border: 1px solid #d4e2ea;
  border-radius: 999px;
  color: var(--brand-dark);
  font-size: 13px;
  font-weight: 700;
  padding: 5px 10px;
}

.credit-badge-empty {
  background: #fdecec;
  border-color: #e0a3a3;
  color: var(--danger);
}

.link-button {
  background: none;
  border: 0;
  color: var(--brand);
  cursor: pointer;
  font: inherit;
  padding: 0;
}

.page {
  margin: 0 auto;
  max-width: 1180px;
  padding: 32px;
}

.narrow {
  margin: 0 auto;
  max-width: 480px;
}

.wide {
  max-width: 980px;
}

h1,
h2 {
  letter-spacing: 0;
  margin: 0 0 12px;
}

h1 {
  font-size: 30px;
}

h2 {
  font-size: 18px;
}

.muted,
.empty {
  color: var(--muted);
}

.messages {
  display: grid;
  gap: 10px;
  margin-bottom: 20px;
}

.message {
  background: #eaf2f8;
  border: 1px solid #c9ddec;
  border-radius: 6px;
  padding: 12px 14px;
}

.message.error {
  background: #fdecec;
  border-color: #f1bcbc;
}

.section-head {
  align-items: flex-start;
  display: flex;
  gap: 24px;
  justify-content: space-between;
  margin-bottom: 22px;
}

.panel,
.form-panel,
.table-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
}

.form-panel,
.form-grid {
  display: grid;
  gap: 18px;
}

.form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.full {
  grid-column: 1 / -1;
}

.advanced-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 18px;
}

label {
  display: grid;
  gap: 6px;
  font-weight: 650;
}

.label-row {
  align-items: center;
  display: inline-flex;
  gap: 6px;
}

label.check {
  align-items: center;
  display: flex;
  flex-direction: row-reverse;
  gap: 10px;
  justify-content: flex-end;
}

input,
select,
textarea {
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  padding: 10px 12px;
  width: 100%;
}

input[type="checkbox"] {
  height: 18px;
  width: 18px;
}

button,
.button {
  background: var(--brand);
  border: 1px solid var(--brand);
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-weight: 700;
  justify-content: center;
  padding: 10px 14px;
}

button.small {
  padding: 6px 10px;
}

button.danger {
  background: #fff;
  border-color: #e0a3a3;
  color: var(--danger);
}

button:disabled {
  cursor: progress;
  opacity: 0.65;
}

.button.secondary {
  background: #fff;
  color: var(--brand);
}

.actions {
  align-items: center;
  display: flex;
  gap: 16px;
}

.actions-inline {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.row-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.row-actions form {
  margin: 0;
}

.submit-progress {
  align-items: center;
  color: var(--muted);
  display: none;
  gap: 8px;
}

.is-submitting .submit-progress {
  display: inline-flex;
}

.spinner {
  animation: spin 0.8s linear infinite;
  border: 2px solid #c9ddec;
  border-top-color: var(--brand);
  border-radius: 999px;
  height: 18px;
  width: 18px;
}

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

.field-error {
  color: var(--danger);
  font-size: 14px;
  font-weight: 500;
}

.field-help {
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
}

.info-bubble {
  align-items: center;
  background: #eef4f7;
  border: 1px solid #c7d8e4;
  border-radius: 999px;
  color: var(--brand-dark);
  cursor: help;
  display: inline-flex;
  font-size: 11px;
  font-weight: 800;
  height: 18px;
  justify-content: center;
  line-height: 1;
  position: relative;
  width: 18px;
}

.info-bubble::after {
  background: #1f2933;
  border-radius: 6px;
  bottom: calc(100% + 8px);
  color: #fff;
  content: attr(aria-label);
  display: none;
  font-size: 12px;
  font-weight: 500;
  left: 50%;
  line-height: 1.35;
  max-width: min(280px, 80vw);
  min-width: 180px;
  padding: 8px 10px;
  position: absolute;
  transform: translateX(-50%);
  white-space: normal;
  z-index: 10;
}

.info-bubble:hover::after,
.info-bubble:focus::after {
  display: block;
}

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

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 12px 10px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
}

th.numeric,
td.numeric {
  text-align: center;
}

.credit-pill {
  background: #eef4f7;
  border: 1px solid #d4e2ea;
  border-radius: 999px;
  color: var(--brand-dark);
  display: inline-flex;
  font-size: 13px;
  font-weight: 800;
  justify-content: center;
  min-width: 56px;
  padding: 5px 10px;
}

.credit-pill-empty {
  background: #d62626;
  border-color: #b71313;
  color: #fff;
}

.status {
  border-radius: 999px;
  display: inline-flex;
  font-size: 13px;
  font-weight: 700;
  padding: 4px 9px;
}

.status-uploaded,
.status-queued,
.status-running {
  background: #fff4db;
  color: var(--warn);
}

.status-succeeded {
  background: #e7f5ec;
  color: var(--ok);
}

.status-failed,
.status-cancelled,
.status-expired {
  background: #fdecec;
  color: var(--danger);
}

.status-line {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

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

.job-panel {
  background: #f9fbfc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
}

.job-panel + .job-panel {
  margin-top: 30px;
}

.file-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  padding: 12px;
}

.file-card-plan {
  background: #e8f7ed;
  border-color: #7fbd92;
  box-shadow: inset 0 0 0 1px #b9dfc5;
  order: -1;
}

.file-card-reference {
  background: #f7fafc;
}

.inline-delete-form {
  margin: 0 0 0 auto;
}

.file-card img {
  aspect-ratio: 4 / 3;
  background: #fff;
  border: 1px solid var(--border);
  object-fit: contain;
  width: 100%;
}

.image-preview-button {
  background: transparent;
  border: 0;
  border-radius: 0;
  color: inherit;
  display: block;
  padding: 0;
}

.image-preview-button:hover img {
  border-color: var(--brand);
}

.file-card span {
  color: var(--muted);
  display: block;
  font-size: 14px;
}

.error-box {
  background: #fff7f7;
  border: 1px solid #f1bcbc;
  border-radius: 6px;
  color: var(--danger);
  overflow: auto;
  padding: 12px;
}

summary {
  cursor: pointer;
  font-weight: 700;
}

.preview-modal {
  border: 0;
  border-radius: 8px;
  max-height: 90vh;
  max-width: min(1100px, 92vw);
  padding: 20px;
  width: 92vw;
}

.preview-modal::backdrop {
  background: rgba(18, 29, 38, 0.55);
}

.preview-modal img {
  background: #fff;
  border: 1px solid var(--border);
  display: block;
  max-height: 76vh;
  object-fit: contain;
  width: 100%;
}

.preview-header {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: auto 1fr auto;
  margin-bottom: 12px;
}

.preview-header h2 {
  margin: 0;
  text-align: center;
}

.preview-nav {
  align-items: center;
  background: #fff;
  border-color: var(--border);
  color: var(--brand);
  font-size: 28px;
  height: 42px;
  line-height: 1;
  padding: 0;
  width: 42px;
}

.modal-close {
  background: #fff;
  color: var(--brand);
  float: right;
}

@media (max-width: 760px) {
  .topbar,
  .section-head,
  .nav {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    padding: 18px;
  }

  .page {
    padding: 18px;
  }

  .form-grid,
  .advanced-grid {
    grid-template-columns: 1fr;
  }
}
