/**
 * Framed Social - Mobile Enhancements CSS
 * Quick Wins + Phase 1 + Phase 2 Styles
 */

/* ============================================
   QUICK WIN 2: Skeleton Screens
   ============================================ */
.skeleton-loader {
  padding: var(--space-4);
  animation: fadeIn 0.3s ease;
}

.skeleton-item {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.05) 25%,
    rgba(255, 255, 255, 0.1) 50%,
    rgba(255, 255, 255, 0.05) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-md);
  margin-bottom: var(--space-3);
}

.skeleton-avatar {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
}

.skeleton-text {
  height: 16px;
  width: 100%;
}

.skeleton-text.short {
  width: 60%;
}

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

.fade-out {
  animation: fadeOut 0.3s ease forwards;
}

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

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

/* ============================================
   QUICK WIN 3: Touch Ripple Effects
   ============================================ */
.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  transform: scale(0);
  animation: ripple-animation 0.6s ease-out;
  pointer-events: none;
}

@keyframes ripple-animation {
  to {
    transform: scale(2);
    opacity: 0;
  }
}

/* Ensure parent elements can contain ripple */
.btn,
.card,
button,
a.btn-primary,
a.btn-secondary {
  position: relative;
  overflow: hidden;
}

/* ============================================
   QUICK WIN 4: Pull to Refresh
   ============================================ */
.pull-refresh-indicator {
  position: absolute;
  top: -60px;
  left: 0;
  right: 0;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  opacity: 0;
  transform: translateY(-100%);
  transition: all 0.3s ease;
  z-index: var(--z-sidebar);
}

.pull-refresh-indicator.refreshing {
  opacity: 1 !important;
  transform: translateY(60px) !important;
}

.refresh-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-color);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.refresh-text {
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ============================================
   QUICK WIN 5: Toast Notifications
   ============================================ */
.toast {
  position: fixed;
  bottom: calc(var(--space-4) + 60px); /* Above bottom nav */
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  box-shadow: var(--shadow-xl);
  z-index: var(--z-theme-popup);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  min-width: 280px;
  max-width: 90vw;
}

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

.toast-icon {
  font-size: var(--text-xl);
  font-weight: var(--font-bold);
}

.toast-message {
  flex: 1;
  font-size: var(--text-base);
}

.toast-success {
  background: #4CAF50;
  color: white;
}

.toast-error {
  background: #F44336;
  color: white;
}

.toast-warning {
  background: #FF9800;
  color: white;
}

.toast-info {
  background: var(--accent-primary);
  color: white;
}

@media (min-width: 768px) {
  .toast {
    bottom: var(--space-6);
    min-width: 320px;
  }
}

/* ============================================
   QUICK WIN 6: Floating Action Button (FAB)
   ============================================ */
.fab {
  position: fixed;
  bottom: calc(var(--space-4) + 70px); /* Above bottom nav */
  right: var(--space-4);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent-primary);
  color: white;
  border: none;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3), 0 2px 8px rgba(var(--accent-primary-rgb, 229, 57, 53), 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-dropdown);
  transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.fab:hover {
  transform: scale(1.1) rotate(90deg);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(var(--accent-primary-rgb, 229, 57, 53), 0.6);
}

.fab:active {
  transform: scale(0.95);
}

.fab-icon {
  font-size: 2em;
  font-weight: 300;
  line-height: 1;
}

.fab-hidden {
  transform: translateY(100px) scale(0.8);
  opacity: 0;
  pointer-events: none;
}

@media (min-width: 768px) {
  .fab {
    bottom: var(--space-6);
    right: var(--space-6);
    width: 64px;
    height: 64px;
  }
}

/* ============================================
   QUICK WIN 9: Loading Spinners
   ============================================ */
.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-8);
  animation: fadeIn 0.3s ease;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border-color);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.loading-message {
  margin-top: var(--space-3);
  color: var(--text-secondary);
  font-size: var(--text-base);
}

/* ============================================
   QUICK WIN 10: Scroll to Top Button
   ============================================ */
.scroll-to-top {
  position: fixed;
  bottom: calc(var(--space-4) + 70px);
  left: var(--space-4);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  color: var(--text-primary);
  font-size: var(--text-xl);
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  z-index: var(--z-nav-secondary);
  opacity: 0;
  transform: translateY(100px) scale(0.8);
  transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  pointer-events: none;
}

.scroll-to-top.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

.scroll-to-top:hover {
  background: var(--accent-primary);
  color: white;
  border-color: var(--accent-primary);
  transform: translateY(-4px) scale(1.05);
}

.scroll-to-top:active {
  transform: scale(0.95);
}

@media (min-width: 768px) {
  .scroll-to-top {
    bottom: var(--space-6);
    left: var(--space-6);
  }
}

/* ============================================
   PHASE 2: Swipe to Delete
   ============================================ */
.swipe-delete-btn {
  opacity: 0;
  transition: opacity 0.3s ease;
}

.notification-card,
.message-preview {
  touch-action: pan-y;
}

/* ============================================
   PHASE 2: Enhanced Mobile Navigation
   ============================================ */
.bottom-nav,
.mobile-nav {
  transition: transform 0.3s ease;
  position: sticky;
  bottom: 0;
  z-index: var(--z-sidebar);
}

.bottom-nav.nav-hidden,
.mobile-nav.nav-hidden {
  transform: translateY(100%);
}

.bottom-nav a.active,
.mobile-nav a.active {
  color: var(--accent-primary);
  font-weight: var(--font-bold);
}

.bottom-nav a.active::after,
.mobile-nav a.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 32px;
  height: 3px;
  background: var(--accent-primary);
  border-radius: var(--radius-full);
}

/* ============================================
   PHASE 1: Font Loading Optimization
   ============================================ */
body {
  font-display: swap;
}

body:not(.fonts-loaded) {
  opacity: 1;
}

.fonts-loaded {
  font-display: auto;
}

/* ============================================
   General Mobile Enhancements
   ============================================ */

/* Smooth scrolling */
html {
  scroll-behavior: smooth;
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  html {
    scroll-behavior: auto;
  }
}

/* Better tap highlighting */
* {
  -webkit-tap-highlight-color: rgba(var(--accent-primary-rgb, 229, 57, 53), 0.2);
}

/* Prevent text selection on buttons */
button,
.btn,
.fab {
  -webkit-user-select: none;
  user-select: none;
}

/* Better form inputs on mobile */
input,
textarea,
select {
  font-size: 16px; /* Prevent zoom on iOS */
}

/* Improve touch target sizes */
a,
button,
input,
select,
textarea {
  min-height: 44px;
  min-width: 44px;
}

/* Image optimization */
img[loading="lazy"] {
  opacity: 0;
  transition: opacity 0.3s ease;
}

img[loading="lazy"].loaded,
img[loading="lazy"]:not([data-src]) {
  opacity: 1;
}

/* Better modal behavior on mobile */
@media (max-width: 768px) {
  .modal-content,
  .modal {
    max-width: 100vw;
    max-height: 100vh;
    margin: 0;
    border-radius: 0;
  }
}

/* Safe area support for notched devices */
@supports (padding: max(0px)) {
  body {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
  }

  .bottom-nav,
  .mobile-nav {
    padding-bottom: max(var(--space-4), env(safe-area-inset-bottom));
  }

  .fab {
    bottom: calc(var(--space-4) + max(70px, env(safe-area-inset-bottom)));
  }
}

/* Better card interactions */
.card,
.post-card,
.win-card,
.event-card,
.group-card {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:active,
.post-card:active,
.win-card:active,
.event-card:active,
.group-card:active {
  transform: scale(0.98);
}

/* Loading states with pulse */
.loading {
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* Improved focus states for mobile */
@media (hover: none) {
  a:focus,
  button:focus,
  input:focus,
  select:focus,
  textarea:focus {
    outline: 3px solid var(--accent-primary);
    outline-offset: 2px;
  }
}

/* Better empty states */
.empty-state {
  animation: fadeIn 0.5s ease;
}

/* Skeleton card for grid layouts */
.skeleton-card {
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  animation: fadeIn 0.3s ease;
}

.skeleton-card .skeleton-item:first-child {
  width: 100%;
  height: 150px;
  margin-bottom: var(--space-3);
}

/* Optimistic UI feedback */
.optimistic {
  opacity: 0.6;
  pointer-events: none;
}

.optimistic::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 24px;
  height: 24px;
  border: 2px solid var(--border-color);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ============================================
   UNIVERSAL MOBILE FIXES - CONSOLIDATED
   Single source of truth for mobile optimizations
   Loads LAST to override all theme-specific CSS
   ============================================ */

/* ============================================
   MOBILE VIEWPORT FIXES (< 768px)
   ============================================ */
@media (max-width: 767.99px) {
    /* 1. RESET HTML & BODY - Remove conflicting heights and spacing */
    html,
    body {
        margin: 0;
        padding: 0;
        min-height: 0;
        height: auto;
        position: static;
        overflow-x: hidden;
    }

    /* 2. DISABLE DECORATIVE PSEUDO-ELEMENTS - Prevent spacing issues */
    body::before,
    body::after,
    html::before,
    html::after {
        display: none;
        content: none;
    }

    /* 3. FIX NAVIGATION POSITIONING - Fixed nav at top */
    body > nav,
    body > nav.main-nav,
    body > header,
    nav.main-nav,
    header.main-nav {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        width: 100%;
        margin: 0;
        padding: 0.5rem 0;
        z-index: var(--z-nav-primary);
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    }

    /* 4. ADD PADDING TO MAIN CONTENT - Account for fixed nav */
    body > #main-content,
    body > div#main-content,
    #main-content,
    main,
    .dashboard-container,
    .content-wrapper {
        margin-top: 0;
        padding-top: 60px;
    }

    /* 5. RESET INNER CONTENT SPACING */
    .main-content,
    .dashboard-container > *:first-child {
        margin-top: 0;
    }

    /* 6. FIX HERO SECTIONS - Account for fixed nav */
    .hero,
    .landing-hero,
    section.hero {
        margin-top: 0;
        padding-top: 70px;
    }

    /* 7. HIDE SKIP LINKS ON MOBILE */
    .skip-link,
    .skip-to-content {
        display: none;
    }

    /* 8. MOBILE MENU POSITIONING */
    body > .mobile-menu,
    .mobile-menu,
    .mobile-nav-menu {
        position: fixed;
        top: 0;
        right: 0;
        z-index: var(--z-mobile-menu);
    }

    /* 9. CONTAINER OPTIMIZATIONS */
    .container,
    .container-fluid {
        width: 100%;
        max-width: 100%;
        padding-left: 1rem;
        padding-right: 1rem;
        overflow-x: hidden;
    }

    /* 10. REDUCE PADDING ON PAGE CONTAINERS */
    .profile-container,
    .friends-container,
    .messages-container,
    .photos-container,
    .groups-container,
    .events-container,
    .wins-container,
    .achievements-container,
    .search-container,
    .shop-container,
    .notifications-container {
        padding: var(--space-2, 0.5rem) var(--space-3, 0.75rem);
    }

    /* 11. PREVENT HORIZONTAL SCROLL */
    img,
    video,
    iframe,
    svg {
        max-width: 100%;
        height: auto;
    }

    /* 12. FIX TABLES ON MOBILE */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* 13. MODAL/OVERLAY POSITIONING */
    .modal,
    .overlay,
    .popup {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: var(--z-modal);
    }
}

/* ============================================
   SMALL MOBILE (< 480px)
   ============================================ */
@media (max-width: 479px) {
    /* Reduce font sizes for very small screens */
    body {
        font-size: 14px;
    }

    h1 {
        font-size: 1.75rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    h3 {
        font-size: 1.25rem;
    }

    /* Tighter padding for very small screens */
    .container {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    .profile-container,
    .friends-container,
    .messages-container,
    .photos-container,
    .groups-container,
    .events-container,
    .wins-container,
    .achievements-container,
    .search-container,
    .shop-container,
    .notifications-container {
        padding: var(--space-1, 0.25rem) var(--space-2, 0.5rem);
    }
}

/* ============================================
   LANDSCAPE MOBILE (height < 500px)
   ============================================ */
@media (max-height: 500px) and (orientation: landscape) {
    /* Reduce header height in landscape */
    nav.main-nav,
    header.main-nav {
        padding: 0.25rem 0;
    }

    main,
    #main-content,
    .main-content {
        padding-top: 50px;
    }
}

/* ============================================
   SAFE AREA INSETS (for notched devices)
   ============================================ */
@supports (padding: env(safe-area-inset-top)) {
    @media (max-width: 767.99px) {
        nav.main-nav,
        header.main-nav {
            padding-top: calc(0.5rem + env(safe-area-inset-top));
        }

        main,
        #main-content,
        .main-content {
            padding-top: calc(60px + env(safe-area-inset-top));
        }

        .mobile-bottom-nav {
            padding-bottom: env(safe-area-inset-bottom);
        }
    }
}
