/**
 * COMPREHENSIVE VISUAL & RESPONSIVENESS FIXES v1.0.0
 * Date: 2026-01-12
 * 
 * This module contains ALL fixes from the comprehensive audit:
 * - Loading screen width (100vw fix)
 * - Search input overlap fixes
 * - Subscribe button glitch fixes
 * - Scrollbar jump prevention
 * - Mobile responsiveness fixes
 * - Dark mode conflicts
 * - Font loading (FOIT/FOUT) fixes
 * - Touch target improvements
 * - Accessibility enhancements
 * 
 * @package AI_WP_Manager
 * @since 1.0.0
 */

/* ========================================
   §1 — PRELOADER VIEWPORT COVERAGE FIX
   Force full viewport width without scrollbar gaps
   ======================================== */

#loader,
.preloader,
.loading-screen {
  /* CRITICAL: Use inset instead of width/height to prevent scrollbar gap */
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: auto !important; /* Override any 100vw */
  height: auto !important; /* Override any 100vh */
  margin: 0 !important;
  padding: 0 !important;
  box-sizing: border-box !important;
  z-index: 999999 !important;
}

/* ========================================
   §2 — SEARCH INPUT TEXT OVERLAP FIX
   Prevent typed text from going under search icon
   ======================================== */

.search-form input.search-field,
input[type='search'],
.header-search input,
.site-header input[type='search'] {
  padding-right: 50px !important;
  box-sizing: border-box;
}

/* Ensure icon is positioned absolutely without shifting layout */
.search-form .search-submit,
.search-form i.fa-search,
.header-search__submit,
.header-search button {
  position: absolute !important;
  right: 12px !important;
  top: 50% !important;
  transform: translateY(-50%) !important;
  z-index: 10 !important;
  background: transparent !important;
  border: none !important;
  pointer-events: auto !important;
}

/* ========================================
   §3 — SUBSCRIBE BUTTON GLITCH FIX
   Prevent layout shift on hover (border changes)
   ======================================== */

.subscribe-form button,
input[type='submit'].subscribe-btn,
.newsletter-cta,
.newsletter-form__button {
  /* Reserve border space to prevent shift */
  border: 2px solid transparent !important;
  /* Hardware acceleration to prevent paint glitches */
  -webkit-backface-visibility: hidden !important;
  backface-visibility: hidden !important;
  transform: translateZ(0) !important;
  overflow: hidden !important;
  /* Prevent margin/padding changes on hover */
  transition:
    background-color 0.2s ease,
    border-color 0.2s ease,
    transform 0.2s ease !important;
}

.subscribe-form button:hover,
.newsletter-cta:hover {
  /* Maintain consistent spacing */
  margin: 0 !important;
}

/* ========================================
   §4 — SCROLLBAR JUMP PREVENTION
   Reserve space for scrollbar on Windows
   ======================================== */

html {
  /* Keeps space for scrollbar even when not needed */
  scrollbar-gutter: stable !important;
}

/* ========================================
   §5 — HORIZONTAL SCROLL PREVENTION
   Eliminate "ghost margin" on mobile
   ======================================== */

body,
html {
  overflow-x: hidden !important;
  width: 100% !important;
  max-width: 100vw !important;
}

/* Prevent any element from breaking the layout */
* {
  max-width: 100%;
}

/* ========================================
   §6 — MOBILE INPUT AUTO-ZOOM FIX (iOS)
   Prevent iPhone from zooming on focus
   ======================================== */

@media screen and (max-width: 768px) {
  input[type='text'],
  input[type='email'],
  input[type='search'],
  input[type='tel'],
  input[type='url'],
  input[type='number'],
  input[type='password'],
  textarea,
  select {
    font-size: 16px !important;
  }
}

/* ========================================
   §7 — TOUCH TARGET SIZE (44x44px Minimum)
   Accessibility requirement
   ======================================== */

.footer-links a,
.nav-links a,
.site-footer a,
nav a,
.button,
a.button,
/* Explicitly include key icon/toggles used in the header */
.newsletter-cta,
.nav-toggle,
.header-search__button {
  min-height: 44px !important;
  min-width: 44px !important;
}

/*
 * IMPORTANT:
 * Do NOT apply global padding/display overrides to ALL <button> elements.
 * That breaks compact UI controls (notably the chatbot Theme/Text panel buttons)
 * and can cause them to balloon and overlap the navbar.
 */

/* ========================================
   §8 — STICKY HOVER ON MOBILE FIX
   Only apply hover effects on devices with mouse
   ======================================== */

@media (hover: hover) {
  .subscribe-btn:hover,
  .button:hover,
  .newsletter-cta:hover,
  a:hover {
    background-color: var(--color-primary-hover, #004d99) !important;
  }
}

/* Disable hover effects on touch devices */
@media (hover: none) {
  .subscribe-btn:hover,
  .button:hover,
  .newsletter-cta:hover {
    background-color: var(--color-primary, #0066cc) !important;
  }
}

/* ========================================
   §9 — TAP HIGHLIGHT REMOVAL
   Remove grey box on Android/mobile taps
   ======================================== */

a,
button,
input,
select,
textarea,
[role='button'],
.button {
  -webkit-tap-highlight-color: transparent !important;
}

/* ========================================
   §10 — BRANDED TEXT SELECTION
   Custom highlight color
   ======================================== */

::selection {
  background: var(--color-primary, #0066cc) !important;
  color: #ffffff !important;
}

::-moz-selection {
  background: var(--color-primary, #0066cc) !important;
  color: #ffffff !important;
}

/* ========================================
   §11 — MOMENTUM SCROLLING (iOS)
   Smooth glide physics on scrollable elements
   ======================================== */

.code-block,
.scroll-container,
pre,
.table-wrapper,
.overflow-scroll {
  -webkit-overflow-scrolling: touch !important;
}

/* ========================================
   §12 — BLURRY TEXT ANIMATION FIX
   Keep text sharp during transforms
   ======================================== */

.card:hover,
.post-card:hover,
[class*='card']:hover,
[class*='animated'] {
  will-change: transform !important;
  -webkit-font-smoothing: antialiased !important;
  -moz-osx-font-smoothing: grayscale !important;
}

/* ========================================
   §13 — OVERSCROLL BEHAVIOR (MODAL TRAP)
   Contain scroll within modals/menus
   ======================================== */

.mobile-menu,
.modal-content,
.scrollable-sidebar,
.primary-nav.is-open,
[role='dialog'],
.aiwp-chatbot-container {
  overscroll-behavior: contain !important;
}

/* ========================================
   §14 — FLEXBOX SHRINK FIX
   Prevent long URLs/text from breaking layout
   ======================================== */

.flex-child-element,
.card,
.post-card,
[class*='card'],
article,
.content {
  min-width: 0 !important;
  overflow-wrap: break-word !important;
  word-wrap: break-word !important;
}

/* Force URLs to break - but NOT navigation links */
a[href]:not(.primary-nav a):not(.menu a):not(.nav a):not(nav a),
.url,
code,
pre {
  word-break: break-all !important;
  overflow-wrap: break-word !important;
}

/* CRITICAL: Navigation links must NOT break words */
.primary-nav a,
.menu a,
nav a,
.site-header a {
  word-break: normal !important;
  white-space: nowrap !important;
}

/* ========================================
   §15 — FOCUS RING VISIBILITY
   Prevent outline from being cut off
   ======================================== */

.btn:focus,
.button:focus,
a:focus,
button:focus,
input:focus,
[role='button']:focus {
  outline-offset: 2px !important;
}

/* Ensure parent containers don't clip focus rings */
.card,
.post-card,
[class*='card'],
.button-group {
  overflow: visible !important;
}

/* ========================================
   §16 — FONT LOADING (FOIT/FOUT) FIX
   Show fallback text immediately, swap when ready
   ======================================== */

@font-face {
  font-family: 'Inter';
  font-display: swap !important;
}

/* Prevent invisible text during font load */
html {
  font-display: swap !important;
}

/* ========================================
   §17 — AUTOFILL DARK MODE FIX
   Override Chrome's yellow autofill background
   ======================================== */

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
textarea:-webkit-autofill,
textarea:-webkit-autofill:hover,
textarea:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0px 1000px var(--color-surface, #ffffff) inset !important;
  -webkit-text-fill-color: var(--color-text, #1a1a1a) !important;
  transition: background-color 5000s ease-in-out 0s !important;
}

[data-theme='dark'] input:-webkit-autofill,
[data-theme='dark'] input:-webkit-autofill:hover,
[data-theme='dark'] input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0px 1000px var(--color-surface, #1a1a1a) inset !important;
  -webkit-text-fill-color: var(--color-text, #ffffff) !important;
}

/* ========================================
   §18 — SYSTEM FONT REVERSION FIX
   Force form elements to inherit main font
   ======================================== */

input,
button,
select,
textarea {
  font-family: inherit !important;
  font-size: inherit !important;
}

/* ========================================
   §19 — IMAGE ASPECT RATIO PRESERVATION
   Prevent stretched/squashed images
   ======================================== */

.post-thumbnail img,
.card-image img,
.featured-image img,
img[class*='thumbnail'],
img[class*='featured'] {
  width: 100% !important;
  height: auto !important;
  object-fit: cover !important;
  object-position: center !important;
}

/* Specific height for cards */
/*
    IMPORTANT:
    `.post-card` contains both the featured image AND small UI images (e.g., author avatars).
    A blanket `.post-card img { height: 250px }` stretches avatars into giant pills and makes
    the /platform page look broken.

    Keep the fixed-height fallback for generic `.card img`, but never apply it to all post-card
    images.
*/
.card img {
  height: 250px !important;
}

/* ========================================
   §20 — CODE BLOCK OVERFLOW FIX
   Prevent horizontal page scroll
   ======================================== */

pre,
code,
.code-block,
.wp-block-code {
  max-width: calc(100vw - 4rem) !important;
  overflow-x: auto !important;
  white-space: pre-wrap !important;
  word-wrap: break-word !important;
}

/* ========================================
   §21 — NAVIGATION OVERLAP FIX
   Prevent items from overlapping at tablet sizes
   ======================================== */

@media (min-width: 768px) and (max-width: 1024px) {
  .site-header nav ul {
    gap: clamp(8px, 1.5vw, 16px) !important;
  }

  .site-header nav a {
    font-size: clamp(0.85rem, 1.2vw, 1rem) !important;
    padding: 0.5rem clamp(0.5rem, 1vw, 1rem) !important;
  }
}

/* ========================================
   §22 — NEWSLETTER FORM STACK ON MOBILE
   Input and button should stack vertically
   ======================================== */

@media (max-width: 640px) {
  .newsletter-form,
  .subscribe-form,
  .site-header__newsletter {
    flex-direction: column !important;
    gap: 12px !important;
  }

  .newsletter-form input,
  .subscribe-form input {
    width: 100% !important;
  }

  .newsletter-form button,
  .subscribe-form button {
    width: 100% !important;
  }
}

/* ========================================
   §23 — STATS GRID RESPONSIVE
   Prevent overlap at tablet sizes
   ======================================== */

.stats-grid,
[class*='stats-grid'],
.synth-stats-grid {
  display: grid !important;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)) !important;
  gap: clamp(1rem, 3vw, 2rem) !important;
}

@media (max-width: 900px) {
  .stats-grid,
  [class*='stats-grid'],
  .synth-stats-grid {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

@media (max-width: 600px) {
  .stats-grid,
  [class*='stats-grid'],
  .synth-stats-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ========================================
   §24 — TOOLS GRID CARD SIZING
   Prevent cards from squeezing together
   ======================================== */

.tools-grid,
[class*='tools-grid'],
.ai-tools-grid {
  display: grid !important;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)) !important;
  gap: clamp(1.5rem, 3vw, 2.5rem) !important;
}

/* ========================================
   §25 — CHAT WIDGET FOOTER CLEARANCE
   Ensure footer links remain clickable
   ======================================== */

@media (max-width: 768px) {
  .aiwp-chat-launcher,
  .aiwp-chatbot-launcher,
  #aiwp-chatbot-launcher {
    bottom: 90px !important;
  }

  /* Keep pagination and footer content clickable/visible (launcher overlap guardrail) */
  .ajax-pagination,
  .pagination,
  .pagination-nav {
    margin-bottom: 96px !important;
  }

  .site-footer {
    padding-bottom: calc(var(--space-8, 2rem) + 96px) !important;
  }

  .site-footer a {
    padding: 12px 8px !important;
    min-height: 44px !important;
  }
}

/* ========================================
   A25b - CHAT OPEN LAYOUT GUARDRAILS
   Prevent header overlap and floating button collision
   ======================================== */

/* Keep the chat surface below the fixed header on open */
.aiwp-chatbot-container.is-open {
  padding-top: calc(var(--header-height, 80px) + env(safe-area-inset-top, 0px)) !important;
  padding-bottom: env(safe-area-inset-bottom, 0px) !important;
  box-sizing: border-box;
}

/* Hide the floating launcher while chat is open to avoid overlap */
/* FIXED v17.7.0: Use chat container state instead of body class to prevent stuck hidden state */
.aiwp-chatbot-container:not(.aiwp-chatbot-closed) ~ .aiwp-chat-launcher,
.aiwp-chatbot-container:not(.aiwp-chatbot-closed) ~ .aiwp-chatbot-launcher,
.aiwp-chatbot-container:not(.aiwp-chatbot-closed) ~ #aiwp-chatbot-launcher,
.aiwp-chatbot-container:not(.aiwp-chatbot-closed) ~ [id*='chatbot-launcher'],
.aiwp-chatbot-container:not(.aiwp-chatbot-closed) ~ [class*='chat-launcher'] {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  transition:
    opacity 0.2s ease,
    visibility 0s linear 0.2s;
}

/* Ensure launcher is visible when chat is closed */
.aiwp-chatbot-container.aiwp-chatbot-closed ~ .aiwp-chat-launcher,
.aiwp-chatbot-container.aiwp-chatbot-closed ~ .aiwp-chatbot-launcher,
.aiwp-chatbot-container.aiwp-chatbot-closed ~ #aiwp-chatbot-launcher,
.aiwp-chatbot-container.aiwp-chatbot-closed ~ [id*='chatbot-launcher'],
.aiwp-chatbot-container.aiwp-chatbot-closed ~ [class*='chat-launcher'] {
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: auto !important;
  transition:
    opacity 0.2s ease,
    visibility 0s linear 0s;
}

/* JS guardrail classes to prevent launcher disappearance */
.aiwp-chat-launcher.aiwp-chat-launcher-hidden,
.aiwp-chatbot-launcher.aiwp-chat-launcher-hidden,
#aiwp-chatbot-launcher.aiwp-chat-launcher-hidden,
[id*='chatbot-launcher'].aiwp-chat-launcher-hidden,
[class*='chat-launcher'].aiwp-chat-launcher-hidden {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

.aiwp-chat-launcher.aiwp-chat-launcher-visible,
.aiwp-chatbot-launcher.aiwp-chat-launcher-visible,
#aiwp-chatbot-launcher.aiwp-chat-launcher-visible,
[id*='chatbot-launcher'].aiwp-chat-launcher-visible,
[class*='chat-launcher'].aiwp-chat-launcher-visible {
  opacity: 1 !important;
  visibility: visible !important;
  pointer-events: auto !important;
}

/* Ensure theme panel stays scrollable on small screens */
.aiwp-chatbot-container.is-open .aiwp-chatbot-theme-panel {
  max-height: min(70vh, 420px) !important;
  overflow: auto !important;
}

@media (max-width: 480px) {
  .aiwp-chatbot-container.is-open .aiwp-chatbot-theme-panel {
    width: min(92vw, 260px) !important;
    max-height: min(60vh, 360px) !important;
  }
}

/* ========================================
   §26 — THEME SWITCHER MOBILE POSITION
   Move to top-left to avoid chat button
   ======================================== */

@media (max-width: 640px) {
  .theme-toggle,
  [class*='theme-switcher'] {
    top: 80px !important;
    left: 10px !important;
    bottom: auto !important;
    right: auto !important;
  }
}

/* ========================================
   §27 — MODAL BACKGROUND SCROLL LOCK
   Prevent scrolling behind open modals
   ======================================== */

body.chat-open,
body.modal-open,
body.menu-open {
  overflow: hidden !important;
  height: 100vh !important;
  height: 100dvh !important;
}

/* ========================================
   §28 — LONG URL WRAPPING
   Force URLs to break at slashes
   ======================================== */

.content a[href*='http'],
.post-content a[href*='http'],
article a[href*='http'] {
  word-break: break-all !important;
  overflow-wrap: break-word !important;
  hyphens: auto !important;
}

/* ========================================
   §29 — HEADING RESPONSIVE SIZING
   Scale headings proportionally on small screens
   ======================================== */

h1,
.h1 {
  font-size: clamp(1.75rem, 5vw, 3rem) !important;
}

h2,
.h2 {
  font-size: clamp(1.5rem, 4vw, 2.5rem) !important;
}

h3,
.h3 {
  font-size: clamp(1.25rem, 3vw, 2rem) !important;
}

/* ========================================
   §30 — CODE BLOCK MOBILE SIZING
   Ensure code is readable without zooming
   ======================================== */

@media (max-width: 768px) {
  pre,
  code,
  .code-block {
    font-size: 0.75rem !important;
    -webkit-overflow-scrolling: touch !important;
  }
}

/* ========================================
   §31 — DARK MODE INPUT VISIBILITY
   Ensure form inputs have visible borders
   ======================================== */

[data-theme='dark'] input[type='text'],
[data-theme='dark'] input[type='email'],
[data-theme='dark'] input[type='search'],
[data-theme='dark'] textarea {
  border: 1px solid rgba(255, 255, 255, 0.2) !important;
  background: rgba(255, 255, 255, 0.05) !important;
  color: #ffffff !important;
}

/* ========================================
   §32 — LAYOUT SHIFT PREVENTION
   Explicit image dimensions
   ======================================== */

img {
  max-width: 100% !important;
  height: auto !important;
}

/* Reserve space for images before load */
/*
  IMPORTANT:
  Post cards use an aspect-ratio/padding-top wrapper (`.post-card__image-wrapper`).
  Applying aspect-ratio + global `img { height:auto !important; }` rules directly to the
  `<img.post-card__image>` can break the intended cover layout and produce a large blank
  area above the image (as seen on /platform/ Trending Now).

  Reserve space on wrappers, not the <img>.
*/
.post-card__image-wrapper,
.card__image {
  background: var(--color-surface, #f5f5f5) !important;
}

/* Ensure post-card featured images always fill the wrapper (and do NOT affect author avatars) */
.post-card__image-wrapper {
  position: relative !important;
  overflow: hidden !important;
}

.post-card__image-wrapper > img.post-card__image {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  display: block !important;
  /* Avoid competing intrinsic aspect-ratio on the <img> */
  aspect-ratio: auto !important;
  background: transparent !important;
}

/* ========================================
   §32b — POST CARD TEXT SAFETY
   Prevent “all text underlined” + overlap
   ======================================== */

/* The entire card is wrapped in an <a>. If any global rule forces link underlines,
   it can visually underline *all* descendant text. Keep card typography clean. */
.post-card__link-wrapper,
.post-card__link-wrapper:hover,
.post-card__link-wrapper:focus,
.post-card__link-wrapper:focus-visible {
  text-decoration: none !important;
  text-decoration-color: transparent !important;
  color: inherit !important;
}

.post-card__link-wrapper * {
  text-decoration: none !important;
  text-decoration-color: transparent !important;
}

/* Ensure card content always uses the intended flow layout so the author row
   can’t collide with the excerpt/title. */
.post-card__content {
  display: flex !important;
  flex-direction: column !important;
  min-height: 0 !important;
}

.post-card__excerpt {
  flex: 1 1 auto !important;
}

.post-card__author {
  position: static !important;
  margin-top: auto !important;
}

/* ========================================
   §33 — SCROLL JANK PREVENTION
   GPU-accelerated transforms
   ======================================== */

.card,
.post-card,
[class*='card'],
.animated-element {
  will-change: transform !important;
  transform: translateZ(0) !important;
}

/* Remove will-change after animation */
.card:not(:hover),
.post-card:not(:hover) {
  will-change: auto !important;
}

/* ========================================
   §34 — KEYBOARD TRAP IN MODAL
   Focus management
   ======================================== */

.modal.is-open,
.aiwp-chatbot-container.is-open,
[role='dialog'][aria-hidden='false'] {
  position: fixed !important;
  inset: 0 !important;
  z-index: 9999 !important;
}

/* ========================================
   §35 — Z-INDEX SYSTEM
   Organized stacking context
   ======================================== */

.site-header {
  z-index: 1000 !important;
}

.primary-nav.is-open {
  z-index: 1100 !important;
}

.modal,
[role='dialog'] {
  z-index: 2000 !important;
}

.aiwp-chat-launcher,
.aiwp-chatbot-launcher {
  z-index: 1500 !important;
}

.theme-toggle {
  z-index: 1200 !important;
}

.preloader,
#loader {
  z-index: 9999 !important;
}

/* ========================================
   §36 — HIGH CONTRAST MODE
   Force colors for accessibility
   ======================================== */

@media (prefers-contrast: high) {
  * {
    border-color: currentColor !important;
  }

  button,
  .button,
  a.button {
    border: 2px solid currentColor !important;
  }
}

/* ========================================
   §37 — REDUCED MOTION
   Respect user preferences
   ======================================== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ========================================
   §38 — PRINT STYLES
   Hide unnecessary elements
   ======================================== */

@media print {
  .site-header,
  .site-footer,
  .primary-nav,
  .newsletter-cta,
  .subscribe-form,
  .aiwp-chat-launcher,
  .theme-toggle,
  .social-share,
  [class*='launcher'],
  [class*='fab'] {
    display: none !important;
  }

  body {
    background: white !important;
    color: black !important;
  }

  a[href]::after {
    content: ' (' attr(href) ')' !important;
    font-size: 0.8em !important;
  }
}

/* ========================================
   §39 — ORIENTATION HANDLING
   Landscape mobile adjustments
   ======================================== */

@media (max-height: 500px) and (orientation: landscape) {
  .site-header {
    height: 60px !important;
  }

  .hero,
  [class*='hero'] {
    padding-top: 2rem !important;
    padding-bottom: 2rem !important;
  }

  h1,
  .h1 {
    font-size: 1.75rem !important;
  }
}

/* ========================================
   §40 — NOTCHED DEVICES (iPhone X+)
   Safe area insets
   ======================================== */

@supports (padding: env(safe-area-inset-top)) {
  body {
    padding-top: env(safe-area-inset-top) !important;
    padding-bottom: env(safe-area-inset-bottom) !important;
    padding-left: env(safe-area-inset-left) !important;
    padding-right: env(safe-area-inset-right) !important;
  }

  .site-header {
    padding-top: env(safe-area-inset-top) !important;
  }
}

/* ========================================
   §41 — RETINA DISPLAYS
   Sharper rendering
   ======================================== */

@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  img {
    image-rendering: -webkit-optimize-contrast !important;
    image-rendering: crisp-edges !important;
  }

  svg {
    shape-rendering: geometricPrecision !important;
  }
}

/* ========================================
   §42 — CAROUSEL TEXT ON IMAGES
   Ensure text is always readable
   ======================================== */

.hero-carousel__slide h1,
.hero-carousel__slide h2,
.hero-carousel__slide p,
.hero-carousel__title,
.hero-carousel__excerpt {
  text-shadow:
    0 2px 4px rgba(0, 0, 0, 0.8),
    0 1px 2px rgba(0, 0, 0, 0.6) !important;
}

/* ========================================
   §43 — FORCED COLORS MODE
   High contrast mode on Windows
   ======================================== */

@media (forced-colors: active) {
  * {
    forced-color-adjust: auto !important;
  }

  button,
  .button {
    border: 2px solid ButtonText !important;
  }
}

/* ========================================
   §44 — ULTRAWIDESCREEN
   Prevent content from stretching too wide
   ======================================== */

@media (min-width: 2560px) {
  .container,
  .content-wrapper,
  main {
    max-width: 1920px !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }
}

/* ========================================
   §45 — EMERGENCY VISIBILITY GUARANTEE
   Nuclear failsafe for critical elements
   ======================================== */

/* Ensure primary CTAs are never invisible */
.newsletter-cta,
.subscribe-btn,
[class*='primary-cta'],
button[type='submit'] {
  opacity: 1 !important;
  visibility: visible !important;
  display: inline-flex !important;
}

/* Ensure icons in CTAs are visible */
.newsletter-cta svg,
.subscribe-btn svg,
button[type='submit'] svg {
  opacity: 1 !important;
  visibility: visible !important;
  display: block !important;
}

/* ========================================
   §46 — HONEYPOT INPUT HIDE FIX
   Ensure honeypot field is invisible and doesn't affect layout
   ======================================== */

.aiwp-hp,
input.aiwp-hp,
.newsletter-form .aiwp-hp,
.newsletter-card__form .aiwp-hp {
  position: absolute !important;
  left: -9999px !important;
  height: 1px !important;
  width: 1px !important;
  min-height: 0 !important;
  min-width: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  border: 0 !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
}

/* ========================================
   END OF COMPREHENSIVE FIXES v1.0.0
   All 46 fix categories implemented
   ======================================== */

/* ========================================
   §47 — MOBILE TIMELINE FOR HOW IT WORKS
   Add vertical connecting line between pipeline steps on mobile
   ======================================== */

@media (max-width: 768px) {
  .pipeline-flow {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0;
    padding-left: 40px; /* Space for timeline */
  }

  /* Hide horizontal connectors on mobile */
  .pipeline-connector {
    display: none !important;
  }

  /* Vertical timeline line */
  .pipeline-flow::before {
    content: '';
    position: absolute;
    left: 16px;
    top: 40px;
    bottom: 40px;
    width: 3px;
    background: var(--color-primary-30, rgba(0, 102, 204, 0.3));
    border-radius: 3px;
    z-index: 0;
  }

  /* Pipeline step positioning */
  .pipeline-step {
    position: relative;
    padding: 24px 0;
    margin-left: 0;
  }

  /* Timeline node circles */
  .pipeline-step::before {
    content: '';
    position: absolute;
    left: -32px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    background: var(--color-primary);
    border: 3px solid var(--color-surface, #fff);
    border-radius: 50%;
    box-shadow: 0 0 0 4px var(--color-primary-20, rgba(0, 102, 204, 0.2));
    z-index: 1;
  }

  /* Connecting arrows between steps (vertical) */
  .pipeline-step:not(:last-child)::after {
    content: '';
    position: absolute;
    left: -26px;
    bottom: -6px;
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 8px solid var(--color-primary);
    z-index: 2;
  }

  /* Step icon positioning */
  .pipeline-step__icon {
    width: 48px;
    height: 48px;
    margin-bottom: 12px;
  }

  /* Step content */
  .pipeline-step__content h3 {
    font-size: 1.125rem;
    margin-bottom: 8px;
  }

  .pipeline-step__content p {
    font-size: 0.875rem;
    line-height: 1.5;
  }
}

/* ========================================
   §48 — FOOTER & CHAT WIDGET Z-INDEX FIX
   Prevent chat widget from covering footer links on mobile
   ======================================== */

/* Give footer breathing room for chat widget */
.site-footer {
  padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)) !important;
}

/* Mobile: extra space for larger touch targets */
@media (max-width: 768px) {
  body {
    padding-bottom: 80px;
  }

  .site-footer {
    padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Ensure footer links are clickable */
  .site-footer a,
  .site-footer button {
    position: relative;
    z-index: 1;
  }
}

/* ========================================
   §49 — SCREEN-READER TEXT BULLETPROOF HIDE
   Fix "Toggle navigation" text bleed
   ======================================== */

.sr-only,
.screen-reader-text,
.visually-hidden,
.skip-link:not(:focus),
.nav-toggle .screen-reader-text {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
  -webkit-clip-path: inset(50%) !important;
  clip-path: inset(50%) !important;
}

/* Ensure hamburger toggle never shows text */
.nav-toggle span.screen-reader-text {
  position: absolute !important;
  left: -9999px !important;
  top: -9999px !important;
  visibility: hidden !important;
  font-size: 0 !important;
  line-height: 0 !important;
}

/* ========================================
   §50 — NEWSLETTER INPUT/BUTTON ALIGNMENT
   Ensure input and button have matching heights and radii
   ======================================== */

.newsletter-card__form,
.newsletter-modal__form,
.newsletter-section form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.newsletter-card__input-wrap,
.newsletter-modal__input-wrapper {
  display: flex;
  gap: 0;
  width: 100%;
}

/* Unified height and border-radius for input and button */
.newsletter-card__input-wrap input[type='email'],
.newsletter-card__form input[type='email'],
.newsletter-modal__form input[type='email'] {
  height: 48px !important;
  border-radius: 12px 0 0 12px !important;
  border: 1.5px solid var(--color-border, #ddd) !important;
  border-right: none !important;
  padding: 12px 16px !important;
  font-size: 15px !important;
  flex: 1;
  min-width: 0;
}

.newsletter-card__input-wrap button,
.newsletter-card__form button[type='submit'],
.newsletter-modal__submit {
  height: 48px !important;
  border-radius: 0 12px 12px 0 !important;
  padding: 12px 20px !important;
  font-size: 15px !important;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Mobile: Stack input and button vertically */
@media (max-width: 480px) {
  .newsletter-card__input-wrap,
  .newsletter-modal__input-wrapper {
    flex-direction: column;
    gap: 12px;
  }

  .newsletter-card__input-wrap input[type='email'],
  .newsletter-card__form input[type='email'],
  .newsletter-modal__form input[type='email'] {
    border-radius: 12px !important;
    border-right: 1.5px solid var(--color-border, #ddd) !important;
  }

  .newsletter-card__input-wrap button,
  .newsletter-card__form button[type='submit'],
  .newsletter-modal__submit {
    border-radius: 12px !important;
    width: 100%;
  }
}

/* ========================================
   §51 — HERO & STATS TEXT ALIGNMENT
   Consistent center alignment for hero section
   ======================================== */

.platform-hero {
  text-align: center;
}

.platform-hero__content {
  text-align: center;
  max-width: 800px;
  margin: 0 auto;
}

.platform-hero__stats {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: clamp(24px, 4vw, 48px);
  flex-wrap: wrap;
  text-align: center;
  margin-top: clamp(24px, 4vh, 40px);
}

.hero-stat {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hero-stat__value {
  text-align: center;
}

.hero-stat__label {
  text-align: center;
}

/* CTA buttons centered */
.platform-hero__actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

/* Section intros centered */
.section-intro {
  text-align: center;
  max-width: 700px;
  margin: 0 auto var(--space-8, 32px);
}

/* ========================================
   §52 — THEME TOGGLE SEGMENTED CONTROL STYLE
   Make theme options look like a proper segmented control
   ======================================== */

/* If theme/text options exist in footer or settings modal */
.theme-options,
.text-options,
.footer-theme-controls {
  display: inline-flex;
  background: var(--color-surface-alt, #f5f5f5);
  border: 1px solid var(--color-border, #e0e0e0);
  border-radius: 999px;
  padding: 4px;
  gap: 0;
}

.theme-options button,
.text-options button,
.footer-theme-controls button {
  padding: 8px 16px;
  border: none;
  background: transparent;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.theme-options button:hover,
.text-options button:hover,
.footer-theme-controls button:hover {
  color: var(--color-text);
}

.theme-options button.active,
.theme-options button[aria-pressed='true'],
.text-options button.active,
.text-options button[aria-pressed='true'],
.footer-theme-controls button.active {
  background: var(--color-primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 102, 204, 0.25);
}

/* Hide theme/text controls from navbar (they're in footer/chat now) */
.site-header .theme-options,
.site-header .text-options,
.site-header__actions .theme-options,
.site-header__actions .text-options {
  display: none !important;
}

/* ========================================
   §53 — ANIMATION FALLBACK NUCLEAR FIX
   Ensure all data-anim elements become visible even if JS fails
   ======================================== */

/* Nuclear fallback: Make ALL animated elements visible after 1.5s no matter what */
@keyframes aiwp-visibility-nuclear {
  0% {
    opacity: 0;
    transform: translateY(20px);
  }
  100% {
    opacity: 1 !important;
    transform: translateY(0) !important;
    visibility: visible !important;
  }
}

/* Apply fallback to ALL elements with data-anim attribute */
[data-anim]:not(.anim-visible) {
  animation: aiwp-visibility-nuclear 0.6s ease-out 1.5s forwards !important;
}

/* Immediate visibility for critical elements */
.animate-on-scroll,
.section-intro,
.feature-card,
.tool-card,
.pipeline-step,
.cta-card,
.hero-stat,
[data-anim] {
  opacity: 1 !important;
  visibility: visible !important;
  transform: none !important;
}

/* If animation has triggered, remove fallback animation */
[data-anim].anim-visible {
  animation: none !important;
  opacity: 1 !important;
  visibility: visible !important;
}

/* Reduced motion: instant visibility, no animation */
@media (prefers-reduced-motion: reduce) {
  [data-anim],
  [data-anim]:not(.anim-visible),
  .animate-on-scroll {
    animation: none !important;
    opacity: 1 !important;
    visibility: visible !important;
    transform: none !important;
    transition: none !important;
  }
}

/* ========================================
   §54 — SAFE AREA INSETS (NOTCH & DYNAMIC ISLAND FIX)
   Prevent content collision with iPhone notches and Dynamic Islands
   ======================================== */

/* Apply safe area insets to header */
.site-header {
  padding-top: env(safe-area-inset-top, 0px) !important;
  padding-left: max(env(safe-area-inset-left, 0px), var(--header-padding-x, 16px)) !important;
  padding-right: max(env(safe-area-inset-right, 0px), var(--header-padding-x, 16px)) !important;
}

.site-header__inner {
  padding-top: env(safe-area-inset-top, 0px);
}

/* Footer safe areas */
.site-footer {
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 100px) !important;
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

/* Chat widget respects safe areas */
#aiwp-chatbot-launcher,
.aiwp-chatbot-launcher {
  bottom: calc(env(safe-area-inset-bottom, 0px) + 20px) !important;
  right: calc(env(safe-area-inset-right, 0px) + 20px) !important;
}

/* ========================================
   §55 — TOUCH TARGET MINIMUM SIZE (44x44px)
   Apple Human Interface Guidelines compliance
   ======================================== */

/* All interactive elements must be at least 44x44px */
.nav-toggle,
.newsletter-cta,
.header-search-toggle,
.theme-toggle,
.text-toggle,
.mobile-menu-item,
.theme-toggle-btn,
button,
a.btn,
.btn,
[role='button'] {
  min-height: 44px !important;
  min-width: 44px !important;
}

/* Mobile menu items need extra spacing to prevent mis-taps */
@media (max-width: 768px) {
  .primary-nav .menu > li > a,
  .mobile-menu-item,
  .theme-toggle-btn,
  .text-options button,
  .theme-options button {
    min-height: 48px !important;
    min-width: 48px !important;
    padding: 12px 16px !important;
    margin-bottom: 8px !important; /* Prevent accidental double-taps */
  }
}

/* ========================================
   §56 — SAFARI ZOOM PREVENTION (16px INPUT FIX)
   Prevent iOS Safari from auto-zooming on input focus
   ======================================== */

@media screen and (max-width: 768px) {
  input[type='email'],
  input[type='text'],
  input[type='search'],
  input[type='tel'],
  input[type='url'],
  input[type='password'],
  textarea,
  select {
    font-size: 16px !important; /* Prevents iOS auto-zoom */
  }
}

/* ========================================
   §57 — STICKY HOVER STATE FIX (TOUCH DEVICES)
   Prevent hover states from "sticking" on touchscreens
   ======================================== */

/* Only apply hover effects on devices that support hover (mouse) */
@media (hover: hover) and (pointer: fine) {
  .btn:hover,
  .newsletter-cta:hover,
  .nav-toggle:hover,
  .theme-toggle:hover,
  button:hover {
    transform: translateY(-2px);
  }
}

/* On touch devices, remove sticky hover */
@media (hover: none) {
  .btn:hover,
  .newsletter-cta:hover,
  .nav-toggle:hover,
  .theme-toggle:hover,
  button:hover {
    transform: none !important;
    background-color: inherit;
  }

  /* Use :active for touch feedback instead */
  .btn:active,
  .newsletter-cta:active,
  .nav-toggle:active,
  button:active {
    transform: scale(0.95) !important;
    opacity: 0.9;
  }
}

/* ========================================
   §58 — WIDOW WORD PREVENTION (TEXT BALANCE)
   Prevent single orphan words on new lines
   ======================================== */

h1,
h2,
h3,
h4,
.hero-title,
.platform-hero__title,
.section-intro__title,
.feature-card__title,
.cta-card__title {
  text-wrap: balance; /* Modern CSS - balances line lengths */
  -webkit-hyphens: auto;
  hyphens: auto;
  word-break: break-word;
  overflow-wrap: break-word;
}

/* Fallback for older browsers */
@supports not (text-wrap: balance) {
  h1,
  h2,
  h3,
  .hero-title {
    max-width: 95%;
    margin-left: auto;
    margin-right: auto;
  }
}

/* ========================================
   §59 — HORIZONTAL OVERFLOW LOCK (DOUBLE SCROLLBAR FIX)
   Prevent side-to-side wobble from overflowing elements
   ======================================== */

html {
  overflow-x: hidden !important;
  width: 100% !important;
  max-width: 100vw !important;
}

body {
  overflow-x: hidden !important;
  width: 100% !important;
  max-width: 100% !important;
  position: relative;
}

/* Catch any overflowing containers */
.container,
.site-header__inner,
.platform-hero,
.newsletter-section,
section,
main {
  max-width: 100% !important;
  overflow-x: hidden;
}

/* ========================================
   §60 — LAYOUT SHIFT PREVENTION (CLS FIX)
   Reserve space for dynamic content before it loads
   ======================================== */

/* Stats containers need minimum height to prevent CLS */
.hero-stat,
.pipeline-stat,
.stat-value,
[data-fetch-stats],
.platform-hero__stats {
  min-height: 60px;
  min-width: 80px;
}

.platform-hero__stats {
  min-height: 80px;
}

/* Skeleton loader for stats while loading */
.hero-stat__value:empty,
.stat-value:empty,
.stat-value[data-loading='true'] {
  background-color: var(--color-surface-alt, #f0f0f0);
  animation: skeleton-shimmer 1.5s ease-in-out 3;
  border-radius: 4px;
  min-width: 60px;
  min-height: 1.5em;
  display: inline-block;
}

@keyframes skeleton-shimmer {
  0% {
    opacity: 0.6;
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0.6;
  }
}

/* ========================================
   §61 — HEADER CRUSH FIX (360-375px VIEWPORTS)
   Hide theme/text controls on ultra-small screens
   ======================================== */

/* NUCLEAR: On screens < 400px, ONLY show logo + hamburger */
@media (max-width: 400px) {
  /* Hide ALL utility controls */
  .site-header__actions .theme-toggle,
  .site-header__actions .theme-options,
  .site-header__actions .text-options,
  .site-header__actions .header-search,
  .site-header__actions .header-search-toggle,
  .theme-controls,
  .text-controls {
    display: none !important;
    visibility: hidden !important;
    width: 0 !important;
    height: 0 !important;
    overflow: hidden !important;
  }

  /* Only keep hamburger and subscribe (icon only) */
  .site-header__actions {
    gap: 8px !important;
    max-width: 120px !important;
  }

  /* Shrink subscribe to icon-only */
  .newsletter-cta {
    width: 40px !important;
    height: 40px !important;
    padding: 8px !important;
  }

  .newsletter-cta__label {
    display: none !important;
  }

  /* Shrink hamburger */
  .nav-toggle {
    width: 40px !important;
    height: 40px !important;
  }

  /* Truncate branding title */
  .branding__title {
    font-size: 0.85rem !important;
    line-height: 1.1 !important;
    white-space: normal !important;
    text-wrap: balance;
  }

  /* Reduce header padding */
  .site-header__inner {
    padding: 8px 12px !important;
    gap: 8px !important;
  }
}

/* Medium small screens (400-480px) - still compact */
@media (max-width: 480px) and (min-width: 401px) {
  .site-header__actions .theme-toggle,
  .site-header__actions .theme-options,
  .site-header__actions .text-options {
    display: none !important;
  }

  .site-header__actions {
    gap: 8px !important;
  }

  .branding__title {
    font-size: 0.9rem !important;
    line-height: 1.1 !important;
    white-space: normal !important;
    text-wrap: balance;
  }
}

/* ========================================
   §62 — CHAT WIDGET FOOTER COLLISION FIX (ENHANCED)
   Dynamically position chat to avoid footer overlap
   ======================================== */

/* Increase footer bottom padding significantly on mobile */
@media (max-width: 768px) {
  .site-footer {
    padding-bottom: calc(120px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Footer links need higher z-index and extra spacing */
  .site-footer a,
  .site-footer button,
  .site-footer .footer-link {
    position: relative;
    z-index: 10 !important;
    padding: 12px !important;
    display: inline-block;
  }

  /* Privacy/Terms links specifically */
  .footer-legal a,
  .footer-bottom a,
  a[href*='privacy'],
  a[href*='terms'] {
    padding: 16px !important;
    margin-right: 80px !important; /* Clear space for chat bubble */
  }
}

/* Chat widget must not cover bottom-right content */
#aiwp-chatbot-launcher,
.aiwp-chatbot-launcher,
.chat-widget {
  z-index: 9990 !important; /* Lower than 9999 to allow footer interaction when needed */
}

/* When user is at footer, chat should be less intrusive */
@media (max-width: 480px) {
  #aiwp-chatbot-launcher,
  .aiwp-chatbot-launcher {
    width: 48px !important;
    height: 48px !important;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 16px) !important;
    right: calc(env(safe-area-inset-right, 0px) + 12px) !important;
  }
}

/* ========================================
   §63 — GHOST LABEL FLASH FIX (FOUC PREVENTION)
   Hide screen-reader text BEFORE CSS loads
   ======================================== */

/* Inline critical hide for sr-only elements */
.screen-reader-text,
.sr-only,
.visually-hidden,
.nav-toggle .screen-reader-text,
[aria-hidden='true'] .screen-reader-text {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
  border: 0 !important;
  font-size: 0 !important;
  line-height: 0 !important;
  visibility: hidden !important;
  opacity: 0 !important;
}

/* Prevent any layout shift from sr-only text */
.nav-toggle {
  position: relative;
  overflow: hidden;
}

/* ========================================
   END OF COMPREHENSIVE FIXES v1.2.0
   All 63 fix categories implemented
   - v1.2.0: Added 10 critical mobile UX fixes
   ======================================== */
