/**
 * Mobile Optimization - 100% Mobile Ready
 * Ensures perfect mobile experience across all devices
 */

/* ========================================
   MOBILE-FIRST BASE STYLES
   ======================================== */

/* Touch-friendly tap targets (minimum 44x44px) */
a, button, input, select, textarea {
    min-height: 44px;
    min-width: 44px;
}

/* Prevent text size adjustment on orientation change */
html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Smooth scrolling for iOS */
body {
    -webkit-overflow-scrolling: touch;
}

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

/* ========================================
   RESPONSIVE IMAGES & MEDIA
   ======================================== */

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

/* Responsive embeds */
.embed-responsive {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 */
    height: 0;
    overflow: hidden;
}

.embed-responsive iframe,
.embed-responsive object,
.embed-responsive embed {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* ========================================
   MOBILE NAVIGATION
   ======================================== */

@media (max-width: 768px) {
    /* Hamburger menu */
    .main-nav__toggle {
        display: block !important;
        width: 44px;
        height: 44px;
        padding: 10px;
        background: none;
        border: none;
        cursor: pointer;
        z-index: 1001;
    }
    
    .main-nav__toggle span {
        display: block;
        width: 24px;
        height: 2px;
        background: var(--cyan);
        margin: 5px 0;
        transition: 0.3s;
    }
    
    .main-nav__toggle.active span:nth-child(1) {
        transform: rotate(-45deg) translate(-5px, 6px);
    }
    
    .main-nav__toggle.active span:nth-child(2) {
        opacity: 0;
    }
    
    .main-nav__toggle.active span:nth-child(3) {
        transform: rotate(45deg) translate(-5px, -6px);
    }
    
    /* Mobile menu */
    .main-nav__links {
        position: fixed;
        top: 0;
        right: -100%;
        width: 80%;
        max-width: 320px;
        height: 100vh;
        background: rgba(10, 14, 39, 0.98);
        backdrop-filter: blur(20px);
        padding: 80px 2rem 2rem;
        transition: right 0.3s ease;
        z-index: 1000;
        overflow-y: auto;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .main-nav__links.active {
        right: 0;
    }
    
    .main-nav__links a {
        width: 100%;
        padding: 1rem 0;
        font-size: 1.125rem;
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }
    
    /* Mobile overlay */
    .mobile-overlay {
        position: fixed;
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
        height: 100vh;
        background: rgba(0, 0, 0, 0.8);
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
        z-index: 999;
    }
    
    .mobile-overlay.active {
        opacity: 1;
        visibility: visible;
    }
}

/* ========================================
   MOBILE TYPOGRAPHY
   ======================================== */

@media (max-width: 768px) {
    /* Responsive headings */
    h1, .section__heading {
        font-size: clamp(1.75rem, 8vw, 2.5rem) !important;
        line-height: 1.2;
    }
    
    h2 {
        font-size: clamp(1.5rem, 6vw, 2rem) !important;
    }
    
    h3 {
        font-size: clamp(1.25rem, 5vw, 1.5rem) !important;
    }
    
    /* Readable body text */
    body, p, .section__subhead {
        font-size: 1rem;
        line-height: 1.6;
    }
    
    /* Prevent text overflow */
    * {
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
}

/* ========================================
   MOBILE LAYOUT
   ======================================== */

@media (max-width: 768px) {
    /* Container padding */
    .container {
        padding-left: 1.25rem !important;
        padding-right: 1.25rem !important;
    }
    
    /* Section spacing */
    .section {
        padding: 3rem 0 !important;
    }
    
    /* Hero adjustments */
    .hero {
        padding: 2rem 0 !important;
        min-height: auto !important;
    }
    
    .hero__content {
        text-align: center;
    }
    
    /* Grid to single column */
    .hero--split,
    .features-grid,
    .pricing-grid,
    .blog-grid,
    .lab-grid,
    .products-grid {
        grid-template-columns: 1fr !important;
        gap: 1.5rem !important;
    }
    
    /* Cards */
    .card, .pricing-card, .feature-card {
        padding: 1.5rem !important;
    }
    
    /* Buttons */
    .cta-button, .btn {
        width: 100%;
        text-align: center;
        padding: 1rem 1.5rem !important;
    }
    
    /* Button groups */
    .button-group, .hero__cta {
        flex-direction: column;
        gap: 1rem;
        width: 100%;
    }
    
    .button-group > *, .hero__cta > * {
        width: 100%;
    }
}

/* ========================================
   MOBILE FORMS
   ======================================== */

@media (max-width: 768px) {
    /* Form inputs */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="url"],
    input[type="password"],
    textarea,
    select {
        width: 100%;
        padding: 1rem;
        font-size: 16px; /* Prevents iOS zoom */
        -webkit-appearance: none;
        appearance: none;
    }
    
    /* Form rows */
    .contact-form__row,
    .form-row {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }
    
    /* Labels */
    label {
        font-size: 0.875rem;
    }
}

/* ========================================
   MOBILE TABLES
   ======================================== */

@media (max-width: 768px) {
    /* Responsive tables */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }
    
    /* Comparison table */
    .comparison-table {
        font-size: 0.875rem;
    }
    
    .comparison-table th,
    .comparison-table td {
        padding: 0.75rem 0.5rem !important;
    }
}

/* ========================================
   MOBILE NAVIGATION DROPDOWN
   ======================================== */

@media (max-width: 768px) {
    .nav-dropdown__menu {
        position: static !important;
        width: 100% !important;
        margin-top: 0 !important;
        margin-bottom: 0.5rem;
        transform: none !important;
        max-height: 0;
        overflow: hidden;
        opacity: 1 !important;
        visibility: visible !important;
        padding: 0 !important;
        border: none !important;
        background: transparent !important;
        box-shadow: none !important;
        transition: max-height 0.3s ease, padding 0.3s ease;
    }
    
    .nav-dropdown__trigger[aria-expanded="true"] + .nav-dropdown__menu {
        max-height: 600px;
        padding: 0.5rem 0 !important;
    }
    
    .nav-dropdown__item {
        padding: 0.75rem 1rem !important;
        margin-left: 1rem;
        border-left: 2px solid rgba(0, 255, 246, 0.2);
    }
    
    .nav-dropdown__trigger {
        width: 100%;
        justify-content: space-between;
        padding: 1rem 0 !important;
    }
}

/* ========================================
   MOBILE FOOTER
   ======================================== */

@media (max-width: 768px) {
    .site-footer__content {
        grid-template-columns: 1fr !important;
        gap: 2rem;
        text-align: center;
    }
    
    .site-footer__col {
        align-items: center;
    }
    
    .site-footer__links {
        flex-direction: column;
        gap: 1rem;
    }
}

/* ========================================
   MOBILE PRICING
   ======================================== */

@media (max-width: 768px) {
    .pricing-grid {
        padding: 0 1rem;
    }
    
    .pricing-card {
        margin-bottom: 1.5rem;
    }
    
    .pricing-card__price {
        font-size: 2.5rem !important;
    }
    
    .savings-columns {
        grid-template-columns: 1fr !important;
        gap: 2rem;
    }
}

/* ========================================
   MOBILE BLOG
   ======================================== */

@media (max-width: 768px) {
    .blog-post__header {
        padding: 2rem 1.25rem !important;
    }
    
    .blog-post__content {
        padding: 2rem 1.25rem !important;
    }
    
    .blog-post__content img {
        margin: 1.5rem 0;
    }
    
    .blog-post__content pre {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ========================================
   MOBILE CLIENT PORTAL
   ======================================== */

@media (max-width: 768px) {
    .client-nav {
        width: 100% !important;
        height: auto !important;
        position: relative !important;
    }
    
    .dashboard-main {
        margin-left: 0 !important;
        padding: 1rem !important;
    }
    
    .dashboard-header h1 {
        font-size: 1.5rem !important;
    }
    
    .products-grid,
    .widgets-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ========================================
   MOBILE UTILITIES
   ======================================== */

@media (max-width: 768px) {
    /* Hide on mobile */
    .hide-mobile {
        display: none !important;
    }
    
    /* Show only on mobile */
    .show-mobile {
        display: block !important;
    }
    
    /* Text alignment */
    .text-center-mobile {
        text-align: center !important;
    }
    
    /* Spacing */
    .mt-mobile-2 { margin-top: 2rem !important; }
    .mb-mobile-2 { margin-bottom: 2rem !important; }
    .p-mobile-1 { padding: 1rem !important; }
}

/* ========================================
   MOBILE PERFORMANCE
   ======================================== */

@media (max-width: 768px) {
    /* Reduce animations 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;
        }
    }
    
    /* Optimize background canvas */
    #bg-canvas {
        opacity: 0.3;
    }
    
    /* Reduce blur effects */
    .backdrop-blur {
        backdrop-filter: blur(5px) !important;
    }
}

/* ========================================
   LANDSCAPE ORIENTATION
   ======================================== */

@media (max-width: 768px) and (orientation: landscape) {
    .hero {
        min-height: auto !important;
        padding: 1.5rem 0 !important;
    }
    
    .section {
        padding: 2rem 0 !important;
    }
}

/* ========================================
   SMALL MOBILE (< 375px)
   ======================================== */

@media (max-width: 374px) {
    .container {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
    
    h1, .section__heading {
        font-size: 1.5rem !important;
    }
    
    .pricing-card__price {
        font-size: 2rem !important;
    }
}

/* ========================================
   TABLET (768px - 1024px)
   ======================================== */

@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        padding-left: 2rem;
        padding-right: 2rem;
    }
    
    .pricing-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    .features-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* ========================================
   TOUCH DEVICE OPTIMIZATIONS
   ======================================== */

@media (hover: none) and (pointer: coarse) {
    /* Remove hover effects on touch devices */
    *:hover {
        transform: none !important;
    }
    
    /* Larger tap targets */
    a, button {
        min-height: 48px;
        min-width: 48px;
    }
    
    /* Prevent double-tap zoom */
    a, button, input, select {
        touch-action: manipulation;
    }
}

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

@supports (-webkit-touch-callout: none) {
    /* iOS Safari safe area */
    body {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    /* Fix iOS input zoom */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    select,
    textarea {
        font-size: 16px !important;
    }
    
    /* Fix iOS sticky hover */
    * {
        -webkit-tap-highlight-color: transparent;
    }
}

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

@media (max-width: 768px) {
    /* Fix Android viewport height */
    .hero,
    .full-height {
        min-height: 100vh;
        min-height: -webkit-fill-available;
    }
}

/* ========================================
   ACCESSIBILITY ON MOBILE
   ======================================== */

@media (max-width: 768px) {
    /* Focus visible */
    *:focus-visible {
        outline: 2px solid var(--cyan);
        outline-offset: 2px;
    }
    
    /* Skip to content link */
    .skip-to-content {
        position: absolute;
        top: -40px;
        left: 0;
        background: var(--cyan);
        color: var(--black);
        padding: 8px;
        text-decoration: none;
        z-index: 100;
    }
    
    .skip-to-content:focus {
        top: 0;
    }
}
