/*
 * Text field — Figma "input-inline" (4041:133) and "text-form" (4041:197).
 *
 * The label starts as a placeholder centred in the box and floats to the top
 * as a caption as soon as the field is focused or filled, which is exactly
 * the Enabled -> Focus/Valid/Error transition of the maquette.
 *
 * The floating relies on :placeholder-shown, so the control always carries a
 * placeholder; the Twig component sets a blank one when none is given.
 *
 * States are driven by the real validity of the control rather than by a
 * modifier class, so a server-side error and a browser-side one look alike.
 */

.mo-field {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: var(--mo-spacing-xxs);
    width: 100%;
    max-width: 320px;
}

.mo-field__box {
    position: relative;
}

.mo-field__control {
    display: block;
    width: 100%;
    height: 50px;
    padding: 11px 20px;
    border: var(--mo-border-width-xs) solid var(--mo-border-default-medium);
    border-radius: var(--mo-radius-md);
    background-color: var(--mo-surface-default-white);
    color: var(--mo-text-body);
    font-family: var(--mo-font-family);
    font-size: var(--mo-font-size-body-md);
    font-weight: var(--mo-font-weight-medium);
    line-height: var(--mo-line-height-body-md);
    transition: border-color 120ms ease, padding 120ms ease;
}

.mo-field__control::placeholder {
    color: transparent;
}

.mo-field__label {
    position: absolute;
    inset-inline-start: 20px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--mo-text-placeholder);
    font-size: var(--mo-font-size-body-md);
    font-weight: var(--mo-font-weight-medium);
    line-height: var(--mo-line-height-body-md);
    pointer-events: none;
    transition: top 120ms ease, transform 120ms ease, font-size 120ms ease;
}

.mo-field__control:focus,
.mo-field__control:not(:placeholder-shown) {
    padding-block: 17px 5px;
}

.mo-field__control:focus ~ .mo-field__label,
.mo-field__control:not(:placeholder-shown) ~ .mo-field__label {
    top: 5px;
    transform: none;
    font-size: var(--mo-font-size-caption);
    line-height: var(--mo-font-size-caption);
}

.mo-field__control:focus {
    outline: none;
}

.mo-field__control[aria-invalid='true'],
.mo-field__control:user-invalid {
    border-color: var(--mo-border-error);
}

.mo-field__control:disabled {
    background-color: var(--mo-surface-disabled);
    color: var(--mo-text-disabled);
    cursor: not-allowed;
}

/* Trailing affordance, e.g. the eye-off toggle of a password field. */
.mo-field__action {
    position: absolute;
    inset-inline-end: 20px;
    top: 50%;
    display: flex;
    transform: translateY(-50%);
    color: var(--mo-icon-default-dark);
    cursor: pointer;
}

.mo-field__action svg {
    width: var(--mo-scale-200);
    height: var(--mo-scale-200);
}

.mo-field:has(.mo-field__action) .mo-field__control {
    padding-inline-end: 48px;
}

/* Help text and error message under the box. */
.mo-field__message {
    color: var(--mo-text-placeholder);
    font-size: var(--mo-font-size-caption);
    line-height: var(--mo-line-height-caption);
}

.mo-field__message--error {
    color: var(--mo-border-error);
}

/* Multi-line variant — Figma "text-form", 150px tall. */
.mo-field--textarea {
    max-width: 320px;
}

.mo-field--textarea .mo-field__control {
    height: 150px;
    resize: vertical;
}

.mo-field--textarea .mo-field__label {
    top: 12px;
    transform: none;
}

.mo-field--textarea .mo-field__control:focus ~ .mo-field__label,
.mo-field--textarea .mo-field__control:not(:placeholder-shown) ~ .mo-field__label {
    top: 5px;
}
