/* Animation master - Error shake */

/*
  Usage:
    <div class="t-error-shake-wrap">
      <div class="t-error-shake">
        <input class="t-error-shake-input">
      </div>
      <p class="t-error-shake-message">Please enter a valid email.</p>
    </div>

  State: add `.is-error` to wrapper and input shell.
  Add `.is-shaking` to `.t-error-shake` to replay the shake.
*/

:root {
  --error-shake-distance: 6px;
  --error-shake-overshoot: 4px;
  --error-shake-dur-a: 80ms;
  --error-shake-dur-b: 60ms;
  --error-shake-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --error-shake-border: #e23014;
  --error-shake-text: #d62b11;
  --error-shake-revert-hold: 3000ms;
  --error-shake-revert-dur: 280ms;
}

.t-error-shake-wrap {
  width: 220px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.t-error-shake {
  height: 36px;
  display: flex;
  align-items: center;
  padding: 4px 4px 4px 12px;
  border: 1px solid #dcdcdc;
  border-radius: 8px;
  background: #ffffff;
  outline: none;
  transition: border-color 150ms ease-out;
  will-change: transform;
}

.t-error-shake:focus-within {
  border-color: #585858;
}

.t-error-shake.is-error {
  border-color: var(--error-shake-border);
  transition: border-color var(--error-shake-revert-dur) ease-out;
}

.t-error-shake-input {
  min-width: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: #0d0d0d;
  font: inherit;
  font-size: 13px;
  line-height: 1.4;
}

.t-error-shake-input::placeholder {
  color: #6c6c6c;
}

.t-error-shake-message {
  margin: 0;
  color: var(--error-shake-text);
  font-size: 13px;
  line-height: 1.4;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity var(--error-shake-revert-dur) ease-out,
    visibility 0s linear var(--error-shake-revert-dur);
}

.t-error-shake-wrap.is-error .t-error-shake-message {
  opacity: 1;
  visibility: visible;
  transition:
    opacity var(--error-shake-revert-dur) ease-out,
    visibility 0s linear 0s;
}

.t-error-shake.is-shaking {
  animation: t-error-shake calc(var(--error-shake-dur-a) * 2 + var(--error-shake-dur-b) * 2) linear;
}

@keyframes t-error-shake {
  0% {
    transform: translateX(0);
    animation-timing-function: var(--error-shake-ease);
  }

  28.57% {
    transform: translateX(var(--error-shake-distance));
    animation-timing-function: var(--error-shake-ease);
  }

  57.14% {
    transform: translateX(calc(var(--error-shake-distance) * -1));
    animation-timing-function: var(--error-shake-ease);
  }

  78.57% {
    transform: translateX(var(--error-shake-overshoot));
    animation-timing-function: var(--error-shake-ease);
  }

  100% {
    transform: translateX(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .t-error-shake {
    animation: none !important;
    transition: none !important;
  }
}
