.hap-textfield {
  display: flex;
  flex-direction: column;
  gap: var(--hap-spacing-xs);
}

/* Label  */

.hap-textfield-label,
.hap-textfield > label {
  display: flex;
  gap: var(--hap-spacing-xs);
  color: light-dark(
    var(--hap-color-text-secondary-on-light),
    var(--hap-color-text-secondary-on-dark)
  );
  font-family: var(--hap-typography-font-family-body);
  font-size: var(--hap-typography-font-size-bodytext-s);
  font-weight: var(--hap-typography-font-weight-medium);
  line-height: var(--hap-typography-line-height-bodytext-s-singleline);
  letter-spacing: var(--hap-typography-letter-spacing-lg);

  & > svg {
    height: var(--hap-typography-line-height-bodytext-s-singleline);
    width: var(--hap-typography-line-height-bodytext-s-singleline);
  }
}

/* Input */

.hap-textfield-input,
.hap-textfield > input {
  --hap-textfield-border-width: var(--hap-border-width-sm);
  --hap-textfield-border-color: var(
    --hap-color-border-secondary-on-light-default
  );

  display: flex;
  flex-direction: row;

  appearance: none;
  outline: none;
  box-sizing: border-box;
  transition: all 150ms linear;
  padding: var(--hap-spacing-sm);
  border: none;
  border-radius: var(--hap-radius-minimal);
  box-shadow: inset 0 0 0 var(--hap-textfield-border-width)
    var(--hap-textfield-border-color);
  background-color: var(--hap-color-fill-input-default);

  &,
  &:not(input) > input {
    color: var(--hap-color-text-primary-on-light);
    font-family: var(--hap-typography-font-family-body);
    font-size: var(--hap-typography-font-size-bodytext-s);
    font-weight: var(--hap-typography-font-weight-regular);
    line-height: var(--hap-typography-line-height-bodytext-standard-singleline);
    letter-spacing: var(--hap-typography-letter-spacing-lg);
  }

  &:hover {
    background-color: var(--hap-color-fill-input-hovered);
  }

  &:not(input):has(input:read-only) {
    --hap-textfield-border-color: var(
      --hap-color-border-secondary-on-light-default
    );
    background-color: var(--hap-color-fill-input-hovered);
  }

  &:focus-visible,
  &:focus-within {
    --hap-textfield-border-width: var(--hap-border-width-md);
    --hap-textfield-border-color: var(--hap-color-border-focused-default);
  }
}

.hap-textfield-input > input {
  border: none;
  background: none;
  width: 100%;
  &:focus-visible {
    outline: none;
  }
}

.hap-textfield-input-tags {
  flex: 1;
}

.hap-textfield-input:disabled,
.hap-textfield:has(input:disabled) {
  pointer-events: none;
  opacity: var(--hap-opacity-disabled);
}

.hap-textfield-input--brand,
.hap-textfield--brand > input,
.hap-textfield--brand > .hap-textfield-input {
  border-radius: var(--hap-radius-full);
  padding-inline: var(--hap-spacing-md-lg);
  padding-block: var(--hap-spacing-md);
}

/* Description */

.hap-textfield-description,
.hap-textfield > span {
  color: light-dark(
    var(--hap-color-text-secondary-on-light),
    var(--hap-color-text-secondary-on-dark)
  );
  font-family: var(--hap-typography-font-family-body);
  font-size: var(--hap-typography-font-size-bodytext-xs);
  font-weight: var(--hap-typography-font-weight-regular);
  line-height: var(--hap-typography-line-height-bodytext-xs-multiline);
  letter-spacing: var(--hap-typography-letter-spacing-lg);
}

/* Error State */

.hap-feedback--invalid:not(input),
.hap-textfield.hap-feedback--invalid > label,
.hap-textfield.hap-feedback--invalid > span {
  color: light-dark(
    var(--hap-color-feedback-critical-dark),
    var(--hap-color-feedback-critical-light)
  );
}

input.hap-feedback--invalid,
.hap-textfield.hap-feedback--invalid > input,
.hap-textfield-input.hap-feedback--invalid,
.hap-textfield.hap-feedback--invalid > .hap-textfield-input {
  --hap-textfield-border-color: var(--hap-color-feedback-critical-dark);
}
