/* The shared pages inside a space (contact, legal notice, privacy and cookie
   policies: SPACE_PAGES in website/site_structure.py). One content template
   per page; inside a space its body takes the space's theme from the tokens
   below, so /pace/contact/ reads as PACE and /jaiko/legal/ as Jaiko.

   Everything is scoped to .spg[data-space]. The institutional pages render
   the same templates without data-space: none of these rules reach them and
   they keep their Tailwind classes, which are the default theme. This sheet
   is unlayered, so inside a space it wins over those utilities without
   !important. Class names carry the spg- prefix so Tailwind never reads them
   as utilities.

   Contrast (WCAG AA) checked for every text token on the ground it sits on;
   the ratios are noted where they were the deciding constraint. */

/* ---- Tokens per space ------------------------------------------------ */

/* Public sector and education: the palette of its entry page (space.css). */
.spg[data-space="public_sector"],
.spg[data-space="industry_aerospace"] {
  --spg-bg: #ffffff;
  --spg-surface: #102540;
  --spg-text: #0f1e2e;
  --spg-title: #0f1e2e;
  --spg-muted: #4b5b6d;            /* 7.0:1 on white */
  --spg-eyebrow: #4b5b6d;
  --spg-rule: #d5dee8;
  /* Cyan fails on white (1.9:1): links are ink with a cyan underline, as
     .sp-textlink does on the entry pages. */
  --spg-link: #0f1e2e;
  --spg-link-line: #10c7ff;
  --spg-surface-title: #ffffff;
  --spg-surface-muted: #b9c6d6;    /* 8.9:1 on #102540 */
  --spg-surface-link: #10c7ff;     /* 7.8:1 on #102540 */
  --spg-label: #dbe4ee;
  --spg-field-bg: #ffffff;
  --spg-field-text: #0f1e2e;
  --spg-field-border: #ffffff;
  --spg-placeholder: #64748b;
  --spg-focus: #10c7ff;
  --spg-error: #ff9b9b;            /* 7.6:1 on #102540 */
  --spg-accent: #10c7ff;
  --spg-accent-hover: #3ad2ff;
  --spg-accent-ink: #0f1e2e;       /* 8.5:1 on the accent */
  --spg-btn-radius: 12px;
  --spg-field-radius: 10px;
  --spg-notice-bg: #f4f8fc;
  --spg-notice-line: #10c7ff;
  --spg-notice-text: #0f1e2e;
  --spg-font-text: 'Poppins', sans-serif;
  --spg-font-display: 'Poppins', sans-serif;
  --spg-font-eyebrow: ui-monospace, SFMono-Regular, Menlo, monospace;
  --spg-title-weight: 600;
  --spg-title-tracking: -0.02em;
  /* The header's grid: 1160 px of content, 20 / 40 px gutters. */
  --spg-wrap: 1240px;
  --spg-gutter-sm: 20px;
  --spg-gutter-md: 40px;
  --spg-gutter-lg: 40px;
}
.spg[data-space="industry_aerospace"] {
  --spg-surface: #0b2540;
  --spg-notice-bg: #f3f6f9;
}

/* PACE: carbon black and graphite, PI Blue for buttons and large marks
   only, its light blue tint for small text (pace.css tokens). */
.spg[data-space="motorsport"] {
  --spg-bg: #0b0b0b;
  --spg-surface: #141820;
  --spg-text: #d9dce1;
  --spg-title: #f2f3f5;
  --spg-muted: #a3a9b3;            /* 8.3:1 on #0b0b0b, 7.5:1 on #141820 */
  --spg-eyebrow: #8fb1ff;          /* 9.3:1 on #0b0b0b */
  --spg-rule: rgba(242, 243, 245, 0.18);
  --spg-link: #8fb1ff;
  --spg-link-line: currentColor;
  --spg-surface-title: #f2f3f5;
  --spg-surface-muted: #a3a9b3;
  --spg-surface-link: #8fb1ff;     /* 8.4:1 on #141820 */
  --spg-label: #d9dce1;
  --spg-field-bg: #0b0b0b;
  --spg-field-text: #f2f3f5;
  --spg-field-border: #6b7280;     /* 3.7:1 against #141820: the field's edge */
  --spg-placeholder: #a3a9b3;
  --spg-focus: #ffd100;            /* PACE's focus colour */
  --spg-error: #ff8a8a;            /* 7.8:1 on #141820 */
  --spg-accent: #0a5bff;
  --spg-accent-hover: #3a7bff;
  --spg-accent-ink: #ffffff;       /* 5.3:1 on #0a5bff */
  --spg-btn-radius: 2px;
  --spg-field-radius: 2px;
  --spg-notice-bg: #141820;
  --spg-notice-line: #0a5bff;
  --spg-notice-text: #d9dce1;
  --spg-font-text: 'DM Sans', ui-sans-serif, system-ui, sans-serif;
  --spg-font-display: 'PACE Archivo', 'DM Sans', ui-sans-serif, system-ui, sans-serif;
  --spg-font-eyebrow: 'DM Sans', ui-sans-serif, system-ui, sans-serif;
  --spg-title-weight: 600;
  --spg-title-tracking: -0.02em;
  /* .pace-wrap: 1440 px with 20 / 40 / 80 px gutters. */
  --spg-wrap: 1440px;
  --spg-gutter-sm: 20px;
  --spg-gutter-md: 40px;
  --spg-gutter-lg: 80px;
}

/* Jaiko: warm paper, ink, orange actions with ink text (white on orange
   fails), Bricolage Grotesque and Manrope (jaiko.css tokens). */
.spg[data-space="video"] {
  --spg-bg: #f7f4ee;
  --spg-surface: #1f1d1a;
  --spg-text: #4a453e;             /* 8.7:1 on paper */
  --spg-title: #1f1d1a;
  --spg-muted: #6b655b;            /* 5.3:1 on paper */
  --spg-eyebrow: #8a3307;          /* 7.5:1 on paper */
  --spg-rule: #e2dacb;
  --spg-link: #8a3307;
  --spg-link-line: currentColor;
  --spg-surface-title: #f7f4ee;
  --spg-surface-muted: #cdc4b4;    /* 9.7:1 on ink */
  --spg-surface-link: #ff6a1a;     /* 5.9:1 on ink */
  --spg-label: #e9e3d7;
  --spg-field-bg: #fbf9f5;
  --spg-field-text: #1f1d1a;
  --spg-field-border: #fbf9f5;
  --spg-placeholder: #6b655b;
  --spg-focus: #ff6a1a;
  --spg-error: #ffa58a;            /* 8.8:1 on ink */
  --spg-accent: #ff6a1a;
  --spg-accent-hover: #ff7e38;
  --spg-accent-ink: #1f1d1a;       /* 5.9:1 on the orange */
  --spg-btn-radius: 14px;
  --spg-field-radius: 12px;
  --spg-notice-bg: #fff1e8;
  --spg-notice-line: #ff6a1a;
  --spg-notice-text: #1f1d1a;
  --spg-font-text: 'Manrope', system-ui, sans-serif;
  --spg-font-display: 'Bricolage Grotesque', 'Manrope', system-ui, sans-serif;
  --spg-font-eyebrow: 'JetBrains Mono', ui-monospace, monospace;
  --spg-title-weight: 700;
  --spg-title-tracking: -0.02em;
  /* .jk-wrap: 1160 px of content, 20 / 40 px gutters. */
  --spg-wrap: 1240px;
  --spg-gutter-sm: 20px;
  --spg-gutter-md: 40px;
  --spg-gutter-lg: 40px;
}

/* The document ground under and around the page, so overscroll and short
   pages do not flash white between the frame's header and footer. */
html:has(.spg[data-space="motorsport"]) body { background: #0b0b0b; }
html:has(.spg[data-space="video"]) body { background: #f7f4ee; }

/* ---- The page, from the tokens ---------------------------------------- */

.spg[data-space] {
  /* The base layer colours h1-h3, p, ul and links from these two. */
  --color-primary: var(--spg-text);
  --color-accent: var(--spg-link);
  background: var(--spg-bg);
  color: var(--spg-text);
  font-family: var(--spg-font-text);
  flex-grow: 1;
}
.spg-main { display: flex; flex-direction: column; flex-grow: 1; }

.spg[data-space] .spg-band { background: var(--spg-bg); }
.spg[data-space] .spg-wrap {
  width: 100%;
  max-width: var(--spg-wrap);
  margin-inline: auto;
  padding-inline: var(--spg-gutter-sm);
}
@media (min-width: 768px) { .spg[data-space] .spg-wrap { padding-inline: var(--spg-gutter-md); } }
@media (min-width: 1280px) { .spg[data-space] .spg-wrap { padding-inline: var(--spg-gutter-lg); } }

.spg[data-space] :where(h1, h2, h3),
.spg[data-space] .spg-title {
  color: var(--spg-title);
  font-family: var(--spg-font-display);
  font-weight: var(--spg-title-weight);
  letter-spacing: var(--spg-title-tracking);
}
.spg[data-space] .spg-eyebrow {
  color: var(--spg-eyebrow);
  font-family: var(--spg-font-eyebrow);
  font-weight: 700;
}
.spg[data-space] .spg-eyebrow--sub { color: var(--spg-muted); }
.spg[data-space] .spg-muted { color: var(--spg-muted); }
.spg[data-space] .spg-rules,
.spg[data-space] .spg-rules > * { border-color: var(--spg-rule); }
.spg[data-space] .spg-value { color: var(--spg-title); }
.spg[data-space] a.spg-value:hover { color: var(--spg-link); }
.spg[data-space] :where(a) { color: var(--spg-link); text-decoration-color: var(--spg-link-line); }
.spg[data-space] :where(a:focus-visible) { outline: 3px solid var(--spg-focus); outline-offset: 3px; border-radius: 2px; }
.spg[data-space] .js-copy { border-color: var(--spg-rule); color: var(--spg-muted); }
.spg[data-space] .js-copy:hover { color: var(--spg-title); border-color: var(--spg-muted); }
.spg[data-space] .js-copy:focus-visible { box-shadow: none; outline: 3px solid var(--spg-focus); outline-offset: 2px; }

/* The form band. */
.spg[data-space] .spg-surface { background: var(--spg-surface); }
.spg[data-space] .spg-narrow { max-width: calc(42rem + 2 * var(--spg-gutter-md)); padding-inline: var(--spg-gutter-sm); }
@media (min-width: 768px) { .spg[data-space] .spg-narrow { padding-inline: var(--spg-gutter-md); } }
.spg[data-space] .spg-surface-title { color: var(--spg-surface-title); }
.spg[data-space] .spg-surface-muted { color: var(--spg-surface-muted); }
.spg[data-space] .spg-surface-muted a { color: var(--spg-surface-link); text-decoration-color: currentColor; }
.spg[data-space] .spg-label { color: var(--spg-label); font-family: var(--spg-font-text); }
.spg[data-space] .spg-error { color: var(--spg-error); }
.spg[data-space] .contact-field {
  background: var(--spg-field-bg);
  color: var(--spg-field-text);
  border-color: var(--spg-field-border);
  border-radius: var(--spg-field-radius);
  font-family: var(--spg-font-text);
}
.spg[data-space] .contact-field::placeholder { color: var(--spg-placeholder); }
.spg[data-space] .contact-field:focus {
  border-color: var(--spg-focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--spg-focus) 35%, transparent);
}
/* Django marks a field with errors aria-invalid="true". */
.spg[data-space] .contact-field[aria-invalid="true"] { border-color: var(--spg-error); border-width: 2px; }
.spg[data-space] .spg-btn {
  background: var(--spg-accent);
  color: var(--spg-accent-ink);
  border-radius: var(--spg-btn-radius);
  font-family: var(--spg-font-text);
  font-weight: 700;
  box-shadow: none;
  filter: none;
}
.spg[data-space] .spg-btn:hover { background: var(--spg-accent-hover); color: var(--spg-accent-ink); }
.spg[data-space] .spg-btn:focus { box-shadow: none; }
.spg[data-space] .spg-btn:focus-visible { outline: 3px solid var(--spg-focus); outline-offset: 3px; }

/* Legal documents: a reading column on the space's grid, its left edge on
   the header's (the institutional pages centre theirs). */
.spg[data-space] .spg-doc {
  max-width: 46rem;
  margin-inline: 0;
  padding: 56px 0 88px;
}
.spg[data-space] .spg-doc :where(ul) { margin-left: 1.5rem; }
.spg[data-space] .spg-doc :where(a) { text-decoration-line: underline; text-underline-offset: 3px; }
.spg[data-space] .spg-doc :where(table, tr, th, td) { border-color: var(--spg-rule); }
.spg[data-space] .spg-doc :where(code) { color: var(--spg-title); }
.spg[data-space] .spg-notice {
  background: var(--spg-notice-bg);
  border-color: var(--spg-notice-line);
  /* The shared legal template gives the notice a 4px left stripe; inside a
     space the tinted block alone carries it (no side stripe). */
  border-left-width: 0;
}
.spg[data-space] .spg-notice,
.spg[data-space] .spg-notice :where(p, button) { color: var(--spg-notice-text); }
.spg[data-space] .spg-bordered { border-color: var(--spg-rule); }
/* The map marker keeps the accent (--color-accent is the link colour here). */
.spg[data-space] .spg-pin { fill: var(--spg-accent); }

/* ---- The confirmation toast, in the space's colours ------------------- */
/* toasts.js renders it in #toast-root, outside the page, hence html:has(). */
html:has(.spg[data-space="motorsport"]) #toast-root > [role] {
  background: #141820; color: #f2f3f5; border-color: #0a5bff; border-radius: 2px;
  font-family: 'DM Sans', ui-sans-serif, system-ui, sans-serif;
}
html:has(.spg[data-space="video"]) #toast-root > [role] {
  background: #1f1d1a; color: #f7f4ee; border-color: #ff6a1a; border-radius: 14px;
  font-family: 'Manrope', system-ui, sans-serif;
}
html:has(.spg[data-space="public_sector"]) #toast-root > [role],
html:has(.spg[data-space="industry_aerospace"]) #toast-root > [role] {
  background: #102540; color: #ffffff; border-color: #10c7ff;
}
html:has(.spg[data-space]) #toast-root > [role="alert"] { border-color: #ff8a8a; }
