@import '../../utils/shared-styles.scss';

.container {
  width: 100%;
  max-width: 480px;
  margin-inline: auto;
  padding-inline: clamp(1rem, 4vw, 2rem);
}

.auth {
  min-height: 80vh;
  display: flex;
  align-items: center;
  padding-block: 3rem;
}

/* ===== AUTH CARD ===== */

@keyframes cardExit {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-20px) scale(0.98);
  }
}

@keyframes successPulse {
  0% {
    box-shadow: $shadow-glass;
  }
  50% {
    box-shadow: 0 0 0 8px rgba(34, 197, 94, 0.15), $shadow-glass;
  }
  100% {
    box-shadow: $shadow-glass;
  }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-6px); }
  20%, 40%, 60%, 80% { transform: translateX(6px); }
}

@keyframes errorPulse {
  0% {
    box-shadow: $shadow-glass;
  }
  50% {
    box-shadow: 0 0 0 8px rgba(239, 68, 68, 0.15), $shadow-glass;
  }
  100% {
    box-shadow: $shadow-glass;
  }
}

.auth-card {
  width: 100%;
  background: $glass-bg;
  backdrop-filter: blur(20px);
  border: 1px solid $glass-border;
  border-radius: $radius-2xl;
  padding: 2.5rem;
  box-shadow: $shadow-glass;
  transition: all 0.4s cubic-bezier(0.22, 1, 0.36, 1);

  &.login-success {
    animation: successPulse 0.5s ease-out, cardExit 0.4s ease-in 0.3s forwards;
    border-color: rgba(34, 197, 94, 0.3);
  }

  &.login-error {
    animation: shake 0.5s ease-out, errorPulse 0.6s ease-out;
    border-color: rgba(239, 68, 68, 0.4);
  }

  @media (max-width: 640px) {
    padding: 2rem 1.5rem;
  }
}

/* ===== HEADER ===== */

.auth-header {
  text-align: center;
  margin-bottom: 2rem;

  .auth-icon {
    width: 72px;
    height: 72px;
    margin: 0 auto 1.5rem;
    background: $gradient-primary;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: $shadow-brand;

    .material-symbols-outlined {
      font-size: 36px;
      color: white;
    }
  }

  h1 {
    font-size: 1.75rem;
    font-weight: 800;
    color: $color-text-primary;
    margin-bottom: 0.5rem;
  }

  p {
    color: $color-text-secondary;
    font-size: 1rem;
    margin: 0;
  }
}

/* ===== FORM ===== */

.auth-form {
  display: grid;
  gap: 1.25rem;
}

.form-field {
  display: grid;
  gap: 0.5rem;

  label {
    font-weight: 600;
    color: $color-text-primary;
    font-size: 0.9375rem;
  }

  .field-hint {
    font-size: 0.875rem;
    color: $color-text-secondary;
    margin-top: -0.25rem;
  }

  &.has-error {
    .input-wrapper input {
      border-color: $color-error;
      box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.1);
    }
  }
}

/* Input Wrapper */
.input-wrapper {
  position: relative;

  .input-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: $color-text-secondary;
    font-size: 20px;
    pointer-events: none;
  }

  input {
    width: 100%;
    padding: 0.875rem 1rem;
    padding-left: 3rem;
    padding-right: 3rem;
    border: 2px solid $color-gray-200;
    border-radius: $radius-md;
    font-size: 0.9375rem;
    font-family: inherit;
    color: $color-text-primary;
    background: $color-white;
    transition: all 0.3s ease;

    &::placeholder {
      color: $color-gray-400;
    }

    &:focus {
      outline: none;
      border-color: $color-brand-primary;
      box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
    }

    &:disabled {
      background: $color-gray-100;
      color: $color-text-tertiary;
      cursor: not-allowed;
    }
  }

  .input-action {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: $radius-sm;
    color: $color-text-secondary;
    cursor: pointer;
    transition: all 0.2s ease;

    &:hover {
      background: $color-gray-100;
      color: $color-text-primary;
    }

    &:focus-visible {
      outline: none;
      box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
    }

    .material-symbols-outlined {
      font-size: 20px;
    }
  }
}

/* Error Text */
.error-text {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  color: $color-error;
  font-size: 0.875rem;
  font-weight: 500;

  .material-symbols-outlined {
    font-size: 16px;
  }
}

/* Alert */
.alert {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-radius: $radius-md;
  font-size: 0.9375rem;

  .material-symbols-outlined {
    font-size: 20px;
    flex-shrink: 0;
  }

  &--error {
    background: $color-error-light;
    border: 1px solid darken($color-error-light, 10%);
    color: darken($color-error, 10%);

    .material-symbols-outlined {
      color: $color-error;
    }
  }
}

/* Button */
.btn--large {
  width: 100%;
  margin-top: 0.5rem;
  padding: 1rem 1.5rem;
  font-size: 1rem;

  &.loading {
    pointer-events: none;
    opacity: 0.8;
  }
}

.loading-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== FOOTER ===== */

.auth-footer {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid $color-gray-200;
  text-align: center;

  p {
    color: $color-text-secondary;
    font-size: 0.9375rem;
    margin: 0;

    a {
      color: $color-brand-primary;
      text-decoration: none;
      font-weight: 600;
      transition: color 0.2s ease;

      &:hover {
        color: $color-brand-dark;
        text-decoration: underline;
      }

      &:focus-visible {
        outline: none;
        text-decoration: underline;
      }
    }
  }
}

/* ===== MOTION PREFERENCES ===== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}