/* ==========================================================================
   Foldables, dual-screen and high-DPR displays
   --------------------------------------------------------------------------
   Targets that the existing breakpoints (900 / 700 / 520) miss:

     280px   Galaxy Fold (1st gen) cover screen
     320px   Galaxy Z Fold4 cover / iPhone SE
     344px   Galaxy Z Fold5 cover
     540px   Surface Duo, single pane
     720px   Surface Duo, spanned across both panes
     904px   Galaxy Z Fold5 unfolded (inner screen)

   Loaded after unified.css so it wins on equal specificity.
   ========================================================================== */


/* --------------------------------------------------------------------------
   1. Surface Duo spanned (720px) and Fold unfolded (904px)
   --------------------------------------------------------------------------
   The desktop nav shows from 701px up, but the 8-item nav needs ~745px to
   fit. Measured: at 720px the last nav item ended at 731px on a 720px
   viewport. Use the drawer from 701px to 1000px so Duo-spanned, small
   tablets and the unfolded Fold all get a nav that fits.
   -------------------------------------------------------------------------- */
@media (min-width: 701px) and (max-width: 1000px) {

  #header .menu-btn {
    display: block;
    position: relative;
    z-index: 10001;
  }

  #header #primary-nav,
  #header .nav-links {
    position: fixed;
    top: 64px;
    left: 0;
    right: 0;
    width: 100%;
    max-width: none;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 10px 24px 26px;
    background: #fff;
    box-shadow: 0 18px 44px -18px rgba(11, 34, 57, .28);
    height: calc(100dvh - 64px);
    overflow-y: auto;
    transform: translateY(-12px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: transform .45s cubic-bezier(.22, 1, .36, 1), opacity .35s ease, visibility 0s .45s;
    z-index: 9000;
  }

  body.menu-locked #header #primary-nav,
  body.menu-locked #header .nav-links {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: transform .45s cubic-bezier(.22, 1, .36, 1), opacity .35s ease, visibility 0s 0s;
  }

  #header .nav-links a {
    display: block;
    width: 100%;
    padding: 13px 0;
    min-height: 46px;
    font-size: 16px;
    font-weight: 600;
    text-align: left;
  }

  #header .nav-links a::after {
    display: none;
  }

  #header .nav-links .nav-cta,
  #header .nav-links .cta {
    margin-top: auto;
    text-align: center;
    justify-content: center;
    border-radius: 10px;
    padding: 15px 16px;
  }

  body.menu-locked::after {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(11, 34, 57, .45);
    z-index: 8000;
    pointer-events: none;
  }

  html:has(body.menu-locked) {
    overflow: hidden !important;
  }

  body.menu-locked {
    overflow: hidden !important;
  }
}


/* --------------------------------------------------------------------------
   2. Narrow foldable cover screens (<= 400px)
   --------------------------------------------------------------------------
   The Fold5 cover is 344px and the original Fold is 280px. At those widths
   the 24px gutters plus fixed-width children left almost no usable column,
   and .showcase-left was 288px wide inside a 240px parent.
   -------------------------------------------------------------------------- */
@media (max-width: 400px) {

  .wrap,
  .clients .wrap {
    padding-left: 16px;
    padding-right: 16px;
  }

  /* nothing may impose a width wider than the column */
  .showcase-left,
  .showcase-right,
  .model-cards-list,
  .column-title,
  .column-description,
  .overline-label,
  .cs-hero-card,
  .cs-stage-grid,
  .form-card,
  .prod-card,
  .jx-stage,
  .pr-stage {
    max-width: 100% !important;
    min-width: 0 !important;
    width: auto !important;
  }

  /* headline scales with the viewport instead of sitting at 38px */
  .hero h1 {
    font-size: clamp(25px, 8.4vw, 34px);
    line-height: 1.16;
    letter-spacing: -0.02em;
  }

  .hero .lead {
    font-size: 15.5px;
    line-height: 1.58;
  }

  .h2,
  .tech-h2,
  .clients-h2,
  .testi-title {
    font-size: clamp(21px, 6.6vw, 27px);
    line-height: 1.2;
  }

  .sub,
  .tech-sub,
  .clients-sub,
  .testi-sub {
    font-size: 14px;
  }

  .sec-head {
    width: 100% !important;
    margin-bottom: 1.4rem;
  }

  /* full-width stacked buttons — 250px + 162px could not sit side by side */
  .hero-ctas {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-top: 26px;
  }

  .hero-ctas .btn {
    width: 100%;
    justify-content: center;
    padding: 13px 16px;
    font-size: 14.5px;
  }

  .hero-proof {
    gap: 10px;
    font-size: 12.5px;
    margin-top: 26px;
  }

  .hero-proof .sep {
    display: none;
  }

  section {
    padding: 34px 0;
  }

  .hero {
    padding-top: 84px;
  }

  /* logo must not eat the whole bar on a 280px screen */
  #header .brand img,
  #header .logo img {
    height: 38px;
  }

  #header .wrap {
    padding-left: 16px;
    padding-right: 16px;
  }

  /* stat / metric grids go single column */
  .stats-grid,
  .kpis,
  .cs-metrics,
  .prod-feats,
  .vals,
  .fgrid {
    grid-template-columns: 1fr !important;
  }

  .f-grid {
    grid-template-columns: 1fr !important;
    gap: 28px;
  }

  /* tech + client pills shrink */
  .mq-item,
  .client-item {
    padding: 6px 12px 6px 7px;
    margin: 0 5px;
  }

  .mq-name {
    font-size: 12px;
  }

  .client-name {
    font-size: 12.5px;
  }

  .filter-chip {
    font-size: 0.72rem;
    padding: 5px 10px;
  }

  /* forms: 16px minimum stops iOS Safari zooming the page on focus */
  .f-field input,
  .f-field select,
  .f-field textarea,
  .apply-form input,
  .apply-form select,
  .apply-form textarea {
    font-size: 16px;
  }

  .cta {
    padding: 30px 20px;
  }

  .cta h2 {
    font-size: clamp(21px, 6.4vw, 27px);
  }

  .cta p {
    font-size: 14.5px;
  }
}


/* --------------------------------------------------------------------------
   3. Very narrow: original Galaxy Fold cover (280px)
   -------------------------------------------------------------------------- */
@media (max-width: 300px) {

  .wrap,
  #header .wrap {
    padding-left: 12px;
    padding-right: 12px;
  }

  .hero h1 {
    font-size: 23px;
  }

  #header .brand img,
  #header .logo img {
    height: 34px;
  }

  .hero-proof {
    display: none;
  }
}


/* --------------------------------------------------------------------------
   4. Fold / Duo hinge awareness
   --------------------------------------------------------------------------
   When the page is spanned across two panes, keep content out of the hinge
   using the viewport-segment environment variables. Browsers that do not
   support these simply ignore the block.
   -------------------------------------------------------------------------- */
@media (horizontal-viewport-segments: 2) {

  .wrap {
    max-width: env(viewport-segment-right 0 0);
    margin-left: 0;
    margin-right: auto;
    padding-left: 24px;
    padding-right: 24px;
  }

  /* two-column layouts map to the two physical panes */
  .hero-grid,
  .inq-grid,
  .faq-grid {
    grid-template-columns: 1fr;
  }
}

@media (vertical-viewport-segments: 2) {

  .hero {
    padding-top: 74px;
    padding-bottom: 18px;
  }
}


/* --------------------------------------------------------------------------
   5. High-DPR / retina rendering
   --------------------------------------------------------------------------
   On 2x and 3x screens, hairline borders and small shadows render heavier
   than intended, and SVG/logo edges benefit from explicit smoothing.
   -------------------------------------------------------------------------- */
@media (-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {

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

  /* 1px borders are 2-3 device px on retina and read as chunky */
  .card,
  .mq-item,
  .client-item,
  .f-field input,
  .f-field select,
  .f-field textarea,
  .role,
  .val,
  .testi-card,
  .prod-card,
  .jx-tab,
  .pr-tile {
    border-width: 0.5px;
  }

  /* keep logo + icon edges crisp when scaled */
  .brand img,
  .logo img,
  .f-logo img,
  .mq-icon img,
  .client-mark img {
    image-rendering: -webkit-optimize-contrast;
  }
}


/* --------------------------------------------------------------------------
   6. iOS Safari specifics
   -------------------------------------------------------------------------- */

/* respect the notch / Dynamic Island and the home indicator */
@supports (padding: max(0px)) {

  .wrap,
  #header .wrap {
    padding-left: max(24px, env(safe-area-inset-left));
    padding-right: max(24px, env(safe-area-inset-right));
  }

  /* narrow foldable covers keep their tighter gutters */
  @media (max-width: 400px) {

    .wrap,
    #header .wrap {
      padding-left: max(16px, env(safe-area-inset-left));
      padding-right: max(16px, env(safe-area-inset-right));
    }
  }

  @media (max-width: 300px) {

    .wrap,
    #header .wrap {
      padding-left: max(12px, env(safe-area-inset-left));
      padding-right: max(12px, env(safe-area-inset-right));
    }
  }

  footer.site,
  footer {
    padding-bottom: max(34px, env(safe-area-inset-bottom));
  }

  /* NOTE: must be ADDED to the header's own 16px padding, not replace it.
     `padding-top: env(safe-area-inset-top)` resolves to 0px on every
     non-notched screen, which silently flattened the header. */
  #header {
    padding-top: calc(16px + env(safe-area-inset-top));
  }
}

/* 100vh on iOS includes the address bar and causes a jump on scroll */
@supports (height: 100dvh) {

  .nav-links,
  #primary-nav,
  .topnav {
    max-height: calc(100dvh - 64px);
  }
}

/* iOS momentum scrolling inside the drawer */
.nav-links,
#primary-nav,
.topnav {
  -webkit-overflow-scrolling: touch;
}

/* stop the grey tap flash on iOS */
a,
button,
.btn,
summary,
.role-head {
  -webkit-tap-highlight-color: rgba(21, 101, 192, .12);
}


/* --------------------------------------------------------------------------
   7. Header parity across home / blog / careers
   --------------------------------------------------------------------------
   The blog + careers templates carry their own .brand rules and the main
   site uses .logo; their breakpoints did not line up (templates dropped to
   38px only below 700px, leaving blog/careers at 46px where home was 56px).
   These rules cover BOTH selectors so the header is identical everywhere.
   Appended last so they win on source order.
   -------------------------------------------------------------------------- */

@media (min-width: 701px) and (max-width: 1000px) {

  #header .logo img,
  #header .brand img,
  header.top .brand img {
    height: 48px !important;
  }
}

@media (max-width: 700px) {

  #header .logo img,
  #header .brand img,
  header.top .brand img {
    height: 38px !important;
  }
}

@media (max-width: 300px) {

  #header .logo img,
  #header .brand img,
  header.top .brand img {
    height: 34px !important;
  }
}


/* blog/careers show .topnav inline until 700px, so between 701-1000px the
   8 links wrapped onto a second row and made the header 102px vs 81px on
   home. Use the drawer there too, matching the main site. */
@media (min-width: 701px) and (max-width: 1000px) {

  header.top .menu-btn {
    display: flex !important;
  }

  header.top .topnav {
    position: fixed;
    inset: 81px 0 auto 0;
    background: #fff;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 8px 0 32px;
    border-bottom: 1px solid var(--line, #e5ebf2);
    box-shadow: 0 12px 28px rgba(11, 31, 58, .10);
    transform: translateY(-12px);
    opacity: 0;
    pointer-events: none;
    transition: .22s ease;
    height: calc(100dvh - 81px);
    max-height: calc(100dvh - 81px);
    overflow-y: auto;
    justify-content: flex-start;
    z-index: 9000;
  }

  header.top .topnav.open {
    transform: none;
    opacity: 1;
    pointer-events: auto;
  }

  header.top .topnav a {
    padding: 14px 24px;
    font-size: 16px;
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  header.top .topnav a.cta {
    margin: 12px 24px 0;
    justify-content: center;
    border-radius: 9px;
  }
}


/* ---------- FIX: no navigation at all between 701-1000px ----------
   unified.css hides `.header-actions` on desktop (it held a duplicate CTA).
   The hamburger lives INSIDE that container, so at 701-1000px the drawer
   rules set `.menu-btn{display:block}` but the parent stayed display:none —
   the button collapsed to 0x0.

   Net effect on a Galaxy Fold unfolded to 904px, or any small tablet:
   the desktop nav is switched to the drawer, and the drawer's only trigger
   is invisible. The header renders as a logo and nothing else, and the site
   cannot be navigated from the header at all.

   The parent must be shown again wherever the drawer is in use. */
@media (min-width: 701px) and (max-width: 1000px) {

  #header .header-actions {
    display: flex !important;
    align-items: center;
    gap: 10px;
    margin-left: auto;
  }

  /* only the hamburger belongs there at this width — the drawer carries
     its own CTA, so a second one would duplicate it */
  #header .header-actions > *:not(.menu-btn) {
    display: none !important;
  }

  #header .menu-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
  }

  /* keep the row balanced: logo left, burger right */
  #header nav {
    justify-content: space-between;
  }
}


/* At 701-1000px the drawer is phone-sized on a much taller/wider screen:
   links pool at the top, the CTA pins to the bottom, leaving a ~660px void.
   Group them and centre the group instead of pushing them apart. */
@media (min-width: 701px) and (max-width: 1000px) {

  #header .nav-links {
    justify-content: center;
    gap: 4px;
    padding: 24px 0 32px;
  }

  #header .nav-links > a:not(:last-child) {
    font-size: 22px;
    padding: 14px 0;
  }

  /* CTA follows the links instead of being pushed to the far bottom */
  #header .nav-links > a:last-child {
    margin-top: 28px;
    max-width: 320px;
    align-self: flex-start;
    margin-left: 24px;
    width: 100%;
  }

  /* trim the oversized head gap so the group reads as one block */
  #header .nav-links {
    padding-top: 12px;
  }
}


/* ---------- Fold 7 / large inner screens: make the header width-proof ----------
   Previous fixes assumed the drawer handles <=1000px and the inline nav handles
   >1000px. A Fold 7 inner screen (or any device reporting ~1000-1200px, or a
   tablet in "Desktop site" mode) lands just above the cliff, where the 8-item
   nav has to fit next to the logo with no fallback. Rather than guess the exact
   width, the header now degrades gracefully at ANY width:

   1. The nav row may shrink and wrap-protect itself.
   2. If the links cannot fit, they scroll horizontally instead of overlapping.
   3. The hamburger is never trapped inside a display:none parent again. */

@media (min-width: 1001px) and (max-width: 1240px) {

  /* tighten spacing so 8 items + logo fit without colliding */
  #header .nav-links {
    gap: clamp(10px, 1.6vw, 22px);
    min-width: 0;
    flex-wrap: nowrap;
  }

  #header .nav-links > a {
    font-size: clamp(13px, 1.25vw, 15px);
    white-space: nowrap;
  }

  #header .nav-links > a:last-child {
    padding-left: clamp(12px, 1.4vw, 18px);
    padding-right: clamp(12px, 1.4vw, 18px);
  }

  #header .logo img,
  #header .brand img {
    height: 48px;
  }

  /* last-resort: never let links sit on top of the logo */
  #header nav {
    gap: 16px;
    min-width: 0;
  }
}

/* Absolute safety net at every width: the header row never overlaps.
   If the links genuinely cannot fit, they scroll rather than collide. */
#header nav {
  align-items: center;
}

#header .logo,
#header .brand {
  flex: 0 0 auto;
}

@media (min-width: 1001px) {
  #header .nav-links {
    overflow-x: auto;
    overflow-y: visible;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
  #header .nav-links::-webkit-scrollbar { display: none; }
}


/* ---------- Single source of truth for the header nav switch ----------
   Root cause of "no hamburger on Fold 7": the button was hidden indirectly,
   by its PARENT (.header-actions) being display:none, and un-hidden only
   inside narrow breakpoint bands. Any width that fell outside a band lost
   the button with no fallback.

   Now the switch is stated once, directly on the elements that matter:
     <= 1000px  -> hamburger visible, inline nav off
     >  1000px  -> inline nav on, hamburger hidden
   Nothing hides .header-actions, so the button can never be orphaned. */

@media (max-width: 1000px) {
  #header .header-actions { display: flex !important; }
  #header .menu-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
  }
}

@media (min-width: 1001px) {
  #header .menu-btn { display: none !important; }
}
