/**
 * SUPERPRECIO MOBILE OPTIMIZATIONS
 * Version: 1.0.0
 *
 * Mobile-first CSS optimizations for touch devices
 * - Touch target enforcement
 * - Sticky positioning utilities
 * - Bottom sheet enhancements
 * - Swipe gesture feedback
 * - Safe area insets for notched devices
 * - Landscape mode optimizations
 * - Lazy loading styles
 */

/* =============================================
   TOUCH TARGET ENFORCEMENT
   Minimum 44x44px for all interactive elements
   ============================================= */

button,
a,
input[type="button"],
input[type="submit"],
input[type="reset"],
.btn,
.dropdown-toggle,
.nav-link {
  min-height: 44px;
  min-width: 44px;
}

/* Exception for inline text links */
a:not(.btn):not(.dropdown-toggle):not(.nav-link) {
  min-height: auto;
  min-width: auto;
}

/* =============================================
   SAFE AREA INSETS - Support for notched devices
   iPhone X, 11, 12, 13, 14, 15, etc.
   ============================================= */

:root {
  /* Safe area environment variables */
  --safe-area-inset-top: env(safe-area-inset-top, 0px);
  --safe-area-inset-right: env(safe-area-inset-right, 0px);
  --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-inset-left: env(safe-area-inset-left, 0px);
}

body {
  /* Ensure content doesn't go under notches */
  padding-left: var(--safe-area-inset-left);
  padding-right: var(--safe-area-inset-right);
}

/* Fixed elements with safe areas */
.fixed-top {
  padding-top: max(8px, var(--safe-area-inset-top));
}

.fixed-bottom {
  padding-bottom: max(8px, var(--safe-area-inset-bottom));
}

/* =============================================
   STICKY POSITIONING UTILITIES
   ============================================= */

.sp-sticky-top {
  position: sticky;
  top: 0;
  z-index: var(--sp-z-sticky);
}

.sp-sticky-bottom {
  position: sticky;
  bottom: 0;
  z-index: var(--sp-z-sticky);
}

/* Sticky with offset (accounts for navbar) */
.sp-sticky-top-offset {
  position: sticky;
  top: 64px;
  z-index: calc(var(--sp-z-sticky) - 1);
}

@media (min-width: 768px) {
  .sp-sticky-top-offset {
    top: 72px;
  }
}

/* =============================================
   LAZY LOADING IMAGE STATES
   ============================================= */

[data-lazy-src] {
  background-color: var(--sp-color-surface-2);
  background-image: linear-gradient(
    90deg,
    var(--sp-color-surface-2) 0%,
    var(--sp-color-surface-3) 50%,
    var(--sp-color-surface-2) 100%
  );
  background-size: 200% 100%;
  animation: sp-shimmer 1.5s infinite;
}

.sp-lazy-loading {
  filter: blur(5px);
  transition: filter 0.3s ease;
}

.sp-lazy-loaded {
  filter: blur(0);
  animation: sp-fade-in 0.3s ease;
}

.sp-lazy-error {
  background-color: var(--sp-color-danger-light);
  background-image: none;
}

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

@keyframes sp-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* =============================================
   SWIPE GESTURE VISUAL FEEDBACK
   ============================================= */

.sp-swipeable {
  position: relative;
  touch-action: pan-y;
  user-select: none;
}

.sp-swipe-indicator {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: var(--sp-color-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--sp-transition-fast);
}

.sp-swipe-indicator--left {
  left: 16px;
}

.sp-swipe-indicator--right {
  right: 16px;
}

.sp-swipeable--swiping .sp-swipe-indicator {
  opacity: 1;
}

/* =============================================
   THUMB ZONE OPTIMIZATION
   Bottom 1/3 of screen is easiest to reach
   ============================================= */

@media (max-width: 767px) {
  /* Float important actions to bottom on mobile */
  .sp-thumb-zone {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: var(--sp-space-md);
    padding-bottom: max(var(--sp-space-md), var(--safe-area-inset-bottom));
    background: linear-gradient(
      to top,
      var(--sp-color-surface-base) 0%,
      var(--sp-color-surface-base) 80%,
      transparent 100%
    );
    z-index: var(--sp-z-sticky);
  }
}

/* =============================================
   LANDSCAPE MODE OPTIMIZATIONS
   Reduce vertical spacing when in landscape
   ============================================= */

@media (max-height: 500px) and (orientation: landscape) {
  /* Reduce header height in landscape */
  .sp-navbar {
    height: 52px !important;
    padding-top: var(--sp-space-xs) !important;
    padding-bottom: var(--sp-space-xs) !important;
  }

  body {
    padding-top: 52px !important;
  }

  /* Reduce vertical spacing */
  .sp-space-lg,
  .py-lg,
  .pt-lg,
  .pb-lg {
    padding-top: var(--sp-space-sm) !important;
    padding-bottom: var(--sp-space-sm) !important;
  }

  .sp-space-xl,
  .py-xl,
  .pt-xl,
  .pb-xl {
    padding-top: var(--sp-space-md) !important;
    padding-bottom: var(--sp-space-md) !important;
  }

  /* Compact bottom sheets in landscape */
  .sp-bottom-sheet {
    max-height: 80vh !important;
  }
}

/* =============================================
   GRID UTILITIES FOR PRODUCT CARDS
   Mobile-first responsive grid
   ============================================= */

.sp-product-grid {
  display: grid;
  gap: var(--sp-space-md);
  width: 100%;
}

/* Mobile: 2 columns (320px+) */
@media (min-width: 320px) {
  .sp-product-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--sp-space-sm);
  }
}

/* Small mobile: Still 2 columns but better spacing (375px+) */
@media (min-width: 375px) {
  .sp-product-grid {
    gap: var(--sp-space-md);
  }
}

/* Tablet: 3 columns (576px+) */
@media (min-width: 576px) {
  .sp-product-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Desktop: 4 columns (768px+) */
@media (min-width: 768px) {
  .sp-product-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: var(--sp-space-lg);
  }
}

/* Large desktop: 5 columns (1200px+) */
@media (min-width: 1200px) {
  .sp-product-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

/* Extra large: 6 columns (1400px+) */
@media (min-width: 1400px) {
  .sp-product-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

/* =============================================
   SCROLL IMPROVEMENTS
   Smooth scrolling and scroll snapping
   ============================================= */

html {
  scroll-behavior: smooth;
}

/* Disable smooth scroll if user prefers reduced motion */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

/* Horizontal scroll containers */
.sp-scroll-x {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scroll-snap-type: x mandatory;
}

.sp-scroll-x::-webkit-scrollbar {
  height: 6px;
}

.sp-scroll-x::-webkit-scrollbar-track {
  background: var(--sp-color-surface-2);
}

.sp-scroll-x::-webkit-scrollbar-thumb {
  background: var(--sp-color-border-medium);
  border-radius: var(--sp-radius-full);
}

/* Scroll snap children */
.sp-scroll-snap-item {
  scroll-snap-align: start;
  scroll-snap-stop: normal;
}

/* =============================================
   PREVENT TEXT SELECTION ON UI ELEMENTS
   ============================================= */

button,
.btn,
.sp-navbar,
.sp-product-card__price-badge,
.sp-market-card__badge {
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

/* =============================================
   TAP HIGHLIGHT COLOR
   Prevent default blue highlight on tap
   ============================================= */

button,
a,
.btn,
.dropdown-toggle {
  -webkit-tap-highlight-color: transparent;
  tap-highlight-color: transparent;
}

/* Custom tap feedback (optional) */
button:active,
.btn:active,
a:active {
  opacity: 0.8;
}

/* =============================================
   PULL-TO-REFRESH PREVENTION
   Prevent accidental pull-to-refresh on scrollable content
   ============================================= */

body {
  overscroll-behavior-y: contain;
}

.sp-bottom-sheet__content {
  overscroll-behavior: contain;
}

/* =============================================
   FOCUS VISIBLE IMPROVEMENTS
   Better keyboard navigation support
   ============================================= */

:focus {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--sp-color-border-focus);
  outline-offset: 2px;
  border-radius: var(--sp-radius-sm);
}

/* =============================================
   PRINT OPTIMIZATIONS
   ============================================= */

@media print {
  .sp-navbar,
  .sp-sticky-top,
  .sp-sticky-bottom,
  .sp-thumb-zone,
  .sp-bottom-sheet,
  .sp-bottom-sheet__backdrop {
    display: none !important;
  }

  body {
    padding-top: 0 !important;
  }

  .sp-product-grid {
    grid-template-columns: repeat(3, 1fr) !important;
  }
}

/* =============================================
   UTILITY CLASSES
   ============================================= */

/* Hide only on mobile */
@media (max-width: 767px) {
  .sp-hide-mobile {
    display: none !important;
  }
}

/* Show only on mobile */
@media (min-width: 768px) {
  .sp-show-mobile {
    display: none !important;
  }
}

/* Hide only on desktop */
@media (min-width: 768px) {
  .sp-hide-desktop {
    display: none !important;
  }
}

/* Show only on desktop */
@media (max-width: 767px) {
  .sp-show-desktop {
    display: none !important;
  }
}

/* Touch-friendly spacing */
.sp-touch-padding {
  padding: var(--sp-space-md);
}

.sp-touch-margin {
  margin: var(--sp-space-md);
}

/* Full-width on mobile */
.sp-full-width-mobile {
  width: 100%;
}

@media (min-width: 768px) {
  .sp-full-width-mobile {
    width: auto;
  }
}

/* Center content horizontally */
.sp-center-content {
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Aspect ratio utilities */
.sp-aspect-square {
  aspect-ratio: 1 / 1;
}

.sp-aspect-video {
  aspect-ratio: 16 / 9;
}

.sp-aspect-portrait {
  aspect-ratio: 3 / 4;
}

/* =============================================
   DEVICE-SPECIFIC CLASSES
   Added by mobile-interactions.js
   ============================================= */

.touch-device button:hover,
.touch-device .btn:hover,
.touch-device a:hover {
  /* Disable hover effects on touch devices */
  transform: none !important;
}

.no-touch button:hover,
.no-touch .btn:hover,
.no-touch a:hover {
  /* Enable hover effects on non-touch devices */
  cursor: pointer;
}

/* =============================================
   PERFORMANCE OPTIMIZATIONS
   ============================================= */

/* GPU acceleration for transforms */
.sp-navbar,
.sp-product-card,
.sp-market-card,
.sp-bottom-sheet {
  will-change: transform;
  transform: translateZ(0);
  backface-visibility: hidden;
}

/* Optimize images */
img {
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

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

/* Screen reader only content */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Skip links for keyboard navigation */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--sp-color-primary);
  color: white;
  padding: var(--sp-space-sm) var(--sp-space-md);
  text-decoration: none;
  border-radius: 0 0 var(--sp-radius-md) 0;
  z-index: 9999;
  transition: top var(--sp-transition-fast);
}

.skip-link:focus {
  top: 0;
}

/* =============================================
   HIGH CONTRAST MODE
   ============================================= */

@media (prefers-contrast: high) {
  button,
  .btn,
  a,
  input,
  select,
  textarea {
    border-width: 2px !important;
  }

  .sp-navbar {
    border-bottom: 3px solid var(--sp-color-border-dark);
  }
}

/* =============================================
   DARK MODE PREPARATION
   ============================================= */

@media (prefers-color-scheme: dark) {
  /* Dark mode adjustments for mobile */
  .sp-navbar {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  }

  [data-lazy-src] {
    background-color: var(--sp-color-surface-2);
  }
}
