/* Comprehensive Mobile Responsive Styles for Star News */

/* ============================================
   BASE MOBILE STYLES (applied to all screens < 768px)
   ============================================ */

/* Prevent horizontal scroll globally */
html, body {
    overflow-x: hidden !important;
    width: 100% !important;
    max-width: 100vw !important;
}

/* Force box-sizing on all elements */
* {
    box-sizing: border-box !important;
}

/* Prevent body children from exceeding viewport */
body > * {
    max-width: 100vw !important;
}

@media (max-width: 768px) {
    /* Prevent horizontal scroll */
    html, body {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100vw !important;
        position: relative !important;
    }
    
    /* Force all elements to respect container width */
    * {
        max-width: 100% !important;
    }
    
    /* Prevent any element from exceeding viewport */
    body > * {
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }

    /* Base font size adjustment for mobile */
    body {
        font-size: 14px;
        line-height: 1.6;
    }

    /* Container adjustments */
    .container,
    .main-container,
    .content-container {
        width: 100% !important;
        max-width: 100% !important;
        padding: 15px !important;
        margin: 0 auto !important;
    }

    /* Grid layouts - force single column */
    .grid,
    .cards-grid,
    .content-grid,
    .news-cards-grid,
    .unified-grid,
    .content-grid-2x2,
    .twelve-grid,
    .feature-cards-grid,
    .featured-content-grid {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 15px !important;
    }

    /* Flex layouts - stack vertically */
    .flex-row,
    .row,
    .flex-container {
        flex-direction: column !important;
    }

    /* Cards - full width on mobile */
    .card,
    .news-card,
    .unified-card,
    .traffic-card,
    .twelve-grid-item {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 0 15px 0 !important;
        padding: 15px !important;
    }

    /* Headings - reduce size for mobile */
    h1 {
        font-size: 28px !important;
        line-height: 1.3 !important;
        margin-bottom: 15px !important;
    }

    h2 {
        font-size: 24px !important;
        line-height: 1.3 !important;
        margin-bottom: 12px !important;
    }

    h3 {
        font-size: 20px !important;
        line-height: 1.4 !important;
        margin-bottom: 10px !important;
    }

    h4 {
        font-size: 18px !important;
        line-height: 1.4 !important;
        margin-bottom: 8px !important;
    }

    /* Buttons - touch-friendly sizing */
    button,
    .btn,
    .button,
    .unified-btn,
    .filter-btn {
        min-height: 44px !important;
        min-width: 44px !important;
        padding: 12px 20px !important;
        font-size: 14px !important;
        touch-action: manipulation;
    }

    /* Form inputs - touch-friendly */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    input[type="number"],
    input[type="url"],
    textarea,
    select,
    .form-control {
        min-height: 44px !important;
        padding: 12px 15px !important;
        font-size: 16px !important; /* Prevents zoom on iOS */
        width: 100% !important;
        box-sizing: border-box !important;
    }

    textarea.form-control {
        min-height: 120px !important;
    }

    /* Images - responsive */
    img {
        max-width: 100% !important;
        height: auto !important;
    }

    /* Tables - make scrollable */
    table {
        display: block !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        width: 100% !important;
    }

    /* Modals and overlays - full screen or properly sized */
    .modal,
    .modal-dialog,
    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        border-radius: 0 !important;
        max-height: 100vh !important;
        overflow-y: auto !important;
    }

    .modal-body {
        padding: 20px 15px !important;
    }

    /* Navigation spacing */
    body {
        padding-top: 70px !important;
    }

    /* Remove negative margins that cause overflow */
    .hero-cards-grid .news-card {
        margin-left: 0 !important;
    }
    
    /* Prevent any element from causing horizontal overflow */
    img, video, iframe, embed, object {
        max-width: 100% !important;
        height: auto !important;
    }
    
    /* Fix table overflow */
    table {
        width: 100% !important;
        table-layout: fixed !important;
    }
    
    /* Fix pre and code blocks */
    pre, code {
        white-space: pre-wrap !important;
        word-wrap: break-word !important;
        max-width: 100% !important;
        overflow-x: auto !important;
    }
    
    /* Ensure containers don't exceed viewport */
    .container, .main-container, .content-container,
    .create-post-container, .traffic-container,
    .debate-container, .forum-container, .classifieds-container {
        width: 100% !important;
        max-width: 100vw !important;
        padding-left: 15px !important;
        padding-right: 15px !important;
        box-sizing: border-box !important;
    }
    
    /* Prevent any positioned elements from causing overflow */
    [style*="position: absolute"],
    [style*="position: fixed"] {
        max-width: 100vw !important;
        left: auto !important;
        right: auto !important;
    }
    
    /* Fix any inline styles that might set widths */
    [style*="width:"] {
        max-width: 100vw !important;
    }
}

/* ============================================
   SMALL MOBILE STYLES (applied to screens < 480px)
   ============================================ */

@media (max-width: 480px) {
    body {
        font-size: 13px;
    }

    .container,
    .main-container,
    .content-container {
        padding: 10px !important;
    }

    h1 {
        font-size: 24px !important;
    }

    h2 {
        font-size: 20px !important;
    }

    h3 {
        font-size: 18px !important;
    }

    .card,
    .news-card,
    .unified-card,
    .traffic-card {
        padding: 12px !important;
        margin-bottom: 12px !important;
    }

    button,
    .btn,
    .button,
    .unified-btn {
        padding: 10px 16px !important;
        font-size: 13px !important;
    }
}

/* ============================================
   SPECIFIC COMPONENT FIXES
   ============================================ */

/* Create Post Page Mobile Fixes */
@media (max-width: 768px) {
    .designer-grid {
        grid-template-columns: 1fr !important;
        gap: 20px !important;
    }

    .tight-grid {
        grid-template-columns: 1fr !important;
    }

    .preview-card {
        order: -1; /* Show preview first on mobile */
    }

    .form-section {
        padding: 15px !important;
        margin-bottom: 15px !important;
    }

    .ai-section {
        padding: 15px !important;
    }
}

/* Forum/Debate/Classifieds Mobile Fixes */
@media (max-width: 768px) {
    .debate-container,
    .forum-container,
    .classifieds-container {
        padding: 0 15px !important;
        margin: 80px auto 30px !important;
    }

    .debate-header,
    .forum-header {
        padding: 25px 15px !important;
        margin-bottom: 20px !important;
    }
}

/* Traffic Page Mobile Fixes */
@media (max-width: 768px) {
    .traffic-container {
        padding: 0 15px !important;
        margin: 80px auto 30px !important;
    }
}

/* Homepage Hero Cards Mobile Fixes */
@media (max-width: 768px) {
    .hero-cards-grid {
        flex-direction: column !important;
        overflow-x: visible !important;
        gap: 20px !important;
    }

    .hero-cards-grid .news-card {
        flex: 1 1 100% !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 100% !important;
        margin-left: 0 !important;
    }

    .hero-rail-btn {
        display: none !important;
    }
}

/* Ad containers - hide or adjust on mobile */
@media (max-width: 768px) {
    .ad-inline,
    .ad-container {
        margin: 15px 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }
}

/* Two-column layouts - stack on mobile */
@media (max-width: 768px) {
    .two-column,
    .two-col,
    .split-layout {
        grid-template-columns: 1fr !important;
        gap: 20px !important;
    }
}

/* Sidebar - full width on mobile */
@media (max-width: 768px) {
    .sidebar,
    .aside,
    .side-content {
        width: 100% !important;
        margin-top: 20px !important;
        order: 2;
    }

    .main-content {
        order: 1;
    }
}

/* Fix text overflow */
@media (max-width: 768px) {
    * {
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
    }

    h1, h2, h3, h4, h5, h6,
    .card-title,
    .news-card h3,
    .unified-card h3 {
        word-break: break-word !important;
        hyphens: auto;
    }
}

/* Fix padding issues */
@media (max-width: 768px) {
    section,
    .section {
        padding: 20px 15px !important;
    }

    .page-header {
        padding: 20px 15px !important;
        margin-bottom: 20px !important;
    }
}

/* Navigation mobile fixes (if not already handled) */
@media (max-width: 768px) {
    .nav-container {
        padding: 8px 12px !important;
    }

    .logo,
    .logo img {
        max-height: 50px !important;
        height: 50px !important;
    }
}

/* Utility classes for mobile */
@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }

    .show-mobile {
        display: block !important;
    }

    .text-center-mobile {
        text-align: center !important;
    }

    .full-width-mobile {
        width: 100% !important;
        max-width: 100% !important;
    }
}

