/* ==============================================================================
   Apex ERP - PWA Install Banner & Native Prompt System
   Compatible with Dark & Light Themes, Responsive Mobile & Desktop
   ============================================================================== */

:root {
  --pwa-bg: rgba(15, 23, 42, 0.94);
  --pwa-border: rgba(59, 130, 246, 0.35);
  --pwa-text: #f8fafc;
  --pwa-muted: #94a3b8;
  --pwa-btn-bg: #2563eb;
  --pwa-btn-hover: #1d4ed8;
  --pwa-btn-text: #ffffff;
  --pwa-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.5), 0 0 20px -3px rgba(37, 99, 235, 0.25);
}

[data-theme="light"], [data-theme="pearl"] {
  --pwa-bg: rgba(255, 255, 255, 0.96);
  --pwa-border: rgba(203, 213, 225, 0.9);
  --pwa-text: #0f172a;
  --pwa-muted: #64748b;
  --pwa-btn-bg: #2563eb;
  --pwa-btn-hover: #1d4ed8;
  --pwa-btn-text: #ffffff;
  --pwa-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.15), 0 0 15px rgba(37, 99, 235, 0.15);
}

/* Floating Bottom Install Prompt Banner */
.apex-pwa-banner {
  position: fixed;
  bottom: 24px;
  right: 24px;
  max-width: 440px;
  width: calc(100vw - 32px);
  z-index: 999999;
  background: var(--pwa-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--pwa-border);
  border-radius: 16px;
  padding: 16px 18px;
  box-shadow: var(--pwa-shadow);
  display: flex;
  align-items: center;
  gap: 14px;
  font-family: inherit;
  animation: apexPwaSlideUp 0.35s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

@keyframes apexPwaSlideUp {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.apex-pwa-banner.apex-pwa-hiding {
  opacity: 0;
  transform: translateY(20px) scale(0.96);
  pointer-events: none;
}

/* App Icon & Badge */
.apex-pwa-icon-wrap {
  position: relative;
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  overflow: hidden;
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.3);
}

.apex-pwa-icon-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.apex-pwa-badge {
  position: absolute;
  bottom: -2px;
  right: -2px;
  background: #10b981;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--pwa-bg);
}

/* Banner Content */
.apex-pwa-content {
  flex: 1;
  min-width: 0;
}

.apex-pwa-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--pwa-text);
  line-height: 1.3;
  margin: 0 0 2px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
}

.apex-pwa-desc {
  font-size: 12px;
  color: var(--pwa-muted);
  line-height: 1.35;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Action Buttons */
.apex-pwa-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.apex-pwa-install-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--pwa-btn-bg);
  color: var(--pwa-btn-text);
  border: none;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  box-shadow: 0 3px 8px rgba(37, 99, 235, 0.3);
}

.apex-pwa-install-btn:hover {
  background: var(--pwa-btn-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
}

.apex-pwa-install-btn:active {
  transform: translateY(0);
}

.apex-pwa-install-btn i {
  font-size: 15px;
}

.apex-pwa-close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: transparent;
  border: none;
  color: var(--pwa-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.apex-pwa-close-btn:hover {
  background: rgba(148, 163, 184, 0.15);
  color: var(--pwa-text);
}

/* Topbar / Header standalone install trigger button (subtle) */
.apex-header-pwa-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(37, 99, 235, 0.12);
  color: #3b82f6;
  border: 1px solid rgba(59, 130, 246, 0.25);
  cursor: pointer;
  transition: all 0.2s ease;
}

.apex-header-pwa-btn:hover {
  background: #2563eb;
  color: #ffffff;
  border-color: #2563eb;
}

/* iOS Safari Guide Sheet */
.apex-pwa-ios-modal {
  position: fixed;
  inset: 0;
  z-index: 1000000;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: apexFadeIn 0.25s ease;
}

.apex-pwa-ios-sheet {
  background: var(--pwa-bg);
  border: 1px solid var(--pwa-border);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 480px;
  padding: 24px 20px 32px 20px;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.4);
  animation: apexPwaSlideUp 0.3s ease;
  position: relative;
}

.apex-pwa-ios-steps {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 16px 0;
}

.apex-pwa-ios-step {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: var(--pwa-text);
}

.apex-pwa-ios-step i {
  font-size: 20px;
  color: #3b82f6;
  width: 28px;
  text-align: center;
}

@keyframes apexFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Mobile Adjustments */
@media (max-width: 640px) {
  .apex-pwa-banner {
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    left: 12px;
    right: 12px;
    width: auto;
    padding: 12px 14px;
    border-radius: 14px;
    gap: 10px;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.65), 0 0 15px rgba(37, 99, 235, 0.35);
  }

  /* If on a page with mobile-bottom-nav, push above it */
  body:has(.mobile-bottom-nav) .apex-pwa-banner {
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  }

  .apex-pwa-icon-wrap {
    width: 42px;
    height: 42px;
    border-radius: 10px;
  }

  .apex-pwa-title {
    font-size: 13px;
  }

  .apex-pwa-desc {
    font-size: 11px;
    -webkit-line-clamp: 1;
  }

  .apex-pwa-install-btn {
    padding: 7px 11px;
    font-size: 12px;
  }
}
