:root {
  color-scheme: dark;
  --bg: oklch(0.17 0.012 178);
  --surface: oklch(0.235 0.012 178);
  --surface-muted: oklch(0.285 0.014 178);
  --surface-strong: oklch(0.35 0.016 178);
  --ink: oklch(0.91 0.012 178);
  --muted: oklch(0.69 0.018 178);
  --line: oklch(0.39 0.016 178);
  --line-strong: oklch(0.51 0.02 178);
  --accent: oklch(0.68 0.118 166);
  --accent-strong: oklch(0.75 0.13 166);
  --accent-soft: oklch(0.33 0.052 166);
  --warning: oklch(0.78 0.13 74);
  --warning-soft: oklch(0.31 0.05 74);
  --success: oklch(0.72 0.11 151);
  --success-soft: oklch(0.31 0.05 151);
  --danger: oklch(0.72 0.14 28);
  --danger-soft: oklch(0.31 0.045 28);
  --code-bg: oklch(0.145 0.014 178);
  --code-ink: oklch(0.88 0.018 178);
  --shadow: 0 18px 42px color-mix(in oklch, oklch(0.08 0.01 178) 52%, transparent);
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  font-size: 16px;
  font-kerning: normal;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 19px;
  line-height: 1.18;
  letter-spacing: 0;
}

h2 {
  font-size: 19px;
  line-height: 1.18;
  letter-spacing: 0;
}

h3 {
  font-size: 15px;
  line-height: 1.25;
}

.skip-link {
  position: fixed;
  inset-block-start: var(--s3);
  inset-inline-start: var(--s3);
  z-index: 20;
  min-height: 44px;
  transform: translateY(-180%);
  border-radius: 8px;
  background: var(--ink);
  color: var(--surface);
  padding: 11px var(--s3);
}

.skip-link:focus {
  transform: translateY(0);
}

.logout-button {
  position: fixed;
  inset-block-start: var(--s4);
  inset-inline-end: var(--s4);
  z-index: 25;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
  color: var(--ink);
  padding: 8px 13px;
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
}

.logout-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-strong);
}

.auth-page {
  display: grid;
  place-items: center;
  padding: var(--s5);
}

.auth-shell {
  width: min(420px, 100%);
}

.auth-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: var(--s6);
}

.auth-copy {
  margin-top: var(--s3);
  color: var(--muted);
  line-height: 1.45;
}

.auth-form {
  display: grid;
  gap: var(--s4);
  margin-top: var(--s5);
}

.auth-error {
  border: 1px solid color-mix(in oklch, var(--danger) 70%, transparent);
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--ink);
  padding: var(--s3);
  font-size: 14px;
}

.eyebrow {
  margin: 0 0 var(--s1);
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted);
  padding: 6px 11px;
  font-size: 13px;
  font-weight: 750;
  white-space: nowrap;
}

.status-pill.success {
  border-color: color-mix(in oklch, var(--success) 26%, transparent);
  background: var(--success-soft);
  color: var(--success);
}

.status-pill.error {
  border-color: color-mix(in oklch, var(--danger) 26%, transparent);
  background: var(--danger-soft);
  color: var(--danger);
}

.status-pill.running {
  border-color: color-mix(in oklch, var(--accent) 26%, transparent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.status-pill.stale {
  border-color: color-mix(in oklch, var(--warning) 32%, transparent);
  background: var(--warning-soft);
  color: var(--warning);
}

.workbench {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-areas:
    "rail rail"
    "source candidates"
    "bom bom";
  gap: var(--s4);
  align-items: stretch;
  width: min(1900px, calc(100vw - 32px));
  margin: 0 auto;
  padding-block: var(--s4);
}

.run-rail,
.source-desk,
.candidate-board,
.bom-board {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.run-rail {
  grid-area: rail;
  align-self: stretch;
}

.source-desk {
  grid-area: source;
}

.candidate-board {
  grid-area: candidates;
}

.bom-board {
  container-type: inline-size;
  grid-area: bom;
}

.run-form,
.source-desk,
.candidate-board,
.bom-board {
  display: grid;
}

.run-form {
  grid-template-columns:
    minmax(170px, 0.72fr)
    minmax(140px, 0.55fr)
    minmax(190px, 0.75fr)
    minmax(230px, 0.95fr)
    minmax(220px, 0.9fr)
    minmax(280px, 0.9fr);
  gap: var(--s4);
  align-items: end;
  padding: var(--s4) var(--s5);
}

.rail-section,
.field,
.source-choice,
.file-source,
.requirement-editor {
  display: grid;
  gap: var(--s2);
  min-width: 0;
}

.rail-section {
  align-self: center;
}

.field span,
.source-choice > span,
.requirement-editor span,
.upload-label {
  color: var(--ink);
  font-size: 13px;
  font-weight: 750;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
  color: var(--ink);
  outline: none;
}

input,
select {
  height: 46px;
  padding: 0 var(--s3);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='14' height='14' viewBox='0 0 14 14' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M3.5 5.25L7 8.75L10.5 5.25' fill='none' stroke='%2398aaa6' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-position: calc(100% - 19px) 50%;
  background-repeat: no-repeat;
  background-size: 14px 14px;
  padding-inline-end: 44px;
}

input::placeholder,
textarea::placeholder {
  color: color-mix(in oklch, var(--muted) 82%, transparent);
}

textarea {
  min-height: 360px;
  resize: none;
  padding: var(--s4);
  line-height: 1.48;
}

input:focus,
select:focus,
textarea:focus,
.source-upload:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--accent) 18%, transparent);
}

button:focus {
  outline: none;
}

button:focus-visible,
.skip-link:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.source-toggle-button:focus-visible,
.file-clear-button:focus-visible,
.candidate-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.source-toggle {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s1);
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
  padding: var(--s1);
}

.source-toggle-button {
  min-height: 36px;
  cursor: pointer;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 0 var(--s3);
  font-size: 14px;
  font-weight: 760;
}

.source-toggle-button:hover {
  color: var(--ink);
}

.source-toggle-button.active {
  background: var(--accent);
  color: var(--surface);
}

.file-input-row {
  position: relative;
  display: block;
  width: 100%;
  min-width: 0;
}

.source-upload {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-width: 0;
  min-height: 46px;
  gap: var(--s2);
  overflow: hidden;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--surface-muted);
  padding: 0 40px;
  text-align: center;
  transition:
    border-color 170ms ease,
    background-color 170ms ease;
}

.source-upload span {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-upload .upload-label {
  flex: 0 1 auto;
}

.source-upload .upload-meta {
  flex: 0 1 auto;
}

.source-upload .upload-meta::before {
  content: "/";
  margin-inline-end: var(--s2);
  color: var(--line-strong);
}

.source-upload:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.source-upload.is-inactive {
  border-style: solid;
  opacity: 0.58;
}

.source-upload.is-inactive:hover {
  border-color: var(--line-strong);
  background: var(--surface-muted);
}

.source-upload.is-inactive input {
  cursor: not-allowed;
}

.source-upload.error {
  border-color: color-mix(in oklch, var(--danger) 54%, transparent);
  background: var(--danger-soft);
}

.source-upload.error .upload-meta {
  color: var(--danger);
}

.source-upload input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  opacity: 0;
}

.file-clear-button {
  position: absolute;
  inset-block-start: 50%;
  inset-inline-end: 10px;
  z-index: 2;
  display: block;
  width: 26px;
  height: 26px;
  min-height: 26px;
  padding: 0;
  transform: translateY(-50%);
  cursor: pointer;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 0;
  line-height: 0;
}

.file-clear-button::before,
.file-clear-button::after {
  content: "";
  position: absolute;
  inset-block-start: 50%;
  inset-inline-start: 50%;
  width: 12px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  transform: translate(-50%, -50%) rotate(45deg);
}

.file-clear-button::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.file-clear-button:hover {
  background: color-mix(in oklch, var(--danger-soft) 78%, transparent);
  color: var(--danger);
}

.upload-meta {
  color: var(--muted);
  font-size: 13px;
  font-style: normal;
}

.requirement-editor.is-inactive span {
  color: var(--muted);
}

.requirement-editor.is-inactive textarea,
textarea:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

.form-error,
.error-box {
  border: 1px solid color-mix(in oklch, var(--danger) 28%, transparent);
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  padding: var(--s3);
}

.form-error {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  border: 0;
  padding: 0;
  white-space: nowrap;
}

.run-actions {
  display: grid;
  gap: var(--s2);
}

.run-actions {
  grid-template-columns: minmax(150px, 1fr) minmax(112px, 0.62fr);
}

.review-actions {
  display: flex;
  grid-column: 5 / -1;
  flex-wrap: wrap;
  gap: var(--s2);
  align-items: center;
  justify-content: flex-end;
  padding-block-start: var(--s3);
  border-block-start: 1px solid var(--line);
}

.review-actions .secondary-button {
  flex: 0 0 auto;
}

.review-save-status {
  flex: 1 0 100%;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  text-align: right;
}

.review-save-status:empty {
  display: none;
}

.review-save-status.success {
  color: var(--success);
}

.review-save-status.error {
  color: var(--danger);
}

.duration-hint {
  grid-column: 1 / -1;
  margin-block-end: var(--s1);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.primary-button,
.secondary-button,
.candidate-build-button,
.tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  cursor: pointer;
  border-radius: 8px;
  padding: 0 var(--s4);
  text-align: center;
  font-weight: 760;
  white-space: nowrap;
  transition:
    background-color 170ms ease,
    border-color 170ms ease,
    color 170ms ease,
    transform 170ms ease;
}

.primary-button {
  background: var(--accent);
  color: var(--surface);
}

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button,
.tab {
  border: 1px solid var(--line);
  background: var(--surface-muted);
  color: var(--ink);
}

.secondary-button:hover,
.tab:hover {
  border-color: var(--line-strong);
  background: var(--surface-strong);
}

.primary-button:active,
.secondary-button:active,
.tab:active {
  transform: translateY(1px);
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.contract-list {
  display: grid;
  gap: var(--s1);
  margin: 0;
  align-self: center;
  padding-inline-start: var(--s3);
  border-inline-start: 1px solid var(--line);
}

.contract-list div {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr);
  gap: var(--s2);
}

.contract-list dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.contract-list dd {
  margin: 0;
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-desk {
  grid-template-rows: auto minmax(0, 1fr);
  min-height: clamp(560px, 62vh, 760px);
  overflow: hidden;
}

.desk-header,
.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s4);
}

.desk-header {
  min-width: 0;
  padding: var(--s5);
  border-block-end: 1px solid var(--line);
}

.requirement-editor {
  min-height: 0;
  height: calc(100% - var(--s5) * 2);
  margin: var(--s5);
}

.requirement-editor textarea {
  height: 100%;
  min-height: 0;
}

.candidate-board,
.bom-board {
  align-content: start;
  overflow: hidden;
}

.candidate-board {
  grid-template-rows: auto minmax(0, 1fr);
  min-height: clamp(560px, 62vh, 760px);
}

.candidate-board > .empty-state {
  min-height: 0;
  height: calc(100% - var(--s5) * 2);
}

.panel-header {
  min-width: 0;
  padding: var(--s5);
  border-block-end: 1px solid var(--line);
}

.panel-header > div {
  min-width: 0;
}

.panel-header .status-pill {
  flex: 0 0 auto;
}

.panel-header h2 {
  overflow-wrap: anywhere;
}

.candidate-content,
.tab-panel {
  padding: var(--s5);
}

.phase-summary,
.result-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: calc(var(--s5) * -1) calc(var(--s5) * -1) var(--s5);
  border-block-end: 1px solid var(--line);
  background: var(--surface-muted);
}

.phase-summary span,
.result-summary span {
  display: grid;
  gap: var(--s1);
  min-width: 0;
  border-inline-end: 1px solid var(--line);
  padding: var(--s3) var(--s4);
}

.phase-summary span:last-child,
.result-summary span:last-child {
  border-inline-end: 0;
}

.phase-summary b,
.result-summary b {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.phase-summary em,
.result-summary em {
  overflow: hidden;
  font-size: 14px;
  font-style: normal;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bom-totals {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--s3);
  margin-block: calc(var(--s5) * -0.35) var(--s4);
}

.bom-totals span {
  display: grid;
  gap: var(--s1);
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
  padding: var(--s3) var(--s4);
}

.bom-totals span.needs-check {
  border-color: color-mix(in oklch, var(--warning) 30%, transparent);
  background: var(--warning-soft);
}

.bom-totals b {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.bom-totals em {
  color: var(--ink);
  font-size: 15px;
  font-style: normal;
  font-weight: 760;
  font-variant-numeric: tabular-nums;
}

.empty-state {
  display: grid;
  min-height: 300px;
  place-content: center;
  gap: var(--s2);
  margin: var(--s5);
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--surface-muted);
  color: var(--muted);
  padding: var(--s5);
  text-align: center;
}

.run-step-state {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--s4);
  align-items: center;
  min-height: 180px;
  margin: var(--s5);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
  color: var(--muted);
  padding: var(--s5);
}

.run-step-state[data-state="ready"],
.run-step-state[data-state="declined"] {
  border-color: color-mix(in oklch, var(--warning) 24%, transparent);
  background: var(--warning-soft);
}

.run-step-state[data-state="building"] {
  border-color: color-mix(in oklch, var(--accent) 24%, transparent);
  background: var(--accent-soft);
}

.run-step-state h3 {
  grid-column: 1;
  color: var(--ink);
  font-size: 18px;
}

.run-step-state .empty-kicker {
  grid-column: 1;
}

.run-step-state p:not(.empty-kicker) {
  grid-column: 1;
  max-width: 68ch;
  margin-block-start: var(--s2);
  font-size: 14px;
  line-height: 1.45;
}

.run-step-actions {
  display: grid;
  grid-column: 2;
  grid-row: 1 / span 3;
  gap: var(--s2);
  align-self: center;
  justify-items: end;
  min-width: 240px;
}

.run-step-actions span {
  max-width: 42ch;
  color: var(--ink);
  font-size: 13px;
  font-weight: 720;
  line-height: 1.4;
  text-align: right;
}

.empty-state h3 {
  color: var(--ink);
  font-size: 18px;
}

.empty-kicker {
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 780;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.candidate-list {
  display: grid;
  gap: var(--s3);
}

.candidate-card {
  display: grid;
  gap: var(--s3);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: var(--s4);
  transition:
    border-color 170ms ease,
    background 170ms ease,
    opacity 170ms ease;
}

.candidate-card:hover:not(.is-disabled),
.candidate-card.selected,
.candidate-card.is-building {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.candidate-card.is-built {
  border-color: color-mix(in oklch, var(--success) 42%, transparent);
}

.candidate-card.is-disabled {
  opacity: 0.58;
}

.candidate-card:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--accent) 18%, transparent);
}

.candidate-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--s3);
  align-items: start;
}

.candidate-card strong,
.candidate-card em {
  display: block;
}

.candidate-card strong {
  font-size: 16px;
}

.candidate-card em {
  color: var(--muted);
  font-size: 13px;
  font-style: normal;
  line-height: 1.35;
}

.candidate-status {
  min-height: 26px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted);
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 760;
  white-space: nowrap;
}

.candidate-card.is-building .candidate-status {
  border-color: color-mix(in oklch, var(--accent) 34%, transparent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.candidate-card.is-built .candidate-status {
  border-color: color-mix(in oklch, var(--success) 32%, transparent);
  background: var(--success-soft);
  color: var(--success);
}

.candidate-card dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s2);
  margin: 0;
}

.candidate-card dl div {
  display: grid;
  gap: var(--s1);
}

.candidate-card dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.candidate-card dd {
  margin: 0;
  font-size: 13px;
}

.candidate-review,
.line-review-check {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 32px;
  gap: var(--s2);
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  font-weight: 760;
  line-height: 1.2;
  user-select: none;
  -webkit-user-select: none;
}

.candidate-review {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-muted);
  padding: 5px 10px;
  transition:
    border-color 150ms ease,
    background 150ms ease,
    color 150ms ease;
}

.candidate-review:hover {
  border-color: color-mix(in oklch, var(--danger) 36%, var(--line));
  background: color-mix(in oklch, var(--danger-soft) 42%, var(--surface-muted));
}

.candidate-review:has(input:checked) {
  border-color: color-mix(in oklch, var(--danger) 58%, transparent);
  background: var(--danger-soft);
  color: var(--danger);
}

.candidate-review input,
.line-review-check input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--danger);
  cursor: pointer;
}

.candidate-review:focus-within,
.line-review-check:focus-within {
  border-radius: 999px;
  outline: 3px solid color-mix(in oklch, var(--accent) 18%, transparent);
  outline-offset: 2px;
}

.candidate-notes {
  display: grid;
  gap: var(--s2);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.38;
}

.candidate-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--s3);
  justify-content: flex-end;
  border-block-start: 1px solid var(--line);
  padding-block-start: var(--s3);
}

.candidate-action-hint {
  grid-column: 1 / -1;
  min-width: 0;
  max-width: 58ch;
  color: var(--ink);
  font-size: 13px;
  font-weight: 740;
  line-height: 1.4;
}

.candidate-build-button {
  grid-column: 2;
  justify-self: end;
  min-width: 154px;
  border: 1px solid color-mix(in oklch, var(--accent) 56%, transparent);
  background: var(--accent);
  color: var(--surface);
  font-weight: 820;
  transition:
    border-color 170ms ease,
    background 170ms ease,
    color 170ms ease,
    opacity 170ms ease;
}

.candidate-build-button:hover:not(:disabled) {
  background: var(--accent-strong);
}

.candidate-build-button:disabled {
  cursor: not-allowed;
  opacity: 0.72;
}

.tabbar {
  display: flex;
  gap: var(--s2);
  padding: var(--s3) var(--s5);
  border-block-end: 1px solid var(--line);
}

.tab.active {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--surface);
}

.tab-panel {
  min-height: 0;
  overflow: auto;
}

.review-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--s4);
  align-items: start;
  padding: var(--s4) var(--s5);
  border-block-end: 1px solid var(--line);
  background: var(--surface-muted);
}

.review-checks {
  display: grid;
  gap: var(--s2);
}

.review-check {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--s3);
  align-items: start;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: var(--s3);
}

.review-check input,
.review-reasons input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.review-check input {
  margin-block-start: 2px;
}

.review-check b,
.review-comment span {
  display: block;
  color: var(--ink);
  font-size: 13px;
  font-weight: 760;
}

.review-check em {
  display: block;
  margin-block-start: var(--s1);
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  line-height: 1.35;
}

.review-reasons {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
  min-width: 0;
  margin: 0;
  border: 0;
  padding: 0;
}

.review-reasons legend {
  flex: 0 0 100%;
  margin-block-end: var(--s1);
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.review-reasons label {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  gap: var(--s2);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  padding: 6px 10px;
  font-size: 13px;
  line-height: 1.25;
}

.review-comment {
  display: grid;
  gap: var(--s2);
}

.review-comment textarea {
  min-height: 78px;
  resize: vertical;
  padding: var(--s3);
  font-size: 14px;
  line-height: 1.42;
}

.error-box {
  margin: var(--s3) var(--s5) 0;
}

.warning-list {
  display: grid;
  gap: var(--s2);
  margin-block-start: var(--s4);
  border: 1px solid color-mix(in oklch, var(--warning) 26%, transparent);
  border-radius: 8px;
  background: var(--warning-soft);
  padding: var(--s4) var(--s5) var(--s4) var(--s6);
}

.warning-title {
  color: var(--warning);
  font-size: 13px;
  font-weight: 760;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.warning-list ul {
  display: grid;
  gap: var(--s2);
  margin: 0;
  padding-inline-start: var(--s4);
}

.warning-list li {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.42;
}

.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
  justify-content: flex-end;
  margin-block: 0 var(--s4);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

table {
  width: 100%;
  min-width: 1490px;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
}

.bom-col-review {
  width: 96px;
}

.bom-col-section {
  width: 132px;
}

.bom-col-category {
  width: 176px;
}

.bom-col-pn {
  width: 210px;
}

.bom-col-qty {
  width: 72px;
}

.bom-col-s4b {
  width: 190px;
}

.bom-col-price,
.bom-col-total {
  width: 120px;
}

th,
td {
  border-block-end: 1px solid var(--line);
  padding: var(--s3);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
  overflow-wrap: anywhere;
  word-break: normal;
}

tbody td {
  min-width: 0;
}

th:not(:last-child),
td:not(:last-child) {
  border-inline-end: 1px solid var(--line);
}

th {
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

th:first-child {
  text-align: center;
  white-space: nowrap;
}

tbody td {
  background: var(--row-bg, var(--surface));
}

.bom-review-cell {
  background: color-mix(in oklch, var(--surface-muted) 72%, var(--row-bg, var(--surface))) !important;
  text-align: center;
  vertical-align: middle;
}

.bom-review-cell .line-review-check {
  justify-content: center;
  width: 100%;
  min-height: 28px;
}

td code,
.html-preview code,
.debug-preview,
.bom-record code {
  font-family: "Cascadia Mono", Consolas, monospace;
}

td code,
.bom-record code {
  font-size: 12px;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.bom-main-row {
  --row-bg: var(--surface);
}

.bom-main-row.s4b-not_found {
  --row-bg: color-mix(in oklch, var(--danger-soft) 54%, var(--surface));
}

.section-cell {
  min-width: 0;
}

.section-chip,
.s4b-badge {
  display: inline-block;
  justify-self: start;
  width: fit-content;
  max-width: 100%;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 760;
  line-height: 1.15;
}

.section-chip {
  border: 1px solid var(--line);
  background: var(--surface-muted);
  color: var(--muted);
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
  text-align: center;
}

.s4b-badge {
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
}

.s4b-cell {
  min-width: 150px;
}

.s4b-cell,
.alternative-s4b {
  display: grid;
  justify-items: start;
  gap: var(--s1);
}

.s4b-cell small,
.alternative-s4b small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.s4b-badge.found {
  background: var(--success-soft);
  color: var(--success);
}

.s4b-badge.not_found {
  background: var(--danger-soft);
  color: var(--danger);
}

.s4b-badge.needs_check {
  background: var(--warning-soft);
  color: var(--warning);
}

.qty-cell,
.money-cell,
.alternative-money {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.bom-description {
  min-width: 260px;
  max-width: 500px;
  overflow-wrap: anywhere;
  line-height: 1.42;
}

.bom-alternative-row td {
  background: color-mix(in oklch, var(--surface-muted) 74%, var(--surface));
  padding-block: 0;
}

.alternative-details {
  padding: var(--s2) 0 var(--s3);
}

.alternative-details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
}

.alternative-details summary:hover {
  color: var(--ink);
}

.alternative-list {
  display: grid;
  gap: var(--s2);
  margin-block-start: var(--s2);
}

.alternative-item {
  display: grid;
  grid-template-columns: 130px 54px minmax(260px, 1fr) minmax(150px, 0.45fr) minmax(100px, auto);
  gap: var(--s3);
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: var(--s2) var(--s3);
}

.alternative-qty {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.alternative-description {
  overflow-wrap: anywhere;
  line-height: 1.38;
}

.bom-mobile {
  display: none;
}

.html-preview,
.debug-preview {
  min-height: 420px;
  margin: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--code-bg);
  color: var(--code-ink);
  padding: var(--s4);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.html-preview {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
}

.html-preview code {
  border: 1px solid color-mix(in oklch, var(--code-ink) 18%, transparent);
  border-radius: 5px;
  background: color-mix(in oklch, var(--code-ink) 8%, transparent);
  padding: 1px 5px;
}

[hidden] {
  display: none !important;
}

@container (max-width: 620px) {
  .run-step-state {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .run-step-state .empty-kicker,
  .run-step-state h3,
  .run-step-state p:not(.empty-kicker),
  .run-step-actions {
    grid-column: 1;
    grid-row: auto;
  }

  .run-step-actions {
    align-self: stretch;
    justify-items: stretch;
    min-width: 0;
  }

  .run-step-actions span {
    max-width: none;
    text-align: left;
  }
}

@media (max-width: 1320px) {
  .workbench {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas:
      "rail rail"
      "source candidates"
      "bom bom";
  }

  .run-form {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .review-actions {
    grid-column: 2 / -1;
  }

  .rail-section {
    align-self: end;
  }

  .contract-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-column: 1 / -1;
    border-block-start: 1px solid var(--line);
    border-inline-start: 0;
    padding-block-start: var(--s3);
    padding-inline-start: 0;
  }
}

@media (max-width: 980px) {
  .workbench {
    grid-template-columns: 1fr;
    grid-template-areas:
      "rail"
      "source"
      "candidates"
      "bom";
  }

  .run-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .run-actions {
    grid-column: 1 / -1;
  }

  .review-actions {
    grid-column: 1 / -1;
  }

  .source-desk,
  .candidate-board {
    min-height: auto;
  }

  .source-desk {
    grid-template-rows: auto auto;
  }

  .requirement-editor {
    height: auto;
  }

  .requirement-editor textarea {
    height: 360px;
    min-height: 360px;
  }
}

@media (max-width: 820px) {
  .workbench {
    width: min(100vw - 20px, 1640px);
  }

  .workbench {
    grid-template-columns: 1fr;
    grid-template-areas:
      "rail"
      "source"
      "candidates"
      "bom";
  }

  .source-desk {
    min-height: auto;
  }

  .run-form {
    grid-template-columns: 1fr;
  }

  .contract-list {
    grid-template-columns: 1fr;
  }

  textarea,
  .requirement-editor textarea {
    height: 260px;
    min-height: 260px;
  }

  .desk-header,
  .panel-header {
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .run-actions {
    grid-template-columns: 1fr;
  }

  .review-actions {
    justify-content: stretch;
  }

  .review-actions .secondary-button {
    flex: 1 1 150px;
  }

  .review-save-status {
    min-width: 100%;
    text-align: left;
  }

  .phase-summary,
  .result-summary,
  .bom-totals,
  .review-panel {
    grid-template-columns: 1fr;
  }

  .run-step-state {
    grid-template-columns: 1fr;
    margin: var(--s4);
    padding: var(--s4);
  }

  .run-step-actions {
    justify-items: stretch;
    min-width: 0;
  }

  .run-step-actions span {
    max-width: none;
    text-align: left;
  }

  .export-actions {
    justify-content: stretch;
  }

  .export-actions .secondary-button {
    flex: 1 1 160px;
  }

  .phase-summary span,
  .result-summary span {
    border-inline-end: 0;
    border-block-end: 1px solid var(--line);
  }

  .phase-summary span:last-child,
  .result-summary span:last-child {
    border-block-end: 0;
  }

  .candidate-card dl {
    grid-template-columns: 1fr;
  }

  .candidate-heading {
    grid-template-columns: 1fr;
  }

  .candidate-actions {
    align-items: stretch;
  }

  .candidate-action-hint {
    margin-inline-end: 0;
    max-width: none;
  }

  .candidate-build-button {
    grid-column: 1 / -1;
    justify-self: stretch;
    width: 100%;
  }

  .tabbar {
    overflow-x: auto;
  }

  .table-wrap {
    display: none;
  }

  .bom-mobile {
    display: grid;
    gap: var(--s3);
  }

  .bom-record {
    display: grid;
    gap: var(--s1);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-muted);
    padding: var(--s3);
  }

  .bom-record .alternative-details {
    margin-block-start: var(--s2);
  }

  .bom-record .line-review-check {
    margin-block-end: var(--s1);
  }

  .bom-record .line-review-check span {
    color: var(--ink);
    font-size: 13px;
    font-weight: 760;
  }

  .alternative-item {
    grid-template-columns: 1fr;
    gap: var(--s1);
  }

  .alternative-money {
    text-align: left;
  }

  .bom-record span,
  .bom-record em {
    color: var(--muted);
    font-size: 12px;
    font-style: normal;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
