/* Generated from packages/ui/src/ds by bundle.mjs. Edit the sources. */
/*
 * 56Atlas design system · entry point
 * Load this one file. The layer order is declared first so later files cannot
 * reorder it: tokens < base < components < patterns < utilities.
 *
 * Unlayered CSS beats every layer, so app stylesheets stay layered too.
 */
@layer ds.tokens, ds.base, ds.components, ds.patterns, ds.utilities;
/*
 * 56Atlas design system · tokens
 *
 * Three tiers, each consuming only the tier above it:
 *   1. Primitives  (--ds-p-*)  raw palette and scales. Never used outside this file.
 *   2. Semantic    (--ds-*)    meaning: surface, text, border, action, status, space, type.
 *   3. Component   (--ds-<component>-*) declared beside each component in components.css.
 *
 * Feature and page CSS uses semantic tokens only. If a screen needs a value that
 * is not here, add a semantic token rather than a literal.
 */
@layer ds.tokens {
  :root {
    /* 1 · Primitives ------------------------------------------------------ */
    --ds-p-white: #ffffff;
    --ds-p-paper-50: #f6f6f3;
    --ds-p-paper-100: #eeeee9;
    --ds-p-paper-200: #e1e2db;
    --ds-p-paper-300: #cdcec5;
    --ds-p-paper-500: #858880;

    --ds-p-ink-950: #0d1828;
    --ds-p-ink-900: #15233a;
    --ds-p-ink-800: #23324b;
    --ds-p-ink-700: #364660;
    --ds-p-ink-600: #4f5e77;
    --ds-p-ink-300: #b4bfcf;
    --ds-p-ink-200: #d3dae5;

    --ds-p-cobalt-50: #eef2fe;
    --ds-p-cobalt-100: #dce4fc;
    --ds-p-cobalt-300: #9fb3f3;
    --ds-p-cobalt-500: #3358d4;
    --ds-p-cobalt-600: #2747bb;
    --ds-p-cobalt-700: #1f3a99;

    --ds-p-green-50: #e9f4ee;
    --ds-p-green-200: #b9dcc8;
    --ds-p-green-700: #1d6a4c;
    --ds-p-amber-50: #fcf3e2;
    --ds-p-amber-200: #efd39c;
    --ds-p-amber-700: #85570f;
    --ds-p-red-50: #fcefeb;
    --ds-p-red-200: #f0c2b6;
    --ds-p-red-700: #a43a28;
    --ds-p-red-800: #842b1c;

    /* 2 · Semantic: color ------------------------------------------------- */
    color-scheme: light;
    --ds-color-bg: var(--ds-p-paper-50);
    --ds-color-surface: var(--ds-p-white);
    --ds-color-surface-sunken: var(--ds-p-paper-100);
    --ds-color-surface-hover: var(--ds-p-paper-100);
    --ds-color-surface-inverse: var(--ds-p-ink-900);
    --ds-color-surface-selected: var(--ds-p-cobalt-50);

    --ds-color-text: var(--ds-p-ink-900);
    --ds-color-text-muted: var(--ds-p-ink-600);
    --ds-color-text-disabled: var(--ds-p-paper-500);
    --ds-color-text-inverse: var(--ds-p-white);
    --ds-color-text-inverse-muted: var(--ds-p-ink-300);

    --ds-color-border: var(--ds-p-paper-200);
    --ds-color-border-strong: var(--ds-p-paper-300);
    --ds-color-border-control: var(--ds-p-paper-500);
    --ds-color-border-inverse: var(--ds-p-ink-700);

    /* The primary action is ink; the accent marks links, focus and selection. */
    --ds-color-action: var(--ds-p-ink-900);
    --ds-color-action-hover: var(--ds-p-ink-700);
    --ds-color-on-action: var(--ds-p-white);
    --ds-color-accent: var(--ds-p-cobalt-600);
    --ds-color-accent-hover: var(--ds-p-cobalt-700);
    --ds-color-accent-soft: var(--ds-p-cobalt-50);
    --ds-color-accent-soft-border: var(--ds-p-cobalt-300);
    --ds-color-focus: var(--ds-p-cobalt-500);
    --ds-color-focus-inverse: var(--ds-p-cobalt-300);

    --ds-color-success: var(--ds-p-green-700);
    --ds-color-success-soft: var(--ds-p-green-50);
    --ds-color-success-border: var(--ds-p-green-200);
    --ds-color-warning: var(--ds-p-amber-700);
    --ds-color-warning-soft: var(--ds-p-amber-50);
    --ds-color-warning-border: var(--ds-p-amber-200);
    --ds-color-danger: var(--ds-p-red-700);
    --ds-color-danger-hover: var(--ds-p-red-800);
    --ds-color-danger-soft: var(--ds-p-red-50);
    --ds-color-danger-border: var(--ds-p-red-200);
    --ds-color-info: var(--ds-p-cobalt-600);
    --ds-color-info-soft: var(--ds-p-cobalt-50);
    --ds-color-info-border: var(--ds-p-cobalt-100);

    --ds-color-backdrop: rgb(13 24 40 / .48);

    /* Fluid sizes use cqi, so they follow the nearest .ds-app container (the
       viewport when the app root is <body>, a panel when it is nested). */

    /* 2 · Semantic: type ---------------------------------------------------
     * Only weights 400 and 600 are shipped. Line-height is left at the font's
     * default for running text (Thai stacked vowels and tone marks need it). */
    --ds-font-sans: "IBM Plex Sans Thai", "IBM Plex Sans", system-ui, sans-serif;
    --ds-font-mono: ui-monospace, "SFMono-Regular", Consolas, monospace;
    --ds-weight-regular: 400;
    --ds-weight-strong: 600;

    --ds-text-xs: .75rem;
    --ds-text-sm: .875rem;
    --ds-text-md: 1rem;
    --ds-text-lg: 1.125rem;
    --ds-text-xl: 1.375rem;
    --ds-text-2xl: 1.75rem;
    --ds-text-3xl: clamp(1.875rem, 1.5rem + 1.2cqi, 2.375rem);
    --ds-text-display: clamp(2.125rem, 1.4rem + 2.8cqi, 3.375rem);

    /* 2 · Semantic: space, size, shape ------------------------------------ */
    --ds-space-0: 0;
    --ds-space-1: .25rem;
    --ds-space-2: .5rem;
    --ds-space-3: .75rem;
    --ds-space-4: 1rem;
    --ds-space-5: 1.25rem;
    --ds-space-6: 1.5rem;
    --ds-space-8: 2rem;
    --ds-space-10: 2.5rem;
    --ds-space-12: 3rem;
    --ds-space-16: 4rem;
    --ds-space-24: 6rem;

    --ds-size-control-sm: 2rem;
    --ds-size-control-md: 2.5rem;
    --ds-size-control-lg: 3rem;
    /* Least hit area for controls that have no size of their own; see the touch rule below. */
    --ds-size-touch-target: 0rem;
    --ds-size-icon: 1.25rem;
    --ds-size-icon-sm: 1rem;

    --ds-radius-sm: .25rem;
    --ds-radius-md: .5rem;
    --ds-radius-lg: .75rem;
    --ds-radius-full: 999px;

    --ds-border-width: 1px;

    --ds-shadow-raised: 0 1px 2px rgb(13 24 40 / .06), 0 1px 1px rgb(13 24 40 / .04);
    --ds-shadow-overlay: 0 .5rem 1.5rem rgb(13 24 40 / .12), 0 1px 3px rgb(13 24 40 / .08);
    --ds-shadow-dialog: 0 1.5rem 4rem rgb(13 24 40 / .24);
    /* Input focus is a contrasting border plus this soft shadow, never a ring. */
    --ds-shadow-focus: 0 .125rem .625rem rgb(51 88 212 / .24);
    --ds-shadow-focus-danger: 0 .125rem .625rem rgb(164 58 40 / .22);

    --ds-duration-fast: 120ms;
    --ds-duration-base: 200ms;
    --ds-ease: cubic-bezier(.2, 0, 0, 1);

    --ds-layout-max: 72rem;
    --ds-layout-narrow: 44rem;
    --ds-layout-gutter: min(clamp(1rem, 4cqi, 2.5rem), 5vw);
    --ds-measure: 40rem;
    --ds-topbar-height: 4rem;

    --ds-z-sticky: 10;
    --ds-z-popover: 50;
    --ds-z-dialog: 100;
  }

  /* Surface context: remaps semantic color for a dark band (landing CTA,
     footer). Components inside need no inverse variants of their own. */
  .ds-theme-inverse {
    --ds-color-bg: var(--ds-p-ink-900);
    --ds-color-surface: var(--ds-p-ink-800);
    --ds-color-surface-sunken: var(--ds-p-ink-950);
    --ds-color-surface-hover: var(--ds-p-ink-700);
    --ds-color-text: var(--ds-p-white);
    --ds-color-text-muted: var(--ds-p-ink-300);
    --ds-color-border: var(--ds-p-ink-700);
    --ds-color-border-strong: var(--ds-p-ink-600);
    --ds-color-border-control: var(--ds-p-ink-600);
    --ds-color-action: var(--ds-p-white);
    --ds-color-action-hover: var(--ds-p-ink-200);
    --ds-color-on-action: var(--ds-p-ink-900);
    --ds-color-accent: var(--ds-p-cobalt-300);
    --ds-color-accent-hover: var(--ds-p-cobalt-100);
    --ds-color-focus: var(--ds-p-cobalt-300);
    background: var(--ds-color-bg);
    color: var(--ds-color-text);
  }

  /* Touch layouts: the 44 px touch policy (docs/design-system.md, D058). The tokens carry it,
     so no component needs its own coarse-pointer rule. Comfortable (48 px) already meets it. */
  @media (pointer: coarse) {
    :root { --ds-size-control-sm: 2.75rem; --ds-size-control-md: 2.75rem; --ds-size-touch-target: 2.75rem; }
  }
  @media (prefers-reduced-motion: reduce) {
    :root { --ds-duration-fast: 0ms; --ds-duration-base: 0ms; }
  }
}

/*
 * 56Atlas design system · base
 * Element defaults only. No classes here except .ds-app, the root a page opts
 * into: a wrapper directly inside <body>, not <body> itself. .ds-app is a size
 * container, and containment would make it the containing block for
 * position: fixed descendants. Overlays appended to <body> stay outside it.
 * Fonts are loaded by each app.
 */
@layer ds.base {
  .ds-app, .ds-app *, .ds-app *::before, .ds-app *::after { box-sizing: border-box; }

  .ds-app {
    /* Patterns respond to the width of this root, so the same markup renders its
       narrow layout inside a narrow frame as well as on a narrow viewport. */
    container: ds / inline-size;
    margin: 0;
    background: var(--ds-color-bg);
    color: var(--ds-color-text);
    font-family: var(--ds-font-sans);
    font-size: var(--ds-text-md);
    font-weight: var(--ds-weight-regular);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
  }

  body:has(> .ds-app) { margin: 0; background: var(--ds-color-bg); }
  /* The page behind an open modal does not scroll. */
  html:has(:is(.ds-dialog, .ds-drawer)[open]) { overflow: hidden; }

  .ds-app :where(h1, h2, h3, h4, h5, h6) {
    margin: 0;
    font-weight: var(--ds-weight-strong);
    text-wrap: balance;
    overflow-wrap: break-word;
  }
  .ds-app :where(p, ul, ol, dl, dd, figure, blockquote) { margin: 0; }
  .ds-app :where(fieldset) { min-width: 0; margin: 0; padding: 0; border: 0; }
  .ds-app :where(p, li, dd) { text-wrap: pretty; overflow-wrap: break-word; }
  .ds-app :where(ul, ol)[role="list"] { padding: 0; list-style: none; }
  .ds-app :where(img, svg, video) { display: block; max-width: 100%; }
  .ds-app :where(button, input, textarea, select) { font: inherit; color: inherit; }
  .ds-app :where(button) { cursor: pointer; }
  .ds-app :where(button:disabled, [aria-disabled="true"]) { cursor: not-allowed; }
  .ds-app :where(a) { color: inherit; text-decoration: none; }
  .ds-app :where(table) { border-collapse: collapse; }
  .ds-app :where(hr) { border: 0; border-top: var(--ds-border-width) solid var(--ds-color-border); margin: 0; }
  .ds-app :where(code, kbd, samp) { font-family: var(--ds-font-mono); font-size: .9em; }
  /* Inline code shrinks to match prose; code inside a block already has the block's size. */
  .ds-app :where(pre) > :where(code) { font-size: inherit; }
  .ds-app ::selection { background: var(--ds-color-accent-soft-border); color: var(--ds-color-text); }

  /* Keyboard focus: a visible outline for actions and links. Text inputs are
     excluded; they show focus with border + soft shadow (see .ds-input). */
  .ds-app :where(a, button, summary, [tabindex], [role="option"], [role="tab"]):focus-visible {
    outline: 2px solid var(--ds-color-focus);
    outline-offset: 2px;
  }
  .ds-app :where(input, textarea, [role="combobox"]):focus-visible { outline: none; }

  .ds-app :where(dialog)::backdrop { background: var(--ds-color-backdrop); }

  @media (prefers-reduced-motion: reduce) {
    .ds-app *, .ds-app *::before, .ds-app *::after { scroll-behavior: auto; }
  }
}

/*
 * 56Atlas design system · components
 *
 * Contract: each component declares its own --ds-<component>-* tokens on its
 * root class and reads only those in its rules. Variants and sizes change those
 * tokens and nothing else, so a screen never needs to override a property.
 * Class names follow block__element--modifier. State is expressed with ARIA or
 * native attributes (aria-pressed, aria-selected, aria-invalid, :disabled).
 */
@layer ds.components {

  /* Button ---------------------------------------------------------------- */
  .ds-button {
    --ds-button-bg: var(--ds-color-surface);
    --ds-button-fg: var(--ds-color-text);
    --ds-button-border: var(--ds-color-border-control);
    --ds-button-bg-hover: var(--ds-color-surface-hover);
    --ds-button-border-hover: var(--ds-color-text);
    --ds-button-height: var(--ds-size-control-md);
    --ds-button-width: auto;
    --ds-button-padding: var(--ds-space-4);
    --ds-button-gutter: var(--ds-button-padding);
    --ds-button-font-size: var(--ds-text-sm);
    --ds-button-icon: var(--ds-size-icon);

    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--ds-space-2);
    width: var(--ds-button-width);
    min-height: var(--ds-button-height);
    padding: 0 var(--ds-button-gutter);
    border: var(--ds-border-width) solid var(--ds-button-border);
    border-radius: var(--ds-radius-md);
    background: var(--ds-button-bg);
    color: var(--ds-button-fg);
    font-size: var(--ds-button-font-size);
    font-weight: var(--ds-weight-strong);
    white-space: nowrap;
    text-decoration: none;
    /* Never wider than its container: a label that does not fit wraps (see
       .ds-button__label) instead of pushing the row past the page edge, e.g. at
       320 px with enlarged text. It keeps its natural width otherwise. */
    flex-shrink: 0;
    max-width: 100%;
    transition: background-color var(--ds-duration-fast) var(--ds-ease),
                border-color var(--ds-duration-fast) var(--ds-ease),
                color var(--ds-duration-fast) var(--ds-ease);
  }
  /* Its display would otherwise beat the hidden attribute. */
  .ds-button[hidden] { display: none; }
  .ds-button svg { flex: none; width: var(--ds-button-icon); height: var(--ds-button-icon); }
  /* One line while it fits. The label keeps the font's line-height (the button
     sets none), so a wrapped Thai label reads as ordinary text; flex centring keeps
     a single line level with the icon. */
  .ds-button__label { min-width: 0; white-space: normal; overflow-wrap: break-word; text-align: center; }
  /* A wrapped label fills the free width; its lines align toward the icon (start after a
     leading icon, end before a trailing one) instead of centring away from it. A single
     line shrinks to fit, so it is unchanged. */
  .ds-button > svg + .ds-button__label { text-align: start; }
  .ds-button > .ds-button__label:has(+ svg):not(svg + .ds-button__label) { text-align: end; }
  .ds-button:where(:hover):where(:not(:disabled, [aria-disabled="true"])) {
    background: var(--ds-button-bg-hover);
    border-color: var(--ds-button-border-hover);
  }
  .ds-button:where(:active):where(:not(:disabled, [aria-disabled="true"])) { transform: translateY(1px); }
  /*
   * Loading keeps the button's size and color; only the content changes, and it
   * cross-fades both ways. The spinner is always in the markup, laid over the
   * slot it replaces, so nothing is inserted or removed and nothing reflows:
   *   leading icon (icon + label) → spinner over the leading icon
   *   trailing icon only          → spinner over the trailing icon
   *   icon-only, label-only       → spinner centred; the icon or label fades out
   * Toggle loading with aria-busy="true" (plus aria-disabled, so focus stays) only.
   */
  .ds-button {
    --ds-button-spinner-size: calc(var(--ds-button-icon) - 4px);
    --ds-button-spinner-offset: calc(var(--ds-button-gutter) + 2px);
    position: relative;
  }
  /* The individual `scale` property is used so it composes with the spinner's rotate animation. */
  .ds-button > svg, .ds-button > .ds-button__label {
    transition: opacity var(--ds-duration-base) var(--ds-ease), scale var(--ds-duration-base) var(--ds-ease);
  }
  .ds-button > .ds-spinner {
    position: absolute;
    inset-block: 0;
    inset-inline-start: var(--ds-button-spinner-offset);
    width: var(--ds-button-spinner-size);
    height: var(--ds-button-spinner-size);
    margin-block: auto;
    opacity: 0;
    visibility: hidden;
    scale: .5;
    animation-play-state: paused;
    transition: opacity var(--ds-duration-base) var(--ds-ease),
                scale var(--ds-duration-base) var(--ds-ease),
                visibility 0s linear var(--ds-duration-base);
  }
  .ds-button:has(> .ds-button__label + svg):not(:has(> svg + .ds-button__label)) > .ds-spinner {
    inset-inline: auto var(--ds-button-spinner-offset);
  }
  .ds-button:is(.ds-button--icon, :not(:has(> svg))) > .ds-spinner { inset-inline: 0; margin-inline: auto; }

  .ds-button[aria-busy="true"] { cursor: progress; }
  .ds-button[aria-busy="true"] > .ds-spinner {
    opacity: 1;
    visibility: visible;
    scale: 1;
    animation-play-state: running;
    transition-delay: 0s;
  }
  .ds-button[aria-busy="true"] > svg:first-of-type { opacity: 0; scale: .5; }
  .ds-button[aria-busy="true"]:not(:has(> svg)) > .ds-button__label { opacity: 0; }

  .ds-button--primary {
    --ds-button-bg: var(--ds-color-action);
    --ds-button-fg: var(--ds-color-on-action);
    --ds-button-border: var(--ds-color-action);
    --ds-button-bg-hover: var(--ds-color-action-hover);
    --ds-button-border-hover: var(--ds-color-action-hover);
  }
  .ds-button--ghost {
    --ds-button-bg: transparent;
    --ds-button-border: transparent;
    --ds-button-border-hover: transparent;
  }
  .ds-button--danger {
    --ds-button-bg: var(--ds-color-danger);
    --ds-button-fg: var(--ds-color-text-inverse);
    --ds-button-border: var(--ds-color-danger);
    --ds-button-bg-hover: var(--ds-color-danger-hover);
    --ds-button-border-hover: var(--ds-color-danger-hover);
  }
  .ds-button--danger-ghost {
    --ds-button-bg: transparent;
    --ds-button-fg: var(--ds-color-danger);
    --ds-button-border: transparent;
    --ds-button-bg-hover: var(--ds-color-danger-soft);
    --ds-button-border-hover: transparent;
  }
  /* After the variants, and with higher specificity, so it wins for every variant.
     A loading button is disabled for input but keeps its variant colors. */
  .ds-button:is(:disabled, [aria-disabled="true"]):not([aria-busy="true"]) {
    --ds-button-bg: var(--ds-color-surface-sunken);
    --ds-button-fg: var(--ds-color-text-disabled);
    --ds-button-border: var(--ds-color-border);
  }
  .ds-button--sm { --ds-button-height: var(--ds-size-control-sm); --ds-button-padding: var(--ds-space-3); --ds-button-icon: var(--ds-size-icon-sm); }
  .ds-button--lg { --ds-button-height: var(--ds-size-control-lg); --ds-button-padding: var(--ds-space-6); --ds-button-font-size: var(--ds-text-md); }
  .ds-button--icon { --ds-button-padding: 0; --ds-button-width: var(--ds-button-height); }
  .ds-button--block { --ds-button-width: 100%; }
  /* Only enlarged text reaches this width (320 px is 20rem at normal size). The padding
     grows with the text but the button cannot, so it would leave less room than one word
     needs and the word would overflow to one side of the label. */
  @container ds (max-width: 16rem) {
    .ds-button { --ds-button-gutter: min(var(--ds-button-padding), var(--ds-space-2)); }
  }

  /* Link ------------------------------------------------------------------ */
  .ds-link {
    color: var(--ds-color-accent);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: .2em;
  }
  .ds-link:hover { color: var(--ds-color-accent-hover); text-decoration-thickness: 2px; }
  /* A trailing icon (e.g. external) sits on the text line at text size. */
  .ds-link > svg { display: inline; width: 1em; height: 1em; margin-inline-start: .25em; vertical-align: -.125em; }
  .ds-link--quiet { color: inherit; text-decoration-color: var(--ds-color-border-strong); }
  /* In a navigation list a link stands alone, so it is a touch target rather than running text. */
  nav .ds-link { display: inline-flex; align-items: center; min-height: var(--ds-size-touch-target); }

  /* Field: label, control, hint, error ------------------------------------ */
  .ds-field { display: grid; gap: var(--ds-space-2); min-width: 0; }
  /* A group of related controls under one name, e.g. a set of checkboxes. */
  .ds-fieldset { display: grid; gap: var(--ds-space-2); }
  .ds-fieldset > legend { padding: 0; margin-bottom: var(--ds-space-2); font-size: var(--ds-text-sm); font-weight: var(--ds-weight-strong); }
  .ds-fieldset__options { display: flex; flex-wrap: wrap; gap: var(--ds-space-2) var(--ds-space-4); }
  .ds-field__label { font-size: var(--ds-text-sm); font-weight: var(--ds-weight-strong); }
  .ds-field__optional { font-weight: var(--ds-weight-regular); color: var(--ds-color-text-muted); }
  .ds-field__hint { font-size: var(--ds-text-sm); color: var(--ds-color-text-muted); }
  .ds-field__error { display: flex; gap: var(--ds-space-1); font-size: var(--ds-text-sm); color: var(--ds-color-danger); }

  /* Input and textarea. Focus = contrasting border + soft shadow, no ring. -- */
  .ds-input {
    --ds-input-border: var(--ds-color-border-control);
    --ds-input-shadow: none;
    width: 100%;
    min-height: var(--ds-size-control-md);
    /* No block padding: like the select trigger and buttons, a single-line input is
       exactly the control height, whatever the font's line box (Thai runs tall). */
    padding: 0 var(--ds-space-3);
    border: var(--ds-border-width) solid var(--ds-input-border);
    border-radius: var(--ds-radius-md);
    background: var(--ds-color-surface);
    color: var(--ds-color-text);
    font-size: var(--ds-text-md);
    box-shadow: var(--ds-input-shadow);
    transition: border-color var(--ds-duration-fast) var(--ds-ease), box-shadow var(--ds-duration-fast) var(--ds-ease);
  }
  .ds-input::placeholder { color: var(--ds-color-text-muted); opacity: 1; }
  .ds-input:hover { --ds-input-border: var(--ds-color-text-muted); }
  .ds-input:focus { --ds-input-border: var(--ds-color-focus); --ds-input-shadow: var(--ds-shadow-focus); outline: none; }
  .ds-input[aria-invalid="true"] { --ds-input-border: var(--ds-color-danger); }
  .ds-input[aria-invalid="true"]:focus { --ds-input-shadow: var(--ds-shadow-focus-danger); }
  .ds-input:disabled { --ds-input-border: var(--ds-color-border); background: var(--ds-color-surface-sunken); color: var(--ds-color-text-disabled); }
  /* No native resize grip: the textarea grows with its content up to a limit,
     then scrolls. Browsers without field-sizing keep the minimum height and scroll. */
  textarea.ds-input { padding-block: var(--ds-space-2); min-height: 6rem; max-height: 16rem; resize: none; field-sizing: content; }

  /* Whole-number stepper: square buttons flank a short centred field. The
     native spin buttons are hidden because the flanking buttons replace them. */
  .ds-stepper { display: inline-flex; align-items: center; gap: var(--ds-space-2); }
  .ds-stepper__input { width: 4.5rem; text-align: center; font-variant-numeric: tabular-nums; appearance: textfield; -moz-appearance: textfield; }
  .ds-stepper__input::-webkit-outer-spin-button, .ds-stepper__input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

  .ds-input-group { position: relative; display: block; }
  .ds-input-group > svg {
    position: absolute;
    inset-block: 0;
    inset-inline-start: var(--ds-space-3);
    width: var(--ds-size-icon);
    height: 100%;
    color: var(--ds-color-text-muted);
    pointer-events: none;
  }
  .ds-input-group > .ds-input { padding-inline-start: calc(var(--ds-space-3) + var(--ds-size-icon) + var(--ds-space-2)); }

  /* Checkbox and radio ---------------------------------------------------- */
  .ds-check {
    --ds-check-size: 1.125rem;
    display: inline-flex;
    align-items: center;
    gap: var(--ds-space-2);
    font-size: var(--ds-text-md);
    cursor: pointer;
  }
  .ds-check input {
    appearance: none;
    flex: none;
    display: grid;
    place-content: center;
    width: var(--ds-check-size);
    height: var(--ds-check-size);
    margin: 0;
    border: var(--ds-border-width) solid var(--ds-color-border-control);
    border-radius: var(--ds-radius-sm);
    background: var(--ds-color-surface);
    cursor: inherit;
    transition: background-color var(--ds-duration-fast) var(--ds-ease), border-color var(--ds-duration-fast) var(--ds-ease);
  }
  .ds-check input[type="radio"] { border-radius: var(--ds-radius-full); }
  .ds-check input::before { content: ""; opacity: 0; }
  .ds-check input[type="checkbox"]::before {
    width: .625rem;
    height: .3125rem;
    border-inline-start: 2px solid var(--ds-color-on-action);
    border-block-end: 2px solid var(--ds-color-on-action);
    transform: translateY(-1px) rotate(-45deg);
  }
  .ds-check input[type="radio"]::before {
    width: .5rem;
    height: .5rem;
    border-radius: var(--ds-radius-full);
    background: var(--ds-color-on-action);
  }
  .ds-check input:checked { border-color: var(--ds-color-action); background: var(--ds-color-action); }
  .ds-check input:checked::before { opacity: 1; }
  .ds-check input:hover:not(:disabled) { border-color: var(--ds-color-text); }
  .ds-check input:focus-visible { outline: 2px solid var(--ds-color-focus); outline-offset: 2px; }
  .ds-check:has(input:disabled) { color: var(--ds-color-text-disabled); cursor: not-allowed; }
  .ds-check input:disabled { border-color: var(--ds-color-border); background: var(--ds-color-surface-sunken); }

  /* Switch (button role="switch") ----------------------------------------- */
  .ds-switch {
    --ds-switch-track: var(--ds-color-border-strong);
    display: inline-flex;
    align-items: center;
    gap: var(--ds-space-3);
    padding: 0;
    border: 0;
    background: none;
    font-size: var(--ds-text-md);
    text-align: start;
  }
  .ds-switch__track {
    position: relative;
    flex: none;
    width: 2.25rem;
    height: 1.25rem;
    border-radius: var(--ds-radius-full);
    background: var(--ds-switch-track);
    transition: background-color var(--ds-duration-base) var(--ds-ease);
  }
  .ds-switch__track::after {
    content: "";
    position: absolute;
    inset-block-start: .125rem;
    inset-inline-start: .125rem;
    width: 1rem;
    height: 1rem;
    border-radius: var(--ds-radius-full);
    background: var(--ds-color-surface);
    box-shadow: var(--ds-shadow-raised);
    transition: transform var(--ds-duration-base) var(--ds-ease);
  }
  .ds-switch[aria-checked="true"] { --ds-switch-track: var(--ds-color-accent); }
  .ds-switch[aria-checked="true"] .ds-switch__track::after { transform: translateX(1rem); }
  .ds-switch:disabled:not([aria-busy="true"]) { --ds-switch-track: var(--ds-color-border); color: var(--ds-color-text-disabled); }
  /* Pending keeps the position and colour; a spinner sits on the thumb. */
  .ds-switch[aria-busy="true"] { cursor: progress; }
  .ds-switch__track > .ds-spinner {
    position: absolute;
    inset-block-start: .25rem;
    inset-inline-start: .25rem;
    z-index: 1;
    width: .75rem;
    height: .75rem;
    border-width: 1.5px;
    color: var(--ds-color-text-muted);
    transition: transform var(--ds-duration-base) var(--ds-ease);
  }
  .ds-switch[aria-checked="true"] .ds-switch__track > .ds-spinner { transform: translateX(1rem); }

  /* File input: the native control is visually hidden, the button shows its focus. */
  .ds-file { display: flex; flex-wrap: wrap; align-items: center; gap: var(--ds-space-2) var(--ds-space-3); min-width: 0; cursor: pointer; }
  .ds-file__input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
  .ds-file__input:focus-visible + .ds-file__button { outline: 2px solid var(--ds-color-focus); outline-offset: 2px; }
  .ds-file:hover .ds-file__button { --ds-button-bg: var(--ds-button-bg-hover); --ds-button-border: var(--ds-button-border-hover); }
  .ds-file__input:disabled + .ds-file__button { --ds-button-bg: var(--ds-color-surface-sunken); --ds-button-fg: var(--ds-color-text-disabled); --ds-button-border: var(--ds-color-border); cursor: not-allowed; }
  .ds-file__name { min-width: 0; color: var(--ds-color-text-muted); font-size: var(--ds-text-sm); overflow-wrap: anywhere; }

  /* Select: custom listbox, never a native popup -------------------------- */
  .ds-select { display: grid; gap: var(--ds-space-2); min-width: 0; }
  .ds-select__control { position: relative; min-width: 0; }
  .ds-select__trigger {
    --ds-select-border: var(--ds-color-border-control);
    --ds-select-shadow: none;
    display: flex;
    align-items: center;
    gap: var(--ds-space-2);
    width: 100%;
    min-height: var(--ds-size-control-md);
    padding: 0 var(--ds-space-3);
    border: var(--ds-border-width) solid var(--ds-select-border);
    border-radius: var(--ds-radius-md);
    background: var(--ds-color-surface);
    box-shadow: var(--ds-select-shadow);
    font-size: var(--ds-text-md);
    text-align: start;
    transition: border-color var(--ds-duration-fast) var(--ds-ease), box-shadow var(--ds-duration-fast) var(--ds-ease);
  }
  .ds-select__trigger:hover { --ds-select-border: var(--ds-color-text-muted); }
  .ds-select__trigger:focus-visible,
  .ds-select__trigger[aria-expanded="true"] { --ds-select-border: var(--ds-color-focus); --ds-select-shadow: var(--ds-shadow-focus); outline: none; }
  .ds-select__trigger[aria-invalid="true"] { --ds-select-border: var(--ds-color-danger); }
  .ds-select__trigger:disabled { --ds-select-border: var(--ds-color-border); background: var(--ds-color-surface-sunken); color: var(--ds-color-text-disabled); }
  .ds-select__trigger > svg { flex: none; width: var(--ds-size-icon); height: var(--ds-size-icon); color: var(--ds-color-text-muted); transition: transform var(--ds-duration-base) var(--ds-ease); }
  .ds-select__trigger[aria-expanded="true"] > .ds-select__chevron { transform: rotate(180deg); }
  .ds-select__value { flex: 1; min-width: 0; overflow-wrap: break-word; }
  .ds-select__placeholder { color: var(--ds-color-text-muted); }
  .ds-select--sm .ds-select__trigger { min-height: var(--ds-size-control-sm); font-size: var(--ds-text-sm); }

  /* A manual popover in the top layer; Select places it beside the trigger. */
  .ds-select__popover {
    position: fixed;
    inset: auto;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    /* As wide as the longest option, never narrower than the trigger, and never
       wider than the page area Select measures (--ds-select-bound-width); past
       that, labels and descriptions wrap, so two long options never read the same. */
    width: max-content;
    min-width: min(max(var(--ds-select-anchor-width, 0px), 16rem), var(--ds-select-bound-width, 100vw));
    max-width: min(28rem, var(--ds-select-bound-width, 100vw));
    max-height: 22rem;
    border: var(--ds-border-width) solid var(--ds-color-border);
    border-radius: var(--ds-radius-md);
    background: var(--ds-color-surface);
    color: var(--ds-color-text);
    box-shadow: var(--ds-shadow-overlay);
    overflow: hidden;
  }
  /* The display above would otherwise override the browser's hidden state for a closed popover. */
  .ds-select__popover:not(:popover-open) { display: none; }
  /* DateTimePicker: the select popover holding a calendar, time and actions. Tall enough
     for all of it at normal text size. With enlarged text or on a short screen the
     calendar and time scroll, and the actions stay in view. */
  .ds-date__popover {
    width: min(20rem, var(--ds-select-bound-width, 100vw));
    min-width: 0;
    max-height: 36rem;
  }
  .ds-date__body {
    display: grid;
    flex: 1 1 auto;
    grid-template-columns: minmax(0, 1fr);
    align-content: start;
    gap: var(--ds-space-3);
    min-height: 0;
    padding: var(--ds-space-3) min(var(--ds-space-3), 2vw);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .ds-date__header { display: flex; align-items: center; justify-content: space-between; gap: var(--ds-space-2); }
  .ds-date__title { flex: 1; min-width: 0; font-weight: var(--ds-weight-strong); text-align: center; overflow-wrap: break-word; }
  /* Only enlarged text reaches this width on a phone: the month takes its own row to stay whole. */
  @container ds (max-width: 18rem) {
    .ds-date__header { flex-wrap: wrap; }
    .ds-date__title { flex-basis: 100%; order: -1; }
  }
  .ds-date__grid { width: 100%; table-layout: fixed; text-align: center; }
  .ds-date__grid th { padding-block: var(--ds-space-1); color: var(--ds-color-text-muted); font-size: var(--ds-text-xs); font-weight: var(--ds-weight-regular); }
  .ds-date__day {
    height: max(2.25rem, var(--ds-size-touch-target));
    border-radius: var(--ds-radius-sm);
    font-size: var(--ds-text-sm);
    font-variant-numeric: tabular-nums;
    cursor: pointer;
  }
  .ds-date__day:hover { background: var(--ds-color-surface-hover); }
  .ds-date__day[data-outside="true"] { color: var(--ds-color-text-muted); }
  .ds-date__day[aria-current="date"] { box-shadow: inset 0 0 0 var(--ds-border-width) var(--ds-color-border-control); }
  .ds-date__day[aria-selected="true"] { background: var(--ds-color-action); color: var(--ds-color-on-action); font-weight: var(--ds-weight-strong); }
  .ds-date__time { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(7rem, 100%), 1fr)); gap: var(--ds-space-3); }
  .ds-date__footer { display: flex; flex: none; flex-wrap: wrap; justify-content: flex-end; gap: var(--ds-space-2); padding: var(--ds-space-2) var(--ds-space-3); border-top: var(--ds-border-width) solid var(--ds-color-border); }
  .ds-select__search {
    display: flex;
    align-items: center;
    gap: var(--ds-space-2);
    padding: var(--ds-space-2) var(--ds-space-3);
    border-bottom: var(--ds-border-width) solid var(--ds-color-border);
    color: var(--ds-color-text-muted);
  }
  .ds-select__search svg { flex: none; width: var(--ds-size-icon); height: var(--ds-size-icon); }
  .ds-select__search input {
    flex: 1;
    min-width: 0;
    min-height: var(--ds-size-control-sm);
    border: 0;
    background: transparent;
    color: var(--ds-color-text);
    font-size: var(--ds-text-md);
    outline: none;
  }
  /* One shrinkable column, so long options truncate instead of widening the list. */
  .ds-select__list { display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: 1px; flex: 1 1 auto; min-height: 0; padding: var(--ds-space-1); overflow-y: auto; outline: none; }
  .ds-select__option {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    column-gap: var(--ds-space-3);
    width: 100%;
    padding: var(--ds-space-2) var(--ds-space-3);
    border: 0;
    border-radius: var(--ds-radius-sm);
    background: transparent;
    color: var(--ds-color-text);
    font-size: var(--ds-text-md);
    text-align: start;
  }
  /* The check spans the description row only when there is one; an implicit empty row would pad the option. */
  .ds-select__option > svg { grid-column: 2; grid-row: 1; width: var(--ds-size-icon); height: var(--ds-size-icon); color: var(--ds-color-accent); visibility: hidden; }
  .ds-select__option > span { min-width: 0; overflow-wrap: break-word; }
  .ds-select__option:has(> .ds-select__option-description) > svg { grid-row: 1 / span 2; }
  .ds-select__option-description { color: var(--ds-color-text-muted); font-size: var(--ds-text-sm); font-weight: var(--ds-weight-regular); overflow-wrap: break-word; }
  .ds-select__option[data-active="true"] { background: var(--ds-color-surface-hover); }
  .ds-select__option[aria-selected="true"] { font-weight: var(--ds-weight-strong); }
  .ds-select__option[aria-selected="true"] > svg { visibility: visible; }
  .ds-select__option:disabled { color: var(--ds-color-text-disabled); cursor: not-allowed; }
  /* MultiSelect: the typed value offered as a new option, and the selection count on the trigger. */
  .ds-select__option--create { color: var(--ds-color-accent); }
  .ds-select__option--create > svg { visibility: visible; }
  .ds-multi-select__count {
    flex: none;
    display: inline-grid;
    place-items: center;
    min-width: 1.5rem;
    height: 1.5rem;
    padding: 0 var(--ds-space-1);
    border-radius: var(--ds-radius-full);
    background: var(--ds-color-surface-sunken);
    color: var(--ds-color-text-muted);
    font-size: var(--ds-text-xs);
    font-variant-numeric: tabular-nums;
    line-height: 1;
  }
  .ds-select__empty { padding: var(--ds-space-4) var(--ds-space-3); color: var(--ds-color-text-muted); font-size: var(--ds-text-sm); }
  .ds-select__footer {
    display: flex;
    justify-content: space-between;
    gap: var(--ds-space-3);
    padding: var(--ds-space-2) var(--ds-space-3);
    border-top: var(--ds-border-width) solid var(--ds-color-border);
    background: var(--ds-color-surface-sunken);
    color: var(--ds-color-text-muted);
    font-size: var(--ds-text-xs);
  }

  /* Badge: non-interactive status label ----------------------------------- */
  .ds-badge {
    --ds-badge-bg: var(--ds-color-surface-sunken);
    --ds-badge-fg: var(--ds-color-text-muted);
    --ds-badge-border: var(--ds-color-border);
    display: inline-flex;
    align-items: center;
    gap: var(--ds-space-1);
    min-height: 1.5rem;
    padding: 0 var(--ds-space-2);
    border: var(--ds-border-width) solid var(--ds-badge-border);
    border-radius: var(--ds-radius-sm);
    background: var(--ds-badge-bg);
    color: var(--ds-badge-fg);
    font-size: var(--ds-text-xs);
    font-weight: var(--ds-weight-strong);
  }
  /* One compact line. A sentence-length badge outside a table (--wrap) wraps instead of
     leaving a narrow container, and keeps the font's line-height to do it. */
  .ds-badge:not(.ds-badge--wrap) { line-height: 1; white-space: nowrap; }
  .ds-badge svg { width: var(--ds-size-icon-sm); height: var(--ds-size-icon-sm); }
  .ds-badge--accent  { --ds-badge-bg: var(--ds-color-accent-soft); --ds-badge-fg: var(--ds-color-accent); --ds-badge-border: var(--ds-color-info-border); }
  .ds-badge--success { --ds-badge-bg: var(--ds-color-success-soft); --ds-badge-fg: var(--ds-color-success); --ds-badge-border: var(--ds-color-success-border); }
  .ds-badge--warning { --ds-badge-bg: var(--ds-color-warning-soft); --ds-badge-fg: var(--ds-color-warning); --ds-badge-border: var(--ds-color-warning-border); }
  .ds-badge--danger  { --ds-badge-bg: var(--ds-color-danger-soft); --ds-badge-fg: var(--ds-color-danger); --ds-badge-border: var(--ds-color-danger-border); }

  /* Chip: a toggle (aria-pressed), e.g. report years. A label stays on one line
     unless it is wider than the container, then it wraps like a button's. --- */
  .ds-chip {
    --ds-chip-bg: var(--ds-color-surface);
    --ds-chip-fg: var(--ds-color-text);
    --ds-chip-border: var(--ds-color-border-control);
    display: inline-flex;
    align-items: center;
    gap: var(--ds-space-1);
    min-height: var(--ds-size-control-sm);
    padding: 0 var(--ds-space-3);
    border: var(--ds-border-width) solid var(--ds-chip-border);
    border-radius: var(--ds-radius-full);
    background: var(--ds-chip-bg);
    color: var(--ds-chip-fg);
    font-size: var(--ds-text-sm);
    font-weight: var(--ds-weight-strong);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    flex-shrink: 0;
    max-width: 100%;
    transition: background-color var(--ds-duration-fast) var(--ds-ease), border-color var(--ds-duration-fast) var(--ds-ease);
  }
  .ds-chip__label { min-width: 0; white-space: normal; }
  .ds-chip > svg + .ds-chip__label { text-align: start; } /* As .ds-button: wrapped lines stay by the leading icon. */
  /* The spinner fills the same slot as the check, so the label never shifts. */
  .ds-chip > :is(svg, .ds-spinner) { width: var(--ds-size-icon-sm); height: var(--ds-size-icon-sm); }
  /* Drawn like an icon from the set: an 18-unit circle with a 1.5-unit stroke in
     the 24-unit box. scale shrinks the ring without touching the layout box
     (and composes with the spin's transform); the border is pre-divided so the
     rendered stroke stays 1px. */
  .ds-chip > .ds-spinner { scale: .75; border-width: calc(1px / .75); }
  .ds-chip[aria-busy="true"] { cursor: progress; }
  .ds-chip:where(:hover):where(:not(:disabled, [aria-disabled="true"])) { --ds-chip-bg: var(--ds-color-surface-hover); }
  .ds-chip[aria-pressed="true"] {
    --ds-chip-bg: var(--ds-color-accent-soft);
    --ds-chip-fg: var(--ds-color-accent-hover);
    --ds-chip-border: var(--ds-color-accent);
  }
  .ds-chip:is(:disabled, [aria-disabled="true"]) {
    --ds-chip-bg: var(--ds-color-surface-sunken);
    --ds-chip-fg: var(--ds-color-text-disabled);
    --ds-chip-border: var(--ds-color-border);
  }

  /* Segmented control: one choice among 2–4 short options ------------------ */
  .ds-segmented {
    display: inline-flex;
    gap: 2px;
    padding: 2px;
    border-radius: var(--ds-radius-md);
    background: var(--ds-color-surface-sunken);
  }
  .ds-segmented > button {
    min-width: var(--ds-size-touch-target);
    min-height: max(calc(var(--ds-size-control-sm) - 4px), var(--ds-size-touch-target));
    padding: 0 var(--ds-space-3);
    border: 0;
    border-radius: calc(var(--ds-radius-md) - 2px);
    background: transparent;
    color: var(--ds-color-text-muted);
    font-size: var(--ds-text-sm);
    font-weight: var(--ds-weight-strong);
    line-height: 1;
    white-space: nowrap;
  }
  .ds-segmented > button:hover { color: var(--ds-color-text); }
  .ds-segmented > button[aria-checked="true"] { background: var(--ds-color-surface); color: var(--ds-color-text); box-shadow: var(--ds-shadow-raised); }
  /* Forced colours drop the raised surface, so the choice keeps the system selection colours. */
  @media (forced-colors: active) {
    .ds-segmented > button[aria-checked="true"] { forced-color-adjust: none; background: SelectedItem; color: SelectedItemText; }
  }

  /* Alert ----------------------------------------------------------------- */
  .ds-alert {
    --ds-alert-bg: var(--ds-color-info-soft);
    --ds-alert-icon: var(--ds-color-info);
    --ds-alert-border: var(--ds-color-info-border);
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: var(--ds-space-1) var(--ds-space-3);
    padding: var(--ds-space-3) var(--ds-space-4);
    border: var(--ds-border-width) solid var(--ds-alert-border);
    border-radius: var(--ds-radius-md);
    background: var(--ds-alert-bg);
    font-size: var(--ds-text-sm);
  }
  /* Icon sits in row 1 only; content stacks in column 2. Spanning rows would add
     empty gap rows (uneven bottom padding) when an alert has only a body. */
  .ds-alert > svg { grid-row: 1; width: var(--ds-size-icon); height: var(--ds-size-icon); color: var(--ds-alert-icon); }
  .ds-alert > :not(svg) { grid-column: 2; }
  .ds-alert__title { font-weight: var(--ds-weight-strong); }
  /* Actions sit at the end, vertically centred beside the title and body. */
  .ds-alert > .ds-alert__actions { grid-column: 3; grid-row: 1 / span 2; align-self: center; display: flex; flex-wrap: wrap; gap: var(--ds-space-2); }
  .ds-alert:not(:has(.ds-alert__title)) > .ds-alert__actions { grid-row: 1; }
  /* Without a title, icon, body and actions share row 1, which the actions make
     taller than a text line; centre the whole row rather than only the actions. */
  .ds-alert:has(> .ds-alert__actions):not(:has(.ds-alert__title)) { align-items: center; }
  /* In a narrow container the actions move under the text. */
  @container ds (max-width: 30rem) {
    .ds-alert > .ds-alert__actions, .ds-alert:not(:has(.ds-alert__title)) > .ds-alert__actions { grid-column: 2; grid-row: auto; margin-top: var(--ds-space-2); }
  }
  /* Room for only about 24 lines of text width, e.g. 320 px, or wider screens with
     enlarged text (rem follows the text size): the icon column would leave a
     word or two per line, so the text and actions use the full width and wrap
     around the icon instead. */
  @container ds (max-width: 24rem) {
    .ds-alert { display: flow-root; }
    .ds-alert > svg { float: inline-start; margin-inline-end: var(--ds-space-2); }
    .ds-alert__title + * { margin-top: var(--ds-space-1); }
    .ds-alert > .ds-alert__actions, .ds-alert:not(:has(.ds-alert__title)) > .ds-alert__actions { clear: both; }
  }
  .ds-alert--success { --ds-alert-bg: var(--ds-color-success-soft); --ds-alert-icon: var(--ds-color-success); --ds-alert-border: var(--ds-color-success-border); }
  .ds-alert--warning { --ds-alert-bg: var(--ds-color-warning-soft); --ds-alert-icon: var(--ds-color-warning); --ds-alert-border: var(--ds-color-warning-border); }
  .ds-alert--danger  { --ds-alert-bg: var(--ds-color-danger-soft); --ds-alert-icon: var(--ds-color-danger); --ds-alert-border: var(--ds-color-danger-border); }

  /* Card: one object set apart from its surroundings ----------------------- */
  .ds-card {
    --ds-card-padding: var(--ds-space-6);
    --ds-card-bg: var(--ds-color-surface);
    --ds-card-border: var(--ds-color-border);
    padding: var(--ds-card-padding);
    border: var(--ds-border-width) solid var(--ds-card-border);
    border-radius: var(--ds-radius-lg);
    background: var(--ds-card-bg);
    min-width: 0;
  }
  .ds-card--compact { --ds-card-padding: var(--ds-space-4); }
  .ds-card--sunken { --ds-card-bg: var(--ds-color-surface-sunken); --ds-card-border: transparent; }
  .ds-card--interactive { display: block; color: inherit; transition: border-color var(--ds-duration-fast) var(--ds-ease), box-shadow var(--ds-duration-fast) var(--ds-ease); }
  .ds-card--interactive:hover { --ds-card-border: var(--ds-color-border-strong); box-shadow: var(--ds-shadow-raised); }

  /* Avatar ---------------------------------------------------------------- */
  .ds-avatar {
    display: grid;
    place-items: center;
    flex: none;
    width: 2rem;
    height: 2rem;
    border-radius: var(--ds-radius-full);
    background: var(--ds-color-accent-soft);
    color: var(--ds-color-accent-hover);
    font-size: var(--ds-text-xs);
    font-weight: var(--ds-weight-strong);
    line-height: 1;
    overflow: hidden;
  }
  .ds-avatar img { width: 100%; height: 100%; object-fit: cover; }

  /* Loading: spinner, progress, skeleton ---------------------------------- */
  /* Inline in text, an empty inline-block's baseline is its bottom edge, which
     lifts it above the line; middle aligns its centre with the text's centre.
     Flex and grid parents (buttons, chips) ignore vertical-align. */
  .ds-spinner {
    display: inline-block;
    flex: none;
    vertical-align: middle;
    width: 1em;
    height: 1em;
    border: 2px solid currentColor;
    border-inline-end-color: transparent;
    border-radius: var(--ds-radius-full);
    animation: ds-spin .7s linear infinite;
  }
  .ds-progress { display: grid; gap: var(--ds-space-2); font-size: var(--ds-text-sm); }
  .ds-progress__track { height: .375rem; border-radius: var(--ds-radius-full); background: var(--ds-color-surface-sunken); overflow: hidden; }
  .ds-progress__bar { height: 100%; width: var(--ds-progress-value, 0%); border-radius: inherit; background: var(--ds-color-accent); transition: width var(--ds-duration-base) var(--ds-ease); }
  .ds-skeleton { display: block; flex: none; height: 1em; border-radius: var(--ds-radius-sm); background: var(--ds-color-surface-sunken); animation: ds-pulse 1.4s var(--ds-ease) infinite; }
  .ds-skeleton--round { border-radius: var(--ds-radius-full); }
  @keyframes ds-spin { to { transform: rotate(360deg); } }
  @keyframes ds-pulse { 50% { opacity: .5; } }
  @media (prefers-reduced-motion: reduce) {
    .ds-spinner { animation-duration: 2s; }
    .ds-skeleton { animation: none; }
  }

  /* Tooltip --------------------------------------------------------------- */
  .ds-tooltip {
    position: absolute;
    z-index: var(--ds-z-popover);
    max-width: 16rem;
    padding: var(--ds-space-2) var(--ds-space-3);
    border-radius: var(--ds-radius-md);
    background: var(--ds-color-surface-inverse);
    color: var(--ds-color-text-inverse);
    font-size: var(--ds-text-sm);
    box-shadow: var(--ds-shadow-overlay);
  }

  /* Tooltip placed by script relative to the viewport. It stays hoverable so
     pointer users can move onto it without it closing (WCAG 1.4.13). */
  .ds-tooltip--floating { position: fixed; }
  .ds-tooltip-anchor { display: inline-flex; }

  /* Dialog (native <dialog>) ---------------------------------------------- */
  .ds-dialog {
    --ds-dialog-width: 32rem;
    --ds-dialog-max-height: calc(100dvh - 2 * var(--ds-space-4));
    /* Side spacing is bounded by the screen, so enlarged text on a phone keeps its width for content. */
    --ds-dialog-inline: min(var(--ds-space-6), 5vw);
    width: min(var(--ds-dialog-width), 100% - 2 * var(--ds-space-4));
    /* One shrinkable column: wide content scrolls or wraps inside the dialog instead of widening it. */
    grid-template-columns: minmax(0, 1fr);
    max-height: var(--ds-dialog-max-height);
    padding: 0;
    border: var(--ds-border-width) solid var(--ds-color-border);
    border-radius: var(--ds-radius-lg);
    background: var(--ds-color-surface);
    color: var(--ds-color-text);
    box-shadow: var(--ds-shadow-dialog);
    overflow: hidden;
  }
  .ds-dialog[open] { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }

  /* Enter and exit motion for modal surfaces. useDialogMotion sets
     data-phase="closing" and waits --ds-duration-base before closing natively. */
  :is(.ds-dialog, .ds-drawer) { transition: opacity var(--ds-duration-base) var(--ds-ease), translate var(--ds-duration-base) var(--ds-ease); }
  :is(.ds-dialog, .ds-drawer)::backdrop { transition: opacity var(--ds-duration-base) var(--ds-ease); }
  .ds-dialog[data-phase="closing"] { opacity: 0; translate: 0 var(--ds-space-2); }
  .ds-drawer[data-phase="closing"] { opacity: 0; translate: -1.5rem 0; }
  :is(.ds-dialog, .ds-drawer)[data-phase="closing"]::backdrop { opacity: 0; }
  @starting-style {
    .ds-dialog[open] { opacity: 0; translate: 0 var(--ds-space-2); }
    .ds-drawer[open] { opacity: 0; translate: -1.5rem 0; }
    :is(.ds-dialog, .ds-drawer)[open]::backdrop { opacity: 0; }
  }
  .ds-dialog--wide { --ds-dialog-width: 48rem; }
  .ds-dialog--full { --ds-dialog-width: 80rem; }
  /* A long list (history, logs) scrolls inside the body instead of filling the screen. */
  .ds-dialog--bounded { --ds-dialog-max-height: min(70dvh, calc(100dvh - 2 * var(--ds-space-4))); }
  .ds-dialog__header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--ds-space-4); padding: var(--ds-space-5) var(--ds-dialog-inline) var(--ds-space-2); }
  .ds-dialog__header > :first-child { min-width: 0; }
  .ds-dialog__title { font-size: var(--ds-text-xl); }
  .ds-dialog__description { margin-top: var(--ds-space-1); color: var(--ds-color-text-muted); font-size: var(--ds-text-sm); }
  .ds-dialog__body { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--ds-space-4); padding: var(--ds-space-2) var(--ds-dialog-inline) var(--ds-space-6); overflow-y: auto; }
  .ds-dialog__footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: var(--ds-space-3);
    padding: var(--ds-space-4) var(--ds-dialog-inline);
    border-top: var(--ds-border-width) solid var(--ds-color-border);
    background: var(--ds-color-surface-sunken);
  }
  /* Constrained screens, phones with enlarged text included. The close control takes its own row above the
     title, so the title keeps the full width instead of breaking word by word beside it. The dialog scrolls
     as one column, because a fixed header and footer would leave no room for the body or push actions out
     of reach, and its actions take the full width. */
  @container ds (max-width: 20rem) {
    .ds-dialog { overflow-y: auto; }
    .ds-dialog[open] { grid-template-rows: none; }
    .ds-dialog__body { overflow-y: visible; }
    .ds-dialog__header { flex-direction: column-reverse; align-items: stretch; gap: var(--ds-space-1); }
    .ds-dialog__header > :last-child { align-self: flex-end; }
    .ds-dialog__footer > * { flex: 1 1 100%; }
  }

  /* Tabs ------------------------------------------------------------------ */
  .ds-tabs { display: flex; gap: var(--ds-space-1); border-bottom: var(--ds-border-width) solid var(--ds-color-border); overflow-x: auto; }
  .ds-tab {
    position: relative;
    padding: var(--ds-space-3);
    border: 0;
    background: none;
    color: var(--ds-color-text-muted);
    font-size: var(--ds-text-sm);
    font-weight: var(--ds-weight-strong);
    line-height: 1;
    white-space: nowrap;
  }
  .ds-tab:hover { color: var(--ds-color-text); }
  .ds-tab[aria-selected="true"] { color: var(--ds-color-text); }
  .ds-tab[aria-selected="true"]::after { content: ""; position: absolute; inset-inline: var(--ds-space-3); inset-block-end: -1px; height: 2px; background: var(--ds-color-action); }

  /* Menu (account menu, row actions) ------------------------------------- */
  .ds-menu {
    display: grid;
    /* Never wider than the screen minus the edge Menu keeps: 13rem doubles with enlarged text. */
    min-width: min(13rem, 100vw - 2 * var(--ds-space-2));
    grid-template-columns: minmax(0, 1fr);
    padding: var(--ds-space-1);
    border: var(--ds-border-width) solid var(--ds-color-border);
    border-radius: var(--ds-radius-md);
    background: var(--ds-color-surface);
    color: var(--ds-color-text);
    box-shadow: var(--ds-shadow-overlay);
  }
  .ds-menu__header { display: grid; gap: var(--ds-space-1); padding: var(--ds-space-2) var(--ds-space-3) var(--ds-space-3); border-bottom: var(--ds-border-width) solid var(--ds-color-border); margin-bottom: var(--ds-space-1); font-size: var(--ds-text-sm); }
  .ds-menu__header small { color: var(--ds-color-text-muted); font-size: var(--ds-text-xs); overflow-wrap: anywhere; }
  .ds-menu__item {
    display: flex;
    align-items: center;
    gap: var(--ds-space-2);
    width: 100%;
    min-height: var(--ds-size-control-md);
    padding: 0 var(--ds-space-3);
    border: 0;
    border-radius: var(--ds-radius-sm);
    background: none;
    color: var(--ds-color-text);
    font-size: var(--ds-text-sm);
    text-align: start;
  }
  .ds-menu__item svg { flex: none; width: var(--ds-size-icon); height: var(--ds-size-icon); color: var(--ds-color-text-muted); }
  .ds-menu__item:is(:hover, :focus-visible) { background: var(--ds-color-surface-hover); }
  a.ds-menu__item { text-decoration: none; }
  /* A form around an item (e.g. logout) adds no box of its own. */
  .ds-menu form { display: contents; }
  /* As a popover (Menu component): placed by script beside its trigger, fading in. */
  .ds-menu[popover] {
    position: fixed;
    inset: auto;
    margin: 0;
    max-width: calc(100vw - 2 * var(--ds-space-2));
    opacity: 0;
    transition: opacity var(--ds-duration-fast) var(--ds-ease), display var(--ds-duration-fast) allow-discrete, overlay var(--ds-duration-fast) allow-discrete;
  }
  /* .ds-menu's display would otherwise override the browser's hidden state for a closed popover. */
  .ds-menu[popover]:not(:popover-open) { display: none; }
  .ds-menu[popover]:popover-open { opacity: 1; }
  @starting-style { .ds-menu[popover]:popover-open { opacity: 0; } }
  .ds-menu__item--danger, .ds-menu__item--danger svg { color: var(--ds-color-danger); }

  /* Empty state ----------------------------------------------------------- */
  .ds-empty { display: grid; justify-items: center; gap: var(--ds-space-2); padding: var(--ds-space-12) var(--ds-space-6); text-align: center; text-wrap: balance; color: var(--ds-color-text-muted); }
  .ds-empty > svg { width: 2rem; height: 2rem; margin-bottom: var(--ds-space-2); }
  .ds-empty__title { color: var(--ds-color-text); font-size: var(--ds-text-lg); font-weight: var(--ds-weight-regular); }
  .ds-empty__actions { margin-top: var(--ds-space-4); }
  .ds-empty--compact { gap: var(--ds-space-1); padding: var(--ds-space-8) var(--ds-space-4); font-size: var(--ds-text-sm); }
  .ds-empty--compact > svg {
    box-sizing: content-box;
    width: var(--ds-size-icon);
    height: var(--ds-size-icon);
    padding: var(--ds-space-3);
    border: var(--ds-border-width) solid var(--ds-color-border);
    border-radius: var(--ds-radius-full);
    background: var(--ds-color-surface);
  }
  .ds-empty--compact .ds-empty__title { font-size: var(--ds-text-sm); font-weight: var(--ds-weight-strong); }

  /* Table ----------------------------------------------------------------- */
  /* Positioned so visually hidden labels in cells scroll with the table instead of widening the page. */
  .ds-table-wrap { position: relative; overflow-x: auto; container: ds-table-scroll / scroll-state; }
  .ds-table { width: 100%; font-size: var(--ds-text-sm); }
  .ds-table th { padding: var(--ds-space-2) var(--ds-space-3); border-bottom: var(--ds-border-width) solid var(--ds-color-border-strong); color: var(--ds-color-text-muted); font-weight: var(--ds-weight-strong); text-align: start; white-space: nowrap; }
  .ds-table td { padding: var(--ds-space-3); border-bottom: var(--ds-border-width) solid var(--ds-color-border); vertical-align: top; }
  .ds-table :is(th, td).ds-num { text-align: end; }
  /* A row header names its row: body text, not a column label. */
  .ds-table tbody th[scope="row"] { min-width: min(12rem, 40vw); padding: var(--ds-space-3); border-bottom-color: var(--ds-color-border); color: var(--ds-color-text); font-weight: var(--ds-weight-regular); white-space: normal; vertical-align: top; }
  /* Enlarged text needs more of the screen for a whole word to fit on a line. */
  @container ds (width < 20rem) {
    .ds-table tbody th[scope="row"] { min-width: min(9rem, 70vw); }
  }
  .ds-table tbody tr:last-child > th[scope="row"] { border-bottom: 0; }
  /* Compact rows whose cells hold controls read better centred than top-aligned. */
  .ds-table--middle :is(td, tbody th[scope="row"]) { vertical-align: middle; }

  .ds-table caption { padding-bottom: var(--ds-space-2); color: var(--ds-color-text-muted); font-size: var(--ds-text-sm); text-align: start; }
  .ds-table tbody tr:last-child > td { border-bottom: 0; }
  /* Rows of a grouped table (tbody per group) open with a full-width heading row. */
  .ds-table th[scope="rowgroup"] { padding-top: var(--ds-space-6); border-bottom-color: var(--ds-color-border); color: var(--ds-color-text); white-space: normal; }
  /* The heading stays in view while a wide group's row scrolls sideways to its action. */
  .ds-table-wrap:has(th[scope="rowgroup"]) { container-type: inline-size scroll-state; }
  .ds-table th[scope="rowgroup"] > * { position: sticky; inset-inline-start: var(--ds-space-3); width: fit-content; max-width: calc(100cqi - 2 * var(--ds-space-3)); }

  /* Tab panel ------------------------------------------------------------- */
  .ds-tab-panel { padding-top: var(--ds-space-4); }

  /* Stats: key figures ---------------------------------------------------- */
  .ds-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(11rem, 100%), 1fr));
    /* Hairline dividers: each tile shades the gap before it, above and to the
       inline start. The first row and column draw under the clipped edge, and a
       short last row leaves plain surface rather than a filled gap. */
    gap: var(--ds-border-width);
    border: var(--ds-border-width) solid var(--ds-color-border);
    border-radius: var(--ds-radius-lg);
    background: var(--ds-color-surface);
    overflow: hidden;
    container: ds-stats / inline-size;
  }
  .ds-stat {
    display: grid;
    align-content: start;
    gap: var(--ds-space-1);
    padding: var(--ds-space-4) var(--ds-space-5);
    min-width: 0;
    box-shadow: calc(-1 * var(--ds-border-width)) 0 0 0 var(--ds-color-border), 0 calc(-1 * var(--ds-border-width)) 0 0 var(--ds-color-border);
  }
  /* One narrow column (a phone, or enlarged text): give figures the width. */
  @container ds-stats (max-width: 24rem) { .ds-stat { padding-inline: var(--ds-space-3); } }
  .ds-stat__label { color: var(--ds-color-text-muted); font-size: var(--ds-text-sm); }
  .ds-stat__value { display: flex; align-items: center; gap: var(--ds-space-2); font-size: var(--ds-text-xl); font-weight: var(--ds-weight-strong); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
  /* A figure with a unit: the number never splits; the unit wraps after it. */
  .ds-stat__value:has(> .ds-stat__unit) { flex-wrap: wrap; }
  .ds-stat__value > .ds-stat__figure { white-space: nowrap; }
  .ds-stat__value > .ds-stat__unit { font-size: var(--ds-text-md); font-weight: var(--ds-weight-regular); }
  .ds-stat__value[data-tone]::after { content: ""; flex: none; width: .5rem; height: .5rem; border-radius: var(--ds-radius-full); background: var(--ds-stat-tone); }
  .ds-stat__value[data-tone="success"] { --ds-stat-tone: var(--ds-color-success); }
  .ds-stat__value[data-tone="warning"] { --ds-stat-tone: var(--ds-color-warning); }
  .ds-stat__value[data-tone="danger"] { --ds-stat-tone: var(--ds-color-danger); }
  .ds-stat__hint { color: var(--ds-color-text-muted); font-size: var(--ds-text-xs); }

  /* Code block: raw output such as JSON or extracted text ------------------ */
  .ds-code-block {
    max-height: 24rem;
    margin: 0;
    padding: var(--ds-space-3) var(--ds-space-4);
    border: var(--ds-border-width) solid transparent; /* an edge in forced colours */
    border-radius: var(--ds-radius-md);
    background: var(--ds-color-surface-sunken);
    font-family: var(--ds-font-mono);
    font-size: var(--ds-text-xs);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    overflow-y: auto;
  }
  /* Source code keeps its lines, so commands and continuations read as written; long lines scroll sideways. */
  .ds-code-block--source { white-space: pre; overflow-wrap: normal; overflow-x: auto; }

  /* Description list ------------------------------------------------------ */
  .ds-dl { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(12rem, 100%), 1fr)); gap: var(--ds-space-3) var(--ds-space-6); }
  .ds-dl__item { display: grid; gap: var(--ds-space-1); min-width: 0; }
  .ds-dl dt { color: var(--ds-color-text-muted); font-size: var(--ds-text-xs); }
  .ds-dl dd { font-size: var(--ds-text-sm); overflow-wrap: anywhere; }

  /* Pagination ------------------------------------------------------------ */
  .ds-pagination { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--ds-space-3); }
  .ds-pagination__status { color: var(--ds-color-text-muted); font-size: var(--ds-text-sm); font-variant-numeric: tabular-nums; }
  .ds-pagination__actions { display: flex; flex-wrap: wrap; gap: var(--ds-space-2); }

  /* Disclosure (details/summary) ------------------------------------------ */
  .ds-disclosure__summary {
    display: inline-flex;
    align-items: center;
    gap: var(--ds-space-2);
    min-height: var(--ds-size-touch-target);
    padding-block: var(--ds-space-1);
    border-radius: var(--ds-radius-sm);
    color: var(--ds-color-text);
    font-size: var(--ds-text-sm);
    font-weight: var(--ds-weight-strong);
    cursor: pointer;
    list-style: none;
  }
  .ds-disclosure__summary::-webkit-details-marker { display: none; }
  .ds-disclosure__summary > svg { flex: none; width: var(--ds-size-icon-sm); height: var(--ds-size-icon-sm); color: var(--ds-color-text-muted); transform: rotate(-90deg); transition: transform var(--ds-duration-base) var(--ds-ease); }
  .ds-disclosure[open] > .ds-disclosure__summary > svg { transform: none; }
  .ds-disclosure__summary:hover { color: var(--ds-color-accent-hover); }
  /* Disclosures hold diagnostic identifiers (model IDs, UUIDs, cron), so the single track may
     shrink below an unbroken token and the token wraps instead of running past the screen. */
  .ds-disclosure__body { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--ds-space-3); padding-top: var(--ds-space-3); padding-inline-start: calc(var(--ds-size-icon-sm) + var(--ds-space-2)); font-size: var(--ds-text-sm); overflow-wrap: anywhere; }

  /* Keyboard key ---------------------------------------------------------- */
  .ds-kbd {
    display: inline-block;
    padding: 0 .375rem;
    border: var(--ds-border-width) solid var(--ds-color-border-strong);
    border-bottom-width: 2px;
    border-radius: var(--ds-radius-sm);
    background: var(--ds-color-surface);
    font-family: var(--ds-font-mono);
    font-size: var(--ds-text-xs);
  }
}

/*
 * 56Atlas design system · layout and text utilities
 * Layout primitives replace per-screen flex/grid rules. Spacing between siblings
 * comes from the parent's gap (--ds-gap), never from margins on children.
 */
@layer ds.utilities {
  .ds-container {
    width: 100%;
    max-width: calc(var(--ds-layout-max) + 2 * var(--ds-layout-gutter));
    margin-inline: auto;
    padding-inline: max(var(--ds-layout-gutter), env(safe-area-inset-left, 0px)) max(var(--ds-layout-gutter), env(safe-area-inset-right, 0px));
  }
  .ds-container--narrow { max-width: calc(var(--ds-layout-narrow) + 2 * var(--ds-layout-gutter)); }

  .ds-stack { display: flex; flex-direction: column; gap: var(--ds-gap, var(--ds-space-4)); min-width: 0; }
  .ds-cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--ds-gap, var(--ds-space-3)); min-width: 0; }
  .ds-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(var(--ds-grid-min, 16rem), 100%), 1fr));
    gap: var(--ds-gap, var(--ds-space-6));
  }
  .ds-spread { justify-content: space-between; }
  .ds-push { margin-inline-start: auto; }
  .ds-grow { flex: 1; min-width: 0; }

  .ds-gap-1 { --ds-gap: var(--ds-space-1); }
  .ds-gap-2 { --ds-gap: var(--ds-space-2); }
  .ds-gap-3 { --ds-gap: var(--ds-space-3); }
  .ds-gap-4 { --ds-gap: var(--ds-space-4); }
  .ds-gap-6 { --ds-gap: var(--ds-space-6); }
  .ds-gap-8 { --ds-gap: var(--ds-space-8); }
  .ds-gap-12 { --ds-gap: var(--ds-space-12); }
  .ds-gap-16 { --ds-gap: var(--ds-space-16); }

  /* Compact icon + label alignment (the only place line-height: 1 belongs). */
  .ds-icon-label { display: inline-flex; align-items: center; gap: var(--ds-space-2); line-height: 1; }
  .ds-icon-label svg { flex: none; width: var(--ds-size-icon); height: var(--ds-size-icon); }

  /* Type roles. Line-height stays at the font default for Thai. */
  .ds-display { font-size: var(--ds-text-display); font-weight: var(--ds-weight-strong); text-wrap: balance; }
  .ds-h1 { font-size: var(--ds-text-3xl); font-weight: var(--ds-weight-strong); text-wrap: balance; }
  .ds-h2 { font-size: var(--ds-text-2xl); font-weight: var(--ds-weight-strong); text-wrap: balance; }
  .ds-h3 { font-size: var(--ds-text-xl); font-weight: var(--ds-weight-strong); }
  .ds-h4 { font-size: var(--ds-text-lg); font-weight: var(--ds-weight-strong); }
  .ds-lead { max-width: var(--ds-measure); color: var(--ds-color-text-muted); font-size: var(--ds-text-lg); }

  .ds-text-xs { font-size: var(--ds-text-xs); }
  .ds-text-sm { font-size: var(--ds-text-sm); }
  .ds-text-md { font-size: var(--ds-text-md); }
  .ds-text-lg { font-size: var(--ds-text-lg); }
  .ds-text-muted { color: var(--ds-color-text-muted); }
  .ds-text-strong { font-weight: var(--ds-weight-strong); }
  .ds-num { font-variant-numeric: tabular-nums; }
  .ds-nowrap { white-space: nowrap; }
  /* Identifiers with no break opportunities (emails, hosts, keys) may break anywhere, so they never widen a table or card. */
  .ds-break-anywhere { overflow-wrap: anywhere; }
  .ds-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  .ds-measure { max-width: var(--ds-measure); }

  /* Long-form answer and article content. */
  .ds-prose { display: grid; gap: var(--ds-space-4); max-width: var(--ds-measure); }
  .ds-prose :where(h2) { font-size: var(--ds-text-xl); margin-top: var(--ds-space-2); }
  .ds-prose :where(h3) { font-size: var(--ds-text-lg); margin-top: var(--ds-space-2); }
  .ds-prose :where(ul, ol) { display: grid; gap: var(--ds-space-2); padding-inline-start: var(--ds-space-6); }
  .ds-prose :where(strong) { font-weight: var(--ds-weight-strong); }
  .ds-prose :where(a) { color: var(--ds-color-accent); text-decoration: underline; text-underline-offset: .2em; }

  .ds-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .ds-skip-link { position: absolute; inset-inline-start: var(--ds-space-4); inset-block-start: var(--ds-space-4); z-index: var(--ds-z-dialog); transform: translateY(-200%); }
  .ds-skip-link:focus { transform: none; }
}

/*
 * 56Atlas design system · patterns
 * Product compositions shared by landing and the research app. Patterns are
 * built from components and tokens; they respond to the width of the nearest
 * .ds-app root (container "ds"), not to the viewport.
 */
@layer ds.patterns {

  /* Brand ----------------------------------------------------------------- */
  .ds-brand {
    display: inline-flex;
    align-items: center;
    gap: var(--ds-space-2);
    min-width: var(--ds-size-touch-target);
    min-height: var(--ds-size-touch-target);
    color: var(--ds-color-text);
    font-size: var(--ds-text-lg);
    font-weight: var(--ds-weight-strong);
    line-height: 1;
    white-space: nowrap;
  }
  .ds-brand img { width: 2rem; height: 2rem; border-radius: var(--ds-radius-sm); }

  /* Top bar: landing navigation and app header ----------------------------- */
  .ds-topbar {
    position: sticky;
    inset-block-start: 0;
    z-index: var(--ds-z-sticky);
    border-bottom: var(--ds-border-width) solid var(--ds-color-border);
    background: var(--ds-color-bg);
  }
  .ds-topbar__inner { display: flex; align-items: center; gap: var(--ds-space-6); min-height: var(--ds-topbar-height); }
  /* The brand pushes navigation and actions to the end, with or without a nav. */
  .ds-topbar__inner > .ds-brand { margin-inline-end: auto; }
  .ds-topbar__nav { display: flex; gap: var(--ds-space-1); }
  .ds-topbar__link {
    display: inline-flex;
    align-items: center;
    min-height: var(--ds-size-touch-target);
    padding: var(--ds-space-2) var(--ds-space-3);
    border-radius: var(--ds-radius-md);
    color: var(--ds-color-text-muted);
    font-size: var(--ds-text-sm);
    line-height: 1;
  }
  .ds-topbar__link:hover, .ds-topbar__link[aria-current="page"] { color: var(--ds-color-text); background: var(--ds-color-surface-hover); }
  .ds-topbar__actions { display: flex; align-items: center; gap: var(--ds-space-2); }
  /* Narrow: navigation moves to its own row and wraps, so every link stays visible. */
  @container ds (max-width: 44rem) {
    /* A wrapped bar would cover much of a small screen, more so with enlarged text, so it scrolls with the page. */
    .ds-topbar { position: static; }
    .ds-topbar__inner { flex-wrap: wrap; gap: var(--ds-space-2) var(--ds-space-4); padding-block: var(--ds-space-2); }
    .ds-topbar__actions { flex-wrap: wrap; min-width: 0; }
    /* The links' padding hangs into the page gutter so their text lines up with the logo, leaving room for the 4px focus ring. */
    .ds-topbar__nav { --ds-topbar-hang: min(var(--ds-space-3), calc(var(--ds-layout-gutter) - 4px)); order: 1; flex-basis: 100%; flex-wrap: wrap; margin-inline: calc(-1 * var(--ds-topbar-hang)); }
    .ds-topbar__link { padding-inline: var(--ds-topbar-hang); white-space: nowrap; }
  }

  /* Page sections ---------------------------------------------------------- */
  .ds-section { padding-block: var(--ds-space-16); }
  .ds-section--sunken { border-block: var(--ds-border-width) solid var(--ds-color-border); background: var(--ds-color-surface-sunken); }
  .ds-section__header { display: grid; gap: var(--ds-space-3); max-width: var(--ds-measure); margin-bottom: var(--ds-space-10); }
  .ds-section__title { font-size: var(--ds-text-3xl); }
  .ds-section__lead { color: var(--ds-color-text-muted); font-size: var(--ds-text-lg); }
  @container ds (max-width: 44rem) {
    .ds-section { padding-block: var(--ds-space-12); }
    .ds-section__header { margin-bottom: var(--ds-space-8); }
  }

  /* Hero ------------------------------------------------------------------- */
  .ds-hero { padding-block: var(--ds-space-16) var(--ds-space-12); }
  .ds-hero__inner {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
    gap: var(--ds-space-12);
    align-items: center;
  }
  .ds-hero__copy { display: grid; gap: var(--ds-space-6); align-content: start; }
  .ds-hero__title { font-size: var(--ds-text-display); }
  .ds-hero__lead { max-width: 34rem; color: var(--ds-color-text-muted); font-size: var(--ds-text-lg); }
  .ds-hero__actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--ds-space-3); }
  .ds-hero__note { color: var(--ds-color-text-muted); font-size: var(--ds-text-sm); }
  .ds-hero__visual { min-width: 0; }
  @container ds (max-width: 60rem) {
    .ds-hero { padding-block: var(--ds-space-10); }
    .ds-hero__inner { grid-template-columns: minmax(0, 1fr); gap: var(--ds-space-10); }
  }

  /* Product preview frame: holds real shared components as a demo ---------- */
  .ds-preview {
    border: var(--ds-border-width) solid var(--ds-color-border);
    border-radius: var(--ds-radius-lg);
    background: var(--ds-color-surface);
    box-shadow: var(--ds-shadow-overlay);
    overflow: hidden;
  }
  .ds-preview__bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--ds-space-3);
    padding: var(--ds-space-2) var(--ds-space-4);
    border-bottom: var(--ds-border-width) solid var(--ds-color-border);
    background: var(--ds-color-surface-sunken);
    color: var(--ds-color-text-muted);
    font-size: var(--ds-text-xs);
  }
  .ds-preview__body { padding: var(--ds-space-6); }
  @container ds (max-width: 44rem) { .ds-preview__body { padding: var(--ds-space-4); } }

  /* Steps: a real ordered sequence, so the number is information ----------- */
  .ds-steps {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(15rem, 100%), 1fr));
    gap: var(--ds-space-8);
    padding: 0;
    list-style: none;
    counter-reset: ds-step;
  }
  .ds-step { display: grid; gap: var(--ds-space-2); align-content: start; padding-top: var(--ds-space-4); border-top: 2px solid var(--ds-color-text); counter-increment: ds-step; }
  .ds-step::before { content: counter(ds-step); color: var(--ds-color-text-muted); font-size: var(--ds-text-sm); font-weight: var(--ds-weight-strong); font-variant-numeric: tabular-nums; }
  .ds-step__title { font-size: var(--ds-text-lg); }
  .ds-step__body { color: var(--ds-color-text-muted); }

  /* Feature: title and explanation, no decorative icon tiles --------------- */
  .ds-feature { display: grid; gap: var(--ds-space-2); align-content: start; }
  .ds-feature__title { font-size: var(--ds-text-lg); }
  .ds-feature__body { color: var(--ds-color-text-muted); }

  /* Comparison table on landing --------------------------------------------- */
  .ds-compare { display: grid; border: var(--ds-border-width) solid var(--ds-color-border); border-radius: var(--ds-radius-lg); background: var(--ds-color-surface); overflow: hidden; }
  .ds-compare__row { display: grid; grid-template-columns: minmax(9rem, .8fr) minmax(0, 1fr) minmax(0, 1fr); }
  .ds-compare__row + .ds-compare__row { border-top: var(--ds-border-width) solid var(--ds-color-border); }
  .ds-compare__row > * { display: grid; gap: var(--ds-space-1); align-content: start; padding: var(--ds-space-4) var(--ds-space-5); min-width: 0; }
  .ds-compare__row > :last-child { background: var(--ds-color-accent-soft); }
  .ds-compare__head { color: var(--ds-color-text-muted); font-size: var(--ds-text-sm); font-weight: var(--ds-weight-strong); }
  .ds-compare__row p { color: var(--ds-color-text-muted); font-size: var(--ds-text-sm); }
  @container ds (max-width: 44rem) {
    .ds-compare__row { grid-template-columns: minmax(0, 1fr); }
    .ds-compare__row--labels { display: none; }
    .ds-compare__row > :first-child { padding-bottom: 0; }
    .ds-compare__row > :last-child { border-top: var(--ds-border-width) solid var(--ds-color-border); }
  }

  /* FAQ (native details) ---------------------------------------------------- */
  .ds-faq { display: grid; border-top: var(--ds-border-width) solid var(--ds-color-border); }
  .ds-faq details { border-bottom: var(--ds-border-width) solid var(--ds-color-border); }
  .ds-faq summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--ds-space-4);
    padding-block: var(--ds-space-4);
    font-weight: var(--ds-weight-strong);
    list-style: none;
    cursor: pointer;
  }
  .ds-faq summary::-webkit-details-marker { display: none; }
  .ds-faq summary svg { flex: none; width: var(--ds-size-icon); height: var(--ds-size-icon); color: var(--ds-color-text-muted); transition: transform var(--ds-duration-base) var(--ds-ease); }
  .ds-faq details[open] summary svg { transform: rotate(180deg); }
  .ds-faq__answer { max-width: var(--ds-measure); padding-bottom: var(--ds-space-5); color: var(--ds-color-text-muted); }

  /* Footer ------------------------------------------------------------------ */
  .ds-footer { padding-block: var(--ds-space-10); border-top: var(--ds-border-width) solid var(--ds-color-border); color: var(--ds-color-text-muted); font-size: var(--ds-text-sm); }
  .ds-footer__inner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--ds-space-4); }

  /* Auth -------------------------------------------------------------------- */
  .ds-auth { --ds-auth-min-height: 100dvh; display: grid; place-items: center; min-height: var(--ds-auth-min-height); padding: var(--ds-space-8) var(--ds-layout-gutter); }
  .ds-auth__card {
    display: grid;
    gap: var(--ds-space-6);
    width: min(26rem, 100%);
    padding: var(--ds-space-8);
    border: var(--ds-border-width) solid var(--ds-color-border);
    border-radius: var(--ds-radius-lg);
    background: var(--ds-color-surface);
    box-shadow: var(--ds-shadow-raised);
  }
  .ds-auth__legal { color: var(--ds-color-text-muted); font-size: var(--ds-text-xs); }
  @container ds (max-width: 30rem) { .ds-auth__card { padding: var(--ds-space-6); } }
  /* Enlarged text at phone width: padding that scales with the text would take half the page. */
  @container ds (max-width: 16rem) { .ds-auth { padding-inline: var(--ds-space-2); } .ds-auth__card { padding: min(var(--ds-space-4), 4vw); } }
}

/*
 * 56Atlas design system · research patterns
 * The research workspace (customer app) and the pieces the landing demo reuses:
 * messages, answers, sources, composer, wallet and credit packs.
 * Layout switches on the width of the nearest .ds-app container.
 */
@layer ds.patterns {

  /* The research page fills the viewport, or a filling shell page holds it; the workspace fills the rest. */
  .ds-chat-page { display: flex; flex-direction: column; height: 100dvh; min-height: 0; overflow: hidden; }
  .ds-chat-page > .ds-chat,
  .ds-shell--fill .ds-shell__page > .ds-chat { flex: 1; min-height: 0; }

  /* Workspace: sidebar + main ------------------------------------------------ */
  /* Fills its parent; the app gives that parent the viewport height. */
  .ds-chat {
    /* Width inside the sidebar's divider. The track adds the divider, so the
       inside stays a whole even number and centred icons land on whole pixels. */
    --ds-chat-sidebar: 17rem;
    display: grid;
    grid-template-columns: calc(var(--ds-chat-sidebar) + var(--ds-border-width)) minmax(0, 1fr);
    height: 100%;
    min-height: 0;
    /* The sidebar track animates between expanded and collapsed widths
       (instant under reduced motion, where the duration token is 0). */
    transition: grid-template-columns var(--ds-duration-base) var(--ds-ease);
  }
  .ds-chat[data-sidebar="collapsed"] { --ds-chat-sidebar: 4.5rem; }
  .ds-chat__sidebar {
    display: flex;
    flex-direction: column;
    gap: var(--ds-space-4);
    min-width: 0;
    min-height: 0;
    /* Insets the footer reads to run edge to edge (see .ds-nav__foot). */
    --ds-nav-inset-inline: var(--ds-space-4);
    --ds-nav-inset-block: var(--ds-space-4);
    padding: var(--ds-nav-inset-block) var(--ds-nav-inset-inline);
    border-inline-end: var(--ds-border-width) solid var(--ds-color-border);
    background: var(--ds-color-bg);
    /* While the column widens, the expanded contents are clipped, not squeezed. */
    overflow-x: clip;
  }
  /* The thread, start form and opening state keep at least 40% of the screen. When enlarged text makes the top bar, header
     and composer taller than the rest, the column scrolls as a whole instead of squeezing the
     content to nothing and clipping the composer below the screen. Positioned, so absolutely
     placed descendants such as screen-reader text stay inside its scroll area. */
  .ds-chat__main { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow-y: auto; background: var(--ds-color-surface); }
  .ds-chat__main > * { flex: none; }
  .ds-chat__main > :is(.ds-chat__scroll, .ds-chat__start, .ds-chat__opening) { position: relative; flex: 1 1 auto; min-height: 40dvh; }
  /* Shown only when the history column is folded into the drawer. */
  .ds-chat__narrow-only { display: none; }
  @container ds (max-width: 56rem) {
    .ds-chat { grid-template-columns: minmax(0, 1fr); }
    .ds-chat > .ds-chat__sidebar { display: none; }
    .ds-chat__narrow-only { display: inline-flex; }
  }

  /* Sidebar contents, shared by the desktop column and the mobile drawer ----- */
  .ds-nav { display: flex; flex-direction: column; gap: var(--ds-space-4); min-height: 0; flex: 1; }
  .ds-nav__head { display: flex; align-items: center; justify-content: space-between; gap: var(--ds-space-2); }
  .ds-nav__history { display: flex; flex-direction: column; gap: var(--ds-space-2); min-height: 0; flex: 1; }
  .ds-nav__history-head { display: flex; align-items: center; justify-content: space-between; gap: var(--ds-space-2); padding-inline: var(--ds-space-3); color: var(--ds-color-text-muted); font-size: var(--ds-text-xs); }
  .ds-nav__list { flex: 1; min-height: 0; overflow-y: auto; margin-inline: calc(-1 * var(--ds-space-1)); padding-inline: var(--ds-space-1); }
  /* Account footer: pinned to the bottom on a white band that spans the column. */
  .ds-nav__foot {
    display: grid;
    gap: var(--ds-space-2);
    margin: auto calc(-1 * var(--ds-nav-inset-inline)) calc(-1 * var(--ds-nav-inset-block));
    padding: var(--ds-space-3) var(--ds-nav-inset-inline);
    border-top: var(--ds-border-width) solid var(--ds-color-border);
    background: var(--ds-color-surface);
  }

  /* Collapsed desktop sidebar: icons only, labels stay as accessible names. */
  .ds-chat[data-sidebar="collapsed"] .ds-chat__sidebar { --ds-nav-inset-inline: var(--ds-space-2); }
  /* Icons centre in the narrow column; the footer band still runs edge to edge. */
  .ds-chat[data-sidebar="collapsed"] .ds-nav { align-items: center; }
  .ds-chat[data-sidebar="collapsed"] .ds-nav__foot { align-self: stretch; }
  .ds-chat[data-sidebar="collapsed"] .ds-nav__head { flex-direction: column; }
  .ds-chat[data-sidebar="collapsed"] :is(.ds-nav__history, .ds-brand__wordmark, .ds-account__name) { display: none; }
  .ds-chat[data-sidebar="collapsed"] .ds-chat__sidebar .ds-button { --ds-button-padding: 0; --ds-button-width: var(--ds-button-height); }
  .ds-chat[data-sidebar="collapsed"] .ds-chat__sidebar .ds-button__label { display: none; }
  .ds-chat[data-sidebar="collapsed"] .ds-account { justify-content: center; }

  /* Mobile drawer: a full-height modal sheet holding the same contents. */
  .ds-drawer {
    width: min(100%, 24rem);
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    --ds-nav-inset-inline: var(--ds-space-4);
    --ds-nav-inset-block: var(--ds-space-4);
    padding: var(--ds-nav-inset-block) var(--ds-nav-inset-inline);
    border: 0;
    border-inline-end: var(--ds-border-width) solid var(--ds-color-border);
    background: var(--ds-color-bg);
    color: var(--ds-color-text);
    box-shadow: var(--ds-shadow-dialog);
  }
  .ds-drawer[open] { display: flex; flex-direction: column; }
  @container ds (max-width: 30rem) { .ds-drawer { width: 100%; } }

  /* Account ------------------------------------------------------------------- */
  .ds-account { display: flex; align-items: center; gap: var(--ds-space-1); min-width: 0; }
  .ds-account__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--ds-text-sm); font-weight: var(--ds-weight-strong); }
  .ds-account__email { color: var(--ds-color-text-muted); }

  /* Chat list ------------------------------------------------------------------ */
  .ds-chat-list { display: grid; gap: 1px; }
  .ds-chat-list__group { padding: var(--ds-space-3) var(--ds-space-3) var(--ds-space-1); color: var(--ds-color-text-muted); font-size: var(--ds-text-xs); }
  .ds-chat-list__item { display: grid; gap: var(--ds-space-1); padding: calc(var(--ds-space-2) - var(--ds-border-width)) calc(var(--ds-space-3) - var(--ds-border-width)); border: var(--ds-border-width) solid transparent; border-radius: var(--ds-radius-md); color: var(--ds-color-text); font-size: var(--ds-text-sm); }
  .ds-chat-list__item:hover { background: var(--ds-color-surface-hover); }
  .ds-chat-list__item[aria-current="page"] { border-color: var(--ds-color-border); background: var(--ds-color-surface); box-shadow: var(--ds-shadow-raised); }
  .ds-chat-list__item[aria-disabled="true"] { pointer-events: none; opacity: .6; }
  .ds-chat-list__title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: var(--ds-weight-strong); }
  .ds-chat-list__meta { display: flex; flex-wrap: wrap; gap: 0 var(--ds-space-2); color: var(--ds-color-text-muted); font-size: var(--ds-text-xs); font-variant-numeric: tabular-nums; }
  .ds-chat-list__pending { color: var(--ds-color-text-muted); font-weight: var(--ds-weight-regular); }

  /* Top bar of the main area: navigation on narrow screens and the wallet. ---- */
  .ds-chat__topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--ds-space-2);
    min-height: 3.5rem;
    padding: var(--ds-space-2) var(--ds-space-6);
    border-bottom: var(--ds-border-width) solid var(--ds-color-border);
  }
  .ds-chat__topbar > .ds-wallet { margin-inline-start: auto; }
  .ds-chat__toolbar-note { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--ds-space-2); min-width: 0; margin-inline-start: auto; color: var(--ds-color-text-muted); font-size: var(--ds-text-sm); }
  .ds-chat__topbar .ds-brand { display: none; }
  @container ds (max-width: 56rem) {
    .ds-chat__topbar { padding-inline: var(--ds-space-3); }
    .ds-chat__topbar .ds-brand { display: inline-flex; }
    .ds-chat__topbar .ds-brand__wordmark { display: none; }
  }
  .ds-chat__notices { display: grid; gap: var(--ds-space-2); padding: var(--ds-space-3) var(--ds-space-6) 0; }
  .ds-chat__notices:empty { display: none; }

  /* Thread header ------------------------------------------------------------- */
  .ds-chat__header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--ds-space-2) var(--ds-space-4);
    padding: var(--ds-space-4) var(--ds-space-6);
    border-bottom: var(--ds-border-width) solid var(--ds-color-border);
  }
  .ds-chat__heading { display: grid; gap: var(--ds-space-1); flex: 1; min-width: min(100%, 16rem); }
  .ds-chat__company { color: var(--ds-color-text-muted); font-size: var(--ds-text-xs); font-weight: var(--ds-weight-strong); }
  .ds-chat__title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--ds-text-lg); }
  /* Each separator sits in the gap before its item. A separator that would start a wrapped
     line falls outside the row, and the row clips it horizontally, so no line begins with "·".
     Items wrap long values inside the row instead of widening it. */
  .ds-chat__meta {
    --ds-chat-meta-gap: calc(2 * var(--ds-space-2) + 1ch);
    display: flex;
    flex-wrap: wrap;
    gap: 0 var(--ds-chat-meta-gap);
    overflow-x: clip;
    color: var(--ds-color-text-muted);
    font-size: var(--ds-text-xs);
    font-variant-numeric: tabular-nums;
  }
  .ds-chat__meta > * { position: relative; min-width: 0; overflow-wrap: anywhere; }
  .ds-chat__meta > * + *::before { content: "·"; position: absolute; inset-inline-end: 100%; inline-size: var(--ds-chat-meta-gap); text-align: center; }
  /* Usage is a row of separator and value, so a skeleton in place of the value stays on the line. */
  .ds-chat__usage { display: inline-flex; align-items: center; }
  .ds-chat__actions { display: flex; gap: var(--ds-space-1); }
  /* Renaming swaps the title for an input in the title's type, one title line tall,
     so the header keeps its height. The rest of the input's look stays the control's own. */
  .ds-chat__rename { display: flex; min-width: 0; }
  .ds-chat__title-input {
    flex: 1;
    min-width: 0;
    min-height: 0;
    block-size: 1lh;
    padding-block: 0;
    padding-inline: var(--ds-space-2);
    font-size: var(--ds-text-lg);
    font-weight: var(--ds-weight-strong);
  }
  @container ds (max-width: 40rem) {
    .ds-chat__header { padding-inline: var(--ds-space-4); }
    .ds-chat__actions .ds-button { --ds-button-padding: 0; --ds-button-width: var(--ds-button-height); }
    .ds-chat__actions .ds-button__label { display: none; }
  }

  /* Conversation -------------------------------------------------------------- */
  /* Positioned so absolutely placed descendants (visually hidden status text) stay
     inside the scroller. Native scroll anchoring is off: useResearchChat keeps the
     reader's place itself and would read a browser adjustment as the reader leaving. */
  .ds-chat__scroll { position: relative; padding: var(--ds-space-8) var(--ds-space-6); overflow-y: auto; overflow-anchor: none; outline: none; }
  .ds-chat__scroll:focus-visible { box-shadow: inset 0 0 0 2px var(--ds-color-focus); }
  /* Messages get a wider measure (780px) than the composer below (46rem). */
  .ds-chat__thread { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--ds-space-10); max-width: 48.75rem; margin-inline: auto; }
  .ds-chat__thread > .ds-button { justify-self: center; }
  /* A message called out for review, e.g. a reported answer. */
  .ds-thread-highlight {
    display: grid;
    gap: var(--ds-space-3);
    justify-items: start;
    padding: var(--ds-space-4);
    border: var(--ds-border-width) solid var(--ds-color-warning-border);
    border-radius: var(--ds-radius-lg);
    border-inline-start: .25rem solid var(--ds-color-warning);
  }
  .ds-thread-highlight > .ds-message { justify-self: stretch; }
  .ds-chat__latest { position: absolute; inset-inline: 0; inset-block-end: calc(100% + var(--ds-space-3)); display: flex; justify-content: center; pointer-events: none; }
  .ds-chat__latest > * { pointer-events: auto; box-shadow: var(--ds-shadow-overlay); }
  .ds-chat__composer { position: relative; display: grid; gap: var(--ds-space-2); padding: var(--ds-space-2) var(--ds-space-6) var(--ds-space-6); }
  .ds-chat__composer > * { width: 100%; max-width: 46rem; margin-inline: auto; }
  @container ds (max-width: 40rem) {
    .ds-chat__notices { padding-inline: var(--ds-space-4); }
    .ds-chat__scroll { padding: var(--ds-space-6) var(--ds-space-4); }
    .ds-chat__composer { padding-inline: var(--ds-space-4); padding-block-end: var(--ds-space-4); }
  }

  /* Start: the first question before a chat exists ---------------------------- */
  .ds-chat__start { display: grid; align-content: center; gap: var(--ds-space-6); width: 100%; max-width: 46rem; margin-inline: auto; padding: var(--ds-space-12) var(--ds-space-6); overflow-y: auto; }
  .ds-chat__start-title { font-size: var(--ds-text-2xl); text-align: center; }
  @container ds (max-width: 40rem) { .ds-chat__start { align-content: start; padding: var(--ds-space-8) var(--ds-space-4); } }
  .ds-chat__opening { display: grid; place-items: center; padding: var(--ds-space-12); color: var(--ds-color-text-muted); }

  /* Scope: company and report years ------------------------------------------- */
  .ds-scope { display: grid; gap: var(--ds-space-4); }
  .ds-scope__years { display: grid; gap: var(--ds-space-2); }
  .ds-scope__note { color: var(--ds-color-text-muted); font-size: var(--ds-text-sm); }

  /* Message: user and assistant both align left; text aligns with the name. --- */
  .ds-message { display: grid; grid-template-columns: 2rem minmax(0, 1fr); gap: var(--ds-space-2) var(--ds-space-3); }
  .ds-message > :is(.ds-avatar, .ds-skeleton--round) { grid-row: 1 / span 2; }
  .ds-message__meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--ds-space-2); min-height: 2rem; font-size: var(--ds-text-sm); }
  .ds-message__name { font-weight: var(--ds-weight-strong); }
  .ds-message__time { color: var(--ds-color-text-muted); font-size: var(--ds-text-xs); font-variant-numeric: tabular-nums; }
  .ds-message__body { display: grid; gap: var(--ds-space-6); min-width: 0; }
  .ds-message__skeleton { gap: var(--ds-space-3); }
  .ds-message__text { white-space: pre-wrap; overflow-wrap: anywhere; }
  /* A failed question edited in place: the text box, then its count and actions on one row. */
  .ds-message__edit { display: grid; gap: var(--ds-space-2); }
  .ds-message__edit-actions { display: flex; align-items: center; gap: var(--ds-space-2); }
  .ds-message__edit-count { flex: 1; color: var(--ds-color-text-muted); font-size: var(--ds-text-xs); font-variant-numeric: tabular-nums; }
  .ds-message__actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--ds-space-2); }
  .ds-message__note { color: var(--ds-color-text-muted); font-size: var(--ds-text-xs); }
  /* Small screens: the body uses the full width instead of aligning with the name.
     The note takes its own line, so the actions start the next one. Ghost actions there
     render as text: with no padding, border or hover fill, the icon lines up with the note,
     and hover underlines the label instead. */
  @container ds (max-width: 40rem) {
    .ds-message > :is(.ds-avatar, .ds-skeleton--round) { grid-row: 1; }
    .ds-message__body { grid-column: 1 / -1; }
    .ds-message__note { flex-basis: 100%; }
    .ds-message__actions > .ds-button--ghost { --ds-button-padding: 0; --ds-button-bg-hover: transparent; border: 0; }
    .ds-message__actions > .ds-button--ghost:hover .ds-button__label { text-decoration: underline; }
  }
  .ds-avatar svg { width: var(--ds-size-icon-sm); height: var(--ds-size-icon-sm); }
  .ds-message--assistant > .ds-avatar { background: var(--ds-color-action); color: var(--ds-color-on-action); }

  /* Answer content -------------------------------------------------------------- */
  .ds-answer { max-width: none; }
  .ds-answer :where(table) { width: 100%; font-size: var(--ds-text-sm); }
  .ds-answer :where(th, td) { padding: var(--ds-space-2) var(--ds-space-3); border-bottom: var(--ds-border-width) solid var(--ds-color-border); text-align: start; vertical-align: top; }
  .ds-answer :where(th) { color: var(--ds-color-text-muted); font-weight: var(--ds-weight-strong); }
  .ds-answer :where(caption) { padding-bottom: var(--ds-space-2); color: var(--ds-color-text-muted); font-size: var(--ds-text-xs); text-align: start; }
  .ds-answer :where(blockquote) { padding-inline-start: var(--ds-space-4); border-inline-start: 2px solid var(--ds-color-border-strong); color: var(--ds-color-text-muted); }
  .ds-answer__table { max-width: 100%; overflow-x: auto; border: var(--ds-border-width) solid var(--ds-color-border); border-radius: var(--ds-radius-md); }
  .ds-answer__table:focus-visible { outline: 2px solid var(--ds-color-focus); outline-offset: 2px; }
  .ds-answer__number { text-align: end; white-space: nowrap; font-variant-numeric: tabular-nums; }

  /* Answer progress: durable named stages ------------------------------------ */
  .ds-answer-progress { display: grid; gap: var(--ds-space-2); }
  .ds-answer-progress ol { --ds-answer-step-gap: var(--ds-space-2); display: grid; gap: var(--ds-answer-step-gap); margin: 0; padding: 0; list-style: none; font-size: var(--ds-text-sm); }
  .ds-answer-progress li { display: flex; align-items: center; gap: var(--ds-space-2); color: var(--ds-color-text-muted); transition: color var(--ds-duration-base) var(--ds-ease); }
  .ds-answer-progress__marker {
    position: relative;
    display: grid;
    place-items: center;
    flex: none;
    width: 1.25rem;
    height: 1.25rem;
    border: var(--ds-border-width) solid var(--ds-color-border-strong);
    border-radius: var(--ds-radius-full);
    font-size: var(--ds-text-xs);
    line-height: 1;
    font-variant-numeric: tabular-nums;
    transition: border-color var(--ds-duration-base) var(--ds-ease), color var(--ds-duration-base) var(--ds-ease);
  }
  /* Connector to the next step; it turns to the done colour when this step finishes. */
  .ds-answer-progress li:not(:last-child) > .ds-answer-progress__marker::after {
    content: "";
    position: absolute;
    inset-block-start: calc(100% + var(--ds-border-width));
    inset-inline-start: 50%;
    width: var(--ds-border-width);
    height: var(--ds-answer-step-gap);
    translate: -50% 0;
    background: var(--ds-color-border-strong);
    transition: background-color var(--ds-duration-base) var(--ds-ease);
  }
  .ds-answer-progress svg { width: var(--ds-size-icon-sm); height: var(--ds-size-icon-sm); }
  .ds-answer-progress [data-state="done"] { color: var(--ds-color-text); }
  .ds-answer-progress [data-state="done"] > .ds-answer-progress__marker { border-color: var(--ds-color-success); color: var(--ds-color-success); }
  .ds-answer-progress [data-state="done"] > .ds-answer-progress__marker::after { background: var(--ds-color-success); }
  .ds-answer-progress [data-state="done"] svg { animation: ds-answer-check var(--ds-duration-base) var(--ds-ease) both; }
  .ds-answer-progress [data-state="active"] { color: var(--ds-color-text); font-weight: var(--ds-weight-strong); }
  .ds-answer-progress [data-state="active"] > .ds-answer-progress__marker { border-color: var(--ds-color-accent-soft-border); color: var(--ds-color-accent); }
  /* Working: an arc runs around the active step's number... */
  .ds-answer-progress [data-state="active"] > .ds-answer-progress__marker::before {
    content: "";
    position: absolute;
    inset: calc(-1 * var(--ds-border-width));
    border: var(--ds-border-width) solid transparent;
    border-block-start-color: var(--ds-color-accent);
    border-radius: inherit;
    animation: ds-spin 1s linear infinite;
  }
  /* ...and a highlight sweeps across its label. */
  .ds-answer-progress [data-state="active"] > .ds-answer-progress__label {
    background: linear-gradient(90deg, var(--ds-color-text) 0 40%, var(--ds-color-text-muted) 50%, var(--ds-color-text) 60% 100%) 0 0 / 250% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: ds-answer-shimmer 2.4s linear infinite;
  }
  @keyframes ds-answer-shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
  @keyframes ds-answer-check { from { opacity: 0; scale: .4; } }
  @media (prefers-reduced-motion: reduce) {
    .ds-answer-progress [data-state="active"] > .ds-answer-progress__marker::before { animation-duration: 2s; }
    .ds-answer-progress [data-state="active"] > .ds-answer-progress__label { animation: none; background: none; color: inherit; }
    .ds-answer-progress [data-state="done"] svg { animation: none; }
  }
  .ds-answer-progress__status { color: var(--ds-color-text-muted); font-size: var(--ds-text-sm); }
  .ds-answer-progress__elapsed { color: var(--ds-color-text-muted); font-size: var(--ds-text-xs); }
  .ds-answer-progress__clock { font-variant-numeric: tabular-nums; }

  /* Sources: aggregated cards after the answer, never inline chips ------------ */
  .ds-sources { interpolate-size: allow-keywords; }
  /* The cards open with a height transition (no transition under reduced motion). */
  .ds-sources::details-content {
    block-size: 0;
    overflow: clip;
    transition: block-size var(--ds-duration-base) var(--ds-ease), content-visibility var(--ds-duration-base) allow-discrete;
  }
  .ds-sources[open]::details-content { block-size: auto; }
  .ds-sources__title {
    display: inline-flex;
    align-items: center;
    gap: var(--ds-space-2);
    min-height: var(--ds-size-touch-target);
    padding-block: var(--ds-space-1);
    color: var(--ds-color-text-muted);
    font-size: var(--ds-text-sm);
    font-weight: var(--ds-weight-strong);
    line-height: 1;
    list-style: none;
    cursor: pointer;
    border-radius: var(--ds-radius-sm);
  }
  .ds-sources__title::-webkit-details-marker { display: none; }
  .ds-sources__title:hover { color: var(--ds-color-text); }
  .ds-sources__title:focus-visible { outline: 2px solid var(--ds-color-focus); outline-offset: 2px; }
  .ds-sources__chevron { transition: rotate var(--ds-duration-base) var(--ds-ease); }
  .ds-sources[open] .ds-sources__chevron { rotate: 180deg; }
  .ds-sources[open] .ds-sources__list { margin-block-start: var(--ds-space-2); }
  .ds-sources__title svg { width: var(--ds-size-icon-sm); height: var(--ds-size-icon-sm); }
  .ds-sources__list { display: flex; flex-wrap: wrap; gap: var(--ds-space-2); margin: 0; padding: 0; list-style: none; }
  .ds-source-card {
    --ds-source-border: var(--ds-color-border);
    display: inline-flex;
    align-items: center;
    gap: var(--ds-space-3);
    min-height: var(--ds-size-touch-target);
    padding: var(--ds-space-2) var(--ds-space-3) var(--ds-space-2) var(--ds-space-2);
    border: var(--ds-border-width) solid var(--ds-source-border);
    border-radius: var(--ds-radius-md);
    background: var(--ds-color-surface);
    color: var(--ds-color-text);
    text-align: start;
    transition: border-color var(--ds-duration-fast) var(--ds-ease), box-shadow var(--ds-duration-fast) var(--ds-ease);
  }
  :is(a, button).ds-source-card:hover { --ds-source-border: var(--ds-color-border-strong); box-shadow: var(--ds-shadow-raised); }
  .ds-source-card > svg { flex: none; width: var(--ds-size-icon-sm); height: var(--ds-size-icon-sm); color: var(--ds-color-text-muted); }
  .ds-source-card__thumb {
    display: grid;
    place-items: center;
    flex: none;
    width: 1.75rem;
    aspect-ratio: 3 / 4;
    border: var(--ds-border-width) solid var(--ds-color-border);
    border-radius: var(--ds-radius-sm);
    background: var(--ds-color-surface-sunken);
    color: var(--ds-color-text-muted);
    overflow: hidden;
  }
  .ds-source-card__thumb img { width: 100%; height: 100%; object-fit: cover; }
  .ds-source-card__thumb svg { width: var(--ds-size-icon-sm); height: var(--ds-size-icon-sm); }
  .ds-source-card__text { display: grid; gap: 2px; min-width: 0; }
  .ds-source-card__title { font-size: var(--ds-text-sm); font-weight: var(--ds-weight-strong); white-space: nowrap; font-variant-numeric: tabular-nums; }
  .ds-source-card__meta { color: var(--ds-color-text-muted); font-size: var(--ds-text-xs); white-space: nowrap; font-variant-numeric: tabular-nums; }
  /* Small screens: a short "2025 / 76" chip with no thumbnail or arrow, so long
     source lists stay short. The year leads, as it groups the pages; the button's
     aria-label keeps the full description in reading order. */
  @container ds (max-width: 40rem) {
    .ds-source-card { padding: var(--ds-space-1) var(--ds-space-3); }
    .ds-source-card__thumb, .ds-source-card > svg, .ds-source-card__long { display: none; }
    .ds-source-card__text { display: flex; align-items: baseline; gap: var(--ds-space-1); }
    .ds-source-card__meta { order: -1; }
    .ds-source-card__meta::after { content: "/" / ""; margin-inline-start: var(--ds-space-1); }
  }

  /* Source page viewer ------------------------------------------------------- */
  .ds-source-viewer__toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--ds-space-2); font-size: var(--ds-text-sm); font-variant-numeric: tabular-nums; }
  .ds-source-viewer__viewport {
    max-height: min(70dvh, 48rem);
    overflow: auto;
    border: var(--ds-border-width) solid var(--ds-color-border);
    border-radius: var(--ds-radius-md);
    background: var(--ds-color-surface-sunken);
  }
  .ds-source-viewer__viewport[data-pannable="true"] { cursor: grab; }
  .ds-source-viewer__viewport[data-dragging="true"] { cursor: grabbing; user-select: none; }
  .ds-source-viewer__viewport img { display: block; max-width: none; margin-inline: auto; }
  .ds-source-viewer__hint { color: var(--ds-color-text-muted); font-size: var(--ds-text-xs); }

  /* Composer -------------------------------------------------------------------- */
  .ds-composer-group { display: grid; gap: var(--ds-space-3); }
  .ds-composer {
    --ds-composer-border: var(--ds-color-border-control);
    --ds-composer-shadow: var(--ds-shadow-raised);
    display: grid;
    gap: var(--ds-space-2);
    padding: var(--ds-space-3);
    border: var(--ds-border-width) solid var(--ds-composer-border);
    border-radius: var(--ds-radius-lg);
    background: var(--ds-color-surface);
    box-shadow: var(--ds-composer-shadow);
    transition: border-color var(--ds-duration-fast) var(--ds-ease), box-shadow var(--ds-duration-fast) var(--ds-ease);
  }
  .ds-composer:focus-within { --ds-composer-border: var(--ds-color-focus); --ds-composer-shadow: var(--ds-shadow-focus); }
  .ds-composer__scope { display: flex; flex-wrap: wrap; align-items: center; gap: var(--ds-space-2); padding-inline: var(--ds-space-1); }
  .ds-composer__input {
    width: 100%;
    min-height: 3rem;
    max-height: 12rem;
    padding: var(--ds-space-1);
    border: 0;
    background: transparent;
    color: var(--ds-color-text);
    font-size: var(--ds-text-md);
    resize: none;
    field-sizing: content;
    outline: none;
  }
  .ds-composer__input::placeholder { color: var(--ds-color-text-muted); }
  .ds-composer__input:disabled { color: var(--ds-color-text-disabled); }
  .ds-composer__footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--ds-space-2); }
  .ds-composer__hint { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--ds-space-1) var(--ds-space-3); color: var(--ds-color-text-muted); font-size: var(--ds-text-xs); font-variant-numeric: tabular-nums; }

  /* Wallet ------------------------------------------------------------------------ */
  /* Actions lead, centred beside the balance and the reserved credits and status below it. */
  .ds-wallet {
    position: relative;
    display: grid;
    grid-template-columns: auto auto;
    grid-template-areas: "actions amount" "actions details";
    justify-content: start;
    align-items: center;
    gap: 0 var(--ds-space-3);
    min-width: 0;
  }
  /* Payment and redeem outcomes hang under the balance they change. */
  .ds-wallet__notices { position: absolute; z-index: var(--ds-z-popover); inset-block-start: calc(100% + var(--ds-space-2)); inset-inline-end: 0; display: grid; gap: var(--ds-space-2); width: min(24rem, 100cqi - 2 * var(--ds-space-3)); }
  .ds-wallet__notices:empty { display: none; }
  /* In a page rather than a top bar there is room for them in the flow. */
  .ds-wallet--inline { grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "actions amount" "actions details" "notices notices"; justify-content: stretch; }
  .ds-wallet--inline > .ds-wallet__notices { position: static; grid-area: notices; width: min(24rem, 100%); margin-block-start: var(--ds-space-3); }
  .ds-wallet--inline > .ds-wallet__notices > .ds-alert { box-shadow: none; }
  .ds-wallet__notices > .ds-alert { box-shadow: var(--ds-shadow-overlay); background-clip: padding-box; }
  .ds-wallet__details { grid-area: details; display: grid; min-width: 0; }
  .ds-wallet__amount { grid-area: amount; display: inline-flex; align-items: center; gap: var(--ds-space-1); font-size: var(--ds-text-md); white-space: nowrap; font-variant-numeric: tabular-nums; }
  .ds-wallet__amount > svg { width: var(--ds-size-icon-sm); height: var(--ds-size-icon-sm); color: var(--ds-color-accent); }
  .ds-wallet__amount strong { font-weight: var(--ds-weight-strong); }
  /* One line beside the balance while it fits; enlarged text wraps it between words rather than past the page edge. */
  .ds-wallet__reserved, .ds-wallet__status { color: var(--ds-color-text-muted); font-size: var(--ds-text-xs); font-variant-numeric: tabular-nums; }
  .ds-wallet__status[role="alert"] { color: var(--ds-color-danger); }
  .ds-wallet__reserved--empty { color: var(--ds-color-warning); }
  .ds-wallet__actions { grid-area: actions; display: flex; align-items: center; gap: var(--ds-space-1); }
  @container ds (max-width: 40rem) {
    .ds-wallet { column-gap: var(--ds-space-2); }
    .ds-wallet__actions .ds-button { --ds-button-padding: 0; --ds-button-width: var(--ds-button-height); }
    .ds-wallet__actions .ds-button__label { display: none; }
  }

  /* Credit history ------------------------------------------------------------- */
  /* One shrinkable column: a row's content wraps inside the dialog instead of widening it. */
  .ds-ledger { display: grid; grid-template-columns: minmax(0, 1fr); margin: 0; padding: 0; list-style: none; }
  /* While the list refreshes it stays in place under a veil, with the status pinned on top. */
  .ds-ledger-frame { position: relative; }
  .ds-ledger-frame > .ds-ledger { transition: opacity var(--ds-duration-base) var(--ds-ease); }
  .ds-ledger-frame[aria-busy="true"] > .ds-ledger { opacity: .45; }
  .ds-ledger-frame__status {
    position: absolute;
    z-index: 1;
    inset-block-start: var(--ds-space-3);
    inset-inline-start: 50%;
    translate: -50% 0;
    display: flex;
    align-items: center;
    gap: var(--ds-space-2);
    margin: 0;
    padding: var(--ds-space-1) var(--ds-space-3);
    border: var(--ds-border-width) solid var(--ds-color-border);
    border-radius: var(--ds-radius-full);
    background: var(--ds-color-surface);
    box-shadow: var(--ds-shadow-raised);
    color: var(--ds-color-text-muted);
    font-size: var(--ds-text-sm);
  }
  /* The amount drops under the description, still at the end, when a row is too narrow for both. */
  .ds-ledger__row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--ds-space-1) var(--ds-space-4); padding-block: var(--ds-space-3); border-bottom: var(--ds-border-width) solid var(--ds-color-border); }
  .ds-ledger__main { display: grid; flex: 1 1 12rem; gap: var(--ds-space-1); min-width: 0; }
  .ds-ledger__kind { font-weight: var(--ds-weight-strong); }
  .ds-ledger__detail { color: var(--ds-color-text-muted); font-size: var(--ds-text-xs); font-variant-numeric: tabular-nums; }
  .ds-ledger__chat { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .ds-ledger__amount { flex: none; margin-inline-start: auto; font-weight: var(--ds-weight-strong); white-space: nowrap; font-variant-numeric: tabular-nums; }
  .ds-ledger__amount[data-sign="positive"] { color: var(--ds-color-success); }

  /* Credit packs ---------------------------------------------------------------- */
  .ds-redeem { display: grid; gap: var(--ds-space-2); padding-bottom: var(--ds-space-4); border-bottom: var(--ds-border-width) solid var(--ds-color-border); }
  /* The button drops below the code field rather than crushing it. */
  .ds-redeem__row { display: flex; flex-wrap: wrap; gap: var(--ds-space-2); }
  .ds-redeem__row > .ds-input { flex: 1 1 12rem; min-width: 0; text-transform: uppercase; }
  .ds-price-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(12rem, 100%), 1fr)); gap: var(--ds-space-3); }
  .ds-price-card {
    --ds-price-border: var(--ds-color-border);
    position: relative;
    display: grid;
    gap: var(--ds-space-2);
    align-content: start;
    padding: var(--ds-space-5);
    border: var(--ds-border-width) solid var(--ds-price-border);
    border-radius: var(--ds-radius-lg);
    background: var(--ds-color-surface);
    color: var(--ds-color-text);
    text-align: start;
    cursor: pointer;
    transition: border-color var(--ds-duration-fast) var(--ds-ease), box-shadow var(--ds-duration-fast) var(--ds-ease);
  }
  .ds-price-card:hover:not(:disabled) { --ds-price-border: var(--ds-color-text-muted); box-shadow: var(--ds-shadow-raised); }
  .ds-price-card:has(input:checked) { --ds-price-border: var(--ds-color-accent); box-shadow: inset 0 0 0 1px var(--ds-color-accent); background: var(--ds-color-accent-soft); }
  .ds-price-card:has(input:focus-visible) { outline: 2px solid var(--ds-color-focus); outline-offset: 2px; }
  .ds-price-card:disabled { cursor: not-allowed; opacity: .6; }
  .ds-price-card[aria-busy="true"] { cursor: progress; opacity: 1; }
  .ds-price-card input { position: absolute; opacity: 0; pointer-events: none; }
  .ds-price-card__head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--ds-space-2); }
  .ds-price-card__name { font-size: var(--ds-text-sm); font-weight: var(--ds-weight-strong); }
  .ds-price-card__credits { font-size: var(--ds-text-2xl); font-weight: var(--ds-weight-strong); font-variant-numeric: tabular-nums; }
  .ds-price-card__credits small { color: var(--ds-color-text-muted); font-size: var(--ds-text-sm); font-weight: var(--ds-weight-regular); }
  .ds-price-card__price { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--ds-space-2); font-size: var(--ds-text-lg); font-weight: var(--ds-weight-strong); font-variant-numeric: tabular-nums; }
  .ds-price-card__was { color: var(--ds-color-text-muted); font-size: var(--ds-text-sm); font-weight: var(--ds-weight-regular); }
  .ds-price-card__note { color: var(--ds-color-text-muted); font-size: var(--ds-text-xs); }
  .ds-price-card__action { display: flex; align-items: center; gap: var(--ds-space-2); margin-top: var(--ds-space-2); color: var(--ds-color-accent); font-size: var(--ds-text-sm); font-weight: var(--ds-weight-strong); line-height: 1; }
  .ds-price-card__action svg { width: var(--ds-size-icon-sm); height: var(--ds-size-icon-sm); }
  /* Small screens: one row per pack. Name, credits and note on the left; discount, then
     price and the struck-out regular price on the right. The head's box steps aside so name
     and badge each take a cell and never share a line. The whole card is the action, so its
     row shows only while checkout opens; otherwise it, and "ราคาปกติ", stay for screen readers. */
  @container ds (max-width: 40rem) {
    .ds-price-grid { gap: var(--ds-space-2); }
    .ds-price-card {
      grid-template-columns: minmax(0, 1fr) auto;
      grid-template-areas: "name badge" "credits price" "note note" "action action";
      gap: var(--ds-space-1) var(--ds-space-3);
      align-items: center;
      padding: var(--ds-space-3) var(--ds-space-4);
    }
    .ds-price-card__head { display: contents; }
    .ds-price-card__name { grid-area: name; }
    .ds-price-card__head > .ds-badge { grid-area: badge; justify-self: end; }
    .ds-price-card__credits { grid-area: credits; font-size: var(--ds-text-lg); }
    .ds-price-card__price { grid-area: price; flex-wrap: nowrap; justify-content: end; }
    .ds-price-card__note { grid-area: note; }
    .ds-price-card__action { grid-area: action; margin-top: 0; }
    .ds-price-card:not([aria-busy="true"]) .ds-price-card__action, .ds-price-card__was-label {
      position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
    }
  }
  /* Very narrow, phones with enlarged text included: one column, so the credits and the price never overlap. */
  @container ds (max-width: 20rem) {
    .ds-price-card { grid-template-columns: minmax(0, 1fr); grid-template-areas: "name" "badge" "credits" "price" "note" "action"; }
    .ds-price-card__head > .ds-badge { justify-self: start; }
    .ds-price-card__price { flex-wrap: wrap; justify-content: start; }
  }
}

/*
 * 56Atlas design system · console patterns
 * Operational screens (Admin): the application shell, page header, breadcrumb
 * and the report processing status. Built from components and tokens only.
 */
@layer ds.patterns {

  .ds-brand__area {
    padding-inline-start: var(--ds-space-2);
    border-inline-start: var(--ds-border-width) solid var(--ds-color-border-strong);
    color: var(--ds-color-text-muted);
    font-size: var(--ds-text-sm);
    font-weight: var(--ds-weight-regular);
  }

  /* Shell: side navigation + page column ------------------------------------ */
  .ds-shell {
    --ds-shell-nav: 15rem;
    display: grid;
    grid-template-columns: var(--ds-shell-nav) minmax(0, 1fr);
    min-height: 100dvh;
  }
  .ds-shell__sidebar {
    position: sticky;
    inset-block-start: 0;
    display: flex;
    flex-direction: column;
    gap: var(--ds-space-8);
    height: 100dvh;
    padding: var(--ds-space-6) var(--ds-space-4);
    overflow-y: auto;
  }
  .ds-shell__head { display: flex; align-items: center; justify-content: space-between; gap: var(--ds-space-2); }
  /* With enlarged text the area name takes its own line instead of running under the close button. */
  .ds-shell__head > .ds-brand { flex-wrap: wrap; min-width: 0; }
  @container ds (width < 20rem) {
    .ds-shell__head > .ds-brand > .ds-brand__area { flex-basis: 100%; padding-inline-start: 0; border-inline-start: 0; }
  }
  .ds-shell__nav { display: grid; gap: var(--ds-space-1); }
  .ds-shell__link {
    display: flex;
    align-items: center;
    gap: var(--ds-space-3);
    min-height: var(--ds-size-control-md);
    padding: 0 var(--ds-space-3);
    border-radius: var(--ds-radius-md);
    color: var(--ds-color-text-muted);
    font-size: var(--ds-text-sm);
    font-weight: var(--ds-weight-strong);
    line-height: 1;
    transition: background-color var(--ds-duration-fast) var(--ds-ease), color var(--ds-duration-fast) var(--ds-ease);
  }
  .ds-shell__link svg { flex: none; width: var(--ds-size-icon); height: var(--ds-size-icon); }
  .ds-shell__link:hover { background: var(--ds-color-surface-hover); color: var(--ds-color-text); }
  .ds-shell__link[aria-current="page"] { background: var(--ds-color-surface); color: var(--ds-color-text); }
  .ds-shell__footer { margin-top: auto; color: var(--ds-color-text-muted); font-size: var(--ds-text-xs); }

  .ds-shell__main {
    /* Patterns in the page respond to the page column, not to the window. */
    container: ds / inline-size;
    display: flex;
    flex-direction: column;
    min-width: 0;
  }
  .ds-shell__topbar {
    position: sticky;
    inset-block-start: 0;
    z-index: var(--ds-z-sticky);
    display: flex;
    align-items: center;
    gap: var(--ds-space-3);
    min-height: 3.5rem;
    padding: var(--ds-space-2) var(--ds-layout-gutter);
    border-bottom: var(--ds-border-width) solid var(--ds-color-border);
    background: var(--ds-color-surface);
  }
  .ds-shell__location { flex: 1; min-width: 0; }
  .ds-shell__actions { display: flex; align-items: center; gap: var(--ds-space-2); }
  /* The menu button sits inside the page column, whose own container width is not
     the app's; the shell decides and passes the answer down. */
  .ds-shell__menu { display: var(--ds-shell-menu, none); }
  /* Only enlarged text reaches this width on a phone. A pinned bar would take too much of the
     screen and could cover whatever a link lands on. */
  @container ds (max-width: 18rem) { .ds-shell__topbar { position: static; } }
  /* Fragment targets clear the sticky top bar. */
  .ds-shell__page [id] { scroll-margin-block-start: calc(3.5rem + var(--ds-space-4)); }
  .ds-shell__page {
    display: flex;
    flex-direction: column;
    gap: var(--ds-space-8);
    width: 100%;
    max-width: calc(var(--ds-layout-max) + 2 * var(--ds-layout-gutter));
    padding: var(--ds-space-8) var(--ds-layout-gutter) var(--ds-space-16);
  }
  /* Fill: the page takes the remaining height and scrolls inside itself. */
  .ds-shell--fill { height: 100dvh; min-height: 0; }
  .ds-shell--fill .ds-shell__main { min-height: 0; overflow: hidden; }
  .ds-shell--fill .ds-shell__page { flex: 1; min-height: 0; max-width: none; padding: 0; gap: 0; }

  .ds-shell__drawer { padding: var(--ds-space-6) var(--ds-space-4); }
  .ds-shell__drawer-body { display: flex; flex-direction: column; gap: var(--ds-space-8); flex: 1; min-height: 0; }

  @container ds (max-width: 56rem) {
    .ds-shell { --ds-shell-menu: inline-flex; grid-template-columns: minmax(0, 1fr); }
    .ds-shell > .ds-shell__sidebar { display: none; }
  }

  /* Toolbar: filters and actions above a list; fields grow, buttons keep their size. */
  .ds-toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--ds-space-3) var(--ds-space-4); }
  .ds-toolbar > .ds-field { flex: 1 1 14rem; }
  .ds-toolbar > .ds-select { flex: 0 1 16rem; }

  /* Bulk actions for the rows checked in a table, shown while any are checked. */
  .ds-bulk-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--ds-space-2) var(--ds-space-3);
    padding: var(--ds-space-3) var(--ds-space-4);
    border: var(--ds-border-width) solid var(--ds-color-border);
    border-radius: var(--ds-radius-md);
    background: var(--ds-color-surface-sunken);
  }
  .ds-bulk-bar > .ds-select { flex: 1 1 14rem; max-width: 22rem; }
  .ds-bulk-bar > :is(.ds-alert, p:last-child:not(:first-child)) { flex-basis: 100%; }
  .ds-table :is(th, td).ds-table__select { width: 1%; padding-inline-end: 0; }
  /* Row actions take their natural width and keep each label on one line; the
     table region scrolls instead when the row cannot fit. Only the cell's own
     buttons are matched, so a dialog opened from the cell keeps wrapping. */
  .ds-table :is(th, td).ds-table__actions { width: 1%; }
  /* A row's action stays in reach while its other columns scroll, unless enlarged text leaves it too little room. */
  @container ds (min-width: 20rem) {
    .ds-table :is(th, td).ds-table__actions { position: sticky; inset-inline-end: 0; background: var(--ds-color-bg); }
    /* The divider appears only while columns are hidden behind the pinned one. */
    @container ds-table-scroll scroll-state(scrollable: inline-end) {
      .ds-table :is(th, td).ds-table__actions { box-shadow: inset var(--ds-border-width) 0 0 var(--ds-color-border); }
    }
  }
  /* A row header holding identifiers that may break anywhere keeps a readable floor; past it the region scrolls instead of crushing the column (D052). */
  .ds-table th[scope="row"]:has(.ds-break-anywhere) { min-width: 12rem; }
  .ds-table :is(th, td).ds-table__actions > .ds-button > .ds-button__label { white-space: nowrap; }
  .ds-table tbody tr[data-selected] > :is(th, td) { background: var(--ds-color-surface-hover); }

  /* Page thumbnail: a scanned page beside its row. */
  .ds-thumb { display: grid; gap: var(--ds-space-1); justify-items: start; font-size: var(--ds-text-xs); font-variant-numeric: tabular-nums; }
  .ds-thumb img, .ds-thumb__empty {
    width: 5rem;
    aspect-ratio: 1 / 1.414;
    border: var(--ds-border-width) solid var(--ds-color-border);
    border-radius: var(--ds-radius-sm);
    background: var(--ds-color-surface-sunken);
    object-fit: cover;
    object-position: top;
  }
  .ds-thumb__empty { display: grid; place-items: center; color: var(--ds-color-text-disabled); }

  /* Breadcrumb -------------------------------------------------------------- */
  .ds-breadcrumb { display: flex; flex-wrap: wrap; align-items: center; gap: var(--ds-space-1) var(--ds-space-2); margin: 0; padding: 0; list-style: none; color: var(--ds-color-text-muted); font-size: var(--ds-text-sm); }
  .ds-breadcrumb li { display: inline-flex; align-items: center; gap: var(--ds-space-2); min-width: 0; }
  .ds-breadcrumb li + li::before { content: "/"; color: var(--ds-color-border-strong); }
  .ds-breadcrumb a { display: inline-flex; align-items: center; min-height: var(--ds-size-touch-target); }
  .ds-breadcrumb a:hover { color: var(--ds-color-accent-hover); text-decoration: underline; }
  .ds-breadcrumb [aria-current="page"] { color: var(--ds-color-text); font-weight: var(--ds-weight-strong); }

  /* Page header ------------------------------------------------------------- */
  .ds-page-header { display: grid; gap: var(--ds-space-3); }
  .ds-page-header__back { display: inline-flex; align-items: center; gap: var(--ds-space-2); justify-self: start; font-size: var(--ds-text-sm); }
  .ds-page-header__back svg { width: var(--ds-size-icon-sm); height: var(--ds-size-icon-sm); }
  .ds-page-header__row { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--ds-space-4); }
  .ds-page-header__text { display: grid; gap: var(--ds-space-2); min-width: 0; }
  .ds-page-header__title { font-size: var(--ds-text-3xl); }
  .ds-page-header__description { max-width: var(--ds-measure); color: var(--ds-color-text-muted); }
  .ds-page-header__actions { display: flex; flex-wrap: wrap; gap: var(--ds-space-2); }

  /* Report processing status: two segmented rings ---------------------------- */
  .ds-report-status {
    --ds-report-size: 3.25rem;
    --ds-report-extracted: var(--ds-color-success);
    --ds-report-indexed: var(--ds-color-accent);
    --ds-report-track: var(--ds-color-border);
    --ds-report-paused: var(--ds-color-text-disabled);
    display: inline-grid;
    justify-items: center;
    gap: var(--ds-space-2);
    font-size: var(--ds-text-xs);
  }
  .ds-report-status__button {
    position: relative;
    display: grid;
    place-items: center;
    width: var(--ds-report-size);
    height: var(--ds-report-size);
    padding: 0;
    border: 0;
    border-radius: var(--ds-radius-full);
    background: none;
    color: var(--ds-color-text);
  }
  .ds-report-status__rings { width: 100%; height: 100%; overflow: visible; }
  .ds-report-status__rings text { fill: currentColor; font-family: var(--ds-font-sans); font-size: .6875rem; font-weight: var(--ds-weight-strong); font-variant-numeric: tabular-nums; }
  .ds-report-ring__segment { fill: none; stroke: var(--ds-report-track); stroke-width: 2.5; transform-origin: 24px 24px; }
  .ds-report-ring[data-kind="extracted"] .ds-report-ring__segment[data-filled] { stroke: var(--ds-report-extracted); }
  .ds-report-ring[data-kind="indexed"] .ds-report-ring__segment[data-filled] { stroke: var(--ds-report-indexed); }
  .ds-report-ring[data-paused] .ds-report-ring__segment[data-filled] { stroke: var(--ds-report-paused); }
  .ds-report-status__badge {
    position: absolute;
    inset-inline-end: -1px;
    inset-block-end: -1px;
    display: grid;
    place-items: center;
    width: 1rem;
    height: 1rem;
    border-radius: var(--ds-radius-full);
    background: var(--ds-color-success);
    color: var(--ds-color-text-inverse);
  }
  .ds-report-status__badge[data-tone="danger"] { background: var(--ds-color-danger); }
  .ds-report-status__badge svg { width: .75rem; height: .75rem; stroke-width: 2.5; }
  /* Hover or keyboard focus reveals that the rings open the report's settings. */
  .ds-report-status__edit {
    position: absolute;
    display: grid;
    place-items: center;
    width: 62%;
    height: 62%;
    border-radius: var(--ds-radius-full);
    background: var(--ds-color-surface);
    color: var(--ds-color-accent);
    opacity: 0;
    transition: opacity var(--ds-duration-fast) var(--ds-ease);
  }
  .ds-report-status__edit svg { width: var(--ds-size-icon-sm); height: var(--ds-size-icon-sm); }
  .ds-report-status__button:is(:hover, :focus-visible) .ds-report-status__edit { opacity: 1; }
  .ds-report-status__caption { color: var(--ds-color-text-muted); font-variant-numeric: tabular-nums; }
  .ds-report-status__summary { display: grid; gap: var(--ds-space-1); color: var(--ds-color-text-muted); text-align: center; white-space: nowrap; font-variant-numeric: tabular-nums; }
  .ds-report-status__summary strong { color: var(--ds-color-text); font-weight: var(--ds-weight-strong); }
  .ds-report-status__summary[data-error] strong { color: var(--ds-color-danger); }

  /* Workers: one compact tile each; the full name sits in the name's tooltip. */
  .ds-worker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(10rem, 100%), 1fr)); gap: var(--ds-space-2); margin: 0; padding: 0; list-style: none; }
  .ds-worker-tile { display: grid; gap: var(--ds-space-1); min-width: 0; padding: var(--ds-space-2) var(--ds-space-3); border: var(--ds-border-width) solid var(--ds-color-border); border-radius: var(--ds-radius-md); background: var(--ds-color-surface); }
  .ds-worker-tile__head { display: flex; align-items: center; justify-content: space-between; gap: var(--ds-space-2); min-width: 0; }
  .ds-worker-tile__anchor { min-width: 0; }
  .ds-worker-tile__name { overflow: hidden; color: var(--ds-color-text); font-family: var(--ds-font-mono); font-size: var(--ds-text-sm); font-weight: var(--ds-weight-strong); text-overflow: ellipsis; white-space: nowrap; border-radius: var(--ds-radius-sm); }
  .ds-worker-tile__jobs { color: var(--ds-color-text-muted); font-size: var(--ds-text-xs); }

  .ds-report-legend { display: flex; flex-wrap: wrap; gap: var(--ds-space-2) var(--ds-space-4); color: var(--ds-color-text-muted); font-size: var(--ds-text-xs); }
  .ds-report-legend span { display: inline-flex; align-items: center; gap: var(--ds-space-1); }
  .ds-report-legend i { width: .5rem; height: .5rem; border-radius: var(--ds-radius-full); background: var(--ds-color-success); }
  .ds-report-legend i[data-kind="indexed"] { background: var(--ds-color-accent); }

  /* Split: a list beside the selected item's detail; stacks in a narrow column. */
  .ds-split { display: grid; grid-template-columns: minmax(16rem, 22rem) minmax(0, 1fr); gap: var(--ds-space-6); align-items: start; }
  @container ds (max-width: 64rem) { .ds-split { grid-template-columns: minmax(0, 1fr); } }

  /* Item list: selectable records, the current one marked with aria-current. */
  .ds-item-list { display: grid; gap: var(--ds-space-2); margin: 0; padding: 0; list-style: none; }
  .ds-item-list__item {
    display: grid;
    gap: var(--ds-space-1);
    width: 100%;
    padding: var(--ds-space-3) var(--ds-space-4);
    border: var(--ds-border-width) solid var(--ds-color-border);
    border-radius: var(--ds-radius-md);
    background: var(--ds-color-surface);
    color: var(--ds-color-text);
    text-align: start;
    overflow-wrap: anywhere;
    transition: border-color var(--ds-duration-fast) var(--ds-ease), background-color var(--ds-duration-fast) var(--ds-ease);
  }
  .ds-item-list__item:hover:not(:disabled) { border-color: var(--ds-color-border-strong); }
  .ds-item-list__item[aria-current="true"] { border-color: var(--ds-color-action); background: var(--ds-color-surface-sunken); }
  .ds-item-list__item:disabled { color: var(--ds-color-text-disabled); }
  .ds-item-list__meta { color: var(--ds-color-text-muted); font-size: var(--ds-text-sm); }

  /* Record list: records with their own actions, such as API keys. The action sits beside the
     record and moves under it when the row is too narrow for both, so it never leaves view. */
  .ds-record-list { display: grid; margin: 0; padding: 0; list-style: none; }
  .ds-record-list > li {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--ds-space-2) var(--ds-space-4);
    padding-block: var(--ds-space-3);
    border-bottom: var(--ds-border-width) solid var(--ds-color-border);
  }
  .ds-record-list > li:first-child { padding-block-start: 0; }
  .ds-record-list > li:last-child { border-bottom: 0; }
  .ds-record-list__body { display: grid; flex: 1 1 16rem; gap: var(--ds-space-1); min-width: 0; font-size: var(--ds-text-sm); }
  .ds-record-list__actions { display: flex; flex-wrap: wrap; gap: var(--ds-space-2); }

  /* Stage: shows a modal surface in place, over its backdrop colour, as a preview. */
  .ds-stage { padding: var(--ds-space-6); border-radius: var(--ds-radius-lg); background: var(--ds-color-backdrop); }
  .ds-stage > .ds-dialog { display: grid; max-height: none; margin-inline: auto; }
  @container ds (max-width: 30rem) { .ds-stage { padding: min(var(--ds-space-3), 3vw); } }

  /* Panel: a titled block of a page ------------------------------------------- */
  .ds-panel { display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: var(--ds-space-4); min-width: 0; }
  .ds-panel__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--ds-space-2) var(--ds-space-4); }
  .ds-panel__title { font-size: var(--ds-text-xl); }
  /* Meta and actions stay together at the end, with or without a title. */
  .ds-panel__end { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--ds-space-2) var(--ds-space-4); min-width: 0; max-width: 100%; margin-inline-start: auto; }
  .ds-panel__meta { color: var(--ds-color-text-muted); font-size: var(--ds-text-sm); }
}
