/* Boxel UI — semantic token contract + default (light) theme.

   This file is the source of record for the semantic design tokens that
   boxel-ui components consume (--primary, --foreground, --muted, etc.).
   Shipping it from the addon means components render correctly with zero
   host configuration — a consumer that imports the addon's styles gets a
   complete, working theme by default.

   The default values below map the semantic tokens onto the --boxel-*
   palette declared in variables.css, so the palette remains the single
   underlying source of truth for brand colors. A consumer overrides any
   token by redeclaring it on :root (or a scoped element) after this file.

   The semantic tokens declared here are the contract every theme must
   satisfy. The typography roles (--boxel-<role>-*) are only their defaults
   outside a card: a theme sets a role through its typography field, never
   by redeclaring the variable. The dark-mode counterpart (a `.dark` /
   `[data-theme='dark']` scope) is layered on separately, below.

   Every card renders against this contract. An unthemed card has the default
   theme: the values in this file. A themed card links its own Theme, so its
   CardContainer carries `data-boxel-theme-scope` and a scoped stylesheet that
   layers that Theme over these defaults. That scope element is the
   "themed-card boundary" the comments below refer to.
*/

/* The inherited light/dark signal that scoped theme stylesheets key off (via a
   style container query). Kept out of the token block below on purpose: it must
   inherit *through* themed-card boundaries so a card's own `.dark` variables
   can follow the ambient scheme, while the token values themselves must not. */
:root,
[data-theme='light'] {
  --boxel-color-scheme: light;
}

/* Typography roles, for readers outside a card. Inside one, CardContainer
   publishes the theme's values over these, and resolves to the same
   defaults when the theme sets no typography. Scheme-independent, so
   declared once on :root. */
:root {
  /* heading (h1) */
  --boxel-heading-font-family: var(--font-sans);
  --boxel-heading-font-size: var(--boxel-font-size-lg); /* 22px */
  --boxel-heading-font-weight: 700;
  --boxel-heading-line-height: var(--boxel-line-height-lg);
  --boxel-heading-letter-spacing: normal;

  /* section heading (h2) */
  --boxel-section-heading-font-family: var(--boxel-heading-font-family);
  --boxel-section-heading-font-size: var(--boxel-font-size-md); /* 20px */
  --boxel-section-heading-font-weight: 500;
  --boxel-section-heading-line-height: var(--boxel-line-height-md);
  --boxel-section-heading-letter-spacing: normal;

  /* subheading (h3) */
  --boxel-subheading-font-family: var(--boxel-heading-font-family);
  --boxel-subheading-font-size: var(--boxel-font-size); /* 16px */
  --boxel-subheading-font-weight: 500;
  --boxel-subheading-line-height: var(--boxel-line-height);
  --boxel-subheading-letter-spacing: normal;

  /* body */
  --boxel-body-font-family: var(--font-sans);
  --boxel-body-font-size: var(--boxel-font-size-sm); /* 14px */
  --boxel-body-font-weight: 400;
  --boxel-body-line-height: var(--boxel-line-height-sm);
  --boxel-body-letter-spacing: var(--tracking-normal);

  /* caption */
  --boxel-caption-font-family: var(--boxel-body-font-family);
  --boxel-caption-font-size: var(--boxel-font-size-xs); /* 12px */
  --boxel-caption-font-weight: 500;
  --boxel-caption-line-height: var(--boxel-line-height-xs);
  --boxel-caption-letter-spacing: var(--boxel-body-letter-spacing);

  /* ui label: control text, table headers, badges. Kept off the
     `--boxel-label-*` family, which is Label's own contract. */
  --boxel-ui-label-font-family: var(--boxel-body-font-family);
  --boxel-ui-label-font-size: var(--boxel-font-size-xs); /* 12px */
  --boxel-ui-label-font-weight: 500;
  --boxel-ui-label-line-height: var(--boxel-line-height-xs);
  --boxel-ui-label-letter-spacing: var(--boxel-body-letter-spacing);

  /* eyebrow: the tracked-out kicker above a title */
  --boxel-eyebrow-font-family: var(--boxel-ui-label-font-family);
  --boxel-eyebrow-font-size: var(--boxel-font-size-2xs); /* 11px */
  --boxel-eyebrow-font-weight: 600;
  --boxel-eyebrow-line-height: var(--boxel-line-height-xs);
  --boxel-eyebrow-letter-spacing: 0.08em;
}

/* Light — the default theme, and the explicit `data-theme="light"` scope used
   to force light back on inside a dark subtree. Both resolve to the same
   values.

   `:where([data-boxel-theme-scope])` re-declares the full contract at every
   themed-card boundary so token values can't inherit into a themed card from
   the chrome or an outer theme card — a theme only overrides the tokens it
   defines, and the rest reset to these defaults instead of leaking through.
   `:where()` keeps the reset at zero specificity, so the card's own scoped
   theme stylesheet always wins. */
:root,
[data-theme='light'],
:where([data-boxel-theme-scope]) {
  /* surfaces */
  --background: var(--boxel-light);
  --foreground: var(--boxel-dark);
  --card: var(--boxel-light);
  --card-foreground: var(--boxel-dark);
  --popover: var(--boxel-light);
  --popover-foreground: var(--boxel-dark);
  /* Neutral surfaces beyond shadcn's, by role: the workspace ground behind the
     page, a well sunk into a card, an editable region at rest, the pointer
     acknowledgement, zebra rows, the selected row. `--foreground` must read on
     all of them, so none carries its own -foreground. `--hover` is translucent
     so it composes over whichever surface it lands on. */
  --canvas: var(--boxel-100);
  --inset: var(--boxel-50);
  --field: var(--boxel-light);
  --hover: var(--boxel-dark-10);
  --stripe: var(--boxel-50);
  --selected: color-mix(in oklch, var(--primary) 15%, var(--card));
  --tooltip: var(--boxel-dark-80);
  --tooltip-foreground: var(--boxel-light);
  /* third ink step, fainter than --muted-foreground */
  --subtle-foreground: var(--boxel-450);

  /* roles */
  --primary: var(--boxel-highlight);
  --primary-foreground: var(--boxel-dark);
  --secondary: var(--boxel-200);
  --secondary-foreground: var(--boxel-dark);
  --muted: var(--boxel-100);
  --muted-foreground: var(--boxel-500);
  --accent: var(--boxel-200);
  --accent-foreground: var(--boxel-dark);
  --destructive: var(--boxel-destructive);
  --destructive-foreground: var(--boxel-50);

  /* form + focus */
  --border: var(--boxel-border-color);
  --border-strong: var(--boxel-400);
  --input: var(--boxel-400);
  --ring: var(--boxel-highlight);
  --control-height: 2.5rem;

  /* charts */
  --chart-1: var(--boxel-fuschia);
  --chart-2: var(--boxel-purple);
  --chart-3: var(--boxel-lime);
  --chart-4: var(--boxel-blue);
  --chart-5: var(--boxel-green);
  --chart-6: var(--boxel-orange);
  --chart-7: var(--boxel-cyan);

  /* sidebar */
  --sidebar: var(--boxel-light);
  --sidebar-foreground: var(--boxel-dark);
  --sidebar-primary: var(--boxel-dark);
  --sidebar-primary-foreground: var(--boxel-light);
  --sidebar-accent: var(--boxel-200);
  --sidebar-accent-foreground: var(--boxel-dark);
  --sidebar-border: var(--boxel-border-color);
  --sidebar-ring: var(--boxel-highlight);

  /* typography */
  --font-sans:
    'IBM Plex Sans', 'Helvetica Neue', Arial, ui-sans-serif, sans-serif,
    system-ui;
  --font-serif: 'IBM Plex Serif', 'Georgia', Times, serif;
  --font-mono:
    'IBM Plex Mono', 'Menlo', 'Courier New', Courier, ui-monospace, monospace;
  --tracking-normal: 0.01em;

  /* geometry + spacing */
  --radius: 0.625rem;
  --spacing: 0.25rem;

  /* shadow scale */
  --shadow-x: 0;
  --shadow-y: 1px;
  --shadow-blur: 3px;
  --shadow-spread: 0px;
  --shadow-opacity: 0.1;
  --shadow-color: var(--boxel-dark);
  --shadow-2xs: 0 1px 3px 0px hsl(0 0% 0% / 0.05);
  --shadow-xs: 0 1px 3px 0px hsl(0 0% 0% / 0.05);
  --shadow-sm:
    0 1px 3px 0px hsl(0 0% 0% / 0.1), 0 1px 2px -1px hsl(0 0% 0% / 0.1);
  --shadow: 0 1px 3px 0px hsl(0 0% 0% / 0.1), 0 1px 2px -1px hsl(0 0% 0% / 0.1);
  --shadow-md:
    0 1px 3px 0px hsl(0 0% 0% / 0.1), 0 2px 4px -1px hsl(0 0% 0% / 0.1);
  --shadow-lg:
    0 1px 3px 0px hsl(0 0% 0% / 0.1), 0 4px 6px -1px hsl(0 0% 0% / 0.1);
  --shadow-xl:
    0 1px 3px 0px hsl(0 0% 0% / 0.1), 0 8px 10px -1px hsl(0 0% 0% / 0.1);
  --shadow-2xl: 0 1px 3px 0px hsl(0 0% 0% / 0.25);
  --shadow-inset: inset 0 1px 2px hsl(0 0% 0% / 0.1);

  /* status */
  --success: var(--boxel-success);
  --success-foreground: var(--boxel-light);
  --warning: var(--boxel-warning);
  --warning-foreground: var(--boxel-dark);
  --info: var(--boxel-blue);
  --info-foreground: var(--boxel-light);
  --attention: var(--boxel-dark-amber);
  --attention-foreground: var(--boxel-light);
  --overlay: var(--boxel-dark-50);

  /* Hue as ink. `--x`/`--x-foreground` cover ink *on* a hue's fill; `--x-ink` is
     the hue used *as* ink on a neutral surface (a status label, a link, an icon).
     The default pulls each hue toward --foreground so it darkens on light and
     lightens on dark; a theme that sets only `--x` still gets a readable ink.
     Re-declared in the dark block: a var() inside a custom property resolves
     where it is declared, so a dark subtree would otherwise inherit the
     light-resolved color. */
  --primary-ink: color-mix(in oklch, var(--primary) 60%, var(--foreground));
  --secondary-ink: color-mix(in oklch, var(--secondary) 60%, var(--foreground));
  --accent-ink: color-mix(in oklch, var(--accent) 60%, var(--foreground));
  --destructive-ink: color-mix(
    in oklch,
    var(--destructive) 60%,
    var(--foreground)
  );
  --success-ink: color-mix(in oklch, var(--success) 60%, var(--foreground));
  --warning-ink: color-mix(in oklch, var(--warning) 60%, var(--foreground));
  --info-ink: color-mix(in oklch, var(--info) 60%, var(--foreground));
  --attention-ink: color-mix(in oklch, var(--attention) 60%, var(--foreground));

  /* other */
  /* same values the Switch falls back to; declared so a light region nested
     in a dark subtree re-resolves them instead of inheriting the dark thumb */
  --boxel-switch-thumb: var(--background);
  --boxel-switch-thumb-icon: var(--foreground);
  --boxel-button-default-border: var(--boxel-button-border-color);
  --boxel-button-default-active-background: var(--background);
  --boxel-button-default-active-foreground: var(--foreground);
  --boxel-button-default-active-border: var(--foreground);
  --boxel-button-primary-active-background: var(--boxel-highlight-hover);
  --boxel-button-secondary-background: transparent;
  /* declared in both scheme blocks: a var() inside a knob resolves where the
     knob is declared, so a light region nested in a dark subtree would
     otherwise inherit the dark-resolved color */
  --boxel-button-secondary-foreground: var(--foreground);
  --boxel-button-secondary-border: var(--boxel-button-border-color);
  --boxel-button-secondary-active-border: var(--foreground);
  --boxel-button-destructive-active-background: var(--boxel-dark-red);
  --boxel-button-link-primary-foreground: var(--boxel-highlight-hover);
  --boxel-button-disabled-opacity: 1;
  --boxel-button-disabled-background: var(--boxel-border-color);
  --boxel-button-disabled-border: 1px solid var(--boxel-border-color);
  --boxel-button-disabled-foreground: var(--boxel-450);
}

/* The default theme's destructive fill is dark enough to read as ink on its
   light surfaces, so its ink is the fill itself. Themed cards keep the mix
   above, since a theme's own fill may be too light to read as text; a theme
   that wants the fill sets its own `--destructive-ink`. */
:root,
[data-theme='light']:not(:where([data-boxel-theme-scope]) *) {
  --destructive-ink: var(--destructive);
}

/* ── Themed-card boundary reset ─────────────────────────────────────────────

  Which values: the component knobs the light or dark block above sets, so
  they can't inherit into a themed card. Keep this list and the scheme-island
  copy below the dark block in step.

  Not listed here, for two different reasons:
  - --success and --warning are already declared with the rest of the contract
    on the scope selector above. Do not re-declare them `initial` here: same
    selector, later in the file, so `initial` would win and blank the token
    inside every themed card.
  - the --theme-* typography knobs are left undeclared on purpose, so a nested
    theme that omits them inherits the ambient typography; one that wants its
    own simply sets them.
*/
:where([data-boxel-theme-scope]) {
  --boxel-switch-thumb: initial;
  --boxel-switch-thumb-icon: initial;
  --boxel-button-default-border: initial;
  --boxel-button-default-active-background: initial;
  --boxel-button-default-active-foreground: initial;
  --boxel-button-default-active-border: initial;
  --boxel-button-primary-active-background: initial;
  --boxel-button-secondary-background: initial;
  --boxel-button-secondary-foreground: initial;
  --boxel-button-secondary-border: initial;
  --boxel-button-secondary-active-border: initial;
  --boxel-button-link-primary-foreground: initial;
  --boxel-button-destructive-active-background: initial;
  --boxel-button-disabled-opacity: initial;
  --boxel-button-disabled-background: initial;
  --boxel-button-disabled-border: initial;
  --boxel-button-disabled-foreground: initial;
}

/* ── Dark mode ──────────────────────────────────────────────────────────────
   Opt-in and explicit: add class `dark` or `data-theme="dark"` to <html>, or to
   any subtree you want themed dark. Force light back on inside a dark subtree
   with `data-theme="light"` (see the light block above).

   OS-driven dark ('system' preference) has no token set of its own: consumers
   (e.g. the host theme service) resolve `prefers-color-scheme` to a concrete
   `data-theme="light"|"dark"` so these two blocks stay the single source of
   truth in both directions. */
.dark,
[data-theme='dark'] {
  --boxel-color-scheme: dark;

  --background: var(--boxel-700);
  --foreground: var(--boxel-light);
  --card: var(--boxel-650);
  --card-foreground: var(--boxel-light);
  --popover: #4f4b57;
  --popover-foreground: var(--boxel-light);
  --primary: var(--boxel-highlight);
  --primary-foreground: var(--boxel-dark);
  --secondary: #46434e;
  --secondary-foreground: var(--boxel-light);
  --muted: #34313c;
  --muted-foreground: #b6b6be;
  --accent: #797788;
  --accent-foreground: var(--boxel-light);
  --destructive: var(--boxel-destructive);
  --destructive-foreground: var(--boxel-light-100);
  --canvas: #1e1b26;
  --inset: #302d3b;
  --field: var(--boxel-700);
  --hover: var(--boxel-light-10);
  --stripe: var(--boxel-600);
  --selected: color-mix(in oklch, var(--primary) 15%, var(--card));
  --tooltip: var(--boxel-dark-80);
  --tooltip-foreground: var(--boxel-light);
  --subtle-foreground: #8a8895;
  --border: var(--boxel-550);
  --border-strong: #6e6c78;
  --input: var(--boxel-550);
  --ring: var(--boxel-highlight);
  --overlay: var(--boxel-dark-80);
  --primary-ink: color-mix(in oklch, var(--primary) 60%, var(--foreground));
  --secondary-ink: color-mix(in oklch, var(--secondary) 60%, var(--foreground));
  --accent-ink: color-mix(in oklch, var(--accent) 60%, var(--foreground));
  /* destructive, success, info and attention mix in more --foreground to read
     on the dark surfaces */
  --destructive-ink: color-mix(
    in oklch,
    var(--destructive) 30%,
    var(--foreground)
  );
  --success-ink: color-mix(in oklch, var(--success) 40%, var(--foreground));
  --warning-ink: color-mix(in oklch, var(--warning) 60%, var(--foreground));
  --info-ink: color-mix(in oklch, var(--info) 40%, var(--foreground));
  --attention-ink: color-mix(in oklch, var(--attention) 40%, var(--foreground));
  --sidebar: #555366;
  --sidebar-foreground: var(--boxel-light);
  --sidebar-primary: var(--boxel-highlight);
  --sidebar-primary-foreground: var(--boxel-dark);
  --sidebar-accent: #797788;
  --sidebar-accent-foreground: var(--boxel-light);
  --sidebar-border: var(--boxel-550);
  --sidebar-ring: var(--boxel-highlight);
  --boxel-switch-thumb: var(--boxel-light);
  --boxel-switch-thumb-icon: var(--background);
  --boxel-button-default-border: var(--border);
  --boxel-button-default-active-background: var(--background);
  --boxel-button-default-active-foreground: var(--foreground);
  --boxel-button-default-active-border: var(--foreground);
  --boxel-button-primary-active-background: var(--boxel-highlight-hover);
  --boxel-button-secondary-background: transparent;
  --boxel-button-secondary-foreground: var(--foreground);
  --boxel-button-secondary-border: var(--border);
  --boxel-button-secondary-active-border: var(--foreground);
  --boxel-button-destructive-active-background: var(--boxel-dark-red);
  --boxel-button-disabled-opacity: 1;
  --boxel-button-disabled-background: #444051;
  --boxel-button-disabled-foreground: #817c93;
  --boxel-button-disabled-border: 1px solid#444051;
}

/* Scheme islands inside a themed card: a `.dark` / `[data-theme]` stamped
   below the card's scope element matches the light or dark block again and
   brings the chrome knobs back with it, so a button inside the island would
   hover to Boxel's colors while the rest of the card hovers to the theme's.
   Repeat the boundary reset there. Two attribute selectors outrank the
   single-selector scheme blocks, and this comes after both of them. The
   theme's own palette reaches the island via theme-scoped-css.ts. */
[data-boxel-theme-scope] :is(.dark, [data-theme]) {
  --boxel-switch-thumb: initial;
  --boxel-switch-thumb-icon: initial;
  --boxel-button-default-border: initial;
  --boxel-button-default-active-background: initial;
  --boxel-button-default-active-foreground: initial;
  --boxel-button-default-active-border: initial;
  --boxel-button-primary-active-background: initial;
  --boxel-button-secondary-background: initial;
  --boxel-button-secondary-foreground: initial;
  --boxel-button-secondary-border: initial;
  --boxel-button-secondary-active-border: initial;
  --boxel-button-link-primary-foreground: initial;
  --boxel-button-destructive-active-background: initial;
  --boxel-button-disabled-opacity: initial;
  --boxel-button-disabled-background: initial;
  --boxel-button-disabled-border: initial;
  --boxel-button-disabled-foreground: initial;
}

/* Dark defaults at themed-card boundaries. The light block re-declares the
   whole contract on `:where([data-boxel-theme-scope])`, so without this a
   themed card in a dark subtree would reset every token its theme omits to the
   light default. Keyed off the inherited scheme signal, the same way a card's
   own `.dark` variables are applied (see theme-scoped-css.ts), so it follows
   the nearest light/dark switch rather than any `[data-theme]` ancestor.
   `:where()` keeps it at zero specificity so the card's scoped stylesheet
   still wins. Declares the dark block's contract tokens, minus
   --boxel-color-scheme (which has to keep inheriting) and minus the
   --boxel-switch/button chrome knobs, which the boundary reset above
   sets to `initial` so themed cards derive them from their own tokens in both
   schemes — a test enforces both. */
@container style(--boxel-color-scheme: dark) {
  :where([data-boxel-theme-scope]) {
    --background: var(--boxel-700);
    --foreground: var(--boxel-light);
    --card: var(--boxel-650);
    --card-foreground: var(--boxel-light);
    --popover: #4f4b57;
    --popover-foreground: var(--boxel-light);
    --primary: var(--boxel-highlight);
    --primary-foreground: var(--boxel-dark);
    --secondary: #46434e;
    --secondary-foreground: var(--boxel-light);
    --muted: #34313c;
    --muted-foreground: #b6b6be;
    --accent: #797788;
    --accent-foreground: var(--boxel-light);
    --destructive: var(--boxel-destructive);
    --destructive-foreground: var(--boxel-light-100);
    --canvas: #1e1b26;
    --inset: #302d3b;
    --field: var(--boxel-700);
    --hover: var(--boxel-light-10);
    --stripe: var(--boxel-600);
    --selected: color-mix(in oklch, var(--primary) 15%, var(--card));
    --tooltip: var(--boxel-dark-80);
    --tooltip-foreground: var(--boxel-light);
    --subtle-foreground: #8a8895;
    --border: var(--boxel-550);
    --border-strong: #6e6c78;
    --input: var(--boxel-550);
    --ring: var(--boxel-highlight);
    --overlay: var(--boxel-dark-80);
    --primary-ink: color-mix(in oklch, var(--primary) 60%, var(--foreground));
    --secondary-ink: color-mix(
      in oklch,
      var(--secondary) 60%,
      var(--foreground)
    );
    --accent-ink: color-mix(in oklch, var(--accent) 60%, var(--foreground));
    --destructive-ink: color-mix(
      in oklch,
      var(--destructive) 30%,
      var(--foreground)
    );
    --success-ink: color-mix(in oklch, var(--success) 40%, var(--foreground));
    --warning-ink: color-mix(in oklch, var(--warning) 60%, var(--foreground));
    --info-ink: color-mix(in oklch, var(--info) 40%, var(--foreground));
    --attention-ink: color-mix(
      in oklch,
      var(--attention) 40%,
      var(--foreground)
    );
    --sidebar: #555366;
    --sidebar-foreground: var(--boxel-light);
    --sidebar-primary: var(--boxel-highlight);
    --sidebar-primary-foreground: var(--boxel-dark);
    --sidebar-accent: #797788;
    --sidebar-accent-foreground: var(--boxel-light);
    --sidebar-border: var(--boxel-550);
    --sidebar-ring: var(--boxel-highlight);
  }
}
