/* ---- inline architecture diagrams (neubrutalism) ---- */
.diagram { position: relative; margin: var(--s4) 0; padding: var(--s4); border: var(--border); box-shadow: var(--shadow); background: var(--surface); }
.diagram .mono-label { display: block; margin-bottom: var(--s2); font-size: 0.78rem; }
.diagram svg.dg { width: 100%; height: auto; display: block; margin-top: var(--s2); max-height: 820px; touch-action: none; }
.diagram svg.dg.is-zoomed { cursor: grab; }
.diagram svg.dg.is-zoomed:active { cursor: grabbing; }
.diagram .dg-node { cursor: pointer; }
.dg-caption { margin-top: var(--s2); font-size: var(--t-small); font-style: italic; color: var(--ink-2); }

/* inline pan/zoom controls */
.dg-pan-bar { position: absolute; top: var(--s4); right: var(--s4); z-index: 3; display: flex; gap: 6px; }
.dg-pan-bar button { font-family: var(--mono); font-weight: 700; font-size: 13px; line-height: 1.5; color: var(--ink); background: var(--surface); border: 2px solid var(--ink); box-shadow: 2px 2px 0 var(--ink); padding: 2px 9px; cursor: pointer; }
.dg-pan-bar button:hover { background: var(--accent-2); }
.dg-pan-bar button:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--ink); }

/* nodes */
.dg-node rect { fill: var(--surface); stroke: var(--ink); stroke-width: 2.5; rx: 0; }
.dg-node text { font-family: var(--mono); text-anchor: middle; fill: var(--ink); font-weight: 600; }
.dg-label { font-size: 12px; font-weight: 700; }
.dg-label.dg-tight { font-size: 10.5px; letter-spacing: -0.02em; }
.dg-sub { font-size: 9.5px; fill: var(--ink-2); }
.dg-sigil { font-family: var(--mono); font-size: 11px; fill: var(--ink-2); text-anchor: start; }
.dg-gateway .dg-sigil { fill: rgba(255,255,255,0.8); }

.dg-client rect { fill: var(--accent-2); }
.dg-gateway rect { fill: var(--ink); }
.dg-gateway .dg-label { fill: var(--bg); }
.dg-gateway .dg-sub { fill: rgba(255, 255, 255, 0.72); }
.dg-db rect { fill: #eae6d8; }
.dg-cache rect { fill: #eae6d8; }
.dg-queue rect { fill: #eae6d8; }
.dg-external rect { fill: transparent; stroke-dasharray: 5 4; stroke: var(--ink-2); }
.dg-external text { fill: var(--ink-2); }
.dg-reject rect { fill: var(--surface); stroke: var(--bad); }
.dg-reject text { fill: var(--bad); }

/* edges */
.dg-edge path { fill: none; stroke: var(--ink); stroke-width: 2; }
.dg-e-dashed path { stroke-dasharray: 5 4; stroke: var(--ink-2); }
.dg-e-bad path { stroke: var(--bad); stroke-width: 3.5; }
.dg-e-good path { stroke: var(--good); stroke-width: 3; }

/* directional flow — a packet marching along each edge toward its arrowhead */
.dg-flow {
  fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linecap: round;
  stroke-dasharray: 2 15; pointer-events: none; animation: dg-flow 1s linear infinite;
}
.dg-e-dashed .dg-flow { stroke: var(--ink-2); }
.dg-e-bad .dg-flow { stroke: var(--bad); }
.dg-e-good .dg-flow { stroke: var(--surface); }
@keyframes dg-flow { to { stroke-dashoffset: -17; } }

.dg-elabel {
  font-family: var(--mono); font-size: 10px; font-weight: 600; text-anchor: middle;
  fill: var(--ink-2); paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round;
}
.dg-e-bad .dg-elabel { fill: var(--bad); }
.dg-e-good .dg-elabel { fill: var(--good); }

/* groups */
.dg-group rect { fill: none; stroke: var(--ink-2); stroke-width: 1.5; stroke-dasharray: 6 4; }
.dg-group-label { font-family: var(--mono); font-size: 9px; font-weight: 600; fill: var(--ink-2); text-anchor: start; }

/* legend */
.dg-legend-sw { stroke: var(--ink); stroke-width: 1.5; }
.dg-legend-tx { font-family: var(--mono); font-size: 9px; fill: var(--ink-2); }
.dg-legend-sig { font-family: var(--mono); font-size: 8px; fill: var(--ink); text-anchor: middle; }
.dg-gateway .dg-legend-sig { fill: rgba(255,255,255,0.9); }

/* arrowheads */
#dg-a path { fill: var(--ink); }
#dg-a-bad path { fill: var(--bad); }
#dg-a-good path { fill: var(--good); }
#dg-a-dim path { fill: var(--ink-2); }

/* highlight states — glossary hover / focus owns dg-hot/dg-dim */
svg.dg [data-id] { transition: opacity 0.3s; }
.dg-dim { opacity: 0.25; }
.dg-node.dg-hot rect { stroke: var(--accent); stroke-width: 3.5; filter: drop-shadow(0 0 8px var(--accent)); }
.dg-edge.dg-hot path:not(.dg-flow) { stroke-width: 3.5; filter: drop-shadow(0 0 6px var(--accent)); } /* keep semantic bad/good colors */

svg.dg {
  background-image: radial-gradient(color-mix(in srgb, var(--ink-2) 65%, transparent) 1px, transparent 1px);
  background-size: 22px 22px;
  background-position: -1px -1px;
}

@media (prefers-reduced-motion: reduce) {
  svg.dg [data-id] { transition: none; }
  .dg-node.dg-hot rect, .dg-edge.dg-hot path { filter: none; }
  .dg-flow { animation: none; opacity: 0; }
}

/* ---- glossary ---- */
.dg-gloss { cursor: pointer; }
.dg-gloss .dg-label { text-decoration: underline dotted; text-underline-offset: 3px; }
.dg-gloss:focus { outline: none; }
.dg-gloss:focus rect { stroke: var(--accent); stroke-width: 3.5; }
.diagram { position: relative; }
.dg-pop {
  position: absolute; right: var(--s3); top: var(--s4); max-width: 300px; z-index: 5;
  background: var(--surface); border: var(--border); box-shadow: var(--shadow); padding: var(--s3);
}
.dg-pop h4 { font-family: var(--mono); margin: 0 0 var(--s2); }
.dg-pop p { font-size: var(--t-small); margin: 0 0 var(--s2); }
.dg-pop .dg-pop-when { font-family: var(--mono); font-size: 0.72rem; color: var(--ink-2); margin: 0; }
.dg-pop > button { position: absolute; top: 4px; right: 6px; border: none; background: none; cursor: pointer; font-size: 1rem; }

/* ---- inline glossary terms ---- */
.dg-term { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; font: inherit; }
.dg-term:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.scenario, .option, .lesson { position: relative; }

/* ---- fullscreen expand (in-place: fig becomes fixed/inset:0, svg fills viewport) ---- */
.dg-full-btn {
  position: absolute; bottom: var(--s4); right: var(--s4); z-index: 3;
  font-family: var(--mono); font-weight: 700; font-size: 15px; line-height: 1;
  color: var(--ink); background: var(--surface); border: 2px solid var(--ink);
  box-shadow: 2px 2px 0 var(--ink); padding: 4px 8px; cursor: pointer;
}
.dg-full-btn:hover { background: var(--accent-2); }
.dg-full-btn:active { transform: translate(1px, 1px); box-shadow: 1px 1px 0 var(--ink); }
.diagram.dg-fullscreen, .sol-panel.dg-fullscreen {
  position: fixed; inset: 0; z-index: 50; margin: 0; width: 100vw; height: 100vh;
  max-width: none; display: flex; flex-direction: column; overflow: auto;
}
.dg-fullscreen svg.dg { flex: 1; width: 100%; height: 100%; max-height: none; min-height: 0; }
