html.is-ios-device,
html.is-ios-device body {
  overscroll-behavior-y: none;
}

html.is-ios-device {
  --iphone-visual-viewport-top: 0px;
  --iphone-visual-viewport-height: 100dvh;
  --iphone-keyboard-inset: 0px;
}

/* The translucent iOS status bar shares the page viewport. Keep normal page
   content below it while fixed modal backdrops continue to cover the full screen. */
@supports (padding-top: env(safe-area-inset-top)) {
  html.is-ios-device.is-ios-standalone .app-shell {
    padding-top: calc(12px + env(safe-area-inset-top));
  }

  @media (max-width: 932px) and (orientation: landscape) {
    html.is-ios-device.is-ios-standalone .app-shell {
      padding-top: calc(6px + env(safe-area-inset-top));
    }
  }

  @media (max-width: 640px) and (orientation: portrait) {
    html.is-ios-device.is-ios-standalone .app-shell {
      padding-top: calc(8px + env(safe-area-inset-top));
    }
  }
}

html.modal-scroll-locked,
html.modal-scroll-locked body {
  overflow: hidden !important;
  overscroll-behavior: none !important;
}

html.modal-scroll-locked body {
  position: fixed !important;
  right: 0;
  left: 0;
  width: 100%;
}

@media (max-width: 932px) {
  html.is-ios-device input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
  html.is-ios-device select,
  html.is-ios-device textarea,
  html.is-ios-device [contenteditable="true"] {
    font-size: 16px !important;
  }

  /* With no software keyboard, every full-screen portal dialog is centered in
     the complete iPhone viewport. This also clears any stale keyboard layout. */
  html.is-ios-device:not(.iphone-keyboard-open) .jiwu-lab-modal,
  html.is-ios-device:not(.iphone-keyboard-open) .jiwu-access-modal,
  html.is-ios-device:not(.iphone-keyboard-open) .parked-aircraft-modal,
  html.is-ios-device:not(.iphone-keyboard-open) .alcohol-history-overlay,
  html.is-ios-device:not(.iphone-keyboard-open) .app-modal-overlay {
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    width: auto !important;
    height: auto !important;
    max-height: none !important;
    align-items: center !important;
    justify-content: center !important;
  }

  html.is-ios-device:not(.iphone-keyboard-open) .jiwu-access-modal {
    place-items: center !important;
  }

  html.is-ios-device.iphone-dialog-keyboard-open,
  html.is-ios-device.iphone-dialog-keyboard-open body {
    width: 100%;
    height: 100%;
    overflow: hidden !important;
  }

  html.is-ios-device.iphone-keyboard-open .jiwu-lab-modal,
  html.is-ios-device.iphone-keyboard-open .jiwu-access-modal,
  html.is-ios-device.iphone-keyboard-open .parked-aircraft-modal,
  html.is-ios-device.iphone-keyboard-open .alcohol-history-overlay {
    box-sizing: border-box;
    top: var(--iphone-visual-viewport-top) !important;
    right: 0 !important;
    bottom: auto !important;
    left: 0 !important;
    width: 100% !important;
    height: var(--iphone-visual-viewport-height) !important;
    max-height: var(--iphone-visual-viewport-height) !important;
    align-items: flex-start !important;
    justify-content: center !important;
    padding: 8px 10px !important;
    overflow: hidden !important;
  }

  html.is-ios-device.iphone-keyboard-open .jiwu-access-modal {
    place-items: start center !important;
  }

  html.is-ios-device.iphone-keyboard-open .flight-pair-editor,
  html.is-ios-device.iphone-keyboard-open .mobile-field-editor,
  html.is-ios-device.iphone-keyboard-open .paper-modal {
    box-sizing: border-box;
    top: var(--iphone-visual-viewport-top) !important;
    right: 0 !important;
    bottom: auto !important;
    left: 0 !important;
    width: 100% !important;
    height: var(--iphone-visual-viewport-height) !important;
    max-height: var(--iphone-visual-viewport-height) !important;
    overflow: hidden !important;
  }

  html.is-ios-device.iphone-keyboard-open .jiwu-lab-panel,
  html.is-ios-device.iphone-keyboard-open .jiwu-access-card,
  html.is-ios-device.iphone-keyboard-open .parked-aircraft-panel,
  html.is-ios-device.iphone-keyboard-open .alcohol-history-table-panel {
    box-sizing: border-box;
    max-height: calc(var(--iphone-visual-viewport-height) - 16px) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    scroll-padding-block: 18px 96px;
    -webkit-overflow-scrolling: touch;
  }

  html.is-ios-device.iphone-keyboard-open .jiwu-access-card {
    width: calc(100vw - 20px) !important;
    min-width: 0 !important;
    max-width: 520px !important;
    height: auto !important;
    margin-right: auto !important;
    margin-left: auto !important;
    transform: none !important;
  }

  html.is-ios-device.iphone-keyboard-open .flight-pair-sheet {
    top: 8px !important;
    bottom: auto !important;
    max-height: calc(var(--iphone-visual-viewport-height) - 16px) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    scroll-padding-block: 16px 80px;
  }

  html.is-ios-device.iphone-keyboard-open .mobile-field-sheet {
    bottom: 8px !important;
    max-height: calc(var(--iphone-visual-viewport-height) - 16px) !important;
    overflow-y: auto !important;
  }

  html.is-ios-device.iphone-keyboard-open .paper-modal-panel {
    inset: 8px !important;
  }

  html.is-ios-device.iphone-keyboard-open .gate-picker.open .gate-picker-menu,
  html.is-ios-device.iphone-keyboard-open .release-picker.open .release-picker-menu {
    box-sizing: border-box;
    top: calc(var(--iphone-visual-viewport-top) + 8px) !important;
    right: 10px !important;
    bottom: auto !important;
    left: 10px !important;
    max-height: calc(var(--iphone-visual-viewport-height) - 16px) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    scroll-padding-block: 16px 80px;
    -webkit-overflow-scrolling: touch;
  }

  html.is-ios-device.iphone-keyboard-open input,
  html.is-ios-device.iphone-keyboard-open textarea,
  html.is-ios-device.iphone-keyboard-open select,
  html.is-ios-device.iphone-keyboard-open [contenteditable="true"] {
    scroll-margin-block: 72px 110px;
  }
}

.iphone-pull-refresh {
  --pull-distance: 0px;
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  left: 50%;
  z-index: 20000;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(18, 52, 87, 0.16);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  color: #087548;
  box-shadow: 0 8px 24px rgba(8, 34, 24, 0.2);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, calc(-58px + var(--pull-distance)));
  transition: opacity 140ms ease, transform 140ms ease;
}

.iphone-pull-refresh.is-pulling,
.iphone-pull-refresh.is-refreshing {
  opacity: 1;
  transition: opacity 60ms linear, transform 60ms linear;
}

.iphone-pull-refresh-icon {
  display: block;
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
  transform: rotate(0deg);
  transition: transform 140ms ease;
}

.iphone-pull-refresh.is-ready .iphone-pull-refresh-icon {
  transform: rotate(180deg);
}

.iphone-pull-refresh.is-refreshing .iphone-pull-refresh-icon {
  animation: iphone-refresh-spin 700ms linear infinite;
}

@keyframes iphone-refresh-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .iphone-pull-refresh,
  .iphone-pull-refresh-icon {
    transition: none;
  }

  .iphone-pull-refresh.is-refreshing .iphone-pull-refresh-icon {
    animation-duration: 1.4s;
  }
}

/* Keep Safari/iOS from assigning an intrinsic width to visible date controls. */
input[type="date"]:not(.date-picker-hidden):not(.date-picker-input) {
  -webkit-appearance: none !important;
  appearance: none !important;
  display: block;
  box-sizing: border-box !important;
  inline-size: 100% !important;
  width: 100% !important;
  min-inline-size: 0 !important;
  min-width: 0 !important;
  max-inline-size: 100% !important;
  max-width: 100% !important;
}

input[type="date"]:not(.date-picker-hidden):not(.date-picker-input)::-webkit-date-and-time-value {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 0;
}

input[type="date"]:not(.date-picker-hidden):not(.date-picker-input)::-webkit-datetime-edit {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  padding: 0;
}

/* On phones every application popup uses the same 16px viewport margin. */
@media (max-width: 640px) {
  .jiwu-access-modal,
  .jiwu-lab-modal {
    box-sizing: border-box !important;
    padding-inline: 16px !important;
  }

  .jiwu-access-modal .jiwu-access-card,
  .jiwu-lab-modal .jiwu-lab-panel {
    box-sizing: border-box !important;
    inline-size: 100% !important;
    width: 100% !important;
    min-inline-size: 0 !important;
    min-width: 0 !important;
    max-inline-size: none !important;
    max-width: none !important;
  }
}

/* iOS may expose a zoomed layout viewport wider than the mobile breakpoint. */
html.is-ios-device .jiwu-access-modal,
html.is-ios-device .jiwu-lab-modal {
  box-sizing: border-box !important;
  padding-inline: 16px !important;
}

html.is-ios-device .jiwu-access-modal .jiwu-access-card,
html.is-ios-device .jiwu-lab-modal .jiwu-lab-panel {
  box-sizing: border-box !important;
  inline-size: 100% !important;
  width: 100% !important;
  min-inline-size: 0 !important;
  min-width: 0 !important;
  max-inline-size: none !important;
  max-width: none !important;
}
