/* Mobile-First Optimizations */

/* iOS Safari Autofill Background Fix */
/* Prevent autofill background in light mode */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
  -webkit-box-shadow: 0 0 0 30px white inset !important;
  -webkit-text-fill-color: #111827 !important;
}

/* Prevent autofill background in dark mode */
@media (prefers-color-scheme: dark) {
  input:-webkit-autofill,
  input:-webkit-autofill:hover,
  input:-webkit-autofill:focus,
  input:-webkit-autofill:active {
    -webkit-box-shadow: 0 0 0 30px #374151 inset !important;
    -webkit-text-fill-color: #f9fafb !important;
  }
}

/* Touch Target Sizes - Minimum 44x44px (WCAG AAA) */
.touch-target {
  min-height: 44px;
  min-width: 44px;
}

.touch-target-lg {
  min-height: 48px;
  min-width: 48px;
}

/* Mobile-optimized buttons */
.btn-mobile {
  padding: 12px 20px; /* Ensures 44px+ height */
  font-size: 16px; /* Prevents iOS zoom on focus */
  min-height: 44px;
  touch-action: manipulation; /* Prevents double-tap zoom */
}

.btn-mobile-sm {
  padding: 10px 16px;
  font-size: 14px;
  min-height: 44px;
}

.btn-mobile-icon {
  padding: 12px;
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Mobile input optimization */
.input-mobile {
  font-size: 16px; /* Prevents iOS zoom */
  padding: 12px;
  min-height: 44px;
}

/* Swipe-friendly list items */
.swipeable {
  position: relative;
  touch-action: pan-y; /* Allows vertical scroll, enables horizontal swipe */
  user-select: none;
}

.swipeable-actions {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  transform: translateX(100%);
  transition: transform 0.3s ease;
}

.swipeable.swiped .swipeable-actions {
  transform: translateX(0);
}

/* Mobile navigation improvements */
.mobile-nav-item {
  padding: 16px;
  min-height: 56px;
  display: flex;
  align-items: center;
  touch-action: manipulation;
}

.mobile-fab {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  touch-action: manipulation;
}

/* Camera integration styles */
.camera-capture {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
}

.camera-capture video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
  display: flex;
  justify-content: center;
  gap: 16px;
}

.camera-shutter {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: white;
  border: 4px solid #333;
  touch-action: manipulation;
  transition: transform 0.1s;
}

.camera-shutter:active {
  transform: scale(0.9);
}

/* QR Scanner overlay */
.qr-scanner-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-scanner-frame {
  width: 280px;
  height: 280px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 12px;
  position: relative;
}

.qr-scanner-corner {
  position: absolute;
  width: 40px;
  height: 40px;
  border: 3px solid #fff;
}

.qr-scanner-corner.top-left {
  top: -2px;
  left: -2px;
  border-right: none;
  border-bottom: none;
  border-top-left-radius: 12px;
}

.qr-scanner-corner.top-right {
  top: -2px;
  right: -2px;
  border-left: none;
  border-bottom: none;
  border-top-right-radius: 12px;
}

.qr-scanner-corner.bottom-left {
  bottom: -2px;
  left: -2px;
  border-right: none;
  border-top: none;
  border-bottom-left-radius: 12px;
}

.qr-scanner-corner.bottom-right {
  bottom: -2px;
  right: -2px;
  border-left: none;
  border-top: none;
  border-bottom-right-radius: 12px;
}

/* Mobile-specific spacing */
@media (max-width: 640px) {
  .mobile-p-safe {
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  }

  .mobile-pb-safe {
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }

  .mobile-pt-safe {
    padding-top: max(16px, env(safe-area-inset-top));
  }
}

/* Responsive header spacing */
@media (max-width: 1023px) {
  /* Ensure search inputs have proper spacing */
  .page-header input[type="search"] {
    font-size: 16px; /* Prevents iOS zoom */
  }

  /* Ensure header items wrap properly on very small screens */
  .page-header .flex {
    flex-wrap: wrap;
  }
}

/* Very small screens - stack header elements */
@media (max-width: 480px) {
  .page-header .flex {
    gap: 0.75rem;
  }
}

/* Pull-to-refresh indicator */
.ptr-indicator {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%) translateY(-100%);
  padding: 12px 24px;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  border-radius: 20px;
  font-size: 14px;
  transition: transform 0.3s;
  pointer-events: none;
}

.ptr-indicator.visible {
  transform: translateX(-50%) translateY(0);
}

/* Haptic feedback class (no visual change, for JS detection) */
.haptic-feedback {
  /* Marker class for JavaScript to add haptic feedback */
}

/* Prevent text selection on interactive elements */
.mobile-no-select {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* Smooth scrolling for mobile */
@media (max-width: 768px) {
  .mobile-scroll-smooth {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
  }
}

/* Bottom sheet for mobile modals */
.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
  transform: translateY(100%);
  transition: transform 0.3s ease-out;
  z-index: 1000;
  max-height: 90vh;
  overflow-y: auto;
}

@media (prefers-color-scheme: dark) {
  .bottom-sheet {
    background: #1f2937; /* gray-800 */
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
  }

  .bottom-sheet-handle {
    background: #4b5563; /* gray-600 */
  }
}

.bottom-sheet.active {
  transform: translateY(0);
}

.bottom-sheet-handle {
  width: 40px;
  height: 4px;
  background: #ddd;
  border-radius: 2px;
  margin: 12px auto;
}

.bottom-sheet-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  z-index: 999;
}

.bottom-sheet-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

/* Safe area for bottom bar on notched devices */
.safe-area-bottom {
  padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
}

/* Content padding to account for fixed bottom bar */
.mobile-bottom-padding {
  padding-bottom: 4.5rem;
}

@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .mobile-bottom-padding {
    padding-bottom: calc(4.5rem + env(safe-area-inset-bottom));
  }
}
