@layer ds_components {
  .comp-form {
    &.is-2up-grid {
      display: grid;
      row-gap: var(--ds-component-form-row-gap-default);
      column-gap: var(--ds-component-form-column-gap-default);

      & > .is-row {
        display: grid;
        column-gap: var(--ds-component-form-column-gap-default);
        row-gap: var(--ds-component-form-row-gap-default);
        @container (width > 40rem) {
          grid-template-columns: repeat(2, 1fr);

          &:has(button[type="submit"]) {
            margin-block-start: var(--ds-component-form-row-gap-default);
          }
        }
      }
    }

    & .is-col.is-full {
      grid-column: 1 / -1;
    }

    & .is-col.has-switch {
      display: flex;
      align-items: center;
      gap: var(--ds-component-form-column-gap-default);

      & input[type="checkbox"][role="switch"] {
        flex-shrink: 0;
      }
    }

    & legend {
      grid-column: span 2;
      width: 100%;
    }

    label:not([hidden]) {
      display: block;
      margin-block-end: var(--ds-component-form-label-margin-block);
      color: var(--ds-component-form-label-color);
    }

    input:not([type="checkbox"]):not([type="radio"]),
    textarea,
    select {
      background-color: var(--ds-component-form-color-background-field);
      color: var(--ds-component-form-color-field);
      outline: var(--ds-component-form-outline-width-default) solid
        var(--ds-component-form-outline-color-default);
      border: none;
      border-radius: var(--ds-component-form-border-radius-field);
      padding-inline: var(--ds-component-form-padding-field-inline);
      padding-block: var(--ds-component-form-padding-field-block);
      width: 100%;
      text-align: left;
      min-height: var(--ds-component-form-text-input-height);
      field-sizing: content;

      &:focus-visible:not([disabled]):not([readonly]) {
        background-color: var(--ds-component-form-color-background-field-focus);
        color: var(--ds-component-form-color-field-focus);
        outline-color: var(--ds-component-form-outline-color-focus);
        outline-offset: 0px;
        outline-width: var(--ds-component-form-outline-width-focus);
      }

      &::selection {
        background-color: var(
          --ds-component-form-color-background-field-selection
        );
        color: var(--ds-component-form-color-field-selection);
      }

      &[readonly],
      &[disabled] {
        background-color: var(
          --ds-component-form-color-background-field-disabled
        );
        outline-color: var(--ds-component-form-color-background-field-disabled);
        opacity: var(--ds-component-form-disabled-opacity);
      }
    }

    input:where([type="checkbox"][role="switch"]) {
      -webkit-appearance: none;
      -moz-appearance: none;
      appearance: none;
      position: relative;
      font-size: inherit;
      width: 3em;
      height: 1.5em;
      box-sizing: content-box;
      border: none;
      border-radius: 1em;
      vertical-align: text-bottom;
      margin: auto;
      color: inherit;
      margin-block-start: 0.375em;
      background-color: var(--ds-component-form-color-background-field);
      color: var(--ds-component-form-color-field);
      cursor: pointer;
      outline: var(--ds-component-form-outline-width-default) solid
        var(--ds-component-form-outline-color-default);

      &:focus:not([disabled]) {
        outline-color: var(--ds-component-form-outline-color-focus);
        outline-width: var(--ds-component-form-outline-width-focus);
      }
    }

    input:where([type="checkbox"][role="switch"])::before {
      content: "";
      position: absolute;
      top: 50%;
      left: 0;
      transform: translate(0, -50%);
      box-sizing: border-box;
      width: 1em;
      height: 1em;
      margin: 0 0.25em;
      border: 1px solid;
      border-radius: 50%;
      opacity: 0.5;
      transition: all 0.1s ease-in-out;
      cursor: pointer;
    }

    input:where([type="checkbox"][role="switch"]):checked::before {
      content: "✓";
      left: 1.3em;
      width: 1.25em;
      height: 1.25em;
      opacity: 1;
      display: flex;
      align-items: center;
      justify-content: center;
    }
  }
}
