/**
 * SmileSlot PWA Loading Animations & Styling
 * Branded loading spinner, notifications, and app UI enhancements
 */

/* Loading Screen Styling */
#app-loader {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: none !important;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1.5rem;
  padding: max(2rem, env(safe-area-inset-top)) 1.5rem max(2rem, env(safe-area-inset-bottom));
  z-index: 9999;
  opacity: 1;
  transition: opacity 0.4s ease-out, visibility 0.4s ease-out;
  visibility: visible;
}

#app-loader.hide {
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
}

/* Loader Container */
.pwa-loader-container {
  text-align: center;
  animation: slideInLoader 0.5s ease-out;
}

@keyframes slideInLoader {
  from {
    opacity: 0;
    transform: translateY(-30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Logo Spinner */
.pwa-logo-spinner {
  width: 96px;
  height: 96px;
  margin: 0 auto 18px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Spinning circle background */
.pwa-spinner-circle {
  position: absolute;
  width: 100%;
  height: 100%;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top: 3px solid rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  animation: rotateSpinner 2.5s linear infinite;
}

@keyframes rotateSpinner {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* Tooth icon */
.pwa-tooth-icon {
  width: 50%;
  height: 50%;
  position: relative;
  z-index: 2;
  filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.2));
}

/* Brand Name */
.pwa-brand-name {
  font-size: 26px;
  font-weight: 800;
  color: white;
  margin: 0 0 8px 0;
  letter-spacing: 0.5px;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Loading Status Text */
.pwa-loading-status {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.9);
  margin: 0;
  font-weight: 500;
  animation: pulseText 2s ease-in-out infinite;
  letter-spacing: 0.3px;
}

@keyframes pulseText {
  0%, 100% {
    opacity: 0.7;
  }
  50% {
    opacity: 1;
  }
}

/* Progress Bar */
.pwa-progress-bar {
  width: min(220px, 70vw);
  height: 3px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  margin: 0 auto;
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}

@media (prefers-reduced-motion: reduce) {
  #app-loader *,
  #app-loader {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

.pwa-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.8) 0%, white 50%, rgba(255, 255, 255, 0.8) 100%);
  border-radius: 10px;
  width: 30%;
  animation: progressAnimation 2.5s ease-in-out infinite;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

@keyframes progressAnimation {
  0% {
    width: 10%;
    opacity: 0.5;
  }
  50% {
    width: 70%;
    opacity: 1;
  }
  100% {
    width: 90%;
    opacity: 0.5;
  }
}

/* Pulsing dot indicator */
.pwa-pulse-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: white;
  border-radius: 50%;
  animation: pulseDot 1.2s ease-in-out infinite;
  margin-left: 4px;
}

@keyframes pulseDot {
  0%, 100% {
    transform: scale(0.8);
    opacity: 0.4;
  }
  50% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ============================================
   PWA Notification Styling (System Native)
   ============================================ */

/* Notification banner for connectivity status */
#pwa-connectivity-banner {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
  from {
    transform: translateY(-100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Offline state banner */
#pwa-connectivity-banner.offline {
  background: linear-gradient(135deg, #f24d56 0%, #e63946 100%);
  color: white;
}

/* Online state banner */
#pwa-connectivity-banner.online {
  background: linear-gradient(135deg, #2dce89 0%, #11cdef 100%);
  color: white;
}

/* Update notification banner */
#pwa-update-banner {
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ============================================
   PWA Offline Alert Styling
   ============================================ */

.pwa-offline-alert {
  background: linear-gradient(135deg, rgba(241, 90, 97, 0.1) 0%, rgba(230, 57, 70, 0.1) 100%) !important;
  border-left: 4px solid #f24d56 !important;
  border-radius: 8px !important;
  color: #333 !important;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideInAlert 0.4s ease-out;
}

@keyframes slideInAlert {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.pwa-offline-alert i {
  color: #f24d56;
  font-size: 18px;
}

/* ============================================
   Page Transition Styling
   ============================================ */

.pwa-transitioning {
  transition: opacity 0.3s ease-out !important;
}

/* ============================================
   Safe Area & Status Bar
   ============================================ */

:root {
  --status-bar-height: env(safe-area-inset-top);
  --status-bar-left: env(safe-area-inset-left);
  --status-bar-right: env(safe-area-inset-right);
  --status-bar-bottom: env(safe-area-inset-bottom);
}

/* Apply safe area padding for notched devices */
@supports (padding: max(0px)) {
  body {
    padding-top: max(var(--status-bar-height), 0px);
    padding-left: max(var(--status-bar-left), 0px);
    padding-right: max(var(--status-bar-right), 0px);
  }
}

/* Responsive Design */
@media (max-width: 768px) {
  .pwa-loader-container {
    padding: 20px;
  }

  .pwa-logo-spinner {
    width: 110px;
    height: 110px;
    margin-bottom: 30px;
  }

  .pwa-brand-name {
    font-size: 28px;
  }

  .pwa-loading-status {
    font-size: 14px;
  }

  .pwa-progress-bar {
    width: 180px;
  }
}

@media (max-width: 480px) {
  .pwa-loader-container {
    padding: 15px;
  }

  .pwa-logo-spinner {
    width: 90px;
    height: 90px;
    margin-bottom: 25px;
  }

  .pwa-brand-name {
    font-size: 24px;
  }

  .pwa-loading-status {
    font-size: 13px;
  }

  .pwa-progress-bar {
    width: 160px;
    height: 3px;
  }

  #pwa-connectivity-banner {
    font-size: 14px;
    padding: 8px 12px;
  }

  #pwa-update-banner {
    margin: 10px;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  #app-loader {
    background: transparent;
  }

  .pwa-offline-alert {
    background: linear-gradient(135deg, rgba(241, 90, 97, 0.15) 0%, rgba(230, 57, 70, 0.15) 100%) !important;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  #app-loader,
  .pwa-loader-container,
  .pwa-spinner-circle,
  .pwa-loading-status,
  .pwa-progress-fill,
  #pwa-connectivity-banner,
  .pwa-offline-alert {
    animation: none !important;
  }

  .pwa-spinner-circle {
    border-top: 3px solid white;
    opacity: 0.7;
  }
}
