.field {
  --_input: 3rem;
  --_start: 1.2rem;
  --_middle: calc(var(--_input, 0) / 2);
  border-radius: 0.25rem 0.25rem 0 0;
  min-block-size: var(--_input);
  display: flex;
  flex-direction: column;
}

.field.fill {
  --_background: var(--surface-variant);
  background-color: unset !important;
  color: unset !important;
}

.field.fill > :is(input, select, textarea) {
  background-color: var(--_background);
  z-index: 0;
}

.field.small {
  --_input: 2.5rem;
  --_start: 1rem;
}

.field.large {
  --_input: 3.5rem;
  --_start: 1.4rem;
}

.field.extra {
  --_input: 4rem;
  --_start: 1.6rem;
}

.field.border {
  border-radius: 0.25rem;
}

.field.round.small {
  border-radius: 1.25rem;
}

.field.round {
  border-radius: 1.5rem;
}

.field.round.large {
  border-radius: 1.75rem;
}

.field.round.extra {
  border-radius: 2rem;
}

/* icon */
.field > :is(i, img, svg, progress.circle, a) {
  position: absolute;
  inset: calc((var(--_input, 0) / 2) - 0.75rem) auto auto auto;
  cursor: pointer;
  z-index: 10;
  inline-size: 1.5rem;
  block-size: 1.5rem;
  margin: auto 0;
  pointer-events: none;
}

.field > :is(a, .front) {
  pointer-events: all !important;
}

.field > a > :is(i, img, svg, progress.circle, a) {
  inline-size: 1.5rem;
  block-size: 1.5rem;
}

.field > :is(i, img, svg, progress.circle, a),
[dir=rtl] .field > :is(i, img, svg, progress.circle, a):first-child {
  inset: calc(var(--_middle, 0) - 0.75rem) 1rem auto auto;
}

.field > :is(i, img, svg, progress.circle, a):first-child,
[dir=rtl] .field > :is(i, img, svg, progress.circle, a) {
  inset: calc(var(--_middle, 0) - 0.75rem) auto auto 1rem;
}

.field.invalid > i {
  color: var(--error);
}

.field > progress.circle {
  border-width: 0.1875rem;
}

/* input, textarea and select */
.field > :is(input, textarea, select) {
  all: unset;
  position: relative;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  border-radius: inherit;
  border: 0.0625rem solid transparent;
  padding: 0 0.9375rem;
  font-family: inherit;
  font-size: 1rem;
  min-block-size: var(--_input);
  outline: none;
  z-index: 1;
  background: none;
  resize: none;
  text-align: start;
  cursor: text;
}

input::-webkit-date-and-time-value {
  text-align: start;
}

:is(input, select, textarea):is(:-webkit-autofill, :autofill) {
  -webkit-background-clip: text;
  -webkit-text-fill-color: var(--on-surface);
}

.field > :is(input, textarea, select):focus {
  border: 0.125rem solid transparent;
  padding-inline: 0.875rem;
}

.field > textarea:not([rows]) {
  field-sizing: content;
  max-block-size: 12rem;
}

input[type=file],
input[type=color],
:not(.field) > input[type^=date],
:not(.field) > input[type^=time],
input::-webkit-calendar-picker-indicator {
  opacity: 0;
  position: absolute;
  inset: 0;
  inline-size: 100%;
  block-size: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  outline: 0;
  z-index: 2 !important;
}

input::-webkit-search-decoration,
input::-webkit-search-cancel-button,
input::-webkit-search-results-button,
input::-webkit-search-results-decoration,
input::-webkit-inner-spin-button,
input::-webkit-outer-spin-button {
  display: none;
}

input[type=number] {
  appearance: textfield;
}

.field.border > :is(input, textarea, select) {
  border-color: var(--outline);
}

.field.border > :is(input, textarea, select):focus {
  border-color: var(--primary);
}

.field.round > :is(input, textarea, select) {
  padding-inline: 1.4376rem;
}

.field.round > :is(input, textarea, select):focus {
  padding-inline: 1.375rem;
}

.field.prefix > :is(input, textarea, select) {
  padding-inline-start: 2.9375rem;
}

.field.prefix > .slider {
  margin-inline-start: 3.5rem;
}

.field.prefix > :is(input, textarea, select):focus {
  padding-inline-start: 2.875rem;
}

.field.suffix > :is(input, textarea, select) {
  padding-inline-end: 2.9375rem;
}

.field.suffix > .slider {
  margin-inline-end: 3.5rem;
}

.field.suffix > :is(input, textarea, select):focus {
  padding-inline-end: 2.875rem;
}

.field:not(.border, .round) > :is(input, textarea, select) {
  border-block-end-color: var(--outline);
}

.field:not(.border, .round) > :is(input, textarea, select):focus {
  border-block-end-color: var(--primary);
}

.field.round:not(.border, .fill) > :is(input, textarea, select),
.field.round:not(.border) > :is(input, textarea, select):focus {
  box-shadow: var(--elevate1);
}

.field.round:not(.border, .fill) > :is(input, textarea, select):focus {
  box-shadow: var(--elevate2);
}

.field.invalid:not(.border, .round) > :is(input, textarea, select),
.field.invalid:not(.border, .round) > :is(input, textarea, select):focus {
  border-block-end-color: var(--error);
}

.field.invalid.border > :is(input, textarea, select),
.field.invalid.border > :is(input, textarea, select):focus {
  border-color: var(--error);
}

.field:has(> :disabled) {
  opacity: 0.5;
  cursor: not-allowed;
}

.field > :disabled {
  cursor: not-allowed;
}

.field > select {
  user-select: none;
}

@-moz-document url-prefix() {
  .field > select:focus {
    background-color: var(--surface);
  }

  .field.fill > select:focus {
    background-color: var(--surface-variant);
  }
  
  .field > select:focus + label {
    z-index: 1;
  }
}

.field > select > option {
  background-color: var(--surface);
}

.field > :is(input, select) {
  padding-block-start: 1rem;
}

.field:not(.label) > :is(input, select),
.field.border:not(.fill) > :is(input, select) {
  padding-block-start: 0;
}

.field > textarea {
  padding-block-start: var(--_start) !important;
}

.field > textarea:focus {
  padding-block-start: calc(var(--_start, 0) - 0.01rem) !important;
}

.field:not(.label) > textarea,
.field.border:not(.fill) > textarea {
  padding-block-start: calc(var(--_start, 0) - 0.5rem) !important;
}

.field:not(.label) > textarea:focus,
.field.border:not(.fill) > textarea:focus {
  padding-block-start: calc(var(--_start, 0) - 0.51rem) !important;
}

/* label */
.field.label > label {
  --_start: 1rem;
  position: absolute;
  inset: -0.5rem 1rem 0 var(--_start);
  display: flex;
  block-size: calc(var(--_input, 0) + 1rem);
  line-height: calc(var(--_input, 0) + 1rem);
  font-size: 1rem;
  transition: all 0.2s;
  gap: 0.25rem;
  white-space: nowrap;
  pointer-events: none;
}

[dir=rtl] .field.label > label {
  inset: -0.5rem var(--_start) 0 1rem;
}

.field.label.round > label {
  inset: -0.5rem 1.75rem 0 var(--_start);
}

[dir=rtl] .field.label.round > label {
  inset: -0.5rem 1.75rem 0 var(--_start);
}

.field.label.border.prefix:not(.fill) > :is(label.active, :focus + label, [placeholder]:not(:placeholder-shown) + label, select + label) {
  --_start: 1rem;
}

.field.label.round > label,
.field.label.border.prefix.round:not(.fill) > :is(label.active, :focus + label, [placeholder]:not(:placeholder-shown) + label, select + label) {
  --_start: 1.5rem;
}

.field.label.prefix > label {
  --_start: 3rem;
}

.field.label > :is(label.active, :focus + label, [placeholder]:not(:placeholder-shown) + label, select + label) {
  block-size: 2.5rem;
  line-height: 2.5rem;
  font-size: 0.75rem;
}

.field.label.border:not(.fill) > :is(label.active, :focus + label, [placeholder]:not(:placeholder-shown) + label, select + label) {
  block-size: 1rem;
  line-height: 1rem;
}

.field.label.border:not(.fill) > label::after {
  content: "";
  display: block;
  margin: 0.5rem 0 0 0;
  border-block-start: 0.0625rem solid var(--outline);
  block-size: 1rem;
  transition: none;
  flex: auto;
}

.field.label.border:not(.fill) > :focus + label::after {
  border-block-start: 0.125rem solid var(--primary);
}

.field.label.border:not(.fill) > :is(input, textarea):is(:focus, [placeholder]:not(:placeholder-shown), .active),
.field.label.border:not(.fill) > select {
  clip-path: polygon(-2% -2%, 0.75rem -2%, 0.75rem 0.5rem, calc(100% - 1rem) 0.5rem, calc(100% - 1rem) -2%, 102% -2%, 102% 102%, -2% 102%);
}

[dir=rtl] .field.label.border:not(.fill) > :is(input, textarea):is(:focus, [placeholder]:not(:placeholder-shown), .active),
[dir=rtl] .field.label.border:not(.fill) > select {
  clip-path: polygon(-2% -2%, 1rem -2%, 1rem 0.5rem, calc(100% - 0.75rem) 0.5rem, calc(100% - 0.75rem) -2%, 102% -2%, 102% 102%, -2% 102%);
}

.field.label.border.round:not(.fill) > :is(input, textarea):is(:focus, [placeholder]:not(:placeholder-shown), .active),
.field.label.border.round:not(.fill) > select {
  clip-path: polygon(-2% -2%, 1.25rem -2%, 1.25rem 0.5rem, calc(100% - 1.75rem) 0.5rem, calc(100% - 1.75rem) -2%, 102% -2%, 102% 102%, -2% 102%);
}

[dir=rtl] .field.label.border.round:not(.fill) > :is(input, textarea):is(:focus, [placeholder]:not(:placeholder-shown), .active),
[dir=rtl] .field.label.border.round:not(.fill) > select {
  clip-path: polygon(-2% -2%, 1.75rem -2%, 1.75rem 0.5rem, calc(100% - 1.25rem) 0.5rem, calc(100% - 1.25rem) -2%, 102% -2%, 102% 102%, -2% 102%);
}

.field.label > :focus + label {
  color: var(--primary);
}

.field.label.invalid > label,
.field.label.invalid > label::after {
  color: var(--error) !important;
  border-color: var(--error) !important;
}

.field.label > label > a {
  block-size: inherit;
  line-height: inherit;
  inline-size: 1rem;
}

.field.label > label > a > :is(i, img, svg) {
  block-size: 1rem;
  line-height: 1rem;
  inline-size: 1rem;
  font-size: 1rem;
}

/* helper */
.field > output {
  display: inline-block;
  font-size: 0.75rem;
  background: none !important;
  padding: 0.25rem 1rem;
  line-height: 1.25rem;
  align-self: start;
}

.field > output.invalid {
  color: var(--error) !important;
}

.field.round > output {
  padding: 0.25rem 1.5rem;
}

.field.invalid > output:not(.invalid),
.field:not(.invalid) > output.invalid {
  display: none;
}

.field.invalid > output.invalid ~ menu,
.field:not(.invalid) > output:not(.invalid) ~ menu {
  inset: auto auto 1.75rem 0;
}

table td > .field {
  margin: 0;
}

fieldset {
  border-radius: 0.25rem;
  padding: 1rem;
  border: 0.0625rem solid var(--outline-variant);
}

fieldset > legend {
  margin: 0 -0.25rem;
  padding: 0 0.25rem;
}

fieldset > legend + * {
  margin-block-start: 0 !important;
}
