/* =============================================================================
   Autofocuss — cross-device layer
   -----------------------------------------------------------------------------
   Loaded on every page, immediately after style.css, so its fluid type and
   breakpoint fixes take precedence over the fixed values there.

   Two jobs:
     A) Shared inner-page chrome (`.af-page-hero`, `.af-page-section`, search
        results, 404, comments) used by page.php / search.php / 404.php /
        index.php — with or without WooCommerce.
     B) Responsive hardening for the existing marketing pages: overflow guards,
        fluid typography, a real tablet tier between 769–1024px, and touch
        target sizing.

   Breakpoints used site-wide: 1200 / 1119 (nav) / 1024 / 900 / 782 / 560 / 380.
   ========================================================================== */


/* =============================================================================
   A.  SHARED INNER-PAGE CHROME
   ========================================================================== */

/* --- Hero band ------------------------------------------------------------
   Carries the offset that clears the fixed 80px header, mirroring
   .case-detail-hero used by posts and case studies. */

.af-page-hero {
  position: relative;
  padding: 140px 24px 56px;
  background: radial-gradient(circle at 80% 20%, var(--accent-glow) 0%, transparent 60%);
  border-bottom: 1px solid var(--border-light);
}

.af-page-hero-inner {
  max-width: 1200px;
  margin: 0 auto;
}

.af-page-hero-title {
  font-family: var(--font-headings);
  font-size: clamp(30px, 5vw, 48px);
  font-weight: 700;
  line-height: 1.12;
  letter-spacing: -0.02em;
  text-transform: uppercase;
  color: var(--text-dark);
  margin: 16px 0 0;
  overflow-wrap: break-word;
}

.af-page-hero .badge-ai + .af-page-hero-title { margin-top: 18px; }

.af-page-hero-subtitle {
  max-width: 700px;
  margin-top: 14px;
  font-size: clamp(15px, 1.6vw, 18px);
  line-height: 1.6;
  color: var(--text-muted-light);
}

.af-page-hero-subtitle p:last-child { margin-bottom: 0; }

/* --- Content section ------------------------------------------------------ */

.af-page-section {
  padding: 56px 24px 100px;
  background: var(--bg-light);
}

.af-page-container {
  max-width: 800px;
  margin: 0 auto;
}

.af-page-container.is-wide { max-width: 1200px; }

.af-page-content { min-width: 0; }

/* Long words and pasted URLs must never widen the page. */
.af-page-content,
.post-content,
.narrative-block { overflow-wrap: break-word; }

/* --- Search results ------------------------------------------------------- */

.af-search-results {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.af-search-result {
  display: grid;
  /* Two columns only when the result actually has a thumbnail — the class is
     set in search.php so no :has() support is required. */
  grid-template-columns: minmax(0, 1fr);
  gap: 24px;
  align-items: center;
  padding: 20px;
  background: var(--card-bg-light);
  border: 1px solid var(--border-light);
  border-radius: 20px;
  transition: transform 0.4s var(--ease-premium), box-shadow 0.4s var(--ease-premium);
}

.af-search-result:hover {
  transform: translateY(-4px);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.05);
}

.af-search-result.has-thumb { grid-template-columns: 220px minmax(0, 1fr); }

.af-search-thumb {
  display: block;
  border-radius: 14px;
  overflow: hidden;
  background: #f1f5f9;
  aspect-ratio: 4 / 3;
}

.af-search-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.af-search-body { min-width: 0; }

.af-search-type {
  display: inline-block;
  margin-bottom: 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--accent-primary);
}

.af-search-title {
  font-family: var(--font-headings);
  font-size: clamp(19px, 2.4vw, 24px);
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 10px;
}

.af-search-title a {
  color: var(--text-dark);
  text-decoration: none;
  transition: color 0.3s ease;
}

.af-search-title a:hover { color: var(--accent-primary); }

.af-search-excerpt {
  margin-bottom: 16px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-muted-light);
}

.af-search-result .price {
  display: block;
  margin-bottom: 10px;
  font-family: var(--font-headings);
  font-size: 19px;
  font-weight: 700;
  color: var(--accent-primary);
}

.af-search-again {
  max-width: 520px;
  margin: 32px auto 0;
}

.af-search-again form,
.search-form,
.wp-block-search__inside-wrapper {
  display: flex;
  gap: 10px;
}

.af-search-again input[type="search"],
.search-form input[type="search"] {
  flex: 1;
  min-width: 0;
  min-height: 48px;
  padding: 12px 18px;
  background: #fff;
  border: 1px solid var(--border-light);
  border-radius: 100px;
  font-family: var(--font-body);
  /* 16px keeps iOS Safari from zooming on focus */
  font-size: 16px;
  color: var(--text-dark);
}

.af-search-again input[type="search"]:focus,
.search-form input[type="search"]:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.af-search-again input[type="submit"],
.search-form input[type="submit"],
.search-form button[type="submit"] {
  min-height: 48px;
  padding: 12px 26px;
  background: var(--accent-primary);
  color: #fff;
  border: 1px solid var(--accent-primary);
  border-radius: 100px;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.search-form label { flex: 1; min-width: 0; }
.search-form label input[type="search"] { width: 100%; }

/* --- 404 ------------------------------------------------------------------ */

.af-404-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
}

.af-404-actions a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
}

/* --- Comments / product reviews ------------------------------------------ */

.af-comments { margin-top: 56px; }

.af-comments-title {
  font-family: var(--font-headings);
  font-size: 22px;
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 20px;
}

.af-comment-list {
  margin: 0 0 40px;
  padding: 0;
  list-style: none;
}

.af-comment-list ol.children {
  margin: 16px 0 0 clamp(12px, 4vw, 40px);
  padding: 0;
  list-style: none;
}

.af-comment-list li.comment,
.af-comment-list li.pingback {
  margin-bottom: 16px;
  padding: 22px;
  background: var(--card-bg-light);
  border: 1px solid var(--border-light);
  border-radius: 18px;
  list-style: none;
}

.af-comment-list .comment-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--text-muted-light);
}

.af-comment-list .comment-author img {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  vertical-align: middle;
  margin-right: 8px;
}

.af-comment-list .comment-content {
  font-size: 15px;
  line-height: 1.7;
  color: var(--text-muted-light);
  overflow-wrap: break-word;
}

.af-comment-list .reply a {
  display: inline-block;
  margin-top: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-primary);
  text-decoration: none;
}

.af-comment-form input[type="text"],
.af-comment-form input[type="email"],
.af-comment-form input[type="url"],
.af-comment-form textarea,
.comment-form input[type="text"],
.comment-form input[type="email"],
.comment-form input[type="url"],
.comment-form textarea {
  width: 100%;
  min-height: 48px;
  padding: 12px 16px;
  background: #fff;
  border: 1px solid var(--border-light);
  border-radius: 12px;
  font-family: var(--font-body);
  font-size: 16px;
  color: var(--text-dark);
}

.comment-form textarea { min-height: 140px; resize: vertical; }

.comment-form p { margin-bottom: 16px; }

.comment-form label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-dark);
}

.comment-form input[type="submit"] {
  min-height: 48px;
  padding: 13px 32px;
  background: var(--accent-primary);
  color: #fff;
  border: none;
  border-radius: 100px;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.af-comments-closed {
  font-size: 15px;
  color: var(--text-muted-light);
}

/* --- Utilities ------------------------------------------------------------ */

.screen-reader-text {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.screen-reader-text:focus {
  position: fixed !important;
  top: 8px;
  left: 8px;
  z-index: 100000;
  width: auto;
  height: auto;
  clip: auto;
  padding: 12px 20px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.page-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 32px;
  font-size: 14px;
}

.page-links a {
  padding: 6px 14px;
  border: 1px solid var(--border-light);
  border-radius: 100px;
  color: var(--text-dark);
  text-decoration: none;
}


/* =============================================================================
   B.  RESPONSIVE HARDENING
   ========================================================================== */

/* --- 1. Overflow guards ---------------------------------------------------
   A single oversized element used to force the whole document to scroll
   sideways on phones. Media is capped and wide blocks scroll inside
   themselves instead of widening the page. */

img,
svg,
video,
canvas,
iframe,
embed,
object {
  max-width: 100%;
}

img,
video { height: auto; }

/* Media that carries explicit sizing keeps it. */
.logo-img,
.custom-cursor,
.custom-cursor-dot,
.connection-svg,
.ai-interactive-hub svg { max-width: none; }

.logo-img { max-width: 100%; }

pre,
code,
kbd,
samp { overflow-wrap: break-word; }

pre { overflow-x: auto; }

table { max-width: 100%; }

/* Content tables scroll rather than stretch the layout. */
.post-content table,
.narrative-block table,
.af-page-content table {
  display: block;
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-collapse: collapse;
}

/* --- 2. Text selection ----------------------------------------------------
   style.css applies `* { user-select: none }` for an app-like feel. That also
   stops visitors copying post text, addresses, order numbers and form input,
   so selection is restored wherever real content lives. */

.post-content,
.post-content *,
.narrative-block,
.narrative-block *,
.af-page-content,
.af-page-content *,
.af-page-hero-title,
.af-page-hero-subtitle,
.af-comments,
.af-comments *,
.af-search-result,
.af-search-result *,
input,
textarea,
select,
[contenteditable="true"] {
  -webkit-user-select: text;
  user-select: text;
}

/* --- 3. Fluid typography --------------------------------------------------
   Replaces the fixed 72 → 54 → 40px steps with a continuous scale, so the
   in-between widths (large phones, 800–1000px tablets) stop overflowing or
   leaving oversized gaps. */

.hero-title    { font-size: clamp(32px, 6.2vw, 72px); }
.section-title { font-size: clamp(28px, 4.4vw, 48px); }
.ai-title      { font-size: clamp(24px, 3.6vw, 48px); }
.automation-title { font-size: clamp(24px, 3.4vw, 42px); }
.case-detail-title { font-size: clamp(28px, 4.4vw, 48px); }
.hero-subtitle { font-size: clamp(15px, 1.7vw, 18px); }

.hero-title,
.section-title,
.ai-title,
.card-title,
.case-detail-title,
.af-page-hero-title { overflow-wrap: break-word; }

/* --- 4. Tablet tier (769–1024px) ------------------------------------------
   style.css jumps straight from a 3-column desktop grid to a single column at
   1024px, which wastes most of the width on tablets and large phones in
   landscape. These give that range a real 2-column layout. */

@media (min-width: 769px) and (max-width: 1024px) {
  .niches-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
  .niches-grid > *:only-child { grid-column: 1 / -1; }

  .team-visual-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .footer-top { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 40px; }

  .section-container { padding: 80px 24px; }
}

/* --- 5. Header & navigation ----------------------------------------------- */

/* Tighten the row just above the hamburger breakpoint so the links never wrap. */
@media (max-width: 1240px) and (min-width: 1120px) {
  .nav-menu { gap: 18px; }
  .nav-item { font-size: 13px; }
}

.nav-container { gap: 16px; }

/* The nav row must never be the thing that overflows. */
.nav-menu { min-width: 0; }

/* Mobile panel: scrollable, and clear of the fixed header + notches. */
@media (max-width: 1119px) {

  .mobile-nav {
    height: 100vh;
    height: 100dvh;
    align-items: flex-start;
    justify-content: center;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 96px 24px calc(40px + env(safe-area-inset-bottom));
  }

  .mobile-nav-links {
    width: 100%;
    max-width: 420px;
    gap: 22px;
  }

  .mobile-nav-item {
    font-size: clamp(20px, 5.2vw, 28px);
    /* comfortable tap target */
    padding: 4px 0;
  }
}

/* Page behind the open overlay must not scroll (set by main.js).
   No `touch-action: none` here — it would inherit into the panel and block
   scrolling of the menu itself; `overscroll-behavior` on .mobile-nav handles
   the rubber-band instead. */
body.mobile-nav-open { overflow: hidden; }

/* Short viewports (landscape phones) need tighter spacing to avoid clipping. */
@media (max-width: 1119px) and (max-height: 560px) {
  .mobile-nav { padding-top: 88px; }
  .mobile-nav-links { gap: 14px; }
  .mobile-nav-item { font-size: 18px; }
}

/* --- 6. Touch targets ------------------------------------------------------ */

@media (pointer: coarse) {
  .nav-btn,
  .nav-btn-primary,
  .btn-primary,
  .btn-secondary,
  .btn-primary-outline,
  .mobile-nav-btn,
  .blog-pagination .page-numbers,
  .hamburger-menu {
    min-height: 44px;
  }

  .hamburger-menu {
    min-width: 44px;
    justify-content: center;
    gap: 5px;
  }

  /* The custom cursor is meaningless without a pointer. */
  .custom-cursor,
  .custom-cursor-dot { display: none !important; }
}

/* --- 7. Footer ------------------------------------------------------------ */

@media (max-width: 900px) {
  .footer-container { padding: 60px 20px 32px; }
  .footer-top { gap: 36px; margin-bottom: 44px; }
}

@media (max-width: 782px) {
  .footer-bottom {
    flex-direction: column;
    align-items: flex-start;
    gap: 20px;
    text-align: left;
  }
  .footer-bottom .social-links { flex-wrap: wrap; }
}

/* --- 8. Shared section spacing -------------------------------------------- */

@media (max-width: 1024px) {
  .af-page-hero { padding: 120px 20px 44px; }
  .af-page-section { padding: 40px 20px 80px; }
  .case-detail-hero { padding: 120px 20px 56px; }
  .case-narrative-section { padding: 48px 20px 80px; }
}

@media (max-width: 782px) {
  .af-page-hero { padding: 108px 16px 36px; }
  .af-page-section { padding: 32px 16px 64px; }
  .case-detail-hero { padding: 104px 16px 44px; }
  .case-narrative-section { padding: 36px 16px 64px; }

  .af-search-result,
  .af-search-result.has-thumb {
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
  }
  .af-search-thumb { aspect-ratio: 16 / 9; }

  .af-404-actions a { width: 100%; }

  .af-search-again form,
  .search-form { flex-wrap: wrap; }
  .af-search-again input[type="submit"],
  .search-form input[type="submit"] { width: 100%; }

  .post-nav { flex-direction: column; }
  .post-nav a { max-width: 100%; }
  .post-nav a[rel="next"] { text-align: left; margin-left: 0; }
}

@media (max-width: 560px) {
  .af-page-hero { padding: 100px 16px 30px; }
  .af-comment-list li.comment { padding: 18px; }
  .blog-pagination .page-numbers {
    min-width: 40px;
    height: 40px;
    padding: 0 10px;
    font-size: 14px;
  }
}

/* --- 9. Motion preferences ------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .custom-cursor,
  .custom-cursor-dot { display: none !important; }
}
