/**
 * Micro-Interactions: Enhanced Form Focus and Skeleton Loaders
 */

/* ========================================
   ENHANCED FORM FOCUS ANIMATIONS
   ======================================== */

/* Base form control styles */
.form-control,
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
input[type="number"],
textarea,
select {
  position: relative;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border: 2px solid var(--color-border, rgba(146, 148, 159, 0.1));
}

/* Focus state with animated border and glow */
.form-control:focus,
input:focus,
textarea:focus,
select:focus {
  border-color: var(--color-accent, #3076FE);
  box-shadow: 
    0 0 0 3px rgba(var(--color-accent-rgb, 48, 118, 254), 0.1),
    0 4px 12px rgba(var(--color-accent-rgb, 48, 118, 254), 0.15);
  transform: translateY(-1px);
  outline: none;
}

/* Floating label animation */
.form-group {
  position: relative;
  margin-bottom: 24px;
}

.form-label-floating {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted, rgba(146, 148, 159, 0.6));
  font-size: 15px;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  background: var(--color-bg-primary, #0C0C0D);
  padding: 0 4px;
}

.form-control:focus ~ .form-label-floating,
.form-control:not([value=""]) ~ .form-label-floating,
.form-control.has-value ~ .form-label-floating {
  top: 0;
  font-size: 12px;
  color: var(--color-accent, #3076FE);
  font-weight: 600;
}

/* Animated underline effect */
.form-control-underline {
  border: none;
  border-bottom: 2px solid var(--color-border, rgba(146, 148, 159, 0.1));
  border-radius: 0;
  padding-left: 0;
  padding-right: 0;
  background: transparent;
  position: relative;
}

.form-control-underline::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--color-accent, #3076FE);
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.form-control-underline:focus::after {
  width: 100%;
}

/* Input with icon - animated icon */
.input-with-icon {
  position: relative;
}

.input-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted, rgba(146, 148, 159, 0.6));
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

.input-with-icon .form-control {
  padding-left: 44px;
}

.input-with-icon .form-control:focus ~ .input-icon {
  color: var(--color-accent, #3076FE);
  transform: translateY(-50%) scale(1.1);
}

/* Success/Error state animations */
.form-control.is-valid {
  border-color: var(--color-success, #27ae60);
  animation: validPulse 0.6s ease;
}

.form-control.is-invalid {
  border-color: var(--color-error, #e74c3c);
  animation: invalidShake 0.4s ease;
}

@keyframes validPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.01); }
}

@keyframes invalidShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* Checkbox and Radio animations */
.custom-checkbox,
.custom-radio {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.custom-checkbox input,
.custom-radio input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
}

.custom-checkbox .checkmark,
.custom-radio .checkmark {
  position: relative;
  height: 20px;
  width: 20px;
  border: 2px solid var(--color-border-strong, rgba(146, 148, 159, 0.2));
  border-radius: 4px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  margin-right: 10px;
}

.custom-radio .checkmark {
  border-radius: 50%;
}

.custom-checkbox:hover .checkmark,
.custom-radio:hover .checkmark {
  border-color: var(--color-accent, #3076FE);
  transform: scale(1.05);
}

.custom-checkbox input:checked ~ .checkmark,
.custom-radio input:checked ~ .checkmark {
  background-color: var(--color-accent, #3076FE);
  border-color: var(--color-accent, #3076FE);
  animation: checkboxPop 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes checkboxPop {
  0% { transform: scale(0.8); }
  50% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

/* Checkmark icon */
.custom-checkbox .checkmark::after {
  content: '';
  position: absolute;
  display: none;
  left: 5px;
  top: 2px;
  width: 5px;
  height: 9px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.custom-checkbox input:checked ~ .checkmark::after {
  display: block;
  animation: checkmarkDraw 0.3s ease 0.1s both;
}

@keyframes checkmarkDraw {
  0% { height: 0; }
  100% { height: 9px; }
}

.custom-radio .checkmark::after {
  content: '';
  position: absolute;
  display: none;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: white;
}

.custom-radio input:checked ~ .checkmark::after {
  display: block;
  animation: radioDot 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes radioDot {
  0% { transform: translate(-50%, -50%) scale(0); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

/* ========================================
   SKELETON LOADERS
   ======================================== */

/* Base skeleton */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-bg-secondary, #141516) 0%,
    var(--color-bg-tertiary, rgba(20, 21, 22, 0.5)) 50%,
    var(--color-bg-secondary, #141516) 100%
  );
  background-size: 200% 100%;
  animation: skeletonLoading 1.5s ease-in-out infinite;
  border-radius: 4px;
  position: relative;
  overflow: hidden;
}

@keyframes skeletonLoading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Skeleton shimmer effect */
.skeleton::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.05) 50%,
    transparent 100%
  );
  animation: skeletonShimmer 2s ease-in-out infinite;
}

@keyframes skeletonShimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* Skeleton variants */
.skeleton-text {
  height: 16px;
  margin-bottom: 8px;
  border-radius: 4px;
}

.skeleton-text--title {
  height: 24px;
  width: 60%;
  margin-bottom: 16px;
}

.skeleton-text--heading {
  height: 32px;
  width: 80%;
  margin-bottom: 20px;
}

.skeleton-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
}

.skeleton-avatar--large {
  width: 80px;
  height: 80px;
}

.skeleton-button {
  height: 44px;
  width: 120px;
  border-radius: 6px;
}

.skeleton-card {
  height: 200px;
  border-radius: 8px;
  margin-bottom: 16px;
}

/* Skeleton for slider */
.slider-skeleton {
  position: relative;
  width: 100%;
  height: 400px;
  border-radius: 8px;
  overflow: hidden;
}

.slider-skeleton-slide {
  display: flex;
  gap: 16px;
  padding: 16px;
}

.slider-skeleton-item {
  flex: 0 0 300px;
  height: 368px;
  border-radius: 8px;
}

/* Image skeleton with aspect ratio */
.skeleton-image {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%; /* 16:9 aspect ratio */
  border-radius: 8px;
  overflow: hidden;
}

.skeleton-image--square {
  padding-bottom: 100%; /* 1:1 aspect ratio */
}

.skeleton-image--portrait {
  padding-bottom: 133.33%; /* 3:4 aspect ratio */
}

/* Fade in animation when content loads */
@keyframes fadeInContent {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.content-loaded {
  animation: fadeInContent 0.4s ease-out;
}

/* Hide skeleton when content is loaded */
.skeleton-wrapper.loaded .skeleton {
  display: none;
}

.skeleton-wrapper.loaded .content-loaded {
  display: block;
}

/* ========================================
   BUTTON MICRO-INTERACTIONS
   ======================================== */

.btn,
button {
  position: relative;
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Ripple effect */
.btn::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
}

.btn:active::before {
  width: 300px;
  height: 300px;
  transition: width 0s, height 0s;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

.btn:active {
  transform: translateY(0);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

/* Loading state */
.btn-loading {
  pointer-events: none;
  position: relative;
  color: transparent !important;
}

.btn-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: buttonSpinner 0.6s linear infinite;
}

@keyframes buttonSpinner {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* ========================================
   RESPONSIVE & ACCESSIBILITY
   ======================================== */

@media (max-width: 768px) {
  .form-control:focus {
    transform: none;
  }

  .slider-skeleton {
    height: 300px;
  }

  .slider-skeleton-item {
    flex: 0 0 250px;
    height: 268px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Focus visible for keyboard navigation */
.form-control:focus-visible,
.btn:focus-visible,
.custom-checkbox:focus-visible .checkmark,
.custom-radio:focus-visible .checkmark {
  outline: 2px solid var(--color-accent, #3076FE);
  outline-offset: 2px;
}
