/**
 * Facebook Theme Elite PWA Stylesheet
 * Safe Area Insets, Native Ergonomics, Install Sheet, Offline UI
 */

/* 1. Native Ergonomics & Scroll Containment */
html.pwa-active,
body.pwa-active,
html.is-pwa-standalone,
body.is-pwa-standalone {
  overscroll-behavior-y: contain !important;
  -webkit-tap-highlight-color: transparent !important;
  touch-action: pan-x pan-y;
}

/* Eliminate tap delay & text selection on action controls */
.btn,
.action-btn,
.nav-link,
.fb-bottom-nav-item,
.fb-reel-circle-btn,
.reactions_item,
.fb-install-sheet-btn {
  -webkit-tap-highlight-color: transparent !important;
  user-select: none !important;
  -webkit-user-select: none !important;
}

/* 2. Safe Area Insets (Notch, Dynamic Island & Navigation Bar) */
@supports (padding-top: env(safe-area-inset-top)) {
  /* Standalone Header Safe Padding */
  body.is-pwa-standalone .main-header {
    padding-top: max(8px, env(safe-area-inset-top, 0px)) !important;
    min-height: calc(56px + env(safe-area-inset-top, 0px)) !important;
  }

  body.is-pwa-standalone .main-wrapper {
    padding-top: calc(56px + env(safe-area-inset-top, 0px)) !important;
  }

  /* Bottom Navigation Safe Padding */
  .fb-bottom-nav,
  .footer-bottom-bar,
  .pwa-bottom-sheet {
    padding-bottom: max(10px, env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Fullscreen Reels Safe Area */
  body.is-pwa-standalone .fb-reel-container {
    padding-top: env(safe-area-inset-top, 0px) !important;
    padding-bottom: env(safe-area-inset-bottom, 0px) !important;
  }
}

/* 3. Facebook-Style PWA Install Bottom Sheet / Modal */
.fb-pwa-install-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 999999;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.3s;
}

.fb-pwa-install-overlay.is-active {
  opacity: 1;
  visibility: visible;
}

.fb-pwa-install-sheet {
  background: #ffffff;
  width: 100%;
  max-width: 540px;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.25);
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  padding: 24px 20px max(24px, calc(16px + env(safe-area-inset-bottom, 0px)));
  position: relative;
  overflow: hidden;
}

@media (min-width: 768px) {
  .fb-pwa-install-overlay {
    align-items: center;
  }
  .fb-pwa-install-sheet {
    border-radius: 18px;
    padding: 24px 20px;
    transform: translateY(30px) scale(0.96);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.3);
  }
  .fb-pwa-install-overlay.is-active .fb-pwa-install-sheet {
    transform: translateY(0) scale(1);
  }
}

.fb-pwa-install-overlay.is-active .fb-pwa-install-sheet {
  transform: translateY(0);
}

/* Handlebar for dragging feel on mobile */
.fb-pwa-handle {
  width: 44px;
  height: 5px;
  background: #d8dadf;
  border-radius: 3px;
  margin: -8px auto 16px;
}

/* Header inside sheet */
.fb-pwa-sheet-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  position: relative;
}

.fb-pwa-app-icon {
  width: 68px;
  height: 68px;
  border-radius: 16px;
  box-shadow: 0 4px 14px rgba(24, 119, 242, 0.25);
  object-fit: cover;
  flex-shrink: 0;
  background: #1877f2;
}

.fb-pwa-sheet-meta {
  flex: 1;
  min-width: 0;
}

.fb-pwa-sheet-title {
  font-size: 19px;
  font-weight: 700;
  color: #050505;
  margin: 0 0 4px;
  line-height: 1.25;
}

.fb-pwa-sheet-subtitle {
  font-size: 13px;
  color: #65676b;
  margin: 0;
}

.fb-pwa-badge-verified {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #e7f3ff;
  color: #1877f2;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
  margin-top: 4px;
}

.fb-pwa-close-btn {
  position: absolute;
  top: -6px;
  inset-inline-end: -6px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #f0f2f5;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #65676b;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}

.fb-pwa-close-btn:hover {
  background: #e4e6eb;
  transform: scale(1.05);
}

/* Feature Perks List */
.fb-pwa-perks {
  list-style: none;
  padding: 0;
  margin: 16px 0 22px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.fb-pwa-perk-item {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: #050505;
}

.fb-pwa-perk-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #e7f3ff;
  color: #1877f2;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

/* Actions */
.fb-pwa-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.fb-pwa-install-btn {
  background: #1877f2;
  color: #ffffff;
  border: none;
  font-size: 16px;
  font-weight: 600;
  height: 48px;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.2s, transform 0.15s;
  box-shadow: 0 4px 12px rgba(24, 119, 242, 0.35);
}

.fb-pwa-install-btn:hover {
  background: #166fe5;
}

.fb-pwa-install-btn:active {
  transform: scale(0.98);
}

.fb-pwa-dismiss-btn {
  background: transparent;
  color: #65676b;
  border: none;
  font-size: 14px;
  font-weight: 500;
  height: 38px;
  border-radius: 10px;
  cursor: pointer;
}

.fb-pwa-dismiss-btn:hover {
  background: #f0f2f5;
  color: #050505;
}

/* iOS Safari Guided Steps Box */
.fb-pwa-ios-instructions {
  background: #f0f2f5;
  border-radius: 12px;
  padding: 14px 16px;
  margin-top: 14px;
  font-size: 13px;
  color: #050505;
  display: none;
  border-inline-start: 4px solid #1877f2;
}

.fb-pwa-ios-instructions.show {
  display: block;
}

.fb-pwa-ios-step {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.fb-pwa-ios-step:last-child {
  margin-bottom: 0;
}

.fb-pwa-ios-icon {
  color: #1877f2;
  font-size: 16px;
}

/* 4. Offline Toast Notification */
.fb-pwa-offline-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: rgba(36, 37, 38, 0.95);
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 24px;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  z-index: 999998;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s;
  pointer-events: none;
  opacity: 0;
}

.fb-pwa-offline-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.fb-pwa-offline-toast.online {
  background: rgba(46, 139, 87, 0.95);
}

/* 5. Dark Mode (Night Mode) Parity */
body.mode-night .fb-pwa-install-sheet {
  background: #242526;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.6);
}

body.mode-night .fb-pwa-handle {
  background: #3a3b3c;
}

body.mode-night .fb-pwa-sheet-title {
  color: #e4e6eb;
}

body.mode-night .fb-pwa-sheet-subtitle {
  color: #b0b3b8;
}

body.mode-night .fb-pwa-badge-verified {
  background: rgba(24, 119, 242, 0.2);
  color: #4599ff;
}

body.mode-night .fb-pwa-close-btn {
  background: #3a3b3c;
  color: #e4e6eb;
}

body.mode-night .fb-pwa-close-btn:hover {
  background: #4e4f50;
}

body.mode-night .fb-pwa-perk-item {
  color: #e4e6eb;
}

body.mode-night .fb-pwa-perk-icon {
  background: rgba(24, 119, 242, 0.2);
  color: #4599ff;
}

body.mode-night .fb-pwa-dismiss-btn {
  color: #b0b3b8;
}

body.mode-night .fb-pwa-dismiss-btn:hover {
  background: #3a3b3c;
  color: #e4e6eb;
}

body.mode-night .fb-pwa-ios-instructions {
  background: #18191a;
  color: #e4e6eb;
  border-inline-start-color: #4599ff;
}
