/* iOS and Safari Specific Enhancements */

/* Prevent rubber band scrolling on iOS */
html {
  position: fixed;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

body {
  position: fixed;
  height: 100%;
  width: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

/* iOS Safe Area Support */
.ios-safe-top {
  padding-top: env(safe-area-inset-top);
  padding-top: constant(safe-area-inset-top);
}

.ios-safe-bottom {
  padding-bottom: env(safe-area-inset-bottom);
  padding-bottom: constant(safe-area-inset-bottom);
}

/* iOS Notch Support */
@supports(padding: max(0px)) {
  .ios-header {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
}

/* Improved iOS Touch Response */
* {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

button, a, [role="button"] {
  -webkit-tap-highlight-color: rgba(0,0,0,0.1);
  touch-action: manipulation;
  cursor: pointer;
}

/* iOS Input Fixes */
input, textarea, select {
  font-size: 16px !important; /* Prevents zoom on focus */
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  border-radius: 0;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="url"],
input[type="search"],
textarea {
  font-size: 16px !important;
  -webkit-text-size-adjust: 100%;
}

/* iOS Keyboard Handling */
.ios-keyboard-open {
  height: calc(100vh - 260px);
  transition: height 0.3s ease;
}

/* iOS Momentum Scrolling */
.scroll-container {
  -webkit-overflow-scrolling: touch;
  overflow-y: auto;
  will-change: transform;
}

/* iOS Performance Optimizations */
.ios-gpu-accelerated {
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  -webkit-perspective: 1000;
  perspective: 1000;
}

/* Disable iOS Bounce Effect for Fixed Elements */
.ios-no-bounce {
  position: fixed;
  overflow: hidden;
  touch-action: none;
}

/* iOS Status Bar Handling */
@media screen and (device-width: 375px) and (device-height: 812px) and (-webkit-device-pixel-ratio: 3) {
  /* iPhone X/XS/11 Pro */
  .ios-status-bar-padding {
    padding-top: 44px;
  }
}

@media screen and (device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 2) {
  /* iPhone XR/11 */
  .ios-status-bar-padding {
    padding-top: 44px;
  }
}

@media screen and (device-width: 414px) and (device-height: 896px) and (-webkit-device-pixel-ratio: 3) {
  /* iPhone XS Max/11 Pro Max */
  .ios-status-bar-padding {
    padding-top: 44px;
  }
}

/* iOS PWA Splash Screens */
@media (device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2) {
  /* iPhone 5/SE */
}

@media (device-width: 375px) and (device-height: 667px) and (-webkit-device-pixel-ratio: 2) {
  /* iPhone 6/7/8/SE2 */
}

@media (device-width: 414px) and (device-height: 736px) and (-webkit-device-pixel-ratio: 3) {
  /* iPhone 6+/7+/8+ */
}

@media (device-width: 390px) and (device-height: 844px) and (-webkit-device-pixel-ratio: 3) {
  /* iPhone 12/13 Pro */
}

@media (device-width: 393px) and (device-height: 852px) and (-webkit-device-pixel-ratio: 3) {
  /* iPhone 14 Pro */
}

@media (device-width: 430px) and (device-height: 932px) and (-webkit-device-pixel-ratio: 3) {
  /* iPhone 14 Pro Max */
}

/* iPad Support */
@media (device-width: 768px) and (device-height: 1024px) {
  /* iPad */
  .ios-ipad-layout {
    max-width: 768px;
    margin: 0 auto;
  }
}

@media (device-width: 834px) and (device-height: 1194px) {
  /* iPad Pro 11" */
  .ios-ipad-layout {
    max-width: 834px;
    margin: 0 auto;
  }
}

@media (device-width: 1024px) and (device-height: 1366px) {
  /* iPad Pro 12.9" */
  .ios-ipad-layout {
    max-width: 1024px;
    margin: 0 auto;
  }
}

/* iOS Dark Mode Support */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
  }
}

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

/* iOS Font Smoothing */
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* iOS Button Active State */
button:active {
  opacity: 0.7;
  transform: scale(0.98);
  transition: all 0.1s ease;
}

/* Prevent iOS Callout Menu */
img, canvas, video {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* iOS Text Selection */
.selectable-text {
  -webkit-user-select: text;
  -moz-user-select: text;
  user-select: text;
}

/* iOS Smooth Scrolling */
.smooth-scroll {
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}