/* Copyright 2026 Marvin van Aalst, Anna Matuszyńska
 * MxlPy dependency graph viewer. Uses mkdocs-material's colour variables; the
 * standalone page (scripts/graph.py serve) defines the same variables itself. */

#mxlgraph {
  --mxlgraph-border: var(--md-default-fg-color--lightest, #0002);
  accent-color: var(--md-primary-fg-color, #009485);
  container-type: inline-size;
  display: grid;
  gap: 0.5rem;
  font-size: 0.75rem;
}

/* The graph page uses the full window width, without the table of contents */
body:has(#mxlgraph) .md-grid {
  max-width: none;
}

body:has(#mxlgraph) .md-sidebar--secondary {
  display: none;
}

.mxlgraph-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.mxlgraph-query {
  display: flex;
  flex: 1 1 30rem;
  gap: 0.5rem;
}

.mxlgraph-query input {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.6rem;
  font: inherit;
  font-family: var(--md-code-font-family, monospace);
  color: var(--md-default-fg-color);
  background: var(--md-code-bg-color, transparent);
  border: 1px solid var(--mxlgraph-border);
  border-radius: 0.2rem;
}

.mxlgraph-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

#mxlgraph .md-button {
  padding: 0.25rem 0.7rem;
  font-size: 0.7rem;
  margin: 0;
}

.mxlgraph-filters summary {
  cursor: pointer;
}

.mxlgraph-filter {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.9rem;
  border: 1px solid var(--mxlgraph-border);
  border-radius: 0.2rem;
  margin: 0.4rem 0.4rem 0 0;
}

.mxlgraph-filter label {
  white-space: nowrap;
}

.mxlgraph-swatch {
  display: inline-block;
  width: 1rem;
  height: 0.2rem;
  margin-left: 0.25rem;
  vertical-align: middle;
  background: var(--edge);
}

.mxlgraph-message {
  margin: 0;
  min-height: 1.2em;
  color: var(--md-default-fg-color--light);
}

.mxlgraph-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(16rem, 22rem);
  gap: 0.5rem;
  height: min(78vh, 60rem);
}

.mxlgraph-stage {
  display: grid;
  min-height: 0;
}

.mxlgraph-canvas,
.mxlgraph-matrix {
  min-height: 0;
  border: 1px solid var(--mxlgraph-border);
  border-radius: 0.2rem;
}

.mxlgraph-canvas[hidden],
.mxlgraph-matrix[hidden] {
  display: none;
}

/* Dependency structure matrix */
.mxlgraph-matrix {
  --mxlgraph-cycle: #d64545;
  overflow: auto;
  overscroll-behavior: contain;
}

.mxlgraph-matrix table {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.6rem;
  font-variant-numeric: tabular-nums;
}

.mxlgraph-matrix th,
.mxlgraph-matrix td {
  padding: 0;
  border-right: 1px solid var(--mxlgraph-border);
  border-bottom: 1px solid var(--mxlgraph-border);
}

.mxlgraph-matrix th {
  position: sticky;
  z-index: 1;
  font-weight: normal;
  white-space: nowrap;
  background: var(--md-default-bg-color, #fff);
}

.mxlgraph-matrix thead th {
  top: 0;
  vertical-align: bottom;
}

.mxlgraph-matrix thead th button {
  writing-mode: vertical-rl;
  rotate: 180deg;
  padding: 0.3rem 0;
}

.mxlgraph-matrix tbody th {
  left: 0;
  text-align: end;
}

.mxlgraph-matrix .mxlgraph-corner {
  left: 0;
  z-index: 2;
  padding: 0.3rem;
  color: var(--md-default-fg-color--light);
  white-space: normal;
}

.mxlgraph-matrix button {
  margin: 0;
  border: 0;
  background: none;
}

.mxlgraph-matrix th button {
  padding: 0 0.3rem;
  font: inherit;
  color: var(--md-typeset-a-color, inherit);
  cursor: pointer;
}

.mxlgraph-matrix td {
  min-width: 1.5rem;
  height: 1.5rem;
  text-align: center;
}

.mxlgraph-matrix td:has(button) {
  background: color-mix(in srgb, var(--md-primary-fg-color, #009485) calc(var(--w) * 100%), transparent);
}

.mxlgraph-matrix td.mxlgraph-back:has(button) {
  background: color-mix(in srgb, var(--mxlgraph-cycle) calc(max(var(--w), 0.35) * 100%), transparent);
}

.mxlgraph-matrix td button {
  width: 100%;
  height: 100%;
  font: inherit;
  color: var(--md-default-fg-color);
  cursor: pointer;
}

.mxlgraph-matrix td.mxlgraph-diag {
  background: var(--md-default-fg-color--lightest, #0002);
}

/* A thicker rule where a new layer starts */
.mxlgraph-matrix .mxlgraph-layer {
  border-left: 2px solid var(--md-default-fg-color--light, #0008);
}

.mxlgraph-matrix tr.mxlgraph-layer > * {
  border-top: 2px solid var(--md-default-fg-color--light, #0008);
}

.mxlgraph-layers {
  padding-left: 1.6rem;
  overflow-wrap: anywhere;
}

.mxlgraph-side {
  overflow: auto;
  overscroll-behavior: contain;
  padding: 0 0.5rem;
  border: 1px solid var(--mxlgraph-border);
  border-radius: 0.2rem;
}

.mxlgraph-side h3 {
  margin: 0.6rem 0 0.3rem;
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.mxlgraph-side pre {
  margin: 0.3rem 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.mxlgraph-side dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.1rem 0.5rem;
  margin: 0.3rem 0;
}

.mxlgraph-side dt {
  color: var(--md-default-fg-color--light);
}

.mxlgraph-side dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.mxlgraph-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.mxlgraph-ids {
  padding-left: 1rem;
  overflow-wrap: anywhere;
}

@container (width < 50rem) {
  .mxlgraph-main {
    grid-template-columns: 1fr;
    height: auto;
  }

  .mxlgraph-canvas,
  .mxlgraph-matrix {
    height: 60vh;
  }

  .mxlgraph-side {
    max-height: 50vh;
  }
}
