/* ==========================================================================
   Codexbase AI Hub design system
   ==========================================================================

   One stylesheet for the whole product. Before this file there was no shared
   CSS at all: 25 templates each carried their own inline <style> block, and
   there were 4 media queries across 59 templates, so every page was its own
   private design and none of them worked on a phone.

   Three rules this file exists to enforce:

   1. No raw hex outside the token blocks below. A component that hardcodes a
      colour cannot be themed, and that is exactly how the product ended up
      dark-only.
   2. Mobile first. Every layout rule starts at the narrow case and widens at
      a breakpoint, never the reverse.
   3. Bootstrap stays, but it is driven from these tokens via --bs-*. Bootstrap
      components set `color: var(--bs-body-color)` on themselves, so pointing
      its variables at the theme fixes cards, dropdowns, modals, list groups
      and offcanvas at once rather than patching each one.

   Style: Minimalism / Swiss. High contrast, grid-based, generous gutters,
   restrained motion. Chosen for dashboards, documentation and developer SaaS.
   ========================================================================== */

/* Fonts are loaded by a <link> in base.html, not an @import here. An @import
   is only discovered once this file has downloaded and parsed, which puts the
   font request a full round trip behind the preload scanner and makes the
   first paint land in a fallback serif. */

/* ==========================================================================
   1. Tokens. Dark is the default theme
   ==========================================================================
   Dark leads because it is the product's existing identity. Light is a full
   peer, not an afterthought: every semantic token below is redefined for it.

   The theme resolves in three steps, and the order matters:
     a) :root                                   -> dark, the default
     b) @media (prefers-color-scheme: light)    -> follow the OS, but only
        :root:not([data-theme="dark"])             when the user has not chosen
     c) :root[data-theme="light"]               -> an explicit user choice wins
   ========================================================================== */

:root {
  /* ---- Neutral ramp (slate). The only greys in the product. ------------- */
  --ink-950: #020617;
  --ink-900: #0b1120;
  --ink-850: #0e1223;
  --ink-800: #141a2e;
  --ink-750: #1a1e2f;
  --ink-700: #243049;
  --ink-600: #334155;
  --ink-500: #475569;
  --ink-450: #55637a;
  --ink-400: #64748b;
  --ink-350: #7c8ba3;
  --ink-300: #94a3b8;
  --ink-200: #cbd5e1;
  --ink-100: #e2e8f0;
  --ink-50:  #f1f5f9;
  --ink-0:   #f8fafc;
  --white:   #ffffff;

  /* ---- Brand ramp (green). "Endpoint green", because it reads as a live,
         healthy API, and it is the one hue allowed to carry emphasis. ----- */
  --brand-900: #052e16;
  --brand-800: #14532d;
  --brand-700: #166534;
  --brand-600: #15803d;
  --brand-500: #16a34a;
  --brand-400: #22c55e;
  --brand-300: #4ade80;
  --brand-200: #86efac;
  --brand-100: #dcfce7;

  /* ---- Status hues. Deliberately few: a status palette that grows past
         four colours stops being readable at a glance.

         These four are NOT a categorical chart palette and must not be used
         as one. It was tried on the admin charts and had to be thrown away:
         in light, danger against warn measured 2.8 separation under colour
         vision deficiency and 9.9 under normal vision, both under the floor,
         and in dark the tokens are tuned for text on a surface, which makes
         them too light to read as filled marks. Ordinal data takes one hue
         in monotone lightness steps instead. A genuinely categorical chart
         cannot be served by the ramps as they stand and would need a real
         categorical slot order added here first. --------------------------- */
  --danger-500:  #ef4444;
  --danger-400:  #f87171;
  --danger-100:  #fee2e2;
  --warn-500:    #f59e0b;
  --warn-400:    #fbbf24;
  --warn-100:    #fef3c7;
  --info-500:    #3b82f6;
  --info-400:    #60a5fa;
  --info-100:    #dbeafe;

  /* ---- Semantic surfaces (dark) ---------------------------------------- */
  --bg:            var(--ink-950);
  --bg-subtle:     var(--ink-900);
  --surface:       var(--ink-850);
  --surface-raised:var(--ink-800);
  --surface-sunken:var(--ink-900);
  --surface-hover: var(--ink-750);

  /* ---- Semantic text (dark) -------------------------------------------- */
  --text:          var(--ink-0);
  --text-muted:    var(--ink-300);
  /* --ink-400 was the obvious choice and measured 4.24:1 on --bg, just under
     the 4.5 floor. --ink-350 is 5.84:1 and still reads as de-emphasised. */
  --text-subtle:   var(--ink-350);
  --text-inverse:  var(--ink-950);

  /* ---- Lines (dark) -----------------------------------------------------
     Two border tokens, because they answer to different rules. --border and
     --border-strong divide and group things, which is decoration, and at 3:1
     they would read as heavy boxes. --border-control draws the edge of an
     input or button, which WCAG 1.4.11 requires to reach 3:1 against its
     background: that edge is the only thing identifying the control.
     --ink-400 measures 4.24:1 on --bg here and 4.76:1 on white in the light
     theme, so one value satisfies both. ---------------------------------- */
  --border:         var(--ink-700);
  --border-strong:  var(--ink-600);
  --border-control: var(--ink-400);
  --border-subtle:  rgba(148, 163, 184, 0.12);

  /* ---- Accent (dark). On a dark surface the lighter green is the readable
         one: --brand-400 on --bg is 8.9:1, while --brand-600 is only 3.4:1
         and fails for body text. ------------------------------------------ */
  --accent:          var(--brand-400);
  --accent-hover:    var(--brand-300);
  --accent-text:     var(--brand-400);
  --accent-contrast: var(--ink-950);
  --accent-soft:     rgba(34, 197, 94, 0.14);
  --accent-ring:     rgba(34, 197, 94, 0.40);

  --danger:      var(--danger-400);
  --danger-soft: rgba(239, 68, 68, 0.14);
  --warn:        var(--warn-400);
  --warn-soft:   rgba(245, 158, 11, 0.14);
  --info:        var(--info-400);
  --info-soft:   rgba(59, 130, 246, 0.14);

  /* ---- Code surface. Always a shade off the page so a block reads as a
         distinct object in both themes. ---------------------------------- */
  --code-bg:     var(--ink-900);
  --code-border: var(--ink-700);
  --code-text:   var(--ink-100);

  /* ---- Type ------------------------------------------------------------- */
  --font-sans: 'IBM Plex Sans', ui-sans-serif, system-ui, -apple-system,
               'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo,
               Consolas, monospace;

  /* A 1.2 modular scale from 16px. 16px is the floor for body text: smaller
     forces zoom on a phone, which iOS then uses to trigger input zoom. */
  --text-xs:   0.75rem;   /* 12px: labels and table meta only, never prose */
  --text-sm:   0.875rem;  /* 14px */
  --text-base: 1rem;      /* 16px: body */
  --text-lg:   1.125rem;  /* 18px */
  --text-xl:   1.375rem;  /* 22px */
  --text-2xl:  1.75rem;   /* 28px */
  --text-3xl:  2.25rem;   /* 36px */
  --text-4xl:  3rem;      /* 48px */

  --leading-tight: 1.2;
  --leading-snug:  1.35;
  --leading-normal:1.6;
  --leading-loose: 1.75;

  --weight-light:  300;
  --weight-normal: 400;
  --weight-medium: 500;
  --weight-semi:   600;
  --weight-bold:   700;

  /* ---- Space. 4px base, density "standard". --------------------------- */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.5rem;
  --space-6:  2rem;
  --space-7:  2.5rem;
  --space-8:  3rem;
  --space-9:  4rem;
  --space-10: 6rem;

  /* ---- Radius, shadow, layout ----------------------------------------- */
  --radius-sm:   4px;
  --radius:      8px;
  --radius-lg:   12px;
  --radius-xl:   16px;
  --radius-full: 999px;

  /* Shadows are near-invisible on dark surfaces, so dark leans on borders
     and light leans on shadows. Both sets are defined; the theme picks. */
  --shadow-sm: 0 1px 2px rgba(2, 6, 23, 0.40);
  --shadow:    0 2px 8px rgba(2, 6, 23, 0.45);
  --shadow-lg: 0 12px 32px rgba(2, 6, 23, 0.55);

  --container:       1200px;
  --container-wide:  1440px;
  --container-prose: 72ch;
  --gutter:          var(--space-4);

  --nav-h: 60px;

  /* ---- Motion. One short duration for state, one longer for entrance.
         Transform and opacity only: animating width, height or top forces
         layout on every frame. ------------------------------------------- */
  --ease:        cubic-bezier(0.4, 0, 0.2, 1);
  --ease-out:    cubic-bezier(0, 0, 0.2, 1);
  --duration:    150ms;
  --duration-md: 240ms;
  --duration-lg: 360ms;

  --z-nav:    100;
  --z-drawer: 200;
  --z-modal:  300;
  --z-toast:  400;

  color-scheme: dark;
}

/* ---- Light tokens -------------------------------------------------------
   Not an inversion. On white the mid greens fail as text: --brand-400 is
   2.28:1. Text and icons therefore use --brand-700 (7.13:1), while filled
   buttons use --brand-600 with white on top (5.02:1). Every pair in both
   themes is measured by scripts/check-contrast.py, not estimated.
   ------------------------------------------------------------------------- */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg:             var(--white);
    --bg-subtle:      var(--ink-0);
    --surface:        var(--white);
    --surface-raised: var(--white);
    --surface-sunken: var(--ink-50);
    --surface-hover:  var(--ink-50);

    --text:          var(--ink-900);
    --text-muted:    var(--ink-500);
    /* --ink-400 is 4.34:1 on --surface-sunken, where placeholders sit. */
    --text-subtle:   var(--ink-450);
    --text-inverse:  var(--white);

    --border:         var(--ink-100);
    --border-strong:  var(--ink-200);
    --border-control: var(--ink-400);
    --border-subtle:  rgba(15, 23, 42, 0.08);

    --accent:          var(--brand-600);
    --accent-hover:    var(--brand-700);
    --accent-text:     var(--brand-700);
    --accent-contrast: var(--white);
    --accent-soft:     var(--brand-100);
    --accent-ring:     rgba(21, 128, 61, 0.35);

    --danger:      #dc2626;
    --danger-soft: var(--danger-100);
    --warn:        #b45309;
    --warn-soft:   var(--warn-100);
    --info:        #1d4ed8;
    --info-soft:   var(--info-100);

    --code-bg:     var(--ink-0);
    --code-border: var(--ink-100);
    --code-text:   var(--ink-900);

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow:    0 1px 3px rgba(15, 23, 42, 0.10), 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);

    color-scheme: light;
  }
}

:root[data-theme="light"] {
  --bg:             var(--white);
  --bg-subtle:      var(--ink-0);
  --surface:        var(--white);
  --surface-raised: var(--white);
  --surface-sunken: var(--ink-50);
  --surface-hover:  var(--ink-50);

  --text:          var(--ink-900);
  --text-muted:    var(--ink-500);
  /* --ink-400 is 4.34:1 on --surface-sunken, where placeholders sit. */
  --text-subtle:   var(--ink-450);
  --text-inverse:  var(--white);

  --border:         var(--ink-100);
  --border-strong:  var(--ink-200);
  --border-control: var(--ink-400);
  --border-subtle:  rgba(15, 23, 42, 0.08);

  --accent:          var(--brand-600);
  --accent-hover:    var(--brand-700);
  --accent-text:     var(--brand-700);
  --accent-contrast: var(--white);
  --accent-soft:     var(--brand-100);
  --accent-ring:     rgba(21, 128, 61, 0.35);

  --danger:      #dc2626;
  --danger-soft: var(--danger-100);
  --warn:        #b45309;
  --warn-soft:   var(--warn-100);
  --info:        #1d4ed8;
  --info-soft:   var(--info-100);

  --code-bg:     var(--ink-0);
  --code-border: var(--ink-100);
  --code-text:   var(--ink-900);

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow:    0 1px 3px rgba(15, 23, 42, 0.10), 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);

  color-scheme: light;
}

/* ---- Bootstrap bridge ---------------------------------------------------
   Bootstrap 5.3 is still rendering most of this product's markup. Mapping its
   variables onto the tokens themes every Bootstrap component in one place.
   ------------------------------------------------------------------------- */
:root {
  --bs-body-color:          var(--text);
  --bs-body-bg:             var(--bg);
  --bs-emphasis-color:      var(--text);
  --bs-secondary-color:     var(--text-muted);
  --bs-tertiary-color:      var(--text-subtle);
  --bs-border-color:        var(--border);
  --bs-heading-color:       var(--text);
  --bs-link-color:          var(--accent-text);
  --bs-link-hover-color:    var(--accent-hover);
  --bs-code-color:          var(--accent-text);
  --bs-font-sans-serif:     var(--font-sans);
  --bs-font-monospace:      var(--font-mono);
  --bs-body-font-size:      var(--text-base);
  --bs-body-line-height:    var(--leading-normal);
  --bs-border-radius:       var(--radius);
  --bs-border-radius-sm:    var(--radius-sm);
  --bs-border-radius-lg:    var(--radius-lg);
  --bs-primary:             var(--accent);
  --bs-secondary-bg:        var(--surface-raised);
  --bs-tertiary-bg:         var(--surface-sunken);
}

/* ==========================================================================
   2. Reset
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

* { margin: 0; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* Anchored headings must clear the sticky navbar or the target lands
     underneath it and looks like the link did nothing. */
  scroll-padding-top: calc(var(--nav-h) + var(--space-4));
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--weight-normal);
  line-height: var(--leading-normal);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  /* The single most common cause of horizontal scroll on a phone is one wide
     child. Clip it at the root rather than hunting every offender. */
  overflow-x: clip;
}

img, svg, video, canvas, picture {
  display: block;
  max-width: 100%;
  height: auto;
}

input, button, textarea, select { font: inherit; color: inherit; }

button { background: none; border: 0; cursor: pointer; }

a { color: var(--accent-text); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* A visible focus ring is not decoration. Removing it makes the product
   unusable by keyboard, so it is defined once here and never unset. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
:focus:not(:focus-visible) { outline: none; }

::selection { background: var(--accent-soft); color: var(--text); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-subtle); }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-full);
  border: 2px solid var(--bg-subtle);
}
::-webkit-scrollbar-thumb:hover { background: var(--text-subtle); }

/* ==========================================================================
   3. Typography
   ========================================================================== */

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-sans);
  font-weight: var(--weight-semi);
  line-height: var(--leading-tight);
  color: var(--text);
  letter-spacing: -0.015em;
  /* Stops a heading breaking to a single orphan word on a narrow screen. */
  text-wrap: balance;
}

h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
h5 { font-size: var(--text-base); }
h6 { font-size: var(--text-sm); text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }

p { text-wrap: pretty; }

.display {
  font-size: var(--text-4xl);
  font-weight: var(--weight-bold);
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.lead {
  font-size: var(--text-lg);
  line-height: var(--leading-loose);
  color: var(--text-muted);
}

.mono { font-family: var(--font-mono); font-variant-ligatures: none; }

.eyebrow {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent-text);
}

.text-muted-token  { color: var(--text-muted); }
.text-subtle-token { color: var(--text-subtle); }

.prose { max-width: var(--container-prose); }
.prose > * + * { margin-top: var(--space-4); }
.prose h2 { margin-top: var(--space-7); }
.prose h3 { margin-top: var(--space-6); }
.prose ul, .prose ol { padding-left: var(--space-5); }
.prose li + li { margin-top: var(--space-2); }

/* ==========================================================================
   4. Layout
   ========================================================================== */

.container-cb {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--gutter);
}
.container-cb--wide  { max-width: var(--container-wide); }
.container-cb--prose { max-width: var(--container-prose); }

.section       { padding-block: var(--space-8); }
.section--tight{ padding-block: var(--space-6); }
.section--hero { padding-block: var(--space-9); }

.stack > * + * { margin-top: var(--space-4); }
.stack-sm > * + * { margin-top: var(--space-2); }
.stack-lg > * + * { margin-top: var(--space-6); }

.row-cb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}
.row-cb--between { justify-content: space-between; }
.row-cb--end     { justify-content: flex-end; }
.row-cb--top     { align-items: flex-start; }

/* Auto-fit grid: collapses to one column on a phone with no media query,
   because the track minimum does the work. */
.grid-cb {
  display: grid;
  gap: var(--space-5);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
}
.grid-cb--tight { gap: var(--space-4); }
.grid-cb--wide  { grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); }

.divider {
  height: 1px;
  background: var(--border);
  border: 0;
  margin-block: var(--space-6);
}

/* Screen-reader-only, and the skip link that uses it. */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: var(--space-2);
  left: var(--space-2);
  z-index: calc(var(--z-toast) + 1);
  padding: var(--space-2) var(--space-4);
  background: var(--accent);
  color: var(--accent-contrast);
  border-radius: var(--radius);
  font-weight: var(--weight-medium);
  transform: translateY(-150%);
  transition: transform var(--duration) var(--ease);
}
.skip-link:focus { transform: translateY(0); text-decoration: none; }

/* ==========================================================================
   5. Buttons
   ==========================================================================
   44px minimum height on every variant except .btn-cb--sm, which is only for
   dense table rows where the row itself is the target.
   ========================================================================== */

.btn-cb {
  --btn-bg: transparent;
  --btn-fg: var(--text);
  --btn-bd: var(--border-control);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: var(--space-3) var(--space-5);
  background: var(--btn-bg);
  color: var(--btn-fg);
  border: 1px solid var(--btn-bd);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: 1;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--duration) var(--ease),
              border-color var(--duration) var(--ease),
              color var(--duration) var(--ease),
              transform var(--duration) var(--ease);
}
.btn-cb:hover { text-decoration: none; color: var(--btn-fg); }
.btn-cb:active { transform: translateY(1px); }
.btn-cb[disabled], .btn-cb.is-disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-cb--primary {
  --btn-bg: var(--accent);
  --btn-fg: var(--accent-contrast);
  --btn-bd: var(--accent);
  font-weight: var(--weight-semi);
}
.btn-cb--primary:hover { --btn-bg: var(--accent-hover); --btn-bd: var(--accent-hover); }

.btn-cb--secondary { --btn-bg: var(--surface-raised); --btn-bd: var(--border); }
.btn-cb--secondary:hover { --btn-bg: var(--surface-hover); --btn-bd: var(--border-strong); }

.btn-cb--ghost { --btn-bd: transparent; --btn-fg: var(--text-muted); }
.btn-cb--ghost:hover { --btn-bg: var(--surface-hover); --btn-fg: var(--text); }

.btn-cb--danger { --btn-bg: var(--danger-soft); --btn-fg: var(--danger); --btn-bd: var(--danger); }
.btn-cb--danger:hover { --btn-bg: var(--danger); --btn-fg: var(--white); }

.btn-cb--sm { min-height: 34px; padding: var(--space-2) var(--space-3); font-size: var(--text-xs); }
.btn-cb--lg { min-height: 52px; padding: var(--space-4) var(--space-6); font-size: var(--text-base); }
.btn-cb--block { width: 100%; }

/* An icon-only button has no text, so it must carry aria-label. The square
   sizing here is a reminder that the label is mandatory, not optional. */
.btn-cb--icon { padding: 0; width: 44px; min-height: 44px; }
.btn-cb--icon.btn-cb--sm { width: 34px; min-height: 34px; }

/* ==========================================================================
   6. Cards
   ========================================================================== */

.card-cb {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}
.card-cb--flush  { padding: 0; overflow: hidden; }
.card-cb--sunken { background: var(--surface-sunken); box-shadow: none; }

/* Only cards that are themselves links get a hover lift. A hover effect on a
   non-interactive card is a false affordance. */
a.card-cb, .card-cb--interactive {
  transition: border-color var(--duration) var(--ease),
              transform var(--duration) var(--ease),
              box-shadow var(--duration) var(--ease);
}
a.card-cb:hover, .card-cb--interactive:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  text-decoration: none;
}

.card-cb__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}
.card-cb__body   { padding: var(--space-5); }
.card-cb__footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border);
  background: var(--surface-sunken);
}
.card-cb__title {
  font-size: var(--text-base);
  font-weight: var(--weight-semi);
  margin: 0;
}

/* ==========================================================================
   7. Badges and pills
   ========================================================================== */

.badge-cb {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.25em 0.625em;
  background: var(--surface-raised);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  line-height: 1.5;
  /* A badge must never wrap to two lines: it stops reading as one token. */
  white-space: nowrap;
}
.badge-cb--accent { background: var(--accent-soft); color: var(--accent-text); border-color: var(--accent); }
.badge-cb--danger { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.badge-cb--warn   { background: var(--warn-soft);   color: var(--warn);   border-color: var(--warn); }
.badge-cb--info   { background: var(--info-soft);   color: var(--info);   border-color: var(--info); }

/* HTTP verbs in docs. Colour alone never carries the meaning: the verb is
   always spelled out in the label. */
.verb {
  display: inline-block;
  min-width: 4.5em;
  padding: 0.2em 0.5em;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  text-align: center;
  text-transform: uppercase;
}
.verb--get    { background: var(--info-soft);   color: var(--info); }
.verb--post   { background: var(--accent-soft); color: var(--accent-text); }
.verb--put,
.verb--patch  { background: var(--warn-soft);   color: var(--warn); }
.verb--delete { background: var(--danger-soft); color: var(--danger); }

/* Live status dot. Paired with text, never used alone. */
.status-dot {
  width: 8px; height: 8px;
  border-radius: var(--radius-full);
  background: var(--text-subtle);
  flex: none;
}
.status-dot--ok     { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.status-dot--warn   { background: var(--warn);   box-shadow: 0 0 0 3px var(--warn-soft); }
.status-dot--danger { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }

/* ==========================================================================
   8. Forms
   ========================================================================== */

.field { display: block; }
.field + .field { margin-top: var(--space-4); }

/* A visible label, always. A placeholder is not a label: it vanishes on the
   first keystroke, which leaves the field unidentified exactly when the user
   is reviewing what they typed. */
.field__label {
  display: block;
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text);
}
.field__label .req { color: var(--danger); margin-left: 2px; }

.field__hint {
  margin-top: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-muted);
}

/* The error sits next to the field it belongs to, not only in a summary at
   the top of the form, so the fix is visible where the cursor already is. */
.field__error {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  margin-top: var(--space-2);
  font-size: var(--text-sm);
  color: var(--danger);
}

.input-cb {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: var(--space-3) var(--space-4);
  background: var(--surface-sunken);
  color: var(--text);
  border: 1px solid var(--border-control);
  border-radius: var(--radius);
  /* 16px exactly. Any smaller and iOS Safari zooms the viewport on focus. */
  font-size: var(--text-base);
  transition: border-color var(--duration) var(--ease),
              box-shadow var(--duration) var(--ease);
}
.input-cb::placeholder { color: var(--text-subtle); }
.input-cb:hover { border-color: var(--text-subtle); }
.input-cb:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.input-cb[disabled] { opacity: 0.6; cursor: not-allowed; }
.input-cb[aria-invalid="true"] { border-color: var(--danger); }
.input-cb[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px var(--danger-soft); }

textarea.input-cb { min-height: 120px; resize: vertical; line-height: var(--leading-normal); }
select.input-cb { cursor: pointer; appearance: none; padding-right: var(--space-7); }

.input-group-cb { display: flex; gap: var(--space-2); align-items: stretch; }
.input-group-cb .input-cb { flex: 1 1 auto; min-width: 0; }

/* ==========================================================================
   9. Tables
   ==========================================================================
   A data table cannot reflow below roughly 600px without becoming unreadable,
   so it scrolls inside its own wrapper instead of widening the page. The
   wrapper is focusable so the scroll region is reachable by keyboard.
   ========================================================================== */

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  -webkit-overflow-scrolling: touch;
}
.table-wrap:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.table-cb {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.table-cb th,
.table-cb td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
}
.table-cb thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-sunken);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: var(--weight-semi);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.table-cb tbody tr:last-child td { border-bottom: 0; }
.table-cb tbody tr { transition: background-color var(--duration) var(--ease); }
.table-cb tbody tr:hover { background: var(--surface-hover); }
.table-cb .num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ==========================================================================
   10. Tabs
   ==========================================================================
   Used by every engine page. Rendered as a real tablist: role="tablist" on
   the container, role="tab" + aria-selected on each trigger, role="tabpanel"
   on each panel, so arrow keys and screen readers both work.
   ========================================================================== */

.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border);
  /* On a phone the tab strip scrolls sideways rather than wrapping into two
     rows, which would push the panel below the fold. */
  overflow-x: auto;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  min-height: 44px;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  white-space: nowrap;
  cursor: pointer;
  scroll-snap-align: start;
  transition: color var(--duration) var(--ease),
              border-color var(--duration) var(--ease),
              background-color var(--duration) var(--ease);
}
.tab:hover { color: var(--text); background: var(--surface-hover); }
.tab[aria-selected="true"] {
  color: var(--accent-text);
  border-bottom-color: var(--accent);
}

.tab-panel { padding-top: var(--space-6); }
.tab-panel[hidden] { display: none; }

/* ==========================================================================
   11. Code
   ========================================================================== */

code, kbd, samp {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

:not(pre) > code {
  padding: 0.15em 0.4em;
  background: var(--accent-soft);
  color: var(--accent-text);
  border-radius: var(--radius-sm);
  /* A long endpoint or key must break rather than widen the page. */
  word-break: break-word;
}

pre {
  margin: 0;
  padding: var(--space-4);
  background: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
  -webkit-overflow-scrolling: touch;
  tab-size: 2;
}
pre code { padding: 0; background: none; color: inherit; font-size: inherit; }

.code-block { position: relative; }
.code-block__copy {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  opacity: 0;
  transition: opacity var(--duration) var(--ease);
}
.code-block:hover .code-block__copy,
.code-block__copy:focus-visible { opacity: 1; }
/* Touch devices have no hover, so the control must simply be visible. */
@media (hover: none) {
  .code-block__copy { opacity: 1; }
}

/* ==========================================================================
   12. Navigation
   ========================================================================== */

.nav-cb {
  position: sticky;
  top: 0;
  z-index: var(--z-nav);
  height: var(--nav-h);
  display: flex;
  align-items: center;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
/* color-mix is recent; this keeps the bar opaque where it is unsupported
   rather than letting content show through the blur. */
@supports not (background: color-mix(in srgb, red 50%, blue)) {
  .nav-cb { background: var(--bg); }
}

.nav-cb__inner {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  width: 100%;
  max-width: var(--container-wide);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.nav-cb__brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: var(--weight-semi);
  font-size: var(--text-base);
  color: var(--text);
  letter-spacing: -0.01em;
}
.nav-cb__brand:hover { color: var(--text); text-decoration: none; }

.nav-cb__links {
  display: none;
  align-items: center;
  gap: var(--space-1);
  margin-inline-start: auto;
}

.nav-cb__link {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  transition: color var(--duration) var(--ease),
              background-color var(--duration) var(--ease);
}
.nav-cb__link:hover { color: var(--text); background: var(--surface-hover); text-decoration: none; }
.nav-cb__link[aria-current="page"] { color: var(--accent-text); background: var(--accent-soft); }

.nav-cb__actions { display: flex; align-items: center; gap: var(--space-2); margin-inline-start: auto; }
.nav-cb__links ~ .nav-cb__actions { margin-inline-start: 0; }

.nav-cb__burger { display: inline-flex; }

/* Mobile drawer. Transform, not display, so it can animate and so focus
   order stays predictable. */
.drawer {
  position: fixed;
  inset: var(--nav-h) 0 0 auto;
  width: min(86vw, 320px);
  z-index: var(--z-drawer);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-4);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform var(--duration-md) var(--ease);
  overflow-y: auto;
  /* Clears the iOS home indicator. */
  padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
}
.drawer[data-open="true"] { transform: translateX(0); }

.drawer__link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 48px;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  color: var(--text);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
}
.drawer__link:hover { background: var(--surface-hover); text-decoration: none; }
.drawer__link[aria-current="page"] { color: var(--accent-text); background: var(--accent-soft); }

.drawer-scrim {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-drawer) - 1);
  background: rgba(2, 6, 23, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--duration-md) var(--ease);
}
.drawer-scrim[data-open="true"] { opacity: 1; pointer-events: auto; }

@media (min-width: 880px) {
  .nav-cb__links  { display: flex; }
  .nav-cb__burger { display: none; }
  .drawer, .drawer-scrim { display: none; }
}

/* ==========================================================================
   13. Footer
   ========================================================================== */

.footer-cb {
  margin-top: var(--space-9);
  padding-block: var(--space-7) var(--space-6);
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-size: var(--text-sm);
}
.footer-cb h2, .footer-cb h3 {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-subtle);
  margin-bottom: var(--space-3);
}
.footer-cb a { color: var(--text-muted); }
.footer-cb a:hover { color: var(--text); }
.footer-cb__grid {
  display: grid;
  gap: var(--space-6);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
}
.footer-cb__bottom {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  justify-content: space-between;
  align-items: center;
  margin-top: var(--space-6);
  padding-top: var(--space-5);
  border-top: 1px solid var(--border);
  color: var(--text-subtle);
  font-size: var(--text-xs);
}

/* ==========================================================================
   14. Feedback: alerts, empty states, skeletons, spinners
   ========================================================================== */

.alert-cb {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: var(--radius);
  background: var(--surface-raised);
  font-size: var(--text-sm);
}
.alert-cb--ok     { border-left-color: var(--accent); background: var(--accent-soft); }
.alert-cb--danger { border-left-color: var(--danger); background: var(--danger-soft); }
.alert-cb--warn   { border-left-color: var(--warn);   background: var(--warn-soft); }
.alert-cb--info   { border-left-color: var(--info);   background: var(--info-soft); }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-8) var(--space-5);
  text-align: center;
  color: var(--text-muted);
}
.empty-state__title { font-size: var(--text-lg); font-weight: var(--weight-semi); color: var(--text); }
.empty-state__icon { font-size: 2.8rem; opacity: 0.4; line-height: 1; }
/* Measured so the sentence wraps to two lines at most on a phone. */
.empty-state__body { max-width: 34ch; margin: 0; font-size: var(--text-sm); }
.empty-state__actions { flex-wrap: wrap; justify-content: center; gap: var(--space-2); margin-top: var(--space-2); }

/* Skeletons reserve the final size so content arriving does not shift the
   page. That is the whole point of them. */
.skeleton {
  background: linear-gradient(90deg,
    var(--surface-raised) 25%,
    var(--surface-hover)  50%,
    var(--surface-raised) 75%);
  background-size: 200% 100%;
  border-radius: var(--radius-sm);
  animation: skeleton-shimmer 1.4s linear infinite;
}
@keyframes skeleton-shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border-control);
  border-top-color: var(--accent);
  border-radius: var(--radius-full);
  animation: spin 0.7s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   15. Entrance motion
   ==========================================================================
   Opt-in only, and opacity/transform only. Nothing here may move layout.
   ========================================================================== */

.reveal {
  opacity: 0;
  transform: translateY(12px);
  animation: reveal var(--duration-lg) var(--ease-out) forwards;
}
@keyframes reveal { to { opacity: 1; transform: none; } }

/* ==========================================================================
   16. Responsive type and spacing
   ==========================================================================
   Type scales at the breakpoint rather than fluidly, so line lengths stay
   predictable and nothing lands at a half pixel.
   ========================================================================== */

@media (max-width: 640px) {
  :root {
    --text-3xl: 1.75rem;
    --text-4xl: 2.125rem;
    --space-9:  2.5rem;
    --space-10: 3rem;
  }
  .section       { padding-block: var(--space-6); }
  .section--hero { padding-block: var(--space-7); }
  .card-cb       { padding: var(--space-4); }
  .display       { font-size: var(--text-4xl); }
  /* Stacked buttons go full width: side-by-side taps under 44px wide are the
     most common mis-tap on a phone. */
  .row-cb--stack-sm { flex-direction: column; align-items: stretch; }
  .row-cb--stack-sm > .btn-cb { width: 100%; }
}

@media (min-width: 1024px) {
  :root { --gutter: var(--space-6); }
}

/* ==========================================================================
   17. Console shell
   ==========================================================================
   The signed-in layout: one sidebar plus one content column, shared by the
   user console and the admin pages. It replaces two separate sidebars that
   had drifted apart in width, colour and behaviour.

   Mobile first. Under 768px the nav is a horizontal scrolling strip pinned
   under the header, because the previous rule hid the sidebar outright and
   left the console with no navigation at all on a phone. The fixed vertical
   rail starts at 768px.
   ========================================================================== */

/* The rail stays in normal flow as a flex child. A fixed rail overlaps
   anything base.html renders outside its <main>, which is exactly what
   happened to the footer. */
.console-shell { display: block; }

/* ---- Console chrome -----------------------------------------------------
   base.html's header is the marketing one: Home, Models and Pricing, plus
   Dashboard and Admin buttons. On a console page every one of those is either
   irrelevant or a duplicate of a sidebar entry, so the page shows two
   navigations offering overlapping destinations.

   :has() lets a console page restyle that header without base.html needing to
   know anything about the console. What is left is the brand, the theme
   toggle and sign out, which is app chrome rather than site chrome. The
   marketing links stay reachable: they are still in the mobile drawer, and
   the brand still links home.
   ------------------------------------------------------------------------ */
/* The console's reduced header is done in base.html with
   `{% set chrome = 'console' %}`, not here. Suppressing it in CSS needed
   !important to outrank Bootstrap's d-none utilities, and left the links in
   the DOM where a screen reader still reaches them. */

.console-nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  /* Pins under the site header, which is itself sticky at --nav-h. */
  top: var(--nav-h);
  z-index: calc(var(--z-nav) - 1);
}

/* The account block and the collapse control are desktop affordances. On the
   strip they would cost a whole row and the rail cannot collapse anyway. */
.console-nav__account,
.console-nav__toggle,
.console-nav__engines { display: none; }

.console-nav__list {
  list-style: none;
  margin: 0;
  padding: var(--space-2) var(--space-3);
  display: flex;
  flex-wrap: nowrap;
  gap: var(--space-1);
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.console-nav__list::-webkit-scrollbar { display: none; }

/* A section label is a heading for a column. In a single scrolling row it is
   noise, and ten of them would double the strip's width. */
.console-nav__section { display: none; }

.console-nav__link {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  /* 44px minimum tap target: anything smaller is a mis-tap on a phone. */
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: var(--text-sm);
  white-space: nowrap;
  text-decoration: none;
  transition: background var(--duration) var(--ease),
              color var(--duration) var(--ease);
}
.console-nav__link:hover {
  background: var(--surface-hover);
  color: var(--text);
  text-decoration: none;
}
.console-nav__link.is-active {
  background: var(--accent-soft);
  color: var(--accent-text);
}

.console-main {
  padding: var(--space-4);
  min-width: 0;
}

/* ---- Desktop rail -------------------------------------------------------- */
@media (min-width: 768px) {
  :root { --console-nav-w: 240px; }
  body.sidebar-collapsed { --console-nav-w: 64px; }

  /* align-items:flex-start stops the flex row stretching the rail to the
     height of the page content. */
  .console-shell { display: flex; align-items: flex-start; }

  .console-nav {
    position: sticky;
    top: var(--nav-h);
    width: var(--console-nav-w);
    flex-shrink: 0;
    /* Its own scroll context, so a nav taller than the viewport stays
       reachable instead of being clipped. */
    height: calc(100vh - var(--nav-h));
    padding: var(--space-5) var(--space-3);
    border-bottom: none;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    overscroll-behavior: contain;
    transition: width var(--duration) var(--ease);
  }

  .console-nav__account { display: block; margin-bottom: var(--space-5); padding-inline: var(--space-3); }
  .console-nav__account-label {
    display: block;
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-subtle);
    margin-bottom: var(--space-2);
  }
  .console-nav__identity { display: flex; align-items: center; gap: var(--space-3); }
  .console-nav__avatar { border-radius: 50%; border: 2px solid var(--border); flex-shrink: 0; }
  .console-nav__who { min-width: 0; }
  .console-nav__name {
    display: block;
    font-size: var(--text-sm);
    font-weight: var(--weight-medium, 500);
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .console-nav__badges { display: flex; gap: var(--space-1); flex-wrap: wrap; margin-top: var(--space-1); }

  .console-nav__toggle {
    display: block;
    position: absolute;
    top: var(--space-3);
    right: var(--space-3);
    width: 44px;
    height: 44px;
    background: var(--surface-raised);
    border: 1px solid var(--border-control);
    border-radius: var(--radius);
    color: var(--text-muted);
    cursor: pointer;
  }
  .console-nav__toggle:hover { color: var(--accent-text); border-color: var(--accent); }

  .console-nav__list { display: block; padding: 0; overflow: visible; }
  .console-nav__section {
    display: block;
    margin: var(--space-5) 0 var(--space-2);
    padding-inline: var(--space-3);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-subtle);
  }
  /* Administration is a privilege boundary, so it gets a rule above it. */
  .console-nav__section--admin {
    margin-top: var(--space-6);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border);
    color: var(--accent-text);
  }

  .console-nav__link { margin-bottom: 2px; }

  /* Engine list: indented and quieter, so the section still reads as one
     group rather than a dozen equal weight destinations. */
  .console-nav__engines { display: block; }
  .console-nav__engines > ul { list-style: none; margin: var(--space-1) 0 0; padding: 0; }
  .console-nav__engine {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 44px;
    padding: var(--space-1) var(--space-3) var(--space-1) var(--space-6);
    border-radius: var(--radius);
    color: var(--text-subtle);
    font-size: var(--text-sm);
    text-decoration: none;
    transition: background var(--duration) var(--ease),
                color var(--duration) var(--ease);
  }
  .console-nav__engine:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
  .console-nav__engine.is-active { background: var(--accent-soft); color: var(--accent-text); }
  .console-nav__dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.55;
    flex-shrink: 0;
  }

  .console-main {
    /* flex:1 with min-width:0 rather than a margin offset. min-width is what
       lets a wide table scroll inside the column instead of forcing the whole
       row wider than the viewport. */
    flex: 1;
    min-width: 0;
    padding: var(--space-6);
  }

  /* Collapsed rail: icons only. The engine list cannot shrink to icons,
     because a dozen identical dots identify nothing. */
  body.sidebar-collapsed .console-nav { padding-inline: var(--space-2); overflow-x: hidden; }
  body.sidebar-collapsed .console-nav__account,
  body.sidebar-collapsed .console-nav__section,
  body.sidebar-collapsed .console-nav__engines,
  body.sidebar-collapsed .console-nav__link span { display: none; }
  body.sidebar-collapsed .console-nav__list { margin-top: var(--space-7); }
  body.sidebar-collapsed .console-nav__link { justify-content: center; padding-inline: 0; }
  body.sidebar-collapsed .console-nav__toggle { right: 50%; transform: translateX(50%); }
}

/* ---- Role and plan badges ------------------------------------------------ */
.badge-cb--plan {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text-muted);
  text-transform: uppercase;
}
.badge-cb--admin {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  color: var(--accent-text);
  text-transform: uppercase;
}

/* Still used by admin/user_detail.html. Same treatment as the nav badge so
   the two cannot drift apart again. */
.admin-badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  color: var(--accent-text);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: var(--weight-semi);
}

/* ---- Page header --------------------------------------------------------- */
.console-page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}
.console-page-head__title { font-size: var(--text-xl); font-weight: var(--weight-bold, 700); margin: 0; }
.console-page-head__sub   { color: var(--text-muted); font-size: var(--text-sm); margin: 0; }

/* ---- Request log ---------------------------------------------------------
   Status pills, latency tones, pagination and the filter bar for the two
   request log tables. dashboard/usage.html and admin/api_usage.html each
   carried an identical private copy of these rules, which is how the pair
   would have drifted. One definition, both pages.

   The 2xx/4xx/5xx names are kept rather than renamed to ok/warn/bad, because
   a reader scanning the template is matching them against HTTP status codes.
   ------------------------------------------------------------------------ */
.status-pill {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: var(--weight-semi);
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
}
.status-2xx { background: var(--accent-soft); color: var(--accent-text); border-color: var(--accent); }
.status-4xx { background: var(--warn-soft);   color: var(--warn);        border-color: var(--warn); }
.status-5xx { background: var(--danger-soft); color: var(--danger);      border-color: var(--danger); }

/* Latency tone. Fast is the accent rather than a separate green, so the
   palette has one success colour and not two that nearly match. */
.lat-fast { color: var(--accent-text); }
.lat-mid  { color: var(--warn); }
.lat-slow { color: var(--danger); }

.pager { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: var(--space-2); margin-top: var(--space-4); }
.pager__ellipsis { color: var(--text-muted); padding-inline: var(--space-1); }
.pg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* 44px, same floor as every other tap target. The old 5px padding gave
     roughly 28px, which is a miss on a phone. */
  min-height: 44px;
  min-width: 44px;
  padding: var(--space-2) var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: var(--text-sm);
  text-decoration: none;
  transition: border-color var(--duration) var(--ease), color var(--duration) var(--ease);
}
.pg-btn:hover { border-color: var(--accent); color: var(--accent-text); text-decoration: none; }
.pg-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

.filter-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
}
.filter-bar label {
  display: block;
  margin-bottom: 3px;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
/* 16px on the controls: anything smaller makes iOS Safari zoom on focus. */
.filter-bar select, .filter-bar input {
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  background: var(--surface-sunken);
  border: 1px solid var(--border-control);
  border-radius: var(--radius);
  color: var(--text);
  font-size: var(--text-base);
}

.log-row { transition: background var(--duration) var(--ease); }
.log-row:hover { background: var(--surface-hover); }

/* An endpoint can be long; it gets one line with an ellipsis rather than
   pushing the table wider than the viewport. */
.log-endpoint {
  display: block;
  font-family: var(--font-mono);
  color: var(--accent-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.log-error {
  display: block;
  margin-top: 2px;
  font-size: var(--text-xs);
  color: var(--danger);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* A timestamp must not wrap to two lines and double the row height. */
.log-time { white-space: nowrap; font-size: var(--text-xs); }
/* Bounds the ellipsis on .log-endpoint; without a max the cell just grows. */
.log-endpoint-cell { max-width: 280px; }

.filter-note {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  font-size: var(--text-sm);
  color: var(--text-muted);
}
.filter-note code { color: var(--accent-text); }

/* ---- Console layout helpers --------------------------------------------- */
/* Chart beside a list on a wide screen, stacked on a narrow one. The chart
   gets the larger share because a bar chart squeezed under 400px is unreadable
   while a list is not. */
.console-split { display: grid; grid-template-columns: 1fr; gap: var(--space-5); margin-bottom: var(--space-5); }
@media (min-width: 992px) { .console-split { grid-template-columns: 2fr 1fr; } }

.console-chart { padding: var(--space-4); }

/* Names the measure in a stacked pair of panels, which is what replaces a
   second y axis. */
.chart-panel__label {
  margin: 0 0 var(--space-2);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-subtle);
}
.chart-panel__label--spaced { margin-top: var(--space-5); }

.card-cb__link { font-size: var(--text-sm); color: var(--accent-text); }
.card-cb__link::after { content: " \2192"; }

.model-list { list-style: none; margin: 0; padding: 0; }
.model-list__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
}
.model-list__row:last-child { border-bottom: none; }
.model-list__id { min-width: 0; }
.model-list__name { display: block; font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--text); }
.model-list__slug { display: block; font-size: var(--text-xs); color: var(--text-muted); overflow-wrap: anywhere; }

/* Status and meta cells -----------------------------------------------------
   A status code is read as a word as much as a colour, so the icon carries
   the meaning too rather than leaving colour as the only signal. */
.status-text { display: inline-flex; align-items: center; gap: var(--space-1); font-size: var(--text-sm); }
.status-text--ok  { color: var(--accent-text); }
.status-text--bad { color: var(--danger); }
.is-meta { color: var(--text-muted); font-size: var(--text-sm); }

.table-cb__empty { text-align: center; padding: var(--space-6) var(--space-4); color: var(--text-muted); }

/* ---- Stat card ----------------------------------------------------------
   A metric tile: icon, optional tag, a number and a label. Used on the
   console overview and on every engine page.

   These class names predate the design system and were defined in the old
   base.html. That file was rebuilt and the definitions did not survive, so
   until now the markup rendered as loose unstyled text on every page that
   used it. Tone is one local custom property rather than four near-copies of
   the rule, so a new tone is one line.
   ------------------------------------------------------------------------ */
.stat-card {
  --stat-tone:      var(--accent);
  --stat-tone-soft: var(--accent-soft);
  --stat-tone-text: var(--accent-text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  height: 100%;
}
.stat-card--warn   { --stat-tone: var(--warn);   --stat-tone-soft: var(--warn-soft);   --stat-tone-text: var(--warn); }
.stat-card--danger { --stat-tone: var(--danger); --stat-tone-soft: var(--danger-soft); --stat-tone-text: var(--danger); }
.stat-card--info   { --stat-tone: var(--info);   --stat-tone-soft: var(--info-soft);   --stat-tone-text: var(--info); }

.stat-card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.stat-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
  background: var(--stat-tone-soft);
  color: var(--stat-tone-text);
}

.stat-value {
  font-family: var(--font-mono);
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  line-height: 1.1;
  color: var(--stat-tone-text);
  /* A long number must not push the tile wider than its grid cell. */
  overflow-wrap: anywhere;
}
.stat-value--plain { color: var(--text); }

.stat-label { margin: var(--space-1) 0 0; font-size: var(--text-sm); color: var(--text-muted); }

/* One column on a phone, because two 150px tiles put a four digit number and
   its label on separate lines. */
.stat-grid { display: grid; grid-template-columns: 1fr; gap: var(--space-4); margin-bottom: var(--space-5); }
@media (min-width: 560px)  { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1200px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }

/* ---- Profile page -------------------------------------------------------- */
.profile-id { display: flex; align-items: center; gap: var(--space-4); margin-bottom: var(--space-5); }
.profile-id__avatar { border-radius: 50%; border: 2px solid var(--border); flex-shrink: 0; }
.profile-id__who { min-width: 0; }
.profile-id__name  { font-size: var(--text-lg); font-weight: var(--weight-semi); margin: 0; }
.profile-id__email { font-size: var(--text-sm); color: var(--text-muted); margin: 0; overflow-wrap: anywhere; }
.profile-id__badges { display: flex; flex-wrap: wrap; gap: var(--space-1); margin: var(--space-2) 0 0; }

.profile-section__title {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-subtle);
  margin: 0 0 var(--space-4);
}

/* Two columns on a phone rather than four: four 90px cells put the numbers
   on two lines each. */
.profile-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-4); margin: 0 0 var(--space-4); }
.profile-stats dt { font-size: var(--text-xs); color: var(--text-muted); }
.profile-stats dd { margin: 0; }
.profile-stats__big { font-size: var(--text-lg); font-weight: var(--weight-semi); color: var(--text); }
@media (min-width: 560px) {
  .profile-stats { grid-template-columns: repeat(4, 1fr); }
}

.quota { height: 7px; background: var(--surface-sunken); border-radius: var(--radius-sm); overflow: hidden; }
.quota__fill { height: 100%; border-radius: var(--radius-sm); transition: width var(--duration-lg) var(--ease); }
.quota__fill--ok     { background: var(--accent); }
.quota__fill--warn   { background: var(--warn); }
.quota__fill--danger { background: var(--danger); }

.profile-facts { display: grid; grid-template-columns: auto 1fr; gap: var(--space-2) var(--space-4); margin: 0; font-size: var(--text-sm); }
.profile-facts dt { color: var(--text-muted); font-weight: var(--weight-regular, 400); }
.profile-facts dd { margin: 0; color: var(--text); }

.profile-actions { flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-4); }


/* ==========================================================================
   18. Accessibility and print
   ========================================================================== */

/* Honour the OS setting. Animation is removed, but never at the cost of the
   final state: everything settles where it would have ended up. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .reveal { opacity: 1; transform: none; }
  html { scroll-behavior: auto; }
}

@media (prefers-contrast: more) {
  :root { --border: var(--text-subtle); --border-strong: var(--text-muted); }
}

@media print {
  .nav-cb, .drawer, .drawer-scrim, .footer-cb,
  .skip-link, .code-block__copy { display: none !important; }
  body { background: #fff; color: #000; }
  pre, .card-cb { border: 1px solid #ccc; break-inside: avoid; }
  a { color: #000; text-decoration: underline; }
  /* A printed page loses every href, so put the URL back in the text. */
  .prose a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 0.85em; }
}
