/* =========================================================================
   source-glossary-search.css: the Sources workspace's search and join path
   diagrams (web/modules/source-glossary-search.js). Theme tokens only.

   Colour carries meaning only, and never alone:
     declared         --csl        solid line, filled arrow
     verified         --ok-text    heavy solid line, arrow with a bar at its tip
     module-reviewed  --info       solid line, ring end
     suggested        --warn-text  dashed line, open arrow, labelled
     rejected         --down-text  dotted line, bar end
   Every line also carries its state in words.
   ========================================================================= */

.sg-search { display: grid; gap: var(--space-4); }

.sg-search-form, .sg-path-form {
  display: grid; gap: var(--space-3);
  padding: var(--space-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl);
}
.sg-search-question input { width: 100%; font-size: var(--fs-base); }
.sg-search-filters, .sg-path-form {
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}
.sg-search-filters { display: grid; gap: var(--space-3); align-items: end; }
.sg-search-filters .field, .sg-path-form .field { margin-bottom: 0; }
.sg-path-form .btn-row, .sg-path-form .sg-check { grid-column: 1 / -1; }
.sg-path-end { display: grid; grid-template-columns: 110px 1fr; gap: var(--space-2); grid-column: span 2; }
.sg-systems { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); border: 0; padding: 0; margin: 0; }
.sg-systems legend { font-size: var(--fs-micro); font-weight: 600; color: var(--text-body); margin-bottom: var(--space-1); }
.sg-check { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; color: var(--text-body); }
.sg-muted { color: var(--text-faint); font-size: var(--fs-micro); }

/* The figure: headline, the diagram at full width, then its legend and list side by side, notes and coverage.
   The diagram is drawn at 1:1 for the width it was given and scrolls rather than shrinks. */
.sg-figure { margin: 0; display: grid; gap: var(--space-3); }
.sg-headline { font-size: var(--fs-h3); font-weight: 600; color: var(--text); }
.sg-figure-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-4); align-items: start; }
.sg-diagram-scroll {
  overflow: auto; max-height: 78vh;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl); padding: var(--space-2);
}
.sg-figure-side { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: var(--space-3); align-items: start; font-size: var(--fs-micro); color: var(--text-body); }
.sg-note-withheld, .sg-note-cap, .sg-note-restricted, .sg-note-crosswalk { color: var(--warn-deep); }

/* Legend and plain list. */
.sg-legend { list-style: none; margin: 0; padding: var(--space-3); display: grid; gap: 6px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.sg-legend li { display: flex; align-items: center; gap: var(--space-2); }
.sg-swatch { flex: none; overflow: visible; }
.sg-plain-list { margin: 0; padding-left: var(--space-4); display: grid; gap: 4px; max-height: 60vh; overflow: auto; }
.sg-plain-list ul, .sg-plain-list ol { padding-left: var(--space-4); margin: 2px 0; }
.sg-list-facts { color: var(--text-faint); }
.sg-link { appearance: none; background: none; border: 0; padding: 0; color: var(--brand); font: inherit; font-family: var(--mono); cursor: pointer; text-decoration: underline; }
.sg-link:focus-visible { outline: 2px solid var(--brand-ring); outline-offset: 1px; }

/* The diagram. The page's global svg rule (fill none, stroke currentColor) is undone here: text is never stroked
   (only edge labels keep a halo), and every shape states its own fill and stroke. */
.sg-diagram { display: block; max-width: none; height: auto; font-family: var(--font); color: var(--text-faint); }
.sg-diagram text { fill: var(--text-body); font-size: var(--fs-micro); stroke: none; }
.sg-diagram .sg-col-head { font-size: var(--fs-label); font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; fill: var(--text-faint); }
.sg-diagram .sg-lane-head { font-size: var(--fs-micro); font-weight: 700; fill: var(--text-dim); }
.sg-diagram .sg-system-head { fill: var(--text-dim); font-weight: 600; font-family: var(--mono); }
.sg-lane-band { fill: var(--surface-subtle); stroke: var(--border-subtle); stroke-width: 1; }
.sg-lane-suggestions .sg-lane-band { fill: var(--warn-tint); stroke: var(--warn-border); stroke-dasharray: 6 4; }
.sg-lane-notheld .sg-lane-band { fill: var(--unknown-tint); stroke: var(--unknown); stroke-dasharray: 2 3; }
.sg-path-card { fill: var(--surface); stroke: var(--border); stroke-width: 1; }
.sg-diagram .sg-path-head { fill: var(--text); font-weight: 600; }
/* A path through a configuration, actor or lookup table in the middle: a heavy dashed card, a band and the word
   "Warning" at its head, never colour alone. */
.sg-path-card.is-warning { stroke: var(--down-text); stroke-width: 2; stroke-dasharray: 8 4; }
.sg-path-warn-band { fill: var(--down-tint); stroke: none; }
.sg-diagram .sg-path-warn { fill: var(--down-text); font-weight: 700; }
/* A middle table whose type is not known: said in words, set in italics so it reads as a caveat, not a fact. */
.sg-diagram .sg-path-unknown { font-style: italic; }
/* "No path": the statement in large type between the two groups. */
.sg-diagram .sg-no-path-label { fill: var(--down-text); font-size: var(--fs-body); font-weight: 700; paint-order: stroke; stroke: var(--surface); stroke-width: 3px; }

.sg-shape { fill: var(--surface); stroke: var(--border-strong); stroke-width: 1.2; }
.sg-diagram .sg-node-title { fill: var(--text); font-weight: 600; font-family: var(--mono); }
.sg-diagram .sg-node-sub { fill: var(--text-faint); }
.sg-diagram .sg-node-column { fill: var(--text-body); font-family: var(--mono); }
.sg-node-rule { stroke: var(--border-subtle); stroke-width: 1; }

.sg-style-node-question .sg-shape { fill: var(--brand-tint); stroke: var(--brand-border); stroke-width: 1.6; }
.sg-style-node-word .sg-shape, .sg-style-node-filter .sg-shape { fill: var(--surface); stroke: var(--border-strong); }
.sg-style-node-concept .sg-shape { fill: var(--il-tint); stroke: var(--il-border); }
.sg-concept-bar { fill: var(--il); stroke: none; }
.sg-style-node-table .sg-shape { fill: var(--surface); stroke: var(--border-strong); }
.sg-style-node-table.is-suggestion .sg-shape { stroke: var(--warn-text); stroke-dasharray: 5 3; }
.sg-style-node-table-restricted .sg-shape { fill: var(--surface-muted); stroke: var(--text-faint); stroke-width: 2; }
.sg-hatch-line { stroke: var(--border-strong); stroke-width: 1; }
.sg-style-node-generic-store .sg-shape { fill: var(--csl-tint); stroke: var(--csl); }
.sg-style-node-generic-store.is-suggestion .sg-shape { fill: var(--surface); stroke: var(--warn-text); stroke-dasharray: 5 3; }
.sg-style-node-absent .sg-shape { fill: var(--unknown-tint); stroke: var(--unknown); stroke-dasharray: 2 3; }
.sg-style-node-withheld .sg-shape { fill: var(--warn-tint); stroke: var(--warn-border); stroke-dasharray: 5 3; }
.sg-style-node-component .sg-shape { fill: var(--surface-muted); stroke: var(--border-strong); }

g[data-sg-open-table] { cursor: pointer; }
g[data-sg-open-table]:hover .sg-shape { stroke: var(--brand); }
g[data-sg-open-table]:focus { outline: none; }
g[data-sg-open-table]:focus-visible .sg-shape { stroke: var(--brand); stroke-width: 3; }

/* Lines: state is colour AND line style AND end marker AND words. */
.sg-edge-line { fill: none; stroke: var(--text-faint); stroke-width: 1.5; }
/* Drawn under a line that may cross a bus: the bus shows a gap there, so a crossing never reads as a branch. */
.sg-edge-halo { fill: none; stroke: var(--surface); stroke-width: 7; stroke-dasharray: none; }
.sg-edge-line.sg-crowfoot { stroke-dasharray: none; stroke-linecap: round; }
.sg-diagram .sg-edge-label {
  fill: var(--text-body); font-size: var(--fs-label);
  paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round;
}
.sg-diagram .sg-edge-label-2 { fill: var(--text-faint); }
.sg-diagram .sg-edge-label-mark { fill: var(--text); font-weight: 600; }
.sg-marker-fill { fill: var(--text-faint); stroke: none; }
.sg-marker-open, .sg-marker-bar { fill: none; stroke: var(--text-faint); stroke-width: 1.6; }
.sg-junction { fill: var(--text-faint); stroke: none; }
.sg-style-state-declared .sg-junction { fill: var(--csl); }
.sg-style-state-verified .sg-junction { fill: var(--ok-text); }
.sg-style-state-module-reviewed .sg-junction { fill: var(--info); }
.sg-style-state-suggested .sg-junction { fill: var(--warn-text); }
.sg-style-state-rejected .sg-junction { fill: var(--down-text); }

/* A mark on a hop's line (where, actor, lookup, config, trigger): a word in a pill, never colour alone. */
.sg-badge rect { fill: var(--surface); stroke: var(--text-dim); stroke-width: 1.2; }
.sg-diagram .sg-badge text { font-size: var(--fs-label); font-weight: 700; fill: var(--text); }
.sg-badge-key { display: inline-block; min-width: 40px; padding: 0 6px; border: 1px solid var(--text-dim); border-radius: 8px; font-size: var(--fs-label); font-weight: 700; text-align: center; color: var(--text); }

.sg-style-edge-reading .sg-edge-line { stroke: var(--text-faint); stroke-width: 1; }
.sg-style-state-declared .sg-edge-line { stroke: var(--csl); stroke-width: 2; }
.sg-style-state-verified .sg-edge-line { stroke: var(--ok-text); stroke-width: 3.2; }
.sg-style-state-module-reviewed .sg-edge-line { stroke: var(--info); stroke-width: 2; }
.sg-style-state-suggested .sg-edge-line { stroke: var(--warn-text); stroke-width: 2; stroke-dasharray: 7 5; }
.sg-style-state-rejected .sg-edge-line { stroke: var(--down-text); stroke-width: 1.6; stroke-dasharray: 1.5 4; stroke-linecap: round; }
.sg-style-edge-none .sg-edge-line { stroke: var(--unknown); stroke-width: 1.4; stroke-dasharray: 1.5 5; stroke-linecap: round; }
.sg-style-edge-no-path .sg-edge-line { stroke: var(--down-text); stroke-width: 2; }

marker.sg-style-edge-reading .sg-marker-fill { fill: var(--text-faint); }
marker.sg-style-state-declared .sg-marker-fill { fill: var(--csl); }
marker.sg-style-state-verified .sg-marker-fill { fill: var(--ok-text); }
marker.sg-style-state-verified .sg-marker-bar { stroke: var(--ok-text); stroke-width: 2; }
marker.sg-style-state-module-reviewed .sg-marker-open { stroke: var(--info); fill: var(--surface); }
marker.sg-style-state-suggested .sg-marker-open { stroke: var(--warn-text); }
marker.sg-style-state-rejected .sg-marker-bar { stroke: var(--down-text); }
marker.sg-style-edge-none .sg-marker-bar { stroke: var(--unknown); }
marker.sg-style-edge-no-path .sg-marker-bar { stroke: var(--down-text); }

.sg-legend .sg-swatch .sg-shape { stroke-width: 1.2; }

/* The lane head's qualifier: what the answer is only as good as. Bold, so "not held" is never read as firm. */
.sg-diagram .sg-lane-qualifier { font-size: var(--fs-micro); font-weight: 700; fill: var(--warn-deep); }
/* The column a line ends on: an arrow mark and bold mono, never colour alone. */
.sg-diagram .sg-node-column.is-matched { font-weight: 700; fill: var(--text); }
/* Reasons and columns of a found table that are only suggested: below a dashed rule, under their own words. */
.sg-node-rule-also { stroke: var(--warn-border); stroke-dasharray: 4 3; }
.sg-diagram .sg-node-also-head { font-size: var(--fs-label); font-weight: 700; fill: var(--warn-deep); }
/* The generic store's small diagram: two cells, the link between them, and named chips. */
.sg-store-cell { fill: var(--surface); stroke: var(--border-strong); stroke-width: 1.2; }
.sg-store-cell-def { fill: var(--surface-subtle); }
.sg-store-link { fill: none; stroke: var(--text-dim); stroke-width: 1.6; }
.sg-store-chip { fill: var(--surface); stroke: var(--border-strong); stroke-width: 1; }
.sg-diagram .sg-node-chip { font-family: var(--mono); fill: var(--text-body); }
.sg-diagram .sg-node-chip-label { fill: var(--text-dim); font-weight: 600; }
.sg-diagram .sg-node-foot { fill: var(--text-faint); font-size: var(--fs-label); }
/* The bracket joining a block's tag to its tables in the narrow layout: not a reason, so thin and neutral. */
.sg-block-rail { fill: none; stroke: var(--border-strong); stroke-width: 1.4; }
.sg-style-node-not-understood .sg-shape { fill: var(--unknown-tint); stroke: var(--unknown); stroke-dasharray: 2 3; }
.sg-style-node-more .sg-shape { fill: var(--surface-subtle); stroke: var(--border-strong); stroke-dasharray: 3 3; }
.sg-style-edge-part .sg-edge-line { stroke: var(--il); stroke-width: 1.2; }
marker.sg-style-edge-part .sg-marker-open { stroke: var(--il); fill: var(--surface); }
/* A crow's foot is never dashed, whatever the hop's state: this rule comes after the state rules on purpose. */
.sg-edge .sg-edge-line.sg-crowfoot { stroke-dasharray: none; }

/* A table's rank in its lane: in words, bold; the best match also says so in words ("best match"), never by colour. */
.sg-diagram .sg-node-rank { font-weight: 700; fill: var(--text-dim); }
.sg-diagram .sg-node-rank.is-best { fill: var(--text); }
/* What a lane draws elsewhere (inside a store, or once among the found): a plain sub line under its head. */
.sg-diagram .sg-lane-sub { fill: var(--text-dim); }
/* Columns that matched by name only: one folded line, in italics, so it reads as a weak match, not a meaning. */
.sg-diagram .sg-node-nameonly { font-style: italic; }
/* A table of a store found by the answer: its chip opens its card. */
.sg-store-chip.is-found { stroke: var(--text-dim); stroke-width: 1.4; }
text[data-sg-open-table] { cursor: pointer; text-decoration: underline; }
text[data-sg-open-table]:focus { outline: none; }
text[data-sg-open-table]:focus-visible { fill: var(--brand); }

/* The path form's table pickers: a type-ahead that asks the semantic layer, a page at a time. */
.sg-path-pick { position: relative; }
.sg-pick-list { list-style: none; margin: 4px 0 0; padding: 4px; display: grid; gap: 2px; max-height: 280px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.sg-pick-list[hidden] { display: none; }
.sg-pick-option { appearance: none; width: 100%; text-align: left; background: none; border: 0; border-radius: var(--radius-sm, 4px); padding: 4px 6px; font: inherit; color: var(--text-body); cursor: pointer; }
.sg-pick-option:hover, .sg-pick-option:focus-visible { background: var(--brand-tint); outline: none; }
.sg-pick-name { font-family: var(--mono); color: var(--text); }
.sg-pick-meta { color: var(--text-faint); font-size: var(--fs-micro); margin-left: 6px; }
.sg-pick-state { color: var(--text-dim); font-size: var(--fs-micro); padding: 4px 6px; }
.sg-pick-chosen { color: var(--text-dim); font-size: var(--fs-micro); }

/* Tables the path search kept out of the middle of a path: a lane of their own. A table kept out of every path has its
   name struck out by a drawn line (never by colour or a font decoration alone) and says the rule in words; a table
   kept out by one link only, which a path still passes through, is a dotted box that is not struck out. */
.sg-lane-avoided .sg-lane-band { fill: var(--surface-muted); stroke: var(--border-strong); stroke-dasharray: 2 4; }
.sg-style-node-avoided .sg-shape { fill: var(--surface); stroke: var(--text-faint); stroke-width: 1.2; }
.sg-diagram .sg-style-node-avoided .sg-node-title { fill: var(--text-dim); }
.sg-strike { fill: none; stroke: var(--text); stroke-width: 1.8; stroke-linecap: round; }
.sg-style-node-avoided-link .sg-shape { fill: var(--surface); stroke: var(--text-dim); stroke-width: 1.4; stroke-dasharray: 2 3; }
.sg-list-name { font-family: var(--mono); }
.sg-path-hint { grid-column: 1 / -1; margin: 0; }
.sg-result { min-width: 0; }

/* Pages of a long answer, and the joins of one result. */
.sg-pager-ask { flex-basis: 100%; margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); color: var(--text-body); }
.sg-pager { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); font-size: var(--fs-small); color: var(--text-body); }
.sg-pager-label { font-weight: 600; }
.sg-pager-cats { display: flex; flex-wrap: wrap; gap: 4px; }
.sg-pager .chip { cursor: pointer; }
.sg-pager .chip.is-active { background: var(--brand-tint); color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand-border); }
.sg-list-rest summary { cursor: pointer; color: var(--text-dim); }
.sg-joins { display: grid; gap: var(--space-3); padding: var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-xl); background: var(--surface); }
.sg-joins-form { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: end; }
.sg-joins-form .field { margin-bottom: 0; min-width: 240px; }

@media (prefers-reduced-motion: reduce) { .sg-search * { transition: none; } }

/* Round 4: how many match in all, the counts by category (each searches again in that category), the next page. */
.sg-search-paging { display: grid; gap: var(--space-2); margin-top: var(--space-3); font-size: var(--fs-small); color: var(--text-body); }
.sg-search-paging p { margin: 0; }
.sg-search-by-category { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-2); align-items: center; }
.sg-cat-count { font: inherit; font-size: var(--fs-small); padding: 2px 8px; border: 1px solid var(--border); border-radius: var(--radius-pill); background: var(--surface); color: var(--text); cursor: pointer; }
.sg-cat-count:hover { border-color: var(--brand-border); }
.sg-cat-count:focus-visible { outline: 2px solid var(--brand-ring); outline-offset: 2px; }
