/* Mobile Performance & iPhone Optimization CSS */

/* Critical Performance Optimizations */

/* Preload and Loading States */
.loading-skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: 8px;
}

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

/* Image Loading Optimization */
img {
    loading: lazy;
    transition: opacity 0.3s ease;
}

img[data-loading="true"] {
    opacity: 0;
}

img[data-loaded="true"] {
    opacity: 1;
}

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

/* Content Loading Skeletons */
.text-skeleton {
    height: 1rem;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    border-radius: 4px;
    margin-bottom: 0.5rem;
}

.text-skeleton.title {
    height: 1.5rem;
    width: 70%;
}

.text-skeleton.subtitle {
    height: 1rem;
    width: 50%;
}

.text-skeleton.paragraph {
    height: 0.875rem;
    width: 100%;
}

.text-skeleton.paragraph:last-child {
    width: 80%;
}

/* Button Loading States */
.btn-loading {
    position: relative;
    color: transparent;
    pointer-events: none;
}

.btn-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid transparent;
    border-top: 2px solid currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* iPhone Specific Optimizations */

/* iPhone SE (375px) */
@media (max-width: 375px) {
    .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    
    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: 0.9rem;
        line-height: 1.6;
    }
    
    .btn {
        padding: 0.75rem 1.25rem;
        font-size: 0.9rem;
        min-height: 44px;
    }
    
    /* Navigation adjustments */
    .nav-menu {
        padding: 0.5rem;
    }
    
    .nav-item {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }
}

/* iPhone 12/13/14 (390px) */
@media (min-width: 376px) and (max-width: 390px) {
    .container {
        padding-left: 1.25rem;
        padding-right: 1.25rem;
    }
    
    .grid-2 {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
    
    .grid-3 {
        grid-template-columns: 1fr;
        gap: 1.25rem;
    }
}

/* iPhone Plus/Max (414px+) */
@media (min-width: 391px) and (max-width: 428px) {
    .container {
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }
    
    .grid-2 {
        grid-template-columns: 1fr;
        gap: 1.75rem;
    }
    
    .grid-3 {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
    }
}

/* Touch Optimization */
.touch-target {
    min-height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
}

/* Improve tap targets */
a, button, input, select, textarea {
    touch-action: manipulation;
}

/* Prevent zoom on input focus */
input, select, textarea {
    font-size: 16px;
}

@media (max-width: 768px) {
    input, select, textarea {
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

/* Swipe Gestures Support */
.swipeable {
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}

.horizontal-scroll {
    touch-action: pan-x;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.horizontal-scroll::-webkit-scrollbar {
    display: none;
}

/* iOS Safari Specific Fixes */
@supports (-webkit-touch-callout: none) {
    /* iOS Safari */
    .ios-fix {
        -webkit-appearance: none;
        -webkit-tap-highlight-color: transparent;
    }
    
    /* Fix for iOS Safari viewport units */
    .full-height {
        height: 100vh;
        height: -webkit-fill-available;
    }
    
    /* Fix for iOS Safari sticky positioning */
    .sticky-header {
        position: -webkit-sticky;
        position: sticky;
        top: 0;
        z-index: 100;
    }
}

/* Performance Optimizations */

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

/* Optimize repaints */
.optimized-animation {
    will-change: transform, opacity;
}

.optimized-animation.complete {
    will-change: auto;
}

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

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

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .loading-skeleton,
    .text-skeleton,
    .image-skeleton {
        background: linear-gradient(90deg, #2a2a2a 25%, #3a3a3a 50%, #2a2a2a 75%);
        background-size: 200% 100%;
    }
}

/* Intersection Observer Loading */
.lazy-load {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.lazy-load.loaded {
    opacity: 1;
    transform: translateY(0);
}

/* Critical CSS for above-the-fold content */
.above-fold {
    contain: layout style paint;
}

/* Optimize font loading */
@font-face {
    font-display: swap;
}

/* Preload critical resources */
.preload-hint {
    content-visibility: auto;
    contain-intrinsic-size: 200px;
}

/* Optimize images */
.responsive-image {
    width: 100%;
    height: auto;
    object-fit: cover;
    content-visibility: auto;
    contain-intrinsic-size: 200px 150px;
}

/* Service Worker Cache Indicators */
.cached-content {
    position: relative;
}

.cached-content::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 3px;
    height: 100%;
    background: #4CAF50;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.cached-content.from-cache::before {
    opacity: 1;
}

/* Network Status Indicators */
.offline-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #f44336;
    color: white;
    text-align: center;
    padding: 0.5rem;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
    z-index: 9999;
}

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

/* Memory Management */
.memory-efficient {
    contain: strict;
    content-visibility: auto;
}

/* Optimize scrolling performance */
.smooth-scroll {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

@media (prefers-reduced-motion: reduce) {
    .smooth-scroll {
        scroll-behavior: auto;
    }
}

/* Battery optimization */
@media (prefers-reduced-motion: reduce) {
    .battery-efficient {
        animation: none;
        transition: none;
    }
}

/* Connection-aware loading */
@media (prefers-reduced-data: reduce) {
    .data-saver {
        background-image: none;
    }
    
    .data-saver img {
        filter: blur(5px);
        transition: filter 0.3s ease;
    }
    
    .data-saver img:hover {
        filter: none;
    }
}

/* Focus management for keyboard navigation */
.focus-trap {
    outline: 2px solid var(--bordeaux);
    outline-offset: 2px;
}

/* Skip links for accessibility */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: var(--bordeaux);
    color: white;
    padding: 8px;
    text-decoration: none;
    border-radius: 4px;
    z-index: 10000;
}

.skip-link:focus {
    top: 6px;
}

/* Print optimizations */
@media print {
    .no-print {
        display: none !important;
    }
    
    .print-break {
        page-break-before: always;
    }
    
    .print-avoid-break {
        page-break-inside: avoid;
    }
    
    * {
        background: transparent !important;
        color: black !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }
    
    a, a:visited {
        text-decoration: underline;
    }
    
    a[href]:after {
        content: " (" attr(href) ")";
    }
    
    .container {
        width: auto;
        margin: 0;
        padding: 0;
    }
}

/* Error boundaries */
.error-boundary {
    padding: 2rem;
    text-align: center;
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 8px;
    color: #856404;
}

@media (max-width: 768px) {
    .error-boundary {
        padding: 1rem;
        font-size: 0.9rem;
    }
}

/* Progressive enhancement */
.js-enabled .no-js {
    display: none;
}

.no-js .js-only {
    display: none;
}

/* Critical path optimization */
.critical {
    font-display: block;
}

.non-critical {
    font-display: swap;
}

/* Resource hints */
.preload-critical {
    /* Critical resources should be preloaded */
}

.prefetch-next {
    /* Next page resources should be prefetched */
}

/* Performance monitoring */
.perf-mark {
    /* Used for performance.mark() */
}

/* Layout stability */
.layout-stable {
    contain: layout;
    min-height: 200px; /* Prevent layout shift */
}

/* Optimize third-party content */
.third-party-content {
    contain: strict;
    width: 100%;
    height: 200px;
    background: #f5f5f5;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    font-size: 0.9rem;
}

/* Final optimizations for iPhone */
@media (max-width: 428px) {
    /* Optimize for all iPhone sizes */
    .mobile-optimized {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        text-rendering: optimizeLegibility;
    }
    
    /* Optimize touch interactions */
    .touch-optimized {
        -webkit-tap-highlight-color: rgba(139, 69, 19, 0.2);
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }
    
    /* Optimize scrolling */
    .scroll-optimized {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
}