/*
 * TAG — the theme for /chat.
 *
 * TrueForge's UI SDK takes a theme object in application code. We do not run an
 * application: /chat is a pinned upstream image. What the server does do is read
 * its shell HTML from disk at boot and serve the directory beside it, so this
 * file is applied by apply-theme.mjs at image build time. trueforge/theme/README.md
 * says why that is the whole mechanism and what would replace it.
 *
 * Every token below is a TrueForge semantic token by its CSS-variable name
 * (primaryButtonBg -> --primary-button-bg). They arrive as inline styles on the
 * theme root, so overriding them needs !important; nothing else here does.
 *
 * TEAL COMES FROM THE BRAND PACKAGE, NOTHING ELSE DOES. Every teal below is
 * one of exactly three things: #106579 — TAG's identity colour — a step off
 * the brand's own ramp in tag-brand v2.0.0 `tokens/tokens.json` (teal.50 …
 * teal.900) or one of its semantic values, or a documented `color-mix` of
 * those over TAG's dark base whose stated formula is exact — which is the
 * rail's surface, and nothing else. The brand's rule is that teal is identity
 * and primary action; it is not a decorative colour, and no teal here was
 * mixed by eye. brand/VERSION is the pin; brand/README.md says why a pin
 * rather than a submodule.
 *
 * Everything else — the greys, the status colours, the type — still comes from
 * tag-mvp-ux: src/lib/theme/presets/sovereign-light.ts and src/app/globals.css,
 * not from a screenshot. Where a value could not carry text at 4.5:1 it is
 * darkened along its own hue and the reason is written next to it;
 * check-contrast.py re-checks every one of those pairs in CI.
 */

/* ------------------------------------------------------------------ light */
/* Sovereign Light. The default: see the boot script in index.html.         */

.aui-theme-root {
  --sidebar-bg: #F6F8FA !important;              /* bgSurface */
  --sidebar-text: #1F2328 !important;            /* rail labels are 10px — textPrimary, not muted */
  --topbar-bg: #FFFFFF !important;
  --primary-bg: #FFFFFF !important;              /* bgBase */
  --secondary-bg: #F0F2F5 !important;            /* bgHover */
  --border: #D0D7DE !important;
  --input-box-bg: #FFFFFF !important;
  /* A text field's edge is a UI component boundary: 3:1, not 1.5:1, which is
     what the brand's --border grey manages on white. This is sovereign-light's
     textMuted, the darkest grey TAG has that is still a grey. */
  --input-border: #8C959F !important;
  --text-primary: #1F2328 !important;
  --text-secondary: #57606A !important;          /* 6.4:1 on white. textMuted #8C959F is 3.0:1 — a border, never text */
  --card-bg: #FFFFFF !important;
  --dropdown-selected-item-bg: #D9EAEA !important;   /* brand:color.semantic.light.accent */
  --dropdown-selected-item-text: #1F2328 !important;
  --user-message-bg: #EDF5F4 !important;         /* brand:color.brand.mist — a teal-tinted surface, not a solid bubble */
  --user-message-text: #1F2328 !important;
  --assistant-message-bg: transparent !important;
  --assistant-message-text: #1F2328 !important;

  /* The brand teal, as the brand intends it: identity and primary action.
     White on #106579 is 6.65:1, so unlike the Sovereign teal this replaces
     (#2D8F83, 3.9:1) it needs no darkening to carry a label — the value on
     the button IS the brand's. Hover is the next step down the brand ramp,
     teal.700, at 8.63:1. */
  --primary-button-bg: #106579 !important;       /* brand:color.semantic.light.primary — the identity colour */
  --primary-button-hover: #0D5363 !important;    /* brand:color.teal.700 */
  --primary-button-text: #FFFFFF !important;

  --secondary-button-bg: #F6F8FA !important;
  --secondary-button-hover: #E9EDF1 !important;
  --secondary-button-text: #1F2328 !important;
  --ghost-button-bg: transparent !important;
  --ghost-button-hover: #E9EDF1 !important;
  --ghost-button-text: #1F2328 !important;

  /* Status. TrueForge uses these three as a solid fill AND as ink — .text-success-bg
     over .bg-success-bg/10 — so each has to clear 4.5:1 in both roles. TAG's own
     satisfied/partial/unmet sit at 4.0–4.2:1 as ink on their own tint, so each is
     darkened to 85% of its value; hue and saturation are untouched. */
  --success-bg: #166C2F !important;              /* satisfied #1A7F37 */
  --success-text: #FFFFFF !important;
  --warning-bg: #835800 !important;              /* partial   #9A6700 */
  --warning-text: #FFFFFF !important;
  --failure-bg: #B01D27 !important;              /* unmet     #CF222E */
  --failure-text: #FFFFFF !important;

  --focus-ring: #106579 !important;              /* brand:color.semantic.light.ring — 6.65:1 on both surfaces */
  --radius: 0.5rem !important;                   /* radiusMd. TrueForge's own is a 1.5rem pill */
  --composer-radius: 0.75rem !important;         /* radiusLg */
  --overlay: rgb(31 35 40 / 0.45) !important;
  --shadow-color: #1F2328 !important;
  --scrollbar-thumb: #AFB8C1 !important;         /* borderStrong */

  --font-agent-ui: "Geist Sans", "Geist", "Inter var", "Inter", ui-sans-serif,
    system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    sans-serif !important;

  /* Not TrueForge tokens — ours, used by the rules below. */
  --tag-mark-ink: #106579;                       /* brand:color.brand.teal — the mark is identity, so it is not a step off it */
  --tag-accent: #E07A5F;                         /* coral: 3.0:1 on white, so never text. NOT a brand 2.0 colour — see README */
  --tag-rule: rgb(16 101 121 / 0.22);            /* brand:color.brand.teal@22% */
}

/* ------------------------------------------------------------------- dark */
/* Not an afterthought: tag.company is dark, and a chat someone lives in all
   day follows the machine. Values are globals.css's :root — TAG's own dark. */

.aui-theme-root[data-theme="dark"] {
  --sidebar-bg: #161B22 !important;              /* bgSurface */
  --sidebar-text: #E6EDF3 !important;
  --topbar-bg: #0D1117 !important;
  --primary-bg: #0D1117 !important;              /* bgBase */
  --secondary-bg: #21262D !important;            /* bgHover */
  --border: #30363D !important;
  --input-box-bg: #161B22 !important;
  --input-border: #6E7681 !important;          /* globals.css textMuted; 3.8:1 on the field */
  --text-primary: #E6EDF3 !important;
  --text-secondary: #8B949E !important;          /* 6.2:1 on bgBase */
  --card-bg: #161B22 !important;                 /* bgElevated #1C2128 is closer to the rail; this separates */
  --dropdown-selected-item-bg: #163A44 !important;   /* brand:color.semantic.dark.accent */
  --dropdown-selected-item-text: #E6EDF3 !important;
  /* A published ramp step rather than a mix of ours, and a step quieter than
     the selected row above so a bubble and a menu highlight are not the same
     surface. --user-message-text on it is 12.36:1. */
  --user-message-bg: #072D36 !important;          /* brand:color.teal.900 */
  --user-message-text: #E6EDF3 !important;
  --assistant-message-text: #E6EDF3 !important;

  /* Inverted on purpose: a bright teal with a dark label. The brand publishes
     exactly this pairing for dark — semantic dark `primary` over
     `primary-foreground` — at 8.07:1, and it is also why the brand teal itself
     is not used here: #106579 on #0D1117 is 2.85:1, under even the 3:1 a
     graphic needs.

     HOVER IS teal.200, NOT teal.300, and the reason is lightness rather than
     contrast. This theme switches TrueForge's own gradient off below, so this
     one token IS the whole hover affordance for the primary action — and
     teal.300 #75B7C7 moves relative luminance 0.406 -> 0.418 against the base,
     which is no affordance at all. teal.200 moves it to 0.625. The label still
     clears its bar on it at 11.95:1, and the direction is the conventional one
     for a dark ground. */
  --primary-button-bg: #5FB7CB !important;       /* brand:color.semantic.dark.primary */
  --primary-button-hover: #AFD6DE !important;    /* brand:color.teal.200 — a visible step, not a neighbouring one */
  --primary-button-text: #0F1413 !important;     /* brand:color.semantic.dark.primary-foreground */

  --secondary-button-bg: #21262D !important;
  --secondary-button-hover: #2D333B !important;
  --secondary-button-text: #E6EDF3 !important;
  --ghost-button-hover: #21262D !important;
  --ghost-button-text: #E6EDF3 !important;

  /* TAG's dark status colours need no darkening: they are already inks. */
  --success-bg: #3FB950 !important;
  --success-text: #04210E !important;
  --warning-bg: #D29922 !important;
  --warning-text: #241800 !important;
  --failure-bg: #F85149 !important;
  --failure-text: #2B0705 !important;

  --focus-ring: #5FB7CB !important;              /* brand:color.semantic.dark.ring */
  --overlay: rgb(1 4 9 / 0.72) !important;
  --shadow-color: #010409 !important;
  --scrollbar-thumb: #484F58 !important;

  --tag-mark-ink: #5FB7CB;                       /* brand:color.semantic.dark.primary */
  --tag-rule: rgb(95 183 203 / 0.28);            /* brand:color.semantic.dark.primary@28% */
}

/* ------------------------------------------------------- what tokens miss */

/* The shipped stylesheet paints a fixed purple-to-indigo gradient over every
   primary button and a matching glow on the rail's. It is a background image
   and a shadow, not a token, so the palette above cannot reach it — this is the
   single biggest reason the page still looked like TrueForge in earlier attempts. */
.harness-primary-gradient button.bg-primary-button-bg,
.harness-primary-gradient .auth-screen-button {
  background-image: none !important;
}
.harness-primary-gradient[data-theme="light"] aside.bg-sidebar-bg button.bg-primary-button-bg {
  box-shadow: 0 1px 2px rgb(31 35 40 / 0.14) !important;
}

/* Same reason: the shipped rule is `body{color:#09090b;background:#fff}`, which
   flashes white behind the app before React paints, and stays white in dark. */
body {
  background: var(--primary-bg, #FFFFFF) !important;
  color: var(--text-primary, #1F2328) !important;
}

/* The mark. The shell draws TrueForge's logo as an inline SVG — in the rail and
   on the welcome screen — with no brand hook to pass ours through, so the
   drawing is hidden and the element is masked with tag-mark.svg instead. A mask
   rather than a background image, so the mark takes a colour from the theme.
   There are two of them: the light logo is a 140 viewBox and the dark one a 120,
   and they swap with the mode — theming only the first leaves TrueForge's own
   mark on the page in dark. apply-theme.mjs refuses to build if either is gone.

   A mask takes the file's ALPHA and ignores `fill` entirely, which is why
   brand v2.0.0 moving `fill` from the root element onto the path changed
   nothing here — and why the colour below is a token rather than the file's.
   What the brand master did change is the box: it carries the brand's clear
   space inside its viewBox, so the drawing is 73% of the box wide and 76% of
   it tall. `contain` in a square element binds on the TALLER axis, so the
   height fraction is the one that governs and the factor is its reciprocal —
   210/160 = 1.3125, which is what the two sizes below are the old ones times.
   The width fraction is not the factor; it is the horizontal slack, which is
   transparent clear space and moves nothing. */
.aui-theme-root svg[viewBox="0 0 140 140"] > *,
.aui-theme-root svg[viewBox="0 0 120 120"] > * {
  display: none !important;
}
.aui-theme-root svg[viewBox="0 0 140 140"],
.aui-theme-root svg[viewBox="0 0 120 120"] {
  background-color: var(--tag-mark-ink);
  -webkit-mask: url("tag-mark.svg") center / contain no-repeat;
  mask: url("tag-mark.svg") center / contain no-repeat;
}
/* 20px of a five-column mark is mud; the rail cell is 3.5rem tall and has room. */
.aui-theme-root aside svg[viewBox="0 0 140 140"],
.aui-theme-root aside svg[viewBox="0 0 120 120"] {
  width: 2.133rem !important;
  height: 2.133rem !important;
}
.aui-theme-root .aui-thread-welcome-root svg[viewBox="0 0 140 140"],
.aui-theme-root .aui-thread-welcome-root svg[viewBox="0 0 120 120"] {
  width: 4.266rem !important;
  height: 4.266rem !important;
}

/* The wordmark — the same two logos again, drawn wide. TrueForge's BrandLogo
   has a `logo` variant beside the `icon` one above: a horizontal logotype,
   737x120 in dark and 614x100 in light. Both shapes shipped in 0.2.1 as well,
   but nothing rendered them; 0.178.2 split the narrow-viewport navigation
   drawer out of the rail into its own component whose header asks for
   `variant="logo"`, so from that version the drawer's header is upstream's
   logotype with the product's name in it. That is what the captain saw.

   brand/ has the mark and no wordmark, and a TAG lockup is the brand
   repository's to publish, not this one's to invent. So the drawing is hidden
   the way the square marks' is and the box is made SQUARE at the rail's own
   size — the mark is never stretched across a 6:1 box and never cropped, and
   the same mark appears at the same size whether the rail or the drawer is
   showing it. If a horizontal TAG lockup is ever published, this is the one
   block that changes. apply-theme.mjs refuses to build when a brand-sized
   element appears that no selector here covers, which is the check that would
   have stopped this version from publishing. */
.aui-theme-root svg[viewBox="0 0 737 120"] > *,
.aui-theme-root svg[viewBox="0 0 614 100"] > * {
  display: none !important;
}
.aui-theme-root svg[viewBox="0 0 737 120"],
.aui-theme-root svg[viewBox="0 0 614 100"] {
  width: 2.133rem !important;
  height: 2.133rem !important;
  background-color: var(--tag-mark-ink);
  -webkit-mask: url("tag-mark.svg") center / contain no-repeat;
  mask: url("tag-mark.svg") center / contain no-repeat;
}

/* The rail is the brand surface. TrueForge's rail is the same near-white as
   everything else, which is most of why the stock page reads as one flat sheet;
   tag.company is a dark chrome around light content, and this is that. It is
   one element — the aside that holds the nav — and the tokens are redefined ON
   that element, so they cascade to its buttons and reach nothing outside it.
   #0E2630 is color-mix(in srgb, #0D1117 75%, #106579): TAG's dark base carrying
   the BRAND teal, where it used to carry the Sovereign one. Text on it is
   14.17:1 and the focus ring is 7.0:1 — check-contrast.py reads this
   `background` back out of this block and re-measures all four pairs against
   it, so moving the value moves the check with it. */
.aui-theme-root aside:has(> nav[aria-label="Sidebar"]) {
  /* Reverse text is the brand's `mist`, not a teal-tinted near-white of our
     own: #DCE7E5 was mixed off the Sovereign teal and nothing published it. */
  --sidebar-text: #EDF5F4 !important;            /* brand:color.brand.mist */
  --text-primary: #EDF5F4 !important;            /* brand:color.brand.mist */
  --ghost-button-text: #EDF5F4 !important;       /* brand:color.brand.mist */
  --ghost-button-hover: rgb(255 255 255 / 0.10) !important;
  --secondary-button-bg: rgb(255 255 255 / 0.06) !important;
  --secondary-button-hover: rgb(255 255 255 / 0.12) !important;
  --secondary-button-text: #EDF5F4 !important;   /* brand:color.brand.mist */
  --primary-button-bg: #5FB7CB !important;       /* brand:color.semantic.dark.primary */
  --primary-button-hover: #AFD6DE !important;    /* brand:color.teal.200 — as the dark block, same pair and same reason */
  --primary-button-text: #0F1413 !important;     /* brand:color.semantic.dark.primary-foreground */
  --focus-ring: #75B7C7 !important;              /* brand:color.teal.300 */
  --border: rgb(255 255 255 / 0.12) !important;
  --tag-mark-ink: #75B7C7;                       /* brand:color.teal.300 — the rail is darker than the dark page */
  --tag-rule: rgb(117 183 199 / 0.28);           /* brand:color.teal.300@28% */
  background: #0E2630 !important;                /* brand:mix(color.brand.teal,25%,#0D1117) */
  border-right-color: rgb(255 255 255 / 0.10) !important;
}

/* TAG's type is set tight and quiet; TrueForge's is not set at all. */
.aui-theme-root h1,
.aui-theme-root h2,
.aui-theme-root h3,
.aui-theme-root .aui-thread-welcome-root {
  letter-spacing: -0.015em;
}

/* Coral is the brand's second colour and the one thing on the page that is not
   teal or graphite. It cannot carry text at 3.0:1, so it gets the two jobs that
   are not text: the selection wash and the hairline under the mark. */
.aui-theme-root ::selection {
  background: rgb(224 122 95 / 0.28);
  color: var(--text-primary);
}
.aui-theme-root aside:has(> nav[aria-label="Sidebar"]) > .h-14 {
  border-bottom: 1px solid var(--tag-rule);
}

@media (prefers-reduced-motion: reduce) {
  .aui-theme-root *,
  .aui-theme-root *::before,
  .aui-theme-root *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
