/* Rich text as a page shows it (RichTextComponent in app/components; docs/data_model/13-operational-domains.md section 8, "As built (rich text)"): the HTML the server wrote, which holds only
   paragraphs, two heading levels, strong, em, underline, links, bulleted and numbered lists, a quotation, a break and pictures. The editor is another stylesheet (58-rich-text.css); this is only how
   what it made is READ.

   Linked after the incident page's rules (61-incidents.css comes later and may add to it). Tokens only and logical properties only, both enforced (test/styles/tokens_test.rb,
   test/styles/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 and nothing sets a height in vh.

   The text takes the size and the color of the box it is in (a narrative is drawn at the panel's reading size), so the one rule for how big a narrative is stays where the panel says it. Words and
   addresses that have no room break (`overflow-wrap`), so a long link or a language 40% longer never widens the page (WCAG 1.4.10). A picture is at most as wide as the box and a good deal shorter than
   a phone's screen, and keeps its shape. */

.rich-text {
  min-inline-size: 0;
  /* An isolate of its own, as the plain narrative's bdi is: a direction mark in a person's words reorders nothing round them. Each block also says dir="auto" (RichText.render), so a paragraph in
     Arabic in a page of English is read from its own side. */
  unicode-bidi: isolate;
  /* The plain narrative sits in a box that keeps its line breaks (`white-space: pre-line`); rich text has its own, and a break in it is a break. */
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.45;
}

.rich-text :is(p, ul, ol, blockquote, .rich-text-heading, .rich-text-subheading) {
  margin-block: 0 var(--space-3);
}

/* A Heading and a Subheading are drawn at the levels below the heading of the box they sit in (RichTextComponent), so they are styled by class and not by the level they were given. */
.rich-text :is(.rich-text-heading, .rich-text-subheading) {
  margin-block-start: var(--space-4);
  font-weight: 700;
  line-height: 1.25;
}

.rich-text .rich-text-heading {
  font-size: 1.125em;
}

.rich-text .rich-text-subheading {
  font-size: 1em;
}

/* The first block has no space above it and the last none below it. These come AFTER the margin rules above, because they have the same specificity as the rules for headings (a class inside :is() counts
   as a class) and the later rule wins. */
.rich-text > :first-child {
  margin-block-start: 0;
}

.rich-text > :last-child {
  margin-block-end: 0;
}

/* The reset (00-preflight.css) takes every list's markers away, and a list of the narrative's own has to keep them: a bullet or a number is what says that it is a list to someone who sees it (a
   screen reader's list semantics are lost in Safari when the markers are gone, too). They sit outside the text, in the padding, and mirror in a right-to-left language. */
.rich-text :is(ul, ol) {
  padding-inline-start: 1.5em;
  list-style-position: outside;
}

.rich-text ul {
  list-style-type: disc;
}

.rich-text ul ul {
  list-style-type: circle;
}

.rich-text ul ul ul {
  list-style-type: square;
}

.rich-text ol {
  list-style-type: decimal;
}

.rich-text li {
  margin-block-end: var(--space-1);
}

/* A list in a list item sits close under its words. */
.rich-text li > :is(ul, ol) {
  margin-block: var(--space-1) 0;
}

/* A quotation has a bar at its start (a border, so it survives forced colors and mirrors), and is not the only signal: it is indented and quieter. */
.rich-text blockquote {
  margin-inline: 0;
  padding-inline-start: var(--space-3);
  border-inline-start: 3px solid var(--rule-strong);
  color: var(--fg2);
}

/* A link in running words is underlined: the reset takes the underline away, and a color alone does not say where a link is (WCAG 1.4.1). Its address may have no room to break at, so it breaks anywhere. */
.rich-text a {
  text-decoration: underline;
  overflow-wrap: anywhere;
}

/* A picture is a block, as the editor draws it (58-rich-text.css): what the writer sees is what the reader sees, and a picture at the end of a sentence does not sit in the middle of a line. */
.rich-text img {
  display: block;
  inline-size: auto;
  block-size: auto;
  max-inline-size: 100%;
  max-block-size: 32rem;
  object-fit: contain;
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
}

/* ── A picture, enlarged (picture_viewer_controller.js) ─────────────────────────────────────────────────
   The script wraps each picture of what was written in a button and opens the picture in a native <dialog> opened with showModal(), so the page behind is inert and the browser draws the backdrop.
   Nothing here decides a mode: the backdrop is the scrim token, the caption and the Close button take the raised surface and its text (pairs the contrast check measures), and the picture's own
   colors are its own. The dialog is the whole screen and has no color, so the empty space round the picture is what a click on the backdrop lands on. It does not move: it is there when it is opened (a fade
   would put the Close button's text mid-way to the backdrop for the first moments, which is a contrast that fails while it lasts, and a modal that appears is what the person asked for). */

/* The button is the picture and nothing else: it takes no box of its own, only the cursor that says a click enlarges it. Its focus ring is the page's (`:focus-visible`, 10-globals.css). */
.rich-text .rich-text-picture {
  display: block;
  max-inline-size: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: inherit;
  font: inherit;
  text-align: start;
  cursor: zoom-in;
}

/* `display` only while it is open: a closed dialog stays hidden by the browser's own rule, which a `display` here would undo. The safe areas are the device's, so the insets are the larger of
   the two sides and a notch is cleared in either direction of writing. */
.picture-viewer {
  inline-size: 100%;
  block-size: 100dvh;
  max-inline-size: none;
  max-block-size: none;
  margin: 0;
  padding-block: calc(var(--safe-top) + var(--space-4)) calc(var(--safe-bottom) + var(--space-4));
  padding-inline: max(var(--safe-left), var(--safe-right), var(--space-4));
  border: 0;
  background: transparent;
  color: var(--fg1);
  overflow: hidden;
}

.picture-viewer[open] {
  display: flex;
  align-items: center;
  justify-content: center;
}

.picture-viewer::backdrop {
  background: var(--scrim);
}

/* The Close button is out of the flow, at the end of the top edge, clear of the notch; it is first in the markup so that it is what the browser focuses. It is a `.btn`, so it is 44px on touch. */
.picture-viewer-close {
  position: absolute;
  inset-block-start: calc(var(--safe-top) + var(--space-3));
  inset-inline-end: calc(max(var(--safe-left), var(--safe-right)) + var(--space-3));
}

/* The picture is behind the button, so it needs a ground of its own: a secondary button's is none on the web and a tint of the accent in the native shells (96-native-ios.css, 97-native-android.css),
   which is a ground only while the page behind it is plain. Three classes, to beat the platforms' `[data-native] .btn-secondary`. */
.picture-viewer .picture-viewer-close.btn-secondary {
  --btn-bg: var(--surface-raised);
}

/* The picture as large as the screen allows, whole: the figure may not be taller or wider than the dialog's room, and the picture gives way first (its minimum is nothing), so a long
   description shrinks the picture and never pushes it off the screen. */
.picture-viewer-figure {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  min-block-size: 0;
  max-inline-size: 100%;
  max-block-size: 100%;
  margin: 0;
}

.picture-viewer-image {
  display: block;
  min-block-size: 0;
  max-inline-size: 100%;
  object-fit: contain;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lift);
}

.picture-viewer-caption {
  flex: none;
  max-inline-size: min(100%, 60ch);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  color: var(--fg1);
  font-size: var(--text-sm);
  line-height: 1.4;
  overflow-wrap: anywhere;
  text-align: start;
}

.picture-viewer-caption[hidden] {
  display: none;
}
