/**
 * CopyPaste.me PWA Styles
 * Install prompts, update notifications, and offline indicators
 */

/* =================================================================
   PWA Install Prompt
   ================================================================= */

.pwa-install-prompt {
  position: fixed;
  bottom: -200px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 500px;
  width: calc(100% - 32px);
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  padding: 16px;
  transition: bottom 0.3s ease-out;
  z-index: 10000;
  margin: 0 16px 16px;
}

.pwa-install-prompt.show {
  bottom: 16px;
}

.pwa-install-content {
  display: flex;
  align-items: center;
  gap: 16px;
}

.pwa-install-icon img {
  border-radius: 8px;
}

.pwa-install-text {
  flex: 1;
}

.pwa-install-title {
  font-weight: 600;
  font-size: 16px;
  color: #333;
  margin-bottom: 4px;
}

.pwa-install-subtitle {
  font-size: 14px;
  color: #666;
}

.pwa-install-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 100px;
}

#pwa-install-btn {
  background: #63a9e1;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  font-size: 14px;
}

#pwa-install-btn:hover {
  background: #5098d0;
}

#pwa-dismiss-btn {
  background: transparent;
  color: #666;
  border: none;
  padding: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: color 0.2s;
}

#pwa-dismiss-btn:hover {
  color: #333;
}

/* Mobile layout for install prompt */
@media (max-width: 600px) {
  .pwa-install-content {
    flex-direction: column;
    text-align: center;
  }
  
  .pwa-install-actions {
    width: 100%;
  }
  
  #pwa-install-btn {
    width: 100%;
  }
}

/* =================================================================
   PWA Update Notification
   ================================================================= */

.pwa-update-notification {
  position: fixed;
  top: -100px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 400px;
  width: calc(100% - 32px);
  background: #2c3e50;
  color: white;
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  transition: top 0.3s ease-out;
  z-index: 10001;
  margin: 0 16px;
}

.pwa-update-notification.show {
  top: 16px;
}

.pwa-update-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.pwa-update-text {
  flex: 1;
}

.pwa-update-text strong {
  display: block;
  font-size: 15px;
  margin-bottom: 4px;
}

.pwa-update-text span {
  font-size: 13px;
  opacity: 0.9;
}

#pwa-update-btn {
  background: #63a9e1;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  font-size: 13px;
  white-space: nowrap;
}

#pwa-update-btn:hover {
  background: #5098d0;
}

/* =================================================================
   Offline Indicator
   ================================================================= */

.pwa-offline-indicator {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: #e74c3c;
  color: white;
  text-align: center;
  padding: 8px;
  font-size: 14px;
  font-weight: 500;
  z-index: 9999;
  transform: translateY(-100%);
  transition: transform 0.3s ease;
}

body.pwa-offline .pwa-offline-indicator {
  transform: translateY(0);
}

.pwa-offline-indicator::before {
  content: '⚠️ ';
  margin-right: 8px;
}

/* Online indicator (subtle animation) */
.pwa-online-indicator {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: #27ae60;
  color: white;
  text-align: center;
  padding: 8px;
  font-size: 14px;
  font-weight: 500;
  z-index: 9999;
  transform: translateY(-100%);
  transition: transform 0.3s ease;
}

body.pwa-online .pwa-online-indicator {
  transform: translateY(0);
  animation: slide-down-fade 3s ease-out forwards;
}

@keyframes slide-down-fade {
  0% {
    transform: translateY(-100%);
    opacity: 0;
  }
  10% {
    transform: translateY(0);
    opacity: 1;
  }
  90% {
    transform: translateY(0);
    opacity: 1;
  }
  100% {
    transform: translateY(-100%);
    opacity: 0;
  }
}

/* =================================================================
   Standalone Mode Adjustments
   ================================================================= */

/* Add safe area insets for notched devices */
body.pwa-standalone {
  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);
}

/* Hide elements that are browser-specific when in standalone */
body.pwa-standalone .browser-only {
  display: none !important;
}

/* Prevent pull-to-refresh bounce effect on iOS */
body.pwa-standalone {
  overscroll-behavior-y: contain;
}

/* =================================================================
   Loading Spinner for PWA
   ================================================================= */

.pwa-loading {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 9998;
}

.pwa-loading-spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(99, 169, 225, 0.2);
  border-top-color: #63a9e1;
  border-radius: 50%;
  animation: pwa-spin 0.8s linear infinite;
}

@keyframes pwa-spin {
  to { transform: rotate(360deg); }
}

/* =================================================================
   iOS Specific Fixes
   ================================================================= */

/* Fix viewport issues on iOS */
@supports (-webkit-touch-callout: none) {
  body.pwa-standalone {
    min-height: -webkit-fill-available;
  }
}

/* Disable text selection on buttons in iOS */
.pwa-install-prompt button,
.pwa-update-notification button {
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* =================================================================
   Dark Mode Support (Optional)
   ================================================================= */

@media (prefers-color-scheme: dark) {
  .pwa-install-prompt {
    background: #2c3e50;
    color: white;
  }
  
  .pwa-install-title {
    color: white;
  }
  
  .pwa-install-subtitle {
    color: #bdc3c7;
  }
  
  #pwa-dismiss-btn {
    color: #bdc3c7;
  }
  
  #pwa-dismiss-btn:hover {
    color: white;
  }
}

/* =================================================================
   Accessibility
   ================================================================= */

/* Focus styles for keyboard navigation */
#pwa-install-btn:focus,
#pwa-update-btn:focus,
#pwa-dismiss-btn:focus {
  outline: 2px solid #63a9e1;
  outline-offset: 2px;
}

/* Reduced motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  .pwa-install-prompt,
  .pwa-update-notification,
  .pwa-offline-indicator,
  .pwa-online-indicator {
    transition: none;
  }
  
  .pwa-loading-spinner {
    animation: none;
    border-top-color: transparent;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .pwa-install-prompt,
  .pwa-update-notification {
    border: 2px solid currentColor;
  }
  
  #pwa-install-btn,
  #pwa-update-btn {
    border: 2px solid white;
  }
}
