/*
 * M3 form fields rendered by RzFormBuilder.
 * Outlined text field: the label sits inside the field and floats onto the border
 * when the field is focused or filled (input:not(:placeholder-shown)), CSS only.
 * The floated label covers the border with --rz-field-bg (background behind the field).
 */
.rz-form {
  --rz-field-bg: var(--md-sys-color-surface);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  max-width: 560px;
}

.rz-form--card {
  --rz-field-bg: var(--md-sys-color-surface-container-low);
  box-sizing: border-box;
  margin: 8px 0 16px;
  padding: 16px;
  border-radius: var(--md-sys-shape-corner-medium);
  background: var(--rz-field-bg);
  box-shadow: var(--md-sys-elevation-level1);
}

.rz-form__actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

/* ---- outlined text field / textarea / select ---- */
.rz-text-field {
  position: relative;
  box-sizing: border-box;
  width: 100%;
  max-width: 560px;
  margin: 8px 0;
}

.rz-text-field__input {
  box-sizing: border-box;
  display: block;
  width: 100%;
  min-height: 56px;
  margin: 0;
  padding: 15px 16px;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-extra-small);
  outline: none;
  background: transparent;
  color: var(--md-sys-color-on-surface);
  font: var(--md-sys-typescale-body-large);
  caret-color: var(--md-sys-color-primary);
  appearance: none;
}
.rz-text-field__input::placeholder { color: var(--md-sys-color-on-surface-variant); }
.rz-text-field__input:hover { border-color: var(--md-sys-color-on-surface); }
.rz-text-field__input:focus {
  padding: 14px 15px;
  border: 2px solid var(--md-sys-color-primary);
}

.rz-text-field--textarea .rz-text-field__input { min-height: 112px; resize: vertical; }

.rz-text-field__label {
  position: absolute;
  top: 16px;
  left: 12px;
  max-width: calc(100% - 32px);
  padding: 0 4px;
  overflow: hidden;
  background: var(--rz-field-bg);
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-body-large);
  white-space: nowrap;
  text-overflow: ellipsis;
  pointer-events: none;
  transition: top var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard),
              font-size var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
}

/* floated label: focused, filled, autofilled, selects (always have a value) */
.rz-text-field__input:focus + .rz-text-field__label,
.rz-text-field__input:not(:placeholder-shown) + .rz-text-field__label,
.rz-text-field__input:autofill + .rz-text-field__label,
.rz-text-field--select .rz-text-field__label {
  top: -8px;
  font: var(--md-sys-typescale-body-small);
}
.rz-text-field__input:focus + .rz-text-field__label { color: var(--md-sys-color-primary); }

/* hide the " " placeholder until the label has floated away */
.rz-text-field:not(.rz-text-field--no-label) .rz-text-field__input:not(:focus)::placeholder { color: transparent; }

.rz-text-field--select .rz-text-field__input { padding-right: 44px; cursor: pointer; }
.rz-text-field--select .rz-text-field__input:focus { padding-right: 43px; }
.rz-select__icon {
  position: absolute;
  top: 16px;
  right: 12px;
  color: var(--md-sys-color-on-surface-variant);
  pointer-events: none;
}

.rz-field__supporting {
  padding: 4px 16px 0;
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-body-small);
}

/* error state */
.rz-text-field--error .rz-text-field__input,
.rz-text-field--error .rz-text-field__input:hover { border-color: var(--md-sys-color-error); }
.rz-text-field--error .rz-text-field__input:focus { border-color: var(--md-sys-color-error); }
.rz-text-field--error .rz-text-field__label,
.rz-text-field--error .rz-text-field__input:focus + .rz-text-field__label,
.rz-text-field--error .rz-field__supporting,
.rz-checkbox--error .rz-field__supporting,
.rz-switch--error .rz-field__supporting { color: var(--md-sys-color-error); }

/* ---- checkbox ---- */
.rz-checkbox,
.rz-switch { margin: 4px 0; }

.rz-checkbox__label,
.rz-switch__label {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: 40px;
  color: var(--md-sys-color-on-surface);
  font: var(--md-sys-typescale-body-large);
  cursor: pointer;
}

.rz-checkbox__input {
  position: relative;
  flex: none;
  width: 18px;
  height: 18px;
  margin: 11px;
  border: 2px solid var(--md-sys-color-on-surface-variant);
  border-radius: 2px;
  background: transparent;
  appearance: none;
  cursor: pointer;
}
.rz-checkbox__input:checked {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-primary);
}
.rz-checkbox__input:checked::after {
  content: "";
  position: absolute;
  top: 1px;
  left: 4px;
  width: 4px;
  height: 9px;
  border: solid var(--md-sys-color-on-primary);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.rz-checkbox__input:focus-visible,
.rz-switch__input:focus-visible { outline: 3px solid var(--md-sys-color-secondary); outline-offset: 2px; }

/* ---- switch ---- */
.rz-switch__input {
  position: relative;
  flex: none;
  width: 52px;
  height: 32px;
  margin: 4px 0;
  border: 2px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--md-sys-color-surface-container-highest);
  appearance: none;
  cursor: pointer;
  transition: background var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
}
.rz-switch__input::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 6px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--md-sys-color-outline);
  transform: translateY(-50%);
  transition: all var(--md-sys-motion-duration-short4) var(--md-sys-motion-easing-standard);
}
.rz-switch__input:checked {
  border-color: var(--md-sys-color-primary);
  background: var(--md-sys-color-primary);
}
.rz-switch__input:checked::before {
  left: 22px;
  width: 24px;
  height: 24px;
  background: var(--md-sys-color-on-primary);
}

/* ---- error summary above a form ---- */
.rz-form-errors {
  box-sizing: border-box;
  max-width: 560px;
  margin: 8px 0 16px;
  padding: 12px 16px;
  border-radius: var(--md-sys-shape-corner-medium);
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
  font: var(--md-sys-typescale-body-medium);
}
.rz-form-errors ul { margin: 0; padding-left: 20px; }

.rz-form--wide { max-width: 720px; }
.rz-form--wide .rz-text-field { max-width: none; }
.rz-form-errors__title { margin: 0 0 4px; font: var(--md-sys-typescale-title-small); }

/* neutral variant (e.g. "you must sign in first") */
.rz-form-errors--info {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

/* trailing icon button (show / hide password) */
.rz-text-field__trailing {
  position: absolute;
  top: 8px;
  right: 8px;
}
.rz-text-field--password .rz-text-field__input { padding-right: 52px; }
.rz-text-field--password .rz-text-field__input:focus { padding-right: 51px; }
.rz-text-field--password .rz-text-field__label { max-width: calc(100% - 72px); }
.rz-text-field__trailing[hidden] { display: none; }
