/*
 * mobile.css — the phone layout of every page.
 *
 * The pages are laid out for desktop and squeezed below 1024 px. These rules fit them to a
 * phone the way Ramp's mobile site does: the same components, content and inner
 * arrangement; only the fit changes (one column, phone spacing and type, product screens
 * shown larger and cropped at an edge, nothing sticky that covers content).
 *
 * The elements are marked with `data-m` tokens by scripts/mobile/build.mjs (rules.mjs says
 * what each token matches). Inline styles carry the desktop design, so these rules need
 * !important. Every rule sits inside a max-width query: desktop (1024 px and up) is never
 * touched.
 */

/* ───────── viewport variants, before any script runs ─────────
 *
 * The server has no viewport, so a page renders BOTH its desktop and its phone version and
 * these rules hide the one that does not apply (scripts/mobile "viewport pass"). The hidden
 * one is display:none: out of the layout, the focus order and the accessibility tree.
 * `data-vp="d"` is on the top-level elements of the desktop version, `"m"` on the phone's.
 * The two media queries are exact complements (no width shows both or neither).
 *
 * `--vp-m` is 1 on a phone and 0 elsewhere. Geometry that used to come from `mobile` in the
 * page logic is a `--vp-*` custom property: desktop values on :root in the page's own
 * <style data-vp-geometry>, phone values in the same block inside the phone query. */
:root {
  --vp-m: 0;
}
@media (max-width: 1023.98px) {
  :root {
    --vp-m: 1;
    /* homepage audience cards: no hover-grow on a phone (page logic sets the desktop value) */
    --vp-audFlex: none;
  }
  [data-vp="d"] {
    display: none !important;
  }
}
@media not all and (max-width: 1023.98px) {
  [data-vp="m"] {
    display: none !important;
  }
}

/* ───────── script-sized elements, before their script runs ─────────
 *
 * Each of these takes its size from a script that runs after hydration. Until it has, the
 * server HTML reserves the box the hydrated element will have, so nothing jumps and nothing
 * overflows the screen. Every rule is for the not-yet-upgraded state only and (fixed-art)
 * only on a phone; once the script has run the rules stop matching and the page is exactly
 * what it was.
 *
 * Family 1: fixed-art stages (website/fixed-art.js). The script lays a stage out at its
 *   design width and writes `zoom = min(1, parent content width / design width)` when it
 *   first fits the stage (it then sets data-fa-id). Before that: the stage shrinks to the
 *   parent (max-width:100%), clips, and where its height is fixed keeps the design aspect
 *   ratio, which is the height the zoom gives it. Stages with a content height have no
 *   known ratio: they reflow to the parent width and clip, and settle when the zoom lands.
 * Family 2: onx-* drawings (website/onx-kit.js and friends). The kit sets the height of an
 *   element that has none from its own design size (`clientHeight < 10`), so the element
 *   keeps a box of that ratio until it is defined; defined, the rule stops and the kit
 *   sets a pixel height from the same ratio. An element that has a height from its parent
 *   (position:absolute;inset:0 panels inside a stage) needs nothing. onx-intuitiondb draws
 *   a different layout above and below 600 px, so it has no single ratio and is not
 *   reserved.
 * Family 3: <ot-arrow> is reserved in lib/dc/base-css.ts. */
@media (max-width: 1023.98px) {
  [data-fixed-art]:not([data-fa-id]) {
    max-width: 100%;
    overflow: hidden;
  }
  [data-fixed-art="564"]:not([data-fa-id]) {
    height: auto !important;
    aspect-ratio: 564 / 600;
  }
  [data-fixed-art="580"]:not([data-fa-id]) {
    height: auto !important;
    aspect-ratio: 580 / 440;
  }
  [data-fixed-art="780"]:not([data-fa-id]) {
    height: auto !important;
    aspect-ratio: 780 / 420;
  }
}
@media (max-width: 639.98px) {
  /* the trimmed product panels (see pp-crop below) are 504 design px tall on a phone */
  [data-fixed-art="564"][data-m~="pp-crop"]:not([data-fa-id]) {
    aspect-ratio: 564 / 504;
  }
}
@media (max-width: 1023.98px) {
  /* Family 4: the hero product mock (page logic: zoom = measured width / 1280). Until the
     width is measured the box keeps the 1280x800 ratio, which is the height the zoom gives
     it, and the unscaled mock is not painted (it would shift every line when the zoom lands). */
  [data-hm-box]:has(> [data-hm="off"]) {
    aspect-ratio: 1280 / 800;
  }
  [data-hm="off"] {
    visibility: hidden;
  }
}
@media (max-width: 1023.98px) {
  /* Family 5: the Cal.com booking iframe on /demo. Cal starts it 300 px tall, centred in the
     600 px box the page already reserves, then grows it to the booking form and moves it to
     the top. Starting at the box's height removes that jump; the form is the same. */
  #cal-embed iframe {
    min-height: 600px;
  }
}
onx-sec-hero:not(:defined) {
  aspect-ratio: 656 / 720;
}
onx-ov-hero:not(:defined) {
  aspect-ratio: 1088 / 520;
}
onx-ov-hero-m:not(:defined) {
  aspect-ratio: 354 / 1584;
}
onx-govern:not(:defined) {
  aspect-ratio: 345 / 333;
}
onx-command:not(:defined) {
  aspect-ratio: 1440 / 900;
}

/* ───────── below the desktop breakpoint: the page is one column ───────── */
@media (max-width: 1023.98px) {
  /* Side headings and contents lists that stick on desktop slide over the content once
     the columns stack. */
  [data-m~="unstick"] {
    position: static !important;
    top: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }

  /* A span with a fixed 64 px size inside a heading that scales with the screen. */
  [data-m~="fs-inherit"] {
    font-size: inherit !important;
  }

  /* Legal pages: the contents list sits above the text instead of beside it. */
  [data-m~="legal-cols"] {
    flex-direction: column !important;
    align-items: stretch !important;
  }
  [data-m~="legal-cols"] > nav {
    flex: none !important;
    width: 100% !important;
  }

  /* Homepage audience cards: the product table's box is exactly as tall as the table
     (520 x 240 stage scaled to the box width), so the card ends where the table is cut. */
  [data-m~="aud-mock"] {
    height: auto !important;
    aspect-ratio: 520 / 240;
  }
}

/* ───────── single-column accordion + visual (the grid is one column below ~880 px) ───────── */
@media (max-width: 879.98px) {
  /* The visual follows the open row instead of the whole list, like an accordion on
     Ramp's phone pages: open point, its text, its visual, then the closed points. Only the
     order changes; rows and visual are the page's own. Three shapes carry the hook:
       team pages             grid > ul + visual
       size / organisation    grid > ol + visual
       product rows           grid > div(display:contents: title, lead, list) + visual */
  [data-m~="acc-grid"] {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0 !important;
  }
  [data-m~="acc-grid"] > :is(ul, ol),
  [data-m~="acc-grid"] > div > :is(ul, ol) {
    display: contents !important;
  }
  /* The list's own bottom rule goes with the list box; the last row carries it. The Agents
     lists (564 px column) draw a line under every row themselves and need the top one. */
  [data-m~="acc-grid"] > :is(ul, ol) > li:last-child,
  [data-m~="acc-grid"] > div > :is(ul, ol):not([style*="max-width:564px"]) > li:last-child {
    border-bottom: 1px solid var(--color-border-default);
  }
  [data-m~="acc-grid"] > div > ol[style*="max-width:564px"] > li:first-child {
    border-top: 1px solid var(--color-border-subtle);
  }
  [data-m~="acc-grid"] > :is(ul, ol) > li:has(button[aria-expanded="true"]) ~ li,
  [data-m~="acc-grid"] > div > :is(ul, ol) > li:has(button[aria-expanded="true"]) ~ li {
    order: 2;
  }
  [data-m~="acc-grid"] > :not(ul, ol):not(:has(> ul, > ol)) {
    order: 1 !important;
    margin: 0 0 24px;
  }
  /* Product rows: the title and lead sit above the list with the phone's own spacing (the
     desktop margins assume the row's 40 px grid gap, which is gone here). */
  [data-m~="acc-grid"] > div > :is(h2, h3) {
    margin-bottom: 40px !important;
  }
  [data-m~="acc-grid"] > div > :is(h2, h3):has(+ p) {
    margin-bottom: 16px !important;
  }
  [data-m~="acc-grid"] > div > p {
    margin-bottom: 40px !important;
  }
}

/* ───────── phones ───────── */
@media (max-width: 639.98px) {
  /* Homepage live strip: in the flow under the hero instead of stuck to the screen bottom. */
  [data-m~="live-static"] {
    position: relative !important;
  }

  /* Product-screen heroes, the way Harvey does it on a phone: the desktop composition
     shrunk as one picture. The whole screen stays in view, never cropped, with the same
     even margin of field around it as on desktop (80 of 1200 px = 6.67%, glass 10 px).
     The page's own sizing (heroMock / container query) scales the screen to fit. */
  [data-m~="hero-frame"] {
    padding: 6.67% !important;
  }
  [data-m~="hero-frame"] > :last-child {
    padding: 0.9% !important;
  }

  /* Card grids that are two cramped columns below 1024 px: one column, no desktop
     min-height, text right under the icon. */
  [data-m~="stack"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  [data-m~="stack"] > li {
    grid-column: auto !important; /* a desktop "span 2" last card would add a hidden 0 px column */
    min-height: 0 !important;
    justify-content: flex-start !important;
    gap: 16px !important;
  }

  /* Link cards: the description sits under the title, not pushed to a desktop height. */
  [data-m~="card-compact"] {
    min-height: 0 !important;
    justify-content: flex-start !important;
    gap: 16px !important;
  }

  /* ── type ── */
  [data-m~="hero-h1"] {
    font-size: 36px !important;
  }
  [data-m~="lead"] {
    font-size: 17px !important;
    line-height: 26px !important;
  }
  [data-m~="quote"] {
    font-size: 22px !important;
    line-height: 1.3 !important;
  }
  [data-m~="quote-sm"] {
    font-size: 19px !important;
    line-height: 1.35 !important;
  }
  [data-m~="sec-hero"] {
    min-height: 0 !important;
    padding: 20px 16px !important;
  }
  /* "Enterprise-Grade Security / is the foundation": one sentence that wraps naturally. */
  [data-m~="flow"] > span {
    display: inline !important;
  }
  [data-m~="flow"] > br {
    display: none !important;
  }
  [data-m~="flow"] > span + br + span::before {
    content: " ";
  }

  /* ── spacing: sections sit ~90 px apart instead of 110-165 ── */
  [data-m~="sec-pb"] {
    padding-bottom: 48px !important;
  }
  [data-m~="sec-pblk"] {
    padding-top: 48px !important;
    padding-bottom: 48px !important;
  }
  [data-m~="cta-pad"] {
    padding-top: 72px !important;
    padding-bottom: 72px !important;
  }
  [data-m~="quote-panel"] {
    padding: 12px !important;
  }
  [data-m~="quote-panel"] > figure {
    padding: 20px !important;
  }

  /* ── buttons ── */
  /* The hero's and the final CTA's primary button runs the full width, like Ramp's. */
  [data-m~="cta-full"] {
    display: flex !important;
    flex: 1 1 auto !important;
    align-self: stretch !important;
    width: 100% !important;
    box-sizing: border-box !important;
    justify-content: center !important;
  }
  [data-m~="cta-pad"] > [data-m~="cta-full"] {
    flex-basis: 100% !important;
  }
  /* The button's row is shrink-wrapped by a column aligned to the start: stretch it too. */
  :has(> [data-m~="cta-full"]) {
    align-self: stretch !important;
  }
  /* Outline buttons from 32 px to a 40 px tap height. */
  [data-m~="tap40"] {
    height: 40px !important;
  }
  /* Email field and button in one box: the button goes under the field, full width. */
  [data-m~="inline-form"] > button {
    flex: 1 1 100% !important;
  }

  /* ── carousels and tables ── */
  /* Video carousels run to the screen edge, so the next card peeks in from the edge
     instead of being cut at the 20 px gutter. Cards still snap to the gutter. */
  .vr-row {
    margin-inline: -20px !important;
    padding-inline: 20px !important;
    scroll-padding-inline: 20px !important;
  }
  .vr-card > span:last-child > span:last-child {
    font-size: 14px !important;
    line-height: 20px !important;
  }
  /* Rules tables: rule and "what Ontelis does" fit the screen, the third column peeks in. */
  [data-m~="rules-table"] {
    grid-template-columns: 116px 214px 190px !important;
  }
  [data-m~="rules-table"] [role="columnheader"],
  [data-m~="rules-table"] [role="rowheader"],
  [data-m~="rules-table"] [role="cell"] {
    padding-left: 14px !important;
    padding-right: 14px !important;
  }
  /* Story tables: every column on screen, the results column included. */
  [data-m~="fit-table"] {
    min-width: 0 !important;
  }
  [data-m~="fit-table"] th,
  [data-m~="fit-table"] td {
    padding-left: 10px !important;
    padding-right: 10px !important;
  }
  /* IntuitionDB's table: narrower first columns so the third one starts on screen. */
  [data-m~="idb-row"] {
    grid-template-columns: 112px 176px 132px 148px !important;
  }
  [data-m~="scroll-fade"] {
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
    mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
  }

  /* ── cards and panels ── */
  /* Homepage product cards take their content's height on a phone. */
  [data-m~="bento-row"] {
    grid-auto-rows: auto !important;
  }
  [data-m~="drawer"] {
    flex: none !important;
    height: 300px !important;
  }
  /* Drawn product panels: the 562x598 stage keeps its size and scale; the box trims 48
     design px above and below, where the centred drawing leaves only empty background. */
  [data-m~="pp-crop"] {
    height: 504px !important;
  }
  [data-m~="pp-crop"] > [data-m~="pp-stage"] {
    inset: auto !important;
    top: -48px !important;
    left: 0 !important;
    right: 0 !important;
    height: 600px !important;
  }

  /* ── footer ── */
  /* Short link groups pair up side by side; Solutions keeps its full-width row. */
  [data-m~="ft-grid"] {
    grid-auto-flow: row dense !important;
  }
}
