/* =========================================================
   Splashes — Mobile-Native Enhancements
   Add to every page: <link rel="stylesheet" href="css/mobile.css">
   ========================================================= */

/* =========================================================
   1. Safe Area Support (Notch / Dynamic Island)
   ========================================================= */

/* Safe area insets are now handled by responsive.css (loaded last) */

/* =========================================================
   2. iOS Momentum Scrolling & Touch Optimizations
   ========================================================= */

#main-content,
#side-nav,
#mobile-nav {
  -webkit-overflow-scrolling: touch;
}

#mobile-drawer,
#mobile-drawer-overlay {
  display: none;
}

* {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

input, textarea, select, button {
  -webkit-appearance: none;
  appearance: none;
  font-size: 16px; /* Prevents iOS zoom on focus */
}

/* =========================================================
   3. Pull-to-Refresh Indicator
   ========================================================= */

#ptr-indicator {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 95;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 0;
  overflow: hidden;
  transition: height 0.2s ease;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
}

#ptr-indicator.active {
  height: 50px;
}

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

#ptr-indicator .ptr-text {
  margin-left: 8px;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* =========================================================
   4. Offline Banner
   ========================================================= */

#offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 999;
  background: var(--warning);
  color: var(--text-inverse);
  text-align: center;
  padding: 8px 16px;
  font-size: 0.875rem;
  font-weight: 500;
  transform: translateY(-100%);
  transition: transform 0.3s ease;
}

#offline-banner.show {
  transform: translateY(0);
}

@supports (padding-top: env(safe-area-inset-top)) {
  #offline-banner {
    padding-top: calc(8px + env(safe-area-inset-top));
  }
}

/* =========================================================
   5. PWA Install Prompt (In-App)
   ========================================================= */

#pwa-install-banner {
  position: fixed;
  bottom: calc(var(--bottom-nav-height, 60px) + 12px + env(safe-area-inset-bottom, 0px));
  left: 16px;
  right: 16px;
  z-index: 999;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-lg);
  display: none;
  animation: slideUp 0.3s ease;
}

#pwa-install-banner.show {
  display: block;
}

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

#pwa-install-banner .install-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

#pwa-install-banner .install-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  object-fit: cover;
}

#pwa-install-banner .install-title {
  font-weight: 600;
  font-size: 1rem;
}

#pwa-install-banner .install-subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

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

#pwa-install-banner .install-actions button {
  flex: 1;
}

/* =========================================================
   6. Page Transition Animations
   ========================================================= */

.page-transition-enter {
  animation: pageIn 0.25s ease-out;
}

@keyframes pageIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Card entrance animation */
.post-card-modern,
.post-card {
  animation: cardEnter 0.3s ease-out;
  animation-fill-mode: both;
}

.post-card-modern:nth-child(1),
.post-card:nth-child(1) { animation-delay: 0ms; }
.post-card-modern:nth-child(2),
.post-card:nth-child(2) { animation-delay: 40ms; }
.post-card-modern:nth-child(3),
.post-card:nth-child(3) { animation-delay: 80ms; }
.post-card-modern:nth-child(4),
.post-card:nth-child(4) { animation-delay: 120ms; }
.post-card-modern:nth-child(5),
.post-card:nth-child(5) { animation-delay: 160ms; }

@keyframes cardEnter {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* =========================================================
   7. Active State Optimizations (Touch)
   ========================================================= */

@media (hover: none) {
  .btn-primary:active {
    transform: scale(0.97);
    opacity: 0.9;
  }

  .post-card-modern:active,
  .post-card:active {
    transform: scale(0.99);
    background: var(--bg-surface-2);
  }

  .bottom-nav-item:active {
    transform: scale(0.92);
  }

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

/* =========================================================
   8. Bottom Sheet Modal (Mobile)
   ========================================================= */

.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 300;
  background: var(--bg-surface);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 -8px 32px rgba(0,0,0,0.3);
}

.bottom-sheet.open {
  transform: translateY(0);
}

.bottom-sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border-color);
  border-radius: 2px;
  margin: 0 auto 16px;
}

/* =========================================================
   9. Haptic-Friendly Touch Targets
   ========================================================= */

@media (max-width: 640px) {
  .post-action {
    min-height: 44px;
    min-width: 44px;
    justify-content: center;
  }

  .pill {
    min-height: 36px;
  }

  .bottom-nav-item {
    min-width: 56px;
  }

  .header-btn {
    min-width: 44px;
    min-height: 44px;
  }
}

/* =========================================================
   10. Reduced Motion Support
   ========================================================= */

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

/* =========================================================
   11. Standalone PWA Optimizations
   ========================================================= */

@media (display-mode: standalone) {
  body {
    /* Prevent overscroll bounce on iOS */
    overscroll-behavior-y: none;
  }

  #main-header {
    /* Slightly smaller header in standalone mode */
    height: calc(56px + env(safe-area-inset-top, 0px));
  }

  #brand-name {
    font-size: 1.125rem;
  }
}

/* =========================================================
   12. Swipe Back Indicator
   ========================================================= */

#swipe-back-indicator {
  position: fixed;
  top: 50%;
  left: 0;
  width: 4px;
  height: 60px;
  background: var(--accent);
  border-radius: 0 4px 4px 0;
  transform: translateY(-50%) translateX(-100%);
  transition: transform 0.2s ease;
  z-index: 90;
}

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

/* Add this to your mobile media query */
@media (max-width: 640px) {
  /* Hide desktop sidebar entirely on mobile */
  #side-nav {
    display: none !important;
  }

  /* Mobile Drawer Overlay */
  #mobile-drawer-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }
  #mobile-drawer-overlay.open {
    opacity: 1;
    pointer-events: auto;
  }

  /* Mobile Drawer Container */
  #mobile-drawer {
    display: flex;
    position: fixed;
    top: 0;
    left: -280px; /* Hides drawer offscreen */
    width: 280px;
    height: 100vh;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    box-shadow: 0 0 32px rgba(0, 0, 0, 0.4);
    z-index: 2000;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex-direction: column;
  }
  #mobile-drawer.open {
    left: 0;
  }

  /* Header inside drawer */
  .mobile-drawer-header {
    padding: 20px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .drawer-close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
  }
  .drawer-close-btn:hover {
    background: var(--bg-surface-2);
    color: var(--text-primary);
  }

  /* Body inside drawer */
  .mobile-drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 24px;
  }
  .drawer-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .drawer-label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 1px;
    margin-bottom: 4px;
  }
  .drawer-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: var(--radius-md);
    color: var(--text-primary);
    text-decoration: none;
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    font-size: 0.9rem;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
  }
  .drawer-item:hover {
    background: var(--bg-surface-2);
    color: var(--accent);
  }
  .drawer-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
  }
  .drawer-item:hover .drawer-icon {
    color: var(--accent);
  }
  .drawer-text {
    flex: 1;
  }

  /* User summary */
  .user-profile-summary {
    display: flex;
    align-items: center;
    gap: 12px;
  }
  .drawer-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--border-color);
  }
  .drawer-user-info {
    display: flex;
    flex-direction: column;
  }
  .drawer-display-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
  }
  .drawer-username {
    font-size: 0.75rem;
    color: var(--text-muted);
  }
}

/* Mobile layout adjustments — header visibility is controlled per-page */
@media (max-width: 768px) {
  #app-body {
    padding-top: 0 !important;
    margin-top: 0 !important;
  }
}