/**
 * Mind Bridge Institute — PWA Design System & Mobile App Experience
 * File: pwa.css
 * 
 * Provides:
 * - Safe area padding & notch handling for iOS & modern Android
 * - Mobile app touch ergonomics (active states, touch targets, overscroll)
 * - Branded Install MindBridge App modal & floating banner
 * - "New version available" update notification toast
 * - Real-time Network connection status toast (Online/Offline)
 * - Minimalist branded startup splash screen
 * - Reduced motion support & dark mode parity
 */

/* ============================================================
   1. GLOBAL MOBILE-FIRST APP FOUNDATIONS & SAFE AREAS
============================================================ */
:root {
  --mbi-safe-top: env(safe-area-inset-top);
  --mbi-safe-bottom: env(safe-area-inset-bottom);
  --mbi-safe-left: env(safe-area-inset-left);
  --mbi-safe-right: env(safe-area-inset-right);

  --pwa-gold-grad: linear-gradient(135deg, #FFE89D 0%, #D4AF37 50%, #B88E28 100%);
  --pwa-card-bg: rgba(14, 17, 24, 0.96);
  --pwa-border: rgba(212, 175, 55, 0.28);
}

/* Standalone App Body Tweaks */
@media all and (display-mode: standalone) {
  body {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }

  /* Allow text selection in inputs and notes */
  input, textarea, [contenteditable="true"], .selectable, .study-content, .note-text {
    -webkit-user-select: text;
    user-select: text;
  }
}

/* Safe area padding on fixed elements */
.dash-topbar,
.classroom-header,
header.dash-topbar {
  padding-top: max(12px, calc(12px + var(--mbi-safe-top))) !important;
  padding-left: max(16px, calc(16px + var(--mbi-safe-left))) !important;
  padding-right: max(16px, calc(16px + var(--mbi-safe-right))) !important;
}

.bottom-nav {
  padding-bottom: max(6px, calc(6px + var(--mbi-safe-bottom))) !important;
  padding-left: max(8px, calc(8px + var(--mbi-safe-left))) !important;
  padding-right: max(8px, calc(8px + var(--mbi-safe-right))) !important;
  height: calc(62px + var(--mbi-safe-bottom)) !important;
  box-sizing: border-box !important;
}

/* Prevent accidental pull-to-refresh reload in standalone app mode */
html, body {
  overscroll-behavior-y: contain;
  -webkit-tap-highlight-color: transparent;
}

/* ============================================================
   2. APP STARTUP SPLASH SCREEN (FAST & MINIMAL)
============================================================ */
.pwa-startup-splash {
  position: fixed;
  inset: 0;
  z-index: 999999;
  background: #08090C;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.35s ease;
  pointer-events: all;
  padding: env(safe-area-inset-top, 20px) 20px env(safe-area-inset-bottom, 20px);
}

.pwa-startup-splash.fade-out {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.pwa-splash-crest {
  width: 82px;
  height: 82px;
  border-radius: 20px;
  border: 2px solid #D4AF37;
  box-shadow: 0 0 30px rgba(212, 175, 55, 0.45);
  overflow: hidden;
  background: #000;
  animation: pwaPulseLogo 1.6s ease-in-out infinite;
}

.pwa-splash-crest img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.pwa-splash-title {
  font-family: 'Plus Jakarta Sans', -apple-system, sans-serif;
  font-size: 1.25rem;
  font-weight: 800;
  color: #FFFFFF;
  letter-spacing: -0.015em;
  margin: 0;
  text-align: center;
}

.pwa-splash-sub {
  font-size: 0.76rem;
  font-weight: 700;
  color: #D4AF37;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: -12px;
  text-align: center;
}

.pwa-splash-bar-wrap {
  width: 140px;
  height: 3px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
  margin-top: 10px;
}

.pwa-splash-bar {
  width: 45%;
  height: 100%;
  background: var(--pwa-gold-grad);
  border-radius: 999px;
  animation: pwaIndeterminate 1.2s ease-in-out infinite;
}

@keyframes pwaIndeterminate {
  0% { transform: translateX(-100%); }
  50% { transform: translateX(120%); }
  100% { transform: translateX(250%); }
}

@keyframes pwaPulseLogo {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 12px rgba(212, 175, 55, 0.35)); }
  50% { transform: scale(1.04); filter: drop-shadow(0 0 24px rgba(212, 175, 55, 0.65)); }
}

/* ============================================================
   3. CUSTOM INSTALL PROMPT MODAL & FLOATING BANNER
============================================================ */
.pwa-install-overlay {
  position: fixed;
  inset: 0;
  z-index: 99998;
  background: rgba(4, 5, 8, 0.78);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  padding-bottom: max(16px, calc(16px + var(--mbi-safe-bottom)));
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.28s ease, visibility 0.28s ease;
}

@media (min-width: 640px) {
  .pwa-install-overlay {
    align-items: center;
  }
}

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

.pwa-install-card {
  width: 100%;
  max-width: 440px;
  background: var(--pwa-card-bg);
  border: 1.5px solid var(--pwa-border);
  border-radius: 22px;
  padding: 24px 22px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.9), 0 0 32px rgba(212, 175, 55, 0.16);
  position: relative;
  overflow: hidden;
  transform: translateY(20px) scale(0.98);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.pwa-install-overlay.active .pwa-install-card {
  transform: translateY(0) scale(1);
}

.pwa-install-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; height: 3px;
  background: var(--pwa-gold-grad);
}

.pwa-install-close-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #94A3B8;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 1rem;
}

.pwa-install-close-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #FFFFFF;
}

.pwa-install-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.pwa-install-icon {
  width: 54px;
  height: 54px;
  border-radius: 14px;
  border: 1.5px solid #D4AF37;
  box-shadow: 0 0 16px rgba(212, 175, 55, 0.35);
  overflow: hidden;
  background: #000;
  flex-shrink: 0;
}

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

.pwa-install-headings h3 {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 1.15rem;
  font-weight: 800;
  color: #FFFFFF;
  margin: 0;
  line-height: 1.25;
}

.pwa-install-headings p {
  font-size: 0.78rem;
  color: #D4AF37;
  font-weight: 600;
  margin-top: 3px;
  letter-spacing: 0.02em;
}

.pwa-install-features {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 16px 0 20px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 12px 14px;
}

.pwa-feature-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
  color: #CBD2DE;
}

.pwa-feature-item svg {
  color: #D4AF37;
  flex-shrink: 0;
}

.pwa-install-actions {
  display: flex;
  gap: 10px;
}

.pwa-btn-install {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: 12px;
  background: var(--pwa-gold-grad);
  color: #000;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 0.92rem;
  font-weight: 800;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(212, 175, 55, 0.35);
  transition: transform 0.2s ease, filter 0.2s ease;
}

.pwa-btn-install:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.pwa-btn-later {
  padding: 12px 18px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #CBD2DE;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.pwa-btn-later:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #FFFFFF;
}

/* iOS Safari Instruction Pill */
.pwa-ios-instructions {
  background: rgba(212, 175, 55, 0.09);
  border: 1px dashed rgba(212, 175, 55, 0.3);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.82rem;
  color: #F8DF93;
  line-height: 1.5;
  margin-top: 12px;
  display: none;
}

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

/* ============================================================
   4. NEW VERSION UPDATE NOTIFICATION TOAST
============================================================ */
.pwa-update-toast {
  position: fixed;
  top: max(16px, calc(16px + var(--mbi-safe-top)));
  right: 16px;
  z-index: 99997;
  max-width: 380px;
  width: calc(100% - 32px);
  background: rgba(14, 17, 24, 0.96);
  border: 1.5px solid #D4AF37;
  border-radius: 14px;
  padding: 12px 16px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.75), 0 0 20px rgba(212, 175, 55, 0.25);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  transform: translateY(-80px);
  opacity: 0;
  visibility: hidden;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease, visibility 0.3s ease;
}

.pwa-update-toast.show {
  transform: translateY(0);
  opacity: 1;
  visibility: visible;
}

.pwa-update-content {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.pwa-update-icon {
  font-size: 1.3rem;
  flex-shrink: 0;
}

.pwa-update-text h4 {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 0.88rem;
  font-weight: 700;
  color: #FFFFFF;
  margin: 0;
}

.pwa-update-text p {
  font-size: 0.74rem;
  color: #94A3B8;
  margin: 1px 0 0;
}

.pwa-update-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.pwa-btn-update {
  background: var(--pwa-gold-grad);
  color: #000;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 0.78rem;
  font-weight: 800;
  border: none;
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  transition: transform 0.18s ease;
}

.pwa-btn-update:hover {
  transform: scale(1.04);
}

.pwa-btn-update-later {
  background: none;
  border: none;
  color: #94A3B8;
  font-size: 0.76rem;
  cursor: pointer;
  padding: 4px;
}

.pwa-btn-update-later:hover {
  color: #FFFFFF;
}

/* ============================================================
   5. REAL-TIME NETWORK STATUS TOAST (ONLINE / OFFLINE)
============================================================ */
.pwa-network-toast {
  position: fixed;
  bottom: calc(76px + var(--mbi-safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(40px);
  z-index: 99996;
  background: rgba(14, 17, 24, 0.94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-radius: 999px;
  padding: 8px 18px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.6);
  opacity: 0;
  visibility: hidden;
  transition: transform 0.28s ease, opacity 0.28s ease, visibility 0.28s ease;
  pointer-events: none;
  white-space: nowrap;
}

.pwa-network-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  visibility: visible;
}

.pwa-network-toast.offline {
  border: 1px solid rgba(239, 68, 68, 0.5);
  color: #FCA5A5;
}

.pwa-network-toast.online {
  border: 1px solid rgba(46, 204, 113, 0.5);
  color: #86EFAC;
}

.pwa-network-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

/* ============================================================
   6. REDUCED MOTION PREFERENCE
============================================================ */
@media (prefers-reduced-motion: reduce) {
  .pwa-startup-splash,
  .pwa-install-card,
  .pwa-update-toast,
  .pwa-network-toast,
  .pwa-splash-crest,
  .pwa-splash-bar {
    animation: none !important;
    transition: none !important;
  }
}
