/*
 * apps/site design tokens and layout.
 *
 * Light is the base palette on bare `:root`. Dark is redefined twice — once
 * under `prefers-color-scheme` guarded against an explicit light choice, and
 * once under `[data-theme='dark']` — so the toggle wins in both directions and
 * no colour has its only definition inside a media query.
 *
 * Every text/background pair below was chosen to clear WCAG AA (4.5:1 for body
 * text, 3:1 for large text and UI borders) in BOTH themes, and the axe sweep in
 * apps/site/a11y.mjs runs both themes on every route so the claim is measured
 * rather than asserted.
 *
 * No web font is loaded. A security company's public site making zero
 * third-party requests is a property worth more than a typeface.
 */

:root {
  color-scheme: light;

  --bg: #ffffff;
  --bg-sunken: #f5f7f9;
  --bg-raised: #ffffff;
  --bg-inset: #eef1f5;

  --border: #d5dae1;
  --border-strong: #aeb7c2;

  --text: #14181d;
  --text-muted: #4d555f;
  --text-faint: #626b76;

  --accent: #0f5bd7;
  --accent-hover: #0b47a9;
  --accent-on: #ffffff;
  --accent-soft: #eaf1fe;
  --accent-border: #b9d0f7;

  --caution-soft: #fdf4e3;
  --caution-border: #e5cd97;
  --caution-text: #6b4a06;

  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 8px 24px -12px rgb(16 24 40 / 14%);

  --font:
    ui-sans-serif, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial,
    'Helvetica Neue', sans-serif;
  --mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;

  --measure: 68ch;
  --page: 1120px;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;

    --bg: #0b0e12;
    --bg-sunken: #10141a;
    --bg-raised: #151a22;
    --bg-inset: #1a212b;

    --border: #262e3a;
    --border-strong: #3d4756;

    --text: #e9edf3;
    --text-muted: #aab4c1;
    --text-faint: #98a3b1;

    --accent: #85b4ff;
    --accent-hover: #a8caff;
    --accent-on: #0b0e12;
    --accent-soft: #14213a;
    --accent-border: #2c3f63;

    --caution-soft: #251d0d;
    --caution-border: #57451c;
    --caution-text: #f0d9a4;

    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px -12px rgb(0 0 0 / 60%);
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;

  --bg: #0b0e12;
  --bg-sunken: #10141a;
  --bg-raised: #151a22;
  --bg-inset: #1a212b;

  --border: #262e3a;
  --border-strong: #3d4756;

  --text: #e9edf3;
  --text-muted: #aab4c1;
  --text-faint: #98a3b1;

  --accent: #85b4ff;
  --accent-hover: #a8caff;
  --accent-on: #0b0e12;
  --accent-soft: #14213a;
  --accent-border: #2c3f63;

  --caution-soft: #251d0d;
  --caution-border: #57451c;
  --caution-text: #f0d9a4;

  --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px -12px rgb(0 0 0 / 60%);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

img,
svg {
  max-width: 100%;
}

a {
  color: var(--accent);
  text-underline-offset: 0.18em;
  text-decoration-thickness: from-font;
}

a:hover {
  color: var(--accent-hover);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

h1,
h2,
h3 {
  line-height: 1.22;
  letter-spacing: -0.015em;
  margin: 0 0 0.5em;
  text-wrap: balance;
}

h1 {
  font-size: clamp(2rem, 1.35rem + 2.6vw, 3.15rem);
  font-weight: 640;
  letter-spacing: -0.028em;
}

h2 {
  font-size: clamp(1.35rem, 1.15rem + 0.85vw, 1.75rem);
  font-weight: 620;
}

h3 {
  font-size: 1.075rem;
  font-weight: 640;
  margin-bottom: 0.35em;
}

p {
  margin: 0 0 1em;
  max-width: var(--measure);
}

code,
kbd {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.08em 0.36em;
}

/* ── skip link ─────────────────────────────────────────────────────────── */

.skip {
  position: absolute;
  left: 12px;
  top: -100px;
  z-index: 100;
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-weight: 600;
  text-decoration: none;
  transition: top 120ms ease;
}

.skip:focus {
  top: 12px;
}

main:focus {
  outline: none;
}

/* ── header ────────────────────────────────────────────────────────────── */

.header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--border);
}

.header__inner {
  max-width: var(--page);
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  text-decoration: none;
  font-weight: 640;
  letter-spacing: -0.015em;
  font-size: 0.98rem;
  padding: 6px 2px;
}

.brand__mark {
  display: inline-flex;
  color: var(--accent);
}

.nav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.nav__links {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-wrap: wrap;
}

.nav__link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.925rem;
  font-weight: 520;
  padding: 7px 10px;
  border-radius: 7px;
}

.nav__link:hover {
  color: var(--text);
  background: var(--bg-sunken);
}

.nav__link[aria-current='page'] {
  color: var(--text);
  background: var(--bg-inset);
}

.nav__signin {
  margin-left: 6px;
}

.themetoggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin-left: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-raised);
  color: var(--text-muted);
  cursor: pointer;
}

.themetoggle:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.themetoggle[hidden] {
  display: none;
}

.themetoggle__moon {
  display: none;
}

/*
 * On a narrow screen the seven header controls wrap to three rows, and a sticky
 * three-row header eats a third of a 375px viewport on every scroll. There is
 * no hamburger here on purpose — a menu that needs JavaScript to open is a menu
 * that does not open on a page whose whole point is being readable without it —
 * so the header stops being sticky instead, and the nav takes its own row.
 */
@media (max-width: 720px) {
  .header {
    position: static;
    backdrop-filter: none;
    background: var(--bg);
  }

  .header__inner {
    padding: 10px 20px 8px;
    gap: 8px;
  }

  .nav {
    margin-left: 0;
    width: 100%;
    gap: 4px;
  }

  .nav__link {
    padding: 6px 8px;
    font-size: 0.9rem;
  }

  .nav__signin {
    margin-left: auto;
  }

  .doc h2,
  .doc h3 {
    scroll-margin-top: 12px;
  }
}

:root[data-theme='dark'] .themetoggle__sun {
  display: none;
}

:root[data-theme='dark'] .themetoggle__moon {
  display: inline;
}

/* ── buttons ───────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 580;
  text-decoration: none;
  border: 1px solid transparent;
  cursor: pointer;
}

.btn--primary {
  background: var(--accent);
  color: var(--accent-on);
  border-color: var(--accent);
}

.btn--primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: var(--accent-on);
}

.btn--ghost {
  background: var(--bg-raised);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn--ghost:hover {
  color: var(--text);
  background: var(--bg-sunken);
}

/* ── page structure ────────────────────────────────────────────────────── */

.wrap {
  max-width: var(--page);
  margin: 0 auto;
  padding: 0 20px;
}

.section {
  padding: 44px 0;
  border-top: 1px solid var(--border);
}

.section:first-of-type {
  border-top: none;
}

.section__head > :last-child {
  margin-bottom: 0;
}

.section__body > :first-child {
  margin-top: 0;
}

.section__body > :last-child {
  margin-bottom: 0;
}

.lead {
  color: var(--text-muted);
  font-size: 1.06rem;
}

.eyebrow {
  display: inline-block;
  font-size: 0.775rem;
  font-weight: 640;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 0 0 14px;
}

/* ── hero ──────────────────────────────────────────────────────────────── */

.hero {
  padding: 68px 0 52px;
  background: linear-gradient(180deg, var(--bg-sunken), var(--bg));
  border-bottom: 1px solid var(--border);
}

.hero__title {
  max-width: 20ch;
}

.hero__sub {
  font-size: 1.16rem;
  color: var(--text-muted);
  max-width: 62ch;
}

.hero__actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 26px;
}

/*
 * The summary panel beside the hero. Below the two-column breakpoint it is
 * REMOVED rather than stacked: every row of it restates something the page says
 * again at full length further down, so at narrow widths it would be a second
 * copy in a reading order that is already good. `display: none` also takes it
 * out of the accessibility tree, so no screen reader meets the duplicate.
 */
.glance {
  display: none;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow);
}

.glance h2 {
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 640;
  margin: 0 0 1.1em;
}

.glance dl {
  margin: 0;
}

.glance dt {
  font-weight: 620;
  font-size: 0.92rem;
}

.glance dd {
  margin: 0.1em 0 15px;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.glance dd:last-child {
  margin-bottom: 0;
}

/* ── page header for interior pages ────────────────────────────────────── */

.pagehead {
  padding: 52px 0 34px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-sunken);
}

.pagehead h1 {
  font-size: clamp(1.75rem, 1.3rem + 1.9vw, 2.5rem);
}

.pagehead .lead {
  max-width: 66ch;
  margin-bottom: 0;
}

.pagemeta {
  margin: 14px 0 0;
  font-size: 0.9rem;
  color: var(--text-faint);
}

/* ── cards ─────────────────────────────────────────────────────────────── */

.grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(255px, 1fr));
  margin: 0;
  padding: 0;
  list-style: none;
}

.card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card h3 {
  margin-top: 0;
}

.card p {
  margin-bottom: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* ── lists ─────────────────────────────────────────────────────────────── */

.list {
  padding-left: 1.15em;
  max-width: var(--measure);
}

.list li {
  margin-bottom: 0.5em;
}

.list--plain {
  list-style: none;
  padding-left: 0;
}

.list--check {
  list-style: none;
  padding-left: 0;
  max-width: var(--measure);
}

.list--check li {
  position: relative;
  padding-left: 26px;
  margin-bottom: 0.72em;
}

.list--check li::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 0.62em;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  border: 2px solid var(--accent);
}

/* ── definition lists ──────────────────────────────────────────────────── */

.defs {
  margin: 0;
  display: grid;
  grid-template-columns: minmax(160px, 15em) 1fr;
  gap: 0;
  border-top: 1px solid var(--border);
}

.defs dt {
  font-weight: 620;
  padding: 14px 18px 14px 0;
  border-bottom: 1px solid var(--border);
}

.defs dd {
  margin: 0;
  padding: 14px 0;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.defs dd p:last-child {
  margin-bottom: 0;
}

@media (max-width: 640px) {
  .defs {
    grid-template-columns: 1fr;
  }

  .defs dt {
    padding-bottom: 2px;
    border-bottom: none;
  }

  .defs dd {
    padding-top: 4px;
  }
}

/* ── tables ────────────────────────────────────────────────────────────── */

.tablewrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  max-width: 100%;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.945rem;
  min-width: 480px;
}

caption {
  text-align: left;
  padding: 14px 18px 0;
  color: var(--text-faint);
  font-size: 0.86rem;
}

th,
td {
  text-align: left;
  vertical-align: top;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
}

thead th {
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 620;
  background: var(--bg-sunken);
}

tbody th {
  font-weight: 600;
  color: var(--text);
}

tbody td {
  color: var(--text-muted);
}

tbody tr:last-child th,
tbody tr:last-child td {
  border-bottom: none;
}

/* ── notes ─────────────────────────────────────────────────────────────── */

.note {
  border: 1px solid var(--accent-border);
  background: var(--accent-soft);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin: 22px 0;
  max-width: var(--measure);
}

.note p {
  margin-bottom: 0.7em;
  color: var(--text);
}

.note p:last-child {
  margin-bottom: 0;
}

.note__title {
  font-weight: 640;
  margin-bottom: 0.4em !important;
}

.note--caution {
  border-color: var(--caution-border);
  background: var(--caution-soft);
}

.note--caution .note__title {
  color: var(--caution-text);
}

/* ── the flow diagram on the homepage ──────────────────────────────────── */

.flow {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto 1fr;
  align-items: stretch;
  gap: 10px;
  margin: 6px 0 26px;
}

.flow__node {
  border: 1px solid var(--border);
  background: var(--bg-raised);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.flow__node--focus {
  border-color: var(--accent-border);
  background: var(--accent-soft);
}

.flow__node h3 {
  font-size: 0.95rem;
  margin-bottom: 0.25em;
}

.flow__node p {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.flow__arrow {
  align-self: center;
  color: var(--text-faint);
  font-size: 1.2rem;
  padding: 0 2px;
}

@media (max-width: 840px) {
  .flow {
    grid-template-columns: 1fr;
  }

  .flow__arrow {
    justify-self: center;
    transform: rotate(90deg);
  }
}

/* ── footer ────────────────────────────────────────────────────────────── */

.footer {
  border-top: 1px solid var(--border);
  background: var(--bg-sunken);
  margin-top: 40px;
}

.footer__inner {
  max-width: var(--page);
  margin: 0 auto;
  padding: 44px 20px 28px;
  display: grid;
  gap: 30px;
  grid-template-columns: minmax(240px, 2fr) 1fr 1fr;
}

@media (max-width: 760px) {
  .footer__inner {
    grid-template-columns: 1fr;
  }
}

.footer__name {
  font-weight: 640;
  margin-bottom: 0.35em;
}

.footer__blurb {
  color: var(--text-muted);
  font-size: 0.92rem;
  margin-bottom: 0;
  max-width: 40ch;
}

.footer__h {
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 640;
  margin-bottom: 0.7em;
}

.footer ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.footer li {
  margin-bottom: 0.42em;
  font-size: 0.93rem;
}

.footer a {
  color: var(--text-muted);
  text-decoration: none;
}

.footer a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.footer__legal {
  border-top: 1px solid var(--border);
}

.footer__legal p {
  max-width: var(--page);
  margin: 0 auto;
  padding: 20px;
  font-size: 0.865rem;
  color: var(--text-faint);
}

/*
 * `.footer a` strips the underline, which is right for the two link COLUMNS and
 * wrong here: this is a link inside a sentence, and axe's `link-in-text-block`
 * flagged it as serious in both themes — a link distinguished from its
 * surrounding text by colour alone. The columns above are lists, not text
 * blocks, so the rule does not reach them.
 */
.footer__legal a {
  color: var(--accent);
  text-decoration: underline;
}

/* ── legal document typography ─────────────────────────────────────────── */

.doc h2 {
  margin-top: 2.1em;
  padding-top: 0.2em;
  scroll-margin-top: 80px;
}

.doc h3 {
  margin-top: 1.6em;
  scroll-margin-top: 80px;
}

.doc > :first-child {
  margin-top: 0;
}

.doc ul,
.doc ol {
  max-width: var(--measure);
  padding-left: 1.2em;
}

.doc li {
  margin-bottom: 0.45em;
}

.doc__inner {
  max-width: 780px;
  margin: 0 auto;
  padding: 44px 20px 8px;
}

.doc__body > :first-child {
  margin-top: 0;
}

.toc {
  border: 1px solid var(--border);
  background: var(--bg-sunken);
  border-radius: var(--radius);
  padding: 18px 22px;
  margin: 0 0 34px;
}

.toc h2 {
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 0 0 0.7em;
  padding: 0;
}

.toc ol {
  margin: 0;
  padding-left: 1.25em;
  columns: 2;
  column-gap: 28px;
}

@media (max-width: 640px) {
  .toc ol {
    columns: 1;
  }
}

.toc li {
  margin-bottom: 0.3em;
  font-size: 0.93rem;
}

/* ── 404 ───────────────────────────────────────────────────────────────── */

.notfound {
  padding: 90px 0 70px;
  text-align: center;
}

.notfound p {
  margin-left: auto;
  margin-right: auto;
}

.notfound .hero__actions {
  justify-content: center;
}

/* ── THE DESKTOP COMPOSITION ────────────────────────────────────────────────
 *
 * Below this breakpoint the page is one column and the narrow reading is the
 * good one — nothing here touches it.
 *
 * Above it, the single column was the weak axis: a heading and its prose capped
 * near 68ch and flush left, with the tables and card grids beside them running
 * the full 1120px container, so scrolling stepped in and out horizontally and
 * roughly 540px of the right-hand side carried nothing at all.
 *
 * The fix is a heading rail plus ONE content column, and the arithmetic is the
 * point of it: 340 + 80 + 700 = 1120, the container width exactly. Every block
 * in a section — paragraph, list, table, card grid, note — is now 700px wide
 * and shares a left AND a right edge. There is one measure per page instead of
 * two, and the container is filled by content rather than by stretching it.
 *
 * The rail is sticky so the heading stays with the material it names through a
 * long section, which is the whole reason to spend 340px on it.
 */
@media (min-width: 1080px) {
  .hero {
    padding: 76px 0 60px;
  }

  .hero__grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    column-gap: 80px;
    align-items: start;
  }

  .glance {
    display: block;
    margin-top: 46px;
  }

  .section {
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr);
    column-gap: 80px;
    padding: 52px 0;
  }

  .section__head {
    position: sticky;
    top: 86px;
    align-self: start;
  }

  /*
   * The column IS the measure now, so the per-element caps that produced the
   * stepping are released. Without this the paragraphs would sit at 68ch inside
   * a 700px column and the tables beside them at 700px — the same defect,
   * smaller.
   */
  .section__body p,
  .section__body .list,
  .section__body .list--check,
  .section__body .defs,
  .section__body .note {
    max-width: none;
  }

  .pagehead {
    padding: 62px 0 40px;
  }

  /* The legal pages get the same rhythm: the contents list becomes the rail. */
  .doc__inner {
    max-width: var(--page);
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    column-gap: 80px;
    align-items: start;
    padding: 52px 20px 8px;
  }

  .toc {
    position: sticky;
    top: 86px;
    margin: 0;
    background: transparent;
    border: none;
    border-left: 2px solid var(--border);
    border-radius: 0;
    padding: 2px 0 2px 20px;
  }

  .toc ol {
    columns: 1;
  }

  .doc__body {
    max-width: 700px;
  }

  .doc__body p,
  .doc__body ul,
  .doc__body ol,
  .doc__body .note {
    max-width: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
