/* Shared layout and states for Checkbox and Radio.
   The native input stays in the DOM and keeps focus/keyboard behaviour; it is
   made transparent and stretched over the painted box, which reacts via
   sibling selectors. */

.ds-choice {
  display: inline-flex;
  align-items: flex-start;
  gap: var(--ds-space-xs);
  min-width: 0;
}

.ds-choice__control {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
  /* Optically centres the box against the first line of label text. */
  margin-top: 1px;
}

.ds-choice__input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.ds-choice__input:disabled {
  cursor: not-allowed;
}

.ds-choice__box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  background-color: var(--ds-color-surface);
  border: 1px solid var(--ds-color-border-strong);
  color: var(--ds-color-accent-text);
  transition:
    background-color var(--ds-duration-fast) var(--ds-ease-standard),
    border-color var(--ds-duration-fast) var(--ds-ease-standard);
}

.ds-choice__input:hover:not(:disabled) + .ds-choice__box {
  border-color: var(--ds-color-accent);
}

/* `:indeterminate` MUST stay scoped to checkboxes. Per the HTML spec it also
   matches every radio in a group with nothing checked, so an unscoped rule
   paints all options of an unanswered group solid accent and its border wins
   over .ds-choice--invalid — hiding the error exactly when a required group
   is unanswered. */
.ds-choice__input:checked + .ds-choice__box,
.ds-choice__input[type='checkbox']:indeterminate + .ds-choice__box {
  background-color: var(--ds-color-accent);
  border-color: var(--ds-color-accent);
}

.ds-choice__input:focus-visible + .ds-choice__box {
  outline: 2px solid var(--ds-color-accent);
  outline-offset: 2px;
}

.ds-choice__input:disabled + .ds-choice__box {
  background-color: var(--ds-color-surface-sunken);
  border-color: var(--ds-color-border);
}

.ds-choice__input:disabled:checked + .ds-choice__box,
.ds-choice__input[type='checkbox']:disabled:indeterminate + .ds-choice__box {
  background-color: var(--ds-color-text-subtle);
  border-color: var(--ds-color-text-subtle);
}

.ds-choice--invalid .ds-choice__box {
  border-color: var(--ds-color-danger);
}

.ds-choice__text {
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-3xs);
  min-width: 0;
}

.ds-choice__label {
  color: var(--ds-color-text);
  font-size: var(--ds-text-md);
  line-height: var(--ds-leading-md);
  cursor: pointer;
}

.ds-choice__input:disabled ~ .ds-choice__text .ds-choice__label {
  color: var(--ds-color-text-muted);
  cursor: not-allowed;
}

.ds-choice__description {
  color: var(--ds-color-text-muted);
  font-size: var(--ds-text-sm);
  line-height: var(--ds-leading-sm);
}
