/*
 * Mamore UI v2 — design tokens.
 *
 * Raw brand values live here and ONLY here. Every other stylesheet consumes
 * semantic tokens, so a theme is a token swap rather than a rewrite.
 *
 * The brand hexes are measured, not guessed: every pixel of
 * public/assets/mtgi-logo-256.png was sampled and ranked, which gives
 * navy #012F6C, gold #FEAA03, red #ED0302 and the deep navy #00225D.
 * See docs/ui-v2/DESIGN_SYSTEM.md.
 *
 * Layering:
 *   1. brand      immutable identity, never overridden by a theme
 *   2. scale      primitive ramps (space, radius, type, motion, layout)
 *   3. semantic   the tokens components actually use -- THEME DEFINES THESE
 *   4. legacy     aliases mapping the v1 names onto the semantic layer
 */

:root {
  /* ---------------------------------------------------------------- brand */
  --brand-primary: #012F6C;        /* navy, dominant ink in the mark */
  --brand-primary-2: #0A429A;      /* lifted navy: hover, gradient partner */
  --brand-primary-dark: #00225D;   /* deep navy plane: pressed, sidebar base */
  --brand-accent: #FEAA03;         /* gold: active nav, emphasis, rescue */
  --brand-accent-hover: #F5A000;
  --brand-accent-soft: rgba(254, 170, 3, 0.12);
  --brand-action: #ED0302;         /* red: destructive + primary submit */
  --brand-action-dark: #B80201;
  --brand-ink: #0B1A2E;            /* deepest ink, light-mode text */
  --brand-surface: #FFFFFF;

  /*
   * Gold discipline. Gold is the most distinctive asset and the easiest to
   * overspend, so the "rescue protection" and "emphasis" tones are pre-mixed
   * at low alpha rather than asking each component to invent an rgba().
   */
  --brand-gold-ring: rgba(254, 170, 3, 0.38);
  --brand-gold-text: #8A5B00;      /* gold-tinted TEXT for light backgrounds */
  --brand-navy-ring: rgba(1, 47, 108, 0.16);
  --brand-navy-veil: rgba(1, 47, 108, 0.06);

  /* --------------------------------------------------------------- space */
  --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;

  /* -------------------------------------------------------------- radius */
  /* Moderate rounding by default. Pills are reserved for status, tags and
     filters -- a pill-shaped everything reads as a cheap SaaS template. */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-input: 9px;
  --radius-button: 10px;
  --radius-card: 14px;
  --radius-panel: 18px;
  --radius-overlay: 20px;
  --radius-pill: 999px;

  /* --------------------------------------------------------------- type */
  /* Families are tokens so a missing webfont degrades to the self-hosted
     Poppins already shipped, without touching a single component.

     "Mamore Lingala" sits directly AFTER Poppins, before any system font. It
     is a four-glyph face (ng, open-o, open-e, gamma) that exists only because
     Poppins upstream has never contained them, and Lingala cannot be spelled
     without them. Placed here it is consulted ONLY for those characters: every
     other glyph is already answered by Poppins, so nothing else changes face.
     It must stay BEFORE the system stack, or a machine that happens to have a
     Lingala-capable system font would render the word in one face and its
     neighbouring words in another. */
  --font-display: "Manrope", "Poppins", "Mamore Lingala", ui-sans-serif,
    -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-ui: "Inter", "Poppins", "Mamore Lingala", ui-sans-serif, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;

  /* Standalone weights, for the many places that need to emphasise text
     WITHOUT changing its size -- a KPI figure, a breadcrumb, an alert title.
     The per-size --weight-* tokens above are for type set at that size; these
     are for type that keeps its size and gains emphasis. 600 is the weight the
     h3 step already uses, so emphasis reads as the same voice, not a louder one.

     These were referenced in components.css before they were defined here,
     which silently left eight rules at the browser default weight of 400. */
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  --text-display-xl: 44px;   --lh-display-xl: 48px;   --weight-display-xl: 800;
  --text-display-l: 34px;    --lh-display-l: 40px;    --weight-display-l: 800;
  --text-h1: 26px;           --lh-h1: 32px;           --weight-h1: 700;
  --text-h2: 20px;           --lh-h2: 26px;           --weight-h2: 700;
  --text-h3: 16px;           --lh-h3: 22px;           --weight-h3: 600;
  --text-body-l: 15px;       --lh-body-l: 24px;
  --text-body: 14px;         --lh-body: 21px;
  --text-body-s: 13px;       --lh-body-s: 19px;
  --text-caption: 12px;      --lh-caption: 16px;      --weight-caption: 500;
  --text-micro: 11px;        --lh-micro: 14px;        --weight-micro: 600;

  --tracking-wide: 0.08em;    /* uppercase eyebrows and table heads */
  --tracking-tight: -0.02em;  /* display figures */

  /* -------------------------------------------------------------- layout */
  --sidebar-width: 264px;
  --sidebar-collapsed: 72px;
  --topbar-height: 64px;
  --content-max: 1680px;
  --z-sidebar: 30;
  --z-topbar: 40;
  --z-drawer: 60;
  --z-modal: 70;
  --z-popover: 80;
  --z-toast: 90;

  /* -------------------------------------------------------------- motion */
  --dur-fast: 120ms;
  --dur-base: 180ms;
  --dur-slow: 260ms;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);

  /* -------------------------------------------------------- status tones */
  /* One palette for status, used by StatusPill, charts and the Action Center.
     Tone is never the only signal -- every use pairs it with an icon or text. */
  --tone-success: #12784A;
  --tone-success-bg: rgba(18, 120, 74, 0.10);
  --tone-warning: #A85A0B;
  --tone-warning-bg: rgba(168, 90, 11, 0.10);
  --tone-danger: #C0261C;
  --tone-danger-bg: rgba(192, 38, 28, 0.10);
  --tone-info: #0B5FA6;
  --tone-info-bg: rgba(11, 95, 166, 0.10);
  --tone-neutral: #5A6B85;
  --tone-neutral-bg: rgba(90, 107, 133, 0.10);

  /*
   * Chart series. Ordered by prominence, not hue rotation, so the first series
   * is always the one the reader should look at first. Semantic, not rainbow.
   */
  --chart-1: #012F6C;   /* navy    - primary series */
  --chart-2: #FEAA03;   /* gold    - emphasis / comparison */
  --chart-3: #0A429A;   /* navy-2  - third series */
  --chart-4: #5A6B85;   /* slate   - neutral context */
  --chart-5: #12784A;   /* green   - positive */
  --chart-6: #C0261C;   /* red     - negative / exceptions */
  --chart-grid: rgba(11, 26, 46, 0.08);
  --chart-axis: #6B7C99;
  /* The series above were previously declared AFTER the closing brace of this
     :root block, which left them as bare declarations belonging to no rule at
     all. The CSS parser discards them, so --chart-3 through --chart-6 resolved
     to the empty string. light.css only redefines --chart-grid and
     --chart-axis, so light theme silently lost series 3-6 while dark theme --
     which redefines all six -- looked correct. Verified in Chrome before this
     fix: getComputedStyle(documentElement).getPropertyValue('--chart-3') === ''. */

  /* ------------------------------------------------- LEGACY COMPATIBILITY
   * The v1 stylesheet (public/assets/app.css, 489 lines) uses these names in
   * roughly 60 declarations. Aliasing them onto the semantic layer is what
   * makes this migration INCREMENTAL: the existing markup keeps rendering
   * correctly while components are rebuilt one at a time, instead of a
   * big-bang rewrite that would break 23 panels at once.
   *
   * Every one of these is removed once the last v1 call site is gone.
   */
  --ink: var(--text-primary);
  --navy: var(--brand-primary);
  --navy-2: var(--brand-primary-2);
  --forest: var(--brand-primary);
  --forest-2: var(--brand-primary-2);
  --red: var(--brand-action);
  --gold: var(--brand-accent);
  --paper: var(--bg-app);
  --surface: var(--surface-1);
  --line: var(--border-default);
  --muted: var(--text-muted);
  --accent: var(--brand-action);
  --accent-dark: var(--brand-action-dark);
  --font: var(--font-ui);
  --shadow: var(--shadow-md);
}

  /* ======================================================================
   * SEMANTIC DEFAULTS
   *
   * These are the LIGHT values, declared here so the design system is complete
   * and legible on its own even if a theme file fails to load. The theme files
   * do NOT use a bare `:root` selector -- they bind to [data-theme="..."]
   * only. Two `:root` blocks at equal specificity would make whichever theme
   * file is linked last win unconditionally, so the page would render dark
   * regardless of the user's choice. Binding both themes to the attribute
   * instead makes load order irrelevant.
   *
   * `data-theme` is written server-side by Core\AppShell on every response, so
   * the attribute is always present.
   *
   * THIS BLOCK WAS NOT INSIDE ANY RULE. The `}` that closed the :root block
   * above sat immediately before it, so every declaration from here to the end
   * of the file -- the backgrounds, surfaces, text ramp, borders, radii,
   * shadows and status tones that the design system is built from -- belonged
   * to no selector and was discarded by the parser. Chrome confirmed it:
   * tokens.css parsed to exactly ONE cssRule. Nothing looked broken because
   * themes/light.css redefines these same tokens under [data-theme="light"],
   * which is why the defect was invisible. What was actually lost is the
   * fallback this comment promises: with a theme file missing or blocked, the
   * application had no semantic tokens at all.
   *
   * Wrapping it in `:root` restores the documented behaviour and is safe
   * against the specificity concern raised above: `:root` and
   * `[data-theme="light"]` are both (0,1,0), so the winner is decided by load
   * order, and app.html links tokens.css (5) BEFORE themes/light.css (6) and
   * themes/dark.css (7). The theme files therefore always win, and they cannot
   * override each other because each is bound to its own attribute.
   * ==================================================================== */
:root {
  color-scheme: light;

  --bg-app: #F4F6FA;
  --surface-1: #FFFFFF;
  --surface-2: #FFFFFF;
  --surface-3: #F8FAFD;
  --surface-raised: #FFFFFF;
  --surface-sunken: #EEF2F8;
  --surface-nav: #012F6C;
  --surface-nav-2: #00225D;
  --surface-topbar: #FFFFFF;

  --text-primary: #0B1A2E;
  --text-secondary: #46587A;
  /* Muted text is still body text and still has to clear 4.5:1, not 3:1 --
     it is used for metadata and table captions, not for decoration. Measured
     against the three lightest surfaces it appears on:
     5.27:1 on white, 4.87:1 on --bg-app, 4.69:1 on --surface-sunken. */
  --text-muted: #5C6D86;
  --text-inverse: #FFFFFF;
  --text-on-accent: #0B1A2E;
  --text-link: #0A429A;

  --border-subtle: #E8ECF3;
  --border-default: #D8E0EC;
  --border-strong: #B9C6DA;
  /* Borders that IDENTIFY an interactive control (an input, a select, a card
     edge that carries meaning) must clear WCAG 1.4.11 at 3:1 against the
     surface they sit on. --border-subtle/--border-default are deliberately
     below that and are for decoration and grouping only. Measured: #7E90AC
     gives 3.24:1 on white, so every control edge clears the bar. */
  --border-control: #7E90AC;
  --border-focus: #0A429A;
  --border-nav: rgba(255, 255, 255, 0.12);
  --border-nav-strong: rgba(255, 255, 255, 0.34);

  /* Tinted with brand navy so elevation reads as part of the identity. */
  --shadow-sm: 0 1px 2px rgba(1, 47, 108, 0.06);
  --shadow-md: 0 4px 12px rgba(1, 47, 108, 0.08), 0 1px 3px rgba(1, 47, 108, 0.05);
  --shadow-lg: 0 12px 32px rgba(1, 47, 108, 0.12), 0 2px 6px rgba(1, 47, 108, 0.06);
  --shadow-overlay: 0 24px 60px rgba(1, 47, 108, 0.22);

  --tone-success: #0F6B41;
  --tone-warning: #8F4C07;
  --tone-danger: #B32219;
  --tone-info: #0A5290;
  --tone-neutral: #4E5F79;
  --tone-success-bg: rgba(15, 107, 65, 0.09);
  --tone-warning-bg: rgba(143, 76, 7, 0.09);
  --tone-danger-bg: rgba(179, 34, 25, 0.09);
  --tone-info-bg: rgba(10, 82, 144, 0.09);
  --tone-neutral-bg: rgba(78, 95, 121, 0.09);

  --skeleton-base: #E7ECF4;
  --skeleton-sheen: #F4F7FB;
}

/* Shared shell surface radii. */
:root { --radius-card: 8px; --radius-panel: 10px; --radius-overlay: 12px; --radius-input: 6px; --radius-button: 6px; }
