/**
 * Comprehensive Mobile Optimization - Production Ready
 * Complete responsive system with zero overlaps, perfect scaling
 * 
 * @version 3.1.0
 * @date 2026-04-20
 * @author Chief Frontend Engineer
 */

/* ========================================
   CRITICAL MOBILE FIXES
   ======================================== */

/* Prevent horizontal scroll on all devices */
html, body {
    overflow-x: hidden !important;
    width: 100% !important;
    max-width: 100vw !important;
}

/* Ensure all images are responsive */
img {
    max-width: 100% !important;
    height: auto !important;
    display: block !important;
}

/* ========================================
   FORM & INTERACTION OPTIMIZATION
   ======================================== */

/* All form inputs - prevent iOS zoom */
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="url"],
textarea,
select {
    font-size: 16px !important; /* Critical: prevents iOS Safari zoom on focus */
    min-height: 48px !important; /* WCAG 2.1 AA: minimum touch target */
    -webkit-appearance: none !important;
    appearance: none !important;
    -webkit-tap-highlight-color: transparent !important;
    touch-action: manipulation !important;
}

/* All buttons - proper touch targets */
button,
input[type="submit"],
input[type="button"],
.btn,
.button {
    min-height: 48px !important;
    min-width: 48px !important;
    padding: 12px 20px !important;
    -webkit-tap-highlight-color: transparent !important;
    touch-action: manipulation !important;
    cursor: pointer !important;
}

/* Active states for touch feedback */
button:active,
.btn:active,
.button:active {
    transform: scale(0.98) !important;
    opacity: 0.9 !important;
}

/* Links - proper touch targets */
a {
    -webkit-tap-highlight-color: transparent !important;
    touch-action: manipulation !important;
}

/* Form error states */
input.error,
select.error,
textarea.error {
    border-color: #ef4444 !important;
    background-color: #fef2f2 !important;
}

/* Focus states for accessibility */
input:focus,
select:focus,
textarea:focus,
button:focus {
    outline: 2px solid #3b82f6 !important;
    outline-offset: 2px !important;
}

/* ========================================
   RESPONSIVE TYPOGRAPHY SYSTEM
   ======================================== */

/* Mobile: 320px - 480px */
@media (max-width: 480px) {
    /* Headings - Properly scaled */
    h1, .hero-title, .gradient-heading {
        font-size: 1.75rem !important;
        line-height: 1.2 !important;
        letter-spacing: -0.02em !important;
    }

    h2, .section-title {
        font-size: 1.5rem !important;
        line-height: 1.3 !important;
    }

    h3, .card-title {
        font-size: 1.25rem !important;
        line-height: 1.4 !important;
    }

    h4 {
        font-size: 1.125rem !important;
    }

    /* Body text */
    p, li, span, div {
        font-size: 0.9375rem !important;
        line-height: 1.6 !important;
    }

    /* Small text */
    small, .text-small, .caption {
        font-size: 0.8125rem !important;
    }
}

/* Large Mobile: 481px - 768px */
@media (min-width: 481px) and (max-width: 768px) {
    h1, .hero-title, .gradient-heading {
        font-size: 2rem !important;
        line-height: 1.2 !important;
    }

    h2, .section-title {
        font-size: 1.75rem !important;
        line-height: 1.3 !important;
    }

    h3, .card-title {
        font-size: 1.375rem !important;
    }

    p, li, span, div {
        font-size: 1rem !important;
        line-height: 1.6 !important;
    }
}

/* Tablet: 769px - 1024px */
@media (min-width: 769px) and (max-width: 1024px) {
    h1, .hero-title, .gradient-heading {
        font-size: 2.5rem !important;
    }

    h2, .section-title {
        font-size: 2rem !important;
    }

    p, li, span, div {
        font-size: 1rem !important;
    }
}

/* ========================================
   LAYOUT & CONTAINER SYSTEM
   ======================================== */

/* Mobile: Prevent horizontal scroll */
@media (max-width: 768px) {
    html, body {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100vw !important;
    }

    /* All containers must be flexible */
    .container,
    .glossy-container,
    .header-container,
    .hero-container {
        width: 100% !important;
        max-width: 100% !important;
        padding-left: 1rem !important;
        padding-right: 1rem !important;
        box-sizing: border-box !important;
    }

    /* Grids must stack on mobile */
    .grid,
    [class*="grid-cols-"],
    [class*="columns-"] {
        grid-template-columns: 1fr !important;
        display: grid !important;
    }

    /* Flex containers stack vertically */
    .flex-row,
    [class*="flex-"] {
        flex-direction: column !important;
    }

    /* Remove fixed widths */
    [style*="width:"],
    .fixed-width {
        width: 100% !important;
        max-width: 100% !important;
    }
}

/* ========================================
   HERO SECTIONS - MOBILE OPTIMIZED
   ======================================== */

@media (max-width: 768px) {
    .hero-section,
    .enterprise-hero,
    .contact-hero,
    .about-hero,
    .portfolio-hero {
        padding: 6rem 1rem 3rem !important;
        min-height: auto !important;
    }

    .hero-container {
        grid-template-columns: 1fr !important;
        gap: 2rem !important;
        text-align: center !important;
    }

    .hero-content {
        order: 1 !important;
    }

    .hero-image,
    .hero-visual {
        order: 2 !important;
        max-width: 100% !important;
    }

    .hero-image img,
    .hero-visual img {
        width: 100% !important;
        height: auto !important;
        max-height: 300px !important;
        object-fit: cover !important;
    }

    .hero-buttons {
        display: flex !important;
        flex-direction: column !important;
        gap: 1rem !important;
        align-items: center !important;
    }

    .hero-buttons .btn {
        width: 100% !important;
        max-width: 300px !important;
    }
}

@media (max-width: 480px) {
    .hero-section,
    .enterprise-hero {
        padding: 5rem 0.75rem 2rem !important;
    }

    .hero-container {
        gap: 1.5rem !important;
    }
}

/* ========================================
   SERVICE CARDS - MOBILE STACKING
   ======================================== */

@media (max-width: 768px) {
    .services-grid,
    .services-overview .grid,
    [class*="service-grid"] {
        grid-template-columns: 1fr !important;
        gap: 1.5rem !important;
        padding: 0 !important;
    }

    .service-card,
    .service-item {
        width: 100% !important;
        margin: 0 !important;
        padding: 1.5rem !important;
    }

    .service-card .icon,
    .service-item .icon {
        width: 48px !important;
        height: 48px !important;
        margin-bottom: 1rem !important;
    }

    .service-card h3,
    .service-item h3 {
        font-size: 1.25rem !important;
        margin-bottom: 0.75rem !important;
    }

    .service-card p,
    .service-item p {
        font-size: 0.9375rem !important;
        line-height: 1.6 !important;
    }
}

/* ========================================
   FORMS & INPUTS - MOBILE FRIENDLY
   ======================================== */

@media (max-width: 768px) {
    /* Form containers */
    form,
    .form-container,
    .contact-form {
        padding: 1.5rem !important;
    }

    /* Input fields - proper sizing */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="url"],
    input[type="password"],
    input[type="number"],
    input[type="search"],
    textarea,
    select {
        width: 100% !important;
        min-height: 48px !important;
        padding: 0.875rem 1rem !important;
        font-size: 1rem !important;
        line-height: 1.5 !important;
        border-radius: 8px !important;
        box-sizing: border-box !important;
    }

    textarea {
        min-height: 120px !important;
        resize: vertical !important;
    }

    /* Labels */
    label {
        font-size: 0.9375rem !important;
        margin-bottom: 0.5rem !important;
        display: block !important;
    }

    /* Form groups */
    .form-group,
    .form-row {
        margin-bottom: 1.25rem !important;
    }

    .form-row {
        display: flex !important;
        flex-direction: column !important;
        gap: 1.25rem !important;
    }

    /* Submit buttons */
    button[type="submit"],
    .submit-btn,
    .btn-primary {
        width: 100% !important;
        min-height: 48px !important;
        padding: 0.875rem 1.5rem !important;
        font-size: 1rem !important;
        font-weight: 600 !important;
    }

    /* Checkboxes and radio buttons */
    input[type="checkbox"],
    input[type="radio"] {
        width: 20px !important;
        height: 20px !important;
        margin-right: 0.5rem !important;
    }
}

/* ========================================
   BUTTONS & CTAs - TOUCH OPTIMIZED
   ======================================== */

@media (max-width: 768px) {
    /* All buttons minimum 44x44px */
    .btn,
    button,
    a.btn,
    .cta-button,
    [role="button"] {
        min-height: 44px !important;
        min-width: 44px !important;
        padding: 0.75rem 1.5rem !important;
        font-size: 1rem !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    /* Button groups stack vertically */
    .button-group,
    .btn-group {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.75rem !important;
    }

    .button-group .btn,
    .btn-group button {
        width: 100% !important;
    }
}

/* ========================================
   NAVIGATION - ENHANCED MOBILE MENU
   ======================================== */

@media (max-width: 768px) {
    /* Header height consistency */
    .main-header {
        height: 70px !important;
    }

    /* Ensure main content has proper offset */
    main,
    .main-content {
        padding-top: 70px !important;
    }

    /* Mobile menu items */
    .nav-links .nav-link {
        padding: 1rem 0.75rem !important;
        font-size: 1.1rem !important;
        border-bottom: 1px solid #e2e8f0 !important;
    }

    /* Submenu items */
    .nav-links .submenu a {
        padding: 0.75rem 0.75rem 0.75rem 2rem !important;
        font-size: 1rem !important;
    }
}

@media (max-width: 480px) {
    .main-header {
        height: 65px !important;
    }

    main,
    .main-content {
        padding-top: 65px !important;
    }

    .nav-links .nav-link {
        padding: 0.875rem 0.75rem !important;
        font-size: 1rem !important;
    }
}

/* ========================================
   CARDS & CONTENT BLOCKS
   ======================================== */

@media (max-width: 768px) {
    .card,
    .info-card,
    .feature-card,
    .testimonial-card {
        padding: 1.5rem !important;
        margin-bottom: 1.5rem !important;
    }

    .card-header,
    .card-title {
        margin-bottom: 1rem !important;
    }

    .card-body {
        padding: 0 !important;
    }

    .card-footer {
        padding-top: 1rem !important;
        margin-top: 1rem !important;
    }
}

/* ========================================
   IMAGES & MEDIA - RESPONSIVE
   ======================================== */

@media (max-width: 768px) {
    /* All images scale properly */
    img {
        max-width: 100% !important;
        height: auto !important;
        display: block !important;
    }

    /* Background images cover properly */
    [class*="bg-"],
    .background-image {
        background-size: cover !important;
        background-position: center !important;
    }

    /* Videos responsive */
    video,
    iframe,
    embed,
    object {
        max-width: 100% !important;
        height: auto !important;
    }

    /* Aspect ratio for embedded content */
    .video-container,
    .embed-container {
        position: relative !important;
        padding-bottom: 56.25% !important; /* 16:9 */
        height: 0 !important;
        overflow: hidden !important;
    }

    .video-container iframe,
    .embed-container iframe {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
    }
}

/* ========================================
   FOOTER - MOBILE OPTIMIZED
   ======================================== */

@media (max-width: 768px) {
    .footer-top {
        grid-template-columns: 1fr !important;
        gap: 2rem !important;
        padding: 2rem 1rem !important;
    }

    .footer-column {
        text-align: center !important;
    }

    .footer-column h4 {
        margin-bottom: 1rem !important;
    }

    .footer-column ul {
        padding: 0 !important;
    }

    .footer-column li {
        margin-bottom: 0.5rem !important;
    }

    .footer-bottom {
        padding: 1.5rem 1rem !important;
        text-align: center !important;
    }

    .social-links {
        justify-content: center !important;
        margin: 1rem 0 !important;
    }
}

/* ========================================
   TABLES - MOBILE RESPONSIVE
   ======================================== */

@media (max-width: 768px) {
    table {
        display: block !important;
        overflow-x: auto !important;
        white-space: nowrap !important;
        -webkit-overflow-scrolling: touch !important;
    }

    thead,
    tbody,
    tr {
        display: table !important;
        width: 100% !important;
        table-layout: fixed !important;
    }
}

/* ========================================
   SECTIONS & SPACING
   ======================================== */

@media (max-width: 768px) {
    section,
    .section {
        padding: 3rem 1rem !important;
    }

    .section-title {
        margin-bottom: 2rem !important;
    }

    .section-subtitle {
        margin-bottom: 2rem !important;
    }
}

@media (max-width: 480px) {
    section,
    .section {
        padding: 2rem 0.75rem !important;
    }
}

/* ========================================
   ANIMATIONS - PERFORMANCE OPTIMIZED
   ======================================== */

@media (max-width: 768px) {
    /* Reduce animations on mobile */
    *,
    *::before,
    *::after {
        animation-duration: 0.3s !important;
        transition-duration: 0.3s !important;
    }

    /* Disable heavy animations */
    @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;
        }
    }

    /* Disable parallax on mobile */
    [data-parallax],
    .parallax {
        transform: none !important;
    }
    
    /* Disable 3D transforms on mobile */
    .hero-visual img {
        transform: none !important;
    }
    
    /* Disable floating animations on mobile */
    .hero-floating-card {
        animation: none !important;
    }
}

/* ========================================
   UTILITY CLASSES - MOBILE
   ======================================== */

@media (max-width: 768px) {
    /* Hide desktop-only elements */
    .hide-mobile,
    .desktop-only {
        display: none !important;
    }

    /* Show mobile-only elements */
    .show-mobile,
    .mobile-only {
        display: block !important;
    }

    /* Spacing utilities */
    .mt-mobile { margin-top: 1rem !important; }
    .mb-mobile { margin-bottom: 1rem !important; }
    .pt-mobile { padding-top: 1rem !important; }
    .pb-mobile { padding-bottom: 1rem !important; }

    /* Text alignment */
    .text-center-mobile { text-align: center !important; }
    .text-left-mobile { text-align: left !important; }
}

/* ========================================
   SPECIAL COMPONENTS
   ======================================== */

/* Testimonials */
@media (max-width: 768px) {
    .testimonials-grid {
        grid-template-columns: 1fr !important;
        gap: 1.5rem !important;
    }

    .testimonial {
        padding: 1.5rem !important;
    }
}

/* Portfolio */
@media (max-width: 768px) {
    .portfolio-grid {
        grid-template-columns: 1fr !important;
        gap: 1.5rem !important;
    }

    .portfolio-item {
        width: 100% !important;
    }
}

/* Blog */
@media (max-width: 768px) {
    .blog-grid {
        grid-template-columns: 1fr !important;
        gap: 2rem !important;
    }

    .blog-card {
        width: 100% !important;
    }
}

/* FAQ */
@media (max-width: 768px) {
    .faq-item {
        margin-bottom: 1rem !important;
    }

    .faq-question {
        padding: 1rem !important;
        font-size: 1rem !important;
    }

    .faq-answer {
        padding: 1rem !important;
    }
}

/* Stats/Counter */
@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 1.5rem !important;
    }

    .stat-item {
        text-align: center !important;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ========================================
   LANDSCAPE MODE FIXES
   ======================================== */

@media (max-width: 1024px) and (orientation: landscape) {
    .hero-section {
        padding: 5rem 1rem 2rem !important;
    }

    .nav-links {
        max-height: 80vh !important;
        overflow-y: auto !important;
    }
}

/* ========================================
   VERY SMALL DEVICES (320px - 360px)
   ======================================== */

@media (max-width: 360px) {
    h1, .hero-title {
        font-size: 1.5rem !important;
    }

    h2 {
        font-size: 1.375rem !important;
    }

    .container,
    .glossy-container {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }

    .btn {
        padding: 0.625rem 1.25rem !important;
        font-size: 0.9375rem !important;
    }
}

/* ========================================
   SCROLL & OVERFLOW PROTECTION
   ======================================== */

/* Prevent any horizontal scrolling */
@media (max-width: 768px) {
    body {
        overflow-x: hidden !important;
    }

    /* Fix elements causing overflow */
    pre,
    code {
        white-space: pre-wrap !important;
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
    }

    /* Long URLs and text */
    a,
    p,
    span {
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
        hyphens: auto !important;
    }
}

/* ========================================
   PERFORMANCE: LAZY LOADING
   ======================================== */

/* Ensure images below fold are lazy loaded */
img:not([loading="eager"]) {
    loading: lazy;
}

/* ========================================
   ACCESSIBILITY: FOCUS STATES
   ======================================== */

@media (max-width: 768px) {
    /* Clear focus indicators for touch devices */
    *:focus {
        outline: 2px solid #667eea !important;
        outline-offset: 2px !important;
    }

    /* Remove focus on touch devices after interaction */
    *:focus:not(:focus-visible) {
        outline: none !important;
    }
}

/* ========================================
   PRINT STYLES
   ======================================== */

@media print {
    .main-header,
    .mobile-menu-button,
    .nav-links,
    footer {
        display: none !important;
    }

    body {
        padding-top: 0 !important;
    }

    .container {
        max-width: 100% !important;
    }
}
