/**
 * Mobile Optimization CSS
 * 
 * Ensures mobile-friendly design with:
 * - Responsive layout (320px - 2560px)
 * - Minimum touch target size (48x48px)
 * - Minimum font size (16px for body text)
 * - No horizontal scrolling
 * - Mobile-optimized navigation
 * 
 * Requirements: 4.1, 4.2, 4.3, 4.4, 4.5, 4.6, 4.7, 4.8
 */

/* ===================================
   Base Mobile Optimization
   =================================== */

/* Prevent horizontal scrolling */
html, body {
    overflow-x: hidden;
    max-width: 100%;
}

/* Box-sizing for all elements */
*, *::before, *::after {
    box-sizing: border-box;
    max-width: 100%;
}

/* Responsive media elements */
img, video, iframe, embed, object {
    max-width: 100%;
    height: auto;
}

/* Base font size - minimum 16px for body text */
html {
    font-size: 16px;
}

body {
    font-size: 1rem; /* 16px */
    line-height: 1.5;
    -webkit-text-size-adjust: 100%; /* Prevent iOS auto-zoom */
}

/* ===================================
   Touch Target Sizes (Minimum 48x48px)
   =================================== */

/* Buttons */
button, 
.btn, 
input[type="submit"], 
input[type="button"], 
input[type="reset"] {
    min-width: 48px;
    min-height: 48px;
    padding: 12px 24px;
    cursor: pointer;
    font-size: 1rem; /* 16px */
}

/* Links */
a {
    min-height: 44px; /* Slightly smaller for inline links */
    display: inline-block;
    padding: 8px 12px;
}

/* Navigation links - larger touch targets */
nav a,
.nav-link,
.menu-item {
    min-height: 48px;
    padding: 12px 16px;
    display: inline-block;
}

/* Form inputs */
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="url"],
input[type="search"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
    min-height: 48px;
    padding: 12px;
    font-size: 1rem; /* 16px - prevents iOS auto-zoom */
    border-radius: 4px;
}

/* Textarea specific */
textarea {
    min-height: 120px;
}

/* Icon buttons */
.icon-button,
.icon-link {
    width: 48px;
    height: 48px;
    padding: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Checkbox and radio - increase clickable area */
input[type="checkbox"],
input[type="radio"] {
    width: 24px;
    height: 24px;
    margin: 12px;
}

/* Labels for checkbox/radio - increase touch area */
label {
    min-height: 48px;
    display: inline-flex;
    align-items: center;
    padding: 8px 0;
    cursor: pointer;
}

/* ===================================
   Mobile Navigation
   =================================== */

/* Mobile menu toggle button */
#mobileMenuBtn {
    min-width: 48px;
    min-height: 48px;
    padding: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Mobile menu items */
#mobileMenu a {
    min-height: 48px;
    padding: 16px 24px;
    display: block;
    width: 100%;
}

/* Ensure adequate spacing between menu items */
#mobileMenu .flex-col > * {
    margin: 8px 0;
}

/* ===================================
   Responsive Typography
   =================================== */

/* Headings - maintain hierarchy */
h1 {
    font-size: clamp(2rem, 5vw, 2.5rem); /* 32px - 40px */
    line-height: 1.2;
}

h2 {
    font-size: clamp(1.75rem, 4vw, 2rem); /* 28px - 32px */
    line-height: 1.3;
}

h3 {
    font-size: clamp(1.5rem, 3.5vw, 1.75rem); /* 24px - 28px */
    line-height: 1.4;
}

h4 {
    font-size: clamp(1.25rem, 3vw, 1.5rem); /* 20px - 24px */
    line-height: 1.4;
}

h5 {
    font-size: clamp(1.125rem, 2.5vw, 1.25rem); /* 18px - 20px */
    line-height: 1.5;
}

h6 {
    font-size: clamp(1rem, 2vw, 1.125rem); /* 16px - 18px */
    line-height: 1.5;
}

/* Small text - minimum 14px */
small, .small, .caption {
    font-size: 0.875rem; /* 14px */
}

/* ===================================
   Responsive Breakpoints
   =================================== */

/* Mobile Small (320px - 374px) */
@media (min-width: 320px) {
    .container {
        width: 100%;
        padding: 0 16px;
    }
}

/* Mobile (375px - 424px) */
@media (min-width: 375px) {
    .container {
        padding: 0 20px;
    }
}

/* Mobile Large (425px - 767px) */
@media (min-width: 425px) {
    .container {
        padding: 0 24px;
    }
}

/* Tablet (768px - 1023px) */
@media (min-width: 768px) {
    .container {
        max-width: 720px;
        margin: 0 auto;
        padding: 0 32px;
    }
}

/* Laptop (1024px - 1439px) */
@media (min-width: 1024px) {
    .container {
        max-width: 960px;
        padding: 0 40px;
    }
}

/* Desktop (1440px - 2559px) */
@media (min-width: 1440px) {
    .container {
        max-width: 1200px;
        padding: 0 48px;
    }
}

/* Desktop Large (2560px+) */
@media (min-width: 2560px) {
    .container {
        max-width: 1600px;
        padding: 0 64px;
    }
}

/* ===================================
   Mobile-Specific Utilities
   =================================== */

/* Hide on mobile */
@media (max-width: 767px) {
    .hide-mobile {
        display: none !important;
    }
}

/* Show only on mobile */
@media (min-width: 768px) {
    .show-mobile {
        display: none !important;
    }
}

/* Stack elements on mobile */
@media (max-width: 767px) {
    .stack-mobile {
        flex-direction: column !important;
    }
    
    .stack-mobile > * {
        width: 100% !important;
        margin: 8px 0 !important;
    }
}

/* ===================================
   Prevent Common Mobile Issues
   =================================== */

/* Prevent text overflow */
p, li, td, th {
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

/* Prevent pre/code overflow */
pre, code {
    max-width: 100%;
    overflow-x: auto;
    word-wrap: break-word;
    white-space: pre-wrap;
}

/* Responsive tables */
@media (max-width: 767px) {
    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
}

/* Prevent absolute positioned elements from causing overflow */
.relative-container {
    position: relative;
    overflow: hidden;
}

/* ===================================
   Mobile Performance Optimizations
   =================================== */

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* Optimize animations for mobile */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Hardware acceleration for animations */
.animate {
    transform: translateZ(0);
    backface-visibility: hidden;
    perspective: 1000px;
}

/* ===================================
   Accessibility Enhancements
   =================================== */

/* Focus indicators for keyboard navigation */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

/* Skip to main content link */
.skip-to-main {
    position: absolute;
    top: -40px;
    left: 0;
    background: #000;
    color: #fff;
    padding: 8px 16px;
    text-decoration: none;
    z-index: 100;
}

.skip-to-main:focus {
    top: 0;
}

/* ===================================
   Mobile Menu Enhancements
   =================================== */

/* Ensure mobile menu is accessible */
#mobileMenu {
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* Prevent body scroll when menu is open */
body.menu-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
}

/* Mobile menu overlay for better UX */
.mobile-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 49;
    display: none;
}

.mobile-menu-overlay.active {
    display: block;
}

/* ===================================
   Touch-Friendly Spacing
   =================================== */

/* Minimum spacing between interactive elements */
.touch-target {
    margin: 8px;
}

/* Button groups - ensure spacing */
.button-group button,
.button-group a {
    margin: 8px;
}

/* Form field spacing */
.form-group {
    margin-bottom: 16px;
}

/* ===================================
   Mobile-Optimized Images
   =================================== */

/* Lazy loading support */
img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s;
}

img[loading="lazy"].loaded {
    opacity: 1;
}

/* Responsive images */
.responsive-img {
    width: 100%;
    height: auto;
    display: block;
}

/* ===================================
   Print Styles (Mobile-Friendly)
   =================================== */

@media print {
    /* Hide navigation and non-essential elements */
    nav,
    #mobileMenu,
    #mobileMenuBtn,
    .no-print {
        display: none !important;
    }
    
    /* Optimize for print */
    body {
        font-size: 12pt;
        line-height: 1.5;
        color: #000;
        background: #fff;
    }
    
    /* Prevent page breaks inside elements */
    h1, h2, h3, h4, h5, h6,
    p, li, blockquote {
        page-break-inside: avoid;
    }
}
