:root {
  color-scheme: light;
  --sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;

  --bg: #f5f2eb;
  --surface: #fcfbf7;
  --surface-recessed: #ede9df;
  --surface-stripe: #f7f4ec;
  --surface-hover: #e7e2d6;

  --ink: #1f2120;
  --ink-secondary: #434644;
  --muted: #5e615e;

  --border: #d9d4c7;
  --border-strong: #b4aea0;
  --rule-dark: #2a2d2b;

  --accent: #c94712;
  --accent-hover: #a9390c;
  --accent-text: #b83d0b;
  --accent-tint: #f8ece6;

  --ok: #2d6a4f;
  --danger: #a62626;
  --danger-bg: #fbf0ee;
  --danger-border: #e2b8b2;

  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
}

p, h1, h2, h3 {
  margin: 0;
}

button, input, select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.primary:disabled {
  background: var(--surface-recessed);
  border-color: var(--border-strong);
  color: var(--muted);
  opacity: 1;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Top navigation bar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 1180px;
  min-height: 54px;
  padding: 8px 24px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.brand svg {
  color: var(--accent);
  flex-shrink: 0;
}

.brand-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.025em;
  color: var(--ink);
}

.brand-tag {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  border-left: 1px solid var(--border-strong);
  padding-left: 9px;
}

/* Three-step workflow rail */
.workflow-rail {
  display: flex;
  align-items: center;
  gap: 6px;
}

.step-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  border: 1px solid transparent;
  border-radius: 2px;
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

.step-pill:hover {
  background: var(--surface-recessed);
  color: var(--ink);
}

.step-num {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
}

.step-pill.is-active {
  background: var(--accent-tint);
  border-color: var(--accent);
  color: var(--ink);
}

.step-pill.is-active .step-num {
  color: var(--accent-text);
}

.step-pill.is-complete {
  color: var(--ink);
  border-color: var(--border);
  background: var(--bg);
}

.step-pill.is-complete .step-num {
  color: var(--ok);
}

.step-sep {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--border-strong);
  user-select: none;
}

.local {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.local-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
}

/* Main editorial layout */
main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 32px 24px 56px;
}

.masthead {
  padding-bottom: 20px;
  border-bottom: 2px solid var(--rule-dark);
  margin-bottom: 24px;
}

.masthead-eyebrow {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-text);
  font-weight: 600;
  margin-bottom: 8px;
}

.masthead-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 32px;
}

h1 {
  font-size: clamp(28px, 3.6vw, 38px);
  line-height: 1.06;
  letter-spacing: -0.035em;
  font-weight: 700;
  color: var(--ink);
}

.masthead-lead {
  color: var(--ink-secondary);
  font-size: 14px;
  max-width: 52ch;
}

/* Sequential workflow stages */
.workflow {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 20px;
}

.stage {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  scroll-margin-top: 72px;
}

.stage.is-active {
  border-color: var(--border-strong);
}

.stage-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.stage-title-group {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
}

.stage-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 24px;
  padding: 0 6px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  border: 1px solid var(--border-strong);
  border-radius: 2px;
  color: var(--muted);
  background: var(--bg);
  flex-shrink: 0;
  margin-top: 1px;
}

.stage.is-active .stage-index {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.stage.is-complete .stage-index {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--surface);
}

.stage h2 {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.015em;
  color: var(--ink);
}

.stage-subtitle {
  margin-top: 2px;
  font-size: 13px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.status-pill {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-secondary);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 4px 9px;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}

.stage-body {
  min-width: 0;
  padding: 18px 20px 20px;
}

#distribution-results {
  min-width: 0;
}

/* Buttons */
.primary {
  border: 1px solid var(--accent);
  border-radius: 2px;
  background: var(--accent);
  color: #fff;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

.primary:disabled {
  transition: none;
}

.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.secondary {
  border: 1px solid var(--border-strong);
  border-radius: 2px;
  background: var(--surface);
  color: var(--ink);
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  transition: background-color 120ms ease, border-color 120ms ease;
}

.secondary:hover:not(:disabled) {
  background: var(--surface-recessed);
  border-color: var(--ink-secondary);
}

.quiet {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--surface);
  color: var(--accent-text);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.quiet:hover:not(:disabled) {
  background: var(--accent-tint);
  border-color: var(--accent);
}

/* Step 01: Dropzone */
.upload {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px 20px;
  padding: 14px 16px;
  border: 1px dashed var(--border-strong);
  border-radius: 2px;
  background: var(--bg);
  transition: background-color 120ms ease, border-color 120ms ease;
}

.upload.is-dragging {
  background: var(--accent-tint);
  border-color: var(--accent);
  border-style: solid;
}

.upload-lead {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.upload-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--surface);
  color: var(--accent-text);
  flex-shrink: 0;
}

.upload-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.upload-hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 1px;
}

.upload-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* Subsections & empty/error states */
.subsection-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
  margin-top: 18px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.subsection-bar h3 {
  font-size: 12px;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: var(--ink);
}

.subsection-note {
  font-size: 12px;
  color: var(--muted);
}

.empty {
  padding: 24px 16px;
  margin-top: 12px;
  border-left: 2px solid var(--border-strong);
  background: var(--bg);
  color: var(--muted);
  font-size: 13px;
}

.error {
  margin-top: 12px;
  padding: 10px 14px;
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  border-left: 3px solid var(--danger);
  border-radius: 2px;
  color: var(--danger);
  font-size: 13px;
  font-weight: 500;
  overflow-wrap: anywhere;
}

/* Compact readable tables */
.table-region {
  margin-top: 12px;
  max-width: 100%;
  overflow: auto;
  max-height: 360px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--surface);
}

.table-region:focus-visible {
  outline-offset: -2px;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  text-align: left;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

th, td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  overflow-wrap: break-word;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-recessed);
  border-bottom: 1px solid var(--border-strong);
  font-weight: 650;
  font-size: 12px;
  color: var(--ink);
  white-space: nowrap;
}

td {
  white-space: pre-wrap;
  word-break: normal;
  color: var(--ink-secondary);
}

tbody tr:nth-child(even) td {
  background: var(--surface-stripe);
}

tbody tr:hover td {
  background: var(--surface-hover);
  color: var(--ink);
}

tbody tr:last-child td {
  border-bottom: 0;
}

/* Step 02: Configure form grid */
.config-grid {
  display: grid;
  grid-template-columns: minmax(120px, 0.7fr) repeat(3, minmax(0, 1fr)) auto;
  gap: 14px;
  align-items: end;
}

.field {
  min-width: 0;
}

.field label {
  display: block;
  margin-bottom: 5px;
  font-size: 11px;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  color: var(--ink-secondary);
}

.field input,
.field select {
  width: 100%;
  height: 34px;
  border: 1px solid var(--border-strong);
  border-radius: 2px;
  background: var(--surface);
  color: var(--ink);
  padding: 5px 9px;
  font-size: 13px;
}

.field input {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.field input:invalid {
  border-color: var(--danger);
}

.field-action {
  display: flex;
  align-items: flex-end;
}

.distribute {
  height: 34px;
}

/* Step 03: KPI summary ledger */
.metrics-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--bg);
}

.metric-cell {
  padding: 12px 16px;
  border-right: 1px solid var(--border);
}

.metric-cell:last-child {
  border-right: 0;
}

.metric-label {
  font-family: var(--mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}

.metric-value {
  margin-top: 4px;
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.metric-value.is-balanced {
  color: var(--ok);
}

.metric-detail {
  margin-top: 3px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Step 03: Workload comparison chart */
.chart-block {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--surface);
}

.chart-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.chart-header h3 {
  font-family: var(--mono);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: var(--ink);
}

.chart-subtitle {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  font-size: 11.5px;
  color: var(--ink-secondary);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  display: inline-block;
  width: 12px;
  height: 6px;
  border-radius: 1px;
}

.swatch-units {
  background: var(--accent);
}

.swatch-orders {
  background: var(--ink-secondary);
  height: 3px;
}

.swatch-avg {
  width: 2px;
  height: 12px;
  border-left: 2px dashed var(--ink);
}

.workload-chart {
  padding: 10px 16px 14px;
}

.chart-scale-row {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr) 210px;
  gap: 14px;
  align-items: center;
  padding-bottom: 6px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chart-scale-axis {
  position: relative;
  display: flex;
  justify-content: space-between;
  font-variant-numeric: tabular-nums;
}

.chart-avg-tag {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  color: var(--ink);
  font-weight: 700;
  background: var(--surface);
  padding: 0 4px;
  white-space: nowrap;
}

.chart-stats-header {
  display: grid;
  grid-template-columns: 1fr 54px 66px;
  gap: 8px;
  text-align: right;
}

.chart-row {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr) 210px;
  gap: 14px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--surface-recessed);
}

.chart-row:last-child {
  border-bottom: 0;
}

.chart-worker {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.worker-code {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 5px;
  border: 1px solid var(--border-strong);
  border-radius: 2px;
  background: var(--bg);
  color: var(--ink);
  flex-shrink: 0;
}

.chart-worker-name {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chart-tracks {
  position: relative;
  display: grid;
  gap: 4px;
  padding: 2px 0;
}

.chart-track {
  position: relative;
  width: 100%;
  background: var(--surface-recessed);
  border-radius: 1px;
  overflow: hidden;
}

.chart-track-units {
  height: 11px;
}

.chart-track-orders {
  height: 4px;
}

.chart-bar-units {
  height: 100%;
  background: var(--accent);
}

.chart-bar-orders {
  height: 100%;
  background: var(--ink-secondary);
}

.chart-avg-line {
  position: absolute;
  top: -1px;
  bottom: -1px;
  width: 0;
  border-left: 1.5px dashed var(--ink);
  pointer-events: none;
  z-index: 2;
}

.chart-stats {
  display: grid;
  grid-template-columns: 1fr 54px 66px;
  gap: 8px;
  align-items: baseline;
  text-align: right;
  font-family: var(--mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.chart-stat-units {
  font-weight: 700;
  color: var(--ink);
}

.chart-stat-share {
  color: var(--muted);
}

.chart-stat-orders {
  color: var(--ink-secondary);
}

.chart-row.is-idle .worker-code,
.chart-row.is-idle .chart-worker-name,
.chart-row.is-idle .chart-stat-units,
.chart-row.is-idle .chart-stat-orders {
  color: var(--muted);
}

/* Step 03: Worker manifest list */
.assignment-list {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--surface);
}

.assignment {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
}

.assignment:last-child {
  border-bottom: 0;
}

.assignment-heading {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px 16px;
}

.assignment-title-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.assignment h4 {
  margin: 0;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink);
}

.assignment-meta {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

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

.assignment details {
  margin-top: 8px;
}

.assignment summary {
  cursor: pointer;
  color: var(--accent-text);
  font-size: 12.5px;
  font-weight: 600;
  width: fit-content;
  user-select: none;
}

.assignment summary:hover {
  text-decoration: underline;
}

.assignment .table-region {
  margin-top: 10px;
  max-height: 280px;
}

.manifest-pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 12px;
}

#assignments-title, #assignment-error { scroll-margin-top: 72px; }

.assignment-idle {
  background: var(--bg);
}

/* Responsive adjustments */
@media (max-width: 960px) {
  .config-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .field-action {
    grid-column: 1 / -1;
  }

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

  .metric-cell:nth-child(2) {
    border-right: 0;
  }

  .metric-cell:nth-child(1),
  .metric-cell:nth-child(2) {
    border-bottom: 1px solid var(--border);
  }
}

@media (max-width: 760px) {
  .stage, #assignments-title, #assignment-error { scroll-margin-top: 112px; }
  .topbar-inner {
    flex-wrap: wrap;
    padding: 10px 16px;
    gap: 10px 12px;
  }

  .brand-tag {
    display: none;
  }

  .workflow-rail {
    order: 3;
    width: 100%;
    justify-content: space-between;
    padding-top: 8px;
    border-top: 1px solid var(--border);
  }

  .step-pill {
    flex: 1;
    justify-content: center;
    padding: 5px 6px;
  }

  main {
    padding: 24px 16px 44px;
  }

  .stage-header,
  .stage-body {
    padding-left: 16px;
    padding-right: 16px;
  }

  .chart-scale-row {
    display: none;
  }

  .chart-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 6px;
    padding: 10px 0;
  }

  .chart-stats {
    grid-template-columns: auto auto auto;
    justify-content: start;
    text-align: left;
    gap: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

@media (max-width: 540px) {
  .step-sep {
    display: none;
  }

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

  .metrics-strip {
    grid-template-columns: minmax(0, 1fr);
  }

  .metric-cell {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .metric-cell:last-child {
    border-bottom: 0;
  }

  .upload-actions {
    width: 100%;
  }

  .upload-actions button {
    flex: 1;
  }

  .distribute {
    width: 100%;
  }
}
