/*
  textImage — text beside one image (component.json textImage, 1 token; layout build step 5d, 2026-11-23;
  decided in the layout pass, 2026-11-21: the homepage Featured work card as the model, also for Good, better, best
  and any single image with a short paragraph).
  A row: a text block, then one visual (an image, or one of the 6sense page's live visuals). Below 1200px they stack, the media gap apart (as before the grid).
  From 1200px, inside a beside or above section (section.css): the text in columns 2-5 (416px at 1440), centered
  top to bottom against the image in columns 6-11 (640px). Rows are 96px apart (text-block-group.css).
  The image keeps its own shape (the code never crops); export at least 1472px wide.
*/
.text-image {
  display: flex;
  flex-direction: column;
  gap: var(--text-image-stacked-gap-all);
}

@media (width >= 1200px) {
  :is(.section--beside, .section--above) .text-block-group > .text-image {
    display: grid;
    grid-template-columns: subgrid;
    column-gap: var(--section-column-gap-grid);
    align-items: center;
  }
  .text-image > :first-child {
    grid-column: 1 / 5; /* the text: page columns 2-5 */
  }
  .text-image > :last-child {
    grid-column: 5 / -1; /* the visual (an image, or a live visual such as a token chart or a color sheet): columns 6-11 */
  }
}

/* TEXT CENTERS ON THE VISUAL, NOT ITS CAPTION; LIVE VISUALS STRETCH TO THE ROW (Vivek, 2026-11-23).
   From 1200px a row has two grid lines: the visual on the first, its caption (if any) on the second. The text sits on
   the first line, centered against the visual itself, so a caption under the visual never pulls the text off center.
   A live visual panel (token chart, type or spacing sheet, color sheet, button sheet: the 6sense page) grows to the
   first line's height, its content centered inside, so panel and text read as one block; if the text is shorter, the
   text centers against the panel. Images never stretch (they would distort or crop): they center on the line. */
@media (width >= 1200px) {
  :is(.section--beside, .section--above) .text-block-group > .text-image {
    grid-template-rows: auto auto;
    row-gap: 0; /* the caption brings its own 16px */
  }
  .text-image > :first-child {
    grid-row: 1;
    align-self: center;
  }
  .text-image > :last-child {
    grid-row: 1;
    align-self: stretch;
  }
  .text-image > :last-child:has(> .figure__caption) {
    grid-row: 1 / 3; /* the caption takes the second line */
  }
  .text-image > .figure {
    display: grid;
    grid-template-rows: subgrid;
  }
  /* FIREFOX FIX (2026-11-24): an image figure steps out of the way (display: contents), so the image and its caption
     sit directly on the row's two lines. Firefox did not size a row from an image nested inside the figure's own
     subgrid: it sized the row from the text alone, the image spilled over, and rows overlapped (Invoicing) or left
     big gaps (Dashboard, Comic Book). Chrome and Safari were not affected. The 6sense live sheets keep the subgrid. */
  .text-image > .figure:has(> img.figure__media) {
    display: contents;
  }
  .text-image > .figure:has(> img.figure__media) > * {
    grid-column: 5 / -1;
  }
  .text-image > .figure:has(> img.figure__media) > .figure__media {
    grid-row: 1;
  }
  .text-image > .figure > .figure__media {
    align-self: center;
  }
  .text-image > .figure > .figure__caption {
    grid-row: 2;
  }
  .text-image > .token-chain,
  .text-image > .figure > .token-chain {
    align-items: center;
  }
  .text-image > .figure > :is(.scale-sheet, .color-sheet) {
    align-content: center;
  }
}

/* CAPTION STAYS WITH ITS IMAGE (2026-11-28, chat "Portfolio: Focus pass, Dashboard"; Vivek approved).
   Bug: the caption sat on the row's second line, so when the text was taller than the image, the image centered in
   the taller first line and the caption fell to its bottom (Dashboard What we found: 60 at 1512, 128 at 1200; DSS 30
   at 1200). Rule: the caption is always the caption gap under its image; the text still centers on the image, not on
   image + caption. How: a captioned image figure is one block (image, then caption), centered in a one-line row, and
   the text gets a bottom margin of exactly one caption (gap + one caption line), so both centers meet in every case.
   Replaces the two-line rows and the display: contents Firefox fix for captioned images only (a flex figure sizes the
   row in Firefox; checked). Uncaptioned images and the 6sense live sheets keep the rules above. */
@media (width >= 1200px) {
  :is(.section--beside, .section--above) .text-block-group > .text-image:has(> .figure > img.figure__media + .figure__caption) {
    grid-template-rows: auto;
  }
  .text-image > .figure:has(> img.figure__media + .figure__caption) {
    display: flex;
    flex-direction: column;
    justify-content: center;
    grid-row: 1;
    grid-column: 5 / -1;
    align-self: stretch;
  }
  .text-image:has(> .figure > img.figure__media + .figure__caption) > :first-child {
    grid-row: 1;
    margin-block-end: calc(var(--figure-caption-gap-all) + var(--figure-caption-text-style-all-font-size) * var(--figure-caption-text-style-all-line-height));
  }
}
