/* ============================================================================
   TRAK PUBLIC FOUNDATION CSS
   Design system for the Trak Solutions public site

   Philosophy: dark, precise, engineered. Deep ink surfaces, one cyan accent
   taken from the Trak mark, a geometric display face for headings and a
   quiet humanist face for reading. Light on ornament, generous on space.
   Distinct from TMS (dense, light, greyscale-first) on purpose.
   ============================================================================ */

/* ============================================================================
   0. FONTS (self-hosted, latin subsets; see static/fonts/README.md)
   ============================================================================ */

@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("/static/fonts/space-grotesk-latin.woff2") format("woff2");
}

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("/static/fonts/inter-latin.woff2") format("woff2");
}

@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("/static/fonts/jetbrains-mono-latin.woff2") format("woff2");
}

/* ============================================================================
   1. DESIGN TOKENS
   ============================================================================ */

:root {
  color-scheme: dark;

  /* === INK (SURFACE PALETTE) === */
  --ink-950: #05070a;
  --ink-900: #07090d;
  --ink-850: #0b0e14;
  --ink-800: #10141b;
  --ink-700: #171c25;
  --ink-600: #222935;
  --ink-500: #2e3746;

  /* === FOG (TEXT PALETTE) === */
  --fog-500: #56606f;
  --fog-400: #7c8798;
  --fog-300: #8b95a5;
  --fog-200: #b7c0cc;
  --fog-100: #dfe5ec;
  --fog-50: #f5f8fb;

  /* === ACCENT (cyan from the Trak mark) === */
  --cyan-300: #5fe3f7;
  --cyan-400: #22c8e6;
  --cyan-500: #00b7d3;
  --cyan-600: #009cb6;
  --cyan-700: #007d94;

  /* === SECONDARY ACCENT (amber, used sparingly for warnings/highlights) === */
  --amber-400: #f5b73b;

  /* === STATUS COLOURS === */
  --status-success-500: #34d399;
  --status-success-bg: rgba(52, 211, 153, 0.12);
  --status-danger-500: #f87171;
  --status-danger-bg: rgba(248, 113, 113, 0.12);
  --status-warning-500: #fbbf24;
  --status-warning-bg: rgba(251, 191, 36, 0.12);
  --status-info-500: var(--cyan-400);
  --status-info-bg: rgba(34, 200, 230, 0.12);

  /* === SEMANTIC TOKENS === */
  /* Text hierarchy */
  --text-strong: var(--fog-50);
  --text: var(--fog-100);
  --text-muted: var(--fog-300);
  --text-subtle: var(--fog-400);
  --text-inverse: #052029;

  /* Interactive */
  --accent: var(--cyan-400);
  --accent-strong: var(--cyan-300);
  --accent-deep: var(--cyan-600);
  --accent-glow: rgba(34, 200, 230, 0.35);
  --accent-tint: rgba(34, 200, 230, 0.10);
  --link: var(--cyan-300);
  --link-hover: #ffffff;

  /* Surfaces */
  --bg-page: var(--ink-900);
  --bg-elev-1: rgba(13, 17, 23, 0.82);
  --bg-elev-2: rgba(23, 28, 37, 0.9);
  --bg-elev-3: var(--ink-600);
  --bg-tint: rgba(255, 255, 255, 0.025);

  /* Borders */
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --border-subtle: rgba(255, 255, 255, 0.05);
  --border-accent: rgba(34, 200, 230, 0.4);

  /* Form fields */
  --field-bg: rgba(255, 255, 255, 0.04);
  --field-border: var(--border-strong);
  --field-border-focus: var(--accent);
  --field-shadow-focus: 0 0 0 4px rgba(34, 200, 230, 0.18);

  /* === SPACING SCALE (4px base) === */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --space-20: 80px;
  --space-24: 96px;
  --space-32: 128px;

  /* Section rhythm */
  --section-y: clamp(64px, 9vw, 128px);
  --nav-height: 72px;

  /* === TYPOGRAPHY === */
  --font-display: "Space Grotesk", "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  /* Font sizes: reading scale (marketing, not dense UI) */
  --text-xs: 0.75rem;      /* 12px */
  --text-sm: 0.875rem;     /* 14px */
  --text-base: 1rem;       /* 16px */
  --text-md: 1.0625rem;    /* 17px */
  --text-lg: 1.125rem;     /* 18px */
  --text-xl: 1.25rem;      /* 20px */
  --text-2xl: 1.5rem;      /* 24px */
  --text-3xl: 1.875rem;    /* 30px */
  --text-4xl: 2.25rem;     /* 36px */
  --text-display-sm: clamp(1.9rem, 1.2rem + 2.6vw, 2.9rem);
  --text-display: clamp(2.4rem, 1.4rem + 4.2vw, 4.6rem);
  --text-display-xl: clamp(2.7rem, 1.4rem + 5.6vw, 5.5rem);

  /* Font weights */
  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;

  /* Line heights */
  --leading-tight: 1.05;
  --leading-snug: 1.25;
  --leading-normal: 1.5;
  --leading-relaxed: 1.65;

  /* Tracking */
  --tracking-display: -0.03em;
  --tracking-heading: -0.02em;
  --tracking-mono: 0.14em;

  /* === EFFECTS === */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --radius-full: 999px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 10px 30px -12px rgba(0, 0, 0, 0.7);
  --shadow-lg: 0 24px 60px -24px rgba(0, 0, 0, 0.8);
  --shadow-glow: 0 0 0 1px rgba(95, 227, 247, 0.3), 0 3px 12px -4px rgba(34, 200, 230, 0.4);

  --focus-ring: 0 0 0 3px var(--bg-page), 0 0 0 6px var(--accent);

  --duration-fast: 120ms;
  --duration-base: 180ms;
  --duration-slow: 320ms;
  --duration-reveal: 700ms;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out: cubic-bezier(0.2, 0.7, 0.2, 1);
}

/* ============================================================================
   2. RESET AND BASE
   ============================================================================ */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--nav-height) + var(--space-4));
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg-page);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-relaxed);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

body.drawer-lock {
  overflow: hidden;
}

img,
svg,
video {
  display: block;
  max-width: 100%;
  height: auto;
}

a {
  color: var(--link);
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease);
}

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

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

address {
  font-style: normal;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

::selection {
  background: rgba(34, 200, 230, 0.35);
  color: #ffffff;
}

/* ============================================================================
   3. TYPOGRAPHY
   ============================================================================ */

h1,
h2,
h3,
h4 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: var(--font-semibold);
  color: var(--text-strong);
  letter-spacing: var(--tracking-heading);
  line-height: var(--leading-snug);
  text-wrap: balance;
}

h1 { font-size: var(--text-display); line-height: var(--leading-tight); letter-spacing: var(--tracking-display); }
h2 { font-size: var(--text-display-sm); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }

p {
  margin: 0;
}

.text-gradient {
  background: linear-gradient(92deg, var(--cyan-300) 0%, var(--cyan-500) 55%, #7dd3fc 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  margin: 0 0 var(--space-4);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  letter-spacing: var(--tracking-mono);
  text-transform: uppercase;
  color: var(--accent);
}

.eyebrow::before {
  content: "";
  width: 22px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent));
}

.text-muted { color: var(--text-muted); }

/* ============================================================================
   4. LAYOUT
   ============================================================================ */

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-5);
}

.container--narrow {
  max-width: 780px;
}

.container--wide {
  max-width: 1400px;
}

@media (min-width: 640px) {
  .container {
    padding: 0 var(--space-8);
  }
}

.site-main {
  padding-top: var(--nav-height);
}

.section {
  padding: var(--section-y) 0;
  position: relative;
}

.section--flush {
  padding-top: 0;
}

.section--tinted {
  background: linear-gradient(180deg, transparent, var(--bg-tint) 20%, var(--bg-tint) 80%, transparent);
}

.section__header {
  max-width: 720px;
  margin-bottom: clamp(32px, 5vw, 56px);
}

.section__header--row {
  max-width: none;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-6);
}

.section__title {
  margin-bottom: var(--space-4);
}

.section__lead {
  font-size: var(--text-lg);
  color: var(--text-muted);
  max-width: 62ch;
}

/* Content for assistive technology only (a heading that gives a list its
   level without a visible title) */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* The skip link target: focusable so the link moves focus in every
   browser, with no ring, since the whole page would be outlined */
.site-main:focus {
  outline: none;
}

.skip-link {
  position: absolute;
  top: -100px;
  left: var(--space-4);
  z-index: 1000;
  padding: var(--space-2) var(--space-4);
  background: var(--accent);
  color: var(--text-inverse);
  border-radius: var(--radius-md);
  font-weight: var(--font-semibold);
}

.skip-link:focus {
  top: var(--space-4);
  color: var(--text-inverse);
}


/* ============================================================================
   5. COMPONENTS
   ============================================================================ */

/* --- Buttons --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 0 var(--space-5);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  letter-spacing: 0.01em;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition:
    background var(--duration-base) var(--ease),
    border-color var(--duration-base) var(--ease),
    color var(--duration-base) var(--ease),
    transform var(--duration-base) var(--ease),
    box-shadow var(--duration-base) var(--ease);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn--primary {
  background: linear-gradient(180deg, #3ad4ee 0%, var(--cyan-500) 100%);
  color: var(--text-inverse);
  box-shadow: var(--shadow-glow);
}

.btn--primary:hover {
  color: var(--text-inverse);
  background: linear-gradient(180deg, #5fe3f7 0%, #10c3dd 100%);
  transform: translateY(-1px);
  box-shadow: 0 0 0 1px rgba(95, 227, 247, 0.45), 0 5px 16px -4px rgba(34, 200, 230, 0.5);
}

.btn--primary:active {
  transform: translateY(0);
}

.btn--secondary {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border-strong);
  color: var(--text-strong);
}

.btn--secondary:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.24);
  color: #ffffff;
}

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn--ghost:hover {
  color: var(--text-strong);
  background: rgba(255, 255, 255, 0.05);
}

.btn--sm {
  min-height: 44px;
  padding: 0 var(--space-4);
  font-size: var(--text-xs);
}

.btn--lg {
  min-height: 52px;
  padding: 0 var(--space-6);
  font-size: var(--text-base);
}

.btn--block {
  width: 100%;
}

/* --- Chips and badges --- */

.chip {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}


/* --- Cards --- */

.card {
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}

.card--form {
  padding: clamp(20px, 3vw, 36px);
}

/* --- Alerts --- */

.alert {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  margin-bottom: var(--space-6);
  font-size: var(--text-sm);
}

.alert__message {
  margin: 0;
}

.alert--danger {
  background: var(--status-danger-bg);
  border-color: rgba(248, 113, 113, 0.35);
  color: #fecaca;
}

.alert--success {
  background: var(--status-success-bg);
  border-color: rgba(52, 211, 153, 0.35);
  color: #a7f3d0;
}

.alert--info {
  background: var(--status-info-bg);
  border-color: rgba(34, 200, 230, 0.35);
  color: #bdf0f9;
}

/* --- Forms --- */

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-5);
}

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

  .field--full {
    grid-column: 1 / -1;
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.label {
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-strong);
}

.label--required::after {
  content: " *";
  color: var(--accent);
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 46px;
  padding: var(--space-3) var(--space-4);
  background: var(--field-bg);
  border: 1px solid var(--field-border);
  border-radius: var(--radius-md);
  color: var(--text-strong);
  font-size: var(--text-base);
  line-height: 1.4;
  transition: border-color var(--duration-base) var(--ease), box-shadow var(--duration-base) var(--ease), background var(--duration-base) var(--ease);
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-subtle);
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--field-border-focus);
  box-shadow: var(--field-shadow-focus);
  background: rgba(255, 255, 255, 0.05);
}

.input[aria-invalid="true"],
.textarea[aria-invalid="true"] {
  border-color: var(--status-danger-500);
}

.textarea {
  resize: vertical;
  min-height: 140px;
}

.select {
  appearance: none;
  padding-right: 44px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14' fill='none'%3E%3Cpath d='M3 5l4 4 4-4' stroke='%238b95a5' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
}

.select option {
  background: var(--ink-800);
  color: var(--text);
}

.field__error {
  margin: var(--space-2) 0 0;
  font-size: var(--text-sm);
  color: var(--status-danger-500);
}

.help-text {
  font-size: var(--text-xs);
  color: var(--text-subtle);
}

.form-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  margin-top: var(--space-8);
  padding-top: var(--space-6);
  border-top: 1px solid var(--border);
}

.form-actions__note {
  font-size: var(--text-xs);
  color: var(--text-subtle);
  max-width: 44ch;
}

@media (min-width: 640px) {
  .form-actions {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

/* Honeypot: off-screen, never hidden with display:none (some bots skip those) */
.hp {
  position: absolute;
  left: -10000px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* --- Breadcrumbs --- */

.crumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
  font-size: var(--text-sm);
  color: var(--text-subtle);
}

.crumbs__link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--text-muted);
}

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

.crumbs__sep {
  color: var(--fog-500);
}

.crumbs__current {
  color: var(--text-strong);
}

/* --- Empty state --- */

.empty {
  padding: clamp(32px, 5vw, 56px);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  text-align: center;
  background: var(--bg-tint);
}

.empty__title {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: var(--font-semibold);
  color: var(--text-strong);
  margin-bottom: var(--space-2);
}

.empty__body {
  color: var(--text-muted);
  max-width: 52ch;
  margin: 0 auto;
}

/* --- Prose (long-form content, markdown articles) --- */

.prose {
  font-size: var(--text-md);
  line-height: var(--leading-relaxed);
  color: var(--text);
  /* Article authors paste long URLs and ids; never let one widen the page */
  overflow-wrap: anywhere;
}

.prose--lead {
  font-size: var(--text-lg);
}

.prose > * + * {
  margin-top: 1.1em;
}

.prose h2 {
  margin-top: 2em;
  margin-bottom: 0.6em;
  font-size: var(--text-2xl);
}

.prose h3 {
  margin-top: 1.6em;
  margin-bottom: 0.5em;
  font-size: var(--text-xl);
}

.prose h4 {
  margin-top: 1.4em;
  margin-bottom: 0.4em;
  font-size: var(--text-lg);
}

.prose h5,
.prose h6 {
  margin-top: 1.2em;
  margin-bottom: 0.3em;
  font-size: var(--text-base);
  color: var(--text-muted);
}

.prose h2:first-child,
.prose h3:first-child {
  margin-top: 0;
}

.prose del {
  color: var(--text-subtle);
}

/* Footnotes (pulldown-cmark): superscript refs and a small-print list */
.prose .footnote-reference {
  font-size: 0.75em;
  vertical-align: super;
  line-height: 0;
}

.prose .footnote-definition {
  display: flex;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.prose .footnote-definition > * + * {
  margin-top: 0;
}

.prose .footnote-definition-label {
  font-size: 0.75em;
  vertical-align: super;
  line-height: 0;
}

.prose a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-color: rgba(95, 227, 247, 0.4);
  text-underline-offset: 3px;
}

.prose a:hover {
  color: var(--link-hover);
  text-decoration-color: currentColor;
}

.prose ul,
.prose ol {
  padding-left: 1.4em;
}

.prose li + li {
  margin-top: 0.4em;
}

.prose strong {
  color: var(--text-strong);
  font-weight: var(--font-semibold);
}

.prose blockquote {
  margin-left: 0;
  padding: var(--space-2) var(--space-5);
  border-left: 2px solid var(--accent);
  color: var(--text-muted);
}

.prose code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  padding: 0.15em 0.4em;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-strong);
}

.prose pre {
  max-width: 100%;
  padding: var(--space-4);
  border-radius: var(--radius-md);
  background: var(--ink-850);
  border: 1px solid var(--border);
  overflow-x: auto;
}

.prose pre code {
  padding: 0;
  background: none;
}

.prose img {
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

.prose hr {
  border: 0;
  height: 1px;
  background: var(--border);
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  display: block;
  overflow-x: auto;
}

.prose th,
.prose td {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
}

.prose th {
  color: var(--text-strong);
  font-weight: var(--font-semibold);
}

/* Grid and flex children default to min-width: auto, which lets one
   unbreakable line (a nowrap description, a long id) widen the whole page on
   a phone. Every card that sits in a grid opts out. */
.bento__card,
.family-card,
.family-row,
.steps__item,
.highlight,
.article-card,
.category-card,
.field,
.facts-card {
  min-width: 0;
}

/* ============================================================================
   6. MOTION
   ============================================================================ */

/* Scroll reveal: hidden only once JS confirms it will reveal (no-JS shows all) */
.js-reveal [data-reveal] {
  opacity: 0;
  transform: translateY(18px);
  transition:
    opacity var(--duration-reveal) var(--ease),
    transform var(--duration-reveal) var(--ease-out);
  transition-delay: var(--reveal-delay, 0ms);
}

.js-reveal [data-reveal].is-visible {
  opacity: 1;
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .js-reveal [data-reveal] {
    opacity: 1;
    transform: none;
  }
}
