/**
 * Community Mobile Optimization CSS
 * Optimized for mobile devices and touch interactions
 */

/* ===========================
   MOBILE-FIRST BASE STYLES
   =========================== */

/* Touch-friendly tap targets (minimum 44x44px) */
.touch-target {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Prevent text selection on buttons and interactive elements */
.no-select {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Smooth scrolling for better UX */
html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* ===========================
   TOUCH INTERACTIONS
   =========================== */

/* Touch feedback for buttons */
.btn-touch,
button,
a.btn {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    transition: transform 0.1s ease, opacity 0.1s ease;
}

.btn-touch:active,
button:active,
a.btn:active {
    transform: scale(0.98);
    opacity: 0.9;
}

/* Card touch feedback */
.community-card,
.post-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.community-card:active,
.post-card:active {
    transform: translateY(2px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* ===========================
   MOBILE NAVIGATION
   =========================== */

/* Fixed bottom navigation spacing */
.has-bottom-nav {
    padding-bottom: 80px !important;
}

/* Pull-to-refresh indicator */
.pull-to-refresh {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.pull-to-refresh.active {
    opacity: 1;
}

/* ===========================
   MOBILE TYPOGRAPHY
   =========================== */

/* Optimized font sizes for mobile readability */
@media (max-width: 640px) {
    body {
        font-size: 16px; /* Prevent zoom on input focus in iOS */
    }
    
    h1 {
        font-size: 1.75rem;
        line-height: 1.2;
    }
    
    h2 {
        font-size: 1.5rem;
        line-height: 1.3;
    }
    
    h3 {
        font-size: 1.25rem;
        line-height: 1.4;
    }
    
    p {
        font-size: 1rem;
        line-height: 1.6;
    }
    
    small,
    .text-sm {
        font-size: 0.875rem;
    }
}

/* ===========================
   MOBILE FORMS
   =========================== */

/* Touch-friendly input fields */
input[type="text"],
input[type="search"],
input[type="email"],
input[type="tel"],
textarea,
select {
    min-height: 44px;
    font-size: 16px; /* Prevent zoom on iOS */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* Search input optimization */
.search-input-mobile {
    padding: 12px 16px;
    border-radius: 12px;
    border: 2px solid #E5E7EB;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-input-mobile:focus {
    border-color: #3B82F6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    outline: none;
}

/* ===========================
   MOBILE IMAGES
   =========================== */

/* Optimized image loading */
img {
    max-width: 100%;
    height: auto;
}

/* Lazy loading placeholder */
img[loading="lazy"] {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

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

/* Image galleries with horizontal scroll */
.image-gallery-mobile {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    gap: 8px;
    padding: 8px 0;
}

.image-gallery-mobile::-webkit-scrollbar {
    display: none;
}

.image-gallery-mobile > * {
    scroll-snap-align: start;
    flex-shrink: 0;
}

/* ===========================
   MOBILE MODALS & OVERLAYS
   =========================== */

/* Full-screen mobile modal */
@media (max-width: 640px) {
    .modal-mobile {
        position: fixed;
        inset: 0;
        z-index: 1000;
        background: white;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .modal-header-mobile {
        position: sticky;
        top: 0;
        background: white;
        border-bottom: 1px solid #E5E7EB;
        padding: 12px 16px;
        z-index: 10;
    }
}

/* Bottom sheet for mobile actions */
.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    max-height: 80vh;
    overflow-y: auto;
}

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

.bottom-sheet-handle {
    width: 40px;
    height: 4px;
    background: #D1D5DB;
    border-radius: 2px;
    margin: 12px auto;
}

/* ===========================
   MOBILE PERFORMANCE
   =========================== */

/* Hardware acceleration for smooth animations */
.gpu-accelerated {
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    will-change: transform;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===========================
   MOBILE SPACING & LAYOUT
   =========================== */

/* Mobile-optimized padding */
@media (max-width: 640px) {
    .container-mobile {
        padding-left: 16px;
        padding-right: 16px;
    }
    
    .section-mobile {
        margin-bottom: 24px;
    }
    
    /* Increased touch targets */
    .btn-mobile {
        padding: 12px 24px;
        min-height: 48px;
        font-size: 16px;
    }
}

/* ===========================
   MOBILE LOADING STATES
   =========================== */

/* Skeleton loading for content */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: 4px;
}

.skeleton-text {
    height: 16px;
    margin-bottom: 8px;
}

.skeleton-title {
    height: 24px;
    margin-bottom: 12px;
    width: 60%;
}

.skeleton-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
}

/* ===========================
   MOBILE ACCESSIBILITY
   =========================== */

/* Focus visible for keyboard navigation */
*:focus-visible {
    outline: 2px solid #3B82F6;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn {
        border: 2px solid currentColor;
    }
}

/* ===========================
   MOBILE DARK MODE SUPPORT
   =========================== */

@media (prefers-color-scheme: dark) {
    .auto-dark {
        background-color: #1F2937;
        color: #F9FAFB;
    }
    
    .auto-dark .card {
        background-color: #374151;
        border-color: #4B5563;
    }
}

/* ===========================
   MOBILE SWIPE GESTURES
   =========================== */

/* Swipeable container */
.swipeable {
    touch-action: pan-y pinch-zoom;
    cursor: grab;
}

.swipeable:active {
    cursor: grabbing;
}

/* Swipe indicators */
.swipe-indicator {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.swipe-indicator.left {
    left: 20px;
}

.swipe-indicator.right {
    right: 20px;
}

.swipeable.swiping .swipe-indicator {
    opacity: 0.5;
}

/* ===========================
   MOBILE INFINITE SCROLL
   =========================== */

/* Loading indicator at bottom */
.infinite-scroll-loading {
    text-align: center;
    padding: 20px;
    color: #6B7280;
}

.infinite-scroll-end {
    text-align: center;
    padding: 20px;
    color: #9CA3AF;
    font-size: 14px;
}

/* ===========================
   MOBILE RESPONSIVE UTILITIES
   =========================== */

/* Hide on mobile */
@media (max-width: 640px) {
    .hide-mobile {
        display: none !important;
    }
}

/* Show only on mobile */
.show-mobile {
    display: none !important;
}

@media (max-width: 640px) {
    .show-mobile {
        display: block !important;
    }
    
    .show-mobile-flex {
        display: flex !important;
    }
    
    .show-mobile-inline {
        display: inline !important;
    }
}

/* ===========================
   MOBILE SAFE AREA SUPPORT
   =========================== */

/* Support for iPhone notch and home indicator */
@supports (padding: max(0px)) {
    .safe-area-top {
        padding-top: max(env(safe-area-inset-top), 12px);
    }
    
    .safe-area-bottom {
        padding-bottom: max(env(safe-area-inset-bottom), 12px);
    }
    
    .safe-area-left {
        padding-left: max(env(safe-area-inset-left), 12px);
    }
    
    .safe-area-right {
        padding-right: max(env(safe-area-inset-right), 12px);
    }
}
