:root {
  color-scheme: light;
  --bg: #f5f4f1;
  --panel: #ffffff;
  --text: #1e2428;
  --muted: #66737a;
  --line: #d9dedf;
  --accent: #176c64;
  --accent-2: #8a4b28;
  --danger: #b3261e;
  --code: #11191d;
}

* { 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;
}

.shell {
  width: min(1360px, calc(100vw - 260px));
  margin: 0 auto;
  padding: 24px 0 44px;
}

.workbench-subtitle {
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
}

.topbar,
.section-head,
.actions,
.toolbar,
.links,
.status-strip,
.copy-grid {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar,
.section-head,
.status-strip {
  justify-content: space-between;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 28px; line-height: 1.1; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }

h2 small,
h3 small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.eyebrow {
  margin-bottom: 5px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

a {
  color: var(--accent);
  font-weight: 800;
  text-decoration: none;
}

.status-strip {
  margin: 16px 0;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
}

.conceptual-pipeline {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.conceptual-pipeline span {
  padding: 5px 8px;
  border-radius: 4px;
  background: #f0f5f3;
  color: var(--accent);
  font-weight: 800;
}

.conceptual-pipeline b { color: #9aa7a3; }

.execution-trace-section {
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.execution-trace {
  display: grid;
  grid-template-columns: repeat(7, minmax(108px, 1fr));
  gap: 7px;
  overflow-x: auto;
  margin: 13px 0 0;
  padding: 0 0 4px;
  list-style: none;
}

.trace-step {
  position: relative;
  min-height: 74px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafbfa;
}

.trace-step-number {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.trace-step strong { display: block; font-size: 12px; line-height: 1.35; }
.trace-step-status { display: block; margin-top: 6px; font-size: 10px; font-weight: 800; text-transform: uppercase; }
.trace-step.waiting .trace-step-status { color: var(--muted); }
.trace-step.active { border-color: #9bbdb3; background: #eef6f3; }
.trace-step.active .trace-step-status,
.trace-step.success .trace-step-status { color: var(--accent); }
.trace-step.success { border-color: #a8cbbf; background: #f3f8f6; }
.trace-step.blocked,
.trace-step.failed { border-color: #e0aaa5; background: #fdf2f1; }
.trace-step.blocked .trace-step-status,
.trace-step.failed .trace-step-status { color: var(--danger); }
.trace-step.invalidated { border-color: #d8bd92; background: #fff8e9; }
.trace-step.invalidated .trace-step-status { color: #8a5a13; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(430px, 0.9fr);
  gap: 16px;
  align-items: start;
}

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

.input-panel,
.output-panel,
.subsection {
  display: grid;
  gap: 14px;
}

.subsection {
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.grid {
  display: grid;
  gap: 12px;
}

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

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--text);
  background: #fff;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

button {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  padding: 0 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 850;
  cursor: pointer;
}

button.secondary {
  border: 1px solid var(--line);
  background: #f9faf9;
  color: var(--text);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

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

.mode-row label,
.switch {
  display: flex;
  grid-template-columns: unset;
  align-items: center;
  gap: 8px;
}

.mode-row label {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 11px;
  color: var(--text);
  background: #fbfcfc;
}

.mode-row input,
.switch input {
  width: auto;
}

.help,
.message {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.state,
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.toolbar {
  flex-wrap: wrap;
}

.cards-builder {
  display: grid;
  gap: 10px;
}

.builder-card,
.block-row,
.plain-preview,
.error-card,
.metadata dl,
.candidate {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.builder-card {
  padding: 12px;
  display: grid;
  gap: 10px;
}

.builder-card-header,
.block-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.block-row {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.block-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.block-fields .wide {
  grid-column: 1 / -1;
}

.plain-preview {
  margin-top: 12px;
  padding: 12px;
  line-height: 1.55;
}

.recommendation-card {
  display: grid;
  gap: 12px;
}

.recommendation-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.recommendation-head strong { font-size: 16px; }

.recommendation-status {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  border: 1px solid #a8cbbf;
  border-radius: 999px;
  padding: 0 9px;
  background: #e8f2ef;
  color: var(--accent);
  font-size: 11px;
  font-weight: 850;
}

.recommendation-status.blocked {
  border-color: #e0aaa5;
  background: #f9e9e7;
  color: var(--danger);
}

.recommendation-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px 16px;
}

.recommendation-field { min-width: 0; }
.recommendation-field span { display: block; margin-bottom: 3px; color: var(--muted); font-size: 11px; font-weight: 800; }
.recommendation-field code,
.recommendation-field strong { overflow-wrap: anywhere; font-size: 12px; }

.recommendation-list {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12px;
}

.recommendation-next {
  padding: 10px;
  border-left: 3px solid var(--accent);
  background: #eef6f3;
  color: var(--accent-dark);
  font-size: 12px;
}

.recommendation-next.blocked { border-color: var(--danger); background: #fdf2f1; color: var(--danger); }

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

.candidate-list,
.images,
.metadata {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.candidate {
  padding: 11px;
}

.candidate.blocked {
  border-color: #e3aaa5;
}

.candidate dl,
.metadata dl {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 6px 10px;
  margin: 0;
  padding: 10px;
  font-size: 13px;
}

.candidate dt,
.metadata dt {
  color: var(--muted);
  font-weight: 800;
}

.candidate dd,
.metadata dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.json {
  margin: 12px 0 0;
  max-height: 430px;
  overflow: auto;
  padding: 13px;
  border-radius: 8px;
  background: var(--code);
  color: #eef7f2;
  font-size: 12px;
  line-height: 1.5;
}

.error,
.error-card {
  color: var(--danger);
  font-weight: 800;
}

.error-card {
  display: none;
  padding: 12px;
}

.error-card.active {
  display: block;
}

.images {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.images figure {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfc;
}

.images img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 4px;
}

.images figcaption {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.examples {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.result-head {
  margin-top: 18px;
}

.copy-grid {
  flex-wrap: wrap;
  margin-top: 12px;
}

details {
  margin-top: 12px;
}

summary {
  cursor: pointer;
  color: var(--accent-2);
  font-weight: 850;
}

@media (max-width: 980px) {
  .shell { width: min(100% - 28px, 1360px); }
  .layout,
  .grid.two,
  .grid.three,
  .block-fields {
    grid-template-columns: 1fr;
  }

  .topbar { align-items: flex-start; }
  .links { flex-wrap: wrap; justify-content: flex-end; }
}

@media (max-width: 640px) {
  .topbar,
  .section-head,
  .status-strip { align-items: stretch; display: grid; }
  .links { justify-content: flex-start; }
  .execution-trace { grid-template-columns: 1fr; overflow: visible; }
  .recommendation-grid { grid-template-columns: 1fr; }
}
