/* The Process diagram: a Go-drawn SVG of the department × stage grid with handoff arrows at two
   zoom levels (D110). Colours come from tokens only; geometry is in diagram units set in the
   template. diagram.js writes the viewBox, the level class and the popovers. */

/* The figure fills the view like the map's scroll box. --dg-cw/--dg-ch are the sticky header row
   and department label column (K49b): real HTML outside the SVG, so they stay at the map's type
   sizes and stay visible when the diagram is panned away from the top or left. */
.dg{--dg-cw:8.5rem;--dg-ch:3.25rem;display:flex;flex-direction:column;flex:1;min-height:0;margin:0}
.dg-tools{flex:none;display:flex;align-items:center;flex-wrap:wrap;gap:var(--space-2);margin-bottom:var(--space-2);min-height:var(--ctl-h)}
#dg-hint{color:var(--muted);font-size:var(--fs-sm)}
#dg-fit{width:auto;padding:0 var(--space-2)}
.dg-lane-step{display:inline-flex;align-items:center;gap:var(--space-1)}
.dg-lane-name{font-size:var(--fs-sm);font-weight:var(--fw-strong);color:var(--ink-2);white-space:nowrap}
.dg-scroll{position:relative;flex:1;min-height:0;overflow:hidden;touch-action:none;cursor:grab;overscroll-behavior:contain;border:var(--card-border);border-bottom:var(--card-border-b);border-radius:var(--card-radius);background:var(--card-bg)}
.dg-scroll.is-panning{cursor:grabbing}
.dg-scroll:focus-visible{outline:2px solid var(--focus);outline-offset:-2px}
.dg-view{position:absolute;inset:var(--dg-ch) 0 0 var(--dg-cw)}
.dg-svg{display:block;width:100%;height:100%;user-select:none}

/* The sticky chrome: a corner, the stage header row and the department label column. diagram.js
   builds one item per column and lane from the SVG labels and sets its left/top/width/height from
   the viewBox every frame, so the text is never scaled and never scrolls out of view. */
.dg-chrome{position:absolute;inset:0;pointer-events:none}
.dg-chrome[hidden]{display:none}
.dg-corner{position:absolute;left:0;top:0;width:var(--dg-cw);height:var(--dg-ch);z-index:3;background:var(--surface-2);border-right:1px solid var(--line);border-bottom:1px solid var(--line)}
.dg-head{position:absolute;left:var(--dg-cw);right:0;top:0;height:var(--dg-ch);overflow:hidden;z-index:2;background:var(--surface-2);border-bottom:1px solid var(--line)}
.dg-lab{position:absolute;left:0;top:var(--dg-ch);bottom:0;width:var(--dg-cw);overflow:hidden;z-index:2;background:var(--surface-2);border-right:1px solid var(--line)}
.dg-hcol,.dg-lrow{position:absolute;box-sizing:border-box;display:flex;flex-direction:column;overflow:hidden;padding:calc(0.25rem * var(--dz)) var(--space-2);color:var(--ink-2);text-decoration:none;pointer-events:auto;cursor:zoom-in}
.dg-hcol{top:0;height:100%;justify-content:flex-end;border-left:1px solid var(--grid)}
.dg-lrow{left:0;width:100%;justify-content:center}
.dg-hcol-name,.dg-lrow-name{font-size:var(--fs-sm);font-weight:var(--fw-strong);line-height:1.2}
.dg-hcol small,.dg-lrow small{font-size:var(--fs-xs);font-weight:var(--fw-medium);color:var(--muted);line-height:1.2;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.dg-hcol.is-tight small,.dg-lrow.is-tight small{display:none}
/* The compare change line on a lane or column label ("+1 −1 ~22"), above the mode stack (K50). */
.dg-hcol-chg,.dg-lrow-chg{font-size:var(--fs-xs);font-weight:var(--fw-strong);color:var(--ink-2);line-height:1.2;white-space:nowrap;pointer-events:none}
.dg-hcol-chg .n-add,.dg-lrow-chg .n-add{color:var(--chg-add)}
.dg-hcol-chg .n-del,.dg-lrow-chg .n-del{color:var(--chg-del)}
.dg-hcol-chg .n-edit,.dg-lrow-chg .n-edit{color:var(--chg-edit)}
.dg-hcol.is-tight .dg-hcol-chg,.dg-lrow.is-tight .dg-lrow-chg{display:none}
/* At a thumbnail zoom (a phone's Fit view) a row or column is too small for any text; hide the name
   so the labels cannot overlap, and leave the row and column itself as the zoom target. */
.dg-hcol.is-tiny,.dg-lrow.is-tiny{visibility:hidden}
/* With the chrome built the SVG's own label band is never shown; hide it so its text, which starts
   left of the viewBox, cannot bleed into the pane (K49b). */
[data-chrome] .dg-lanes .dg-label,[data-chrome] .dg-cols .dg-label{display:none}
.dg-hcol:hover,.dg-lrow:hover,.dg-hcol:focus-visible,.dg-lrow:focus-visible{background:var(--accent-wash)}
.dg-hcol:hover .dg-hcol-name,.dg-lrow:hover .dg-lrow-name{text-decoration:underline;text-underline-offset:3px}
.dg-hcol:focus-visible,.dg-lrow:focus-visible{outline:2px solid var(--focus);outline-offset:-2px}

/* The key under the toolbar (the map's four levels, plus the arrow and the inside badge). */
#dg-legend .dg-key{display:inline-flex;align-items:center;gap:calc(0.25rem * var(--dz))}
.dg-key-line{width:1.5rem;height:0;border-top:2px solid var(--ink-2);display:inline-block}
.dg-key-inside{width:0.75rem;height:0.75rem;display:inline-block;border-radius:var(--radius-round);border:2px solid var(--muted)}

/* Lanes: alternating bands with a grid separator. */
.dg-lane-bg{fill:var(--surface);stroke:var(--grid);stroke-width:1}
.dg-lane:nth-child(even) .dg-lane-bg{fill:var(--surface-2)}

/* Labels: the department down the side, the stage across the top; both zoom to their band. */
.dg-label-hit{fill:transparent;stroke:none}
.dg-label a{cursor:zoom-in}
.dg-label a:hover .dg-label-hit{fill:var(--accent-wash)}
.dg-label-name,.dg-col-name{fill:var(--ink);font-size:var(--fs-sm);font-weight:var(--fw-strong)}
.dg-label-meta,.dg-col-meta{fill:var(--muted);font-size:var(--fs-xs)}
.dg-label-chg,.dg-col-chg{fill:var(--ink-2);font-size:var(--fs-xs);font-weight:var(--fw-strong)}
.dg-col .dg-label-hit{fill:var(--surface-2)}
.dg-col .dg-label a:hover .dg-label-hit{fill:var(--accent-wash)}

/* Cells: filled boxes at the cell level, faint outlines behind the processes when zoomed in. */
.dg-cell-rect{fill:var(--surface-2);stroke:var(--line);stroke-width:1;rx:var(--radius-5)}
.dg-cell a{cursor:pointer}
.dg-cell-nums{fill:var(--ink);font-size:var(--fs-h3);font-weight:var(--fw-bold);font-variant-numeric:tabular-nums}
.dg-cell-count{fill:var(--muted);font-size:var(--fs-lg)}
.dg-cell-chg{fill:var(--ink-2);font-size:var(--fs-lg);font-weight:var(--fw-strong)}
.dg-cell-chg .n-add{fill:var(--chg-add)}
.dg-cell-chg .n-del{fill:var(--chg-del)}
.dg-num-ghost{text-decoration:line-through;fill:var(--chg-del)}
.dg-inside{fill:var(--ink-2);font-size:var(--fs-lg);font-weight:var(--fw-strong)}
.dg-cell-bar{fill:var(--m-unrated)}
.dg-cell-bar.seg-manual{fill:var(--m-manual)}
.dg-cell-bar.seg-hybrid{fill:var(--m-hybrid)}
.dg-cell-bar.seg-system{fill:var(--m-system)}
.dg-cell-bar.seg-automated{fill:var(--m-automated)}
.dg-cell:hover .dg-cell-rect,.dg-cell.is-hover .dg-cell-rect{stroke:var(--ink-2)}

/* Arrows: a wide invisible hit line, a halo that lifts the line off the grid, then the line. All
   three are <use> references to one shared <defs> path (K49b), so the path data is written once per
   edge; stroke and stroke-width inherit into the reference. */
.dg-hit,.dg-halo,.dg-line{fill:none;stroke-linecap:round;stroke-linejoin:round}
.dg-halo{stroke:var(--surface);stroke-width:4}
.dg-hit{stroke:transparent;stroke-width:12}
.dg-line{stroke:var(--ink-2);stroke-width:1.5}
.dg-line.is-multi{stroke-width:3}
.dg-edge{cursor:pointer}
.dg-edge.is-hover .dg-line{stroke:var(--accent-ink);stroke-width:2.5}
.dg-edge.is-hover .dg-halo{stroke-width:6}
.dg-count{fill:var(--ink);font-size:var(--fs-2xs);font-weight:var(--fw-bold);text-anchor:middle;paint-order:stroke;stroke:var(--surface);stroke-width:3px;stroke-linejoin:round}
.dg-edge-mark{font-size:var(--fs-sm);font-weight:var(--fw-bold);text-anchor:middle;paint-order:stroke;stroke:var(--surface);stroke-width:3px;stroke-linejoin:round;fill:var(--ink-2)}
.dg-edge-mark.chg-added{fill:var(--chg-add)}
.dg-edge-mark.chg-deleted{fill:var(--chg-del)}
.dg-marker{fill:var(--ink-2)}
.dg-marker.chg-added{fill:var(--chg-add)}
.dg-marker.chg-deleted{fill:var(--chg-del)}
.dg-marker.sel{fill:var(--accent)}

/* Process boxes: the ID and name; also the far-zoom number and the SIPOC strip (one shared <defs>
   group per distinct mode pattern, referenced with <use>; K49b). */
.dg-box-rect{fill:var(--surface-2);stroke:var(--line);stroke-width:1;rx:var(--radius-xs)}
.dg-box:hover .dg-box-rect,.dg-box.is-hover .dg-box-rect{stroke:var(--ink-2)}
.dg-num{fill:var(--ink);font-size:var(--fs-h3);font-weight:var(--fw-bold);font-variant-numeric:tabular-nums}
.dg-id{fill:var(--muted);font-size:var(--fs-sm);font-weight:var(--fw-strong)}
.dg-name{fill:var(--ink);font-size:var(--fs-xs-plus)}
.dg-strip use,.dg-strip rect{stroke:none}
.dg-lv{fill:var(--m-unrated)}
.dg-lv.s-manual{fill:var(--m-manual)}
.dg-lv.s-hybrid{fill:var(--m-hybrid)}
.dg-lv.s-system{fill:var(--m-system)}
.dg-lv.s-automated{fill:var(--m-automated)}
.dg-lv.s-unrated{fill:var(--m-unrated)}

/* The change chip on a box (an SVG chip: a <button> has no box inside <svg>). */
.dg-chip rect{fill:var(--ink-2)}
.dg-chip text{fill:var(--on-chg);font-size:var(--fs-2xs);font-weight:var(--fw-bold)}
.dg-chip.chg-added rect{fill:var(--chg-add)}
.dg-chip.chg-edited rect{fill:var(--chg-edit)}
.dg-chip.chg-deleted rect{fill:var(--chg-del)}
.dg-box[data-change="added"] .dg-box-rect{stroke:var(--chg-add);stroke-width:2}
.dg-box[data-change="edited"] .dg-box-rect{stroke:var(--chg-edit);stroke-width:2}
.dg-box[data-change="deleted"] .dg-box-rect{stroke-dasharray:4 3;stroke:var(--chg-del)}
.dg-box.is-ghost .dg-box-rect{fill:none;stroke-dasharray:4 3}
.dg-box.is-ghost .dg-box-rect{stroke:var(--chg-del)}
.dg-box.is-ghost .dg-id{text-decoration:line-through;fill:var(--chg-del)}
.dg-box.is-ghost .dg-num{text-decoration:line-through;fill:var(--chg-del)}

/* Compare, focus and filter states, set by K50 (classes defined here so only the data changes):
   is-sel / is-up / is-down / is-dim on cells, boxes and edges; chg-added / chg-edited / chg-deleted /
   chg-mixed; is-ghost. */
.dg-box.is-sel .dg-box-rect,.dg-cell.is-sel .dg-cell-rect,.dg-edge.is-sel .dg-line{stroke:var(--accent);stroke-width:2.5}
.dg-box.is-up .dg-box-rect,.dg-cell.is-up .dg-cell-rect{stroke:var(--ink-2);stroke-dasharray:4 3}
.dg-box.is-down .dg-box-rect,.dg-cell.is-down .dg-cell-rect{stroke:var(--ink);stroke-width:2}
.dg-box.is-dim,.dg-cell.is-dim,.dg-edge.is-dim,.dg-lane.is-dim .dg-label,.dg-col.is-dim .dg-label{opacity:.35}
.dg-box.chg-added .dg-box-rect,.dg-cell.chg-added .dg-cell-rect{stroke:var(--chg-add);stroke-width:2}
.dg-box.chg-edited .dg-box-rect,.dg-cell.chg-edited .dg-cell-rect{stroke:var(--chg-edit);stroke-width:2}
.dg-box.chg-deleted .dg-box-rect,.dg-cell.chg-deleted .dg-cell-rect{stroke:var(--chg-del);stroke-dasharray:4 3}
.dg-edge.chg-added .dg-line{stroke:var(--chg-add)}
.dg-edge.chg-deleted .dg-line{stroke:var(--chg-del);stroke-dasharray:4 3}
.dg-cell-edge.chg-mixed .dg-line{stroke:var(--ink-2)}
.dg-cell.is-ghost .dg-cell-rect{fill:none;stroke-dasharray:4 3}

/* The compare legend key (K50). */
#dg-legend .dg-key-cmp{color:var(--muted)}
#dg-legend .dg-key-cmp b{font-weight:var(--fw-bold)}
#dg-legend .dg-cmp-add{color:var(--chg-add)}
#dg-legend .dg-cmp-edit{color:var(--chg-edit)}
#dg-legend .dg-cmp-del{color:var(--chg-del)}
.dg-key-line.dg-key-del{border-top-style:dashed;border-top-color:var(--chg-del)}
.dg-key-line.dg-key-add{border-top-color:var(--chg-add)}

/* Level of detail inside the process level (D110). */
[data-lod="far"] .dg-id,[data-lod="far"] .dg-name,[data-lod="far"] .dg-strip{display:none}
[data-lod="near"] .dg-num{display:none}

/* The level switch: one attribute on the root crossfades the two groups; nothing moves (D110). */
.dg-level-procs,.dg-cell-edges{transition:opacity .15s ease}
[data-level="cells"] .dg-level-procs{opacity:0;pointer-events:none}
[data-level="procs"] .dg-cell-edges{opacity:0;pointer-events:none}
[data-level="procs"] .dg-cell-rect{fill:none;stroke:var(--grid)}
[data-level="procs"] .dg-cell-nums,[data-level="procs"] .dg-cell-count,[data-level="procs"] .dg-inside,[data-level="procs"] .dg-cell-modes{display:none}
[data-level="procs"] .dg-cell a{cursor:default}
[data-level="cells"] .dg-box a{cursor:default}
@media (prefers-reduced-motion:reduce){
  .dg-level-procs,.dg-cell-edges{transition:none}
}

/* Focus rings for the keyboard (the anchors and the edge groups). */
.dg-box a:focus-visible,.dg-cell a:focus-visible,.dg-label a:focus-visible{outline:2px solid var(--focus);outline-offset:2px}
.dg-box a:focus-visible .dg-box-rect,.dg-cell a:focus-visible .dg-cell-rect{stroke:var(--focus);stroke-width:2}
.dg-edge:focus-visible{outline:none}
.dg-edge:focus-visible .dg-line{stroke:var(--focus);stroke-width:2.5}
.dg-edge:focus-visible .dg-halo{stroke-width:6}

/* Popovers: the .pop-panel look, fixed beside the target, moved into #dg-pop-layer by diagram.js. */
#dg-pop-layer{position:fixed;inset:0;z-index:var(--z-pop);pointer-events:none}
.dg-pops[hidden]{display:none}
.dg-pop{position:fixed;z-index:var(--z-pop);width:min(var(--w-pop),calc(100vw - 2rem));max-height:70vh;overflow:auto;pointer-events:auto;text-align:left}
.dg-pop-head{margin:0 0 var(--space-1);font-size:var(--fs-md)}
.dg-pop-note{margin:0 0 var(--space-1);font-size:var(--fs-sm);color:var(--ink-2)}
.dg-pop-note.chg-added{color:var(--chg-add)}
.dg-pop-note.chg-edited{color:var(--chg-edit)}
.dg-pop-note.chg-deleted{color:var(--chg-del)}
.dg-pills{display:flex;flex-wrap:wrap;gap:var(--space-1);margin:0 0 var(--space-1)}
.dg-pop-links{margin:var(--space-2) 0 0}
.dg-pop-list{margin:var(--space-1) 0;padding-left:1.1rem}
.dg-pop .stack{margin-top:var(--space-2)}
.dg-pop .stack .seg{flex:1 1 0}

/* The fallback table is screen-reader-only by default. A table ignores the sr-only width/height (its
   rows set its height and overflow is not clipped), so pin it: a fixed element stays out of the
   document's scroll area and clip-path hides it. */
#dg-fallback.sr-only{position:fixed;top:0;left:0;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap;border:0}

/* Phones (D116): Fit / Lane / Table, below 45 em only. The scroll box is 75dvh like the map's. */
#dg-phone-view,#dg-lane-step{display:none}
@media (max-width:45em){
  .dg{--dg-cw:7rem;--dg-ch:3rem}
  .dg-scroll{height:75dvh;flex:none}
  #dg-phone-view{display:inline-flex}
  .dg[data-phone="lane"] #dg-lane-step{display:inline-flex}
  .dg[data-phone="table"] .dg-scroll{display:none}
  .dg[data-phone="table"] .dg-tools #dg-hint{display:none}
  #dg-fallback.dg-table{display:block;height:75dvh;overflow:auto}
}
