/* forms.css — shared form-control components for the Olympion app pages.
 *
 * Load it BEFORE the page's own <style> so a page can still override:
 *   <link rel="stylesheet" href="/app/forms.css">
 *
 * Exists because every page inlines its own CSS, and every page independently
 * reinvented the checkbox — badly. The recurring failure is not a matter of
 * taste, it is one specific collision: pages define a caption/input pair for
 * text fields, e.g.
 *
 *   .field label { display:block; text-transform:uppercase; font-size:12px; … }
 *   .field input { width:100%; padding:9px 12px; border:1px solid …; }
 *
 * …and then someone puts a checkbox inside `.field`. The checkbox inherits
 * `width:100%`, so it eats the entire row and squeezes its own text into a
 * one-word-per-line column that overflows the card; the label text inherits the
 * caption style, so a full sentence renders SHOUTING IN DIM 12PX LETTERSPACED
 * CAPS. The `style="width:auto;margin:0"` patches scattered across app/*.html
 * are people hitting this one at a time.
 *
 * The fix is structural, not cosmetic: a checkbox is NOT a text input and its
 * label is NOT a field caption, so it gets its own class and never inherits
 * either family. Use `.check` / `.check-list` below and do not nest them in
 * `.field`.
 *
 * These rules are self-contained: they set every property that a page-level
 * `.field input` / `.field label` rule could bleed in (width, padding, border,
 * text-transform, letter-spacing, font-size, color, display), so dropping the
 * component into an existing page cannot inherit the bug it exists to prevent.
 *
 * Colors come from the page's own custom properties, with fallbacks for pages
 * that name them differently, so this file never hardcodes a palette.
 */

/* ---------- one checkbox / radio row ---------- */
/*
 * <label class="check">
 *   <input type="checkbox" id="…">
 *   <span>Short imperative label</span>
 * </label>
 *
 * With a description — the description is a SIBLING of the text, never inside
 * a caption-styled element:
 *
 * <label class="check">
 *   <input type="checkbox" id="…">
 *   <span>Short imperative label
 *     <small>What this actually does, and what happens if you get it wrong.</small>
 *   </span>
 * </label>
 */
.check {
  /* The whole row is the hit target, and the row is a label, so clicking the
     text toggles the box. WCAG 2.2 §2.5.8 wants ≥24px; min-height gets us
     there even when the text is a single short line. */
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-height: 24px;
  cursor: pointer;
  /* Beat any `.field label` / `label` caption rule the host page defines. */
  font-size: 14px;
  font-weight: 400;
  line-height: 1.45;
  text-transform: none;
  letter-spacing: normal;
  color: var(--text, #e6ebf5);
  margin: 0;
}

.check + .check {
  margin-top: 10px;
}

.check > input[type="checkbox"],
.check > input[type="radio"] {
  /* width:auto AND flex:none — the first undoes `.field input { width:100% }`,
     the second stops flex from stretching or shrinking the control. Both are
     needed; either alone still yields the squeezed-text failure. */
  width: auto;
  flex: none;
  min-width: 0;
  /* Native controls are ~13px and sit on the text baseline. 16px with a nudge
     lines the box up with the cap height of the first line of label text and
     keeps the tap area honest. */
  inline-size: 16px;
  block-size: 16px;
  margin: 3px 0 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  /* The one property that reliably restyles a native checkbox across engines.
     A hand-built control (appearance:none + ::before) loses the indeterminate
     state, forced-colors mode and the platform's own focus ring, and is not
     worth it for a tick box. */
  accent-color: var(--primary, var(--brand-primary, #5b8def));
  cursor: pointer;
}

.check > input:disabled,
.check:has(> input:disabled) {
  cursor: not-allowed;
  opacity: 0.55;
}

/* The text column. min-width:0 lets it wrap normally instead of overflowing
   its flex parent — the other half of the runaway-column bug. */
.check > span {
  min-width: 0;
  flex: 1 1 auto;
}

/* Secondary explanation under the label text. Muted and smaller, but NOT
   uppercase and NOT letterspaced: this is prose, and prose in caps is the
   thing that made these look shouty.
   --text-dim, NOT --text-faint: measured on the app's own surfaces, faint is
   3.36:1 against --bg-elev and fails WCAG AA (4.5:1) at this size. dim is
   7.37:1. "Muted" is where secondary text quietly stops being readable. */
.check > span > small {
  display: block;
  margin-top: 3px;
  font-size: 12px;
  line-height: 1.5;
  text-transform: none;
  letter-spacing: normal;
  color: var(--text-dim, #9aa5bc);
}

/* Keyboard focus must stay visible — accent-color does not draw one. */
.check > input:focus-visible {
  outline: 2px solid var(--primary, var(--brand-primary, #5b8def));
  outline-offset: 2px;
}

/* ---------- a group of them ---------- */
/*
 * <fieldset class="check-list">
 *   <legend>Which surfaces?</legend>
 *   <label class="check">…</label>
 * </fieldset>
 *
 * fieldset/legend so screen readers announce the group name with each option.
 * A plain <div> + heading does not do that.
 */
.check-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 0;
  margin: 0;
  padding: 0;
  min-inline-size: 0; /* fieldset defaults to min-content and blows out grids */
}

.check-list > legend {
  padding: 0;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim, #9aa5bc);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.check-list .check + .check {
  margin-top: 0; /* the flex gap already spaces them */
}

/* Dense variant for tables and long option lists (role grids, tag pickers). */
.check-list.is-dense {
  gap: 4px;
}
.check-list.is-dense .check {
  min-height: 0;
  font-size: 13px;
}

/* A bare checkbox in a table cell: no label text, so none of the row rules
   apply, but it still must not inherit `.field input { width:100% }`. */
.check-cell {
  width: auto;
  flex: none;
  inline-size: 16px;
  block-size: 16px;
  margin: 0;
  padding: 0;
  border: 0;
  accent-color: var(--primary, var(--brand-primary, #5b8def));
  cursor: pointer;
}
