/*
 * OmniStrat mobile enhancement layer.
 *
 * Included from every product page (foundry / agora / cohorts /
 * matchmaking / compliance / taskforces / passport). Handles what
 * per-page media queries miss: nav, touch targets, form density,
 * grid reflow, safe-area insets, prevents horizontal scroll.
 *
 * Load ORDER matters — link this AFTER the page's inline <style>
 * so these rules win when they need to.
 */

/* ─── Global protections ──────────────────────────────────────── */
html, body {
  overflow-x: hidden;                             /* no horizontal jitter */
  -webkit-text-size-adjust: 100%;                 /* prevent iOS auto-zoom */
  text-size-adjust: 100%;
}
* { -webkit-tap-highlight-color: rgba(0,0,0,0);  /* no blue flash on tap */ }
a, button { touch-action: manipulation; }         /* faster tap response */

/* Respect iOS notch + Android nav bar */
@supports (padding: env(safe-area-inset-top)) {
  body {
    padding-left:  env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  nav { padding-top: env(safe-area-inset-top) !important; }
  footer { padding-bottom: max(env(safe-area-inset-bottom), 32px) !important; }
}

/* ─── Tablet breakpoint (≤900px) ──────────────────────────────── */
@media (max-width: 900px) {
  /* Any 2/3/4 col grid collapses to single column */
  .stats-grid, .stat-cell,
  .cards, .actions, .sides, .verticals, .entry-grid,
  .form-row, .form-row.wide, .price, .scope-grid,
  .why-grid, .promise-grid, .pillars, .tiers,
  .flow, .how, .prov-grid {
    grid-template-columns: 1fr !important;
  }
  /* Reduce hero font weight for readability */
  .hero h1, .head h1 { font-size: clamp(28px, 8vw, 44px) !important; letter-spacing: -0.02em !important; }
  .hero .lede, .head .lede { font-size: 15px !important; }
}

/* ─── Tablet (641–900px): keep pricing 2-up + moats readable ───── */
@media (min-width: 641px) and (max-width: 900px) {
  .tiers { grid-template-columns: repeat(2, 1fr) !important; }
  .tier.wide { grid-column: span 2 !important; }
  .moats-strip { grid-template-columns: repeat(3, 1fr) !important; gap: 16px 12px !important; }
}

/* ─── Phone breakpoint (≤640px) — the main work ────────────────── */
@media (max-width: 640px) {

  /* Container padding tightens on phone so content isn't squeezed */
  .container { padding: 0 16px !important; }

  /* ── NAV — collapse horizontal to compact, still-usable strip ── */
  nav .row {
    padding: 12px 16px !important;
    flex-wrap: nowrap !important;
    gap: 10px !important;
  }
  nav .logo { font-size: 14px !important; }
  nav .logo .mark { width: 18px !important; height: 18px !important; }
  /* The wordmark never wraps (r38 polish): on the Talent, Passport and Admin
     pages "OmniStrat AI" broke onto two lines at 390px because the links
     beside it took the row. The logo keeps its width; the links scroll. */
  nav .logo { white-space: nowrap; flex-shrink: 0; }
  nav .right {
    min-width: 0;
    gap: 10px !important;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  nav .right::-webkit-scrollbar { display: none; }
  nav .right a { font-size: 13px !important; white-space: nowrap; }
  /* Hide low-priority nav items on tiny screens if the container is very narrow */
  @media (max-width: 380px) {
    nav .right a:not(.btn-nav):first-of-type { display: none; }
  }

  /* ── HERO / HEAD — tighter typography, tighter margins ─────────── */
  .hero, .head { padding-top: 40px !important; margin-bottom: 32px !important; }
  .hero h1, .head h1 {
    font-size: clamp(28px, 9vw, 40px) !important;
    line-height: 1.08 !important;
    margin-bottom: 14px !important;
  }
  .hero .lede, .head .lede { font-size: 14.5px !important; line-height: 1.5 !important; }
  .hero .cta { flex-direction: column; align-items: stretch; gap: 8px !important; }
  .hero .cta a, .hero .cta button { width: 100%; text-align: center; }

  /* ── SECTION HEADS ─────────────────────────────────────────────── */
  .sect { margin-top: 40px !important; }
  .sect-head { padding-bottom: 10px !important; margin-bottom: 16px !important; }
  .sect-head h2 { font-size: 19px !important; }
  .sect-head .sub { font-size: 10.5px !important; }

  /* ── CARDS / STATS — mobile density ────────────────────────────── */
  .card, .stat-cell, .action, .entry, .vertical, .scope, .price-tile, .moat,
  .chain-preview, .chain-preview .row {
    padding: 18px 18px !important;
  }
  .stat-cell .value { font-size: 24px !important; }
  .stat-cell .label { font-size: 10.5px !important; margin-bottom: 10px !important; }
  .stat-cell .meta { font-size: 11px !important; }

  /* -- BUTTONS -- hit targets are css/omni-actions.css's job now (44px under
     720px, for every tier). The !important block that lived here re-sized
     every .btn on every page and fought the shared geometry. */
  .btn-signout, .btn-amber { min-height: 44px !important; }

  /* ── FORM CONTROLS — mobile-native sizing ──────────────────────── */
  /* Not checkboxes or radios: 12px/14px padding and a 44px min-height turned
     each box into an invisible 44px slab beside its label (the homepage tier
     chips grew to 60px tall, 2026-10-17). Their LABEL is the touch target. */
  input:not([type="checkbox"]):not([type="radio"]), select, textarea {
    font-size: 16px !important;                    /* prevents iOS auto-zoom on focus */
    padding: 12px 14px !important;
    min-height: 44px !important;
  }
  textarea { min-height: 100px !important; }
  label { display: block; margin-bottom: 12px; }

  /* ── PASSPORT CARD — scale gracefully ──────────────────────────── */
  .passport-card {
    max-width: 100% !important;
    aspect-ratio: auto !important;
    min-height: 220px !important;
  }
  .passport-card .card-layer { padding: 20px 20px !important; }
  .passport-card .card-body { grid-template-columns: 60px 1fr !important; gap: 12px !important; }
  .passport-card .identicon { width: 60px !important; height: 60px !important; }
  .passport-card .identity .name { font-size: 18px !important; }
  .passport-card .identity .email { font-size: 10.5px !important; }
  .passport-card .card-tier { font-size: 9px !important; padding: 3px 8px !important; }
  .passport-card .card-brand { font-size: 11.5px !important; }
  .passport-card .ent-chip { font-size: 9px !important; padding: 2px 6px !important; }
  .passport-card .field-mini { font-size: 8px !important; }
  .passport-card .field-mini .v { font-size: 10.5px !important; }
  .passport-card .watermark { font-size: 140px !important; }

  /* ── FEATURE LIST rows (Your Access) ───────────────────────────── */
  .feat-item {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
    padding: 16px 18px !important;
  }
  .feat-item .body { min-width: 0; }
  .feat-item .nm { font-size: 14.5px !important; }
  .feat-item .det { font-size: 12.5px !important; line-height: 1.5 !important; }
  /* A 44px target, left-aligned under the text: full width it was a 320x22
     strip of centred text (persona audit F29). The whole row is clickable. */
  .feat-item .show-passport { min-height: 44px; display: inline-flex; align-items: center; justify-self: start; }

  /* ── LISTS (attestations, cohorts, matches, apps) ──────────────── */
  .att-row, .cohort, .match-row, .tf-row {
    grid-template-columns: 1fr !important;
    gap: 8px !important;
    padding: 14px 16px !important;
  }
  /* Stacked into one column, a status chip and a date box stretched to the
     full row width (a 340px green bar saying "active"); they size to content. */
  .att-row > *, .cohort > *, .match-row > *, .tf-row > * { justify-self: start; max-width: 100%; }

  /* ── PRICING TIER CARDS ────────────────────────────────────────── */
  .tier { padding: 20px 22px !important; }
  .tier .price { font-size: 24px !important; }
  .cathedral, .cta-strip {
    padding: 24px 22px !important;
    grid-template-columns: 1fr !important;
    text-align: left !important;
  }
  .cath-features { grid-template-columns: 1fr !important; }

  /* ── FOOTER stacked vertically ─────────────────────────────────── */
  footer .row {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 10px !important;
    padding: 0 16px !important;
  }
  footer { padding: 24px 0 !important; }

  /* ── CODE BLOCKS scroll horizontally on mobile ────────────────── */
  .code, .codeblock, pre {
    font-size: 12px !important;
    padding: 14px 16px !important;
    -webkit-overflow-scrolling: touch;
  }

  /* ── INLINE DRAWERS (charter/join forms) tighten ──────────────── */
  #startForm, #joinForm, #candidateForm, #roleForm,
  #chainArtifactForm, #urlArtifactForm, #charterForm,
  #approvalForm, #memoryForm {
    padding: 18px 18px !important;
  }

  /* ── TAG CHIPS / STATUS PILLS remain legible ──────────────────── */
  .chip, .status, .tier-chip, .locked-badge {
    font-size: 11px !important;
    padding: 2px 7px !important;
  }

  /* ── DIALOG / MODAL scroll containers respect viewport ────────── */
  main { padding-bottom: 64px !important; }

  /* ── MOATS STRIP — 5 across is unreadable on a phone, go 2-up ──── */
  .moats-strip {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 18px 12px !important;
    padding: 18px 16px !important;
    text-align: left !important;
  }
  /* Wide tier cards must not try to span 2 in a single-column grid */
  .tier.wide { grid-column: auto !important; }
  /* Free band stacks: price aligns left under the copy when wrapped */
  .price-intro { padding: 20px 18px !important; gap: 12px !important; }
  .price-intro .px { margin-left: 0 !important; }
}

/* ─── Small phone (≤380px) — final tightening ─────────────────── */
@media (max-width: 380px) {
  .container { padding: 0 12px !important; }
  .hero h1, .head h1 { font-size: 26px !important; }
  .sect-head h2 { font-size: 17px !important; }
  .card, .stat-cell, .action, .entry, .vertical, .scope, .price-tile {
    padding: 14px 14px !important;
  }
  .stat-cell .value { font-size: 22px !important; }
  nav .logo { font-size: 13px !important; }
  nav .logo span:not(.mark) { display: none; }        /* logo mark only, no wordmark */
  nav .right a:not(.btn-nav) { display: none; }        /* only Passport btn remains */
}

/* ─── Landscape orientation on phone — reclaim vertical space ── */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .hero, .head { padding-top: 20px !important; margin-bottom: 20px !important; }
  .sect { margin-top: 28px !important; }
  main { padding-top: 20px !important; padding-bottom: 40px !important; }
}

/* ─── High-DPI displays: tighten borders + shadows ─────────────── */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .card, .stat-cell, .action, .entry, .vertical, .scope, .price-tile { border-width: 0.5px; }
}

/* ─── Prefers-reduced-motion respected everywhere ──────────────── */
/* An INFINITE animation at 0.001s is not stopped, it is sped up: passport's
 * rotating holo jumped to a random angle every frame (persona audit F21). One
 * iteration at 0.001s ends every animation on its final frame instead, and
 * animationend still fires for code that waits on it. */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001s !important; animation-iteration-count: 1 !important; transition-duration: 0.001s !important; }
}

/* ─── Desktop default zoom (80%) ──────────────────────────────── */
/*
 * Bakes an 80% desktop zoom into every page so first-visit visuals
 * match the density that reads best on modern high-res displays.
 * Uses the `zoom` property (native browser scaling) so all layout
 * math, media queries, click targets, and scrollbars stay aligned
 * without any transform tricks. Scoped to real desktops only —
 * tablets and phones keep their tuned responsive breakpoints.
 *
 * Supported natively in Chrome, Edge, Safari (all versions) and
 * Firefox 126+. Older browsers just render at 100%, which is fine.
 */
/* Mouse-and-trackpad desktops only (2026-10-28). Scoped by width alone, an
 * iPad or Android tablet in landscape (1024-1366px), a spanned Surface Duo
 * and a Fold in landscape were all shrunk to 75%: 44px touch targets became
 * 33px and 10px labels 7.5px, on exactly the devices driven by a finger.
 * A touch screen has no hover and a coarse pointer, so it keeps 100%.
 * Every consumer reads var(--page-zoom, 1), so it falls back cleanly. */
@media (min-width: 901px) and (hover: hover) and (pointer: fine) {
  html {
    zoom: 0.75;
    /* The same number, readable by a page: 100vw and 100dvh are NOT zoomed
       (they stay the viewport's CSS size, then render at 75%), so a layout
       that must fill the screen divides by this (foundry.html's workbench). */
    --page-zoom: 0.75;
  }
}

/* ─── Wide tables ──────────────────────────────────────────────────
 * A multi-column table (the billing statement is 6 wide) has no way to
 * fit a 390px phone. Without a scroll container it either overflows the
 * viewport -- which `overflow-x: hidden` on <body> then CLIPS, silently
 * hiding the Cost column -- or forces the whole page wide.
 *
 * Make the table itself the scroll region, and keep the header legible.
 * Applies to any table on any page, so a table added later is covered
 * by default rather than by remembering. */
@media (max-width: 900px) {
  table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
  table thead th {
    position: sticky;
    top: 0;
    background: var(--surface, #fff);
  }
  /* Give the scroll affordance a hint on touch devices. */
  table::-webkit-scrollbar { height: 4px; }
  table::-webkit-scrollbar-thumb {
    background: var(--border-mid, #d6d3d1);
    border-radius: 2px;
  }
}

/* ─── Code blocks and pre ─────────────────────────────────────────
 * Quickstart curl samples are long single lines. Let them scroll
 * horizontally instead of stretching the page. */
@media (max-width: 900px) {
  pre, .codeblock, .code {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-size: 12px !important;
    line-height: 1.5;
  }
  /* A page's `code { font-size: .85em }` compounded with the 11px above to
     9.4px inside a snippet; the block sets the size, its code inherits it. */
  pre code { font-size: inherit !important; }
  code { word-break: break-word; }
}

/* --- Scrollbars: thin and quiet, in both themes ---------------------------
 * The platform default on Windows is a 17px grey gutter with arrow buttons,
 * which sat on every chat box, pane and text box like scaffolding (owner,
 * 2026-10-18). A scrollbar is a cue, not a feature: a thin rounded thumb in
 * a neutral grey that reads on light and dark alike, no track, no buttons,
 * a little darker under the pointer so it is still easy to grab.
 *
 * Two rule sets, deliberately exclusive. Chrome 121+ IGNORES every
 * ::-webkit-scrollbar rule on an element whose scrollbar-width or
 * scrollbar-color is set (and scrollbar-color inherits), so setting the
 * standard properties everywhere would throw away the styling below and
 * bring the arrow buttons back. Browsers with ::-webkit-scrollbar (Chrome,
 * Edge, Safari) get it; the rest (Firefox) get the standard properties.
 * Elements that hide their scrollbar (scrollbar-width: none) are unaffected. */
@supports selector(::-webkit-scrollbar) {
  ::-webkit-scrollbar { width: 10px; height: 10px; }
  ::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: transparent; }
  ::-webkit-scrollbar-button { display: none; width: 0; height: 0; }
  ::-webkit-scrollbar-thumb {
    background-color: rgba(128, 128, 128, 0.32);
    border: 3px solid transparent; background-clip: padding-box; border-radius: 999px;
  }
  ::-webkit-scrollbar-thumb:hover { background-color: rgba(128, 128, 128, 0.55); }
  ::-webkit-scrollbar-thumb:active { background-color: rgba(128, 128, 128, 0.7); }
}
@supports not selector(::-webkit-scrollbar) {
  html { scrollbar-width: thin; scrollbar-color: rgba(128, 128, 128, 0.4) transparent; }
}

/* --- Never wider than the screen (2026-10-28) ------------------------------
 * Most pages are a sticky-footer grid: body { display: grid;
 * grid-template-rows: auto 1fr auto } with no column template, so the one
 * implicit column is sized "auto" and grows to the widest unbreakable thing
 * in the page (legal's sub-processor table, talent's seats table, a nowrap
 * label). The whole page then laid out at 450-900px on a 320-820px screen
 * and `overflow-x: hidden` above CLIPPED the right side of every block --
 * no sideways scroll, so nothing looked wrong except missing text. A
 * minmax(0, 1fr) column is capped at the viewport and lets the table's own
 * scroll region (below) do its job. Harmless on a body that is not a grid. */
body { grid-template-columns: minmax(0, 1fr); }
body > * { min-width: 0; }

/* --- Inline 3- and 4-up grids (taskforces' stats, matchmaking's steps) -----
 * Set in a style attribute, so only an attribute match reaches them. Four
 * equal tracks with a nowrap value in each cannot fit 320-430px: two up. */
@media (max-width: 640px) {
  [style*="grid-template-columns: repeat(4, 1fr)"], [style*="grid-template-columns: repeat(3, 1fr)"] { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
}

/* --- Module grid on the home page (inline repeat(3, 1fr)) ----------------- */
@media (max-width: 900px) { .mod-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; } }
@media (max-width: 560px) { .mod-grid { grid-template-columns: minmax(0, 1fr) !important; } }

/* --- Touch targets on a coarse pointer (2026-10-28) ------------------------
 * Nav, crumb and footer links were 15-22px tall on phones and tablets, under
 * WCAG 2.5.8's 24px minimum. On a touch screen (any width: tablets too) the
 * box grows; the text does not move, and a mouse desktop is unchanged. */
@media (pointer: coarse) {
  nav a, nav .logo { display: inline-flex; align-items: center; min-height: 44px; }
  /* :where() = zero specificity: a page that already sizes these (the Talent
     pages' 44px footer, TST-03) keeps its own rule. This is only a floor. */
  :where(footer a, .crumb a, .trip .links a, .os-legal-strip a) {
    display: inline-flex; align-items: center; justify-content: center; min-height: 32px; min-width: 32px;
  }
  /* A disclosure's summary line and a checkbox's label are the targets. */
  :where(summary) { padding-block: 12px; }
  label:has(> input[type="checkbox"]), label:has(> input[type="radio"]) { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; }
  /* Segmented time-window toggles (foundry, login): bare text buttons 19px tall. */
  .win-opt { min-height: 32px; }
  /* Text buttons set in a sentence (statement's Details, foundry's copy the
     MCP URL) and the passport card's product chips. */
  .lrn-link, .card-more-copy { padding-block: 7px; }
  .passport-card .ent-chip { padding-top: 4px !important; padding-bottom: 4px !important; }
  footer p a, footer li a { display: inline; min-height: 0; }
  /* Under 380px the logo is the mark alone (18px wide): keep a 44px square. */
  nav .logo { min-width: 44px; }
  /* A standalone text link ("Verify a live record", "Talk to the team") is an
     inline box 17-22px tall. Vertical padding on an INLINE box grows its hit
     area without moving a single line of text. :where() keeps this at zero
     specificity, so every link that sets its own padding (buttons, tabs,
     cards) is untouched. */
  :where(a[href]) { padding-block: 7px; }
  /* Text fields on a touch tablet were 21px tall (the 44px rule was phone-only). */
  input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select { min-height: 44px; }
}

/* --- Phone tap areas (r38 polish) ------------------------------------------
 * At 480px and under, nav, footer, crumb and tab links reach 44px tall by
 * padding and min-height, never by bigger type (they were 32-36px). Links
 * set in running text (footer p a, footer li a) stay inline. :where() keeps
 * this a floor: a page that sizes its own control keeps its rule. */
@media (max-width: 480px) {
  :where(nav a, footer a, .crumb a, .trip .links a, .os-legal-strip a) { display: inline-flex; align-items: center; min-height: 44px; }
  :where(.tab, [role="tab"]) { min-height: 44px; }
  /* The footer disclaimer (.fin) is running text too: its "disclaimer" link
     as a 44px block opened a gap in the middle of the paragraph. */
  footer p a, footer li a, .fin a { display: inline; min-height: 0; }
}

/* A text field in a flex row keeps its intrinsic width (size=20) unless told
   it may shrink: webhooks' URL field pushed its row past a 320px screen. */
input, select, textarea { max-width: 100%; }
/* Text fields only: a <select> sized to 0 collapsed to its arrow (14px, the
   foundry Rowdy model picker). */
:where(input:not([type="checkbox"]):not([type="radio"]), textarea) { min-width: 0; }

/* --- Legible floor for small text (2026-10-28) -----------------------------
 * Chips, status pills, section subtitles, the footer's copyright and the
 * financial disclaimer were 8-10.5px. 11px is the floor; the disclaimer is
 * a legal notice and reads at 12px. */
/* Only classes that are 10px wherever they are defined (studio's .chip is
   14px and .status is 13px on most pages, so neither is floored globally). */
.tag, .tier-chip, .locked-badge, .tier-closed-badge, .ent-chip { font-size: 11px !important; }

.os-legal-strip .co, footer .co, .fin, .fin strong, .fin a { font-size: 12px !important; }
@media (max-width: 640px) {
  .sect-head .sub { font-size: 11.5px !important; }
  .stat-cell .label { font-size: 11px !important; }
  .passport-card .card-tier, .passport-card .ent-chip, .passport-card .field-mini { font-size: 11px !important; }
  .passport-card .card-brand, .passport-card .identity .email, .passport-card .field-mini .v { font-size: 11.5px !important; }
}
