/*
 * Design tokens ("Chart room", agreed in Phase 5). Python code never hard-codes colours; add a
 * token here instead. Every text/background pair meets WCAG AA; the dark values are tuned
 * separately, not inverted.
 */

:root {
  --fi-ink: #1b2a3a;
  --fi-ink-2: #4a5b6c; /* secondary text, labels: 7.0:1 on surface */
  --fi-ink-3: #5f6f80; /* captions, axis ticks: 5.2:1 on surface */
  --fi-paper: #f4f6f8;
  --fi-surface: #ffffff;
  --fi-surface-2: #f7f9fb; /* grid header, hover row */
  --fi-rule: #d8dee4; /* hairlines */
  --fi-control: #7f8e9e; /* input, select and chip borders: 3.4:1 (WCAG 1.4.11) */

  /* Harbour: active, selected and focus. */
  --fi-accent: #1d5b7a;
  --fi-on-accent: #ffffff;
  --fi-accent-tint: color-mix(in srgb, var(--fi-accent) 9%, var(--fi-surface));
  --fi-accent-tint-hover: color-mix(in srgb, var(--fi-accent) 14%, var(--fi-surface));

  /*
   * Harbour as a 10-step scale for Mantine's primary colour (app.py). Light mode uses step 7
   * (the accent); dark mode fills with step 6 (white text 5.6:1) and takes the lighter accent
   * for text and focus from --fi-accent.
   */
  --fi-harbour-0: #eaf4f9;
  --fi-harbour-1: #d2e8f2;
  --fi-harbour-2: #a6d0e4;
  --fi-harbour-3: #6db2d2;
  --fi-harbour-4: #4b9bc0;
  --fi-harbour-5: #3585aa;
  --fi-harbour-6: #276f92;
  --fi-harbour-7: #1d5b7a;
  --fi-harbour-8: #174b65;
  --fi-harbour-9: #113a4f;

  /* Tooltips invert the scheme, so they stand clear of the grid. */
  --fi-tip-bg: #1b2a3a;
  --fi-tip-ink: #f4f6f8;

  /* Alerts: text on a light tint of the status colour (6.6:1). */
  --fi-warning-ink: #7a4a0c;
  --fi-warning-bg: color-mix(in srgb, #c07a28 12%, #ffffff);
  --fi-error-ink: #a0271f;
  --fi-error-bg: color-mix(in srgb, #d14a3f 10%, #ffffff);

  --fi-row-hover: var(--fi-surface-2);

  /*
   * Chart lines: one colour family per load country, a shade per port (components/
   * line_colors.py). Brazil green, US blue, Argentina orange, then magenta for the next
   * country. Shade 1 is the first port, 2 the second, 3 any others. Checked with the dataviz
   * palette validator (all pairs, CVD): shades 1 and 2 stay apart within a family and across
   * families; shade 3 is weak, and every line is labelled, so identity never rests on colour.
   */
  --fi-country-green-1: #00682e;
  --fi-country-green-2: #4aa969;
  --fi-country-green-3: #008769;
  --fi-country-blue-1: #1762b6;
  --fi-country-blue-2: #6aa7f4;
  --fi-country-blue-3: #707ad0;
  --fi-country-orange-1: #e4762c;
  --fi-country-orange-2: #feb98b;
  --fi-country-orange-3: #e9a03e;
  --fi-country-magenta-1: #953490;
  --fi-country-magenta-2: #d588ce;
  --fi-country-magenta-3: #c35890;
  /* Countries past the fourth: neutral, and told apart by their line labels. */
  --fi-series-overflow: var(--fi-ink-3);
  /* Implied CFR: the CBOT line under the CFR curves, neutral and dashed (components/fob_view.py). */
  --fi-cbot-line: var(--fi-ink-3);
  /* Crush margin: its one curve, in the accent (components/crush_view.py). */
  --fi-crush-line: var(--fi-accent);
  /* Crush margin history: a line per contract, the first the curve's colour. */
  --fi-crush-contract-1: var(--fi-crush-line);
  --fi-crush-contract-2: var(--fi-country-orange-1);
  --fi-crush-contract-3: var(--fi-country-magenta-1);
  --fi-crush-contract-4: var(--fi-country-green-1);
  /* Freight matrix chart: a colour per line, by its place in the ticked routes (at most four;
     Jack, 2026-11-23: not by country). Dark mode follows through the country tokens. */
  --fi-matrix-line-1: var(--fi-country-blue-1);
  --fi-matrix-line-2: var(--fi-country-orange-1);
  --fi-matrix-line-3: var(--fi-country-green-1);
  --fi-matrix-line-4: var(--fi-country-magenta-1);

  /*
   * Spread shading (diverging): teal = cheaper than the reference, amber = dearer, mixed into
   * the surface at 10/20/32% so ink stays AA on top. Teal and amber stay apart for colour-blind
   * readers (CVD ΔE 15.8), and signs are always shown, so colour is never the only cue.
   */
  --fi-spread-cheaper: #00869b;
  --fi-spread-dearer: #c07a28;
  --fi-spread-neg-1: color-mix(in srgb, var(--fi-spread-cheaper) 10%, var(--fi-surface));
  --fi-spread-neg-2: color-mix(in srgb, var(--fi-spread-cheaper) 20%, var(--fi-surface));
  --fi-spread-neg-3: color-mix(in srgb, var(--fi-spread-cheaper) 32%, var(--fi-surface));
  --fi-spread-pos-1: color-mix(in srgb, var(--fi-spread-dearer) 10%, var(--fi-surface));
  --fi-spread-pos-2: color-mix(in srgb, var(--fi-spread-dearer) 20%, var(--fi-surface));
  --fi-spread-pos-3: color-mix(in srgb, var(--fi-spread-dearer) 32%, var(--fi-surface));

  /*
   * Refresh flash (components/auto_refresh.py): a cell that moved since the last refresh
   * flashes pale green (up) or pale red (down) for a few seconds, whatever the size of the
   * move (Jack, 2026-09-28). Pale, so ink stays readable on top.
   */
  --fi-flash-up-base: #2f9e55;
  --fi-flash-down-base: #d64545;
  --fi-flash-up: color-mix(in srgb, var(--fi-flash-up-base) 24%, var(--fi-surface));
  --fi-flash-down: color-mix(in srgb, var(--fi-flash-down-base) 24%, var(--fi-surface));

  /* IBM Plex Sans ships with the app (assets/fonts.css), under the SIL Open Font License. */
  --fi-font-sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --fi-radius: 4px;
}

/* IBM Plex Sans has no Chinese characters, so Chinese pages fall back to each system's own
 * Simplified Chinese face (macOS, Windows, Linux/Android). Latin text stays in Plex. */
html:lang(zh) {
  --fi-font-sans: "IBM Plex Sans", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    "Noto Sans SC", "Noto Sans CJK SC", system-ui, sans-serif;
}

[data-mantine-color-scheme="dark"] {
  --fi-ink: #e4eaf0;
  --fi-ink-2: #b1bdc9;
  --fi-ink-3: #8d9cac;
  --fi-paper: #0d151d;
  --fi-surface: #131d27;
  --fi-surface-2: #18242f;
  --fi-rule: #243140;
  --fi-control: #607185;

  --fi-accent: #6db2d2;
  --fi-on-accent: #0d151d;
  --fi-accent-tint: color-mix(in srgb, var(--fi-accent) 12%, var(--fi-surface));
  --fi-accent-tint-hover: color-mix(in srgb, var(--fi-accent) 18%, var(--fi-surface));

  --fi-tip-bg: #e4eaf0;
  --fi-tip-ink: #131d27;

  --fi-warning-ink: #e8b470;
  --fi-warning-bg: color-mix(in srgb, #e0a25a 16%, #131d27);
  --fi-error-ink: #f2a097;
  --fi-error-bg: color-mix(in srgb, #e0665c 16%, #131d27);

  --fi-country-green-1: #5bcc80;
  --fi-country-green-2: #2e9052;
  --fi-country-green-3: #b0e7be;
  --fi-country-blue-1: #65a7fa;
  --fi-country-blue-2: #3370c7;
  --fi-country-blue-3: #b3d4ff;
  --fi-country-orange-1: #df6c32;
  --fi-country-orange-2: #a94524;
  --fi-country-orange-3: #f9bb92;
  --fi-country-magenta-1: #db7cd4;
  --fi-country-magenta-2: #a0459a;
  --fi-country-magenta-3: #f3c2ee;

  --fi-spread-cheaper: #2a9cb0;
  --fi-spread-dearer: #c4863a;
  --fi-flash-up-base: #3fbf6a;
  --fi-flash-down-base: #e5605e;
}
