/*
 * globals.css — Global layout & reset rules
 *
 * Linked by every page after tokens.css.
 * Do NOT redeclare container or section padding in component CSS.
 * Adjust layout behaviour by overriding the tokens in tokens.css.
 */

/* ── Base font size ──────────────────────────────────────────────────────────
 * Sets 1rem = 10px so token values map directly to px (e.g. 1.6rem = 16px).
 * ──────────────────────────────────────────────────────────────────────────── */
html {
  font-size: 62.5%;
}

/* ── Section ─────────────────────────────────────────────────────────────────
 * Semantic full-width wrapper. Owns the gutter padding and section spacing.
 * Apply background colours and images to .section, never to .container.
 * ──────────────────────────────────────────────────────────────────────────── */
.section {
  display: flex;
  flex-direction: column;
  width: 100%;
  row-gap: var(--space-l);
  padding-top: var(--section-m);
  padding-right: var(--space-s);
  padding-bottom: var(--section-m);
  padding-left: var(--space-s);
}

/* ── Section modifiers ───────────────────────────────────────────────────────
 * Apply to .section to override bg color or padding rhythm.
 * ──────────────────────────────────────────────────────────────────────────── */
.section--tinted  { background-color: var(--color-bg); }
.section--white   { background-color: var(--color-surface-1); }
.section--primary { background-color: var(--color-primary); }
.section--dark    { background-color: var(--color-footer-bg); }
.section--green   { background-color: var(--color-secondary); }
.section--strip   {
  padding-top: var(--space-2xl);
  padding-bottom: var(--space-2xl);
}
.section--hero    {
  padding-top: 0;
  padding-bottom: 0;
  padding-left: 0;
  padding-right: 0;
}

/* ── Container ────────────────────────────────────────────────────────────────
 * Inner wrapper inside every <section>. Centres content, constrains width,
 * and establishes the flex column context for components stacked inside.
 * ──────────────────────────────────────────────────────────────────────────── */
.container {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  max-width: var(--max-width);
  row-gap: var(--space-l);
  column-gap: var(--space-l);
  margin-left: auto;
  margin-right: auto;
}

div {
  width: 100%;
}

/* ── Grid utilities: auto-centering orphaned bottom-row items ───────────────
 * Use .grid--2col / .grid--3col / .grid--4col on any grid container.
 * Orphaned items in the last row center automatically via :has().
 * :has() required — Chrome 105+, Safari 15.4+, Firefox 121+.
 * ─────────────────────────────────────────────────────────────────────────── */

/* ── 2-col (4 actual cols, items span 2) ── */
.grid--2col {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-m);
  width: 100%;
}
.grid--2col > * { width: auto; grid-column: span 2; }
/* 1 orphan → center */
.grid--2col:has(> *:last-child:nth-child(2n + 1)) > *:last-child { grid-column: 2 / span 2; }

/* ── 3-col (6 actual cols, items span 2) ── */
.grid--3col {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: var(--space-m);
  width: 100%;
}
.grid--3col > * { width: auto; grid-column: span 2; }
/* 1 orphan → center */
.grid--3col:has(> *:last-child:nth-child(3n + 1)) > *:last-child { grid-column: 3 / span 2; }
/* 2 orphans → center pair */
.grid--3col:has(> *:last-child:nth-child(3n + 2)) > *:nth-last-child(2) { grid-column: 2 / span 2; }
.grid--3col:has(> *:last-child:nth-child(3n + 2)) > *:last-child        { grid-column: 4 / span 2; }

/* ── 4-col (8 actual cols, items span 2) ── */
.grid--4col {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: var(--space-m);
  width: 100%;
}
.grid--4col > * { width: auto; grid-column: span 2; }
/* 1 orphan → center */
.grid--4col:has(> *:last-child:nth-child(4n + 1)) > *:last-child { grid-column: 4 / span 2; }
/* 2 orphans → center pair */
.grid--4col:has(> *:last-child:nth-child(4n + 2)) > *:nth-last-child(2) { grid-column: 3 / span 2; }
.grid--4col:has(> *:last-child:nth-child(4n + 2)) > *:last-child         { grid-column: 5 / span 2; }
/* 3 orphans → center trio */
.grid--4col:has(> *:last-child:nth-child(4n + 3)) > *:nth-last-child(3) { grid-column: 2 / span 2; }
.grid--4col:has(> *:last-child:nth-child(4n + 3)) > *:nth-last-child(2) { grid-column: 4 / span 2; }
.grid--4col:has(> *:last-child:nth-child(4n + 3)) > *:last-child         { grid-column: 6 / span 2; }

@media (max-width: 991px) {
  /* 3-col → 2-col at tablet */
  .grid--3col { grid-template-columns: repeat(4, 1fr); }
  .grid--3col:has(> *:last-child:nth-child(2n + 1)) > *:last-child { grid-column: 2 / span 2; }
  /* 4-col → 2-col at tablet */
  .grid--4col { grid-template-columns: repeat(4, 1fr); }
  .grid--4col:has(> *:last-child:nth-child(2n + 1)) > *:last-child { grid-column: 2 / span 2; }
}

@media (max-width: 767px) {
  .grid--2col,
  .grid--3col,
  .grid--4col { grid-template-columns: 1fr; }
  .grid--2col > *,
  .grid--3col > *,
  .grid--4col > * { grid-column: 1; }
}

/* ── Heading defaults ─────────────────────────────────────────────────────────
 * Zero browser margins (Bricks adds them). Set fluid size tokens as defaults
 * so unstyled headings are readable. Component CSS can always override.
 * ──────────────────────────────────────────────────────────────────────────── */
h1,
h2,
h3,
h4,
h5,
h6 {
  margin: 0;
  font-family: var(--font-heading);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  color: var(--color-text);
}

h1 {
  font-size: var(--heading-l);
}

h2 {
  font-size: var(--heading-m);
}

h3 {
  font-size: var(--heading-s);
}

h4 {
  font-size: var(--heading-xs);
}

h5 {
  font-size: var(--heading-2xs);
}

h6 {
  font-size: var(--heading-2xs);
}

/* ── Paragraph defaults ───────────────────────────────────────────────────────
 * Zero browser margins. Set base font size so the 62.5% html root doesn't
 * make unstyled text tiny. Component CSS can always override.
 * ──────────────────────────────────────────────────────────────────────────── */
p {
  margin: 0;
  font-size: var(--text-m);
  line-height: var(--leading-relaxed);
}

p:last-child {
  margin-bottom: var(--space-s);
}

/* ── Entrance Animations ──────────────────────────────────────────────────────
 * Progressive enhancement — all rules scoped to .js-animations so the page
 * is fully visible and functional without JavaScript.
 * animation.js adds .js-animations to <html> synchronously, then uses
 * IntersectionObserver to add .is-visible as elements enter the viewport.
 * ──────────────────────────────────────────────────────────────────────────── */

@keyframes anim-fade-up {
  from {
    opacity: 0;
    transform: translateY(24px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes anim-fade-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes anim-slide-up {
  from {
    opacity: 0;
    transform: translateY(32px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.js-animations [data-animate] {
  opacity: 0;
  will-change: opacity, transform;
}

.js-animations [data-animate="fade-up"] {
  transform: translateY(24px);
}

.js-animations [data-animate="slide-up"] {
  transform: translateY(32px);
}

.js-animations [data-animate].is-visible {
  animation-fill-mode: both;
  animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
  animation-duration: 0.55s;
}

.js-animations [data-animate="fade-up"].is-visible {
  animation-name: anim-fade-up;
}

.js-animations [data-animate="fade-in"].is-visible {
  animation-name: anim-fade-in;
}

.js-animations [data-animate="slide-up"].is-visible {
  animation-name: anim-slide-up;
}

.js-animations [data-animate-order="0"] {
  animation-delay: 0ms;
}

.js-animations [data-animate-order="1"] {
  animation-delay: 80ms;
}

.js-animations [data-animate-order="2"] {
  animation-delay: 160ms;
}

.js-animations [data-animate-order="3"] {
  animation-delay: 240ms;
}

.js-animations [data-animate-order="4"] {
  animation-delay: 320ms;
}

.js-animations [data-animate-order="5"] {
  animation-delay: 400ms;
}

.js-animations [data-animate-order="6"] {
  animation-delay: 480ms;
}

.js-animations [data-animate-order="7"] {
  animation-delay: 560ms;
}

@media (prefers-reduced-motion: reduce) {

  .js-animations [data-animate],
  .js-animations [data-animate].is-visible {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }
}