/* Homepage Mobile Layout Fixes */
/* SystemRatings Homepage Mobile Optimization */

/* ============================================
   MOBILE BREAKPOINT: 768px and below
   ============================================ */

@media (max-width: 768px) {
    /* Fix horizontal scrolling */
    body {
        overflow-x: hidden !important;
        width: 100% !important;
    }
    
    html, body {
        max-width: 100% !important;
        overflow-x: hidden !important;
    }
    
    /* Header Wrapper Fixes */
    .header-wrapper {
        position: relative !important;
        width: 100% !important;
    }
    
    /* Performance Ticker Bar */
    .header-top {
        padding: 8px 0 !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    .header-top-content {
        padding: 0 16px !important;
        flex-direction: column !important;
        gap: 12px !important;
        min-width: 100% !important;
    }
    
    .performance-index {
        width: 100% !important;
        flex-direction: row !important;
        gap: 16px !important;
        overflow-x: auto !important;
        padding-bottom: 8px !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    .index-item {
        flex-shrink: 0 !important;
        min-width: 120px !important;
    }
    
    .index-label {
        font-size: 10px !important;
    }
    
    .index-value {
        font-size: 14px !important;
    }
    
    .header-date {
        font-size: 11px !important;
        text-align: center !important;
        width: 100% !important;
    }
    
    /* Main Header */
    .header-main {
        padding: 16px 0 !important;
    }
    
    .header-content {
        flex-direction: column !important;
        gap: 16px !important;
        padding: 0 16px !important;
        align-items: stretch !important;
    }
    
    .logo {
        justify-content: center !important;
        text-align: center !important;
    }
    
    .logo-text {
        font-size: 24px !important;
    }
    
    .logo-tagline {
        font-size: 12px !important;
    }
    
    /* Search Bar */
    .header-actions form {
        width: 100% !important;
        flex-direction: column !important;
        gap: 8px !important;
    }
    
    .header-actions input[type="text"] {
        width: 100% !important;
        font-size: 16px !important; /* Prevents zoom on iOS */
    }
    
    .header-actions button {
        width: 100% !important;
    }
    
    /* Navigation */
    .nav-main {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    .nav-content {
        padding: 0 !important;
    }
    
    .nav-items {
        padding: 0 16px !important;
        min-width: max-content !important;
        justify-content: flex-start !important;
    }
    
    .nav-items a {
        padding: 12px 16px !important;
        font-size: 14px !important;
        white-space: nowrap !important;
    }
    
    /* Main Container */
    .main-container {
        padding: 0 16px !important;
        margin: 16px auto !important;
        grid-template-columns: 1fr !important;
        gap: 24px !important;
        max-width: 100% !important;
    }
    
    /* Hero Article */
    .hero-article {
        margin-bottom: 24px !important;
        border-radius: 0 !important;
        margin-left: -16px !important;
        margin-right: -16px !important;
    }
    
    .hero-image {
        height: 250px !important;
        border-radius: 0 !important;
    }
    
    .hero-content {
        padding: 20px 16px !important;
    }
    
    .hero-category {
        font-size: 12px !important;
    }
    
    .hero-title {
        font-size: 28px !important;
        line-height: 1.2 !important;
        word-wrap: break-word !important;
        hyphens: auto !important;
    }
    
    .hero-summary {
        font-size: 16px !important;
        line-height: 1.4 !important;
    }
    
    .hero-meta {
        flex-wrap: wrap !important;
        gap: 12px !important;
        font-size: 12px !important;
    }
    
    /* Section Headers */
    .section-header {
        font-size: 20px !important;
        margin-bottom: 16px !important;
        padding-bottom: 8px !important;
    }
    
    /* Featured Grid */
    .featured-grid {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }
    
    /* Article Cards */
    .article-card {
        margin-bottom: 16px !important;
    }
    
    .article-image {
        height: 180px !important;
    }
    
    .article-content {
        padding: 16px !important;
    }
    
    .article-title {
        font-size: 18px !important;
        line-height: 1.3 !important;
    }
    
    .article-summary {
        font-size: 14px !important;
        margin-bottom: 8px !important;
    }
    
    .article-meta {
        font-size: 12px !important;
    }
    
    /* Sidebar */
    .sidebar {
        position: static !important;
        width: 100% !important;
        margin-top: 32px !important;
    }
    
    .sidebar-widget {
        margin-bottom: 20px !important;
        padding: 20px !important;
        border-radius: 8px !important;
    }
    
    .widget-title {
        font-size: 18px !important;
        margin-bottom: 16px !important;
    }
    
    /* Performance Widget */
    .perf-metric {
        padding: 12px 0 !important;
    }
    
    .perf-label {
        font-size: 12px !important;
    }
    
    .perf-value {
        font-size: 24px !important;
    }
    
    .perf-change {
        font-size: 12px !important;
    }
    
    /* Top Rated List */
    .top-rated-item {
        padding: 10px 0 !important;
    }
    
    .rank-number {
        font-size: 20px !important;
        min-width: 28px !important;
    }
    
    .rated-info {
        margin-left: 12px !important;
    }
    
    .rated-name {
        font-size: 14px !important;
    }
    
    .rated-meta {
        font-size: 12px !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
    }
    
    /* Newsletter Widget */
    .newsletter-description {
        font-size: 14px !important;
        margin-bottom: 16px !important;
    }
    
    .newsletter-form input {
        padding: 12px !important;
        font-size: 16px !important; /* Prevents zoom on iOS */
        margin-bottom: 10px !important;
    }
    
    .newsletter-form button {
        padding: 12px !important;
        font-size: 14px !important;
    }
    
    /* Footer */
    .footer {
        margin-top: 48px !important;
        padding: 40px 0 30px !important;
    }
    
    .footer-content {
        padding: 0 16px !important;
        grid-template-columns: 1fr !important;
        gap: 32px !important;
    }
    
    .footer-brand {
        margin-right: 0 !important;
        text-align: center !important;
    }
    
    .footer-logo {
        font-size: 24px !important;
    }
    
    .footer-description {
        font-size: 14px !important;
        margin-bottom: 20px !important;
    }
    
    .footer-social {
        justify-content: center !important;
        gap: 12px !important;
    }
    
    .social-link {
        width: 36px !important;
        height: 36px !important;
        font-size: 14px !important;
    }
    
    .footer-section {
        text-align: center !important;
    }
    
    .footer-section h4 {
        font-size: 13px !important;
        margin-bottom: 16px !important;
    }
    
    .footer-links li {
        margin-bottom: 10px !important;
    }
    
    .footer-links a {
        font-size: 14px !important;
    }
    
    .footer-bottom {
        margin-top: 32px !important;
        padding-top: 24px !important;
        font-size: 12px !important;
        padding-left: 16px !important;
        padding-right: 16px !important;
    }
}

/* ============================================
   SMALL MOBILE: 480px and below
   ============================================ */

@media (max-width: 480px) {
    /* Even smaller adjustments for very small screens */
    
    .logo-text {
        font-size: 22px !important;
    }
    
    .hero-title {
        font-size: 24px !important;
    }
    
    .hero-summary {
        font-size: 15px !important;
    }
    
    .section-header {
        font-size: 18px !important;
    }
    
    .article-title {
        font-size: 16px !important;
    }
    
    .widget-title {
        font-size: 16px !important;
    }
    
    .perf-value {
        font-size: 20px !important;
    }
    
    /* Reduce padding on very small screens */
    .main-container {
        padding: 0 12px !important;
    }
    
    .hero-content {
        padding: 16px 12px !important;
    }
    
    .article-content {
        padding: 12px !important;
    }
    
    .sidebar-widget {
        padding: 16px !important;
    }
}

/* ============================================
   TABLET: 768px to 1024px
   ============================================ */

@media (min-width: 769px) and (max-width: 1024px) {
    /* Tablet-specific adjustments */
    
    .main-container {
        grid-template-columns: 1fr !important;
        padding: 0 24px !important;
    }
    
    .featured-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    .hero-title {
        font-size: 36px !important;
    }
    
    .sidebar {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 20px !important;
        margin-top: 32px !important;
    }
    
    .footer-content {
        grid-template-columns: repeat(3, 1fr) !important;
    }
}

/* ============================================
   LANDSCAPE MOBILE: Height < 500px
   ============================================ */

@media (max-height: 500px) and (orientation: landscape) {
    .header-wrapper {
        position: relative !important;
    }
    
    .hero-image {
        height: 200px !important;
    }
    
    .hero-title {
        font-size: 24px !important;
    }
}

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

@media (max-width: 768px) {
    /* Hide on mobile */
    .hide-mobile {
        display: none !important;
    }
    
    /* Show only on mobile */
    .show-mobile {
        display: block !important;
    }
    
    /* Prevent horizontal scroll */
    .no-scroll-x {
        overflow-x: hidden !important;
    }
    
    /* Touch-friendly tap targets */
    a, button, input, select, textarea {
        min-height: 44px !important;
    }
    
    /* Improve readability */
    p, li {
        line-height: 1.5 !important;
    }
    
    /* Fix any absolute positioning issues */
    .main-content {
        position: relative !important;
        width: 100% !important;
    }
    
    /* Fix giant logos in header on mobile */
    .nav-logo-img {
        height: 25px !important;
        max-width: 80px !important;
    }
}

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

@media (max-width: 768px) {
    /* Reduce animations on mobile */
    * {
        animation-duration: 0.2s !important;
        transition-duration: 0.2s !important;
    }
    
    /* Optimize images */
    img {
        max-width: 100% !important;
        height: auto !important;
    }
    
    /* Improve tap feedback */
    a:active, button:active {
        opacity: 0.8 !important;
    }
}

/* ============================================
   iOS SPECIFIC FIXES
   ============================================ */

@supports (-webkit-touch-callout: none) {
    /* iOS only */
    input, textarea, select {
        font-size: 16px !important; /* Prevents zoom on focus */
        -webkit-appearance: none !important;
        border-radius: 0 !important;
    }
    
    /* Fix iOS scroll bounce */
    .header-wrapper {
        -webkit-overflow-scrolling: touch !important;
    }
}

/* ============================================
   ANDROID SPECIFIC FIXES
   ============================================ */

@media screen and (-webkit-min-device-pixel-ratio: 0) {
    /* Android only */
    select {
        background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20width%3D%2714%27%20height%3D%278%27%20viewBox%3D%270%200%2014%208%27%20xmlns%3D%27http%3A//www.w3.org/2000/svg%27%3E%3Cpath%20d%3D%27M7%208L0%200h14z%27%20fill%3D%27%23000%27/%3E%3C/svg%3E") !important;
        background-repeat: no-repeat !important;
        background-position: right 10px center !important;
        padding-right: 30px !important;
    }
}