/* ===== PWA SPECIFIC STYLES ===== */

/* Rilevamento modalità PWA */
@media (display-mode: standalone) {
  :root {
    --status-bar-height: env(safe-area-inset-top, 20px);
    --nav-height: env(safe-area-inset-bottom, 0px);
  }
  
  body {
    padding-top: var(--status-bar-height);
    padding-bottom: var(--nav-height);
  }
  
  /* Header adjustments per PWA */
  header {
    position: sticky;
    top: 0;
    background: rgba(26, 26, 26, 0.95);
    backdrop-filter: blur(10px);
    z-index: 1000;
    border-bottom: 1px solid #333;
  }
}

/* Stili per dispositivi iOS in PWA */
@media (display-mode: standalone) and (-webkit-device-pixel-ratio: 2) {
  body {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
  }
  
  /* Nascondi elementi di interfaccia Safari */
  input, textarea, select {
    -webkit-appearance: none;
    appearance: none;
  }
}

/* PWA Install Banner */
.pwa-install-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: linear-gradient(90deg, #8753b7, #c17fff);
  color: white;
  padding: 12px 16px;
  text-align: center;
  z-index: 10000;
  font-size: 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  animation: slideDown 0.3s ease-out;
}

.pwa-install-banner button {
  background: white;
  color: #8753b7;
  border: none;
  padding: 6px 16px;
  border-radius: 4px;
  font-weight: bold;
  cursor: pointer;
  margin: 0 4px;
  transition: transform 0.2s ease;
}

.pwa-install-banner button:hover {
  transform: scale(1.05);
}

.pwa-install-banner button.secondary {
  background: transparent;
  color: white;
  border: 1px solid white;
}

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

/* PWA Update notification */
.pwa-update-notification {
  position: fixed;
  bottom: 20px;
  left: 20px;
  right: 20px;
  background: rgba(26, 26, 26, 0.95);
  color: white;
  padding: 16px;
  border-radius: 12px;
  border: 1px solid #c17fff;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  z-index: 10000;
  display: flex;
  justify-content: space-between;
  align-items: center;
  animation: slideUp 0.3s ease-out;
}

.pwa-update-notification button {
  background: #c17fff;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
}

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

/* Offline indicator */
.offline-indicator {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: #ff4444;
  color: white;
  text-align: center;
  padding: 8px;
  font-size: 14px;
  z-index: 10001;
  animation: slideDown 0.3s ease-out;
}

.online-indicator {
  background: #22c55e;
  animation: slideDown 0.3s ease-out, fadeOut 2s ease-out 1s forwards;
}

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

/* PWA Splash Screen personalizzata per iOS */
@media (display-mode: standalone) and (orientation: portrait) {
  .pwa-splash {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(135deg, #111, #1a1a1a);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10002;
    opacity: 1;
    transition: opacity 0.5s ease-out;
  }
  
  .pwa-splash.hidden {
    opacity: 0;
    pointer-events: none;
  }
  
  .pwa-splash-logo {
    width: 120px;
    height: 120px;
    margin-bottom: 2rem;
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(193, 127, 255, 0.3);
  }
  
  .pwa-splash-title {
    color: #c17fff;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
  }
  
  .pwa-splash-subtitle {
    color: #aaa;
    font-size: 1rem;
    text-align: center;
    max-width: 280px;
  }
}

/* Miglioramenti touch per PWA */
.pwa-mode {
  touch-action: manipulation;
}

.pwa-mode button,
.pwa-mode .btn,
.pwa-mode a[role="button"] {
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(193, 127, 255, 0.3);
  tap-highlight-color: rgba(193, 127, 255, 0.3);
}

/* Nasconde elementi specifici del browser in PWA */
@media (display-mode: standalone) {
  .browser-only {
    display: none !important;
  }
  
  /* Aggiusta il layout senza barra indirizzo */
  #map {
    height: calc(100vh - 60px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  }
}

/* Stili per notifica installazione */
.install-prompt {
  position: fixed;
  bottom: 20px;
  left: 20px;
  right: 20px;
  background: rgba(26, 26, 26, 0.95);
  backdrop-filter: blur(10px);
  border: 1px solid #c17fff;
  border-radius: 12px;
  padding: 16px;
  color: white;
  z-index: 10000;
  animation: slideUp 0.4s ease-out;
}

.install-prompt-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.install-prompt-icon {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  flex-shrink: 0;
}

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

.install-prompt-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.install-prompt-description {
  font-size: 0.9rem;
  color: #aaa;
}

.install-prompt-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.install-prompt-actions button {
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.install-prompt-actions .primary {
  background: #c17fff;
  color: white;
  border: none;
}

.install-prompt-actions .primary:hover {
  background: #a855f7;
}

.install-prompt-actions .secondary {
  background: transparent;
  color: #aaa;
  border: 1px solid #444;
}

.install-prompt-actions .secondary:hover {
  color: white;
  border-color: #666;
}

/* Responsive per tablet in landscape */
@media (display-mode: standalone) and (orientation: landscape) and (min-width: 768px) {
  .install-prompt {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: 400px;
  }
  
  .pwa-install-banner {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: 500px;
    border-radius: 0 0 12px 12px;
  }
}

/* Loading states per PWA */
.pwa-loading {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: linear-gradient(90deg, transparent, #c17fff, transparent);
  background-size: 200% 100%;
  animation: loadingBar 1.5s ease-in-out infinite;
  z-index: 10001;
}

@keyframes loadingBar {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

/* Cache status indicator */
.cache-status {
  position: fixed;
  top: 10px;
  right: 10px;
  background: rgba(0,0,0,0.8);
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
  z-index: 10000;
  opacity: 0;
  transition: opacity 0.3s ease;
}

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

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

.cache-status.network {
  background: rgba(255, 68, 68, 0.8);
}

/* Miglioramenti accessibilità per PWA */
@media (prefers-reduced-motion: reduce) {
  .pwa-install-banner,
  .pwa-update-notification,
  .install-prompt,
  .offline-indicator,
  .online-indicator {
    animation: none;
  }
  
  .pwa-splash {
    transition: none;
  }
}

/* Dark mode specifico per PWA */
@media (prefers-color-scheme: dark) and (display-mode: standalone) {
  .pwa-splash {
    background: linear-gradient(135deg, #000, #111);
  }
}

/* Orientamento landscape per mobile PWA */
@media (display-mode: standalone) and (orientation: landscape) and (max-height: 500px) {
  header {
    padding: 0.5rem 1rem;
  }
  
  .header h1 {
    font-size: 1.2rem;
  }
  
  #map {
    height: calc(100vh - 50px - env(safe-area-inset-top, 0px));
  }
}

/* Fix per PWA su dispositivi con notch */
@media (display-mode: standalone) and (orientation: portrait) {
  .container {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
}

/* Styling per elementi quando la PWA è in background/foreground */
.pwa-mode.app-background {
  filter: brightness(0.8);
}

.pwa-mode.app-foreground {
  filter: brightness(1);
  transition: filter 0.3s ease;
}
