/* ========================================
   MOBILE RESPONSIVE FIXES
   Critical fixes for horizontal scrolling on mobile devices
   Target: iPhone SE 375px and all mobile viewports
   ======================================== */

/* ========================================
   GLOBAL MOBILE FIXES
   ======================================== */

/* Ensure all elements respect viewport width */
* {
    max-width: 100%;
    box-sizing: border-box;
}

/* Prevent horizontal overflow on body */
body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

/* Ensure main containers don't overflow */
.container,
.company-profile-container,
.page-container {
    max-width: 100vw;
    overflow-x: hidden;
}

/* ========================================
   MOBILE BREAKPOINT: max-width 480px
   ======================================== */

@media (max-width: 480px) {
    /* Body and global spacing */
    body {
        padding: var(--space-1) !important; /* 8px instead of 24px */
    }

    /* Container padding fixes */
    .container {
        padding: 0 var(--space-2) !important; /* 16px instead of 4rem (64px) */
        max-width: 100%;
        width: 100%;
    }

    /* Company profile specific fixes */
    .company-hero {
        padding: 0 var(--space-2) !important; /* 16px instead of 4rem */
        max-width: 100%;
        width: 100%;
    }

    .company-content {
        padding: var(--space-2) var(--space-2) !important; /* 16px all around */
        max-width: 100%;
        width: 100%;
    }

    /* Company section padding */
    .company-section {
        padding: var(--space-2) !important; /* 16px instead of 32px */
        margin-bottom: var(--space-2);
    }

    /* Breadcrumb fixes */
    .breadcrumb,
    .company-breadcrumb,
    nav[aria-label="Breadcrumb"] {
        padding: var(--space-1) var(--space-2) !important;
        font-size: 0.75rem;
        gap: 0.25rem;
        flex-wrap: wrap;
        word-break: break-word;
        overflow-wrap: break-word;
    }

    .company-breadcrumb a,
    .company-breadcrumb span {
        word-break: break-word;
        overflow-wrap: break-word;
    }

    /* Titles - prevent overflow */
    h1,
    .company-title {
        font-size: clamp(1.5rem, 5vw, 2rem) !important;
        word-break: break-word;
        overflow-wrap: break-word;
        line-height: 1.2;
        margin-bottom: var(--space-2);
    }

    h2,
    .section-title {
        font-size: clamp(1.25rem, 4vw, 1.5rem) !important;
        word-break: break-word;
        overflow-wrap: break-word;
    }

    /* Tagline and subtitles */
    .company-tagline,
    .subtitle {
        font-size: 0.875rem !important;
        word-break: break-word;
        overflow-wrap: break-word;
    }

    /* ========================================
       CATEGORY BADGES - CRITICAL FIX
       ======================================== */

    .category-badges {
        display: flex;
        flex-wrap: wrap;
        gap: var(--space-1);
        width: 100%;
        max-width: 100%;
    }

    .category-badge,
    .company-category {
        flex: 0 1 auto; /* Allow badges to shrink */
        max-width: 100%;
        word-break: break-word;
        overflow-wrap: break-word;
        font-size: 0.75rem !important;
        padding: var(--space-1) var(--space-2) !important;
        white-space: normal; /* Allow text wrapping */
        line-height: 1.3;
    }

    /* Info grid badges container */
    .info-item-full {
        grid-column: 1 / -1;
        max-width: 100%;
    }

    .info-item-full .category-badges {
        max-width: 100%;
        overflow-x: hidden;
    }

    /* ========================================
       GRID LAYOUTS - RESPONSIVE FIXES
       ======================================== */

    /* Company metrics grid */
    .company-metrics {
        grid-template-columns: 1fr !important; /* Single column on mobile */
        gap: var(--space-2);
        width: 100%;
        max-width: 100%;
    }

    /* Metric cards */
    .metric-card {
        width: 100%;
        max-width: 100%;
        padding: var(--space-2);
    }

    /* Info grid - single column */
    .info-grid {
        grid-template-columns: 1fr !important;
        gap: var(--space-2);
        width: 100%;
        max-width: 100%;
    }

    .info-item {
        width: 100%;
        max-width: 100%;
        padding: var(--space-2);
    }

    /* Related companies grid */
    .related-companies {
        grid-template-columns: 1fr !important;
        gap: var(--space-2);
        width: 100%;
        max-width: 100%;
    }

    .related-company {
        width: 100%;
        max-width: 100%;
        padding: var(--space-2);
    }

    /* Companies grid on homepage */
    .companies-grid {
        grid-template-columns: 1fr !important;
        gap: var(--space-2);
        width: 100%;
        max-width: 100%;
        padding: 0;
    }

    .company-card {
        width: 100%;
        max-width: 100%;
        padding: var(--space-2);
    }

    /* Stats grid */
    .stats,
    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: var(--space-2);
        width: 100%;
        max-width: 100%;
    }

    .stat-card {
        width: 100%;
        max-width: 100%;
        padding: var(--space-2);
    }

    /* ========================================
       SEARCH AND FILTER FIXES
       ======================================== */

    .search-container {
        flex-direction: column;
        gap: var(--space-2);
        width: 100%;
        max-width: 100%;
        padding: 0;
    }

    .search-box {
        width: 100%;
        max-width: 100%;
    }

    input[type="text"],
    select {
        width: 100%;
        max-width: 100%;
        font-size: 16px; /* Prevent iOS zoom */
        min-height: 48px; /* Touch target size */
    }

    /* Filter buttons */
    .filters {
        flex-direction: column;
        gap: var(--space-2);
        width: 100%;
        max-width: 100%;
    }

    .filter-btn {
        width: 100%;
        max-width: 100%;
        text-align: center;
        padding: var(--space-2);
        min-height: 48px;
    }

    /* ========================================
       BUTTONS AND LINKS
       ======================================== */

    .company-website,
    .back-to-directory,
    .compare-button,
    .contact-button,
    .nav-link {
        width: 100%;
        max-width: 100%;
        text-align: center;
        justify-content: center;
        padding: var(--space-2) var(--space-3);
        min-height: 48px;
        font-size: 1rem;
        word-break: break-word;
        overflow-wrap: break-word;
    }

    /* ========================================
       FOOTER FIXES
       ======================================== */

    .footer-grid {
        grid-template-columns: 1fr !important;
        gap: var(--space-3);
        width: 100%;
        max-width: 100%;
    }

    .footer-container {
        padding: var(--space-4) var(--space-2) var(--space-3);
        width: 100%;
        max-width: 100%;
    }

    .footer-bottom {
        flex-direction: column;
        gap: var(--space-2);
        text-align: center;
        width: 100%;
        max-width: 100%;
    }

    .footer-copyright {
        font-size: 0.75rem;
        word-break: break-word;
        overflow-wrap: break-word;
    }

    .footer-link,
    .footer-scroll-top {
        width: 100%;
        max-width: 100%;
        text-align: center;
        justify-content: center;
        min-height: 48px;
    }

    /* ========================================
       TEXT AND CONTENT FIXES
       ======================================== */

    .company-description,
    .info-content,
    .page-content {
        word-break: break-word;
        overflow-wrap: break-word;
        width: 100%;
        max-width: 100%;
    }

    .company-description p,
    .info-content p,
    .page-content p {
        word-break: break-word;
        overflow-wrap: break-word;
        font-size: 0.9rem;
        line-height: 1.6;
    }

    /* Lists */
    .company-description ul,
    .company-description ol {
        padding-left: var(--space-3);
        margin: var(--space-2) 0;
        width: 100%;
        max-width: 100%;
    }

    .company-description li {
        word-break: break-word;
        overflow-wrap: break-word;
        margin-bottom: var(--space-1);
    }

    /* ========================================
       TABLES - MOBILE OPTIMIZATION
       ======================================== */

    table {
        display: block;
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 0;
    }

    table thead,
    table tbody,
    table tr,
    table th,
    table td {
        display: block;
        width: 100%;
        max-width: 100%;
    }

    table tr {
        margin-bottom: var(--space-2);
        border: 1px solid var(--border-subtle);
        border-radius: var(--radius-sm);
        padding: var(--space-2);
    }

    table th {
        position: absolute;
        left: -9999px;
    }

    table td {
        position: relative;
        padding-left: 50%;
        text-align: right;
        word-break: break-word;
        overflow-wrap: break-word;
    }

    table td::before {
        content: attr(data-label);
        position: absolute;
        left: var(--space-2);
        width: 45%;
        text-align: left;
        font-weight: 600;
        color: var(--text-secondary);
    }

    /* ========================================
       IMAGE AND MEDIA FIXES
       ======================================== */

    img,
    video,
    iframe,
    embed,
    object {
        max-width: 100%;
        height: auto;
    }

    /* Ad containers */
    .ad-banner,
    .footer-ad-section,
    .in-feed-ad {
        max-width: 100%;
        width: 100%;
        overflow: hidden;
        margin-left: 0;
        margin-right: 0;
    }

    /* ========================================
       ANIMATIONS - DISABLE ON MOBILE FOR PERFORMANCE
       ======================================== */

    @media (prefers-reduced-motion: reduce) {
        *,
        *::before,
        *::after {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
        }
    }

    /* Disable complex animations on mobile for performance */
    .company-card,
    .metric-card,
    .stat-card,
    .info-item {
        transition: none;
    }

    .company-card:hover,
    .metric-card:hover,
    .stat-card:hover {
        transform: none;
    }
}

/* ========================================
   TABLET BREAKPOINT: 481px - 768px
   ======================================== */

@media (min-width: 481px) and (max-width: 768px) {
    body {
        padding: var(--space-2);
    }

    .container,
    .company-hero {
        padding: 0 var(--space-3); /* 24px */
    }

    .company-content {
        padding: var(--space-3);
    }

    .company-section {
        padding: var(--space-3);
    }

    /* 2-column grids on tablets */
    .company-metrics {
        grid-template-columns: repeat(2, 1fr);
    }

    .companies-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .stats,
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Category badges can wrap */
    .category-badges {
        flex-wrap: wrap;
        gap: var(--space-2);
    }

    .category-badge {
        flex: 0 1 auto;
        white-space: nowrap;
    }
}

/* ========================================
   LANDSCAPE MOBILE: max-height 480px
   ======================================== */

@media (max-height: 480px) and (orientation: landscape) {
    .company-header {
        padding: var(--space-2) 0;
    }

    .company-metrics {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-2);
    }

    h1,
    .company-title {
        font-size: 1.5rem !important;
        margin-bottom: var(--space-1);
    }
}

/* ========================================
   UTILITIES - MOBILE HELPERS
   ======================================== */

/* Mobile-only visibility */
@media (max-width: 480px) {
    .hide-mobile {
        display: none !important;
    }

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

/* Tablet-only visibility */
@media (min-width: 481px) and (max-width: 768px) {
    .hide-tablet {
        display: none !important;
    }

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

/* Desktop-only visibility */
@media (min-width: 769px) {
    .hide-desktop {
        display: none !important;
    }

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

    .show-mobile,
    .show-tablet {
        display: none !important;
    }
}

/* ========================================
   ACCESSIBILITY IMPROVEMENTS FOR MOBILE
   ======================================== */

@media (max-width: 480px) {
    /* Larger touch targets */
    a,
    button,
    input,
    select,
    textarea,
    [role="button"],
    [tabindex]:not([tabindex="-1"]) {
        min-height: 48px;
        min-width: 48px;
    }

    /* Better focus indicators on mobile */
    *:focus-visible {
        outline: 3px solid var(--accent-orange) !important;
        outline-offset: 2px;
    }

    /* Increase font size for readability */
    body {
        font-size: 16px;
    }

    p,
    li,
    span {
        line-height: 1.6;
    }
}

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

@media print {
    body {
        overflow-x: visible;
        width: auto;
    }

    .container,
    .company-profile-container {
        max-width: none;
        padding: 0;
    }

    .no-print {
        display: none !important;
    }
}
