/* ========================================
   iOS & Mobile Safari Compatibility Fixes
   ======================================== */

/* Prevent text size adjustment on orientation change (iOS Safari bug) */
html {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Smooth scrolling for iOS */
html {
    -webkit-overflow-scrolling: touch;
}

/* Fix iOS Safari bottom bar height issues with 100vh */
body {
    min-height: 100vh;
    /* Support for iOS Safari */
    min-height: -webkit-fill-available;
}

html {
    height: -webkit-fill-available;
}

/* Prevent input zoom on iOS (inputs < 16px cause zoom) */
input, select, textarea, button {
    font-size: 16px !important;
}

/* Better touch targets (iOS Human Interface Guidelines: minimum 44x44px) */
.btn,
.nav-menu a,
.mobile-menu-toggle,
.menu-toggle,
button,
a[href^="tel:"] {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Disable tap highlight on iOS (use custom hover states instead) */
* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* Allow text selection for inputs and content */
input, textarea, p, span, div, h1, h2, h3, h4, h5, h6 {
    -webkit-touch-callout: default;
}

/* Fix iOS Safari sticky positioning */
.navbar,
.main-nav,
.emergency-banner {
    position: -webkit-sticky;
    position: sticky;
}

/* Improve iOS scroll performance */
.nav-menu,
.blog-grid,
.footer-content {
    -webkit-overflow-scrolling: touch;
}

/* Fix iOS Safari border-radius clipping issues */
.blog-card,
.service-card,
.btn,
.form-group input,
.form-group select,
.form-group textarea {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* iOS Safe Area Insets (for iPhone X and newer with notch) */
@supports (padding: env(safe-area-inset-top)) {
    body {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
    
    .navbar,
    .main-nav {
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
    }
    
    .emergency-banner {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
}

/* Remove default iOS button styling */
button,
input[type="submit"],
input[type="button"],
.btn {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    border-radius: 8px;
}

/* Fix iOS Safari input shadows */
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
textarea,
select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* Prevent iOS from adding blue link color to phone numbers */
a[href^="tel:"] {
    color: inherit;
    text-decoration: none;
}

/* Fix iOS Safari flexbox bugs */
.nav-menu,
.footer-content,
.blog-grid,
.service-grid {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
}

/* Better iOS form controls */
input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--bright-orange);
    box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.2);
}

/* iOS active states for buttons */
.btn:active,
button:active {
    transform: scale(0.98);
    opacity: 0.9;
}

/* Fix iOS Safari vh units in modals/popups */
.modal,
.popup {
    height: 100vh;
    height: -webkit-fill-available;
}

/* Prevent iOS Safari from resizing text in landscape */
@media screen and (orientation: landscape) {
    html, body {
        -webkit-text-size-adjust: 100%;
    }
}

/* iOS-specific media queries for better mobile experience */
@media screen and (max-width: 768px) {
    /* Larger touch targets on mobile */
    .nav-menu a {
        padding: 1rem 1.5rem;
    }
    
    /* Prevent accidental zoom on double-tap */
    * {
        touch-action: manipulation;
    }
    
    /* Better spacing for iOS keyboard */
    form {
        margin-bottom: 300px;
    }
}

/* iPhone X, XS, 11 Pro, 12 Mini, 13 Mini */
@media only screen 
  and (device-width: 375px) 
  and (device-height: 812px) 
  and (-webkit-device-pixel-ratio: 3) {
    .emergency-banner {
        padding-top: 44px; /* Status bar height */
    }
}

/* iPhone XR, 11, 12, 12 Pro, 13, 13 Pro, 14 */
@media only screen 
  and (device-width: 390px) 
  and (device-height: 844px) 
  and (-webkit-device-pixel-ratio: 3) {
    .emergency-banner {
        padding-top: 47px; /* Status bar height */
    }
}

/* iPhone 12 Pro Max, 13 Pro Max, 14 Plus */
@media only screen 
  and (device-width: 428px) 
  and (device-height: 926px) 
  and (-webkit-device-pixel-ratio: 3) {
    .emergency-banner {
        padding-top: 47px; /* Status bar height */
    }
}

/* iPhone 14 Pro, 15 Pro */
@media only screen 
  and (device-width: 393px) 
  and (device-height: 852px) 
  and (-webkit-device-pixel-ratio: 3) {
    .emergency-banner {
        padding-top: 54px; /* Dynamic Island height */
    }
}

/* iPhone 14 Pro Max, 15 Pro Max */
@media only screen 
  and (device-width: 430px) 
  and (device-height: 932px) 
  and (-webkit-device-pixel-ratio: 3) {
    .emergency-banner {
        padding-top: 54px; /* Dynamic Island height */
    }
}

/* Optimize images for iOS Retina displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    img {
        image-rendering: -webkit-optimize-contrast;
    }
}

/* Fix iOS Safari video playback issues */
video {
    -webkit-playsinline: true;
    playsinline: true;
}

/* Improve iOS font rendering */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* iOS momentum scrolling for containers */
.scrollable-content {
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
}

/* Fix iOS Safari position: fixed issues */
@supports (-webkit-overflow-scrolling: touch) {
    .navbar,
    .main-nav {
        position: -webkit-sticky;
        position: sticky;
        top: 0;
        z-index: 1000;
    }
}

/* Better iOS click delay removal (faster taps) */
a, button, input, select, textarea, label {
    -ms-touch-action: manipulation;
    touch-action: manipulation;
}
