/*
 * Checkbox + radio — custom-styled native inputs. The two controls are the
 * same 3rem bordered box with the same states, so they share one recipe; the
 * radio differs only in shape (round box, round dot). Both support an
 * optional conditional reveal.
 *
 * Markup: <input class="govbb-checkbox"> (or .govbb-radio) beside a
 * .govbb-checkbox-item__label (or .govbb-radio-item__label), wrapped in
 * .govbb-checkbox-item (or .govbb-radio-item).
 */

.govbb-checkbox,
.govbb-radio {
  appearance: none;
  display: inline-grid;
  place-content: center;
  grid-column: 1;
  grid-row: 1;
  flex-shrink: 0;
  width: 3rem;
  height: 3rem;
  margin: 0;
  padding: 0;
  background: var(--govbb-color-surface);
  border: var(--govbb-border-width-form) solid var(--govbb-color-ink);
  cursor: pointer;
  outline: 0;
  transition:
    box-shadow 0.2s,
    border-color 0.2s;
}

/* The mark — a filled square (check) or circle (dot) revealed on :checked. */
.govbb-checkbox::before,
.govbb-radio::before {
  content: '';

  /* 1.1875rem = the comp's 19px, in rem so the mark keeps pace with its
     rem-sized control under text zoom */
  width: 1.1875rem;
  height: 1.1875rem;
  background: var(--govbb-color-interactive);
  transform: scale(0);
}

/* Round shapes for the radio. */
.govbb-radio,
.govbb-radio::before {
  border-radius: 50%;
}

.govbb-checkbox:checked::before,
.govbb-radio:checked::before {
  transform: scale(1);
}

.govbb-checkbox:hover,
.govbb-radio:hover {
  box-shadow: var(--govbb-shadow-form-hover);
}

/* Keyboard focus ring: shared rule in focus.css; only the border recolour is
   ours. */
.govbb-checkbox:focus-visible,
.govbb-radio:focus-visible {
  border-color: var(--govbb-color-interactive);
}

.govbb-checkbox[aria-invalid='true'],
.govbb-radio[aria-invalid='true'] {
  border-color: var(--govbb-color-error);
}

.govbb-checkbox:disabled,
.govbb-radio:disabled {
  opacity: var(--govbb-opacity-disabled);
  box-shadow: none;
  cursor: not-allowed;
}

/* Control + copy. The control sits against the label's first line (its block
   padding centres one line of text on the 3rem box), so a label that wraps
   grows downwards from the control instead of floating it mid-paragraph. A
   per-option hint sits beneath its label instead of becoming a third inline
   item; options without hints retain the same single-row alignment. */
.govbb-checkbox-item,
.govbb-radio-item {
  display: grid;
  grid-template-columns: 3rem minmax(0, 1fr);
  align-items: start;
  column-gap: 1.25rem; /* 20px — control↔copy */
}

.govbb-checkbox-item__label,
.govbb-radio-item__label {
  grid-column: 2;
  grid-row: 1;
  padding-block: calc(
    (3rem - var(--govbb-line-height-base) * var(--govbb-font-size-body)) / 2
  );
  font-size: var(--govbb-font-size-body);
  line-height: var(--govbb-line-height-base);
  color: var(--govbb-color-ink);
  overflow-wrap: anywhere;
  cursor: pointer;
}

.govbb-checkbox-item > .govbb-hint,
.govbb-radio-item > .govbb-hint {
  grid-column: 2;
  grid-row: 2;
  align-self: start;
}

.govbb-checkbox:disabled + .govbb-checkbox-item__label,
.govbb-radio:disabled + .govbb-radio-item__label,
.govbb-checkbox:disabled ~ .govbb-hint,
.govbb-radio:disabled ~ .govbb-hint {
  opacity: var(--govbb-opacity-disabled);
  cursor: not-allowed;
}

/* Conditional reveal — shown only when the preceding control is checked. */
.govbb-checkbox-item__conditional,
.govbb-radio-item__conditional {
  display: none;
  margin-top: var(--govbb-space-xs);
  margin-bottom: var(--govbb-space-s);
  margin-left: 1.25rem;
  padding-left: 3rem; /* 48px */
  padding-bottom: var(--govbb-space-s);
  border-left: 8px solid var(--govbb-color-highlight);
}

.govbb-checkbox-item:has(> .govbb-checkbox:checked)
  + .govbb-checkbox-item__conditional,
.govbb-radio-item:has(> .govbb-radio:checked) + .govbb-radio-item__conditional {
  display: block;
}

/* Forced colors strips background fills, which would make :checked
   indistinguishable from unchecked — repaint the mark in the system ink. */
@media (forced-colors: active) {
  .govbb-checkbox::before,
  .govbb-radio::before {
    forced-color-adjust: none;
    background: CanvasText;
  }
}
