/* ============================================================================
   tm-tokens.css — the single source of truth for the product's design tokens.

   Created for Phase 1 of PROJECT_UX_JOURNEY.md ("Design system foundations").
   The guide asks for one token file so a future theme change is a one-file edit.
   Most of this vocabulary already existed — it was just buried inside the middle of
   tm-polish.css, where nobody would look for it. So this is an extraction, moved
   verbatim with its measurements intact, not a rewrite. tm-polish.css keeps every
   RULE; this file owns every VALUE.

   ── On the guide's colour table ───────────────────────────────────────────────
   PROJECT_UX_JOURNEY.md §9.2 proposes --tm-primary #3b82f6, --tm-success #22c55e,
   --tm-warning #f59e0b, --tm-danger #ef4444. Those are the raw Tailwind-500 values,
   and they were measured on this app in an earlier pass: as TEXT on white, success
   #22c55e reads 2.28:1, warning #f59e0b reads 2.15:1 — both far below the 4.5 that
   AA asks of body text. Adopting the table literally would reintroduce contrast
   failures that are currently at zero across 30 pages and both themes.

   So the guide's NAMES are adopted (see the alias block at the end) and its VALUES
   are not: each alias points at the measured colour that carries the same meaning.
   Anyone following the guide gets --tm-primary and it works; nobody gets a colour
   that fails a contrast check the moment it lands on a page.
   ============================================================================ */


/* --------------------------------------------------------------------------
   1. TOKENS
   Extends the --tm-pro-* palette that already existed in the codebase rather
   than opening a ninth competing namespace.
   -------------------------------------------------------------------------- */
/* Bootstrap's own light block is written ":root, [data-bs-theme='light']" precisely so a
   permanently-light surface can re-declare the variables on ITSELF rather than inherit the
   dark ones from <html>. This block has to match that shape for the same reason: the
   standalone auth and sign-up pages are fixed-light art with white cards, but Metronic's
   scripts.bundle.js stamps data-bs-theme onto <html> from localStorage on EVERY page, so on
   those pages the tokens went dark while the card stayed white - a dark muted label on white
   at 2.45. They now carry data-bs-theme="light" on <body>, which only works because the
   selector below names it. Which element carries the attribute decides everything (trap 1). */
:root,
[data-bs-theme="light"] {
  /* Brand indigo, taken from the logo mark, not invented. KEEP #6366f1: the wordmark
     writes that exact hex inline and the two must not drift apart.
     But white on #6366f1 measures 4.47:1 - it misses WCAG AA (4.5) by 0.03. A
     rounding-level miss is still a miss, and a 13px/600 button label is not "large
     text". Rather than nudge the brand hex by one unit to game the threshold, the colour
     is split into three roles, because each has a DIFFERENT contrast partner:
       accent        identity only - borders, active markers, icons. Bears no text.
       accent-strong a SURFACE carrying a white label. Its partner is that label, not the
                     page, so a single value is correct in both themes.
       accent-text   accent used AS text, sitting on the page. Its partner IS the page,
                     so dark mode has to lighten it - see the dark block below. */
  --tm-pro-accent:        #6366f1;   /* identity        - white on it: 4.47 */
  --tm-pro-accent-strong: #4f46e5;   /* white on it: 6.29  AA pass, both themes */
  --tm-pro-accent-text:   #4f46e5;   /* on #fff: 6.29  AA pass */
  --tm-pro-accent-hover:  #4338ca;   /* the darker step above accent-strong */
  --tm-pro-accent-soft:   #eef2ff;
  /* Soft state tints - the pale backgrounds behind status callouts. Company/Create carried 14
     literal pastel hexes for these (#e8f5e9, #fff3cd, #ffe6e6, #e3f2fd ...). Light values are
     the ones that page already used; dark values are the state colour at .16 alpha. */
  --tm-pro-success-soft:  #e8f5e9;
  --tm-pro-warning-soft:  #fff3cd;
  --tm-pro-danger-soft:   #ffe6e6;
  --tm-pro-info-soft:     #e7f3ff;
  --tm-pro-accent-rgb:    99, 102, 241;
  --tm-pro-accent-strong-rgb: 79, 70, 229;
  --tm-pro-accent-text-rgb:   79, 70, 229;

  /* surfaces */
  --tm-pro-bg:            #ffffff;
  --tm-pro-bg-alt:        #f7f8fb;
  --tm-pro-bg-sunken:     #f1f3f9;
  --tm-pro-border:        #e6e8ef;
  --tm-pro-border-strong: #d5d9e4;

  /* Text - three levels, no more. Ratios against #ffffff, measured with the WCAG 2.1
     relative-luminance formula, not eyeballed: 17.85 / 7.58 / 4.51. text-light was
     #94a3b8, which is 2.56 - it was used for input placeholders and .text-gray-400, and
     placeholder text is still text. Darkened to the minimum that passes AA with the hue
     held constant; the three-step hierarchy survives (17.85 > 7.58 > 4.51). */
  --tm-pro-text:          #0f172a;   /* 17.85 */
  --tm-pro-text-muted:    #475569;   /*  7.58 */
  --tm-pro-text-light:    #637895;   /*  4.51  (was #94a3b8 = 2.56, AA fail) */

  /* State colours. The Tailwind-500/600 values these started from are built for large or
     bold text and fail AA at body size on white: success #16a34a was 3.30, warning
     #d97706 was 3.19, info #0284c7 was 4.10. Each is darkened to the minimum that
     reaches 4.5 with its hue unchanged, which also makes white legible ON them, so the
     same fix serves both the text and the badge-background use. danger #dc2626 already
     passed at 4.83 and is untouched. */
  /* These four were computed against WHITE and landed on 4.50-4.55 - both mistakes at once,
     trap 5 (a token computed against white does not serve a tinted partner) and trap 7 (never
     target the exact threshold). On the light indigo tint rgb(238,242,255), which this app
     really does paint under text, they measured 4.03-4.32, i.e. failing. Recomputed against
     that tint aiming 4.8; on plain white they now carry 5.37-5.43, so the margin is real
     rather than borderline. The dark sidebar is a separate surface and is not the partner
     here (trap 9). Nothing paints white text on these, so darkening costs no other pairing. */
  --tm-pro-success:       #107b38;   /*  4.80 on tint · 5.37 white  (was #12883e = 4.07 tint) */
  --tm-pro-warning:       #a05804;   /*  4.82 on tint · 5.40 white  (was #b26205 = 4.05 tint) */
  --tm-pro-danger:        #ce2121;   /*  4.86 on tint · 5.43 white  (was #dc2626 = 4.32 tint) */
  --tm-pro-info:          #0270a8;   /*  4.83 on tint · 5.40 white  (was #027dbc = 4.03 tint) */

  /* Badge text on Metronic's light tints. These CANNOT be the state tokens above: those
     are computed against pure white, and a tinted ground is dimmer, so the same value
     scores lower on it. They also cannot be literals - I tried that, and the light values
     then measured 2.60 / 2.55 / 2.64 on the DARK tints, 226 failing nodes. Theme-aware
     tokens, each computed against the tint it actually sits on. */
  --tm-badge-success-text: #0f7e35;   /* 4.85 on #dfffea */
  --tm-badge-warning-text: #886a00;   /* 4.80 on #fff8dd */
  --tm-badge-danger-text:  #d50738;   /* 4.80 on #ffeef3 */

  /* elevation - three levels replacing the seven measured */
  --tm-elev-1: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .06);
  --tm-elev-2: 0 2px 4px rgba(15, 23, 42, .04), 0 4px 12px rgba(15, 23, 42, .07);
  --tm-elev-3: 0 8px 16px rgba(15, 23, 42, .06), 0 16px 40px rgba(15, 23, 42, .10);

  /* geometry - four radii replacing the fifteen measured */
  --tm-r-sm: 6px;
  --tm-r-md: 8px;
  --tm-r-lg: 12px;
  --tm-r-pill: 999px;

  /* rhythm */
  --tm-sp-1: .25rem;  --tm-sp-2: .5rem;   --tm-sp-3: .75rem;
  --tm-sp-4: 1rem;    --tm-sp-5: 1.5rem;  --tm-sp-6: 2rem;

  /* motion */
  --tm-t-fast: 120ms cubic-bezier(.4, 0, .2, 1);
  --tm-t-base: 200ms cubic-bezier(.4, 0, .2, 1);

  /* --- the fix that matters most -------------------------------------------
     Latin family first, Arabic family second. Browsers resolve fallback per
     GLYPH, not per run, so Latin letters take Inter and Arabic letters take
     Cairo automatically - one stack, both scripts, each correct. Note that
     "Segoe UI" sits AFTER Cairo on purpose: it does carry Arabic, so placing
     it earlier would quietly win and undo the whole point. */
  --tm-font-ui: "Inter", "Cairo", "Noto Kufi Arabic", "Segoe UI",
                system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;

  /* Bootstrap / Metronic surface variables, repointed at the tokens above */
  --bs-font-sans-serif:    var(--tm-font-ui);
  --bs-body-bg:            var(--tm-pro-bg-alt);
  --bs-body-color:         var(--tm-pro-text);
  --bs-border-color:       var(--tm-pro-border);
  /* Bootstrap's primary drives buttons and links - both carry text, so both take the
     white-safe step, not the identity hex. */
  --bs-primary:            var(--tm-pro-accent-strong);
  --bs-primary-rgb:        var(--tm-pro-accent-strong-rgb);
  --bs-primary-active:     var(--tm-pro-accent-hover);
  --bs-primary-light:      var(--tm-pro-accent-soft);
  --bs-link-color:         var(--tm-pro-accent-text);
  --bs-link-hover-color:   var(--tm-pro-accent-hover);
  /* Metronic writes  a { color: rgba(var(--bs-link-color-RGB), var(--bs-link-opacity,1)) }
     - the -rgb channel form, so it can apply link opacity. Overriding the hex variable
     above therefore reached nothing: every link in the application stayed Metronic blue
     #1b84ff, which measures 3.63:1 on white and FAILS WCAG AA - and left links a
     different blue from the indigo buttons beside them. */
  --bs-link-color-rgb:       var(--tm-pro-accent-text-rgb);
  /* Metronic's .text-primary utility reads --bs-text-primary with !important and nothing
     was setting it, so every .text-primary label kept Metronic blue #1b84ff - 3.24:1 on
     the light-primary tint it is usually paired with. */
  --bs-text-primary:         var(--tm-pro-accent-text);
  --bs-link-hover-color-rgb: 67, 56, 202;

  /* The same treatment for the other three states, and for the same reason: Metronic derives
     EVERY success/warning/danger surface from one four-token set, so the defect and the fix
     both live at the token, not at the class. Measured on the shipped values:

         .btn-success        white on #17C653   2.27      .btn-light-success  2.12
         .btn-warning        white on #F6C000   1.69      .btn-light-warning  1.58  (65 nodes)
         .btn-danger         white on #F8285A   3.86      .btn-light-danger   3.45

     Contrast is symmetric, so a fill that carries a white label at 4.8 is also readable AS
     text on white at 4.8 - one darkened value therefore fixes the solid button, the light
     variant's label and the .text-* utility together. Success and danger take that step.

     WARNING CANNOT: yellow dark enough to carry white stops being yellow (#8c6d00, olive).
     Its fill keeps the brand hex and the LABEL flips to ink instead - 10.52:1, and it fixes
     the .btn-light-warning hover state too, since that hover paints --bs-warning under
     --bs-warning-inverse. The text role is split off into the -rgb channel (trap 2), which is
     what .text-warning actually reads. Same three-role split as the accent above. */
  --bs-success:            #0f8237;   /* white on it 4.92  (was #17C653 = 2.27) */
  --bs-success-rgb:        16, 123, 56;
  --bs-success-active:     #0c6a2d;
  --bs-danger:             #e2073c;   /* white on it 4.85  (was #F8285A = 3.86) */
  --bs-danger-rgb:         206, 33, 33;
  --bs-danger-active:      #c30634;
  --bs-warning-inverse:    #111827;   /* ink on the brand yellow 10.52 (was #fff = 1.69) */
  --bs-warning-rgb:        160, 88, 4;
  /* <code> takes Bootstrap's pink --bs-code-color; it renders session hashes and account
     identifiers here, and measured 2.67:1 on a dark card. accent-text is already
     theme-aware, so one declaration serves both themes. */
  --bs-code-color:           var(--tm-pro-accent-text);
  --bs-card-bg:            var(--tm-pro-bg);
  --bs-card-border-color:  var(--tm-pro-border);
  --bs-card-border-radius: var(--tm-r-lg);
  --bs-card-box-shadow:    var(--tm-elev-1);
}

[data-bs-theme="dark"] {
  --tm-pro-bg:            #151521;
  --tm-pro-bg-alt:        #0f0f18;
  --tm-pro-bg-sunken:     #1b1b29;
  --tm-pro-border:        #2b2b40;
  --tm-pro-border-strong: #3a3a52;
  --tm-pro-text:          #e9eaf2;
  --tm-pro-text-muted:    #a1a5b7;

  /* The light-mode values above were darkened to pass AA on white - which makes them
     FAIL on #151521. Measured against the dark page: text-light 4.01, accent-text 2.88,
     success 3.98, warning 4.00, danger 3.74, info 4.02. Each is lightened here to the
     minimum that reaches 4.5 with its hue held constant. accent-strong is deliberately
     NOT overridden: it is a button surface and its contrast partner is the white label
     on it (6.29), not the page behind it. */
  --tm-pro-text-light:    #6c819d;   /*  4.52 on dark  (light-mode #637895 = 4.01) */
  --tm-pro-accent:        #6d70f2;   /*  4.53 on dark */
  --tm-pro-accent-text:   #9e99f1;   /*  4.94 on the dark accent tint rgb(33,34,66)
                                        (was #766feb = 3.82 there) */
  --tm-pro-accent-text-rgb: 158, 153, 241;
  --bs-link-color-rgb:      158, 153, 241;
  /* "4.5x on dark" was measured against the DARKEST dark ground, rgb(15,16,20). The app also
     paints rgb(30,30,45) cards, rgb(38,38,52) hovers, rgb(43,43,64) code and rgb(44,44,58) -
     on that lightest one these four sat at 3.43-3.46, i.e. failing. That never showed while
     they were only used on badge TINTS; the moment state colour is written as plain text on a
     card it does. Recomputed against rgb(44,44,58), the lightest ground in play, aiming 4.8.
     Raising lightness only ever helps on a dark partner, so the tinted badges gain margin too;
     nothing paints white text on these, so no partner is lost. See traps 5, 6 and 7. */
  --tm-pro-success:       #17b050;   /*  4.82 lightest · 5.76 card  (was #139343 = 3.46) */
  --tm-pro-warning:       #e77f06;   /*  4.87 lightest · 5.81 card  (was #bf6905 = 3.43) */
  --tm-pro-danger:        #ea7878;   /*  4.88 lightest · 5.83 card  (was #e24848 = 3.44) */
  --tm-pro-info:          #02a1f1;   /*  4.82 lightest · 5.76 card  (was #0286c9 = 3.44) */

  /* Metronic ships DIFFERENT solid fills in dark - #00a261 / #c59a00 / #e42855 - and white
     sat at 3.31 / 2.63 / 4.44 on them. In dark the fill and the text role genuinely diverge:
     the fill must go DARKER so the white label clears, while .text-success must go LIGHTER so
     it clears the card behind it. That is why the hex and the -rgb channel below point at
     opposite ends here, and it is the one place the two must not agree. */
  --bs-success:            #00834f;   /* white on it 4.82  (was #00a261 = 3.31) */
  --bs-success-rgb:        23, 176, 80;    /* text role - matches --tm-pro-success */
  --bs-success-active:     #006b41;
  --bs-danger:             #de1c4a;   /* white on it 4.80  (was #e42855 = 4.44) */
  --bs-danger-rgb:         234, 120, 120;  /* text role - matches --tm-pro-danger */
  --bs-danger-active:      #c11840;
  --bs-warning-inverse:    #111827;   /* ink on the dark yellow fill 6.75 */
  --bs-warning-rgb:        231, 127, 6;    /* text role - matches --tm-pro-warning */

  /* measured against the dark badge tints, not the light ones */
  --tm-badge-success-text: #16b54c;   /* 4.94 on rgb(28,50,56) */
  --tm-badge-warning-text: #c49900;   /* 4.90 on rgb(57,47,40) */
  --tm-badge-danger-text:  #fa6588;   /* 4.90 on rgb(58,36,52) */
  /* <code> sits on Bootstrap's own dark code background, not the card, so accent-text
     (#8c86ee) landed at 4.44 there. Computed against rgb(44,44,58) - the LIGHTEST dark
     ground measured - so it clears everywhere, not just where I happened to sample. */
  --bs-code-color:         #9590ef;   /* 4.92 */
  /* (the stale --tm-pro-text-light: #6d6f83 that used to sit here was declared AFTER the
     override above and silently won it back, holding the placeholder colour at 3.66 on
     dark. Removed - the value is set once, higher up.) */
  --tm-pro-accent-soft:   rgba(99, 102, 241, .16);
  --tm-pro-success-soft:  rgba(23, 176, 80, .16);
  --tm-pro-warning-soft:  rgba(231, 127, 6, .16);
  --tm-pro-danger-soft:   rgba(234, 120, 120, .16);
  --tm-pro-info-soft:     rgba(2, 161, 241, .16);
  --tm-elev-1: 0 1px 2px rgba(0, 0, 0, .28);
  --tm-elev-2: 0 4px 14px rgba(0, 0, 0, .34);
  --tm-elev-3: 0 16px 40px rgba(0, 0, 0, .44);
}

/* ============================================================================
   ADDITIONS — the families PROJECT_UX_JOURNEY.md asks for that did not exist yet.
   ============================================================================ */
:root,
[data-bs-theme="light"],
[data-bs-theme="dark"] {
  /* Layout dimensions. The guide fixes the shell geometry so the sidebar, its
     collapsed rail and the header stop being magic numbers repeated per view. */
  --tm-sidebar-w:           240px;
  --tm-sidebar-w-collapsed:  64px;
  --tm-header-h:             56px;

  /* Spacing. --tm-sp-1..6 already covered 4 · 8 · 12 · 16 · 24 · 32px at a 16px
     root; the guide's scale ends at 48, so only that last step is new. */
  --tm-sp-7: 3rem;   /* 48px */

  /* ── Aliases for the vocabulary PROJECT_UX_JOURNEY.md §9.2 names ─────────────
     Values are the measured ones, for the reason given in the header. Use either
     name; they resolve to the same colour, so there is still one source. */
  --tm-primary:  var(--tm-pro-accent-strong);   /* guide said #3b82f6 */
  --tm-success:  var(--tm-pro-success);         /* guide said #22c55e — 2.28:1 as text */
  --tm-warning:  var(--tm-pro-warning);         /* guide said #f59e0b — 2.15:1 as text */
  --tm-danger:   var(--tm-pro-danger);          /* guide said #ef4444 */
  --tm-info:     var(--tm-pro-info);            /* guide said #06b6d4 */
  --tm-neutral-50:  var(--tm-pro-bg-alt);
  --tm-neutral-100: var(--tm-pro-bg-sunken);
  --tm-neutral-200: var(--tm-pro-border);
  --tm-neutral-300: var(--tm-pro-border-strong);
  --tm-neutral-500: var(--tm-pro-text-light);
  --tm-neutral-700: var(--tm-pro-text-muted);
  --tm-neutral-900: var(--tm-pro-text);

  /* The guide's shadow names, mapped onto the elevation scale already in use. */
  --tm-sh-1: var(--tm-elev-1);
  --tm-sh-2: var(--tm-elev-2);
  --tm-sh-3: var(--tm-elev-3);
}

/* The product-surface type scale. Lifted out of tm-polish.css §13 with the rest of the
   vocabulary; its own rules stayed behind. At the 12.5px root this surface uses, the
   values land on whole pixels — 10 · 11 · 12 · 13. The floor is deliberate: Arabic
   carries diacritics and dense joins in the same band and loses more than Latin below
   it, which is why nothing on this surface is allowed under 0.8rem. */
:root {
  --tm-ui-xs: 0.8rem;   /* 10px — the floor */
  --tm-ui-sm: 0.88rem;  /* 11px */
  --tm-ui-md: 0.96rem;  /* 12px */
  --tm-ui-lg: 1.04rem;  /* 13px */
}
