/*
 * Responsive layer for landing pages built with inline desktop styles
 * (module pages, ad versions and the new landing pages).
 * Loaded after the page's own styles; the !important rules override inline styles.
 */

/* Pages exported at a fixed desktop width: let them fill the screen instead. */
body > div[style*="width: 1440px"] { width: auto !important; max-width: 100% !important; }
img, video, iframe { max-width: 100%; }

@media (max-width: 960px) {
  /* Side-by-side layout rows (wide gaps, or spread across the row) wrap onto new lines. */
  [style*="display: flex"]:not([style*="flex-direction: column"])[style*="gap: 2"],
  [style*="display: flex"]:not([style*="flex-direction: column"])[style*="gap: 3"],
  [style*="display: flex"]:not([style*="flex-direction: column"])[style*="gap: 4"],
  [style*="display: flex"]:not([style*="flex-direction: column"])[style*="gap: 5"],
  [style*="display: flex"]:not([style*="flex-direction: column"])[style*="gap: 6"],
  [style*="display: flex"]:not([style*="flex-direction: column"])[style*="gap: 7"],
  [style*="display: flex"]:not([style*="flex-direction: column"])[style*="gap: 8"],
  [style*="display: flex"]:not([style*="flex-direction: column"])[style*="justify-content: space-between"] {
    flex-wrap: wrap !important;
  }
  /* Items in those rows share the row on tablets and stack on phones. */
  [style*="display: flex"]:not([style*="flex-direction: column"])[style*="gap: 2"] > *:not(img),
  [style*="display: flex"]:not([style*="flex-direction: column"])[style*="gap: 3"] > *:not(img),
  [style*="display: flex"]:not([style*="flex-direction: column"])[style*="gap: 4"] > *:not(img),
  [style*="display: flex"]:not([style*="flex-direction: column"])[style*="gap: 5"] > *:not(img),
  [style*="display: flex"]:not([style*="flex-direction: column"])[style*="gap: 6"] > *:not(img),
  [style*="display: flex"]:not([style*="flex-direction: column"])[style*="gap: 7"] > *:not(img),
  [style*="display: flex"]:not([style*="flex-direction: column"])[style*="gap: 8"] > *:not(img) {
    flex: 1 1 260px !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }
  /* Every other flex item (icon + text rows, badges) may shrink instead of pushing the page wider. */
  [style*="display: flex"] > * { min-width: 0; }

  /* Grids: as many columns as fit, never narrower than the screen allows. */
  [style*="display: grid"] {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)) !important;
  }
  [style*="display: grid"] > * { min-width: 0; }
  [style*="grid-column: span"] { grid-column: 1 / -1 !important; }

  /* Fixed pixel widths shrink to the screen. */
  [style*="width: 3"], [style*="width: 4"], [style*="width: 5"], [style*="width: 6"],
  [style*="width: 7"], [style*="width: 8"], [style*="width: 9"] { max-width: 100% !important; }

  /* Long words and links can break rather than overflow. */
  p, li, h1, h2, h3, h4, a, span, strong, b, td, th, figcaption, blockquote { overflow-wrap: break-word; }
}

@media (max-width: 960px) {
  /* Top bar of standalone landing pages: logo and button keep their natural size. */
  header div[style*="display: flex"][style*="align-items: center"] > *:not(img):not(svg) { flex: 0 1 auto !important; }
  header div[style*="display: flex"] > img { flex: 0 0 auto !important; }
  header div[style*="display: flex"] div[style*="display: flex"][style*="align-items: center"] { flex-wrap: nowrap !important; flex-shrink: 0 !important; }
  header div[style*="display: flex"] div[style*="display: flex"] > * { white-space: nowrap; flex-shrink: 0 !important; }

  /* Badges and labels that must stay on one line keep their width; their row wraps instead. */
  [style*="display: flex"] > [style*="white-space: nowrap"] { flex-shrink: 0 !important; min-width: auto !important; }
  [style*="display: flex"]:has(> [style*="white-space: nowrap"]) { flex-wrap: wrap !important; }
}

@media (max-width: 600px) {
  /* Top bar: the phone number is shown further down the page and in the sticky call bar. */
  header div[style*="display: flex"] div[style*="display: flex"] > :first-child:not(:last-child) { display: none !important; }
  header img[style*="height: 42px"], header img[style*="height: 40px"] { height: 34px !important; }

  /* Scale very large headings for phones. */
  h1[style*="font-size"] { font-size: clamp(28px, 8.2vw, 36px) !important; }
  h2[style*="font-size: 3"], h2[style*="font-size: 4"], h2[style*="font-size: 5"] { font-size: clamp(24px, 7vw, 30px) !important; }

  /* Long labels and badges may wrap on narrow screens. */
  span[style*="white-space: nowrap"], strong[style*="white-space: nowrap"] { white-space: normal !important; }

  /* Big section padding eases off on phones. */
  [style*="padding: 96px 32px"], [style*="padding: 72px 32px"], [style*="padding: 80px 32px"] {
    padding-left: 20px !important; padding-right: 20px !important;
  }
  [style*="padding: 56px 24px"], [style*="padding: 64px 24px"], [style*="padding: 72px 24px"] {
    padding-left: 16px !important; padding-right: 16px !important;
  }

  /* Floating labels pinned to the corners of a screenshot sit underneath it instead of overlapping. */
  [style*="position: absolute"][style*="bottom"][style*="padding: 12px 16px"],
  [style*="position: absolute"][style*="bottom"][style*="padding: 8px 14px"] {
    position: static !important;
    display: inline-block !important;
    margin: 10px 8px 0 0 !important;
    max-width: 100% !important;
  }
}
