:root {
  --bg: #f5f3ef;
  --panel: #ffffff;
  --panel-2: #faf7f2;
  --ink: #141414;
  --muted: #67615a;
  --line: #ddd6ca;
  --line-strong: #bfb5a6;
  --accent: #1f6f78;
  --accent-soft: #e2f0ef;
  --danger: #9b2c2c;
  --shadow: 0 12px 30px rgba(26, 22, 18, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(31, 111, 120, 0.08), transparent 30%),
    radial-gradient(circle at 85% 10%, rgba(163, 135, 92, 0.12), transparent 24%),
    var(--bg);
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
}

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

button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

button:hover {
  border-color: var(--line-strong);
  background: #fffdf8;
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

button.secondary {
  background: transparent;
}

button.primary {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}

button.primary:hover {
  background: #202020;
}

.app-shell {
  width: min(1440px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 12px 0 18px;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 12px;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  padding: 18px 20px;
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.brand-block h1 {
  margin: 4px 0 8px;
  font-size: clamp(24px, 3vw, 38px);
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.brand-block p,
.brand-kicker,
.stage-note,
.panel-note,
.meta-line,
.overlay-meta,
.report-citation,
.report-meta,
.timeline-time,
.timeline-details,
.small-copy,
.branch-item,
.sequence-subtext {
  color: var(--muted);
}

.brand-kicker,
.stage-kicker,
.overlay-kicker,
.report-kicker {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
}

.topbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.case-select-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.case-select-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted, #888);
}

.case-select {
  appearance: none;
  background: var(--surface, #1a1a1a);
  border: 1px solid var(--line, #333);
  border-radius: 8px;
  color: var(--text, #f0f0f0);
  font-size: 13px;
  padding: 7px 32px 7px 10px;
  min-width: 220px;
  max-width: 340px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23888' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.case-select:hover {
  border-color: var(--accent, #6c63ff);
}

.case-select:focus {
  outline: 2px solid var(--accent, #6c63ff);
  outline-offset: 2px;
}

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

.step-button {
  padding: 14px 12px;
  text-align: left;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.85);
}

.step-button .step-index {
  display: block;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 4px;
}

.step-button strong {
  display: block;
  font-size: 14px;
  margin-bottom: 4px;
}

.step-button span {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

.step-button.active {
  border-color: rgba(31, 111, 120, 0.4);
  box-shadow: 0 0 0 1px rgba(31, 111, 120, 0.08);
  background: linear-gradient(180deg, #ffffff 0%, #f4fbfa 100%);
}

.stage-shell {
  min-height: 0;
  width: 100%;
  min-width: 0;
}

.stage-viewport {
  min-height: calc(100vh - 190px);
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: var(--shadow);
  overflow: hidden;
  box-sizing: border-box;
}

.stage-frame {
  min-height: 100%;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-sizing: border-box;
}

.stage-hero {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(250, 247, 242, 0.95));
}

.stage-hero h2 {
  margin: 6px 0 8px;
  font-size: clamp(24px, 2.8vw, 34px);
  line-height: 1.08;
  letter-spacing: -0.03em;
}

.stage-hero p {
  margin: 0;
  max-width: 72ch;
  line-height: 1.55;
}

.pill-row,
.callout-row,
.report-meta-grid,
.sequence-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill,
.callout,
.badge,
.report-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 11px;
  background: rgba(255, 255, 255, 0.9);
}

.content-grid,
.intake-grid,
.report-grid {
  display: grid;
  grid-template-columns: minmax(280px, 32%) minmax(0, 1fr);
  gap: 16px;
  min-height: 0;
  flex: 1;
}

.panel,
.paper-panel,
.fishbone-panel,
.timeline-panel,
.sequence-panel,
.report-section,
.overlay-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 8px 22px rgba(18, 16, 12, 0.05);
}

.panel,
.paper-panel,
.fishbone-panel,
.timeline-panel,
.sequence-panel,
.report-section {
  padding: 16px;
}

.panel-title,
.report-section h3,
.fishbone-title,
.sequence-title,
.timeline-title {
  margin: 0 0 8px;
  font-size: 14px;
  letter-spacing: -0.01em;
}

.panel-copy,
.sequence-copy,
.timeline-copy,
.report-copy {
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.intake-card,
.sequence-card,
.fishbone-card,
.report-card,
.document-card,
.report-block,
.timeline-block {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel-2);
}

.intake-card,
.document-card {
  padding: 16px;
}

.intake-fields,
.report-stack,
.overlay-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label,
.report-label,
.overlay-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  font-weight: 700;
}

.field input,
.field textarea,
.overlay-card textarea,
.report-card textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--ink);
}

.field textarea {
  min-height: 170px;
  resize: vertical;
}

.file-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.file-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 11px;
  background: #fff;
  color: var(--muted);
}

.form-actions,
.overlay-actions,
.report-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.sequence-wrap,
.fishbone-wrap,
.report-wrap {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.sequence-lanes {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sequence-node {
  min-width: 230px;
  max-width: 260px;
  text-align: left;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  min-width: 0;
  background: linear-gradient(180deg, #fff 0%, #fbfaf7 100%);
}

.sequence-node:hover,
.sequence-node:focus-visible,
.branch-button:hover,
.branch-button:focus-visible,
.report-link:hover,
.report-link:focus-visible {
  border-color: rgba(31, 111, 120, 0.38);
  outline: none;
}

.sequence-node .sequence-index,
.branch-label,
.report-index {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
  margin-bottom: 6px;
}

.sequence-node strong {
  display: block;
  margin-bottom: 8px;
  font-size: 15px;
  line-height: 1.2;
}

.sequence-node .sequence-subtext {
  display: block;
  font-size: 12px;
  line-height: 1.45;
}

.sequence-lane {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, #fff 0%, #fbfaf7 100%);
  padding: 12px;
}

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

.sequence-lane-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
}

.sequence-lane-meta {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 3px;
}

.sequence-lane-toggle {
  white-space: nowrap;
}

.sequence-lane-strip {
  display: flex;
  align-items: stretch;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 4px;
  scroll-snap-type: x proximity;
}

.sequence-lane-card {
  flex: 0 0 auto;
  scroll-snap-align: start;
}

.sequence-lane.is-collapsed .sequence-lane-strip {
  display: none;
}

.sequence-series {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sequence-episode-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sequence-episode {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, #fff 0%, #fbfaf7 100%);
  padding: 14px;
}

.sequence-episode-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.sequence-episode-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
}

.sequence-episode-meta {
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.sequence-episode-summary {
  margin: 10px 0 12px;
  color: #2e2b27;
  line-height: 1.5;
  font-size: 13px;
}

.sequence-episode-more {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

.sequence-lane-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.sequence-lane {
  min-width: 0;
}

.sequence-lane-controls {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.sequence-lane-scroll-btn {
  width: 34px;
  min-width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
}

.timeline-cards-track {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  scroll-behavior: smooth;
}

.event-card.selected {
  border-color: rgba(31, 111, 120, 0.7);
  box-shadow: 0 0 0 1px rgba(31, 111, 120, 0.08), 0 4px 12px rgba(31, 111, 120, 0.12);
  transform: translateY(-1px);
}

.sequence-series-item {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, #fff 0%, #fbfaf7 100%);
  padding: 14px;
  box-shadow: 0 10px 24px rgba(18, 16, 12, 0.04);
}

.sequence-series-item.active {
  border-color: rgba(31, 111, 120, 0.38);
  box-shadow: 0 12px 28px rgba(31, 111, 120, 0.12);
}

.sequence-series-marker {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
}

.sequence-series-marker::before {
  content: "";
  position: absolute;
  left: 27px;
  top: 0;
  bottom: -12px;
  width: 2px;
  background: linear-gradient(180deg, rgba(31, 111, 120, 0.34), rgba(31, 111, 120, 0.12));
}

.sequence-series-item:last-child .sequence-series-marker::before {
  display: none;
}

.sequence-series-marker .sequence-index {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  background: #1f6f78;
  color: #fff;
  font-size: 11px;
  letter-spacing: 0.08em;
}

.sequence-series-body strong {
  display: block;
  margin-bottom: 8px;
  font-size: 15px;
  line-height: 1.25;
}

.sequence-series-body .sequence-subtext {
  display: block;
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}

.sequence-causal-links {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.sequence-causal-link {
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, #fff 0%, #faf7f2 100%);
  padding: 12px 14px;
  box-shadow: 0 8px 20px rgba(18, 16, 12, 0.04);
}

.sequence-causal-link strong,
.sequence-causal-link span {
  display: block;
}

.sequence-causal-link strong {
  font-size: 13px;
  margin-bottom: 4px;
}

.sequence-causal-link span {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}

.sequence-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  color: var(--line-strong);
  font-size: 22px;
  font-weight: 700;
}

.sequence-detail {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
  gap: 16px;
}

.document-preview,
.root-cause-summary,
.report-side,
.timeline-side {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
}

.document-preview h3,
.root-cause-summary h3,
.report-side h3,
.timeline-side h3 {
  margin: 0 0 10px;
  font-size: 14px;
}

.document-excerpt,
.highlight-excerpt,
.report-excerpt,
.timeline-text {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.65;
  color: #251f1b;
}

.document-excerpt mark,
.highlight-excerpt mark,
.report-excerpt mark {
  background: #fff2b8;
  padding: 0 2px;
}

.flow-empty,
.report-empty {
  padding: 18px;
  border: 1px dashed var(--line-strong);
  border-radius: 14px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.7);
}

.fishbone-canvas {
  position: relative;
  min-height: 560px;
  overflow: auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, #fff 0%, #faf7f2 100%);
}

.fishbone-head {
  position: absolute;
  right: 18px;
  top: 50%;
  transform: translateY(-50%);
  width: 220px;
  min-height: 120px;
  padding: 18px;
  border-radius: 18px;
  border: 1px solid rgba(31, 111, 120, 0.18);
  background: linear-gradient(180deg, #1f6f78 0%, #17555c 100%);
  color: #fff;
  box-shadow: 0 18px 34px rgba(31, 111, 120, 0.2);
}

.fishbone-head h3 {
  margin: 6px 0 8px;
  font-size: 18px;
}

.fishbone-head p {
  margin: 0;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.9);
}

.fishbone-spine {
  position: absolute;
  left: 10%;
  right: 260px;
  top: 50%;
  height: 4px;
  transform: translateY(-50%);
  background: linear-gradient(90deg, #5f6b63 0%, #2f3432 100%);
  border-radius: 999px;
}

.fishbone-spine::before {
  content: "";
  position: absolute;
  left: -28px;
  top: 50%;
  width: 34px;
  height: 34px;
  transform: translateY(-50%) rotate(45deg);
  border-top: 4px solid #2f3432;
  border-right: 4px solid #2f3432;
}

.fishbone-branches {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  min-height: 500px;
  padding: 12px 252px 12px 12px;
  align-content: center;
}

.branch-card {
  position: relative;
  width: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.92);
  padding: 14px;
  box-shadow: 0 10px 24px rgba(18, 16, 12, 0.05);
  min-height: 142px;
}

.root-cause-graph-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.root-cause-branch-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.root-cause-thread-meta {
  margin-top: 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.root-cause-branch-summary {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: #2e2b27;
  line-height: 1.5;
  font-size: 12px;
}

.root-cause-cause-list {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.root-cause-cause {
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 10px 12px;
}

.root-cause-cause strong,
.root-cause-cause span {
  display: block;
}

.root-cause-cause strong {
  font-size: 13px;
  margin-bottom: 4px;
}

.root-cause-cause span {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}

.branch-card.top,
.branch-card.bottom,
.branch-card.machine,
.branch-card.material,
.branch-card.method,
.branch-card.measurement,
.branch-card.manpower,
.branch-card.milieu {
  top: auto;
  left: auto;
  bottom: auto;
}

.branch-card ul {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.branch-button,
.report-link {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 10px 12px;
}

.branch-button strong,
.report-link strong {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
}

.branch-button span,
.report-link span {
  display: block;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}

.report-document {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfaf7 100%);
}

.report-document h1 {
  margin: 0 0 12px;
  font-size: clamp(28px, 3vw, 34px);
  letter-spacing: -0.03em;
}

.report-section-heading {
  margin: 24px 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid #d7d0c4;
  font-size: 18px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.report-box,
.report-highlight,
.report-table-card,
.report-timeline,
.report-fishbone-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #f6f4ef;
  padding: 16px;
}

.report-highlight {
  border-left: 4px solid #111;
}

.report-table,
.report-table-compact {
  width: 100%;
  border-collapse: collapse;
}

.report-table th,
.report-table td,
.report-table-compact th,
.report-table-compact td {
  padding: 10px 10px 10px 0;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid #e5ddd1;
  font-size: 13px;
}

.report-table th,
.report-table-compact th {
  color: #555048;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 11px;
}

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

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

.report-branch-title {
  margin: 0 0 10px;
  padding-bottom: 6px;
  border-bottom: 2px solid #878074;
  font-size: 14px;
  text-transform: uppercase;
}

.timeline-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.timeline-item {
  position: relative;
  padding-left: 20px;
  border-left: 2px solid #d8d1c5;
}

.timeline-item::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 5px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #6f665a;
}

.timeline-event {
  margin: 2px 0 4px;
  font-weight: 700;
  color: #111;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
}

.overlay[hidden] {
  display: none;
}

.overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 20, 20, 0.42);
  backdrop-filter: blur(4px);
}

.overlay-card {
  position: relative;
  z-index: 1;
  width: min(1240px, calc(100vw - 24px));
  max-height: min(86vh, 920px);
  overflow: auto;
  padding: 18px;
}

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

.overlay-header h2 {
  margin: 4px 0 0;
  font-size: 24px;
}

.overlay-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Passage rail beside the document. Both columns must be able to shrink
   (minmax(0, …)) or the PDF canvas forces the grid wider than the overlay. */
.overlay-citation-layout {
  display: grid;
  grid-template-columns: minmax(0, 17rem) minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  min-height: 360px;
}

.overlay-citation-layout--single {
  grid-template-columns: minmax(0, 1fr);
}

.citation-rail {
  border-right: 1px solid var(--line);
  background: #fcfaf6;
  overflow-y: auto;
  max-height: 70vh;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.citation-card {
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
  font: inherit;
  width: 100%;
}

.citation-card:hover { border-color: rgba(31, 111, 120, 0.35); }

.citation-card.is-active {
  border-color: rgba(31, 111, 120, 0.45);
  background: var(--accent-soft);
}

.citation-source {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 6px;
}

.citation-excerpt {
  font-size: 12px;
  line-height: 1.45;
  color: #2e2b27;
}

/* The claim under verification, above the document that should support it. */
.overlay-claim {
  border-left: 3px solid var(--accent, #1f6f78);
  background: var(--accent-soft, #f2f7f7);
  border-radius: 0 8px 8px 0;
  padding: 10px 12px;
  margin-bottom: 10px;
}

.overlay-claim-text {
  margin: 4px 0 0;
  font-size: 13px;
  line-height: 1.55;
  color: #2e2b27;
  text-wrap: pretty;
}

.excerpt-pane {
  padding: 12px;
  overflow: auto;
}

.overlay-pdf-pane {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
  position: relative;
  min-height: 0;
}

.overlay-pdf-sticky {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.03);
}

.overlay-pdf-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.overlay-pdf-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.overlay-pdf-segment {
  margin-top: 2px;
  font-size: 12px;
  line-height: 1.45;
  color: #494949;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.overlay-pdf-canvas-wrap {
  flex: 1;
  min-height: 0;
  height: clamp(360px, 62vh, 900px);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  overflow: auto;
  padding: 10px;
  position: relative;
}

.overlay-pdf-canvas {
  display: none;
  margin: 0 auto;
  max-width: 100%;
  height: auto;
  position: relative;
  z-index: 1;
}

.overlay-pdf-text-layer {
  position: absolute;
  inset: 10px;
  margin: 0 auto;
  pointer-events: none;
  color: transparent;
  mix-blend-mode: multiply;
  z-index: 2;
}

.overlay-pdf-text-layer span,
.overlay-pdf-text-layer div {
  position: absolute;
  white-space: pre;
  transform-origin: 0 0;
}

.overlay-pdf-text-layer .overlay-pdf-text-hit {
  background: rgba(255, 236, 116, 0.72);
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(210, 155, 0, 0.28) inset;
}

.overlay-review-panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: #fcfaf6;
}

.overlay-review-panel textarea {
  width: 100%;
  min-height: 88px;
  border: 1px solid var(--line);
  border-radius: 10px;
  margin: 6px 0 10px;
  padding: 10px;
  background: #fff;
}

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

.overlay-open-doc {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  text-decoration: none;
  padding: 8px 10px;
  background: #fff;
}

.overlay-error {
  color: var(--danger);
}

.overlay-excerpt {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fffdf8;
  white-space: pre-wrap;
  line-height: 1.7;
}

.overlay-excerpt mark {
  background: #fff2b6;
}

@media (max-width: 1120px) {
  .content-grid,
  .intake-grid,
  .report-grid,
  .sequence-detail {
    grid-template-columns: 1fr;
  }

  .fishbone-head {
    position: static;
    transform: none;
    width: auto;
    margin-bottom: 14px;
  }

  .fishbone-spine,
  .fishbone-branches {
    position: static;
    min-height: auto;
    padding-right: 0;
  }

  .fishbone-branches {
    grid-template-columns: 1fr 1fr;
    padding: 0;
  }

  .fishbone-canvas {
    min-height: auto;
  }

  .branch-card {
    position: static;
    width: auto;
    margin-bottom: 12px;
    min-height: 0;
  }

  .overlay-citation-layout {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .citation-rail {
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: 220px;
  }
}

@media (max-width: 840px) {
  .app-shell {
    width: min(100vw, calc(100vw - 16px));
  }

  .topbar,
  .stage-hero {
    flex-direction: column;
  }

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

  .sequence-lane-strip {
    flex-wrap: nowrap;
  }

  .root-cause-graph-grid {
    grid-template-columns: 1fr;
  }

  .sequence-arrow {
    min-width: 100%;
    transform: rotate(90deg);
    padding: 8px 0;
  }
}

/* ============================================================
   EVENT CARD — event first, evidence listed, passage disclosed
   ============================================================ */
.ec {
  --ec-white:#fff; --ec-panel:#fafafa; --ec-rail:#d2d2d7;
  --ec-edge:#e2e2e7; --ec-edge2:#cdcdd2;
  --ec-ink:#1d1d1f; --ec-ink2:#2a2a2c; --ec-ink3:#424245; --ec-ink4:#606065; --ec-ink5:#86868b;
  --ec-link:#1a4d8f; --ec-alert:#9c3b33;
  flex: 0 0 18.5rem; max-width: 18.5rem;
  background: var(--ec-white); border: 1px solid var(--ec-edge); border-radius: 8px;
  box-shadow: 0 1px 2px rgba(29,29,31,.04);
  padding: 1rem 1.05rem 1.05rem;
  display: flex; flex-direction: column; gap: .85rem;
  scroll-snap-align: start;
}
/* The whole card opens its evidence, so it reads and behaves as one control. */
.ec { cursor: pointer; transition: border-color .14s ease, box-shadow .14s ease; }
.ec:hover { border-color: var(--ec-edge2); box-shadow: 0 2px 8px rgba(29,29,31,.08); }
.ec:focus-visible { outline: 2px solid var(--ec-link); outline-offset: 2px; }
.ec:hover .ec-more { text-decoration-thickness: 1px; }

.ec.selected { border-color: var(--ec-ink); }
.ec.gap { border-style: dashed; border-color: color-mix(in srgb, var(--ec-alert) 40%, var(--ec-edge)); }
.ec.gap .ec-what { color: var(--ec-alert); }

.ec-fld { display: flex; flex-direction: column; gap: .3rem; }
.ec-lb { font-size: .735rem; font-weight: 660; color: var(--ec-ink2); line-height: 1.3; }

.ec-what { font-size: .93rem; font-weight: 640; color: var(--ec-ink);
           line-height: 1.3; letter-spacing: -.011em; text-wrap: balance; }
.ec-when { font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
           font-size: .705rem; color: var(--ec-ink4);
           display: flex; flex-wrap: wrap; gap: .18rem .42rem; align-items: baseline; }
.ec-when .ec-date { color: var(--ec-ink2); font-weight: 500; }
.ec-soft { font-style: italic; opacity: .85; }
.ec-dot { opacity: .5; margin: 0 .12rem; }

.ec-sup { font-size: .8rem; color: var(--ec-ink3); line-height: 1.5;
          display: flex; flex-wrap: wrap; gap: .18rem .3rem; align-items: baseline; }
.ec-sup b { font-weight: 650; color: var(--ec-ink2); font-variant-numeric: tabular-nums; }
.ec-sup.none { color: var(--ec-alert); }

.ec-evlist { display: flex; flex-direction: column; }
.ec-ev { display: flex; flex-direction: column; gap: .1rem;
         padding: .48rem 0 .48rem .6rem; border-left: 2px solid var(--ec-edge);
         text-decoration: none; color: inherit;
         transition: border-color .14s ease, background .14s ease; }
.ec-ev + .ec-ev { border-top: 1px solid var(--ec-edge); }
.ec-ev:hover { border-left-color: var(--ec-rail); background: var(--ec-panel); }
.ec-ev .ec-doc { font-size: .795rem; font-weight: 600; color: var(--ec-ink2); line-height: 1.3; }
.ec-ev:hover .ec-doc { color: var(--ec-link); }
.ec-ev .ec-loc { font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
                 font-size: .655rem; color: var(--ec-ink4);
                 display: flex; flex-wrap: wrap; gap: .16rem .2rem; align-items: baseline; }
.ec-ev.thin .ec-doc { color: var(--ec-alert); }
.ec-ev.thin { border-left-color: color-mix(in srgb, var(--ec-alert) 45%, transparent); }

.ec-empty { font-size: .8rem; color: var(--ec-alert); line-height: 1.5;
            border-left: 2px dashed color-mix(in srgb, var(--ec-alert) 45%, transparent);
            padding: .45rem 0 .45rem .6rem; }

.ec-more { font-size: .765rem; color: var(--ec-link); text-decoration: underline;
           text-underline-offset: 2px; text-decoration-thickness: .5px; align-self: flex-start; }

/* Deterministic orientation summary, directly under the title. Set quieter
   than the quote below it: it says who is speaking and how well the record
   backs them, while the quote carries what was actually said. */
.ec-sum { margin: .3rem 0 0; font-size: .765rem; line-height: 1.5;
          color: var(--ec-ink4); text-wrap: pretty; }

/* Lead quote. The card's centre of gravity: it is what the record says about
   the subject named in the title, so it gets the visual weight the counts used
   to hold. Clamped so a long passage cannot make one card tower over its lane;
   the full text is one click away in the source document. */
.ec-lead { margin: 0; background: var(--ec-panel);
           border-left: 3px solid var(--ec-rail); border-radius: 0 4px 4px 0;
           padding: .62rem .75rem; font-size: .815rem; line-height: 1.55;
           color: var(--ec-ink2); cursor: pointer;
           display: -webkit-box; -webkit-line-clamp: 7; -webkit-box-orient: vertical;
           overflow: hidden;
           transition: border-color .14s ease, background .14s ease; }
.ec-lead:hover { border-left-color: var(--ec-link); background: #fff; }
.ec-lead-src { display: flex; flex-wrap: wrap; gap: .2rem .34rem; align-items: baseline;
               font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
               font-size: .655rem; color: var(--ec-ink4); }
.ec-lead-src .ec-doc { font-family: inherit; font-size: .68rem; font-weight: 600;
                       color: var(--ec-ink3); }
.ec-tag { font-size: .58rem; font-weight: 700; letter-spacing: .045em;
          padding: .1rem .32rem; border-radius: 3px; white-space: nowrap; }
.ec-withheld { color: var(--ec-alert); }

.ec-disc > summary { list-style: none; cursor: pointer; font-size: .735rem;
                     color: var(--ec-ink4); display: flex; align-items: center; gap: .34rem; }
.ec-disc > summary::-webkit-details-marker { display: none; }
.ec-disc > summary::before { content: "▸"; font-size: .6rem; transition: transform .15s ease; }
.ec-disc[open] > summary::before { transform: rotate(90deg); }
.ec-disc > summary:hover { color: var(--ec-ink3); }
.ec-quote { margin-top: .55rem; background: var(--ec-panel);
            border-left: 6px solid var(--ec-rail); border-radius: 0 4px 4px 0;
            padding: .7rem .8rem; font-size: .82rem; line-height: 1.6; color: var(--ec-ink2); }
