/**
 * Cross-Browser Compatibility Styles
 * @package Dennis_Theme
 * @since 1.0.0
 *
 * BROWSER SUPPORT:
 * - Chrome/Edge (latest & -2 versions)
 * - Firefox (latest & -2 versions)
 * - Safari (latest & -2 versions)
 * - Mobile Safari (iOS 13+)
 * - Chrome Mobile (Android 8+)
 */

/* ============================================
   SAFARI-SPECIFIC FIXES
   ============================================ */

/* Fix: Safari smooth scroll with Lenis */
@supports (-webkit-backdrop-filter: blur(1px)) {
  html.lenis {
    scroll-behavior: auto !important;
  }

  /* Prevent elastic bounce on Safari iOS */
  html.lenis body {
    overscroll-behavior-y: none;
    -webkit-overflow-scrolling: auto;
  }
}

/* Fix: Safari backdrop-filter support */
.site-header.header-solid,
.site-header.header-scrolled {
  /* Standard */
  backdrop-filter: blur(10px);
  /* Safari/WebKit */
  -webkit-backdrop-filter: blur(10px);
}

/* Fallback for browsers without backdrop-filter support */
@supports not (backdrop-filter: blur(10px)) {
  .site-header.header-solid,
  .site-header.header-scrolled {
    background-color: rgba(255, 255, 255, 0.98) !important;
  }

  .site-header.header-dark.header-solid,
  .site-header.header-dark.header-scrolled {
    background-color: rgba(26, 26, 26, 0.98) !important;
  }
}

/* Fix: Safari 100vh mobile issues */
/* Use CSS custom property for dynamic viewport height */
:root {
  --vh: 1vh;
}

.mobile-navigation {
  /* Fallback */
  height: 100vh;
  /* Modern dynamic viewport (iOS 15+) */
  height: 100dvh;
  /* Custom property fallback for older iOS */
  height: calc(var(--vh, 1vh) * 100);
}

/* Fix: Safari position fixed + transform bug */
@supports (-webkit-touch-callout: none) {
  .site-header {
    transform: translate3d(0, 0, 0);
  }

  .site-header.header-hidden {
    transform: translate3d(0, -100%, 0);
  }
}

/* Fix: Safari text rendering */
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Fix: Safari flexbox gap issues (iOS < 14.5) */
@supports not (gap: 1rem) {
  .site-header__inner > * + * {
    margin-left: 2rem;
  }

  .main-navigation ul > * + * {
    margin-left: 2.5rem;
  }

  .mobile-navigation__social > * + * {
    margin-left: 1.5rem;
  }
}

/* Fix: Safari aspect-ratio support */
@supports not (aspect-ratio: 16 / 9) {
  .aspect-16-9 {
    position: relative;
    padding-bottom: 56.25%; /* 9/16 = 0.5625 */
  }

  .aspect-16-9 > * {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
  }

  .aspect-4-3 {
    position: relative;
    padding-bottom: 75%; /* 3/4 = 0.75 */
  }

  .aspect-4-3 > * {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
  }

  .aspect-square {
    position: relative;
    padding-bottom: 100%;
  }

  .aspect-square > * {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
  }
}

/* ============================================
   FIREFOX-SPECIFIC FIXES
   ============================================ */

/* Fix: Firefox scrollbar styling */
@-moz-document url-prefix() {
  * {
    scrollbar-width: thin;
    scrollbar-color: var(--color-accent) var(--color-neutral-200);
  }

  /* Hide scrollbar for Lenis smooth scroll */
  html.lenis {
    scrollbar-width: auto;
  }
}

/* Fix: Firefox focus outline */
@supports (-moz-appearance: none) {
  button::-moz-focus-inner,
  input::-moz-focus-inner {
    border: 0;
    padding: 0;
  }

  /* Improve focus visibility */
  *:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
  }
}

/* Fix: Firefox image rendering */
@-moz-document url-prefix() {
  img {
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
  }

  img[loading="lazy"] {
    image-rendering: auto;
  }
}

/* ============================================
   MOBILE-SPECIFIC FIXES
   ============================================ */

/* Fix: Mobile touch events */
@media (hover: none) and (pointer: coarse) {
  /* Disable hover effects on touch devices */
  .btn:hover,
  .card:hover,
  .main-navigation a:hover,
  .mobile-navigation__social-link:hover {
    transform: none;
    box-shadow: none;
  }

  /* Add active states instead */
  .btn:active {
    transform: scale(0.98);
  }

  .card:active {
    transform: translateY(-2px);
  }

  /* Prevent iOS text size adjustment */
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  /* Prevent iOS tap highlight */
  * {
    -webkit-tap-highlight-color: transparent;
  }

  /* Add custom tap highlight for interactive elements */
  a, button, [role="button"] {
    -webkit-tap-highlight-color: rgba(201, 166, 107, 0.1);
  }
}

/* Fix: Mobile viewport units */
@supports (height: 100dvh) {
  .mobile-navigation {
    height: 100dvh;
  }
}

/* Fix: iOS Safari bouncing */
@supports (-webkit-touch-callout: none) {
  body {
    position: relative;
    overflow-x: hidden;
  }

  body.mobile-menu-open {
    position: fixed;
    overflow: hidden;
    width: 100%;
    height: 100%;
    -webkit-overflow-scrolling: auto;
  }

  .mobile-navigation {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
}

/* Fix: Android Chrome address bar height */
@media screen and (max-width: 767px) {
  .mobile-navigation {
    min-height: 100vh;
    min-height: -webkit-fill-available;
  }

  html {
    height: -webkit-fill-available;
  }
}

/* Fix: Orientation change handling */
@media (orientation: landscape) and (max-height: 500px) {
  .mobile-navigation {
    padding-top: 4rem;
    padding-bottom: 2rem;
  }

  .mobile-navigation a {
    font-size: clamp(1.5rem, 4vw, 2rem);
    padding: 0.75rem 0;
  }

  .mobile-navigation__footer {
    margin-top: 2rem;
    padding-top: 1rem;
  }
}

/* ============================================
   EDGE-SPECIFIC FIXES
   ============================================ */

/* Fix: Edge legacy grid support */
@supports (-ms-ime-align: auto) {
  .grid {
    display: -ms-grid;
  }
}

/* Fix: Edge scrollbar */
@supports (-ms-overflow-style: none) {
  html.lenis {
    -ms-overflow-style: none;
  }
}

/* ============================================
   FEATURE QUERY FALLBACKS
   ============================================ */

/* Fix: CSS Grid fallback */
@supports not (display: grid) {
  .grid {
    display: flex;
    flex-wrap: wrap;
  }

  .grid > * {
    flex: 1 1 auto;
  }
}

/* Fix: CSS Custom Properties fallback */
@supports not (--custom: property) {
  :root {
    /* Fallback colors */
  }

  body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    color: #1a1a1a;
    background-color: #f5f0eb;
  }

  .btn-primary {
    background-color: #c9a66b;
    color: white;
  }
}

/* Fix: CSS clamp() fallback */
@supports not (font-size: clamp(1rem, 2vw, 2rem)) {
  h1 {
    font-size: 2.5rem;
  }

  h2 {
    font-size: 2rem;
  }

  h3 {
    font-size: 1.75rem;
  }

  @media (min-width: 768px) {
    h1 {
      font-size: 3rem;
    }

    h2 {
      font-size: 2.25rem;
    }

    h3 {
      font-size: 1.875rem;
    }
  }

  @media (min-width: 1280px) {
    h1 {
      font-size: 4rem;
    }

    h2 {
      font-size: 3rem;
    }

    h3 {
      font-size: 2.25rem;
    }
  }
}

/* Fix: position: sticky fallback */
@supports not (position: sticky) {
  .sticky-element {
    position: fixed;
  }
}

/* Fix: object-fit fallback */
@supports not (object-fit: cover) {
  img {
    width: 100%;
    height: auto;
  }
}

/* ============================================
   WEBGL / THREE.JS FALLBACKS
   ============================================ */

/* Fallback for browsers without WebGL support */
.no-webgl .hero-canvas,
.no-webgl .color-picker-3d {
  display: none;
}

.no-webgl .hero-section {
  background: linear-gradient(135deg, #f5f0eb 0%, #e5ddd3 100%);
}

/* ============================================
   INTERSECTION OBSERVER FALLBACK
   ============================================ */

/* Show content immediately if IntersectionObserver not supported */
.no-js [data-animate],
.no-intersection-observer [data-animate] {
  opacity: 1 !important;
  transform: none !important;
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
  /* Remove animations */
  *,
  *::before,
  *::after {
    animation-duration: 0s !important;
    transition-duration: 0s !important;
  }

  /* Remove backgrounds */
  .site-header,
  .mobile-navigation,
  .hero-section {
    background: white !important;
    box-shadow: none !important;
  }

  /* Hide unnecessary elements */
  .mobile-menu-toggle,
  .mobile-navigation,
  .hero-canvas,
  .scroll-indicator,
  .page-loader,
  .page-transition-overlay,
  [data-no-print] {
    display: none !important;
  }

  /* Show all content */
  body,
  main,
  header,
  footer {
    opacity: 1 !important;
    transform: none !important;
  }

  /* Optimize typography */
  body {
    font-size: 12pt;
    line-height: 1.5;
    color: #000;
  }

  h1 {
    font-size: 24pt;
    page-break-after: avoid;
  }

  h2 {
    font-size: 18pt;
    page-break-after: avoid;
  }

  h3 {
    font-size: 14pt;
    page-break-after: avoid;
  }

  /* Show link URLs */
  a[href^="http"]:after {
    content: " (" attr(href) ")";
    font-size: 10pt;
    font-weight: normal;
  }

  /* Avoid page breaks inside elements */
  img,
  table,
  figure,
  .card {
    page-break-inside: avoid;
  }

  /* Ensure images are visible */
  img {
    max-width: 100% !important;
  }

  /* Page margins */
  @page {
    margin: 2cm;
  }
}

/* ============================================
   HIGH CONTRAST MODE
   ============================================ */

@media (prefers-contrast: high) {
  /* Increase contrast for better visibility */
  body {
    color: #000;
    background-color: #fff;
  }

  .btn {
    border-width: 3px;
  }

  a {
    text-decoration: underline;
  }

  :focus-visible {
    outline-width: 4px;
    outline-offset: 4px;
  }
}

/* ============================================
   FORCED COLORS MODE (Windows High Contrast)
   ============================================ */

@media (forced-colors: active) {
  /* Remove custom colors */
  * {
    background-color: Canvas;
    color: CanvasText;
  }

  a {
    color: LinkText;
  }

  button,
  .btn {
    border: 2px solid ButtonBorder;
  }

  :focus-visible {
    outline: 3px solid Highlight;
  }
}

/* ============================================
   REDUCED DATA MODE
   ============================================ */

@media (prefers-reduced-data: reduce) {
  /* Disable heavy resources */
  .hero-canvas,
  .color-picker-3d,
  video,
  [data-src] {
    display: none;
  }

  /* Use system fonts */
  body {
    font-family: system-ui, -apple-system, sans-serif;
  }
}

/* ============================================
   BROWSER-SPECIFIC SCROLLBAR STYLING
   ============================================ */

/* Chromium browsers (Chrome, Edge, Opera) */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--color-neutral-100, #f5f5f5);
}

::-webkit-scrollbar-thumb {
  background: var(--color-neutral-400, #999);
  border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--color-accent, #c9a66b);
}

/* Hide scrollbar for Lenis smooth scroll */
html.lenis::-webkit-scrollbar {
  display: none;
}

/* ============================================
   LEGACY BROWSER WARNINGS
   ============================================ */

/* Show warning for very old browsers */
.browser-warning {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10001;
  padding: 1rem;
  background-color: #ffc107;
  color: #000;
  text-align: center;
  font-weight: 600;
}

.no-css-grid .browser-warning,
.no-flexbox .browser-warning,
.ie .browser-warning {
  display: block;
}

/* ============================================
   PERFORMANCE OPTIMIZATIONS
   ============================================ */

/* Hardware acceleration for animations */
.site-header,
.mobile-navigation,
[data-animate],
.card {
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  will-change: transform;
}

.animated {
  will-change: auto;
}

/* Optimize paint performance */
.hero-canvas,
.color-picker-3d {
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

/* Contain layout shifts */
img,
video,
iframe {
  max-width: 100%;
  height: auto;
}

/* ============================================
   BROWSER BUG FIXES
   ============================================ */

/* Fix: Safari/iOS input zoom */
@supports (-webkit-touch-callout: none) {
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="number"],
  textarea,
  select {
    font-size: 16px !important;
  }
}

/* Fix: Chrome autofill background */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0px 1000px white inset;
  -webkit-text-fill-color: var(--color-primary, #1a1a1a);
  transition: background-color 5000s ease-in-out 0s;
}

/* Fix: Firefox button padding */
@-moz-document url-prefix() {
  button::-moz-focus-inner {
    border: 0;
    padding: 0;
  }
}

/* Fix: Safari date input */
input[type="date"]::-webkit-inner-spin-button,
input[type="date"]::-webkit-calendar-picker-indicator {
  display: none;
  -webkit-appearance: none;
}
