/**
 * WP-Kore iOS, WebKit & Cross-Device Compatibility Layer
 *
 * Implements [cross-device-webkit-immunity-law] (L-295).
 * Universal physical & ergonomic normalization for iOS Safari, iPadOS,
 * WebKit, and mobile viewport edge cases.
 */

/* ── 1. GLOBAL ROOT NORMALIZATION & TOUCH ERGONOMICS ── */
html {
  /* Prevent font scaling issues on orientation change */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;

  /* Remove tap highlight gray overlay on mobile Safari */
  -webkit-tap-highlight-color: transparent;

  /* Prevent horizontal scroll bleed without breaking position: sticky */
  overflow-x: clip;
}

body {
  /* Safe minimum height using dynamic viewport with fallback */
  min-height: 100vh;
  min-height: 100dvh;
  min-height: -webkit-fill-available;

  /* Contain horizontal overflow */
  overflow-x: clip;
  max-width: 100%;
}

/* ── 2. SAFE-AREA INSETS CANONICAL TOKENS ── */
:root {
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-left: env(safe-area-inset-left, 0px);
  --safe-area-right: env(safe-area-inset-right, 0px);

  /* Modern dynamic viewport height with fallback */
  --vh-safe: 100dvh;
  --app-height: 100dvh;
}

@supports not (height: 100dvh) {
  :root {
    --vh-safe: 100vh;
    --app-height: 100vh;
  }
}

/* ── 3. FORM INPUT 16PX ZOOM PREVENTION (iOS SAFARI AUTO-ZOOM FIX) ── */
/* If form inputs have computed font-size < 16px, iOS Safari forcibly zooms the page */
@media screen and (max-width: 768px) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="hidden"]),
  select,
  textarea,
  .fluentform .ff-el-form-control,
  .kore-input,
  .kore-search-input {
    font-size: var(--font-size-ios-antizoom, 1rem) !important;
  }
}

/* ── 4. NATIVE APARRENCE & BUTTON NORMALIZATION ── */
/* Eradicate default iOS gray gradients, rounded pills, and inner shadows */
button,
input[type="button"],
input[type="submit"],
input[type="reset"] {
  -webkit-appearance: none;
  appearance: none;
  touch-action: manipulation;
}

/* Search input normalization */
input[type="search"] {
  -webkit-appearance: none;
  appearance: none;
  box-sizing: border-box;
}

input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-results-button,
input[type="search"]::-webkit-search-results-decoration {
  -webkit-appearance: none;
}

/* Anti-Zoom on Input Focus for iOS Safari (requires font-size >= 16px) */
@media screen and (max-width: 768px) {
  input:not([type="checkbox"]):not([type="radio"]),
  select,
  textarea {
    font-size: var(--font-size-ios-antizoom, 1rem) !important;
  }
}

/* Select element appearance reset */
select.kore-select,
.fluentform select.ff-el-form-control {
  -webkit-appearance: none;
  appearance: none;
}

/* ── 5. SAFE-AREA ANCHORING FOR STICKY / FIXED COMPONENTS ── */
/* Header sticky safe-area under notch / dynamic island */
.site-header.is-sticky,
.oxy-header.is-sticky,
header.is-sticky,
.header-sticky {
  padding-top: max(var(--header-pad-top, 0px), var(--safe-area-top));
}

/* Bottom fixed CTAs, dock bars, and floating elements */
.mobile-dock-bar {
  padding-bottom: max(var(--space-sm), var(--safe-area-bottom));
}
.floating-cta {
  padding-bottom: max(var(--space-sm), var(--safe-area-bottom));
}
.pwa-install-banner {
  padding-bottom: max(var(--space-sm), var(--safe-area-bottom));
}
.kore-notification-bar.position-bottom {
  padding-bottom: max(var(--space-sm), var(--safe-area-bottom));
}

/* Back-to-top button safe clearance */
.kore-back-to-top,
#kore-back-to-top {
  bottom: calc(var(--space-md, 1.5rem) + var(--safe-area-bottom));
  right: calc(var(--space-md, 1.5rem) + var(--safe-area-right));
}

/* ── 6. MOMENTUM SCROLLING & MODAL HARDENING ── */
.overflow-y-auto {
  -webkit-overflow-scrolling: touch;
}
.overflow-y-scroll {
  -webkit-overflow-scrolling: touch;
}
.kore-modal-content {
  -webkit-overflow-scrolling: touch;
}
.kore-drawer-content {
  -webkit-overflow-scrolling: touch;
}
.kore-tabs-nav {
  -webkit-overflow-scrolling: touch;
}
.scroll-container {
  -webkit-overflow-scrolling: touch;
}

/* Modal and Drawer safe insets */
:is(.kore-modal, .kore-modal-backdrop) {
  padding-top: var(--safe-area-top);
  padding-bottom: var(--safe-area-bottom);
  padding-left: var(--safe-area-left);
  padding-right: var(--safe-area-right);
}

/* ── 7. FLEXBOX & CONTAINER INTRINSIC COMPATIBILITY ── */
/* Prevent WebKit flex items with long text from overflowing the container */
:is(.cluster, .repel, .stack, [class*="grid"]) > * {
  min-inline-size: 0;
}

/* WebKit hardware acceleration stability for backdrop-filter */
:is(.surface-glass, [class*="surface-glass"]) {
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}
