/**
 * Before/After Slider Component - RomaPaint
 * Interactive comparison slider for impermeabilización results
 * Mobile & Desktop optimized
 */

/* ============================================
   BEFORE/AFTER CONTAINER
   ============================================ */

.before-after-container {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: 1rem;
  box-shadow: 0 8px 32px rgba(155, 139, 126, 0.2);
  cursor: col-resize;
  user-select: none;
  -webkit-user-select: none;
  background: #1C1917;
}

@media (min-width: 768px) {
  .before-after-container {
    border-radius: 1.5rem;
  }
}

/* ============================================
   BEFORE IMAGE (Base Layer)
   ============================================ */

.ba-before {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.ba-before img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ============================================
   AFTER IMAGE (Top Layer with Clip)
   ============================================ */

.ba-after {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  clip-path: inset(0 50% 0 0);
  transition: clip-path 0.05s ease-out;
}

.ba-after img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ============================================
   SLIDER HANDLE (Vertical Line)
   ============================================ */

.ba-slider {
  position: absolute;
  top: 0;
  left: 50%;
  width: 4px;
  height: 100%;
  background: white;
  transform: translateX(-50%);
  z-index: 10;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
  transition: left 0.05s ease-out;
}

/* ============================================
   SLIDER HANDLE (Circle in Center)
   ============================================ */

.ba-slider::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 56px;
  height: 56px;
  background: white;
  border: 4px solid #D4A574;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 11;
}

@media (min-width: 768px) {
  .ba-slider::before {
    width: 64px;
    height: 64px;
  }
}

/* Arrows in handle */
.ba-slider::after {
  content: '⟷';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.5rem;
  font-weight: bold;
  color: #9B8B7E;
  z-index: 12;
  pointer-events: none;
}

/* ============================================
   LABELS (Antes/Después)
   ============================================ */

.ba-label {
  position: absolute;
  top: 1rem;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-weight: 700;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  z-index: 5;
}

@media (min-width: 768px) {
  .ba-label {
    padding: 0.625rem 1.25rem;
    font-size: 1rem;
  }
}

.ba-label-before {
  left: 1rem;
  background: rgba(212, 53, 28, 0.85);
}

.ba-label-after {
  right: 1rem;
  background: rgba(34, 197, 94, 0.85);
}

/* ============================================
   INTERACTION STATES
   ============================================ */

.before-after-container:active {
  cursor: col-resize;
}

.ba-slider:hover::before {
  border-color: #C39463;
  transform: translate(-50%, -50%) scale(1.1);
}

/* Mobile touch optimization */
@media (max-width: 767px) {
  .ba-slider::before {
    width: 64px;
    height: 64px;
  }

  .ba-slider {
    width: 6px;
  }
}

/* ============================================
   LOADING STATE
   ============================================ */

.before-after-container.loading {
  background: linear-gradient(
    90deg,
    #E7E5E4 0%,
    #F7F5F3 50%,
    #E7E5E4 100%
  );
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
}

@keyframes loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.before-after-container.loading .ba-before,
.before-after-container.loading .ba-after,
.before-after-container.loading .ba-slider {
  display: none;
}

/* ============================================
   INSTRUCTIONS (Show on first load)
   ============================================ */

.ba-instructions {
  position: absolute;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(10px);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 9999px;
  font-size: 0.875rem;
  font-weight: 600;
  z-index: 20;
  animation: fadeInUp 0.5s ease, fadeOut 0.5s ease 3s forwards;
  pointer-events: none;
}

@keyframes fadeOut {
  to {
    opacity: 0;
    visibility: hidden;
  }
}

.ba-instructions i {
  margin-right: 0.5rem;
}

/* Hide on mobile after interaction */
.before-after-container.interacted .ba-instructions {
  display: none;
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

/* Focus state for keyboard navigation */
.before-after-container:focus {
  outline: 3px solid #D4A574;
  outline-offset: 4px;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .ba-after,
  .ba-slider,
  .ba-slider::before {
    transition: none;
  }

  .ba-instructions {
    animation: none;
  }
}

/* High contrast mode */
@media (prefers-contrast: high) {
  .ba-slider {
    background: #000000;
    width: 6px;
  }

  .ba-slider::before {
    border-width: 6px;
    border-color: #000000;
  }

  .ba-label {
    background: rgba(0, 0, 0, 0.95);
    border: 2px solid white;
  }
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */

/* Tablet */
@media (min-width: 768px) and (max-width: 1023px) {
  .ba-label {
    font-size: 0.875rem;
    padding: 0.5rem 1rem;
  }
}

/* Large screens */
@media (min-width: 1024px) {
  .before-after-container {
    aspect-ratio: 16 / 10;
  }
}
