:root {
  color-scheme: light;
  --bg: #f4f5f2;
  --panel: #ffffff;
  --ink: #191c1f;
  --muted: #64706f;
  --line: #d9ded9;
  --soft: #f8f9f6;
  --accent: #0d766e;
  --accent-strong: #084f4b;
  --blue: #2c5d8f;
  --warn: #9a5a14;
  --error: #a33131;
  --shadow: 0 18px 44px rgba(36, 43, 40, 0.12);
  --preview: #171c1f;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

.shell {
  width: min(1320px, calc(100vw - 28px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 20px 0;
  display: flex;
  align-items: stretch;
}

.workspace {
  width: 100%;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 0.76rem;
  font-weight: 750;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 3rem;
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.12rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

h3 {
  margin-bottom: 10px;
  font-size: 0.9rem;
}

.status-pill,
.confidence {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 10px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

.status-pill.is-error,
.confidence.error {
  border-color: rgba(163, 49, 49, 0.32);
  color: var(--error);
}

.confidence.instant,
.confidence.quoted,
.confidence.done,
.confidence.ok {
  border-color: rgba(18, 124, 114, 0.32);
  color: var(--accent-strong);
}

.confidence.needs_review,
.confidence.review,
.confidence.processing {
  border-color: rgba(154, 90, 20, 0.35);
  color: var(--warn);
}

.confidence.blocked {
  border-color: rgba(163, 49, 49, 0.32);
  color: var(--error);
}

.tool-grid {
  display: grid;
  grid-template-columns: minmax(300px, 420px) minmax(0, 1fr);
  gap: 16px;
}

.upload-panel,
.results-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.upload-panel {
  padding: 14px;
}

.drop-zone {
  min-height: 300px;
  border: 1.5px dashed #9db2ac;
  border-radius: 8px;
  background: var(--soft);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    transform 160ms ease;
}

.drop-zone:hover,
.drop-zone.is-dragging {
  border-color: var(--accent);
  background: #eef8f6;
}

.drop-zone.is-loading {
  opacity: 0.72;
}

.drop-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.drop-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #ffffff;
  font-size: 2rem;
  line-height: 1;
}

.drop-title {
  max-width: 100%;
  font-size: 1.06rem;
  font-weight: 760;
  overflow-wrap: anywhere;
}

.drop-meta {
  color: var(--muted);
  font-size: 0.9rem;
}

.controls {
  display: grid;
  grid-template-columns: 0.8fr 1fr 0.7fr;
  gap: 10px;
  margin: 12px 0;
}

.unit-hint {
  min-height: 1.35em;
  margin: -2px 0 12px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

label span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  padding: 0 10px;
}

input[type="range"] {
  height: 24px;
  padding: 0;
  accent-color: var(--accent);
}

.quantity-control {
  display: grid;
  gap: 5px;
}

input:focus,
select:focus,
button:focus-visible,
.drop-zone:focus-within {
  outline: 2px solid rgba(18, 124, 114, 0.28);
  outline-offset: 2px;
}

.primary-button {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 760;
  cursor: pointer;
}

.primary-button:disabled {
  cursor: not-allowed;
  background: #b8c7c3;
}

.secondary-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  padding: 0 12px;
  font-weight: 760;
  cursor: pointer;
}

.secondary-button:hover {
  border-color: rgba(13, 118, 110, 0.42);
  background: #f3fbf8;
}

.results-panel {
  min-height: 620px;
  padding: 18px;
}

.empty-state {
  min-height: 420px;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.empty-state p {
  width: min(34ch, 100%);
  margin-bottom: 0;
}

.result-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.preview-section {
  position: relative;
  border: 1px solid #222b30;
  border-radius: 8px;
  overflow: hidden;
  background: var(--preview);
}

#part-preview {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 260px;
  cursor: grab;
  touch-action: none;
}

#part-preview:active {
  cursor: grabbing;
}

.preview-caption {
  position: absolute;
  left: 10px;
  bottom: 10px;
  max-width: calc(100% - 20px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  padding: 6px 10px;
  background: rgba(13, 18, 20, 0.76);
  color: #e7ecea;
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.route-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfbf8;
}

.route-summary strong {
  display: block;
  font-size: 1.02rem;
}

.route-summary span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.9rem;
}

.process-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.process-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: inherit;
  overflow: hidden;
}

.process-card.is-primary {
  border-color: rgba(13, 118, 110, 0.42);
  background: #f3fbf8;
}

.process-card.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(13, 118, 110, 0.14);
}

.process-card.is-rejected {
  opacity: 0.72;
}

.process-card-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.process-select {
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  padding: 12px;
  text-align: left;
}

.process-select:focus-visible {
  outline-offset: -2px;
}

.process-card h4 {
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.2;
}

.process-title {
  display: block;
  margin: 0;
  font-size: 0.98rem;
  font-weight: 780;
  line-height: 1.2;
}

.process-card p {
  margin-bottom: 9px;
  color: #39423f;
  font-size: 0.88rem;
  line-height: 1.35;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  border: 1px solid #d4d9d3;
  border-radius: 999px;
  padding: 4px 7px;
  background: #fbfbf8;
  color: #3f4947;
  font-size: 0.74rem;
  line-height: 1.2;
}

.chip.is-optional {
  border-color: rgba(44, 93, 143, 0.28);
  color: var(--blue);
}

.process-quote {
  display: grid;
  gap: 3px;
  margin-top: 10px;
  border-top: 1px solid rgba(217, 222, 217, 0.82);
  padding-top: 9px;
}

.process-quote strong {
  font-size: 0.95rem;
  line-height: 1.2;
}

.process-quote span {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.choice-details {
  border-top: 1px solid var(--line);
  background: #fbfbf8;
}

.choice-details summary {
  cursor: pointer;
  padding: 9px 12px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 760;
  overflow-wrap: anywhere;
}

.choice-list {
  display: grid;
  gap: 10px;
  padding: 0 12px 12px;
}

.choice-group {
  display: grid;
  gap: 5px;
}

.choice-label {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 760;
  text-transform: uppercase;
}

.choice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.choice-button {
  min-height: 30px;
  border: 1px solid #d4d9d3;
  border-radius: 999px;
  background: #ffffff;
  color: #3f4947;
  cursor: pointer;
  padding: 4px 9px;
  font-size: 0.78rem;
  font-weight: 700;
}

.choice-button.is-selected {
  border-color: rgba(13, 118, 110, 0.5);
  background: #eaf7f3;
  color: var(--accent-strong);
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.section-heading h3 {
  margin-bottom: 10px;
}

.section-heading span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  overflow-wrap: anywhere;
  text-align: right;
}

.material-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.material-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  overflow: hidden;
}

.material-card.is-recommended {
  border-color: rgba(13, 118, 110, 0.36);
  background: #f6fbf9;
}

.material-card.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(13, 118, 110, 0.14);
}

.material-select {
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  padding: 12px;
  text-align: left;
}

.material-select:focus-visible {
  outline-offset: -2px;
}

.material-card-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.material-card strong {
  display: block;
  font-size: 0.96rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.material-card p {
  margin-bottom: 9px;
  color: #39423f;
  font-size: 0.88rem;
  line-height: 1.35;
}

.fact-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0 0;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0 0;
}

.metric-grid.compact,
.fact-grid.compact {
  margin-top: 0;
}

.metric-grid > div,
.fact-grid > div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #fbfbf8;
}

.metric-label,
dt {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 760;
}

.metric-value,
dd {
  display: block;
  margin: 0;
  min-height: 1.35em;
  font-size: 0.96rem;
  font-weight: 760;
  overflow-wrap: anywhere;
}

.subsection {
  margin-top: 18px;
}

.batch-list {
  display: grid;
  gap: 8px;
}

.batch-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #fbfcfc;
}

.batch-row strong,
.batch-row span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.batch-row span {
  color: var(--muted);
  font-size: 0.82rem;
}

.batch-row.is-error {
  border-color: rgba(163, 49, 49, 0.32);
}

.issues {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.issues li {
  border-left: 3px solid var(--warn);
  padding: 8px 10px;
  background: #fff8ef;
  color: #503314;
  overflow-wrap: anywhere;
}

.artifacts {
  display: grid;
  gap: 8px;
}

.artifacts div {
  display: grid;
  grid-template-columns: 90px minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
  color: var(--muted);
  font-size: 0.86rem;
}

code,
pre {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

code {
  color: var(--ink);
  overflow-wrap: anywhere;
}

.artifacts-details,
.raw-json {
  margin-top: 18px;
}

.artifacts-details summary,
.raw-json summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

pre {
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: #101817;
  color: #d9f0ea;
  font-size: 0.78rem;
}

@media (max-width: 840px) {
  .shell {
    align-items: stretch;
    padding: 18px 0;
  }

  .topbar,
  .result-head {
    align-items: start;
    flex-direction: column;
  }

  .tool-grid,
  .controls,
  .metric-grid,
  .fact-grid,
  .process-list,
  .material-list,
  .route-summary {
    grid-template-columns: 1fr;
  }

  .section-heading {
    align-items: start;
    flex-direction: column;
    gap: 0;
  }

  .section-heading span {
    text-align: left;
  }

  .drop-zone {
    min-height: 220px;
  }

  .artifacts div {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .batch-row {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 2.45rem;
  }
}
