/* ============================================================================
   SAHE Library — "Editorial Command Centre" design system
   Foundation: fonts, tokens, base layer, utilities, keyframes.

   Spec: docs/design-system.md §4 (colour) §5 (type) §6 (space) §7 (contract)
   Re-hued to the SAHE brand: navy #071933 (ink/chrome), orange #e36036 (coral
   slot). Royal, amber, crimson, plum and slate are the system's generic status
   colours and are deliberately left unchanged.

   LAW 1: never hard-code a colour anywhere else. Every paint is var(--token).
   ========================================================================= */

/* ── Fonts — self-hosted, no CDN request ─────────────────────────────────── */

@font-face {
  font-family: "Outfit";
  src: url("../fonts/outfit-normal.woff2") format("woff2");
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
}

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

/* ── Light theme tokens ──────────────────────────────────────────────────── */

:root {
  color-scheme: light;

  /* Ink — the navy text ramp */
  --ink: #071933;
  --ink-soft: #425166;
  --ink-mute: #606e81;
  --ink-faint: #8994a4;
  --ink-line: #c9d1dc;

  /* Hues — five variants each */
  --coral: #e36036;
  --coral-strong: #c53f1c;
  --coral-hover: #ab3718;
  --coral-soft: #f9efea;
  --coral-line: #f5d4c8;

  --teal: #20a187;
  --teal-strong: #177c69;
  --teal-hover: #146959;
  --teal-soft: #e5f5f1;
  --teal-line: #b3e0d4;

  --royal: #123a85;
  --royal-strong: #123a85;
  --royal-hover: #0e2f6e;
  --royal-soft: #e8eefa;
  --royal-line: #bfd0ee;

  --amber: #b77a21;
  --amber-strong: #8f5e14;
  --amber-hover: #744c0f;
  --amber-soft: #fbf1de;
  --amber-line: #ecd5a6;

  --crimson: #b4331f;
  --crimson-strong: #b4331f;
  --crimson-hover: #962917;
  --crimson-soft: #fceeeb;
  --crimson-line: #f2c4ba;

  --plum: #6b3fa0;
  --plum-strong: #5b2f92;
  --plum-hover: #4b2680;
  --plum-soft: #f2ecfb;
  --plum-line: #d6c3ee;

  --slate: #5b6b84;
  --slate-strong: #4c5a70;
  --slate-hover: #3f4b5e;
  --slate-soft: #eef1f5;
  --slate-line: #d4dbe5;

  /* Surfaces */
  --paper: #fbfaf8;
  --surface: #ffffff;
  --surface-alt: #f5f3ef;
  --surface-sunken: #f0eee9;
  --rule: #e6e3dd;
  --rule-strong: #d3cfc6;

  /* Chrome — keeps its own scale, reads identically in both themes */
  --chrome: #071933;
  --chrome-alt: #0b2549;
  --chrome-rule: #173460;
  --chrome-text: #bcc3cb;
  --chrome-text-mute: #7d8897;
  --chrome-text-strong: #ffffff;

  /* Effects — navy at low alpha, never black: a black shadow on warm paper
     reads dirty. */
  --shadow-raise:  0 1px 2px rgb(7 25 51 / 0.04), 0 4px 16px rgb(7 25 51 / 0.06);
  --shadow-float:  0 2px 4px rgb(7 25 51 / 0.05), 0 12px 32px rgb(7 25 51 / 0.11);
  --shadow-drawer: -12px 0 48px rgb(7 25 51 / 0.14);
  --focus-ring:    0 0 0 2px var(--surface), 0 0 0 4px var(--royal);

  /* Type — Outfit for every role, mono for machine strings */
  /* One typeface across the product. `display` is the same family as `sans`;
     it keeps its own token so the display role still has a name of its own. */
  --font-display: "Outfit", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-sans:    "Outfit", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-mono:  "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  /* Nine steps. Not a modular ratio — each exists because something needs it. */
  --text-display: 2.5rem;    --text-display-lh: 1.1;   --text-display-ls: -0.022em;
  --text-figure:  2.125rem;  --text-figure-lh:  1;     --text-figure-ls:  -0.02em;
  --text-h1:      1.875rem;  --text-h1-lh:      1.2;   --text-h1-ls:      -0.018em;
  --text-h2:      1.25rem;   --text-h2-lh:      1.4;   --text-h2-ls:      -0.012em;
  --text-h3:      0.9375rem; --text-h3-lh:      1.45;  --text-h3-ls:      -0.004em;
  --text-body:    0.875rem;  --text-body-lh:    1.55;
  --text-sm:      0.8125rem; --text-sm-lh:      1.5;
  --text-xs:      0.75rem;   --text-xs-lh:      1.45;
  --text-label:   0.625rem;  --text-label-lh:   1.4;   --text-label-ls:   0.09em;

  /* One radius per role */
  --radius-sm: 4px;   /* badges, chips, small buttons, focus ring */
  --radius-md: 6px;   /* inputs, default buttons, cards-in-a-list */
  --radius-lg: 10px;  /* panels, dialogs, menus, toasts */
  --radius-xl: 14px;  /* the command palette, and nothing else */

  /* One easing curve for the entire product */
  --ease: cubic-bezier(0.2, 0, 0, 1);

  /* Shell measurements */
  --rail-w: 232px;
  --rail-w-collapsed: 68px;
  --topbar-h: 64px;
  --canvas-max: 1600px;
}

/* ── Dark theme — derived by inversion. -strong LIFTS instead of darkening,
      which is why no component ever branches on theme. ─────────────────── */

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

  /* Ink — the navy text ramp */
  --ink: #eef2f9;
  --ink-soft: #a9bbd6;
  --ink-mute: #8ba1c0;
  --ink-faint: #6b82a4;
  --ink-line: #264a7e;

  /* Hues — five variants each */
  --coral: #e36036;
  --coral-strong: #e36c42;
  --coral-hover: #e7805c;
  --coral-soft: #291914;
  --coral-line: #623a2c;

  --teal: #2fbfa1;
  --teal-strong: #4ed6ba;
  --teal-hover: #6ee2ca;
  --teal-soft: #0d2a26;
  --teal-line: #1a4f44;

  --royal: #4c82e0;
  --royal-strong: #7aa6ee;
  --royal-hover: #96baf3;
  --royal-soft: #11244a;
  --royal-line: #2a4d8f;

  --amber: #d99a3c;
  --amber-strong: #e8b464;
  --amber-hover: #f0c684;
  --amber-soft: #2b2010;
  --amber-line: #57411d;

  --crimson: #e0553c;
  --crimson-strong: #ef7a63;
  --crimson-hover: #f59583;
  --crimson-soft: #2d1512;
  --crimson-line: #5a2a22;

  --plum: #a97ce8;
  --plum-strong: #bb99f0;
  --plum-hover: #ccb0f5;
  --plum-soft: #1e1a33;
  --plum-line: #3a3160;

  --slate: #8496ae;
  --slate-strong: #a2b1c5;
  --slate-hover: #b8c4d4;
  --slate-soft: #172a4a;
  --slate-line: #2a3f61;

  /* Surfaces */
  --paper: #071933;
  --surface: #0d2850;
  --surface-alt: #112f5b;
  --surface-sunken: #081e3f;
  --rule: #1d3f70;
  --rule-strong: #2a5088;

  /* Chrome — keeps its own scale, reads identically in both themes */
  --chrome: #071933;
  --chrome-alt: #0d2850;
  --chrome-rule: #1d3f70;
  --chrome-text: #a9bbd6;
  --chrome-text-mute: #6c83a5;
  --chrome-text-strong: #ffffff;

  --shadow-raise:  0 1px 2px rgb(0 0 0 / 0.3),  0 4px 16px rgb(0 0 0 / 0.35);
  --shadow-float:  0 2px 4px rgb(0 0 0 / 0.35), 0 12px 32px rgb(0 0 0 / 0.5);
  --shadow-drawer: -12px 0 48px rgb(0 0 0 / 0.5);
  --focus-ring:    0 0 0 2px var(--surface), 0 0 0 4px var(--royal);
}

/* ── Base layer ──────────────────────────────────────────────────────────── */

*, *::before, *::after {
  box-sizing: border-box;
  border-color: var(--rule);   /* so `border: 1px solid` is always correct */
}

* { margin: 0; }

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

/* A component class that sets `display` beats the UA rule for [hidden], so an
   overlay rendered hidden would paint open. This has to win. */
[hidden] { display: none !important; }

body {
  background-color: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--text-body);
  line-height: var(--text-body-lh);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 500;
  text-wrap: balance;
}

p { text-wrap: pretty; }

a {
  color: var(--royal-strong);
  text-decoration: none;
  transition: color 160ms var(--ease);
}

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

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

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

button { background: none; border: none; cursor: pointer; }

ul, ol { list-style: none; padding: 0; }

table { border-collapse: collapse; }

/* One global focus ring. A double ring reads on any background, light or
   dark, without a single line of per-component work. */
:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

::selection {
  background-color: var(--coral);
  color: #fff;
}

/* The 3px --paper border is what turns a 10px scrollbar into a thin pill
   without a custom scrollbar library. */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--rule-strong);
  border: 3px solid var(--paper);
  border-radius: 8px;
}
::-webkit-scrollbar-thumb:hover { background: var(--ink-faint); }

.scroll-chrome::-webkit-scrollbar-thumb {
  background: var(--chrome-rule);
  border-color: var(--chrome);
}

/* ── Type utilities ──────────────────────────────────────────────────────── */

/* THE signature of the system. Section headers, panel headers, stat labels,
   form labels, table headers, eyebrows, badges. Used liberally. */
.label {
  font-size: var(--text-label);
  line-height: var(--text-label-lh);
  letter-spacing: var(--text-label-ls);
  text-transform: uppercase;
  font-weight: 600;
}

/* Any number that sits above or beside another number. */
.tabular {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

.font-display { font-family: var(--font-display); }
.font-sans  { font-family: var(--font-sans); }
.font-mono  { font-family: var(--font-mono); }

.text-display { font-size: var(--text-display); line-height: var(--text-display-lh); letter-spacing: var(--text-display-ls); }
.text-figure  { font-size: var(--text-figure);  line-height: var(--text-figure-lh);  letter-spacing: var(--text-figure-ls); }
.text-h1      { font-size: var(--text-h1);      line-height: var(--text-h1-lh);      letter-spacing: var(--text-h1-ls); }
.text-h2      { font-size: var(--text-h2);      line-height: var(--text-h2-lh);      letter-spacing: var(--text-h2-ls); }
.text-h3      { font-size: var(--text-h3);      line-height: var(--text-h3-lh);      letter-spacing: var(--text-h3-ls); }
.text-body    { font-size: var(--text-body);    line-height: var(--text-body-lh); }
.text-sm      { font-size: var(--text-sm);      line-height: var(--text-sm-lh); }
.text-xs      { font-size: var(--text-xs);      line-height: var(--text-xs-lh); }

.text-ink       { color: var(--ink); }
.text-ink-soft  { color: var(--ink-soft); }
.text-ink-mute  { color: var(--ink-mute); }
.text-ink-faint { color: var(--ink-faint); }

.font-medium   { font-weight: 500; }
.font-semibold { font-weight: 600; }

.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.measure  { max-width: 68ch; }   /* never let a paragraph run the full canvas */
.measure-narrow { max-width: 46ch; }

/* ── Structural utilities ────────────────────────────────────────────────── */

/* A vertical hairline dividing stat columns, the way a newspaper divides them */
.rule-y { border-inline-start: 1px solid var(--rule); }

/* The hairline that fades out — closes every section header. A small thing
   that says "this section starts here" without drawing a box. */
.rule-fade {
  background: linear-gradient(90deg, var(--rule) 0%, transparent 100%);
  height: 1px;
}

/* Texture for the navy sign-in panel. One place only. */
.grain {
  background-image: radial-gradient(circle at 1px 1px,
    color-mix(in srgb, var(--ink) 6%, transparent) 1px, transparent 0);
  background-size: 4px 4px;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.scroll-x { overflow-x: auto; }   /* wide content scrolls in its own box */

/* ── Keyframes ───────────────────────────────────────────────────────────── */

@keyframes rise     { from { opacity: 0; transform: translateY(6px); }
                      to   { opacity: 1; transform: none; } }
@keyframes fade     { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-in { from { transform: translateX(100%); } to { transform: none; } }
@keyframes shimmer  { from { background-position: -200% 0; }
                      to   { background-position: 200% 0; } }
@keyframes spin     { to { transform: rotate(360deg); } }

.animate-rise     { animation: rise 0.24s var(--ease) both; }
.animate-fade     { animation: fade 0.18s var(--ease) both; }
.animate-slide-in { animation: slide-in 0.26s var(--ease) both; }

/* ── Reduced motion ──────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── Tone utilities ───────────────────────────────────────────────────────
   The classes the TONE_* maps in design/tones.py resolve to. Generated from
   the token set, so a tone can never point at a colour that does not exist. */

.text-coral        { color: var(--coral); }
.text-coral-strong { color: var(--coral-strong); }
.bg-coral          { background-color: var(--coral); }
.bg-coral-strong   { background-color: var(--coral-strong); }
.bg-coral-soft     { background-color: var(--coral-soft); }
.border-coral      { border-color: var(--coral); }
.border-coral-line { border-color: var(--coral-line); }

.text-teal        { color: var(--teal); }
.text-teal-strong { color: var(--teal-strong); }
.bg-teal          { background-color: var(--teal); }
.bg-teal-strong   { background-color: var(--teal-strong); }
.bg-teal-soft     { background-color: var(--teal-soft); }
.border-teal      { border-color: var(--teal); }
.border-teal-line { border-color: var(--teal-line); }

.text-royal        { color: var(--royal); }
.text-royal-strong { color: var(--royal-strong); }
.bg-royal          { background-color: var(--royal); }
.bg-royal-strong   { background-color: var(--royal-strong); }
.bg-royal-soft     { background-color: var(--royal-soft); }
.border-royal      { border-color: var(--royal); }
.border-royal-line { border-color: var(--royal-line); }

.text-amber        { color: var(--amber); }
.text-amber-strong { color: var(--amber-strong); }
.bg-amber          { background-color: var(--amber); }
.bg-amber-strong   { background-color: var(--amber-strong); }
.bg-amber-soft     { background-color: var(--amber-soft); }
.border-amber      { border-color: var(--amber); }
.border-amber-line { border-color: var(--amber-line); }

.text-crimson        { color: var(--crimson); }
.text-crimson-strong { color: var(--crimson-strong); }
.bg-crimson          { background-color: var(--crimson); }
.bg-crimson-strong   { background-color: var(--crimson-strong); }
.bg-crimson-soft     { background-color: var(--crimson-soft); }
.border-crimson      { border-color: var(--crimson); }
.border-crimson-line { border-color: var(--crimson-line); }

.text-plum        { color: var(--plum); }
.text-plum-strong { color: var(--plum-strong); }
.bg-plum          { background-color: var(--plum); }
.bg-plum-strong   { background-color: var(--plum-strong); }
.bg-plum-soft     { background-color: var(--plum-soft); }
.border-plum      { border-color: var(--plum); }
.border-plum-line { border-color: var(--plum-line); }

.text-slate        { color: var(--slate); }
.text-slate-strong { color: var(--slate-strong); }
.bg-slate          { background-color: var(--slate); }
.bg-slate-strong   { background-color: var(--slate-strong); }
.bg-slate-soft     { background-color: var(--slate-soft); }
.border-slate      { border-color: var(--slate); }
.border-slate-line { border-color: var(--slate-line); }

.bg-ink          { background-color: var(--ink); }
.border-ink-line { border-color: var(--ink-line); }
.bg-surface      { background-color: var(--surface); }
.bg-surface-alt  { background-color: var(--surface-alt); }
.bg-surface-sunken { background-color: var(--surface-sunken); }
.bg-paper        { background-color: var(--paper); }
.border-rule     { border-color: var(--rule); }
.border-rule-strong { border-color: var(--rule-strong); }
