/* ============================================
   CRITICAL MOBILE FIXES - EMERGENCY PATCH
   Fixes all mobile UI/UX issues across every page
   ============================================ */

/* CRITICAL MOBILE BUTTON FIXES */
@media (max-width: 768px) {
    /* Override ALL button layouts that cause mobile issues */
    .btn {
        min-height: 44px !important;
        padding: 12px 20px !important;
        font-size: 1rem !important;
        font-weight: 500 !important;
        border-radius: 10px !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        line-height: 1.2 !important;
        margin-bottom: 8px !important;
        width: 100% !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1) !important;
    }

    .btn-sm {
        min-height: 40px !important;
        padding: 10px 16px !important;
        font-size: 0.9rem !important;
        border-radius: 8px !important;
    }

    .btn-lg {
        min-height: 52px !important;
        padding: 16px 24px !important;
        font-size: 1.1rem !important;
        border-radius: 12px !important;
    }

    /* Fix ALL flex layouts that break on mobile */
    .d-flex.justify-content-between,
    .d-flex.align-items-center.justify-content-between,
    .d-flex.gap-2,
    .d-flex.gap-3,
    .d-flex.flex-wrap.gap-2,
    .d-flex.flex-wrap.gap-3,
    .d-flex.align-items-center {
        flex-direction: column !important;
        gap: 12px !important;
        align-items: stretch !important;
    }

    /* Homepage tool cards button container fix */
    #featured-tools .d-flex.justify-content-between,
    .tools-grid .d-flex.justify-content-between {
        flex-direction: column !important;
        gap: 8px !important;
    }

    /* Article cards button container fix */
    .articles-section .d-flex.justify-content-between {
        flex-direction: column !important;
        gap: 8px !important;
    }

    /* Tool detail page button fixes */
    .tool-detail .d-flex.justify-content-between {
        flex-direction: column !important;
        gap: 12px !important;
    }

    /* Profile page button fixes */
    .profile .d-flex.gap-3 {
        flex-direction: column !important;
        gap: 8px !important;
    }

    /* Category page button fixes */
    .category-tools .d-flex.justify-content-between {
        flex-direction: column !important;
        gap: 8px !important;
    }
}

/* CRITICAL MOBILE CARD FIXES */
@media (max-width: 768px) {
    /* Fix ALL cards across the website */
    .card {
        border-radius: 12px !important;
        box-shadow: 0 3px 15px rgba(0,0,0,0.1) !important;
        border: 1px solid #e2e8f0 !important;
        background: #ffffff !important;
        margin-bottom: 20px !important;
        overflow: hidden !important;
    }

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

    .card-header {
        padding: 16px 20px !important;
        background: #f8f9fa !important;
        border-bottom: 1px solid #e2e8f0 !important;
    }

    /* Fix ALL card typography for readability */
    .card-title {
        color: #000000 !important;
        font-size: 1.125rem !important;
        font-weight: 600 !important;
        line-height: 1.4 !important;
        margin-bottom: 12px !important;
    }

    .card-text {
        color: #2d3748 !important;
        font-size: 1rem !important;
        line-height: 1.7 !important;
        margin-bottom: 16px !important;
    }

    /* Fix text contrast issues */
    .text-muted {
        color: #4a5568 !important;
        font-weight: 400 !important;
    }

    .text-secondary {
        color: #2d3748 !important;
        font-weight: 400 !important;
    }

    small, .small {
        color: #4a5568 !important;
        font-size: 0.875rem !important;
        line-height: 1.5 !important;
    }
}

/* CRITICAL MOBILE GRID FIXES */
@media (max-width: 768px) {
    .row.g-4 {
        --bs-gutter-x: 16px !important;
        --bs-gutter-y: 24px !important;
    }

    .row.g-3 {
        --bs-gutter-x: 12px !important;
        --bs-gutter-y: 20px !important;
    }

    .container {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }
}

/* EXTRA SMALL MOBILE FIXES */
@media (max-width: 576px) {
    .btn {
        min-height: 48px !important;
        padding: 14px 20px !important;
        font-size: 1rem !important;
        border-radius: 12px !important;
        width: 100% !important;
    }

    .card {
        border-radius: 16px !important;
        box-shadow: 0 4px 20px rgba(0,0,0,0.1) !important;
        margin-bottom: 24px !important;
    }

    .card-body {
        padding: 24px 20px !important;
    }

    .card-title {
        font-size: 1.25rem !important;
        margin-bottom: 12px !important;
    }

    .col-lg-4,
    .col-lg-3,
    .col-md-6,
    .col-sm-6 {
        padding-left: 8px !important;
        padding-right: 8px !important;
        margin-bottom: 20px !important;
    }

    .row.g-4 {
        --bs-gutter-x: 0px !important;
        --bs-gutter-y: 24px !important;
    }
}

/* CRITICAL CONTRAST AND READABILITY FIXES */
@media (max-width: 768px) {
    /* Fix dark background sections causing readability issues */
    .bg-primary {
        background-color: #ffffff !important;
        color: #000000 !important;
        border: 1px solid #e2e8f0 !important;
    }
    
    .bg-primary.text-white {
        background-color: #ffffff !important;
        color: #000000 !important;
    }
    
    .text-white {
        color: #000000 !important;
    }
    
    .text-white-75 {
        color: #2d3748 !important;
    }
    
    /* Fix newsletter sections and CTAs */
    section.bg-primary {
        background-color: #f8f9fa !important;
        color: #000000 !important;
        border: 1px solid #e2e8f0 !important;
        border-radius: 12px !important;
        padding: 32px 20px !important;
    }
    
    section.bg-primary.text-white {
        background-color: #f8f9fa !important;
        color: #000000 !important;
    }
    
    /* Fix any other dark sections */
    .bg-dark {
        background-color: #ffffff !important;
        color: #000000 !important;
        border: 1px solid #e2e8f0 !important;
    }
    
    .bg-secondary {
        background-color: #f8f9fa !important;
        color: #000000 !important;
    }
    
    /* Fix badge colors for readability */
    .badge.bg-primary {
        background-color: #e3f2fd !important;
        color: #1976d2 !important;
        border: 1px solid #bbdefb !important;
    }
    
    /* Fix article content background */
    .article-content {
        background-color: #ffffff !important;
        color: #000000 !important;
        padding: 20px !important;
        border-radius: 12px !important;
        line-height: 1.7 !important;
    }
    
    .article-content h1,
    .article-content h2, 
    .article-content h3,
    .article-content h4,
    .article-content h5,
    .article-content h6 {
        color: #000000 !important;
        margin-top: 24px !important;
        margin-bottom: 16px !important;
    }
    
    .article-content p {
        color: #2d3748 !important;
        font-size: 1rem !important;
        line-height: 1.7 !important;
        margin-bottom: 16px !important;
    }
    
    .article-content ul,
    .article-content ol {
        color: #2d3748 !important;
        margin-bottom: 16px !important;
    }
    
    .article-content li {
        color: #2d3748 !important;
        line-height: 1.6 !important;
        margin-bottom: 8px !important;
    }
    
    /* Fix author avatars and elements */
    .author-avatar.bg-primary,
    .comment-avatar.bg-primary,
    .user-avatar.bg-primary,
    .profile-avatar.bg-primary {
        background-color: #1976d2 !important;
        color: #ffffff !important;
        border: 2px solid #ffffff !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1) !important;
    }
    
    /* Ensure all text is readable */
    p, div, span, h1, h2, h3, h4, h5, h6 {
        color: inherit !important;
    }
    
    .text-muted {
        color: #6c757d !important;
    }
    
    /* Fix any overlay or hero sections */
    .hero-section,
    .banner-section {
        background-color: #ffffff !important;
        color: #000000 !important;
    }
}

/* DISABLE HOVER EFFECTS ON MOBILE */
@media (hover: none) and (pointer: coarse) {
    .card:hover,
    .hover-lift:hover {
        transform: none !important;
        box-shadow: 0 3px 15px rgba(0,0,0,0.1) !important;
    }

    .btn:hover {
        transform: none !important;
    }

    .btn:active {
        transform: scale(0.98) !important;
        transition: transform 0.1s ease !important;
    }
}