/* The source map on the Sources page (Sources::MapTableComponent, MapCardComponent, MapDetailComponent, MapRunComponent, MapDecisionsComponent and ChipComponent in
   app/components/sources; docs/data_model/08-integration-and-warehouse.md section 3, "As built (the source map)"), built from the card, the badge, the figure strip,
   the table and the button, so what is here is only how they sit together.

   Linked after the sources page's own stylesheet (46-sources.css), whose `.source-facts` and `.identifier` it reuses, and after the device rules (40-native.css), so the
   touch floor still wins. Tokens only and logical properties only, both enforced (test/styles/tokens_test.rb, components_test.rb), so all of it reads on the light shell
   and on the console, in light and in dark, and mirrors in a right-to-left language. It decides no mode and no surface. Nothing is pinned to an edge except the table's
   header, which sticks to the top of its own region, and nothing sets a height in vh.

   Everything that holds words may shrink (`min-inline-size: 0`) and breaks a word that has no room, so one long label or a language 40% longer never widens the page
   (WCAG 1.4.10). A status is its words and a drawn mark, in a badge whose tone is a second signal and never the only one. */

/* ── One map, two views ───────────────────────────────────────────────────
   Both are in the page and the stylesheet shows one (the one not shown is `display: none`, which leaves it out of the reading order too, so nobody hears the map
   twice). The person's choice (`data-view` is `table` or `cards`) is always kept; with none (`auto`) the room decides, and the room is the map's own width, not the
   screen's: the console's rail takes a column from a wide screen, and a table of eight columns wants about 62rem. */

.source-map {
  container: source-map / inline-size;
  min-inline-size: 0;
  margin-block: var(--density-block);
}
.source-map .source-map-table {
  display: none;
}
.source-map .source-map-cards {
  display: grid;
}
@container source-map (min-width: 62rem) {
  .source-map[data-view="auto"] .source-map-table {
    display: block;
  }
  .source-map[data-view="auto"] .source-map-cards {
    display: none;
  }
}
.source-map[data-view="table"] .source-map-table {
  display: block;
}
.source-map[data-view="table"] .source-map-cards {
  display: none;
}

/* The page's three parts are a section's distance apart (`--section-gap`, 10-globals.css), as the sections of every console page are: they were twice the density token, which is the room between two rows. */
.source-map-section {
  min-inline-size: 0;
  margin-block-start: var(--section-gap);
}
.source-map-note {
  max-inline-size: 66ch;
  color: var(--fg2);
  font-size: var(--text-sm);
}
/* Each note is a sentence of its own in a paragraph of its own (the keys are never joined), and two of them under one heading ran together as one paragraph. */
.source-map-note + .source-map-note {
  margin-block-start: var(--space-2);
}
.source-map-heading {
  margin: 0 0 var(--space-2);
  font-size: var(--text-lg);
}

/* The choice of view: three links in a row, the one in force marked by its weight, its fill and the word the page gives it (aria-current), and none of them by color
   alone. Each is 24px at the least (WCAG 2.5.8) and the floor on touch. */
.source-map-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem var(--density-block);
  min-inline-size: 0;
  margin-block: var(--density-gap);
}
.source-map-views {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  min-inline-size: 0;
}
.source-map-views-label {
  color: var(--fg3);
  font-size: var(--text-sm);
  font-weight: 650;
}
.source-map-view-link {
  display: inline-flex;
  align-items: center;
  min-block-size: 1.5rem;
  padding-inline: 0.6rem;
  border: 1px solid var(--control-line);
  border-radius: var(--radius-md);
  color: var(--accent-text);
  font-size: var(--text-sm);
  text-decoration: none;
}
.source-map-view-link:hover {
  background: var(--surface-tint);
}
.source-map-view-link[aria-current="true"] {
  background: var(--accent-soft);
  color: var(--fg1);
  font-weight: 700;
}
.source-map-views-help {
  max-inline-size: 66ch;
  margin: 0;
  color: var(--fg2);
  font-size: var(--text-sm);
}
@media (pointer: coarse) {
  .source-map-view-link {
    min-block-size: var(--target-min);
  }
}

.source-map-tools {
  display: flex;
  justify-content: flex-end;
  min-inline-size: 0;
  margin-block-end: var(--density-gap);
}

/* ── The table ────────────────────────────────────────────────────────────
   The region is what scrolls, both ways: sideways when the table is wider than the map (it is focusable and named), and down inside the height it is given, so that
   the header, which sticks to the top of the region, stays in sight while the rows go under it. `scroll-padding` keeps what has the focus out from under the
   header (WCAG 2.4.11). The header's own color is the raised surface, so rows do not show through it; the shadow at the region's edges is the table component's. */

.source-map-region {
  inline-size: 100%;
  max-inline-size: 100%;
  min-inline-size: 0;
  max-block-size: min(80dvh, 60rem);
  overflow: auto;
  scroll-padding-block-start: 3rem;
}
.source-map-region table.data.source-map-data.data-table thead th {
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
  background: var(--surface-raised);
}
table.data.source-map-data {
  min-inline-size: 60rem;
}
/* The cells keep a little room each, so a column never shrinks to a word's width, and sit close: eight columns have to fit the console's content at 1440px. */
table.data.source-map-data.data-table :is(th, td) {
  padding-inline: var(--density-cell);
}
.source-map-data [data-column="stance"] {
  min-inline-size: 8.5rem;
}
.source-map-data [data-column="phase"] {
  min-inline-size: 5.5rem;
}
.source-map-data [data-column="compartments"] {
  min-inline-size: 6.5rem;
}
.source-map-data [data-column="network"] {
  min-inline-size: 7.5rem;
}
.source-map-data [data-column="cadence"] {
  min-inline-size: 8rem;
}
.source-map-data [data-column="last_run"] {
  min-inline-size: 9.5rem;
}
.source-map-data [data-column="decisions"] {
  min-inline-size: 6.5rem;
}
table.data.source-map-data.data-table td,
table.data.source-map-data.data-table tbody th[scope="row"] {
  padding-block: 0.6rem;
  border-block-end: 0;
}
/* A system is a group of two rows (the facts, and the deep text), and the rule is under the group; the hover tints both. */
.source-map-source-body {
  border-block-end: 1px solid var(--rule);
}
table.data.source-map-data tbody tr:hover {
  background: transparent;
}
table.data.source-map-data tbody.source-map-source-body:hover > tr {
  background: var(--surface-tint);
}
/* A table cell's chips wrap in their cell (the table component keeps a badge on one line, which a stance as long as "Integrate now, replace later" turns into a
   wide column), and none is wider than its column wants. */
table.data.source-map-data.data-table td .source-chip {
  max-inline-size: 9.5rem;
  white-space: normal;
  overflow-wrap: normal;
}
.source-map-name {
  min-inline-size: 11.5rem;
}
.source-map-source {
  display: block;
  font-weight: 700;
}
.source-map-office,
.source-map-summary {
  display: block;
  margin-block-start: 0.15rem;
  color: var(--fg2);
  font-size: var(--text-sm);
  font-weight: 400;
}
.source-map-summary {
  max-inline-size: 34ch;
}

/* The row's own button, and the one above the table that opens every row: a real control, 24px at the least and the floor on touch, the chevron turned over when the
   detail is open. */
.source-map-toggle,
.source-map-expand {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  min-block-size: 1.5rem;
  margin-block-start: 0.35rem;
  padding: 0 0.4rem;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--accent-text);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 650;
  cursor: pointer;
}
.source-map-toggle:hover,
.source-map-expand:hover {
  background: var(--surface-tint);
  border-color: var(--rule-strong);
}
.source-map-chevron {
  flex: none;
  inline-size: 1em;
  block-size: 1em;
}
.source-map-toggle[aria-expanded="true"] .source-map-chevron,
.source-map-expand[aria-expanded="true"] .source-map-chevron {
  transform: rotate(180deg);
}
@media (pointer: coarse) {
  .source-map-toggle,
  .source-map-expand {
    min-block-size: var(--target-min);
  }
}

/* The deep text of a system, in the second row of its group: closed by the controller (data-state) and open with no script, and open on paper. */
.source-map-detail-row[data-state="closed"] {
  display: none;
}
table.data.source-map-data.data-table .source-map-detail-row td {
  padding-block-start: 0;
  padding-block-end: 0.9rem;
}

/* ── What a cell or a card holds ─────────────────────────────────────────── */

.map-plain-list,
.map-chip-list,
.map-decisions,
.map-reads,
.map-networks,
.map-rejections {
  margin: 0;
  padding: 0;
  list-style: none;
  min-inline-size: 0;
}
.map-plain-list li {
  overflow-wrap: break-word;
}
.map-chip-list {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
}
.map-quiet {
  margin: 0;
  color: var(--fg2);
}
/* The words under a source's compartments when the decision that settles the walls is still open. */
.map-compartment-note {
  display: block;
  margin: 0.25rem 0 0;
  color: var(--fg2);
  font-size: var(--text-sm);
}

/* The chips in a row: the legend's and the preview's. */
.map-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0;
}

/* The chip: the badge with a small drawn mark before the word. The mark is the text's color and the size of its line. */
.source-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.source-chip-icon {
  flex: none;
  inline-size: 1em;
  block-size: 1em;
}
.source-chip-label {
  min-inline-size: 0;
}

/* How it runs: three short lines, the stage in the quieter color and the plan in the stronger. */
.map-cadence {
  margin: 0;
  min-inline-size: 0;
}
.map-cadence-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 0.4rem;
  min-inline-size: 0;
  padding-block: 0.1rem;
}
.map-cadence-row dt,
.map-cadence-stage {
  color: var(--fg3);
  font-size: var(--text-sm);
}
.map-cadence-row dd {
  margin: 0;
  min-inline-size: 0;
  font-weight: 650;
}
.map-cadence-compact .map-cadence-row {
  display: block;
}
.map-cadence-compact .map-cadence-row dt,
.map-cadence-compact .map-cadence-row dd {
  display: inline;
}
.map-cadence-compact .map-cadence-row dt {
  margin-inline-end: 0.3rem;
}

/* What has run: the badge and how long ago, then three small figures. */
.map-run {
  min-inline-size: 0;
}
.map-run-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.4rem;
  margin: 0;
}
.map-run-age {
  color: var(--fg2);
  font-size: var(--text-sm);
}
.map-run-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.1rem 0.8rem;
  margin: 0.3rem 0 0;
}
.map-run-count {
  display: inline-flex;
  align-items: baseline;
  gap: 0.3rem;
}
.map-run-count dt {
  color: var(--fg3);
  font-size: var(--text-sm);
}
.map-run-count dd {
  margin: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.map-run-adapter {
  margin: 0.25rem 0 0;
  color: var(--fg2);
  font-size: var(--text-sm);
}
/* The run before the live one, beside it; the other adapters of the system whose last run did not end well (each a line: the adapter, then how it ended). */
.map-run-previous {
  margin-block-start: 0.25rem;
}
.map-run-others {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin: 0.3rem 0 0;
  padding: 0;
  list-style: none;
}
.map-run-other {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.2rem 0.4rem;
  min-inline-size: 0;
  color: var(--fg2);
  font-size: var(--text-sm);
}
.map-run-loaded-with {
  margin-block-start: 0.25rem;
  font-size: var(--text-sm);
}

/* A decision: its number and state in words (never the color), one link, 24px at the least and the floor on touch. An open one is outlined and a decided one is
   filled, which is a shape and not a color. */
.map-decisions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
}
.map-decision {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 0.5rem;
  min-inline-size: 0;
}
.map-decision-link {
  flex: none;
  white-space: nowrap;
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
  min-block-size: 1.5rem;
  color: var(--accent-text);
  text-decoration: underline;
  text-underline-offset: 0.18em;
}
.map-decision-number {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.map-decision-state {
  padding-inline: 0.35rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-sm);
  color: var(--fg2);
  font-size: var(--text-xs);
  text-decoration: none;
}
.map-decision[data-state="decided"] .map-decision-state {
  background: var(--surface-tint);
  border-color: var(--surface-tint);
}
.map-decision-title {
  min-inline-size: 0;
  max-inline-size: 60ch;
  overflow-wrap: break-word;
}
@media (pointer: coarse) {
  .map-decision-link,
  .map-link {
    min-block-size: var(--target-min);
    align-items: center;
  }
}
/* A link of its own (a decision's number, a card, a project): at least 24px tall (WCAG 2.5.8) and the floor on touch, above. A flex box drops the space
   between a word and the key after it, so the gap puts it back. */
.map-link {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: 0.25em;
  min-block-size: 1.5rem;
  color: var(--accent-text);
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

/* ── The deep text ────────────────────────────────────────────────────────
   Parts in as many columns as fit (18rem each), each with a small heading (the eyebrow's look at the outline's level) over a paragraph or a list. */

.map-detail {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
  gap: var(--density-block) 1.5rem;
  min-inline-size: 0;
  padding-block: 0.25rem;
}
.map-detail-part {
  min-inline-size: 0;
}
.map-detail-part p {
  max-inline-size: 62ch;
  margin: 0;
  overflow-wrap: break-word;
}
.map-detail-part p + p {
  margin-block-start: 0.4rem;
}
.map-detail-heading {
  margin: 0 0 0.25rem;
}
.map-reads,
.map-networks {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.map-read,
.map-network {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.2rem 0.5rem;
  min-inline-size: 0;
}
.map-read-text,
.map-network-help {
  min-inline-size: 0;
  max-inline-size: 60ch;
  overflow-wrap: break-word;
}
.map-network-help {
  color: var(--fg2);
  font-size: var(--text-sm);
}
.map-milestones,
.map-facts {
  margin: 0;
  min-inline-size: 0;
}
.map-milestone,
.map-fact {
  min-inline-size: 0;
  padding-block: 0.2rem;
}
.map-milestone dt,
.map-fact dt {
  color: var(--fg3);
  font-size: var(--text-sm);
  font-weight: 650;
}
.map-milestone dd,
.map-fact dd {
  margin: 0;
  min-inline-size: 0;
  overflow-wrap: break-word;
}
.map-rejections li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 0.5rem;
  padding-block: 0.1rem;
}
.map-rejection-count {
  font-weight: 700;
}
.map-adapters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.8rem;
  margin: 0.4rem 0 0;
}

/* ── The cards ────────────────────────────────────────────────────────────
   One column on a phone, as many as fit from there: a card wants about 24rem for its facts to sit on one line each, as the cards under it do. */

.source-map-cards {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 24rem), 1fr));
  align-items: start;
  gap: var(--density-block);
  min-inline-size: 0;
}
.map-card {
  min-inline-size: 0;
}
.map-card-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  min-inline-size: 0;
}
.map-card-summary {
  margin: 0.5rem 0 0;
  color: var(--fg2);
  overflow-wrap: break-word;
}
/* A fact is a row between two hairlines, as the cards under the map say theirs (46-sources.css): the label and the value on one line when there is room, and the value
   under the label when there is not. Written here with the child combinator, so the lists inside a value (how it runs, what ran) take none of its rules. */
.map-card-facts {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-inline-size: 0;
  margin: var(--density-block) 0 0;
  border-block-start: 1px solid var(--rule);
}
.map-card-fact {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 var(--density-block);
  min-inline-size: 0;
  padding-block: var(--density-row);
  border-block-end: 1px solid var(--rule);
}
.map-card-fact > dt {
  flex: 0 1 9rem;
  min-inline-size: 0;
  color: var(--fg2);
  overflow-wrap: anywhere;
}
.map-card-fact > dd {
  flex: 1 1 9rem;
  min-inline-size: 0;
  margin: 0;
  font-weight: 650;
  overflow-wrap: anywhere;
}
.map-card-more {
  min-inline-size: 0;
  margin-block-start: var(--density-block);
}
.map-card-more-summary {
  /* A list item, which is what a summary is by default and what draws its disclosure marker: a flex box would lose the marker and leave the control with no sign
     that it opens. The marker follows the text's direction, so it mirrors in a right-to-left language. */
  display: list-item;
  list-style-position: inside;
  min-block-size: 1.5rem;
  font-weight: 650;
  cursor: pointer;
}
@media (pointer: coarse) {
  .map-card-more-summary {
    min-block-size: var(--target-min);
    padding-block: calc((var(--target-min) - 1.55em) / 2);
  }
}
.map-card-more[open] .map-card-more-summary {
  margin-block-end: var(--density-gap);
}

/* ── The legend, the callout and the decisions' table ───────────────────── */

.source-map-legend {
  min-inline-size: 0;
  margin-block: var(--density-block);
}
.source-map-legend-summary {
  display: list-item;
  list-style-position: inside;
  min-block-size: 1.5rem;
  font-weight: 650;
  cursor: pointer;
}
@media (pointer: coarse) {
  .source-map-legend-summary {
    min-block-size: var(--target-min);
    padding-block: calc((var(--target-min) - 1.55em) / 2);
  }
}
.source-map-legend-body {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 20rem), 1fr));
  gap: var(--density-block) 1.5rem;
  min-inline-size: 0;
  padding-block: var(--density-gap);
}
.source-map-legend-list {
  margin: 0;
  min-inline-size: 0;
}
.source-map-legend-item {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.2rem 0.6rem;
  padding-block: 0.25rem;
}
.source-map-legend-item dt {
  flex: 0 1 auto;
  min-inline-size: 0;
  max-inline-size: 100%;
}
.source-map-legend-item dd {
  flex: 1 1 14rem;
  min-inline-size: 0;
  margin: 0;
  color: var(--fg2);
  font-size: var(--text-sm);
}
.source-map-unmapped {
  margin-block: var(--density-block);
}
/* The way past the map to what is under it: three links, each 24px at the least and the floor on touch. */
.source-map-jump {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.9rem;
  min-inline-size: 0;
  margin-block: var(--density-gap);
  font-size: var(--text-sm);
}
.source-map-jump-label {
  color: var(--fg3);
  font-weight: 650;
}
.source-map-jump a {
  display: inline-flex;
  align-items: center;
  min-block-size: 1.5rem;
  color: var(--accent-text);
  text-decoration: underline;
  text-underline-offset: 0.18em;
}
@media (pointer: coarse) {
  .source-map-jump a {
    min-block-size: var(--target-min);
  }
}
.source-run-strip {
  margin-block-start: var(--density-gap);
}

/* ── On paper ─────────────────────────────────────────────────────────────
   The table, whole: every detail open, no controls, no scrolling region, and nothing cut off at the edge of the paper. The screen's table is 60rem wide at the least and
   has eight columns, and a Letter page is about 720px, so on paper a system is not a row under a header: it is a block of its own, the name and what it is across the
   top, then its facts three to a line, each with its label (the cell's `data-label`, drawn before it, because there is no header to read it from), then its deep text in
   one column. Nothing has a width of its own, so nothing can be wider than the paper, and every word that is longer than its room breaks. A system's block may break
   between pages (its deep text is longer than a page), but a part of the deep text is never cut across two. */

@media print {
  .source-map .source-map-table,
  .source-map[data-view] .source-map-table {
    display: block;
  }
  .source-map .source-map-cards,
  .source-map[data-view] .source-map-cards,
  .source-map-bar,
  .source-map-jump,
  .source-map-tools,
  .source-map-toggle,
  .source-map-expand,
  .source-map-legend {
    display: none;
  }
  .source-map-region {
    inline-size: auto;
    max-inline-size: 100%;
    max-block-size: none;
    overflow: visible;
  }
  table.data.source-map-data,
  table.data.source-map-data.data-table,
  .source-map-data tbody,
  .source-map-data tr,
  .source-map-data th,
  .source-map-data td {
    display: block;
    inline-size: auto;
    min-inline-size: 0;
    max-inline-size: 100%;
  }
  .source-map-data thead {
    display: none;
  }
  .source-map-data {
    font-size: 0.8rem;
  }
  .source-map-data :is(th, td) {
    overflow-wrap: anywhere;
  }
  .source-map-data [data-column] {
    min-inline-size: 0;
  }
  table.data.source-map-data.data-table :is(th, td) {
    padding-inline: 0;
  }
  .source-map-source-body {
    padding-block: 0.5rem;
    break-inside: auto;
  }
  /* The facts: the name takes the line, and the seven cells follow three to a line. */
  .source-map-data tr.source-map-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.35rem 1rem;
    break-after: avoid;
  }
  .source-map-data tr.source-map-row > .source-map-name {
    grid-column: 1 / -1;
  }
  .source-map-row td[data-label]::before {
    display: block;
    margin-block-end: 0.15rem;
    color: var(--fg3);
    font-size: 0.65rem;
    font-weight: 650;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    content: attr(data-label);
  }
  .source-map-row .map-decisions,
  .source-map-row .map-chip-list {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.2rem 0.8rem;
  }
  .source-map-detail-row[data-state="closed"] {
    display: block;
  }
  .map-detail {
    display: block;
  }
  .map-detail-part {
    break-inside: avoid;
    margin-block-end: 0.5rem;
  }
  .map-detail-part p {
    max-inline-size: none;
  }
  .map-card-summary,
  .source-map-summary,
  .source-map-name .source-map-summary {
    max-inline-size: none;
  }
}
