/* PWA Mobile Optimizations - inspired by Vite PWA best practices */

:root {
  /* Custom viewport height that works with PWA */
  --vh: 1vh;
  
  /* PWA safe area insets for devices with notches */
  --safe-area-inset-top: env(safe-area-inset-top, 0);
  --safe-area-inset-right: env(safe-area-inset-right, 0);
  --safe-area-inset-bottom: env(safe-area-inset-bottom, 0);
  --safe-area-inset-left: env(safe-area-inset-left, 0);
}

/* PWA Detection and Standalone Mode Styles */
@media all and (display-mode: standalone) {
  /* Styles only for PWA standalone mode */
  body {
    padding-top: var(--safe-area-inset-top);
    padding-bottom: var(--safe-area-inset-bottom);
    padding-left: var(--safe-area-inset-left);
    padding-right: var(--safe-area-inset-right);
  }
  
  /* Hide any browser-specific elements in PWA mode */
  .browser-only {
    display: none !important;
  }
  
  /* Enhanced fullscreen experience */
  html, body {
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
    overflow-x: hidden;
  }
}

/* Mobile-specific optimizations */
@media screen and (max-width: 768px) {
  /* Better touch targets */
  button, .btn, a[role="button"] {
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
  }
  
  /* Prevent zoom on form inputs */
  input, select, textarea {
    font-size: 16px; /* Prevents zoom on iOS */
    touch-action: manipulation;
  }
  
  /* Better scroll performance */
  * {
    -webkit-overflow-scrolling: touch;
  }
  
  /* Disable text selection where not needed */
  .no-select {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
  }
  
  /* Remove tap highlight */
  * {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
  }
  
  /* Better mobile typography */
  body {
    text-size-adjust: 100%;
    -webkit-text-size-adjust: 100%;
  }
}

/* PWA Status Indicator Base Styles */
#pwa-status {
  pointer-events: auto;
  transition: all 0.3s ease;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

#pwa-status:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

/* Install Button Styles */
#pwa-install-button {
  animation: slideInFromTop 0.3s ease-out;
}

@keyframes slideInFromTop {
  from {
    transform: translateY(-100px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* PWA Loading States */
.pwa-loading {
  position: relative;
  overflow: hidden;
}

.pwa-loading::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.2),
    transparent
  );
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { left: -100%; }
  100% { left: 100%; }
}

/* Offline Indicator */
.offline-indicator {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: #f39c12;
  color: white;
  text-align: center;
  padding: 8px;
  font-size: 14px;
  z-index: 10000;
  transform: translateY(-100%);
  transition: transform 0.3s ease;
}

.offline-indicator.show {
  transform: translateY(0);
}

/* Enhanced iOS Support */
@supports (-webkit-touch-callout: none) {
  /* iOS-specific styles */
  input {
    border-radius: 0; /* Remove iOS default styling */
  }
  
  /* Better iOS scroll behavior */
  body {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
  }
  
  /* iOS safe area handling */
  .ios-safe-top {
    padding-top: var(--safe-area-inset-top);
  }
  
  .ios-safe-bottom {
    padding-bottom: var(--safe-area-inset-bottom);
  }
}

/* Android-specific optimizations */
@media screen and (min-resolution: 2dppx) {
  /* High DPI Android devices */
  .high-dpi-optimized {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  #pwa-status {
    background-color: rgba(40, 40, 40, 0.95) !important;
    color: white !important;
    border-color: rgba(255, 255, 255, 0.1);
  }
  
  #pwa-install-button {
    background-color: #1a1a1a !important;
    border-color: rgba(255, 255, 255, 0.2);
  }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Utility classes for PWA development */
.pwa-hide-browser {
  display: block;
}

@media all and (display-mode: browser) {
  .pwa-hide-browser {
    display: none !important;
  }
}

.pwa-show-browser {
  display: none;
}

@media all and (display-mode: browser) {
  .pwa-show-browser {
    display: block !important;
  }
}

/* Better focus management for PWA */
:focus {
  outline: 2px solid #2c5aa0;
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

/* PWA specific animations */
.pwa-fade-in {
  animation: pwaFadeIn 0.3s ease-out;
}

@keyframes pwaFadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
