html, body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
}

:root {
  --accent: #4f7bd9;
  --border: #ddd;
  --muted: #666;
  --bg: #fff;
}

.header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.header__title {
  font-weight: 800;
  color: #0b1a3a;
  font-size: 16px;
  line-height: 1.2;
}

.header__meta {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.content {
  padding: 12px 14px 40px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 8px;
  font-size: 12px;
}

.section {
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  padding: 10px 12px;
  background: var(--bg);
}

.section h2 {
  font-size: 14px;
  margin: 0 0 10px;
  color: #0b1a3a;
}

/* Table of contents */
.toc__list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: block;
}

.toc__list li {
  margin: 0 0 6px;
}

.toc__list li:last-child {
  margin-bottom: 0;
}

.toc__link {
  display: inline-block;
  font-size: 12px;
  color: #0b1a3a;
  text-decoration: none;
  border: 1px solid var(--border);
  background: #f7f9ff;
  padding: 3px 8px;
}

.toc__link:hover {
  text-decoration: underline;
}

.toc__link:focus-visible,
.toc__link:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: var(--accent);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.table th,
.table td {
  border: 1px solid var(--border);
  padding: 4px 6px;
  text-align: left;
}

.table th {
  background: #f7f9ff;
}

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

.controls {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.control {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  font-size: 12px;
  user-select: none;
}

.button {
  font-size: 12px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  background: #f7f9ff;
  cursor: pointer;
}

.graph {
  width: 100%;
  height: var(--section-panel-height, 520px);
  border: 1px solid var(--border);
}

.matrix {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--border);
  max-height: var(--section-panel-height, 520px);

  --matrix-cell-size: 28px;
  --matrix-row-header-width: 360px;
  --matrix-header-height: 210px;
}

/* AG Grid dependency matrix */
.dep-grid {
  height: var(--section-panel-height, 520px);
  width: 100%;
}

.dep-matrix {
  overflow: hidden;
}

.dep-grid .ag-root-wrapper {
  border: 0;
}

.dep-grid .ag-header-cell-label {
  font-size: 12px;
}

/* Diagonal column headers for dependency matrices (avoid crushed long names). */
/* Keep the scroll viewport clipped so headers behave correctly on horizontal scroll. */
.dep-grid .ag-header-viewport {
  overflow: hidden;
}

.dep-grid .ag-header-cell.dep-col-header {
  overflow: visible;
}

.dep-grid .ag-header-cell.dep-col-header .ag-header-cell-label {
  height: 100%;
  align-items: flex-end;
  padding-bottom: 6px;
  overflow: visible;
  /* AG Grid sets min-width: 0 in some themes; keep label from squashing */
  min-width: 0;
  position: relative;
}

.dep-grid .ag-header-cell.dep-col-header .ag-header-cell-text {
  /* Cancel AG Grid's default ellipsis/clipping so rotated text stays readable */
  overflow: visible;
  text-overflow: clip;
  max-width: none;
  white-space: nowrap;

  /* Place and rotate the label without it being constrained by the cell width */
  position: absolute;
  left: 6px;
  bottom: 6px;
  display: inline-block;
  line-height: 1.1;
  transform: rotate(-80deg);
  transform-origin: bottom left;
}

.dep-grid .ag-cell {
  font-size: 12px;
  line-height: 1.2;
}

.dep-yes {
  background: #f7f9ff;
}

.matrix table {
  width: max-content;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
  table-layout: fixed;
}

.matrix th,
.matrix td {
  border: 1px solid var(--border);
  padding: 2px 4px;
  white-space: nowrap;
}

.matrix thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #f7f9ff;
  overflow: visible;
}

.matrix .matrix-corner {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 5;
  background: #f7f9ff;
  width: var(--matrix-row-header-width);
  min-width: var(--matrix-row-header-width);
  max-width: var(--matrix-row-header-width);
}

.matrix .matrix-row-header {
  position: sticky;
  left: 0;
  z-index: 4;
  background: #f7f9ff;
  width: var(--matrix-row-header-width);
  min-width: var(--matrix-row-header-width);
  max-width: var(--matrix-row-header-width);
  text-align: left;
  white-space: normal;
  overflow-wrap: anywhere;
}

.matrix .matrix-col-header {
  width: var(--matrix-cell-size);
  min-width: var(--matrix-cell-size);
  max-width: var(--matrix-cell-size);
  height: var(--matrix-header-height);
  vertical-align: bottom;
  padding: 0;
  position: sticky;
  top: 0;
  overflow: visible;
}

.matrix .matrix-col-label {
  display: inline-block;
  position: absolute;
  left: 50%;
  bottom: 6px;
  transform: translateX(-50%) rotate(-90deg);
  transform-origin: bottom center;
  white-space: nowrap;
}

.matrix .matrix-cell {
  width: var(--matrix-cell-size);
  min-width: var(--matrix-cell-size);
  max-width: var(--matrix-cell-size);
  text-align: center;
}

.sortable {
  cursor: pointer;
}
