/* =============================================
   Mobile App Shell — Iteration 7
   PWA-optimised styles: bottom nav, pull-to-refresh,
   swipe gestures, image optimisation hints.
   ============================================= */

/* ── Bottom Navigation Bar ────────────────────────────────────────────
   Fixed bottom nav shown on screens < 992px.  Replaces the hamburger
   menu for a native-app feel.  Uses the same glassmorphism as the
   desktop navbar.
*/

.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1050;
  background: rgba(8, 10, 46, 0.92);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid rgba(139, 92, 246, 0.2);
  padding: 4px 0 env(safe-area-inset-bottom, 0);
  transition: transform 0.25s ease;
}

@media (max-width: 991.98px) {
  .mobile-bottom-nav {
    display: flex;
    justify-content: space-around;
    align-items: stretch;
  }

  /* Add padding at the bottom of the page so content isn't hidden */
  body {
    padding-bottom: 72px !important;
  }

  /* Hide the desktop navbar hamburger on mobile */
  .navbar-toggler {
    display: none !important;
  }

  /* Collapse the desktop navbar links on mobile */
  .navbar-collapse {
    display: none !important;
  }

  /* Slim down the top navbar on mobile */
  .glass-nav {
    padding-top: 8px !important;
    padding-bottom: 8px !important;
  }
}

.mobile-bottom-nav .mobile-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 2px;
  text-decoration: none;
  color: #8b89b8;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  min-height: 56px;
  transition: color 0.2s;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}

.mobile-nav-item i {
  font-size: 1.25rem;
  margin-bottom: 2px;
  transition: transform 0.2s;
}

.mobile-nav-item.active,
.mobile-nav-item:hover {
  color: #c4b5fd;
}

.mobile-nav-item.active i {
  color: #8b5cf6;
  transform: scale(1.1);
}

.mobile-nav-item.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 25%;
  right: 25%;
  height: 2px;
  background: linear-gradient(90deg, transparent, #8b5cf6, transparent);
  border-radius: 1px;
}

/* More menu popover */
.mobile-more-menu {
  display: none;
  position: fixed;
  bottom: 64px;
  left: 8px;
  right: 8px;
  z-index: 1051;
  background: rgba(14, 16, 72, 0.97);
  border: 1px solid rgba(139, 92, 246, 0.25);
  border-radius: 16px;
  padding: 12px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  max-height: 60vh;
  overflow-y: auto;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.5);
}

.mobile-more-menu.show {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.mobile-more-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 4px;
  border-radius: 10px;
  color: #8b89b8;
  text-decoration: none;
  font-size: 0.68rem;
  text-align: center;
  transition: background 0.2s;
}

.mobile-more-link i {
  font-size: 1.15rem;
  margin-bottom: 4px;
  color: #c4b5fd;
}

.mobile-more-link:hover,
.mobile-more-link:active {
  background: rgba(139, 92, 246, 0.12);
  color: #e0e0ff;
}

/* Overlay behind more menu */
.mobile-more-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1049;
  background: rgba(0, 0, 0, 0.5);
}

.mobile-more-overlay.show {
  display: block;
}


/* ── PWA Install Prompt ───────────────────────────────────────────────*/

.pwa-install-banner {
  display: none;
  position: fixed;
  bottom: 72px;
  left: 12px;
  right: 12px;
  z-index: 1048;
  background: linear-gradient(135deg, rgba(14, 16, 72, 0.97), rgba(30, 20, 80, 0.97));
  border: 1px solid rgba(139, 92, 246, 0.3);
  border-radius: 16px;
  padding: 16px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  animation: slideUp 0.35s ease-out;
}

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

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

.pwa-install-banner .pwa-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: linear-gradient(135deg, #8b5cf6, #7c3aed);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.pwa-install-banner .pwa-icon i {
  font-size: 1.3rem;
  color: #fff;
}

.pwa-install-banner .pwa-text {
  flex: 1;
}

.pwa-install-banner .pwa-text h6 {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 700;
  color: #f0f1ff;
}

.pwa-install-banner .pwa-text p {
  margin: 2px 0 0;
  font-size: 0.75rem;
  color: #8b89b8;
}

.pwa-install-banner .pwa-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.pwa-install-btn {
  background: linear-gradient(135deg, #8b5cf6, #7c3aed);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 8px 16px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 36px;
}

.pwa-dismiss-btn {
  background: transparent;
  color: #8b89b8;
  border: 1px solid rgba(139, 92, 246, 0.2);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.8rem;
  cursor: pointer;
  min-height: 36px;
}

@media (min-width: 992px) {
  .pwa-install-banner {
    max-width: 420px;
    left: auto;
    right: 20px;
    bottom: 20px;
  }
}


/* ── Pull-to-Refresh ──────────────────────────────────────────────────*/

.ptr-indicator {
  display: none;
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1052;
  width: 40px;
  height: 40px;
  background: rgba(14, 16, 72, 0.95);
  border: 1px solid rgba(139, 92, 246, 0.3);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  transition: top 0.15s ease;
  pointer-events: none;
}

.ptr-indicator.pulling {
  display: flex;
}

.ptr-indicator.refreshing {
  display: flex;
  top: 12px;
}

.ptr-indicator i {
  font-size: 1.1rem;
  color: #8b5cf6;
  transition: transform 0.2s;
}

.ptr-indicator.refreshing i {
  animation: ptrSpin 0.8s linear infinite;
}

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


/* ── View Transition Animations ───────────────────────────────────────*/

@view-transition {
  navigation: auto;
}

::view-transition-old(root) {
  animation: 0.2s ease-out both fadeSlideOut;
}

::view-transition-new(root) {
  animation: 0.2s ease-in both fadeSlideIn;
}

@keyframes fadeSlideOut {
  to {
    opacity: 0;
    transform: translateX(-8px);
  }
}

@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateX(8px);
  }
}


/* ── Responsive Image Optimisation Hints ──────────────────────────────*/

img.responsive-img {
  max-width: 100%;
  height: auto;
  object-fit: cover;
}

/* Skeleton placeholder while images load */
.img-skeleton {
  background: linear-gradient(90deg,
    rgba(139, 92, 246, 0.05) 25%,
    rgba(139, 92, 246, 0.12) 50%,
    rgba(139, 92, 246, 0.05) 75%);
  background-size: 200% 100%;
  animation: skeletonShimmer 1.5s infinite;
  border-radius: 8px;
}

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


/* ── Touch Feedback ───────────────────────────────────────────────────*/

@media (max-width: 991.98px) {
  .card,
  .btn,
  .dropdown-item,
  .nav-link,
  .mobile-nav-item {
    -webkit-tap-highlight-color: rgba(139, 92, 246, 0.15);
  }

  /* Swipe-back visual hint */
  .swipe-back-indicator {
    position: fixed;
    top: 50%;
    left: 0;
    transform: translateY(-50%) translateX(-100%);
    width: 32px;
    height: 64px;
    background: rgba(139, 92, 246, 0.3);
    border-radius: 0 16px 16px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease;
    z-index: 1048;
    pointer-events: none;
  }

  .swipe-back-indicator.visible {
    transform: translateY(-50%) translateX(0);
  }

  .swipe-back-indicator i {
    color: #fff;
    font-size: 0.9rem;
  }
}


/* ── Reduced Motion Override ──────────────────────────────────────────*/

@media (prefers-reduced-motion: reduce) {
  .pwa-install-banner {
    animation: none;
  }

  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation: none;
  }

  .img-skeleton {
    animation: none;
  }

  .ptr-indicator.refreshing i {
    animation: none;
  }
}


/* ── Light Theme Overrides ────────────────────────────────────────────*/

.light-theme .mobile-bottom-nav {
  background: rgba(255, 255, 255, 0.92);
  border-top-color: rgba(139, 92, 246, 0.15);
}

.light-theme .mobile-nav-item {
  color: #6b7280;
}

.light-theme .mobile-nav-item.active {
  color: #7c3aed;
}

.light-theme .mobile-nav-item.active i {
  color: #7c3aed;
}

.light-theme .mobile-more-menu {
  background: rgba(255, 255, 255, 0.97);
  border-color: rgba(139, 92, 246, 0.15);
}

.light-theme .mobile-more-link {
  color: #6b7280;
}

.light-theme .mobile-more-link i {
  color: #7c3aed;
}

.light-theme .pwa-install-banner {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.97), rgba(245, 243, 255, 0.97));
  border-color: rgba(139, 92, 246, 0.2);
}

.light-theme .pwa-install-banner .pwa-text h6 {
  color: #1f2937;
}

.light-theme .pwa-install-banner .pwa-text p {
  color: #6b7280;
}

.light-theme .ptr-indicator {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(139, 92, 246, 0.2);
}
