.forge-shell .document-coherence-view {
  --coherence-paper: var(--forge-paper, #fbf8f3);
  --coherence-ink: var(--forge-text, #241e16);
  --coherence-muted: var(--forge-muted, #756b5f);
  --coherence-line: var(--forge-border, #ded6ca);
  --coherence-accent: var(--forge-accent, #4a341b);
  color: var(--coherence-ink);
}

.forge-shell .document-coherence-page {
  display: grid;
  gap: 1.25rem;
}

.forge-shell .coherence-hierarchy {
  display: grid;
  gap: 0.95rem;
  padding: 1rem 1.15rem;
  border: 1px solid var(--coherence-line);
  border-radius: 10px;
  background: var(--coherence-paper);
}

.forge-shell .coherence-hierarchy-heading h3,
.forge-shell .coherence-hierarchy-heading p { margin: 0; }
.forge-shell .coherence-hierarchy-heading p {
  margin-top: 0.3rem;
  color: var(--coherence-muted);
}

.forge-shell .coherence-hierarchy-list {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.forge-shell .coherence-hierarchy-item {
  position: relative;
  display: flex;
  gap: 0.5rem;
  align-items: center;
  min-height: 3.25rem;
  padding: 0.65rem 0.8rem;
  border: 1px solid var(--coherence-line);
  background: #f4efe7;
  font-size: 0.88rem;
  line-height: 1.25;
}

.forge-shell .coherence-hierarchy-item:first-child { border-radius: 8px 0 0 8px; }
.forge-shell .coherence-hierarchy-item:last-child { border-radius: 0 8px 8px 0; }
.forge-shell .coherence-hierarchy-item + .coherence-hierarchy-item { border-left: 0; }
.forge-shell .coherence-hierarchy-index {
  display: inline-grid;
  flex: 0 0 1.65rem;
  width: 1.65rem;
  height: 1.65rem;
  place-items: center;
  border: 1px solid var(--coherence-accent);
  border-radius: 50%;
  color: var(--coherence-accent);
  background: var(--coherence-paper);
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 0.72rem;
}

.forge-shell .coherence-form-card,
.forge-shell .coherence-result-card { display: grid; gap: 1rem; }
.forge-shell .coherence-form {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: start;
}
.forge-shell .coherence-form > .incident-field:not(.coherence-file-field) {
  grid-template-rows: minmax(2.6rem, auto) auto;
}
.forge-shell .coherence-file-field,
.forge-shell .coherence-boundary,
.forge-shell .coherence-status,
.forge-shell .coherence-form-actions { grid-column: 1 / -1; }
.forge-shell .coherence-file-input { padding: 0.5rem; }
.forge-shell .coherence-form-actions { justify-content: flex-end; }
.forge-shell .coherence-form-actions .primary-action { min-width: 12rem; }

.forge-shell .coherence-result-meta {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 0.35rem 0.8rem;
  margin: 0;
  padding: 0.85rem 1rem;
  border: 1px solid var(--coherence-line);
  border-radius: 8px;
  background: #f4efe7;
}
.forge-shell .coherence-result-meta dt { font-weight: 700; }
.forge-shell .coherence-result-meta dd { margin: 0; overflow-wrap: anywhere; }
.forge-shell .coherence-answer { max-width: 64rem; }
.forge-shell .coherence-result-card { scroll-margin-top: 1rem; }
.forge-shell .coherence-result-card:focus { outline: none; }
.forge-shell .coherence-sources { display: grid; gap: 0.7rem; }
.forge-shell .coherence-sources h3 { margin: 0; }
.forge-shell .coherence-source-list { display: grid; gap: 0.65rem; margin: 0; padding-left: 1.25rem; }
.forge-shell .coherence-source-item {
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--coherence-line);
  border-radius: 8px;
  background: var(--coherence-paper);
}
.forge-shell .coherence-source-item p { margin: 0.35rem 0 0; color: var(--coherence-muted); }

@media (max-width: 1100px) {
  .forge-shell .coherence-hierarchy-list { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.55rem; }
  .forge-shell .coherence-hierarchy-item,
  .forge-shell .coherence-hierarchy-item:first-child,
  .forge-shell .coherence-hierarchy-item:last-child { border: 1px solid var(--coherence-line); border-radius: 8px; }
}

@media (max-width: 850px) {
  .forge-shell .coherence-form { grid-template-columns: 1fr; }
  .forge-shell .coherence-form > .incident-field:not(.coherence-file-field) { grid-template-rows: auto; }
}

@media (max-width: 620px) {
  .forge-shell .coherence-hierarchy-list { grid-template-columns: 1fr; }
  .forge-shell .coherence-form-actions,
  .forge-shell .coherence-form-actions .primary-action { width: 100%; }
  .forge-shell .coherence-result-meta { grid-template-columns: 1fr; }
  .forge-shell .coherence-result-meta dd + dt { margin-top: 0.45rem; }
}

@media (prefers-reduced-motion: reduce) {
  .forge-shell .document-coherence-view * { scroll-behavior: auto !important; }
}
