/* Shared form scaffolding — label, hint, error message, and the
   grouping/fieldset wrappers used across form controls (input, radio, …).
   Note: root src ships no global reset, so text primitives zero their own
   UA margins here (they render on <p>, <legend>, <h2>, … elements). */

.govbb-form-group {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--govbb-space-xs);
  width: 100%;
  margin-bottom: var(--govbb-space-xm);
}

.govbb-fieldset {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--govbb-space-xs);
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.govbb-fieldset__legend {
  margin: 0;
  padding: 0;
  font-size: var(--govbb-font-size-body);
  line-height: var(--govbb-line-height-base);
  font-weight: 700;
  color: var(--govbb-color-ink);
  overflow-wrap: anywhere;
}

/* Text primitives let an unbreakable word (an email address, a reference)
   wrap rather than overflow the column. anywhere, not break-word: as
   shrink-wrapped flex items they would otherwise size to the word. */
.govbb-label {
  display: block;
  margin: 0;
  font-size: var(--govbb-font-size-body);
  line-height: var(--govbb-line-height-base);
  font-weight: 700;
  color: var(--govbb-color-ink);
  overflow-wrap: anywhere;
}

/* "(optional)" suffix inside the label — required fields carry no mark.
   Kept inside the <label> so it's announced with the field name. */
.govbb-label__optional {
  font-weight: 400;
  color: var(--govbb-color-muted);
}

.govbb-hint {
  display: block;
  margin: 0;
  font-size: var(--govbb-font-size-body);
  line-height: var(--govbb-line-height-base);
  color: var(--govbb-color-muted);
  overflow-wrap: anywhere;
}

.govbb-error-message {
  display: block;
  margin: 0;
  font-size: var(--govbb-font-size-body);
  line-height: var(--govbb-line-height-base);
  color: var(--govbb-color-error);
  overflow-wrap: anywhere;
}

/* Keep label/legend, hint and error message tight together — no gap between
   them (line-height carries the rhythm); only the control(s) below get 8px. */
.govbb-form-group > .govbb-label + .govbb-hint,
.govbb-form-group > .govbb-label + .govbb-error-message,
.govbb-form-group > .govbb-hint + .govbb-error-message,
.govbb-fieldset > .govbb-hint + .govbb-error-message {
  margin-block-start: calc(var(--govbb-space-xs) * -1);
}

/* A legend sits outside the fieldset's flex content box, so gap does not
   separate it from the first child. Add that 8px only when controls follow
   the legend directly; hint/error text remains grouped with the legend. */
.govbb-fieldset
  > .govbb-fieldset__legend
  + :not(:where(.govbb-hint, .govbb-error-message)) {
  margin-block-start: var(--govbb-space-xs);
}
