:root {
  --bg: #f3f4f1;
  --panel: #ffffff;
  --panel-soft: #f8f8f5;
  --ink: #20231f;
  --muted: #70766c;
  --line: #dfe2da;
  --green: #2f7d46;
  --blue: #3454d1;
  --red: #b42318;
  --amber: #a16207;
  --shadow: 0 18px 60px rgba(32, 35, 31, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

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

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #fbfbf8;
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand span,
.label,
.panel-header span,
#statusText {
  color: var(--muted);
  font-size: 13px;
}

.mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: white;
  font-weight: 700;
  border-radius: 8px;
}

nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
}

.nav-item:not(:disabled):hover {
  background: #f0f3ec;
  border-color: #dfe8da;
  color: #384033;
  cursor: pointer;
}

.nav-item.active {
  background: #eef3eb;
  color: var(--green);
  border-color: #d5e3cf;
}

.state-block {
  margin-top: auto;
  display: grid;
  gap: 8px;
}

code {
  display: block;
  max-width: 100%;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #485044;
  font-size: 12px;
}

.workspace {
  padding: 24px;
  min-width: 0;
}

.analysis-layout {
  display: grid;
  grid-template-columns: minmax(340px, 0.75fr) minmax(420px, 1.25fr);
  gap: 16px;
  align-items: start;
}

.analysis-form {
  display: grid;
  gap: 16px;
}

.analysis-form textarea {
  min-height: 220px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
}

.form-help,
.muted-copy {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.run-result-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 16px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--panel-soft);
}

.run-result-card h2 {
  margin: 8px 0 5px;
}

.run-result-card p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.score-block,
.grade-card {
  display: grid;
  place-items: center;
  min-width: 68px;
  border: 1px solid #d5e3cf;
  border-radius: 8px;
  background: #f3f8f1;
  padding: 10px;
}

.score-block strong,
.grade-card strong {
  color: var(--green);
  font-size: 24px;
}

.score-block span,
.grade-card span {
  color: var(--muted);
  font-size: 11px;
}

.status-pill {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  border-radius: 999px;
  background: #eef3eb;
  color: var(--green);
  padding: 4px 8px;
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.02em;
  overflow-wrap: anywhere;
}

.loading-card {
  border: 1px dashed #aeb7a8;
  border-radius: 8px;
  padding: 20px;
  color: var(--muted);
  background: var(--panel-soft);
}

.reports-layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.34fr) minmax(0, 0.66fr);
  gap: 16px;
  align-items: start;
}

.reports-list-panel,
.report-detail-panel {
  min-width: 0;
}

.graph-category-control {
  width: min(260px, 100%);
}

.graph-panel {
  min-width: 0;
}

.graph-panel-header {
  flex-wrap: wrap;
}

.graph-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
}

.graph-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.graph-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--graph-node-color);
}

.graph-stage {
  position: relative;
  min-height: 680px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

#qualityGraphSvg {
  display: block;
  width: 100%;
  min-height: 680px;
}

.graph-edge {
  stroke: #cbd1c6;
  stroke-width: 0.8;
  stroke-opacity: 0.12;
  vector-effect: non-scaling-stroke;
  transition: stroke-opacity 120ms ease, stroke-width 120ms ease;
}

.graph-edge.graph-active {
  stroke: #596d50;
  stroke-width: 1.5;
  stroke-opacity: 0.8;
}

.graph-edge.graph-dimmed {
  stroke-opacity: 0.035;
}

.graph-node-mark {
  fill: var(--graph-node-color);
  stroke: var(--panel);
  stroke-width: 1.2;
  vector-effect: non-scaling-stroke;
  transition: opacity 120ms ease, stroke-width 120ms ease;
}

.graph-node-hit {
  fill: transparent;
  cursor: pointer;
}

.graph-node.graph-active .graph-node-mark {
  stroke: var(--ink);
  stroke-width: 2.2;
}

.graph-node.graph-dimmed .graph-node-mark {
  opacity: 0.12;
}

.graph-cluster-label {
  fill: var(--muted);
  font-size: 15px;
  font-weight: 700;
  text-anchor: middle;
  pointer-events: none;
}

.graph-tooltip {
  position: absolute;
  z-index: 4;
  width: min(330px, calc(100% - 24px));
  max-height: 360px;
  overflow: auto;
  border-radius: 8px;
  background: var(--ink);
  color: white;
  box-shadow: var(--shadow);
  padding: 12px;
  pointer-events: none;
  user-select: none;
}

.graph-tooltip.is-pinned {
  pointer-events: auto;
  user-select: text;
  cursor: text;
}

.graph-tooltip h3 {
  margin: 0 0 4px;
  font-size: 14px;
}

.graph-tooltip-type {
  color: #cfd6ca;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.graph-tooltip-fields {
  display: grid;
  grid-template-columns: minmax(88px, 0.36fr) minmax(0, 0.64fr);
  gap: 5px 10px;
  margin: 10px 0 0;
  font-size: 11px;
  line-height: 1.35;
}

.graph-tooltip-fields dt {
  color: #cfd6ca;
}

.graph-tooltip-fields dd {
  margin: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.graph-group-biology {
  --graph-node-color: #2f7d46;
}

.graph-group-method {
  --graph-node-color: #3454d1;
}

.graph-group-assay {
  --graph-node-color: #8b5fbf;
}

.graph-group-data {
  --graph-node-color: #b7791f;
}

.graph-group-quality {
  --graph-node-color: #b42318;
}

.reports-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 170px);
  overflow: auto;
}

.report-list-item {
  display: grid;
  gap: 8px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 12px;
  text-align: left;
  color: var(--ink);
}

.report-list-item:hover,
.report-list-item.active {
  cursor: pointer;
  border-color: #b8d0ae;
  background: #f1f7ee;
}

.report-list-top {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 8px;
}

.report-list-top strong {
  color: var(--green);
  font-size: 20px;
}

.report-list-top small,
.report-list-meta {
  color: var(--muted);
  font-size: 10px;
  overflow-wrap: anywhere;
}

.report-list-title {
  font-weight: 700;
  line-height: 1.3;
}

.report-detail {
  display: grid;
  gap: 14px;
}

.report-hero {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: start;
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
}

.report-hero h1 {
  margin: 10px 0 8px;
}

.report-hero p,
.agent-comment p {
  color: #485044;
  line-height: 1.55;
}

.report-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfbf8;
  padding: 14px;
}

.report-section > h2 {
  margin-bottom: 12px;
}

.report-section h3 {
  margin: 14px 0 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}

.report-section ul {
  margin: 5px 0 0;
  padding-left: 20px;
}

.report-section li {
  margin: 5px 0;
  line-height: 1.45;
}

.report-summary {
  line-height: 1.6;
  overflow-wrap: anywhere;
  min-width: 0;
}

.report-summary :is(h1, h2, h3, h4, h5, h6) {
  margin: 1.2em 0 0.5em;
  line-height: 1.3;
  font-size: 1.05rem;
}

.report-summary > :first-child {
  margin-top: 0;
}

.report-summary p {
  margin: 0.6em 0;
}

.report-summary :is(ul, ol) {
  padding-left: 1.5em;
  margin: 0.6em 0;
}

.report-summary li {
  margin: 0.7em 0;
}

.report-summary pre {
  white-space: pre-wrap;
  padding: 0.75em;
  background: #f5f6f2;
  border-radius: 6px;
}

.report-summary hr {
  border: 0;
  border-top: 1px solid #d9dfd3;
  margin: 1.2em 0;
}

.report-summary a,
.report-section a,
.source-block a {
  color: var(--blue);
  overflow-wrap: anywhere;
}

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

.data-status-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.detail-value,
.source-block,
.agent-comment {
  border-radius: 8px;
  background: white;
  border: 1px solid #e8ebe3;
  padding: 10px;
}

.detail-value span,
.source-block span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  margin-bottom: 5px;
}

.detail-value p {
  color: #384033;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.source-block {
  margin-top: 10px;
}

.agent-comment {
  margin-top: 12px;
}

.report-footer {
  color: var(--muted);
  font-size: 11px;
  overflow-wrap: anywhere;
}

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

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.2;
}

h2 {
  font-size: 15px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(420px, 1.3fr) minmax(300px, 0.7fr);
  gap: 16px;
  align-items: start;
}

.main-column,
.side-column {
  display: grid;
  gap: 16px;
  align-items: start;
}

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

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.dropzone {
  min-height: 154px;
  border: 1px dashed #aeb7a8;
  background: var(--panel-soft);
  border-radius: 8px;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 8px;
  cursor: pointer;
  margin-bottom: 16px;
}

.dropzone input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.drop-title {
  font-weight: 700;
}

.drop-meta {
  color: var(--muted);
  font-size: 13px;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
}

label span {
  color: #42483f;
  font-size: 13px;
  font-weight: 650;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 10px 11px;
  color: var(--ink);
  outline: none;
}

select {
  min-height: 42px;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, #596055 50%),
    linear-gradient(135deg, #596055 50%, transparent 50%);
  background-position: calc(100% - 18px) 18px, calc(100% - 13px) 18px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

textarea {
  resize: vertical;
  min-height: 96px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(52, 84, 209, 0.12);
}

input.field-empty,
select.field-empty,
textarea.field-empty {
  border-color: var(--red);
  background: #fff7f6;
}

input.field-empty:focus,
select.field-empty:focus,
textarea.field-empty:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.13);
}

input.field-insufficient,
select.field-insufficient,
textarea.field-insufficient {
  border-color: var(--amber);
  background: #fffbeb;
}

input.field-insufficient:focus,
select.field-insufficient:focus,
textarea.field-insufficient:focus {
  border-color: var(--amber);
  box-shadow: 0 0 0 3px rgba(161, 98, 7, 0.14);
}

input.field-ok,
select.field-ok,
textarea.field-ok {
  border-color: #9cc7a8;
}

button {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 700;
  transition: background-color 140ms ease, color 140ms ease, border-color 140ms ease,
    box-shadow 140ms ease, transform 140ms ease;
}

.primary {
  background: var(--ink);
  color: white;
}

.primary:not(:disabled):hover {
  background: #30352f;
  box-shadow: 0 8px 22px rgba(32, 35, 31, 0.18);
  cursor: pointer;
}

.primary:disabled {
  background: #a9aea4;
}

.secondary {
  margin-top: 14px;
  background: #e8eee4;
  color: var(--green);
}

.secondary:not(:disabled):hover {
  background: #dbe8d5;
  box-shadow: 0 8px 20px rgba(47, 125, 70, 0.14);
  cursor: pointer;
}

.secondary:disabled {
  background: #eceee9;
  color: #969d92;
}

.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: #485044;
}

.ghost:not(:disabled):hover {
  background: #f0f3ec;
  border-color: #d5e3cf;
  box-shadow: 0 8px 20px rgba(32, 35, 31, 0.1);
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

.empty {
  color: var(--muted);
  background: var(--panel-soft);
  border-radius: 8px;
  padding: 14px;
}

.field-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
}

.field-card-empty {
  border-color: rgba(180, 35, 24, 0.38);
  background: #fff7f6;
}

.field-card-insufficient {
  border-color: rgba(161, 98, 7, 0.42);
  background: #fffbeb;
}

.field-card-ok {
  border-color: rgba(47, 125, 70, 0.35);
  background: #f5fbf6;
}

.field-title-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.field-title-row span {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.field-card strong {
  display: block;
  margin-bottom: 4px;
}

.field-card p {
  color: var(--muted);
  font-size: 13px;
}

.field-card small {
  display: block;
  color: #596055;
  font-size: 12px;
  line-height: 1.35;
  margin-top: 8px;
}

.suggestion-button {
  margin-top: 10px;
  background: white;
  border: 1px solid var(--line);
  color: #384033;
  padding: 8px 10px;
  font-size: 12px;
}

.suggestion-button:not(:disabled):hover {
  background: #f0f3ec;
  border-color: #d5e3cf;
  box-shadow: 0 6px 16px rgba(32, 35, 31, 0.1);
  cursor: pointer;
}

.review-output {
  display: grid;
  gap: 12px;
  color: #384033;
}

.feedback-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfbf8;
}

.feedback-title-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}

.feedback-title-row span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.feedback-card strong {
  display: block;
}

.feedback-body {
  color: #384033;
  font-size: 13px;
  line-height: 1.45;
}

.feedback-body p {
  color: #384033;
  font-size: 13px;
  line-height: 1.45;
}

.feedback-subcard {
  border: 1px solid #e8ebe3;
  border-radius: 8px;
  background: white;
  padding: 10px;
  margin-top: 8px;
}

.feedback-subcard:first-child {
  margin-top: 0;
}

.feedback-subcard p {
  color: var(--muted);
  margin-top: 4px;
}

.review-output ul {
  margin: 6px 0 0;
  padding-left: 18px;
}

.status-ok {
  color: var(--green);
}

.status-needs_input {
  color: var(--amber);
}

.status-failed {
  color: var(--red);
}

.path-list,
.skills-list {
  display: grid;
  gap: 8px;
}

.path-list-inner {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.file-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.file-row strong {
  display: block;
  font-size: 13px;
  margin-bottom: 3px;
}

.file-row span {
  color: var(--muted);
  font-size: 12px;
}

.icon-button {
  flex: 0 0 auto;
  padding: 7px 9px;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.icon-button:not(:disabled):hover {
  background: #fff7f6;
  border-color: rgba(180, 35, 24, 0.4);
  color: var(--red);
  cursor: pointer;
}

.path-row,
.skill-row {
  padding: 10px;
  background: var(--panel-soft);
  border-radius: 8px;
}

.path-row span,
.skill-row span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

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

  .content-grid {
    grid-template-columns: 1fr;
  }

  .analysis-layout,
  .reports-layout {
    grid-template-columns: 1fr;
  }

  .graph-stage,
  #qualityGraphSvg {
    min-height: 580px;
  }

  .reports-list {
    max-height: 360px;
  }
}

@media (max-width: 620px) {
  .workspace {
    padding: 16px;
  }

  .topbar,
  .field-grid {
    grid-template-columns: 1fr;
    display: grid;
  }

  .topbar-actions {
    justify-content: stretch;
  }

  .topbar-actions button {
    width: 100%;
  }

  .run-result-card,
  .detail-grid,
  .data-status-grid,
  .detail-columns {
    grid-template-columns: 1fr;
  }

  .report-hero {
    display: grid;
  }

  .graph-category-control {
    width: 100%;
  }
}

/* Research chains always fit the available width and use only their scaled height. */
.graph-stage:has(.research-graph) { overflow: hidden; min-height: 0; height: auto; }
.graph-article-control { display: grid; gap: 6px; margin: 18px 0 12px; }
.graph-article-control[hidden] { display: none; }
.graph-article-control select { width: 100%; max-width: 100%; }
.graph-notice { color: var(--muted); font-size: 13px; line-height: 1.6; margin: 12px 0 18px; }
.research-heading { text-anchor: middle; fill: #334155; font-size: 16px; font-weight: 700; }
.research-node-label { font-size: 13px; fill: #17324d; font-weight: 600; }
.research-node-meta { font-size: 11px; fill: #64748b; }
.research-empty { text-anchor: middle; fill: #64748b; font-size: 13px; }
.research-qc-label { text-anchor: middle; fill: #475569; font-size: 11px; }
.research-node, .research-edge { cursor: pointer; }
.research-node:hover > rect, .research-node.is-selected > rect, .research-node:focus > rect { stroke-width: 3; }
.research-edge:hover > path:first-child, .research-edge:focus > path:first-child { stroke: #17324d; stroke-width: 3; }
.research-edge { outline: none; }
.research-qc { cursor: pointer; outline: none; }
.research-qc:focus, .research-qc:focus-visible { outline: none !important; }
.research-qc:hover > rect, .research-qc:focus > rect, .research-qc.is-selected > rect { stroke: #17324d; stroke-width: 2; }
.research-details { margin-top: 20px; padding: 20px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.research-details h2 { font-size: 18px; margin: 0 0 16px; }
.research-details dl { display: grid; grid-template-columns: minmax(130px, 0.25fr) minmax(0, 1fr); gap: 10px 18px; font-size: 13px; }
.research-details dt { color: var(--muted); overflow-wrap: anywhere; }
.research-details dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; }

#qualityGraphSvg.research-graph { min-height: 0; }
.research-details dl dl { margin: 0; }
.research-details ul { margin: 0; padding-left: 18px; }
.research-details blockquote { margin: 8px 0; border-left: 3px solid var(--line); padding-left: 12px; color: var(--muted); }
.research-description, .research-detail-note { font-size: 13px; line-height: 1.6; max-width: 85ch; }
.research-detail-note { color: var(--muted); margin: 14px 0; }
.research-source-links { display: flex; flex-wrap: wrap; gap: 10px 22px; margin-top: 18px; font-size: 13px; }
.research-checks { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 24px; }
.research-checks h3 { font-size: 14px; margin: 8px 0 12px; }
.research-checks ul { font-size: 13px; line-height: 1.6; }
.research-check-list { list-style: none; padding: 0 !important; }
.research-check-list li { margin-bottom: 12px; }
.research-check-list li > div { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.research-check-list span, .research-check-list p { color: var(--muted); }
.research-check-list p { margin: 3px 0 0; }
@media (max-width: 800px) {
  .research-checks { grid-template-columns: 1fr; gap: 12px; }
  .research-details dl { grid-template-columns: 1fr; gap: 4px; }
  .research-details dd { margin-bottom: 10px; }
}
