:root {
  --lc-bg: #fafafa;
  --lc-surface: #ffffff;
  --lc-border: #e5e5e5;
  --lc-muted: #737373;
  --lc-text: #171717;
  --lc-brand: #2563eb;
  --lc-brand-dark: #1d4ed8;
  --lc-success: #15803d;
  --lc-warning: #b45309;
  --lc-danger: #b91c1c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--lc-bg);
  color: var(--lc-text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

a {
  color: inherit;
}

a.table-link,
.back-link,
.link-button {
  color: var(--lc-brand-dark);
  font-weight: 600;
  text-decoration: none;
}

a.table-link:hover,
.back-link:hover,
.link-button:hover {
  text-decoration: underline;
}

.link-button {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.inline-form {
  display: inline;
}

.factory-shell {
  min-height: 100vh;
}

.factory-header {
  background: var(--lc-surface);
  border-bottom: 1px solid var(--lc-border);
}

.factory-header-inner,
.factory-main {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
}

.factory-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  gap: 24px;
}

.factory-brand {
  font-size: 18px;
  font-weight: 700;
  text-decoration: none;
}

.factory-nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 14px;
}

.factory-nav a {
  color: #525252;
  text-decoration: none;
}

.factory-nav a:hover {
  color: var(--lc-brand-dark);
}

.factory-main {
  padding: 28px 0 48px;
}

.page-title {
  margin: 0 0 4px;
  font-size: 28px;
  line-height: 1.2;
}

.page-subtitle {
  margin: 0;
  color: var(--lc-muted);
}

.section {
  margin-top: 24px;
}

.page-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.back-link {
  display: inline-flex;
  margin-bottom: 12px;
  font-size: 14px;
}

.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.card {
  background: var(--lc-surface);
  border: 1px solid var(--lc-border);
  border-radius: 8px;
  padding: 18px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.detail-panel {
  min-width: 0;
  background: var(--lc-surface);
  border: 1px solid var(--lc-border);
  border-radius: 8px;
  padding: 18px;
}

.detail-panel h2 {
  margin: 0 0 14px;
  font-size: 18px;
  line-height: 1.25;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.panel-heading h2,
.panel-heading h3 {
  margin: 0;
  line-height: 1.25;
}

.panel-heading h3 {
  font-size: 16px;
}

.panel-heading p {
  margin: 4px 0 0;
}

.panel-heading.compact {
  align-items: center;
}

.detail-list {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 10px 16px;
  margin: 0;
}

.detail-list dt {
  color: var(--lc-muted);
  font-size: 13px;
  font-weight: 700;
}

.detail-list dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.metric-label {
  margin: 0;
  color: var(--lc-muted);
  font-size: 13px;
}

.metric-value {
  margin: 4px 0 0;
  font-size: 32px;
  font-weight: 700;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric-card {
  min-width: 0;
  border: 1px solid var(--lc-border);
  border-radius: 8px;
  padding: 14px;
  background: #fafafa;
}

.metric-value-small {
  margin: 4px 0 0;
  font-size: 22px;
  font-weight: 800;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.metric-forms,
.related-activity {
  margin-top: 16px;
}

.metric-form {
  min-width: 0;
  border-top: 1px solid var(--lc-border);
  padding-top: 16px;
}

.table-wrap {
  overflow-x: auto;
  background: var(--lc-surface);
  border: 1px solid var(--lc-border);
  border-radius: 8px;
}

.factory-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.factory-table th,
.factory-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--lc-border);
  text-align: left;
  vertical-align: top;
}

.factory-table th {
  color: #525252;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.factory-table tr:last-child td {
  border-bottom: 0;
}

.detail-table {
  font-size: 13px;
}

.detail-table th:first-child,
.detail-table td:first-child {
  padding-left: 0;
}

.detail-table th:last-child,
.detail-table td:last-child {
  padding-right: 0;
}

.clamped {
  max-width: 320px;
  overflow-wrap: anywhere;
}

.code-block,
.markdown-block {
  max-height: 420px;
  overflow: auto;
  margin: 0;
  padding: 14px;
  background: #171717;
  color: #fafafa;
  border-radius: 8px;
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.screenshot-preview {
  display: block;
  width: 100%;
  max-height: 360px;
  object-fit: contain;
  margin-top: 12px;
  border: 1px solid var(--lc-border);
  border-radius: 8px;
  background: #f5f5f5;
}

.factory-form {
  display: grid;
  gap: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
  font-size: 14px;
  font-weight: 700;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--lc-border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--lc-text);
  background: #ffffff;
  font: inherit;
  font-weight: 400;
}

.field textarea {
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--lc-brand);
  outline: 2px solid #bfdbfe;
}

.field-error,
.validation-summary {
  color: var(--lc-danger);
  font-size: 13px;
  font-weight: 600;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.button-primary {
  color: #ffffff;
  background: var(--lc-brand);
  border-color: var(--lc-brand);
}

.button-primary:hover {
  background: var(--lc-brand-dark);
  border-color: var(--lc-brand-dark);
}

.button-secondary {
  color: #404040;
  background: #ffffff;
  border-color: var(--lc-border);
}

.button-secondary:hover {
  background: #f5f5f5;
}

.factory-map-shell {
  background: var(--lc-surface);
  border: 1px solid var(--lc-border);
  border-radius: 8px;
  padding: 18px;
}

.factory-map-loop {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--lc-border);
}

.loop-title {
  margin: 2px 0 0;
  font-size: 22px;
  font-weight: 800;
  line-height: 1.25;
}

.loop-return {
  flex: 0 0 auto;
  border: 1px solid #a7f3d0;
  border-radius: 999px;
  padding: 6px 12px;
  color: #065f46;
  background: #ecfdf5;
  font-size: 13px;
  font-weight: 800;
}

.factory-flow {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: factory-step;
}

.flow-step {
  position: relative;
  min-width: 0;
  min-height: 230px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 1px solid var(--lc-border);
  border-top: 5px solid var(--step-accent, var(--lc-brand));
  border-radius: 8px;
  padding: 16px;
  background: #ffffff;
}

.flow-step::after {
  content: "";
  position: absolute;
  top: 34px;
  right: -11px;
  width: 7px;
  height: 7px;
  border-top: 2px solid #a3a3a3;
  border-right: 2px solid #a3a3a3;
  transform: rotate(45deg);
  background: transparent;
}

.flow-step:nth-child(4)::after,
.flow-step:nth-child(8)::after {
  display: none;
}

.flow-step h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

.flow-step p {
  margin: 0;
  color: #404040;
  font-size: 14px;
}

.step-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  color: #ffffff;
  background: var(--step-accent, var(--lc-brand));
  font-size: 14px;
  font-weight: 800;
}

.artifact-label {
  display: inline-flex;
  align-self: flex-start;
  margin-top: auto;
  border: 1px solid var(--lc-border);
  border-radius: 999px;
  padding: 4px 9px;
  color: #404040;
  background: #fafafa;
  font-size: 12px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.flow-step-intake {
  --step-accent: #2563eb;
}

.flow-step-triage {
  --step-accent: #0f766e;
}

.flow-step-proposal {
  --step-accent: #7c3aed;
}

.flow-step-approve {
  --step-accent: #b45309;
}

.flow-step-spec {
  --step-accent: #be123c;
}

.flow-step-build {
  --step-accent: #4338ca;
}

.flow-step-validate {
  --step-accent: #15803d;
}

.flow-step-release {
  --step-accent: #525252;
}

.factory-lanes {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.lane {
  min-width: 0;
  border-left: 4px solid var(--lc-brand);
  background: var(--lc-surface);
  border-radius: 8px;
  padding: 14px 16px;
  box-shadow: inset 0 0 0 1px var(--lc-border);
}

.lane p:last-child {
  margin: 5px 0 0;
  color: #404040;
  font-size: 14px;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid var(--lc-border);
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.pill-p0,
.pill-danger {
  color: var(--lc-danger);
  background: #fee2e2;
}

.pill-p1,
.pill-warning {
  color: var(--lc-warning);
  background: #fef3c7;
}

.pill-success {
  color: var(--lc-success);
  background: #dcfce7;
}

.muted {
  color: var(--lc-muted);
}

.empty {
  padding: 22px;
  color: var(--lc-muted);
}

@media (max-width: 840px) {
  .factory-header-inner {
    align-items: flex-start;
    flex-direction: column;
    padding: 16px 0;
  }

  .grid-4,
  .grid-2,
  .metric-grid,
  .detail-grid,
  .form-grid,
  .factory-flow,
  .factory-lanes {
    grid-template-columns: 1fr;
  }

  .factory-map-loop {
    align-items: flex-start;
    flex-direction: column;
  }

  .loop-return {
    flex: 1 1 auto;
  }

  .flow-step {
    min-height: 0;
  }

  .flow-step::after {
    top: auto;
    right: 24px;
    bottom: -11px;
    transform: rotate(135deg);
  }

  .flow-step:nth-child(4)::after {
    display: block;
  }

  .flow-step:nth-child(8)::after {
    display: none;
  }

  .detail-header {
    flex-direction: column;
  }

  .detail-list {
    grid-template-columns: 1fr;
  }

  .page-actions,
  .form-actions {
    justify-content: stretch;
  }

  .button {
    width: 100%;
  }
}
