/* CRM library, file 2 of 7: base. Loaded after ds.css and lib/tokens.css, before the other lib files and app.css.

   Belongs here: the reset of a button and the focus ring, the bridge to ds.css (what `.ds input`, `.ds a` and `.ds h1-h4` set on every element and a primitive has to undo
   once), the layout utilities (crm-stack, crm-row, crm-grid, crm-split, crm-cq), the text roles (crm-overline, crm-title,
   crm-truncate, crm-clamp, crm-num, crm-mono) and the responsive hide utilities.

   Contract: a base rule is ONE class, a modifier two, descendant parts go inside :where(); no id, no @layer, no !important, and an
   element selector only in a bridge rule (`.crm .crm-x`, `.ds input.crm-x`), marked with a comment that starts with the word bridge.
   A value a page may adjust is a --k-* knob, declared again on every primitive; app.css never restyles a class of this file on its own. */

/* ── Reset and focus ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
   A button that is not a ds button starts bare, and everything a person can reach with the keyboard shows where the focus is:
   2px of --blue, 2px outside the element, in both themes. These two rules stood at the top of app.css; they are here because
   a rule of app.css wins from a rule of the library that weighs the same, and a control of the library (crm-icon-btn, crm-chip,
   crm-seg-item) sets the colour, the border and the padding that the reset clears. A control that clips its ring draws it
   inside (crm-seg-item in lib/controls.css); a ds field shows its focus with its own border and ring. */
.crm :where(button:not(.btn)) { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-align: inherit; }
.crm :where(button, a, [tabindex]):focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
/* A list, a heading and a paragraph start without the margins of the browser. They stood at the top of app.css too, and are here
   for the same reason: there they outweighed a library rule of one class on a heading, a paragraph or a list (a title, a notice). */
.crm :where(ul) { list-style: none; margin: 0; padding: 0; }
.crm :where(h1, h2, h3, p) { margin: 0; }

/* ── Bridge to ds.css ────────────────────────────────────────────────────────────────────────────────────────────────────────────
   ds.css gives every input the width and the padding of a text field (`.ds input { width: 100%; padding }`, weight (0,1,1)). A tick
   box or a radio is no field: without this rule one without a class of its own is as wide as its row (the radios of crm-radio in
   the segment editor and of crm-ac-role in the user editor pushed their label to the far side). Same weight as ds.css and a later
   file, so it wins there and loses from every rule of app.css that sizes one (`.crm-check input`, `.crm .crm-cb`,
   `.ds input.crm-task-check`).
   Not here yet, because they change what is on screen and come with the step that means to: the same for colour and range
   inputs, and --crm-fs-input on every field of a wider screen (a field inherits its size there, `.ds input { font: inherit }`, so
   one inside smaller text would grow); on a phone it is here (below). */
/* bridge: (0,1,1), later than `.ds input` */
.ds input:where([type="checkbox"], [type="radio"]) { width: auto; padding: 0; }
@media (width < 48rem) {
  /* bridge: on a phone every field has --crm-fs-input (1rem there, 16px): iOS zooms in on a field under 16px, and `.ds input`
     gives a field the size of the text around it (font: inherit). Later than `.ds input` and as heavy. */
  .ds input:where(:not([type="checkbox"], [type="radio"])), .ds select, .ds textarea { font-size: var(--crm-fs-input); }
}
/* bridge: `.ds input` takes the outline away and shows the focus as a border and a soft ring; a tick box has no border to colour and
   the ring is 1.1:1 against the page, so with the keyboard it gets the ring of a button (later than `.ds input:focus`, same weight) */
.ds input:where([type="checkbox"], [type="radio"]):focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; box-shadow: none; }

/* ── Layout ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   A column, a row, a grid of equal tiles and a main-with-aside. Each declares its own --k-gap, so a gap never leaks from an
   enclosing stack into a nested row. A page adjusts through the knob on its own class (`.crm-task-facts { --k-gap: var(--sp-2); }`)
   or with a step class g1..g6 (the --sp-* step of the same number). A row that may run over more lines is `multi`, not `wrap`:
   ds.css owns that word (`.ds .wrap` is its page container and gets 5svw of side padding on a phone). */
.crm-stack { --k-gap: var(--sp-4); display: flex; flex-direction: column; gap: var(--k-gap); min-width: 0; }
.crm-row { --k-gap: var(--sp-3); display: flex; align-items: center; gap: var(--k-gap); min-width: 0; }
.crm-row.multi { flex-wrap: wrap; }
.crm-row.between { justify-content: space-between; }
.crm-row.top { align-items: flex-start; }
.crm-row.end { justify-content: flex-end; }
:where(.crm-row, .crm-stack) > :where(.grow) { flex: 1 1 auto; min-width: 0; }
:where(.crm-row) > :where(.push) { margin-left: auto; }
.crm-stack.g1, .crm-row.g1 { --k-gap: var(--sp-1); }
.crm-stack.g2, .crm-row.g2 { --k-gap: var(--sp-2); }
.crm-stack.g3, .crm-row.g3 { --k-gap: var(--sp-3); }
.crm-stack.g4, .crm-row.g4 { --k-gap: var(--sp-4); }
.crm-stack.g5, .crm-row.g5 { --k-gap: var(--sp-5); }
.crm-stack.g6, .crm-row.g6 { --k-gap: var(--sp-6); }

/* Tiles of one width that fill the row: as many columns as fit --k-min, never wider than the box. */
.crm-grid { --k-gap: var(--sp-4); --k-min: 11rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--k-min)), 1fr)); gap: var(--k-gap); }

/* Main and aside without a breakpoint: the aside drops under the main when the row gets narrower than --k-main plus --k-aside,
   so it also works in a dialog or a side panel, where the width of the window says nothing. */
.crm-split { --k-gap: var(--crm-gap); --k-aside: 20rem; --k-main: 28rem; display: flex; flex-wrap: wrap; align-items: flex-start; gap: var(--k-gap); }
:where(.crm-split) > :where(:not(.crm-split-aside)) { flex: 999 1 min(100%, var(--k-main)); min-width: 0; }
.crm-split-aside { flex: 1 1 min(100%, var(--k-aside)); min-width: 0; }
.crm-split-aside.sticky { position: sticky; top: var(--sp-4); }
.crm-split-aside.first { order: -1; }

/* A box whose own width its content may ask about (@container). Mind the unit: at the 90 % root a rem in @container is 0.9 of
   a rem in @media. */
.crm-cq { container-type: inline-size; }

/* Hidden under a breakpoint: the text of a button that keeps its icon, a column a phone has no room for. */
@media (width < 48rem) { .crm-hide-sm { display: none; } }
@media (width < 40rem) { .crm-hide-xs { display: none; } }

/* ── Text roles ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────── */
.crm-overline { color: var(--muted); font-size: var(--fs-2xs); font-weight: var(--crm-fw-bold); letter-spacing: var(--crm-track-caps); text-transform: uppercase; }
/* On h2-h4 as well: ds.css gives a heading its colour and weight and never a size. */
.crm-title { font-size: var(--fs-lg); font-weight: var(--crm-fw-semibold); line-height: 1.25; }
.crm-title.sub { font-size: var(--fs-md); }
.crm-title.page { font-size: var(--fs-2xl); }
.crm-truncate { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crm-clamp { --k-lines: 2; display: -webkit-box; -webkit-line-clamp: var(--k-lines); -webkit-box-orient: vertical; overflow: hidden; }
.crm-num { font-variant-numeric: tabular-nums; }
.crm-mono { font-family: var(--crm-font-mono); }
/* The four roles the pages use most (they stood in app.css): muted text, the lede under the title of a page, a link in the CRM and
   the small line under a name in a cell. crm-ac-muted and crm-tr-lede are the older names. A link is written with the scope in
   front, as heavy as it was: `.ds a` of ds.css colours every link and weighs a class and an element. */
.crm-muted, .crm-ac-muted { color: var(--muted); font-size: var(--fs-sm); }
.crm-lede, .crm-tr-lede { color: var(--muted); margin: var(--sp-2) 0 var(--sp-6); max-width: 42rem; }
.crm .crm-link { color: var(--blue); font-weight: var(--crm-fw-medium); }
.crm .crm-link:where(:hover) { text-decoration: underline; }
.crm-cell-sub { overflow: hidden; text-overflow: ellipsis; color: var(--faint); font-size: var(--fs-xs); }
