/* Mobile-First Advanced Optimizations */

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

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

/* High contrast mode support */
@media (prefers-contrast: high) {
    .news-card,
    .mobile-news-card {
        border: 2px solid #000;
    }
    
    .nav-link:hover,
    .nav-link:focus {
        background: #000;
        color: #fff;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .mobile-news-card {
        background: #1e293b;
        color: #f1f5f9;
        border: 1px solid #374151;
    }
    
    .mobile-bottom-nav {
        background: #1e293b;
        border-top-color: #374151;
    }
    
    .nav-item {
        color: #94a3b8;
    }
    
    .nav-item:hover,
    .nav-item.active {
        color: #60a5fa;
        background: rgba(96, 165, 250, 0.1);
    }
}

/* ==============================================
   PROGRESSIVE ENHANCEMENT
============================================== */

/* No-JS fallbacks */
.no-js .mobile-search-overlay,
.no-js .mobile-menu-overlay {
    display: none !important;
}

.no-js .mobile-bottom-nav {
    display: none;
}

/* Touch device optimizations */
@media (pointer: coarse) {
    /* Larger touch targets */
    .nav-link,
    .pagination-btn,
    .mobile-news-card .read-more-btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Better thumb scrolling */
    .pagination-pages {
        scroll-behavior: smooth;
        overscroll-behavior: contain;
    }
}

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

/* Base mobile typography */
@media (max-width: 768px) {
    html {
        font-size: 14px;
    }
    
    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; }
    h4 { font-size: 1.125rem; line-height: 1.4; }
    h5 { font-size: 1rem; line-height: 1.5; }
    h6 { font-size: 0.875rem; line-height: 1.5; }
    
    p { font-size: 1rem; line-height: 1.6; }
    small { font-size: 0.875rem; }
}

/* Small mobile devices */
@media (max-width: 480px) {
    html {
        font-size: 13px;
    }
    
    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.375rem; }
    h3 { font-size: 1.125rem; }
}

/* Very small devices */
@media (max-width: 360px) {
    html {
        font-size: 12px;
    }
    
    h1 { font-size: 1.375rem; }
    h2 { font-size: 1.25rem; }
}

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

.loading-skeleton {
    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; }
}

.mobile-news-card.loading {
    pointer-events: none;
}

.mobile-news-card.loading .card-title,
.mobile-news-card.loading .card-excerpt {
    background: #f0f0f0;
    color: transparent;
    border-radius: 4px;
}

.mobile-news-card.loading .card-title {
    height: 1.5rem;
    margin-bottom: 1rem;
}

.mobile-news-card.loading .card-excerpt {
    height: 3rem;
}

/* ==============================================
   MOBILE ANIMATIONS & TRANSITIONS
============================================== */

/* Smooth page transitions */
@media (max-width: 768px) {
    .main {
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    .page-enter {
        opacity: 0;
        transform: translateY(20px);
    }
    
    .page-enter-active {
        opacity: 1;
        transform: translateY(0);
        transition: opacity 0.3s ease, transform 0.3s ease;
    }
    
    .page-exit {
        opacity: 1;
        transform: translateY(0);
    }
    
    .page-exit-active {
        opacity: 0;
        transform: translateY(-20px);
        transition: opacity 0.3s ease, transform 0.3s ease;
    }
}

/* Mobile-specific hover effects */
@media (hover: hover) and (pointer: fine) {
    .mobile-news-card:hover {
        transform: translateY(-4px);
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    }
}

/* Touch feedback for mobile */
@media (pointer: coarse) {
    .mobile-news-card:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }
    
    .nav-item:active,
    .pagination-btn:active {
        transform: scale(0.95);
        transition: transform 0.1s ease;
    }
}

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

/* Focus indicators for mobile */
@media (max-width: 768px) {
    *:focus {
        outline: 3px solid #3b82f6;
        outline-offset: 2px;
    }
    
    .nav-item:focus,
    .mobile-news-card:focus {
        outline: 3px solid #3b82f6;
        outline-offset: 4px;
    }
}

/* Screen reader improvements */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.sr-only-focusable:focus {
    position: static;
    width: auto;
    height: auto;
    padding: 0.5rem;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
    background: #3b82f6;
    color: white;
    z-index: 9999;
}

/* ==============================================
   MOBILE PRINT STYLES
============================================== */

@media print {
    .mobile-bottom-nav,
    .mobile-search-overlay,
    .mobile-menu-overlay,
    .nav-toggle,
    .share-btn {
        display: none !important;
    }
    
    .mobile-news-card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ccc;
    }
    
    .mobile-news-card .card-actions {
        display: none;
    }
    
    .mobile-pagination {
        display: none;
    }
}

/* ==============================================
   MOBILE ERROR STATES
============================================== */

.mobile-error-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #64748b;
}

.mobile-error-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    color: #ef4444;
}

.mobile-error-state h3 {
    margin-bottom: 1rem;
    color: #1e293b;
}

.mobile-error-state .retry-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: #3b82f6;
    color: white;
    border: none;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    transition: all 0.3s ease;
    margin-top: 1rem;
}

.mobile-error-state .retry-btn:hover {
    background: #1d4ed8;
    transform: translateY(-1px);
}

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

/* GPU acceleration for smooth animations */
.mobile-news-card,
.mobile-bottom-nav,
.pagination-btn {
    transform: translateZ(0);
    will-change: transform;
}

/* Optimize repaints */
.mobile-news-card img {
    transform: translateZ(0);
}

/* Contain layout shifts */
.mobile-news-card {
    contain: layout style paint;
}

/* ==============================================
   MOBILE UTILITY CLASSES
============================================== */

@media (max-width: 768px) {
    .mobile-only { display: block !important; }
    .desktop-only { display: none !important; }
    
    .mobile-full-width { width: 100% !important; }
    .mobile-text-center { text-align: center !important; }
    .mobile-text-left { text-align: left !important; }
    
    .mobile-mt-0 { margin-top: 0 !important; }
    .mobile-mt-1 { margin-top: 0.5rem !important; }
    .mobile-mt-2 { margin-top: 1rem !important; }
    .mobile-mt-3 { margin-top: 1.5rem !important; }
    
    .mobile-mb-0 { margin-bottom: 0 !important; }
    .mobile-mb-1 { margin-bottom: 0.5rem !important; }
    .mobile-mb-2 { margin-bottom: 1rem !important; }
    .mobile-mb-3 { margin-bottom: 1.5rem !important; }
    
    .mobile-p-1 { padding: 0.5rem !important; }
    .mobile-p-2 { padding: 1rem !important; }
    .mobile-p-3 { padding: 1.5rem !important; }
}

@media (min-width: 769px) {
    .mobile-only { display: none !important; }
    .desktop-only { display: block !important; }
}