/* ==================================================================
   base.css — tokens, reset, typography, accessibility primitives
   ================================================================== */

/* Self-hosted variable fonts (latin subset, SIL OFL 1.1 — see assets/fonts/OFL-*.txt).
   Paths are relative to this stylesheet. */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("../fonts/inter-latin-variable.woff2") format("woff2");
}

@font-face {
  font-family: "Manrope";
  font-style: normal;
  font-weight: 600 800;
  font-display: swap;
  src: url("../fonts/manrope-latin-variable.woff2") format("woff2");
}

:root {
  /* Brand palette (see docs/BRAND-GUIDELINES.md) */
  --brand-industrial-navy: #101d2c;
  --brand-deep-navy: #1b2c40;
  --brand-manufacturing-orange: #f28c28;
  --brand-white: #ffffff;
  --brand-tech-light: #f4f6f8;
  --brand-slate-gray: #526174;

  /* Semantic tokens: use these in components */
  --color-primary: var(--brand-industrial-navy);
  --color-secondary: var(--brand-deep-navy);
  --color-accent: var(--brand-manufacturing-orange);
  --color-background: var(--brand-white);

  /* Legacy scale names kept as aliases so existing components stay valid */
  --color-navy-900: var(--brand-industrial-navy);
  --color-navy-800: var(--brand-deep-navy);
  --color-navy-700: #2a405b;
  --color-orange-500: var(--brand-manufacturing-orange);
  --color-orange-600: #d9741a;
  --color-orange-700: #a8550c; /* AA-compliant orange for text on light surfaces */
  --color-focus: #c2620f; /* focus ring: >=3.4:1 on white, light grey and both navies (WCAG 1.4.11) */
  --color-white: var(--brand-white);
  --color-surface: var(--brand-tech-light);
  --color-surface-alt: #e9edf1;
  --color-border: #e1e6eb;
  --color-text: var(--brand-industrial-navy);       /* body copy: 17.0:1 on white */
  --color-text-strong: var(--brand-industrial-navy);
  --color-text-muted: var(--brand-slate-gray);      /* 6.3:1 white, 5.8:1 Tech Light */
  --color-text-inverse: #e8edf3;
  --color-text-inverse-muted: #a9b6c6;

  /* Status colours (reserved: always paired with a text label) */
  --color-status-good: #1f7a4d;
  --color-status-warning: #9a6200;
  --color-status-critical: #b42318;

  /* Typography */
  --font-heading: "Manrope", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-body: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", "Consolas", monospace;

  --text-xs: 0.8125rem;
  --text-sm: 0.9375rem;
  --text-base: 1.0625rem;
  --text-lg: clamp(1.125rem, 1.05rem + 0.35vw, 1.3125rem);
  --text-xl: clamp(1.3125rem, 1.15rem + 0.7vw, 1.625rem);
  --text-2xl: clamp(1.625rem, 1.35rem + 1.2vw, 2.25rem);
  --text-3xl: clamp(2rem, 1.55rem + 2vw, 3.25rem);

  --leading-tight: 1.2;
  --leading-snug: 1.4;
  --leading-body: 1.7;

  /* Spacing scale */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --space-8: 4rem;
  --space-9: 6rem;
  --section-padding: clamp(3.5rem, 2.5rem + 4vw, 6rem);

  /* Shape and depth */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 14px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(16, 29, 44, 0.06), 0 1px 3px rgba(16, 29, 44, 0.08);
  --shadow-md: 0 4px 12px rgba(16, 29, 44, 0.08), 0 2px 4px rgba(16, 29, 44, 0.06);
  --shadow-lg: 0 18px 40px rgba(16, 29, 44, 0.14);

  /* Containers */
  --container-max: 72rem;
  --container-narrow: 46rem;
  --container-gutter: 1rem;

  /* Breakpoints — documentation only (see main.css) */
  --bp-sm: 36em;
  --bp-md: 48em;
  --bp-lg: 64em;
  --bp-xl: 90em;

  /* Motion */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;

  --header-height: 4rem;
}

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

* {
  margin: 0;
}

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

body {
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  color: var(--color-text);
  background-color: var(--color-white);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

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

img {
  height: auto;
}

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

button {
  cursor: pointer;
}

/* ---------- Typography ---------- */
h1,
h2,
h3,
h4 {
  font-family: var(--font-heading);
  color: var(--color-text-strong);
  line-height: var(--leading-tight);
  letter-spacing: -0.015em;
  text-wrap: balance;
}

h1 {
  font-size: var(--text-3xl);
  font-weight: 700;
}

h2 {
  font-size: var(--text-2xl);
  font-weight: 700;
}

h3 {
  font-size: var(--text-lg);
  font-weight: 700;
}

h4 {
  font-size: var(--text-base);
  font-weight: 700;
}

p {
  text-wrap: pretty;
}

a {
  color: var(--color-navy-800);
  text-decoration-color: var(--color-orange-500);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--color-orange-700);
}

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

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

/* The hidden attribute must win over component display rules. */
[hidden] {
  display: none !important;
}

ul[role="list"],
ol[role="list"] {
  list-style: none;
  padding: 0;
}

/* ---------- Accessibility primitives ---------- */
:focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 3px;
  border-radius: 2px;
}

.skip-link {
  position: absolute;
  top: var(--space-2);
  left: var(--space-2);
  z-index: 100;
  padding: var(--space-2) var(--space-4);
  background: var(--color-navy-900);
  color: var(--color-white);
  font-weight: 500;
  border-radius: var(--radius-sm);
  transform: translateY(-200%);
}

.skip-link:focus {
  transform: translateY(0);
  color: var(--color-white);
}

.visually-hidden {
  position: absolute !important; /* utility must never be overridden */
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

::selection {
  background: rgba(242, 140, 40, 0.3);
  color: var(--color-text-strong);
}

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

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

@media (prefers-reduced-motion: no-preference) {
  html {
    scroll-behavior: smooth;
  }
}

@media (forced-colors: active) {
  .button,
  .kpi-card,
  .bar-chart__bar {
    border: 1px solid CanvasText;
  }
}
