/**
 * PWA-specific styles for offline functionality and app-like experience
 */

/* PWA Installation and Offline States */
.pwa-enabled {
  /* PWA-specific optimizations */
}

.app-online {
  /* Online state styles */
}

.app-offline {
  /* Offline state styles */
  --offline-overlay: rgba(255, 165, 0, 0.1);
}

.app-offline::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--offline-overlay);
  pointer-events: none;
  z-index: 1;
}

/* Network Status Indicator */
#network-status-indicator {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1000;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.3s ease;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(8px);
}

#network-status-indicator.online {
  background-color: rgba(34, 197, 94, 0.9);
  color: white;
}

#network-status-indicator.offline {
  background-color: rgba(249, 115, 22, 0.9);
  color: white;
}

/* PWA Install Button */
#pwa-install-button {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translate(-50%, 100%);
  background: linear-gradient(135deg, #0ea5e9, #3b82f6);
  color: white;
  border: none;
  padding: 1rem 1.5rem;
  border-radius: 2rem;
  font-weight: 600;
  box-shadow: 0 10px 25px rgba(14, 165, 233, 0.3);
  transition: all 0.3s ease;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

#pwa-install-button:hover {
  background: linear-gradient(135deg, #0284c7, #2563eb);
  transform: translate(-50%, 0) scale(1.05);
  box-shadow: 0 15px 35px rgba(14, 165, 233, 0.4);
}

#pwa-install-button:active {
  transform: translate(-50%, 0) scale(0.95);
}

/* Update Notification */
.update-notification {
  position: fixed;
  bottom: 1rem;
  left: 1rem;
  right: 1rem;
  max-width: 24rem;
  margin: 0 auto;
  background: rgba(37, 99, 235, 0.95);
  color: white;
  padding: 1rem;
  border-radius: 0.75rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(8px);
  z-index: 1000;
  transform: translateY(100%);
  transition: transform 0.3s ease;
}

.update-notification.show {
  transform: translateY(0);
}

.update-notification .notification-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.update-notification .notification-text h4 {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.update-notification .notification-text p {
  font-size: 0.875rem;
  opacity: 0.9;
}

.update-notification .notification-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.update-notification button {
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

.update-notification .btn-refresh {
  background: white;
  color: #2563eb;
}

.update-notification .btn-refresh:hover {
  background: #f3f4f6;
}

.update-notification .btn-dismiss {
  background: transparent;
  color: white;
  opacity: 0.75;
}

.update-notification .btn-dismiss:hover {
  opacity: 1;
}

/* Offline Content Indicators */
.content-cached::after {
  content: '📱';
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  font-size: 0.75rem;
  opacity: 0.6;
}

.content-loading::after {
  content: '⏳';
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  font-size: 0.75rem;
  opacity: 0.6;
}

/* PWA Splash Screen Styles */
@media (display-mode: standalone) {
  body {
    /* App-like experience when installed */
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
  }
  
  /* Hide browser UI elements */
  #app {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
}

/* iOS PWA specific styles */
@media (display-mode: standalone) and (-webkit-min-device-pixel-ratio: 2) {
  /* iOS-specific PWA optimizations */
  body {
    -webkit-overflow-scrolling: touch;
  }
}

/* Android PWA specific styles */
@media (display-mode: standalone) and (orientation: portrait) {
  /* Android portrait optimizations */
}

@media (display-mode: standalone) and (orientation: landscape) {
  /* Android landscape optimizations */
}

/* Cache Status Indicators */
.cache-status {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.75rem;
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.cache-status.show {
  opacity: 1;
}

.cache-status.success {
  background: rgba(34, 197, 94, 0.9);
}

.cache-status.error {
  background: rgba(239, 68, 68, 0.9);
}

.cache-status.warning {
  background: rgba(249, 115, 22, 0.9);
}

/* Performance Optimizations for PWA */
.pwa-enabled * {
  /* Optimize for touch interactions */
  touch-action: manipulation;
}

.pwa-enabled img,
.pwa-enabled video {
  /* Optimize media loading */
  loading: lazy;
}

/* Reduced Motion Support for PWA */
@media (prefers-reduced-motion: reduce) {
  #pwa-install-button,
  .update-notification,
  #network-status-indicator {
    transition: none;
  }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
  #network-status-indicator,
  #pwa-install-button,
  .update-notification {
    border: 2px solid currentColor;
  }
}

/* Dark Mode Support for PWA Elements */
@media (prefers-color-scheme: dark) {
  .update-notification {
    background: rgba(17, 24, 39, 0.95);
    border: 1px solid rgba(75, 85, 99, 0.3);
  }
  
  #network-status-indicator {
    backdrop-filter: blur(8px) brightness(0.8);
  }
}

/* Focus Management for PWA */
.pwa-enabled button:focus,
.pwa-enabled [role="button"]:focus {
  outline: 2px solid #0ea5e9;
  outline-offset: 2px;
}

/* Loading States for Offline Content */
.offline-loading {
  position: relative;
  opacity: 0.7;
}

.offline-loading::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* PWA-specific responsive adjustments */
@media (max-width: 768px) {
  #pwa-install-button {
    bottom: 2rem;
    padding: 0.875rem 1.25rem;
    font-size: 0.875rem;
  }
  
  .update-notification {
    left: 0.5rem;
    right: 0.5rem;
    bottom: 0.5rem;
  }
  
  #network-status-indicator {
    top: 0.5rem;
    right: 0.5rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
  }
}

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

/* PWA Performance Indicators */
.performance-indicator {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, #0ea5e9, #3b82f6);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.3s ease;
  z-index: 1001;
}

.performance-indicator.loading {
  animation: progressBar 2s ease-in-out;
}

@keyframes progressBar {
  0% { transform: scaleX(0); }
  50% { transform: scaleX(0.7); }
  100% { transform: scaleX(1); }
}