@use "../../wc";

:host {
  display: block;
  line-height: var(--zn-line-height-dense);
}

:host([horizontal]) .form-control-input {
  display: flex;
  flex-wrap: wrap;
  column-gap: var(--zn-spacing-2x-large);
  row-gap: var(--zn-spacing-small);
}

::slotted(zn-checkbox[horizontal]) {
  flex-basis: 20%;
  min-width: 100px;
}

/* The label supplies the gap above the options, so a group without one starts flush. */
:host([contained]) .form-control--has-label .form-control-input {
  margin-top: var(--zn-spacing-medium);
}

:host([horizontal][contained]) .form-control-input {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, var(--zn-checkbox-group-column-width, 152px)), 1fr));
  align-items: stretch;
  gap: var(--zn-spacing-small);
}

::slotted(zn-checkbox) {
  margin-top: var(--zn-spacing-medium);
}

::slotted(zn-checkbox[horizontal]),
::slotted(zn-checkbox[contained]) {
  margin-top: var(--zn-spacing-small);
}

::slotted(zn-checkbox[horizontal][contained]) {
  margin-top: 0;
  height: 100%;
}

/* `wrap` swaps the equal-width grid for a flex row: cards start from their basis and wrap onto new lines. */
:host([horizontal][contained][wrap]) .form-control-input {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: var(--zn-spacing-x-small);
}

:host([wrap]) ::slotted(zn-checkbox[horizontal][contained]) {
  flex: 1 1 var(--zn-checkbox-group-column-width, 152px);
  min-width: 0;

  /* A percentage height would resolve against every line, not the card's own. */
  height: auto;
}


.form-control {
  position: relative;
  border: none;
  padding: 0;
  margin: 0;
}

.form-control__label {
  padding: 0;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
