/* ARAMAH design tokens — one source for the chat (LibreChat fork) and the
   admin site, so both read as the same product (WBS 1.3.1).

   Layers:
     1. Primitives  — brand and neutral values. Don't use these in
                      components; they exist so the semantic layer has names.
     2. Semantic    — what components use: surface, text, border, accent,
                      status, chart series, plus font, size, radius, spacing,
                      shadow. Light is the default; dark applies on
                      <html class="dark"> (LibreChat) or
                      <html data-theme="dark"> (admin).
     3. Accent      — the primary brand colour as an interactive colour
                      (buttons, links, focus, active nav), with hover and
                      tints derived from it.

   Tenant theme (WBS 3.7). The admin Settings → Branding page stores three
   colours; GET /platform/branding returns them with a readable text colour
   (WCAG AA) and a dark-mode variant for each, and the chat's BrandingProvider
   and the admin's applyBranding set them on <html> as
       --brand-primary   --brand-on-primary   --brand-primary-dark   --brand-on-primary-dark
       --brand-secondary --brand-on-secondary --brand-secondary-dark --brand-on-secondary-dark
       --brand-highlight --brand-on-highlight --brand-highlight-dark --brand-on-highlight-dark
   Unset, the ARAMAH colours apply. Everything else here is derived from
   them: the gradient, hover, soft tints, chart series and the neutral greys,
   which carry a slight tint of the primary's hue (cool for ARAMAH blue, warm
   for an orange brand).

   Scope. Custom properties resolve on the element that declares them, so a
   brand variable set on a child would not reach tokens computed on <html>.
   An element with class "aramah-brand-scope" re-declares every token, which
   lets the admin preview a theme inside one box before it is saved
   (add data-theme="dark" to that element for the dark preview).

   Mapping LibreChat's own variables (--surface-*, --text-*) onto these is
   WBS 1.3.2 (client/src/aramah/theme/token-map.css). */

:root,
.aramah-brand-scope {
  /* ── 1. Primitives ──────────────────────────────────────────────────── */
  --aramah-blue:       var(--brand-primary, #0F4DB8);
  --aramah-purple:     var(--brand-secondary, #7A2BC8);
  --aramah-magenta:    var(--brand-highlight, #E5008A);
  --aramah-on-blue:    var(--brand-on-primary, #ffffff);
  --aramah-on-purple:  var(--brand-on-secondary, #ffffff);
  --aramah-on-magenta: var(--brand-on-highlight, #ffffff);
  --aramah-grad:       linear-gradient(90deg, var(--aramah-blue), var(--aramah-purple), var(--aramah-magenta));
  /* Text on a gradient-filled control: centred labels sit over the middle
     stop, so they take the secondary colour's readable text colour. */
  --aramah-on-grad:    var(--aramah-on-purple);

  /* Neutral greys: a pure grey with a few percent of --aramah-tint. The
     percentages reproduce ARAMAH's original blue-grey ramp; the tint itself
     is the primary's hue at ARAMAH blue's lightness and (at most) chroma
     (see @supports below), so a tenant colour shifts the hue, never the
     strength. Browsers without relative colours keep the ARAMAH tint. */
  --aramah-tint:     #0F4DB8;
  --aramah-gray-0:   #ffffff;
  --aramah-gray-50:  color-mix(in srgb, var(--aramah-tint) 4.3%,  #fefefe);
  --aramah-gray-100: color-mix(in srgb, var(--aramah-tint) 6.1%,  #fafafa);
  --aramah-gray-200: color-mix(in srgb, var(--aramah-tint) 9.5%,  #f6f6f6);
  --aramah-gray-300: color-mix(in srgb, var(--aramah-tint) 13.6%, #e6e6e6);
  --aramah-gray-500: color-mix(in srgb, var(--aramah-tint) 22.7%, #6f6f6f);
  --aramah-gray-600: color-mix(in srgb, var(--aramah-tint) 22%,   #b8b8b8);
  --aramah-gray-700: color-mix(in srgb, var(--aramah-tint) 25%,   #3f3f3f);
  --aramah-gray-800: color-mix(in srgb, var(--aramah-tint) 20.9%, #2c2c2c);
  --aramah-gray-850: color-mix(in srgb, var(--aramah-tint) 16.6%, #1f1f1f);
  --aramah-gray-900: color-mix(in srgb, var(--aramah-tint) 13.5%, #181818);
  --aramah-gray-950: color-mix(in srgb, var(--aramah-tint) 10.5%, #0e0e0e);
  --aramah-gray-990: color-mix(in srgb, var(--aramah-tint) 11.5%, #0c0c0c);
  --aramah-ink:      color-mix(in srgb, var(--aramah-tint) 15.1%, #1b1b1b);
  --aramah-snow:     color-mix(in srgb, var(--aramah-tint) 9%,    #fbfbfb);

  /* ── 2. Semantic: light (default) ───────────────────────────────────── */
  --aramah-bg:              var(--aramah-gray-50);   /* page behind everything */
  --aramah-surface:         var(--aramah-gray-0);    /* cards, panels, composer */
  --aramah-surface-raised:  var(--aramah-gray-0);    /* menus, modals, popovers */
  --aramah-surface-sunken:  var(--aramah-gray-100);  /* sidebar, table header, code */
  --aramah-surface-hover:   var(--aramah-gray-100);
  --aramah-input:           var(--aramah-gray-0);

  --aramah-border:          var(--aramah-gray-200);
  --aramah-border-strong:   var(--aramah-gray-300);

  --aramah-text:            var(--aramah-ink);
  --aramah-text-muted:      var(--aramah-gray-500);
  --aramah-text-inverse:    var(--aramah-gray-0);
  --aramah-link:            var(--aramah-accent);

  --aramah-ok:              #1f9d6b;
  --aramah-warn:            #b7791f;
  --aramah-err:             #d03a45;
  --aramah-info:            var(--aramah-blue);
  --aramah-ok-soft:         color-mix(in srgb, var(--aramah-ok) 12%, transparent);
  --aramah-warn-soft:       color-mix(in srgb, var(--aramah-warn) 14%, transparent);
  --aramah-err-soft:        color-mix(in srgb, var(--aramah-err) 12%, transparent);

  /* Secondary / highlight as quiet fills: active nav item, tab underline,
     badges. */
  --aramah-secondary-soft:  color-mix(in srgb, var(--aramah-purple) 16%, transparent);
  --aramah-highlight:       var(--aramah-magenta);

  /* Chart series, in order; -on is the label colour on a filled mark. */
  --aramah-series-1:        var(--aramah-blue);
  --aramah-series-1-on:     var(--aramah-on-blue);
  --aramah-series-2:        var(--aramah-magenta);
  --aramah-series-2-on:     var(--aramah-on-magenta);
  --aramah-series-3:        var(--aramah-purple);
  --aramah-series-3-on:     var(--aramah-on-purple);
  --aramah-series-4:        #43c590;
  --aramah-series-4-on:     #ffffff;
  --aramah-series-5:        #e6a23c;
  --aramah-series-5-on:     #ffffff;
  --aramah-series-6:        color-mix(in oklab, var(--aramah-blue) 55%, var(--aramah-magenta));
  --aramah-series-6-on:     var(--aramah-on-blue);

  --aramah-shadow-sm:       0 1px 2px rgba(16, 24, 40, .06);
  --aramah-shadow-md:       0 4px 16px rgba(16, 24, 40, .10);
  --aramah-scrim:           rgba(15, 20, 32, .45);   /* behind modals */

  /* ── 3. Accent (primary brand colour, interactive) ──────────────────── */
  --aramah-accent:          var(--aramah-blue);
  --aramah-on-accent:       var(--aramah-on-blue);
  --aramah-accent-hover:    color-mix(in srgb, var(--aramah-accent) 85%, #000);
  --aramah-accent-soft:     color-mix(in srgb, var(--aramah-accent) 12%, transparent);
  --aramah-focus-ring:      0 0 0 3px color-mix(in srgb, var(--aramah-accent) 35%, transparent);

  /* Group headings in the left menus (chat sidebar, admin): a light tint of
     the accent, so they stand apart from the links under them. Lighter than
     --aramah-accent-soft and the active-link fills, which also carry a bar. */
  --aramah-nav-group-bg:       color-mix(in srgb, var(--aramah-accent) 9%, transparent);
  --aramah-nav-group-bg-hover: color-mix(in srgb, var(--aramah-accent) 15%, transparent);
  --aramah-nav-group-text:     var(--aramah-text);

  /* ── Type ───────────────────────────────────────────────────────────── */
  --aramah-font-sans: system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --aramah-font-mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  --aramah-text-xs:   12px;
  --aramah-text-sm:   13px;
  --aramah-text-base: 14px;
  --aramah-text-md:   15px;
  --aramah-text-lg:   18px;
  --aramah-text-xl:   22px;
  --aramah-text-2xl:  28px;
  --aramah-leading:   1.5;
  --aramah-weight-regular:  400;
  --aramah-weight-medium:   500;
  --aramah-weight-semibold: 600;
  --aramah-weight-bold:     700;

  /* ── Shape ──────────────────────────────────────────────────────────── */
  --aramah-radius-sm:   6px;    /* chips, small buttons */
  --aramah-radius-md:   8px;    /* inputs, buttons */
  --aramah-radius-lg:   12px;   /* cards, panels, modals */
  --aramah-radius-xl:   16px;   /* composer, large surfaces */
  --aramah-radius-pill: 999px;

  /* ── Spacing (4 px grid) ────────────────────────────────────────────── */
  --aramah-space-1:  4px;
  --aramah-space-2:  8px;
  --aramah-space-3:  12px;
  --aramah-space-4:  16px;
  --aramah-space-5:  20px;
  --aramah-space-6:  24px;
  --aramah-space-8:  32px;
  --aramah-space-10: 40px;

  color-scheme: light;
}

/* The primary's hue at ARAMAH blue's lightness (0.454) and at most its
   chroma (0.18): ARAMAH blue maps onto itself, a grey brand stays neutral. */
@supports (color: oklch(from red l c h)) {
  :root,
  .aramah-brand-scope {
    --aramah-tint: oklch(from var(--brand-primary, #0F4DB8) 0.454 min(c, 0.18) h);
  }
}

/* ── 2. Semantic: dark ────────────────────────────────────────────────── */
:root.dark,
:root[data-theme="dark"],
.aramah-brand-scope[data-theme="dark"] {
  /* Brand colours switch to their dark-mode variants (lightened by the admin
     service until they stand out from the dark surface). The defaults keep
     ARAMAH's own dark look: the gradient as is, a lifted blue for accents
     and chart series. */
  --aramah-blue:       var(--brand-primary-dark, #0F4DB8);
  --aramah-purple:     var(--brand-secondary-dark, #7A2BC8);
  --aramah-magenta:    var(--brand-highlight-dark, #E5008A);
  --aramah-on-blue:    var(--brand-on-primary-dark, #ffffff);
  --aramah-on-purple:  var(--brand-on-secondary-dark, #ffffff);
  --aramah-on-magenta: var(--brand-on-highlight-dark, #ffffff);

  --aramah-bg:              var(--aramah-gray-950);
  --aramah-surface:         var(--aramah-gray-900);
  --aramah-surface-raised:  var(--aramah-gray-850);
  --aramah-surface-sunken:  var(--aramah-gray-990);
  --aramah-surface-hover:   var(--aramah-gray-850);
  --aramah-input:           var(--aramah-gray-990);

  --aramah-border:          var(--aramah-gray-800);
  --aramah-border-strong:   var(--aramah-gray-700);

  --aramah-text:            var(--aramah-snow);
  --aramah-text-muted:      var(--aramah-gray-600);
  --aramah-text-inverse:    var(--aramah-ink);

  --aramah-ok:              #43c590;
  --aramah-warn:            #e6a23c;
  --aramah-err:             #e5616a;
  --aramah-info:            var(--brand-primary-dark, #5b8def);

  --aramah-series-1:        var(--brand-primary-dark, #3D7BE6);
  --aramah-series-2:        var(--brand-highlight-dark, #E8299A);

  --aramah-shadow-sm:       0 1px 2px rgba(0, 0, 0, .30);
  --aramah-shadow-md:       0 4px 16px rgba(0, 0, 0, .40);
  --aramah-scrim:           rgba(0, 0, 0, .60);

  /* ARAMAH blue is too dark to read on a dark surface; the default accent
     lifts to the admin's existing dark-mode blue. */
  --aramah-accent:          var(--brand-primary-dark, #2b5fd0);
  --aramah-accent-hover:    color-mix(in srgb, var(--aramah-accent) 85%, #fff);
  --aramah-accent-soft:     color-mix(in srgb, var(--aramah-accent) 20%, transparent);
  --aramah-nav-group-bg:       color-mix(in srgb, var(--aramah-accent) 20%, transparent);
  --aramah-nav-group-bg-hover: color-mix(in srgb, var(--aramah-accent) 28%, transparent);

  color-scheme: dark;
}
